• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <ability_context.h>
19 #include "window.h"
20 #include "window_option.h"
21 #include "window_scene.h"
22 #include "wm_common.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 class WindowSystemSubWindowTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     virtual void SetUp() override;
34     virtual void TearDown() override;
35 };
36 
SetUpTestCase()37 void WindowSystemSubWindowTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void WindowSystemSubWindowTest::TearDownTestCase()
42 {
43 }
44 
SetUp()45 void WindowSystemSubWindowTest::SetUp()
46 {
47 }
48 
TearDown()49 void WindowSystemSubWindowTest::TearDown()
50 {
51 }
52 
CreateBaseWindow(WindowType type,struct Rect rect,uint32_t flags)53 static sptr<Window> CreateBaseWindow(WindowType type, struct Rect rect, uint32_t flags)
54 {
55     sptr<WindowOption> baseOp = new WindowOption();
56     baseOp->SetWindowType(type);
57     baseOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
58     baseOp->SetWindowRect(rect);
59     baseOp->SetWindowFlags(flags);
60 
61     static int baseCount = 0;
62     std::string baseWindowName = "BaseWindow" + std::to_string(baseCount++);
63     sptr<Window> window = Window::Create(baseWindowName, baseOp, nullptr);
64     return window;
65 }
66 
CreateAppSubWindow(sptr<Window> parentWindow,WindowType type,struct Rect rect,uint32_t flags,std::string name="")67 static sptr<Window> CreateAppSubWindow(sptr<Window> parentWindow, WindowType type, struct Rect rect,
68     uint32_t flags, std::string name = "")
69 {
70     sptr<WindowOption> subOp = new WindowOption();
71     subOp->SetWindowType(type);
72     subOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
73     subOp->SetWindowRect(rect);
74     subOp->SetWindowFlags(flags);
75     subOp->SetParentId(parentWindow->GetWindowId());
76 
77     static int cnt = 0;
78     std::string subWinName = (name == "") ? "AppSubWindow" + std::to_string(cnt++) : name;
79     sptr<Window> window = Window::Create(subWinName, subOp);
80     return window;
81 }
82 
CreateSystemSubWindow(sptr<Window> parentWindow,struct Rect rect,uint32_t flags,std::string name="")83 static sptr<Window> CreateSystemSubWindow(sptr<Window> parentWindow, struct Rect rect,
84     uint32_t flags, std::string name = "")
85 {
86     sptr<WindowOption> subOp = new WindowOption();
87     subOp->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
88     subOp->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
89     subOp->SetWindowRect(rect);
90     subOp->SetWindowFlags(flags);
91     subOp->SetParentId(parentWindow->GetWindowId());
92 
93     static int cnt = 0;
94     std::string subWinName = (name == "") ? "SystemSubWindow" + std::to_string(cnt++) : name;
95     sptr<Window> window = Window::Create(subWinName, subOp);
96     return window;
97 }
98 
99 /**
100  * @tc.name: SystemSubWindow01
101  * @tc.desc: create sub windows with below system Windows
102  * @tc.type: FUNC
103  */
104 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow01, Function | MediumTest | Level2)
105 {
106     std::vector<WindowType> windowTypes = {
107         WindowType::WINDOW_TYPE_WALLPAPER,
108         WindowType::WINDOW_TYPE_DESKTOP,
109     };
110     for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
111         struct Rect baseRect = {0, 0, 100, 200};
112         uint32_t baseFlags = 0;
113         sptr<Window> baseWindow = CreateBaseWindow(static_cast<WindowType>(*itor), baseRect, baseFlags);
114         ASSERT_NE(nullptr, baseWindow);
115         struct Rect rect = {0, 0, 100, 200};
116         uint32_t flags = 0;
117         sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
118         ASSERT_NE(nullptr, subWindow);
119 
120         ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
121         ASSERT_EQ(WMError::WM_OK, subWindow->Show());
122 
123         ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
124         ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
125 
126         ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
127         ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
128     }
129 }
130 
131 /**
132  * @tc.name: SystemSubWindow02
133  * @tc.desc: create sub windows with above system Windows except WINDOW_TYPE_DIALOG
134  * @tc.type: FUNC
135  */
136 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow02, Function | MediumTest | Level2)
137 {
138     std::vector<WindowType> windowTypes = {
139         WindowType::WINDOW_TYPE_APP_LAUNCHING,
140         WindowType::WINDOW_TYPE_DOCK_SLICE,
141         WindowType::WINDOW_TYPE_INCOMING_CALL,
142         WindowType::WINDOW_TYPE_SEARCHING_BAR,
143         WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
144         WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,
145         WindowType::WINDOW_TYPE_FLOAT,
146         WindowType::WINDOW_TYPE_TOAST,
147         WindowType::WINDOW_TYPE_STATUS_BAR,
148         WindowType::WINDOW_TYPE_PANEL,
149         WindowType::WINDOW_TYPE_KEYGUARD,
150         WindowType::WINDOW_TYPE_VOLUME_OVERLAY,
151         WindowType::WINDOW_TYPE_NAVIGATION_BAR,
152         WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
153         WindowType::WINDOW_TYPE_POINTER,
154         WindowType::WINDOW_TYPE_LAUNCHER_RECENT,
155         WindowType::WINDOW_TYPE_LAUNCHER_DOCK,
156         WindowType::WINDOW_TYPE_BOOT_ANIMATION,
157         WindowType::WINDOW_TYPE_FREEZE_DISPLAY,
158         WindowType::WINDOW_TYPE_VOICE_INTERACTION,
159         WindowType::WINDOW_TYPE_FLOAT_CAMERA,
160         WindowType::WINDOW_TYPE_PLACEHOLDER,
161         WindowType::WINDOW_TYPE_SCREENSHOT,
162     };
163     for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
164         struct Rect baseRect = {0, 0, 100, 200};
165         uint32_t baseFlags = 0;
166         sptr<Window> baseWindow = CreateBaseWindow(static_cast<WindowType>(*itor), baseRect, baseFlags);
167         ASSERT_NE(nullptr, baseWindow);
168 
169         struct Rect rect = {0, 0, 100, 200};
170         uint32_t flags = 0;
171         sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
172         ASSERT_NE(nullptr, subWindow);
173 
174         ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
175         ASSERT_EQ(WMError::WM_OK, subWindow->Show());
176 
177         ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
178         ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
179 
180         ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
181         ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
182     }
183 }
184 
185 /**
186  * @tc.name: SystemSubWindow03
187  * @tc.desc: create sub windows with app main Windows
188  * @tc.type: FUNC
189  */
190 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow03, Function | MediumTest | Level2)
191 {
192     std::vector<WindowType> windowTypes = { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
193     for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
194         struct Rect baseRect = {0, 0, 100, 200};
195         uint32_t baseFlags = 0;
196         sptr<Window> baseWindow = CreateBaseWindow(static_cast<WindowType>(*itor), baseRect, baseFlags);
197         ASSERT_NE(nullptr, baseWindow);
198 
199         struct Rect rect = {0, 0, 100, 200};
200         uint32_t flags = 0;
201         sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
202         ASSERT_NE(nullptr, subWindow);
203 
204         ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
205         ASSERT_EQ(WMError::WM_OK, subWindow->Show());
206 
207         ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
208         ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
209 
210         ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
211         ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
212     }
213 }
214 
215 /**
216  * @tc.name: SystemSubWindow04
217  * @tc.desc: create sub windows with app sub Windows
218  * @tc.type: FUNC
219  */
220 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow04, Function | MediumTest | Level2)
221 {
222     std::vector<WindowType> windowTypes = {
223         WindowType::WINDOW_TYPE_MEDIA,
224         WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
225         WindowType::WINDOW_TYPE_APP_COMPONENT,
226     };
227     for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
228         struct Rect baseRect = {0, 0, 100, 200};
229         uint32_t baseFlags = 0;
230         sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, baseRect, baseFlags);
231         ASSERT_NE(nullptr, baseWindow);
232 
233         sptr<Window> appSubWindow = CreateAppSubWindow(baseWindow, static_cast<WindowType>(*itor), baseRect, baseFlags);
234         ASSERT_NE(nullptr, appSubWindow);
235 
236         struct Rect rect = {0, 0, 100, 200};
237         uint32_t flags = 0;
238         sptr<Window> subWindow = CreateSystemSubWindow(appSubWindow, rect, flags);
239         ASSERT_EQ(nullptr, subWindow);
240         ASSERT_EQ(WMError::WM_OK, appSubWindow->Destroy());
241         ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
242     }
243 }
244 
245 /**
246  * @tc.name: SystemSubWindow05
247  * @tc.desc: create sub windows with system sub Windows
248  * @tc.type: FUNC
249  */
250 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow05, Function | MediumTest | Level3)
251 {
252     struct Rect baseRect = {0, 0, 100, 200};
253     uint32_t baseFlags = 0;
254     sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_DOCK_SLICE, baseRect, baseFlags);
255     ASSERT_NE(nullptr, baseWindow);
256 
257     sptr<Window> systemSubWindow = CreateSystemSubWindow(baseWindow, baseRect, baseFlags);
258     ASSERT_NE(nullptr, systemSubWindow);
259 
260     struct Rect rect = {0, 0, 100, 200};
261     uint32_t flags = 0;
262     sptr<Window> subWindow = CreateSystemSubWindow(systemSubWindow, rect, flags);
263     ASSERT_EQ(nullptr, subWindow);
264 
265     ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
266     ASSERT_EQ(WMError::WM_OK, systemSubWindow->Show());
267 
268     ASSERT_EQ(WMError::WM_OK, systemSubWindow->Hide());
269     ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
270 
271     ASSERT_EQ(WMError::WM_OK, systemSubWindow->Destroy());
272     ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
273 }
274 
275 /**
276  * @tc.name: SystemSubWindow06
277  * @tc.desc: FullScreen Main Window + 2 SubWindows
278  * @tc.type: FUNC
279  */
280 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow06, Function | MediumTest | Level3)
281 {
282     struct Rect baseRect = {0, 0, 100, 200};
283     uint32_t baseFlags = 0;
284     sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_DOCK_SLICE, baseRect, baseFlags);
285     ASSERT_NE(nullptr, baseWindow);
286 
287     struct Rect rect = {0, 0, 100, 200};
288     uint32_t flags = 0;
289     sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
290     ASSERT_NE(nullptr, subWindow);
291 
292     ASSERT_EQ(WMError::WM_OK, baseWindow->Show());
293     ASSERT_EQ(WMError::WM_OK, subWindow->Show());
294 
295     bool isFocus = subWindow->GetFocusable();
296     ASSERT_EQ(WMError::WM_OK, subWindow->SetFocusable(!isFocus));
297     ASSERT_EQ(WMError::WM_OK, subWindow->MoveTo(0, 0));
298     ASSERT_EQ(WMError::WM_OK, subWindow->Resize(200, 400));
299     ASSERT_EQ(WMError::WM_OK, subWindow->SetTurnScreenOn(true));
300 
301     ASSERT_EQ(WMError::WM_ERROR_INVALID_TYPE, subWindow->SetBrightness(0.5f));
302     ASSERT_EQ(WMError::WM_OK, subWindow->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN));
303 
304     ASSERT_EQ(WMError::WM_OK, subWindow->Hide());
305     ASSERT_EQ(WMError::WM_OK, baseWindow->Hide());
306 
307     ASSERT_EQ(WMError::WM_OK, subWindow->Destroy());
308     ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
309 }
310 /**
311  * @tc.name: SystemSubWindow07
312  * @tc.desc: create sub windows with dialog
313  * @tc.type: FUNC
314  */
315 HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow07, Function | MediumTest | Level3)
316 {
317     struct Rect baseRect = {0, 0, 100, 200};
318     uint32_t baseFlags = 0;
319     sptr<Window> baseWindow = CreateBaseWindow(WindowType::WINDOW_TYPE_DIALOG, baseRect, baseFlags);
320     ASSERT_NE(nullptr, baseWindow);
321 
322     struct Rect rect = {0, 0, 100, 200};
323     uint32_t flags = 0;
324     sptr<Window> subWindow = CreateSystemSubWindow(baseWindow, rect, flags);
325     ASSERT_EQ(nullptr, subWindow);
326     ASSERT_EQ(WMError::WM_OK, baseWindow->Destroy());
327 }
328 } // namespace Rosen
329 } // namespace OHOS
330