1 /*
2 * Copyright (c) 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_manager.h"
19 #include "window_test_utils.h"
20 #include "wm_common.h"
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 using Utils = WindowTestUtils;
27 class WindowModeSupportInfoTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 virtual void SetUp() override;
32 virtual void TearDown() override;
33 Utils::TestWindowInfo fullAppInfo_1_;
34 Utils::TestWindowInfo fullAppInfo_2_;
35 private:
36 static constexpr uint32_t WAIT_SYANC_US = 100000;
37 };
38
SetUpTestCase()39 void WindowModeSupportInfoTest::SetUpTestCase()
40 {
41 auto display = DisplayManager::GetInstance().GetDisplayById(0);
42 ASSERT_TRUE((display != nullptr));
43 Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
44 Utils::InitByDisplayRect(displayRect);
45 }
46
TearDownTestCase()47 void WindowModeSupportInfoTest::TearDownTestCase()
48 {
49 }
50
SetUp()51 void WindowModeSupportInfoTest::SetUp()
52 {
53 fullAppInfo_1_ = {
54 .name = "FullWindow",
55 .rect = Utils::customAppRect_,
56 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
57 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
58 .needAvoid = false,
59 .parentLimit = false,
60 .parentId = INVALID_WINDOW_ID,
61 };
62 fullAppInfo_2_ = {
63 .name = "FullWindow2",
64 .rect = Utils::customAppRect_,
65 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
66 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
67 .needAvoid = false,
68 .parentLimit = false,
69 .parentId = INVALID_WINDOW_ID,
70 };
71 }
72
TearDown()73 void WindowModeSupportInfoTest::TearDown()
74 {
75 }
76
77 namespace {
78 /**
79 * @tc.name: WindowModeSupportInfo01
80 * @tc.desc: SetRequestModeSupportInfo | GetRequestModeSupportInfo
81 * @tc.type: FUNC
82 */
83 HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo01, Function | MediumTest | Level3)
84 {
85 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
86
87 window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
88 ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetRequestModeSupportInfo());
89 window->Destroy();
90 }
91
92 /**
93 * @tc.name: WindowModeSupportInfo02
94 * @tc.desc: modeSupportInfo test for single window, only support fullScreen mode
95 * @tc.type: FUNC
96 */
97 HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo02, Function | MediumTest | Level3)
98 {
99 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
100
101 window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
102 ASSERT_EQ(WMError::WM_OK, window->Show());
103 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
104
105 window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
106 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
107
108 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
109 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
110
111 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
112 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
113
114 ASSERT_EQ(WMError::WM_OK, window->Hide());
115 window->Destroy();
116 }
117
118 /**
119 * @tc.name: WindowModeSupportInfo03
120 * @tc.desc: modeSupportInfo test for single window, support both fullScreen and floating mode
121 * @tc.type: FUNC
122 */
123 HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTest | Level3)
124 {
125 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
126
127 window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN |
128 WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING);
129 ASSERT_EQ(WMError::WM_OK, window->Show());
130 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
131
132 window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
133 ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode());
134
135 window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
136 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
137
138 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
139 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
140
141 window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
142 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
143
144 ASSERT_EQ(WMError::WM_OK, window->Hide());
145 window->Destroy();
146 }
147
148 /**
149 * @tc.name: WindowModeSupportInfo04
150 * @tc.desc: modeSupportInfo test for single window, window mode is not supported when show, show failed
151 * @tc.type: FUNC
152 */
153 HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTest | Level3)
154 {
155 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
156 window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING |
157 WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
158 WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
159 ASSERT_NE(WMError::WM_OK, window->Show());
160 ASSERT_EQ(WMError::WM_OK, window->Hide());
161 window->Destroy();
162 }
163
164 /**
165 * @tc.name: WindowModeSupportInfo05
166 * @tc.desc: modeSupportInfo test for layout cascade
167 * @tc.type: FUNC
168 */
169 HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTest | Level3)
170 {
171 const sptr<Window>& window1 = Utils::CreateTestWindow(fullAppInfo_1_);
172 window1->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
173 const sptr<Window>& window2 = Utils::CreateTestWindow(fullAppInfo_2_);
174 window2->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL);
175 ASSERT_EQ(WMError::WM_OK, window1->Show());
176 ASSERT_EQ(WMError::WM_OK, window2->Show());
177 WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
178 usleep(WAIT_SYANC_US);
179
180 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window1->GetMode());
181 ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window2->GetMode());
182
183 window1->Destroy();
184 window2->Destroy();
185 }
186
187 /**
188 * @tc.name: WindowModeSupportInfo06
189 * @tc.desc: modeSupportInfo test for layout tile
190 * @tc.type: FUNC
191 */
192 HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTest | Level3)
193 {
194 const sptr<Window>& window = Utils::CreateTestWindow(fullAppInfo_1_);
195 window->SetRequestModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN);
196 ASSERT_EQ(WMError::WM_OK, window->Show());
197 WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE);
198 usleep(WAIT_SYANC_US);
199
200 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode());
201
202 window->Destroy();
203 WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
204 usleep(WAIT_SYANC_US);
205 }
206 } // namespace
207 } // namespace Rosen
208 } // namespace OHOS