1 /*
2 * Copyright (c) 2021 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 "window_test_utils.h"
19 #include "wm_common.h"
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 using Utils = WindowTestUtils;
26 class WindowSplitTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 virtual void SetUp() override;
31 virtual void TearDown() override;
32 std::vector<sptr<Window>> activeWindows_;
33 Utils::TestWindowInfo fullInfo_;
34 Utils::TestWindowInfo splitInfo_;
35
36 private:
37 static constexpr uint32_t SPLIT_TEST_SLEEP_S = 1; // split test sleep time
38 };
39
SetUpTestCase()40 void WindowSplitTest::SetUpTestCase()
41 {
42 }
43
TearDownTestCase()44 void WindowSplitTest::TearDownTestCase()
45 {
46 }
47
SetUp()48 void WindowSplitTest::SetUp()
49 {
50 fullInfo_ = {
51 .name = "",
52 .rect = Utils::customAppRect_,
53 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
54 .mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY,
55 .needAvoid = true,
56 .parentLimit = false,
57 .parentId = INVALID_WINDOW_ID,
58 };
59
60 splitInfo_ = {
61 .name = "",
62 .rect = Utils::customAppRect_,
63 .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
64 .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
65 .needAvoid = true,
66 .parentLimit = false,
67 .parentId = INVALID_WINDOW_ID,
68 };
69
70 activeWindows_.clear();
71 }
72
TearDown()73 void WindowSplitTest::TearDown()
74 {
75 while (!activeWindows_.empty()) {
76 ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
77 activeWindows_.pop_back();
78 }
79 }
80
81 namespace {
82 /**
83 * @tc.name: SplitWindow01
84 * @tc.desc: first create a secondary window, then create a primary window, test mode change
85 * @tc.type: FUNC
86 */
87 HWTEST_F(WindowSplitTest, SplitWindow01, Function | MediumTest | Level3)
88 {
89 fullInfo_.name = "fullscreen.1";
90 fullInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
91 splitInfo_.name = "primary.1";
92 splitInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
93
94 const sptr<Window>& priWindow = Utils::CreateTestWindow(splitInfo_);
95 if (priWindow == nullptr) {
96 return;
97 }
98 activeWindows_.push_back(priWindow);
99 priWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
100 sleep(SPLIT_TEST_SLEEP_S);
101 ASSERT_EQ(WMError::WM_OK, priWindow->Show());
102 sleep(SPLIT_TEST_SLEEP_S);
103
104 const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
105 if (fullWindow == nullptr) {
106 return;
107 }
108 activeWindows_.push_back(fullWindow);
109 fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
110 sleep(SPLIT_TEST_SLEEP_S);
111 ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
112 sleep(SPLIT_TEST_SLEEP_S);
113
114
115 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode());
116 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode());
117
118 ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
119 sleep(SPLIT_TEST_SLEEP_S);
120 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode());
121 ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
122 sleep(SPLIT_TEST_SLEEP_S);
123 }
124
125 /**
126 * @tc.name: SplitWindow02
127 * @tc.desc: first create a primary window, then create a secondary window, test mode change
128 * @tc.type: FUNC
129 */
130 HWTEST_F(WindowSplitTest, SplitWindow02, Function | MediumTest | Level3)
131 {
132 fullInfo_.name = "fullscreen.2";
133 fullInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
134 splitInfo_.name = "secondary.2";
135 splitInfo_.mode = WindowMode::WINDOW_MODE_FULLSCREEN;
136
137 const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
138 if (fullWindow == nullptr) {
139 return;
140 }
141 activeWindows_.push_back(fullWindow);
142 fullWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
143 sleep(SPLIT_TEST_SLEEP_S);
144 ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
145 sleep(SPLIT_TEST_SLEEP_S);
146
147 const sptr<Window>& secWindow = Utils::CreateTestWindow(splitInfo_);
148 ASSERT_NE(nullptr, secWindow);
149 activeWindows_.push_back(secWindow);
150 secWindow->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
151 sleep(SPLIT_TEST_SLEEP_S);
152 ASSERT_EQ(WMError::WM_OK, secWindow->Show());
153 sleep(SPLIT_TEST_SLEEP_S);
154
155
156 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, secWindow->GetMode());
157 ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, fullWindow->GetMode());
158
159 ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
160 sleep(SPLIT_TEST_SLEEP_S);
161 ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, secWindow->GetMode());
162 ASSERT_EQ(WMError::WM_OK, secWindow->Hide());
163 sleep(SPLIT_TEST_SLEEP_S);
164 }
165
166 /**
167 * @tc.name: SplitScreen03
168 * @tc.desc: first create a secondary window, then create a primary window, test rects
169 * @tc.type: FUNC
170 */
171 HWTEST_F(WindowSplitTest, SplitScreen03, Function | MediumTest | Level3)
172 {
173 fullInfo_.name = "fullscreen.3";
174 fullInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
175 splitInfo_.name = "primary.3";
176 splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
177
178 const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
179 if (fullWindow == nullptr) {
180 return;
181 }
182 activeWindows_.push_back(fullWindow);
183 ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
184 sleep(SPLIT_TEST_SLEEP_S);
185 const sptr<Window>& priWindow = Utils::CreateTestWindow(splitInfo_);
186 ASSERT_NE(nullptr, priWindow);
187 activeWindows_.push_back(priWindow);
188 ASSERT_EQ(WMError::WM_OK, priWindow->Show());
189 sleep(SPLIT_TEST_SLEEP_S);
190
191 Utils::InitSplitRects();
192 Utils::UpdateSplitRects(fullWindow);
193
194 ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.secondaryRect));
195 ASSERT_TRUE(Utils::RectEqualTo(priWindow, Utils::splitRects_.primaryRect));
196
197 ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
198 sleep(SPLIT_TEST_SLEEP_S);
199 ASSERT_EQ(WMError::WM_OK, priWindow->Hide());
200 sleep(SPLIT_TEST_SLEEP_S);
201 }
202
203 /**
204 * @tc.name: SplitScreen04
205 * @tc.desc: first create a primary window, then create a secondary window, test rects
206 * @tc.type: FUNC
207 */
208 HWTEST_F(WindowSplitTest, SplitScreen04, Function | MediumTest | Level3)
209 {
210 fullInfo_.name = "fullscreen.4";
211 splitInfo_.name = "secondary.4";
212 splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
213
214 const sptr<Window>& fullWindow = Utils::CreateTestWindow(fullInfo_);
215 if (fullWindow == nullptr) {
216 return;
217 }
218
219 activeWindows_.push_back(fullWindow);
220 ASSERT_EQ(WMError::WM_OK, fullWindow->Show());
221 sleep(SPLIT_TEST_SLEEP_S);
222 const sptr<Window>& secWindow = Utils::CreateTestWindow(splitInfo_);
223 ASSERT_NE(nullptr, secWindow);
224 activeWindows_.push_back(secWindow);
225 ASSERT_EQ(WMError::WM_OK, secWindow->Show());
226 sleep(SPLIT_TEST_SLEEP_S);
227
228 Utils::InitSplitRects();
229 Utils::UpdateSplitRects(fullWindow);
230
231 ASSERT_TRUE(Utils::RectEqualTo(fullWindow, Utils::splitRects_.primaryRect));
232 ASSERT_TRUE(Utils::RectEqualTo(secWindow, Utils::splitRects_.secondaryRect));
233
234 ASSERT_EQ(WMError::WM_OK, fullWindow->Hide());
235 sleep(SPLIT_TEST_SLEEP_S);
236 ASSERT_EQ(WMError::WM_OK, secWindow->Hide());
237 sleep(SPLIT_TEST_SLEEP_S);
238 }
239 }
240 } // namespace Rosen
241 } // namespace OHOS
242