1 /*
2 * Copyright (c) 2021-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 // gtest
17 #include <gtest/gtest.h>
18 #include "avoid_area_controller.h"
19 #include "window_manager.h"
20 #include "window_test_utils.h"
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 using utils = WindowTestUtils;
27
28 class WindowSplitImmersiveTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 virtual void SetUp() override;
33 virtual void TearDown() override;
34 void IsShowTopBar(const sptr<Window>& top, bool isShow);
35 void HideAndUnregister(const sptr<Window>& fullWindow, const sptr<Window>& priWindow, const sptr<Window>& top);
36
37 std::vector<sptr<Window>> activeWindows_;
38 utils::TestWindowInfo fullInfo_;
39 utils::TestWindowInfo splitInfo_;
40
41 private:
42 static constexpr uint32_t SPLIT_TEST_SLEEP_S = 1; // split test sleep time
43 };
44
SetUpTestCase()45 void WindowSplitImmersiveTest::SetUpTestCase()
46 {
47 }
48
TearDownTestCase()49 void WindowSplitImmersiveTest::TearDownTestCase()
50 {
51 }
52
SetUp()53 void WindowSplitImmersiveTest::SetUp()
54 {
55 fullInfo_ = {
56 .name = "fullscreen.1",
57 .rect = utils::customAppRect_,
58 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
59 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
60 .needAvoid = true,
61 .parentLimit = false,
62 .parentName = "",
63 };
64
65 splitInfo_ = {
66 .name = "primary.1",
67 .rect = utils::customAppRect_,
68 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
69 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
70 .needAvoid = true,
71 .parentLimit = false,
72 .parentName = "",
73 };
74
75 activeWindows_.clear();
76 }
77
TearDown()78 void WindowSplitImmersiveTest::TearDown()
79 {
80 while (!activeWindows_.empty()) {
81 ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
82 activeWindows_.pop_back();
83 }
84 }
85
86 namespace {
87 /**
88 * @tc.name: SplitImmersive01
89 * @tc.desc: one primary window and one fullscreen window, test enter and out split immersive
90 * @tc.type: FUNC
91 */
92 HWTEST_F(WindowSplitImmersiveTest, SplitImmersive01, Function | MediumTest | Level3)
93 {
94 // create fullscreen win and show
95 const sptr<Window>& fullWindow = utils::CreateTestWindow(fullInfo_);
96 activeWindows_.push_back(fullWindow);
97 ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
98 sleep(SPLIT_TEST_SLEEP_S);
99
100 // enter split mode
101 splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
102 const sptr<Window>& priWindow = utils::CreateTestWindow(splitInfo_);
103 activeWindows_.push_back(priWindow);
104 ASSERT_EQ(WMError::WM_OK, priWindow->Show());
105 sleep(SPLIT_TEST_SLEEP_S);
106
107 // check is enter split Immersive
108 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode());
109 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode());
110 Rect immersivePriRect = priWindow->GetRect();
111 ASSERT_EQ(0, immersivePriRect.posX_);
112 ASSERT_EQ(0, immersivePriRect.posY_);
113 sleep(SPLIT_TEST_SLEEP_S);
114
115 // Exit split Mode.
116 ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
117 sleep(SPLIT_TEST_SLEEP_S);
118
119 // check is out split Immersive
120 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode());
121 Rect curFullScreenRect = fullWindow->GetRect();
122 AvoidArea avoidArea;
123 fullWindow->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM, avoidArea);
124 ASSERT_EQ(avoidArea.topRect.height_, curFullScreenRect.posY_);
125
126 ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
127 sleep(SPLIT_TEST_SLEEP_S);
128 ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
129 sleep(SPLIT_TEST_SLEEP_S);
130 }
131 }
132 } // namespace Rosen
133 } // namespace OHOS
134