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 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 using Utils = WindowTestUtils;
26 class WindowInputMethodTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 virtual void SetUp() override;
31 virtual void TearDown() override;
32 Utils::TestWindowInfo inputMethodWindowInfo_;
33 };
34
SetUpTestCase()35 void WindowInputMethodTest::SetUpTestCase()
36 {
37 auto display = DisplayManager::GetInstance().GetDisplayById(0);
38 ASSERT_TRUE((display != nullptr));
39 Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
40 Utils::InitByDisplayRect(displayRect);
41 }
42
TearDownTestCase()43 void WindowInputMethodTest::TearDownTestCase()
44 {
45 }
46
SetUp()47 void WindowInputMethodTest::SetUp()
48 {
49 inputMethodWindowInfo_ = {
50 .name = "",
51 .rect = Utils::customAppRect_,
52 .type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,
53 .mode = WindowMode::WINDOW_MODE_FLOATING,
54 .needAvoid = false,
55 .parentLimit = false,
56 .showWhenLocked = true,
57 .parentId = INVALID_WINDOW_ID,
58 };
59 }
60
TearDown()61 void WindowInputMethodTest::TearDown()
62 {
63 }
64
65 namespace {
66 /**
67 * @tc.name: InputMethodWindow01
68 * @tc.desc: One InputMethod Floating Window
69 * @tc.type: FUNC
70 */
71 HWTEST_F(WindowInputMethodTest, InputMethodWindow01, Function | MediumTest | Level3)
72 {
73 inputMethodWindowInfo_.name = "input_method.1";
74 const sptr<Window>& window = Utils::CreateTestWindow(inputMethodWindowInfo_);
75 ASSERT_NE(window, nullptr);
76 ASSERT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, window->GetType());
77 window->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_BOTTOM, 0);
78 ASSERT_EQ(WMError::WM_OK, window->Show());
79 ASSERT_EQ(WMError::WM_OK, window->Hide());
80 window->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_FLOAT, 0);
81 ASSERT_EQ(WMError::WM_OK, window->Show());
82 ASSERT_EQ(WMError::WM_OK, window->Hide());
83 }
84
85 /**
86 * @tc.name: InputMethodWindow02
87 * @tc.desc: One InputMethod Floating Window & One KeyGuard Window
88 * @tc.type: FUNC
89 */
90 HWTEST_F(WindowInputMethodTest, InputMethodWindow02, Function | MediumTest | Level3)
91 {
92 inputMethodWindowInfo_.name = "input_method.2";
93 const sptr<Window>& inputMethodWindow = Utils::CreateTestWindow(inputMethodWindowInfo_);
94 ASSERT_NE(inputMethodWindow, nullptr);
95 inputMethodWindow->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_BOTTOM, 0);
96 inputMethodWindow->Show();
97 if (Utils::customAppRect_.width_ == inputMethodWindow->GetRect().width_) {
98 ASSERT_EQ(inputMethodWindow->GetRect().width_, Utils::customAppRect_.width_);
99 }
100
101 if (inputMethodWindow->GetRect().height_ == Utils::customAppRect_.height_) {
102 ASSERT_EQ(inputMethodWindow->GetRect().height_, Utils::customAppRect_.height_);
103 }
104
105 inputMethodWindow->Hide();
106 inputMethodWindow->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_FLOAT, 0);
107 inputMethodWindow->Show();
108
109 if (Utils::customAppRect_.width_ == inputMethodWindow->GetRect().width_) {
110 ASSERT_EQ(inputMethodWindow->GetRect().width_, Utils::customAppRect_.width_);
111 ASSERT_EQ(inputMethodWindow->GetRect().height_, Utils::customAppRect_.height_);
112 }
113 inputMethodWindow->Hide();
114 }
115 } // namespace
116 } // namespace Rosen
117 } // namespace OHOS
118