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
18 #include "display_manager.h"
19 #include "display_manager_config.h"
20 #include "window_node_container.h"
21 #include "future.h"
22 #include "window_node.h"
23 #include "wm_common.h"
24 #include "window_transition_info.h"
25 #include "starting_window.h"
26 #include "minimize_app.h"
27
28 using namespace testing;
29 using namespace testing::ext;
30
31 namespace OHOS {
32 namespace Rosen {
33 namespace {
34 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowNodeContainerTest"};
35 }
36
37 class WindowNodeContainerTest : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 virtual void SetUp() override;
42 virtual void TearDown() override;
43 static sptr<Display> defaultDisplay_;
44 static sptr<WindowNodeContainer> container_;
45 static Rect windowRect_;
46 };
47
48 sptr<Display> WindowNodeContainerTest::defaultDisplay_ = nullptr;
49 sptr<WindowNodeContainer> WindowNodeContainerTest::container_ = nullptr;
50 Rect WindowNodeContainerTest::windowRect_;
51
SetUpTestCase()52 void WindowNodeContainerTest::SetUpTestCase()
53 {
54 defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
55 ASSERT_TRUE((defaultDisplay_ != nullptr));
56 WLOGFI("GetDefaultDisplay: id %{public}" PRIu64", w %{public}d, h %{public}d, fps %{public}u",
57 defaultDisplay_->GetId(), defaultDisplay_->GetWidth(), defaultDisplay_->GetHeight(),
58 defaultDisplay_->GetRefreshRate());
59
60 container_ = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(), defaultDisplay_->GetScreenId());
61 windowRect_ = {0, 0, 100, 200};
62 }
63
TearDownTestCase()64 void WindowNodeContainerTest::TearDownTestCase()
65 {
66 container_ = nullptr;
67 }
68
SetUp()69 void WindowNodeContainerTest::SetUp()
70 {
71 }
72
TearDown()73 void WindowNodeContainerTest::TearDown()
74 {
75 }
76
CreateWindowProperty(uint32_t windowId,const std::string & windowName,WindowType type,WindowMode mode,const Rect & screenRect)77 sptr<WindowProperty> CreateWindowProperty(uint32_t windowId, const std::string& windowName,
78 WindowType type, WindowMode mode, const Rect& screenRect)
79 {
80 sptr<WindowProperty> property = new WindowProperty();
81 property->SetWindowId(windowId);
82 property->SetWindowName(windowName);
83 property->SetWindowType(type);
84 property->SetWindowMode(mode);
85 property->SetWindowRect(screenRect);
86 return property;
87 }
88
89 namespace {
90 /**
91 * @tc.name: AddWindowNodeOnWindowTree01
92 * @tc.desc: add system sub window to system window
93 * @tc.type: FUNC
94 */
95 HWTEST_F(WindowNodeContainerTest, AddWindowNodeOnWindowTree01, Function | SmallTest | Level2)
96 {
97 sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
98 WindowType::WINDOW_TYPE_APP_LAUNCHING, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
99 sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
100
101 sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
102 WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
103 sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
104
105 ASSERT_EQ(WMError::WM_OK, container_->AddWindowNodeOnWindowTree(subNode, parentNode));
106 }
107
108 /**
109 * @tc.name: AddWindowNodeOnWindowTree02
110 * @tc.desc: add system sub window to system sub window
111 * @tc.type: FUNC
112 */
113 HWTEST_F(WindowNodeContainerTest, AddWindowNodeOnWindowTree02, Function | SmallTest | Level2)
114 {
115 sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
116 WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
117 sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
118
119 sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
120 WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
121 sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
122
123 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, container_->AddWindowNodeOnWindowTree(subNode, parentNode));
124 }
125
126 /**
127 * @tc.name: AddWindowNodeOnWindowTree03
128 * @tc.desc: add system sub window without parent
129 * @tc.type: FUNC
130 */
131 HWTEST_F(WindowNodeContainerTest, AddWindowNodeOnWindowTree03, Function | SmallTest | Level2)
132 {
133 sptr<WindowProperty> subProperty = CreateWindowProperty(110u, "test1",
134 WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
135 sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
136
137 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container_->AddWindowNodeOnWindowTree(subNode, nullptr));
138 }
139 /**
140 * @tc.name: MinimizeAppNodeExceptOptions
141 * @tc.desc: minimize app node
142 * @tc.type: FUNC
143 */
144 HWTEST_F(WindowNodeContainerTest, MinimizeAppNodeExceptOptions, Function | SmallTest | Level2)
145 {
146 std::vector<uint32_t> exceptionalIds;
147 std::vector<WindowMode> exceptionalModes;
148 ASSERT_EQ(WMError::WM_OK, container_->MinimizeAppNodeExceptOptions(MinimizeReason::OTHER_WINDOW,
149 exceptionalIds, exceptionalModes));
150
151 sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1",
152 WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
153 sptr<WindowNode> node1 = new WindowNode(property1, nullptr, nullptr);
154
155 sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2",
156 WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
157 sptr<WindowNode> node2 = new WindowNode(property2, nullptr, nullptr);
158
159 ASSERT_EQ(WMError::WM_OK, container_->AddWindowNodeOnWindowTree(node1, nullptr));
160 ASSERT_EQ(WMError::WM_OK, container_->AddWindowNodeOnWindowTree(node2, nullptr));
161 ASSERT_EQ(WMError::WM_OK, container_->MinimizeAppNodeExceptOptions(MinimizeReason::OTHER_WINDOW,
162 exceptionalIds, exceptionalModes));
163 }
164 /**
165 * @tc.name: DropShowWhenLockedWindowIfNeeded
166 * @tc.desc: drop show when locken window
167 * @tc.type: FUNC
168 */
169 HWTEST_F(WindowNodeContainerTest, DropShowWhenLockedWindowIfNeeded, Function | SmallTest | Level2)
170 {
171 sptr<WindowProperty> property = CreateWindowProperty(110u, "test1",
172 WindowType::WINDOW_TYPE_KEYGUARD, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
173 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
174 ASSERT_NE(nullptr, node);
175 container_->DropShowWhenLockedWindowIfNeeded(node);
176 }
177 /**
178 * @tc.name: GetModeChangeHotZones
179 * @tc.desc: get mode change hot zones
180 * @tc.type: FUNC
181 */
182 HWTEST_F(WindowNodeContainerTest, GetModeChangeHotZones, Function | SmallTest | Level2)
183 {
184 ModeChangeHotZonesConfig hotZonesConfig { true, 10, 20, 30 };
185 ModeChangeHotZones hotZones;
186 container_->GetModeChangeHotZones(0, hotZones, hotZonesConfig);
187 ASSERT_EQ(hotZones.fullscreen_.height_, 10);
188 ASSERT_EQ(hotZones.primary_.width_, 20);
189 ASSERT_EQ(hotZones.secondary_.width_, 30);
190 }
191 /**
192 * @tc.name: UpdateCameraFloatWindowStatus
193 * @tc.desc: update camera float window status
194 * @tc.type: FUNC
195 */
196 HWTEST_F(WindowNodeContainerTest, UpdateCameraFloatWindowStatus, Function | SmallTest | Level2)
197 {
198 sptr<WindowProperty> property = CreateWindowProperty(110u, "test1",
199 WindowType::WINDOW_TYPE_FLOAT_CAMERA, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
200 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
201 ASSERT_NE(nullptr, node);
202 container_->UpdateCameraFloatWindowStatus(node, true);
203 }
204 /**
205 * @tc.name: UpdateWindowNode
206 * @tc.desc: preprocess node and update RSTree
207 * @tc.type: FUNC
208 */
209 HWTEST_F(WindowNodeContainerTest, UpdateWindowNode, Function | SmallTest | Level2)
210 {
211 sptr<WindowProperty> property = CreateWindowProperty(110u, "test1",
212 WindowType::SYSTEM_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
213 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
214 ASSERT_EQ(WMError::WM_OK, container_->UpdateWindowNode(node, WindowUpdateReason::UPDATE_ALL));
215 ASSERT_EQ(WMError::WM_OK, container_->UpdateWindowNode(node, WindowUpdateReason::UPDATE_MODE));
216 }
217
218 /**
219 * @tc.name: ShowStartingWindow
220 * @tc.desc: show starting window
221 * @tc.type: FUNC
222 */
223 HWTEST_F(WindowNodeContainerTest, ShowStartingWindow, Function | SmallTest | Level2)
224 {
225 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
226 defaultDisplay_->GetScreenId());
227 sptr<WindowTransitionInfo> transitionInfo = new WindowTransitionInfo();
228 sptr<WindowNode> node = StartingWindow::CreateWindowNode(transitionInfo, 101); // 101 is windowId
229 node->SetWindowRect({0, 0, 100, 100});
230 node->currentVisibility_ = true;
231 ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, container->ShowStartingWindow(node));
232 ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(node, nullptr));
233 node->currentVisibility_ = false;
234 ASSERT_EQ(WMError::WM_OK, container->ShowStartingWindow(node));
235 WindowType invalidType = static_cast<WindowType>(0);
236 sptr<WindowProperty> invalidProperty = CreateWindowProperty(110u, "test1", invalidType,
237 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
238 sptr<WindowNode> invalidNode = new WindowNode(invalidProperty, nullptr, nullptr);
239 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->AddWindowNodeOnWindowTree(invalidNode, nullptr));
240 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->ShowStartingWindow(invalidNode));
241 }
242
243 /**
244 * @tc.name: IsForbidDockSliceMove
245 * @tc.desc: forbid dock slice move
246 * @tc.type: FUNC
247 */
248 HWTEST_F(WindowNodeContainerTest, IsForbidDockSliceMove, Function | SmallTest | Level2)
249 {
250 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
251 defaultDisplay_->GetScreenId());
252 ASSERT_NE(nullptr, container->displayGroupController_);
253 ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
254 ASSERT_TRUE(!container->IsForbidDockSliceMove(defaultDisplay_->GetId()));
255 }
256
257 /**
258 * @tc.name: GetWindowCountByType01
259 * @tc.desc: get window count
260 * @tc.type: FUNC
261 */
262 HWTEST_F(WindowNodeContainerTest, GetWindowCountByType01, Function | SmallTest | Level2)
263 {
264 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
265 defaultDisplay_->GetScreenId());
266 ASSERT_EQ(0, container->GetWindowCountByType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE));
267 sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1", WindowType::BELOW_APP_SYSTEM_WINDOW_BASE,
268 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
269 sptr<WindowNode> node1 = new WindowNode(property1, nullptr, nullptr);
270 sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
271 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
272 sptr<WindowNode> node2 = new WindowNode(property2, nullptr, nullptr);
273 sptr<WindowProperty> property3 = CreateWindowProperty(112u, "test3", WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE,
274 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
275 sptr<WindowNode> node3 = new WindowNode(property3, nullptr, nullptr);
276 container->belowAppWindowNode_->children_.insert(container->belowAppWindowNode_->children_.end(), node1);
277 container->appWindowNode_->children_.insert(container->appWindowNode_->children_.end(), node2);
278 container->aboveAppWindowNode_->children_.insert(container->aboveAppWindowNode_->children_.end(), node3);
279 ASSERT_EQ(0, container->GetWindowCountByType(WindowType::WINDOW_TYPE_KEYGUARD));
280 ASSERT_EQ(1, container->GetWindowCountByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW));
281 ASSERT_EQ(1, container->GetWindowCountByType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE));
282 ASSERT_EQ(1, container->GetWindowCountByType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE));
283 node1->startingWindowShown_ = true;
284 node2->startingWindowShown_ = true;
285 node3->startingWindowShown_ = true;
286 ASSERT_EQ(0, container->GetWindowCountByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW));
287 ASSERT_EQ(0, container->GetWindowCountByType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE));
288 ASSERT_EQ(0, container->GetWindowCountByType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE));
289 }
290
291 /**
292 * @tc.name: IsTileRectSatisfiedWithSizeLimits
293 * @tc.desc: judge tile rect satisfied with size limits
294 * @tc.type: FUNC
295 */
296 HWTEST_F(WindowNodeContainerTest, IsTileRectSatisfiedWithSizeLimits, Function | SmallTest | Level2)
297 {
298 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
299 defaultDisplay_->GetScreenId());
300 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE,
301 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
302 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
303 node->SetDisplayId(defaultDisplay_->GetId());
304 ASSERT_EQ(defaultDisplay_->GetId(), node->GetDisplayId());
305 ASSERT_EQ(WMError::WM_OK, container->IsTileRectSatisfiedWithSizeLimits(node));
306 ASSERT_EQ(WMError::WM_OK, container->SwitchLayoutPolicy(WindowLayoutMode::TILE, node->GetDisplayId()));
307 ASSERT_EQ(WMError::WM_OK, container->IsTileRectSatisfiedWithSizeLimits(node));
308 }
309
310 /**
311 * @tc.name: AddWindowNode01
312 * @tc.desc: add main window
313 * @tc.type: FUNC
314 */
315 HWTEST_F(WindowNodeContainerTest, AddWindowNode01, Function | SmallTest | Level2)
316 {
317 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
318 defaultDisplay_->GetScreenId());
319 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
320 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
321 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
322 sptr<WindowNode> parentNode = nullptr;
323 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
324 node->startingWindowShown_ = true;
325 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
326 }
327
328 /**
329 * @tc.name: AddWindowNode02
330 * @tc.desc: add sub window
331 * @tc.type: FUNC
332 */
333 HWTEST_F(WindowNodeContainerTest, AddWindowNode02, Function | SmallTest | Level2)
334 {
335 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
336 defaultDisplay_->GetScreenId());
337 sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
338 WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
339 sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
340
341 sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
342 WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
343 sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
344
345 sptr<WindowNode> rootNode = nullptr;
346 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(parentNode, rootNode));
347 ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(subNode, parentNode));
348 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(subNode, parentNode));
349 }
350
351 /**
352 * @tc.name: AddWindowNode03
353 * @tc.desc: add system window
354 * @tc.type: FUNC
355 */
356 HWTEST_F(WindowNodeContainerTest, AddWindowNode03, Function | SmallTest | Level2)
357 {
358 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
359 defaultDisplay_->GetScreenId());
360 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE,
361 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
362 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
363 sptr<WindowNode> parentNode = nullptr;
364 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
365 }
366
367 /**
368 * @tc.name: RemoveWindowNodeFromWindowTree
369 * @tc.desc: remove sub window from window tree
370 * @tc.type: FUNC
371 */
372 HWTEST_F(WindowNodeContainerTest, RemoveWindowNodeFromWindowTree, Function | SmallTest | Level2)
373 {
374 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
375 defaultDisplay_->GetScreenId());
376 sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
377 WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
378 sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
379
380 sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
381 WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
382 sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
383
384 sptr<WindowNode> rootNode = nullptr;
385 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(parentNode, rootNode));
386 ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(subNode, parentNode));
387 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(subNode, parentNode));
388 ASSERT_EQ(1, parentNode->children_.size());
389 container->RemoveWindowNodeFromWindowTree(subNode);
390 ASSERT_EQ(0, parentNode->children_.size());
391 }
392
393 /**
394 * @tc.name: RemoveWindowNode01
395 * @tc.desc: remove main window
396 * @tc.type: FUNC
397 */
398 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode01, Function | SmallTest | Level2)
399 {
400 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
401 defaultDisplay_->GetScreenId());
402 sptr<WindowNode> node = nullptr;
403 ASSERT_EQ(WMError::WM_ERROR_DESTROYED_OBJECT, container->RemoveWindowNode(node));
404 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
405 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
406 node = new WindowNode(property, nullptr, nullptr);
407 sptr<WindowNode> parentNode = nullptr;
408 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
409 ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(node));
410 }
411
412 /**
413 * @tc.name: RemoveWindowNode02
414 * @tc.desc: remove sub window
415 * @tc.type: FUNC
416 */
417 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode02, Function | SmallTest | Level2)
418 {
419 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
420 defaultDisplay_->GetScreenId());
421 sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
422 WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
423 sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
424
425 sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
426 WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
427 sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
428
429 sptr<WindowNode> rootNode = nullptr;
430 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(parentNode, rootNode));
431 ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(subNode, parentNode));
432 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(subNode, parentNode));
433 ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(subNode));
434 }
435
436 /**
437 * @tc.name: RemoveWindowNode03
438 * @tc.desc: remove keyguard window
439 * @tc.type: FUNC
440 */
441 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode03, Function | SmallTest | Level2)
442 {
443 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
444 defaultDisplay_->GetScreenId());
445 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
446 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
447 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
448 sptr<WindowNode> parentNode = nullptr;
449 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
450 ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(node));
451 }
452
453 /**
454 * @tc.name: RemoveWindowNode04
455 * @tc.desc: remove boot animation window
456 * @tc.type: FUNC
457 */
458 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode04, Function | SmallTest | Level2)
459 {
460 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
461 defaultDisplay_->GetScreenId());
462 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
463 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
464 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
465 sptr<WindowNode> parentNode = nullptr;
466 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
467 ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(node));
468 }
469
470 /**
471 * @tc.name: HandleRemoveWindow01
472 * @tc.desc: remove status bar
473 * @tc.type: FUNC
474 */
475 HWTEST_F(WindowNodeContainerTest, HandleRemoveWindow01, Function | SmallTest | Level2)
476 {
477 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
478 defaultDisplay_->GetScreenId());
479 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_STATUS_BAR,
480 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
481 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
482 sptr<WindowNode> parentNode = nullptr;
483 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
484 ASSERT_EQ(WMError::WM_OK, container->HandleRemoveWindow(node));
485 }
486
487 /**
488 * @tc.name: HandleRemoveWindow02
489 * @tc.desc: remove navigation bar
490 * @tc.type: FUNC
491 */
492 HWTEST_F(WindowNodeContainerTest, HandleRemoveWindow02, Function | SmallTest | Level2)
493 {
494 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
495 defaultDisplay_->GetScreenId());
496 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_NAVIGATION_BAR,
497 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
498 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
499 sptr<WindowNode> parentNode = nullptr;
500 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
501 ASSERT_EQ(WMError::WM_OK, container->HandleRemoveWindow(node));
502 }
503
504 /**
505 * @tc.name: FindDividerNode
506 * @tc.desc: find divider node
507 * @tc.type: FUNC
508 */
509 HWTEST_F(WindowNodeContainerTest, FindDividerNode, Function | SmallTest | Level2)
510 {
511 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
512 defaultDisplay_->GetScreenId());
513 ASSERT_EQ(nullptr, container->FindDividerNode());
514 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
515 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
516 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
517 sptr<WindowNode> parentNode = nullptr;
518 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
519 ASSERT_EQ(1, container->appWindowNode_->children_.size());
520 ASSERT_EQ(nullptr, container->FindDividerNode());
521 sptr<WindowProperty> dividerProperty = CreateWindowProperty(112u, "test2", WindowType::WINDOW_TYPE_DOCK_SLICE,
522 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
523 sptr<WindowNode> dividerNode = new WindowNode(dividerProperty, nullptr, nullptr);
524 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(dividerNode, parentNode));
525 ASSERT_EQ(2, container->appWindowNode_->children_.size());
526 ASSERT_EQ(dividerNode, container->FindDividerNode());
527 }
528
529 /**
530 * @tc.name: RaiseZOrderForAppWindow01
531 * @tc.desc: raise main window z order
532 * @tc.type: FUNC
533 */
534 HWTEST_F(WindowNodeContainerTest, RaiseZOrderForAppWindow01, Function | SmallTest | Level2)
535 {
536 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
537 defaultDisplay_->GetScreenId());
538 sptr<WindowProperty> property1 = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
539 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
540 sptr<WindowNode> node1 = nullptr;
541 sptr<WindowNode> parentNode = nullptr;
542 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->RaiseZOrderForAppWindow(node1, parentNode));
543 node1 = new WindowNode(property1, nullptr, nullptr);
544 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node1, parentNode));
545 sptr<WindowProperty> property2 = CreateWindowProperty(112u, "test2", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
546 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
547 sptr<WindowNode> node2 = new WindowNode(property2, nullptr, nullptr);
548 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node2, parentNode));
549 ASSERT_EQ(WMError::WM_OK, container->RaiseZOrderForAppWindow(node1, parentNode));
550 }
551
552 /**
553 * @tc.name: RaiseZOrderForAppWindow02
554 * @tc.desc: raise sub window z order
555 * @tc.type: FUNC
556 */
557 HWTEST_F(WindowNodeContainerTest, RaiseZOrderForAppWindow02, Function | SmallTest | Level2)
558 {
559 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
560 defaultDisplay_->GetScreenId());
561 sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
562 WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
563 sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
564
565 sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
566 WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
567 sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
568 sptr<WindowNode> rootNode = nullptr;
569 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->RaiseZOrderForAppWindow(subNode, rootNode));
570 ASSERT_EQ(WMError::WM_OK, container->RaiseZOrderForAppWindow(subNode, parentNode));
571 }
572
573 /**
574 * @tc.name: RaiseZOrderForAppWindow03
575 * @tc.desc: raise dialog z order
576 * @tc.type: FUNC
577 */
578 HWTEST_F(WindowNodeContainerTest, RaiseZOrderForAppWindow03, Function | SmallTest | Level2)
579 {
580 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
581 defaultDisplay_->GetScreenId());
582 sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
583 WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
584 sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
585
586 sptr<WindowProperty> dialogProperty = CreateWindowProperty(111u, "test2",
587 WindowType::WINDOW_TYPE_DIALOG, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
588 sptr<WindowNode> dialog = new WindowNode(dialogProperty, nullptr, nullptr);
589 sptr<WindowNode> rootNode = nullptr;
590 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->RaiseZOrderForAppWindow(dialog, rootNode));
591 ASSERT_EQ(WMError::WM_OK, container->RaiseZOrderForAppWindow(dialog, parentNode));
592 }
593
594 /**
595 * @tc.name: IsDockSliceInExitSplitModeArea
596 * @tc.desc: if dock slice in exit split mode area
597 * @tc.type: FUNC
598 */
599 HWTEST_F(WindowNodeContainerTest, IsDockSliceInExitSplitModeArea, Function | SmallTest | Level2)
600 {
601 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
602 defaultDisplay_->GetScreenId());
603 ASSERT_NE(nullptr, container->displayGroupController_);
604 ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
605 ASSERT_TRUE(!container->IsDockSliceInExitSplitModeArea(defaultDisplay_->GetId()));
606 }
607
608 /**
609 * @tc.name: ExitSplitMode
610 * @tc.desc: exit split mode
611 * @tc.type: FUNC
612 */
613 HWTEST_F(WindowNodeContainerTest, ExitSplitMode, Function | SmallTest | Level2)
614 {
615 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
616 defaultDisplay_->GetScreenId());
617 ASSERT_NE(nullptr, container->displayGroupController_);
618 ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
619 container->ExitSplitMode(defaultDisplay_->GetId());
620 }
621
622 /**
623 * @tc.name: MinimizeOldestAppWindow01
624 * @tc.desc: minimize main window
625 * @tc.type: FUNC
626 */
627 HWTEST_F(WindowNodeContainerTest, MinimizeOldestAppWindow01, Function | SmallTest | Level2)
628 {
629 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
630 defaultDisplay_->GetScreenId());
631 container->MinimizeOldestAppWindow();
632 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
633 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
634 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
635 sptr<WindowNode> parentNode = nullptr;
636 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
637 ASSERT_EQ(1, container->appWindowNode_->children_.size());
638 container->MinimizeOldestAppWindow();
639 ASSERT_EQ(1, MinimizeApp::needMinimizeAppNodes_.size());
640 MinimizeApp::needMinimizeAppNodes_.clear();
641 }
642
643 /**
644 * @tc.name: MinimizeOldestAppWindow02
645 * @tc.desc: minimize above main window
646 * @tc.type: FUNC
647 */
648 HWTEST_F(WindowNodeContainerTest, MinimizeOldestAppWindow02, Function | SmallTest | Level2)
649 {
650 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
651 defaultDisplay_->GetScreenId());
652 sptr<WindowProperty> property = CreateWindowProperty(111u, "test2",
653 WindowType::WINDOW_TYPE_STATUS_BAR, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
654 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
655 sptr<WindowNode> parentNode = nullptr;
656 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
657 ASSERT_EQ(1, container->aboveAppWindowNode_->children_.size());
658 size_t size = MinimizeApp::needMinimizeAppNodes_.size();
659 container->MinimizeOldestAppWindow();
660 ASSERT_EQ(size, MinimizeApp::needMinimizeAppNodes_.size());
661 MinimizeApp::needMinimizeAppNodes_.clear();
662 }
663
664 /**
665 * @tc.name: ToggleShownStateForAllAppWindows01
666 * @tc.desc: toggle shown state for status bar
667 * @tc.type: FUNC
668 */
669 HWTEST_F(WindowNodeContainerTest, ToggleShownStateForAllAppWindows01, Function | SmallTest | Level2)
670 {
671 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
672 defaultDisplay_->GetScreenId());
673 sptr<WindowProperty> property = CreateWindowProperty(111u, "test2",
674 WindowType::WINDOW_TYPE_STATUS_BAR, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
675 sptr<WindowNode> statusBar = new WindowNode(property, nullptr, nullptr);
676 sptr<WindowNode> parentNode = nullptr;
677 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(statusBar, parentNode));
678 ASSERT_EQ(1, container->aboveAppWindowNode_->children_.size());
__anon2a546e0e0302(uint32_t windowId, WindowMode mode) 679 auto restoreFunc = [](uint32_t windowId, WindowMode mode) {
680 return false;
681 };
682 ASSERT_EQ(WMError::WM_OK, container->ToggleShownStateForAllAppWindows(restoreFunc, true));
683 }
684
685 /**
686 * @tc.name: ToggleShownStateForAllAppWindows02
687 * @tc.desc: toggle shown state for launcher recent
688 * @tc.type: FUNC
689 */
690 HWTEST_F(WindowNodeContainerTest, ToggleShownStateForAllAppWindows02, Function | SmallTest | Level2)
691 {
692 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
693 defaultDisplay_->GetScreenId());
694 sptr<WindowProperty> property = CreateWindowProperty(111u, "test2",
695 WindowType::WINDOW_TYPE_LAUNCHER_RECENT, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
696 sptr<WindowNode> statusBar = new WindowNode(property, nullptr, nullptr);
697 sptr<WindowNode> parentNode = nullptr;
698 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(statusBar, parentNode));
699 ASSERT_EQ(1, container->aboveAppWindowNode_->children_.size());
__anon2a546e0e0402(uint32_t windowId, WindowMode mode) 700 auto restoreFunc = [](uint32_t windowId, WindowMode mode) {
701 return false;
702 };
703 ASSERT_EQ(WMError::WM_DO_NOTHING, container->ToggleShownStateForAllAppWindows(restoreFunc, true));
704 }
705
706 /**
707 * @tc.name: SetWindowMode01
708 * @tc.desc: set main window mode
709 * @tc.type: FUNC
710 */
711 HWTEST_F(WindowNodeContainerTest, SetWindowMode01, Function | SmallTest | Level2)
712 {
713 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
714 defaultDisplay_->GetScreenId());
715 sptr<WindowNode> node = nullptr;
716 WindowMode dstMode = WindowMode::WINDOW_MODE_FLOATING;
717 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->SetWindowMode(node, dstMode));
718 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
719 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
720 node = new WindowNode(property, nullptr, nullptr);
721 sptr<WindowNode> parentNode = nullptr;
722 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
723 ASSERT_EQ(1, container->appWindowNode_->children_.size());
724 dstMode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
725 container->isScreenLocked_ = false;
726 ASSERT_EQ(WMError::WM_OK, container->SetWindowMode(node, dstMode));
727 }
728
729 /**
730 * @tc.name: SetWindowMode02
731 * @tc.desc: set main window mode with show when locked
732 * @tc.type: FUNC
733 */
734 HWTEST_F(WindowNodeContainerTest, SetWindowMode02, Function | SmallTest | Level2)
735 {
736 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
737 defaultDisplay_->GetScreenId());
738 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
739 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
740 property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
741 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
742 sptr<WindowNode> parentNode = nullptr;
743 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
744 ASSERT_EQ(1, container->appWindowNode_->children_.size());
745 WindowMode dstMode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
746 container->isScreenLocked_ = true;
747 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, container->SetWindowMode(node, dstMode));
748 }
749
750 /**
751 * @tc.name: RemoveSingleUserWindowNodes
752 * @tc.desc: remove single user window node
753 * @tc.type: FUNC
754 */
755 HWTEST_F(WindowNodeContainerTest, RemoveSingleUserWindowNodes, Function | SmallTest | Level2)
756 {
757 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
758 defaultDisplay_->GetScreenId());
759 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
760 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
761 property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
762 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
763 sptr<WindowNode> parentNode = nullptr;
764 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
765 ASSERT_EQ(1, container->appWindowNode_->children_.size());
766 int accountId = 0;
767 container->RemoveSingleUserWindowNodes(accountId);
768 }
769
770 /**
771 * @tc.name: TakeWindowPairSnapshot
772 * @tc.desc: take window pair snapshot
773 * @tc.type: FUNC
774 */
775 HWTEST_F(WindowNodeContainerTest, TakeWindowPairSnapshot, Function | SmallTest | Level2)
776 {
777 sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
778 defaultDisplay_->GetScreenId());
779 sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
780 WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
781 property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
782 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
783 sptr<WindowNode> parentNode = nullptr;
784 ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
785 ASSERT_EQ(1, container->appWindowNode_->children_.size());
786 ASSERT_NE(nullptr, container->displayGroupController_);
787 ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
788 ASSERT_TRUE(!container->TakeWindowPairSnapshot(defaultDisplay_->GetId()));
789 container->ClearWindowPairSnapshot(defaultDisplay_->GetId());
790 }
791 /**
792 * @tc.name: Destroy
793 * @tc.desc: clear vector cache completely, swap with empty vector
794 * @tc.type: FUNC
795 */
796 HWTEST_F(WindowNodeContainerTest, Destroy, Function | SmallTest | Level2)
797 {
798 ASSERT_EQ(0, container_->Destroy().size());
799 }
800 }
801 }
802 }
803