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