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