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_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, window->GetType());
76 window->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_BOTTOM, 0);
77 ASSERT_EQ(WMError::WM_OK, window->Show());
78 ASSERT_EQ(WMError::WM_OK, window->Hide());
79 window->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_FLOAT, 0);
80 ASSERT_EQ(WMError::WM_OK, window->Show());
81 ASSERT_EQ(WMError::WM_OK, window->Hide());
82 }
83
84 /**
85 * @tc.name: InputMethodWindow02
86 * @tc.desc: One InputMethod Floating Window & One KeyGuard Window
87 * @tc.type: FUNC
88 */
89 HWTEST_F(WindowInputMethodTest, InputMethodWindow02, Function | MediumTest | Level3)
90 {
91 inputMethodWindowInfo_.name = "input_method.2";
92 const sptr<Window>& inputMethodWindow = Utils::CreateTestWindow(inputMethodWindowInfo_);
93 inputMethodWindow->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_BOTTOM, 0);
94 inputMethodWindow->Show();
95 ASSERT_EQ(inputMethodWindow->GetRect().width_, Utils::customAppRect_.width_);
96 ASSERT_EQ(inputMethodWindow->GetRect().height_, Utils::customAppRect_.height_);
97 inputMethodWindow->Hide();
98 inputMethodWindow->SetWindowGravity(WindowGravity::WINDOW_GRAVITY_FLOAT, 0);
99 inputMethodWindow->Show();
100 ASSERT_EQ(inputMethodWindow->GetRect().width_, Utils::customAppRect_.width_);
101 ASSERT_EQ(inputMethodWindow->GetRect().height_, Utils::customAppRect_.height_);
102 inputMethodWindow->Hide();
103 }
104 } // namespace
105 } // namespace Rosen
106 } // namespace OHOS
107