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();
139     node1->SetWindowProperty(CreateWindowProperty(100));
140     ASSERT_NE(nullptr, node1);
141     WindowRootNodeType rootType = static_cast<WindowRootNodeType>(100);
142     displayGroupController_->AddWindowNodeOnWindowTree(node1, rootType);
143 }
144 
145 /**
146  * @tc.name: UpdateDisplayGroupWindowTree01
147  * @tc.desc: Use appWindowNode with nullptr
148  * @tc.type: FUNC
149  */
150 HWTEST_F(DisplayGroupControllerTest, UpdateDisplayGroupWindowTree01, Function | SmallTest | Level2)
151 {
152     auto originRootNode = container_->GetRootNode(WindowRootNodeType::APP_WINDOW_NODE);
153     ASSERT_NE(nullptr, originRootNode);
154     container_->appWindowNode_ = nullptr;
155     ASSERT_EQ(nullptr, container_->GetRootNode(WindowRootNodeType::APP_WINDOW_NODE));
156     displayGroupController_->UpdateDisplayGroupWindowTree();
157     container_->appWindowNode_ = originRootNode;
158     displayGroupController_->UpdateDisplayGroupWindowTree();
159 }
160 
161 
162 /**
163  * @tc.name: ProcessCrossNodes02
164  * @tc.desc: IsShowingOnMultiDisplays_ is true with different DisplayStateChangeType
165  * @tc.type: FUNC
166  */
167 HWTEST_F(DisplayGroupControllerTest, ProcessCrossNodes02, Function | SmallTest | Level2)
168 {
169     sptr<WindowNode> node1 = new WindowNode();
170     node1->SetWindowProperty(CreateWindowProperty(100));
171     ASSERT_NE(nullptr, node1);
172     sptr<WindowNode> child = new WindowNode();
173     child->SetWindowProperty(CreateWindowProperty(101));
174     ASSERT_NE(nullptr, child);
175     node1->children_.push_back(child);
176     node1->isShowingOnMultiDisplays_ = true;
177     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
178         0, WindowRootNodeType::APP_WINDOW_NODE);
179     rootApp->push_back(node1);
180     displayGroupController_->ProcessCrossNodes(1, DisplayStateChangeType::SIZE_CHANGE);
181 }
182 
183 /**
184  * @tc.name: ProcessCrossNodes03
185  * @tc.desc: IsShowingOnMultiDisplays_ is true with different DisplayStateChangeType
186  * @tc.type: FUNC
187  */
188 HWTEST_F(DisplayGroupControllerTest, ProcessCrossNodes03, Function | SmallTest | Level2)
189 {
190     sptr<WindowNode> node1 = new WindowNode();
191     node1->SetWindowProperty(CreateWindowProperty(100));
192     ASSERT_NE(nullptr, node1);
193     sptr<WindowNode> child = new WindowNode();
194     child->SetWindowProperty(CreateWindowProperty(101));
195     ASSERT_NE(nullptr, child);
196     node1->children_.push_back(child);
197     node1->isShowingOnMultiDisplays_ = true;
198     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
199         0, WindowRootNodeType::APP_WINDOW_NODE);
200     rootApp->push_back(node1);
201     displayGroupController_->ProcessCrossNodes(1, DisplayStateChangeType::UPDATE_ROTATION);
202 }
203 
204 /**
205  * @tc.name: ProcessCrossNodes04
206  * @tc.desc: IsShowingOnMultiDisplays_ is true with multi showing display
207  * @tc.type: FUNC
208  */
209 HWTEST_F(DisplayGroupControllerTest, ProcessCrossNodes04, Function | SmallTest | Level2)
210 {
211     sptr<WindowNode> node1 = new WindowNode();
212     node1->SetWindowProperty(CreateWindowProperty(100));
213     ASSERT_NE(nullptr, node1);
214     sptr<WindowNode> child = new WindowNode();
215     child->SetWindowProperty(CreateWindowProperty(101));
216     ASSERT_NE(nullptr, child);
217     node1->children_.push_back(child);
218     node1->isShowingOnMultiDisplays_ = true;
219     node1->SetShowingDisplays({0, 1});
220     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
221         0, WindowRootNodeType::APP_WINDOW_NODE);
222     rootApp->push_back(node1);
223     displayGroupController_->ProcessCrossNodes(1, DisplayStateChangeType::DISPLAY_COMPRESS);
224 }
225 
226 /**
227  * @tc.name: UpdateWindowShowingDisplays01
228  * @tc.desc: Show only on left display
229  * @tc.type: FUNC
230  */
231 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays01, Function | SmallTest | Level2)
232 {
233     sptr<WindowNode> node1 = new WindowNode();
234     node1->SetWindowProperty(CreateWindowProperty(100));
235     ASSERT_NE(nullptr, node1);
236     sptr<WindowNode> child = new WindowNode();
237     child->SetWindowProperty(CreateWindowProperty(101));
238     ASSERT_NE(nullptr, child);
239     node1->children_.push_back(child);
240     node1->SetWindowRect({0, 0, 50, 50});
241     displayGroupController_->UpdateWindowShowingDisplays(node1);
242     ASSERT_EQ(1, node1->GetShowingDisplays().size());
243 }
244 
245 /**
246  * @tc.name: UpdateWindowShowingDisplays02
247  * @tc.desc: Not show on any display
248  * @tc.type: FUNC
249  */
250 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays02, Function | SmallTest | Level2)
251 {
252     sptr<WindowNode> node1 = new WindowNode();
253     node1->SetWindowProperty(CreateWindowProperty(100));
254     ASSERT_NE(nullptr, node1);
255     sptr<WindowNode> child = new WindowNode();
256     child->SetWindowProperty(CreateWindowProperty(101));
257     ASSERT_NE(nullptr, child);
258     node1->children_.push_back(child);
259     node1->SetWindowRect({0, 0, 0, 0});
260     SetDisplayGroupInfo(0, {0, 0, 0, 0});
261     displayGroupController_->InitNewDisplay(1);
262     SetDisplayGroupInfo(1, {0, 0, 0, 0});
263     displayGroupController_->UpdateWindowShowingDisplays(node1);
264 }
265 
266 /**
267  * @tc.name: UpdateWindowShowingDisplays03
268  * @tc.desc: Show only on right display
269  * @tc.type: FUNC
270  */
271 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays03, Function | SmallTest | Level2)
272 {
273     sptr<WindowNode> node1 = new WindowNode();
274     node1->SetWindowProperty(CreateWindowProperty(100));
275     ASSERT_NE(nullptr, node1);
276     sptr<WindowNode> child = new WindowNode();
277     child->SetWindowProperty(CreateWindowProperty(101));
278     ASSERT_NE(nullptr, child);
279     node1->children_.push_back(child);
280     node1->SetWindowRect({100, 100, 50, 50});
281     SetDisplayGroupInfo(0, {0, 0, 50, 50});
282     displayGroupController_->InitNewDisplay(1);
283     SetDisplayGroupInfo(1, {50, 50, 100, 100});
284     displayGroupController_->UpdateWindowShowingDisplays(node1);
285     ASSERT_EQ(1, node1->GetShowingDisplays().size());
286 }
287 
288 /**
289  * @tc.name: UpdateWindowShowingDisplays04
290  * @tc.desc: Show on multi display
291  * @tc.type: FUNC
292  */
293 HWTEST_F(DisplayGroupControllerTest, UpdateWindowShowingDisplays04, Function | SmallTest | Level2)
294 {
295     sptr<WindowNode> node1 = new WindowNode();
296     node1->SetWindowProperty(CreateWindowProperty(100));
297     ASSERT_NE(nullptr, node1);
298     sptr<WindowNode> child = new WindowNode();
299     child->SetWindowProperty(CreateWindowProperty(101));
300     ASSERT_NE(nullptr, child);
301     node1->children_.push_back(child);
302     node1->SetWindowRect({50, 50, 60, 60}); // 110 > 0 && 50 < 100
303     displayGroupController_->InitNewDisplay(0);
304     SetDisplayGroupInfo(0, {0, 0, 100, 100});
305     displayGroupController_->InitNewDisplay(1);
306     SetDisplayGroupInfo(1, {100, 100, 200, 200});
307     displayGroupController_->UpdateWindowShowingDisplays(node1);
308     ASSERT_EQ(2, node1->GetShowingDisplays().size());
309 }
310 
311 /**
312  * @tc.name: UpdateWindowDisplayIdIfNeeded01
313  * @tc.desc: Not show on any display
314  * @tc.type: FUNC
315  */
316 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded01, Function | SmallTest | Level2)
317 {
318     sptr<WindowNode> node1 = new WindowNode();
319     node1->SetWindowProperty(CreateWindowProperty(100));
320     ASSERT_NE(nullptr, node1);
321     node1->SetWindowRect({50, 50, 60, 60});
322     displayGroupController_->InitNewDisplay(0);
323     SetDisplayGroupInfo(0, {0, 0, 100, 100});
324     displayGroupController_->InitNewDisplay(1);
325     SetDisplayGroupInfo(1, {100, 100, 200, 200});
326     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
327     ASSERT_EQ(0, node1->GetShowingDisplays().size());
328 }
329 
330 /**
331  * @tc.name: UpdateWindowDisplayIdIfNeeded02
332  * @tc.desc: Show on left display
333  * @tc.type: FUNC
334  */
335 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded02, Function | SmallTest | Level2)
336 {
337     sptr<WindowNode> node1 = new WindowNode();
338     node1->SetWindowProperty(CreateWindowProperty(100));
339     ASSERT_NE(nullptr, node1);
340     node1->SetShowingDisplays({0});
341     node1->SetWindowRect({50, 50, 60, 60});
342     displayGroupController_->InitNewDisplay(0);
343     SetDisplayGroupInfo(0, {0, 0, 100, 100});
344     displayGroupController_->InitNewDisplay(1);
345     SetDisplayGroupInfo(1, {100, 100, 200, 200});
346     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
347     ASSERT_EQ(0, node1->GetDisplayId());
348 }
349 
350 /**
351  * @tc.name: UpdateWindowDisplayIdIfNeeded03
352  * @tc.desc: Window covers whole display region
353  * @tc.type: FUNC
354  */
355 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded03, Function | SmallTest | Level2)
356 {
357     sptr<WindowNode> node1 = new WindowNode();
358     node1->SetWindowProperty(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();
378     node1->SetWindowProperty(CreateWindowProperty(100));
379     ASSERT_NE(nullptr, node1);
380     node1->SetShowingDisplays({0, 1});
381     node1->SetWindowRect({50, 50, 100, 100});
382     displayGroupController_->InitNewDisplay(0);
383     SetDisplayGroupInfo(0, {0, 0, 100, 100});
384     displayGroupController_->InitNewDisplay(1);
385     SetDisplayGroupInfo(1, {200, 200, 200, 200});
386     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
387     ASSERT_EQ(0, node1->GetDisplayId());
388 }
389 
390 /**
391  * @tc.name: UpdateWindowDisplayIdIfNeeded05
392  * @tc.desc: Current display is expand display
393  * @tc.type: FUNC
394  */
395 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded05, Function | SmallTest | Level2)
396 {
397     sptr<WindowNode> node1 = new WindowNode();
398     node1->SetWindowProperty(CreateWindowProperty(100));
399     ASSERT_NE(nullptr, node1);
400     node1->SetShowingDisplays({0, 1});
401     node1->SetWindowRect({60, 60, 100, 100});
402     SetDisplayGroupInfo(0, {0, 0, 100, 100});
403     displayGroupController_->InitNewDisplay(1);
404     SetDisplayGroupInfo(1, {200, 200, 200, 200});
405     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
406     ASSERT_EQ(0, node1->GetDisplayId());
407 }
408 
409 /**
410  * @tc.name: UpdateWindowDisplayIdIfNeeded06
411  * @tc.desc: Current display is expand display
412  * @tc.type: FUNC
413  */
414 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayIdIfNeeded06, Function | SmallTest | Level2)
415 {
416     sptr<WindowNode> node1 = new WindowNode();
417     node1->SetWindowProperty(CreateWindowProperty(100));
418     ASSERT_NE(nullptr, node1);
419     node1->SetShowingDisplays({0, 1});
420     node1->SetWindowRect({60, 60, 120, 120});
421     SetDisplayGroupInfo(0, {0, 0, 70, 70});
422     displayGroupController_->InitNewDisplay(1);
423     SetDisplayGroupInfo(1, {70, 70, 200, 200});
424     displayGroupController_->UpdateWindowDisplayIdIfNeeded(node1);
425     ASSERT_EQ(1, node1->GetDisplayId());
426 }
427 
428 /**
429  * @tc.name: ChangeToRectInDisplayGroup01
430  * @tc.desc: Change to rect in Display Group
431  * @tc.type: FUNC
432  */
433 HWTEST_F(DisplayGroupControllerTest, ChangeToRectInDisplayGroup01, Function | SmallTest | Level2)
434 {
435     sptr<WindowNode> node1 = new WindowNode();
436     node1->SetWindowProperty(CreateWindowProperty(100));
437     ASSERT_NE(nullptr, node1);
438     displayGroupController_->ChangeToRectInDisplayGroup(node1, 0);
439     Rect actualRect = node1->GetRequestRect();
440     Rect expectRect = {DEFAULT_RECT.posX_, DEFAULT_RECT.posY_, 0, 0};
441     ASSERT_EQ(expectRect, actualRect);
442 }
443 
444 /**
445  * @tc.name: PreProcessWindowNode01
446  * @tc.desc: PreProcessWindowNode with child
447  * @tc.type: FUNC
448  */
449 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode01, Function | SmallTest | Level2)
450 {
451     sptr<WindowNode> node1 = new WindowNode();
452     node1->SetWindowProperty(CreateWindowProperty(100));
453     ASSERT_NE(nullptr, node1);
454     sptr<WindowNode> child = new WindowNode();
455     child->SetWindowProperty(CreateWindowProperty(101));
456     ASSERT_NE(nullptr, child);
457     node1->children_.push_back(child);
458     displayGroupController_->PreProcessWindowNode(node1, WindowUpdateType::WINDOW_UPDATE_ADDED);
459     Rect actualRect = node1->GetRequestRect();
460     Rect expectRect = {DEFAULT_RECT.posX_, DEFAULT_RECT.posY_, 0, 0};
461     ASSERT_EQ(expectRect, actualRect);
462 }
463 
464 /**
465  * @tc.name: PreProcessWindowNode02
466  * @tc.desc: PreProcessWindowNode with WINDOW_UPDATE_ACTIVE, and size change reason undefined
467  * @tc.type: FUNC
468  */
469 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode02, Function | SmallTest | Level2)
470 {
471     sptr<WindowNode> node1 = new WindowNode();
472     node1->SetWindowProperty(CreateWindowProperty(100));
473     ASSERT_NE(nullptr, node1);
474     container_->GetLayoutPolicy()->isMultiDisplay_ = true;
475     displayGroupController_->PreProcessWindowNode(node1, WindowUpdateType::WINDOW_UPDATE_ACTIVE);
476     Rect actualRect = node1->GetRequestRect();
477     Rect expectRect = {0, 0, 0, 0};
478     ASSERT_EQ(expectRect, actualRect);
479 }
480 
481 /**
482  * @tc.name: PreProcessWindowNode03
483  * @tc.desc: PreProcessWindowNode with WINDOW_UPDATE_ADDED, and isShowingOnMultiDisplays_ is true
484  * @tc.type: FUNC
485  */
486 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode03, Function | SmallTest | Level2)
487 {
488     sptr<WindowNode> node1 = new WindowNode();
489     node1->SetWindowProperty(CreateWindowProperty(100));
490     ASSERT_NE(nullptr, node1);
491     node1->isShowingOnMultiDisplays_ = true;
492     displayGroupController_->PreProcessWindowNode(node1, WindowUpdateType::WINDOW_UPDATE_ADDED);
493     Rect actualRect = node1->GetRequestRect();
494     Rect expectRect = {0, 0, 0, 0};
495     ASSERT_EQ(expectRect, actualRect);
496 }
497 
498 
499 /**
500  * @tc.name: PostProcessWindowNode01
501  * @tc.desc: PostProcessWindowNode with multi display is true
502  * @tc.type: FUNC
503  */
504 HWTEST_F(DisplayGroupControllerTest, PostProcessWindowNode01, Function | SmallTest | Level2)
505 {
506     sptr<WindowNode> node1 = new WindowNode();
507     node1->SetWindowProperty(CreateWindowProperty(100));
508     ASSERT_NE(nullptr, node1);
509     container_->GetLayoutPolicy()->isMultiDisplay_ = true;
510     ASSERT_EQ(true, container_->GetLayoutPolicy()->IsMultiDisplay());
511 }
512 
513 /**
514  * @tc.name: UpdateWindowDisplayId01
515  * @tc.desc: UpdateWindowDisplayId with windowToken
516  * @tc.type: FUNC
517  */
518 HWTEST_F(DisplayGroupControllerTest, UpdateWindowDisplayId01, Function | SmallTest | Level2)
519 {
520     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
521     sptr<IWindow> iWindow = iface_cast<IWindow>(iRemoteObjectMocker);
522     ASSERT_NE(nullptr, iWindow);
523     sptr<WindowNode> node1 = new WindowNode();
524     node1->SetWindowProperty(CreateWindowProperty(100));
525     ASSERT_NE(nullptr, node1);
526     node1->SetWindowToken(iWindow);
527     ASSERT_NE(nullptr, node1->GetWindowToken());
528     displayGroupController_->UpdateWindowDisplayId(node1, 1);
529     ASSERT_EQ(1, node1->GetDisplayId());
530 }
531 
532 /**
533  * @tc.name: MoveCrossNodeToTargetDisplay01
534  * @tc.desc: TargetDisplayId equals to default displayId
535  * @tc.type: FUNC
536  */
537 HWTEST_F(DisplayGroupControllerTest, MoveCrossNodeToTargetDisplay01, Function | SmallTest | Level2)
538 {
539     sptr<WindowNode> node1 = new WindowNode();
540     node1->SetWindowProperty(CreateWindowProperty(100));
541     ASSERT_NE(nullptr, node1);
542     sptr<WindowNode> child = new WindowNode();
543     child->SetWindowProperty(CreateWindowProperty(101));
544     ASSERT_NE(nullptr, child);
545     node1->children_.push_back(child);
546     displayGroupController_->MoveCrossNodeToTargetDisplay(node1, 0);
547     auto showingDisplays = child->GetShowingDisplays();
548     ASSERT_NE(0, showingDisplays.size());
549     ASSERT_EQ(0, showingDisplays[0]);
550 }
551 
552 /**
553  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay01
554  * @tc.desc: DisplayId equals to defaultDisplayId
555  * @tc.type: FUNC
556  */
557 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay01, Function | SmallTest | Level2)
558 {
559     std::vector<uint32_t> windowIds;
560     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(0, windowIds);
561     ASSERT_EQ(0, windowIds.size());
562 }
563 
564 /**
565  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay04
566  * @tc.desc: Node with WINDOW_TYPE_STATUS_BAR
567  * @tc.type: FUNC
568  */
569 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay04, Function | SmallTest | Level2)
570 {
571     displayGroupController_->InitNewDisplay(1);
572     SetDisplayGroupInfo(1, {200, 200, 200, 200});
573     sptr<WindowNode> node1 = new WindowNode();
574     node1->SetWindowProperty(CreateWindowProperty(100, WindowType::WINDOW_TYPE_STATUS_BAR));
575     ASSERT_NE(nullptr, node1);
576     displayGroupController_->InitNewDisplay(1);
577     SetDisplayGroupInfo(1, {200, 200, 200, 200});
578     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
579         1, WindowRootNodeType::ABOVE_WINDOW_NODE);
580     rootApp->push_back(node1);
581     node1->SetDisplayId(1);
582     std::vector<uint32_t> windowIds;
583     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
584     ASSERT_EQ(1, windowIds.size());
585     ASSERT_EQ(1, node1->GetDisplayId());
586 }
587 
588 /**
589  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay06
590  * @tc.desc: Execute to move to default display
591  * @tc.type: FUNC
592  */
593 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay06, Function | SmallTest | Level2)
594 {
595     displayGroupController_->InitNewDisplay(1);
596     SetDisplayGroupInfo(1, {200, 200, 200, 200});
597     sptr<WindowNode> node1 = new WindowNode();
598     node1->SetWindowProperty(CreateWindowProperty(100));
599     ASSERT_NE(nullptr, node1);
600     displayGroupController_->InitNewDisplay(1);
601     SetDisplayGroupInfo(1, {200, 200, 200, 200});
602     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
603         1, WindowRootNodeType::APP_WINDOW_NODE);
604     rootApp->push_back(node1);
605     node1->SetDisplayId(1);
606     std::vector<uint32_t> windowIds;
607     windowIds.push_back(node1->GetWindowId());
608     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
609     ASSERT_EQ(0, node1->GetDisplayId());
610     rootApp->clear();
611 }
612 
613 /**
614  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay07
615  * @tc.desc: DisplayId not equals to defaultDisplayId, and no node on groupWindowTree
616  * @tc.type: FUNC
617  */
618 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay07, Function | SmallTest | Level2)
619 {
620     displayGroupController_->InitNewDisplay(1);
621     SetDisplayGroupInfo(1, {200, 200, 200, 200});
622     std::vector<uint32_t> windowIds;
623     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
624     ASSERT_EQ(0, windowIds.size());
625 }
626 
627 /**
628  * @tc.name: UpdateNodeSizeChangeReasonWithRotation02
629  * @tc.desc: UpdateNodeSizeChangeReasonWithRotation failed
630  * @tc.type: FUNC
631  */
632 HWTEST_F(DisplayGroupControllerTest, UpdateNodeSizeChangeReasonWithRotation02, Function | SmallTest | Level2)
633 {
634     sptr<WindowNode> node1 = new WindowNode();
635     node1->SetWindowProperty(CreateWindowProperty(100, WindowType::WINDOW_TYPE_DOCK_SLICE));
636     ASSERT_NE(nullptr, node1);
637     std::vector<sptr<WindowNode>>* rootApp = displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
638         0, WindowRootNodeType::ABOVE_WINDOW_NODE);
639     rootApp->push_back(node1);
640     displayGroupController_->UpdateNodeSizeChangeReasonWithRotation(0, displayGroupInfo_.GetAllDisplayRects());
641     ASSERT_NE(WindowSizeChangeReason::ROTATION, node1->GetWindowSizeChangeReason());
642 }
643 
644 /**
645  * @tc.name: UpdateNodeSizeChangeReasonWithRotation03
646  * @tc.desc: UpdateNodeSizeChangeReasonWithRotation with rootNodeVectorPtr null
647  * @tc.type: FUNC
648  */
649 HWTEST_F(DisplayGroupControllerTest, UpdateNodeSizeChangeReasonWithRotation03, Function | SmallTest | Level2)
650 {
651     displayGroupController_->displayGroupWindowTree_[0].erase(WindowRootNodeType::ABOVE_WINDOW_NODE);
652     ASSERT_EQ(nullptr, displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
653         0, WindowRootNodeType::ABOVE_WINDOW_NODE));
654     displayGroupController_->UpdateNodeSizeChangeReasonWithRotation(0, displayGroupInfo_.GetAllDisplayRects());
655     ASSERT_EQ(nullptr, displayGroupController_->GetWindowNodesByDisplayIdAndRootType(
656         0, WindowRootNodeType::ABOVE_WINDOW_NODE));
657 }
658 
659 /**
660  * @tc.name: ProcessDisplayChange01
661  * @tc.desc: ProcessDisplayChange with different DisplayStateChangeType
662  * @tc.type: FUNC
663  */
664 HWTEST_F(DisplayGroupControllerTest, ProcessDisplayChange01, Function | SmallTest | Level2)
665 {
666     sptr<DisplayInfo> displayInfo = new DisplayInfo();
667     ASSERT_NE(nullptr, displayInfo);
668     displayInfo->SetDisplayId(0);
669     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
670         DisplayStateChangeType::UPDATE_ROTATION);
671     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
672         DisplayStateChangeType::DISPLAY_COMPRESS);
673     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
674         DisplayStateChangeType::SIZE_CHANGE);
675     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
676         DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE);
677     displayGroupController_->ProcessDisplayChange(0, displayInfo, displayGroupInfo_.GetAllDisplayRects(),
678         DisplayStateChangeType::DESTROY);
679 }
680 
681 /**
682  * @tc.name: ProcessDisplaySizeChangeOrRotation01
683  * @tc.desc: ProcessDisplaySizeChangeOrRotation with layout policy null
684  * @tc.type: FUNC
685  */
686 HWTEST_F(DisplayGroupControllerTest, ProcessDisplaySizeChangeOrRotation01, Function | SmallTest | Level2)
687 {
688     auto oriLayoutPolicy = container_->GetLayoutPolicy();
689     container_->layoutPolicy_ = nullptr;
690     displayGroupController_->ProcessDisplaySizeChangeOrRotation(0, 0, displayGroupInfo_.GetAllDisplayRects(),
691         DisplayStateChangeType::UPDATE_ROTATION);
692     ASSERT_EQ(nullptr, container_->GetLayoutPolicy());
693     container_->layoutPolicy_ = oriLayoutPolicy;
694 }
695 
696 /**
697  * @tc.name: GetWindowPairByDisplayId
698  * @tc.desc: GetWindowPairByDisplayId with displayId 1, which not exists
699  * @tc.type: FUNC
700  */
701 HWTEST_F(DisplayGroupControllerTest, GetWindowPairByDisplayId01, Function | SmallTest | Level2)
702 {
703     ASSERT_EQ(nullptr, displayGroupController_->GetWindowPairByDisplayId(1));
704 }
705 
706 /**
707  * @tc.name: ProcessDisplayCreate
708  * @tc.desc: ProcessDisplayCreate
709  * @tc.type: FUNC
710  */
711 HWTEST_F(DisplayGroupControllerTest, ProcessDisplayCreate, Function | SmallTest | Level2)
712 {
713     DisplayId defaultDisplayId = 0;
714     sptr<DisplayInfo> displayInfo = new DisplayInfo();
715     std::map<DisplayId, Rect> displayRectMap;
716     displayGroupController_->ProcessDisplayCreate(defaultDisplayId, displayInfo, displayRectMap);
717     auto layoutPolicy = container_->GetLayoutPolicy();
718     ASSERT_NE(nullptr, layoutPolicy);
719 }
720 
721 /**
722  * @tc.name: ProcessDisplayDestroy
723  * @tc.desc: ProcessDisplayDestroy
724  * @tc.type: FUNC
725  */
726 HWTEST_F(DisplayGroupControllerTest, ProcessDisplayDestroy, Function | SmallTest | Level2)
727 {
728     DisplayId defaultDisplayId = 0;
729     sptr<DisplayInfo> displayInfo = new DisplayInfo();
730     std::map<DisplayId, Rect> displayRectMap;
731     std::vector<uint32_t> windowIds;
732     displayGroupController_->ProcessDisplayDestroy(defaultDisplayId, displayInfo,
733                                                    displayRectMap, windowIds);
734     auto layoutPolicy = container_->GetLayoutPolicy();
735     ASSERT_NE(nullptr, layoutPolicy);
736 }
737 
738 /**
739  * @tc.name: ProcessSystemBarRotation
740  * @tc.desc: ProcessSystemBarRotation
741  * @tc.type: FUNC
742  */
743 HWTEST_F(DisplayGroupControllerTest, ProcessSystemBarRotation, Function | SmallTest | Level2)
744 {
745     sptr<WindowNode> node = new WindowNode();
746     node->SetWindowProperty(CreateWindowProperty(100));
747     ASSERT_NE(nullptr, node);
748     std::map<DisplayId, Rect> displayRectMap = {};
749     displayGroupController_->ProcessSystemBarRotation(node, displayRectMap);
750     auto layoutPolicy = container_->GetLayoutPolicy();
751     ASSERT_NE(nullptr, layoutPolicy);
752 }
753 
754 /**
755  * @tc.name: ProcessWindowPairWhenDisplayChange
756  * @tc.desc: ProcessWindowPairWhenDisplayChange
757  * @tc.type: FUNC
758  */
759 HWTEST_F(DisplayGroupControllerTest, ProcessWindowPairWhenDisplayChange, Function | SmallTest | Level2)
760 {
761     bool rotateDisplay = true;
762     displayGroupController_->ProcessWindowPairWhenDisplayChange(rotateDisplay);
763     auto layoutPolicy = container_->GetLayoutPolicy();
764     layoutPolicy = nullptr;
765     ASSERT_EQ(nullptr, layoutPolicy);
766 }
767 /**
768  * @tc.name: ProcessNotCrossNodesOnDestroyedDisplay08
769  * @tc.desc: DisplayId not equals to defaultDisplayId, and no node on groupWindowTree
770  * @tc.type: FUNC
771  */
772 HWTEST_F(DisplayGroupControllerTest, ProcessNotCrossNodesOnDestroyedDisplay08, Function | SmallTest | Level2)
773 {
774     DisplayId displayId = 0;
775     std::vector<uint32_t> windowIds;
776     DisplayGroupWindowTree displayGroupWindowTree_;
777     displayGroupWindowTree_.find(displayId) = displayGroupWindowTree_.end();
778     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
779     ASSERT_EQ(0, windowIds.size());
780 }
781 
782 /**
783  * @tc.name: SetSplitRatioConfig
784  * @tc.desc:SetSplitRatioConfig
785  * @tc.type: FUNC
786  */
787 HWTEST_F(DisplayGroupControllerTest, SetSplitRatioConfig, Function | SmallTest | Level2)
788 {
789     DisplayId displayId = 0;
790     std::vector<uint32_t> windowIds;
791     SplitRatioConfig splitRatioConfig;
792     displayGroupController_->SetSplitRatioConfig(splitRatioConfig);
793     auto windowPair = displayGroupController_->GetWindowPairByDisplayId(displayId);
794     windowPair = nullptr;
795     DisplayGroupWindowTree displayGroupWindowTree_;
796     displayGroupWindowTree_.find(displayId) = displayGroupWindowTree_.end();
797     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
798     ASSERT_EQ(0, windowIds.size());
799 }
800 
801 /**
802  * @tc.name: UpdateSplitRatioPoints01
803  * @tc.desc:UpdateSplitRatioPoints
804  * @tc.type: FUNC
805  */
806 HWTEST_F(DisplayGroupControllerTest, UpdateSplitRatioPoints01, Function | SmallTest | Level2)
807 {
808     DisplayId displayId = 0;
809     std::vector<uint32_t> windowIds;
810     auto windowPair = displayGroupController_->GetWindowPairByDisplayId(displayId);
811     windowPair = nullptr;
812     displayGroupController_->UpdateSplitRatioPoints(displayId);
813     DisplayGroupWindowTree displayGroupWindowTree_;
814     displayGroupWindowTree_.find(displayId) = displayGroupWindowTree_.end();
815     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
816     ASSERT_EQ(0, windowIds.size());
817 }
818 
819 /**
820  * @tc.name: UpdateSplitRatioPoints02
821  * @tc.desc:UpdateSplitRatioPoints
822  * @tc.type: FUNC
823  */
824 HWTEST_F(DisplayGroupControllerTest, UpdateSplitRatioPoints02, Function | SmallTest | Level2)
825 {
826     DisplayId displayId = 0;
827     std::vector<uint32_t> windowIds;
828     auto displayRects = DisplayGroupInfo::GetInstance().GetAllDisplayRects();
829     displayRects.find(displayId) = displayRects.end();
830     displayGroupController_->UpdateSplitRatioPoints(displayId);
831     DisplayGroupWindowTree displayGroupWindowTree_;
832     displayGroupWindowTree_.find(displayId) = displayGroupWindowTree_.end();
833     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
834     ASSERT_EQ(0, windowIds.size());
835 }
836 
837 /**
838  * @tc.name: UpdateSplitRatioPoints03
839  * @tc.desc:UpdateSplitRatioPoints
840  * @tc.type: FUNC
841  */
842 HWTEST_F(DisplayGroupControllerTest, UpdateSplitRatioPoints03, Function | SmallTest | Level2)
843 {
844     DisplayId displayId = 0;
845     std::vector<uint32_t> windowIds;
846     auto layoutPolicy = container_->GetLayoutPolicy();
847     layoutPolicy = nullptr;
848     displayGroupController_->UpdateSplitRatioPoints(displayId);
849     DisplayGroupWindowTree displayGroupWindowTree_;
850     displayGroupWindowTree_.find(displayId) = displayGroupWindowTree_.end();
851     displayGroupController_->ProcessNotCrossNodesOnDestroyedDisplay(1, windowIds);
852     ASSERT_EQ(0, windowIds.size());
853 }
854 
855 /**
856  * @tc.name: PreProcessWindowNode05
857  * @tc.desc:UpdateSplitRatioPoints
858  * @tc.type: FUNC
859  */
860 HWTEST_F(DisplayGroupControllerTest, PreProcessWindowNode05, Function | SmallTest | Level2)
861 {
862     WindowUpdateType type = WindowUpdateType::WINDOW_UPDATE_ACTIVE;
863     sptr<WindowNode> node1 = new WindowNode();
864     node1->SetWindowProperty(CreateWindowProperty(100));
865     ASSERT_NE(nullptr, node1);
866     displayGroupController_->PreProcessWindowNode(node1, type);
867     if (type != WindowUpdateType::WINDOW_UPDATE_ADDED)
868     {
869         type = WindowUpdateType::WINDOW_UPDATE_ADDED;
870     }
871     std::vector<uint32_t> windowIds;
872     ASSERT_EQ(0, windowIds.size());
873 }
874 }
875 }
876 }
877