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 #include <gtest/gtest.h>
17 #include "window_root.h"
18 #include "window_manager.h"
19 #include "display_manager.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace Rosen {
25
26 class WindowRootTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 static sptr<WindowRoot> windowRoot_;
33 };
34
35 sptr<WindowRoot> WindowRootTest::windowRoot_ = nullptr;
36
SetUpTestCase()37 void WindowRootTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void WindowRootTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void WindowRootTest::SetUp()
46 {
47 windowRoot_ = new WindowRoot(nullptr);
48 auto display = DisplayManager::GetInstance().GetDefaultDisplay();
49 ASSERT_TRUE((display != nullptr));
50 sptr<DisplayInfo> displayInfo = display->GetDisplayInfo();
51 ASSERT_TRUE((displayInfo != nullptr));
52 }
53
TearDown()54 void WindowRootTest::TearDown()
55 {
56 windowRoot_ = nullptr;
57 }
58
59 namespace {
60 /**
61 * @tc.name: WindowRootTest01
62 * @tc.desc: test WindowRoot GetTotalWindowNum
63 * @tc.type: FUNC
64 */
65 HWTEST_F(WindowRootTest, WindowRootTest01, Function | SmallTest | Level2)
66 {
67 uint32_t size = windowRoot_->GetTotalWindowNum();
68 ASSERT_EQ(size, 0);
69 }
70
71 /**
72 * @tc.name: WindowRootTest02
73 * @tc.desc: test WindowRoot GetWindowForDumpAceHelpInfo
74 * @tc.type: FUNC
75 */
76 HWTEST_F(WindowRootTest, WindowRootTest02, Function | SmallTest | Level2)
77 {
78 sptr<WindowProperty> property = new WindowProperty();
79 property->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
80 sptr<WindowNode> windowNode = new WindowNode(property);
81 windowRoot_->SaveWindow(windowNode);
82 sptr<WindowNode> node = windowRoot_->GetWindowForDumpAceHelpInfo();
83 ASSERT_NE(node, nullptr);
84 windowRoot_->DestroyWindowInner(windowNode);
85
86 property = new WindowProperty();
87 property->SetWindowType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
88 windowNode = new WindowNode(property);
89 windowRoot_->SaveWindow(windowNode);
90 node = windowRoot_->GetWindowForDumpAceHelpInfo();
91 ASSERT_NE(node, nullptr);
92 windowRoot_->DestroyWindowInner(windowNode);
93
94 property = new WindowProperty();
95 property->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
96 windowNode = new WindowNode(property);
97 windowRoot_->SaveWindow(windowNode);
98 node = windowRoot_->GetWindowForDumpAceHelpInfo();
99 ASSERT_NE(node, nullptr);
100 windowRoot_->DestroyWindowInner(windowNode);
101
102 property = new WindowProperty();
103 property->SetWindowType(WindowType::WINDOW_TYPE_KEYGUARD);
104 windowNode = new WindowNode(property);
105 windowRoot_->SaveWindow(windowNode);
106 node = windowRoot_->GetWindowForDumpAceHelpInfo();
107 ASSERT_NE(node, nullptr);
108 windowRoot_->DestroyWindowInner(windowNode);
109 }
110
111 /**
112 * @tc.name: WindowRootTest03
113 * @tc.desc: test WindowRoot CreateWindowNodeContainer
114 * @tc.type: FUNC
115 */
116 HWTEST_F(WindowRootTest, WindowRootTest03, Function | SmallTest | Level2)
117 {
118 sptr<DisplayInfo> displayInfo = new DisplayInfo();
119
120 displayInfo->SetWidth(49);
121 auto container = windowRoot_->CreateWindowNodeContainer(0, displayInfo);
122 ASSERT_EQ(container, nullptr);
123
124 displayInfo->SetWidth(7681);
125 container = windowRoot_->CreateWindowNodeContainer(0, displayInfo);
126 ASSERT_EQ(container, nullptr);
127
128 displayInfo->SetWidth(50);
129 displayInfo->SetHeight(49);
130 container = windowRoot_->CreateWindowNodeContainer(0, displayInfo);
131 ASSERT_EQ(container, nullptr);
132
133 displayInfo->SetHeight(7681);
134 container = windowRoot_->CreateWindowNodeContainer(0, displayInfo);
135 ASSERT_EQ(container, nullptr);
136 }
137
138 /**
139 * @tc.name: WindowRootTest04
140 * @tc.desc: test WindowRoot GetWindowNodeContainer
141 * @tc.type: FUNC
142 */
143 HWTEST_F(WindowRootTest, WindowRootTest04, Function | SmallTest | Level2)
144 {
145 auto display = DisplayManager::GetInstance().GetDefaultDisplay();
146 ASSERT_NE(display, nullptr);
147 sptr<DisplayInfo> displayInfo = display->GetDisplayInfo();
148 ASSERT_NE(displayInfo, nullptr);
149 displayInfo->SetDisplayId(0);
150 displayInfo->SetScreenGroupId(SCREEN_ID_INVALID);
151 auto container = windowRoot_->CreateWindowNodeContainer(0, displayInfo);
152 ASSERT_NE(container, nullptr);
153
154 windowRoot_->GetWindowNodeContainer(DISPLAY_ID_INVALID);
155 }
156
157 /**
158 * @tc.name: WindowRootTest05
159 * @tc.desc: test WindowRoot GetBackgroundNodesByScreenId
160 * @tc.type: FUNC
161 */
162 HWTEST_F(WindowRootTest, WindowRootTest05, Function | SmallTest | Level2)
163 {
164 std::vector<sptr<WindowNode>> windowNodes;
165
166 sptr<WindowProperty> property = new WindowProperty();
167 property->SetDisplayId(DISPLAY_ID_INVALID);
168 sptr<WindowNode> windowNode1 = new WindowNode(property);
169 windowRoot_->SaveWindow(windowNode1);
170 property->SetDisplayId(0);
171 sptr<WindowNode> windowNode2 = new WindowNode(property);
172 windowRoot_->SaveWindow(windowNode2);
173
174 auto screenGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(DISPLAY_ID_INVALID);
175 windowRoot_->GetBackgroundNodesByScreenId(screenGroupId, windowNodes);
176
177 windowRoot_->DestroyWindowInner(windowNode1);
178 windowRoot_->DestroyWindowInner(windowNode2);
179
180 ASSERT_EQ(true, true);
181 }
182
183 /**
184 * @tc.name: WindowRootTest06
185 * @tc.desc: test WindowRoot AddDeathRecipient
186 * @tc.type: FUNC
187 */
188 HWTEST_F(WindowRootTest, WindowRootTest06, Function | SmallTest | Level2)
189 {
190 windowRoot_->AddDeathRecipient(nullptr);
191
192 ASSERT_EQ(true, true);
193 }
194
195 /**
196 * @tc.name: WindowRootTest07
197 * @tc.desc: test WindowRoot SaveWindow
198 * @tc.type: FUNC
199 */
200 HWTEST_F(WindowRootTest, WindowRootTest07, Function | SmallTest | Level2)
201 {
202 windowRoot_->SaveWindow(nullptr);
203
204 ASSERT_EQ(true, true);
205 }
206
207 /**
208 * @tc.name: WindowRootTest08
209 * @tc.desc: test WindowRoot MinimizeStructuredAppWindowsExceptSelf
210 * @tc.type: FUNC
211 */
212 HWTEST_F(WindowRootTest, WindowRootTest08, Function | SmallTest | Level2)
213 {
214 sptr<WindowProperty> property = new WindowProperty();
215 property->SetDisplayId(DISPLAY_ID_INVALID);
216 sptr<WindowNode> windowNode = new WindowNode(property);
217
218 WMError ret = windowRoot_->MinimizeStructuredAppWindowsExceptSelf(windowNode);
219
220 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
221 }
222
223 /**
224 * @tc.name: WindowRootTest09
225 * @tc.desc: test WindowRoot MinimizeTargetWindows
226 * @tc.type: FUNC
227 */
228 HWTEST_F(WindowRootTest, WindowRootTest09, Function | SmallTest | Level2)
229 {
230 std::vector<uint32_t> windowIds;
231
232 windowRoot_->MinimizeTargetWindows(windowIds);
233
234 windowIds.push_back(INVALID_WINDOW_ID);
235 windowRoot_->MinimizeTargetWindows(windowIds);
236
237 sptr<WindowProperty> property = new WindowProperty();
238 property->SetWindowId(1);
239 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
240 auto windowNode = new WindowNode(property);
241 windowRoot_->SaveWindow(windowNode);
242 property = new WindowProperty();
243 property->SetWindowId(2);
244 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
245 windowNode = new WindowNode(property);
246 windowRoot_->SaveWindow(windowNode);
247 windowIds.push_back(1);
248 windowIds.push_back(2);
249 windowRoot_->MinimizeTargetWindows(windowIds);
250
251 ASSERT_EQ(true, true);
252 }
253
254 /**
255 * @tc.name: WindowRootTest10
256 * @tc.desc: test WindowRoot GetSplitScreenWindowNodes
257 * @tc.type: FUNC
258 */
259 HWTEST_F(WindowRootTest, WindowRootTest10, Function | SmallTest | Level2)
260 {
261 std::vector<sptr<WindowNode>> windowNodes = windowRoot_->GetSplitScreenWindowNodes(DISPLAY_ID_INVALID);
262 ASSERT_EQ(windowNodes.empty(), true);
263 }
264
265 /**
266 * @tc.name: WindowRootTest11
267 * @tc.desc: test WindowRoot IsForbidDockSliceMove
268 * @tc.type: FUNC
269 */
270 HWTEST_F(WindowRootTest, WindowRootTest11, Function | SmallTest | Level2)
271 {
272 bool ret = windowRoot_->IsForbidDockSliceMove(DISPLAY_ID_INVALID);
273 ASSERT_EQ(ret, true);
274
275 ret = windowRoot_->IsForbidDockSliceMove(0);
276 ASSERT_EQ(ret, true);
277 }
278
279 /**
280 * @tc.name: WindowRootTest12
281 * @tc.desc: test WindowRoot IsDockSliceInExitSplitModeArea
282 * @tc.type: FUNC
283 */
284 HWTEST_F(WindowRootTest, WindowRootTest12, Function | SmallTest | Level2)
285 {
286 bool ret = windowRoot_->IsDockSliceInExitSplitModeArea(DISPLAY_ID_INVALID);
287 ASSERT_EQ(ret, false);
288
289 ret = windowRoot_->IsDockSliceInExitSplitModeArea(0);
290 ASSERT_EQ(ret, false);
291 }
292
293 /**
294 * @tc.name: WindowRootTest13
295 * @tc.desc: test WindowRoot ExitSplitMode
296 * @tc.type: FUNC
297 */
298 HWTEST_F(WindowRootTest, WindowRootTest13, Function | SmallTest | Level2)
299 {
300 windowRoot_->ExitSplitMode(DISPLAY_ID_INVALID);
301
302 windowRoot_->ExitSplitMode(0);
303 ASSERT_EQ(true, true);
304 }
305
306 /**
307 * @tc.name: WindowRootTest14
308 * @tc.desc: test WindowRoot AddSurfaceNodeIdWindowNodePair
309 * @tc.type: FUNC
310 */
311 HWTEST_F(WindowRootTest, WindowRootTest14, Function | SmallTest | Level2)
312 {
313 windowRoot_->AddSurfaceNodeIdWindowNodePair(INVALID_WINDOW_ID, nullptr);
314
315 ASSERT_EQ(true, true);
316 }
317
318 /**
319 * @tc.name: WindowRootTest15
320 * @tc.desc: test WindowRoot GetVisibilityWindowInfo
321 * @tc.type: FUNC
322 */
323 HWTEST_F(WindowRootTest, WindowRootTest15, Function | SmallTest | Level2)
324 {
325 std::vector<sptr<WindowVisibilityInfo>> infos = {};
326
327 windowRoot_->GetVisibilityWindowInfo(infos);
328
329 ASSERT_EQ(true, true);
330 }
331
332 /**
333 * @tc.name: WindowRootTest16
334 * @tc.desc: test WindowRoot GetAvoidAreaByType
335 * @tc.type: FUNC
336 */
337 HWTEST_F(WindowRootTest, WindowRootTest16, Function | SmallTest | Level2)
338 {
339 AvoidArea emptyArea;
340 AvoidArea area;
341 sptr<WindowNode> node = new WindowNode();
342
343 area = windowRoot_->GetAvoidAreaByType(node->GetWindowId(), AvoidAreaType::TYPE_CUTOUT);
344 ASSERT_EQ(area, emptyArea);
345
346 windowRoot_->windowNodeMap_.insert(std::make_pair(node->GetWindowId(), node));
347 area = windowRoot_->GetAvoidAreaByType(node->GetWindowId(), AvoidAreaType::TYPE_CUTOUT);
348 ASSERT_EQ(area, emptyArea);
349 }
350
351 /**
352 * @tc.name: WindowRootTest17
353 * @tc.desc: test WindowRoot MinimizeAllAppWindows
354 * @tc.type: FUNC
355 */
356 HWTEST_F(WindowRootTest, WindowRootTest17, Function | SmallTest | Level2)
357 {
358 windowRoot_->MinimizeAllAppWindows(DISPLAY_ID_INVALID);
359
360 ASSERT_EQ(true, true);
361 }
362
363 /**
364 * @tc.name: WindowRootTest18
365 * @tc.desc: test WindowRoot DestroyLeakStartingWindow
366 * @tc.type: FUNC
367 */
368 HWTEST_F(WindowRootTest, WindowRootTest18, Function | SmallTest | Level2)
369 {
370 windowRoot_->DestroyLeakStartingWindow();
371
372 ASSERT_EQ(true, true);
373 }
374
375 /**
376 * @tc.name: WindowRootTest20
377 * @tc.desc: test WindowRoot LayoutWhenAddWindowNode
378 * @tc.type: FUNC
379 */
380 HWTEST_F(WindowRootTest, WindowRootTest20, Function | SmallTest | Level2)
381 {
382 sptr<WindowNode> node = nullptr;
383 windowRoot_->LayoutWhenAddWindowNode(node, true);
384
385 node = new WindowNode();
386 windowRoot_->LayoutWhenAddWindowNode(node, true);
387
388 ASSERT_EQ(true, true);
389 }
390
391 /**
392 * @tc.name: WindowRootTest21
393 * @tc.desc: test WindowRoot AddWindowNode
394 * @tc.type: FUNC
395 */
396 HWTEST_F(WindowRootTest, WindowRootTest21, Function | SmallTest | Level2)
397 {
398 WMError ret;
399 sptr<WindowNode> node = nullptr;
400
401 ret = windowRoot_->AddWindowNode(INVALID_WINDOW_ID, node, true);
402 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
403 }
404
405 /**
406 * @tc.name: WindowRootTest22
407 * @tc.desc: test WindowRoot RemoveWindowNode
408 * @tc.type: FUNC
409 */
410 HWTEST_F(WindowRootTest, WindowRootTest22, Function | SmallTest | Level2)
411 {
412 WMError ret;
413 sptr<WindowNode> node = new WindowNode();
414
415 windowRoot_->windowNodeMap_.insert(std::make_pair(node->GetWindowId(), node));
416 ret = windowRoot_->RemoveWindowNode(node->GetWindowId(), true);
417 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_DISPLAY);
418 }
419
420 /**
421 * @tc.name: WindowRootTest23
422 * @tc.desc: test WindowRoot UpdateWindowNode
423 * @tc.type: FUNC
424 */
425 HWTEST_F(WindowRootTest, WindowRootTest23, Function | SmallTest | Level2)
426 {
427 WMError ret;
428
429 ret = windowRoot_->UpdateWindowNode(INVALID_WINDOW_ID, WindowUpdateReason::UPDATE_MODE);
430 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
431
432 sptr<WindowNode> node = new WindowNode();
433 windowRoot_->windowNodeMap_.insert(std::make_pair(node->GetWindowId(), node));
434 ret = windowRoot_->UpdateWindowNode(node->GetWindowId(), WindowUpdateReason::UPDATE_MODE);
435 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_DISPLAY);
436 }
437
438 /**
439 * @tc.name: WindowRootTest24
440 * @tc.desc: test WindowRoot UpdateSizeChangeReason
441 * @tc.type: FUNC
442 */
443 HWTEST_F(WindowRootTest, WindowRootTest24, Function | SmallTest | Level2)
444 {
445 WMError ret;
446
447 ret = windowRoot_->UpdateSizeChangeReason(INVALID_WINDOW_ID, WindowSizeChangeReason::UNDEFINED);
448 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
449
450 sptr<WindowNode> node = new WindowNode();
451 windowRoot_->windowNodeMap_.insert(std::make_pair(node->GetWindowId(), node));
452 ret = windowRoot_->UpdateSizeChangeReason(node->GetWindowId(), WindowSizeChangeReason::UNDEFINED);
453 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_DISPLAY);
454 }
455
456 /**
457 * @tc.name: WindowRootTest25
458 * @tc.desc: test WindowRoot SetBrightness
459 * @tc.type: FUNC
460 */
461 HWTEST_F(WindowRootTest, WindowRootTest25, Function | SmallTest | Level2)
462 {
463 windowRoot_->SetBrightness(INVALID_WINDOW_ID, 0);
464
465 sptr<WindowNode> node = new WindowNode();
466 windowRoot_->windowNodeMap_.insert(std::make_pair(node->GetWindowId(), node));
467 windowRoot_->SetBrightness(node->GetWindowId(), 0);
468
469 ASSERT_EQ(true, true);
470 }
471
472 /**
473 * @tc.name: CheckAndNotifyWaterMarkChangedResult
474 * @tc.desc: test WindowRoot CheckAndNotifyWaterMarkChangedResult
475 * @tc.type: FUNC
476 */
477 HWTEST_F(WindowRootTest, CheckAndNotifyWaterMarkChangedResult, Function | SmallTest | Level2)
478 {
479 auto display = DisplayManager::GetInstance().GetDefaultDisplay();
480 ASSERT_NE(display, nullptr);
481 sptr<DisplayInfo> displayInfo = display->GetDisplayInfo();
482 auto container = windowRoot_->CreateWindowNodeContainer(display->GetId(), displayInfo);
483 ASSERT_NE(container, nullptr);
484
485 windowRoot_->lastWaterMarkShowStates_ = false;
486 windowRoot_->CheckAndNotifyWaterMarkChangedResult();
487 ASSERT_EQ(windowRoot_->lastWaterMarkShowStates_, false);
488
489 auto windowNode = new (std::nothrow)WindowNode();
490 ASSERT_NE(windowNode, nullptr);
491 windowNode->isVisible_ = true;
492 windowNode->SetDisplayId(displayInfo->GetDisplayId());
493 windowNode->property_->flags_ |= static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_WATER_MARK);
494 container->appWindowNode_->children_.push_back(windowNode);
495
496 windowRoot_->CheckAndNotifyWaterMarkChangedResult();
497 ASSERT_EQ(windowRoot_->lastWaterMarkShowStates_, true);
498
499 container->appWindowNode_->children_.clear();
500 windowRoot_->CheckAndNotifyWaterMarkChangedResult();
501 ASSERT_EQ(windowRoot_->lastWaterMarkShowStates_, false);
502 }
503
504 /**
505 * @tc.name: SetGestureNavigaionEnabled
506 * @tc.desc: test WindowRoot SetGestureNavigaionEnabled
507 * @tc.type: FUNC
508 */
509 HWTEST_F(WindowRootTest, SetGestureNavigaionEnabled, Function | SmallTest | Level2)
510 {
511 windowRoot_->lastGestureNativeEnabled_ = false;
512 auto ret = windowRoot_->SetGestureNavigaionEnabled(false);
513 ASSERT_EQ(ret, WMError::WM_DO_NOTHING);
514
515 ret = windowRoot_->SetGestureNavigaionEnabled(true);
516 ASSERT_EQ(ret, WMError::WM_OK);
517
518 windowRoot_->lastGestureNativeEnabled_ = false;
519 }
520 }
521 }
522 }
523