1 /*
2 * Copyright (c) 2025 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
18 #include "ability_context_impl.h"
19
20 #include "mock_session.h"
21 #include "mock_uicontent.h"
22 #include "window_scene_session_impl.h"
23 #include "window_test_utils.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 using Utils = WindowTestUtils;
31
32 class WindowPCTest : public testing::Test {
33 public:
34 void SetUp() override;
35 void TearDown() override;
36
37 private:
38 static constexpr uint32_t TEST_SLEEP_S = 1; // test sleep time
39 std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
40 };
41
SetUp()42 void WindowPCTest::SetUp()
43 {
44 abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
45 }
46
TearDown()47 void WindowPCTest::TearDown()
48 {
49 abilityContext_ = nullptr;
50 }
51
52 namespace {
53 /**
54 * @tc.name: setHandwritingFlag01
55 * @tc.desc: setHandwritingFlag
56 * @tc.type: FUNC
57 */
58 HWTEST_F(WindowPCTest, setHandwritingFlag01, Function | MediumTest | Level0)
59 {
60 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
61 option->SetWindowName("Window2_1");
62 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
63 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
64
65 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
66 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
67 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
68 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
69
70 window->property_->SetPersistentId(10021);
71 window->hostSession_ = session;
72
73 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
74 ASSERT_EQ(WMError::WM_OK, window->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_HANDWRITING)));
75
76 window->Destroy(true, true);
77 }
78
79 /**
80 * @tc.name: setHandwritingFlag02
81 * @tc.desc: setHandwritingFlag
82 * @tc.type: FUNC
83 */
84 HWTEST_F(WindowPCTest, setHandwritingFlag02, Function | MediumTest | Level0)
85 {
86 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
87 option->SetWindowName("Window2_2");
88 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
89 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
90
91 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
92 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
93 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
94 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
95
96 window->property_->SetPersistentId(10022);
97 window->hostSession_ = session;
98
99 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
100 ASSERT_EQ(WMError::WM_OK, window->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_HANDWRITING)));
101
102 window->Destroy(true, true);
103 }
104
105 /**
106 * @tc.name: setHandwritingFlag03
107 * @tc.desc: setHandwritingFlag
108 * @tc.type: FUNC
109 */
110 HWTEST_F(WindowPCTest, setHandwritingFlag03, Function | MediumTest | Level0)
111 {
112 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
113 option->SetWindowName("Window2_3");
114 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
115 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
116
117 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
118 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
119 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
120 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
121
122 window->property_->SetPersistentId(10023);
123 window->hostSession_ = session;
124
125 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
126 ASSERT_EQ(WMError::WM_OK, window->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_HANDWRITING)));
127
128 window->Destroy(true, true);
129 }
130
131 /**
132 * @tc.name: SetResizeByDragEnabled01
133 * @tc.desc: SetResizeByDragEnabled MAIN_WINDOW
134 * @tc.type: FUNC
135 */
136 HWTEST_F(WindowPCTest, SetResizeByDragEnabled01, Function | MediumTest | Level0)
137 {
138 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
139 option->SetWindowName("Window5_1");
140 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
141 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
142
143 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
144 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
145 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
146 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
147
148 window->hostSession_ = session;
149 window->property_->SetPersistentId(10051);
150 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
151
152 ASSERT_EQ(true, window->property_->GetDragEnabled());
153
154 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
155 ASSERT_EQ(WMError::WM_OK, window->SetResizeByDragEnabled(false));
156 ASSERT_EQ(false, window->property_->GetDragEnabled());
157
158 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
159 ASSERT_EQ(WMError::WM_OK, window->SetResizeByDragEnabled(true));
160 ASSERT_EQ(true, window->property_->GetDragEnabled());
161
162 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
163 ASSERT_EQ(WMError::WM_OK, window->SetResizeByDragEnabled(false));
164 ASSERT_EQ(false, window->property_->GetDragEnabled());
165
166 window->Destroy(true, true);
167 }
168
169 /**
170 * @tc.name: SetResizeByDragEnabled02
171 * @tc.desc: SetResizeByDragEnabled SUB_WINDOW
172 * @tc.type: FUNC
173 */
174 HWTEST_F(WindowPCTest, SetResizeByDragEnabled02, Function | MediumTest | Level0)
175 {
176 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
177 option->SetWindowName("Window5_2");
178 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
179 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
180 option->SetSubWindowDecorEnable(true);
181
182 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
183 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
184 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
185 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
186
187 window->hostSession_ = session;
188 window->property_->SetPersistentId(10052);
189 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
190
191 ASSERT_EQ(true, window->property_->GetDragEnabled());
192
193 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
194 ASSERT_EQ(WMError::WM_OK, window->SetResizeByDragEnabled(false));
195 ASSERT_EQ(false, window->property_->GetDragEnabled());
196
197 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
198 ASSERT_EQ(WMError::WM_OK, window->SetResizeByDragEnabled(true));
199 ASSERT_EQ(true, window->property_->GetDragEnabled());
200
201 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
202 ASSERT_EQ(WMError::WM_OK, window->SetResizeByDragEnabled(false));
203 ASSERT_EQ(false, window->property_->GetDragEnabled());
204
205 window->Destroy(true, true);
206 }
207
208 /**
209 * @tc.name: SetResizeByDragEnabled03
210 * @tc.desc: SetResizeByDragEnabled SYSTEM_SUB_WINDOW
211 * @tc.type: FUNC
212 */
213 HWTEST_F(WindowPCTest, SetResizeByDragEnabled03, Function | MediumTest | Level0)
214 {
215 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
216 option->SetWindowName("Window5_3");
217 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
218 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
219 option->SetSubWindowDecorEnable(true);
220
221 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
222 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
223 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
224 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
225
226 window->hostSession_ = session;
227 window->property_->SetPersistentId(10053);
228 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
229
230 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
231 ASSERT_EQ(WMError::WM_ERROR_INVALID_TYPE, window->SetResizeByDragEnabled(true));
232
233 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
234 ASSERT_EQ(WMError::WM_ERROR_INVALID_TYPE, window->SetResizeByDragEnabled(false));
235
236 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
237 ASSERT_EQ(WMError::WM_ERROR_INVALID_TYPE, window->SetResizeByDragEnabled(true));
238
239 window->Destroy(true, true);
240 }
241
242 /**
243 * @tc.name: SetWindowTitleMoveEnabled01
244 * @tc.desc: SetWindowTitleMoveEnabled MAIN_WINDOW
245 * @tc.type: FUNC
246 */
247 HWTEST_F(WindowPCTest, SetWindowTitleMoveEnabled01, Function | MediumTest | Level0)
248 {
249 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
250 option->SetWindowName("Window6_1");
251 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
252 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
253
254 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
255 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
256 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
257 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
258
259 window->hostSession_ = session;
260 window->property_->SetPersistentId(10061);
261 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
262
263 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
264
265 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
266 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
267 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
268 ASSERT_EQ(WMError::WM_OK, window->SetWindowTitleMoveEnabled(false));
269 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
270 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
271
272 window->Destroy(true, true);
273 }
274
275 /**
276 * @tc.name: SetWindowTitleMoveEnabled02
277 * @tc.desc: SetWindowTitleMoveEnabled SUB_WINDOW
278 * @tc.type: FUNC
279 */
280 HWTEST_F(WindowPCTest, SetWindowTitleMoveEnabled02, Function | MediumTest | Level0)
281 {
282 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
283 option->SetWindowName("Window6_2");
284 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
285 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
286
287 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
288 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
289 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
290 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
291
292 window->hostSession_ = session;
293 window->property_->SetPersistentId(10062);
294 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
295
296 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
297
298 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
299 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
300 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
301 ASSERT_EQ(WMError::WM_OK, window->SetWindowTitleMoveEnabled(false));
302 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
303 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
304
305 window->Destroy(true, true);
306 }
307
308 /**
309 * @tc.name: SetWindowTitleMoveEnabled03
310 * @tc.desc: SetWindowTitleMoveEnabled SYSTEM_SUB_WINDOW
311 * @tc.type: FUNC
312 */
313 HWTEST_F(WindowPCTest, SetWindowTitleMoveEnabled03, Function | MediumTest | Level0)
314 {
315 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
316 option->SetWindowName("Window6_3");
317 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
318 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
319
320 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
321 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
322 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
323 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
324
325 window->hostSession_ = session;
326 window->property_->SetPersistentId(10063);
327 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
328
329 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
330
331 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
332 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
333 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
334 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetWindowTitleMoveEnabled(false));
335 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
336 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetWindowTitleMoveEnabled(true));
337
338 window->Destroy(true, true);
339 }
340
341 /**
342 * @tc.name: StartMoveWindow01
343 * @tc.desc: startMoving MAIN_WINDOW
344 * @tc.type: FUNC
345 */
346 HWTEST_F(WindowPCTest, StartMoveWindow01, Function | MediumTest | Level0)
347 {
348 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
349 option->SetWindowName("Window7_1");
350 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
351 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
352
353 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
354 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
355 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
356 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
357
358 window->hostSession_ = session;
359 window->property_->SetPersistentId(10071);
360 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
361
362 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
363
364 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
365 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
366 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
367 ASSERT_EQ(WmErrorCode::WM_OK, window->StartMoveWindow());
368 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
369 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
370
371 window->Destroy(true, true);
372 }
373
374 /**
375 * @tc.name: StartMoveWindow02
376 * @tc.desc: startMoving SUB_WINDOW
377 * @tc.type: FUNC
378 */
379 HWTEST_F(WindowPCTest, StartMoveWindow02, Function | MediumTest | Level0)
380 {
381 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
382 option->SetWindowName("Window7_2");
383 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
384 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
385
386 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
387 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
388 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
389 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
390
391 window->hostSession_ = session;
392 window->property_->SetPersistentId(10072);
393 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
394
395 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
396
397 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
398 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
399 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
400 ASSERT_EQ(WmErrorCode::WM_OK, window->StartMoveWindow());
401 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
402 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
403
404 window->Destroy(true, true);
405 }
406
407 /**
408 * @tc.name: StartMoveWindow03
409 * @tc.desc: startMoving SYSTEM_SUB_WINDOW
410 * @tc.type: FUNC
411 */
412 HWTEST_F(WindowPCTest, StartMoveWindow03, Function | MediumTest | Level0)
413 {
414 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
415 option->SetWindowName("Window7_3");
416 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
417 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
418
419 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
420 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
421 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
422 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
423
424 window->hostSession_ = session;
425 window->property_->SetPersistentId(10073);
426 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
427
428 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
429
430 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
431 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
432 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
433 ASSERT_EQ(WmErrorCode::WM_OK, window->StartMoveWindow());
434 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
435 ASSERT_EQ(WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT, window->StartMoveWindow());
436
437 window->Destroy(true, true);
438 }
439
440 /**
441 * @tc.name: SetMainWindowTopmost01
442 * @tc.desc: SetMainWindowTopmost MAIN_WINDOW
443 * @tc.type: FUNC
444 */
445 HWTEST_F(WindowPCTest, SetMainWindowTopmost01, Function | MediumTest | Level0)
446 {
447 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
448 option->SetWindowName("Window8_1");
449 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
450 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
451
452 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
453 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
454 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
455 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
456
457 window->hostSession_ = session;
458 window->property_->SetPersistentId(10081);
459 window->state_ = WindowState::STATE_CREATED;
460
461 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
462 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetMainWindowTopmost(true));
463 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
464 ASSERT_EQ(WMError::WM_OK, window->SetMainWindowTopmost(false));
465 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
466 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetMainWindowTopmost(true));
467
468 window->Destroy(true, true);
469 }
470
471 /**
472 * @tc.name: SetMainWindowTopmost02
473 * @tc.desc: SetMainWindowTopmost SUB_WINDOW
474 * @tc.type: FUNC
475 */
476 HWTEST_F(WindowPCTest, SetMainWindowTopmost02, Function | MediumTest | Level0)
477 {
478 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
479 option->SetWindowName("Window8_2");
480 option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
481 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
482
483 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
484 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
485 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
486 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
487
488 window->hostSession_ = session;
489 window->property_->SetPersistentId(10082);
490 window->state_ = WindowState::STATE_CREATED;
491
492 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
493 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetMainWindowTopmost(true));
494 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
495 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetMainWindowTopmost(false));
496 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
497 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetMainWindowTopmost(true));
498
499 window->Destroy(true, true);
500 }
501
502 /**
503 * @tc.name: SetMainWindowTopmost03
504 * @tc.desc: SetMainWindowTopmost SYSTEM_SUB_WINDOW
505 * @tc.type: FUNC
506 */
507 HWTEST_F(WindowPCTest, SetMainWindowTopmost03, Function | MediumTest | Level0)
508 {
509 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
510 option->SetWindowName("Window8_3");
511 option->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
512 option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
513
514 sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
515 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
516 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
517 ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session));
518
519 window->hostSession_ = session;
520 window->property_->SetPersistentId(10083);
521 window->state_ = WindowState::STATE_CREATED;
522
523 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
524 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetMainWindowTopmost(true));
525 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
526 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window->SetMainWindowTopmost(false));
527 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
528 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT, window->SetMainWindowTopmost(true));
529
530 window->Destroy(true, true);
531 }
532
533 }
534 } // namespace Rosen
535 } // namespace OHOS