1 /*
2 * Copyright (c) 2022-2023 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 "display_group_controller.h"
18 #include "display_group_info.h"
19 #include "display_manager.h"
20 #include "remote_animation.h"
21 #include "window_helper.h"
22 #include "window_layout_policy.h"
23 #include "window_layout_policy_cascade.h"
24 #include "window_layout_policy_tile.h"
25 #include "window_node_container.h"
26 #include "window_layout_policy.h"
27 #include "display_manager_service_inner.h"
28 #include "window_inner_manager.h"
29 #include "window_manager_hilog.h"
30 #include "wm_common_inner.h"
31 #include "wm_math.h"
32 #include "window_node.h"
33 #include <transaction/rs_sync_transaction_controller.h>
34 #include "display.h"
35 #include "persistent_storage.h"
36
37 using namespace testing;
38 using namespace testing::ext;
39
40 namespace OHOS {
41 namespace Rosen {
42
43 struct WindowInfo {
44 Rect winRect_;
45 WindowType winType_;
46 WindowMode winMode_;
47 WindowSizeChangeReason reason_;
48 DragType dragType_;
49 bool decorEnable_;
50 };
51
52 class WindowLayoutPolicyTest : public testing::Test {
53 public:
54 static void SetUpTestCase();
55 static void TearDownTestCase();
56 virtual void SetUp() override;
57 virtual void TearDown() override;
58 sptr<WindowNode> CreateWindowNode(const WindowInfo& windowInfo);
59 sptr<DisplayInfo> CreateDisplayInfo(const Rect& displayRect);
60
61 static WindowInfo windowInfo_;
62 static sptr<WindowNodeContainer> container_;
63 static DisplayGroupInfo& displayGroupInfo_;
64 static sptr<DisplayInfo> defaultDisplayInfo_;
65 static sptr<DisplayGroupController> displayGroupController_;
66 static sptr<WindowLayoutPolicyCascade> layoutPolicy_;
67 static sptr<WindowLayoutPolicyTile> layoutPolicyTile_;
68 };
69
70 sptr<WindowNodeContainer> WindowLayoutPolicyTest::container_ = nullptr;
71 DisplayGroupInfo& WindowLayoutPolicyTest::displayGroupInfo_ = DisplayGroupInfo::GetInstance();
72 sptr<DisplayGroupController> WindowLayoutPolicyTest::displayGroupController_ = nullptr;
73 sptr<WindowLayoutPolicyCascade> WindowLayoutPolicyTest::layoutPolicy_ = nullptr;
74 sptr<WindowLayoutPolicyTile> WindowLayoutPolicyTest::layoutPolicyTile_ = nullptr;
75 sptr<DisplayInfo> WindowLayoutPolicyTest::defaultDisplayInfo_ = nullptr;
76 WindowInfo WindowLayoutPolicyTest::windowInfo_ = {
77 .winRect_ = { 0, 0, 0, 0 },
78 .winType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
79 .winMode_ = WindowMode::WINDOW_MODE_FLOATING,
80 .reason_ = WindowSizeChangeReason::UNDEFINED,
81 .dragType_ = DragType::DRAG_UNDEFINED,
82 .decorEnable_ = false,
83 };
84
SetUpTestCase()85 void WindowLayoutPolicyTest::SetUpTestCase()
86 {
87 auto display = DisplayManager::GetInstance().GetDefaultDisplay();
88 ASSERT_TRUE((display != nullptr));
89
90 DisplayGroupInfo::GetInstance().Init(0, display->GetDisplayInfo());
91
92 defaultDisplayInfo_ = display->GetDisplayInfo();
93 ASSERT_TRUE((defaultDisplayInfo_ != nullptr));
94
95 windowInfo_ = {
96 .winRect_ = { 0, 0, 0, 0 },
97 .winType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
98 .winMode_ = WindowMode::WINDOW_MODE_FLOATING,
99 .reason_ = WindowSizeChangeReason::UNDEFINED,
100 .dragType_ = DragType::DRAG_UNDEFINED,
101 .decorEnable_ = false,
102 };
103
104 container_ = new WindowNodeContainer(defaultDisplayInfo_, display->GetScreenId());
105 displayGroupController_ = container_->displayGroupController_;
106 layoutPolicy_ = static_cast<WindowLayoutPolicyCascade*>(container_->GetLayoutPolicy().GetRefPtr());
107 layoutPolicyTile_ = static_cast<WindowLayoutPolicyTile*>(container_->GetLayoutPolicy().GetRefPtr());
108 }
109
TearDownTestCase()110 void WindowLayoutPolicyTest::TearDownTestCase()
111 {
112 container_ = nullptr;
113 defaultDisplayInfo_ = nullptr;
114 displayGroupController_ = nullptr;
115 layoutPolicy_ = nullptr;
116 layoutPolicyTile_ = nullptr;
117 }
118
SetUp()119 void WindowLayoutPolicyTest::SetUp()
120 {
121 displayGroupInfo_.AddDisplayInfo(defaultDisplayInfo_);
122 }
123
TearDown()124 void WindowLayoutPolicyTest::TearDown()
125 {
126 displayGroupInfo_.displayInfosMap_.clear();
127 }
128
CreateWindowNode(const WindowInfo & windowInfo)129 sptr<WindowNode> WindowLayoutPolicyTest::CreateWindowNode(const WindowInfo& windowInfo)
130 {
131 sptr<WindowProperty> property = new WindowProperty();
132 property->SetWindowType(windowInfo.winType_);
133 property->SetWindowMode(windowInfo.winMode_);
134 property->SetWindowRect(windowInfo.winRect_);
135 property->SetOriginRect(windowInfo.winRect_);
136 property->SetDecorEnable(windowInfo.decorEnable_);
137 property->SetWindowSizeChangeReason(windowInfo.reason_);
138 property->SetDragType(windowInfo.dragType_);
139 property->SetDisplayId(0);
140 property->SetWindowId(0);
141 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
142 node->SetWindowProperty(property);
143 return node;
144 }
145
CreateDisplayInfo(const Rect & displayRect)146 sptr<DisplayInfo> WindowLayoutPolicyTest::CreateDisplayInfo(const Rect& displayRect)
147 {
148 sptr<DisplayInfo> displayInfo = new DisplayInfo();
149 displayInfo->SetOffsetX(displayRect.posX_);
150 displayInfo->SetOffsetY(displayRect.posY_);
151 displayInfo->SetWidth(displayRect.width_);
152 displayInfo->SetHeight(displayRect.height_);
153 displayInfo->SetDisplayId((defaultDisplayInfo_->GetDisplayId() + 1));
154 return displayInfo;
155 }
156 namespace {
157 /**
158 * @tc.name: CalcEntireWindowHotZone
159 * @tc.desc: calc entire window hot zone
160 * @tc.type: FUNC
161 * @tc.require issueI5LYDC
162 */
163 HWTEST_F(WindowLayoutPolicyTest, CalcEntireWindowHotZone, Function | SmallTest | Level2)
164 {
165 TransformHelper::Vector2 hotZoneScale = {1.f, 1.f}; // ratio 1.0
166 sptr<WindowProperty> property = new WindowProperty();
167
168 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
169 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
170 sptr<WindowNode> node0 = new WindowNode(property, nullptr, nullptr);
171 node0->SetWindowProperty(property);
172 Rect winRect = { 50, 100, 400, 500 }; // rect: 50, 100, 400, 500
173 auto actRect0 = layoutPolicy_->CalcEntireWindowHotZone(node0, winRect, 10, 2.f, hotZoneScale); // param: 10, 2.0
174 Rect expRect0 = { 30, 80, 440, 540 }; // rect: 30, 80, 440, 540
175 ASSERT_EQ(expRect0, actRect0);
176
177 property->SetWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE);
178 sptr<WindowNode> node1 = new WindowNode(property, nullptr, nullptr);
179 node1->SetWindowProperty(property);
180 auto actRect1 = layoutPolicy_->CalcEntireWindowHotZone(node1, winRect, 10, 2.f, hotZoneScale); // param: 10, 2.0
181 Rect expRect1 = { 30, 100, 440, 500 }; // rect: 30, 100, 440, 500
182 ASSERT_EQ(expRect1, actRect1);
183
184 property->SetWindowType(WindowType::WINDOW_TYPE_LAUNCHER_RECENT);
185 sptr<WindowNode> node2 = new WindowNode(property, nullptr, nullptr);
186 node2->SetWindowProperty(property);
187 auto actRect2 = layoutPolicy_->CalcEntireWindowHotZone(node2, winRect, 10, 2.f, hotZoneScale); // param: 10, 2.0
188 Rect expRect2 = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
189 ASSERT_EQ(expRect2, actRect2);
190 }
191
192 /**
193 * @tc.name: UpdateFloatingWindowSizeForStretchableWindow01
194 * @tc.desc: UpdateFloatingWindowSizeForStretchableWindow test for drag width
195 * @tc.type: FUNC
196 */
197 HWTEST_F(WindowLayoutPolicyTest, UpdateFloatingWindowSizeForStretchableWindow01, Function | SmallTest | Level2)
198 {
199 windowInfo_.winRect_ = { 50, 50, 100, 150 }; // rect: 50, 50, 100, 150
200 windowInfo_.dragType_ = DragType::DRAG_LEFT_OR_RIGHT;
201 windowInfo_.reason_ = WindowSizeChangeReason::DRAG;
202 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
203 Rect newWinRect = { 50, 50, 200, 200 }; // rect: 50, 50, 200, 200
204 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, { 0, 0, 0, 0 }, newWinRect);
205 Rect expRect = { 50, 50, 200, 300 }; // rect: 50, 50, 200, 300
206 ASSERT_EQ(expRect, expRect);
207 }
208
209 /**
210 * @tc.name: UpdateFloatingWindowSizeForStretchableWindow02
211 * @tc.desc: UpdateFloatingWindowSizeForStretchableWindow test for drag coner
212 * @tc.type: FUNC
213 */
214 HWTEST_F(WindowLayoutPolicyTest, UpdateFloatingWindowSizeForStretchableWindow02, Function | SmallTest | Level2)
215 {
216 windowInfo_.winRect_ = { 50, 50, 100, 150 }; // rect: 50, 50, 100, 150
217 windowInfo_.dragType_ = DragType::DRAG_LEFT_TOP_CORNER;
218 windowInfo_.reason_ = WindowSizeChangeReason::DRAG;
219 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
220 Rect newWinRect = { 50, 50, 200, 200 }; // rect: 50, 50, 200, 200
221 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, { 0, 0, 0, 0 }, newWinRect);
222 Rect expRect = { 50, 50, 200, 300 }; // rect: 50, 50, 200, 300
223 ASSERT_EQ(expRect, expRect);
224 }
225
226 /**
227 * @tc.name: UpdateFloatingWindowSizeForStretchableWindow03
228 * @tc.desc: UpdateFloatingWindowSizeForStretchableWindow test for drag height
229 * @tc.type: FUNC
230 */
231 HWTEST_F(WindowLayoutPolicyTest, UpdateFloatingWindowSizeForStretchableWindow03, Function | SmallTest | Level2)
232 {
233 windowInfo_.winRect_ = { 50, 50, 100, 150 }; // rect: 50, 50, 100, 150
234 windowInfo_.dragType_ = DragType::DRAG_BOTTOM_OR_TOP;
235 windowInfo_.reason_ = WindowSizeChangeReason::DRAG;
236 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
237 Rect newWinRect = { 50, 50, 150, 300 }; // rect: 50, 50, 150, 300
238 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, { 0, 0, 0, 0 }, newWinRect);
239 Rect expRect = { 50, 50, 200, 300 }; // rect: 50, 50, 200, 300
240 ASSERT_EQ(expRect, expRect);
241 }
242
243 /**
244 * @tc.name: LimitWindowToBottomRightCorner
245 * @tc.desc: test LimitWindowToBottomRightCorner01
246 * @tc.type: FUNC
247 */
248 HWTEST_F(WindowLayoutPolicyTest, LimitWindowToBottomRightCorner01, Function | SmallTest | Level2)
249 {
250 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
251 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
252 windowInfo_.winRect_ = {
253 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_ * 0.5), // ratio: 0.5
254 .posY_ = displayRect.posY_,
255 .width_ = displayRect.width_,
256 .height_ = displayRect.height_
257 };
258 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
259 ASSERT_TRUE(node != nullptr);
260 layoutPolicy_->LimitWindowToBottomRightCorner(node);
261
262 Rect winRect = {
263 .posX_ = displayRect.posX_,
264 .posY_ = displayRect.posY_,
265 .width_ = static_cast<uint32_t>(displayRect.width_ * 0.5), // ratio: 0.5
266 .height_ = static_cast<uint32_t>(displayRect.height_ * 0.5) // ratio: 0.5
267 };
268 node ->SetRequestRect(winRect);
269 layoutPolicy_->LimitWindowToBottomRightCorner(node);
270 }
271
272 /**
273 * @tc.name: LimitWindowToBottomRightCorner
274 * @tc.desc: test LimitWindowToBottomRightCorner02
275 * @tc.type: FUNC
276 */
277 HWTEST_F(WindowLayoutPolicyTest, LimitWindowToBottomRightCorner02, Function | SmallTest | Level2)
278 {
279 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
280 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
281 windowInfo_.winRect_ = {
282 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_ * 0.5), // ratio: 0.5
283 .posY_ = static_cast<int32_t>(displayRect.posY_ + displayRect.height_ * 0.5), // ratio: 0.5
284 .width_ = displayRect.width_,
285 .height_ = displayRect.height_
286 };
287 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
288 ASSERT_TRUE(node != nullptr);
289 layoutPolicy_->LimitWindowToBottomRightCorner(node);
290
291 Rect winRect = {
292 .posX_ = displayRect.posX_,
293 .posY_ = static_cast<int32_t>(displayRect.posY_ + displayRect.height_ * 0.5), // ratio: 0.5
294 .width_ = displayRect.width_,
295 .height_ = displayRect.height_
296 };
297 node ->SetRequestRect(winRect);
298 layoutPolicy_->LimitWindowToBottomRightCorner(node);
299 ASSERT_TRUE(node != nullptr);
300 }
301
302 /**
303 * @tc.name: LimitWindowToBottomRightCorner
304 * @tc.desc: test LimitWindowToBottomRightCorner03, test childNode
305 * @tc.type: FUNC
306 */
307 HWTEST_F(WindowLayoutPolicyTest, LimitWindowToBottomRightCorner03, Function | SmallTest | Level2)
308 {
309 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
310 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
311 windowInfo_.winRect_ = {
312 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_ * 0.5), // ratio: 0.5
313 .posY_ = static_cast<int32_t>(displayRect.posY_ + displayRect.height_ * 0.5), // ratio: 0.5
314 .width_ = displayRect.width_,
315 .height_ = displayRect.height_
316 };
317 sptr<WindowNode> parentNode = CreateWindowNode(windowInfo_);
318 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
319 ASSERT_TRUE(parentNode != nullptr);
320 ASSERT_TRUE(node != nullptr);
321 parentNode->children_.push_back(node);
322 layoutPolicy_->LimitWindowToBottomRightCorner(node);
323 }
324
325 /**
326 * @tc.name: UpdateDisplayGroupRect
327 * @tc.desc: test UpdateDisplayGroupRect
328 * @tc.type: FUNC
329 */
330 HWTEST_F(WindowLayoutPolicyTest, UpdateDisplayGroupRect, Function | SmallTest | Level2)
331 {
332 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
333 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
334
335 Rect newDisplayRect = {
336 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_),
337 .posY_ = displayRect.posY_,
338 .width_ = 1920, // width: 1920
339 .height_ = 1280 // height: 1080
340 };
341 auto displayInfo = CreateDisplayInfo(newDisplayRect);
342 ASSERT_TRUE(displayInfo != nullptr);
343 displayGroupInfo_.AddDisplayInfo(displayInfo);
344 layoutPolicy_->UpdateDisplayGroupRect();
345
346 displayGroupInfo_.displayInfosMap_.clear();
347 layoutPolicy_->UpdateDisplayGroupRect();
348 }
349
350 /**
351 * @tc.name: UpdateDisplayGroupLimitRect
352 * @tc.desc: test UpdateDisplayGroupLimitRect
353 * @tc.type: FUNC
354 */
355 HWTEST_F(WindowLayoutPolicyTest, UpdateDisplayGroupLimitRect, Function | SmallTest | Level2)
356 {
357 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
358 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
359 Rect newDisplayRect = {
360 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_),
361 .posY_ = displayRect.posY_,
362 .width_ = 1920, // width: 1920
363 .height_ = 1280 // height: 1080
364 };
365 auto displayInfo = CreateDisplayInfo(newDisplayRect);
366 ASSERT_TRUE(displayInfo != nullptr);
367 displayGroupInfo_.AddDisplayInfo(displayInfo);
368 auto allDisplayRect = displayGroupInfo_.GetAllDisplayRects();
369 layoutPolicy_->limitRectMap_ = allDisplayRect;
370 layoutPolicy_->UpdateDisplayGroupLimitRect();
371
372 layoutPolicy_->limitRectMap_.clear();
373 layoutPolicy_->UpdateDisplayGroupLimitRect();
374 }
375
376 /**
377 * @tc.name: UpdateRectInDisplayGroup
378 * @tc.desc: test UpdateRectInDisplayGroup, test childNode
379 * @tc.type: FUNC
380 */
381 HWTEST_F(WindowLayoutPolicyTest, UpdateRectInDisplayGroup, Function | SmallTest | Level2)
382 {
383 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
384 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
385 windowInfo_.winRect_ = {
386 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_ * 0.5), // ratio: 0.5
387 .posY_ = static_cast<int32_t>(displayRect.posY_ + displayRect.height_ * 0.5), // ratio: 0.5
388 .width_ = displayRect.width_,
389 .height_ = displayRect.height_
390 };
391 sptr<WindowNode> parentNode = CreateWindowNode(windowInfo_);
392 ASSERT_TRUE(parentNode != nullptr);
393
394 Rect newDisplayRect = {
395 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_),
396 .posY_ = displayRect.posY_,
397 .width_ = 1920, // width: 1920
398 .height_ = 1280 // height: 1080
399 };
400 layoutPolicy_->UpdateRectInDisplayGroup(parentNode, displayRect, newDisplayRect);
401
402 // create child node
403 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
404 ASSERT_TRUE(node != nullptr);
405 parentNode->children_.push_back(node);
406 layoutPolicy_->UpdateRectInDisplayGroup(parentNode, displayRect, newDisplayRect);
407 }
408
409 /**
410 * @tc.name: UpdateMultiDisplayFlag
411 * @tc.desc: test UpdateMultiDisplayFlag
412 * @tc.type: FUNC
413 */
414 HWTEST_F(WindowLayoutPolicyTest, UpdateMultiDisplayFlag, Function | SmallTest | Level2)
415 {
416 layoutPolicy_->UpdateMultiDisplayFlag();
417
418 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
419 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
420 Rect newDisplayRect = {
421 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_),
422 .posY_ = displayRect.posY_,
423 .width_ = 1920, // width: 1920
424 .height_ = 1280 // height: 1080
425 };
426 auto displayInfo = CreateDisplayInfo(newDisplayRect);
427 ASSERT_TRUE(displayInfo != nullptr);
428 displayGroupInfo_.AddDisplayInfo(displayInfo);
429 layoutPolicy_->UpdateMultiDisplayFlag();
430 }
431
432 /**
433 * @tc.name: UpdateRectInDisplayGroupForAllNodes01
434 * @tc.desc: test UpdateRectInDisplayGroupForAllNodes01
435 * @tc.type: FUNC
436 */
437 HWTEST_F(WindowLayoutPolicyTest, UpdateRectInDisplayGroupForAllNodes01, Function | SmallTest | Level2)
438 {
439 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
440 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
441 Rect newDisplayRect = {
442 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_),
443 .posY_ = displayRect.posY_,
444 .width_ = 1920, // width: 1920
445 .height_ = 1280 // height: 1080
446 };
447
448 layoutPolicy_->UpdateRectInDisplayGroupForAllNodes(0, displayRect, newDisplayRect);
449
450 windowInfo_.winRect_ = {
451 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_ * 0.5), // ratio: 0.5
452 .posY_ = static_cast<int32_t>(displayRect.posY_ + displayRect.height_ * 0.5), // ratio: 0.5
453 .width_ = displayRect.width_,
454 .height_ = displayRect.height_
455 };
456 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
457 ASSERT_TRUE(node != nullptr);
458
459 // Add node on display window tree
460 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::APP_WINDOW_NODE]->push_back(node);
461 layoutPolicy_->UpdateRectInDisplayGroupForAllNodes(0, displayRect, newDisplayRect);
462
463 node->isShowingOnMultiDisplays_ = true;
464 layoutPolicy_->UpdateRectInDisplayGroupForAllNodes(0, displayRect, newDisplayRect);
465 }
466
467 /**
468 * @tc.name: UpdateRectInDisplayGroupForAllNodes02
469 * @tc.desc: test UpdateRectInDisplayGroupForAllNodes
470 * @tc.type: FUNC
471 */
472 HWTEST_F(WindowLayoutPolicyTest, UpdateRectInDisplayGroupForAllNodes02, Function | SmallTest | Level2)
473 {
474 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
475 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
476 Rect newDisplayRect = {
477 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_),
478 .posY_ = displayRect.posY_,
479 .width_ = 1920, // width: 1920
480 .height_ = 1280 // height: 1080
481 };
482
483 windowInfo_.winRect_ = {
484 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_ * 0.5), // ratio: 0.5
485 .posY_ = static_cast<int32_t>(displayRect.posY_ + displayRect.height_ * 0.5), // ratio: 0.5
486 .width_ = displayRect.width_,
487 .height_ = displayRect.height_
488 };
489
490 // Add app node on display window tree
491 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
492 ASSERT_TRUE(node != nullptr);
493 node->isShowingOnMultiDisplays_ = true;
494 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::APP_WINDOW_NODE]->push_back(node);
495 layoutPolicy_->UpdateRectInDisplayGroupForAllNodes(0, displayRect, newDisplayRect);
496
497 // Add above node on display window tree
498 windowInfo_.winType_ = WindowType::WINDOW_TYPE_FLOAT_CAMERA;
499 sptr<WindowNode> aboveNode = CreateWindowNode(windowInfo_);
500 ASSERT_TRUE(aboveNode != nullptr);
501 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::ABOVE_WINDOW_NODE]->push_back(aboveNode);
502 layoutPolicy_->UpdateRectInDisplayGroupForAllNodes(0, displayRect, newDisplayRect);
503 }
504
505 /**
506 * @tc.name: UpdateDisplayRectAndDisplayGroupInfo
507 * @tc.desc: test UpdateDisplayRectAndDisplayGroupInfo
508 * @tc.type: FUNC
509 */
510 HWTEST_F(WindowLayoutPolicyTest, UpdateDisplayRectAndDisplayGroupInfo, Function | SmallTest | Level2)
511 {
512 auto baseSize = displayGroupInfo_.displayInfosMap_.size();
513 ASSERT_EQ(baseSize, 1);
514 auto defaultDisplayInfo = displayGroupInfo_.displayInfosMap_.at(0);
515 ASSERT_EQ(defaultDisplayInfo->GetDisplayId(), defaultDisplayInfo_->GetDisplayId());
516 auto displayId = defaultDisplayInfo->GetDisplayId();
517 Rect baseRect = { defaultDisplayInfo->GetOffsetX(), defaultDisplayInfo->GetOffsetY(),
518 defaultDisplayInfo->GetWidth(), defaultDisplayInfo->GetHeight() };
519
520 std::map<DisplayId, Rect> insertMapData = {};
521 layoutPolicy_->UpdateDisplayRectAndDisplayGroupInfo(insertMapData);
522 auto rectInfo = displayGroupInfo_.GetDisplayRect(displayId);
523 ASSERT_EQ(rectInfo.posX_, baseRect.posX_);
524 ASSERT_EQ(rectInfo.posY_, baseRect.posY_);
525 ASSERT_EQ(rectInfo.width_, baseRect.width_);
526 ASSERT_EQ(rectInfo.height_, baseRect.height_);
527
528 insertMapData.clear();
529 insertMapData.insert(std::make_pair(0, Rect{10, 10, 10, 10}));
530 layoutPolicy_->UpdateDisplayRectAndDisplayGroupInfo(insertMapData);
531 rectInfo = displayGroupInfo_.GetDisplayRect(displayId);
532 ASSERT_EQ(rectInfo.posX_, 10);
533 ASSERT_EQ(rectInfo.posY_, 10);
534 ASSERT_EQ(rectInfo.width_, 10);
535 ASSERT_EQ(rectInfo.height_, 10);
536 }
537
538 /**
539 * @tc.name: ProcessDisplayCreate
540 * @tc.desc: test ProcessDisplayCreate
541 * @tc.type: FUNC
542 */
543 HWTEST_F(WindowLayoutPolicyTest, ProcessDisplayCreate, Function | SmallTest | Level2)
544 {
545 std::map<DisplayId, Rect> newDisplayRectMap = {};
546 layoutPolicy_->ProcessDisplayCreate(0, newDisplayRectMap);
547
548 layoutPolicy_->ProcessDisplayCreate(1, newDisplayRectMap);
549
550 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
551 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
552 newDisplayRectMap.insert(std::make_pair(0, displayRect));
553 Rect newDisplayRect = {
554 .posX_ = static_cast<int32_t>(displayRect.posX_ + displayRect.width_),
555 .posY_ = displayRect.posY_,
556 .width_ = 1920, // width: 1920
557 .height_ = 1280 // height: 1080
558 };
559 newDisplayRectMap.insert(std::make_pair(1, newDisplayRect));
560 layoutPolicy_->ProcessDisplayCreate(1, newDisplayRectMap);
561
562 auto displayInfo = CreateDisplayInfo(newDisplayRect);
563 ASSERT_TRUE(displayInfo != nullptr);
564 }
565
566 /**
567 * @tc.name: ProcessDisplayDestroy
568 * @tc.desc: test ProcessDisplayDestroy
569 * @tc.type: FUNC
570 */
571 HWTEST_F(WindowLayoutPolicyTest, ProcessDisplayDestroy, Function | SmallTest | Level2)
572 {
573 std::map<DisplayId, Rect> newDisplayRectMap = {};
574 layoutPolicy_->ProcessDisplayDestroy(0, newDisplayRectMap);
575
576 layoutPolicy_->ProcessDisplayDestroy(1, newDisplayRectMap);
577
578 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
579 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
580 }
581
582 /**
583 * @tc.name: ProcessDisplaySizeChangeOrRotation
584 * @tc.desc: test ProcessDisplaySizeChangeOrRotation
585 * @tc.type: FUNC
586 */
587 HWTEST_F(WindowLayoutPolicyTest, ProcessDisplaySizeChangeOrRotation, Function | SmallTest | Level2)
588 {
589 std::map<DisplayId, Rect> newDisplayRectMap = {};
590 layoutPolicy_->ProcessDisplayDestroy(0, newDisplayRectMap);
591
592 layoutPolicy_->ProcessDisplayDestroy(1, newDisplayRectMap);
593
594 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
595 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
596 SetUpTestCase();
597 }
598
599 /**
600 * @tc.name: LayoutWindowNode
601 * @tc.desc: test LayoutWindowNode
602 * @tc.type: FUNC
603 */
604 HWTEST_F(WindowLayoutPolicyTest, LayoutWindowNode, Function | SmallTest | Level2)
605 {
606 sptr<WindowNode> node = nullptr;
607 layoutPolicy_->LayoutWindowNode(node);
608
609 node = CreateWindowNode(windowInfo_);
610 ASSERT_TRUE(node != nullptr);
611 layoutPolicy_->LayoutWindowNode(node);
612
613 node->parent_ = container_->appWindowNode_;
614 layoutPolicy_->LayoutWindowNode(node);
615
616 node->currentVisibility_ = true;
617 layoutPolicy_->LayoutWindowNode(node);
618
619 node->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
620 layoutPolicy_->LayoutWindowNode(node);
621
622 // create child node
623 sptr<WindowNode> child = CreateWindowNode(windowInfo_);
624 ASSERT_TRUE(child != nullptr);
625 node->children_.push_back(child);
626 layoutPolicy_->LayoutWindowNode(node);
627 }
628
629 /**
630 * @tc.name: CalcAndSetNodeHotZone
631 * @tc.desc: test CalcAndSetNodeHotZone
632 * @tc.type: FUNC
633 */
634 HWTEST_F(WindowLayoutPolicyTest, CalcAndSetNodeHotZone, Function | SmallTest | Level2)
635 {
636 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
637 ASSERT_TRUE(node != nullptr);
638 layoutPolicy_->CalcAndSetNodeHotZone(node->GetWindowRect(), node);
639
640 layoutPolicy_->UpdateLayoutRect(node);
641 layoutPolicy_->CalcAndSetNodeHotZone(node->GetWindowRect(), node);
642 }
643
644 /**
645 * @tc.name: FixWindowSizeByRatioIfDragBeyondLimitRegion01
646 * @tc.desc: test FixWindowSizeByRatioIfDragBeyondLimitRegion01
647 * @tc.type: FUNC
648 */
649 HWTEST_F(WindowLayoutPolicyTest, FixWindowSizeByRatioIfDragBeyondLimitRegion01, Function | SmallTest | Level2)
650 {
651 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
652 ASSERT_TRUE(node != nullptr);
653 WindowLimits sizeLimits = { 400, 400, 400, 400, 2.0, 2.0 }; // sizeLimits: 400, 400, 400, 400, 2.0, 2.0
654 node->SetWindowUpdatedSizeLimits(sizeLimits);
655 Rect finalRect;
656 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
657
658 sizeLimits.maxWidth_ = 800; // maxWidth: 800
659 node->SetWindowUpdatedSizeLimits(sizeLimits);
660 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
661
662 sizeLimits.maxWidth_ = 400; // maxWidth: 400
663 sizeLimits.maxHeight_ = 800; // maxHeight: 800
664 node->SetWindowUpdatedSizeLimits(sizeLimits);
665 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
666
667 sizeLimits.maxWidth_ = 800; // maxWidth: 800
668 sizeLimits.maxHeight_ = 800; // maxHeight: 800
669 node->SetWindowUpdatedSizeLimits(sizeLimits);
670 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
671
672 sizeLimits.maxWidth_ = 800; // maxWidth: 800
673 sizeLimits.maxHeight_ = 800; // maxHeight: 800
674 node->SetWindowUpdatedSizeLimits(sizeLimits);
675
676 auto newRect = node->GetWindowRect();
677 newRect.height_ = 400; // maxHeight: 400
678 node->SetWindowRect(newRect);
679 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
680
681 newRect = { 200, 200, 500, 200 }; // rect: 200, 200, 500, 200
682 node->SetWindowRect(newRect);
683 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
684
685 newRect = { 200, 200, 100, 200 }; // rect: 200, 200, 100, 200
686 node->SetWindowRect(newRect);
687 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
688 }
689
690 /**
691 * @tc.name: FixWindowSizeByRatioIfDragBeyondLimitRegion02
692 * @tc.desc: test FixWindowSizeByRatioIfDragBeyondLimitRegion02
693 * @tc.type: FUNC
694 */
695 HWTEST_F(WindowLayoutPolicyTest, FixWindowSizeByRatioIfDragBeyondLimitRegion02, Function | SmallTest | Level2)
696 {
697 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
698 ASSERT_TRUE(node != nullptr);
699 WindowLimits sizeLimits = { 800, 800, 400, 400, 2.0, 1.0 }; // sizeLimits: 800, 800, 400, 400, 2.0, 1.0
700 node->SetWindowUpdatedSizeLimits(sizeLimits);
701
702 Rect newRect = { 200, 200, 300, 200 }; // rect: 200, 200, 300, 200
703 Rect finalRect;
704 node->SetWindowRect(newRect);
705 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
706
707 sizeLimits.minRatio_ = 1.0; // ratio: 1.0
708 sizeLimits.maxRatio_ = 1.0; // ratio: 1.0
709 node->SetWindowUpdatedSizeLimits(sizeLimits);
710 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
711
712 sizeLimits.minRatio_ = 2.0; // ratio: 2.0
713 sizeLimits.maxRatio_ = 2.0; // ratio: 2.0
714 node->SetWindowUpdatedSizeLimits(sizeLimits);
715 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
716
717 newRect = { 200, 200, 400, 200 }; // rect: 200, 200, 400, 200
718 node->SetWindowRect(newRect);
719 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
720
721 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
722 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
723 layoutPolicy_->limitRectMap_[0] = displayRect;
724 }
725
726 /**
727 * @tc.name: FixWindowSizeByRatioIfDragBeyondLimitRegion03
728 * @tc.desc: test FixWindowSizeByRatioIfDragBeyondLimitRegion03
729 * @tc.type: FUNC
730 */
731 HWTEST_F(WindowLayoutPolicyTest, FixWindowSizeByRatioIfDragBeyondLimitRegion03, Function | SmallTest | Level2)
732 {
733 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
734 ASSERT_TRUE(node != nullptr);
735 WindowLimits sizeLimits = { 800, 800, 400, 400, 2.0, 1.0 }; // sizeLimits: 800, 800, 400, 400, 2.0, 1.0
736
737 node->SetWindowUpdatedSizeLimits(sizeLimits);
738
739 Rect newRect = { 200, 200, 300, 200 }; // rect: 200, 200, 300, 200
740 node->SetWindowRect(newRect);
741
742 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
743 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
744 layoutPolicy_->limitRectMap_[0] = displayRect;
745
746 windowInfo_.winType_ = WindowType::WINDOW_TYPE_LAUNCHER_DOCK;
747 sptr<WindowNode> dockNode = CreateWindowNode(windowInfo_);
748 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::ABOVE_WINDOW_NODE]->push_back(dockNode);
749
750 Rect dockWinRect = { 200, 200, 50, 20 }; // rect: 200, 200, 50, 20
751 Rect finalRect;
752 dockNode->SetWindowRect(dockWinRect);
753 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
754
755 dockWinRect = { 200, 200, 50, (displayRect.height_ - static_cast<uint32_t>(200)) }; // param: 200, 50
756 dockNode->SetWindowRect(dockWinRect);
757 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
758
759 dockWinRect = { 200, 200, 20, 50 }; // param: 200, 200, 20, 50
760 dockNode->SetWindowRect(dockWinRect);
761 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
762
763 dockWinRect = { 0, 200, 20, 50 }; // param: 0, 200, 20, 50
764 dockNode->SetWindowRect(dockWinRect);
765 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
766
767 dockWinRect = { 200, 200, (displayRect.width_ - static_cast<uint32_t>(200)), 50 }; // param: 200, 50
768 dockNode->SetWindowRect(dockWinRect);
769 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
770
771 dockWinRect = { 200, 200, (displayRect.width_ - static_cast<uint32_t>(100)), 50 }; // param: 200, 100, 50
772 dockNode->SetWindowRect(dockWinRect);
773 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
774 }
775
776 /**
777 * @tc.name: FixWindowSizeByRatioIfDragBeyondLimitRegion04
778 * @tc.desc: test FixWindowSizeByRatioIfDragBeyondLimitRegion04
779 * @tc.type: FUNC
780 */
781 HWTEST_F(WindowLayoutPolicyTest, FixWindowSizeByRatioIfDragBeyondLimitRegion04, Function | SmallTest | Level2)
782 {
783 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
784 ASSERT_TRUE(node != nullptr);
785 WindowLimits sizeLimits = { 800, 800, 400, 400, 2.0, 1.0 }; // sizeLimits: 800, 800, 400, 400, 2.0, 1.0
786 node->SetWindowUpdatedSizeLimits(sizeLimits);
787
788 Rect newRect = { 200, 200, 300, 200 }; // rect: 200, 200, 300, 200
789 node->SetWindowRect(newRect);
790
791 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
792 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
793 layoutPolicy_->limitRectMap_[0] = displayRect;
794 windowInfo_.winType_ = WindowType::WINDOW_TYPE_LAUNCHER_DOCK;
795 sptr<WindowNode> dockNode = CreateWindowNode(windowInfo_);
796 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::ABOVE_WINDOW_NODE]->push_back(dockNode);
797
798 Rect dockWinRect = { 200, (displayRect.height_ * 0.9), // param: 200, 0.9,
799 50, ((displayRect.height_ * 0.1)) }; // param: 50, 0.1
800 dockNode->SetWindowRect(dockWinRect);
801 Rect finalRect;
802 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
803
804 float virtualPixelRatio = displayGroupInfo_.GetDisplayVirtualPixelRatio(node->GetDisplayId());
805 uint32_t windowTitleBarH = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio);
806 int32_t limitMaxPosX = displayRect.posX_ + static_cast<int32_t>(displayRect.width_ - windowTitleBarH);
807
808 newRect = { limitMaxPosX, 200, 300, 200 }; // param: 200, 300
809 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
810
811 newRect = { limitMaxPosX, 200, 200, 200 }; // param: 200
812 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
813 }
814
815 /**
816 * @tc.name: FixWindowSizeByRatioIfDragBeyondLimitRegion05
817 * @tc.desc: test FixWindowSizeByRatioIfDragBeyondLimitRegion05
818 * @tc.type: FUNC
819 */
820 HWTEST_F(WindowLayoutPolicyTest, FixWindowSizeByRatioIfDragBeyondLimitRegion05, Function | SmallTest | Level2)
821 {
822 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
823 ASSERT_TRUE(node != nullptr);
824 WindowLimits sizeLimits = { 800, 800, 400, 400, 2.0, 1.0 }; // sizeLimits: 800, 800, 400, 400, 2.0, 1.0
825 node->SetWindowUpdatedSizeLimits(sizeLimits);
826
827 Rect newRect = { 200, 200, 300, 200 }; // rect: 200, 200, 300, 200
828 node->SetWindowRect(newRect);
829
830 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
831 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
832 layoutPolicy_->limitRectMap_[0] = displayRect;
833 windowInfo_.winType_ = WindowType::WINDOW_TYPE_LAUNCHER_DOCK;
834 sptr<WindowNode> dockNode = CreateWindowNode(windowInfo_);
835 ASSERT_TRUE(dockNode != nullptr);
836 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::ABOVE_WINDOW_NODE]->push_back(dockNode);
837
838 Rect dockWinRect = {
839 0,
840 static_cast<uint32_t>(displayRect.height_ * 0.9), // ratio: 0.9
841 static_cast<uint32_t>(displayRect.height_ * 0.1), // ratio: 0.1
842 static_cast<uint32_t>(displayRect.height_ * 0.1) // ratio: 0.1
843 };
844 dockNode->SetWindowRect(dockWinRect);
845 Rect finalRect;
846 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
847
848 float virtualPixelRatio = displayGroupInfo_.GetDisplayVirtualPixelRatio(node->GetDisplayId());
849 uint32_t windowTitleBarH = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio);
850 int32_t limitMinPosX = displayRect.posX_ + static_cast<int32_t>(windowTitleBarH);
851
852 newRect = { limitMinPosX, 200, 300, 200 }; // rect: 200, 300, 200
853 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
854
855 newRect = { limitMinPosX, 200, 200, 200 }; // rect: 200, 200, 200
856 layoutPolicy_->FixWindowSizeByRatioIfDragBeyondLimitRegion(node, finalRect);
857 }
858
859 /**
860 * @tc.name: GetSystemSizeLimits
861 * @tc.desc: test GetSystemSizeLimits
862 * @tc.type: FUNC
863 */
864 HWTEST_F(WindowLayoutPolicyTest, GetSystemSizeLimits, Function | SmallTest | Level2)
865 {
866 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
867 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
868
869 sptr<WindowNode> node1 = CreateWindowNode(windowInfo_);
870 ASSERT_TRUE(node1 != nullptr);
871 static_cast<void>(layoutPolicy_->GetSystemSizeLimits(node1, displayRect, 1.0)); // ratio: 1.0
872
873 windowInfo_.winType_ = WindowType::WINDOW_TYPE_FLOAT_CAMERA;
874 sptr<WindowNode> node2 = CreateWindowNode(windowInfo_);
875 ASSERT_TRUE(node2 != nullptr);
876 static_cast<void>(layoutPolicy_->GetSystemSizeLimits(node2, displayRect, 1.0)); // ratio: 1.0
877 }
878
879 /**
880 * @tc.name: UpdateWindowSizeLimits
881 * @tc.desc: test UpdateWindowSizeLimits
882 * @tc.type: FUNC
883 */
884 HWTEST_F(WindowLayoutPolicyTest, UpdateWindowSizeLimits, Function | SmallTest | Level2)
885 {
886 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
887 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
888
889 sptr<WindowNode> node1 = CreateWindowNode(windowInfo_);
890 ASSERT_TRUE(node1 != nullptr);
891 static_cast<void>(layoutPolicy_->GetSystemSizeLimits(node1, displayRect, 1.0)); // ratio: 1.0
892
893 windowInfo_.winType_ = WindowType::WINDOW_TYPE_FLOAT_CAMERA;
894 sptr<WindowNode> node2 = CreateWindowNode(windowInfo_);
895 ASSERT_TRUE(node2 != nullptr);
896 static_cast<void>(layoutPolicy_->GetSystemSizeLimits(node2, displayRect, 1.0)); // ratio: 1.0
897 }
898
899 /**
900 * @tc.name: UpdateFloatingWindowSizeForStretchableWindow04
901 * @tc.desc: test UpdateFloatingWindowSizeForStretchableWindow04
902 * @tc.type: FUNC
903 */
904 HWTEST_F(WindowLayoutPolicyTest, UpdateFloatingWindowSizeForStretchableWindow04, Function | SmallTest | Level2)
905 {
906 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
907 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
908
909 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
910 ASSERT_TRUE(node != nullptr);
911 Rect winRect = { 0, 0, 0, 0};
912 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
913
914 winRect = { 0, 0, 40, 0 }; // width: 40
915 node->SetOriginRect(winRect);
916 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
917
918 winRect = { 0, 0, 0, 40 }; // height: 40
919 node->SetOriginRect(winRect);
920 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
921
922 winRect = { 0, 0, 40, 40 }; // width/height: 40
923 node->SetOriginRect(winRect);
924 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
925
926 node->SetDragType(DragType::DRAG_LEFT_OR_RIGHT);
927 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
928
929 node->SetDragType(DragType::DRAG_BOTTOM_OR_TOP);
930 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
931
932 node->SetDragType(DragType::DRAG_LEFT_TOP_CORNER);
933 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
934
935 node->SetDragType(DragType::DRAG_RIGHT_TOP_CORNER);
936 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
937 }
938
939 /**
940 * @tc.name: UpdateFloatingWindowSizeForStretchableWindow05
941 * @tc.desc: test UpdateFloatingWindowSizeForStretchableWindow05
942 * @tc.type: FUNC
943 */
944 HWTEST_F(WindowLayoutPolicyTest, UpdateFloatingWindowSizeForStretchableWindow05, Function | SmallTest | Level2)
945 {
946 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
947 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
948
949 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
950 ASSERT_TRUE(node != nullptr);
951 WindowLimits sizeLimits = { 800, 800, 400, 400, 2.0, 1.0 }; // sizeLimits: 800, 800, 400, 400, 2.0, 1.0
952 node->SetWindowUpdatedSizeLimits(sizeLimits);
953
954 Rect winRect = { 0, 0, 400, 400 }; // width/height: 400
955 node->SetOriginRect(winRect);
956 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
957
958 winRect = { 0, 0, 300, 300 }; // width/height: 300
959 node->SetOriginRect(winRect);
960 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
961
962 winRect = { 0, 0, 500, 500 }; // width/height: 500
963 node->SetOriginRect(winRect);
964 layoutPolicy_->UpdateFloatingWindowSizeForStretchableWindow(node, displayRect, winRect);
965 }
966
967 /**
968 * @tc.name: UpdateFloatingWindowSizeBySizeLimits
969 * @tc.desc: test UpdateFloatingWindowSizeBySizeLimits
970 * @tc.type: FUNC
971 */
972 HWTEST_F(WindowLayoutPolicyTest, UpdateFloatingWindowSizeBySizeLimits, Function | SmallTest | Level2)
973 {
974 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
975 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
976
977 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
978 ASSERT_TRUE(node != nullptr);
979 WindowLimits sizeLimits = { 800, 400, 800, 400, 2.0, 1.0 }; // sizeLimits: 800, 400, 800, 400, 2.0, 1.0
980 node->SetWindowUpdatedSizeLimits(sizeLimits);
981 Rect winRect = { 0, 0, 400, 400 }; // width/height: 400
982 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
983
984 sizeLimits = { 800, 800, 400, 400, 2.0, 1.0 }; // sizeLimits: 800, 800, 400, 400, 2.0, 1.0
985 node->SetWindowUpdatedSizeLimits(sizeLimits);
986 winRect = { 0, 0, 400, 400 }; // width/height: 400
987 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
988
989 sizeLimits = { 800, 500, 800, 400, 2.0, 1.0 }; // sizeLimits: 800, 500, 800, 400, 2.0, 1.0
990 node->SetWindowUpdatedSizeLimits(sizeLimits);
991 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
992
993 sizeLimits = { 800, 400, 600, 400, 2.0, 1.0 }; // sizeLimits: 800, 400, 600, 400, 2.0, 1.0
994 node->SetWindowUpdatedSizeLimits(sizeLimits);
995 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
996
997 sizeLimits = { 800, 400, 800, 400, 2.0, 1.0 }; // sizeLimits: 800, 400, 800, 400, 2.0, 1.0
998 node->SetWindowUpdatedSizeLimits(sizeLimits);
999 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
1000
1001 sizeLimits = { 800, 800, 400, 400, 2.0, 1.0 }; // sizeLimits: 800, 800, 400, 400, 2.0, 1.0
1002 node->SetWindowUpdatedSizeLimits(sizeLimits);
1003 node->SetDragType(DragType::DRAG_BOTTOM_OR_TOP);
1004 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
1005
1006 node->SetDragType(DragType::DRAG_LEFT_OR_RIGHT);
1007 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
1008
1009 node->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_DRAGGING_EFFECT);
1010 layoutPolicy_->UpdateFloatingWindowSizeBySizeLimits(node, displayRect, winRect);
1011 }
1012
1013 /**
1014 * @tc.name: LimitFloatingWindowSize
1015 * @tc.desc: test LimitFloatingWindowSize
1016 * @tc.type: FUNC
1017 */
1018 HWTEST_F(WindowLayoutPolicyTest, LimitFloatingWindowSize, Function | SmallTest | Level2)
1019 {
1020 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1021 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1022
1023 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1024 ASSERT_TRUE(node != nullptr);
1025 Rect winRect = { 0, 0, 400, 400 }; // width/height: 400
1026 layoutPolicy_->LimitFloatingWindowSize(node, winRect);
1027
1028 Rect newRect = { 10, 0, 400, 400 }; // window rect: 10, 0, 400, 400
1029 layoutPolicy_->LimitFloatingWindowSize(node, newRect);
1030
1031 newRect = { 0, 10, 400, 400 }; // window rect: 0, 10, 400, 400
1032 layoutPolicy_->LimitFloatingWindowSize(node, newRect);
1033
1034 newRect = { 10, 10, 400, 400 }; // window rect: 10, 10, 400, 400
1035 layoutPolicy_->LimitFloatingWindowSize(node, newRect);
1036
1037 node->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1038 layoutPolicy_->LimitFloatingWindowSize(node, winRect);
1039
1040 node->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT);
1041 layoutPolicy_->LimitFloatingWindowSize(node, winRect);
1042 }
1043
1044 /**
1045 * @tc.name: LimitMainFloatingWindowPosition
1046 * @tc.desc: test LimitMainFloatingWindowPosition
1047 * @tc.type: FUNC
1048 */
1049 HWTEST_F(WindowLayoutPolicyTest, LimitMainFloatingWindowPosition, Function | SmallTest | Level2)
1050 {
1051 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1052 ASSERT_TRUE(node != nullptr);
1053 Rect winRect = { 0, 0, 400, 400 }; // width/height: 400
1054 node->SetWindowRect(winRect);
1055 node->SetRequestRect(winRect);
1056 winRect.posX_ = 20; // posX: 20
1057 layoutPolicy_->LimitMainFloatingWindowPosition(node, winRect);
1058
1059 node->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1060 layoutPolicy_->LimitMainFloatingWindowPosition(node, winRect);
1061 }
1062
1063 /**
1064 * @tc.name: LimitWindowPositionWhenDrag
1065 * @tc.desc: test LimitWindowPositionWhenDrag
1066 * @tc.type: FUNC
1067 */
1068 HWTEST_F(WindowLayoutPolicyTest, LimitWindowPositionWhenDrag, Function | SmallTest | Level2)
1069 {
1070 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1071 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1072
1073 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1074 ASSERT_TRUE(node != nullptr);
1075 Rect winRect = { 0, 0, 400, 400 }; // width/height: 400
1076 node->SetWindowRect(winRect);
1077
1078 windowInfo_.winType_ = WindowType::WINDOW_TYPE_LAUNCHER_DOCK;
1079 sptr<WindowNode> dockNode = CreateWindowNode(windowInfo_);
1080 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::ABOVE_WINDOW_NODE]->push_back(dockNode);
1081
1082 Rect dockWinRect = { 200, 200, 50, 20 }; // 200, 200, 50, 20
1083 dockNode->SetWindowRect(dockWinRect);
1084 layoutPolicy_->LimitWindowPositionWhenDrag(node, winRect);
1085
1086 dockWinRect = { 200, 200, 50, (displayRect.height_ - static_cast<uint32_t>(200)) }; // param: 200 200 20
1087 dockNode->SetWindowRect(dockWinRect);
1088 layoutPolicy_->LimitWindowPositionWhenDrag(node, winRect);
1089
1090 dockWinRect = { 200, 200, 20, 50 }; // 200, 200, 20, 50
1091 dockNode->SetWindowRect(dockWinRect);
1092 layoutPolicy_->LimitWindowPositionWhenDrag(node, winRect);
1093
1094 dockWinRect = { 0, 200, 20, 50 }; // 200, 200, 20, 50
1095 dockNode->SetWindowRect(dockWinRect);
1096 layoutPolicy_->LimitWindowPositionWhenDrag(node, winRect);
1097 }
1098
1099 /**
1100 * @tc.name: LimitWindowPositionWhenDrag01
1101 * @tc.desc: test LimitWindowPositionWhenDrag01
1102 * @tc.type: FUNC
1103 */
1104 HWTEST_F(WindowLayoutPolicyTest, LimitWindowPositionWhenDrag01, Function | SmallTest | Level2)
1105 {
1106 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1107 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1108
1109 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1110 ASSERT_TRUE(node != nullptr);
1111 Rect winRect = { 0, 0, 400, 400 }; // width/height: 400
1112 node->SetWindowRect(winRect);
1113
1114 layoutPolicy_->limitRectMap_[node->GetDisplayId()] = displayRect;
1115 float virtualPixelRatio = displayGroupInfo_.GetDisplayVirtualPixelRatio(node->GetDisplayId());
1116 uint32_t windowTitleBarH = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio);
1117 int32_t limitMinPosX = displayRect.posX_ + static_cast<int32_t>(windowTitleBarH);
1118 int32_t limitMaxPosX = displayRect.posX_ + static_cast<int32_t>(displayRect.width_ - windowTitleBarH);
1119 int32_t limitMinPosY = displayRect.posY_;
1120 int32_t limitMaxPosY = displayRect.posY_ + static_cast<int32_t>(displayRect.height_ - windowTitleBarH);
1121
1122 Rect newRect = winRect;
1123 newRect.posX_ = limitMinPosX - newRect.width_ - 1;
1124 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1125
1126 newRect.width_ -= 1;
1127 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1128
1129 winRect.posX_ = limitMaxPosX + 1;
1130 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1131
1132 newRect.width_ = winRect.width_;
1133 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1134
1135 newRect.posY_ = limitMaxPosY + 1;
1136 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1137
1138 newRect.height_ += 1;
1139 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1140
1141 newRect.posY_ = limitMinPosY - 1;
1142 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1143
1144 newRect.height_ = winRect.height_;
1145 layoutPolicy_->LimitWindowPositionWhenDrag(node, newRect);
1146 }
1147
1148 /**
1149 * @tc.name: LimitWindowPositionWhenInitRectOrMove
1150 * @tc.desc: test LimitWindowPositionWhenInitRectOrMove
1151 * @tc.type: FUNC
1152 */
1153 HWTEST_F(WindowLayoutPolicyTest, LimitWindowPositionWhenInitRectOrMove, Function | SmallTest | Level2)
1154 {
1155 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1156 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1157
1158 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1159 ASSERT_TRUE(node != nullptr);
1160 Rect winRect = { 0, 0, 400, 400 }; // width/height: 400
1161 node->SetWindowRect(winRect);
1162
1163 windowInfo_.winType_ = WindowType::WINDOW_TYPE_LAUNCHER_DOCK;
1164 sptr<WindowNode> dockNode = CreateWindowNode(windowInfo_);
1165 ASSERT_TRUE(dockNode != nullptr);
1166 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::ABOVE_WINDOW_NODE]->push_back(dockNode);
1167
1168 Rect dockWinRect = { 200, 200, 50, 20 }; // rect : 200, 200, 50, 20
1169 dockNode->SetWindowRect(dockWinRect);
1170 layoutPolicy_->LimitWindowPositionWhenInitRectOrMove(node, winRect);
1171
1172 dockWinRect = { 200, 200, 50, (displayRect.height_ - static_cast<uint32_t>(200)) }; // param: 200, 50
1173 dockNode->SetWindowRect(dockWinRect);
1174 layoutPolicy_->LimitWindowPositionWhenInitRectOrMove(node, winRect);
1175
1176 dockWinRect = { 200, 200, 20, 50 }; // rect : 200, 200, 20, 50
1177 dockNode->SetWindowRect(dockWinRect);
1178 layoutPolicy_->LimitWindowPositionWhenInitRectOrMove(node, winRect);
1179
1180 dockWinRect = { 0, 200, 20, 50 }; // rect : 0, 200, 20, 50
1181 dockNode->SetWindowRect(dockWinRect);
1182 layoutPolicy_->LimitWindowPositionWhenInitRectOrMove(node, winRect);
1183
1184 node->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1185 layoutPolicy_->LimitWindowPositionWhenInitRectOrMove(node, winRect);
1186 }
1187
1188 /**
1189 * @tc.name: GetDockWindowShowState
1190 * @tc.desc: test GetDockWindowShowState
1191 * @tc.type: FUNC
1192 */
1193 HWTEST_F(WindowLayoutPolicyTest, GetDockWindowShowState, Function | SmallTest | Level2)
1194 {
1195 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1196 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1197
1198 Rect dockWinRect = { 200, 200, 50, 20 }; // rect : 200, 200, 50, 20
1199 layoutPolicy_->GetDockWindowShowState(0, dockWinRect);
1200
1201 windowInfo_.winType_ = WindowType::WINDOW_TYPE_LAUNCHER_DOCK;
1202 sptr<WindowNode> dockNode = CreateWindowNode(windowInfo_);
1203 ASSERT_TRUE(dockNode != nullptr);
1204 layoutPolicy_->displayGroupWindowTree_[0][WindowRootNodeType::ABOVE_WINDOW_NODE]->push_back(dockNode);
1205
1206 dockNode->SetWindowRect(dockWinRect);
1207 layoutPolicy_->GetDockWindowShowState(0, dockWinRect);
1208
1209 dockWinRect = { 200, 200, 50, (displayRect.height_ - static_cast<uint32_t>(200)) }; // param : 200, 50
1210 dockNode->SetWindowRect(dockWinRect);
1211 layoutPolicy_->GetDockWindowShowState(0, dockWinRect);
1212
1213 dockWinRect = { 200, 200, 20, 50 }; // rect : 200, 200, 20, 50
1214 dockNode->SetWindowRect(dockWinRect);
1215 layoutPolicy_->GetDockWindowShowState(0, dockWinRect);
1216
1217 dockWinRect = { 0, 200, 20, 50 }; // rect : 0, 200, 20, 50
1218 dockNode->SetWindowRect(dockWinRect);
1219 layoutPolicy_->GetDockWindowShowState(0, dockWinRect);
1220 }
1221
1222 /**
1223 * @tc.name: GetAvoidPosType
1224 * @tc.desc: test GetAvoidPosType
1225 * @tc.type: FUNC
1226 */
1227 HWTEST_F(WindowLayoutPolicyTest, GetAvoidPosType, Function | SmallTest | Level2)
1228 {
1229 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1230 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1231
1232 Rect winRect = { 200, 200, 50, 20 }; // rect : 200, 200, 50, 20
1233 layoutPolicy_->GetAvoidPosType(winRect, 0);
1234
1235 layoutPolicy_->GetAvoidPosType(winRect, 1);
1236
1237 winRect.width_ = displayRect.width_;
1238 layoutPolicy_->GetAvoidPosType(winRect, 0);
1239
1240 winRect.posY_ = displayRect.posY_;
1241 layoutPolicy_->GetAvoidPosType(winRect, 0);
1242
1243 winRect.height_ = displayRect.height_;
1244 layoutPolicy_->GetAvoidPosType(winRect, 0);
1245
1246 winRect.posY_ = displayRect.posY_;
1247 layoutPolicy_->GetAvoidPosType(winRect, 0);
1248 }
1249
1250 /**
1251 * @tc.name: UpdateDisplayLimitRect
1252 * @tc.desc: test UpdateDisplayLimitRect
1253 * @tc.type: FUNC
1254 */
1255 HWTEST_F(WindowLayoutPolicyTest, UpdateDisplayLimitRect, Function | SmallTest | Level2)
1256 {
1257 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1258 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1259
1260 Rect limitRect = displayRect;
1261
1262 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1263 ASSERT_TRUE(node != nullptr);
1264 Rect avoidRect = { 200, 200, 50, 20 }; // rect : 200, 200, 50, 20
1265 node->SetWindowRect(avoidRect);
1266 layoutPolicy_->UpdateDisplayLimitRect(node, limitRect);
1267
1268 node->GetWindowProperty()->SetWindowType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
1269 layoutPolicy_->UpdateDisplayLimitRect(node, limitRect);
1270
1271 avoidRect.width_ = displayRect.width_;
1272 node->SetWindowRect(avoidRect);
1273 layoutPolicy_->UpdateDisplayLimitRect(node, limitRect);
1274
1275 avoidRect.posY_ = displayRect.posY_;
1276 node->SetWindowRect(avoidRect);
1277 layoutPolicy_->UpdateDisplayLimitRect(node, limitRect);
1278
1279 avoidRect.height_ = displayRect.height_;
1280 node->SetWindowRect(avoidRect);
1281 layoutPolicy_->UpdateDisplayLimitRect(node, limitRect);
1282
1283 avoidRect.posY_ = displayRect.posY_;
1284 node->SetWindowRect(avoidRect);
1285 layoutPolicy_->UpdateDisplayLimitRect(node, limitRect);
1286 }
1287
1288 /**
1289 * @tc.name: UpdateSurfaceBounds
1290 * @tc.desc: test UpdateSurfaceBounds
1291 * @tc.type: FUNC
1292 */
1293 HWTEST_F(WindowLayoutPolicyTest, UpdateSurfaceBounds, Function | SmallTest | Level2)
1294 {
1295 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1296 ASSERT_TRUE(node != nullptr);
1297 Rect winRect = { 0, 0, 20, 50 }; // rect : 0, 0, 20, 50
1298 Rect preRect = { 0, 0, 20, 60 }; // rect : 0, 0, 20, 60
1299 layoutPolicy_->UpdateSurfaceBounds(node, winRect, preRect);
1300
1301 node->SetWindowSizeChangeReason(WindowSizeChangeReason::MAXIMIZE);
1302 layoutPolicy_->UpdateSurfaceBounds(node, winRect, preRect);
1303
1304 node->SetWindowSizeChangeReason(WindowSizeChangeReason::RECOVER);
1305 layoutPolicy_->UpdateSurfaceBounds(node, winRect, preRect);
1306
1307 node->SetWindowSizeChangeReason(WindowSizeChangeReason::ROTATION);
1308 layoutPolicy_->UpdateSurfaceBounds(node, winRect, preRect);
1309
1310 node->SetWindowSizeChangeReason(WindowSizeChangeReason::UNDEFINED);
1311 layoutPolicy_->UpdateSurfaceBounds(node, winRect, preRect);
1312 }
1313
1314 /**
1315 * @tc.name: PerformWindowLayout
1316 * @tc.desc: test WindowLayoutPolicyTile PerformWindowLayout
1317 * @tc.type: FUNC
1318 */
1319 HWTEST_F(WindowLayoutPolicyTest, PerformWindowLayout, Function | SmallTest | Level2)
1320 {
1321 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1322 ASSERT_TRUE(node != nullptr);
1323 WindowUpdateType updateType = WindowUpdateType::WINDOW_UPDATE_ACTIVE;
1324 layoutPolicyTile_->PerformWindowLayout(node, updateType);
1325 }
1326
1327 /**
1328 * @tc.name: UpdateLayoutRect
1329 * @tc.desc: test WindowLayoutPolicyTile UpdateLayoutRect
1330 * @tc.type: FUNC
1331 */
1332 HWTEST_F(WindowLayoutPolicyTest, UpdateLayoutRect, Function | SmallTest | Level2)
1333 {
1334 sptr<WindowProperty> property = new WindowProperty();
1335
1336 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1337 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1338 property->SetWindowFlags(1);
1339 Rect winRect = { 200, 200, 50, 20 }; // rect : 200, 200, 50, 50
1340
1341 property->SetWindowSizeChangeReason(WindowSizeChangeReason::DRAG);
1342 sptr<WindowNode> node = new WindowNode(property, nullptr, nullptr);
1343 ASSERT_TRUE(node != nullptr);
1344 node->SetWindowProperty(property);
1345 node->SetWindowRect(winRect);
1346 node->SetRequestRect(winRect);
1347 node->SetCallingWindow(1);
1348 layoutPolicyTile_->UpdateLayoutRect(node);
1349 }
1350
1351 /**
1352 * @tc.name: IsFullScreenRecentWindowExist
1353 * @tc.desc: test IsFullScreenRecentWindowExist
1354 * @tc.type: FUNC
1355 */
1356 HWTEST_F(WindowLayoutPolicyTest, IsFullScreenRecentWindowExist, Function | SmallTest | Level2)
1357 {
1358 std::vector<sptr<WindowNode>> *nodeVec = new std::vector<sptr<WindowNode>>;
1359 auto result = layoutPolicy_->IsFullScreenRecentWindowExist(*nodeVec);
1360 ASSERT_EQ(result, false);
1361 }
1362
1363 /**
1364 * @tc.name: GetDividerRect
1365 * @tc.desc: test GetDividerRect
1366 * @tc.type: FUNC
1367 */
1368 HWTEST_F(WindowLayoutPolicyTest, GetDividerRect, Function | SmallTest | Level2)
1369 {
1370 DisplayId displayId = 0;
1371 auto result = layoutPolicy_->GetDividerRect(displayId);
1372 Rect rect{0, 0, 0, 0};
1373 ASSERT_NE(result, rect);
1374 }
1375 /**
1376 * @tc.name: AdjustFixedOrientationRSSurfaceNode
1377 * @tc.desc: test AdjustFixedOrientationRSSurfaceNode
1378 * @tc.type: FUNC
1379 */
1380 HWTEST_F(WindowLayoutPolicyTest, AdjustFixedOrientationRSSurfaceNode, Function | SmallTest | Level2)
1381 {
1382 std::shared_ptr<RSSurfaceNode> surfaceNode = std::shared_ptr<RSSurfaceNode>();
1383 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>();
1384 ASSERT_EQ(nullptr, displayInfo);
1385 }
1386
1387 /**
1388 * @tc.name: IsTileRectSatisfiedWithSizeLimits
1389 * @tc.desc: test IsTileRectSatisfiedWithSizeLimits
1390 * @tc.type: FUNC
1391 */
1392 HWTEST_F(WindowLayoutPolicyTest, IsTileRectSatisfiedWithSizeLimits, Function | SmallTest | Level2)
1393 {
1394 sptr<WindowNode> windowNode = nullptr;
1395 auto result = layoutPolicyTile_->IsTileRectSatisfiedWithSizeLimits(windowNode);
1396 ASSERT_EQ(true, result);
1397 }
1398
1399 /**
1400 * @tc.name: SetCascadeRectBottomPosYLimit
1401 * @tc.desc: test SetCascadeRectBottomPosYLimit
1402 * @tc.type: FUNC
1403 */
1404 HWTEST_F(WindowLayoutPolicyTest, SetCascadeRectBottomPosYLimit, Function | SmallTest | Level2)
1405 {
1406 uint32_t floatingBottomPosY = 0;
1407 layoutPolicy_->SetCascadeRectBottomPosYLimit(floatingBottomPosY);
1408 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1409 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1410 }
1411
1412 /**
1413 * @tc.name: SetMaxFloatingWindowSize
1414 * @tc.desc: test SetMaxFloatingWindowSize
1415 * @tc.type: FUNC
1416 */
1417 HWTEST_F(WindowLayoutPolicyTest, SetMaxFloatingWindowSize, Function | SmallTest | Level2)
1418 {
1419 uint32_t maxSize = 0;
1420 layoutPolicy_->SetMaxFloatingWindowSize(maxSize);
1421 auto displayRect = displayGroupInfo_.GetDisplayRect(defaultDisplayInfo_->GetDisplayId());
1422 ASSERT_FALSE(WindowHelper::IsEmptyRect(displayRect));
1423 }
1424
1425 /**
1426 * @tc.name: GetStoragedAspectRatio
1427 * @tc.desc: test GetStoragedAspectRatio
1428 * @tc.type: FUNC
1429 */
1430 HWTEST_F(WindowLayoutPolicyTest, GetStoragedAspectRatio, Function | SmallTest | Level2)
1431 {
1432 auto display = DisplayManager::GetInstance().GetDefaultDisplay();
1433 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1434 layoutPolicy_->GetStoragedAspectRatio(node);
1435 auto abilityName = "";
1436 auto nameVector = WindowHelper::Split(abilityName, ".");
1437 std::string keyName = " ";
1438 auto result = PersistentStorage::HasKey(keyName, PersistentStorageType::ASPECT_RATIO);
1439 ASSERT_EQ(false, result);
1440 }
1441 /**
1442 * @tc.name: FixWindowRectWithinDisplay
1443 * @tc.desc: test FixWindowRectWithinDisplay
1444 * @tc.type: FUNC
1445 */
1446 HWTEST_F(WindowLayoutPolicyTest, FixWindowRectWithinDisplay, Function | SmallTest | Level2)
1447 {
1448 auto display = DisplayManager::GetInstance().GetDefaultDisplay();
1449 sptr<WindowNode> node = CreateWindowNode(windowInfo_);
1450 layoutPolicy_->FixWindowRectWithinDisplay(node);
1451 auto displayInfo = display->GetDisplayInfo();
1452 EXPECT_EQ(displayInfo->GetWaterfallDisplayCompressionStatus(), false);
1453 }
1454 /**
1455 * @tc.name: IsNeedAnimationSync
1456 * @tc.desc: test IsNeedAnimationSync
1457 * @tc.type: FUNC
1458 */
1459 HWTEST_F(WindowLayoutPolicyTest, IsNeedAnimationSync, Function | SmallTest | Level2)
1460 {
1461 WindowType windowType = WindowType::ABOVE_APP_SYSTEM_WINDOW_END;
1462 auto result = layoutPolicy_->IsNeedAnimationSync(windowType);
1463 ASSERT_EQ(true, result);
1464 }
1465
1466 /**
1467 * @tc.name: NotifyClientAndAnimation
1468 * @tc.desc: test NotifyClientAndAnimation
1469 * @tc.type: FUNC
1470 */
1471 HWTEST_F(WindowLayoutPolicyTest, NotifyClientAndAnimation, Function | SmallTest | Level2)
1472 {
1473 sptr<WindowNode> node= CreateWindowNode(windowInfo_);
1474 Rect winRect;
1475 WindowSizeChangeReason reason = WindowSizeChangeReason::DRAG;
1476 EXPECT_EQ(node->GetWindowToken(), nullptr);
1477 layoutPolicy_->NotifyClientAndAnimation(node, winRect, reason);
1478 }
1479
1480 }
1481 }
1482 }
1483