1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <regex>
18 #include <pointer_event.h>
19 #include <ui/rs_surface_node.h>
20
21 #include "mock/mock_session_stage.h"
22 #include "mock/mock_window_event_channel.h"
23 #include "mock/mock_pattern_detach_callback.h"
24 #include "session/host/include/extension_session.h"
25 #include "session/host/include/move_drag_controller.h"
26 #include "session/host/include/scene_session.h"
27 #include "session_manager/include/scene_session_manager.h"
28 #include "session/host/include/session.h"
29 #include "session_info.h"
30 #include "process_options.h"
31 #include "key_event.h"
32 #include "wm_common.h"
33 #include "window_manager_hilog.h"
34 #include "accessibility_event_info.h"
35
36 using namespace testing;
37 using namespace testing::ext;
38
39 namespace OHOS {
40 namespace Rosen {
41 namespace {
42 const std::string UNDEFINED = "undefined";
43 std::string g_logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)44 void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
45 const char *msg)
46 {
47 g_logMsg += msg;
48 }
49 }
50
51 class WindowSessionTest2 : public testing::Test {
52 public:
53 static void SetUpTestCase();
54 static void TearDownTestCase();
55 void SetUp() override;
56 void TearDown() override;
57
58 sptr<SceneSessionManager> ssm_;
59
60 private:
61 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
62 sptr<Session> session_ = nullptr;
63 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
64
65 class TLifecycleListener : public ILifecycleListener {
66 public:
~TLifecycleListener()67 virtual ~TLifecycleListener() {}
OnActivation()68 void OnActivation() override {}
OnConnect()69 void OnConnect() override {}
OnForeground()70 void OnForeground() override {}
OnBackground()71 void OnBackground() override {}
OnDisconnect()72 void OnDisconnect() override {}
OnExtensionDied()73 void OnExtensionDied() override {}
OnExtensionTimeout(int32_t errorCode)74 void OnExtensionTimeout(int32_t errorCode) override {}
OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)75 void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
76 int64_t uiExtensionIdLevel) override
77 {
78 }
OnDrawingCompleted()79 void OnDrawingCompleted() override {}
OnAppRemoveStartingWindow()80 void OnAppRemoveStartingWindow() override {}
81 };
82 std::shared_ptr<TLifecycleListener> lifecycleListener_ = std::make_shared<TLifecycleListener>();
83
84 sptr<SessionStageMocker> mockSessionStage_ = nullptr;
85 sptr<WindowEventChannelMocker> mockEventChannel_ = nullptr;
86 };
87
SetUpTestCase()88 void WindowSessionTest2::SetUpTestCase() {}
89
TearDownTestCase()90 void WindowSessionTest2::TearDownTestCase() {}
91
SetUp()92 void WindowSessionTest2::SetUp()
93 {
94 SessionInfo info;
95 info.abilityName_ = "testSession1";
96 info.moduleName_ = "testSession2";
97 info.bundleName_ = "testSession3";
98 session_ = sptr<Session>::MakeSptr(info);
99 session_->surfaceNode_ = CreateRSSurfaceNode();
100 EXPECT_NE(nullptr, session_);
101 ssm_ = sptr<SceneSessionManager>::MakeSptr();
102 session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
103 auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); };
104 session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
105
106 mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
107 ASSERT_NE(mockSessionStage_, nullptr);
108
109 mockEventChannel_ = sptr<WindowEventChannelMocker>::MakeSptr(mockSessionStage_);
110 ASSERT_NE(mockEventChannel_, nullptr);
111 }
112
TearDown()113 void WindowSessionTest2::TearDown()
114 {
115 session_ = nullptr;
116 usleep(WAIT_SYNC_IN_NS);
117 }
118
CreateRSSurfaceNode()119 RSSurfaceNode::SharedPtr WindowSessionTest2::CreateRSSurfaceNode()
120 {
121 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
122 rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTest2SurfaceNode";
123 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
124 if (surfaceNode == nullptr) {
125 GTEST_LOG_(INFO) << "WindowSessionTest2::CreateRSSurfaceNode surfaceNode is nullptr";
126 }
127 return surfaceNode;
128 }
129
130 namespace {
131 /**
132 * @tc.name: SetParentSession
133 * @tc.desc: SetParentSession Test
134 * @tc.type: FUNC
135 */
136 HWTEST_F(WindowSessionTest2, SetParentSession, TestSize.Level1)
137 {
138 ASSERT_NE(session_, nullptr);
139 SessionInfo info;
140 info.abilityName_ = "testSession1";
141 info.moduleName_ = "testSession2";
142 info.bundleName_ = "testSession3";
143 sptr<Session> session = sptr<Session>::MakeSptr(info);
144 session_->SetParentSession(session);
145
146 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
147 }
148
149 /**
150 * @tc.name: TransferPointerEvent01
151 * @tc.desc: !IsSystemSession() && !IsSessionValid() is true
152 * @tc.type: FUNC
153 */
154 HWTEST_F(WindowSessionTest2, TransferPointerEvent01, TestSize.Level1)
155 {
156 ASSERT_NE(session_, nullptr);
157
158 session_->sessionInfo_.isSystem_ = false;
159 session_->state_ = SessionState::STATE_DISCONNECT;
160
161 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
162 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->TransferPointerEvent(pointerEvent));
163 }
164
165 /**
166 * @tc.name: TransferPointerEvent02
167 * @tc.desc: pointerEvent is nullptr
168 * @tc.type: FUNC
169 */
170 HWTEST_F(WindowSessionTest2, TransferPointerEvent02, TestSize.Level1)
171 {
172 ASSERT_NE(session_, nullptr);
173 session_->sessionInfo_.isSystem_ = true;
174
175 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
176 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
177 }
178
179 /**
180 * @tc.name: TransferPointerEvent03
181 * @tc.desc: WindowType is WINDOW_TYPE_APP_MAIN_WINDOW, CheckDialogOnForeground() is true
182 * @tc.type: FUNC
183 */
184 HWTEST_F(WindowSessionTest2, TransferPointerEvent03, TestSize.Level1)
185 {
186 ASSERT_NE(session_, nullptr);
187
188 session_->sessionInfo_.isSystem_ = true;
189
190 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
191 ASSERT_NE(pointerEvent, nullptr);
192 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
193
194 SessionInfo info;
195 info.abilityName_ = "dialogAbilityName";
196 info.moduleName_ = "dialogModuleName";
197 info.bundleName_ = "dialogBundleName";
198 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
199 ASSERT_NE(dialogSession, nullptr);
200 dialogSession->state_ = SessionState::STATE_ACTIVE;
201 session_->dialogVec_.push_back(dialogSession);
202
203 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
204 }
205
206 /**
207 * @tc.name: TransferPointerEvent04
208 * @tc.desc: parentSession_ && parentSession_->CheckDialogOnForeground() is true
209 * @tc.type: FUNC
210 */
211 HWTEST_F(WindowSessionTest2, TransferPointerEvent04, TestSize.Level1)
212 {
213 ASSERT_NE(session_, nullptr);
214
215 session_->sessionInfo_.isSystem_ = true;
216
217 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
218 ASSERT_NE(pointerEvent, nullptr);
219
220 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
221
222 SessionInfo info;
223 info.abilityName_ = "dialogAbilityName";
224 info.moduleName_ = "dialogModuleName";
225 info.bundleName_ = "dialogBundleName";
226 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
227 ASSERT_NE(dialogSession, nullptr);
228 dialogSession->state_ = SessionState::STATE_ACTIVE;
229 session_->dialogVec_.push_back(dialogSession);
230 session_->parentSession_ = session_;
231
232 ASSERT_EQ(WSError::WS_ERROR_INVALID_PERMISSION, session_->TransferPointerEvent(pointerEvent));
233 }
234
235 /**
236 * @tc.name: TransferPointerEvent05
237 * @tc.desc: windowEventChannel_ is nullptr
238 * @tc.type: FUNC
239 */
240 HWTEST_F(WindowSessionTest2, TransferPointerEvent05, TestSize.Level1)
241 {
242 ASSERT_NE(session_, nullptr);
243
244 session_->sessionInfo_.isSystem_ = true;
245
246 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
247
248 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
249
250 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
251 }
252
253 /**
254 * @tc.name: TransferPointerEvent06
255 * @tc.desc: windowEventChannel_ is not nullptr
256 * @tc.type: FUNC
257 */
258 HWTEST_F(WindowSessionTest2, TransferPointerEvent06, TestSize.Level1)
259 {
260 ASSERT_NE(session_, nullptr);
261
262 session_->sessionInfo_.isSystem_ = true;
263
264 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
265 ASSERT_NE(pointerEvent, nullptr);
266
267 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
268 session_->windowEventChannel_ = mockEventChannel_;
269
270 auto needNotifyClient = true;
271 session_->TransferPointerEvent(pointerEvent, needNotifyClient);
272
273 needNotifyClient = false;
274 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
275 ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
276
277 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
278 ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
279
280 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
281 ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
282
283 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
284 ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
285
286 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW);
287 ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
288
289 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW);
290 ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
291 }
292
293 /**
294 * @tc.name: TransferPointerEvent07
295 * @tc.desc: isExecuteDelayRaise is true
296 * @tc.type: FUNC
297 */
298 HWTEST_F(WindowSessionTest2, TransferPointerEvent07, TestSize.Level1)
299 {
300 ASSERT_NE(session_, nullptr);
301 session_->sessionInfo_.isSystem_ = true;
302 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
303 session_->windowEventChannel_ = mockEventChannel_;
304
305 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
306 ASSERT_NE(pointerEvent, nullptr);
307 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_UP);
308 session_->UpdateFocus(false);
309 session_->property_->SetFocusable(true);
310 bool needNotifyClient = true;
311 bool isExecuteDelayRaise = true;
312 ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient, isExecuteDelayRaise));
313 }
314
315 /**
316 * @tc.name: TransferKeyEvent01
317 * @tc.desc: !IsSystemSession() && !IsSessionValid() is true
318 * @tc.type: FUNC
319 */
320 HWTEST_F(WindowSessionTest2, TransferKeyEvent01, TestSize.Level1)
321 {
322 ASSERT_NE(session_, nullptr);
323
324 session_->sessionInfo_.isSystem_ = false;
325 session_->state_ = SessionState::STATE_DISCONNECT;
326
327 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
328 ASSERT_NE(keyEvent, nullptr);
329 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
330
331 session_->windowEventChannel_ = mockEventChannel_;
332 ASSERT_EQ(WSError::WS_OK, session_->TransferKeyEvent(keyEvent));
333 }
334
335 /**
336 * @tc.name: TransferKeyEvent02
337 * @tc.desc: keyEvent is nullptr
338 * @tc.type: FUNC
339 */
340 HWTEST_F(WindowSessionTest2, TransferKeyEvent02, TestSize.Level1)
341 {
342 ASSERT_NE(session_, nullptr);
343
344 session_->sessionInfo_.isSystem_ = true;
345
346 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
347 ASSERT_NE(keyEvent, nullptr);
348 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
349 }
350
351 /**
352 * @tc.name: TransferKeyEvent03
353 * @tc.desc: WindowType is WINDOW_TYPE_APP_MAIN_WINDOW, CheckDialogOnForeground() is true
354 * @tc.type: FUNC
355 */
356 HWTEST_F(WindowSessionTest2, TransferKeyEvent03, TestSize.Level1)
357 {
358 ASSERT_NE(session_, nullptr);
359
360 session_->sessionInfo_.isSystem_ = true;
361
362 auto keyEvent = MMI::KeyEvent::Create();
363 ASSERT_NE(keyEvent, nullptr);
364
365 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
366
367 SessionInfo info;
368 info.abilityName_ = "dialogAbilityName";
369 info.moduleName_ = "dialogModuleName";
370 info.bundleName_ = "dialogBundleName";
371 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
372 ASSERT_NE(dialogSession, nullptr);
373 dialogSession->state_ = SessionState::STATE_ACTIVE;
374 session_->dialogVec_.push_back(dialogSession);
375
376 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
377 }
378
379 /**
380 * @tc.name: TransferKeyEvent04
381 * @tc.desc: parentSession_ && parentSession_->CheckDialogOnForeground() is true
382 * @tc.type: FUNC
383 */
384 HWTEST_F(WindowSessionTest2, TransferKeyEvent04, TestSize.Level1)
385 {
386 ASSERT_NE(session_, nullptr);
387
388 session_->sessionInfo_.isSystem_ = true;
389
390 auto keyEvent = MMI::KeyEvent::Create();
391 ASSERT_NE(keyEvent, nullptr);
392
393 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
394
395 SessionInfo info;
396 info.abilityName_ = "dialogAbilityName";
397 info.moduleName_ = "dialogModuleName";
398 info.bundleName_ = "dialogBundleName";
399 sptr<Session> dialogSession = sptr<Session>::MakeSptr(info);
400 ASSERT_NE(dialogSession, nullptr);
401 dialogSession->state_ = SessionState::STATE_ACTIVE;
402 session_->dialogVec_.push_back(dialogSession);
403 session_->parentSession_ = session_;
404
405 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
406 }
407
408 /**
409 * @tc.name: TransferKeyEvent05
410 * @tc.desc: windowEventChannel_ is nullptr
411 * @tc.type: FUNC
412 */
413 HWTEST_F(WindowSessionTest2, TransferKeyEvent05, TestSize.Level1)
414 {
415 ASSERT_NE(session_, nullptr);
416
417 session_->sessionInfo_.isSystem_ = true;
418
419 auto keyEvent = MMI::KeyEvent::Create();
420 ASSERT_NE(keyEvent, nullptr);
421
422 session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
423
424 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
425 }
426
427 /**
428 * @tc.name: TransferBackPressedEventForConsumed01
429 * @tc.desc: windowEventChannel_ is nullptr
430 * @tc.type: FUNC
431 */
432 HWTEST_F(WindowSessionTest2, TransferBackPressedEventForConsumed01, TestSize.Level1)
433 {
434 ASSERT_NE(session_, nullptr);
435
436 session_->windowEventChannel_ = nullptr;
437
438 bool isConsumed = false;
439 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferBackPressedEventForConsumed(isConsumed));
440 }
441
442 /**
443 * @tc.name: TransferKeyEventForConsumed01
444 * @tc.desc: windowEventChannel_ is nullptr
445 * @tc.type: FUNC
446 */
447 HWTEST_F(WindowSessionTest2, TransferKeyEventForConsumed01, TestSize.Level1)
448 {
449 ASSERT_NE(session_, nullptr);
450
451 session_->windowEventChannel_ = nullptr;
452
453 auto keyEvent = MMI::KeyEvent::Create();
454 bool isConsumed = false;
455 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEventForConsumed(keyEvent, isConsumed));
456 }
457
458 /**
459 * @tc.name: TransferFocusActiveEvent01
460 * @tc.desc: windowEventChannel_ is nullptr
461 * @tc.type: FUNC
462 */
463 HWTEST_F(WindowSessionTest2, TransferFocusActiveEvent01, TestSize.Level1)
464 {
465 ASSERT_NE(session_, nullptr);
466
467 session_->windowEventChannel_ = nullptr;
468
469 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferFocusActiveEvent(false));
470 }
471
472 /**
473 * @tc.name: TransferFocusStateEvent01
474 * @tc.desc: windowEventChannel_ is nullptr
475 * @tc.type: FUNC
476 */
477 HWTEST_F(WindowSessionTest2, TransferFocusStateEvent01, TestSize.Level1)
478 {
479 ASSERT_NE(session_, nullptr);
480
481 session_->windowEventChannel_ = nullptr;
482
483 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferFocusStateEvent(false));
484 }
485
486 /**
487 * @tc.name: Snapshot01
488 * @tc.desc: ret is false
489 * @tc.type: FUNC
490 */
491 HWTEST_F(WindowSessionTest2, Snapshot01, TestSize.Level1)
492 {
493 ASSERT_NE(session_, nullptr);
494
495 session_->surfaceNode_ = nullptr;
496
497 ASSERT_EQ(nullptr, session_->Snapshot());
498 }
499
500 /**
501 * @tc.name: SetSessionStateChangeListenser
502 * @tc.desc: SetSessionStateChangeListenser Test
503 * @tc.type: FUNC
504 */
505 HWTEST_F(WindowSessionTest2, SetSessionStateChangeListenser, TestSize.Level1)
506 {
507 ASSERT_NE(session_, nullptr);
508
509 NotifySessionStateChangeFunc func = nullptr;
510 session_->SetSessionStateChangeListenser(func);
511
512 session_->state_ = SessionState::STATE_DISCONNECT;
513 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
514 }
515
516 /**
517 * @tc.name: SetClearSubSessionCallback
518 * @tc.desc: SetClearSubSessionCallback Test
519 * @tc.type: FUNC
520 */
521 HWTEST_F(WindowSessionTest2, SetClearSubSessionCallback, TestSize.Level1)
522 {
523 SessionInfo info;
524 info.abilityName_ = "SetClearSubSessionCallback";
525 info.moduleName_ = "SetClearSubSessionCallback";
526 info.bundleName_ = "SetClearSubSessionCallback";
527 sptr<Session> session = sptr<Session>::MakeSptr(info);
528
529 NotifyClearSubSessionFunc func = nullptr;
530 session->SetClearSubSessionCallback(func);
531 EXPECT_TRUE(session->clearSubSessionFunc_ == nullptr);
532
__anonbfdbf0d10402(const int32_t subPersistentId) 533 func = [](const int32_t subPersistentId) {
534 };
535 session->SetClearSubSessionCallback(func);
536 EXPECT_FALSE(session->clearSubSessionFunc_ == nullptr);
537 }
538
539 /**
540 * @tc.name: NotifySessionStateChange
541 * @tc.desc: NotifySessionStateChange Test
542 * @tc.type: FUNC
543 */
544 HWTEST_F(WindowSessionTest2, NotifySessionStateChange, TestSize.Level1)
545 {
546 g_logMsg.clear();
547 LOG_SetCallback(MyLogCallback);
548 SessionInfo info;
549 info.abilityName_ = "NotifySessionStateChange";
550 info.moduleName_ = "NotifySessionStateChange";
551 info.bundleName_ = "NotifySessionStateChange";
552 sptr<Session> session = sptr<Session>::MakeSptr(info);
553
554 session->NotifySessionStateChange(SessionState::STATE_ACTIVE);
555 EXPECT_TRUE(g_logMsg.find("notify clear subSession") == std::string::npos);
556
557 info.abilityName_ = "parentSession";
558 info.moduleName_ = "parentSession";
559 info.bundleName_ = "parentSession";
560 sptr<Session> parentSession = sptr<Session>::MakeSptr(info);
561 EXPECT_NE(parentSession, nullptr);
562
563 session->SetParentSession(parentSession);
564 session->NotifySessionStateChange(SessionState::STATE_ACTIVE);
565 EXPECT_TRUE(g_logMsg.find("notify clear subSession") == std::string::npos);
566
__anonbfdbf0d10502(const int32_t subPersistentId) 567 parentSession->clearSubSessionFunc_ = [](const int32_t subPersistentId) {
568 };
569 session->SetParentSession(parentSession);
570 session->NotifySessionStateChange(SessionState::STATE_ACTIVE);
571 EXPECT_TRUE(g_logMsg.find("notify clear subSession") == std::string::npos);
572
573 session->NotifySessionStateChange(SessionState::STATE_DISCONNECT);
574 EXPECT_TRUE(g_logMsg.find("notify clear subSession") != std::string::npos);
575 }
576
577 /**
578 * @tc.name: SetSessionFocusableChangeListener
579 * @tc.desc: SetSessionFocusableChangeListener Test
580 * @tc.type: FUNC
581 */
582 HWTEST_F(WindowSessionTest2, SetSessionFocusableChangeListener, TestSize.Level1)
583 {
584 ASSERT_NE(session_, nullptr);
585
__anonbfdbf0d10602(const bool isFocusable) 586 NotifySessionFocusableChangeFunc func = [](const bool isFocusable) {};
587 session_->SetSessionFocusableChangeListener(func);
588
589 session_->state_ = SessionState::STATE_DISCONNECT;
590 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
591 }
592
593 /**
594 * @tc.name: SetSessionTouchableChangeListener
595 * @tc.desc: SetSessionTouchableChangeListener Test
596 * @tc.type: FUNC
597 */
598 HWTEST_F(WindowSessionTest2, SetSessionTouchableChangeListener, TestSize.Level1)
599 {
600 ASSERT_NE(session_, nullptr);
601
__anonbfdbf0d10702(const bool touchable) 602 NotifySessionTouchableChangeFunc func = [](const bool touchable) {};
603 session_->SetSessionTouchableChangeListener(func);
604
605 session_->state_ = SessionState::STATE_DISCONNECT;
606 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
607 }
608
609 /**
610 * @tc.name: SetSessionInfoLockedStateChangeListener
611 * @tc.desc: SetSessionInfoLockedStateChangeListener Test
612 * @tc.type: FUNC
613 */
614 HWTEST_F(WindowSessionTest2, SetSessionInfoLockedStateChangeListener, TestSize.Level1)
615 {
616 ASSERT_NE(session_, nullptr);
617
__anonbfdbf0d10802(const bool lockedState) 618 NotifySessionTouchableChangeFunc func = [](const bool lockedState) {};
619 session_->SetSessionInfoLockedStateChangeListener(func);
620
621 session_->SetSessionInfoLockedState(true);
622 ASSERT_EQ(true, session_->sessionInfo_.lockedState);
623 }
624
625 /**
626 * @tc.name: SetClickListener
627 * @tc.desc: SetClickListener Test
628 * @tc.type: FUNC
629 */
630 HWTEST_F(WindowSessionTest2, SetClickListener, TestSize.Level1)
631 {
632 ASSERT_NE(session_, nullptr);
633
634 NotifyClickFunc func = nullptr;
635 session_->SetClickListener(func);
636
637 session_->state_ = SessionState::STATE_DISCONNECT;
638 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
639 }
640
641 /**
642 * @tc.name: UpdateFocus01
643 * @tc.desc: isFocused_ equal isFocused
644 * @tc.type: FUNC
645 */
646 HWTEST_F(WindowSessionTest2, UpdateFocus01, TestSize.Level1)
647 {
648 ASSERT_NE(session_, nullptr);
649
650 bool isFocused = session_->isFocused_;
651 ASSERT_EQ(WSError::WS_DO_NOTHING, session_->UpdateFocus(isFocused));
652 }
653
654 /**
655 * @tc.name: UpdateFocus02
656 * @tc.desc: isFocused_ not equal isFocused, IsSessionValid() return false
657 * @tc.type: FUNC
658 */
659 HWTEST_F(WindowSessionTest2, UpdateFocus02, TestSize.Level1)
660 {
661 ASSERT_NE(session_, nullptr);
662
663 session_->sessionInfo_.isSystem_ = true;
664
665 bool isFocused = session_->isFocused_;
666 ASSERT_EQ(WSError::WS_OK, session_->UpdateFocus(!isFocused));
667 }
668
669 /**
670 * @tc.name: UpdateWindowMode01
671 * @tc.desc: IsSessionValid() return false
672 * @tc.type: FUNC
673 */
674 HWTEST_F(WindowSessionTest2, UpdateWindowMode01, TestSize.Level1)
675 {
676 ASSERT_NE(session_, nullptr);
677 ASSERT_EQ(WSError::WS_OK, session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED));
678 }
679
680 /**
681 * @tc.name: NotifyForegroundInteractiveStatus
682 * @tc.desc: NotifyForegroundInteractiveStatus Test
683 * @tc.type: FUNC
684 */
685 HWTEST_F(WindowSessionTest2, NotifyForegroundInteractiveStatus, TestSize.Level1)
686 {
687 g_logMsg.clear();
688 LOG_SetCallback(MyLogCallback);
689 ASSERT_NE(session_, nullptr);
690 int32_t persistentId = 123;
691 session_->sessionStage_ = nullptr;
692 bool interactive = true;
693 session_->NotifyForegroundInteractiveStatus(interactive);
694
695 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
696 ASSERT_NE(mockSessionStage, nullptr);
697 session_->sessionStage_ = mockSessionStage;
698 session_->state_ = SessionState::STATE_FOREGROUND;
699 session_->persistentId_ = persistentId;
700 interactive = false;
701 session_->NotifyForegroundInteractiveStatus(interactive);
702 EXPECT_TRUE(g_logMsg.find("id:123") != std::string::npos);
703 LOG_SetCallback(nullptr);
704 }
705
706 /**
707 * @tc.name: SetEventHandler001
708 * @tc.desc: SetEventHandler Test
709 * @tc.type: FUNC
710 */
711 HWTEST_F(WindowSessionTest2, SetEventHandler001, TestSize.Level1)
712 {
713 ASSERT_NE(session_, nullptr);
714 std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
715 std::shared_ptr<AppExecFwk::EventHandler> exportHandler = nullptr;
716 session_->SetEventHandler(handler, exportHandler);
717 EXPECT_EQ(nullptr, session_->handler_);
718 EXPECT_EQ(nullptr, session_->exportHandler_);
719 }
720
721 /**
722 * @tc.name: PostTask002
723 * @tc.desc: PostTask Test
724 * @tc.type: FUNC
725 */
726 HWTEST_F(WindowSessionTest2, PostTask002, TestSize.Level1)
727 {
728 ASSERT_NE(session_, nullptr);
729 int32_t persistentId = 0;
730 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
731 ASSERT_NE(nullptr, property);
732 property->SetPersistentId(persistentId);
733 int32_t res = session_->GetPersistentId();
734 ASSERT_EQ(res, 0);
735 }
736
737 /**
738 * @tc.name: GetSurfaceNode
739 * @tc.desc: GetSurfaceNode Test
740 * @tc.type: FUNC
741 */
742 HWTEST_F(WindowSessionTest2, GetSurfaceNode, TestSize.Level1)
743 {
744 ASSERT_NE(session_, nullptr);
745 session_->surfaceNode_ = nullptr;
746 std::shared_ptr<RSSurfaceNode> res = session_->GetSurfaceNode();
747 ASSERT_EQ(res, nullptr);
748 }
749
750 /**
751 * @tc.name: GetLeashWinSurfaceNode
752 * @tc.desc: GetLeashWinSurfaceNode Test
753 * @tc.type: FUNC
754 */
755 HWTEST_F(WindowSessionTest2, GetLeashWinSurfaceNode, TestSize.Level1)
756 {
757 ASSERT_NE(session_, nullptr);
758 session_->leashWinSurfaceNode_ = nullptr;
759 std::shared_ptr<RSSurfaceNode> res = session_->GetLeashWinSurfaceNode();
760 ASSERT_EQ(res, nullptr);
761 }
762
763 /**
764 * @tc.name: SetSessionInfoAncoSceneState
765 * @tc.desc: SetSessionInfoAncoSceneState Test
766 * @tc.type: FUNC
767 */
768 HWTEST_F(WindowSessionTest2, SetSessionInfoAncoSceneState, TestSize.Level1)
769 {
770 ASSERT_NE(session_, nullptr);
771 int32_t ancoSceneState = 0;
772 session_->SetSessionInfoAncoSceneState(ancoSceneState);
773 EXPECT_EQ(0, session_->sessionInfo_.ancoSceneState);
774 }
775
776 /**
777 * @tc.name: SetSessionInfoTime
778 * @tc.desc: SetSessionInfoTime Test
779 * @tc.type: FUNC
780 */
781 HWTEST_F(WindowSessionTest2, SetSessionInfoTime, TestSize.Level1)
782 {
783 ASSERT_NE(session_, nullptr);
784 std::string time = "";
785 session_->SetSessionInfoTime(time);
786 EXPECT_EQ("", session_->sessionInfo_.time);
787 }
788
789 /**
790 * @tc.name: SetSessionInfoAbilityInfo
791 * @tc.desc: SetSessionInfoAbilityInfo Test
792 * @tc.type: FUNC
793 */
794 HWTEST_F(WindowSessionTest2, SetSessionInfoAbilityInfo, TestSize.Level1)
795 {
796 ASSERT_NE(session_, nullptr);
797 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
798 session_->SetSessionInfoAbilityInfo(abilityInfo);
799 EXPECT_EQ(nullptr, session_->sessionInfo_.abilityInfo);
800 }
801
802 /**
803 * @tc.name: SetSessionInfoWant
804 * @tc.desc: SetSessionInfoWant Test
805 * @tc.type: FUNC
806 */
807 HWTEST_F(WindowSessionTest2, SetSessionInfoWant, TestSize.Level1)
808 {
809 ASSERT_NE(session_, nullptr);
810 std::shared_ptr<AAFwk::Want> want = nullptr;
811 session_->SetSessionInfoWant(want);
812 EXPECT_EQ(nullptr, session_->sessionInfo_.want);
813 }
814
815 /**
816 * @tc.name: SetSessionInfoPersistentId
817 * @tc.desc: SetSessionInfoPersistentId Test
818 * @tc.type: FUNC
819 */
820 HWTEST_F(WindowSessionTest2, SetSessionInfoPersistentId, TestSize.Level1)
821 {
822 ASSERT_NE(session_, nullptr);
823 int32_t persistentId = 0;
824 session_->SetSessionInfoPersistentId(persistentId);
825 EXPECT_EQ(0, session_->sessionInfo_.persistentId_);
826 }
827
828 /**
829 * @tc.name: SetSessionInfoCallerPersistentId
830 * @tc.desc: SetSessionInfoCallerPersistentId Test
831 * @tc.type: FUNC
832 */
833 HWTEST_F(WindowSessionTest2, SetSessionInfoCallerPersistentId, TestSize.Level1)
834 {
835 ASSERT_NE(session_, nullptr);
836 int32_t callerPersistentId = 0;
837 session_->SetSessionInfoCallerPersistentId(callerPersistentId);
838 EXPECT_EQ(0, session_->sessionInfo_.callerPersistentId_);
839 }
840
841 /**
842 * @tc.name: PostExportTask
843 * @tc.desc: PostExportTask Test
844 * @tc.type: FUNC
845 */
846 HWTEST_F(WindowSessionTest2, PostExportTask, TestSize.Level1)
847 {
848 ASSERT_NE(session_, nullptr);
849 int32_t persistentId = 0;
850 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
851 ASSERT_NE(nullptr, property);
852 property->SetPersistentId(persistentId);
853 int32_t ret = session_->GetPersistentId();
854 ASSERT_EQ(ret, 0);
855 }
856
857 /**
858 * @tc.name: GetPersistentId
859 * @tc.desc: GetPersistentId Test
860 * @tc.type: FUNC
861 */
862 HWTEST_F(WindowSessionTest2, GetPersistentId, TestSize.Level1)
863 {
864 ASSERT_NE(session_, nullptr);
865 int32_t persistentId = 0;
866 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
867 EXPECT_NE(nullptr, property);
868 property->SetPersistentId(persistentId);
869 int32_t ret = session_->GetPersistentId();
870 ASSERT_EQ(ret, 0);
871 }
872
873 /**
874 * @tc.name: SetLeashWinSurfaceNode
875 * @tc.desc: SetLeashWinSurfaceNode Test
876 * @tc.type: FUNC
877 */
878 HWTEST_F(WindowSessionTest2, SetLeashWinSurfaceNode, TestSize.Level1)
879 {
880 ASSERT_NE(session_, nullptr);
881 auto leashWinSurfaceNode = WindowSessionTest2::CreateRSSurfaceNode();
882 session_->SetLeashWinSurfaceNode(leashWinSurfaceNode);
883 ASSERT_EQ(session_->leashWinSurfaceNode_, leashWinSurfaceNode);
884 }
885
886 /**
887 * @tc.name: SetSessionInfoContinueState
888 * @tc.desc: SetSessionInfoContinueState Test
889 * @tc.type: FUNC
890 */
891 HWTEST_F(WindowSessionTest2, SetSessionInfoContinueState, TestSize.Level1)
892 {
893 ASSERT_NE(session_, nullptr);
894 enum ContinueState state = CONTINUESTATE_UNKNOWN;
895 session_->SetSessionInfoContinueState(state);
896 ASSERT_EQ(session_->sessionInfo_.continueState, state);
897 }
898
899 /**
900 * @tc.name: SetSessionInfoIsClearSession01
901 * @tc.desc: SetSessionInfoIsClearSession return false
902 * @tc.type: FUNC
903 */
904 HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession01, TestSize.Level1)
905 {
906 ASSERT_NE(session_, nullptr);
907 session_->SetSessionInfoIsClearSession(false);
908 ASSERT_EQ(false, session_->sessionInfo_.isClearSession);
909 }
910
911 /**
912 * @tc.name: SetSessionInfoIsClearSession02
913 * @tc.desc: SetSessionInfoIsClearSession return true
914 * @tc.type: FUNC
915 */
916 HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession02, TestSize.Level1)
917 {
918 ASSERT_NE(session_, nullptr);
919 session_->SetSessionInfoIsClearSession(true);
920 ASSERT_EQ(true, session_->sessionInfo_.isClearSession);
921 }
922
923 /**
924 * @tc.name: SetSessionInfoAffinity
925 * @tc.desc: SetSessionInfoAffinity
926 * @tc.type: FUNC
927 */
928 HWTEST_F(WindowSessionTest2, SetSessionInfoAffinity, TestSize.Level1)
929 {
930 ASSERT_NE(session_, nullptr);
931 std::string affinity = "setSessionIofoAffinity";
932 session_->SetSessionInfoAffinity(affinity);
933 ASSERT_EQ(affinity, session_->sessionInfo_.sessionAffinity);
934 }
935
936 /**
937 * @tc.name: SetSessionInfo
938 * @tc.desc: SetSessionInfo
939 * @tc.type: FUNC
940 */
941 HWTEST_F(WindowSessionTest2, SetSessionInfo, TestSize.Level1)
942 {
943 ASSERT_NE(session_, nullptr);
944 SessionInfo info;
945 info.want = nullptr;
946 info.callerToken_ = nullptr;
947 info.requestCode = 1;
948 info.callerPersistentId_ = 1;
949 info.callingTokenId_ = 1;
950 info.uiAbilityId_ = 1;
951 info.startSetting = nullptr;
952 info.continueSessionId_ = "";
953 std::shared_ptr<AAFwk::ProcessOptions> processOptions = std::make_shared<AAFwk::ProcessOptions>();
954 info.processOptions = processOptions;
955 session_->SetSessionInfo(info);
956 ASSERT_EQ(nullptr, session_->sessionInfo_.want);
957 ASSERT_EQ(nullptr, session_->sessionInfo_.callerToken_);
958 ASSERT_EQ(1, session_->sessionInfo_.requestCode);
959 ASSERT_EQ(1, session_->sessionInfo_.callerPersistentId_);
960 ASSERT_EQ(1, session_->sessionInfo_.callingTokenId_);
961 ASSERT_EQ(1, session_->sessionInfo_.uiAbilityId_);
962 ASSERT_EQ("", session_->sessionInfo_.continueSessionId_);
963 ASSERT_EQ(nullptr, session_->sessionInfo_.startSetting);
964 ASSERT_EQ(processOptions, session_->sessionInfo_.processOptions);
965 info.continueSessionId_ = "continueSessionId";
966 session_->SetSessionInfo(info);
967 ASSERT_EQ(session_->sessionInfo_.continueSessionId_, "continueSessionId");
968 }
969
970 /**
971 * @tc.name: SetScreenId
972 * @tc.desc: SetScreenId
973 * @tc.type: FUNC
974 */
975 HWTEST_F(WindowSessionTest2, SetScreenId, TestSize.Level1)
976 {
977 ASSERT_NE(session_, nullptr);
978 uint64_t screenId = 0;
979 session_->SetScreenId(screenId);
980 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
981 }
982
983 /**
984 * @tc.name: RegisterLifecycleListener
985 * @tc.desc: RegisterLifecycleListener
986 * @tc.type: FUNC
987 */
988 HWTEST_F(WindowSessionTest2, RegisterLifecycleListener, TestSize.Level1)
989 {
990 ASSERT_NE(session_, nullptr);
991 const std::shared_ptr<ILifecycleListener>& listener = nullptr;
992 bool ret = session_->RegisterLifecycleListener(listener);
993 ASSERT_EQ(false, ret);
994 }
995
996 /**
997 * @tc.name: UnregisterLifecycleListener
998 * @tc.desc: UnregisterLifecycleListener
999 * @tc.type: FUNC
1000 */
1001 HWTEST_F(WindowSessionTest2, UnregisterLifecycleListener, TestSize.Level1)
1002 {
1003 ASSERT_NE(session_, nullptr);
1004 const std::shared_ptr<ILifecycleListener>& listener = nullptr;
1005 bool ret = session_->UnregisterLifecycleListener(listener);
1006 ASSERT_EQ(false, ret);
1007 }
1008
1009 /**
1010 * @tc.name: NotifyActivation02
1011 * @tc.desc: NotifyActivation
1012 * @tc.type: FUNC
1013 */
1014 HWTEST_F(WindowSessionTest2, NotifyActivation02, TestSize.Level1)
1015 {
1016 ASSERT_NE(session_, nullptr);
1017 session_->NotifyActivation();
1018 uint64_t screenId = 0;
1019 session_->SetScreenId(screenId);
1020 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1021 }
1022
1023 /**
1024 * @tc.name: NotifyConnect
1025 * @tc.desc: NotifyConnect
1026 * @tc.type: FUNC
1027 */
1028 HWTEST_F(WindowSessionTest2, NotifyConnect, TestSize.Level1)
1029 {
1030 ASSERT_NE(session_, nullptr);
1031 session_->NotifyConnect();
1032 uint64_t screenId = 0;
1033 session_->SetScreenId(screenId);
1034 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1035 }
1036
1037 /**
1038 * @tc.name: NotifyForeground02
1039 * @tc.desc: NotifyForeground
1040 * @tc.type: FUNC
1041 */
1042 HWTEST_F(WindowSessionTest2, NotifyForeground02, TestSize.Level1)
1043 {
1044 ASSERT_NE(session_, nullptr);
1045 session_->NotifyForeground();
1046 uint64_t screenId = 0;
1047 session_->SetScreenId(screenId);
1048 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1049 }
1050
1051 /**
1052 * @tc.name: NotifyBackground02
1053 * @tc.desc: NotifyBackground
1054 * @tc.type: FUNC
1055 */
1056 HWTEST_F(WindowSessionTest2, NotifyBackground02, TestSize.Level1)
1057 {
1058 ASSERT_NE(session_, nullptr);
1059 session_->NotifyBackground();
1060 uint64_t screenId = 0;
1061 session_->SetScreenId(screenId);
1062 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1063 }
1064
1065 /**
1066 * @tc.name: NotifyDisconnect
1067 * @tc.desc: NotifyDisconnect
1068 * @tc.type: FUNC
1069 */
1070 HWTEST_F(WindowSessionTest2, NotifyDisconnect, TestSize.Level1)
1071 {
1072 ASSERT_NE(session_, nullptr);
1073 session_->NotifyDisconnect();
1074 uint64_t screenId = 0;
1075 session_->SetScreenId(screenId);
1076 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1077 }
1078
1079 /**
1080 * @tc.name: NotifyExtensionDied02
1081 * @tc.desc: NotifyExtensionDied
1082 * @tc.type: FUNC
1083 */
1084 HWTEST_F(WindowSessionTest2, NotifyExtensionDied02, TestSize.Level1)
1085 {
1086 ASSERT_NE(session_, nullptr);
1087 session_->NotifyExtensionDied();
1088
1089 session_->RegisterLifecycleListener(lifecycleListener_);
1090 session_->NotifyExtensionDied();
1091 uint64_t screenId = 0;
1092 session_->SetScreenId(screenId);
1093 session_->UnregisterLifecycleListener(lifecycleListener_);
1094 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1095 }
1096
1097 /**
1098 * @tc.name: NotifyTransferAccessibilityEvent
1099 * @tc.desc: NotifyTransferAccessibilityEvent
1100 * @tc.type: FUNC
1101 */
1102 HWTEST_F(WindowSessionTest2, NotifyTransferAccessibilityEvent, TestSize.Level1)
1103 {
1104 ASSERT_NE(session_, nullptr);
1105 OHOS::Accessibility::AccessibilityEventInfo info1;
1106 int64_t uiExtensionIdLevel = 6;
1107 session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1108
1109 session_->RegisterLifecycleListener(lifecycleListener_);
1110 session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1111 uint64_t screenId = 0;
1112 session_->SetScreenId(screenId);
1113 session_->UnregisterLifecycleListener(lifecycleListener_);
1114 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1115 }
1116
1117 /**
1118 * @tc.name: GetAspectRatio
1119 * @tc.desc: GetAspectRatio
1120 * @tc.type: FUNC
1121 */
1122 HWTEST_F(WindowSessionTest2, GetAspectRatio, TestSize.Level1)
1123 {
1124 ASSERT_NE(session_, nullptr);
1125 float ret = session_->GetAspectRatio();
1126 float res = 0.0f;
1127 ASSERT_EQ(ret, res);
1128 }
1129
1130 /**
1131 * @tc.name: SetAspectRatio02
1132 * @tc.desc: SetAspectRatio
1133 * @tc.type: FUNC
1134 */
1135 HWTEST_F(WindowSessionTest2, SetAspectRatio02, TestSize.Level1)
1136 {
1137 ASSERT_NE(session_, nullptr);
1138 float radio = 2.0f;
1139 WSError ERR = session_->SetAspectRatio(radio);
1140 float ret = session_->GetAspectRatio();
1141 ASSERT_EQ(ret, radio);
1142 ASSERT_EQ(ERR, WSError::WS_OK);
1143 }
1144
1145 /**
1146 * @tc.name: GetSessionState
1147 * @tc.desc: GetSessionState
1148 * @tc.type: FUNC
1149 */
1150 HWTEST_F(WindowSessionTest2, GetSessionState, TestSize.Level1)
1151 {
1152 ASSERT_NE(session_, nullptr);
1153 SessionState state = session_->GetSessionState();
1154 ASSERT_EQ(state, session_->state_);
1155 }
1156
1157 /**
1158 * @tc.name: SetSessionState02
1159 * @tc.desc: SetSessionState
1160 * @tc.type: FUNC
1161 */
1162 HWTEST_F(WindowSessionTest2, SetSessionState02, TestSize.Level1)
1163 {
1164 ASSERT_NE(session_, nullptr);
1165 SessionState state = SessionState::STATE_CONNECT;
1166 session_->SetSessionState(state);
1167 ASSERT_EQ(state, session_->state_);
1168 }
1169
1170 /**
1171 * @tc.name: SetChangeSessionVisibilityWithStatusBarEventListener
1172 * @tc.desc: SetChangeSessionVisibilityWithStatusBarEventListener Test
1173 * @tc.type: FUNC
1174 */
1175 HWTEST_F(WindowSessionTest2, SetChangeSessionVisibilityWithStatusBarEventListener, TestSize.Level1)
1176 {
1177 int resultValue = 0;
1178 session_->SetChangeSessionVisibilityWithStatusBarEventListener(
__anonbfdbf0d10902(const SessionInfo& info, const bool visible) 1179 [&resultValue](const SessionInfo& info, const bool visible) { resultValue = 1; });
1180 usleep(WAIT_SYNC_IN_NS);
1181 ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1182
1183 SessionInfo info;
1184 session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1185 ASSERT_EQ(resultValue, 1);
1186
1187 session_->SetChangeSessionVisibilityWithStatusBarEventListener(
__anonbfdbf0d10a02(const SessionInfo& info, const bool visible) 1188 [&resultValue](const SessionInfo& info, const bool visible) { resultValue = 2; });
1189 usleep(WAIT_SYNC_IN_NS);
1190 ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1191 session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1192 ASSERT_EQ(resultValue, 2);
1193 }
1194
1195 /**
1196 * @tc.name: UpdateSesionState
1197 * @tc.desc: UpdateSesionState
1198 * @tc.type: FUNC
1199 */
1200 HWTEST_F(WindowSessionTest2, UpdateSesionState, TestSize.Level1)
1201 {
1202 ASSERT_NE(session_, nullptr);
1203 SessionState state = SessionState::STATE_CONNECT;
1204 session_->UpdateSessionState(state);
1205 ASSERT_EQ(session_->state_, SessionState::STATE_CONNECT);
1206 }
1207
1208 /**
1209 * @tc.name: GetTouchable
1210 * @tc.desc: GetTouchable
1211 * @tc.type: FUNC
1212 */
1213 HWTEST_F(WindowSessionTest2, GetTouchable, TestSize.Level1)
1214 {
1215 ASSERT_NE(session_, nullptr);
1216 bool res = session_->GetTouchable();
1217 ASSERT_EQ(true, res);
1218 }
1219
1220 /**
1221 * @tc.name: SetSystemTouchable
1222 * @tc.desc: SetSystemTouchable
1223 * @tc.type: FUNC
1224 */
1225 HWTEST_F(WindowSessionTest2, SetSystemTouchable, TestSize.Level1)
1226 {
1227 ASSERT_NE(session_, nullptr);
1228 bool touchable = false;
1229 session_->SetSystemTouchable(touchable);
1230 ASSERT_EQ(session_->systemTouchable_, touchable);
1231 }
1232
1233 /**
1234 * @tc.name: GetSystemTouchable
1235 * @tc.desc: GetSystemTouchable
1236 * @tc.type: FUNC
1237 */
1238 HWTEST_F(WindowSessionTest2, GetSystemTouchable, TestSize.Level1)
1239 {
1240 ASSERT_NE(session_, nullptr);
1241 bool res = session_->GetSystemTouchable();
1242 ASSERT_EQ(res, true);
1243 }
1244
1245 /**
1246 * @tc.name: SetRSVisible
1247 * @tc.desc: SetRSVisible
1248 * @tc.type: FUNC
1249 */
1250 HWTEST_F(WindowSessionTest2, SetVisible, TestSize.Level1)
1251 {
1252 ASSERT_NE(session_, nullptr);
1253 bool isVisible = false;
1254 ASSERT_EQ(WSError::WS_OK, session_->SetRSVisible(isVisible));
1255 }
1256
1257 /**
1258 * @tc.name: GetRSVisible02
1259 * @tc.desc: GetRSVisible
1260 * @tc.type: FUNC
1261 */
1262 HWTEST_F(WindowSessionTest2, GetRSVisible02, TestSize.Level1)
1263 {
1264 ASSERT_NE(session_, nullptr);
1265 if (!session_->GetRSVisible()) {
1266 ASSERT_EQ(false, session_->GetRSVisible());
1267 }
1268 }
1269
1270 /**
1271 * @tc.name: SetVisibilityState
1272 * @tc.desc: SetVisibilityState
1273 * @tc.type: FUNC
1274 */
1275 HWTEST_F(WindowSessionTest2, SetVisibilityState, TestSize.Level1)
1276 {
1277 ASSERT_NE(session_, nullptr);
1278 WindowVisibilityState state{ WINDOW_VISIBILITY_STATE_NO_OCCLUSION };
1279 ASSERT_EQ(WSError::WS_OK, session_->SetVisibilityState(state));
1280 ASSERT_EQ(state, session_->visibilityState_);
1281 }
1282
1283 /**
1284 * @tc.name: GetVisibilityState
1285 * @tc.desc: GetVisibilityState
1286 * @tc.type: FUNC
1287 */
1288 HWTEST_F(WindowSessionTest2, GetVisibilityState, TestSize.Level1)
1289 {
1290 ASSERT_NE(session_, nullptr);
1291 WindowVisibilityState state{ WINDOW_LAYER_STATE_MAX };
1292 ASSERT_EQ(state, session_->GetVisibilityState());
1293 }
1294
1295 /**
1296 * @tc.name: SetDrawingContentState
1297 * @tc.desc: SetDrawingContentState
1298 * @tc.type: FUNC
1299 */
1300 HWTEST_F(WindowSessionTest2, SetDrawingContentState, TestSize.Level1)
1301 {
1302 ASSERT_NE(session_, nullptr);
1303 bool isRSDrawing = false;
1304 ASSERT_EQ(WSError::WS_OK, session_->SetDrawingContentState(isRSDrawing));
1305 ASSERT_EQ(false, session_->isRSDrawing_);
1306 }
1307
1308 /**
1309 * @tc.name: GetDrawingContentState
1310 * @tc.desc: GetDrawingContentState
1311 * @tc.type: FUNC
1312 */
1313 HWTEST_F(WindowSessionTest2, GetDrawingContentState, TestSize.Level1)
1314 {
1315 ASSERT_NE(session_, nullptr);
1316 bool res = session_->GetDrawingContentState();
1317 ASSERT_EQ(res, false);
1318 }
1319
1320 /**
1321 * @tc.name: GetBrightness
1322 * @tc.desc: GetBrightness
1323 * @tc.type: FUNC
1324 */
1325 HWTEST_F(WindowSessionTest2, GetBrightness, TestSize.Level1)
1326 {
1327 ASSERT_NE(session_, nullptr);
1328 session_->state_ = SessionState::STATE_DISCONNECT;
1329 ASSERT_EQ(UNDEFINED_BRIGHTNESS, session_->GetBrightness());
1330 }
1331
1332 /**
1333 * @tc.name: IsActive02
1334 * @tc.desc: IsActive
1335 * @tc.type: FUNC
1336 */
1337 HWTEST_F(WindowSessionTest2, IsActive02, TestSize.Level1)
1338 {
1339 ASSERT_NE(session_, nullptr);
1340 bool res = session_->IsActive();
1341 ASSERT_EQ(res, false);
1342 }
1343
1344 /**
1345 * @tc.name: Hide
1346 * @tc.desc: Hide
1347 * @tc.type: FUNC
1348 */
1349 HWTEST_F(WindowSessionTest2, Hide, TestSize.Level1)
1350 {
1351 ASSERT_NE(session_, nullptr);
1352 auto res = session_->Hide();
1353 ASSERT_EQ(res, WSError::WS_OK);
1354 }
1355
1356 /**
1357 * @tc.name: Show
1358 * @tc.desc: Show
1359 * @tc.type: FUNC
1360 */
1361 HWTEST_F(WindowSessionTest2, Show, TestSize.Level1)
1362 {
1363 ASSERT_NE(session_, nullptr);
1364 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1365 ASSERT_NE(nullptr, property);
1366 auto result = session_->Show(property);
1367 ASSERT_EQ(result, WSError::WS_OK);
1368 }
1369
1370 /**
1371 * @tc.name: DrawingCompleted
1372 * @tc.desc: DrawingCompleled
1373 * @tc.type: FUNC
1374 */
1375 HWTEST_F(WindowSessionTest2, DrawingCompleted, TestSize.Level1)
1376 {
1377 ASSERT_NE(session_, nullptr);
1378 auto result = session_->DrawingCompleted();
1379 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1380 }
1381
1382 /**
1383 * @tc.name: RemoveStartingWindow
1384 * @tc.desc: RemoveStartingWindow
1385 * @tc.type: FUNC
1386 */
1387 HWTEST_F(WindowSessionTest2, RemoveStartingWindow, TestSize.Level1)
1388 {
1389 ASSERT_NE(session_, nullptr);
1390 session_->RegisterLifecycleListener(lifecycleListener_);
1391 session_->RemoveStartingWindow();
1392 uint64_t screenId = 0;
1393 session_->SetScreenId(screenId);
1394 session_->UnregisterLifecycleListener(lifecycleListener_);
1395 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1396 }
1397
1398 /**
1399 * @tc.name: IsSystemActive
1400 * @tc.desc: IsSystemActive
1401 * @tc.type: FUNC
1402 */
1403 HWTEST_F(WindowSessionTest2, IsSystemActive, TestSize.Level1)
1404 {
1405 ASSERT_NE(session_, nullptr);
1406 bool res = session_->IsSystemActive();
1407 ASSERT_EQ(res, false);
1408 }
1409
1410 /**
1411 * @tc.name: SetSystemActive
1412 * @tc.desc: SetSystemActive
1413 * @tc.type: FUNC
1414 */
1415 HWTEST_F(WindowSessionTest2, SetSystemActive48, TestSize.Level1)
1416 {
1417 ASSERT_NE(session_, nullptr);
1418 bool systemActive = false;
1419 session_->SetSystemActive(systemActive);
1420 ASSERT_EQ(systemActive, session_->isSystemActive_);
1421 }
1422
1423 /**
1424 * @tc.name: IsTerminated
1425 * @tc.desc: IsTerminated
1426 * @tc.type: FUNC
1427 */
1428 HWTEST_F(WindowSessionTest2, IsTerminated, TestSize.Level1)
1429 {
1430 ASSERT_NE(session_, nullptr);
1431 session_->state_ = SessionState::STATE_DISCONNECT;
1432 bool res = session_->IsTerminated();
1433 ASSERT_EQ(true, res);
1434 session_->state_ = SessionState::STATE_FOREGROUND;
1435 res = session_->IsTerminated();
1436 ASSERT_EQ(false, res);
1437 session_->state_ = SessionState::STATE_ACTIVE;
1438 res = session_->IsTerminated();
1439 ASSERT_EQ(false, res);
1440 session_->state_ = SessionState::STATE_INACTIVE;
1441 res = session_->IsTerminated();
1442 ASSERT_EQ(false, res);
1443 session_->state_ = SessionState::STATE_BACKGROUND;
1444 res = session_->IsTerminated();
1445 ASSERT_EQ(false, res);
1446 session_->state_ = SessionState::STATE_CONNECT;
1447 res = session_->IsTerminated();
1448 ASSERT_EQ(false, res);
1449 }
1450
1451 /**
1452 * @tc.name: SetAttachState01
1453 * @tc.desc: SetAttachState Test
1454 * @tc.type: FUNC
1455 */
1456 HWTEST_F(WindowSessionTest2, SetAttachState01, TestSize.Level1)
1457 {
1458 ASSERT_NE(session_, nullptr);
1459 session_->SetAttachState(false);
1460 ASSERT_EQ(session_->isAttach_, false);
1461 }
1462
1463 /**
1464 * @tc.name: SetAttachState02
1465 * @tc.desc: SetAttachState Test
1466 * @tc.type: FUNC
1467 */
1468 HWTEST_F(WindowSessionTest2, SetAttachState02, TestSize.Level1)
1469 {
1470 ASSERT_NE(session_, nullptr);
1471 int32_t persistentId = 123;
1472 sptr<PatternDetachCallbackMocker> detachCallback = sptr<PatternDetachCallbackMocker>::MakeSptr();
1473 EXPECT_CALL(*detachCallback, OnPatternDetach(persistentId)).Times(1);
1474 session_->persistentId_ = persistentId;
1475 session_->SetAttachState(true);
1476 session_->RegisterDetachCallback(detachCallback);
1477 session_->SetAttachState(false);
1478 usleep(WAIT_SYNC_IN_NS);
1479 Mock::VerifyAndClearExpectations(&detachCallback);
1480 }
1481
1482 /**
1483 * @tc.name: SetAttachState03
1484 * @tc.desc: SetAttachState Test
1485 * @tc.type: FUNC
1486 */
1487 HWTEST_F(WindowSessionTest2, SetAttachState03, TestSize.Level1)
1488 {
1489 g_logMsg.clear();
1490 LOG_SetCallback(MyLogCallback);
1491 ASSERT_NE(session_, nullptr);
1492 int32_t persistentId = 123;
1493 session_->persistentId_ = persistentId;
1494
1495 session_->SetAttachState(true);
1496 EXPECT_TRUE(g_logMsg.find("NotifyWindowAttachStateChange, persistentId") == std::string::npos);
1497 }
1498
1499 /**
1500 * @tc.name: RegisterDetachCallback01
1501 * @tc.desc: RegisterDetachCallback Test
1502 * @tc.type: FUNC
1503 */
1504 HWTEST_F(WindowSessionTest2, RegisterDetachCallback01, TestSize.Level1)
1505 {
1506 ASSERT_NE(session_, nullptr);
1507 sptr<IPatternDetachCallback> detachCallback;
1508 session_->RegisterDetachCallback(detachCallback);
1509 ASSERT_EQ(session_->detachCallback_, detachCallback);
1510 }
1511
1512 /**
1513 * @tc.name: RegisterDetachCallback02
1514 * @tc.desc: RegisterDetachCallback Test
1515 * @tc.type: FUNC
1516 */
1517 HWTEST_F(WindowSessionTest2, RegisterDetachCallback02, TestSize.Level1)
1518 {
1519 ASSERT_NE(session_, nullptr);
1520 sptr<IPatternDetachCallback> detachCallback;
1521 session_->RegisterDetachCallback(detachCallback);
1522 ASSERT_EQ(session_->detachCallback_, detachCallback);
1523 sptr<IPatternDetachCallback> detachCallback2;
1524 session_->RegisterDetachCallback(detachCallback2);
1525 ASSERT_EQ(session_->detachCallback_, detachCallback2);
1526 }
1527
1528 /**
1529 * @tc.name: SetContextTransparentFunc
1530 * @tc.desc: SetContextTransparentFunc Test
1531 * @tc.type: FUNC
1532 */
1533 HWTEST_F(WindowSessionTest2, SetContextTransparentFunc, TestSize.Level1)
1534 {
1535 ASSERT_NE(session_, nullptr);
1536 session_->SetContextTransparentFunc(nullptr);
1537 ASSERT_EQ(session_->contextTransparentFunc_, nullptr);
__anonbfdbf0d10b02() 1538 NotifyContextTransparentFunc func = []() {};
1539 session_->SetContextTransparentFunc(func);
1540 ASSERT_NE(session_->contextTransparentFunc_, nullptr);
1541 }
1542
1543 /**
1544 * @tc.name: NeedCheckContextTransparent
1545 * @tc.desc: NeedCheckContextTransparent Test
1546 * @tc.type: FUNC
1547 */
1548 HWTEST_F(WindowSessionTest2, NeedCheckContextTransparent, TestSize.Level1)
1549 {
1550 ASSERT_NE(session_, nullptr);
1551 session_->SetContextTransparentFunc(nullptr);
1552 ASSERT_EQ(session_->NeedCheckContextTransparent(), false);
__anonbfdbf0d10c02() 1553 NotifyContextTransparentFunc func = []() {};
1554 session_->SetContextTransparentFunc(func);
1555 ASSERT_EQ(session_->NeedCheckContextTransparent(), true);
1556 }
1557
1558 /**
1559 * @tc.name: GetBorderUnoccupied
1560 * @tc.desc: GetBorderUnoccupied Test
1561 * @tc.type: FUNC
1562 */
1563 HWTEST_F(WindowSessionTest2, GetBorderUnoccupied, TestSize.Level1)
1564 {
1565 ASSERT_NE(session_, nullptr);
1566 bool res = session_->GetBorderUnoccupied();
1567 ASSERT_EQ(res, false);
1568 }
1569
1570 /**
1571 * @tc.name: SetBorderUnoccupied
1572 * @tc.desc: SetBorderUnoccupied Test
1573 * @tc.type: FUNC
1574 */
1575 HWTEST_F(WindowSessionTest2, SetBorderUnoccupied, TestSize.Level1)
1576 {
1577 ASSERT_NE(session_, nullptr);
1578 session_->SetBorderUnoccupied(true);
1579 bool res = session_->GetBorderUnoccupied();
1580 ASSERT_EQ(res, true);
1581 }
1582 } // namespace
1583 } // namespace Rosen
1584 } // namespace OHOS