• 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 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     Utils::TestWindowInfo keyGuardWindowInfo_;
34 };
35 
SetUpTestCase()36 void WindowInputMethodTest::SetUpTestCase()
37 {
38     auto display = DisplayManager::GetInstance().GetDisplayById(0);
39     ASSERT_TRUE((display != nullptr));
40     Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
41     Utils::InitByDisplayRect(displayRect);
42 }
43 
TearDownTestCase()44 void WindowInputMethodTest::TearDownTestCase()
45 {
46 }
47 
SetUp()48 void WindowInputMethodTest::SetUp()
49 {
50     inputMethodWindowInfo_ = {
51         .name = "",
52         .rect = Utils::customAppRect_,
53         .type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,
54         .mode = WindowMode::WINDOW_MODE_FLOATING,
55         .needAvoid = false,
56         .parentLimit = false,
57         .parentId = INVALID_WINDOW_ID,
58     };
59     keyGuardWindowInfo_ = {
60         .name = "",
61         .rect = Utils::customAppRect_,
62         .type = WindowType::WINDOW_TYPE_KEYGUARD,
63         .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
64         .needAvoid = false,
65         .parentLimit = false,
66         .parentId = INVALID_WINDOW_ID,
67     };
68 }
69 
TearDown()70 void WindowInputMethodTest::TearDown()
71 {
72 }
73 
74 namespace {
75 /**
76  * @tc.name: InputMethodWindow01
77  * @tc.desc: One InputMethod Floating Window
78  * @tc.type: FUNC
79  */
80 HWTEST_F(WindowInputMethodTest, InputMethodWindow01, Function | MediumTest | Level3)
81 {
82     inputMethodWindowInfo_.name = "input_method.1";
83     const sptr<Window>& window = Utils::CreateTestWindow(inputMethodWindowInfo_);
84     ASSERT_EQ(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, window->GetType());
85     ASSERT_EQ(WMError::WM_OK, window->Show());
86     ASSERT_EQ(WMError::WM_OK, window->Hide());
87 }
88 
89 /**
90  * @tc.name: InputMethodWindow02
91  * @tc.desc: One KeyGuard Window
92  * @tc.type: FUNC
93  */
94 HWTEST_F(WindowInputMethodTest, InputMethodWindow02, Function | MediumTest | Level3)
95 {
96     keyGuardWindowInfo_.name  = "keyGuard.1";
97     const sptr<Window>& window = Utils::CreateTestWindow(keyGuardWindowInfo_);
98     ASSERT_EQ(WindowType::WINDOW_TYPE_KEYGUARD, window->GetType());
99     ASSERT_EQ(WMError::WM_OK, window->Show());
100     ASSERT_EQ(WMError::WM_OK, window->Hide());
101 }
102 
103 /**
104  * @tc.name: InputMethodWindow03
105  * @tc.desc: One InputMethod Floating Window & One KeyGuard Window
106  * @tc.type: FUNC
107  */
108 HWTEST_F(WindowInputMethodTest, InputMethodWindow03, Function | MediumTest | Level3)
109 {
110     inputMethodWindowInfo_.name = "input_method.2";
111     keyGuardWindowInfo_.name  = "keyGuard.2";
112     const sptr<Window>& inputMethodWindow = Utils::CreateTestWindow(inputMethodWindowInfo_);
113     const sptr<Window>& keyGuardWindow = Utils::CreateTestWindow(keyGuardWindowInfo_);
114     keyGuardWindow->Show();
115     inputMethodWindow->Show();
116     ASSERT_TRUE(Utils::RectEqualTo(keyGuardWindow, Utils::displayRect_));
117     ASSERT_EQ(inputMethodWindow->GetRect().width_,  Utils::customAppRect_.width_);
118     ASSERT_EQ(inputMethodWindow->GetRect().height_,  Utils::customAppRect_.height_);
119 }
120 } // namespace
121 } // namespace Rosen
122 } // namespace OHOS
123