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 "window_session_impl.h"
17
18 #include <gtest/gtest.h>
19
20 #include "display_info.h"
21 #include "mock_session.h"
22 #include "mock_uicontent.h"
23 #include "mock_window.h"
24 #include "parameters.h"
25 #include "wm_common.h"
26
27 using namespace testing;
28 using namespace testing::ext;
29
30 namespace OHOS {
31 namespace Rosen {
32 class WindowSessionImplTwoTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 sptr<WindowSessionImpl> window_;
39
40 private:
41 static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
42 };
43
SetUpTestCase()44 void WindowSessionImplTwoTest::SetUpTestCase()
45 {
46 }
47
TearDownTestCase()48 void WindowSessionImplTwoTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void WindowSessionImplTwoTest::SetUp()
53 {
54 }
55
TearDown()56 void WindowSessionImplTwoTest::TearDown()
57 {
58 usleep(WAIT_SYNC_IN_NS);
59 if (window_ != nullptr) {
60 window_->Destroy();
61 }
62 }
63
64 namespace {
GetTestWindowImpl(const std::string & name)65 sptr<WindowSessionImpl> GetTestWindowImpl(const std::string& name)
66 {
67 sptr<WindowOption> option = new (std::nothrow) WindowOption();
68 if (option == nullptr) {
69 return nullptr;
70 }
71 option->SetWindowName(name);
72 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
73 if (window == nullptr) {
74 return nullptr;
75 }
76
77 SessionInfo sessionInfo = {name, name, name};
78 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
79 if (session == nullptr) {
80 return nullptr;
81 }
82
83 window->hostSession_ = session;
84 return window;
85 }
86
87 template <typename TListener, typename MockListener>
GetListenerList()88 std::vector<sptr<TListener>> GetListenerList()
89 {
90 std::vector<sptr<TListener>> listeners;
91 sptr<TListener> listener = new (std::nothrow) MockListener();
92 if (listener == nullptr) {
93 return listeners;
94 }
95
96 listeners.insert(listeners.begin(), listener);
97 return listeners;
98 }
99
100 /**
101 * @tc.name: GetTitleButtonVisible
102 * @tc.desc: GetTitleButtonVisible
103 * @tc.type: FUNC
104 */
105 HWTEST_F(WindowSessionImplTwoTest, GetTitleButtonVisible, Function | SmallTest | Level2)
106 {
107 auto window = GetTestWindowImpl("GetTitleButtonVisible");
108 ASSERT_NE(window, nullptr);
109 window->windowSystemConfig_.uiType_ = "phone";
110 bool isMaximizeVisible = false;
111 bool isMinimizeVisible = false;
112 bool isSplitVisible = false;
113 bool isCloseVisible = false;
114 window->GetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, isSplitVisible, isCloseVisible);
115 ASSERT_FALSE(isSplitVisible);
116
117 window->windowSystemConfig_.uiType_ = "pc";
118 window->windowTitleVisibleFlags_.isSplitVisible = false;
119 window->windowTitleVisibleFlags_.isMaximizeVisible = false;
120 window->windowTitleVisibleFlags_.isMinimizeVisible = false;
121 window->windowTitleVisibleFlags_.isCloseVisible = false;
122 window->GetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, isSplitVisible, isCloseVisible);
123 ASSERT_TRUE(isSplitVisible);
124 ASSERT_TRUE(isMaximizeVisible);
125 ASSERT_TRUE(isMinimizeVisible);
126 ASSERT_TRUE(isCloseVisible);
127
128 window->windowTitleVisibleFlags_.isSplitVisible = true;
129 window->windowTitleVisibleFlags_.isMaximizeVisible = true;
130 window->windowTitleVisibleFlags_.isMinimizeVisible = true;
131 window->windowTitleVisibleFlags_.isCloseVisible = true;
132 window->GetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, isSplitVisible, isCloseVisible);
133 ASSERT_TRUE(isSplitVisible);
134 ASSERT_TRUE(isMaximizeVisible);
135 ASSERT_TRUE(isMinimizeVisible);
136 ASSERT_TRUE(isCloseVisible);
137 }
138
139 /**
140 * @tc.name: GetSystemSessionConfig
141 * @tc.desc: GetSystemSessionConfig
142 * @tc.type: FUNC
143 */
144 HWTEST_F(WindowSessionImplTwoTest, GetSystemSessionConfig, Function | SmallTest | Level2)
145 {
146 auto window = GetTestWindowImpl("GetSystemSessionConfig");
147 ASSERT_NE(window, nullptr);
148 window->GetSystemSessionConfig();
149 window->Destroy();
150 }
151
152 /**
153 * @tc.name: GetColorSpaceFromSurfaceGamut
154 * @tc.desc: GetColorSpaceFromSurfaceGamut
155 * @tc.type: FUNC
156 */
157 HWTEST_F(WindowSessionImplTwoTest, GetColorSpaceFromSurfaceGamut, Function | SmallTest | Level2)
158 {
159 auto window = GetTestWindowImpl("GetColorSpaceFromSurfaceGamut");
160 ASSERT_NE(window, nullptr);
161 ASSERT_EQ(window->GetColorSpaceFromSurfaceGamut(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB),
162 ColorSpace::COLOR_SPACE_DEFAULT);
163 ASSERT_EQ(window->GetColorSpaceFromSurfaceGamut(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3),
164 ColorSpace::COLOR_SPACE_WIDE_GAMUT);
165 ASSERT_EQ(window->GetColorSpaceFromSurfaceGamut(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_INVALID),
166 ColorSpace::COLOR_SPACE_DEFAULT);
167 window->Destroy();
168 }
169
170 /**
171 * @tc.name: GetSurfaceGamutFromColorSpace
172 * @tc.desc: GetSurfaceGamutFromColorSpace
173 * @tc.type: FUNC
174 */
175 HWTEST_F(WindowSessionImplTwoTest, GetSurfaceGamutFromColorSpace, Function | SmallTest | Level2)
176 {
177 auto window = GetTestWindowImpl("GetSurfaceGamutFromColorSpace");
178 ASSERT_NE(window, nullptr);
179 ASSERT_EQ(window->GetSurfaceGamutFromColorSpace(ColorSpace::COLOR_SPACE_DEFAULT),
180 GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB);
181 ASSERT_EQ(window->GetSurfaceGamutFromColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT),
182 GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
183 ASSERT_EQ(window->GetSurfaceGamutFromColorSpace(ColorSpace(uint32_t(3))),
184 GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB);
185 window->Destroy();
186 }
187
188 /**
189 * @tc.name: Create
190 * @tc.desc: Create
191 * @tc.type: FUNC
192 */
193 HWTEST_F(WindowSessionImplTwoTest, Create, Function | SmallTest | Level2)
194 {
195 auto window = GetTestWindowImpl("Create");
196 ASSERT_NE(window, nullptr);
197 std::shared_ptr<AbilityRuntime::Context> context;
198 sptr<Rosen::ISession> ISession;
199 ASSERT_EQ(window->Create(context, ISession), WMError::WM_OK);
200 window->Destroy();
201 }
202
203 /**
204 * @tc.name: Destroy
205 * @tc.desc: Destroy
206 * @tc.type: FUNC
207 */
208 HWTEST_F(WindowSessionImplTwoTest, Destroy, Function | SmallTest | Level2)
209 {
210 auto window = GetTestWindowImpl("Destroy");
211 ASSERT_NE(window, nullptr);
212
213 window->property_->SetPersistentId(INVALID_SESSION_ID);
214 ASSERT_EQ(window->Destroy(true, true), WMError::WM_ERROR_INVALID_WINDOW);
215
216 window->property_->SetPersistentId(1);
217 window->state_ = WindowState::STATE_DESTROYED;
218 ASSERT_EQ(window->Destroy(true, true), WMError::WM_ERROR_INVALID_WINDOW);
219
220 window->state_ = WindowState::STATE_INITIAL;
221 ASSERT_EQ(window->Destroy(true, true), WMError::WM_OK);
222
223 window = GetTestWindowImpl("Destroy");
224 ASSERT_NE(window, nullptr);
225 window->state_ = WindowState::STATE_INITIAL;
226 window->property_->SetPersistentId(1);
227 ASSERT_EQ(window->Destroy(true, false), WMError::WM_OK);
228
229 window->hostSession_ = nullptr;
230 ASSERT_EQ(window->Destroy(true, true), WMError::WM_ERROR_INVALID_WINDOW);
231
232 window->Destroy();
233 }
234
235 /**
236 * @tc.name: GetWindowState
237 * @tc.desc: GetWindowState
238 * @tc.type: FUNC
239 */
240 HWTEST_F(WindowSessionImplTwoTest, GetWindowState, Function | SmallTest | Level2)
241 {
242 auto window = GetTestWindowImpl("GetWindowState");
243 ASSERT_NE(window, nullptr);
244 window->state_ = WindowState::STATE_DESTROYED;
245 ASSERT_EQ(window->GetWindowState(), WindowState::STATE_DESTROYED);
246 window->Destroy();
247 }
248
249 /**
250 * @tc.name: RecoverSessionListener
251 * @tc.desc: RecoverSessionListener
252 * @tc.type: FUNC
253 */
254 HWTEST_F(WindowSessionImplTwoTest, RecoverSessionListener, Function | SmallTest | Level2)
255 {
256 auto window = GetTestWindowImpl("RecoverSessionListener");
257 ASSERT_NE(window, nullptr);
258 int32_t id = 1;
259 window->property_->SetPersistentId(id);
260 window->RecoverSessionListener();
261
262 std::vector<sptr<IAvoidAreaChangedListener>> iAvoidAreaChangedListeners;
263 std::vector<sptr<ITouchOutsideListener>> iTouchOutsideListeners;
264 window->avoidAreaChangeListeners_.insert({id, iAvoidAreaChangedListeners});
265 window->touchOutsideListeners_.insert({id, iTouchOutsideListeners});
266 window->RecoverSessionListener();
267
268 window->avoidAreaChangeListeners_.clear();
269 window->touchOutsideListeners_.clear();
270 sptr<MockAvoidAreaChangedListener> changedListener = new (std::nothrow) MockAvoidAreaChangedListener();
271 ASSERT_NE(nullptr, changedListener);
272 sptr<MockTouchOutsideListener> touchOutsideListener = new (std::nothrow) MockTouchOutsideListener();
273 ASSERT_NE(nullptr, touchOutsideListener);
274 iAvoidAreaChangedListeners.insert(iAvoidAreaChangedListeners.begin(), changedListener);
275 iTouchOutsideListeners.insert(iTouchOutsideListeners.begin(), touchOutsideListener);
276 window->avoidAreaChangeListeners_.insert({id, iAvoidAreaChangedListeners});
277 window->touchOutsideListeners_.insert({id, iTouchOutsideListeners});
278 window->RecoverSessionListener();
279 ASSERT_TRUE(window->avoidAreaChangeListeners_.find(id) != window->avoidAreaChangeListeners_.end() &&
280 !window->avoidAreaChangeListeners_[id].empty());
281 ASSERT_TRUE(window->touchOutsideListeners_.find(id) != window->touchOutsideListeners_.end() &&
282 !window->touchOutsideListeners_[id].empty());
283 window->Destroy();
284 }
285
286 /**
287 * @tc.name: NotifyUIContentFocusStatus
288 * @tc.desc: NotifyUIContentFocusStatus
289 * @tc.type: FUNC
290 */
291 HWTEST_F(WindowSessionImplTwoTest, NotifyUIContentFocusStatus, Function | SmallTest | Level2)
292 {
293 auto window = GetTestWindowImpl("NotifyUIContentFocusStatus");
294 ASSERT_NE(window, nullptr);
295 window->isFocused_ = false;
296 window->NotifyUIContentFocusStatus();
297
298 window->isFocused_ = true;
299 window->NotifyUIContentFocusStatus();
300
301 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
302 window->NotifyUIContentFocusStatus();
303 window->Destroy();
304 }
305
306 /**
307 * @tc.name: NotifyAfterFocused
308 * @tc.desc: NotifyAfterFocused
309 * @tc.type: FUNC
310 */
311 HWTEST_F(WindowSessionImplTwoTest, NotifyAfterFocused, Function | SmallTest | Level2)
312 {
313 auto window = GetTestWindowImpl("NotifyAfterFocused");
314 ASSERT_NE(window, nullptr);
315 window->NotifyAfterFocused();
316 ASSERT_TRUE(window->shouldReNotifyFocus_);
317
318 window->shouldReNotifyFocus_ = false;
319 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
320 window->NotifyAfterFocused();
321 ASSERT_FALSE(window->shouldReNotifyFocus_);
322 window->Destroy();
323 }
324
325 /**
326 * @tc.name: NotifyForegroundFailed
327 * @tc.desc: NotifyForegroundFailed
328 * @tc.type: FUNC
329 */
330 HWTEST_F(WindowSessionImplTwoTest, NotifyForegroundFailed, Function | SmallTest | Level2)
331 {
332 auto window = GetTestWindowImpl("NotifyForegroundFailed");
333 ASSERT_NE(window, nullptr);
334 window->NotifyForegroundFailed(WMError::WM_OK);
335 window->Destroy();
336 }
337
338 /**
339 * @tc.name: NotifyTransferComponentDataSync
340 * @tc.desc: NotifyTransferComponentDataSync
341 * @tc.type: FUNC
342 */
343 HWTEST_F(WindowSessionImplTwoTest, NotifyTransferComponentDataSync, Function | SmallTest | Level2)
344 {
345 auto window = GetTestWindowImpl("NotifyTransferComponentDataSync");
346 ASSERT_NE(window, nullptr);
347 AAFwk::WantParams wantParams;
348 AAFwk::WantParams reWantParams;
349 ASSERT_EQ(WSErrorCode::WS_OK, window->NotifyTransferComponentDataSync(wantParams, reWantParams));
350 window->Destroy();
351 }
352
353 /**
354 * @tc.name: UpdateAvoidArea
355 * @tc.desc: UpdateAvoidArea
356 * @tc.type: FUNC
357 */
358 HWTEST_F(WindowSessionImplTwoTest, UpdateAvoidArea, Function | SmallTest | Level2)
359 {
360 auto window = GetTestWindowImpl("UpdateAvoidArea");
361 ASSERT_NE(window, nullptr);
362 sptr<AvoidArea> avoidArea = new AvoidArea();
363 avoidArea->topRect_ = {1, 0, 0, 0};
364 avoidArea->leftRect_ = {0, 1, 0, 0};
365 avoidArea->rightRect_ = {0, 0, 1, 0};
366 avoidArea->bottomRect_ = {0, 0, 0, 1};
367 AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
368 ASSERT_EQ(WSError::WS_OK, window->UpdateAvoidArea(avoidArea, type));
369 window->Destroy();
370 }
371
372 /**
373 * @tc.name: DispatchKeyEventCallback
374 * @tc.desc: DispatchKeyEventCallback
375 * @tc.type: FUNC
376 */
377 HWTEST_F(WindowSessionImplTwoTest, DispatchKeyEventCallback, Function | SmallTest | Level2)
378 {
379 auto window = GetTestWindowImpl("DispatchKeyEventCallback");
380 ASSERT_NE(window, nullptr);
381
382 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
383 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_VIRTUAL_MULTITASK);
384 bool isConsumed = false;
385 window->DispatchKeyEventCallback(keyEvent, isConsumed);
386 ASSERT_FALSE(isConsumed);
387
388 std::shared_ptr<MockInputEventConsumer> inputEventConsumer = std::make_shared<MockInputEventConsumer>();
389 window->inputEventConsumer_ = inputEventConsumer;
390 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
391 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
392 window->DispatchKeyEventCallback(keyEvent, isConsumed);
393
394 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
395 window->DispatchKeyEventCallback(keyEvent, isConsumed);
396
397 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
398 window->inputEventConsumer_ = nullptr;
399 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
400 window->DispatchKeyEventCallback(keyEvent, isConsumed);
401
402 keyEvent->SetKeyAction(MMI::KeyEvent::KEYCODE_ESCAPE);
403 window->DispatchKeyEventCallback(keyEvent, isConsumed);
404 window->Destroy();
405 }
406
407 /**
408 * @tc.name: HandleBackEvent01
409 * @tc.desc: HandleBackEvent
410 * @tc.type: FUNC
411 */
412 HWTEST_F(WindowSessionImplTwoTest, HandleBackEvent01, Function | SmallTest | Level3)
413 {
414 sptr<WindowOption> option = new (std::nothrow) WindowOption();
415 option->SetWindowName("HandleBackEvent01");
416 sptr<WindowSessionImpl> windowSession = new (std::nothrow) WindowSessionImpl(option);
417 ASSERT_NE(nullptr, windowSession);
418
419 windowSession->uiContent_ = std::make_unique<Ace::UIContentMocker>();
420 ASSERT_EQ(WSError::WS_OK, windowSession->HandleBackEvent());
421 }
422
423 /**
424 * @tc.name: IsKeyboardEvent
425 * @tc.desc: IsKeyboardEvent
426 * @tc.type: FUNC
427 */
428 HWTEST_F(WindowSessionImplTwoTest, IsKeyboardEvent, Function | SmallTest | Level2)
429 {
430 auto window = GetTestWindowImpl("IsKeyboardEvent");
431 ASSERT_NE(window, nullptr);
432
433 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
434 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_VIRTUAL_MULTITASK);
435 ASSERT_FALSE(window->IsKeyboardEvent(keyEvent));
436
437 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_NUMPAD_RIGHT_PAREN);
438 ASSERT_TRUE(window->IsKeyboardEvent(keyEvent));
439
440 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
441 ASSERT_TRUE(window->IsKeyboardEvent(keyEvent));
442
443 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_FN);
444 ASSERT_TRUE(window->IsKeyboardEvent(keyEvent));
445
446 window->Destroy();
447 }
448
449 /**
450 * @tc.name: GetVSyncPeriod
451 * @tc.desc: GetVSyncPeriod
452 * @tc.type: FUNC
453 */
454 HWTEST_F(WindowSessionImplTwoTest, GetVSyncPeriod, Function | SmallTest | Level2)
455 {
456 auto window = GetTestWindowImpl("GetVSyncPeriod");
457 ASSERT_NE(window, nullptr);
458
459 auto vsyncStation = window->vsyncStation_;
460 if (vsyncStation == nullptr) {
461 vsyncStation = std::make_shared<VsyncStation>(DisplayId(0));
462 }
463 window->vsyncStation_ = nullptr;
464 ASSERT_EQ(window->GetVSyncPeriod(), 0);
465
466 window->vsyncStation_ = vsyncStation;
467 window->GetVSyncPeriod();
468 window->Destroy();
469 }
470
471 /**
472 * @tc.name: FlushFrameRate
473 * @tc.desc: FlushFrameRate
474 * @tc.type: FUNC
475 */
476 HWTEST_F(WindowSessionImplTwoTest, FlushFrameRate, Function | SmallTest | Level2)
477 {
478 auto window = GetTestWindowImpl("FlushFrameRate");
479 ASSERT_NE(window, nullptr);
480
481 auto vsyncStation = window->vsyncStation_;
482 if (vsyncStation == nullptr) {
483 vsyncStation = std::make_shared<VsyncStation>(DisplayId(0));
484 }
485 window->vsyncStation_ = nullptr;
486 window->FlushFrameRate(1, -1);
487
488 window->vsyncStation_ = vsyncStation;
489 window->FlushFrameRate(1, -1);
490 window->Destroy();
491 }
492
493 /**
494 * @tc.name: FindWindowById
495 * @tc.desc: FindWindowById
496 * @tc.type: FUNC
497 */
498 HWTEST_F(WindowSessionImplTwoTest, FindWindowById, Function | SmallTest | Level2)
499 {
500 auto window = GetTestWindowImpl("FindWindowById");
501 ASSERT_NE(window, nullptr);
502 window->windowSessionMap_.clear();
503 ASSERT_EQ(window->FindWindowById(0), nullptr);
504
505 window->windowSessionMap_.insert(
506 {"test1", std::pair<int32_t, sptr<WindowSessionImpl>>(1, window)}
507 );
508 window->windowSessionMap_.insert(
509 {"test2", std::pair<int32_t, sptr<WindowSessionImpl>>(2, window)}
510 );
511 ASSERT_EQ(window->FindWindowById(0), nullptr);
512
513 window->windowSessionMap_.insert(
514 {"test0", std::pair<int32_t, sptr<WindowSessionImpl>>(0, window)}
515 );
516 ASSERT_NE(window->FindWindowById(0), nullptr);
517 window->Destroy();
518 }
519
520 /**
521 * @tc.name: SetLayoutFullScreenByApiVersion
522 * @tc.desc: SetLayoutFullScreenByApiVersion
523 * @tc.type: FUNC
524 */
525 HWTEST_F(WindowSessionImplTwoTest, SetLayoutFullScreenByApiVersion, Function | SmallTest | Level2)
526 {
527 auto window = GetTestWindowImpl("SetLayoutFullScreenByApiVersion");
528 ASSERT_NE(window, nullptr);
529 window->windowSessionMap_.clear();
530 ASSERT_EQ(window->SetLayoutFullScreenByApiVersion(true), WMError::WM_OK);
531 window->Destroy();
532 }
533
534 /**
535 * @tc.name: SetSystemBarProperty
536 * @tc.desc: SetSystemBarProperty
537 * @tc.type: FUNC
538 */
539 HWTEST_F(WindowSessionImplTwoTest, SetSystemBarProperty, Function | SmallTest | Level2)
540 {
541 auto window = GetTestWindowImpl("SetSystemBarProperty");
542 ASSERT_NE(window, nullptr);
543 window->windowSessionMap_.clear();
544 SystemBarProperty property;
545 ASSERT_EQ(window->SetSystemBarProperty(WindowType::APP_MAIN_WINDOW_END, property), WMError::WM_OK);
546 window->Destroy();
547 }
548
549 /**
550 * @tc.name: SetSpecificBarProperty
551 * @tc.desc: SetSpecificBarProperty
552 * @tc.type: FUNC
553 */
554 HWTEST_F(WindowSessionImplTwoTest, SetSpecificBarProperty, Function | SmallTest | Level2)
555 {
556 auto window = GetTestWindowImpl("SetSpecificBarProperty");
557 ASSERT_NE(window, nullptr);
558 window->windowSessionMap_.clear();
559 SystemBarProperty property;
560 ASSERT_EQ(window->SetSpecificBarProperty(WindowType::APP_MAIN_WINDOW_END, property), WMError::WM_OK);
561 window->Destroy();
562 }
563
564 /**
565 * @tc.name: NotifyOccupiedAreaChangeInfo
566 * @tc.desc: NotifyOccupiedAreaChangeInfo
567 * @tc.type: FUNC
568 */
569 HWTEST_F(WindowSessionImplTwoTest, NotifyOccupiedAreaChangeInfo, Function | SmallTest | Level2)
570 {
571 auto window = GetTestWindowImpl("NotifyOccupiedAreaChangeInfo");
572 ASSERT_NE(window, nullptr);
573
574 auto listeners = GetListenerList<IOccupiedAreaChangeListener, MockIOccupiedAreaChangeListener>();
575 ASSERT_NE(listeners.size(), 0);
576 listeners.insert(listeners.begin(), nullptr);
577 window->occupiedAreaChangeListeners_.insert({window->GetPersistentId(), listeners});
578
579 sptr<OccupiedAreaChangeInfo> info = new (std::nothrow) OccupiedAreaChangeInfo();
580 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
581 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
582 window->NotifyOccupiedAreaChangeInfo(info);
583
584 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
585 window->NotifyOccupiedAreaChangeInfo(info);
586
587 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
588 window->windowSessionMap_.insert(
589 {"test1", std::pair<int32_t, sptr<WindowSessionImpl>>(window->GetPersistentId(), nullptr)}
590 );
591 window->NotifyOccupiedAreaChangeInfo(info);
592 window->windowSessionMap_.clear();
593
594 window->windowSessionMap_.insert(
595 {"test1", std::pair<int32_t, sptr<WindowSessionImpl>>(window->GetPersistentId(), window)}
596 );
597 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
598 window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
599 window->NotifyOccupiedAreaChangeInfo(info);
600
601 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
602 window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
603 window->NotifyOccupiedAreaChangeInfo(info);
604 window->Destroy();
605 }
606
607 /**
608 * @tc.name: NotifyWindowStatusChange
609 * @tc.desc: NotifyWindowStatusChange
610 * @tc.type: FUNC
611 */
612 HWTEST_F(WindowSessionImplTwoTest, NotifyWindowStatusChange, Function | SmallTest | Level2)
613 {
614 auto window = GetTestWindowImpl("NotifyWindowStatusChange");
615 ASSERT_NE(window, nullptr);
616
617 auto listeners = GetListenerList<IWindowStatusChangeListener, MockWindowStatusChangeListener>();
618 ASSERT_NE(listeners.size(), 0);
619 listeners.insert(listeners.begin(), nullptr);
620 window->windowStatusChangeListeners_.insert({window->GetPersistentId(), listeners});
621
622 WindowMode mode = WindowMode::WINDOW_MODE_FLOATING;
623 window->state_ = WindowState::STATE_HIDDEN;
624 window->property_->SetMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR);
625 window->NotifyWindowStatusChange(mode);
626
627 window->state_ = WindowState::STATE_FROZEN;
628 window->property_->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
629 window->NotifyWindowStatusChange(mode);
630
631 mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
632 window->NotifyWindowStatusChange(mode);
633
634 mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
635 window->NotifyWindowStatusChange(mode);
636
637 mode = WindowMode::WINDOW_MODE_PIP;
638 window->NotifyWindowStatusChange(mode);
639 window->Destroy();
640 }
641
642 /**
643 * @tc.name: UpdatePiPRect
644 * @tc.desc: UpdatePiPRect
645 * @tc.type: FUNC
646 */
647 HWTEST_F(WindowSessionImplTwoTest, UpdatePiPRect, Function | SmallTest | Level2)
648 {
649 auto window = GetTestWindowImpl("UpdatePiPRect");
650 ASSERT_NE(window, nullptr);
651
652 window->property_->SetPersistentId(1);
653 window->state_ = WindowState::STATE_FROZEN;
654 Rect rect;
655 window->UpdatePiPRect(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
656
657 window->hostSession_ = nullptr;
658 window->UpdatePiPRect(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
659 window->Destroy();
660 }
661
662 /**
663 * @tc.name: NotifyTransformChange
664 * @tc.desc: NotifyTransformChange
665 * @tc.type: FUNC
666 */
667 HWTEST_F(WindowSessionImplTwoTest, NotifyTransformChange, Function | SmallTest | Level2)
668 {
669 auto window = GetTestWindowImpl("NotifyTransformChange");
670 ASSERT_NE(window, nullptr);
671
672 Transform transform;
673 window->NotifyTransformChange(transform);
674
675 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
676 window->NotifyTransformChange(transform);
677 window->Destroy();
678 }
679
680 /**
681 * @tc.name: SubmitNoInteractionMonitorTask
682 * @tc.desc: SubmitNoInteractionMonitorTask
683 * @tc.type: FUNC
684 */
685 HWTEST_F(WindowSessionImplTwoTest, SubmitNoInteractionMonitorTask, Function | SmallTest | Level2)
686 {
687 auto window = GetTestWindowImpl("SubmitNoInteractionMonitorTask");
688 ASSERT_NE(window, nullptr);
689
690 IWindowNoInteractionListenerSptr listener = new (std::nothrow) MockWindowNoInteractionListener();
691 window->SubmitNoInteractionMonitorTask(window->lastInteractionEventId_.load() + 1, listener);
692
693 window->state_ = WindowState::STATE_SHOWN;
694 window->SubmitNoInteractionMonitorTask(window->lastInteractionEventId_.load(), listener);
695
696 window->state_ = WindowState::STATE_FROZEN;
697 window->SubmitNoInteractionMonitorTask(window->lastInteractionEventId_.load(), listener);
698 window->Destroy();
699 }
700
701 /**
702 * @tc.name: RefreshNoInteractionTimeoutMonitor
703 * @tc.desc: RefreshNoInteractionTimeoutMonitor
704 * @tc.type: FUNC
705 */
706 HWTEST_F(WindowSessionImplTwoTest, RefreshNoInteractionTimeoutMonitor, Function | SmallTest | Level2)
707 {
708 auto window = GetTestWindowImpl("RefreshNoInteractionTimeoutMonitor");
709 ASSERT_NE(window, nullptr);
710
711 window->RefreshNoInteractionTimeoutMonitor();
712
713 auto listeners = GetListenerList<IWindowStatusChangeListener, MockWindowStatusChangeListener>();
714 ASSERT_NE(listeners.size(), 0);
715 window->windowStatusChangeListeners_.insert({window->GetPersistentId(), listeners});
716 window->RefreshNoInteractionTimeoutMonitor();
717 window->Destroy();
718 }
719
720 /**
721 * @tc.name: IsUserOrientation
722 * @tc.desc: IsUserOrientation
723 * @tc.type: FUNC
724 */
725 HWTEST_F(WindowSessionImplTwoTest, IsUserOrientation, Function | SmallTest | Level2)
726 {
727 auto window = GetTestWindowImpl("IsUserOrientation");
728 ASSERT_NE(window, nullptr);
729
730 ASSERT_FALSE(window->IsUserOrientation(Orientation::FOLLOW_DESKTOP));
731 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_PORTRAIT));
732 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_LANDSCAPE));
733 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED));
734 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED));
735 window->Destroy();
736 }
737
738 /**
739 * @tc.name: WindowSessionCreateCheck
740 * @tc.desc: WindowSessionCreateCheck
741 * @tc.type: FUNC
742 */
743 HWTEST_F(WindowSessionImplTwoTest, WindowSessionCreateCheck, Function | SmallTest | Level2)
744 {
745 auto window = GetTestWindowImpl("WindowSessionCreateCheck");
746 ASSERT_NE(window, nullptr);
747
748 int32_t nullWindowTestId = 1001;
749 int32_t displayId = 1003;
750 int32_t cameraId = 1004;
751
752 window->windowSessionMap_.clear();
753 window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
754 window->windowSessionMap_.insert(
755 std::make_pair<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>(
756 "nullWindow",
757 std::pair<int32_t, sptr<WindowSessionImpl>>(nullWindowTestId, nullptr)
758 )
759 );
760 auto displayWindow = GetTestWindowImpl("displayWindow");
761 ASSERT_NE(displayWindow, nullptr);
762 displayWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_FREEZE_DISPLAY);
763 window->windowSessionMap_.insert(
764 std::make_pair<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>(
765 "displayWindow",
766 std::pair<int32_t, sptr<WindowSessionImpl>>(displayId, displayWindow)
767 )
768 );
769 ASSERT_EQ(window->WindowSessionCreateCheck(), WMError::WM_OK);
770
771 window->windowSessionMap_.clear();
772 auto cameraWindow = GetTestWindowImpl("cameraWindow");
773 ASSERT_NE(cameraWindow, nullptr);
774 cameraWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
775 window->windowSessionMap_.insert(
776 std::make_pair<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>(
777 "cameraWindow",
778 std::pair<int32_t, sptr<WindowSessionImpl>>(cameraId, cameraWindow)
779 )
780 );
781 ASSERT_EQ(window->WindowSessionCreateCheck(), WMError::WM_ERROR_REPEAT_OPERATION);
782 window->Destroy();
783 displayWindow->Destroy();
784 cameraWindow->Destroy();
785 }
786
787 /**
788 * @tc.name: NotifyForegroundInteractiveStatus
789 * @tc.desc: NotifyForegroundInteractiveStatus
790 * @tc.type: FUNC
791 */
792 HWTEST_F(WindowSessionImplTwoTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
793 {
794 auto window = GetTestWindowImpl("NotifyForegroundInteractiveStatus");
795 ASSERT_NE(window, nullptr);
796
797 window->property_->SetPersistentId(1);
798 window->state_ = WindowState::STATE_SHOWN;
799 window->NotifyForegroundInteractiveStatus(true);
800 window->NotifyForegroundInteractiveStatus(false);
801
802 window->state_ = WindowState::STATE_DESTROYED;
803 window->NotifyForegroundInteractiveStatus(true);
804 window->state_ = WindowState::STATE_FROZEN;
805 window->NotifyForegroundInteractiveStatus(true);
806 window->Destroy();
807 }
808
809 /**
810 * @tc.name: UpdateDecorEnableToAce
811 * @tc.desc: UpdateDecorEnableToAce
812 * @tc.type: FUNC
813 */
814 HWTEST_F(WindowSessionImplTwoTest, UpdateDecorEnableToAce, Function | SmallTest | Level2)
815 {
816 auto window = GetTestWindowImpl("UpdateDecorEnableToAce");
817 ASSERT_NE(window, nullptr);
818 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
819 auto listeners = GetListenerList<IWindowChangeListener, MockWindowChangeListener>();
820 sptr<MockWindowChangeListener> nullListener;
821 listeners.insert(listeners.begin(), nullListener);
822 window->windowChangeListeners_.insert({window->GetPersistentId(), listeners});
823 window->windowSystemConfig_.freeMultiWindowSupport_ = false;
824 window->UpdateDecorEnableToAce(false);
825
826 window->uiContent_ = nullptr;
827 window->UpdateDecorEnableToAce(false);
828 window->Destroy();
829 }
830
831 /**
832 * @tc.name: UpdateDecorEnable
833 * @tc.desc: UpdateDecorEnable
834 * @tc.type: FUNC
835 */
836 HWTEST_F(WindowSessionImplTwoTest, UpdateDecorEnable, Function | SmallTest | Level2)
837 {
838 auto window = GetTestWindowImpl("UpdateDecorEnable");
839 ASSERT_NE(window, nullptr);
840 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
841 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
842 window->UpdateDecorEnable(true, WindowMode::WINDOW_MODE_UNDEFINED);
843
844 window->windowSystemConfig_.freeMultiWindowSupport_ = false;
845 window->UpdateDecorEnable(true, WindowMode::WINDOW_MODE_FULLSCREEN);
846
847 window->uiContent_ = nullptr;
848 window->UpdateDecorEnable(true, WindowMode::WINDOW_MODE_FULLSCREEN);
849 window->UpdateDecorEnable(false, WindowMode::WINDOW_MODE_FULLSCREEN);
850 window->Destroy();
851 }
852
853 /**
854 * @tc.name: NotifyModeChange
855 * @tc.desc: NotifyModeChange
856 * @tc.type: FUNC
857 */
858 HWTEST_F(WindowSessionImplTwoTest, NotifyModeChange, Function | SmallTest | Level2)
859 {
860 auto window = GetTestWindowImpl("NotifyModeChange");
861 ASSERT_NE(window, nullptr);
862 auto listeners = GetListenerList<IWindowChangeListener, MockWindowChangeListener>();
863 sptr<MockWindowChangeListener> nullListener;
864 listeners.insert(listeners.begin(), nullListener);
865 window->windowChangeListeners_.insert({window->GetPersistentId(), listeners});
866
867 window->NotifyModeChange(WindowMode::WINDOW_MODE_FULLSCREEN, true);
868 window->Destroy();
869 }
870
871 /**
872 * @tc.name: SetRequestedOrientation
873 * @tc.desc: SetRequestedOrientation
874 * @tc.type: FUNC
875 */
876 HWTEST_F(WindowSessionImplTwoTest, SetRequestedOrientation, Function | SmallTest | Level2)
877 {
878 auto window = GetTestWindowImpl("SetRequestedOrientation");
879 ASSERT_NE(window, nullptr);
880 window->property_->SetRequestedOrientation(Orientation::BEGIN);
881 window->SetRequestedOrientation(Orientation::END);
882
883 window->property_->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
884 window->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
885
886 window->property_->SetRequestedOrientation(Orientation::BEGIN);
887 window->SetRequestedOrientation(Orientation::BEGIN);
888 window->Destroy();
889 }
890
891 /**
892 * @tc.name: GetContentInfo
893 * @tc.desc: GetContentInfo
894 * @tc.type: FUNC
895 */
896 HWTEST_F(WindowSessionImplTwoTest, GetContentInfo, Function | SmallTest | Level2)
897 {
898 auto window = GetTestWindowImpl("GetContentInfo");
899 ASSERT_NE(window, nullptr);
900
901 ASSERT_EQ(window->GetContentInfo(), "");
902 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
903 window->GetContentInfo();
904 window->Destroy();
905 }
906
907 /**
908 * @tc.name: GetDecorHeight
909 * @tc.desc: GetDecorHeight
910 * @tc.type: FUNC
911 */
912 HWTEST_F(WindowSessionImplTwoTest, GetDecorHeight, Function | SmallTest | Level2)
913 {
914 auto window = GetTestWindowImpl("GetDecorHeight");
915 ASSERT_NE(window, nullptr);
916 ASSERT_NE(window->property_, nullptr);
917 window->property_->SetPersistentId(1);
918 int32_t height = -1;
919 ASSERT_EQ(window->GetDecorHeight(height), WMError::WM_ERROR_NULLPTR);
920
921 auto uiContent = std::make_unique<Ace::UIContentMocker>();
922 EXPECT_CALL(*uiContent, GetContainerModalTitleHeight()).WillRepeatedly(Return(-1));
923 window->uiContent_ = std::move(uiContent);
924 ASSERT_EQ(window->GetDecorHeight(height), WMError::WM_OK);
925 height = 1;
926 window->GetDecorHeight(height);
927 window->Destroy();
928 }
929
930 /**
931 * @tc.name: GetTitleButtonArea
932 * @tc.desc: GetTitleButtonArea
933 * @tc.type: FUNC
934 */
935 HWTEST_F(WindowSessionImplTwoTest, GetTitleButtonArea, Function | SmallTest | Level2)
936 {
937 auto window = GetTestWindowImpl("GetTitleButtonArea");
938 ASSERT_NE(window, nullptr);
939 ASSERT_NE(window->property_, nullptr);
940 window->property_->SetPersistentId(1);
941 auto uiContent = std::make_unique<Ace::UIContentMocker>();
942 EXPECT_CALL(*uiContent, GetContainerModalButtonsRect(testing::_, testing::_)).WillRepeatedly(Return(false));
943 window->uiContent_ = std::move(uiContent);
944 TitleButtonRect titleButtonRect;
945 ASSERT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_OK);
946 window->Destroy();
947 }
948
949 /**
950 * @tc.name: RegisterWindowTitleButtonRectChangeListener
951 * @tc.desc: RegisterWindowTitleButtonRectChangeListener
952 * @tc.type: FUNC
953 */
954 HWTEST_F(WindowSessionImplTwoTest, RegisterWindowTitleButtonRectChangeListener, Function | SmallTest | Level2)
955 {
956 auto window = GetTestWindowImpl("RegisterWindowTitleButtonRectChangeListener");
957 ASSERT_NE(window, nullptr);
958 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
959 sptr<IWindowTitleButtonRectChangedListener> listener =
960 new (std::nothrow) MockWindowTitleButtonRectChangedListener();
961 ASSERT_NE(listener, nullptr);
962 window->RegisterWindowTitleButtonRectChangeListener(listener);
963 window->Destroy();
964 }
965
966 /**
967 * @tc.name: UnregisterWindowTitleButtonRectChangeListener
968 * @tc.desc: UnregisterWindowTitleButtonRectChangeListener
969 * @tc.type: FUNC
970 */
971 HWTEST_F(WindowSessionImplTwoTest, UnregisterWindowTitleButtonRectChangeListener, Function | SmallTest | Level2)
972 {
973 auto window = GetTestWindowImpl("UnregisterWindowTitleButtonRectChangeListener");
974 ASSERT_NE(window, nullptr);
975 sptr<IWindowTitleButtonRectChangedListener> listener =
976 new (std::nothrow) MockWindowTitleButtonRectChangedListener();
977 ASSERT_NE(listener, nullptr);
978 window->UnregisterWindowTitleButtonRectChangeListener(listener);
979
980 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
981 window->UnregisterWindowTitleButtonRectChangeListener(listener);
982 window->Destroy();
983 }
984
985 /**
986 * @tc.name: NotifyWindowTitleButtonRectChange
987 * @tc.desc: NotifyWindowTitleButtonRectChange
988 * @tc.type: FUNC
989 */
990 HWTEST_F(WindowSessionImplTwoTest, NotifyWindowTitleButtonRectChange, Function | SmallTest | Level2)
991 {
992 auto window = GetTestWindowImpl("NotifyWindowTitleButtonRectChange");
993 ASSERT_NE(window, nullptr);
994 auto listeners = GetListenerList<IWindowTitleButtonRectChangedListener,
995 MockWindowTitleButtonRectChangedListener>();
996 listeners.insert(listeners.begin(), nullptr);
997 window->windowTitleButtonRectChangeListeners_.insert({window->GetPersistentId(), listeners});
998 TitleButtonRect titleButtonRect;
999 window->NotifyWindowTitleButtonRectChange(titleButtonRect);
1000 window->Destroy();
1001 }
1002
1003 /**
1004 * @tc.name: RegisterWindowRectChangeListener
1005 * @tc.desc: RegisterWindowRectChangeListener
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(WindowSessionImplTwoTest, RegisterWindowRectChangeListener, Function | SmallTest | Level2)
1009 {
1010 auto window = GetTestWindowImpl("RegisterWindowRectChangeListener");
1011 ASSERT_NE(window, nullptr);
1012 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterWindowRectChangeListener(nullptr));
1013
1014 sptr<IWindowRectChangeListener> listener = new (std::nothrow) MockWindowRectChangeListener();
1015 ASSERT_NE(listener, nullptr);
1016 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1017
1018 window->hostSession_ = nullptr;
1019 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1020 window->Destroy();
1021 }
1022
1023 /**
1024 * @tc.name: UnregisterWindowRectChangeListener
1025 * @tc.desc: UnregisterWindowRectChangeListener01
1026 * @tc.type: FUNC
1027 */
1028 HWTEST_F(WindowSessionImplTwoTest, UnregisterWindowRectChangeListener01, Function | SmallTest | Level2)
1029 {
1030 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: UnregisterWindowRectChangeListener01 start";
1031 auto window = GetTestWindowImpl("UnregisterWindowRectChangeListener01");
1032 ASSERT_NE(window, nullptr);
1033 window->hostSession_ = nullptr;
1034 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterWindowRectChangeListener(nullptr));
1035 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterWindowRectChangeListener(nullptr));
1036
1037 sptr<IWindowRectChangeListener> listener = new (std::nothrow) MockWindowRectChangeListener();
1038 ASSERT_NE(listener, nullptr);
1039 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1040 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
1041
1042 SessionInfo sessionInfo = {"CreateTestBunble", "CreateTestModule", "CreateTestAbility"};
1043 sptr<SessionMocker> hostSession = new (std::nothrow) SessionMocker(sessionInfo);
1044 window->hostSession_ = hostSession;
1045 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1046 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
1047 window->Destroy();
1048 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: UnregisterWindowRectChangeListener01 end";
1049 }
1050
1051 /**
1052 * @tc.name: GetVirtualPixelRatio
1053 * @tc.desc: GetVirtualPixelRatio
1054 * @tc.type: FUNC
1055 */
1056 HWTEST_F(WindowSessionImplTwoTest, GetVirtualPixelRatio, Function | SmallTest | Level2)
1057 {
1058 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: GetVirtualPixelRatio start";
1059 auto window = GetTestWindowImpl("GetVirtualPixelRatio");
1060 ASSERT_NE(nullptr, window);
1061 sptr<DisplayInfo> displayInfo = new (std::nothrow) DisplayInfo();
1062 float vpr = window->GetVirtualPixelRatio(displayInfo);
1063 ASSERT_EQ(1.0, vpr);
1064 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: GetVirtualPixelRatio end";
1065 }
1066
1067 /**
1068 * @tc.name: InitUIContent
1069 * @tc.desc: InitUIContent
1070 * @tc.type: FUNC
1071 */
1072 HWTEST_F(WindowSessionImplTwoTest, InitUIContent, Function | SmallTest | Level2)
1073 {
1074 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: InitUIContent start";
1075 auto window = GetTestWindowImpl("InitUIContent_Default");
1076 ASSERT_NE(window, nullptr);
1077 std::string contentInfo = "contentInfo";
1078 napi_env env = nullptr;
1079 napi_value storage = nullptr;
1080 WindowSetUIContentType type = WindowSetUIContentType::DEFAULT;
1081 AppExecFwk::Ability *ability = nullptr;
1082 OHOS::Ace::UIContentErrorCode aceRet;
1083 BackupAndRestoreType restoreType = BackupAndRestoreType::NONE;
1084
1085 window->uiContent_ = nullptr;
1086 EXPECT_EQ(window->InitUIContent(contentInfo, env, storage, type, restoreType, ability, aceRet), WMError::WM_OK);
1087
1088 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1089 EXPECT_EQ(window->InitUIContent(contentInfo, env, storage, type, restoreType, ability, aceRet), WMError::WM_OK);
1090
1091 type = WindowSetUIContentType::RESTORE;
1092 EXPECT_EQ(window->InitUIContent(contentInfo, env, storage, type, restoreType, ability, aceRet), WMError::WM_OK);
1093
1094 type = WindowSetUIContentType::BY_NAME;
1095 EXPECT_EQ(window->InitUIContent(contentInfo, env, storage, type, restoreType, ability, aceRet), WMError::WM_OK);
1096
1097 type = WindowSetUIContentType::BY_ABC;
1098 EXPECT_EQ(window->InitUIContent(contentInfo, env, storage, type, restoreType, ability, aceRet), WMError::WM_OK);
1099 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: InitUIContent end";
1100 }
1101
1102 /**
1103 * @tc.name: RegisterSubWindowCloseListeners
1104 * @tc.desc: RegisterSubWindowCloseListeners01
1105 * @tc.type: FUNC
1106 */
1107 HWTEST_F(WindowSessionImplTwoTest, RegisterSubWindowCloseListeners01, Function | SmallTest | Level2)
1108 {
1109 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: RegisterSubWindowCloseListeners01 start";
1110 class MockISubWindowCloseListener : public ISubWindowCloseListener
1111 {
1112 public:
OnSubWindowClose(bool & terminateCloseProcess)1113 void OnSubWindowClose(bool &terminateCloseProcess) {}
1114 };
1115 window_ = GetTestWindowImpl("RegisterSubWindowCloseListeners01");
1116 ASSERT_NE(window_, nullptr);
1117 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->RegisterSubWindowCloseListeners(nullptr));
1118 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UnregisterSubWindowCloseListeners(nullptr));
1119
1120 sptr<ISubWindowCloseListener> listener = new MockISubWindowCloseListener();
1121 window_->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1122 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window_->RegisterSubWindowCloseListeners(listener));
1123 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window_->UnregisterSubWindowCloseListeners(listener));
1124
1125 window_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1126 ASSERT_EQ(WMError::WM_OK, window_->RegisterSubWindowCloseListeners(listener));
1127 ASSERT_EQ(WMError::WM_OK, window_->UnregisterSubWindowCloseListeners(listener));
1128 window_->Destroy();
1129 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: RegisterSubWindowCloseListeners01 end";
1130 }
1131
1132 /**
1133 * @tc.name: GetListeners
1134 * @tc.desc: GetListeners01 IWindowLifeCycle
1135 * @tc.type: FUNC
1136 */
1137 HWTEST_F(WindowSessionImplTwoTest, GetListeners01, Function | SmallTest | Level2)
1138 {
1139 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: GetListeners01 start";
1140 window_ = GetTestWindowImpl("GetListeners01");
1141 ASSERT_NE(window_, nullptr);
1142 window_->lifecycleListeners_.clear();
1143 window_->NotifyWindowAfterFocused();
1144 ASSERT_TRUE(window_->lifecycleListeners_[window_->GetPersistentId()].empty());
1145 sptr<IWindowLifeCycle> listener = new (std::nothrow) MockWindowLifeCycleListener();
1146 window_->RegisterLifeCycleListener(listener);
1147 window_->NotifyWindowAfterFocused();
1148 ASSERT_FALSE(window_->lifecycleListeners_[window_->GetPersistentId()].empty());
1149 window_->Destroy();
1150 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: GetListeners01 end";
1151 }
1152
1153 /**
1154 * @tc.name: GetListeners
1155 * @tc.desc: GetListeners02 IOccupiedAreaChangeListener
1156 * @tc.type: FUNC
1157 */
1158 HWTEST_F(WindowSessionImplTwoTest, GetListeners02, Function | SmallTest | Level2)
1159 {
1160 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: GetListeners02 start";
1161 window_ = GetTestWindowImpl("GetListeners02");
1162 ASSERT_NE(window_, nullptr);
1163 window_->occupiedAreaChangeListeners_.clear();
1164 sptr<OccupiedAreaChangeInfo> occupiedAreaChangeInfo = new OccupiedAreaChangeInfo();
1165 window_->NotifyOccupiedAreaChangeInfo(occupiedAreaChangeInfo, nullptr);
1166 ASSERT_TRUE(window_->occupiedAreaChangeListeners_[window_->GetPersistentId()].empty());
1167 sptr<IOccupiedAreaChangeListener> listener = new (std::nothrow) MockIOccupiedAreaChangeListener();
1168 window_->RegisterOccupiedAreaChangeListener(listener);
1169 window_->NotifyOccupiedAreaChangeInfo(occupiedAreaChangeInfo, nullptr);
1170 ASSERT_FALSE(window_->occupiedAreaChangeListeners_[window_->GetPersistentId()].empty());
1171 window_->Destroy();
1172 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: GetListeners02 end";
1173 }
1174
1175 /**
1176 * @tc.name: GetUIContent
1177 * @tc.desc: GetUIContent
1178 * @tc.type: FUNC
1179 */
1180 HWTEST_F(WindowSessionImplTwoTest, GetUIContent, Function | SmallTest | Level2)
1181 {
1182 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1183 ASSERT_NE(option, nullptr);
1184 option->SetWindowName("GetUIContent");
1185 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1186 ASSERT_NE(window, nullptr);
1187 Ace::UIContent *res = window->GetUIContent();
1188 ASSERT_EQ(res, nullptr);
1189 ASSERT_EQ(window->Destroy(), WMError::WM_ERROR_INVALID_WINDOW);
1190 }
1191
1192 /**
1193 * @tc.name: NotifySizeChange
1194 * @tc.desc: NotifySizeChange
1195 * @tc.type: FUNC
1196 */
1197 HWTEST_F(WindowSessionImplTwoTest, NotifySizeChange, Function | SmallTest | Level2)
1198 {
1199 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1200 ASSERT_NE(option, nullptr);
1201 option->SetWindowName("NotifySizeChange");
1202 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1203 ASSERT_NE(window, nullptr);
1204 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1205 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1206 ASSERT_NE(nullptr, session);
1207 EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1208
1209 Rect rect;
1210 sptr<IWindowChangeListener> listener = new (std::nothrow) MockWindowChangeListener();
1211 ASSERT_NE(nullptr, listener);
1212 window->RegisterWindowChangeListener(listener);
1213 window->NotifySizeChange(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
1214
1215 sptr<IWindowRectChangeListener> listener1 = new (std::nothrow) MockWindowRectChangeListener();
1216 ASSERT_NE(nullptr, listener1);
1217 window->RegisterWindowRectChangeListener(listener1);
1218 window->NotifySizeChange(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
1219 window->Destroy(true);
1220 }
1221
1222 /**
1223 * @tc.name: AvoidAreaChangeListener
1224 * @tc.desc: AvoidAreaChangeListener
1225 * @tc.type: FUNC
1226 */
1227 HWTEST_F(WindowSessionImplTwoTest, AvoidAreaChangeListener, Function | SmallTest | Level2)
1228 {
1229 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1230 ASSERT_NE(option, nullptr);
1231 option->SetWindowName("AvoidAreaChangeListener");
1232 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1233 ASSERT_NE(window, nullptr);
1234 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1235 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1236 ASSERT_NE(nullptr, session);
1237 EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1238
1239 sptr<IAvoidAreaChangedListener> nullListener = nullptr;
1240 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterAvoidAreaChangeListener(nullListener));
1241
1242 sptr<IAvoidAreaChangedListener> listener = new (std::nothrow) MockAvoidAreaChangedListener();
1243 ASSERT_NE(nullptr, listener);
1244 window->UnregisterAvoidAreaChangeListener(listener);
1245
1246 window->RegisterAvoidAreaChangeListener(nullListener);
1247 window->RegisterAvoidAreaChangeListener(listener);
1248
1249 sptr<IAvoidAreaChangedListener> listener1 = new (std::nothrow) MockAvoidAreaChangedListener();
1250 ASSERT_NE(nullptr, listener1);
1251 window->RegisterAvoidAreaChangeListener(listener1);
1252
1253 window->UnregisterAvoidAreaChangeListener(listener);
1254 window->UnregisterAvoidAreaChangeListener(listener1);
1255 }
1256
1257 /**
1258 * @tc.name: TouchOutsideListener
1259 * @tc.desc: TouchOutsideListener
1260 * @tc.type: FUNC
1261 */
1262 HWTEST_F(WindowSessionImplTwoTest, TouchOutsideListener, Function | SmallTest | Level2)
1263 {
1264 sptr<WindowOption> option = new (std::nothrow) WindowOption();
1265 ASSERT_NE(option, nullptr);
1266 option->SetWindowName("TouchOutsideListener");
1267 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
1268 ASSERT_NE(window, nullptr);
1269 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1270 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
1271 ASSERT_NE(nullptr, session);
1272 EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session));
1273
1274 sptr<ITouchOutsideListener> nullListener = nullptr;
1275 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterTouchOutsideListener(nullListener));
1276
1277 sptr<ITouchOutsideListener> listener = new (std::nothrow) MockTouchOutsideListener();
1278 ASSERT_NE(nullptr, listener);
1279 window->UnregisterTouchOutsideListener(listener);
1280
1281 window->RegisterTouchOutsideListener(nullListener);
1282 window->RegisterTouchOutsideListener(listener);
1283
1284 sptr<ITouchOutsideListener> listener1 = new (std::nothrow) MockTouchOutsideListener();
1285 ASSERT_NE(nullptr, listener1);
1286 window->RegisterTouchOutsideListener(listener1);
1287
1288 window->UnregisterTouchOutsideListener(listener);
1289 window->UnregisterTouchOutsideListener(listener1);
1290 }
1291
1292 /**
1293 * @tc.name: NotifyScreenshot
1294 * @tc.desc: NotifyScreenshot01 listener==nullptr
1295 * @tc.type: FUNC
1296 */
1297 HWTEST_F(WindowSessionImplTwoTest, NotifyScreenshot01, Function | SmallTest | Level2)
1298 {
1299 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyScreenshot01 start";
1300 class MockIScrenshotListener : public IScreenshotListener
1301 {
1302 public:
1303 MOCK_METHOD0(OnScreenshot, void());
1304 };
1305 window_ = GetTestWindowImpl("NotifyScreenshot01");
1306 auto listeners = GetListenerList<IScreenshotListener, MockIScrenshotListener>();
1307 listeners[0] = nullptr;
1308 ASSERT_EQ(listeners.size(), 1);
1309 window_->screenshotListeners_.insert({window_->GetPersistentId(), listeners});
1310 window_->NotifyScreenshot();
1311 std::vector<sptr<IScreenshotListener>> screenshotListeners =
1312 window_->screenshotListeners_[window_->GetPersistentId()];
1313 ASSERT_NE(std::find(screenshotListeners.begin(), screenshotListeners.end(), nullptr), screenshotListeners.end());
1314 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyScreenshot01 end";
1315 }
1316
1317 /**
1318 * @tc.name: NotifyScreenshot
1319 * @tc.desc: NotifyScreenshot02 listener!=nullptr
1320 * @tc.type: FUNC
1321 */
1322 HWTEST_F(WindowSessionImplTwoTest, NotifyScreenshot02, Function | SmallTest | Level2)
1323 {
1324 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyScreenshot02 start";
1325 class ScreenshotListener : public IScreenshotListener
1326 {
1327 public:
OnScreenshot()1328 void OnScreenshot()
1329 {
1330 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyScreenshot02 OnScreenshot";
1331 SUCCEED();
1332 }
1333 };
1334 window_ = GetTestWindowImpl("NotifyScreenshot02");
1335 sptr<IScreenshotListener> listener = new (std::nothrow) ScreenshotListener();
1336 window_->RegisterScreenshotListener(listener);
1337 window_->NotifyScreenshot();
1338 window_->UnregisterScreenshotListener(listener);
1339 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyScreenshot02 end";
1340 }
1341
1342 /**
1343 * @tc.name: SetContinueState
1344 * @tc.desc: SetContinueState test
1345 * @tc.type: FUNC
1346 */
1347 HWTEST_F(WindowSessionImplTwoTest, SetContinueState, Function | SmallTest | Level2)
1348 {
1349 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: SetContinueState start";
1350 window_ = GetTestWindowImpl("SetContinueState");
1351 ASSERT_NE(window_, nullptr);
1352 WMError ret = window_->SetContinueState(static_cast<int32_t>(ContinueState::CONTINUESTATE_INACTIVE));
1353 ASSERT_EQ(ret, WMError::WM_OK);
1354 ret = window_->SetContinueState(-100);
1355 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
1356 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: SetContinueState end";
1357 }
1358
1359 /**
1360 * @tc.name: NotifyTouchDialogTarget
1361 * @tc.desc: NotifyTouchDialogTarget01 hostSession_==nullptr
1362 * @tc.type: FUNC
1363 */
1364 HWTEST_F(WindowSessionImplTwoTest, NotifyTouchDialogTarget01, Function | SmallTest | Level2)
1365 {
1366 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget01 start";
1367 window_ = GetTestWindowImpl("NotifyTouchDialogTarget01");
1368 int32_t posX = 100;
1369 int32_t posY = 100;
1370 window_->hostSession_ = nullptr;
1371 window_->NotifyTouchDialogTarget(posX, posY);
1372 sptr<ISession> hostSession = window_->GetHostSession();
1373 ASSERT_EQ(nullptr, hostSession);
1374 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget01 end";
1375 }
1376
1377 /**
1378 * @tc.name: NotifyTouchDialogTarget
1379 * @tc.desc: NotifyTouchDialogTarget02 hostSession_!=nullptr
1380 * @tc.type: FUNC
1381 */
1382 HWTEST_F(WindowSessionImplTwoTest, NotifyTouchDialogTarget02, Function | SmallTest | Level2)
1383 {
1384 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget02 start";
1385 window_ = GetTestWindowImpl("NotifyTouchDialogTarget02");
1386 SessionInfo sessionInfo = {"CreateTestBundle", "CreateTestModule", "CreateTestAbility"};
1387 sptr<SessionMocker> hostSession = new (std::nothrow) SessionMocker(sessionInfo);
1388 window_->hostSession_ = hostSession;
1389 int32_t posX = 100;
1390 int32_t posY = 100;
1391 window_->NotifyTouchDialogTarget(posX, posY);
1392 sptr<ISession> hostSession1 = window_->GetHostSession();
1393 ASSERT_NE(nullptr, hostSession1);
1394 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget02 end";
1395 }
1396
1397 /**
1398 * @tc.name: NotifyTouchDialogTarget
1399 * @tc.desc: NotifyTouchDialogTarget03 hostSession_==nullptr listener==nullptr
1400 * @tc.type: FUNC
1401 */
1402 HWTEST_F(WindowSessionImplTwoTest, NotifyTouchDialogTarget03, Function | SmallTest | Level2)
1403 {
1404 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget03 start";
1405 class MockIDialogTargetTouchListener : public IDialogTargetTouchListener
1406 {
1407 public:
1408 MOCK_CONST_METHOD0(OnDialogTargetTouch, void());
1409 };
1410 window_ = GetTestWindowImpl("NotifyTouchDialogTarget03");
1411 window_->hostSession_ = nullptr;
1412 auto listeners = GetListenerList<IDialogTargetTouchListener, MockIDialogTargetTouchListener>();
1413 listeners[0] = nullptr;
1414 (window_->dialogTargetTouchListener_)[window_->GetPersistentId()] = listeners;
1415 int32_t posX = 100;
1416 int32_t posY = 100;
1417 window_->NotifyTouchDialogTarget(posX, posY);
1418 std::vector<sptr<IDialogTargetTouchListener>> dialogTargetTouchListeners =
1419 (window_->dialogTargetTouchListener_)[window_->GetPersistentId()];
1420 ASSERT_NE(std::find(dialogTargetTouchListeners.begin(), dialogTargetTouchListeners.end(), nullptr),
1421 dialogTargetTouchListeners.end());
1422 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget03 end";
1423 }
1424
1425 /**
1426 * @tc.name: NotifyTouchDialogTarget
1427 * @tc.desc: NotifyTouchDialogTarget04 hostSession_==nullptr listener!=nullptr
1428 * @tc.type: FUNC
1429 */
1430 HWTEST_F(WindowSessionImplTwoTest, NotifyTouchDialogTarget04, Function | SmallTest | Level2)
1431 {
1432 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget04 start";
1433 class MockIDialogTargetTouchListener : public IDialogTargetTouchListener
1434 {
1435 public:
OnDialogTargetTouch() const1436 void OnDialogTargetTouch() const
1437 {
1438 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget04 OnDialogTargetTouch";
1439 SUCCEED();
1440 }
1441 };
1442 window_ = GetTestWindowImpl("NotifyTouchDialogTarget04");
1443 window_->hostSession_ = nullptr;
1444 sptr<IDialogTargetTouchListener> dialogTargetTouchListener = new (std::nothrow) MockIDialogTargetTouchListener();
1445 window_->RegisterDialogTargetTouchListener(dialogTargetTouchListener);
1446 int32_t posX = 100;
1447 int32_t posY = 100;
1448 window_->NotifyTouchDialogTarget(posX, posY);
1449 window_->UnregisterDialogTargetTouchListener(dialogTargetTouchListener);
1450 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyTouchDialogTarget04 end";
1451 }
1452
1453 /**
1454 * @tc.name: NotifyDisplayMove
1455 * @tc.desc: NotifyDisplayMove01 listener==nullptr
1456 * @tc.type: FUNC
1457 */
1458 HWTEST_F(WindowSessionImplTwoTest, NotifyDisplayMove01, Function | SmallTest | Level2)
1459 {
1460 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDisplayMove01 start";
1461 class MockIDisplayMoveListener : public IDisplayMoveListener
1462 {
1463 public:
1464 MOCK_METHOD2(OnDisplayMove, void(DisplayId from, DisplayId to));
1465 };
1466 window_ = GetTestWindowImpl("NotifyDisplayMove01");
1467 auto listeners = GetListenerList<IDisplayMoveListener, MockIDisplayMoveListener>();
1468 listeners[0] = nullptr;
1469 (window_->displayMoveListeners_)[window_->GetPersistentId()] = listeners;
1470 int32_t posX = 100;
1471 int32_t posY = 100;
1472 window_->NotifyTouchDialogTarget(posX, posY);
1473 std::vector<sptr<IDisplayMoveListener>> displayMoveListeners =
1474 (window_->displayMoveListeners_)[window_->GetPersistentId()];
1475 ASSERT_NE(std::find(displayMoveListeners.begin(), displayMoveListeners.end(), nullptr),
1476 displayMoveListeners.end());
1477 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDisplayMove01 end";
1478 }
1479
1480 /**
1481 * @tc.name: NotifyDisplayMove
1482 * @tc.desc: NotifyDisplayMove02 listener!=nullptr
1483 * @tc.type: FUNC
1484 */
1485 HWTEST_F(WindowSessionImplTwoTest, NotifyDisplayMove02, Function | SmallTest | Level2)
1486 {
1487 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDisplayMove02 start";
1488 class MockIDisplayMoveListener : public IDisplayMoveListener
1489 {
1490 public:
OnDisplayMove(DisplayId from,DisplayId to)1491 void OnDisplayMove(DisplayId from, DisplayId to)
1492 {
1493 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDisplayMove02 OnDisplayMove";
1494 SUCCEED();
1495 }
1496 };
1497 window_ = GetTestWindowImpl("NotifyDisplayMove02");
1498 sptr<IDisplayMoveListener> displayMoveListener = new (std::nothrow) MockIDisplayMoveListener();
1499 EXPECT_EQ(window_->RegisterDisplayMoveListener(displayMoveListener), WMError::WM_OK);
1500 int32_t posX = 100;
1501 int32_t posY = 100;
1502 window_->NotifyTouchDialogTarget(posX, posY);
1503 EXPECT_EQ(window_->UnregisterDisplayMoveListener(displayMoveListener), WMError::WM_OK);
1504 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDisplayMove02 end";
1505 }
1506
1507 /**
1508 * @tc.name: NotifyDestroy
1509 * @tc.desc: NotifyDestroy01 listener==nullptr
1510 * @tc.type: FUNC
1511 */
1512 HWTEST_F(WindowSessionImplTwoTest, NotifyDestroy01, Function | SmallTest | Level2)
1513 {
1514 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDestroy01 start";
1515 class MockIDialogDeathRecipientListener : public IDialogDeathRecipientListener
1516 {
1517 public:
1518 MOCK_CONST_METHOD0(OnDialogDeathRecipient, void());
1519 };
1520 window_ = GetTestWindowImpl("NotifyDestroy01");
1521 auto listeners = GetListenerList<IDialogDeathRecipientListener, MockIDialogDeathRecipientListener>();
1522 listeners[0] = nullptr;
1523 (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()] = listeners;
1524 window_->NotifyDestroy();
1525 std::vector<sptr<IDialogDeathRecipientListener>> dialogDeathRecipientListeners =
1526 (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()];
1527 ASSERT_NE(std::find(dialogDeathRecipientListeners.begin(), dialogDeathRecipientListeners.end(), nullptr),
1528 dialogDeathRecipientListeners.end());
1529 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDestroy01 end";
1530 }
1531
1532 /**
1533 * @tc.name: NotifyDestroy
1534 * @tc.desc: NotifyDestroy02 listener!=nullptr
1535 * @tc.type: FUNC
1536 */
1537 HWTEST_F(WindowSessionImplTwoTest, NotifyDestroy02, Function | SmallTest | Level2)
1538 {
1539 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDestroy02 start";
1540 class MockIDialogDeathRecipientListener : public IDialogDeathRecipientListener
1541 {
1542 public:
OnDialogDeathRecipient() const1543 void OnDialogDeathRecipient() const
1544 {
1545 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDestroy02 OnDialogDeathRecipient";
1546 SUCCEED();
1547 }
1548 };
1549 window_ = GetTestWindowImpl("NotifyDestroy02");
1550 sptr<IDialogDeathRecipientListener> listener = new (std::nothrow) MockIDialogDeathRecipientListener();
1551 window_->RegisterDialogDeathRecipientListener(listener);
1552 window_->NotifyDestroy();
1553 window_->UnregisterDialogDeathRecipientListener(listener);
1554 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: NotifyDestroy02 end";
1555 }
1556
1557 /**
1558 * @tc.name: RegisterDialogTargetTouchListener
1559 * @tc.desc: RegisterDialogTargetTouchListener01 listener!=nullptr
1560 * @tc.type: FUNC
1561 */
1562 HWTEST_F(WindowSessionImplTwoTest, RegisterDialogTargetTouchListener01, Function | SmallTest | Level2)
1563 {
1564 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: RegisterDialogTargetTouchListener01 start";
1565 class MockIDialogTargetTouchListener : public IDialogTargetTouchListener
1566 {
1567 public:
OnDialogTargetTouch() const1568 void OnDialogTargetTouch() const
1569 {
1570 }
1571 };
1572 window_ = GetTestWindowImpl("RegisterDialogTargetTouchListener01");
1573 sptr<IDialogTargetTouchListener> listener = new (std::nothrow) MockIDialogTargetTouchListener();
1574 WMError res = window_->RegisterDialogTargetTouchListener(listener);
1575 ASSERT_EQ(WMError::WM_OK, res);
1576 window_->UnregisterDialogTargetTouchListener(listener);
1577 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: RegisterDialogTargetTouchListener01 end";
1578 }
1579
1580 /**
1581 * @tc.name: RegisterDialogDeathRecipientListener
1582 * @tc.desc: RegisterDialogDeathRecipientListener01 listener!=nullptr
1583 * @tc.type: FUNC
1584 */
1585 HWTEST_F(WindowSessionImplTwoTest, RegisterDialogDeathRecipientListener01, Function | SmallTest | Level2)
1586 {
1587 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: RegisterDialogDeathRecipientListener01 start";
1588 class MockIDialogDeathRecipientListener : public IDialogDeathRecipientListener
1589 {
1590 public:
OnDialogDeathRecipient() const1591 void OnDialogDeathRecipient() const
1592 {
1593 }
1594 };
1595 window_ = GetTestWindowImpl("RegisterDialogDeathRecipientListener01");
1596 sptr<IDialogDeathRecipientListener> listener = new MockIDialogDeathRecipientListener();
1597 int32_t count = (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()].size();
1598 window_->RegisterDialogDeathRecipientListener(listener);
1599 std::vector<sptr<IDialogDeathRecipientListener>> dialogDeathRecipientListeners =
1600 (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()];
1601 ASSERT_EQ(++count, dialogDeathRecipientListeners.size());
1602 window_->UnregisterDialogDeathRecipientListener(listener);
1603 GTEST_LOG_(INFO) << "WindowSessionImplTwoTest: RegisterDialogDeathRecipientListener01 end";
1604 }
1605 }
1606 } // namespace Rosen
1607 } // namespace OHOS
1608