• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowSessionTest2"};
44 }
45 
46 class WindowSessionTest2 : public testing::Test {
47 public:
48     static void SetUpTestCase();
49     static void TearDownTestCase();
50     void SetUp() override;
51     void TearDown() override;
52 
53     int32_t GetTaskCount();
54     sptr<SceneSessionManager> ssm_;
55 
56 private:
57     RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
58     sptr<Session> session_ = nullptr;
59     static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
60 
61     class TLifecycleListener : public ILifecycleListener {
62     public:
~TLifecycleListener()63         virtual ~TLifecycleListener() {}
OnActivation()64         void OnActivation() override {}
OnConnect()65         void OnConnect() override {}
OnForeground()66         void OnForeground() override {}
OnBackground()67         void OnBackground() override {}
OnDisconnect()68         void OnDisconnect() override {}
OnExtensionDied()69         void OnExtensionDied() override {}
OnExtensionTimeout(int32_t errorCode)70         void OnExtensionTimeout(int32_t errorCode) override {}
OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)71         void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
72             int64_t uiExtensionIdLevel) override {}
OnDrawingCompleted()73         void OnDrawingCompleted() override {}
OnAppRemoveStartingWindow()74         void OnAppRemoveStartingWindow() override {}
75     };
76     std::shared_ptr<TLifecycleListener> lifecycleListener_ = std::make_shared<TLifecycleListener>();
77 
78     sptr<SessionStageMocker> mockSessionStage_ = nullptr;
79     sptr<WindowEventChannelMocker> mockEventChannel_ = nullptr;
80 };
81 
SetUpTestCase()82 void WindowSessionTest2::SetUpTestCase()
83 {
84 }
85 
TearDownTestCase()86 void WindowSessionTest2::TearDownTestCase()
87 {
88 }
89 
SetUp()90 void WindowSessionTest2::SetUp()
91 {
92     SessionInfo info;
93     info.abilityName_ = "testSession1";
94     info.moduleName_ = "testSession2";
95     info.bundleName_ = "testSession3";
96     session_ = new (std::nothrow) Session(info);
97     session_->surfaceNode_ = CreateRSSurfaceNode();
98     EXPECT_NE(nullptr, session_);
99     ssm_ = new SceneSessionManager();
100     session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
101     auto isScreenLockedCallback = [this]() {
102         return ssm_->IsScreenLocked();
103     };
104     session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
105 
106     mockSessionStage_ = new (std::nothrow) SessionStageMocker();
107     ASSERT_NE(mockSessionStage_, nullptr);
108 
109     mockEventChannel_ = new (std::nothrow) WindowEventChannelMocker(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 
GetTaskCount()130 int32_t WindowSessionTest2::GetTaskCount()
131 {
132     std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
133     std::regex pattern("\\d+");
134     std::smatch matches;
135     int32_t taskNum = 0;
136     while (std::regex_search(dumpInfo, matches, pattern)) {
137         taskNum += std::stoi(matches.str());
138         dumpInfo = matches.suffix();
139     }
140     return taskNum;
141 }
142 
143 namespace {
144 /**
145  * @tc.name: SetParentSession
146  * @tc.desc: SetParentSession Test
147  * @tc.type: FUNC
148  */
149 HWTEST_F(WindowSessionTest2, SetParentSession, Function | SmallTest | Level2)
150 {
151     ASSERT_NE(session_, nullptr);
152     SessionInfo info;
153     info.abilityName_ = "testSession1";
154     info.moduleName_ = "testSession2";
155     info.bundleName_ = "testSession3";
156     sptr<Session> session = new (std::nothrow) Session(info);
157     session_->SetParentSession(session);
158 
159     session_->property_ = new WindowSessionProperty();
160     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
161 }
162 
163 /**
164  * @tc.name: BindDialogToParentSession
165  * @tc.desc: BindDialogToParentSession Test
166  * @tc.type: FUNC
167  */
168 HWTEST_F(WindowSessionTest2, BindDialogToParentSession, Function | SmallTest | Level2)
169 {
170     ASSERT_NE(session_, nullptr);
171     SessionInfo info;
172     info.abilityName_ = "testSession1";
173     info.moduleName_ = "testSession2";
174     info.bundleName_ = "testSession3";
175     sptr<Session> session = new (std::nothrow) Session(info);
176     session_->BindDialogToParentSession(session);
177 
178     sptr<Session> session1 = new (std::nothrow) Session(info);
179     ASSERT_NE(session1, nullptr);
180     session1->persistentId_ = 33;
181     session1->SetParentSession(session_);
182     session1->state_ = SessionState::STATE_ACTIVE;
183     session_->dialogVec_.push_back(session1);
184 
185     sptr<Session> session2 = new (std::nothrow) Session(info);
186     ASSERT_NE(session2, nullptr);
187     session2->persistentId_ = 34;
188     session2->SetParentSession(session_);
189     session2->state_ = SessionState::STATE_ACTIVE;
190     session_->dialogVec_.push_back(session2);
191     session_->BindDialogToParentSession(session1);
192 
193     session_->property_ = new WindowSessionProperty();
194     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
195 }
196 
197 /**
198  * @tc.name: RemoveDialogToParentSession
199  * @tc.desc: RemoveDialogToParentSession Test
200  * @tc.type: FUNC
201  */
202 HWTEST_F(WindowSessionTest2, RemoveDialogToParentSession, Function | SmallTest | Level2)
203 {
204     ASSERT_NE(session_, nullptr);
205     SessionInfo info;
206     info.abilityName_ = "testSession1";
207     info.moduleName_ = "testSession2";
208     info.bundleName_ = "testSession3";
209     sptr<Session> session = new (std::nothrow) Session(info);
210     session_->RemoveDialogToParentSession(session);
211 
212     sptr<Session> session1 = new (std::nothrow) Session(info);
213     ASSERT_NE(session1, nullptr);
214     session1->persistentId_ = 33;
215     session1->SetParentSession(session_);
216     session1->state_ = SessionState::STATE_ACTIVE;
217     session_->dialogVec_.push_back(session1);
218 
219     sptr<Session> session2 = new (std::nothrow) Session(info);
220     ASSERT_NE(session2, nullptr);
221     session2->persistentId_ = 34;
222     session2->SetParentSession(session_);
223     session2->state_ = SessionState::STATE_ACTIVE;
224     session_->dialogVec_.push_back(session2);
225     session_->RemoveDialogToParentSession(session1);
226 
227     session_->property_ = new WindowSessionProperty();
228     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
229 }
230 
231 /**
232  * @tc.name: TransferPointerEvent01
233  * @tc.desc: !IsSystemSession() && !IsSessionValid() is true
234  * @tc.type: FUNC
235  */
236 HWTEST_F(WindowSessionTest2, TransferPointerEvent01, Function | SmallTest | Level2)
237 {
238     ASSERT_NE(session_, nullptr);
239 
240     session_->sessionInfo_.isSystem_ = false;
241     session_->state_ = SessionState::STATE_DISCONNECT;
242 
243     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
244     ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->TransferPointerEvent(pointerEvent));
245 }
246 
247 /**
248  * @tc.name: TransferPointerEvent02
249  * @tc.desc: pointerEvent is nullptr
250  * @tc.type: FUNC
251  */
252 HWTEST_F(WindowSessionTest2, TransferPointerEvent02, Function | SmallTest | Level2)
253 {
254     ASSERT_NE(session_, nullptr);
255     session_->sessionInfo_.isSystem_ = true;
256 
257     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
258     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
259 }
260 
261 /**
262  * @tc.name: TransferPointerEvent03
263  * @tc.desc: WindowType is WINDOW_TYPE_APP_MAIN_WINDOW, CheckDialogOnForeground() is true
264  * @tc.type: FUNC
265  */
266 HWTEST_F(WindowSessionTest2, TransferPointerEvent03, Function | SmallTest | Level2)
267 {
268     ASSERT_NE(session_, nullptr);
269 
270     session_->sessionInfo_.isSystem_ = true;
271 
272     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
273     ASSERT_NE(pointerEvent, nullptr);
274 
275     session_->property_ = new WindowSessionProperty();
276     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
277 
278     SessionInfo info;
279     info.abilityName_ = "dialogAbilityName";
280     info.moduleName_ = "dialogModuleName";
281     info.bundleName_ = "dialogBundleName";
282     sptr<Session> dialogSession = new (std::nothrow) Session(info);
283     ASSERT_NE(dialogSession, nullptr);
284     dialogSession->state_ = SessionState::STATE_ACTIVE;
285     session_->dialogVec_.push_back(dialogSession);
286 
287     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
288 }
289 
290 /**
291  * @tc.name: TransferPointerEvent04
292  * @tc.desc: parentSession_ && parentSession_->CheckDialogOnForeground() is true
293  * @tc.type: FUNC
294  */
295 HWTEST_F(WindowSessionTest2, TransferPointerEvent04, Function | SmallTest | Level2)
296 {
297     ASSERT_NE(session_, nullptr);
298 
299     session_->sessionInfo_.isSystem_ = true;
300 
301     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
302     ASSERT_NE(pointerEvent, nullptr);
303 
304     session_->property_ = new WindowSessionProperty();
305     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
306 
307     SessionInfo info;
308     info.abilityName_ = "dialogAbilityName";
309     info.moduleName_ = "dialogModuleName";
310     info.bundleName_ = "dialogBundleName";
311     sptr<Session> dialogSession = new (std::nothrow) Session(info);
312     ASSERT_NE(dialogSession, nullptr);
313     dialogSession->state_ = SessionState::STATE_ACTIVE;
314     session_->dialogVec_.push_back(dialogSession);
315     session_->parentSession_ = session_;
316 
317     ASSERT_EQ(WSError::WS_ERROR_INVALID_PERMISSION, session_->TransferPointerEvent(pointerEvent));
318 }
319 
320 /**
321  * @tc.name: TransferPointerEvent05
322  * @tc.desc: windowEventChannel_ is nullptr
323  * @tc.type: FUNC
324  */
325 HWTEST_F(WindowSessionTest2, TransferPointerEvent05, Function | SmallTest | Level2)
326 {
327     ASSERT_NE(session_, nullptr);
328 
329     session_->sessionInfo_.isSystem_ = true;
330 
331     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
332 
333     session_->property_ = new WindowSessionProperty();
334     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
335 
336     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
337 }
338 
339 /**
340  * @tc.name: TransferPointerEvent06
341  * @tc.desc: windowEventChannel_ is not nullptr
342  * @tc.type: FUNC
343  */
344 HWTEST_F(WindowSessionTest2, TransferPointerEvent06, Function | SmallTest | Level2)
345 {
346     ASSERT_NE(session_, nullptr);
347 
348     session_->sessionInfo_.isSystem_ = true;
349 
350     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
351     ASSERT_NE(pointerEvent, nullptr);
352 
353     session_->property_ = new WindowSessionProperty();
354     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
355     session_->windowEventChannel_ = mockEventChannel_;
356 
357     auto needNotifyClient = true;
358     session_->TransferPointerEvent(pointerEvent, needNotifyClient);
359 
360     needNotifyClient = false;
361     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
362     ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
363 
364     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
365     ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
366 
367     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
368     ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
369 
370     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
371     ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
372 
373     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW);
374     ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
375 
376     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW);
377     ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
378 }
379 
380 /**
381  * @tc.name: TransferKeyEvent01
382  * @tc.desc: !IsSystemSession() && !IsSessionValid() is true
383  * @tc.type: FUNC
384  */
385 HWTEST_F(WindowSessionTest2, TransferKeyEvent01, Function | SmallTest | Level2)
386 {
387     ASSERT_NE(session_, nullptr);
388 
389     session_->sessionInfo_.isSystem_ = false;
390     session_->state_ = SessionState::STATE_DISCONNECT;
391 
392     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
393     ASSERT_NE(keyEvent, nullptr);
394     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
395 
396     session_->windowEventChannel_ = mockEventChannel_;
397     ASSERT_EQ(WSError::WS_OK, session_->TransferKeyEvent(keyEvent));
398 }
399 
400 /**
401  * @tc.name: TransferKeyEvent02
402  * @tc.desc: keyEvent is nullptr
403  * @tc.type: FUNC
404  */
405 HWTEST_F(WindowSessionTest2, TransferKeyEvent02, Function | SmallTest | Level2)
406 {
407     ASSERT_NE(session_, nullptr);
408 
409     session_->sessionInfo_.isSystem_ = true;
410 
411     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
412     ASSERT_NE(keyEvent, nullptr);
413     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
414 }
415 
416 /**
417  * @tc.name: TransferKeyEvent03
418  * @tc.desc: WindowType is WINDOW_TYPE_APP_MAIN_WINDOW, CheckDialogOnForeground() is true
419  * @tc.type: FUNC
420  */
421 HWTEST_F(WindowSessionTest2, TransferKeyEvent03, Function | SmallTest | Level2)
422 {
423     ASSERT_NE(session_, nullptr);
424 
425     session_->sessionInfo_.isSystem_ = true;
426 
427     auto keyEvent = MMI::KeyEvent::Create();
428     ASSERT_NE(keyEvent, nullptr);
429 
430     session_->property_ = new WindowSessionProperty();
431     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
432 
433     SessionInfo info;
434     info.abilityName_ = "dialogAbilityName";
435     info.moduleName_ = "dialogModuleName";
436     info.bundleName_ = "dialogBundleName";
437     sptr<Session> dialogSession = new (std::nothrow) Session(info);
438     ASSERT_NE(dialogSession, nullptr);
439     dialogSession->state_ = SessionState::STATE_ACTIVE;
440     session_->dialogVec_.push_back(dialogSession);
441 
442     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
443 }
444 
445 /**
446  * @tc.name: TransferKeyEvent04
447  * @tc.desc: parentSession_ && parentSession_->CheckDialogOnForeground() is true
448  * @tc.type: FUNC
449  */
450 HWTEST_F(WindowSessionTest2, TransferKeyEvent04, Function | SmallTest | Level2)
451 {
452     ASSERT_NE(session_, nullptr);
453 
454     session_->sessionInfo_.isSystem_ = true;
455 
456     auto keyEvent = MMI::KeyEvent::Create();
457     ASSERT_NE(keyEvent, nullptr);
458 
459     session_->property_ = new WindowSessionProperty();
460     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
461 
462     SessionInfo info;
463     info.abilityName_ = "dialogAbilityName";
464     info.moduleName_ = "dialogModuleName";
465     info.bundleName_ = "dialogBundleName";
466     sptr<Session> dialogSession = new (std::nothrow) Session(info);
467     ASSERT_NE(dialogSession, nullptr);
468     dialogSession->state_ = SessionState::STATE_ACTIVE;
469     session_->dialogVec_.push_back(dialogSession);
470     session_->parentSession_ = session_;
471 
472     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
473 }
474 
475 /**
476  * @tc.name: TransferKeyEvent05
477  * @tc.desc: windowEventChannel_ is nullptr
478  * @tc.type: FUNC
479  */
480 HWTEST_F(WindowSessionTest2, TransferKeyEvent05, Function | SmallTest | Level2)
481 {
482     ASSERT_NE(session_, nullptr);
483 
484     session_->sessionInfo_.isSystem_ = true;
485 
486     auto keyEvent = MMI::KeyEvent::Create();
487     ASSERT_NE(keyEvent, nullptr);
488 
489     session_->property_ = new WindowSessionProperty();
490     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
491 
492     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
493 }
494 
495 /**
496  * @tc.name: TransferBackPressedEventForConsumed01
497  * @tc.desc: windowEventChannel_ is nullptr
498  * @tc.type: FUNC
499  */
500 HWTEST_F(WindowSessionTest2, TransferBackPressedEventForConsumed01, Function | SmallTest | Level2)
501 {
502     ASSERT_NE(session_, nullptr);
503 
504     session_->windowEventChannel_ = nullptr;
505 
506     bool isConsumed = false;
507     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferBackPressedEventForConsumed(isConsumed));
508 }
509 
510 /**
511  * @tc.name: TransferKeyEventForConsumed01
512  * @tc.desc: windowEventChannel_ is nullptr
513  * @tc.type: FUNC
514  */
515 HWTEST_F(WindowSessionTest2, TransferKeyEventForConsumed01, Function | SmallTest | Level2)
516 {
517     ASSERT_NE(session_, nullptr);
518 
519     session_->windowEventChannel_ = nullptr;
520 
521     auto keyEvent = MMI::KeyEvent::Create();
522     bool isConsumed = false;
523     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEventForConsumed(keyEvent, isConsumed));
524 }
525 
526 /**
527  * @tc.name: TransferFocusActiveEvent01
528  * @tc.desc: windowEventChannel_ is nullptr
529  * @tc.type: FUNC
530  */
531 HWTEST_F(WindowSessionTest2, TransferFocusActiveEvent01, Function | SmallTest | Level2)
532 {
533     ASSERT_NE(session_, nullptr);
534 
535     session_->windowEventChannel_ = nullptr;
536 
537     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferFocusActiveEvent(false));
538 }
539 
540 /**
541  * @tc.name: TransferFocusStateEvent01
542  * @tc.desc: windowEventChannel_ is nullptr
543  * @tc.type: FUNC
544  */
545 HWTEST_F(WindowSessionTest2, TransferFocusStateEvent01, Function | SmallTest | Level2)
546 {
547     ASSERT_NE(session_, nullptr);
548 
549     session_->windowEventChannel_ = nullptr;
550 
551     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferFocusStateEvent(false));
552 }
553 
554 /**
555  * @tc.name: Snapshot01
556  * @tc.desc: ret is false
557  * @tc.type: FUNC
558  */
559 HWTEST_F(WindowSessionTest2, Snapshot01, Function | SmallTest | Level2)
560 {
561     ASSERT_NE(session_, nullptr);
562 
563     session_->surfaceNode_ = nullptr;
564 
565     ASSERT_EQ(nullptr, session_->Snapshot());
566 }
567 
568 /**
569  * @tc.name: ResetSnapshot
570  * @tc.desc: ResetSnapshot Test
571  * @tc.type: FUNC
572  */
573 HWTEST_F(WindowSessionTest2, ResetSnapshot, Function | SmallTest | Level2)
574 {
575     ASSERT_NE(session_, nullptr);
576     std::string bundleName = "testBundleName";
577     int32_t persistentId = 1423;
578     session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
579     session_->snapshot_ = std::make_shared<Media::PixelMap>();
580 
581     session_->ResetSnapshot();
582     ASSERT_EQ(nullptr, session_->snapshot_);
583 }
584 
585 /**
586  * @tc.name: SaveSnapshot
587  * @tc.desc: SaveSnapshot Test
588  * @tc.type: FUNC
589  */
590 HWTEST_F(WindowSessionTest2, SaveSnapshot, Function | SmallTest | Level2)
591 {
592     ASSERT_NE(session_, nullptr);
593 
594     session_->scenePersistence_ = nullptr;
595     session_->snapshot_ = nullptr;
596     session_->SaveSnapshot(true);
597     EXPECT_EQ(session_->snapshot_, nullptr);
598 
599     session_->scenePersistence_ = new ScenePersistence(session_->sessionInfo_.bundleName_, session_->persistentId_);
600 
601     session_->SaveSnapshot(false);
602     ASSERT_EQ(session_->snapshot_, nullptr);
603 
604     session_->SaveSnapshot(true);
605     ASSERT_EQ(session_->snapshot_, nullptr);
606 }
607 
608 /**
609  * @tc.name: SetSessionStateChangeListenser
610  * @tc.desc: SetSessionStateChangeListenser Test
611  * @tc.type: FUNC
612  */
613 HWTEST_F(WindowSessionTest2, SetSessionStateChangeListenser, Function | SmallTest | Level2)
614 {
615     ASSERT_NE(session_, nullptr);
616 
617     NotifySessionStateChangeFunc func = nullptr;
618     session_->SetSessionStateChangeListenser(func);
619 
620     session_->state_ = SessionState::STATE_DISCONNECT;
621     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
622 }
623 
624 /**
625  * @tc.name: SetSessionFocusableChangeListener
626  * @tc.desc: SetSessionFocusableChangeListener Test
627  * @tc.type: FUNC
628  */
629 HWTEST_F(WindowSessionTest2, SetSessionFocusableChangeListener, Function | SmallTest | Level2)
630 {
631     ASSERT_NE(session_, nullptr);
632 
633     NotifySessionFocusableChangeFunc func = [](const bool isFocusable)
__anon8603b9f10402(const bool isFocusable) 634     {
635     };
636     session_->SetSessionFocusableChangeListener(func);
637 
638     session_->state_ = SessionState::STATE_DISCONNECT;
639     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
640 }
641 
642 /**
643  * @tc.name: SetSessionTouchableChangeListener
644  * @tc.desc: SetSessionTouchableChangeListener Test
645  * @tc.type: FUNC
646  */
647 HWTEST_F(WindowSessionTest2, SetSessionTouchableChangeListener, Function | SmallTest | Level2)
648 {
649     ASSERT_NE(session_, nullptr);
650 
651     NotifySessionTouchableChangeFunc func = [](const bool touchable)
__anon8603b9f10502(const bool touchable) 652     {
653     };
654     session_->SetSessionTouchableChangeListener(func);
655 
656     session_->state_ = SessionState::STATE_DISCONNECT;
657     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
658 }
659 
660 /**
661  * @tc.name: SetSessionInfoLockedStateChangeListener
662  * @tc.desc: SetSessionInfoLockedStateChangeListener Test
663  * @tc.type: FUNC
664  */
665 HWTEST_F(WindowSessionTest2, SetSessionInfoLockedStateChangeListener, Function | SmallTest | Level2)
666 {
667     ASSERT_NE(session_, nullptr);
668 
669     NotifySessionTouchableChangeFunc func = [](const bool lockedState)
__anon8603b9f10602(const bool lockedState) 670     {
671     };
672     session_->SetSessionInfoLockedStateChangeListener(func);
673 
674     session_->SetSessionInfoLockedState(true);
675     ASSERT_EQ(true, session_->sessionInfo_.lockedState);
676 }
677 
678 /**
679  * @tc.name: SetClickListener
680  * @tc.desc: SetClickListener Test
681  * @tc.type: FUNC
682  */
683 HWTEST_F(WindowSessionTest2, SetClickListener, Function | SmallTest | Level2)
684 {
685     ASSERT_NE(session_, nullptr);
686 
687     NotifyClickFunc func = nullptr;
688     session_->SetClickListener(func);
689 
690     session_->state_ = SessionState::STATE_DISCONNECT;
691     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
692 }
693 
694 /**
695  * @tc.name: UpdateFocus01
696  * @tc.desc: isFocused_ equal isFocused
697  * @tc.type: FUNC
698  */
699 HWTEST_F(WindowSessionTest2, UpdateFocus01, Function | SmallTest | Level2)
700 {
701     ASSERT_NE(session_, nullptr);
702 
703     bool isFocused = session_->isFocused_;
704     ASSERT_EQ(WSError::WS_DO_NOTHING, session_->UpdateFocus(isFocused));
705 }
706 
707 /**
708  * @tc.name: UpdateFocus02
709  * @tc.desc: isFocused_ not equal isFocused, IsSessionValid() return false
710  * @tc.type: FUNC
711  */
712 HWTEST_F(WindowSessionTest2, UpdateFocus02, Function | SmallTest | Level2)
713 {
714     ASSERT_NE(session_, nullptr);
715 
716     session_->sessionInfo_.isSystem_ = true;
717 
718     bool isFocused = session_->isFocused_;
719     ASSERT_EQ(WSError::WS_OK, session_->UpdateFocus(!isFocused));
720 }
721 
722 /**
723  * @tc.name: UpdateWindowMode01
724  * @tc.desc: IsSessionValid() return false
725  * @tc.type: FUNC
726  */
727 HWTEST_F(WindowSessionTest2, UpdateWindowMode01, Function | SmallTest | Level2)
728 {
729     ASSERT_NE(session_, nullptr);
730 
731     session_->property_ = nullptr;
732 
733     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED));
734 }
735 
736 /**
737  * @tc.name: NotifyForegroundInteractiveStatus
738  * @tc.desc: NotifyForegroundInteractiveStatus Test
739  * @tc.type: FUNC
740  */
741 HWTEST_F(WindowSessionTest2, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
742 {
743     ASSERT_NE(session_, nullptr);
744     int res = 0;
745     session_->sessionStage_ = nullptr;
746     bool interactive = true;
747     session_->NotifyForegroundInteractiveStatus(interactive);
748 
749     sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
750     ASSERT_NE(mockSessionStage, nullptr);
751     session_->sessionStage_ = mockSessionStage;
752     session_->state_ = SessionState::STATE_FOREGROUND;
753     interactive = false;
754     session_->NotifyForegroundInteractiveStatus(interactive);
755     ASSERT_EQ(0, res);
756 }
757 
758 /**
759  * @tc.name: SetEventHandler001
760  * @tc.desc: SetEventHandler Test
761  * @tc.type: FUNC
762  */
763 HWTEST_F(WindowSessionTest2, SetEventHandler001, Function | SmallTest | Level2)
764 {
765     ASSERT_NE(session_, nullptr);
766     int res = 0;
767     std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
768     session_->SetEventHandler(handler);
769     ASSERT_EQ(res, 0);
770 }
771 
772 /**
773  * @tc.name: PostTask002
774  * @tc.desc: PostTask Test
775  * @tc.type: FUNC
776  */
777 HWTEST_F(WindowSessionTest2, PostTask002, Function | SmallTest | Level2)
778 {
779     ASSERT_NE(session_, nullptr);
780     int32_t persistentId = 0;
781     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
782     if (property == nullptr) {
783         return;
784     }
785     property->SetPersistentId(persistentId);
786     int32_t res = session_->GetPersistentId();
787     ASSERT_EQ(res, 0);
788 }
789 
790 /**
791  * @tc.name: GetSurfaceNode
792  * @tc.desc: GetSurfaceNode Test
793  * @tc.type: FUNC
794  */
795 HWTEST_F(WindowSessionTest2, GetSurfaceNode, Function | SmallTest | Level2)
796 {
797     ASSERT_NE(session_, nullptr);
798     session_->surfaceNode_ = nullptr;
799     std::shared_ptr<RSSurfaceNode> res = session_->GetSurfaceNode();
800     ASSERT_EQ(res, nullptr);
801 }
802 
803 /**
804  * @tc.name: GetLeashWinSurfaceNode
805  * @tc.desc: GetLeashWinSurfaceNode Test
806  * @tc.type: FUNC
807  */
808 HWTEST_F(WindowSessionTest2, GetLeashWinSurfaceNode, Function | SmallTest | Level2)
809 {
810     ASSERT_NE(session_, nullptr);
811     session_->leashWinSurfaceNode_ = nullptr;
812     std::shared_ptr<RSSurfaceNode> res = session_->GetLeashWinSurfaceNode();
813     ASSERT_EQ(res, nullptr);
814 }
815 
816 /**
817  * @tc.name: SetSessionInfoAncoSceneState
818  * @tc.desc: SetSessionInfoAncoSceneState Test
819  * @tc.type: FUNC
820  */
821 HWTEST_F(WindowSessionTest2, SetSessionInfoAncoSceneState, Function | SmallTest | Level2)
822 {
823     ASSERT_NE(session_, nullptr);
824     int res = 0;
825     int32_t ancoSceneState = 0;
826     session_->SetSessionInfoAncoSceneState(ancoSceneState);
827     ASSERT_EQ(res, 0);
828 }
829 
830 /**
831  * @tc.name: SetSessionInfoTime
832  * @tc.desc: SetSessionInfoTime Test
833  * @tc.type: FUNC
834  */
835 HWTEST_F(WindowSessionTest2, SetSessionInfoTime, Function | SmallTest | Level2)
836 {
837     ASSERT_NE(session_, nullptr);
838     int res = 0;
839     std::string time = "";
840     session_->SetSessionInfoTime(time);
841     ASSERT_EQ(res, 0);
842 }
843 
844 /**
845  * @tc.name: SetSessionInfoAbilityInfo
846  * @tc.desc: SetSessionInfoAbilityInfo Test
847  * @tc.type: FUNC
848  */
849 HWTEST_F(WindowSessionTest2, SetSessionInfoAbilityInfo, Function | SmallTest | Level2)
850 {
851     ASSERT_NE(session_, nullptr);
852     int res = 0;
853     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
854     session_->SetSessionInfoAbilityInfo(abilityInfo);
855     ASSERT_EQ(res, 0);
856 }
857 
858 /**
859  * @tc.name: SetSessionInfoWant
860  * @tc.desc: SetSessionInfoWant Test
861  * @tc.type: FUNC
862  */
863 HWTEST_F(WindowSessionTest2, SetSessionInfoWant, Function | SmallTest | Level2)
864 {
865     ASSERT_NE(session_, nullptr);
866     int res = 0;
867     std::shared_ptr<AAFwk::Want> want = nullptr;
868     session_->SetSessionInfoWant(want);
869     ASSERT_EQ(res, 0);
870 }
871 
872 /**
873  * @tc.name: SetSessionInfoProcessOptions
874  * @tc.desc: SetSessionInfoProcessOptions Test
875  * @tc.type: FUNC
876  */
877 HWTEST_F(WindowSessionTest2, SetSessionInfoProcessOptions, Function | SmallTest | Level2)
878 {
879     ASSERT_NE(session_, nullptr);
880     std::shared_ptr<AAFwk::ProcessOptions> processOptions = std::make_shared<AAFwk::ProcessOptions>();
881     session_->SetSessionInfoProcessOptions(processOptions);
882     ASSERT_EQ(processOptions, session_->sessionInfo_.processOptions);
883 }
884 
885 /**
886  * @tc.name: SetSessionInfoPersistentId
887  * @tc.desc: SetSessionInfoPersistentId Test
888  * @tc.type: FUNC
889  */
890 HWTEST_F(WindowSessionTest2, SetSessionInfoPersistentId, Function | SmallTest | Level2)
891 {
892     ASSERT_NE(session_, nullptr);
893     int res = 0;
894     int32_t persistentId = 0;
895     session_->SetSessionInfoPersistentId(persistentId);
896     ASSERT_EQ(res, 0);
897 }
898 
899 /**
900  * @tc.name: SetSessionInfoCallerPersistentId
901  * @tc.desc: SetSessionInfoCallerPersistentId Test
902  * @tc.type: FUNC
903  */
904 HWTEST_F(WindowSessionTest2, SetSessionInfoCallerPersistentId, Function | SmallTest | Level2)
905 {
906     ASSERT_NE(session_, nullptr);
907     int res = 0;
908     int32_t callerPersistentId = 0;
909     session_->SetSessionInfoCallerPersistentId(callerPersistentId);
910     ASSERT_EQ(res, 0);
911 }
912 
913 /**
914  * @tc.name: PostExportTask
915  * @tc.desc: PostExportTask Test
916  * @tc.type: FUNC
917  */
918 HWTEST_F(WindowSessionTest2, PostExportTask, Function | SmallTest | Level2)
919 {
920     ASSERT_NE(session_, nullptr);
921     int32_t persistentId = 0;
922     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
923     if (property == nullptr) {
924         return;
925     }
926     property->SetPersistentId(persistentId);
927     int32_t ret = session_->GetPersistentId();
928     ASSERT_EQ(ret, 0);
929 }
930 
931 /**
932  * @tc.name: GetPersistentId
933  * @tc.desc: GetPersistentId Test
934  * @tc.type: FUNC
935  */
936 HWTEST_F(WindowSessionTest2, GetPersistentId, Function | SmallTest | Level2)
937 {
938     ASSERT_NE(session_, nullptr);
939     int32_t persistentId = 0;
940     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
941     if (property == nullptr) {
942         return;
943     }
944     property->SetPersistentId(persistentId);
945     int32_t ret = session_->GetPersistentId();
946     ASSERT_EQ(ret, 0);
947 }
948 
949 /**
950  * @tc.name: SetLeashWinSurfaceNode
951  * @tc.desc: SetLeashWinSurfaceNode Test
952  * @tc.type: FUNC
953  */
954 HWTEST_F(WindowSessionTest2, SetLeashWinSurfaceNode, Function | SmallTest | Level2)
955 {
956     ASSERT_NE(session_, nullptr);
957     auto leashWinSurfaceNode = WindowSessionTest2::CreateRSSurfaceNode();
958     session_->SetLeashWinSurfaceNode(leashWinSurfaceNode);
959     ASSERT_EQ(session_->leashWinSurfaceNode_, leashWinSurfaceNode);
960 }
961 
962 /**
963  * @tc.name: SetSessionInfoContinueState
964  * @tc.desc: SetSessionInfoContinueState Test
965  * @tc.type: FUNC
966  */
967 HWTEST_F(WindowSessionTest2, SetSessionInfoContinueState, Function | SmallTest | Level2)
968 {
969     ASSERT_NE(session_, nullptr);
970     enum ContinueState state = CONTINUESTATE_UNKNOWN;
971     session_->SetSessionInfoContinueState(state);
972     ASSERT_EQ(session_->sessionInfo_.continueState, state);
973 }
974 
975 /**
976  * @tc.name: SetSessionInfoIsClearSession01
977  * @tc.desc: SetSessionInfoIsClearSession return false
978  * @tc.type: FUNC
979  */
980 HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession01, Function | SmallTest | Level2)
981 {
982     ASSERT_NE(session_, nullptr);
983     session_->SetSessionInfoIsClearSession(false);
984     ASSERT_EQ(false, session_->sessionInfo_.isClearSession);
985 }
986 
987 /**
988  * @tc.name: SetSessionInfoIsClearSession02
989  * @tc.desc: SetSessionInfoIsClearSession return true
990  * @tc.type: FUNC
991  */
992 HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession02, Function | SmallTest | Level2)
993 {
994     ASSERT_NE(session_, nullptr);
995     session_->SetSessionInfoIsClearSession(true);
996     ASSERT_EQ(true, session_->sessionInfo_.isClearSession);
997 }
998 
999 /**
1000  * @tc.name: SetSessionInfoAffinity
1001  * @tc.desc: SetSessionInfoAffinity
1002  * @tc.type: FUNC
1003  */
1004 HWTEST_F(WindowSessionTest2, SetSessionInfoAffinity, Function | SmallTest | Level2)
1005 {
1006     ASSERT_NE(session_, nullptr);
1007     std::string affinity = "setSessionIofoAffinity";
1008     session_->SetSessionInfoAffinity(affinity);
1009     ASSERT_EQ(affinity, session_->sessionInfo_.sessionAffinity);
1010 }
1011 
1012 /**
1013  * @tc.name: SetSessionInfo
1014  * @tc.desc: SetSessionInfo
1015  * @tc.type: FUNC
1016  */
1017 HWTEST_F(WindowSessionTest2, SetSessionInfo, Function | SmallTest | Level2)
1018 {
1019     ASSERT_NE(session_, nullptr);
1020     SessionInfo info;
1021     info.want = nullptr;
1022     info.callerToken_ = nullptr;
1023     info.requestCode = 1;
1024     info.callerPersistentId_ = 1;
1025     info.callingTokenId_ = 1;
1026     info.uiAbilityId_ = 1;
1027     info.startSetting = nullptr;
1028     info.continueSessionId_ = "";
1029     session_->SetSessionInfo(info);
1030     ASSERT_EQ(nullptr, session_->sessionInfo_.want);
1031     ASSERT_EQ(nullptr, session_->sessionInfo_.callerToken_);
1032     ASSERT_EQ(1, session_->sessionInfo_.requestCode);
1033     ASSERT_EQ(1, session_->sessionInfo_.callerPersistentId_);
1034     ASSERT_EQ(1, session_->sessionInfo_.callingTokenId_);
1035     ASSERT_EQ(1, session_->sessionInfo_.uiAbilityId_);
1036     ASSERT_EQ("", session_->sessionInfo_.continueSessionId_);
1037     ASSERT_EQ(nullptr, session_->sessionInfo_.startSetting);
1038 }
1039 
1040 /**
1041  * @tc.name: SetScreenId
1042  * @tc.desc: SetScreenId
1043  * @tc.type: FUNC
1044  */
1045 HWTEST_F(WindowSessionTest2, SetScreenId, Function | SmallTest | Level2)
1046 {
1047     ASSERT_NE(session_, nullptr);
1048     uint64_t screenId = 0;
1049     session_->SetScreenId(screenId);
1050     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1051 }
1052 
1053 /**
1054  * @tc.name: RegisterLifecycleListener
1055  * @tc.desc: RegisterLifecycleListener
1056  * @tc.type: FUNC
1057  */
1058 HWTEST_F(WindowSessionTest2, RegisterLifecycleListener, Function | SmallTest | Level2)
1059 {
1060     ASSERT_NE(session_, nullptr);
1061     const std::shared_ptr<ILifecycleListener>& listener = nullptr;
1062     bool ret = session_->RegisterLifecycleListener(listener);
1063     ASSERT_EQ(false, ret);
1064 }
1065 
1066 /**
1067  * @tc.name: UnregisterLifecycleListener
1068  * @tc.desc: UnregisterLifecycleListener
1069  * @tc.type: FUNC
1070  */
1071 HWTEST_F(WindowSessionTest2, UnregisterLifecycleListener, Function | SmallTest | Level2)
1072 {
1073     ASSERT_NE(session_, nullptr);
1074     const std::shared_ptr<ILifecycleListener>& listener = nullptr;
1075     bool ret = session_->UnregisterLifecycleListener(listener);
1076     ASSERT_EQ(false, ret);
1077 }
1078 
1079 /**
1080  * @tc.name: NotifyActivation02
1081  * @tc.desc: NotifyActivation
1082  * @tc.type: FUNC
1083  */
1084 HWTEST_F(WindowSessionTest2, NotifyActivation02, Function | SmallTest | Level2)
1085 {
1086     ASSERT_NE(session_, nullptr);
1087     session_->NotifyActivation();
1088     uint64_t screenId = 0;
1089     session_->SetScreenId(screenId);
1090     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1091 }
1092 
1093 /**
1094  * @tc.name: NotifyConnect
1095  * @tc.desc: NotifyConnect
1096  * @tc.type: FUNC
1097  */
1098 HWTEST_F(WindowSessionTest2, NotifyConnect, Function | SmallTest | Level2)
1099 {
1100     ASSERT_NE(session_, nullptr);
1101     session_->NotifyConnect();
1102     uint64_t screenId = 0;
1103     session_->SetScreenId(screenId);
1104     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1105 }
1106 
1107 /**
1108  * @tc.name: NotifyForeground02
1109  * @tc.desc: NotifyForeground
1110  * @tc.type: FUNC
1111  */
1112 HWTEST_F(WindowSessionTest2, NotifyForeground02, Function | SmallTest | Level2)
1113 {
1114     ASSERT_NE(session_, nullptr);
1115     session_->NotifyForeground();
1116     uint64_t screenId = 0;
1117     session_->SetScreenId(screenId);
1118     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1119 }
1120 
1121 /**
1122  * @tc.name: NotifyBackground02
1123  * @tc.desc: NotifyBackground
1124  * @tc.type: FUNC
1125  */
1126 HWTEST_F(WindowSessionTest2, NotifyBackground02, Function | SmallTest | Level2)
1127 {
1128     ASSERT_NE(session_, nullptr);
1129     session_->NotifyBackground();
1130     uint64_t screenId = 0;
1131     session_->SetScreenId(screenId);
1132     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1133 }
1134 
1135 /**
1136  * @tc.name: NotifyDisconnect
1137  * @tc.desc: NotifyDisconnect
1138  * @tc.type: FUNC
1139  */
1140 HWTEST_F(WindowSessionTest2, NotifyDisconnect, Function | SmallTest | Level2)
1141 {
1142     ASSERT_NE(session_, nullptr);
1143     session_->NotifyDisconnect();
1144     uint64_t screenId = 0;
1145     session_->SetScreenId(screenId);
1146     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1147 }
1148 
1149 /**
1150  * @tc.name: NotifyExtensionDied02
1151  * @tc.desc: NotifyExtensionDied
1152  * @tc.type: FUNC
1153  */
1154 HWTEST_F(WindowSessionTest2, NotifyExtensionDied02, Function | SmallTest | Level2)
1155 {
1156     ASSERT_NE(session_, nullptr);
1157     session_->NotifyExtensionDied();
1158 
1159     session_->RegisterLifecycleListener(lifecycleListener_);
1160     session_->NotifyExtensionDied();
1161     uint64_t screenId = 0;
1162     session_->SetScreenId(screenId);
1163     session_->UnregisterLifecycleListener(lifecycleListener_);
1164     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1165 }
1166 
1167 /**
1168  * @tc.name: NotifyTransferAccessibilityEvent
1169  * @tc.desc: NotifyTransferAccessibilityEvent
1170  * @tc.type: FUNC
1171  */
1172 HWTEST_F(WindowSessionTest2, NotifyTransferAccessibilityEvent, Function | SmallTest | Level2)
1173 {
1174     ASSERT_NE(session_, nullptr);
1175     OHOS::Accessibility::AccessibilityEventInfo info1;
1176     int64_t uiExtensionIdLevel = 6;
1177     session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1178 
1179     session_->RegisterLifecycleListener(lifecycleListener_);
1180     session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1181     uint64_t screenId = 0;
1182     session_->SetScreenId(screenId);
1183     session_->UnregisterLifecycleListener(lifecycleListener_);
1184     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1185 }
1186 
1187 /**
1188  * @tc.name: GetAspectRatio
1189  * @tc.desc: GetAspectRatio
1190  * @tc.type: FUNC
1191  */
1192 HWTEST_F(WindowSessionTest2, GetAspectRatio, Function | SmallTest | Level2)
1193 {
1194     ASSERT_NE(session_, nullptr);
1195     float ret = session_->aspectRatio_;
1196     float res = 0.0f;
1197     ASSERT_EQ(ret, res);
1198 }
1199 
1200 /**
1201  * @tc.name: SetAspectRatio02
1202  * @tc.desc: SetAspectRatio
1203  * @tc.type: FUNC
1204  */
1205 HWTEST_F(WindowSessionTest2, SetAspectRatio02, Function | SmallTest | Level2)
1206 {
1207     ASSERT_NE(session_, nullptr);
1208     float radio = 2.0f;
1209     WSError ERR = session_->SetAspectRatio(radio);
1210     float ret = session_->aspectRatio_;
1211     ASSERT_EQ(ret, radio);
1212     ASSERT_EQ(ERR, WSError::WS_OK);
1213 }
1214 
1215 /**
1216  * @tc.name: GetSessionState
1217  * @tc.desc: GetSessionState
1218  * @tc.type: FUNC
1219  */
1220 HWTEST_F(WindowSessionTest2, GetSessionState, Function | SmallTest | Level2)
1221 {
1222     ASSERT_NE(session_, nullptr);
1223     SessionState state = session_->GetSessionState();
1224     ASSERT_EQ(state, session_->state_);
1225 }
1226 
1227 /**
1228  * @tc.name: SetSessionState02
1229  * @tc.desc: SetSessionState
1230  * @tc.type: FUNC
1231  */
1232 HWTEST_F(WindowSessionTest2, SetSessionState02, Function | SmallTest | Level2)
1233 {
1234     ASSERT_NE(session_, nullptr);
1235     SessionState state = SessionState::STATE_CONNECT;
1236     session_->SetSessionState(state);
1237     ASSERT_EQ(state, session_->state_);
1238 }
1239 
1240 /**
1241  * @tc.name: SetChangeSessionVisibilityWithStatusBarEventListener
1242  * @tc.desc: SetChangeSessionVisibilityWithStatusBarEventListener Test
1243  * @tc.type: FUNC
1244  */
1245 HWTEST_F(WindowSessionTest2, SetChangeSessionVisibilityWithStatusBarEventListener, Function | SmallTest | Level2)
1246 {
1247     int resultValue = 0;
__anon8603b9f10702(SessionInfo& info, const bool visible) 1248     NotifyChangeSessionVisibilityWithStatusBarFunc func1 = [&resultValue](SessionInfo& info, const bool visible) {
1249         resultValue = 1;
1250     };
__anon8603b9f10802(SessionInfo& info, const bool visible) 1251     NotifyChangeSessionVisibilityWithStatusBarFunc func2 = [&resultValue](SessionInfo& info, const bool visible) {
1252         resultValue = 2;
1253     };
1254 
1255     session_->SetChangeSessionVisibilityWithStatusBarEventListener(func1);
1256     ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1257 
1258     SessionInfo info;
1259     session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1260     ASSERT_EQ(resultValue, 1);
1261 
1262     session_->SetChangeSessionVisibilityWithStatusBarEventListener(func2);
1263     ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1264     session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1265     ASSERT_EQ(resultValue, 2);
1266 }
1267 
1268 /**
1269  * @tc.name: UpdateSessionState
1270  * @tc.desc: UpdateSessionState
1271  * @tc.type: FUNC
1272  */
1273 HWTEST_F(WindowSessionTest2, UpdateSessionState, Function | SmallTest | Level2)
1274 {
1275     ASSERT_NE(session_, nullptr);
1276     SessionState state = SessionState::STATE_CONNECT;
1277     session_->UpdateSessionState(state);
1278     ASSERT_EQ(session_->state_, SessionState::STATE_CONNECT);
1279 }
1280 
1281 /**
1282  * @tc.name: GetTouchable
1283  * @tc.desc: GetTouchable
1284  * @tc.type: FUNC
1285  */
1286 HWTEST_F(WindowSessionTest2, GetTouchable, Function | SmallTest | Level2)
1287 {
1288     ASSERT_NE(session_, nullptr);
1289     bool res = session_->GetTouchable();
1290     ASSERT_EQ(true, res);
1291 }
1292 
1293 /**
1294  * @tc.name: SetSystemTouchable
1295  * @tc.desc: SetSystemTouchable
1296  * @tc.type: FUNC
1297  */
1298 HWTEST_F(WindowSessionTest2, SetSystemTouchable, Function | SmallTest | Level2)
1299 {
1300     ASSERT_NE(session_, nullptr);
1301     bool touchable = false;
1302     session_->SetSystemTouchable(touchable);
1303     ASSERT_EQ(session_->systemTouchable_, touchable);
1304 }
1305 
1306 /**
1307  * @tc.name: GetSystemTouchable
1308  * @tc.desc: GetSystemTouchable
1309  * @tc.type: FUNC
1310  */
1311 HWTEST_F(WindowSessionTest2, GetSystemTouchable, Function | SmallTest | Level2)
1312 {
1313     ASSERT_NE(session_, nullptr);
1314     bool res = session_->GetSystemTouchable();
1315     ASSERT_EQ(res, true);
1316 }
1317 
1318 /**
1319  * @tc.name: SetRSVisible
1320  * @tc.desc: SetRSVisible
1321  * @tc.type: FUNC
1322  */
1323 HWTEST_F(WindowSessionTest2, SetVisible, Function | SmallTest | Level2)
1324 {
1325     ASSERT_NE(session_, nullptr);
1326     bool isVisible = false;
1327     ASSERT_EQ(WSError::WS_OK, session_->SetRSVisible(isVisible));
1328 }
1329 
1330 /**
1331  * @tc.name: GetRSVisible02
1332  * @tc.desc: GetRSVisible
1333  * @tc.type: FUNC
1334  */
1335 HWTEST_F(WindowSessionTest2, GetVisible02, Function | SmallTest | Level2)
1336 {
1337     ASSERT_NE(session_, nullptr);
1338     if (!session_->GetRSVisible()) {
1339         ASSERT_EQ(false, session_->GetRSVisible());
1340     }
1341 }
1342 
1343 /**
1344  * @tc.name: SetVisibilityState
1345  * @tc.desc: SetVisibilityState
1346  * @tc.type: FUNC
1347  */
1348 HWTEST_F(WindowSessionTest2, SetVisibilityState, Function | SmallTest | Level2)
1349 {
1350     ASSERT_NE(session_, nullptr);
1351     WindowVisibilityState state { WINDOW_VISIBILITY_STATE_NO_OCCLUSION};
1352     ASSERT_EQ(WSError::WS_OK, session_->SetVisibilityState(state));
1353     ASSERT_EQ(state, session_->visibilityState_);
1354 }
1355 
1356 /**
1357  * @tc.name: GetVisibilityState
1358  * @tc.desc: GetVisibilityState
1359  * @tc.type: FUNC
1360  */
1361 HWTEST_F(WindowSessionTest2, GetVisibilityState, Function | SmallTest | Level2)
1362 {
1363     ASSERT_NE(session_, nullptr);
1364     WindowVisibilityState state { WINDOW_LAYER_STATE_MAX};
1365     ASSERT_EQ(state, session_->GetVisibilityState());
1366 }
1367 
1368 /**
1369  * @tc.name: SetDrawingContentState
1370  * @tc.desc: SetDrawingContentState
1371  * @tc.type: FUNC
1372  */
1373 HWTEST_F(WindowSessionTest2, SetDrawingContentState, Function | SmallTest | Level2)
1374 {
1375     ASSERT_NE(session_, nullptr);
1376     bool isRSDrawing = false;
1377     ASSERT_EQ(WSError::WS_OK, session_->SetDrawingContentState(isRSDrawing));
1378     ASSERT_EQ(false, session_->isRSDrawing_);
1379 }
1380 
1381 /**
1382  * @tc.name: GetDrawingContentState
1383  * @tc.desc: GetDrawingContentState
1384  * @tc.type: FUNC
1385  */
1386 HWTEST_F(WindowSessionTest2, GetDrawingContentState, Function | SmallTest | Level2)
1387 {
1388     ASSERT_NE(session_, nullptr);
1389     bool res = session_->GetDrawingContentState();
1390     ASSERT_EQ(res, false);
1391 }
1392 
1393 /**
1394  * @tc.name: GetBrightness
1395  * @tc.desc: GetBrightness
1396  * @tc.type: FUNC
1397  */
1398 HWTEST_F(WindowSessionTest2, GetBrightness, Function | SmallTest | Level2)
1399 {
1400     ASSERT_NE(session_, nullptr);
1401     session_->state_ = SessionState::STATE_DISCONNECT;
1402     session_->property_ = nullptr;
1403     ASSERT_EQ(UNDEFINED_BRIGHTNESS, session_->GetBrightness());
1404 }
1405 
1406 /**
1407  * @tc.name: IsActive02
1408  * @tc.desc: IsActive
1409  * @tc.type: FUNC
1410  */
1411 HWTEST_F(WindowSessionTest2, IsActive02, Function | SmallTest | Level2)
1412 {
1413     ASSERT_NE(session_, nullptr);
1414     bool res = session_->IsActive();
1415     ASSERT_EQ(res, false);
1416 }
1417 
1418 /**
1419  * @tc.name: IsSystemSession
1420  * @tc.desc: IsSystemSession
1421  * @tc.type: FUNC
1422  */
1423 HWTEST_F(WindowSessionTest2, IsSystemSession, Function | SmallTest | Level2)
1424 {
1425     ASSERT_NE(session_, nullptr);
1426     bool res = session_->IsSystemSession();
1427     ASSERT_EQ(res, false);
1428 }
1429 
1430 /**
1431  * @tc.name: Hide
1432  * @tc.desc: Hide
1433  * @tc.type: FUNC
1434  */
1435 HWTEST_F(WindowSessionTest2, Hide, Function | SmallTest | Level2)
1436 {
1437     ASSERT_NE(session_, nullptr);
1438     auto result = session_->Hide();
1439     ASSERT_EQ(result, WSError::WS_OK);
1440 }
1441 
1442 /**
1443  * @tc.name: Show
1444  * @tc.desc: Show
1445  * @tc.type: FUNC
1446  */
1447 HWTEST_F(WindowSessionTest2, Show, Function | SmallTest | Level2)
1448 {
1449     ASSERT_NE(session_, nullptr);
1450     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1451     ASSERT_NE(nullptr, property);
1452     auto result = session_->Show(property);
1453     ASSERT_EQ(result, WSError::WS_OK);
1454 }
1455 
1456 /**
1457  * @tc.name: DrawingCompleted
1458  * @tc.desc: DrawingCompleled
1459  * @tc.type: FUNC
1460  */
1461 HWTEST_F(WindowSessionTest2, DrawingCompleted, Function | SmallTest | Level2)
1462 {
1463     ASSERT_NE(session_, nullptr);
1464     auto result = session_->DrawingCompleted();
1465     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1466 }
1467 
1468 /**
1469  * @tc.name: RemoveStartingWindow
1470  * @tc.desc: RemoveStartingWindow
1471  * @tc.type: FUNC
1472  */
1473 HWTEST_F(WindowSessionTest2, RemoveStartingWindow, Function | SmallTest | Level2)
1474 {
1475     ASSERT_NE(session_, nullptr);
1476     session_->RegisterLifecycleListener(lifecycleListener_);
1477     session_->RemoveStartingWindow();
1478     uint64_t screenId = 0;
1479     session_->SetScreenId(screenId);
1480     session_->UnregisterLifecycleListener(lifecycleListener_);
1481     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1482 }
1483 
1484 /**
1485  * @tc.name: IsSystemActive
1486  * @tc.desc: IsSystemActive
1487  * @tc.type: FUNC
1488  */
1489 HWTEST_F(WindowSessionTest2, IsSystemActive, Function | SmallTest | Level2)
1490 {
1491     ASSERT_NE(session_, nullptr);
1492     bool res = session_->IsSystemActive();
1493     ASSERT_EQ(res, false);
1494 }
1495 
1496 /**
1497  * @tc.name: SetSystemActive
1498  * @tc.desc: SetSystemActive
1499  * @tc.type: FUNC
1500  */
1501 HWTEST_F(WindowSessionTest2, SetSystemActive, Function | SmallTest | Level2)
1502 {
1503     ASSERT_NE(session_, nullptr);
1504     bool systemActive = false;
1505     session_->SetSystemActive(systemActive);
1506     ASSERT_EQ(systemActive, session_->isSystemActive_);
1507 }
1508 
1509 /**
1510  * @tc.name: IsTerminated
1511  * @tc.desc: IsTerminated
1512  * @tc.type: FUNC
1513  */
1514 HWTEST_F(WindowSessionTest2, IsTerminated, Function | SmallTest | Level2)
1515 {
1516     ASSERT_NE(session_, nullptr);
1517     session_->state_ = SessionState::STATE_DISCONNECT;
1518     bool res = session_->IsTerminated();
1519     ASSERT_EQ(true, res);
1520     session_->state_ = SessionState::STATE_FOREGROUND;
1521     res = session_->IsTerminated();
1522     ASSERT_EQ(false, res);
1523     session_->state_ = SessionState::STATE_ACTIVE;
1524     res = session_->IsTerminated();
1525     ASSERT_EQ(false, res);
1526     session_->state_ = SessionState::STATE_INACTIVE;
1527     res = session_->IsTerminated();
1528     ASSERT_EQ(false, res);
1529     session_->state_ = SessionState::STATE_BACKGROUND;
1530     res = session_->IsTerminated();
1531     ASSERT_EQ(false, res);
1532     session_->state_ = SessionState::STATE_CONNECT;
1533     res = session_->IsTerminated();
1534     ASSERT_EQ(false, res);
1535 }
1536 
1537 /**
1538  * @tc.name: SetAttachState01
1539  * @tc.desc: SetAttachState Test
1540  * @tc.type: FUNC
1541  */
1542 HWTEST_F(WindowSessionTest2, SetAttachState01, Function | SmallTest | Level2)
1543 {
1544     ASSERT_NE(session_, nullptr);
1545     session_->SetAttachState(false);
1546     ASSERT_EQ(session_->isAttach_, false);
1547 }
1548 
1549 /**
1550  * @tc.name: SetAttachState02
1551  * @tc.desc: SetAttachState Test
1552  * @tc.type: FUNC
1553  */
1554 HWTEST_F(WindowSessionTest2, SetAttachState02, Function | SmallTest | Level2)
1555 {
1556     ASSERT_NE(session_, nullptr);
1557     int32_t persistentId = 123;
1558     sptr<PatternDetachCallbackMocker> detachCallback = new PatternDetachCallbackMocker();
1559     EXPECT_CALL(*detachCallback, OnPatternDetach(persistentId)).Times(1);
1560     session_->persistentId_ = persistentId;
1561     session_->SetAttachState(true);
1562     session_->RegisterDetachCallback(detachCallback);
1563     session_->SetAttachState(false);
1564     usleep(WAIT_SYNC_IN_NS);
1565     Mock::VerifyAndClearExpectations(&detachCallback);
1566 }
1567 
1568 /**
1569  * @tc.name: RegisterDetachCallback01
1570  * @tc.desc: RegisterDetachCallback Test
1571  * @tc.type: FUNC
1572  */
1573 HWTEST_F(WindowSessionTest2, RegisterDetachCallback01, Function | SmallTest | Level2)
1574 {
1575     ASSERT_NE(session_, nullptr);
1576     sptr<IPatternDetachCallback> detachCallback;
1577     session_->RegisterDetachCallback(detachCallback);
1578     ASSERT_EQ(session_->detachCallback_, detachCallback);
1579 }
1580 
1581 /**
1582  * @tc.name: RegisterDetachCallback02
1583  * @tc.desc: RegisterDetachCallback Test
1584  * @tc.type: FUNC
1585  */
1586 HWTEST_F(WindowSessionTest2, RegisterDetachCallback02, Function | SmallTest | Level2)
1587 {
1588     ASSERT_NE(session_, nullptr);
1589     sptr<IPatternDetachCallback> detachCallback;
1590     session_->RegisterDetachCallback(detachCallback);
1591     ASSERT_EQ(session_->detachCallback_, detachCallback);
1592     sptr<IPatternDetachCallback> detachCallback2;
1593     session_->RegisterDetachCallback(detachCallback2);
1594     ASSERT_EQ(session_->detachCallback_, detachCallback2);
1595 }
1596 
1597 /**
1598  * @tc.name: RegisterDetachCallback03
1599  * @tc.desc: RegisterDetachCallback Test
1600  * @tc.type: FUNC
1601  */
1602 HWTEST_F(WindowSessionTest2, RegisterDetachCallback03, Function | SmallTest | Level2)
1603 {
1604     ASSERT_NE(session_, nullptr);
1605     int32_t persistentId = 123;
1606     sptr<PatternDetachCallbackMocker> detachCallback = new PatternDetachCallbackMocker();
1607     EXPECT_CALL(*detachCallback, OnPatternDetach(persistentId)).Times(::testing::AtLeast(1));
1608     session_->persistentId_ = persistentId;
1609     session_->SetAttachState(true);
1610     session_->SetAttachState(false);
1611     session_->RegisterDetachCallback(detachCallback);
1612     Mock::VerifyAndClearExpectations(&detachCallback);
1613 }
1614 
1615 /**
1616  * @tc.name: SetContextTransparentFunc
1617  * @tc.desc: SetContextTransparentFunc Test
1618  * @tc.type: FUNC
1619  */
1620 HWTEST_F(WindowSessionTest2, SetContextTransparentFunc, Function | SmallTest | Level2)
1621 {
1622     ASSERT_NE(session_, nullptr);
1623     session_->SetContextTransparentFunc(nullptr);
1624     ASSERT_EQ(session_->contextTransparentFunc_, nullptr);
__anon8603b9f10902()1625     NotifyContextTransparentFunc func = [](){};
1626     session_->SetContextTransparentFunc(func);
1627     ASSERT_NE(session_->contextTransparentFunc_, nullptr);
1628 }
1629 
1630 /**
1631  * @tc.name: NeedCheckContextTransparent
1632  * @tc.desc: NeedCheckContextTransparent Test
1633  * @tc.type: FUNC
1634  */
1635 HWTEST_F(WindowSessionTest2, NeedCheckContextTransparent, Function | SmallTest | Level2)
1636 {
1637     ASSERT_NE(session_, nullptr);
1638     session_->SetContextTransparentFunc(nullptr);
1639     ASSERT_EQ(session_->NeedCheckContextTransparent(), false);
__anon8603b9f10a02()1640     NotifyContextTransparentFunc func = [](){};
1641     session_->SetContextTransparentFunc(func);
1642     ASSERT_EQ(session_->NeedCheckContextTransparent(), true);
1643 }
1644 
1645 /**
1646  * @tc.name: SetShowRecent001
1647  * @tc.desc: Exist detect task when in recent.
1648  * @tc.type: FUNC
1649  */
1650 HWTEST_F(WindowSessionTest2, SetShowRecent001, Function | SmallTest | Level2)
1651 {
1652     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anon8603b9f10b02()1653     auto task = [](){};
1654     int64_t delayTime = 3000;
1655     session_->handler_->PostTask(task, taskName, delayTime);
1656     int32_t beforeTaskNum = GetTaskCount();
1657 
1658     session_->SetShowRecent(true);
1659     ASSERT_EQ(beforeTaskNum, GetTaskCount());
1660     session_->handler_->RemoveTask(taskName);
1661 }
1662 
1663 /**
1664  * @tc.name: SetShowRecent002
1665  * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is false.
1666  * @tc.type: FUNC
1667  */
1668 HWTEST_F(WindowSessionTest2, SetShowRecent002, Function | SmallTest | Level2)
1669 {
1670     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anon8603b9f10c02()1671     auto task = [](){};
1672     int64_t delayTime = 3000;
1673     session_->handler_->PostTask(task, taskName, delayTime);
1674     session_->showRecent_ = false;
1675     int32_t beforeTaskNum = GetTaskCount();
1676 
1677     session_->SetShowRecent(false);
1678     ASSERT_EQ(beforeTaskNum, GetTaskCount());
1679     session_->handler_->RemoveTask(taskName);
1680 }
1681 
1682 /**
1683  * @tc.name: SetShowRecent003
1684  * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is true, detach task.
1685  * @tc.type: FUNC
1686  */
1687 HWTEST_F(WindowSessionTest2, SetShowRecent003, Function | SmallTest | Level2)
1688 {
1689     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anon8603b9f10d02()1690     auto task = [](){};
1691     int64_t delayTime = 3000;
1692     session_->handler_->PostTask(task, taskName, delayTime);
1693     session_->showRecent_ = true;
1694     session_->isAttach_ = false;
1695     int32_t beforeTaskNum = GetTaskCount();
1696 
1697     session_->SetShowRecent(false);
1698     ASSERT_EQ(beforeTaskNum, GetTaskCount());
1699     session_->handler_->RemoveTask(taskName);
1700 }
1701 
1702 /**
1703  * @tc.name: SetShowRecent004
1704  * @tc.desc: SetShowRecent
1705  * @tc.type: FUNC
1706  */
1707 HWTEST_F(WindowSessionTest2, SetShowRecent004, Function | SmallTest | Level2)
1708 {
1709     session_->systemConfig_.uiType_ = "phone";
1710     ssm_->SetScreenLocked(false);
1711 
1712     session_->property_ = new WindowSessionProperty();
1713     session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1714 
1715     bool showRecent = false;
1716     session_->showRecent_ = true;
1717     session_->SetAttachState(true);
1718     session_->SetShowRecent(showRecent);
1719     ASSERT_EQ(session_->GetShowRecent(), showRecent);
1720 }
1721 
1722 /**
1723  * @tc.name: CreateDetectStateTask001
1724  * @tc.desc: Create detection task when there are no pre_existing tasks.
1725  * @tc.type: FUNC
1726  */
1727 HWTEST_F(WindowSessionTest2, CreateDetectStateTask001, Function | SmallTest | Level2)
1728 {
1729     session_->systemConfig_.uiType_ = "phone";
1730     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1731     DetectTaskInfo detectTaskInfo;
1732     detectTaskInfo.taskState = DetectTaskState::NO_TASK;
1733     int32_t beforeTaskNum = GetTaskCount();
1734     session_->SetDetectTaskInfo(detectTaskInfo);
1735     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1736 
1737     ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1738     ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState);
1739     session_->handler_->RemoveTask(taskName);
1740 
1741     session_->showRecent_ = true;
1742     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1743 }
1744 
1745 /**
1746  * @tc.name: CreateDetectStateTask002
1747  * @tc.desc: Detect state when window mode changed.
1748  * @tc.type: FUNC
1749  */
1750 HWTEST_F(WindowSessionTest2, CreateDetectStateTask002, Function | SmallTest | Level2)
1751 {
1752     session_->systemConfig_.uiType_ = "phone";
1753     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anon8603b9f10e02()1754     auto task = [](){};
1755     int64_t delayTime = 3000;
1756     session_->handler_->PostTask(task, taskName, delayTime);
1757     int32_t beforeTaskNum = GetTaskCount();
1758 
1759     DetectTaskInfo detectTaskInfo;
1760     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1761     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1762     session_->SetDetectTaskInfo(detectTaskInfo);
1763     session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1764 
1765     ASSERT_EQ(beforeTaskNum - 1, GetTaskCount());
1766     ASSERT_EQ(DetectTaskState::NO_TASK, session_->GetDetectTaskInfo().taskState);
1767     ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, session_->GetDetectTaskInfo().taskWindowMode);
1768     session_->handler_->RemoveTask(taskName);
1769 
1770     session_->showRecent_ = true;
1771     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1772 }
1773 
1774 /**
1775  * @tc.name: CreateDetectStateTask003
1776  * @tc.desc: Detect sup and down tree tasks for the same type.
1777  * @tc.type: FUNC
1778  */
1779 HWTEST_F(WindowSessionTest2, CreateDetectStateTask003, Function | SmallTest | Level2)
1780 {
1781     session_->systemConfig_.uiType_ = "phone";
1782     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1783     DetectTaskInfo detectTaskInfo;
1784     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1785     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1786     int32_t beforeTaskNum = GetTaskCount();
1787     session_->SetDetectTaskInfo(detectTaskInfo);
1788     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1789 
1790     ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1791     ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState);
1792     session_->handler_->RemoveTask(taskName);
1793 
1794     session_->showRecent_ = true;
1795     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1796 }
1797 
1798 /**
1799  * @tc.name: CreateDetectStateTask004
1800  * @tc.desc: Detection tasks under the same window mode.
1801  * @tc.type: FUNC
1802  */
1803 HWTEST_F(WindowSessionTest2, CreateDetectStateTask004, Function | SmallTest | Level2)
1804 {
1805     session_->systemConfig_.uiType_ = "phone";
1806     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1807     DetectTaskInfo detectTaskInfo;
1808     int32_t beforeTaskNum = GetTaskCount();
1809     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1810     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1811     session_->SetDetectTaskInfo(detectTaskInfo);
1812     session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_FULLSCREEN);
1813 
1814     ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1815     ASSERT_EQ(DetectTaskState::ATTACH_TASK, session_->GetDetectTaskInfo().taskState);
1816     session_->handler_->RemoveTask(taskName);
1817 
1818     session_->showRecent_ = true;
1819     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1820 }
1821 
1822 /**
1823  * @tc.name: GetAttachState001
1824  * @tc.desc: GetAttachState001
1825  * @tc.type: FUNC
1826  */
1827 HWTEST_F(WindowSessionTest2, GetAttachState001, Function | SmallTest | Level2)
1828 {
1829     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1830     session_->SetAttachState(false);
1831     bool isAttach = session_->GetAttachState();
1832     ASSERT_EQ(false, isAttach);
1833     session_->handler_->RemoveTask(taskName);
1834 }
1835 
1836 /**
1837  * @tc.name: ResetSessionConnectState
1838  * @tc.desc: ResetSessionConnectState
1839  * @tc.type: FUNC
1840  */
1841 HWTEST_F(WindowSessionTest2, ResetSessionConnectState, Function | SmallTest | Level2)
1842 {
1843     ASSERT_NE(session_, nullptr);
1844     session_->ResetSessionConnectState();
1845     ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
1846     ASSERT_EQ(session_->GetCallingPid(), -1);
1847 }
1848 
1849 /**
1850  * @tc.name: ResetIsActive
1851  * @tc.desc: ResetIsActive
1852  * @tc.type: FUNC
1853  */
1854 HWTEST_F(WindowSessionTest2, ResetIsActive, Function | SmallTest | Level2)
1855 {
1856     ASSERT_NE(session_, nullptr);
1857     session_->ResetIsActive();
1858     ASSERT_EQ(session_->isActive_, false);
1859 }
1860 
1861 /**
1862  * @tc.name: PostExportTask02
1863  * @tc.desc: PostExportTask
1864  * @tc.type: FUNC
1865  */
1866 HWTEST_F(WindowSessionTest2, PostExportTask02, Function | SmallTest | Level2)
1867 {
1868     ASSERT_NE(session_, nullptr);
1869     std::string name = "sessionExportTask";
__anon8603b9f10f02()1870     auto task = [](){};
1871     int64_t delayTime = 0;
1872 
1873     session_->PostExportTask(task, name, delayTime);
1874     auto result = session_->GetBufferAvailable();
1875     ASSERT_EQ(result, false);
1876 
1877     sptr<SceneSessionManager> sceneSessionManager = new SceneSessionManager();
1878     session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(),
1879         sceneSessionManager->eventHandler_);
1880     session_->PostExportTask(task, name, delayTime);
1881     auto result2 = session_->GetBufferAvailable();
1882     ASSERT_EQ(result2, false);
1883 }
1884 
1885 /**
1886  * @tc.name: SetLeashWinSurfaceNode02
1887  * @tc.desc: SetLeashWinSurfaceNode
1888  * @tc.type: FUNC
1889  */
1890 HWTEST_F(WindowSessionTest2, SetLeashWinSurfaceNode02, Function | SmallTest | Level2)
1891 {
1892     ASSERT_NE(session_, nullptr);
1893     session_->leashWinSurfaceNode_ = WindowSessionTest2::CreateRSSurfaceNode();
1894     session_->SetLeashWinSurfaceNode(nullptr);
1895 
1896     session_->leashWinSurfaceNode_ = nullptr;
1897     session_->SetLeashWinSurfaceNode(nullptr);
1898     auto result = session_->GetBufferAvailable();
1899     ASSERT_EQ(result, false);
1900 }
1901 
1902 /**
1903  * @tc.name: GetCloseAbilityWantAndClean
1904  * @tc.desc: GetCloseAbilityWantAndClean
1905  * @tc.type: FUNC
1906  */
1907 HWTEST_F(WindowSessionTest2, GetCloseAbilityWantAndClean, Function | SmallTest | Level2)
1908 {
1909     ASSERT_NE(session_, nullptr);
1910     AAFwk::Want outWant;
1911     session_->sessionInfo_.closeAbilityWant = std::make_shared<AAFwk::Want>();
1912     session_->GetCloseAbilityWantAndClean(outWant);
1913 
1914     session_->sessionInfo_.closeAbilityWant = nullptr;
1915     session_->GetCloseAbilityWantAndClean(outWant);
1916     auto result = session_->GetBufferAvailable();
1917     ASSERT_EQ(result, false);
1918 }
1919 
1920 /**
1921  * @tc.name: SetScreenId02
1922  * @tc.desc: SetScreenId Test
1923  * @tc.type: FUNC
1924  */
1925 HWTEST_F(WindowSessionTest2, SetScreenId02, Function | SmallTest | Level2)
1926 {
1927     ASSERT_NE(session_, nullptr);
1928     uint64_t screenId = 0;
1929     session_->sessionStage_ = new (std::nothrow) SessionStageMocker();
1930     session_->SetScreenId(screenId);
1931     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1932 }
1933 
1934 /**
1935  * @tc.name: SetSessionState
1936  * @tc.desc: SetSessionState
1937  * @tc.type: FUNC
1938  */
1939 HWTEST_F(WindowSessionTest2, SetSessionState, Function | SmallTest | Level2)
1940 {
1941     ASSERT_NE(session_, nullptr);
1942 
1943     SessionState state03 = SessionState::STATE_CONNECT;
1944     session_->SetSessionState(state03);
1945     ASSERT_EQ(state03, session_->state_);
1946 }
1947 
1948 /**
1949  * @tc.name: SetFocusable03
1950  * @tc.desc: SetFocusable
1951  * @tc.type: FUNC
1952  */
1953 HWTEST_F(WindowSessionTest2, SetFocusable03, Function | SmallTest | Level2)
1954 {
1955     ASSERT_NE(session_, nullptr);
1956     session_->isFocused_ = true;
1957     session_->property_ = new (std::nothrow) WindowSessionProperty();
1958     session_->property_->focusable_ = false;
1959     bool isFocusable = true;
1960 
1961     auto result = session_->SetFocusable(isFocusable);
1962     ASSERT_EQ(result, WSError::WS_OK);
1963 }
1964 
1965 /**
1966  * @tc.name: GetFocused
1967  * @tc.desc: GetFocused Test
1968  * @tc.type: FUNC
1969  */
1970 HWTEST_F(WindowSessionTest2, GetFocused, Function | SmallTest | Level2)
1971 {
1972     ASSERT_NE(session_, nullptr);
1973     bool result = session_->GetFocused();
1974     ASSERT_EQ(result, false);
1975 
1976     session_->isFocused_ = true;
1977     bool result2 = session_->GetFocused();
1978     ASSERT_EQ(result2, true);
1979 }
1980 
1981 /**
1982  * @tc.name: UpdatePointerArea
1983  * @tc.desc: UpdatePointerArea Test
1984  * @tc.type: FUNC
1985  */
1986 HWTEST_F(WindowSessionTest2, UpdatePointerArea, Function | SmallTest | Level2)
1987 {
1988     ASSERT_NE(session_, nullptr);
1989     WSRect rect = { 0, 0, 0, 0 };
1990     session_->preRect_ = rect;
1991     session_->UpdatePointerArea(rect);
1992     ASSERT_EQ(session_->GetFocused(), false);
1993 }
1994 
1995 /**
1996  * @tc.name: UpdateSizeChangeReason02
1997  * @tc.desc: UpdateSizeChangeReason Test
1998  * @tc.type: FUNC
1999  */
2000 HWTEST_F(WindowSessionTest2, UpdateSizeChangeReason02, Function | SmallTest | Level2)
2001 {
2002     ASSERT_NE(session_, nullptr);
2003     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
2004     WSError result = session_->UpdateSizeChangeReason(reason);
2005     ASSERT_EQ(result, WSError::WS_DO_NOTHING);
2006 }
2007 
2008 /**
2009  * @tc.name: UpdateDensity
2010  * @tc.desc: UpdateDensity Test
2011  * @tc.type: FUNC
2012  */
2013 HWTEST_F(WindowSessionTest2, UpdateDensity, Function | SmallTest | Level2)
2014 {
2015     ASSERT_NE(session_, nullptr);
2016 
2017     session_->state_ = SessionState::STATE_DISCONNECT;
2018     ASSERT_FALSE(session_->IsSessionValid());
2019     WSError result = session_->UpdateDensity();
2020     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
2021 
2022     session_->state_ = SessionState::STATE_CONNECT;
2023     ASSERT_TRUE(session_->IsSessionValid());
2024     session_->sessionStage_ = nullptr;
2025     WSError result02 = session_->UpdateDensity();
2026     ASSERT_EQ(result02, WSError::WS_ERROR_NULLPTR);
2027 }
2028 
2029 /**
2030  * @tc.name: UpdateSizeChangeReason
2031  * @tc.desc: UpdateSizeChangeReason UpdateDensity
2032  * @tc.type: FUNC
2033  */
2034 HWTEST_F(WindowSessionTest2, UpdateSizeChangeReason, Function | SmallTest | Level2)
2035 {
2036     SizeChangeReason reason = SizeChangeReason{1};
2037     ASSERT_EQ(session_->UpdateSizeChangeReason(reason), WSError::WS_OK);
2038 }
2039 
2040 /**
2041  * @tc.name: SetPendingSessionActivationEventListener
2042  * @tc.desc: SetPendingSessionActivationEventListener
2043  * @tc.type: FUNC
2044  */
2045 HWTEST_F(WindowSessionTest2, SetPendingSessionActivationEventListener, Function | SmallTest | Level2)
2046 {
2047     int resultValue = 0;
__anon8603b9f11002(const SessionInfo& info) 2048     session_->SetPendingSessionActivationEventListener([&resultValue](const SessionInfo& info) {
2049         resultValue = 1;
2050     });
2051     usleep(WAIT_SYNC_IN_NS);
__anon8603b9f11102(const SessionInfo& info) 2052     session_->SetTerminateSessionListener([&resultValue](const SessionInfo& info) {
2053         resultValue = 2;
2054     });
2055     usleep(WAIT_SYNC_IN_NS);
2056     LifeCycleTaskType taskType = LifeCycleTaskType{0};
2057     session_->RemoveLifeCycleTask(taskType);
2058     ASSERT_EQ(resultValue, 0);
2059 }
2060 
2061 /**
2062  * @tc.name: SetSessionIcon
2063  * @tc.desc: SetSessionIcon UpdateDensity
2064  * @tc.type: FUNC
2065  */
2066 HWTEST_F(WindowSessionTest2, SetSessionIcon, Function | SmallTest | Level2)
2067 {
2068     std::shared_ptr<Media::PixelMap> icon;
2069     session_->SetSessionIcon(icon);
2070     ASSERT_EQ(session_->Clear(), WSError::WS_OK);
2071     session_->SetSessionSnapshotListener(nullptr);
__anon8603b9f11202(const SessionInfo& info) 2072     NotifyPendingSessionActivationFunc func = [](const SessionInfo& info) {};
2073     session_->pendingSessionActivationFunc_ = func;
2074     ASSERT_EQ(session_->PendingSessionToForeground(), WSError::WS_OK);
2075 
2076     session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("SetSessionIcon", 1);
2077     session_->updateSessionIconFunc_ = nullptr;
2078     ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
2079 
__anon8603b9f11302(const std::string& iconPath) 2080     NofitySessionIconUpdatedFunc func2 = [](const std::string& iconPath) {};
2081     session_->updateSessionIconFunc_ = func2;
2082     ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
2083 
__anon8603b9f11402(const SessionInfo& info, bool needStartCaller, bool isFromBroker) 2084     NotifyTerminateSessionFuncNew func3 = [](const SessionInfo& info, bool needStartCaller, bool isFromBroker) {};
2085     session_->terminateSessionFuncNew_ = func3;
2086     ASSERT_EQ(WSError::WS_OK, session_->Clear());
2087 }
2088 
2089 /**
2090  * @tc.name: SetSessionExceptionListener
2091  * @tc.desc: SetSessionExceptionListener
2092  * @tc.type: FUNC
2093  */
2094 HWTEST_F(WindowSessionTest2, SetSessionExceptionListener, Function | SmallTest | Level2)
2095 {
2096     session_->SetSessionExceptionListener(nullptr, true);
__anon8603b9f11502(const SessionInfo& info, bool removeSession, bool startFail) 2097     session_->SetSessionExceptionListener([](const SessionInfo& info, bool removeSession, bool startFail) {}, true);
2098     usleep(WAIT_SYNC_IN_NS);
2099     ASSERT_NE(nullptr, session_->jsSceneSessionExceptionFunc_);
2100 }
2101 
2102 /**
2103  * @tc.name: SetRaiseToAppTopForPointDownFunc
2104  * @tc.desc: SetRaiseToAppTopForPointDownFunc Test
2105  * @tc.type: FUNC
2106  */
2107 HWTEST_F(WindowSessionTest2, SetRaiseToAppTopForPointDownFunc, Function | SmallTest | Level2)
2108 {
2109     ASSERT_NE(session_, nullptr);
2110     session_->SetRaiseToAppTopForPointDownFunc(nullptr);
2111 
__anon8603b9f11602() 2112     NotifyRaiseToTopForPointDownFunc func = []() {};
2113     session_->raiseToTopForPointDownFunc_ = func;
2114     session_->RaiseToAppTopForPointDown();
2115     session_->HandlePointDownDialog();
2116     session_->ClearDialogVector();
2117 
2118     session_->SetBufferAvailableChangeListener(nullptr);
2119     session_->UnregisterSessionChangeListeners();
2120     session_->SetSessionStateChangeNotifyManagerListener(nullptr);
2121     session_->SetSessionInfoChangeNotifyManagerListener(nullptr);
2122     session_->NotifyFocusStatus(true);
2123 
2124     session_->SetRequestFocusStatusNotifyManagerListener(nullptr);
2125     session_->SetNotifyUIRequestFocusFunc(nullptr);
2126     session_->SetNotifyUILostFocusFunc(nullptr);
2127     session_->UnregisterSessionChangeListeners();
2128 
__anon8603b9f11702(const SessionInfo& info, bool shouldBackToCaller) 2129     NotifyPendingSessionToBackgroundForDelegatorFunc func2 = [](const SessionInfo& info, bool shouldBackToCaller) {};
2130     session_->pendingSessionToBackgroundForDelegatorFunc_ = func2;
2131     ASSERT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
2132 }
2133 
2134 /**
2135  * @tc.name: NotifyCloseExistPipWindow
2136  * @tc.desc: check func NotifyCloseExistPipWindow
2137  * @tc.type: FUNC
2138  */
2139 HWTEST_F(WindowSessionTest2, NotifyCloseExistPipWindow, Function | SmallTest | Level2)
2140 {
2141     sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
2142     ASSERT_NE(mockSessionStage, nullptr);
2143     ManagerState key = ManagerState{0};
2144     session_->GetStateFromManager(key);
2145     session_->NotifyUILostFocus();
2146 
__anon8603b9f11802() 2147     session_->lostFocusFunc_ = []() {};
2148     session_->NotifyUILostFocus();
2149 
2150     session_->SetSystemSceneBlockingFocus(true);
2151     session_->GetBlockingFocus();
2152     session_->sessionStage_ = mockSessionStage;
2153     EXPECT_CALL(*(mockSessionStage), NotifyCloseExistPipWindow()).Times(1).WillOnce(Return(WSError::WS_OK));
2154     ASSERT_EQ(WSError::WS_OK, session_->NotifyCloseExistPipWindow());
2155     session_->sessionStage_ = nullptr;
2156     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyCloseExistPipWindow());
2157 }
2158 
2159 /**
2160  * @tc.name: SetSystemConfig
2161  * @tc.desc: SetSystemConfig Test
2162  * @tc.type: FUNC
2163  */
2164 HWTEST_F(WindowSessionTest2, SetSystemConfig, Function | SmallTest | Level2)
2165 {
2166     ASSERT_NE(session_, nullptr);
2167     SystemSessionConfig systemConfig;
2168     session_->SetSystemConfig(systemConfig);
2169     float snapshotScale = 0.5;
2170     session_->SetSnapshotScale(snapshotScale);
2171     session_->ProcessBackEvent();
2172     session_->NotifyOccupiedAreaChangeInfo(nullptr);
2173     session_->UpdateMaximizeMode(true);
2174     ASSERT_EQ(session_->GetZOrder(), 0);
2175 
2176     session_->SetUINodeId(0);
2177     session_->GetUINodeId();
2178     session_->SetShowRecent(true);
2179     session_->GetShowRecent();
2180     session_->SetBufferAvailable(true);
2181 
2182     session_->SetNeedSnapshot(true);
2183     session_->SetFloatingScale(0.5);
2184     ASSERT_EQ(session_->GetFloatingScale(), 0.5f);
2185     session_->SetScale(50, 100, 50, 100);
2186     session_->GetScaleX();
2187     session_->GetScaleY();
2188     session_->GetPivotX();
2189     session_->GetPivotY();
2190     session_->SetSCBKeepKeyboard(true);
2191     session_->GetSCBKeepKeyboardFlag();
2192     ASSERT_EQ(WSError::WS_OK, session_->MarkProcessed(11));
2193 }
2194 
2195 /**
2196  * @tc.name: SetOffset
2197  * @tc.desc: SetOffset Test
2198  * @tc.type: FUNC
2199  */
2200 HWTEST_F(WindowSessionTest2, SetOffset, Function | SmallTest | Level2)
2201 {
2202     ASSERT_NE(session_, nullptr);
2203     session_->SetOffset(50, 100);
2204     session_->GetOffsetX();
2205     session_->GetOffsetY();
2206     WSRectF bounds;
2207     session_->SetBounds(bounds);
2208     session_->GetBounds();
2209     session_->UpdateTitleInTargetPos(true, 100);
2210     session_->SetNotifySystemSessionPointerEventFunc(nullptr);
2211     session_->SetNotifySystemSessionKeyEventFunc(nullptr);
2212     ASSERT_EQ(session_->GetBufferAvailable(), false);
2213 }
2214 
2215 /**
2216  * @tc.name: SetBackPressedListenser
2217  * @tc.desc: SetBackPressedListenser Test
2218  * @tc.type: FUNC
2219  */
2220 HWTEST_F(WindowSessionTest2, SetBackPressedListenser, Function | SmallTest | Level2)
2221 {
2222     ASSERT_NE(session_, nullptr);
2223     int32_t result = 0;
__anon8603b9f11902(const bool needMoveToBackground) 2224     session_->SetBackPressedListenser([&result](const bool needMoveToBackground) {
2225         result = 1;
2226     });
2227     usleep(WAIT_SYNC_IN_NS);
2228     session_->backPressedFunc_(true);
2229     ASSERT_EQ(result, 1);
2230 }
2231 
2232 /**
2233  * @tc.name: SetUpdateSessionIconListener
2234  * @tc.desc: SetUpdateSessionIconListener Test
2235  * @tc.type: FUNC
2236  */
2237 HWTEST_F(WindowSessionTest2, SetUpdateSessionIconListener, Function | SmallTest | Level2)
2238 {
2239     ASSERT_NE(session_, nullptr);
2240     WLOGFI("SetUpdateSessionIconListener begin!");
2241 
2242     session_->SetUpdateSessionIconListener(session_->updateSessionIconFunc_);
2243 
2244     WLOGFI("SetUpdateSessionIconListener end!");
2245 }
2246 
2247 /**
2248  * @tc.name: NotifyContextTransparent
2249  * @tc.desc: NotifyContextTransparent Test
2250  * @tc.type: FUNC
2251  */
2252 HWTEST_F(WindowSessionTest2, NotifyContextTransparent, Function | SmallTest | Level2)
2253 {
2254     WLOGFI("NotifyContextTransparent begin!");
2255     ASSERT_NE(session_, nullptr);
2256 
2257     NotifyContextTransparentFunc contextTransparentFunc = session_->contextTransparentFunc_;
2258     if (contextTransparentFunc == nullptr) {
__anon8603b9f11a02() 2259         contextTransparentFunc = []() {};
2260     }
2261     session_->contextTransparentFunc_ = nullptr;
2262     session_->NotifyContextTransparent();
2263 
2264     session_->SetContextTransparentFunc(contextTransparentFunc);
2265     session_->NotifyContextTransparent();
2266 
2267     WLOGFI("NotifyContextTransparent end!");
2268 }
2269 
2270 /**
2271  * @tc.name: NotifySessionInfoLockedStateChange
2272  * @tc.desc: NotifySessionInfoLockedStateChange Test
2273  * @tc.type: FUNC
2274  */
2275 HWTEST_F(WindowSessionTest2, NotifySessionInfoLockedStateChange, Function | SmallTest | Level2)
2276 {
2277     WLOGFI("NotifySessionInfoLockedStateChange begin!");
2278     ASSERT_NE(session_, nullptr);
2279 
2280     NotifySessionInfoLockedStateChangeFunc sessionInfoLockedStateChangeFunc =
2281         session_->sessionInfoLockedStateChangeFunc_;
2282     if (sessionInfoLockedStateChangeFunc == nullptr) {
__anon8603b9f11b02(const bool lockedState) 2283         sessionInfoLockedStateChangeFunc = [](const bool lockedState) {};
2284     }
2285     session_->sessionInfoLockedStateChangeFunc_ = nullptr;
2286     session_->NotifySessionInfoLockedStateChange(true);
2287 
2288     session_->SetSessionInfoLockedStateChangeListener(sessionInfoLockedStateChangeFunc);
2289     session_->NotifySessionInfoLockedStateChange(true);
2290 
2291     WLOGFI("NotifySessionInfoLockedStateChange end!");
2292 }
2293 
2294 /**
2295  * @tc.name: GetMainSession
2296  * @tc.desc: GetMainSession Test
2297  * @tc.type: FUNC
2298  */
2299 HWTEST_F(WindowSessionTest2, GetMainSession, Function | SmallTest | Level2)
2300 {
2301     ASSERT_NE(session_, nullptr);
2302     SessionInfo info;
2303     info.abilityName_ = "getMainSession";
2304     info.moduleName_ = "getMainSession";
2305     info.bundleName_ = "getMainSession";
2306     sptr<Session> session = sptr<Session>::MakeSptr(info);
2307     ASSERT_NE(session, nullptr);
2308     session->property_ = sptr<WindowSessionProperty>::MakeSptr();
2309     ASSERT_NE(session->property_, nullptr);
2310     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
2311     EXPECT_EQ(session, session->GetMainSession());
2312 
2313     sptr<Session> subSession = sptr<Session>::MakeSptr(info);
2314     ASSERT_NE(subSession, nullptr);
2315     subSession->SetParentSession(session);
2316     subSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
2317     ASSERT_NE(subSession->property_, nullptr);
2318     subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
2319     EXPECT_EQ(session, subSession->GetMainSession());
2320 
2321     sptr<Session> subSubSession = sptr<Session>::MakeSptr(info);
2322     ASSERT_NE(subSubSession, nullptr);
2323     subSubSession->SetParentSession(subSession);
2324     subSubSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
2325     ASSERT_NE(subSubSession->property_, nullptr);
2326     subSubSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
2327     EXPECT_EQ(session, subSubSession->GetMainSession());
2328 }
2329 
2330 /**
2331  * @tc.name: GetMainOrFloatSession
2332  * @tc.desc: GetMainOrFloatSession Test
2333  * @tc.type: FUNC
2334  */
2335 HWTEST_F(WindowSessionTest2, GetMainOrFloatSession, Function | SmallTest | Level2)
2336 {
2337     ASSERT_NE(session_, nullptr);
2338     SessionInfo info;
2339     info.abilityName_ = "GetMainOrFloatSession";
2340     info.moduleName_ = "GetMainOrFloatSession";
2341     info.bundleName_ = "GetMainOrFloatSession";
2342     sptr<Session> session = sptr<Session>::MakeSptr(info);
2343     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
2344     EXPECT_EQ(session, session->GetMainOrFloatSession());
2345 
2346     sptr<Session> floatSession = sptr<Session>::MakeSptr(info);
2347     floatSession->SetParentSession(session);
2348     floatSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
2349     EXPECT_EQ(floatSession, floatSession->GetMainOrFloatSession());
2350 
2351     sptr<Session> subSession = sptr<Session>::MakeSptr(info);
2352     subSession->SetParentSession(floatSession);
2353     subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
2354     EXPECT_EQ(floatSession, subSession->GetMainOrFloatSession());
2355 }
2356 
2357 /**
2358  * @tc.name: IsSupportDetectWindow
2359  * @tc.desc: IsSupportDetectWindow Test
2360  * @tc.type: FUNC
2361  */
2362 HWTEST_F(WindowSessionTest2, IsSupportDetectWindow, Function | SmallTest | Level2)
2363 {
2364     session_->systemConfig_.uiType_ = "phone";
2365     ssm_->SetScreenLocked(true);
2366     bool ret = session_->IsSupportDetectWindow(true);
2367     ASSERT_EQ(ret, false);
2368 
2369     ssm_->SetScreenLocked(false);
2370     session_->property_ = new WindowSessionProperty();
2371     session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
2372     ret = session_->IsSupportDetectWindow(true);
2373     ASSERT_EQ(ret, false);
2374 
2375     ssm_->SetScreenLocked(false);
2376     session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
2377     session_->systemConfig_.uiType_ = "pc";
2378     ret = session_->IsSupportDetectWindow(false);
2379     ASSERT_EQ(ret, false);
2380 }
2381 
2382 /**
2383  * @tc.name: ShouldCreateDetectTask
2384  * @tc.desc: ShouldCreateDetectTask Test
2385  * @tc.type: FUNC
2386  */
2387 HWTEST_F(WindowSessionTest2, ShouldCreateDetectTask, Function | SmallTest | Level2)
2388 {
2389     DetectTaskInfo detectTaskInfo;
2390     detectTaskInfo.taskState = DetectTaskState::ATTACH_TASK;
2391     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
2392     session_->SetDetectTaskInfo(detectTaskInfo);
2393     bool ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
2394     ASSERT_EQ(ret, true);
2395     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
2396     session_->SetDetectTaskInfo(detectTaskInfo);
2397     ret = session_->ShouldCreateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
2398     ASSERT_EQ(ret, true);
2399     ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
2400     ASSERT_EQ(ret, false);
2401 }
2402 
2403 /**
2404  * @tc.name: ShouldCreateDetectTaskInRecent
2405  * @tc.desc: ShouldCreateDetectTaskInRecent Test
2406  * @tc.type: FUNC
2407  */
2408 HWTEST_F(WindowSessionTest2, ShouldCreateDetectTaskInRecent, Function | SmallTest | Level2)
2409 {
2410     bool ret = session_->ShouldCreateDetectTaskInRecent(true, true, true);
2411     ASSERT_EQ(ret, false);
2412     ret = session_->ShouldCreateDetectTaskInRecent(false, true, true);
2413     ASSERT_EQ(ret, true);
2414     ret = session_->ShouldCreateDetectTaskInRecent(false, true, false);
2415     ASSERT_EQ(ret, false);
2416     ret = session_->ShouldCreateDetectTaskInRecent(false, false, false);
2417     ASSERT_EQ(ret, false);
2418 }
2419 
2420 /**
2421  * @tc.name: CreateWindowStateDetectTask
2422  * @tc.desc: CreateWindowStateDetectTask Test
2423  * @tc.type: FUNC
2424  */
2425 HWTEST_F(WindowSessionTest2, CreateWindowStateDetectTask, Function | SmallTest | Level2)
2426 {
__anon8603b9f11c02() 2427     auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); };
2428     session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
2429     session_->SetSessionState(SessionState::STATE_CONNECT);
2430     bool isAttach = true;
2431     session_->CreateWindowStateDetectTask(isAttach, WindowMode::WINDOW_MODE_UNDEFINED);
2432     ASSERT_EQ(isAttach, true);
2433 
2434     session_->handler_ = nullptr;
2435     session_->CreateWindowStateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
2436     ASSERT_EQ(session_->handler_, nullptr);
2437 }
2438 
2439 /**
2440  * @tc.name: SetOffset01
2441  * @tc.desc: SetOffset Test
2442  * @tc.type: FUNC
2443  */
2444 HWTEST_F(WindowSessionTest2, SetOffset01, Function | SmallTest | Level2)
2445 {
2446     ASSERT_NE(session_, nullptr);
2447     session_->SetOffset(0, 0);
2448     ASSERT_EQ(session_->GetOffsetX(), 0);
2449 }
2450 }
2451 } // namespace Rosen
2452 } // namespace OHOS
2453