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 #include <transaction/rs_transaction.h>
20
21 #include "ability_context_impl.h"
22 #include "display_info.h"
23 #include "mock_session.h"
24 #include "mock_uicontent.h"
25 #include "mock_window.h"
26 #include "parameters.h"
27 #include "wm_common.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace {
33 std::string logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)34 void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag,
35 const char* msg)
36 {
37 logMsg = msg;
38 }
39 }
40
41 namespace OHOS {
42 namespace Rosen {
43 class WindowSessionImplTest2 : public testing::Test {
44 public:
45 static void SetUpTestCase();
46 static void TearDownTestCase();
47 void SetUp() override;
48 void TearDown() override;
49 sptr<WindowSessionImpl> window_;
50
51 private:
52 static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
53 };
54
SetUpTestCase()55 void WindowSessionImplTest2::SetUpTestCase() {}
56
TearDownTestCase()57 void WindowSessionImplTest2::TearDownTestCase() {}
58
SetUp()59 void WindowSessionImplTest2::SetUp() {}
60
TearDown()61 void WindowSessionImplTest2::TearDown()
62 {
63 usleep(WAIT_SYNC_IN_NS);
64 if (window_ != nullptr) {
65 window_->Destroy();
66 }
67 }
68
69 namespace {
GetTestWindowImpl(const std::string & name)70 sptr<WindowSessionImpl> GetTestWindowImpl(const std::string& name)
71 {
72 sptr<WindowOption> option = new (std::nothrow) WindowOption();
73 if (option == nullptr) {
74 return nullptr;
75 }
76 option->SetWindowName(name);
77 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
78 if (window == nullptr) {
79 return nullptr;
80 }
81
82 SessionInfo sessionInfo = { name, name, name };
83 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
84 if (session == nullptr) {
85 return nullptr;
86 }
87
88 window->hostSession_ = session;
89 auto runner = AppExecFwk::EventRunner::Create("WindowSessionImpl");
90 std::shared_ptr<AppExecFwk::EventHandler> handler = std::make_shared<AppExecFwk::EventHandler>(runner);
91 window->handler_ = handler;
92 return window;
93 }
94
GetListenerList()95 template <typename TListener, typename MockListener> std::vector<sptr<TListener>> GetListenerList()
96 {
97 std::vector<sptr<TListener>> listeners;
98 sptr<TListener> listener = new (std::nothrow) MockListener();
99 if (listener == nullptr) {
100 return listeners;
101 }
102
103 listeners.insert(listeners.begin(), listener);
104 return listeners;
105 }
106
107 /**
108 * @tc.name: GetTitleButtonVisible
109 * @tc.desc: GetTitleButtonVisible
110 * @tc.type: FUNC
111 */
112 HWTEST_F(WindowSessionImplTest2, GetTitleButtonVisible, TestSize.Level1)
113 {
114 auto window = GetTestWindowImpl("GetTitleButtonVisible");
115 ASSERT_NE(window, nullptr);
116 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
117 bool isMaximizeVisible = false;
118 bool isMinimizeVisible = false;
119 bool isSplitVisible = false;
120 bool isCloseVisible = false;
121 window->GetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, isSplitVisible, isCloseVisible);
122 ASSERT_FALSE(isSplitVisible);
123
124 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
125 window->windowTitleVisibleFlags_.isSplitVisible = false;
126 window->windowTitleVisibleFlags_.isMaximizeVisible = false;
127 window->windowTitleVisibleFlags_.isMinimizeVisible = false;
128 window->windowTitleVisibleFlags_.isCloseVisible = false;
129 window->GetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, isSplitVisible, isCloseVisible);
130 ASSERT_TRUE(isSplitVisible);
131 ASSERT_TRUE(isMaximizeVisible);
132 ASSERT_TRUE(isMinimizeVisible);
133 ASSERT_TRUE(isCloseVisible);
134
135 window->windowTitleVisibleFlags_.isSplitVisible = true;
136 window->windowTitleVisibleFlags_.isMaximizeVisible = true;
137 window->windowTitleVisibleFlags_.isMinimizeVisible = true;
138 window->windowTitleVisibleFlags_.isCloseVisible = true;
139 window->GetTitleButtonVisible(isMaximizeVisible, isMinimizeVisible, isSplitVisible, isCloseVisible);
140 ASSERT_TRUE(isSplitVisible);
141 ASSERT_TRUE(isMaximizeVisible);
142 ASSERT_TRUE(isMinimizeVisible);
143 ASSERT_TRUE(isCloseVisible);
144 }
145
146 /**
147 * @tc.name: GetSystemSessionConfig
148 * @tc.desc: GetSystemSessionConfig
149 * @tc.type: FUNC
150 */
151 HWTEST_F(WindowSessionImplTest2, GetSystemSessionConfig, TestSize.Level1)
152 {
153 auto window = GetTestWindowImpl("GetSystemSessionConfig");
154 ASSERT_NE(window, nullptr);
155 window->GetSystemSessionConfig();
156 window->Destroy();
157 }
158
159 /**
160 * @tc.name: GetColorSpaceFromSurfaceGamut
161 * @tc.desc: GetColorSpaceFromSurfaceGamut
162 * @tc.type: FUNC
163 */
164 HWTEST_F(WindowSessionImplTest2, GetColorSpaceFromSurfaceGamut, TestSize.Level1)
165 {
166 auto window = GetTestWindowImpl("GetColorSpaceFromSurfaceGamut");
167 ASSERT_NE(window, nullptr);
168 ASSERT_EQ(window->GetColorSpaceFromSurfaceGamut(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB),
169 ColorSpace::COLOR_SPACE_DEFAULT);
170 ASSERT_EQ(window->GetColorSpaceFromSurfaceGamut(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3),
171 ColorSpace::COLOR_SPACE_WIDE_GAMUT);
172 ASSERT_EQ(window->GetColorSpaceFromSurfaceGamut(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_INVALID),
173 ColorSpace::COLOR_SPACE_DEFAULT);
174 window->Destroy();
175 }
176
177 /**
178 * @tc.name: GetSurfaceGamutFromColorSpace
179 * @tc.desc: GetSurfaceGamutFromColorSpace
180 * @tc.type: FUNC
181 */
182 HWTEST_F(WindowSessionImplTest2, GetSurfaceGamutFromColorSpace, TestSize.Level1)
183 {
184 auto window = GetTestWindowImpl("GetSurfaceGamutFromColorSpace");
185 ASSERT_NE(window, nullptr);
186 ASSERT_EQ(window->GetSurfaceGamutFromColorSpace(ColorSpace::COLOR_SPACE_DEFAULT),
187 GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB);
188 ASSERT_EQ(window->GetSurfaceGamutFromColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT),
189 GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
190 ASSERT_EQ(window->GetSurfaceGamutFromColorSpace(ColorSpace(uint32_t(3))),
191 GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB);
192 window->Destroy();
193 }
194
195 /**
196 * @tc.name: Create
197 * @tc.desc: Create
198 * @tc.type: FUNC
199 */
200 HWTEST_F(WindowSessionImplTest2, Create, TestSize.Level1)
201 {
202 auto window = GetTestWindowImpl("Create");
203 ASSERT_NE(window, nullptr);
204 std::shared_ptr<AbilityRuntime::Context> context;
205 sptr<Rosen::ISession> ISession;
206 ASSERT_EQ(window->Create(context, ISession), WMError::WM_OK);
207 window->Destroy();
208 }
209
210 /**
211 * @tc.name: Destroy
212 * @tc.desc: Destroy
213 * @tc.type: FUNC
214 */
215 HWTEST_F(WindowSessionImplTest2, Destroy, TestSize.Level1)
216 {
217 auto window = GetTestWindowImpl("Destroy");
218 ASSERT_NE(window, nullptr);
219
220 window->property_->SetPersistentId(INVALID_SESSION_ID);
221 ASSERT_EQ(window->Destroy(true, true), WMError::WM_ERROR_INVALID_WINDOW);
222
223 window->property_->SetPersistentId(1);
224 window->state_ = WindowState::STATE_DESTROYED;
225 ASSERT_EQ(window->Destroy(true, true), WMError::WM_ERROR_INVALID_WINDOW);
226
227 window->state_ = WindowState::STATE_INITIAL;
228 ASSERT_EQ(window->Destroy(true, true), WMError::WM_OK);
229
230 window = GetTestWindowImpl("Destroy");
231 ASSERT_NE(window, nullptr);
232 window->state_ = WindowState::STATE_INITIAL;
233 window->property_->SetPersistentId(1);
234 ASSERT_EQ(window->Destroy(true, false), WMError::WM_OK);
235
236 window->hostSession_ = nullptr;
237 ASSERT_EQ(window->Destroy(true, true), WMError::WM_ERROR_INVALID_WINDOW);
238
239 window = GetTestWindowImpl("Destroy");
240 ASSERT_NE(window, nullptr);
241 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
242 sptr<SessionMocker> hostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
243 window->hostSession_ = hostSession;
244 ASSERT_EQ(window->Destroy(true, true), WMError::WM_ERROR_INVALID_WINDOW);
245
246 window = GetTestWindowImpl("Destroy");
247 ASSERT_NE(window, nullptr);
248 window->hostSession_ = hostSession;
249 window->state_ = WindowState::STATE_INITIAL;
250 window->property_->SetPersistentId(1);
251 ASSERT_FALSE(window->IsWindowSessionInvalid());
252 window->context_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
253 ASSERT_EQ(window->Destroy(true, true), WMError::WM_OK);
254 }
255
256 /**
257 * @tc.name: GetWindowState
258 * @tc.desc: GetWindowState
259 * @tc.type: FUNC
260 */
261 HWTEST_F(WindowSessionImplTest2, GetWindowState, TestSize.Level1)
262 {
263 auto window = GetTestWindowImpl("GetWindowState");
264 ASSERT_NE(window, nullptr);
265 window->state_ = WindowState::STATE_DESTROYED;
266 ASSERT_EQ(window->GetWindowState(), WindowState::STATE_DESTROYED);
267 window->Destroy();
268 }
269
270 /**
271 * @tc.name: RecoverSessionListener
272 * @tc.desc: RecoverSessionListener
273 * @tc.type: FUNC
274 */
275 HWTEST_F(WindowSessionImplTest2, RecoverSessionListener, TestSize.Level1)
276 {
277 auto window = GetTestWindowImpl("RecoverSessionListener");
278 ASSERT_NE(window, nullptr);
279 int32_t id = 1;
280 window->property_->SetPersistentId(id);
281 window->RecoverSessionListener();
282
283 std::vector<sptr<IAcrossDisplaysChangeListener>> iAcrossDisplaysChangeListener;
284 std::vector<sptr<IAvoidAreaChangedListener>> iAvoidAreaChangedListeners;
285 std::vector<sptr<ITouchOutsideListener>> iTouchOutsideListeners;
286 window->avoidAreaChangeListeners_.insert({ id, iAvoidAreaChangedListeners });
287 window->acrossDisplaysChangeListeners_.insert({ id, iAcrossDisplaysChangeListener });
288 window->touchOutsideListeners_.insert({ id, iTouchOutsideListeners });
289 window->RecoverSessionListener();
290
291 window->avoidAreaChangeListeners_.clear();
292 window->acrossDisplaysChangeListeners_.clear();
293 window->touchOutsideListeners_.clear();
294 sptr<MockAvoidAreaChangedListener> changedListener = sptr<MockAvoidAreaChangedListener>::MakeSptr();
295 sptr<MockTouchOutsideListener> touchOutsideListener = sptr<MockTouchOutsideListener>::MakeSptr();
296 sptr<MockAcrossDisplaysChangeListener> changedListener2 = sptr<MockAcrossDisplaysChangeListener>::MakeSptr();
297 iAvoidAreaChangedListeners.insert(iAvoidAreaChangedListeners.begin(), changedListener);
298 iAcrossDisplaysChangeListener.insert(iAcrossDisplaysChangeListener.begin(), changedListener2);
299 iTouchOutsideListeners.insert(iTouchOutsideListeners.begin(), touchOutsideListener);
300 window->avoidAreaChangeListeners_.insert({ id, iAvoidAreaChangedListeners });
301 window->acrossDisplaysChangeListeners_.insert({ id, iAcrossDisplaysChangeListener });
302 window->touchOutsideListeners_.insert({ id, iTouchOutsideListeners });
303 window->RecoverSessionListener();
304 ASSERT_TRUE(window->avoidAreaChangeListeners_.find(id) != window->avoidAreaChangeListeners_.end() &&
305 !window->avoidAreaChangeListeners_[id].empty());
306 ASSERT_TRUE(window->touchOutsideListeners_.find(id) != window->touchOutsideListeners_.end() &&
307 !window->touchOutsideListeners_[id].empty());
308 ASSERT_TRUE(window->acrossDisplaysChangeListeners_.find(id) != window->acrossDisplaysChangeListeners_.end() &&
309 !window->acrossDisplaysChangeListeners_[id].empty());
310 window->Destroy();
311 }
312
313 /**
314 * @tc.name: UpdateViewportConfig_KeyFrame
315 * @tc.desc: UpdateViewportConfig_KeyFrame
316 * @tc.type: FUNC
317 */
318 HWTEST_F(WindowSessionImplTest2, UpdateViewportConfig_KeyFrame, TestSize.Level1)
319 {
320 auto window = GetTestWindowImpl("UpdateViewportConfig_KeyFrame");
321 ASSERT_NE(window, nullptr);
322 Rect rect{ 10, 10, 10, 10 };
323 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
324 std::map<AvoidAreaType, AvoidArea> avoidAreas;
325 KeyFramePolicy keyFramePolicy;
326 window->SetKeyFramePolicy(keyFramePolicy);
327 WindowSizeChangeReason reason = WindowSizeChangeReason::UNDEFINED;
328 window->UpdateViewportConfig(rect, reason, nullptr, displayInfo, avoidAreas);
329 ASSERT_EQ(window->keyFramePolicy_.stopping_, false);
330 reason = WindowSizeChangeReason::DRAG_END;
331 window->UpdateViewportConfig(rect, reason, nullptr, displayInfo, avoidAreas);
332 ASSERT_EQ(window->keyFramePolicy_.stopping_, false);
333 window->Destroy();
334 }
335
336 /**
337 * @tc.name: RegisterKeyFrameCallback
338 * @tc.desc: RegisterKeyFrameCallback
339 * @tc.type: FUNC
340 */
341 HWTEST_F(WindowSessionImplTest2, RegisterKeyFrameCallback, TestSize.Level1)
342 {
343 auto window = GetTestWindowImpl("RegisterKeyFrameCallback");
344 ASSERT_NE(window, nullptr);
345 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
346 window->RegisterKeyFrameCallback();
347 window->uiContent_ = nullptr;
348 window->RegisterKeyFrameCallback();
349 window->Destroy();
350 }
351
352 /**
353 * @tc.name: LinkKeyFrameCanvasNode
354 * @tc.desc: LinkKeyFrameCanvasNode
355 * @tc.type: FUNC
356 */
357 HWTEST_F(WindowSessionImplTest2, LinkKeyFrameCanvasNode, TestSize.Level1)
358 {
359 auto window = GetTestWindowImpl("LinkKeyFrameCanvasNode");
360 ASSERT_NE(window, nullptr);
361 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
362 auto hostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
363 auto rsCanvasNode = RSCanvasNode::Create();
364 window->uiContent_ = nullptr;
365 window->hostSession_ = nullptr;
366 ASSERT_EQ(window->LinkKeyFrameCanvasNode(rsCanvasNode), WSError::WS_ERROR_NULLPTR);
367 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
368 ASSERT_EQ(window->LinkKeyFrameCanvasNode(rsCanvasNode), WSError::WS_ERROR_NULLPTR);
369 window->uiContent_ = nullptr;
370 window->hostSession_ = hostSession;
371 ASSERT_EQ(window->LinkKeyFrameCanvasNode(rsCanvasNode), WSError::WS_ERROR_NULLPTR);
372 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
373 ASSERT_EQ(window->LinkKeyFrameCanvasNode(rsCanvasNode), WSError::WS_OK);
374 window->Destroy();
375 }
376
377 /**
378 * @tc.name: SetKeyFramePolicy
379 * @tc.desc: SetKeyFramePolicy
380 * @tc.type: FUNC
381 */
382 HWTEST_F(WindowSessionImplTest2, SetKeyFramePolicy, TestSize.Level1)
383 {
384 auto window = GetTestWindowImpl("SetKeyFramePolicy");
385 ASSERT_NE(window, nullptr);
386 KeyFramePolicy keyFramePolicy;
387 ASSERT_EQ(window->SetKeyFramePolicy(keyFramePolicy), WSError::WS_OK);
388 ASSERT_EQ(window->keyFramePolicy_, keyFramePolicy);
389 window->Destroy();
390 }
391
392 /**
393 * @tc.name: NotifyUIContentFocusStatus
394 * @tc.desc: NotifyUIContentFocusStatus
395 * @tc.type: FUNC
396 */
397 HWTEST_F(WindowSessionImplTest2, NotifyUIContentFocusStatus, TestSize.Level1)
398 {
399 auto window = GetTestWindowImpl("NotifyUIContentFocusStatus");
400 ASSERT_NE(window, nullptr);
401 window->isFocused_ = false;
402 window->NotifyUIContentFocusStatus();
403
404 window->isFocused_ = true;
405 window->NotifyUIContentFocusStatus();
406
407 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
408 window->NotifyUIContentFocusStatus();
409 window->Destroy();
410 }
411
412 /**
413 * @tc.name: NotifyAfterFocused
414 * @tc.desc: NotifyAfterFocused
415 * @tc.type: FUNC
416 */
417 HWTEST_F(WindowSessionImplTest2, NotifyAfterFocused, TestSize.Level1)
418 {
419 auto window = GetTestWindowImpl("NotifyAfterFocused");
420 ASSERT_NE(window, nullptr);
421 window->NotifyAfterFocused();
422 ASSERT_TRUE(window->shouldReNotifyFocus_);
423
424 window->shouldReNotifyFocus_ = false;
425 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
426 window->NotifyAfterFocused();
427 ASSERT_FALSE(window->shouldReNotifyFocus_);
428 window->Destroy();
429 }
430
431 /**
432 * @tc.name: NotifyForegroundFailed
433 * @tc.desc: NotifyForegroundFailed
434 * @tc.type: FUNC
435 */
436 HWTEST_F(WindowSessionImplTest2, NotifyForegroundFailed, TestSize.Level1)
437 {
438 auto window = GetTestWindowImpl("NotifyForegroundFailed");
439 ASSERT_NE(window, nullptr);
440 window->NotifyForegroundFailed(WMError::WM_OK);
441 window->Destroy();
442 }
443
444 /**
445 * @tc.name: NotifyTransferComponentDataSync
446 * @tc.desc: NotifyTransferComponentDataSync
447 * @tc.type: FUNC
448 */
449 HWTEST_F(WindowSessionImplTest2, NotifyTransferComponentDataSync, TestSize.Level1)
450 {
451 auto window = GetTestWindowImpl("NotifyTransferComponentDataSync");
452 ASSERT_NE(window, nullptr);
453 AAFwk::WantParams wantParams;
454 AAFwk::WantParams reWantParams;
455 ASSERT_EQ(WSErrorCode::WS_OK, window->NotifyTransferComponentDataSync(wantParams, reWantParams));
456 window->Destroy();
457 }
458
459 /**
460 * @tc.name: UpdateAvoidArea
461 * @tc.desc: UpdateAvoidArea
462 * @tc.type: FUNC
463 */
464 HWTEST_F(WindowSessionImplTest2, UpdateAvoidArea, TestSize.Level1)
465 {
466 auto window = GetTestWindowImpl("UpdateAvoidArea");
467 ASSERT_NE(window, nullptr);
468 sptr<AvoidArea> avoidArea = sptr<AvoidArea>::MakeSptr();
469 avoidArea->topRect_ = { 1, 0, 0, 0 };
470 avoidArea->leftRect_ = { 0, 1, 0, 0 };
471 avoidArea->rightRect_ = { 0, 0, 1, 0 };
472 avoidArea->bottomRect_ = { 0, 0, 0, 1 };
473 AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM;
474 ASSERT_EQ(WSError::WS_OK, window->UpdateAvoidArea(avoidArea, type));
475 window->Destroy();
476 }
477
478 /**
479 * @tc.name: HandleEscKeyEvent001
480 * @tc.desc: HandleEscKeyEvent test
481 * @tc.type: FUNC
482 */
483 HWTEST_F(WindowSessionImplTest2, HandleEscKeyEvent001, TestSize.Level1)
484 {
485 auto window = GetTestWindowImpl("HandleEscKeyEvent001");
486 ASSERT_NE(window, nullptr);
487
488 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
489 ASSERT_NE(keyEvent, nullptr);
490 ASSERT_NE(window->property_, nullptr);
491 bool isConsumed = false;
492 window->escKeyEventTriggered_ = false;
493 window->escKeyHasDown_ = true;
494 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_ESCAPE);
495 ASSERT_EQ(WMError::WM_DO_NOTHING, window->HandleEscKeyEvent(keyEvent, isConsumed));
496
497 keyEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE);
498 EXPECT_EQ(true, keyEvent->HasFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE));
499 WMError result = window->HandleEscKeyEvent(keyEvent, isConsumed);
500 EXPECT_EQ(result, WMError::WM_OK);
501 window->Destroy();
502 }
503
504 /**
505 * @tc.name: HandleEscKeyEvent002
506 * @tc.desc: HandleEscKeyEvent test
507 * @tc.type: FUNC
508 */
509 HWTEST_F(WindowSessionImplTest2, HandleEscKeyEvent002, TestSize.Level1)
510 {
511 auto window = GetTestWindowImpl("HandleEscKeyEvent002");
512 ASSERT_NE(window, nullptr);
513 ASSERT_NE(window->property_, nullptr);
514
515 std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
516 bool isConsumed = false;
517 WMError result = window->HandleEscKeyEvent(keyEvent, isConsumed);
518 EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR);
519 window->Destroy();
520 }
521
522 /**
523 * @tc.name: HandleEscKeyEvent003
524 * @tc.desc: HandleEscKeyEvent test
525 * @tc.type: FUNC
526 */
527 HWTEST_F(WindowSessionImplTest2, HandleEscKeyEvent003, TestSize.Level1)
528 {
529 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
530 option->SetWindowName("HandleEscKeyEvent003");
531 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
532 ASSERT_NE(window, nullptr);
533 ASSERT_NE(window->property_, nullptr);
534
535 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
536 ASSERT_NE(keyEvent, nullptr);
537 bool isConsumed = true;
538 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_A);
539 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
540 isConsumed = false;
541 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
542
543 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_ESCAPE);
544 keyEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE);
545 EXPECT_EQ(true, keyEvent->HasFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE));
546
547 WMError result = window->HandleEscKeyEvent(keyEvent, isConsumed);
548 EXPECT_EQ(result, WMError::WM_OK);
549 }
550
551 /**
552 * @tc.name: HandleEscKeyEvent004
553 * @tc.desc: HandleEscKeyEvent test
554 * @tc.type: FUNC
555 */
556 HWTEST_F(WindowSessionImplTest2, HandleEscKeyEvent004, TestSize.Level1)
557 {
558 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
559 option->SetWindowName("HandleEscKeyEvent004");
560 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
561 ASSERT_NE(window, nullptr);
562 ASSERT_NE(window->property_, nullptr);
563
564 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
565 ASSERT_NE(keyEvent, nullptr);
566 bool isConsumed = false;
567 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_ESCAPE);
568 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
569 keyEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE);
570 EXPECT_EQ(true, keyEvent->HasFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE));
571
572 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
573 window->escKeyEventTriggered_ = false;
574 window->windowSystemConfig_.freeMultiWindowEnable_ = true;
575 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
576 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
577
578 window->windowSystemConfig_.freeMultiWindowEnable_ = false;
579 window->windowSystemConfig_.freeMultiWindowSupport_ = false;
580 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
581
582 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
583 window->windowSystemConfig_.freeMultiWindowEnable_ = true;
584 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
585 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
586
587 window->SetImmersiveModeEnabledState(true);
588 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
589
590 window->escKeyEventTriggered_ = true;
591 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
592
593 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
594 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
595
596 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
597 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
598 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
599 }
600
601 /**
602 * @tc.name: HandleEscKeyEvent005
603 * @tc.desc: HandleEscKeyEvent test
604 * @tc.type: FUNC
605 */
606 HWTEST_F(WindowSessionImplTest2, HandleEscKeyEvent005, TestSize.Level1)
607 {
608 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
609 option->SetWindowName("HandleEscKeyEvent005");
610 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
611 ASSERT_NE(window, nullptr);
612 ASSERT_NE(window->property_, nullptr);
613
614 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
615 ASSERT_NE(keyEvent, nullptr);
616 bool isConsumed = false;
617 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_ESCAPE);
618 keyEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE);
619 EXPECT_EQ(true, keyEvent->HasFlag(MMI::InputEvent::EVENT_FLAG_KEYBOARD_ESCAPE));
620
621 window->escKeyEventTriggered_ = true;
622 window->escKeyHasDown_ = true;
623 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
624 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
625
626 window->escKeyEventTriggered_ = false;
627 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
628
629 window->escKeyHasDown_ = false;
630 window->escKeyEventTriggered_ = true;
631 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
632
633 window->escKeyEventTriggered_ = false;
634 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
635
636 window->escKeyEventTriggered_ = true;
637 window->escKeyHasDown_ = true;
638 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
639 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
640
641 window->escKeyEventTriggered_ = false;
642 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
643
644 window->escKeyHasDown_ = false;
645 window->escKeyEventTriggered_ = true;
646 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
647
648 window->escKeyEventTriggered_ = false;
649 EXPECT_EQ(WMError::WM_OK, window->HandleEscKeyEvent(keyEvent, isConsumed));
650 }
651
652 /**
653 * @tc.name: DispatchKeyEventCallback
654 * @tc.desc: DispatchKeyEventCallback
655 * @tc.type: FUNC
656 */
657 HWTEST_F(WindowSessionImplTest2, DispatchKeyEventCallback, TestSize.Level1)
658 {
659 auto window = GetTestWindowImpl("DispatchKeyEventCallback");
660 ASSERT_NE(window, nullptr);
661
662 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
663 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_VIRTUAL_MULTITASK);
664 bool isConsumed = false;
665 window->DispatchKeyEventCallback(keyEvent, isConsumed);
666 ASSERT_FALSE(isConsumed);
667
668 std::shared_ptr<MockInputEventConsumer> inputEventConsumer = std::make_shared<MockInputEventConsumer>();
669 window->inputEventConsumer_ = inputEventConsumer;
670 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
671 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
672 window->DispatchKeyEventCallback(keyEvent, isConsumed);
673
674 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
675 window->DispatchKeyEventCallback(keyEvent, isConsumed);
676
677 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
678 window->inputEventConsumer_ = nullptr;
679 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
680 window->DispatchKeyEventCallback(keyEvent, isConsumed);
681
682 keyEvent->SetKeyAction(MMI::KeyEvent::KEYCODE_ESCAPE);
683 window->DispatchKeyEventCallback(keyEvent, isConsumed);
684 window->Destroy();
685 }
686
687
688 /**
689 * @tc.name: DispatchKeyEventCallback001
690 * @tc.desc: DispatchKeyEventCallback test
691 * @tc.type: FUNC
692 */
693 HWTEST_F(WindowSessionImplTest2, DispatchKeyEventCallback001, TestSize.Level1)
694 {
695 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
696 option->SetWindowName("DispatchKeyEventCallback001");
697 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
698 ASSERT_NE(window, nullptr);
699
700 bool isConsumed = false;
701 window->uiContent_ = nullptr;
702 std::shared_ptr<MockInputEventConsumer> inputEventConsumer = std::make_shared<MockInputEventConsumer>();
703 window->inputEventConsumer_ = inputEventConsumer;
704 ASSERT_NE(window->inputEventConsumer_, nullptr);
705
706 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
707 ASSERT_NE(keyEvent, nullptr);
708 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_ESCAPE);
709 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
710 window->DispatchKeyEventCallback(keyEvent, isConsumed);
711
712 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
713 window->DispatchKeyEventCallback(keyEvent, isConsumed);
714
715 isConsumed = false;
716 window->inputEventConsumer_ = nullptr;
717 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
718 ASSERT_NE(window->uiContent_, nullptr);
719
720 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
721 window->DispatchKeyEventCallback(keyEvent, isConsumed);
722 EXPECT_EQ(window->escKeyHasDown_, true);
723 EXPECT_EQ(window->escKeyEventTriggered_, false);
724
725 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
726 window->DispatchKeyEventCallback(keyEvent, isConsumed);
727 EXPECT_EQ(window->escKeyHasDown_, false);
728 EXPECT_EQ(window->escKeyEventTriggered_, false);
729 }
730
731 /**
732 * @tc.name: DispatchKeyEventCallback002
733 * @tc.desc: DispatchKeyEventCallback test
734 * @tc.type: FUNC
735 */
736 HWTEST_F(WindowSessionImplTest2, DispatchKeyEventCallback002, TestSize.Level1)
737 {
738 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
739 option->SetWindowName("DispatchKeyEventCallback002");
740 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
741 ASSERT_NE(window, nullptr);
742
743 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
744 ASSERT_NE(keyEvent, nullptr);
745 window->inputEventConsumer_ = nullptr;
746 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
747 ASSERT_NE(window->uiContent_, nullptr);
748
749 bool isConsumed = false;
750 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_ESCAPE);
751 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
752 window->escKeyEventTriggered_ = false;
753 window->escKeyHasDown_ = true;
754 window->DispatchKeyEventCallback(keyEvent, isConsumed);
755 EXPECT_EQ(window->escKeyHasDown_, false);
756 EXPECT_EQ(window->escKeyEventTriggered_, false);
757
758 window->escKeyEventTriggered_ = false;
759 window->escKeyHasDown_ = false;
760 window->DispatchKeyEventCallback(keyEvent, isConsumed);
761 EXPECT_EQ(window->escKeyHasDown_, false);
762 EXPECT_EQ(window->escKeyEventTriggered_, false);
763
764 window->escKeyEventTriggered_ = true;
765 window->escKeyHasDown_ = false;
766 window->DispatchKeyEventCallback(keyEvent, isConsumed);
767 EXPECT_EQ(window->escKeyHasDown_, false);
768 EXPECT_EQ(window->escKeyEventTriggered_, false);
769
770 window->escKeyEventTriggered_ = true;
771 window->escKeyHasDown_ = true;
772 window->DispatchKeyEventCallback(keyEvent, isConsumed);
773 EXPECT_EQ(window->escKeyHasDown_, false);
774 EXPECT_EQ(window->escKeyEventTriggered_, false);
775 }
776
777 /**
778 * @tc.name: DispatchKeyEventCallback003
779 * @tc.desc: DispatchKeyEventCallback test
780 * @tc.type: FUNC
781 */
782 HWTEST_F(WindowSessionImplTest2, DispatchKeyEventCallback003, TestSize.Level1)
783 {
784 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
785 option->SetWindowName("DispatchKeyEventCallback003");
786 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
787 ASSERT_NE(window, nullptr);
788
789 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
790 ASSERT_NE(keyEvent, nullptr);
791 window->inputEventConsumer_ = nullptr;
792 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
793 ASSERT_NE(window->uiContent_, nullptr);
794
795 bool isConsumed = false;
796 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_ESCAPE);
797 keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
798 window->escKeyEventTriggered_ = false;
799 window->escKeyHasDown_ = false;
800 window->DispatchKeyEventCallback(keyEvent, isConsumed);
801 EXPECT_EQ(window->escKeyHasDown_, true);
802 EXPECT_EQ(window->escKeyEventTriggered_, false);
803
804 window->escKeyEventTriggered_ = false;
805 window->escKeyHasDown_ = true;
806 window->DispatchKeyEventCallback(keyEvent, isConsumed);
807 EXPECT_EQ(window->escKeyHasDown_, true);
808 EXPECT_EQ(window->escKeyEventTriggered_, false);
809
810 window->escKeyEventTriggered_ = true;
811 window->escKeyHasDown_ = false;
812 window->DispatchKeyEventCallback(keyEvent, isConsumed);
813 EXPECT_EQ(window->escKeyHasDown_, true);
814 EXPECT_EQ(window->escKeyEventTriggered_, false);
815
816 window->escKeyEventTriggered_ = true;
817 window->escKeyHasDown_ = true;
818 window->DispatchKeyEventCallback(keyEvent, isConsumed);
819 EXPECT_EQ(window->escKeyHasDown_, true);
820 EXPECT_EQ(window->escKeyEventTriggered_, false);
821 }
822
823 /**
824 * @tc.name: HandleBackEvent01
825 * @tc.desc: HandleBackEvent
826 * @tc.type: FUNC
827 */
828 HWTEST_F(WindowSessionImplTest2, HandleBackEvent01, TestSize.Level0)
829 {
830 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
831 option->SetWindowName("HandleBackEvent01");
832 sptr<WindowSessionImpl> windowSession = sptr<WindowSessionImpl>::MakeSptr(option);
833
834 windowSession->uiContent_ = std::make_unique<Ace::UIContentMocker>();
835 ASSERT_EQ(WSError::WS_OK, windowSession->HandleBackEvent());
836 }
837
838 /**
839 * @tc.name: IsKeyboardEvent
840 * @tc.desc: IsKeyboardEvent
841 * @tc.type: FUNC
842 */
843 HWTEST_F(WindowSessionImplTest2, IsKeyboardEvent, TestSize.Level1)
844 {
845 auto window = GetTestWindowImpl("IsKeyboardEvent");
846 ASSERT_NE(window, nullptr);
847
848 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
849 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_VIRTUAL_MULTITASK);
850 ASSERT_FALSE(window->IsKeyboardEvent(keyEvent));
851
852 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_NUMPAD_RIGHT_PAREN);
853 ASSERT_TRUE(window->IsKeyboardEvent(keyEvent));
854
855 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
856 ASSERT_TRUE(window->IsKeyboardEvent(keyEvent));
857
858 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_FN);
859 ASSERT_TRUE(window->IsKeyboardEvent(keyEvent));
860
861 window->Destroy();
862 }
863
864 /**
865 * @tc.name: GetVSyncPeriod
866 * @tc.desc: GetVSyncPeriod
867 * @tc.type: FUNC
868 */
869 HWTEST_F(WindowSessionImplTest2, GetVSyncPeriod, TestSize.Level1)
870 {
871 auto window = GetTestWindowImpl("GetVSyncPeriod");
872 ASSERT_NE(window, nullptr);
873
874 auto vsyncStation = window->vsyncStation_;
875 if (vsyncStation == nullptr) {
876 vsyncStation = std::make_shared<VsyncStation>(DisplayId(0));
877 }
878 window->vsyncStation_ = nullptr;
879 ASSERT_EQ(window->GetVSyncPeriod(), 0);
880
881 window->vsyncStation_ = vsyncStation;
882 window->GetVSyncPeriod();
883 window->Destroy();
884 }
885
886 /**
887 * @tc.name: FlushFrameRate
888 * @tc.desc: FlushFrameRate
889 * @tc.type: FUNC
890 */
891 HWTEST_F(WindowSessionImplTest2, FlushFrameRate, TestSize.Level1)
892 {
893 auto window = GetTestWindowImpl("FlushFrameRate");
894 ASSERT_NE(window, nullptr);
895
896 auto vsyncStation = window->vsyncStation_;
897 if (vsyncStation == nullptr) {
898 vsyncStation = std::make_shared<VsyncStation>(DisplayId(0));
899 }
900 window->vsyncStation_ = nullptr;
901 window->FlushFrameRate(1, -1);
902
903 window->vsyncStation_ = vsyncStation;
904 window->FlushFrameRate(1, -1);
905 window->Destroy();
906 }
907
908 /**
909 * @tc.name: FindWindowById
910 * @tc.desc: FindWindowById
911 * @tc.type: FUNC
912 */
913 HWTEST_F(WindowSessionImplTest2, FindWindowById, TestSize.Level1)
914 {
915 auto window = GetTestWindowImpl("FindWindowById");
916 ASSERT_NE(window, nullptr);
917 window->windowSessionMap_.clear();
918 ASSERT_EQ(window->FindWindowById(0), nullptr);
919
920 window->windowSessionMap_.insert({ "test1", std::pair<int32_t, sptr<WindowSessionImpl>>(1, window) });
921 window->windowSessionMap_.insert({ "test2", std::pair<int32_t, sptr<WindowSessionImpl>>(2, window) });
922 ASSERT_EQ(window->FindWindowById(0), nullptr);
923
924 window->windowSessionMap_.insert({ "test0", std::pair<int32_t, sptr<WindowSessionImpl>>(0, window) });
925 ASSERT_NE(window->FindWindowById(0), nullptr);
926 window->Destroy();
927 }
928
929 /**
930 * @tc.name: SetLayoutFullScreenByApiVersion
931 * @tc.desc: SetLayoutFullScreenByApiVersion
932 * @tc.type: FUNC
933 */
934 HWTEST_F(WindowSessionImplTest2, SetLayoutFullScreenByApiVersion, TestSize.Level1)
935 {
936 auto window = GetTestWindowImpl("SetLayoutFullScreenByApiVersion");
937 ASSERT_NE(window, nullptr);
938 window->windowSessionMap_.clear();
939 ASSERT_EQ(window->SetLayoutFullScreenByApiVersion(true), WMError::WM_OK);
940 window->Destroy();
941 }
942
943 /**
944 * @tc.name: SetSystemBarProperty
945 * @tc.desc: SetSystemBarProperty
946 * @tc.type: FUNC
947 */
948 HWTEST_F(WindowSessionImplTest2, SetSystemBarProperty, TestSize.Level1)
949 {
950 auto window = GetTestWindowImpl("SetSystemBarProperty");
951 ASSERT_NE(window, nullptr);
952 window->windowSessionMap_.clear();
953 SystemBarProperty property;
954 ASSERT_EQ(window->SetSystemBarProperty(WindowType::APP_MAIN_WINDOW_END, property), WMError::WM_OK);
955 window->Destroy();
956 }
957
958 /**
959 * @tc.name: SetSpecificBarProperty
960 * @tc.desc: SetSpecificBarProperty
961 * @tc.type: FUNC
962 */
963 HWTEST_F(WindowSessionImplTest2, SetSpecificBarProperty, TestSize.Level0)
964 {
965 auto window = GetTestWindowImpl("SetSpecificBarProperty");
966 ASSERT_NE(window, nullptr);
967 window->windowSessionMap_.clear();
968 SystemBarProperty property;
969 ASSERT_EQ(window->SetSpecificBarProperty(WindowType::APP_MAIN_WINDOW_END, property), WMError::WM_OK);
970 window->Destroy();
971 }
972
973 /**
974 * @tc.name: NotifyOccupiedAreaChangeInfo
975 * @tc.desc: NotifyOccupiedAreaChangeInfo
976 * @tc.type: FUNC
977 */
978 HWTEST_F(WindowSessionImplTest2, NotifyOccupiedAreaChangeInfo, TestSize.Level1)
979 {
980 auto window = GetTestWindowImpl("NotifyOccupiedAreaChangeInfo");
981 ASSERT_NE(window, nullptr);
982
983 auto listeners = GetListenerList<IOccupiedAreaChangeListener, MockIOccupiedAreaChangeListener>();
984 ASSERT_NE(listeners.size(), 0);
985 listeners.insert(listeners.begin(), nullptr);
986 window->occupiedAreaChangeListeners_.insert({ window->GetPersistentId(), listeners });
987
988 sptr<OccupiedAreaChangeInfo> info = sptr<OccupiedAreaChangeInfo>::MakeSptr();
989 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
990 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
991 window->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
992
993 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
994 window->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
995
996 window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
997 window->windowSessionMap_.insert(
998 { "test1", std::pair<int32_t, sptr<WindowSessionImpl>>(window->GetPersistentId(), nullptr) });
999 window->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
1000 window->windowSessionMap_.clear();
1001
1002 window->windowSessionMap_.insert(
1003 { "test1", std::pair<int32_t, sptr<WindowSessionImpl>>(window->GetPersistentId(), window) });
1004 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1005 window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1006 window->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
1007
1008 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1009 window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1010 window->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
1011
1012 window->handler_ = nullptr;
1013 window->NotifyOccupiedAreaChangeInfo(info, nullptr, {}, {});
1014 window->Destroy();
1015 }
1016
1017 /**
1018 * @tc.name: NotifyOccupiedAreaChangeInfoInner
1019 * @tc.desc: NotifyOccupiedAreaChangeInfoInner
1020 * @tc.type: FUNC
1021 */
1022 HWTEST_F(WindowSessionImplTest2, NotifyOccupiedAreaChangeInfoInner, TestSize.Level1)
1023 {
1024 auto window = GetTestWindowImpl("NotifyOccupiedAreaChangeInfoInner");
1025 ASSERT_NE(window, nullptr);
1026
1027 auto listeners = GetListenerList<IOccupiedAreaChangeListener, MockIOccupiedAreaChangeListener>();
1028 ASSERT_NE(listeners.size(), 0);
1029 listeners.insert(listeners.begin(), nullptr);
1030 window->occupiedAreaChangeListeners_.insert({ window->GetPersistentId(), listeners });
1031
1032 window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1033 sptr<OccupiedAreaChangeInfo> info = sptr<OccupiedAreaChangeInfo>::MakeSptr();
1034 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1035 window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1036 window->NotifyOccupiedAreaChangeInfoInner(info);
1037
1038 window->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1039 window->NotifyOccupiedAreaChangeInfoInner(info);
1040
1041 window->windowSystemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
1042 window->windowSystemConfig_.freeMultiWindowEnable_ = false;
1043 window->NotifyOccupiedAreaChangeInfoInner(info);
1044
1045 window->windowSystemConfig_.freeMultiWindowEnable_ = true;
1046 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1047 window->NotifyOccupiedAreaChangeInfoInner(info);
1048
1049 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1050 window->NotifyOccupiedAreaChangeInfoInner(info);
1051
1052 window->Destroy();
1053 }
1054
1055 /**
1056 * @tc.name: NotifyWindowStatusChange
1057 * @tc.desc: NotifyWindowStatusChange
1058 * @tc.type: FUNC
1059 */
1060 HWTEST_F(WindowSessionImplTest2, NotifyWindowStatusChange, TestSize.Level1)
1061 {
1062 auto window = GetTestWindowImpl("NotifyWindowStatusChange");
1063 ASSERT_NE(window, nullptr);
1064
1065 auto listeners = GetListenerList<IWindowStatusChangeListener, MockWindowStatusChangeListener>();
1066 ASSERT_NE(listeners.size(), 0);
1067 listeners.insert(listeners.begin(), nullptr);
1068 window->windowStatusChangeListeners_.insert({ window->GetPersistentId(), listeners });
1069
1070 WindowMode mode = WindowMode::WINDOW_MODE_FLOATING;
1071 window->state_ = WindowState::STATE_HIDDEN;
1072 window->property_->SetMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR);
1073 window->NotifyWindowStatusChange(mode);
1074
1075 window->state_ = WindowState::STATE_FROZEN;
1076 window->property_->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
1077 window->NotifyWindowStatusChange(mode);
1078
1079 mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
1080 window->NotifyWindowStatusChange(mode);
1081
1082 mode = WindowMode::WINDOW_MODE_SPLIT_SECONDARY;
1083 window->NotifyWindowStatusChange(mode);
1084
1085 mode = WindowMode::WINDOW_MODE_PIP;
1086 window->NotifyWindowStatusChange(mode);
1087 ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1088 }
1089
1090 /**
1091 * @tc.name: NotifyWindowStatusChange02
1092 * @tc.desc: NotifyWindowStatusChange
1093 * @tc.type: FUNC
1094 */
1095 HWTEST_F(WindowSessionImplTest2, NotifyWindowStatusChange02, TestSize.Level1)
1096 {
1097 auto window = GetTestWindowImpl("NotifyWindowStatusChange02");
1098 ASSERT_NE(window, nullptr);
1099
1100 auto listeners = GetListenerList<IWindowStatusChangeListener, MockWindowStatusChangeListener>();
1101 EXPECT_NE(listeners.size(), 0);
1102 listeners.insert(listeners.begin(), nullptr);
1103 window->windowStatusChangeListeners_.insert({window->GetPersistentId(), listeners});
1104
1105 WindowMode mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
1106 window->state_ = WindowState::STATE_SHOWN;
1107 window->NotifyWindowStatusChange(mode);
1108 EXPECT_EQ(WindowStatus::WINDOW_STATUS_SPLITSCREEN, window->lastWindowStatus_);
1109
1110 window->NotifyWindowStatusChange(mode);
1111 EXPECT_EQ(WindowStatus::WINDOW_STATUS_SPLITSCREEN, window->lastWindowStatus_);
1112 EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1113 }
1114
1115 /**
1116 * @tc.name: UpdatePiPRect
1117 * @tc.desc: UpdatePiPRect
1118 * @tc.type: FUNC
1119 */
1120 HWTEST_F(WindowSessionImplTest2, UpdatePiPRect, TestSize.Level1)
1121 {
1122 auto window = GetTestWindowImpl("UpdatePiPRect");
1123 ASSERT_NE(window, nullptr);
1124
1125 window->property_->SetPersistentId(1);
1126 window->state_ = WindowState::STATE_FROZEN;
1127 Rect rect;
1128 window->UpdatePiPRect(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
1129
1130 window->hostSession_ = nullptr;
1131 window->UpdatePiPRect(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
1132 window->Destroy();
1133 }
1134
1135 /**
1136 * @tc.name: NotifyTransformChange
1137 * @tc.desc: NotifyTransformChange
1138 * @tc.type: FUNC
1139 */
1140 HWTEST_F(WindowSessionImplTest2, NotifyTransformChange, TestSize.Level1)
1141 {
1142 auto window = GetTestWindowImpl("NotifyTransformChange");
1143 ASSERT_NE(window, nullptr);
1144
1145 Transform transform;
1146 window->NotifyTransformChange(transform);
1147
1148 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1149 window->NotifyTransformChange(transform);
1150 window->Destroy();
1151 }
1152
1153 /**
1154 * @tc.name: SubmitNoInteractionMonitorTask
1155 * @tc.desc: SubmitNoInteractionMonitorTask
1156 * @tc.type: FUNC
1157 */
1158 HWTEST_F(WindowSessionImplTest2, SubmitNoInteractionMonitorTask, TestSize.Level1)
1159 {
1160 auto window = GetTestWindowImpl("SubmitNoInteractionMonitorTask");
1161 ASSERT_NE(window, nullptr);
1162
1163 IWindowNoInteractionListenerSptr listener = sptr<MockWindowNoInteractionListener>::MakeSptr();
1164 window->SubmitNoInteractionMonitorTask(window->lastInteractionEventId_.load() + 1, listener);
1165
1166 window->state_ = WindowState::STATE_SHOWN;
1167 window->SubmitNoInteractionMonitorTask(window->lastInteractionEventId_.load(), listener);
1168
1169 window->state_ = WindowState::STATE_FROZEN;
1170 window->SubmitNoInteractionMonitorTask(window->lastInteractionEventId_.load(), listener);
1171 window->Destroy();
1172 }
1173
1174 /**
1175 * @tc.name: RefreshNoInteractionTimeoutMonitor
1176 * @tc.desc: RefreshNoInteractionTimeoutMonitor
1177 * @tc.type: FUNC
1178 */
1179 HWTEST_F(WindowSessionImplTest2, RefreshNoInteractionTimeoutMonitor, TestSize.Level1)
1180 {
1181 auto window = GetTestWindowImpl("RefreshNoInteractionTimeoutMonitor");
1182 ASSERT_NE(window, nullptr);
1183 window->RefreshNoInteractionTimeoutMonitor();
1184 ASSERT_TRUE(window->windowNoInteractionListeners_[window->GetPersistentId()].empty());
1185 ASSERT_NE(window->property_, nullptr);
1186 window->property_->SetPersistentId(1);
1187 sptr<IWindowNoInteractionListener> listener = sptr<MockWindowNoInteractionListener>::MakeSptr();
1188 ASSERT_EQ(window->RegisterWindowNoInteractionListener(listener), WMError::WM_OK);
1189 window->RefreshNoInteractionTimeoutMonitor();
1190 ASSERT_EQ(window->GetPersistentId(), 1);
1191 ASSERT_FALSE(window->windowNoInteractionListeners_[window->GetPersistentId()].empty());
1192 window->Destroy();
1193 }
1194
1195 /**
1196 * @tc.name: IsUserOrientation
1197 * @tc.desc: IsUserOrientation
1198 * @tc.type: FUNC
1199 */
1200 HWTEST_F(WindowSessionImplTest2, IsUserOrientation, TestSize.Level1)
1201 {
1202 auto window = GetTestWindowImpl("IsUserOrientation");
1203 ASSERT_NE(window, nullptr);
1204
1205 ASSERT_FALSE(window->IsUserOrientation(Orientation::FOLLOW_DESKTOP));
1206 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_PORTRAIT));
1207 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_LANDSCAPE));
1208 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED));
1209 ASSERT_TRUE(window->IsUserOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED));
1210 window->Destroy();
1211 }
1212
1213 /**
1214 * @tc.name: WindowSessionCreateCheck
1215 * @tc.desc: WindowSessionCreateCheck
1216 * @tc.type: FUNC
1217 */
1218 HWTEST_F(WindowSessionImplTest2, WindowSessionCreateCheck, TestSize.Level1)
1219 {
1220 auto window = GetTestWindowImpl("WindowSessionCreateCheck");
1221 ASSERT_NE(window, nullptr);
1222
1223 int32_t nullWindowTestId = 1001;
1224 int32_t displayId = 1003;
1225 int32_t cameraId = 1004;
1226
1227 window->windowSessionMap_.clear();
1228 window->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
1229 window->windowSessionMap_.insert(std::make_pair<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>(
1230 "nullWindow", std::pair<int32_t, sptr<WindowSessionImpl>>(nullWindowTestId, nullptr)));
1231
1232 auto displayWindow = GetTestWindowImpl("displayWindow");
1233 ASSERT_NE(displayWindow, nullptr);
1234 displayWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_FREEZE_DISPLAY);
1235 window->windowSessionMap_.insert(std::make_pair<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>(
1236 "displayWindow", std::pair<int32_t, sptr<WindowSessionImpl>>(displayId, displayWindow)));
1237 ASSERT_EQ(window->WindowSessionCreateCheck(), WMError::WM_OK);
1238
1239 window->windowSessionMap_.clear();
1240 auto cameraWindow = GetTestWindowImpl("cameraWindow");
1241 ASSERT_NE(cameraWindow, nullptr);
1242 cameraWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
1243 window->windowSessionMap_.insert(std::make_pair<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>(
1244 "cameraWindow", std::pair<int32_t, sptr<WindowSessionImpl>>(cameraId, cameraWindow)));
1245 ASSERT_EQ(window->WindowSessionCreateCheck(), WMError::WM_ERROR_REPEAT_OPERATION);
1246 window->Destroy();
1247 displayWindow->Destroy();
1248 cameraWindow->Destroy();
1249 }
1250
1251 /**
1252 * @tc.name: NotifyForegroundInteractiveStatus
1253 * @tc.desc: NotifyForegroundInteractiveStatus
1254 * @tc.type: FUNC
1255 */
1256 HWTEST_F(WindowSessionImplTest2, NotifyForegroundInteractiveStatus, TestSize.Level1)
1257 {
1258 auto window = GetTestWindowImpl("NotifyForegroundInteractiveStatus");
1259 ASSERT_NE(window, nullptr);
1260
1261 window->property_->SetPersistentId(1);
1262 window->state_ = WindowState::STATE_SHOWN;
1263 window->NotifyForegroundInteractiveStatus(true);
1264 window->NotifyForegroundInteractiveStatus(false);
1265
1266 window->state_ = WindowState::STATE_DESTROYED;
1267 window->NotifyForegroundInteractiveStatus(true);
1268 window->state_ = WindowState::STATE_FROZEN;
1269 window->NotifyForegroundInteractiveStatus(true);
1270 window->Destroy();
1271 }
1272
1273 /**
1274 * @tc.name: UpdateDecorEnableToAce
1275 * @tc.desc: UpdateDecorEnableToAce
1276 * @tc.type: FUNC
1277 */
1278 HWTEST_F(WindowSessionImplTest2, UpdateDecorEnableToAce, TestSize.Level1)
1279 {
1280 auto window = GetTestWindowImpl("UpdateDecorEnableToAce");
1281 ASSERT_NE(window, nullptr);
1282 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1283 auto listeners = GetListenerList<IWindowChangeListener, MockWindowChangeListener>();
1284 sptr<MockWindowChangeListener> nullListener;
1285 listeners.insert(listeners.begin(), nullListener);
1286 window->windowChangeListeners_.insert({ window->GetPersistentId(), listeners });
1287 window->windowSystemConfig_.freeMultiWindowSupport_ = false;
1288 window->UpdateDecorEnableToAce(false);
1289
1290 window->uiContent_ = nullptr;
1291 window->UpdateDecorEnableToAce(false);
1292 EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy());
1293 }
1294
1295 /**
1296 * @tc.name: UpdateDecorEnable
1297 * @tc.desc: UpdateDecorEnable
1298 * @tc.type: FUNC
1299 */
1300 HWTEST_F(WindowSessionImplTest2, UpdateDecorEnable, TestSize.Level1)
1301 {
1302 auto window = GetTestWindowImpl("UpdateDecorEnable");
1303 ASSERT_NE(window, nullptr);
1304 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1305 window->windowSystemConfig_.freeMultiWindowSupport_ = true;
1306 window->UpdateDecorEnable(true, WindowMode::WINDOW_MODE_UNDEFINED);
1307
1308 window->windowSystemConfig_.freeMultiWindowSupport_ = false;
1309 window->UpdateDecorEnable(true, WindowMode::WINDOW_MODE_FULLSCREEN);
1310
1311 window->uiContent_ = nullptr;
1312 window->UpdateDecorEnable(true, WindowMode::WINDOW_MODE_FULLSCREEN);
1313 window->UpdateDecorEnable(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1314 window->Destroy();
1315 }
1316
1317 /**
1318 * @tc.name: NotifyModeChange
1319 * @tc.desc: NotifyModeChange
1320 * @tc.type: FUNC
1321 */
1322 HWTEST_F(WindowSessionImplTest2, NotifyModeChange, TestSize.Level1)
1323 {
1324 auto window = GetTestWindowImpl("NotifyModeChange");
1325 ASSERT_NE(window, nullptr);
1326 auto listeners = GetListenerList<IWindowChangeListener, MockWindowChangeListener>();
1327 sptr<MockWindowChangeListener> nullListener;
1328 listeners.insert(listeners.begin(), nullListener);
1329 window->windowChangeListeners_.insert({ window->GetPersistentId(), listeners });
1330
1331 window->NotifyModeChange(WindowMode::WINDOW_MODE_FULLSCREEN, true);
1332 window->Destroy();
1333 }
1334
1335 /**
1336 * @tc.name: GetContentInfo
1337 * @tc.desc: GetContentInfo
1338 * @tc.type: FUNC
1339 */
1340 HWTEST_F(WindowSessionImplTest2, GetContentInfo, TestSize.Level1)
1341 {
1342 auto window = GetTestWindowImpl("GetContentInfo");
1343 ASSERT_NE(window, nullptr);
1344
1345 ASSERT_EQ(window->GetContentInfo(BackupAndRestoreType::CONTINUATION), "");
1346 ASSERT_EQ(window->GetContentInfo(BackupAndRestoreType::APP_RECOVERY), "");
1347 ASSERT_EQ(window->GetContentInfo(BackupAndRestoreType::NONE), "");
1348 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1349 window->GetContentInfo(BackupAndRestoreType::NONE);
1350 window->Destroy();
1351 }
1352
1353 /**
1354 * @tc.name: SetDecorHeight
1355 * @tc.desc: SetDecorHeight
1356 * @tc.type: FUNC
1357 */
1358 HWTEST_F(WindowSessionImplTest2, SetDecorHeight, TestSize.Level1)
1359 {
1360 auto window = GetTestWindowImpl("SetDecorHeight");
1361 ASSERT_NE(window, nullptr);
1362 int32_t height = 50;
1363 EXPECT_EQ(window->SetDecorHeight(height), WMError::WM_ERROR_INVALID_WINDOW);
1364 window->property_->SetPersistentId(1);
1365 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1366 EXPECT_EQ(window->SetDecorHeight(height), WMError::WM_ERROR_NULLPTR);
1367
1368 window->property_->SetDisplayId(0);
1369 EXPECT_EQ(window->SetDecorHeight(height), WMError::WM_ERROR_NULLPTR);
1370 auto uiContent = std::make_unique<Ace::UIContentMocker>();
1371 window->uiContent_ = std::move(uiContent);
1372 EXPECT_EQ(window->SetDecorHeight(height), WMError::WM_OK);
1373 window->property_->SetDisplayId(-1);
1374 EXPECT_EQ(window->SetDecorHeight(height), WMError::WM_ERROR_NULLPTR);
1375 window->property_->SetDisplayId(0);
1376 EXPECT_EQ(window->SetDecorHeight(height), WMError::WM_OK);
1377 window->Destroy();
1378 }
1379
1380 /**
1381 * @tc.name: GetDecorHeight01
1382 * @tc.desc: GetDecorHeight
1383 * @tc.type: FUNC
1384 */
1385 HWTEST_F(WindowSessionImplTest2, GetDecorHeight01, TestSize.Level1)
1386 {
1387 auto window = GetTestWindowImpl("GetDecorHeight01");
1388 ASSERT_NE(window, nullptr);
1389 int32_t height = -1;
1390 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_ERROR_INVALID_WINDOW);
1391 window->property_->SetPersistentId(1);
1392 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1393 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_ERROR_NULLPTR);
1394
1395 auto uiContent = std::make_unique<Ace::UIContentMocker>();
1396 EXPECT_CALL(*uiContent, GetContainerModalTitleHeight()).WillRepeatedly(Return(-1));
1397 window->uiContent_ = std::move(uiContent);
1398 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_OK);
1399 window->Destroy();
1400 }
1401
1402 /**
1403 * @tc.name: GetDecorHeight02
1404 * @tc.desc: GetDecorHeight
1405 * @tc.type: FUNC
1406 */
1407 HWTEST_F(WindowSessionImplTest2, GetDecorHeight02, TestSize.Level1)
1408 {
1409 auto window = GetTestWindowImpl("GetDecorHeight02");
1410 ASSERT_NE(window, nullptr);
1411 int32_t height = -1;
1412 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_ERROR_INVALID_WINDOW);
1413 window->property_->SetPersistentId(1);
1414 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1415 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_ERROR_NULLPTR);
1416
1417 auto uiContent = std::make_unique<Ace::UIContentMocker>();
1418 EXPECT_CALL(*uiContent, GetContainerModalTitleHeight()).WillRepeatedly(Return(1));
1419 window->uiContent_ = std::move(uiContent);
1420 window->property_->SetDisplayId(-1);
1421 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_ERROR_NULLPTR);
1422 window->property_->SetDisplayId(0);
1423 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_OK);
1424 height = 1;
1425 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_OK);
1426 window->Destroy();
1427 }
1428
1429 /**
1430 * @tc.name: GetDecorHeight03
1431 * @tc.desc: GetDecorHeight version isolation test cases
1432 * @tc.type: FUNC
1433 */
1434 HWTEST_F(WindowSessionImplTest2, GetDecorHeight03, TestSize.Level1)
1435 {
1436 auto window = GetTestWindowImpl("GetDecorHeight03");
1437 ASSERT_NE(window, nullptr);
1438 window->property_->SetPersistentId(1);
1439 window->property_->SetDisplayId(0);
1440 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1441 window->useUniqueDensity_ = true;
1442 window->virtualPixelRatio_ = 1.9f;
1443 auto uiContent = std::make_unique<Ace::UIContentMocker>();
1444 EXPECT_CALL(*uiContent, GetContainerModalTitleHeight()).WillRepeatedly(Return(72));
1445 window->uiContent_ = std::move(uiContent);
1446 int32_t decorHeight = 38;
1447 window->SetDecorHeight(decorHeight);
1448 EXPECT_EQ(window->decorHeight_, decorHeight);
1449
1450 window->SetTargetAPIVersion(14);
1451 int32_t height = -1;
1452 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_OK);
1453 EXPECT_EQ(height, 37);
1454 window->SetTargetAPIVersion(18);
1455 EXPECT_EQ(window->GetDecorHeight(height), WMError::WM_OK);
1456 EXPECT_EQ(height, 37);
1457 window->Destroy();
1458 }
1459
1460 /**
1461 * @tc.name: GetTitleButtonArea01
1462 * @tc.desc: GetTitleButtonArea
1463 * @tc.type: FUNC
1464 */
1465 HWTEST_F(WindowSessionImplTest2, GetTitleButtonArea01, TestSize.Level1)
1466 {
1467 auto window = GetTestWindowImpl("GetTitleButtonArea01");
1468 ASSERT_NE(window, nullptr);
1469 TitleButtonRect titleButtonRect;
1470 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_ERROR_INVALID_WINDOW);
1471 window->property_->SetPersistentId(1);
1472 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1473
1474 window->uiContent_ = nullptr;
1475 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_ERROR_NULLPTR);
1476 auto uiContent = std::make_unique<Ace::UIContentMocker>();
1477 EXPECT_CALL(*uiContent, GetContainerModalButtonsRect(testing::_, testing::_)).WillRepeatedly(Return(false));
1478 window->uiContent_ = std::move(uiContent);
1479 ASSERT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_OK);
1480 window->Destroy();
1481 }
1482
1483 /**
1484 * @tc.name: GetTitleButtonArea02
1485 * @tc.desc: GetTitleButtonArea
1486 * @tc.type: FUNC
1487 */
1488 HWTEST_F(WindowSessionImplTest2, GetTitleButtonArea02, TestSize.Level1)
1489 {
1490 auto window = GetTestWindowImpl("GetTitleButtonArea02");
1491 ASSERT_NE(window, nullptr);
1492 TitleButtonRect titleButtonRect;
1493 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_ERROR_INVALID_WINDOW);
1494 window->property_->SetPersistentId(1);
1495 window->property_->SetDisplayId(0);
1496 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1497
1498 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_ERROR_NULLPTR);
1499 auto uiContent = std::make_unique<Ace::UIContentMocker>();
1500 EXPECT_CALL(*uiContent, GetContainerModalButtonsRect(testing::_, testing::_)).WillRepeatedly(Return(true));
1501 window->uiContent_ = std::move(uiContent);
1502 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_OK);
1503 window->property_->SetDisplayId(-1);
1504 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_ERROR_NULLPTR);
1505 window->property_->SetDisplayId(0);
1506 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_OK);
1507 window->Destroy();
1508 }
1509
1510 /**
1511 * @tc.name: GetTitleButtonArea03
1512 * @tc.desc: GetTitleButtonArea
1513 * @tc.type: FUNC
1514 */
1515 HWTEST_F(WindowSessionImplTest2, GetTitleButtonArea03, TestSize.Level1)
1516 {
1517 auto window = GetTestWindowImpl("GetTitleButtonArea03");
1518 ASSERT_NE(window, nullptr);
1519 TitleButtonRect titleButtonRect = { 1400, 0, 0, 0 };
1520 window->property_->SetPersistentId(1);
1521 window->property_->SetDisplayId(0);
1522 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1523 auto uiContent = std::make_unique<Ace::UIContentMocker>();
1524 EXPECT_CALL(*uiContent, GetContainerModalButtonsRect(testing::_, testing::_)).WillRepeatedly(Return(false));
1525 window->uiContent_ = std::move(uiContent);
1526 window->SetTargetAPIVersion(14);
1527 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_OK);
1528 EXPECT_EQ(titleButtonRect.IsUninitializedRect(), false);
1529
1530 window->SetTargetAPIVersion(15);
1531 EXPECT_EQ(window->GetTitleButtonArea(titleButtonRect), WMError::WM_OK);
1532 EXPECT_EQ(titleButtonRect.IsUninitializedRect(), true);
1533 window->Destroy();
1534 }
1535
1536 /**
1537 * @tc.name: RegisterWindowTitleButtonRectChangeListener
1538 * @tc.desc: RegisterWindowTitleButtonRectChangeListener
1539 * @tc.type: FUNC
1540 */
1541 HWTEST_F(WindowSessionImplTest2, RegisterWindowTitleButtonRectChangeListener, TestSize.Level1)
1542 {
1543 auto window = GetTestWindowImpl("RegisterWindowTitleButtonRectChangeListener");
1544 ASSERT_NE(window, nullptr);
1545 sptr<IWindowTitleButtonRectChangedListener> listener = nullptr;
1546 auto ret = window->RegisterWindowTitleButtonRectChangeListener(listener);
1547 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW);
1548 window->property_->SetPersistentId(1);
1549 window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1550 ret = window->RegisterWindowTitleButtonRectChangeListener(listener);
1551 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
1552 listener = sptr<MockWindowTitleButtonRectChangedListener>::MakeSptr();
1553 ret = window->RegisterWindowTitleButtonRectChangeListener(listener);
1554 EXPECT_EQ(ret, WMError::WM_OK);
1555 listener = sptr<MockWindowTitleButtonRectChangedListener>::MakeSptr();
1556 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1557 ret = window->RegisterWindowTitleButtonRectChangeListener(listener);
1558 EXPECT_EQ(ret, WMError::WM_OK);
1559 window->Destroy();
1560 }
1561
1562 /**
1563 * @tc.name: UnregisterWindowTitleButtonRectChangeListener
1564 * @tc.desc: UnregisterWindowTitleButtonRectChangeListener
1565 * @tc.type: FUNC
1566 */
1567 HWTEST_F(WindowSessionImplTest2, UnregisterWindowTitleButtonRectChangeListener, TestSize.Level1)
1568 {
1569 auto window = GetTestWindowImpl("UnregisterWindowTitleButtonRectChangeListener");
1570 ASSERT_NE(window, nullptr);
1571 sptr<IWindowTitleButtonRectChangedListener> listener = nullptr;
1572 auto ret = window->UnregisterWindowTitleButtonRectChangeListener(listener);
1573 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW);
1574 window->property_->SetPersistentId(1);
1575 ret = window->UnregisterWindowTitleButtonRectChangeListener(listener);
1576 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
1577 listener = sptr<MockWindowTitleButtonRectChangedListener>::MakeSptr();
1578 ret = window->UnregisterWindowTitleButtonRectChangeListener(listener);
1579 EXPECT_EQ(ret, WMError::WM_OK);
1580 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
1581 ret = window->UnregisterWindowTitleButtonRectChangeListener(listener);
1582 EXPECT_EQ(ret, WMError::WM_OK);
1583 window->Destroy();
1584 }
1585
1586 /**
1587 * @tc.name: NotifyWindowTitleButtonRectChange
1588 * @tc.desc: NotifyWindowTitleButtonRectChange
1589 * @tc.type: FUNC
1590 */
1591 HWTEST_F(WindowSessionImplTest2, NotifyWindowTitleButtonRectChange, TestSize.Level1)
1592 {
1593 auto window = GetTestWindowImpl("NotifyWindowTitleButtonRectChange");
1594 ASSERT_NE(window, nullptr);
1595 auto listeners = GetListenerList<IWindowTitleButtonRectChangedListener, MockWindowTitleButtonRectChangedListener>();
1596 listeners.insert(listeners.begin(), nullptr);
1597 window->windowTitleButtonRectChangeListeners_.insert({ window->GetPersistentId(), listeners });
1598 TitleButtonRect titleButtonRect;
1599 window->NotifyWindowTitleButtonRectChange(titleButtonRect);
1600 window->Destroy();
1601 }
1602
1603 /**
1604 * @tc.name: RegisterWindowRectChangeListener
1605 * @tc.desc: RegisterWindowRectChangeListener
1606 * @tc.type: FUNC
1607 */
1608 HWTEST_F(WindowSessionImplTest2, RegisterWindowRectChangeListener, TestSize.Level1)
1609 {
1610 auto window = GetTestWindowImpl("RegisterWindowRectChangeListener");
1611 ASSERT_NE(window, nullptr);
1612 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterWindowRectChangeListener(nullptr));
1613
1614 sptr<IWindowRectChangeListener> listener = sptr<MockWindowRectChangeListener>::MakeSptr();
1615 ASSERT_NE(listener, nullptr);
1616 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1617
1618 window->hostSession_ = nullptr;
1619 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1620 window->Destroy();
1621 }
1622
1623 /**
1624 * @tc.name: UnregisterWindowRectChangeListener
1625 * @tc.desc: UnregisterWindowRectChangeListener01
1626 * @tc.type: FUNC
1627 */
1628 HWTEST_F(WindowSessionImplTest2, UnregisterWindowRectChangeListener01, TestSize.Level1)
1629 {
1630 GTEST_LOG_(INFO) << "WindowSessionImplTest2: UnregisterWindowRectChangeListener01 start";
1631 auto window = GetTestWindowImpl("UnregisterWindowRectChangeListener01");
1632 ASSERT_NE(window, nullptr);
1633 window->hostSession_ = nullptr;
1634 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->RegisterWindowRectChangeListener(nullptr));
1635 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterWindowRectChangeListener(nullptr));
1636
1637 sptr<IWindowRectChangeListener> listener = sptr<MockWindowRectChangeListener>::MakeSptr();
1638 ASSERT_NE(listener, nullptr);
1639 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1640 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
1641
1642 SessionInfo sessionInfo = { "CreateTestBunble", "CreateTestModule", "CreateTestAbility" };
1643 sptr<SessionMocker> hostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
1644 window->hostSession_ = hostSession;
1645 ASSERT_EQ(WMError::WM_OK, window->RegisterWindowRectChangeListener(listener));
1646 ASSERT_EQ(WMError::WM_OK, window->UnregisterWindowRectChangeListener(listener));
1647 window->Destroy();
1648 GTEST_LOG_(INFO) << "WindowSessionImplTest2: UnregisterWindowRectChangeListener01 end";
1649 }
1650
1651 /**
1652 * @tc.name: GetVirtualPixelRatio
1653 * @tc.desc: GetVirtualPixelRatio
1654 * @tc.type: FUNC
1655 */
1656 HWTEST_F(WindowSessionImplTest2, GetVirtualPixelRatio, TestSize.Level1)
1657 {
1658 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetVirtualPixelRatio start";
1659 auto window = GetTestWindowImpl("GetVirtualPixelRatio");
1660 ASSERT_NE(nullptr, window);
1661 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
1662 float density = 2.0f;
1663 displayInfo->SetVirtualPixelRatio(density);
1664 float vpr = window->GetVirtualPixelRatio(displayInfo);
1665 ASSERT_EQ(density, vpr);
1666
1667 window->useUniqueDensity_ = true;
1668 vpr = window->GetVirtualPixelRatio(displayInfo);
1669 ASSERT_EQ(window->virtualPixelRatio_, vpr);
1670 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetVirtualPixelRatio end";
1671 }
1672
1673 /**
1674 * @tc.name: SetDragKeyFramePolicy
1675 * @tc.desc: SetDragKeyFramePolicy
1676 * @tc.type: FUNC
1677 */
1678 HWTEST_F(WindowSessionImplTest2, SetDragKeyFramePolicy, TestSize.Level1)
1679 {
1680 auto window = GetTestWindowImpl("SetDragKeyFramePolicy");
1681 ASSERT_NE(nullptr, window);
1682 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1683 sptr<SessionMocker> hostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
1684 window->hostSession_ = hostSession;
1685 KeyFramePolicy keyFramePolicy;
1686 ASSERT_EQ(window->SetDragKeyFramePolicy(keyFramePolicy), WMError::WM_OK);
1687 window->hostSession_ = nullptr;
1688 ASSERT_EQ(window->SetDragKeyFramePolicy(keyFramePolicy), WMError::WM_ERROR_NULLPTR);
1689 }
1690
1691 /**
1692 * @tc.name: NotifyScreenshot
1693 * @tc.desc: NotifyScreenshot01 listener==nullptr
1694 * @tc.type: FUNC
1695 */
1696 HWTEST_F(WindowSessionImplTest2, NotifyScreenshot01, TestSize.Level1)
1697 {
1698 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyScreenshot01 start";
1699 class MockIScrenshotListener : public IScreenshotListener {
1700 public:
1701 MOCK_METHOD0(OnScreenshot, void());
1702 };
1703 window_ = GetTestWindowImpl("NotifyScreenshot01");
1704 auto listeners = GetListenerList<IScreenshotListener, MockIScrenshotListener>();
1705 listeners[0] = nullptr;
1706 ASSERT_EQ(listeners.size(), 1);
1707 window_->screenshotListeners_.insert({ window_->GetPersistentId(), listeners });
1708 window_->NotifyScreenshot();
1709 std::vector<sptr<IScreenshotListener>> screenshotListeners =
1710 window_->screenshotListeners_[window_->GetPersistentId()];
1711 ASSERT_NE(std::find(screenshotListeners.begin(), screenshotListeners.end(), nullptr), screenshotListeners.end());
1712 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyScreenshot01 end";
1713 }
1714
1715 /**
1716 * @tc.name: NotifyScreenshot
1717 * @tc.desc: NotifyScreenshot02 listener!=nullptr
1718 * @tc.type: FUNC
1719 */
1720 HWTEST_F(WindowSessionImplTest2, NotifyScreenshot02, TestSize.Level1)
1721 {
1722 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyScreenshot02 start";
1723 class ScreenshotListener : public IScreenshotListener {
1724 public:
OnScreenshot()1725 void OnScreenshot()
1726 {
1727 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyScreenshot02 OnScreenshot";
1728 SUCCEED();
1729 }
1730 };
1731 window_ = GetTestWindowImpl("NotifyScreenshot02");
1732 sptr<IScreenshotListener> listener = new (std::nothrow) ScreenshotListener();
1733 window_->RegisterScreenshotListener(listener);
1734 window_->NotifyScreenshot();
1735 window_->UnregisterScreenshotListener(listener);
1736 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyScreenshot02 end";
1737 }
1738
1739 /**
1740 * @tc.name: NotifyTouchDialogTarget
1741 * @tc.desc: NotifyTouchDialogTarget01 hostSession_==nullptr
1742 * @tc.type: FUNC
1743 */
1744 HWTEST_F(WindowSessionImplTest2, NotifyTouchDialogTarget01, TestSize.Level1)
1745 {
1746 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget01 start";
1747 window_ = GetTestWindowImpl("NotifyTouchDialogTarget01");
1748 int32_t posX = 100;
1749 int32_t posY = 100;
1750 window_->hostSession_ = nullptr;
1751 window_->NotifyTouchDialogTarget(posX, posY);
1752 sptr<ISession> hostSession = window_->GetHostSession();
1753 ASSERT_EQ(nullptr, hostSession);
1754 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget01 end";
1755 }
1756
1757 /**
1758 * @tc.name: NotifyTouchDialogTarget
1759 * @tc.desc: NotifyTouchDialogTarget02 hostSession_!=nullptr
1760 * @tc.type: FUNC
1761 */
1762 HWTEST_F(WindowSessionImplTest2, NotifyTouchDialogTarget02, TestSize.Level1)
1763 {
1764 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget02 start";
1765 window_ = GetTestWindowImpl("NotifyTouchDialogTarget02");
1766 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
1767 sptr<SessionMocker> hostSession = sptr<SessionMocker>::MakeSptr(sessionInfo);
1768 window_->hostSession_ = hostSession;
1769 int32_t posX = 100;
1770 int32_t posY = 100;
1771 window_->NotifyTouchDialogTarget(posX, posY);
1772 sptr<ISession> hostSession1 = window_->GetHostSession();
1773 ASSERT_NE(nullptr, hostSession1);
1774 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget02 end";
1775 }
1776
1777 /**
1778 * @tc.name: NotifyTouchDialogTarget
1779 * @tc.desc: NotifyTouchDialogTarget03 hostSession_==nullptr listener==nullptr
1780 * @tc.type: FUNC
1781 */
1782 HWTEST_F(WindowSessionImplTest2, NotifyTouchDialogTarget03, TestSize.Level1)
1783 {
1784 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget03 start";
1785 class MockIDialogTargetTouchListener : public IDialogTargetTouchListener {
1786 public:
1787 MOCK_CONST_METHOD0(OnDialogTargetTouch, void());
1788 };
1789 window_ = GetTestWindowImpl("NotifyTouchDialogTarget03");
1790 window_->hostSession_ = nullptr;
1791 auto listeners = GetListenerList<IDialogTargetTouchListener, MockIDialogTargetTouchListener>();
1792 listeners[0] = nullptr;
1793 (window_->dialogTargetTouchListener_)[window_->GetPersistentId()] = listeners;
1794 int32_t posX = 100;
1795 int32_t posY = 100;
1796 window_->NotifyTouchDialogTarget(posX, posY);
1797 std::vector<sptr<IDialogTargetTouchListener>> dialogTargetTouchListeners =
1798 (window_->dialogTargetTouchListener_)[window_->GetPersistentId()];
1799 ASSERT_NE(std::find(dialogTargetTouchListeners.begin(), dialogTargetTouchListeners.end(), nullptr),
1800 dialogTargetTouchListeners.end());
1801 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget03 end";
1802 }
1803
1804 /**
1805 * @tc.name: NotifyTouchDialogTarget
1806 * @tc.desc: NotifyTouchDialogTarget04 hostSession_==nullptr listener!=nullptr
1807 * @tc.type: FUNC
1808 */
1809 HWTEST_F(WindowSessionImplTest2, NotifyTouchDialogTarget04, TestSize.Level1)
1810 {
1811 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget04 start";
1812 class MockIDialogTargetTouchListener : public IDialogTargetTouchListener {
1813 public:
OnDialogTargetTouch() const1814 void OnDialogTargetTouch() const
1815 {
1816 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget04 OnDialogTargetTouch";
1817 SUCCEED();
1818 }
1819 };
1820 window_ = GetTestWindowImpl("NotifyTouchDialogTarget04");
1821 window_->hostSession_ = nullptr;
1822 sptr<IDialogTargetTouchListener> dialogTargetTouchListener = new (std::nothrow) MockIDialogTargetTouchListener();
1823 window_->RegisterDialogTargetTouchListener(dialogTargetTouchListener);
1824 int32_t posX = 100;
1825 int32_t posY = 100;
1826 window_->NotifyTouchDialogTarget(posX, posY);
1827 window_->UnregisterDialogTargetTouchListener(dialogTargetTouchListener);
1828 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyTouchDialogTarget04 end";
1829 }
1830
1831 /**
1832 * @tc.name: NotifyDisplayMove
1833 * @tc.desc: NotifyDisplayMove01 listener==nullptr
1834 * @tc.type: FUNC
1835 */
1836 HWTEST_F(WindowSessionImplTest2, NotifyDisplayMove01, TestSize.Level1)
1837 {
1838 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDisplayMove01 start";
1839 class MockIDisplayMoveListener : public IDisplayMoveListener {
1840 public:
1841 MOCK_METHOD2(OnDisplayMove, void(DisplayId from, DisplayId to));
1842 };
1843 window_ = GetTestWindowImpl("NotifyDisplayMove01");
1844 auto listeners = GetListenerList<IDisplayMoveListener, MockIDisplayMoveListener>();
1845 listeners[0] = nullptr;
1846 (window_->displayMoveListeners_)[window_->GetPersistentId()] = listeners;
1847 int32_t posX = 100;
1848 int32_t posY = 100;
1849 window_->NotifyTouchDialogTarget(posX, posY);
1850 std::vector<sptr<IDisplayMoveListener>> displayMoveListeners =
1851 (window_->displayMoveListeners_)[window_->GetPersistentId()];
1852 ASSERT_NE(std::find(displayMoveListeners.begin(), displayMoveListeners.end(), nullptr), displayMoveListeners.end());
1853 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDisplayMove01 end";
1854 }
1855
1856 /**
1857 * @tc.name: NotifyDisplayMove
1858 * @tc.desc: NotifyDisplayMove02 listener!=nullptr
1859 * @tc.type: FUNC
1860 */
1861 HWTEST_F(WindowSessionImplTest2, NotifyDisplayMove02, TestSize.Level1)
1862 {
1863 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDisplayMove02 start";
1864 class MockIDisplayMoveListener : public IDisplayMoveListener {
1865 public:
OnDisplayMove(DisplayId from,DisplayId to)1866 void OnDisplayMove(DisplayId from, DisplayId to)
1867 {
1868 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDisplayMove02 OnDisplayMove";
1869 SUCCEED();
1870 }
1871 };
1872 window_ = GetTestWindowImpl("NotifyDisplayMove02");
1873 sptr<IDisplayMoveListener> displayMoveListener = sptr<MockIDisplayMoveListener>::MakeSptr();
1874 EXPECT_EQ(window_->RegisterDisplayMoveListener(displayMoveListener), WMError::WM_OK);
1875 int32_t posX = 100;
1876 int32_t posY = 100;
1877 window_->NotifyTouchDialogTarget(posX, posY);
1878 EXPECT_EQ(window_->UnregisterDisplayMoveListener(displayMoveListener), WMError::WM_OK);
1879 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDisplayMove02 end";
1880 }
1881
1882 /**
1883 * @tc.name: NotifyDestroy
1884 * @tc.desc: NotifyDestroy01 listener==nullptr
1885 * @tc.type: FUNC
1886 */
1887 HWTEST_F(WindowSessionImplTest2, NotifyDestroy01, TestSize.Level1)
1888 {
1889 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDestroy01 start";
1890 class MockIDialogDeathRecipientListener : public IDialogDeathRecipientListener {
1891 public:
1892 MOCK_CONST_METHOD0(OnDialogDeathRecipient, void());
1893 };
1894 window_ = GetTestWindowImpl("NotifyDestroy01");
1895 auto listeners = GetListenerList<IDialogDeathRecipientListener, MockIDialogDeathRecipientListener>();
1896 listeners[0] = nullptr;
1897 (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()] = listeners;
1898 window_->NotifyDestroy();
1899 std::vector<sptr<IDialogDeathRecipientListener>> dialogDeathRecipientListeners =
1900 (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()];
1901 ASSERT_NE(std::find(dialogDeathRecipientListeners.begin(), dialogDeathRecipientListeners.end(), nullptr),
1902 dialogDeathRecipientListeners.end());
1903 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDestroy01 end";
1904 }
1905
1906 /**
1907 * @tc.name: NotifyDestroy
1908 * @tc.desc: NotifyDestroy02 listener!=nullptr
1909 * @tc.type: FUNC
1910 */
1911 HWTEST_F(WindowSessionImplTest2, NotifyDestroy02, TestSize.Level1)
1912 {
1913 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDestroy02 start";
1914 class MockIDialogDeathRecipientListener : public IDialogDeathRecipientListener {
1915 public:
OnDialogDeathRecipient() const1916 void OnDialogDeathRecipient() const
1917 {
1918 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDestroy02 OnDialogDeathRecipient";
1919 SUCCEED();
1920 }
1921 };
1922 window_ = GetTestWindowImpl("NotifyDestroy02");
1923 sptr<IDialogDeathRecipientListener> listener = new (std::nothrow) MockIDialogDeathRecipientListener();
1924 window_->RegisterDialogDeathRecipientListener(listener);
1925 window_->NotifyDestroy();
1926 window_->UnregisterDialogDeathRecipientListener(listener);
1927 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDestroy02 end";
1928 }
1929
1930 /**
1931 * @tc.name: RegisterDialogTargetTouchListener
1932 * @tc.desc: RegisterDialogTargetTouchListener01 listener!=nullptr
1933 * @tc.type: FUNC
1934 */
1935 HWTEST_F(WindowSessionImplTest2, RegisterDialogTargetTouchListener01, TestSize.Level1)
1936 {
1937 GTEST_LOG_(INFO) << "WindowSessionImplTest2: RegisterDialogTargetTouchListener01 start";
1938 class MockIDialogTargetTouchListener : public IDialogTargetTouchListener {
1939 public:
OnDialogTargetTouch() const1940 void OnDialogTargetTouch() const {}
1941 };
1942 window_ = GetTestWindowImpl("RegisterDialogTargetTouchListener01");
1943 sptr<IDialogTargetTouchListener> listener = sptr<MockIDialogTargetTouchListener>::MakeSptr();
1944 WMError res = window_->RegisterDialogTargetTouchListener(listener);
1945 ASSERT_EQ(WMError::WM_OK, res);
1946 window_->UnregisterDialogTargetTouchListener(listener);
1947 GTEST_LOG_(INFO) << "WindowSessionImplTest2: RegisterDialogTargetTouchListener01 end";
1948 }
1949
1950 /**
1951 * @tc.name: RegisterDialogDeathRecipientListener
1952 * @tc.desc: RegisterDialogDeathRecipientListener01 listener!=nullptr
1953 * @tc.type: FUNC
1954 */
1955 HWTEST_F(WindowSessionImplTest2, RegisterDialogDeathRecipientListener01, TestSize.Level1)
1956 {
1957 GTEST_LOG_(INFO) << "WindowSessionImplTest2: RegisterDialogDeathRecipientListener01 start";
1958 class MockIDialogDeathRecipientListener : public IDialogDeathRecipientListener {
1959 public:
OnDialogDeathRecipient() const1960 void OnDialogDeathRecipient() const {}
1961 };
1962 window_ = GetTestWindowImpl("RegisterDialogDeathRecipientListener01");
1963 sptr<IDialogDeathRecipientListener> listener = sptr<MockIDialogDeathRecipientListener>::MakeSptr();
1964 int32_t count = (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()].size();
1965 window_->RegisterDialogDeathRecipientListener(listener);
1966 std::vector<sptr<IDialogDeathRecipientListener>> dialogDeathRecipientListeners =
1967 (window_->dialogDeathRecipientListeners_)[window_->GetPersistentId()];
1968 ASSERT_EQ(++count, dialogDeathRecipientListeners.size());
1969 window_->UnregisterDialogDeathRecipientListener(listener);
1970 GTEST_LOG_(INFO) << "WindowSessionImplTest2: RegisterDialogDeathRecipientListener01 end";
1971 }
1972
1973 /**
1974 * @tc.name: RegisterSubWindowCloseListeners
1975 * @tc.desc: RegisterSubWindowCloseListeners01
1976 * @tc.type: FUNC
1977 */
1978 HWTEST_F(WindowSessionImplTest2, RegisterSubWindowCloseListeners01, TestSize.Level1)
1979 {
1980 GTEST_LOG_(INFO) << "WindowSessionImplTest2: RegisterSubWindowCloseListeners01 start";
1981 class MockISubWindowCloseListener : public ISubWindowCloseListener {
1982 public:
OnSubWindowClose(bool & terminateCloseProcess)1983 void OnSubWindowClose(bool& terminateCloseProcess) {}
1984 };
1985 window_ = GetTestWindowImpl("RegisterSubWindowCloseListeners01");
1986 ASSERT_NE(window_, nullptr);
1987 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->RegisterSubWindowCloseListeners(nullptr));
1988 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window_->UnregisterSubWindowCloseListeners(nullptr));
1989
1990 sptr<ISubWindowCloseListener> listener = sptr<MockISubWindowCloseListener>::MakeSptr();
1991 window_->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1992 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window_->RegisterSubWindowCloseListeners(listener));
1993 ASSERT_EQ(WMError::WM_ERROR_INVALID_CALLING, window_->UnregisterSubWindowCloseListeners(listener));
1994
1995 window_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1996 ASSERT_EQ(WMError::WM_OK, window_->RegisterSubWindowCloseListeners(listener));
1997 ASSERT_EQ(WMError::WM_OK, window_->UnregisterSubWindowCloseListeners(listener));
1998 window_->Destroy();
1999 GTEST_LOG_(INFO) << "WindowSessionImplTest2: RegisterSubWindowCloseListeners01 end";
2000 }
2001
2002 /**
2003 * @tc.name: GetListeners
2004 * @tc.desc: GetListeners01 IWindowLifeCycle
2005 * @tc.type: FUNC
2006 */
2007 HWTEST_F(WindowSessionImplTest2, GetListeners01, TestSize.Level1)
2008 {
2009 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetListeners01 start";
2010 window_ = GetTestWindowImpl("GetListeners01");
2011 ASSERT_NE(window_, nullptr);
2012 window_->lifecycleListeners_.clear();
2013 window_->NotifyWindowAfterFocused();
2014 ASSERT_TRUE(window_->lifecycleListeners_[window_->GetPersistentId()].empty());
2015 sptr<IWindowLifeCycle> listener = sptr<MockWindowLifeCycleListener>::MakeSptr();
2016 window_->RegisterLifeCycleListener(listener);
2017 window_->NotifyWindowAfterFocused();
2018 ASSERT_FALSE(window_->lifecycleListeners_[window_->GetPersistentId()].empty());
2019 window_->Destroy();
2020 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetListeners01 end";
2021 }
2022
2023 /**
2024 * @tc.name: GetListeners
2025 * @tc.desc: GetListeners02 IOccupiedAreaChangeListener
2026 * @tc.type: FUNC
2027 */
2028 HWTEST_F(WindowSessionImplTest2, GetListeners02, TestSize.Level1)
2029 {
2030 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetListeners02 start";
2031 window_ = GetTestWindowImpl("GetListeners02");
2032 ASSERT_NE(window_, nullptr);
2033 window_->occupiedAreaChangeListeners_.clear();
2034 sptr<OccupiedAreaChangeInfo> occupiedAreaChangeInfo = sptr<OccupiedAreaChangeInfo>::MakeSptr();
2035 window_->NotifyOccupiedAreaChangeInfo(occupiedAreaChangeInfo, nullptr, {}, {});
2036 ASSERT_TRUE(window_->occupiedAreaChangeListeners_[window_->GetPersistentId()].empty());
2037 sptr<IOccupiedAreaChangeListener> listener = sptr<MockIOccupiedAreaChangeListener>::MakeSptr();
2038 window_->RegisterOccupiedAreaChangeListener(listener);
2039 window_->NotifyOccupiedAreaChangeInfo(occupiedAreaChangeInfo, nullptr, {}, {});
2040 ASSERT_FALSE(window_->occupiedAreaChangeListeners_[window_->GetPersistentId()].empty());
2041 window_->Destroy();
2042 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetListeners02 end";
2043 }
2044
2045 /**
2046 * @tc.name: GetListeners
2047 * @tc.desc: GetListeners03 IKeyboardDidShowListener IKeyboardDidHideListener
2048 * @tc.type: FUNC
2049 */
2050 HWTEST_F(WindowSessionImplTest2, GetListeners03, TestSize.Level1)
2051 {
2052 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetListeners03 start";
2053 window_ = GetTestWindowImpl("GetListeners03");
2054 ASSERT_NE(window_, nullptr);
2055 KeyboardPanelInfo keyboardPanelInfo;
2056 window_->NotifyKeyboardAnimationCompleted(keyboardPanelInfo);
2057 keyboardPanelInfo.isShowing_ = true;
2058 window_->NotifyKeyboardAnimationCompleted(keyboardPanelInfo);
2059 ASSERT_TRUE(window_->keyboardDidShowListeners_[window_->GetPersistentId()].empty());
2060 ASSERT_TRUE(window_->keyboardDidHideListeners_[window_->GetPersistentId()].empty());
2061 sptr<IKeyboardDidShowListener> listener = sptr<MockIKeyboardDidShowListener>::MakeSptr();
2062 window_->RegisterKeyboardDidShowListener(listener);
2063 keyboardPanelInfo.isShowing_ = true;
2064 window_->NotifyKeyboardAnimationCompleted(keyboardPanelInfo);
2065 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2066 window_->NotifyKeyboardAnimationCompleted(keyboardPanelInfo);
2067 ASSERT_FALSE(window_->keyboardDidShowListeners_[window_->GetPersistentId()].empty());
2068 window_->UnregisterKeyboardDidShowListener(listener);
2069
2070 sptr<IKeyboardDidHideListener> listener1 = sptr<MockIKeyboardDidHideListener>::MakeSptr();
2071 window_->RegisterKeyboardDidHideListener(listener1);
2072 keyboardPanelInfo.isShowing_ = false;
2073 window_->uiContent_ = nullptr;
2074 window_->NotifyKeyboardAnimationCompleted(keyboardPanelInfo);
2075 window_->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2076 window_->NotifyKeyboardAnimationCompleted(keyboardPanelInfo);
2077 ASSERT_FALSE(window_->keyboardDidHideListeners_[window_->GetPersistentId()].empty());
2078 window_->UnregisterKeyboardDidHideListener(listener1);
2079 window_->Destroy();
2080 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetListeners03 end";
2081 }
2082
2083 /**
2084 * @tc.name: GetUIContent
2085 * @tc.desc: GetUIContent
2086 * @tc.type: FUNC
2087 */
2088 HWTEST_F(WindowSessionImplTest2, GetUIContent, TestSize.Level1)
2089 {
2090 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2091 option->SetWindowName("GetUIContent");
2092 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2093 Ace::UIContent* res = window->GetUIContent();
2094 ASSERT_EQ(res, nullptr);
2095 ASSERT_EQ(window->Destroy(), WMError::WM_ERROR_INVALID_WINDOW);
2096 }
2097
2098 /**
2099 * @tc.name: NotifySizeChange
2100 * @tc.desc: NotifySizeChange
2101 * @tc.type: FUNC
2102 */
2103 HWTEST_F(WindowSessionImplTest2, NotifySizeChange, TestSize.Level1)
2104 {
2105 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2106 option->SetWindowName("NotifySizeChange");
2107 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2108 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2109 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2110 EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2111
2112 Rect rect;
2113 sptr<IWindowChangeListener> listener = sptr<MockWindowChangeListener>::MakeSptr();
2114 window->RegisterWindowChangeListener(listener);
2115 window->NotifySizeChange(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
2116
2117 sptr<IWindowRectChangeListener> listener1 = sptr<MockWindowRectChangeListener>::MakeSptr();
2118 window->RegisterWindowRectChangeListener(listener1);
2119 window->NotifySizeChange(rect, WindowSizeChangeReason::PIP_RATIO_CHANGE);
2120 window->Destroy(true);
2121 }
2122
2123 /**
2124 * @tc.name: NotifyUIExtHostWindowRectChangeListeners
2125 * @tc.desc: NotifyUIExtHostWindowRectChangeListeners test
2126 * @tc.type: FUNC
2127 */
2128 HWTEST_F(WindowSessionImplTest2, NotifyUIExtHostWindowRectChangeListeners, TestSize.Level1)
2129 {
2130 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2131 option->SetWindowName("NotifyUIExtHostWindowRectChangeListeners");
2132 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2133 SessionInfo sessionInfo;
2134 window->hostSession_ = sptr<SessionMocker>::MakeSptr(sessionInfo);
2135 window->property_->SetPersistentId(1);
2136 ASSERT_NE(0, window->GetPersistentId());
2137 window->uiContent_ = nullptr;
2138
2139 Rect rect;
2140 WindowSizeChangeReason reason = WindowSizeChangeReason::MOVE;
2141 window->NotifyUIExtHostWindowRectChangeListeners(rect, reason);
2142 window->uiContent_ = std::make_unique<Ace::UIContentMocker>();
2143 window->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
2144 ASSERT_TRUE(window->rectChangeUIExtListenerIds_.empty());
2145 window->NotifyUIExtHostWindowRectChangeListeners(rect, reason);
2146 window->rectChangeUIExtListenerIds_.emplace(111);
2147 window->NotifyUIExtHostWindowRectChangeListeners(rect, reason);
2148 }
2149
2150 /**
2151 * @tc.name: AvoidAreaChangeListener
2152 * @tc.desc: AvoidAreaChangeListener
2153 * @tc.type: FUNC
2154 */
2155 HWTEST_F(WindowSessionImplTest2, AvoidAreaChangeListener, TestSize.Level1)
2156 {
2157 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2158 option->SetWindowName("AvoidAreaChangeListener");
2159 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2160 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2161 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2162 EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2163
2164 sptr<IAvoidAreaChangedListener> nullListener = nullptr;
2165 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterAvoidAreaChangeListener(nullListener));
2166
2167 sptr<IAvoidAreaChangedListener> listener = sptr<MockAvoidAreaChangedListener>::MakeSptr();
2168 window->UnregisterAvoidAreaChangeListener(listener);
2169
2170 window->RegisterAvoidAreaChangeListener(nullListener);
2171 window->RegisterAvoidAreaChangeListener(listener);
2172
2173 sptr<IAvoidAreaChangedListener> listener1 = sptr<MockAvoidAreaChangedListener>::MakeSptr();
2174 window->RegisterAvoidAreaChangeListener(listener1);
2175
2176 window->UnregisterAvoidAreaChangeListener(listener);
2177 window->UnregisterAvoidAreaChangeListener(listener1);
2178 }
2179
2180 /**
2181 * @tc.name: RegisterScreenshotAppEventListener
2182 * @tc.desc: RegisterScreenshotAppEventListener01
2183 * @tc.type: FUNC
2184 */
2185 HWTEST_F(WindowSessionImplTest2, RegisterScreenshotAppEventListener01, TestSize.Level1)
2186 {
2187 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2188 option->SetWindowName("RegisterScreenshotAppEventListener");
2189
2190 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2191 sptr<IScreenshotAppEventListener> listener = nullptr;
2192 WMError ret = window->RegisterScreenshotAppEventListener(listener);
2193 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW);
2194
2195 window->property_->SetPersistentId(1);
2196 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2197 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2198 ASSERT_NE(nullptr, session);
2199 window->hostSession_ = session;
2200 ret = window->RegisterScreenshotAppEventListener(listener);
2201 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2202
2203 listener = sptr<IScreenshotAppEventListener>::MakeSptr();
2204 std::vector<sptr<IScreenshotAppEventListener>> holder;
2205 window->screenshotAppEventListeners_[window->property_->GetPersistentId()] = holder;
2206 ret = window->RegisterScreenshotAppEventListener(listener);
2207 EXPECT_EQ(ret, WMError::WM_OK);
2208 holder = window->screenshotAppEventListeners_[window->property_->GetPersistentId()];
2209 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2210 EXPECT_NE(existsListener, holder.end());
2211
2212 ret = window->RegisterScreenshotAppEventListener(listener);
2213 EXPECT_EQ(ret, WMError::WM_OK);
2214 holder = window->screenshotAppEventListeners_[window->property_->GetPersistentId()];
2215 EXPECT_EQ(holder.size(), 1);
2216 }
2217
2218 /**
2219 * @tc.name: unregisterScreenshotAppEventListener
2220 * @tc.desc: unregisterScreenshotAppEventListener01
2221 * @tc.type: FUNC
2222 */
2223 HWTEST_F(WindowSessionImplTest2, unregisterScreenshotAppEventListener01, TestSize.Level1)
2224 {
2225 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2226 option->SetWindowName("unregisterScreenshotAppEventListener");
2227
2228 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2229 sptr<IScreenshotAppEventListener> listener = nullptr;
2230 WMError ret = window->UnregisterScreenshotAppEventListener(listener);
2231 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW);
2232
2233 window->property_->SetPersistentId(1);
2234 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2235 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2236 ASSERT_NE(nullptr, session);
2237 window->hostSession_ = session;
2238 ret = window->RegisterScreenshotAppEventListener(listener);
2239 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2240
2241 listener = sptr<IScreenshotAppEventListener>::MakeSptr();
2242 std::vector<sptr<IScreenshotAppEventListener>> holder;
2243 window->screenshotAppEventListeners_[window->property_->GetPersistentId()] = holder;
2244 ret = window->UnregisterScreenshotAppEventListener(listener);
2245 EXPECT_EQ(ret, WMError::WM_OK);
2246
2247 holder = window->screenshotAppEventListeners_[window->property_->GetPersistentId()];
2248 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2249 EXPECT_EQ(existsListener, holder.end());
2250 }
2251
2252 /**
2253 * @tc.name: RegisterAcrossDisplaysChangeListener
2254 * @tc.desc: RegisterAcrossDisplaysChangeListener01
2255 * @tc.type: FUNC
2256 */
2257 HWTEST_F(WindowSessionImplTest2, RegisterAcrossDisplaysChangeListener01, TestSize.Level1)
2258 {
2259 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2260 option->SetWindowName("RegisterAcrossDisplaysChangeListener");
2261 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2262
2263 sptr<IAcrossDisplaysChangeListener> listener = nullptr;
2264 auto ret = window->RegisterAcrossDisplaysChangeListener(listener);
2265 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW);
2266
2267 window->property_->SetPersistentId(1);
2268 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2269 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2270 ASSERT_NE(nullptr, session);
2271 window->hostSession_ = session;
2272 ret = window->RegisterAcrossDisplaysChangeListener(listener);
2273 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2274
2275 listener = sptr<IAcrossDisplaysChangeListener>::MakeSptr();
2276 std::vector<sptr<IAcrossDisplaysChangeListener>> holder;
2277 window->acrossDisplaysChangeListeners_[window->property_->GetPersistentId()] = holder;
2278 ret = window->RegisterAcrossDisplaysChangeListener(listener);
2279 EXPECT_EQ(ret, WMError::WM_OK);
2280 holder = window->acrossDisplaysChangeListeners_[window->property_->GetPersistentId()];
2281 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2282 EXPECT_NE(existsListener, holder.end());
2283
2284 ret = window->RegisterAcrossDisplaysChangeListener(listener);
2285 EXPECT_EQ(ret, WMError::WM_OK);
2286 holder = window->acrossDisplaysChangeListeners_[window->property_->GetPersistentId()];
2287 EXPECT_EQ(holder.size(), 1);
2288 }
2289
2290 /**
2291 * @tc.name: UnRegisterAcrossDisplaysChangeListener
2292 * @tc.desc: UnRegisterAcrossDisplaysChangeListener01
2293 * @tc.type: FUNC
2294 */
2295 HWTEST_F(WindowSessionImplTest2, UnRegisterAcrossDisplaysChangeListener01, TestSize.Level1)
2296 {
2297 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2298 option->SetWindowName("UnRegisterAcrossDisplaysChangeListener01");
2299 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2300
2301 sptr<IAcrossDisplaysChangeListener> listener = nullptr;
2302 auto ret = window->UnRegisterAcrossDisplaysChangeListener(listener);
2303 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_WINDOW);
2304
2305 window->property_->SetPersistentId(1);
2306 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2307 sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
2308 ASSERT_NE(nullptr, session);
2309 window->hostSession_ = session;
2310 ret = window->UnRegisterAcrossDisplaysChangeListener(listener);
2311 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
2312
2313 listener = sptr<IAcrossDisplaysChangeListener>::MakeSptr();
2314 std::vector<sptr<IAcrossDisplaysChangeListener>> holder;
2315 window->acrossDisplaysChangeListeners_[window->property_->GetPersistentId()] = holder;
2316 ret = window->UnRegisterAcrossDisplaysChangeListener(listener);
2317 EXPECT_EQ(ret, WMError::WM_OK);
2318
2319 holder = window->acrossDisplaysChangeListeners_[window->property_->GetPersistentId()];
2320 auto existsListener = std::find(holder.begin(), holder.end(), listener);
2321 EXPECT_EQ(existsListener, holder.end());
2322 }
2323
2324 /**
2325 * @tc.name: NotifyScreenshotAppEvent
2326 * @tc.desc: NotifyScreenshotAppEvent IScreenshotAppEventListener
2327 * @tc.type: FUNC
2328 */
2329 HWTEST_F(WindowSessionImplTest2, NotifyScreenshotAppEvent, TestSize.Level1)
2330 {
2331 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2332 option->SetWindowName("unregisterScreenshotAppEventListener");
2333
2334 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2335 ASSERT_NE(window, nullptr);
2336 window->screenshotAppEventListeners_.clear();
2337 EXPECT_EQ(0, window->screenshotAppEventListeners_.size());
2338
2339 sptr<IScreenshotAppEventListener> listeners = sptr<IScreenshotAppEventListener>::MakeSptr();
2340 std::vector<sptr<IScreenshotAppEventListener>> holder;
2341 holder.push_back(listeners);
2342 window->screenshotAppEventListeners_[window->property_->GetPersistentId()] = holder;
2343 EXPECT_EQ(1, window->screenshotAppEventListeners_.size());
2344 auto ret = window->NotifyScreenshotAppEvent(ScreenshotEventType::SCROLL_SHOT_START);
2345 EXPECT_EQ(WSError::WS_OK, ret);
2346 }
2347
2348 /**
2349 * @tc.name: TouchOutsideListener
2350 * @tc.desc: TouchOutsideListener
2351 * @tc.type: FUNC
2352 */
2353 HWTEST_F(WindowSessionImplTest2, TouchOutsideListener, TestSize.Level1)
2354 {
2355 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2356 ASSERT_NE(option, nullptr);
2357 option->SetWindowName("TouchOutsideListener");
2358 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2359 ASSERT_NE(window, nullptr);
2360 SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
2361 sptr<SessionMocker> session = new (std::nothrow) SessionMocker(sessionInfo);
2362 ASSERT_NE(nullptr, session);
2363 EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session));
2364
2365 sptr<ITouchOutsideListener> nullListener = nullptr;
2366 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->UnregisterTouchOutsideListener(nullListener));
2367
2368 sptr<ITouchOutsideListener> listener = new (std::nothrow) MockTouchOutsideListener();
2369 ASSERT_NE(nullptr, listener);
2370 window->UnregisterTouchOutsideListener(listener);
2371
2372 window->RegisterTouchOutsideListener(nullListener);
2373 window->RegisterTouchOutsideListener(listener);
2374
2375 sptr<ITouchOutsideListener> listener1 = new (std::nothrow) MockTouchOutsideListener();
2376 ASSERT_NE(nullptr, listener1);
2377 window->RegisterTouchOutsideListener(listener1);
2378
2379 window->UnregisterTouchOutsideListener(listener);
2380 window->UnregisterTouchOutsideListener(listener1);
2381 }
2382
2383 /**
2384 * @tc.name: NotifyDialogStateChange
2385 * @tc.desc: NotifyDialogStateChange
2386 * @tc.type: FUNC
2387 */
2388 HWTEST_F(WindowSessionImplTest2, NotifyDialogStateChange, TestSize.Level1)
2389 {
2390 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDialogStateChange start";
2391 window_ = GetTestWindowImpl("NotifyDialogStateChange");
2392 ASSERT_NE(window_, nullptr);
2393 ASSERT_EQ(window_->NotifyDialogStateChange(true), WSError::WS_OK);
2394 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifyDialogStateChange end";
2395 }
2396
2397 /**
2398 * @tc.name: SwitchFreeMultiWindow
2399 * @tc.desc: SwitchFreeMultiWindow
2400 * @tc.type: FUNC
2401 */
2402 HWTEST_F(WindowSessionImplTest2, SwitchFreeMultiWindow, TestSize.Level1)
2403 {
2404 GTEST_LOG_(INFO) << "WindowSessionImplTest2: SwitchFreeMultiWindow start";
2405 window_ = GetTestWindowImpl("SwitchFreeMultiWindow");
2406 ASSERT_NE(window_, nullptr);
2407 ASSERT_EQ(window_->SwitchFreeMultiWindow(true), WSError::WS_OK);
2408 GTEST_LOG_(INFO) << "WindowSessionImplTest2: SwitchFreeMultiWindow end";
2409 }
2410
2411 /**
2412 * @tc.name: UpdateTitleInTargetPos
2413 * @tc.desc: UpdateTitleInTargetPos
2414 * @tc.type: FUNC
2415 */
2416 HWTEST_F(WindowSessionImplTest2, UpdateTitleInTargetPos, TestSize.Level1)
2417 {
2418 GTEST_LOG_(INFO) << "WindowSessionImplTest2: UpdateTitleInTargetPos start";
2419 window_ = GetTestWindowImpl("UpdateTitleInTargetPos");
2420 ASSERT_NE(window_, nullptr);
2421 ASSERT_EQ(window_->UpdateTitleInTargetPos(true, 100), WSError::WS_OK);
2422 GTEST_LOG_(INFO) << "WindowSessionImplTest2: UpdateTitleInTargetPos end";
2423 }
2424
2425 /**
2426 * @tc.name: NotifySessionBackground
2427 * @tc.desc: NotifySessionBackground
2428 * @tc.type: FUNC
2429 */
2430 HWTEST_F(WindowSessionImplTest2, NotifySessionBackground, TestSize.Level1)
2431 {
2432 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifySessionBackground start";
2433 window_ = GetTestWindowImpl("NotifySessionBackground");
2434 ASSERT_NE(window_, nullptr);
2435 window_->NotifySessionBackground(true, true, true);
2436 GTEST_LOG_(INFO) << "WindowSessionImplTest2: NotifySessionBackground end";
2437 }
2438
2439 /**
2440 * @tc.name: UpdateMaximizeMode
2441 * @tc.desc: UpdateMaximizeMode
2442 * @tc.type: FUNC
2443 */
2444 HWTEST_F(WindowSessionImplTest2, UpdateMaximizeMode, TestSize.Level1)
2445 {
2446 GTEST_LOG_(INFO) << "WindowSessionImplTest2: UpdateMaximizeMode start";
2447 window_ = GetTestWindowImpl("UpdateMaximizeMode");
2448 ASSERT_NE(window_, nullptr);
2449 ASSERT_EQ(window_->UpdateMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR), WSError::WS_OK);
2450 GTEST_LOG_(INFO) << "WindowSessionImplTest2: UpdateMaximizeMode end";
2451 }
2452
2453 /**
2454 * @tc.name: DumpSessionElementInfo
2455 * @tc.desc: DumpSessionElementInfo
2456 * @tc.type: FUNC
2457 */
2458 HWTEST_F(WindowSessionImplTest2, DumpSessionElementInfo, TestSize.Level1)
2459 {
2460 GTEST_LOG_(INFO) << "WindowSessionImplTest2: DumpSessionElementInfo start";
2461 window_ = GetTestWindowImpl("DumpSessionElementInfo");
2462 ASSERT_NE(window_, nullptr);
2463 std::vector<std::string> params;
2464 params.push_back("test");
2465 window_->DumpSessionElementInfo(params);
2466 GTEST_LOG_(INFO) << "WindowSessionImplTest2: DumpSessionElementInfo end";
2467 }
2468
2469 /**
2470 * @tc.name: GetKeyboardAnimationConfig
2471 * @tc.desc: GetKeyboardAnimationConfig
2472 * @tc.type: FUNC
2473 */
2474 HWTEST_F(WindowSessionImplTest2, GetKeyboardAnimationConfig, TestSize.Level1)
2475 {
2476 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetKeyboardAnimationConfig start";
2477 window_ = GetTestWindowImpl("GetKeyboardAnimationConfig");
2478 ASSERT_NE(window_, nullptr);
2479 window_->GetKeyboardAnimationConfig();
2480 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetKeyboardAnimationConfig end";
2481 }
2482
2483 /**
2484 * @tc.name: GetSubWindow
2485 * @tc.desc: GetSubWindow
2486 * @tc.type: FUNC
2487 */
2488 HWTEST_F(WindowSessionImplTest2, GetSubWindow, TestSize.Level1)
2489 {
2490 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetSubWindow start";
2491 window_ = GetTestWindowImpl("GetSubWindow");
2492 ASSERT_NE(window_, nullptr);
2493 ASSERT_TRUE(window_->subWindowSessionMap_.empty());
2494 std::vector<sptr<WindowSessionImpl>> vec;
2495 vec.push_back(window_);
2496 int32_t parentId = 111;
2497 window_->subWindowSessionMap_.insert(std::pair<int32_t, std::vector<sptr<WindowSessionImpl>>>(parentId, vec));
2498 std::vector<sptr<Window>> subWindows = window_->GetSubWindow(parentId);
2499 ASSERT_EQ(subWindows.size(), 1);
2500 GTEST_LOG_(INFO) << "WindowSessionImplTest2: GetSubWindow end";
2501 }
2502
2503 /**
2504 * @tc.name: SetRestoredRouterStack_0200
2505 * @tc.desc: basic function test of set or get restored router stack.
2506 * @tc.type: FUNC
2507 * @tc.require: issue
2508 */
2509 HWTEST_F(WindowSessionImplTest2, SetRestoredRouterStack_0200, TestSize.Level1)
2510 {
2511 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2512 ASSERT_NE(option, nullptr);
2513 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2514 ASSERT_NE(window, nullptr);
2515 std::string routerStack = "stackInfo:{}";
2516 EXPECT_EQ(window->SetRestoredRouterStack(routerStack), WMError::WM_OK);
2517 std::string gettedStack = window->GetRestoredRouterStack();
2518 EXPECT_EQ(gettedStack, routerStack);
2519 EXPECT_TRUE(window->GetRestoredRouterStack().empty());
2520 }
2521
2522 /**
2523 * @tc.name: SetUiDvsyncSwitch
2524 * @tc.desc: SetUiDvsyncSwitch
2525 * @tc.type: FUNC
2526 */
2527 HWTEST_F(WindowSessionImplTest2, SetUiDvsyncSwitch, TestSize.Level1)
2528 {
2529 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2530 ASSERT_NE(option, nullptr);
2531 option->SetWindowName("SetUiDvsyncSwitch");
2532 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2533 ASSERT_NE(window, nullptr);
2534 window->SetUiDvsyncSwitch(true);
2535 window->vsyncStation_ = nullptr;
2536 window->SetUiDvsyncSwitch(true);
2537 }
2538
2539 /**
2540 * @tc.name: SetUiDvsyncSwitchSucc
2541 * @tc.desc: SetUiDvsyncSwitch Test Succ
2542 * @tc.type: FUNC
2543 */
2544 HWTEST_F(WindowSessionImplTest2, SetUiDvsyncSwitchSucc, TestSize.Level1)
2545 {
2546 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2547 option->SetWindowName("SetUiDvsyncSwitchSucc");
2548 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2549 ASSERT_NE(window, nullptr);
2550 window->SetUiDvsyncSwitch(true);
2551 window->SetUiDvsyncSwitch(false);
2552 }
2553
2554 /**
2555 * @tc.name: SetUiDvsyncSwitchErr
2556 * @tc.desc: SetUiDvsyncSwitch Test Err
2557 * @tc.type: FUNC
2558 */
2559 HWTEST_F(WindowSessionImplTest2, SetUiDvsyncSwitchErr, TestSize.Level1)
2560 {
2561 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2562 option->SetWindowName("SetUiDvsyncSwitchErr");
2563 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2564 ASSERT_NE(window, nullptr);
2565 window->vsyncStation_ = nullptr;
2566 window->SetUiDvsyncSwitch(true);
2567 window->SetUiDvsyncSwitch(false);
2568 }
2569
2570 /**
2571 * @tc.name: SetTouchEvent
2572 * @tc.desc: SetTouchEvent
2573 * @tc.type: FUNC
2574 */
2575 HWTEST_F(WindowSessionImplTest2, SetTouchEvent, TestSize.Level1)
2576 {
2577 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2578 ASSERT_NE(option, nullptr);
2579 option->SetWindowName("SetTouchEvent");
2580 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2581 ASSERT_NE(window, nullptr);
2582 window->SetTouchEvent(0);
2583 window->vsyncStation_ = nullptr;
2584 window->SetTouchEvent(1);
2585 }
2586
2587 /**
2588 * @tc.name: SetTouchEventSucc
2589 * @tc.desc: SetTouchEvent Test Succ
2590 * @tc.type: FUNC
2591 */
2592 HWTEST_F(WindowSessionImplTest2, SetTouchEventSucc, TestSize.Level1)
2593 {
2594 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2595 option->SetWindowName("SetTouchEventSucc");
2596 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2597 ASSERT_NE(window, nullptr);
2598 window->SetTouchEvent(0);
2599 window->SetTouchEvent(1);
2600 }
2601
2602 /**
2603 * @tc.name: SetTouchEventErr
2604 * @tc.desc: SetTouchEvent Test Err
2605 * @tc.type: FUNC
2606 */
2607 HWTEST_F(WindowSessionImplTest2, SetTouchEventErr, TestSize.Level1)
2608 {
2609 sptr<WindowOption> option = new (std::nothrow) WindowOption();
2610 option->SetWindowName("SetTouchEventErr");
2611 sptr<WindowSessionImpl> window = new (std::nothrow) WindowSessionImpl(option);
2612 ASSERT_NE(window, nullptr);
2613 window->vsyncStation_ = nullptr;
2614 window->SetTouchEvent(0);
2615 window->SetTouchEvent(1);
2616 }
2617 /**
2618 * @tc.name: SetRestoredRouterStack_0100
2619 * @tc.desc: basic function test of set or get restored router stack.
2620 * @tc.type: FUNC
2621 * @tc.require: issue
2622 */
2623 HWTEST_F(WindowSessionImplTest2, SetRestoredRouterStack_0100, TestSize.Level1)
2624 {
2625 sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
2626 ASSERT_NE(option, nullptr);
2627 sptr<WindowSessionImpl> window = sptr<WindowSessionImpl>::MakeSptr(option);
2628 ASSERT_NE(window, nullptr);
2629 std::string routerStack = "stackInfo:{}";
2630 EXPECT_EQ(window->SetRestoredRouterStack(routerStack), WMError::WM_OK);
2631 EXPECT_EQ(window->NapiSetUIContent("info", (napi_env)nullptr, (napi_value)nullptr, BackupAndRestoreType::NONE,
2632 nullptr, nullptr), WMError::WM_ERROR_INVALID_WINDOW);
2633 }
2634
2635 /**
2636 * @tc.name: RegisterKeyboardWillShowListener
2637 * @tc.desc: RegisterKeyboardWillShowListener
2638 * @tc.type: FUNC
2639 * @tc.require: issue
2640 */
2641 HWTEST_F(WindowSessionImplTest2, RegisterKeyboardWillShowListener, TestSize.Level1)
2642 {
2643 window_ = GetTestWindowImpl("RegisterKeyboardWillShowListener");
2644 sptr<IKeyboardWillShowListener> listener = sptr<MockIKeyboardWillShowListener>::MakeSptr();
2645 auto status = window_->RegisterKeyboardWillShowListener(listener);
2646 EXPECT_EQ(status, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2647
2648 window_->windowSystemConfig_.supportFunctionType_ = SupportFunctionType::ALLOW_KEYBOARD_WILL_ANIMATION_NOTIFICATION;
2649 status = window_->RegisterKeyboardWillShowListener(listener);
2650 EXPECT_EQ(status, WMError::WM_OK);
2651 }
2652
2653 /**
2654 * @tc.name: UnregisterKeyboardWillShowListener
2655 * @tc.desc: UnregisterKeyboardWillShowListener
2656 * @tc.type: FUNC
2657 * @tc.require: issue
2658 */
2659 HWTEST_F(WindowSessionImplTest2, UnregisterKeyboardWillShowListener, TestSize.Level1)
2660 {
2661 window_ = GetTestWindowImpl("RegisterKeyboardWillShowListener");
2662 sptr<IKeyboardWillShowListener> listener = sptr<MockIKeyboardWillShowListener>::MakeSptr();
2663
2664 window_->windowSystemConfig_.supportFunctionType_ = SupportFunctionType::ALLOW_KEYBOARD_WILL_ANIMATION_NOTIFICATION;
2665 auto status = window_->RegisterKeyboardWillShowListener(listener);
2666 EXPECT_EQ(status, WMError::WM_OK);
2667
2668 EXPECT_EQ(window_->UnregisterKeyboardWillShowListener(listener), WMError::WM_OK);
2669 }
2670
2671 /**
2672 * @tc.name: RegisterKeyboardWillHideListener
2673 * @tc.desc: RegisterKeyboardWillHideListener
2674 * @tc.type: FUNC
2675 * @tc.require: issue
2676 */
2677 HWTEST_F(WindowSessionImplTest2, RegisterKeyboardWillHideListener, TestSize.Level1)
2678 {
2679 window_ = GetTestWindowImpl("RegisterKeyboardWillHideListener");
2680 sptr<IKeyboardWillHideListener> listener = sptr<MockIKeyboardWillHideListener>::MakeSptr();
2681 auto status = window_->RegisterKeyboardWillHideListener(listener);
2682 EXPECT_EQ(status, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2683
2684 window_->windowSystemConfig_.supportFunctionType_ = SupportFunctionType::ALLOW_KEYBOARD_WILL_ANIMATION_NOTIFICATION;
2685 status = window_->RegisterKeyboardWillHideListener(listener);
2686 EXPECT_EQ(status, WMError::WM_OK);
2687 }
2688
2689 /**
2690 * @tc.name: UnregisterKeyboardWillHideListener
2691 * @tc.desc: UnregisterKeyboardWillHideListener
2692 * @tc.type: FUNC
2693 * @tc.require: issue
2694 */
2695 HWTEST_F(WindowSessionImplTest2, UnregisterKeyboardWillHideListener, TestSize.Level1)
2696 {
2697 window_ = GetTestWindowImpl("RegisterKeyboardWillHideListener");
2698 sptr<IKeyboardWillHideListener> listener = sptr<MockIKeyboardWillHideListener>::MakeSptr();
2699 window_->windowSystemConfig_.supportFunctionType_ = SupportFunctionType::ALLOW_KEYBOARD_WILL_ANIMATION_NOTIFICATION;
2700 auto status = window_->RegisterKeyboardWillHideListener(listener);
2701 EXPECT_EQ(status, WMError::WM_OK);
2702
2703 EXPECT_EQ(window_->UnregisterKeyboardWillHideListener(listener), WMError::WM_OK);
2704 }
2705
2706 /**
2707 * @tc.name: NotifyKeyboardAnimationWillBegin
2708 * @tc.desc: NotifyKeyboardAnimationWillBegin
2709 * @tc.type: FUNC
2710 * @tc.require: issue
2711 */
2712 HWTEST_F(WindowSessionImplTest2, NotifyKeyboardAnimationWillBegin, TestSize.Level1)
2713 {
2714 logMsg.clear();
2715 LOG_SetCallback(MyLogCallback);
2716 window_ = GetTestWindowImpl("RegisterKeyboardWillHideListener");
2717 window_->windowSystemConfig_.supportFunctionType_ = SupportFunctionType::ALLOW_KEYBOARD_WILL_ANIMATION_NOTIFICATION;
2718 sptr<IKeyboardWillShowListener> listener = sptr<MockIKeyboardWillShowListener>::MakeSptr();
2719 window_->RegisterKeyboardWillShowListener(listener);
2720 sptr<IKeyboardWillHideListener> listener1 = sptr<MockIKeyboardWillHideListener>::MakeSptr();
2721 window_->RegisterKeyboardWillHideListener(listener1);
2722
2723 KeyboardAnimationInfo animationInfo;
2724 const std::shared_ptr<RSTransaction>& rsTransaction = std::make_shared<RSTransaction>();
2725 window_->NotifyKeyboardAnimationWillBegin(animationInfo, nullptr);
2726 animationInfo.isShow = true;
2727 window_->NotifyKeyboardAnimationWillBegin(animationInfo, rsTransaction);
2728 animationInfo.isShow = false;
2729 window_->NotifyKeyboardAnimationWillBegin(animationInfo, rsTransaction);
2730
2731 EXPECT_TRUE(logMsg.find("handler is nullptr") == std::string::npos);
2732 }
2733 } // namespace
2734 } // namespace Rosen
2735 } // namespace OHOS
2736