• 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 #include <transaction/rs_transaction.h>
18 #include "iremote_object_mocker.h"
19 #include "display_group_controller.h"
20 #include "display_manager.h"
21 #include "window_helper.h"
22 #include "window_node_container.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace {
30     const Rect DEFAULT_RECT = {0, 0, 200, 200};
31 }
32 class DisplayGroupControllerTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38     sptr<WindowProperty> CreateWindowProperty(uint32_t windowId,
39         WindowType type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
40     static void SetDisplayGroupInfo(DisplayId displayId, Rect displayRect);
41 private:
42     static sptr<WindowNodeContainer> container_;
43     static DisplayGroupInfo& displayGroupInfo_;
44     static sptr<DisplayGroupController> displayGroupController_;
45 };
46 
47 sptr<WindowNodeContainer> DisplayGroupControllerTest::container_ = nullptr;
48 DisplayGroupInfo& DisplayGroupControllerTest::displayGroupInfo_ = DisplayGroupInfo::GetInstance();
49 sptr<DisplayGroupController> DisplayGroupControllerTest::displayGroupController_ = nullptr;
50 
SetUpTestCase()51 void DisplayGroupControllerTest::SetUpTestCase()
52 {
53     auto display = DisplayManager::GetInstance().GetDefaultDisplay();
54     ASSERT_TRUE((display != nullptr));
55     container_ = new WindowNodeContainer(display->GetDisplayInfo(), display->GetScreenId());
56     displayGroupController_ = container_->displayGroupController_;
57 
58     DisplayGroupInfo::GetInstance().Init(0, display->GetDisplayInfo());
59 }
60 
TearDownTestCase()61 void DisplayGroupControllerTest::TearDownTestCase()
62 {
63     container_ = nullptr;
64     displayGroupController_ = nullptr;
65 }
66 
SetUp()67 void DisplayGroupControllerTest::SetUp()
68 {
69     DisplayId defaultId = 0;
70     displayGroupController_->displayGroupWindowTree_.clear();
71     displayGroupController_->InitNewDisplay(defaultId);
72     SetDisplayGroupInfo(0, DEFAULT_RECT);
73 }
74 
TearDown()75 void DisplayGroupControllerTest::TearDown()
76 {
77     displayGroupController_->defaultDisplayId_ = 0;
78     container_->GetLayoutPolicy()->isMultiDisplay_ = false;
79     displayGroupController_->ClearMapOfDestroyedDisplay(0);
80     displayGroupController_->ClearMapOfDestroyedDisplay(1);
81 }
82 
CreateWindowProperty(uint32_t windowId,WindowType type)83 sptr<WindowProperty> DisplayGroupControllerTest::CreateWindowProperty(uint32_t windowId, WindowType type)
84 {
85     sptr<WindowProperty> property = new WindowProperty();
86     property->SetWindowId(windowId);
87     property->SetWindowType(type);
88     return property;
89 }
90 
SetDisplayGroupInfo(DisplayId displayId,Rect displayRect)91 void DisplayGroupControllerTest::SetDisplayGroupInfo(DisplayId displayId, Rect displayRect)
92 {
93     sptr<DisplayInfo> displayInfo = new DisplayInfo();
94     displayInfo->SetDisplayId(displayId);
95     displayInfo->SetOffsetX(displayRect.posX_);
96     displayInfo->SetOffsetY(displayRect.posY_);
97     displayInfo->SetWidth(displayRect.width_);
98     displayInfo->SetHeight(displayRect.height_);
99     displayGroupInfo_.displayInfosMap_[displayId] = displayInfo;
100     displayGroupInfo_.leftDisplayId_ = 0;
101     displayGroupInfo_.rightDisplayId_ = 1;
102 }
103 
104 namespace {
105 /**
106  * @tc.name: GetWindowNodesByDisplayIdAndRootType01
107  * @tc.desc: Use displayId which not exists
108  * @tc.type: FUNC
109  */
110 HWTEST_F(DisplayGroupControllerTest, GetWindowNodesByDisplayIdAndRootType01, Function | SmallTest | Level2)
111 {
112     DisplayId testId = 100; // 100 test display id
113     std::vector<sptr<WindowNode>>* rootNodeVectorPtr =
114         displayGroupController_->GetWindowNodesByDisplayIdAndRootType(testId, WindowRootNodeType::APP_WINDOW_NODE);
115     ASSERT_EQ(nullptr, rootNodeVectorPtr);
116 }
117 
118 /**
119  * @tc.name: GetWindowNodesByDisplayIdAndRootType02
120  * @tc.desc: Use WindowRootNodeType which not exists
121  * @tc.type: FUNC
122  */
123 HWTEST_F(DisplayGroupControllerTest, GetWindowNodesByDisplayIdAndRootType02, Function | SmallTest | Level2)
124 {
125     WindowRootNodeType rootType = static_cast<WindowRootNodeType>(100);
126     std::vector<sptr<WindowNode>>* rootNodeVectorPtr =
127         displayGroupController_->GetWindowNodesByDisplayIdAndRootType(0, rootType);
128     ASSERT_EQ(nullptr, rootNodeVectorPtr);
129 }
130 
131 /**
132  * @tc.name: AddWindowNodeOnWindowTree01
133  * @tc.desc: Use WindowRootNodeType which not exists
134  * @tc.type: FUNC
135  */
136 HWTEST_F(DisplayGroupControllerTest, AddWindowNodeOnWindowTree01, Function | SmallTest | Level2)
137 {
138     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
139     ASSERT_NE(nullptr, node1);
140     WindowRootNodeType rootType = static_cast<WindowRootNodeType>(100);
141     displayGroupController_->AddWindowNodeOnWindowTree(node1, rootType);
142 }
143 
144 /**
145  * @tc.name: UpdateDisplayGroupWindowTree01
146  * @tc.desc: Use appWindowNode with nullptr
147  * @tc.type: FUNC
148  */
149 HWTEST_F(DisplayGroupControllerTest, UpdateDisplayGroupWindowTree01, Function | SmallTest | Level2)
150 {
151     auto originRootNode = container_->GetRootNode(WindowRootNodeType::APP_WINDOW_NODE);
152     ASSERT_NE(nullptr, originRootNode);
153     container_->appWindowNode_ = nullptr;
154     ASSERT_EQ(nullptr, container_->GetRootNode(WindowRootNodeType::APP_WINDOW_NODE));
155     displayGroupController_->UpdateDisplayGroupWindowTree();
156     container_->appWindowNode_ = originRootNode;
157     displayGroupController_->UpdateDisplayGroupWindowTree();
158 }
159 
160 /**
161  * @tc.name: ProcessCrossNodes01
162  * @tc.desc: IsShowingOnMultiDisplays_ is true
163  * @tc.type: FUNC
164  */
165 HWTEST_F(DisplayGroupControllerTest, ProcessCrossNodes01, Function | SmallTest | Level2)
166 {
167     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
168     ASSERT_NE(nullptr, node1);
169     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
170     ASSERT_NE(nullptr, child);
171     node1->children_.push_back(child);
172     node1->isShowingOnMultiDisplays_ = true;
173     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
174         0, WindowRootNodeType::APP_WINDOW_NODE);
175     rootApp->push_back(node1);
176     displayGroupController_->ProcessCrossNodes(1, DisplayStateChangeType::CREATE);
177 }
178 
179 /**
180  * @tc.name: ProcessCrossNodes02
181  * @tc.desc: IsShowingOnMultiDisplays_ is true with different DisplayStateChangeType
182  * @tc.type: FUNC
183  */
184 HWTEST_F(DisplayGroupControllerTest, ProcessCrossNodes02, Function | SmallTest | Level2)
185 {
186     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
187     ASSERT_NE(nullptr, node1);
188     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
189     ASSERT_NE(nullptr, child);
190     node1->children_.push_back(child);
191     node1->isShowingOnMultiDisplays_ = true;
192     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
193         0, WindowRootNodeType::APP_WINDOW_NODE);
194     rootApp->push_back(node1);
195     displayGroupController_->ProcessCrossNodes(1, DisplayStateChangeType::SIZE_CHANGE);
196 }
197 
198 /**
199  * @tc.name: ProcessCrossNodes03
200  * @tc.desc: IsShowingOnMultiDisplays_ is true with different DisplayStateChangeType
201  * @tc.type: FUNC
202  */
203 HWTEST_F(DisplayGroupControllerTest, ProcessCrossNodes03, Function | SmallTest | Level2)
204 {
205     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
206     ASSERT_NE(nullptr, node1);
207     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
208     ASSERT_NE(nullptr, child);
209     node1->children_.push_back(child);
210     node1->isShowingOnMultiDisplays_ = true;
211     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
212         0, WindowRootNodeType::APP_WINDOW_NODE);
213     rootApp->push_back(node1);
214     displayGroupController_->ProcessCrossNodes(1, DisplayStateChangeType::UPDATE_ROTATION);
215 }
216 
217 /**
218  * @tc.name: ProcessCrossNodes04
219  * @tc.desc: IsShowingOnMultiDisplays_ is true with multi showing display
220  * @tc.type: FUNC
221  */
222 HWTEST_F(DisplayGroupControllerTest, ProcessCrossNodes04, Function | SmallTest | Level2)
223 {
224     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
225     ASSERT_NE(nullptr, node1);
226     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
227     ASSERT_NE(nullptr, child);
228     node1->children_.push_back(child);
229     node1->isShowingOnMultiDisplays_ = true;
230     node1->SetShowingDisplays({0, 1});
231     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
232         0, WindowRootNodeType::APP_WINDOW_NODE);
233     rootApp->push_back(node1);
234     displayGroupController_->ProcessCrossNodes(1, DisplayStateChangeType::DISPLAY_COMPRESS);
235 }
236 
237 /**
238  * @tc.name: UpdateWindowShowingDisplays01
239  * @tc.desc: Show only on left display
240  * @tc.type: FUNC
241  */
242 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays01, Function | SmallTest | Level2)
243 {
244     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
245     ASSERT_NE(nullptr, node1);
246     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
247     ASSERT_NE(nullptr, child);
248     node1->children_.push_back(child);
249     node1->SetWindowRect({0, 0, 50, 50});
250     displayGroupController_->UpdateWindowShowingDisplays(node1);
251     ASSERT_EQ(1, node1->GetShowingDisplays().size());
252 }
253 
254 /**
255  * @tc.name: UpdateWindowShowingDisplays02
256  * @tc.desc: Not show on any display
257  * @tc.type: FUNC
258  */
259 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays02, Function | SmallTest | Level2)
260 {
261     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
262     ASSERT_NE(nullptr, node1);
263     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
264     ASSERT_NE(nullptr, child);
265     node1->children_.push_back(child);
266     node1->SetWindowRect({0, 0, 0, 0});
267     SetDisplayGroupInfo(0, {0, 0, 0, 0});
268     displayGroupController_->InitNewDisplay(1);
269     SetDisplayGroupInfo(1, {0, 0, 0, 0});
270     displayGroupController_->UpdateWindowShowingDisplays(node1);
271 }
272 
273 /**
274  * @tc.name: UpdateWindowShowingDisplays03
275  * @tc.desc: Show only on right display
276  * @tc.type: FUNC
277  */
278 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays03, Function | SmallTest | Level2)
279 {
280     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
281     ASSERT_NE(nullptr, node1);
282     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
283     ASSERT_NE(nullptr, child);
284     node1->children_.push_back(child);
285     node1->SetWindowRect({100, 100, 50, 50});
286     SetDisplayGroupInfo(0, {0, 0, 50, 50});
287     displayGroupController_->InitNewDisplay(1);
288     SetDisplayGroupInfo(1, {50, 50, 100, 100});
289     displayGroupController_->UpdateWindowShowingDisplays(node1);
290     ASSERT_EQ(1, node1->GetShowingDisplays().size());
291 }
292 
293 /**
294  * @tc.name: UpdateWindowShowingDisplays04
295  * @tc.desc: Show on multi display
296  * @tc.type: FUNC
297  */
298 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays04, Function | SmallTest | Level2)
299 {
300     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
301     ASSERT_NE(nullptr, node1);
302     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
303     ASSERT_NE(nullptr, child);
304     node1->children_.push_back(child);
305     node1->SetWindowRect({50, 50, 60, 60}); // 110 > 0 && 50 < 100
306     displayGroupController_->InitNewDisplay(0);
307     SetDisplayGroupInfo(0, {0, 0, 100, 100});
308     displayGroupController_->InitNewDisplay(1);
309     SetDisplayGroupInfo(1, {100, 100, 200, 200});
310     displayGroupController_->UpdateWindowShowingDisplays(node1);
311     ASSERT_EQ(2, node1->GetShowingDisplays().size());
312 }
313 
314 /**
315  * @tc.name: UpdateWindowDisplayIdIfNeeded01
316  * @tc.desc: Not show on any display
317  * @tc.type: FUNC
318  */
319 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded01, Function | SmallTest | Level2)
320 {
321     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
322     ASSERT_NE(nullptr, node1);
323     node1->SetWindowRect({50, 50, 60, 60});
324     displayGroupController_->InitNewDisplay(0);
325     SetDisplayGroupInfo(0, {0, 0, 100, 100});
326     displayGroupController_->InitNewDisplay(1);
327     SetDisplayGroupInfo(1, {100, 100, 200, 200});
328     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
329     ASSERT_EQ(0, node1->GetShowingDisplays().size());
330 }
331 
332 /**
333  * @tc.name: UpdateWindowDisplayIdIfNeeded02
334  * @tc.desc: Show on left display
335  * @tc.type: FUNC
336  */
337 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded02, Function | SmallTest | Level2)
338 {
339     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
340     ASSERT_NE(nullptr, node1);
341     node1->SetShowingDisplays({0});
342     node1->SetWindowRect({50, 50, 60, 60});
343     displayGroupController_->InitNewDisplay(0);
344     SetDisplayGroupInfo(0, {0, 0, 100, 100});
345     displayGroupController_->InitNewDisplay(1);
346     SetDisplayGroupInfo(1, {100, 100, 200, 200});
347     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
348     ASSERT_EQ(0, node1->GetDisplayId());
349 }
350 
351 /**
352  * @tc.name: UpdateWindowDisplayIdIfNeeded03
353  * @tc.desc: Window covers whole display region
354  * @tc.type: FUNC
355  */
356 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded03, Function | SmallTest | Level2)
357 {
358     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
359     ASSERT_NE(nullptr, node1);
360     node1->SetShowingDisplays({0, 1});
361     node1->SetWindowRect({-50, -50, 200, 200});
362     displayGroupController_->InitNewDisplay(0);
363     SetDisplayGroupInfo(0, {0, 0, 100, 100});
364     displayGroupController_->InitNewDisplay(1);
365     SetDisplayGroupInfo(1, {200, 200, 200, 200});
366     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
367     ASSERT_EQ(0, node1->GetDisplayId());
368 }
369 
370 /**
371  * @tc.name: UpdateWindowDisplayIdIfNeeded04
372  * @tc.desc: Current display is default display
373  * @tc.type: FUNC
374  */
375 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded04, Function | SmallTest | Level2)
376 {
377     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
378     ASSERT_NE(nullptr, node1);
379     node1->SetShowingDisplays({0, 1});
380     node1->SetWindowRect({50, 50, 100, 100});
381     displayGroupController_->InitNewDisplay(0);
382     SetDisplayGroupInfo(0, {0, 0, 100, 100});
383     displayGroupController_->InitNewDisplay(1);
384     SetDisplayGroupInfo(1, {200, 200, 200, 200});
385     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
386     ASSERT_EQ(0, node1->GetDisplayId());
387 }
388 
389 /**
390  * @tc.name: UpdateWindowDisplayIdIfNeeded05
391  * @tc.desc: Current display is expand display
392  * @tc.type: FUNC
393  */
394 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded05, Function | SmallTest | Level2)
395 {
396     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
397     ASSERT_NE(nullptr, node1);
398     node1->SetShowingDisplays({0, 1});
399     node1->SetWindowRect({60, 60, 100, 100});
400     SetDisplayGroupInfo(0, {0, 0, 100, 100});
401     displayGroupController_->InitNewDisplay(1);
402     SetDisplayGroupInfo(1, {200, 200, 200, 200});
403     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
404     ASSERT_EQ(0, node1->GetDisplayId());
405 }
406 
407 /**
408  * @tc.name: UpdateWindowDisplayIdIfNeeded06
409  * @tc.desc: Current display is expand display
410  * @tc.type: FUNC
411  */
412 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded06, Function | SmallTest | Level2)
413 {
414     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
415     ASSERT_NE(nullptr, node1);
416     node1->SetShowingDisplays({0, 1});
417     node1->SetWindowRect({60, 60, 120, 120});
418     SetDisplayGroupInfo(0, {0, 0, 70, 70});
419     displayGroupController_->InitNewDisplay(1);
420     SetDisplayGroupInfo(1, {70, 70, 200, 200});
421     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
422     ASSERT_EQ(1, node1->GetDisplayId());
423 }
424 
425 /**
426  * @tc.name: ChangeToRectInDisplayGroup01
427  * @tc.desc: Change to rect in Display Group
428  * @tc.type: FUNC
429  */
430 HWTEST_F(DisplayGroupControllerTest, ChangeToRectInDisplayGroup01, Function | SmallTest | Level2)
431 {
432     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
433     ASSERT_NE(nullptr, node1);
434     displayGroupController_->ChangeToRectInDisplayGroup(node1, 0);
435     Rect actualRect = node1->GetRequestRect();
436     Rect expectRect = {DEFAULT_RECT.posX_, DEFAULT_RECT.posY_, 0, 0};
437     ASSERT_EQ(expectRect, actualRect);
438 }
439 
440 /**
441  * @tc.name: PreProcessWindowNode01
442  * @tc.desc: PreProcessWindowNode with child
443  * @tc.type: FUNC
444  */
445 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode01, Function | SmallTest | Level2)
446 {
447     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
448     ASSERT_NE(nullptr, node1);
449     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
450     ASSERT_NE(nullptr, child);
451     node1->children_.push_back(child);
452     displayGroupController_->PreProcessWindowNode(node1, WindowUpdateType::WINDOW_UPDATE_ADDED);
453     Rect actualRect = node1->GetRequestRect();
454     Rect expectRect = {DEFAULT_RECT.posX_, DEFAULT_RECT.posY_, 0, 0};
455     ASSERT_EQ(expectRect, actualRect);
456 }
457 
458 /**
459  * @tc.name: PreProcessWindowNode02
460  * @tc.desc: PreProcessWindowNode with WINDOW_UPDATE_ACTIVE, and size change reason undefined
461  * @tc.type: FUNC
462  */
463 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode02, Function | SmallTest | Level2)
464 {
465     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
466     ASSERT_NE(nullptr, node1);
467     container_->GetLayoutPolicy()->isMultiDisplay_ = true;
468     displayGroupController_->PreProcessWindowNode(node1, WindowUpdateType::WINDOW_UPDATE_ACTIVE);
469     Rect actualRect = node1->GetRequestRect();
470     Rect expectRect = {0, 0, 0, 0};
471     ASSERT_EQ(expectRect, actualRect);
472 }
473 
474 /**
475  * @tc.name: PreProcessWindowNode03
476  * @tc.desc: PreProcessWindowNode with WINDOW_UPDATE_ADDED, and isShowingOnMultiDisplays_ is true
477  * @tc.type: FUNC
478  */
479 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode03, Function | SmallTest | Level2)
480 {
481     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
482     ASSERT_NE(nullptr, node1);
483     node1->isShowingOnMultiDisplays_ = true;
484     displayGroupController_->PreProcessWindowNode(node1, WindowUpdateType::WINDOW_UPDATE_ADDED);
485     Rect actualRect = node1->GetRequestRect();
486     Rect expectRect = {0, 0, 0, 0};
487     ASSERT_EQ(expectRect, actualRect);
488 }
489 
490 /**
491  * @tc.name: PreProcessWindowNode04
492  * @tc.desc: PreProcessWindowNode with WINDOW_UPDATE_ACTIVE, and size change reason MOVE
493  * @tc.type: FUNC
494  */
495 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode04, Function | SmallTest | Level2)
496 {
497     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
498     ASSERT_NE(nullptr, node1);
499     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
500     ASSERT_NE(nullptr, child);
501     node1->children_.push_back(child);
502     node1->SetWindowSizeChangeReason(WindowSizeChangeReason::MOVE);
503     displayGroupController_->PreProcessWindowNode(node1, WindowUpdateType::WINDOW_UPDATE_ACTIVE);
504     Rect actualRect = node1->GetRequestRect();
505     Rect expectRect = {DEFAULT_RECT.posX_, DEFAULT_RECT.posY_, 0, 0};
506     ASSERT_EQ(expectRect, actualRect);
507 }
508 
509 /**
510  * @tc.name: PostProcessWindowNode01
511  * @tc.desc: PostProcessWindowNode with multi display is true
512  * @tc.type: FUNC
513  */
514 HWTEST_F(DisplayGroupControllerTest, PostProcessWindowNode01, Function | SmallTest | Level2)
515 {
516     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
517     ASSERT_NE(nullptr, node1);
518     container_->GetLayoutPolicy()->isMultiDisplay_ = true;
519     ASSERT_EQ(true, container_->GetLayoutPolicy()->IsMultiDisplay());
520 }
521 
522 /**
523  * @tc.name: UpdateWindowDisplayId01
524  * @tc.desc: UpdateWindowDisplayId with windowToken
525  * @tc.type: FUNC
526  */
527 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayId01, Function | SmallTest | Level2)
528 {
529     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
530     sptr<IWindow> iWindow = iface_cast<IWindow>(iRemoteObjectMocker);
531     ASSERT_NE(nullptr, iWindow);
532     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
533     ASSERT_NE(nullptr, node1);
534     node1->SetWindowToken(iWindow);
535     ASSERT_NE(nullptr, node1->GetWindowToken());
536     displayGroupController_->UpdateWindowDisplayId(node1, 1);
537     ASSERT_EQ(1, node1->GetDisplayId());
538 }
539 
540 /**
541  * @tc.name: MoveCrossNodeToTargetDisplay01
542  * @tc.desc: TargetDisplayId equals to default displayId
543  * @tc.type: FUNC
544  */
545 HWTEST_F(DisplayGroupControllerTest, MoveCrossNodeToTargetDisplay01, Function | SmallTest | Level2)
546 {
547     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
548     ASSERT_NE(nullptr, node1);
549     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
550     ASSERT_NE(nullptr, child);
551     node1->children_.push_back(child);
552     displayGroupController_->MoveCrossNodeToTargetDisplay(node1, 0);
553     auto showingDisplays = child->GetShowingDisplays();
554     ASSERT_NE(0, showingDisplays.size());
555     ASSERT_EQ(0, showingDisplays[0]);
556 }
557 
558 /**
559  * @tc.name: MoveCrossNodeToTargetDisplay02
560  * @tc.desc: No child and targetDisplayId not equals to default displayId
561  * @tc.type: FUNC
562  */
563 HWTEST_F(DisplayGroupControllerTest, MoveCrossNodeToTargetDisplay02, Function | SmallTest | Level2)
564 {
565     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
566     ASSERT_NE(nullptr, node1);
567     displayGroupController_->MoveCrossNodeToTargetDisplay(node1, 1);
568     ASSERT_EQ(1, node1->GetDisplayId());
569 }
570 
571 /**
572  * @tc.name: MoveCrossNodeToTargetDisplay03
573  * @tc.desc: TargetDisplayId not equals to default displayId
574  * @tc.type: FUNC
575  */
576 HWTEST_F(DisplayGroupControllerTest, MoveCrossNodeToTargetDisplay03, Function | SmallTest | Level2)
577 {
578     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
579     ASSERT_NE(nullptr, node1);
580     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
581     ASSERT_NE(nullptr, child);
582     node1->children_.push_back(child);
583     displayGroupController_->MoveCrossNodeToTargetDisplay(node1, 1);
584     ASSERT_EQ(1, node1->GetDisplayId());
585     ASSERT_EQ(1, child->GetDisplayId());
586 }
587 
588 /**
589  * @tc.name: MoveNotCrossNodeToDefaultDisplay01
590  * @tc.desc: MoveNotCrossNodeToDefaultDisplay with window type pointer without child
591  * @tc.type: FUNC
592  */
593 HWTEST_F(DisplayGroupControllerTest, MoveNotCrossNodeToDefaultDisplay01, Function | SmallTest | Level2)
594 {
595     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100, WindowType::WINDOW_TYPE_POINTER));
596     ASSERT_NE(nullptr, node1);
597     displayGroupController_->MoveNotCrossNodeToDefaultDisplay(node1, 1);
598     Rect actualRect = node1->GetRequestRect();
599     Rect expectRect = {100, 100, 0, 0};
600     ASSERT_EQ(expectRect, actualRect);
601 }
602 
603 /**
604  * @tc.name: MoveNotCrossNodeToDefaultDisplay02
605  * @tc.desc: MoveNotCrossNodeToDefaultDisplay with window type app with child
606  * @tc.type: FUNC
607  */
608 HWTEST_F(DisplayGroupControllerTest, MoveNotCrossNodeToDefaultDisplay02, Function | SmallTest | Level2)
609 {
610     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
611     ASSERT_NE(nullptr, node1);
612     sptr<WindowNode> child = new WindowNode(CreateWindowProperty(101));
613     ASSERT_NE(nullptr, child);
614     node1->children_.push_back(child);
615     displayGroupController_->InitNewDisplay(1);
616     SetDisplayGroupInfo(1, {200, 200, 200, 200});
617     displayGroupController_->MoveNotCrossNodeToDefaultDisplay(node1, 1);
618     Rect actualRect = node1->GetRequestRect();
619     Rect expectRect = {-200, -200, 0, 0};
620     ASSERT_EQ(expectRect, actualRect);
621     ASSERT_EQ(expectRect, child->GetRequestRect());
622 }
623 
624 /**
625  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay01
626  * @tc.desc: DisplayId equals to defaultDisplayId
627  * @tc.type: FUNC
628  */
629 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay01, Function | SmallTest | Level2)
630 {
631     std::vector<uint32_t> windowIds;
632     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(0, windowIds);
633     ASSERT_EQ(0, windowIds.size());
634 }
635 
636 /**
637  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay02
638  * @tc.desc: DisplayId not equals to defaultDisplayId or node displayId
639  * @tc.type: FUNC
640  */
641 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay02, Function | SmallTest | Level2)
642 {
643     displayGroupController_->InitNewDisplay(1);
644     SetDisplayGroupInfo(1, {200, 200, 200, 200});
645     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
646     ASSERT_NE(nullptr, node1);
647     displayGroupController_->InitNewDisplay(1);
648     SetDisplayGroupInfo(1, {200, 200, 200, 200});
649     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
650         1, WindowRootNodeType::APP_WINDOW_NODE);
651     rootApp->push_back(node1);
652     std::vector<uint32_t> windowIds;
653     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
654     ASSERT_EQ(0, node1->GetDisplayId());
655 }
656 
657 /**
658  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay03
659  * @tc.desc: DisplayId not equals to defaultDisplayId but equals to node displayId, isShowingOnMultiDisplays_ is true
660  * @tc.type: FUNC
661  */
662 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay03, Function | SmallTest | Level2)
663 {
664     displayGroupController_->InitNewDisplay(1);
665     SetDisplayGroupInfo(1, {200, 200, 200, 200});
666     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
667     ASSERT_NE(nullptr, node1);
668     displayGroupController_->InitNewDisplay(1);
669     SetDisplayGroupInfo(1, {200, 200, 200, 200});
670     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
671         1, WindowRootNodeType::APP_WINDOW_NODE);
672     rootApp->push_back(node1);
673     node1->SetDisplayId(1);
674     node1->isShowingOnMultiDisplays_ = true;
675     std::vector<uint32_t> windowIds;
676     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
677     ASSERT_EQ(1, node1->GetDisplayId());
678 }
679 
680 /**
681  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay04
682  * @tc.desc: Node with WINDOW_TYPE_STATUS_BAR
683  * @tc.type: FUNC
684  */
685 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay04, Function | SmallTest | Level2)
686 {
687     displayGroupController_->InitNewDisplay(1);
688     SetDisplayGroupInfo(1, {200, 200, 200, 200});
689     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100, WindowType::WINDOW_TYPE_STATUS_BAR));
690     ASSERT_NE(nullptr, node1);
691     displayGroupController_->InitNewDisplay(1);
692     SetDisplayGroupInfo(1, {200, 200, 200, 200});
693     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
694         1, WindowRootNodeType::ABOVE_WINDOW_NODE);
695     rootApp->push_back(node1);
696     node1->SetDisplayId(1);
697     std::vector<uint32_t> windowIds;
698     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
699     ASSERT_EQ(1, windowIds.size());
700     ASSERT_EQ(1, node1->GetDisplayId());
701 }
702 
703 /**
704  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay05
705  * @tc.desc: Node with WINDOW_TYPE_NAVIGATION_BAR
706  * @tc.type: FUNC
707  */
708 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay05, Function | SmallTest | Level2)
709 {
710     displayGroupController_->InitNewDisplay(1);
711     SetDisplayGroupInfo(1, {200, 200, 200, 200});
712     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100, WindowType::WINDOW_TYPE_NAVIGATION_BAR));
713     ASSERT_NE(nullptr, node1);
714     displayGroupController_->InitNewDisplay(1);
715     SetDisplayGroupInfo(1, {200, 200, 200, 200});
716     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
717         1, WindowRootNodeType::ABOVE_WINDOW_NODE);
718     rootApp->push_back(node1);
719     node1->SetDisplayId(1);
720     std::vector<uint32_t> windowIds;
721     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
722     ASSERT_EQ(1, windowIds.size());
723     ASSERT_EQ(1, node1->GetDisplayId());
724 }
725 
726 /**
727  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay06
728  * @tc.desc: Execute to move to default display
729  * @tc.type: FUNC
730  */
731 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay06, Function | SmallTest | Level2)
732 {
733     displayGroupController_->InitNewDisplay(1);
734     SetDisplayGroupInfo(1, {200, 200, 200, 200});
735     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
736     ASSERT_NE(nullptr, node1);
737     displayGroupController_->InitNewDisplay(1);
738     SetDisplayGroupInfo(1, {200, 200, 200, 200});
739     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
740         1, WindowRootNodeType::APP_WINDOW_NODE);
741     rootApp->push_back(node1);
742     node1->SetDisplayId(1);
743     std::vector<uint32_t> windowIds;
744     windowIds.push_back(node1->GetWindowId());
745     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
746     ASSERT_EQ(0, node1->GetDisplayId());
747 }
748 
749 /**
750  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay07
751  * @tc.desc: DisplayId not equals to defaultDisplayId, and no node on groupWindowTree
752  * @tc.type: FUNC
753  */
754 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay07, Function | SmallTest | Level2)
755 {
756     displayGroupController_->InitNewDisplay(1);
757     SetDisplayGroupInfo(1, {200, 200, 200, 200});
758     std::vector<uint32_t> windowIds;
759     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
760     ASSERT_EQ(0, windowIds.size());
761 }
762 
763 /**
764  * @tc.name: UpdateNodeSizeChangeReasonWithRotation01
765  * @tc.desc: UpdateNodeSizeChangeReasonWithRotation Success
766  * @tc.type: FUNC
767  */
768 HWTEST_F(DisplayGroupControllerTest, UpdateNodeSizeChangeReasonWithRotation01, Function | SmallTest | Level2)
769 {
770     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100));
771     ASSERT_NE(nullptr, node1);
772     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
773         0, WindowRootNodeType::APP_WINDOW_NODE);
774     rootApp->push_back(node1);
775     displayGroupController_->UpdateNodeSizeChangeReasonWithRotation(0, displayGroupInfo_.GetAllDisplayRects());
776     ASSERT_EQ(WindowSizeChangeReason::ROTATION, node1->GetWindowSizeChangeReason());
777 }
778 
779 /**
780  * @tc.name: UpdateNodeSizeChangeReasonWithRotation02
781  * @tc.desc: UpdateNodeSizeChangeReasonWithRotation failed
782  * @tc.type: FUNC
783  */
784 HWTEST_F(DisplayGroupControllerTest, UpdateNodeSizeChangeReasonWithRotation02, Function | SmallTest | Level2)
785 {
786     sptr<WindowNode> node1 = new WindowNode(CreateWindowProperty(100, WindowType::WINDOW_TYPE_DOCK_SLICE));
787     ASSERT_NE(nullptr, node1);
788     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
789         0, WindowRootNodeType::ABOVE_WINDOW_NODE);
790     rootApp->push_back(node1);
791     displayGroupController_->UpdateNodeSizeChangeReasonWithRotation(0, displayGroupInfo_.GetAllDisplayRects());
792     ASSERT_NE(WindowSizeChangeReason::ROTATION, node1->GetWindowSizeChangeReason());
793 }
794 
795 /**
796  * @tc.name: UpdateNodeSizeChangeReasonWithRotation03
797  * @tc.desc: UpdateNodeSizeChangeReasonWithRotation with rootNodeVectorPtr null
798  * @tc.type: FUNC
799  */
800 HWTEST_F(DisplayGroupControllerTest, UpdateNodeSizeChangeReasonWithRotation03, Function | SmallTest | Level2)
801 {
802     displayGroupController_->displayGroupWindowTree_[0].erase(WindowRootNodeType::ABOVE_WINDOW_NODE);
803     ASSERT_EQ(nullptr, displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
804         0, WindowRootNodeType::ABOVE_WINDOW_NODE));
805     displayGroupController_->UpdateNodeSizeChangeReasonWithRotation(0, displayGroupInfo_.GetAllDisplayRects());
806     ASSERT_EQ(nullptr, displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
807         0, WindowRootNodeType::ABOVE_WINDOW_NODE));
808 }
809 
810 /**
811  * @tc.name: ProcessDisplayChange01
812  * @tc.desc: ProcessDisplayChange with different DisplayStateChangeType
813  * @tc.type: FUNC
814  */
815 HWTEST_F(DisplayGroupControllerTest, ProcessDisplayChange01, Function | SmallTest | Level2)
816 {
817     sptr<DisplayInfo> displayInfo = new DisplayInfo();
818     ASSERT_NE(nullptr, displayInfo);
819     displayInfo->SetDisplayId(0);
820     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
821         DisplayStateChangeType::UPDATE_ROTATION);
822     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
823         DisplayStateChangeType::DISPLAY_COMPRESS);
824     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
825         DisplayStateChangeType::SIZE_CHANGE);
826     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
827         DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE);
828     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
829         DisplayStateChangeType::DESTROY);
830 }
831 
832 /**
833  * @tc.name: ProcessDisplaySizeChangeOrRotation01
834  * @tc.desc: ProcessDisplaySizeChangeOrRotation with layout policy null
835  * @tc.type: FUNC
836  */
837 HWTEST_F(DisplayGroupControllerTest, ProcessDisplaySizeChangeOrRotation01, Function | SmallTest | Level2)
838 {
839     auto oriLayoutPolicy = container_->GetLayoutPolicy();
840     container_->layoutPolicy_ = nullptr;
841     displayGroupController_->ProcessDisplaySizeChangeOrRotation(0, 0, displayGroupInfo_.GetAllDisplayRects(),
842         DisplayStateChangeType::UPDATE_ROTATION);
843     ASSERT_EQ(nullptr, container_->GetLayoutPolicy());
844     container_->layoutPolicy_ = oriLayoutPolicy;
845 }
846 
847 /**
848  * @tc.name: GetWindowPairByDisplayId
849  * @tc.desc: GetWindowPairByDisplayId with displayId 1, which not exists
850  * @tc.type: FUNC
851  */
852 HWTEST_F(DisplayGroupControllerTest, GetWindowPairByDisplayId01, Function | SmallTest | Level2)
853 {
854     ASSERT_EQ(nullptr, displayGroupController_->GetWindowPairByDisplayId(1));
855 }
856 }
857 }
858 }
859