• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 // gtest
17 #include <gtest/gtest.h>
18 #include "ability_context_impl.h"
19 #include "common_test_utils.h"
20 #include "mock_session.h"
21 #include "session/host/include/scene_session.h"
22 #include "window_adapter.h"
23 #include "window_scene_session_impl.h"
24 #include "window_test_utils.h"
25 #include "wm_common.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 using Utils = WindowTestUtils;
33 class WindowLayoutTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39     DisplayId displayId_ = 0;
40     std::vector<sptr<Window>> activeWindows_;
41     static vector<Rect> fullScreenExpecteds_;
42     static inline float virtualPixelRatio_ = 0.0;
43 
44 private:
45     static constexpr uint32_t WAIT_SYANC_US = 100000;
46     static constexpr uint32_t WAIT_SERVERAL_FRAMES = 36000;
47     static constexpr uint32_t WAIT_SYANC_S = 2; // second;
48     static void InitAvoidArea();
49     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
50 };
51 
52 vector<Rect> WindowLayoutTest::fullScreenExpecteds_;
53 
SetUpTestCase()54 void WindowLayoutTest::SetUpTestCase()
55 {
56     SingletonContainer::Get<WindowAdapter>().MinimizeAllAppWindows(0);
57     sleep(WAIT_SYANC_S);
58     auto display = DisplayManager::GetInstance().GetDisplayById(0);
59     ASSERT_NE(display, nullptr);
60     ASSERT_TRUE((display != nullptr));
61     Rect displayRect = { 0, 0, display->GetWidth(), display->GetHeight() };
62     Utils::InitByDisplayRect(displayRect);
63 
64     virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0);
65 
66     // calc expected rects
67     Rect expected = {
68         // 0. only statusBar
69         0,
70         Utils::statusBarRect_.height_,
71         Utils::displayRect_.width_,
72         Utils::displayRect_.height_ - Utils::statusBarRect_.height_,
73     };
74     fullScreenExpecteds_.push_back(expected);
75     expected = {
76         // 1. both statusBar and naviBar
77         0,
78         Utils::statusBarRect_.height_,
79         Utils::displayRect_.width_,
80         Utils::displayRect_.height_ - Utils::statusBarRect_.height_ - Utils::naviBarRect_.height_,
81     };
82     fullScreenExpecteds_.push_back(expected);
83     expected = {
84         // 2. only naviBar
85         0,
86         0,
87         Utils::displayRect_.width_,
88         Utils::displayRect_.height_ - Utils::naviBarRect_.height_,
89     };
90     fullScreenExpecteds_.push_back(expected);
91     InitAvoidArea();
92     sleep(WAIT_SYANC_S);
93 }
94 
InitAvoidArea()95 void WindowLayoutTest::InitAvoidArea()
96 {
97     Utils::TestWindowInfo info = {
98         .name = "avoidArea",
99         .rect = { 0, 0, 0, 0 },
100         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
101         .mode = WindowMode::WINDOW_MODE_FLOATING,
102         .needAvoid = true,
103         .parentLimit = false,
104         .parentId = INVALID_WINDOW_ID,
105     };
106     const sptr<Window>& window = Utils::CreateTestWindow(info);
107     ASSERT_NE(window, nullptr);
108     window->Show();
109     window->SetLayoutFullScreen(true);
110     window->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, WindowTestUtils::systemAvoidArea_);
111     window->Hide();
112     window->Destroy();
113 }
114 
TearDownTestCase()115 void WindowLayoutTest::TearDownTestCase() {}
116 
SetUp()117 void WindowLayoutTest::SetUp()
118 {
119     activeWindows_.clear();
120     abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
121     CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_app_floating_window_test");
122 }
123 
TearDown()124 void WindowLayoutTest::TearDown()
125 {
126     for (auto window : activeWindows_) {
127         window->Destroy();
128     }
129     sleep(WAIT_SYANC_S);
130     abilityContext_ = nullptr;
131 }
132 
133 namespace {
134 /**
135  * @tc.name: LayoutWindow01
136  * @tc.desc: One FLOATING APP Window with on custom rect
137  * @tc.type: FUNC
138  */
139 HWTEST_F(WindowLayoutTest, LayoutWindow01, TestSize.Level1)
140 {
141     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE);
142     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
143     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE);
144     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
145 
146     Utils::TestWindowInfo info = {
147         .name = "main1",
148         .rect = { 0, 0, 0, 0 },
149         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
150         .mode = WindowMode::WINDOW_MODE_FLOATING,
151         .needAvoid = true,
152         .parentLimit = false,
153         .showWhenLocked = true,
154         .parentId = INVALID_WINDOW_ID,
155     };
156     const sptr<Window>& window = Utils::CreateTestWindow(info);
157     ASSERT_NE(window, nullptr);
158     ASSERT_EQ(true, window != nullptr);
159     activeWindows_.push_back(window);
160     Rect expect = Utils::GetDefaultFloatingRect(window, true);
161     ASSERT_EQ(WMError::WM_OK, window->Show());
162     ASSERT_TRUE(Utils::RectEqualTo(window, Utils::GetFloatingLimitedRect(expect, virtualPixelRatio_)));
163     ASSERT_EQ(WMError::WM_OK, window->Hide());
164 }
165 
166 /**
167  * @tc.name: LayoutWindow02
168  * @tc.desc: One FLOATING APP Window
169  * @tc.type: FUNC
170  */
171 HWTEST_F(WindowLayoutTest, LayoutWindow02, TestSize.Level1)
172 {
173     Rect res = Utils::GetFloatingLimitedRect(Utils::customAppRect_, virtualPixelRatio_);
174     Utils::TestWindowInfo info = {
175         .name = "main2",
176         .rect = res,
177         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
178         .mode = WindowMode::WINDOW_MODE_FLOATING,
179         .needAvoid = true,
180         .parentLimit = false,
181         .showWhenLocked = true,
182         .parentId = INVALID_WINDOW_ID,
183     };
184     const sptr<Window>& window = Utils::CreateTestWindow(info);
185     ASSERT_NE(window, nullptr);
186     activeWindows_.push_back(window);
187 
188     ASSERT_EQ(WMError::WM_OK, window->Show());
189     if (window->IsDecorEnable()) {
190         ASSERT_TRUE(Utils::RectEqualTo(window, Utils::GetDecorateRect(res, virtualPixelRatio_)));
191     } else {
192         ASSERT_TRUE(Utils::RectEqualTo(window, res));
193     }
194     ASSERT_EQ(WMError::WM_OK, window->Hide());
195 }
196 
197 /**
198  * @tc.name: LayoutWindow04
199  * @tc.desc: One FLOATING APP Window & One StatusBar Window
200  * @tc.type: FUNC
201  */
202 HWTEST_F(WindowLayoutTest, LayoutWindow04, TestSize.Level1)
203 {
204     // app window
205     Rect res = Utils::GetFloatingLimitedRect(Utils::customAppRect_, virtualPixelRatio_);
206     Utils::TestWindowInfo info = {
207         .name = "main4",
208         .rect = res,
209         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
210         .mode = WindowMode::WINDOW_MODE_FLOATING,
211         .needAvoid = true,
212         .parentLimit = false,
213         .showWhenLocked = true,
214         .parentId = INVALID_WINDOW_ID,
215     };
216     sptr<Window> appWin = Utils::CreateTestWindow(info);
217     ASSERT_NE(appWin, nullptr);
218 
219     activeWindows_.push_back(appWin);
220 
221     // statusBar window
222     sptr<Window> statBar = Utils::CreateStatusBarWindow();
223     activeWindows_.push_back(statBar);
224 
225     ASSERT_EQ(WMError::WM_OK, appWin->Show());
226     if (appWin->IsDecorEnable()) {
227         ASSERT_TRUE(Utils::RectEqualTo(appWin, Utils::GetDecorateRect(res, virtualPixelRatio_)));
228     } else {
229         ASSERT_TRUE(Utils::RectEqualTo(appWin, res));
230     }
231     ASSERT_EQ(WMError::WM_OK, statBar->Show());
232     if (appWin->IsDecorEnable()) {
233         ASSERT_TRUE(Utils::RectEqualTo(appWin, Utils::GetDecorateRect(res, virtualPixelRatio_)));
234     } else {
235         ASSERT_TRUE(Utils::RectEqualTo(appWin, res));
236     }
237     ASSERT_EQ(WMError::WM_OK, statBar->Hide());
238     if (appWin->IsDecorEnable()) {
239         ASSERT_TRUE(Utils::RectEqualTo(appWin, Utils::GetDecorateRect(res, virtualPixelRatio_)));
240     } else {
241         ASSERT_TRUE(Utils::RectEqualTo(appWin, res));
242     }
243 }
244 
245 /**
246  * @tc.name: LayoutWindow06
247  * @tc.desc: StatusBar Window and NaviBar & Sys Window FULLSCRENN,NOT NEEDVOID,PARENTLIMIT
248  * @tc.type: FUNC
249  */
250 HWTEST_F(WindowLayoutTest, LayoutWindow06, TestSize.Level1)
251 {
252     sptr<Window> statBar = Utils::CreateStatusBarWindow();
253     ASSERT_NE(statBar, nullptr);
254 
255     activeWindows_.push_back(statBar);
256     sptr<Window> naviBar = Utils::CreateNavigationBarWindow();
257     activeWindows_.push_back(naviBar);
258     Utils::TestWindowInfo info = {
259         .name = "main6",
260         .rect = Utils::customAppRect_,
261         .type = WindowType::WINDOW_TYPE_PANEL,
262         .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
263         .needAvoid = false,
264         .parentLimit = true,
265         .showWhenLocked = true,
266         .parentId = INVALID_WINDOW_ID,
267     };
268     sptr<Window> sysWin = Utils::CreateTestWindow(info);
269     ASSERT_NE(sysWin, nullptr);
270     activeWindows_.push_back(sysWin);
271     if (statBar->Show() == WMError::WM_OK) {
272         ASSERT_EQ(WMError::WM_OK, statBar->Show());
273     } else if (statBar->Show() == WMError::WM_ERROR_INVALID_WINDOW) {
274         ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, statBar->Show());
275     }
276     sysWin->Show();
277     if (Utils::RectEqualTo(sysWin, Utils::displayRect_)) {
278         ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::displayRect_));
279     }
280     if (Utils::RectEqualTo(sysWin, Utils::displayRect_)) {
281         ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::displayRect_));
282     } else {
283         ASSERT_FALSE(Utils::RectEqualTo(sysWin, Utils::displayRect_));
284     }
285     if (WMError::WM_OK == naviBar->Show()) {
286         ASSERT_EQ(WMError::WM_OK, naviBar->Show());
287     }
288     if (Utils::RectEqualTo(sysWin, Utils::displayRect_)) {
289         ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::displayRect_));
290     }
291     if (WMError::WM_OK == statBar->Hide()) {
292         ASSERT_EQ(WMError::WM_OK, statBar->Hide());
293     }
294     if (Utils::RectEqualTo(sysWin, Utils::displayRect_)) {
295         ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::displayRect_));
296     }
297 }
298 
299 /**
300  * @tc.name: LayoutWindow07
301  * @tc.desc: StatusBar Window and NaviBar & One Floating Sys Window
302  * @tc.type: FUNC
303  */
304 HWTEST_F(WindowLayoutTest, LayoutWindow07, TestSize.Level1)
305 {
306     // statusBar window
307     sptr<Window> statBar = Utils::CreateStatusBarWindow();
308     ASSERT_NE(statBar, nullptr);
309     activeWindows_.push_back(statBar);
310 
311     // naviBar window
312     sptr<Window> naviBar = Utils::CreateNavigationBarWindow();
313     ASSERT_NE(naviBar, nullptr);
314     activeWindows_.push_back(naviBar);
315     // sys window
316     Utils::TestWindowInfo info = {
317         .name = "main7",
318         .rect = Utils::customAppRect_,
319         .type = WindowType::WINDOW_TYPE_PANEL,
320         .mode = WindowMode::WINDOW_MODE_FLOATING,
321         .needAvoid = false,
322         .parentLimit = true,
323         .showWhenLocked = true,
324         .parentId = INVALID_WINDOW_ID,
325     };
326     sptr<Window> sysWin = Utils::CreateTestWindow(info);
327     ASSERT_NE(sysWin, nullptr);
328     activeWindows_.push_back(sysWin);
329     if (statBar->Show() == WMError::WM_OK) {
330         ASSERT_EQ(WMError::WM_OK, statBar->Show());
331     } else if (statBar->Show() == WMError::WM_ERROR_INVALID_WINDOW) {
332         ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, statBar->Show());
333     }
334     sysWin->Show();
335 
336     ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::customAppRect_));
337 
338     if (WMError::WM_OK == naviBar->Show()) {
339         ASSERT_EQ(WMError::WM_OK, naviBar->Show());
340     } else {
341         ASSERT_NE(WMError::WM_OK, naviBar->Show());
342     }
343 
344     ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::customAppRect_));
345     if (statBar->Hide() == WMError::WM_OK) {
346         ASSERT_EQ(WMError::WM_OK, statBar->Hide());
347     } else if (statBar->Hide() == WMError::WM_ERROR_INVALID_WINDOW) {
348         ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, statBar->Hide());
349     }
350     ASSERT_TRUE(Utils::RectEqualTo(sysWin, Utils::customAppRect_));
351 }
352 
353 /**
354  * @tc.name: LayoutWindow08
355  * @tc.desc: One FLOATING APP Window with on custom rect
356  * @tc.type: FUNC
357  */
358 HWTEST_F(WindowLayoutTest, LayoutWindow08, TestSize.Level1)
359 {
360     Utils::TestWindowInfo info = {
361         .name = "main8",
362         .rect = { 0, 0, 0, 0 },
363         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
364         .mode = WindowMode::WINDOW_MODE_FLOATING,
365         .needAvoid = true,
366         .parentLimit = false,
367         .showWhenLocked = true,
368         .parentId = INVALID_WINDOW_ID,
369     };
370     const sptr<Window>& window = Utils::CreateTestWindow(info);
371     ASSERT_NE(window, nullptr);
372 
373     activeWindows_.push_back(window);
374     Rect expect = Utils::GetDefaultFloatingRect(window, true);
375     ASSERT_EQ(WMError::WM_OK, window->Show());
376     usleep(WAIT_SYANC_US);
377     ASSERT_TRUE(Utils::RectEqualTo(window, expect));
378     ASSERT_EQ(WMError::WM_OK, window->Hide());
379     usleep(WAIT_SYANC_US);
380 }
381 
382 /**
383  * @tc.name: LayoutWindow09
384  * @tc.desc: Add a floating and resize(2, 2)
385  * @tc.type: FUNC
386  */
387 HWTEST_F(WindowLayoutTest, LayoutWindow09, TestSize.Level1)
388 {
389     Utils::TestWindowInfo info = {
390         .name = "main9",
391         .rect = { 0, 0, 0, 0 },
392         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
393         .mode = WindowMode::WINDOW_MODE_FLOATING,
394         .needAvoid = true,
395         .parentLimit = false,
396         .showWhenLocked = true,
397         .parentId = INVALID_WINDOW_ID,
398     };
399     const sptr<Window>& window = Utils::CreateTestWindow(info);
400     ASSERT_NE(window, nullptr);
401     activeWindows_.push_back(window);
402     Rect expect = Utils::GetDefaultFloatingRect(window, true);
403 
404     ASSERT_EQ(WMError::WM_OK, window->Show());
405     usleep(WAIT_SYANC_US);
406     ASSERT_TRUE(Utils::RectEqualTo(window, expect));
407 
408     ASSERT_EQ(WMError::WM_OK, window->Resize(2u, 2u));         // 2: custom min size
409     Rect finalExcept = { expect.posX_, expect.posY_, 2u, 2u }; // 2: custom min size
410     finalExcept = Utils::GetFloatingLimitedRect(finalExcept, virtualPixelRatio_);
411     ASSERT_TRUE(Utils::RectEqualTo(window, finalExcept));
412     ASSERT_EQ(WMError::WM_OK, window->Hide());
413 }
414 
415 /**
416  * @tc.name: LayoutWindow10
417  * @tc.desc: One FLOATING APP Window do max and recovery
418  * @tc.type: FUNC
419  */
420 HWTEST_F(WindowLayoutTest, LayoutWindow10, TestSize.Level1)
421 {
422     Utils::TestWindowInfo info = {
423         .name = "main10",
424         .rect = { 0, 0, 0, 0 },
425         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
426         .mode = WindowMode::WINDOW_MODE_FLOATING,
427         .needAvoid = true,
428         .parentLimit = false,
429         .showWhenLocked = true,
430         .parentId = INVALID_WINDOW_ID,
431     };
432     const sptr<Window>& window = Utils::CreateTestWindow(info);
433     ASSERT_NE(window, nullptr);
434 
435     activeWindows_.push_back(window);
436     Rect expect = Utils::GetDefaultFloatingRect(window, true);
437     ASSERT_EQ(WMError::WM_OK, window->Show());
438     usleep(WAIT_SYANC_US);
439     ASSERT_TRUE(Utils::RectEqualTo(window, expect));
440     ASSERT_EQ(WMError::WM_OK, window->Maximize());
441     usleep(WAIT_SYANC_US);
442     ASSERT_TRUE(Utils::RectEqualTo(window, Utils::displayRect_));
443     ASSERT_EQ(WMError::WM_OK, window->Recover());
444     usleep(WAIT_SYANC_US);
445     ASSERT_TRUE(Utils::RectEqualTo(window, expect));
446     ASSERT_EQ(WMError::WM_OK, window->Minimize());
447     usleep(WAIT_SYANC_US);
448     ASSERT_EQ(WMError::WM_OK, window->Close());
449 }
450 
451 /**
452  * @tc.name: LayoutTile01
453  * @tc.desc: One FLOATING APP Window into tile mode, show 4 new window
454  * @tc.type: FUNC
455  */
456 HWTEST_F(WindowLayoutTest, LayoutTile01, TestSize.Level1)
457 {
458     Utils::TestWindowInfo info = {
459         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING, .needAvoid = true,
460         .parentId = INVALID_WINDOW_ID, .parentLimit = false, .name = "mainTile1", .rect = {0, 0, 0, 0},
461     };
462     const sptr<Window>& window = Utils::CreateTestWindow(info);
463     ASSERT_NE(window, nullptr);
464     activeWindows_.push_back(window);
465     Rect expect = Utils::GetDefaultFloatingRect(window, true);
466     EXPECT_EQ(WMError::WM_OK, window->Show());
467     usleep(WAIT_SYANC_US);
468     // init tile window rects and get max tile window num
469     Utils::InitTileWindowRects(window, false);
470     uint32_t maxTileNum = Utils::GetMaxTileWinNum();
471     EXPECT_FALSE(maxTileNum < 1);
472     usleep(WAIT_SYANC_US);
473     EXPECT_TRUE(Utils::RectEqualTo(window, expect));
474     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE);
475     usleep(WAIT_SYANC_US);
476     EXPECT_TRUE(Utils::RectEqualTo(window, Utils::singleTileRect_));
477 
478     info.name = "test1";
479     const sptr<Window>& test1 = Utils::CreateTestWindow(info);
480     ASSERT_NE(nullptr, test1);
481     activeWindows_.push_back(test1);
482     EXPECT_EQ(WMError::WM_OK, test1->Show());
483     usleep(WAIT_SYANC_US);
484     EXPECT_EQ(maxTileNum, 1);
485     EXPECT_FALSE(Utils::RectEqualTo(window, Utils::doubleTileRects_[0]));
486     EXPECT_FALSE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[1]));
487 
488     info.name = "test2";
489     const sptr<Window>& test2 = Utils::CreateTestWindow(info);
490     EXPECT_NE(nullptr, test2);
491     activeWindows_.push_back(test2);
492     EXPECT_EQ(WMError::WM_OK, test2->Show());
493     usleep(WAIT_SYANC_US);
494     if (maxTileNum == 2) {
495         EXPECT_TRUE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[0]));
496         EXPECT_TRUE(Utils::RectEqualTo(test2, Utils::doubleTileRects_[1]));
497     } else {
498         EXPECT_FALSE(Utils::RectEqualTo(window, Utils::tripleTileRects_[0]));
499         EXPECT_FALSE(Utils::RectEqualTo(test1, Utils::tripleTileRects_[1]));
500         EXPECT_FALSE(Utils::RectEqualTo(test2, Utils::tripleTileRects_[2])); // 2 is second rect idx
501     }
502     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
503 }
504 
505 /**
506  * @tc.name: LayoutTileNegative01
507  * @tc.desc: negative test for tile window
508  * @tc.type: FUNC
509  */
510 HWTEST_F(WindowLayoutTest, LayoutTileNegative01, TestSize.Level1)
511 {
512     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
513     Utils::TestWindowInfo info = {
514         .name = "mainTileNegative1", .rect = {-1, -100, -1, -100}, // -1, -100, -1, -100 is typical negative case nums
515         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, .mode = WindowMode::WINDOW_MODE_FLOATING,
516         .needAvoid = true, .parentLimit = false, .parentId = INVALID_WINDOW_ID,
517     };
518     const sptr<Window>& window = Utils::CreateTestWindow(info);
519     ASSERT_NE(window, nullptr);
520 
521     activeWindows_.push_back(window);
522     EXPECT_EQ(WMError::WM_OK, window->Show());
523     usleep(WAIT_SYANC_US);
524     // init tile window rects and get max tile window num
525     Utils::InitTileWindowRects(window, false);
526     uint32_t maxTileNum = Utils::GetMaxTileWinNum();
527     EXPECT_FALSE(maxTileNum < 1);
528 
529     usleep(WAIT_SYANC_US);
530     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE);
531     usleep(WAIT_SYANC_US);
532     EXPECT_TRUE(Utils::RectEqualTo(window, Utils::singleTileRect_));
533 
534     info.name = "test1";
535     const sptr<Window>& test1 = Utils::CreateTestWindow(info);
536     ASSERT_NE(nullptr, test1);
537     activeWindows_.push_back(test1);
538     EXPECT_EQ(WMError::WM_OK, test1->Show());
539     usleep(WAIT_SYANC_US);
540     EXPECT_EQ(maxTileNum, 1);
541     EXPECT_FALSE(Utils::RectEqualTo(window, Utils::doubleTileRects_[0]));
542     EXPECT_FALSE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[1]));
543 
544     info.name = "test2";
545     const sptr<Window>& test2 = Utils::CreateTestWindow(info);
546     EXPECT_NE(nullptr, test2);
547     activeWindows_.push_back(test2);
548     EXPECT_EQ(WMError::WM_OK, test2->Show());
549     usleep(WAIT_SYANC_US);
550     if (maxTileNum == 2) {
551         EXPECT_TRUE(Utils::RectEqualTo(test1, Utils::doubleTileRects_[0]));
552         EXPECT_TRUE(Utils::RectEqualTo(test2, Utils::doubleTileRects_[1]));
553     } else {
554         EXPECT_FALSE(Utils::RectEqualTo(window, Utils::tripleTileRects_[0]));
555         EXPECT_FALSE(Utils::RectEqualTo(test1, Utils::tripleTileRects_[1]));
556         EXPECT_FALSE(Utils::RectEqualTo(test2, Utils::tripleTileRects_[2])); // 2 is second rect idx
557     }
558     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
559 }
560 
561 /**
562  * @tc.name: LayoutTileNegative01
563  * @tc.desc: move window out of the display
564  * @tc.type: FUNC
565  */
566 HWTEST_F(WindowLayoutTest, LayoutNegative01, TestSize.Level1)
567 {
568     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
569     Utils::TestWindowInfo info = {
570         .name = "mainNegative1",
571         .rect = { 0, 0, 0, 0 },
572         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
573         .mode = WindowMode::WINDOW_MODE_FLOATING,
574         .needAvoid = true,
575         .parentLimit = false,
576         .parentId = INVALID_WINDOW_ID,
577     };
578     const sptr<Window>& window = Utils::CreateTestWindow(info);
579     ASSERT_NE(window, nullptr);
580 
581     activeWindows_.push_back(window);
582     Rect expect = Utils::GetDefaultFloatingRect(window, true);
583     ASSERT_EQ(WMError::WM_OK, window->Show());
584     usleep(WAIT_SYANC_US);
585     ASSERT_TRUE(Utils::RectEqualTo(window, expect));
586 }
587 
588 /**
589  * @tc.name: LayoutNegative02
590  * @tc.desc: resize window to negative size
591  * @tc.type: FUNC
592  */
593 HWTEST_F(WindowLayoutTest, LayoutNegative02, TestSize.Level1)
594 {
595     WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE);
596     const uint32_t negativeW = 0;
597     const uint32_t negativeH = 0;
598     Utils::TestWindowInfo info = {
599         .name = "mainNegative2",
600         .rect = { 0, 0, 0, 0 },
601         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
602         .mode = WindowMode::WINDOW_MODE_FLOATING,
603         .needAvoid = true,
604         .parentLimit = false,
605         .parentId = INVALID_WINDOW_ID,
606     };
607     const sptr<Window>& window = Utils::CreateTestWindow(info);
608     ASSERT_NE(window, nullptr);
609 
610     activeWindows_.push_back(window);
611     Rect expect = Utils::GetDefaultFloatingRect(window, true);
612     ASSERT_EQ(WMError::WM_OK, window->Show());
613     usleep(WAIT_SYANC_US);
614     ASSERT_TRUE(Utils::RectEqualTo(window, expect));
615     window->Resize(negativeW, negativeH);
616     usleep(WAIT_SYANC_US);
617     Rect expect2 = { expect.posX_, expect.posY_, negativeW, negativeH };
618     expect2 = Utils::CalcLimitedRect(expect2, virtualPixelRatio_);
619     ASSERT_TRUE(Utils::RectEqualTo(window, expect2));
620 }
621 
622 } // namespace
623 } // namespace Rosen
624 } // namespace OHOS
625