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