• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 // gtest
17 #include <gtest/gtest.h>
18 #include "window_test_utils.h"
19 #include "wm_common.h"
20 #include "scene_board_judgement.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 using Utils = WindowTestUtils;
28 class WindowInputMethodTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 
35 private:
36     static constexpr uint32_t TEST_SLEEP_SECOND = 1;
37     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
38 };
39 
SetUpTestCase()40 void WindowInputMethodTest::SetUpTestCase()
41 {
42     auto display = DisplayManager::GetInstance().GetDisplayById(0);
43     ASSERT_TRUE((display != nullptr));
44     Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
45     Utils::InitByDisplayRect(displayRect);
46 }
47 
TearDownTestCase()48 void WindowInputMethodTest::TearDownTestCase()
49 {
50 }
51 
SetUp()52 void WindowInputMethodTest::SetUp()
53 {
54 }
55 
TearDown()56 void WindowInputMethodTest::TearDown()
57 {
58     usleep(WAIT_SYNC_IN_NS);
59 }
60 
61 namespace {
62 /**
63  * @tc.name: ShowKeyboard1
64  * @tc.desc: create window and show keyboard.
65  * @tc.type: FUNC
66  */
67 HWTEST_F(WindowInputMethodTest, ShowKeyboard01, Function | MediumTest | Level3)
68 {
69     WindowTestUtils::TestWindowInfo windowInfo = {
70         .name = "ShowKeyboard",
71         .rect = Utils::customAppRect_,
72         .type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,
73         .mode = WindowMode::WINDOW_MODE_FLOATING,
74         .needAvoid = false,
75         .parentLimit = false,
76         .showWhenLocked = true,
77         .parentId = INVALID_WINDOW_ID,
78     };
79     const sptr<Window>& fullWindow = Utils::CreateTestWindow(windowInfo);
80     if (fullWindow == nullptr) {
81         return;
82     }
83     if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
84         sleep(TEST_SLEEP_SECOND);
85         ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(KeyboardViewMode::NON_IMMERSIVE_MODE));
86         sleep(TEST_SLEEP_SECOND);
87         ASSERT_EQ(WMError::WM_OK, fullWindow->ChangeKeyboardViewMode(KeyboardViewMode::NON_IMMERSIVE_MODE));
88         sleep(TEST_SLEEP_SECOND);
89         fullWindow->Destroy();
90         return;
91     }
92     ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(KeyboardViewMode::DARK_IMMERSIVE_MODE));
93     sleep(TEST_SLEEP_SECOND);
94 
95     ASSERT_EQ(WMError::WM_OK, fullWindow->ChangeKeyboardViewMode(KeyboardViewMode::LIGHT_IMMERSIVE_MODE));
96     sleep(TEST_SLEEP_SECOND);
97 
98     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM,
99         fullWindow->ChangeKeyboardViewMode(static_cast<KeyboardViewMode>(-1)));
100     sleep(TEST_SLEEP_SECOND);
101 
102     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
103     sleep(TEST_SLEEP_SECOND);
104 
105     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
106         fullWindow->ChangeKeyboardViewMode(KeyboardViewMode::DARK_IMMERSIVE_MODE));
107     sleep(TEST_SLEEP_SECOND);
108     fullWindow->Destroy();
109 }
110 } // namespace
111 } // namespace Rosen
112 } // namespace OHOS
113