• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     WLOGI("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 
CreateSFNode(const std::string & nodeName)89 RSSurfaceNode::SharedPtr CreateSFNode(const std::string& nodeName)
90 {
91     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
92     rsSurfaceNodeConfig.SurfaceNodeName = "name1";
93     RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT;
94 
95     return RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType);
96 }
97 
98 namespace {
99 /**
100  * @tc.name: AddWindowNodeOnWindowTree01
101  * @tc.desc: add system sub window to system window
102  * @tc.type: FUNC
103  */
104 HWTEST_F(WindowNodeContainerTest, AddWindowNodeOnWindowTree01, Function | SmallTest | Level2)
105 {
106     sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
107         WindowType::WINDOW_TYPE_APP_LAUNCHING, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
108     sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
109 
110     sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
111         WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
112     sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
113 
114     ASSERT_EQ(WMError::WM_OK, container_->AddWindowNodeOnWindowTree(subNode, parentNode));
115 }
116 
117 /**
118  * @tc.name: AddWindowNodeOnWindowTree02
119  * @tc.desc: add system sub window to system sub window
120  * @tc.type: FUNC
121  */
122 HWTEST_F(WindowNodeContainerTest, AddWindowNodeOnWindowTree02, Function | SmallTest | Level2)
123 {
124     sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
125         WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
126     sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
127 
128     sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
129         WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
130     sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
131 
132     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, container_->AddWindowNodeOnWindowTree(subNode, parentNode));
133 }
134 
135 /**
136  * @tc.name: AddWindowNodeOnWindowTree03
137  * @tc.desc: add system sub window without parent
138  * @tc.type: FUNC
139  */
140 HWTEST_F(WindowNodeContainerTest, AddWindowNodeOnWindowTree03, Function | SmallTest | Level2)
141 {
142     sptr<WindowProperty> subProperty = CreateWindowProperty(110u, "test1",
143         WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
144     sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
145 
146     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container_->AddWindowNodeOnWindowTree(subNode, nullptr));
147 }
148 /**
149  * @tc.name: MinimizeAppNodeExceptOptions
150  * @tc.desc: minimize app node
151  * @tc.type: FUNC
152  */
153 HWTEST_F(WindowNodeContainerTest, MinimizeAppNodeExceptOptions, Function | SmallTest | Level2)
154 {
155     std::vector<uint32_t> exceptionalIds;
156     std::vector<WindowMode> exceptionalModes;
157     ASSERT_EQ(WMError::WM_OK, container_->MinimizeAppNodeExceptOptions(MinimizeReason::OTHER_WINDOW,
158         exceptionalIds, exceptionalModes));
159 
160     sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1",
161         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
162     sptr<WindowNode> node1 = new WindowNode(property1, nullptr, nullptr);
163 
164     sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2",
165         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
166     sptr<WindowNode> node2 = new WindowNode(property2, nullptr, nullptr);
167 
168     ASSERT_EQ(WMError::WM_OK, container_->AddWindowNodeOnWindowTree(node1, nullptr));
169     ASSERT_EQ(WMError::WM_OK, container_->AddWindowNodeOnWindowTree(node2, nullptr));
170     ASSERT_EQ(WMError::WM_OK, container_->MinimizeAppNodeExceptOptions(MinimizeReason::OTHER_WINDOW,
171         exceptionalIds, exceptionalModes));
172 }
173 /**
174  * @tc.name: DropShowWhenLockedWindowIfNeeded
175  * @tc.desc: drop show when locken window
176  * @tc.type: FUNC
177  */
178 HWTEST_F(WindowNodeContainerTest, DropShowWhenLockedWindowIfNeeded, Function | SmallTest | Level2)
179 {
180     sptr<WindowProperty> property = CreateWindowProperty(110u, "test1",
181         WindowType::WINDOW_TYPE_KEYGUARD, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
182     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
183     ASSERT_NE(nullptr, node);
184     container_->DropShowWhenLockedWindowIfNeeded(node);
185 }
186 /**
187  * @tc.name: GetModeChangeHotZones
188  * @tc.desc: get mode change hot zones
189  * @tc.type: FUNC
190  */
191 HWTEST_F(WindowNodeContainerTest, GetModeChangeHotZones, Function | SmallTest | Level2)
192 {
193     ModeChangeHotZonesConfig hotZonesConfig { true, 10, 20, 30 };
194     ModeChangeHotZones hotZones;
195     container_->GetModeChangeHotZones(0, hotZones, hotZonesConfig);
196     ASSERT_EQ(hotZones.fullscreen_.height_, 10);
197     ASSERT_EQ(hotZones.primary_.width_, 20);
198     ASSERT_EQ(hotZones.secondary_.width_, 30);
199 }
200 /**
201  * @tc.name: UpdateCameraFloatWindowStatus
202  * @tc.desc: update camera float window status
203  * @tc.type: FUNC
204  */
205 HWTEST_F(WindowNodeContainerTest, UpdateCameraFloatWindowStatus, Function | SmallTest | Level2)
206 {
207     sptr<WindowProperty> property = CreateWindowProperty(110u, "test1",
208         WindowType::WINDOW_TYPE_FLOAT_CAMERA, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
209     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
210     ASSERT_NE(nullptr, node);
211     container_->UpdateCameraFloatWindowStatus(node, true);
212 }
213 /**
214  * @tc.name: UpdateWindowNode
215  * @tc.desc: preprocess node and update RSTree
216  * @tc.type: FUNC
217  */
218 HWTEST_F(WindowNodeContainerTest, UpdateWindowNode, Function | SmallTest | Level2)
219 {
220     sptr<WindowProperty> property = CreateWindowProperty(110u, "test1",
221         WindowType::SYSTEM_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
222     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
223     ASSERT_EQ(WMError::WM_OK, container_->UpdateWindowNode(node, WindowUpdateReason::UPDATE_ALL));
224     ASSERT_EQ(WMError::WM_OK, container_->UpdateWindowNode(node, WindowUpdateReason::UPDATE_MODE));
225 }
226 
227 /**
228  * @tc.name: ShowStartingWindow
229  * @tc.desc: show starting window
230  * @tc.type: FUNC
231  */
232 HWTEST_F(WindowNodeContainerTest, ShowStartingWindow, Function | SmallTest | Level2)
233 {
234     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
235         defaultDisplay_->GetScreenId());
236     sptr<WindowTransitionInfo> transitionInfo = new WindowTransitionInfo();
237     sptr<WindowNode> node = StartingWindow::CreateWindowNode(transitionInfo, 101); // 101 is windowId
238     node->SetWindowRect({0, 0, 100, 100});
239     node->currentVisibility_ = true;
240     ASSERT_EQ(WMError::WM_ERROR_INVALID_OPERATION, container->ShowStartingWindow(node));
241     ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(node, nullptr));
242     node->currentVisibility_ = false;
243     ASSERT_EQ(WMError::WM_OK, container->ShowStartingWindow(node));
244     WindowType invalidType = static_cast<WindowType>(0);
245     sptr<WindowProperty> invalidProperty = CreateWindowProperty(110u, "test1", invalidType,
246         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
247     sptr<WindowNode> invalidNode = new WindowNode(invalidProperty, nullptr, nullptr);
248     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->AddWindowNodeOnWindowTree(invalidNode, nullptr));
249     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->ShowStartingWindow(invalidNode));
250 }
251 
252 /**
253  * @tc.name: IsForbidDockSliceMove
254  * @tc.desc: forbid dock slice move
255  * @tc.type: FUNC
256  */
257 HWTEST_F(WindowNodeContainerTest, IsForbidDockSliceMove, Function | SmallTest | Level2)
258 {
259     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
260         defaultDisplay_->GetScreenId());
261     ASSERT_NE(nullptr, container->displayGroupController_);
262     ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
263     ASSERT_TRUE(!container->IsForbidDockSliceMove(defaultDisplay_->GetId()));
264 }
265 
266 /**
267  * @tc.name: GetWindowCountByType01
268  * @tc.desc: get window count
269  * @tc.type: FUNC
270  */
271 HWTEST_F(WindowNodeContainerTest, GetWindowCountByType01, Function | SmallTest | Level2)
272 {
273     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
274         defaultDisplay_->GetScreenId());
275     ASSERT_EQ(0, container->GetWindowCountByType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE));
276     sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1", WindowType::BELOW_APP_SYSTEM_WINDOW_BASE,
277         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
278     sptr<WindowNode> node1 = new WindowNode(property1, nullptr, nullptr);
279     sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
280         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
281     sptr<WindowNode> node2 = new WindowNode(property2, nullptr, nullptr);
282     sptr<WindowProperty> property3 = CreateWindowProperty(112u, "test3", WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE,
283         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
284     sptr<WindowNode> node3 = new WindowNode(property3, nullptr, nullptr);
285     container->belowAppWindowNode_->children_.insert(container->belowAppWindowNode_->children_.end(), node1);
286     container->appWindowNode_->children_.insert(container->appWindowNode_->children_.end(), node2);
287     container->aboveAppWindowNode_->children_.insert(container->aboveAppWindowNode_->children_.end(), node3);
288     ASSERT_EQ(0, container->GetWindowCountByType(WindowType::WINDOW_TYPE_KEYGUARD));
289     ASSERT_EQ(1, container->GetWindowCountByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW));
290     ASSERT_EQ(1, container->GetWindowCountByType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE));
291     ASSERT_EQ(1, container->GetWindowCountByType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE));
292     node1->startingWindowShown_ = true;
293     node2->startingWindowShown_ = true;
294     node3->startingWindowShown_ = true;
295     ASSERT_EQ(0, container->GetWindowCountByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW));
296     ASSERT_EQ(0, container->GetWindowCountByType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE));
297     ASSERT_EQ(0, container->GetWindowCountByType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE));
298 }
299 
300 /**
301  * @tc.name: IsTileRectSatisfiedWithSizeLimits
302  * @tc.desc: judge tile rect satisfied with size limits
303  * @tc.type: FUNC
304  */
305 HWTEST_F(WindowNodeContainerTest, IsTileRectSatisfiedWithSizeLimits, Function | SmallTest | Level2)
306 {
307     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
308         defaultDisplay_->GetScreenId());
309     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE,
310         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
311     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
312     node->SetDisplayId(defaultDisplay_->GetId());
313     ASSERT_EQ(defaultDisplay_->GetId(), node->GetDisplayId());
314     ASSERT_EQ(WMError::WM_OK, container->IsTileRectSatisfiedWithSizeLimits(node));
315     ASSERT_EQ(WMError::WM_OK, container->SwitchLayoutPolicy(WindowLayoutMode::TILE, node->GetDisplayId()));
316     ASSERT_EQ(WMError::WM_OK, container->IsTileRectSatisfiedWithSizeLimits(node));
317 }
318 
319 /**
320  * @tc.name: AddWindowNode01
321  * @tc.desc: add main window
322  * @tc.type: FUNC
323  */
324 HWTEST_F(WindowNodeContainerTest, AddWindowNode01, Function | SmallTest | Level2)
325 {
326     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
327         defaultDisplay_->GetScreenId());
328     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
329         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
330     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
331     node->GetWindowProperty()->SetPrivacyMode(true);
332     sptr<WindowNode> parentNode = nullptr;
333     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
334     node->startingWindowShown_ = true;
335     node->GetWindowProperty()->SetPrivacyMode(false);
336     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
337 }
338 
339 /**
340  * @tc.name: AddWindowNode02
341  * @tc.desc: add sub window
342  * @tc.type: FUNC
343  */
344 HWTEST_F(WindowNodeContainerTest, AddWindowNode02, Function | SmallTest | Level2)
345 {
346     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
347         defaultDisplay_->GetScreenId());
348     sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
349         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
350     sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
351 
352     sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
353         WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
354     sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
355 
356     sptr<WindowNode> rootNode = nullptr;
357     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(parentNode, rootNode));
358     ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(subNode, parentNode));
359     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(subNode, parentNode));
360 }
361 
362 /**
363  * @tc.name: AddWindowNode03
364  * @tc.desc: add system window
365  * @tc.type: FUNC
366  */
367 HWTEST_F(WindowNodeContainerTest, AddWindowNode03, Function | SmallTest | Level2)
368 {
369     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
370         defaultDisplay_->GetScreenId());
371     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE,
372         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
373     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
374     sptr<WindowNode> parentNode = nullptr;
375     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
376 }
377 
378 /**
379  * @tc.name: RemoveWindowNodeFromWindowTree
380  * @tc.desc: remove sub window from window tree
381  * @tc.type: FUNC
382  */
383 HWTEST_F(WindowNodeContainerTest, RemoveWindowNodeFromWindowTree, Function | SmallTest | Level2)
384 {
385     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
386         defaultDisplay_->GetScreenId());
387     sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
388         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
389     sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
390 
391     sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
392         WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
393     sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
394 
395     sptr<WindowNode> rootNode = nullptr;
396     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(parentNode, rootNode));
397     ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(subNode, parentNode));
398     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(subNode, parentNode));
399     ASSERT_EQ(1, parentNode->children_.size());
400     container->RemoveWindowNodeFromWindowTree(subNode);
401     ASSERT_EQ(0, parentNode->children_.size());
402 }
403 
404 /**
405  * @tc.name: RemoveWindowNode01
406  * @tc.desc: remove main window
407  * @tc.type: FUNC
408  */
409 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode01, Function | SmallTest | Level2)
410 {
411     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
412         defaultDisplay_->GetScreenId());
413     sptr<WindowNode> node = nullptr;
414     ASSERT_EQ(WMError::WM_ERROR_DESTROYED_OBJECT, container->RemoveWindowNode(node));
415     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
416         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
417     node = new WindowNode(property, nullptr, nullptr);
418     sptr<WindowNode> parentNode = nullptr;
419     node->GetWindowProperty()->SetPrivacyMode(true);
420     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
421     node->GetWindowProperty()->SetPrivacyMode(false);
422     ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(node));
423 }
424 
425 /**
426  * @tc.name: RemoveWindowNode02
427  * @tc.desc: remove sub window
428  * @tc.type: FUNC
429  */
430 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode02, Function | SmallTest | Level2)
431 {
432     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
433         defaultDisplay_->GetScreenId());
434     sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
435         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
436     sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
437 
438     sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
439         WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
440     sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
441 
442     sptr<WindowNode> rootNode = nullptr;
443     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(parentNode, rootNode));
444     ASSERT_EQ(WMError::WM_OK, container->AddWindowNodeOnWindowTree(subNode, parentNode));
445     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(subNode, parentNode));
446     ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(subNode));
447 }
448 
449 /**
450  * @tc.name: RemoveWindowNode03
451  * @tc.desc: remove keyguard window
452  * @tc.type: FUNC
453  */
454 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode03, Function | SmallTest | Level2)
455 {
456     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
457         defaultDisplay_->GetScreenId());
458     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
459         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
460     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
461     sptr<WindowNode> parentNode = nullptr;
462     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
463     ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(node));
464 }
465 
466 /**
467  * @tc.name: RemoveWindowNode04
468  * @tc.desc: remove boot animation window
469  * @tc.type: FUNC
470  */
471 HWTEST_F(WindowNodeContainerTest, RemoveWindowNode04, Function | SmallTest | Level2)
472 {
473     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
474         defaultDisplay_->GetScreenId());
475     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
476         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
477     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
478     sptr<WindowNode> parentNode = nullptr;
479     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
480     ASSERT_EQ(WMError::WM_OK, container->RemoveWindowNode(node));
481 }
482 
483 /**
484  * @tc.name: HandleRemoveWindow01
485  * @tc.desc: remove status bar
486  * @tc.type: FUNC
487  */
488 HWTEST_F(WindowNodeContainerTest, HandleRemoveWindow01, Function | SmallTest | Level2)
489 {
490     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
491         defaultDisplay_->GetScreenId());
492     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_STATUS_BAR,
493         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
494     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
495     sptr<WindowNode> parentNode = nullptr;
496     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
497     ASSERT_EQ(WMError::WM_OK, container->HandleRemoveWindow(node));
498 }
499 
500 /**
501  * @tc.name: HandleRemoveWindow02
502  * @tc.desc: remove navigation bar
503  * @tc.type: FUNC
504  */
505 HWTEST_F(WindowNodeContainerTest, HandleRemoveWindow02, Function | SmallTest | Level2)
506 {
507     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
508         defaultDisplay_->GetScreenId());
509     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_NAVIGATION_BAR,
510         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
511     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
512     sptr<WindowNode> parentNode = nullptr;
513     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
514     ASSERT_EQ(WMError::WM_OK, container->HandleRemoveWindow(node));
515 }
516 
517 /**
518  * @tc.name: FindDividerNode
519  * @tc.desc: find divider node
520  * @tc.type: FUNC
521  */
522 HWTEST_F(WindowNodeContainerTest, FindDividerNode, Function | SmallTest | Level2)
523 {
524     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
525         defaultDisplay_->GetScreenId());
526     ASSERT_EQ(nullptr, container->FindDividerNode());
527     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
528         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
529     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
530     sptr<WindowNode> parentNode = nullptr;
531     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
532     ASSERT_EQ(1, container->appWindowNode_->children_.size());
533     ASSERT_EQ(nullptr, container->FindDividerNode());
534     sptr<WindowProperty> dividerProperty = CreateWindowProperty(112u, "test2", WindowType::WINDOW_TYPE_DOCK_SLICE,
535         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
536     sptr<WindowNode> dividerNode = new WindowNode(dividerProperty, nullptr, nullptr);
537     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(dividerNode, parentNode));
538     ASSERT_EQ(2, container->appWindowNode_->children_.size());
539     ASSERT_EQ(dividerNode, container->FindDividerNode());
540 }
541 
542 /**
543  * @tc.name: RaiseZOrderForAppWindow01
544  * @tc.desc: raise main window z order
545  * @tc.type: FUNC
546  */
547 HWTEST_F(WindowNodeContainerTest, RaiseZOrderForAppWindow01, Function | SmallTest | Level2)
548 {
549     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
550         defaultDisplay_->GetScreenId());
551     sptr<WindowProperty> property1 = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
552         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
553     sptr<WindowNode> node1 = nullptr;
554     sptr<WindowNode> parentNode = nullptr;
555     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->RaiseZOrderForAppWindow(node1, parentNode));
556     node1 = new WindowNode(property1, nullptr, nullptr);
557     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node1, parentNode));
558     sptr<WindowProperty> property2 = CreateWindowProperty(112u, "test2", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
559         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
560     sptr<WindowNode> node2 = new WindowNode(property2, nullptr, nullptr);
561     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node2, parentNode));
562     ASSERT_EQ(WMError::WM_OK, container->RaiseZOrderForAppWindow(node1, parentNode));
563 }
564 
565 /**
566  * @tc.name: RaiseZOrderForAppWindow02
567  * @tc.desc: raise sub window z order
568  * @tc.type: FUNC
569  */
570 HWTEST_F(WindowNodeContainerTest, RaiseZOrderForAppWindow02, Function | SmallTest | Level2)
571 {
572     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
573         defaultDisplay_->GetScreenId());
574     sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
575         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
576     sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
577 
578     sptr<WindowProperty> subProperty = CreateWindowProperty(111u, "test2",
579         WindowType::WINDOW_TYPE_APP_SUB_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
580     sptr<WindowNode> subNode = new WindowNode(subProperty, nullptr, nullptr);
581     sptr<WindowNode> rootNode = nullptr;
582     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->RaiseZOrderForAppWindow(subNode, rootNode));
583     ASSERT_EQ(WMError::WM_OK, container->RaiseZOrderForAppWindow(subNode, parentNode));
584 }
585 
586 /**
587  * @tc.name: RaiseZOrderForAppWindow03
588  * @tc.desc: raise dialog z order
589  * @tc.type: FUNC
590  */
591 HWTEST_F(WindowNodeContainerTest, RaiseZOrderForAppWindow03, Function | SmallTest | Level2)
592 {
593     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
594         defaultDisplay_->GetScreenId());
595     sptr<WindowProperty> parentProperty = CreateWindowProperty(110u, "test1",
596         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
597     sptr<WindowNode> parentNode = new WindowNode(parentProperty, nullptr, nullptr);
598 
599     sptr<WindowProperty> dialogProperty = CreateWindowProperty(111u, "test2",
600         WindowType::WINDOW_TYPE_DIALOG, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
601     sptr<WindowNode> dialog = new WindowNode(dialogProperty, nullptr, nullptr);
602     sptr<WindowNode> rootNode = nullptr;
603     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->RaiseZOrderForAppWindow(dialog, rootNode));
604     ASSERT_EQ(WMError::WM_OK, container->RaiseZOrderForAppWindow(dialog, parentNode));
605 }
606 
607 /**
608  * @tc.name: IsDockSliceInExitSplitModeArea
609  * @tc.desc: if dock slice in exit split mode area
610  * @tc.type: FUNC
611  */
612 HWTEST_F(WindowNodeContainerTest, IsDockSliceInExitSplitModeArea, Function | SmallTest | Level2)
613 {
614     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
615         defaultDisplay_->GetScreenId());
616     ASSERT_NE(nullptr, container->displayGroupController_);
617     ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
618     ASSERT_TRUE(!container->IsDockSliceInExitSplitModeArea(defaultDisplay_->GetId()));
619 }
620 
621 /**
622  * @tc.name: ExitSplitMode
623  * @tc.desc: exit split mode
624  * @tc.type: FUNC
625  */
626 HWTEST_F(WindowNodeContainerTest, ExitSplitMode, Function | SmallTest | Level2)
627 {
628     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
629         defaultDisplay_->GetScreenId());
630     ASSERT_NE(nullptr, container->displayGroupController_);
631     ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
632     container->ExitSplitMode(defaultDisplay_->GetId());
633 }
634 
635 /**
636  * @tc.name: MinimizeOldestAppWindow01
637  * @tc.desc: minimize main window
638  * @tc.type: FUNC
639  */
640 HWTEST_F(WindowNodeContainerTest, MinimizeOldestAppWindow01, Function | SmallTest | Level2)
641 {
642     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
643         defaultDisplay_->GetScreenId());
644     container->MinimizeOldestAppWindow();
645     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
646         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
647     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
648     sptr<WindowNode> parentNode = nullptr;
649     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
650     ASSERT_EQ(1, container->appWindowNode_->children_.size());
651     container->MinimizeOldestAppWindow();
652     ASSERT_EQ(1, MinimizeApp::needMinimizeAppNodes_.size());
653     MinimizeApp::needMinimizeAppNodes_.clear();
654 }
655 
656 /**
657  * @tc.name: MinimizeOldestAppWindow02
658  * @tc.desc: minimize above main window
659  * @tc.type: FUNC
660  */
661 HWTEST_F(WindowNodeContainerTest, MinimizeOldestAppWindow02, Function | SmallTest | Level2)
662 {
663     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
664         defaultDisplay_->GetScreenId());
665     sptr<WindowProperty> property = CreateWindowProperty(111u, "test2",
666         WindowType::WINDOW_TYPE_STATUS_BAR, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
667     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
668     sptr<WindowNode> parentNode = nullptr;
669     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
670     ASSERT_EQ(1, container->aboveAppWindowNode_->children_.size());
671     size_t size = MinimizeApp::needMinimizeAppNodes_.size();
672     container->MinimizeOldestAppWindow();
673     ASSERT_EQ(size, MinimizeApp::needMinimizeAppNodes_.size());
674     MinimizeApp::needMinimizeAppNodes_.clear();
675 }
676 
677 /**
678  * @tc.name: ToggleShownStateForAllAppWindows01
679  * @tc.desc: toggle shown state for status bar
680  * @tc.type: FUNC
681  */
682 HWTEST_F(WindowNodeContainerTest, ToggleShownStateForAllAppWindows01, Function | SmallTest | Level2)
683 {
684     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
685         defaultDisplay_->GetScreenId());
686     sptr<WindowProperty> property = CreateWindowProperty(111u, "test2",
687         WindowType::WINDOW_TYPE_STATUS_BAR, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
688     sptr<WindowNode> statusBar = new WindowNode(property, nullptr, nullptr);
689     sptr<WindowNode> parentNode = nullptr;
690     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(statusBar, parentNode));
691     ASSERT_EQ(1, container->aboveAppWindowNode_->children_.size());
__anona0a880ee0302(uint32_t windowId, WindowMode mode) 692     auto restoreFunc = [](uint32_t windowId, WindowMode mode) {
693         return false;
694     };
695     ASSERT_EQ(WMError::WM_OK, container->ToggleShownStateForAllAppWindows(restoreFunc, true));
696 }
697 
698 /**
699  * @tc.name: ToggleShownStateForAllAppWindows02
700  * @tc.desc: toggle shown state for launcher recent
701  * @tc.type: FUNC
702  */
703 HWTEST_F(WindowNodeContainerTest, ToggleShownStateForAllAppWindows02, Function | SmallTest | Level2)
704 {
705     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
706         defaultDisplay_->GetScreenId());
707     sptr<WindowProperty> property = CreateWindowProperty(111u, "test2",
708         WindowType::WINDOW_TYPE_LAUNCHER_RECENT, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
709     sptr<WindowNode> statusBar = new WindowNode(property, nullptr, nullptr);
710     sptr<WindowNode> parentNode = nullptr;
711     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(statusBar, parentNode));
712     ASSERT_EQ(1, container->aboveAppWindowNode_->children_.size());
__anona0a880ee0402(uint32_t windowId, WindowMode mode) 713     auto restoreFunc = [](uint32_t windowId, WindowMode mode) {
714         return false;
715     };
716     ASSERT_EQ(WMError::WM_DO_NOTHING, container->ToggleShownStateForAllAppWindows(restoreFunc, true));
717 }
718 
719 /**
720  * @tc.name: SetWindowMode01
721  * @tc.desc: set main window mode
722  * @tc.type: FUNC
723  */
724 HWTEST_F(WindowNodeContainerTest, SetWindowMode01, Function | SmallTest | Level2)
725 {
726     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
727         defaultDisplay_->GetScreenId());
728     sptr<WindowNode> node = nullptr;
729     WindowMode dstMode = WindowMode::WINDOW_MODE_FLOATING;
730     ASSERT_EQ(WMError::WM_ERROR_NULLPTR, container->SetWindowMode(node, dstMode));
731     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
732         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
733     node = new WindowNode(property, nullptr, nullptr);
734     sptr<WindowNode> parentNode = nullptr;
735     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
736     ASSERT_EQ(1, container->appWindowNode_->children_.size());
737     dstMode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
738     container->isScreenLocked_ = false;
739     ASSERT_EQ(WMError::WM_OK, container->SetWindowMode(node, dstMode));
740 }
741 
742 /**
743  * @tc.name: SetWindowMode02
744  * @tc.desc: set main window mode with show when locked
745  * @tc.type: FUNC
746  */
747 HWTEST_F(WindowNodeContainerTest, SetWindowMode02, Function | SmallTest | Level2)
748 {
749     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
750         defaultDisplay_->GetScreenId());
751     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
752         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
753     property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
754     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
755     sptr<WindowNode> parentNode = nullptr;
756     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
757     ASSERT_EQ(1, container->appWindowNode_->children_.size());
758     WindowMode dstMode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
759     container->isScreenLocked_ = true;
760     ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, container->SetWindowMode(node, dstMode));
761 }
762 
763 /**
764  * @tc.name: RemoveSingleUserWindowNodes
765  * @tc.desc: remove single user window node
766  * @tc.type: FUNC
767  */
768 HWTEST_F(WindowNodeContainerTest, RemoveSingleUserWindowNodes, Function | SmallTest | Level2)
769 {
770     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
771         defaultDisplay_->GetScreenId());
772     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
773         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
774     property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
775     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
776     sptr<WindowNode> parentNode = nullptr;
777     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
778     ASSERT_EQ(1, container->appWindowNode_->children_.size());
779     int accountId = 0;
780     container->RemoveSingleUserWindowNodes(accountId);
781 }
782 
783 /**
784  * @tc.name: TakeWindowPairSnapshot
785  * @tc.desc: take window pair snapshot
786  * @tc.type: FUNC
787  */
788 HWTEST_F(WindowNodeContainerTest, TakeWindowPairSnapshot, Function | SmallTest | Level2)
789 {
790     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
791         defaultDisplay_->GetScreenId());
792     sptr<WindowProperty> property = CreateWindowProperty(111u, "test1", WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
793         WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
794     property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED));
795     sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
796     sptr<WindowNode> parentNode = nullptr;
797     ASSERT_EQ(WMError::WM_OK, container->AddWindowNode(node, parentNode));
798     ASSERT_EQ(1, container->appWindowNode_->children_.size());
799     ASSERT_NE(nullptr, container->displayGroupController_);
800     ASSERT_NE(nullptr, container->displayGroupController_->GetWindowPairByDisplayId(defaultDisplay_->GetId()));
801     ASSERT_TRUE(!container->TakeWindowPairSnapshot(defaultDisplay_->GetId()));
802     container->ClearWindowPairSnapshot(defaultDisplay_->GetId());
803 }
804 /**
805  * @tc.name: Destroy
806  * @tc.desc: clear vector cache completely, swap with empty vector
807  * @tc.type: FUNC
808  */
809 HWTEST_F(WindowNodeContainerTest, Destroy, Function | SmallTest | Level2)
810 {
811     ASSERT_EQ(0, container_->Destroy().size());
812 }
813 /**
814  * @tc.name: UpdatePrivateStateAndNotify
815  * @tc.desc: update private window count
816  * @tc.type: FUNC
817  */
818 HWTEST_F(WindowNodeContainerTest, UpdatePrivateStateAndNotify, Function | SmallTest | Level2)
819 {
820     container_->belowAppWindowNode_->children_.clear();
821     container_->appWindowNode_->children_.clear();
822     container_->aboveAppWindowNode_->children_.clear();
823     container_->privateWindowCount_ = 0;
824     // private window count : from 0 to 1
825     sptr<WindowNode> node = new WindowNode();
826     node->GetWindowProperty()->SetPrivacyMode(true);
827     container_->appWindowNode_->children_.emplace_back(node);
828     container_->UpdatePrivateStateAndNotify();
829     ASSERT_EQ(1, container_->privateWindowCount_);
830     // private window count : from 1 to 0
831     container_->appWindowNode_->children_.clear();
832     container_->UpdatePrivateStateAndNotify();
833     ASSERT_EQ(0, container_->privateWindowCount_);
834 }
835 /**
836  * @tc.name: MinimizeOldestMainFloatingWindow
837  * @tc.desc: check function MinimizeOldestMainFloatingWindow
838  * @tc.type: FUNC
839  */
840 HWTEST_F(WindowNodeContainerTest, MinimizeOldestMainFloatingWindow, Function | SmallTest | Level2)
841 {
842     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
843         defaultDisplay_->GetScreenId());
844 
845     sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1",
846         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
847     sptr<WindowNode> window1 = new WindowNode(property1, nullptr, nullptr);
848 
849     sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2",
850         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
851     sptr<WindowNode> window2 = new WindowNode(property2, nullptr, nullptr);
852 
853     container->appWindowNode_->children_.push_back(window1);
854     container->appWindowNode_->children_.push_back(window2);
855 
856     window1->parent_ = container->appWindowNode_;
857     window2->parent_ = container->appWindowNode_;
858 
859     auto oldInfo = MinimizeApp::needMinimizeAppNodes_[MinimizeReason::MAX_APP_COUNT];
860     MinimizeApp::ClearNodesWithReason(MinimizeReason::MAX_APP_COUNT);
861 
862     container->maxMainFloatingWindowNumber_ = -1;
863     container->MinimizeOldestMainFloatingWindow(110u);
864     auto needMinimizeNum = MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::MAX_APP_COUNT);
865     ASSERT_EQ(needMinimizeNum.size(), 0);
866     MinimizeApp::ClearNodesWithReason(MinimizeReason::MAX_APP_COUNT);
867 
868     container->maxMainFloatingWindowNumber_ = 3;
869     container->MinimizeOldestMainFloatingWindow(110u);
870     needMinimizeNum = MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::MAX_APP_COUNT);
871     ASSERT_EQ(needMinimizeNum.size(), 0);
872     MinimizeApp::ClearNodesWithReason(MinimizeReason::MAX_APP_COUNT);
873 
874     container->maxMainFloatingWindowNumber_ = 1;
875     container->MinimizeOldestMainFloatingWindow(110u);
876     needMinimizeNum = MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::MAX_APP_COUNT);
877     ASSERT_EQ(needMinimizeNum.size(), 1);
878     MinimizeApp::ClearNodesWithReason(MinimizeReason::MAX_APP_COUNT);
879 
880     sptr<WindowProperty> property3 = CreateWindowProperty(112u, "test3",
881         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
882     sptr<WindowNode> window3 = new WindowNode(property3, nullptr, nullptr);
883     container->appWindowNode_->children_.push_back(window3);
884     window3->parent_ = container->appWindowNode_;
885 
886     container->maxMainFloatingWindowNumber_ = 1;
887     container->MinimizeOldestMainFloatingWindow(110u);
888     needMinimizeNum = MinimizeApp::GetNeedMinimizeAppNodesWithReason(MinimizeReason::MAX_APP_COUNT);
889     ASSERT_EQ(needMinimizeNum.size(), 1);
890     MinimizeApp::ClearNodesWithReason(MinimizeReason::MAX_APP_COUNT);
891 
892     auto headItor = MinimizeApp::needMinimizeAppNodes_[MinimizeReason::MAX_APP_COUNT].end();
893     MinimizeApp::needMinimizeAppNodes_[MinimizeReason::MAX_APP_COUNT].insert(headItor, oldInfo.begin(), oldInfo.end());
894 }
895 
896 /**
897  * @tc.name: GetMainFloatingWindowCount
898  * @tc.desc: check GetMainFloatingWindowCount
899  * @tc.type: FUNC
900  */
901 HWTEST_F(WindowNodeContainerTest, GetMainFloatingWindowCount, Function | SmallTest | Level2)
902 {
903     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
904         defaultDisplay_->GetScreenId());
905 
906     sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1",
907         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
908     sptr<WindowNode> window1 = new WindowNode(property1, nullptr, nullptr);
909 
910     sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2",
911         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
912     sptr<WindowNode> window2 = new WindowNode(property2, nullptr, nullptr);
913     window2->startingWindowShown_ = true;
914 
915     sptr<WindowProperty> property3 = CreateWindowProperty(112u, "test3",
916         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
917     sptr<WindowNode> window3 = new WindowNode(property3, nullptr, nullptr);
918 
919     sptr<WindowProperty> property4 = CreateWindowProperty(112u, "test3",
920         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
921     sptr<WindowNode> window4 = new WindowNode(property4, nullptr, nullptr);
922 
923     container->appWindowNode_->children_.push_back(window1);
924     container->aboveAppWindowNode_->children_.push_back(window2);
925     container->appWindowNode_->children_.push_back(window3);
926     container->aboveAppWindowNode_->children_.push_back(window4);
927 
928     auto result = container->GetMainFloatingWindowCount();
929     ASSERT_EQ(result, 2);
930 }
931 
932 /**
933  * @tc.name: ResetWindowZOrderPriorityWhenSetMode
934  * @tc.desc: check function ResetWindowZOrderPriorityWhenSetMode
935  * @tc.type: FUNC
936  */
937 HWTEST_F(WindowNodeContainerTest, ResetWindowZOrderPriorityWhenSetMode, Function | SmallTest | Level2)
938 {
939     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
940         defaultDisplay_->GetScreenId());
941 
942     sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1",
943         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
944     sptr<WindowNode> window1 = new WindowNode(property1, nullptr, nullptr);
945     window1->parent_ = container->appWindowNode_;
946 
947     sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2",
948         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
949     sptr<WindowNode> window2 = new WindowNode(property2, nullptr, nullptr);
950     window2->parent_ = container->appWindowNode_;
951 
952     container->appWindowNode_->children_.push_back(window1);
953     container->appWindowNode_->children_.push_back(window2);
954 
955     container->isFloatWindowAboveFullWindow_ = false;
956     container->ResetWindowZOrderPriorityWhenSetMode(window1, WindowMode::WINDOW_MODE_FLOATING,
957         WindowMode::WINDOW_MODE_FULLSCREEN);
958     ASSERT_EQ(window1->priority_, 0);
959 
960     container->isFloatWindowAboveFullWindow_ = true;
961     std::map<std::pair<WindowMode, WindowMode>, uint32_t> pairMode = {
962         {{WindowMode::WINDOW_MODE_FLOATING, WindowMode::WINDOW_MODE_FULLSCREEN}, 2},
963         {{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_FLOATING}, 2},
964         {{WindowMode::WINDOW_MODE_UNDEFINED, WindowMode::WINDOW_MODE_FULLSCREEN}, 0},
965         {{WindowMode::WINDOW_MODE_FULLSCREEN, WindowMode::WINDOW_MODE_SPLIT_PRIMARY}, 2},
966         {{WindowMode::WINDOW_MODE_SPLIT_PRIMARY, WindowMode::WINDOW_MODE_SPLIT_SECONDARY}, 2},
967         {{WindowMode::WINDOW_MODE_SPLIT_SECONDARY, WindowMode::WINDOW_MODE_SPLIT_PRIMARY}, 2},
968     };
969     container->focusedWindow_ = 111u;
970     for (auto itor = pairMode.begin(); itor != pairMode.end(); itor++) {
971         auto pair = itor->first;
972         auto priority = itor->second;
973         container->ResetWindowZOrderPriorityWhenSetMode(window1, pair.first, pair.second);
974         ASSERT_EQ(window1->priority_, priority);
975         window1->priority_ = 0;
976     }
977 
978     window1->zOrder_ = 0;
979     window1->surfaceNode_ = CreateSFNode("sfNode1");
980     window2->surfaceNode_ = CreateSFNode("sfNode2");
981     container->focusedWindow_ = window1->GetWindowId();
982     container->ResetWindowZOrderPriorityWhenSetMode(window1, WindowMode::WINDOW_MODE_FLOATING,
983         WindowMode::WINDOW_MODE_FULLSCREEN);
984     ASSERT_EQ(window1->zOrder_, 2);
985 }
986 
987 /**
988  * @tc.name: ResetMainFloatingWindowPriorityIfNeeded
989  * @tc.desc: check function ResetMainFloatingWindowPriorityIfNeeded
990  * @tc.type: FUNC
991  */
992 HWTEST_F(WindowNodeContainerTest, ResetMainFloatingWindowPriorityIfNeeded, Function | SmallTest | Level2)
993 {
994     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
995         defaultDisplay_->GetScreenId());
996 
997     sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1",
998         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
999     sptr<WindowNode> window1 = new WindowNode(property1, nullptr, nullptr);
1000     window1->parent_ = container->appWindowNode_;
1001 
1002     sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2",
1003         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
1004     sptr<WindowNode> window2 = new WindowNode(property2, nullptr, nullptr);
1005     window2->parent_ = container->appWindowNode_;
1006 
1007     container->appWindowNode_->children_.push_back(window1);
1008     container->appWindowNode_->children_.push_back(window2);
1009 
1010     container->isFloatWindowAboveFullWindow_ = false;
1011     auto zorderPolicy = container->zorderPolicy_;
1012     const auto baseZOrderPolicy = zorderPolicy->GetWindowPriority(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1013     container->ResetMainFloatingWindowPriorityIfNeeded(window1);
1014     ASSERT_EQ(window1->priority_, 0);
1015 
1016     container->isFloatWindowAboveFullWindow_ = true;
1017     container->ResetMainFloatingWindowPriorityIfNeeded(window1);
1018     ASSERT_EQ(window1->priority_, baseZOrderPolicy + 1);
1019 
1020     container->ResetMainFloatingWindowPriorityIfNeeded(window2);
1021     ASSERT_EQ(window2->priority_, 0);
1022 
1023     auto displayGroupControl = container->displayGroupController_;
1024     auto defaultDisplayId = defaultDisplay_->GetId();
1025     sptr<WindowPair> windowPair = displayGroupControl->GetWindowPairByDisplayId(defaultDisplayId);
1026     windowPair->status_ = WindowPairStatus::SINGLE_PRIMARY;
1027     window1->SetDisplayId(defaultDisplayId);
1028     container->ResetMainFloatingWindowPriorityIfNeeded(window1);
1029     ASSERT_EQ(window1->priority_, baseZOrderPolicy - 1);
1030 }
1031 
1032 /**
1033  * @tc.name: Destroy
1034  * @tc.desc: check function ResetAllMainFloatingWindowZOrder
1035  * @tc.type: FUNC
1036  */
1037 HWTEST_F(WindowNodeContainerTest, ResetAllMainFloatingWindowZOrder, Function | SmallTest | Level2)
1038 {
1039     sptr<WindowNodeContainer> container = new WindowNodeContainer(defaultDisplay_->GetDisplayInfo(),
1040         defaultDisplay_->GetScreenId());
1041 
1042     sptr<WindowProperty> property1 = CreateWindowProperty(110u, "test1",
1043         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FLOATING, windowRect_);
1044     sptr<WindowNode> window1 = new WindowNode(property1, nullptr, nullptr);
1045     window1->parent_ = container->appWindowNode_;
1046 
1047     sptr<WindowProperty> property2 = CreateWindowProperty(111u, "test2",
1048         WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, WindowMode::WINDOW_MODE_FULLSCREEN, windowRect_);
1049     sptr<WindowNode> window2 = new WindowNode(property2, nullptr, nullptr);
1050     window2->parent_ = container->appWindowNode_;
1051 
1052     container->appWindowNode_->children_.push_back(window1);
1053     container->appWindowNode_->children_.push_back(window2);
1054 
1055     container->isFloatWindowAboveFullWindow_ = false;
1056     container->ResetAllMainFloatingWindowZOrder(container->appWindowNode_);
1057     ASSERT_EQ(window1->priority_, 0);
1058 
1059     container->isFloatWindowAboveFullWindow_ = true;
1060     container->ResetAllMainFloatingWindowZOrder(container->appWindowNode_);
1061     ASSERT_EQ(window1->priority_, 2);
1062 }
1063 }
1064 }
1065 }