• 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 "scene_board_judgement.h"
19 #include "window_test_utils.h"
20 #include "wm_common.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28 using Utils = WindowTestUtils;
29 constexpr uint32_t MAX_INT = -1;
30 }
31 
32 class WindowInputMethodTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 
39 private:
40     static constexpr uint32_t TEST_SLEEP_SECOND = 1;
41     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
42 };
43 
SetUpTestCase()44 void WindowInputMethodTest::SetUpTestCase()
45 {
46     auto display = DisplayManager::GetInstance().GetDisplayById(0);
47     ASSERT_TRUE((display != nullptr));
48     Rect displayRect = { 0, 0, display->GetWidth(), display->GetHeight() };
49     Utils::InitByDisplayRect(displayRect);
50 }
51 
TearDownTestCase()52 void WindowInputMethodTest::TearDownTestCase() {}
53 
SetUp()54 void WindowInputMethodTest::SetUp() {}
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, TestSize.Level1)
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     KeyboardEffectOption effectOption;
84     if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
85         sleep(TEST_SLEEP_SECOND);
86         ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(effectOption));
87         sleep(TEST_SLEEP_SECOND);
88         ASSERT_EQ(WMError::WM_OK, fullWindow->ChangeKeyboardEffectOption(effectOption));
89         sleep(TEST_SLEEP_SECOND);
90         fullWindow->Destroy();
91         return;
92     }
93     effectOption.viewMode_ = KeyboardViewMode::DARK_IMMERSIVE_MODE;
94     ASSERT_EQ(WMError::WM_OK, fullWindow->ShowKeyboard(effectOption));
95     sleep(TEST_SLEEP_SECOND);
96 
97     effectOption.viewMode_ = KeyboardViewMode::LIGHT_IMMERSIVE_MODE;
98     ASSERT_EQ(WMError::WM_OK, fullWindow->ChangeKeyboardEffectOption(effectOption));
99     sleep(TEST_SLEEP_SECOND);
100 
101     effectOption.viewMode_ = static_cast<KeyboardViewMode>(MAX_INT);
102     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, fullWindow->ChangeKeyboardEffectOption(effectOption));
103     sleep(TEST_SLEEP_SECOND);
104 
105     ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
106     sleep(TEST_SLEEP_SECOND);
107 
108     effectOption.viewMode_ = KeyboardViewMode::DARK_IMMERSIVE_MODE;
109     ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW,
110               fullWindow->ChangeKeyboardEffectOption(effectOption));
111     sleep(TEST_SLEEP_SECOND);
112     fullWindow->Destroy();
113 }
114 } // namespace
115 } // namespace Rosen
116 } // namespace OHOS
117