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