1 /*
2 * Copyright (c) 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 #include <gtest/gtest.h>
17 #include "ability_context_impl.h"
18 #include "display_manager_proxy.h"
19 #include "mock_uicontent.h"
20 #include "mock_window_adapter.h"
21 #include "singleton_mocker.h"
22 #include "window_impl.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Rosen {
29 using Mocker = SingletonMocker<WindowAdapter, MockWindowAdapter>;
30 class MockOccupiedAreaChangeListener : public IOccupiedAreaChangeListener {
31 public:
32 MOCK_METHOD2(OnSizeChange,
33 void(const sptr<OccupiedAreaChangeInfo>& info, const std::shared_ptr<RSTransaction>& rsTransaction));
34 };
35
36 class MockMmiPointerEvent : public MMI::PointerEvent {
37 public:
MockMmiPointerEvent()38 MockMmiPointerEvent() : MMI::PointerEvent(0) {}
39 };
40
41 class MockWindowDragListener : public IWindowDragListener {
42 public:
43 MOCK_METHOD3(OnDrag, void(int32_t x, int32_t y, DragEvent event));
44 };
45
46 class WindowImplTest5 : public testing::Test {
47 public:
48 static void SetUpTestCase();
49 static void TearDownTestCase();
50 void SetUp() override;
51 void TearDown() override;
52
53 std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
54
55 private:
56 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
57 };
SetUpTestCase()58 void WindowImplTest5::SetUpTestCase() {}
59
TearDownTestCase()60 void WindowImplTest5::TearDownTestCase() {}
61
SetUp()62 void WindowImplTest5::SetUp() {}
63
TearDown()64 void WindowImplTest5::TearDown()
65 {
66 usleep(WAIT_SYNC_IN_NS);
67 }
68
69 namespace {
70 /**
71 * @tc.name: IsAllowHaveSystemSubWindow
72 * @tc.desc: IsAllowHaveSystemSubWindow desc
73 * @tc.type: FUNC
74 */
75 HWTEST_F(WindowImplTest5, IsAllowHaveSystemSubWindow, Function | SmallTest | Level1)
76 {
77 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
78 option->SetWindowName("IsAllowHaveSystemSubWindow");
79 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
80 window->property_->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
81 EXPECT_EQ(window->IsAllowHaveSystemSubWindow(), false);
82
83 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
84 EXPECT_EQ(window->IsAllowHaveSystemSubWindow(), false);
85
86 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
87 EXPECT_EQ(window->IsAllowHaveSystemSubWindow(), false);
88
89 window->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
90 EXPECT_EQ(window->IsAllowHaveSystemSubWindow(), true);
91 }
92
93 /**
94 * @tc.name: NotifyMemoryLevel
95 * @tc.desc: NotifyMemoryLevel desc
96 * @tc.type: FUNC
97 */
98 HWTEST_F(WindowImplTest5, NotifyMemoryLevel, Function | SmallTest | Level1)
99 {
100 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
101 option->SetWindowName("NotifyMemoryLevel");
102 option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
103 option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
104 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
105 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->SetWindowFlags(0));
106 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
107 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
108 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
109 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
110
111 Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window->uiContent_.get());
112 EXPECT_CALL(*content, NotifyMemoryLevel(_)).Times(1).WillOnce(Return());
113 window->NotifyMemoryLevel(1);
114 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
115 EXPECT_CALL(*content, Destroy());
116 ASSERT_EQ(WMError::WM_OK, window->Destroy());
117 }
118
119 /**
120 * @tc.name: SetRequestedOrientation
121 * @tc.desc: SetRequestedOrientation desc
122 * @tc.type: FUNC
123 */
124 HWTEST_F(WindowImplTest5, SetRequestedOrientation, Function | SmallTest | Level1)
125 {
126 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
127 option->SetWindowName("SetRequestedOrientation");
128 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
129 window->property_->SetRequestedOrientation(Orientation::BEGIN);
130 auto orientation = Orientation::BEGIN;
131 window->SetRequestedOrientation(orientation);
132
133 orientation = Orientation::VERTICAL;
134 window->state_ = WindowState::STATE_CREATED;
135 window->SetRequestedOrientation(orientation);
136
137 window->state_ = WindowState::STATE_SHOWN;
138 window->SetRequestedOrientation(orientation);
139 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
140 }
141
142 /**
143 * @tc.name: GetSystemAlarmWindowDefaultSize
144 * @tc.desc: GetSystemAlarmWindowDefaultSize desc
145 * @tc.type: FUNC
146 */
147 HWTEST_F(WindowImplTest5, GetSystemAlarmWindowDefaultSize, Function | SmallTest | Level1)
148 {
149 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
150 option->SetWindowName("GetSystemAlarmWindowDefaultSize");
151 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
152 Rect defaultRect{ 10, 10, 10, 10 };
153 Rect resRect{ 0, 0, 0, 0 };
154
155 SingletonContainer::GetInstance().destroyed_ = true;
156 resRect = window->GetSystemAlarmWindowDefaultSize(defaultRect);
157 EXPECT_EQ(resRect.posX_, defaultRect.posX_);
158
159 SingletonContainer::GetInstance().destroyed_ = false;
160 resRect = window->GetSystemAlarmWindowDefaultSize(defaultRect);
161 }
162
163 /**
164 * @tc.name: CheckCameraFloatingWindowMultiCreated
165 * @tc.desc: CheckCameraFloatingWindowMultiCreated desc
166 * @tc.type: FUNC
167 */
168 HWTEST_F(WindowImplTest5, CheckCameraFloatingWindowMultiCreated, Function | SmallTest | Level1)
169 {
170 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
171 option->SetWindowName("CheckCameraFloatingWindowMultiCreated");
172 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
173 auto type = WindowType::WINDOW_TYPE_FLOAT;
174 EXPECT_EQ(window->CheckCameraFloatingWindowMultiCreated(type), false);
175
176 type = WindowType::WINDOW_TYPE_FLOAT_CAMERA;
177 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
178 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
179 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
180 EXPECT_EQ(window->CheckCameraFloatingWindowMultiCreated(type), false);
181
182 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
183 EXPECT_EQ(window->CheckCameraFloatingWindowMultiCreated(type), false);
184 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
185 ASSERT_EQ(WMError::WM_OK, window->Destroy());
186 }
187
188 /**
189 * @tc.name: SetDefaultOption01
190 * @tc.desc: SetDefaultOption desc
191 * @tc.type: FUNC
192 */
193 HWTEST_F(WindowImplTest5, SetDefaultOption01, Function | SmallTest | Level1)
194 {
195 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
196 option->SetWindowName("SetDefaultOption01");
197 option->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
198 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
199 window->SetDefaultOption();
200
201 window->property_->SetWindowType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
202 window->SetDefaultOption();
203
204 window->property_->SetWindowType(WindowType::WINDOW_TYPE_VOLUME_OVERLAY);
205 window->SetDefaultOption();
206
207 window->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
208 window->SetDefaultOption();
209
210 window->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR);
211 window->SetDefaultOption();
212
213 window->property_->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
214 window->SetDefaultOption();
215
216 window->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYGUARD);
217 window->SetDefaultOption();
218
219 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DRAGGING_EFFECT);
220 window->SetDefaultOption();
221
222 window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT);
223 window->SetDefaultOption();
224
225 window->property_->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
226 window->SetDefaultOption();
227
228 window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
229 window->SetDefaultOption();
230
231 window->property_->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
232 window->SetDefaultOption();
233
234 window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
235 window->SetDefaultOption();
236 ASSERT_EQ(window->property_->GetWindowMode(), WindowMode::WINDOW_MODE_FLOATING);
237 }
238
239 /**
240 * @tc.name: SetDefaultOption02
241 * @tc.desc: SetDefaultOption desc
242 * @tc.type: FUNC
243 */
244 HWTEST_F(WindowImplTest5, SetDefaultOption02, Function | SmallTest | Level1)
245 {
246 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
247 option->SetWindowName("SetDefaultOption02");
248 option->SetWindowType(WindowType::WINDOW_TYPE_VOICE_INTERACTION);
249 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
250 window->SetDefaultOption();
251
252 window->property_->SetWindowType(WindowType::WINDOW_TYPE_LAUNCHER_DOCK);
253 window->SetDefaultOption();
254
255 window->property_->SetWindowType(WindowType::WINDOW_TYPE_SEARCHING_BAR);
256 window->SetDefaultOption();
257
258 window->property_->SetWindowType(WindowType::WINDOW_TYPE_SCREENSHOT);
259 window->SetDefaultOption();
260
261 window->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
262 window->SetDefaultOption();
263
264 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
265 window->SetDefaultOption();
266
267 window->property_->SetWindowType(WindowType::WINDOW_TYPE_BOOT_ANIMATION);
268 window->SetDefaultOption();
269
270 window->property_->SetWindowType(WindowType::WINDOW_TYPE_POINTER);
271 window->SetDefaultOption();
272
273 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE);
274 window->SetDefaultOption();
275
276 window->property_->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_TOAST);
277 window->SetDefaultOption();
278 ASSERT_EQ(window->property_->GetWindowMode(), WindowMode::WINDOW_MODE_FLOATING);
279
280 window->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
281 window->SetDefaultOption();
282 }
283
284 /**
285 * @tc.name: UpdateActiveStatus
286 * @tc.desc: UpdateActiveStatus desc
287 * @tc.type: FUNC
288 */
289 HWTEST_F(WindowImplTest5, UpdateActiveStatus, Function | SmallTest | Level1)
290 {
291 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
292 ASSERT_NE(option, nullptr);
293 option->SetWindowName("UpdateActiveStatus");
294 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
295 ASSERT_NE(window, nullptr);
296
297 bool isActive = true;
298 window->UpdateActiveStatus(isActive);
299
300 isActive = false;
301 window->UpdateActiveStatus(isActive);
302 }
303
304 /**
305 * @tc.name: NotifyForegroundInteractiveStatus
306 * @tc.desc: NotifyForegroundInteractiveStatus desc
307 * @tc.type: FUNC
308 */
309 HWTEST_F(WindowImplTest5, NotifyForegroundInteractiveStatus, Function | SmallTest | Level1)
310 {
311 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
312 option->SetWindowName("NotifyForegroundInteractiveStatus");
313 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
314
315 bool interactive = false;
316 window->state_ = WindowState::STATE_INITIAL;
317 window->NotifyForegroundInteractiveStatus(interactive);
318
319 window->state_ = WindowState::STATE_CREATED;
320 window->NotifyForegroundInteractiveStatus(interactive);
321
322 window->state_ = WindowState::STATE_SHOWN;
323 window->NotifyForegroundInteractiveStatus(interactive);
324
325 interactive = true;
326 window->NotifyForegroundInteractiveStatus(interactive);
327 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
328 }
329
330 /**
331 * @tc.name: UpdateWindowState02
332 * @tc.desc: UpdateWindowState desc
333 * @tc.type: FUNC
334 */
335 HWTEST_F(WindowImplTest5, UpdateWindowState02, Function | SmallTest | Level1)
336 {
337 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
338 option->SetWindowName("UpdateWindowState02");
339 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
340 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
341 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
342 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
343 window->state_ = WindowState::STATE_CREATED;
344 std::shared_ptr<AbilityRuntime::Context> context = std::make_shared<AbilityRuntime::AbilityContextImpl>();
345 window->context_ = context;
346
347 WindowState state = WindowState::STATE_FROZEN;
348
349 window->windowTag_ = WindowTag::MAIN_WINDOW;
350 window->UpdateWindowState(state);
351
352 window->windowTag_ = WindowTag::SUB_WINDOW;
353 window->UpdateWindowState(state);
354
355 state = WindowState::STATE_SHOWN;
356
357 window->windowTag_ = WindowTag::MAIN_WINDOW;
358 window->UpdateWindowState(state);
359
360 window->windowTag_ = WindowTag::SUB_WINDOW;
361 window->UpdateWindowState(state);
362
363 EXPECT_CALL(m->Mock(), RemoveWindow(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
364
365 state = WindowState::STATE_HIDDEN;
366
367 window->windowTag_ = WindowTag::MAIN_WINDOW;
368 window->UpdateWindowState(state);
369
370 window->windowTag_ = WindowTag::SUB_WINDOW;
371 window->UpdateWindowState(state);
372
373 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
374 ASSERT_EQ(WMError::WM_OK, window->Destroy());
375 }
376
377 /**
378 * @tc.name: UpdateWindowStateUnfrozen
379 * @tc.desc: UpdateWindowStateUnfrozen desc
380 * @tc.type: FUNC
381 */
382 HWTEST_F(WindowImplTest5, UpdateWindowStateUnfrozen, Function | SmallTest | Level1)
383 {
384 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
385 option->SetWindowName("UpdateWindowStateUnfrozen");
386 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
387 window->context_ = nullptr;
388
389 window->state_ = WindowState::STATE_CREATED;
390 window->UpdateWindowStateUnfrozen();
391
392 window->state_ = WindowState::STATE_SHOWN;
393 window->UpdateWindowStateUnfrozen();
394
395 std::shared_ptr<AbilityRuntime::Context> context = std::make_shared<AbilityRuntime::AbilityContextImpl>();
396 window->context_ = context;
397
398 window->windowTag_ = WindowTag::MAIN_WINDOW;
399 window->UpdateWindowStateUnfrozen();
400
401 window->windowTag_ = WindowTag::SUB_WINDOW;
402 window->UpdateWindowStateUnfrozen();
403
404 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
405 ASSERT_EQ(WMError::WM_OK, window->Destroy());
406 }
407
408 /**
409 * @tc.name: UpdateFocusStatus
410 * @tc.desc: UpdateFocusStatus desc
411 * @tc.type: FUNC
412 */
413 HWTEST_F(WindowImplTest5, UpdateFocusStatus, Function | SmallTest | Level1)
414 {
415 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
416 option->SetWindowName("UpdateFocusStatus");
417 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
418
419 bool focused = true;
420
421 window->state_ = WindowState::STATE_CREATED;
422 window->UpdateFocusStatus(focused);
423
424 window->state_ = WindowState::STATE_HIDDEN;
425 window->UpdateFocusStatus(focused);
426
427 window->state_ = WindowState::STATE_SHOWN;
428 window->UpdateFocusStatus(focused);
429
430 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
431 ASSERT_EQ(WMError::WM_OK, window->Destroy());
432 }
433
434 /**
435 * @tc.name: RegisterListener01
436 * @tc.desc: Run successfully
437 * @tc.type: FUNC
438 */
439 HWTEST_F(WindowImplTest5, RegisterListener01, Function | SmallTest | Level1)
440 {
441 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
442 option->SetWindowName("UnregisterListener");
443 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
444
445 sptr<MockOccupiedAreaChangeListener> listener1;
446 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener1);
447 sptr<MockOccupiedAreaChangeListener> listener2 = sptr<MockOccupiedAreaChangeListener>::MakeSptr();
448 ASSERT_NE(listener2, nullptr);
449 ASSERT_EQ(window->RegisterOccupiedAreaChangeListener(listener2), WMError::WM_OK);
450 window->occupiedAreaChangeListeners_[window->GetWindowId()].clear();
451 }
452
453 /**
454 * @tc.name: RegisterListener02
455 * @tc.desc: Listener is nullptr
456 * @tc.type: FUNC
457 */
458 HWTEST_F(WindowImplTest5, RegisterListener02, Function | SmallTest | Level1)
459 {
460 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
461 option->SetWindowName("UnregisterListener");
462 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
463
464 sptr<MockOccupiedAreaChangeListener> listener1;
465 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener1);
466 sptr<MockOccupiedAreaChangeListener> listener2 = sptr<MockOccupiedAreaChangeListener>::MakeSptr();
467 ASSERT_NE(listener2, nullptr);
468 ASSERT_EQ(window->RegisterOccupiedAreaChangeListener(nullptr), WMError::WM_ERROR_NULLPTR);
469 window->occupiedAreaChangeListeners_[window->GetWindowId()].clear();
470 }
471
472 /**
473 * @tc.name: UnregisterListener01
474 * @tc.desc: Run successfully
475 * @tc.type: FUNC
476 */
477 HWTEST_F(WindowImplTest5, UnregisterListener01, Function | SmallTest | Level1)
478 {
479 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
480 option->SetWindowName("UnregisterListener");
481 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
482
483 sptr<MockOccupiedAreaChangeListener> listener1;
484 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener1);
485 sptr<MockOccupiedAreaChangeListener> listener2 = sptr<MockOccupiedAreaChangeListener>::MakeSptr();
486 ASSERT_NE(listener2, nullptr);
487 window->RegisterOccupiedAreaChangeListener(listener2);
488 ASSERT_EQ(window->UnregisterOccupiedAreaChangeListener(listener2), WMError::WM_OK);
489 window->occupiedAreaChangeListeners_[window->GetWindowId()].clear();
490 }
491
492 /**
493 * @tc.name: UnregisterListener02
494 * @tc.desc: Listener is nullptr
495 * @tc.type: FUNC
496 */
497 HWTEST_F(WindowImplTest5, UnregisterListener02, Function | SmallTest | Level1)
498 {
499 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
500 option->SetWindowName("UnregisterListener");
501 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
502
503 sptr<MockOccupiedAreaChangeListener> listener1;
504 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener1);
505 sptr<MockOccupiedAreaChangeListener> listener2 = sptr<MockOccupiedAreaChangeListener>::MakeSptr();
506 ASSERT_NE(listener2, nullptr);
507 ASSERT_EQ(window->UnregisterOccupiedAreaChangeListener(nullptr), WMError::WM_ERROR_NULLPTR);
508 window->occupiedAreaChangeListeners_[window->GetWindowId()].clear();
509 }
510
511 /**
512 * @tc.name: Close
513 * @tc.desc: Close test
514 * @tc.type: FUNC
515 */
516 HWTEST_F(WindowImplTest5, Close, Function | SmallTest | Level1)
517 {
518 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
519 option->SetWindowName("Close");
520 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
521
522 window->state_ = WindowState::STATE_CREATED;
523 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
524 ASSERT_EQ(window->Close(), WMError::WM_OK);
525
526 std::shared_ptr<AbilityRuntime::Context> context = std::make_shared<AbilityRuntime::AbilityContextImpl>();
527 window->context_ = context;
528 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
529 window->Close();
530 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
531 }
532
533 /**
534 * @tc.name: GetVSyncPeriod
535 * @tc.desc: GetVSyncPeriod test
536 * @tc.type: FUNC
537 */
538 HWTEST_F(WindowImplTest5, GetVSyncPeriod, Function | SmallTest | Level1)
539 {
540 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
541 option->SetWindowName("GetVSyncPeriod");
542 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
543
544 window->SetWindowState(WindowState::STATE_DESTROYED);
545 ASSERT_EQ(window->GetWindowState(), WindowState::STATE_DESTROYED);
546 SingletonContainer::GetInstance().destroyed_ = true;
547 ASSERT_EQ(window->GetVSyncPeriod(), 0);
548
549 SingletonContainer::GetInstance().destroyed_ = false;
550 window->vsyncStation_ = std::make_shared<VsyncStation>(1);
551 window->GetVSyncPeriod();
552
553 window->vsyncStation_ = nullptr;
554 ASSERT_EQ(window->GetVSyncPeriod(), 0);
555 }
556
557 /**
558 * @tc.name: RequestVsync02
559 * @tc.desc: RequestVsync test
560 * @tc.type: FUNC
561 */
562 HWTEST_F(WindowImplTest5, RequestVsync02, Function | SmallTest | Level1)
563 {
564 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
565 option->SetWindowName("RequestVsync02");
566 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
567
568 window->state_ = WindowState::STATE_CREATED;
569 std::shared_ptr<VsyncCallback> callback = std::make_shared<VsyncCallback>();
570
571 SingletonContainer::GetInstance().destroyed_ = true;
572 window->RequestVsync(callback);
573
574 SingletonContainer::GetInstance().destroyed_ = false;
575 window->vsyncStation_ = std::make_shared<VsyncStation>(1);
576 window->RequestVsync(callback);
577
578 window->vsyncStation_ = nullptr;
579 window->RequestVsync(callback);
580 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
581 }
582
583 /**
584 * @tc.name: ConsumePointerEvent02
585 * @tc.desc: ConsumePointerEvent test
586 * @tc.type: FUNC
587 */
588 HWTEST_F(WindowImplTest5, ConsumePointerEvent02, Function | SmallTest | Level1)
589 {
590 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
591 ASSERT_NE(option, nullptr);
592 option->SetWindowName("ConsumePointerEvent02");
593 option->SetWindowType(WindowType::WINDOW_TYPE_LAUNCHER_RECENT);
594 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
595 ASSERT_NE(window, nullptr);
596
597 Rect rect{ 0, 0, 10u, 10u };
598 window->property_->SetWindowRect(rect);
599
600 std::shared_ptr<MMI::PointerEvent> pointerEvent = std::make_shared<MockMmiPointerEvent>();
601 MMI::PointerEvent::PointerItem item;
602 pointerEvent->SetPointerId(0);
603 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
604 window->ConsumePointerEvent(pointerEvent);
605
606 item.SetPointerId(0);
607 item.SetDisplayX(15);
608 item.SetDisplayY(15);
609 pointerEvent->AddPointerItem(item);
610 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP);
611 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
612 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
613 window->ConsumePointerEvent(pointerEvent);
614
615 item.SetDisplayX(5);
616 item.SetDisplayY(5);
617 pointerEvent->UpdatePointerItem(0, item);
618 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
619 window->ConsumePointerEvent(pointerEvent);
620
621 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL);
622 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE);
623 window->ConsumePointerEvent(pointerEvent);
624
625 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
626 window->ConsumePointerEvent(pointerEvent);
627
628 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
629 window->ConsumePointerEvent(pointerEvent);
630
631 window->property_->SetWindowType(WindowType::WINDOW_TYPE_LAUNCHER_RECENT);
632 window->ConsumePointerEvent(pointerEvent);
633 }
634
635 /**
636 * @tc.name: PerfLauncherHotAreaIfNeed
637 * @tc.desc: PerfLauncherHotAreaIfNeed test
638 * @tc.type: FUNC
639 */
640 HWTEST_F(WindowImplTest5, PerfLauncherHotAreaIfNeed, Function | SmallTest | Level1)
641 {
642 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
643 ASSERT_NE(option, nullptr);
644 option->SetWindowName("PerfLauncherHotAreaIfNeed");
645 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
646 ASSERT_NE(window, nullptr);
647
648 std::shared_ptr<MMI::PointerEvent> pointerEvent = std::make_shared<MockMmiPointerEvent>();
649 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_CANCEL);
650 pointerEvent->SetPointerId(0);
651
652 SingletonContainer::GetInstance().destroyed_ = true;
653 window->PerfLauncherHotAreaIfNeed(pointerEvent);
654
655 SingletonContainer::GetInstance().destroyed_ = false;
656 window->PerfLauncherHotAreaIfNeed(pointerEvent);
657 }
658
659 /**
660 * @tc.name: NotifyOccupiedAreaChange
661 * @tc.desc: NotifyOccupiedAreaChange test
662 * @tc.type: FUNC
663 */
664 HWTEST_F(WindowImplTest5, NotifyOccupiedAreaChange, Function | SmallTest | Level1)
665 {
666 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
667 option->SetWindowName("NotifyOccupiedAreaChange");
668 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
669
670 sptr<MockOccupiedAreaChangeListener> listener;
671 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener);
672 listener = sptr<MockOccupiedAreaChangeListener>::MakeSptr();
673 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener);
674 EXPECT_CALL(*listener, OnSizeChange(_, _));
675 sptr<OccupiedAreaChangeInfo> info = sptr<OccupiedAreaChangeInfo>::MakeSptr();
676 ASSERT_NE(info, nullptr);
677 std::shared_ptr<RSTransaction> rsTransaction;
678 window->NotifyOccupiedAreaChange(info, rsTransaction);
679 window->occupiedAreaChangeListeners_[window->GetWindowId()].clear();
680 }
681
682 /**
683 * @tc.name: NotifyDragEvent
684 * @tc.desc: NotifyDragEvent test
685 * @tc.type: FUNC
686 */
687 HWTEST_F(WindowImplTest5, NotifyDragEvent, Function | SmallTest | Level1)
688 {
689 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
690 option->SetWindowName("NotifyDragEvent");
691 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
692
693 sptr<MockWindowDragListener> listener;
694 window->windowDragListeners_.push_back(listener);
695 listener = sptr<MockWindowDragListener>::MakeSptr();
696 window->windowDragListeners_.push_back(listener);
697 EXPECT_CALL(*listener, OnDrag(_, _, _));
698 PointInfo point({ 10, 20 });
699 window->NotifyDragEvent(point, DragEvent::DRAG_EVENT_OUT);
700 window->windowDragListeners_.clear();
701 }
702
703 /**
704 * @tc.name: TransferPointerEvent02
705 * @tc.desc: TransferPointerEvent test
706 * @tc.type: FUNC
707 */
708 HWTEST_F(WindowImplTest5, TransferPointerEvent02, Function | SmallTest | Level1)
709 {
710 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
711 ASSERT_NE(option, nullptr);
712 option->SetWindowName("TransferPointerEvent02");
713 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
714 ASSERT_NE(window, nullptr);
715 window->TransferPointerEvent(nullptr);
716
717 window->windowSystemConfig_.isStretchable_ = true;
718 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
719
720 std::shared_ptr<MMI::PointerEvent> pointerEvent = std::make_shared<MockMmiPointerEvent>();
721 window->TransferPointerEvent(pointerEvent);
722 }
723
724 /**
725 * @tc.name: ReadyToMoveOrDragWindow
726 * @tc.desc: ReadyToMoveOrDragWindow test
727 * @tc.type: FUNC
728 */
729 HWTEST_F(WindowImplTest5, ReadyToMoveOrDragWindow, Function | SmallTest | Level1)
730 {
731 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
732 option->SetWindowName("ReadyToMoveOrDragWindow");
733 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
734
735 window->moveDragProperty_->pointEventStarted_ = false;
736 std::shared_ptr<MMI::PointerEvent> pointerEvent = std::make_shared<MockMmiPointerEvent>();
737 MMI::PointerEvent::PointerItem item;
738 SingletonContainer::GetInstance().destroyed_ = true;
739 window->ReadyToMoveOrDragWindow(pointerEvent, item);
740
741 SingletonContainer::GetInstance().destroyed_ = false;
742 window->property_->SetWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE);
743 window->ReadyToMoveOrDragWindow(pointerEvent, item);
744
745 window->property_->SetMaximizeMode(MaximizeMode::MODE_RECOVER);
746 window->ReadyToMoveOrDragWindow(pointerEvent, item);
747
748 window->property_->SetMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR);
749 window->ReadyToMoveOrDragWindow(pointerEvent, item);
750 ASSERT_EQ(window->moveDragProperty_->pointEventStarted_, true);
751 }
752
753 /**
754 * @tc.name: StartMove04
755 * @tc.desc: StartMove test
756 * @tc.type: FUNC
757 */
758 HWTEST_F(WindowImplTest5, StartMove04, Function | SmallTest | Level1)
759 {
760 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
761 option->SetWindowName("StartMove04");
762 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
763
764 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
765 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
766 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
767 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
768 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
769 window->moveDragProperty_->pointEventStarted_ = true;
770 window->moveDragProperty_->startDragFlag_ = false;
771 window->StartMove();
772
773 window->moveDragProperty_->startDragFlag_ = true;
774 window->StartMove();
775
776 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
777 ASSERT_EQ(WMError::WM_OK, window->Destroy());
778 }
779
780 /**
781 * @tc.name: IsPointInDragHotZone
782 * @tc.desc: IsPointInDragHotZone test
783 * @tc.type: FUNC
784 */
785 HWTEST_F(WindowImplTest5, IsPointInDragHotZone, Function | SmallTest | Level1)
786 {
787 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
788 option->SetWindowName("IsPointInDragHotZone");
789 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
790
791 Rect rect{ 10, 10, 10, 10 };
792 window->property_->SetWindowRect(rect);
793 window->moveDragProperty_->startRectExceptFrame_ = { 6, 6, 18, 18 };
794 window->moveDragProperty_->startRectExceptCorner_ = { 6, 6, 18, 18 };
795 ASSERT_EQ(window->IsPointInDragHotZone(6, 6, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN), true);
796
797 ASSERT_EQ(window->IsPointInDragHotZone(5, 5, MMI::PointerEvent::SOURCE_TYPE_MOUSE), false);
798
799 ASSERT_EQ(window->IsPointInDragHotZone(5, 5, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN), true);
800
801 ASSERT_EQ(window->IsPointInDragHotZone(10, 10, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN), false);
802
803 window->moveDragProperty_->startRectExceptCorner_ = { 16, 16, 18, 18 };
804 ASSERT_EQ(window->IsPointInDragHotZone(10, 10, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN), true);
805 }
806
807 /**
808 * @tc.name: CalculateStartRectExceptHotZone
809 * @tc.desc: CalculateStartRectExceptHotZone test
810 * @tc.type: FUNC
811 */
812 HWTEST_F(WindowImplTest5, CalculateStartRectExceptHotZone, Function | SmallTest | Level1)
813 {
814 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
815 option->SetWindowName("CalculateStartRectExceptHotZone");
816 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
817
818 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
819 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
820 ASSERT_EQ(WMError::WM_OK, window->Create(INVALID_WINDOW_ID));
821
822 window->property_->SetDisplayZoomState(true);
823 window->property_->SetTransform(Transform::Identity());
824 window->CalculateStartRectExceptHotZone(1.0);
825
826 window->property_->SetDisplayZoomState(false);
827 window->CalculateStartRectExceptHotZone(1.0);
828 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
829 ASSERT_EQ(WMError::WM_OK, window->Destroy());
830 }
831
832 /**
833 * @tc.name: PendingClose02
834 * @tc.desc: PendingClose test
835 * @tc.type: FUNC
836 */
837 HWTEST_F(WindowImplTest5, PendingClose02, Function | SmallTest | Level1)
838 {
839 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
840 ASSERT_NE(option, nullptr);
841 option->SetWindowName("PendingClose02");
842 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
843 ASSERT_NE(window, nullptr);
844
845 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
846 window->context_ = nullptr;
847 window->PendingClose();
848 }
849
850 /**
851 * @tc.name: Recover03
852 * @tc.desc: Recover test
853 * @tc.type: FUNC
854 */
855 HWTEST_F(WindowImplTest5, Recover03, Function | SmallTest | Level1)
856 {
857 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
858 option->SetWindowName("Recover03");
859 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
860
861 EXPECT_CALL(m->Mock(), GetSystemConfig(_)).WillOnce(Return(WMError::WM_OK));
862 EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
863 window->Create(INVALID_WINDOW_ID);
864 window->state_ = WindowState::STATE_CREATED;
865 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
866 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
867 window->property_->SetMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR);
868 EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
869 ASSERT_EQ(window->Recover(), WMError::WM_OK);
870
871 window->property_->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
872 ASSERT_EQ(window->Recover(), WMError::WM_OK);
873 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
874 ASSERT_EQ(WMError::WM_OK, window->Destroy());
875 }
876
877 /**
878 * @tc.name: Minimize03
879 * @tc.desc: Minimize test
880 * @tc.type: FUNC
881 */
882 HWTEST_F(WindowImplTest5, Minimize03, Function | SmallTest | Level1)
883 {
884 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
885 option->SetWindowName("Minimize03");
886 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
887
888 window->state_ = WindowState::STATE_CREATED;
889 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
890 std::shared_ptr<AbilityRuntime::Context> context = std::make_shared<AbilityRuntime::AbilityContextImpl>();
891 window->context_ = context;
892 window->Minimize();
893 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
894 }
895
896 /**
897 * @tc.name: RegisterListener
898 * @tc.desc: UnregisterListener | RegisterListener desc
899 * @tc.type: FUNC
900 */
901 HWTEST_F(WindowImplTest5, RegisterListener, Function | SmallTest | Level1)
902 {
903 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
904 option->SetWindowName("RegisterListener");
905 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
906
907 sptr<MockOccupiedAreaChangeListener> listener1;
908 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener1);
909 sptr<MockOccupiedAreaChangeListener> listener2 = sptr<MockOccupiedAreaChangeListener>::MakeSptr();
910 ASSERT_NE(listener2, nullptr);
911 window->UnregisterOccupiedAreaChangeListener(nullptr);
912 window->occupiedAreaChangeListeners_[window->GetWindowId()].push_back(listener2);
913 window->RegisterOccupiedAreaChangeListener(listener2);
914 window->occupiedAreaChangeListeners_[window->GetWindowId()].clear();
915 }
916
917 /**
918 * @tc.name: SetImmersiveModeEnabledState02
919 * @tc.desc: SetImmersiveModeEnabledState test
920 * @tc.type: FUNC
921 */
922 HWTEST_F(WindowImplTest5, SetImmersiveModeEnabledState02, Function | SmallTest | Level1)
923 {
924 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
925 option->SetWindowName("SetImmersiveModeEnabledState02");
926 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
927
928 window->state_ = WindowState::STATE_INITIAL;
929 EXPECT_EQ(window->SetImmersiveModeEnabledState(true), WMError::WM_ERROR_INVALID_WINDOW);
930
931 window->state_ = WindowState::STATE_CREATED;
932 window->UpdateWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL);
933
934 window->property_->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
935 EXPECT_EQ(window->SetImmersiveModeEnabledState(true), WMError::WM_ERROR_INVALID_WINDOW);
936
937 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
938 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
939 EXPECT_EQ(window->SetImmersiveModeEnabledState(true), WMError::WM_OK);
940 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
941 }
942
943 /**
944 * @tc.name: SetGlobalMaximizeMode
945 * @tc.desc: SetGlobalMaximizeMode test
946 * @tc.type: FUNC
947 */
948 HWTEST_F(WindowImplTest5, SetGlobalMaximizeMode, Function | SmallTest | Level1)
949 {
950 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
951 option->SetWindowName("SetGlobalMaximizeMode");
952 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
953
954 window->state_ = WindowState::STATE_INITIAL;
955 EXPECT_EQ(window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER), WMError::WM_ERROR_INVALID_WINDOW);
956
957 window->state_ = WindowState::STATE_CREATED;
958 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
959 EXPECT_EQ(window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER), WMError::WM_OK);
960
961 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
962 EXPECT_EQ(window->SetGlobalMaximizeMode(MaximizeMode::MODE_RECOVER), WMError::WM_ERROR_INVALID_PARAM);
963 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
964 }
965
966 /**
967 * @tc.name: MaximizeFloating02
968 * @tc.desc: MaximizeFloating test
969 * @tc.type: FUNC
970 */
971 HWTEST_F(WindowImplTest5, MaximizeFloating02, Function | SmallTest | Level1)
972 {
973 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
974 option->SetWindowName("MaximizeFloating02");
975 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
976
977 window->state_ = WindowState::STATE_CREATED;
978 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
979 window->MaximizeFloating();
980 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
981 }
982
983 /**
984 * @tc.name: SetCallingWindow
985 * @tc.desc: SetCallingWindow test
986 * @tc.type: FUNC
987 */
988 HWTEST_F(WindowImplTest5, SetCallingWindow, Function | SmallTest | Level1)
989 {
990 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
991 ASSERT_NE(option, nullptr);
992 option->SetWindowName("SetCallingWindow");
993 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
994 ASSERT_NE(window, nullptr);
995
996 window->state_ = WindowState::STATE_INITIAL;
997 window->SetCallingWindow(1);
998 }
999
1000 /**
1001 * @tc.name: Resize
1002 * @tc.desc: Resize test
1003 * @tc.type: FUNC
1004 */
1005 HWTEST_F(WindowImplTest5, Resize, Function | SmallTest | Level1)
1006 {
1007 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1008 option->SetWindowName("Resize");
1009 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1010
1011 window->state_ = WindowState::STATE_INITIAL;
1012 EXPECT_EQ(window->Resize(10, 10), WMError::WM_ERROR_INVALID_WINDOW);
1013
1014 window->state_ = WindowState::STATE_CREATED;
1015 EXPECT_EQ(window->Resize(10, 10), WMError::WM_OK);
1016
1017 window->state_ = WindowState::STATE_HIDDEN;
1018 EXPECT_EQ(window->Resize(10, 10), WMError::WM_OK);
1019
1020 window->state_ = WindowState::STATE_SHOWN;
1021 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1022 EXPECT_EQ(window->Resize(10, 10), WMError::WM_ERROR_INVALID_OPERATION);
1023
1024 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1025 EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1026 EXPECT_EQ(window->Resize(10, 10), WMError::WM_OK);
1027 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1028 ASSERT_EQ(WMError::WM_OK, window->Destroy());
1029 }
1030
1031 /**
1032 * @tc.name: MoveTo
1033 * @tc.desc: MoveTo test
1034 * @tc.type: FUNC
1035 */
1036 HWTEST_F(WindowImplTest5, MoveTo, Function | SmallTest | Level1)
1037 {
1038 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1039 option->SetWindowName("MoveTo");
1040 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1041
1042 window->state_ = WindowState::STATE_CREATED;
1043 EXPECT_EQ(window->MoveTo(10, 10), WMError::WM_OK);
1044
1045 window->state_ = WindowState::STATE_HIDDEN;
1046 EXPECT_EQ(window->MoveTo(10, 10), WMError::WM_OK);
1047
1048 window->state_ = WindowState::STATE_SHOWN;
1049 EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
1050 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1051 EXPECT_EQ(window->MoveTo(10, 10), WMError::WM_ERROR_INVALID_OPERATION);
1052
1053 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1054 window->MoveTo(10, 10);
1055 EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
1056 }
1057
1058 /**
1059 * @tc.name: AdjustWindowAnimationFlag
1060 * @tc.desc: AdjustWindowAnimationFlag test
1061 * @tc.type: FUNC
1062 */
1063 HWTEST_F(WindowImplTest5, AdjustWindowAnimationFlag, Function | SmallTest | Level1)
1064 {
1065 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1066 option->SetWindowName("AdjustWindowAnimationFlag");
1067 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1068
1069 window->property_->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1070 sptr<IAnimationTransitionController> animationTransitionController =
1071 sptr<IAnimationTransitionController>::MakeSptr();
1072 ASSERT_NE(animationTransitionController, nullptr);
1073 window->animationTransitionController_ = animationTransitionController;
1074
1075 window->AdjustWindowAnimationFlag(true);
1076
1077 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1078 window->needDefaultAnimation_ = true;
1079 window->AdjustWindowAnimationFlag(true);
1080
1081 window->animationTransitionController_ = nullptr;
1082 window->needDefaultAnimation_ = false;
1083 window->AdjustWindowAnimationFlag(true);
1084
1085 window->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1086 window->AdjustWindowAnimationFlag(false);
1087 }
1088
1089 /**
1090 * @tc.name: NeedToStopShowing
1091 * @tc.desc: NeedToStopShowing test
1092 * @tc.type: FUNC
1093 */
1094 HWTEST_F(WindowImplTest5, NeedToStopShowing, Function | SmallTest | Level1)
1095 {
1096 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1097 option->SetWindowName("NeedToStopShowing");
1098 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1099
1100 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1101 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1102 EXPECT_EQ(window->NeedToStopShowing(), true);
1103
1104 window->UpdateWindowModeSupportType(WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY);
1105 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
1106 window->property_->SetWindowFlags(1 << 2);
1107 EXPECT_EQ(window->NeedToStopShowing(), false);
1108
1109 window->property_->SetWindowFlags(1);
1110 EXPECT_EQ(window->NeedToStopShowing(), false);
1111 }
1112
1113 /**
1114 * @tc.name: DestroyFloatingWindow
1115 * @tc.desc: DestroyFloatingWindow test
1116 * @tc.type: FUNC
1117 */
1118 HWTEST_F(WindowImplTest5, DestroyFloatingWindow, Function | SmallTest | Level1)
1119 {
1120 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1121 option->SetWindowName("DestroyFloatingWindow");
1122 option->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1123 option->SetWindowType(WindowType::WINDOW_TYPE_VOLUME_OVERLAY);
1124 option->SetWindowRect({ 1, 1, 1, 1 });
1125 option->SetBundleName("OK");
1126 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1127 window->DestroyFloatingWindow();
1128
1129 std::map<uint32_t, std::vector<sptr<WindowImpl>>> appFloatingWindowMap;
1130 sptr<WindowImpl> windowImpl = sptr<WindowImpl>::MakeSptr(option);
1131 ASSERT_NE(windowImpl, nullptr);
1132 std::vector<sptr<WindowImpl>> v;
1133 std::vector<sptr<WindowImpl>> v2;
1134 v.push_back(windowImpl);
1135 appFloatingWindowMap.insert({ 0, v });
1136 appFloatingWindowMap.insert({ 0, v2 });
1137 window->appFloatingWindowMap_ = appFloatingWindowMap;
1138 window->DestroyFloatingWindow();
1139 }
1140
1141 /**
1142 * @tc.name: DestroyDialogWindow
1143 * @tc.desc: DestroyDialogWindow test
1144 * @tc.type: FUNC
1145 */
1146 HWTEST_F(WindowImplTest5, DestroyDialogWindow, Function | SmallTest | Level1)
1147 {
1148 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1149 option->SetWindowName("DestroyDialogWindow");
1150 option->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1151 option->SetWindowType(WindowType::WINDOW_TYPE_VOLUME_OVERLAY);
1152 option->SetWindowRect({ 1, 1, 1, 1 });
1153 option->SetBundleName("OK");
1154 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1155 window->DestroyFloatingWindow();
1156
1157 std::map<uint32_t, std::vector<sptr<WindowImpl>>> appDialogWindowMap;
1158 sptr<WindowImpl> windowImpl = sptr<WindowImpl>::MakeSptr(option);
1159 ASSERT_NE(windowImpl, nullptr);
1160 std::vector<sptr<WindowImpl>> v;
1161 std::vector<sptr<WindowImpl>> v2;
1162 v.push_back(windowImpl);
1163 appDialogWindowMap.insert({ 0, v });
1164 appDialogWindowMap.insert({ 0, v2 });
1165 window->appDialogWindowMap_ = appDialogWindowMap;
1166 window->DestroyFloatingWindow();
1167 }
1168
1169 /**
1170 * @tc.name: GetOriginalAbilityInfo
1171 * @tc.desc: GetOriginalAbilityInfo test
1172 * @tc.type: FUNC
1173 */
1174 HWTEST_F(WindowImplTest5, GetOriginalAbilityInfo, Function | SmallTest | Level1)
1175 {
1176 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1177 option->SetWindowName("GetOriginalAbilityInfo");
1178 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1179
1180 std::shared_ptr<AbilityRuntime::Context> context = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1181 window->context_ = context;
1182 ASSERT_EQ(nullptr, window->GetOriginalAbilityInfo());
1183 }
1184
1185 /**
1186 * @tc.name: WindowCreateCheck05
1187 * @tc.desc: WindowCreateCheck test
1188 * @tc.type: FUNC
1189 */
1190 HWTEST_F(WindowImplTest5, WindowCreateCheck05, Function | SmallTest | Level1)
1191 {
1192 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1193 option->SetWindowName("WindowCreateCheck05");
1194 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1195
1196 window->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
1197 EXPECT_EQ(window->WindowCreateCheck(INVALID_WINDOW_ID), WMError::WM_OK);
1198
1199 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1200 EXPECT_EQ(window->WindowCreateCheck(INVALID_WINDOW_ID), WMError::WM_ERROR_INVALID_PARENT);
1201
1202 window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
1203 sptr<WindowImpl> windowImpl1 = sptr<WindowImpl>::MakeSptr(option);
1204 ASSERT_NE(windowImpl1, nullptr);
1205 windowImpl1->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
1206 WindowImpl::windowMap_.insert(std::make_pair("test", std::pair<uint32_t, sptr<Window>>(1, windowImpl1)));
1207 EXPECT_EQ(window->WindowCreateCheck(INVALID_WINDOW_ID), WMError::WM_ERROR_REPEAT_OPERATION);
1208
1209 window->property_->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
1210 sptr<WindowImpl> windowImpl2 = sptr<WindowImpl>::MakeSptr(option);
1211 ASSERT_NE(windowImpl2, nullptr);
1212 windowImpl2->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1213 WindowImpl::windowMap_.insert(std::make_pair("test", std::pair<uint32_t, sptr<Window>>(0, windowImpl2)));
1214 EXPECT_EQ(window->WindowCreateCheck(0), WMError::WM_ERROR_INVALID_PARENT);
1215
1216 sptr<WindowImpl> windowImpl3 = sptr<WindowImpl>::MakeSptr(option);
1217 ASSERT_NE(windowImpl3, nullptr);
1218 windowImpl3->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1219 WindowImpl::windowMap_.insert(std::make_pair("test", std::pair<uint32_t, sptr<Window>>(1, windowImpl3)));
1220 EXPECT_EQ(window->WindowCreateCheck(1), WMError::WM_OK);
1221 }
1222
1223 /**
1224 * @tc.name: IsAppMainOrSubOrFloatingWindow
1225 * @tc.desc: IsAppMainOrSubOrFloatingWindow test
1226 * @tc.type: FUNC
1227 */
1228 HWTEST_F(WindowImplTest5, IsAppMainOrSubOrFloatingWindow, Function | SmallTest | Level1)
1229 {
1230 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1231 option->SetWindowName("IsAppMainOrSubOrFloatingWindow");
1232 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1233
1234 window->property_->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1235 EXPECT_EQ(window->IsAppMainOrSubOrFloatingWindow(), false);
1236
1237 window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1238 WindowImpl::windowMap_.insert(std::make_pair("test", std::pair<uint32_t, sptr<Window>>(1, nullptr)));
1239 EXPECT_EQ(window->IsAppMainOrSubOrFloatingWindow(), false);
1240
1241 sptr<WindowImpl> windowImpl1 = sptr<WindowImpl>::MakeSptr(option);
1242 ASSERT_NE(windowImpl1, nullptr);
1243 windowImpl1->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1244 WindowImpl::windowMap_.insert(std::make_pair("test", std::pair<uint32_t, sptr<Window>>(1, windowImpl1)));
1245 EXPECT_EQ(window->IsAppMainOrSubOrFloatingWindow(), false);
1246
1247 sptr<WindowImpl> windowImpl2 = sptr<WindowImpl>::MakeSptr(option);
1248 ASSERT_NE(windowImpl2, nullptr);
1249 windowImpl2->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1250 WindowImpl::windowMap_.insert(std::make_pair("test", std::pair<uint32_t, sptr<Window>>(1, windowImpl2)));
1251 EXPECT_EQ(window->IsAppMainOrSubOrFloatingWindow(), false);
1252
1253 sptr<WindowImpl> windowImpl3 = sptr<WindowImpl>::MakeSptr(option);
1254 ASSERT_NE(windowImpl3, nullptr);
1255 windowImpl3->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1256 std::shared_ptr<AbilityRuntime::Context> context = std::make_shared<AbilityRuntime::AbilityContextImpl>();
1257 window->context_ = context;
1258 windowImpl3->context_ = context;
1259 WindowImpl::windowMap_.insert(std::make_pair("test", std::pair<uint32_t, sptr<Window>>(1, windowImpl3)));
1260 EXPECT_EQ(window->IsAppMainOrSubOrFloatingWindow(), false);
1261 }
1262
1263 /**
1264 * @tc.name: UpdateTitleButtonVisibility02
1265 * @tc.desc: UpdateTitleButtonVisibility test
1266 * @tc.type: FUNC
1267 */
1268 HWTEST_F(WindowImplTest5, UpdateTitleButtonVisibility02, Function | SmallTest | Level1)
1269 {
1270 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1271 option->SetWindowName("UpdateTitleButtonVisibility02");
1272 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1273 window->uiContent_ = nullptr;
1274 window->UpdateTitleButtonVisibility();
1275
1276 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1277 Ace::UIContentMocker* content = reinterpret_cast<Ace::UIContentMocker*>(window->uiContent_.get());
1278 EXPECT_CALL(*content, HideWindowTitleButton(_, _, _, _));
1279 window->windowSystemConfig_.isSystemDecorEnable_ = false;
1280 window->UpdateTitleButtonVisibility();
1281
1282 window->windowSystemConfig_.isSystemDecorEnable_ = true;
1283 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1284 window->UpdateTitleButtonVisibility();
1285 }
1286
1287 /**
1288 * @tc.name: GetConfigurationFromAbilityInfo02
1289 * @tc.desc: GetConfigurationFromAbilityInfo test
1290 * @tc.type: FUNC
1291 */
1292 HWTEST_F(WindowImplTest5, GetConfigurationFromAbilityInfo02, Function | SmallTest | Level1)
1293 {
1294 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1295 option->SetWindowName("GetConfigurationFromAbilityInfo02");
1296 option->SetDisplayId(1);
1297 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1298 ASSERT_EQ(1, window->GetDisplayId());
1299
1300 std::shared_ptr<AbilityRuntime::AbilityContextImpl> context =
1301 std::make_shared<AbilityRuntime::AbilityContextImpl>();
1302 window->context_ = context;
1303 window->GetConfigurationFromAbilityInfo();
1304
1305 std::shared_ptr<AppExecFwk::AbilityInfo> info = std::make_shared<AppExecFwk::AbilityInfo>();
1306 context->SetAbilityInfo(info);
1307 window->GetConfigurationFromAbilityInfo();
1308
1309 std::vector<AppExecFwk::SupportWindowMode> supportModes;
1310 supportModes.push_back(AppExecFwk::SupportWindowMode::SPLIT);
1311 context->GetAbilityInfo()->windowModes = supportModes;
1312 window->GetConfigurationFromAbilityInfo();
1313 }
1314
1315 /**
1316 * @tc.name: GetVirtualPixelRatio01
1317 * @tc.desc: GetVirtualPixelRatio test
1318 * @tc.type: FUNC
1319 */
1320 HWTEST_F(WindowImplTest5, GetVirtualPixelRatio01, Function | SmallTest | Level1)
1321 {
1322 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
1323 option->SetWindowName("GetVirtualPixelRatio01");
1324 option->SetDisplayId(1);
1325 sptr<WindowImpl> window = sptr<WindowImpl>::MakeSptr(option);
1326 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1327 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1328
1329 float vpr = 0.0f;
1330 window->property_->SetDisplayId(-1);
1331 vpr = window->GetVirtualPixelRatio();
1332 ASSERT_EQ(vpr, 1.0f);
1333 }
1334 } // namespace
1335 } // namespace Rosen
1336 } // namespace OHOS