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 <ability_context.h>
19
20 #include "window_test_utils.h"
21 #include "window.h"
22 #include "window_option.h"
23 #include "window_scene.h"
24 #include "wm_common.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 class WindowSystemSubWindowTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 virtual void SetUp() override;
36 virtual void TearDown() override;
37 };
38
SetUpTestCase()39 void WindowSystemSubWindowTest::SetUpTestCase()
40 {
41 }
42
TearDownTestCase()43 void WindowSystemSubWindowTest::TearDownTestCase()
44 {
45 }
46
SetUp()47 void WindowSystemSubWindowTest::SetUp()
48 {
49 }
50
TearDown()51 void WindowSystemSubWindowTest::TearDown()
52 {
53 }
54
CreateBaseWindow(WindowType type,struct Rect rect,uint32_t flags)55 static sptr<Window> CreateBaseWindow(WindowType type, struct Rect rect, uint32_t flags)
56 {
57 sptr<WindowOption> baseOp = new WindowOption();
58 baseOp->SetWindowType(type);
59 baseOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
60 baseOp->SetWindowRect(rect);
61 baseOp->SetWindowFlags(flags);
62
63 static int baseCount = 0;
64 std::string baseWindowName = "BaseWindow" + std::to_string(baseCount++);
65 sptr<Window> window = Window::Create(baseWindowName, baseOp, nullptr);
66 return window;
67 }
68
CreateAppSubWindow(sptr<Window> parentWindow,WindowType type,struct Rect rect,uint32_t flags,std::string name="")69 static sptr<Window> CreateAppSubWindow(sptr<Window> parentWindow, WindowType type, struct Rect rect,
70 uint32_t flags, std::string name = "")
71 {
72 sptr<WindowOption> subOp = new WindowOption();
73 subOp->SetWindowType(type);
74 subOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
75 subOp->SetWindowRect(rect);
76 subOp->SetWindowFlags(flags);
77 subOp->SetParentId(parentWindow->GetWindowId());
78
79 static int cnt = 0;
80 std::string subWinName = (name == "") ? "AppSubWindow" + std::to_string(cnt++) : name;
81 sptr<Window> window = Window::Create(subWinName, subOp);
82 return window;
83 }
84
CreateSystemSubWindow(sptr<Window> parentWindow,struct Rect rect,uint32_t flags,std::string name="")85 static sptr<Window> CreateSystemSubWindow(sptr<Window> parentWindow, struct Rect rect,
86 uint32_t flags, std::string name = "")
87 {
88 sptr<WindowOption> subOp = new WindowOption();
89 subOp->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
90 subOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
91 subOp->SetWindowRect(rect);
92 subOp->SetWindowFlags(flags);
93 subOp->SetParentId(parentWindow->GetWindowId());
94
95 static int cnt = 0;
96 std::string subWinName = (name == "") ? "SystemSubWindow" + std::to_string(cnt++) : name;
97 sptr<Window> window = Window::Create(subWinName, subOp);
98 return window;
99 }
100
101 /**
102 * @tc.name: SystemSubWindow01
103 * @tc.desc: create sub windows with below system Windows
104 * @tc.type: FUNC
105 */
106 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow01, Function | MediumTest | Level2)
107 {
108 std::vector<WindowType> windowTypes = {
109 WindowType::WINDOW_TYPE_WALLPAPER,
110 WindowType::WINDOW_TYPE_DESKTOP,
111 };
112 for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
113 struct Rect baseRect = {0, 0, 100, 200};
114 uint32_t baseFlags = 0;
115 sptr<Window> baseWindow = CreateBaseWindow(static_cast<WindowType>(*itor), baseRect, baseFlags);
116 ASSERT_NE(nullptr, baseWindow);
117 struct Rect rect = {0, 0, 100, 200};
118 uint32_t flags = 0;
119 sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
120 ASSERT_NE(nullptr, subWindow);
121
122 ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
123 ASSERT_EQ(WMError::WM_OK, subWindow->Show());
124
125 ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
126 ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
127
128 ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
129 ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
130 }
131 }
132
133 /**
134 * @tc.name: SystemSubWindow02
135 * @tc.desc: create sub windows with above system Windows except WINDOW_TYPE_DIALOG
136 * @tc.type: FUNC
137 */
138 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow02, Function | MediumTest | Level2)
139 {
140 std::vector<WindowType> windowTypes = {
141 WindowType::WINDOW_TYPE_APP_LAUNCHING,
142 WindowType::WINDOW_TYPE_DOCK_SLICE,
143 WindowType::WINDOW_TYPE_INCOMING_CALL,
144 WindowType::WINDOW_TYPE_SEARCHING_BAR,
145 WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
146 WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,
147 WindowType::WINDOW_TYPE_FLOAT,
148 WindowType::WINDOW_TYPE_TOAST,
149 WindowType::WINDOW_TYPE_STATUS_BAR,
150 WindowType::WINDOW_TYPE_PANEL,
151 WindowType::WINDOW_TYPE_VOLUME_OVERLAY,
152 WindowType::WINDOW_TYPE_NAVIGATION_BAR,
153 WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
154 WindowType::WINDOW_TYPE_POINTER,
155 WindowType::WINDOW_TYPE_LAUNCHER_RECENT,
156 WindowType::WINDOW_TYPE_LAUNCHER_DOCK,
157 WindowType::WINDOW_TYPE_BOOT_ANIMATION,
158 WindowType::WINDOW_TYPE_FREEZE_DISPLAY,
159 WindowType::WINDOW_TYPE_VOICE_INTERACTION,
160 WindowType::WINDOW_TYPE_FLOAT_CAMERA,
161 WindowType::WINDOW_TYPE_PLACEHOLDER,
162 WindowType::WINDOW_TYPE_SCREENSHOT,
163 };
164 for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
165 struct Rect baseRect = {0, 0, 100, 200};
166 uint32_t baseFlags = 0;
167 sptr<Window> baseWindow = CreateBaseWindow(static_cast<WindowType>(*itor), baseRect, baseFlags);
168 ASSERT_NE(nullptr, baseWindow);
169
170 struct Rect rect = {0, 0, 100, 200};
171 uint32_t flags = 0;
172 sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
173 ASSERT_NE(nullptr, subWindow);
174
175 ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
176 ASSERT_EQ(WMError::WM_OK, subWindow->Show());
177
178 ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
179 ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
180
181 ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
182 ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
183 }
184 }
185
186 /**
187 * @tc.name: SystemSubWindow03
188 * @tc.desc: create sub windows with app main Windows, no allow to add as app_main_window's subwindow
189 * @tc.type: FUNC
190 */
191 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow03, Function | MediumTest | Level2)
192 {
193
194 std::vector<WindowType> windowTypes = { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
195 for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
196 struct Rect baseRect = {0, 0, 100, 200};
197 uint32_t baseFlags = 0;
198 sptr<Window> baseWindow = CreateBaseWindow(static_cast<WindowType>(*itor), baseRect, baseFlags);
199 ASSERT_NE(nullptr, baseWindow);
200
201 struct Rect rect = {0, 0, 100, 200};
202 uint32_t flags = 0;
203 sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
204 ASSERT_EQ(nullptr, subWindow);
205 }
206 }
207
208 /**
209 * @tc.name: SystemSubWindow04
210 * @tc.desc: create sub windows with app sub Windows
211 * @tc.type: FUNC
212 */
213 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow04, Function | MediumTest | Level2)
214 {
215 std::vector<WindowType> windowTypes = {
216 WindowType::WINDOW_TYPE_MEDIA,
217 WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
218 WindowType::WINDOW_TYPE_APP_COMPONENT,
219 };
220 for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
221 struct Rect baseRect = {0, 0, 100, 200};
222 uint32_t baseFlags = 0;
223 sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, baseRect, baseFlags);
224 ASSERT_NE(nullptr, baseWindow);
225
226 sptr<Window> appSubWindow = CreateAppSubWindow(baseWindow, static_cast<WindowType>(*itor), baseRect, baseFlags);
227 ASSERT_NE(nullptr, appSubWindow);
228
229 struct Rect rect = {0, 0, 100, 200};
230 uint32_t flags = 0;
231 sptr<Window> subWindow = CreateSystemSubWindow(appSubWindow, rect, flags);
232 ASSERT_EQ(nullptr, subWindow);
233 ASSERT_EQ(WMError::WM_OK, appSubWindow->Destroy());
234 ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
235 }
236 }
237
238 /**
239 * @tc.name: SystemSubWindow05
240 * @tc.desc: create sub windows with system sub Windows
241 * @tc.type: FUNC
242 */
243 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow05, Function | MediumTest | Level3)
244 {
245 struct Rect baseRect = {0, 0, 100, 200};
246 uint32_t baseFlags = 0;
247 sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_DOCK_SLICE, baseRect, baseFlags);
248 ASSERT_NE(nullptr, baseWindow);
249
250 sptr<Window> systemSubWindow = CreateSystemSubWindow(baseWindow, baseRect, baseFlags);
251 ASSERT_NE(nullptr, systemSubWindow);
252
253 struct Rect rect = {0, 0, 100, 200};
254 uint32_t flags = 0;
255 sptr<Window> subWindow = CreateSystemSubWindow(systemSubWindow, rect, flags);
256 ASSERT_EQ(nullptr, subWindow);
257
258 ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
259 ASSERT_EQ(WMError::WM_OK, systemSubWindow->Show());
260
261 ASSERT_EQ(WMError::WM_OK, systemSubWindow->Hide());
262 ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
263
264 ASSERT_EQ(WMError::WM_OK, systemSubWindow->Destroy());
265 ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
266 }
267
268 /**
269 * @tc.name: SystemSubWindow06
270 * @tc.desc: FullScreen Main Window + 2 SubWindows
271 * @tc.type: FUNC
272 */
273 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow06, Function | MediumTest | Level3)
274 {
275 struct Rect baseRect = {0, 0, 100, 200};
276 uint32_t baseFlags = 0;
277 sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_DOCK_SLICE, baseRect, baseFlags);
278 ASSERT_NE(nullptr, baseWindow);
279
280 struct Rect rect = {0, 0, 100, 200};
281 uint32_t flags = 0;
282 sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
283 ASSERT_NE(nullptr, subWindow);
284
285 ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
286 ASSERT_EQ(WMError::WM_OK, subWindow->Show());
287
288 bool isFocus = subWindow->GetFocusable();
289 ASSERT_EQ(WMError::WM_OK, subWindow->SetFocusable(!isFocus));
290 ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(0, 0));
291 ASSERT_EQ(WMError::WM_OK, subWindow->Resize(200, 400));
292 ASSERT_EQ(WMError::WM_OK, subWindow->SetTurnScreenOn(true));
293
294 ASSERT_EQ(WMError::WM_ERROR_INVALID_TYPE, subWindow->SetBrightness(0.5f));
295 ASSERT_EQ(WMError::WM_OK, subWindow->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
296
297 ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
298 ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
299
300 ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
301 ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
302 }
303 /**
304 * @tc.name: SystemSubWindow07
305 * @tc.desc: create sub windows with dialog
306 * @tc.type: FUNC
307 */
308 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow07, Function | MediumTest | Level3)
309 {
310 struct Rect baseRect = {0, 0, 100, 200};
311 uint32_t baseFlags = 0;
312 sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_DIALOG, baseRect, baseFlags);
313 ASSERT_NE(nullptr, baseWindow);
314
315 struct Rect rect = {0, 0, 100, 200};
316 uint32_t flags = 0;
317 sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
318 ASSERT_EQ(nullptr, subWindow);
319 ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
320 }
321 } // namespace Rosen
322 } // namespace OHOS
323