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