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: SaveSnapshot
570  * @tc.desc: SaveSnapshot Test
571  * @tc.type: FUNC
572  */
573 HWTEST_F(WindowSessionTest2, SaveSnapshot, Function | SmallTest | Level2)
574 {
575     ASSERT_NE(session_, nullptr);
576 
577     session_->scenePersistence_ = nullptr;
578     session_->snapshot_ = nullptr;
579     session_->SaveSnapshot(true);
580     EXPECT_EQ(session_->snapshot_, nullptr);
581 
582     session_->scenePersistence_ = new ScenePersistence(session_->sessionInfo_.bundleName_, session_->persistentId_);
583 
584     session_->SaveSnapshot(false);
585     ASSERT_EQ(session_->snapshot_, nullptr);
586 
587     session_->SaveSnapshot(true);
588     ASSERT_EQ(session_->snapshot_, nullptr);
589 }
590 
591 /**
592  * @tc.name: SetSessionStateChangeListenser
593  * @tc.desc: SetSessionStateChangeListenser Test
594  * @tc.type: FUNC
595  */
596 HWTEST_F(WindowSessionTest2, SetSessionStateChangeListenser, Function | SmallTest | Level2)
597 {
598     ASSERT_NE(session_, nullptr);
599 
600     NotifySessionStateChangeFunc func = nullptr;
601     session_->SetSessionStateChangeListenser(func);
602 
603     session_->state_ = SessionState::STATE_DISCONNECT;
604     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
605 }
606 
607 /**
608  * @tc.name: SetSessionFocusableChangeListener
609  * @tc.desc: SetSessionFocusableChangeListener Test
610  * @tc.type: FUNC
611  */
612 HWTEST_F(WindowSessionTest2, SetSessionFocusableChangeListener, Function | SmallTest | Level2)
613 {
614     ASSERT_NE(session_, nullptr);
615 
616     NotifySessionFocusableChangeFunc func = [](const bool isFocusable)
__anond2f947a70402(const bool isFocusable) 617     {
618     };
619     session_->SetSessionFocusableChangeListener(func);
620 
621     session_->state_ = SessionState::STATE_DISCONNECT;
622     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
623 }
624 
625 /**
626  * @tc.name: SetSessionTouchableChangeListener
627  * @tc.desc: SetSessionTouchableChangeListener Test
628  * @tc.type: FUNC
629  */
630 HWTEST_F(WindowSessionTest2, SetSessionTouchableChangeListener, Function | SmallTest | Level2)
631 {
632     ASSERT_NE(session_, nullptr);
633 
634     NotifySessionTouchableChangeFunc func = [](const bool touchable)
__anond2f947a70502(const bool touchable) 635     {
636     };
637     session_->SetSessionTouchableChangeListener(func);
638 
639     session_->state_ = SessionState::STATE_DISCONNECT;
640     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
641 }
642 
643 /**
644  * @tc.name: SetSessionInfoLockedStateChangeListener
645  * @tc.desc: SetSessionInfoLockedStateChangeListener Test
646  * @tc.type: FUNC
647  */
648 HWTEST_F(WindowSessionTest2, SetSessionInfoLockedStateChangeListener, Function | SmallTest | Level2)
649 {
650     ASSERT_NE(session_, nullptr);
651 
652     NotifySessionTouchableChangeFunc func = [](const bool lockedState)
__anond2f947a70602(const bool lockedState) 653     {
654     };
655     session_->SetSessionInfoLockedStateChangeListener(func);
656 
657     session_->SetSessionInfoLockedState(true);
658     ASSERT_EQ(true, session_->sessionInfo_.lockedState);
659 }
660 
661 /**
662  * @tc.name: SetClickListener
663  * @tc.desc: SetClickListener Test
664  * @tc.type: FUNC
665  */
666 HWTEST_F(WindowSessionTest2, SetClickListener, Function | SmallTest | Level2)
667 {
668     ASSERT_NE(session_, nullptr);
669 
670     NotifyClickFunc func = nullptr;
671     session_->SetClickListener(func);
672 
673     session_->state_ = SessionState::STATE_DISCONNECT;
674     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
675 }
676 
677 /**
678  * @tc.name: UpdateFocus01
679  * @tc.desc: isFocused_ equal isFocused
680  * @tc.type: FUNC
681  */
682 HWTEST_F(WindowSessionTest2, UpdateFocus01, Function | SmallTest | Level2)
683 {
684     ASSERT_NE(session_, nullptr);
685 
686     bool isFocused = session_->isFocused_;
687     ASSERT_EQ(WSError::WS_DO_NOTHING, session_->UpdateFocus(isFocused));
688 }
689 
690 /**
691  * @tc.name: UpdateFocus02
692  * @tc.desc: isFocused_ not equal isFocused, IsSessionValid() return false
693  * @tc.type: FUNC
694  */
695 HWTEST_F(WindowSessionTest2, UpdateFocus02, Function | SmallTest | Level2)
696 {
697     ASSERT_NE(session_, nullptr);
698 
699     session_->sessionInfo_.isSystem_ = true;
700 
701     bool isFocused = session_->isFocused_;
702     ASSERT_EQ(WSError::WS_OK, session_->UpdateFocus(!isFocused));
703 }
704 
705 /**
706  * @tc.name: UpdateWindowMode01
707  * @tc.desc: IsSessionValid() return false
708  * @tc.type: FUNC
709  */
710 HWTEST_F(WindowSessionTest2, UpdateWindowMode01, Function | SmallTest | Level2)
711 {
712     ASSERT_NE(session_, nullptr);
713 
714     session_->property_ = nullptr;
715 
716     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED));
717 }
718 
719 /**
720  * @tc.name: NotifyForegroundInteractiveStatus
721  * @tc.desc: NotifyForegroundInteractiveStatus Test
722  * @tc.type: FUNC
723  */
724 HWTEST_F(WindowSessionTest2, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
725 {
726     ASSERT_NE(session_, nullptr);
727     int res = 0;
728     session_->sessionStage_ = nullptr;
729     bool interactive = true;
730     session_->NotifyForegroundInteractiveStatus(interactive);
731 
732     sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
733     ASSERT_NE(mockSessionStage, nullptr);
734     session_->sessionStage_ = mockSessionStage;
735     session_->state_ = SessionState::STATE_FOREGROUND;
736     interactive = false;
737     session_->NotifyForegroundInteractiveStatus(interactive);
738     ASSERT_EQ(0, res);
739 }
740 
741 /**
742  * @tc.name: SetEventHandler001
743  * @tc.desc: SetEventHandler Test
744  * @tc.type: FUNC
745  */
746 HWTEST_F(WindowSessionTest2, SetEventHandler001, Function | SmallTest | Level2)
747 {
748     ASSERT_NE(session_, nullptr);
749     int res = 0;
750     std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
751     session_->SetEventHandler(handler);
752     ASSERT_EQ(res, 0);
753 }
754 
755 /**
756  * @tc.name: PostTask002
757  * @tc.desc: PostTask Test
758  * @tc.type: FUNC
759  */
760 HWTEST_F(WindowSessionTest2, PostTask002, Function | SmallTest | Level2)
761 {
762     ASSERT_NE(session_, nullptr);
763     int32_t persistentId = 0;
764     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
765     if (property == nullptr) {
766         return;
767     }
768     property->SetPersistentId(persistentId);
769     int32_t res = session_->GetPersistentId();
770     ASSERT_EQ(res, 0);
771 }
772 
773 /**
774  * @tc.name: GetSurfaceNode
775  * @tc.desc: GetSurfaceNode Test
776  * @tc.type: FUNC
777  */
778 HWTEST_F(WindowSessionTest2, GetSurfaceNode, Function | SmallTest | Level2)
779 {
780     ASSERT_NE(session_, nullptr);
781     session_->surfaceNode_ = nullptr;
782     std::shared_ptr<RSSurfaceNode> res = session_->GetSurfaceNode();
783     ASSERT_EQ(res, nullptr);
784 }
785 
786 /**
787  * @tc.name: GetLeashWinSurfaceNode
788  * @tc.desc: GetLeashWinSurfaceNode Test
789  * @tc.type: FUNC
790  */
791 HWTEST_F(WindowSessionTest2, GetLeashWinSurfaceNode, Function | SmallTest | Level2)
792 {
793     ASSERT_NE(session_, nullptr);
794     session_->leashWinSurfaceNode_ = nullptr;
795     std::shared_ptr<RSSurfaceNode> res = session_->GetLeashWinSurfaceNode();
796     ASSERT_EQ(res, nullptr);
797 }
798 
799 /**
800  * @tc.name: SetSessionInfoAncoSceneState
801  * @tc.desc: SetSessionInfoAncoSceneState Test
802  * @tc.type: FUNC
803  */
804 HWTEST_F(WindowSessionTest2, SetSessionInfoAncoSceneState, Function | SmallTest | Level2)
805 {
806     ASSERT_NE(session_, nullptr);
807     int res = 0;
808     int32_t ancoSceneState = 0;
809     session_->SetSessionInfoAncoSceneState(ancoSceneState);
810     ASSERT_EQ(res, 0);
811 }
812 
813 /**
814  * @tc.name: SetSessionInfoTime
815  * @tc.desc: SetSessionInfoTime Test
816  * @tc.type: FUNC
817  */
818 HWTEST_F(WindowSessionTest2, SetSessionInfoTime, Function | SmallTest | Level2)
819 {
820     ASSERT_NE(session_, nullptr);
821     int res = 0;
822     std::string time = "";
823     session_->SetSessionInfoTime(time);
824     ASSERT_EQ(res, 0);
825 }
826 
827 /**
828  * @tc.name: SetSessionInfoAbilityInfo
829  * @tc.desc: SetSessionInfoAbilityInfo Test
830  * @tc.type: FUNC
831  */
832 HWTEST_F(WindowSessionTest2, SetSessionInfoAbilityInfo, Function | SmallTest | Level2)
833 {
834     ASSERT_NE(session_, nullptr);
835     int res = 0;
836     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
837     session_->SetSessionInfoAbilityInfo(abilityInfo);
838     ASSERT_EQ(res, 0);
839 }
840 
841 /**
842  * @tc.name: SetSessionInfoWant
843  * @tc.desc: SetSessionInfoWant Test
844  * @tc.type: FUNC
845  */
846 HWTEST_F(WindowSessionTest2, SetSessionInfoWant, Function | SmallTest | Level2)
847 {
848     ASSERT_NE(session_, nullptr);
849     int res = 0;
850     std::shared_ptr<AAFwk::Want> want = nullptr;
851     session_->SetSessionInfoWant(want);
852     ASSERT_EQ(res, 0);
853 }
854 
855 /**
856  * @tc.name: SetSessionInfoProcessOptions
857  * @tc.desc: SetSessionInfoProcessOptions Test
858  * @tc.type: FUNC
859  */
860 HWTEST_F(WindowSessionTest2, SetSessionInfoProcessOptions, Function | SmallTest | Level2)
861 {
862     ASSERT_NE(session_, nullptr);
863     std::shared_ptr<AAFwk::ProcessOptions> processOptions = std::make_shared<AAFwk::ProcessOptions>();
864     session_->SetSessionInfoProcessOptions(processOptions);
865     ASSERT_EQ(processOptions, session_->sessionInfo_.processOptions);
866 }
867 
868 /**
869  * @tc.name: SetSessionInfoPersistentId
870  * @tc.desc: SetSessionInfoPersistentId Test
871  * @tc.type: FUNC
872  */
873 HWTEST_F(WindowSessionTest2, SetSessionInfoPersistentId, Function | SmallTest | Level2)
874 {
875     ASSERT_NE(session_, nullptr);
876     int res = 0;
877     int32_t persistentId = 0;
878     session_->SetSessionInfoPersistentId(persistentId);
879     ASSERT_EQ(res, 0);
880 }
881 
882 /**
883  * @tc.name: SetSessionInfoCallerPersistentId
884  * @tc.desc: SetSessionInfoCallerPersistentId Test
885  * @tc.type: FUNC
886  */
887 HWTEST_F(WindowSessionTest2, SetSessionInfoCallerPersistentId, Function | SmallTest | Level2)
888 {
889     ASSERT_NE(session_, nullptr);
890     int res = 0;
891     int32_t callerPersistentId = 0;
892     session_->SetSessionInfoCallerPersistentId(callerPersistentId);
893     ASSERT_EQ(res, 0);
894 }
895 
896 /**
897  * @tc.name: PostExportTask
898  * @tc.desc: PostExportTask Test
899  * @tc.type: FUNC
900  */
901 HWTEST_F(WindowSessionTest2, PostExportTask, Function | SmallTest | Level2)
902 {
903     ASSERT_NE(session_, nullptr);
904     int32_t persistentId = 0;
905     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
906     if (property == nullptr) {
907         return;
908     }
909     property->SetPersistentId(persistentId);
910     int32_t ret = session_->GetPersistentId();
911     ASSERT_EQ(ret, 0);
912 }
913 
914 /**
915  * @tc.name: GetPersistentId
916  * @tc.desc: GetPersistentId Test
917  * @tc.type: FUNC
918  */
919 HWTEST_F(WindowSessionTest2, GetPersistentId, Function | SmallTest | Level2)
920 {
921     ASSERT_NE(session_, nullptr);
922     int32_t persistentId = 0;
923     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
924     if (property == nullptr) {
925         return;
926     }
927     property->SetPersistentId(persistentId);
928     int32_t ret = session_->GetPersistentId();
929     ASSERT_EQ(ret, 0);
930 }
931 
932 /**
933  * @tc.name: SetLeashWinSurfaceNode
934  * @tc.desc: SetLeashWinSurfaceNode Test
935  * @tc.type: FUNC
936  */
937 HWTEST_F(WindowSessionTest2, SetLeashWinSurfaceNode, Function | SmallTest | Level2)
938 {
939     ASSERT_NE(session_, nullptr);
940     auto leashWinSurfaceNode = WindowSessionTest2::CreateRSSurfaceNode();
941     session_->SetLeashWinSurfaceNode(leashWinSurfaceNode);
942     ASSERT_EQ(session_->leashWinSurfaceNode_, leashWinSurfaceNode);
943 }
944 
945 /**
946  * @tc.name: SetSessionInfoContinueState
947  * @tc.desc: SetSessionInfoContinueState Test
948  * @tc.type: FUNC
949  */
950 HWTEST_F(WindowSessionTest2, SetSessionInfoContinueState, Function | SmallTest | Level2)
951 {
952     ASSERT_NE(session_, nullptr);
953     enum ContinueState state = CONTINUESTATE_UNKNOWN;
954     session_->SetSessionInfoContinueState(state);
955     ASSERT_EQ(session_->sessionInfo_.continueState, state);
956 }
957 
958 /**
959  * @tc.name: SetSessionInfoIsClearSession01
960  * @tc.desc: SetSessionInfoIsClearSession return false
961  * @tc.type: FUNC
962  */
963 HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession01, Function | SmallTest | Level2)
964 {
965     ASSERT_NE(session_, nullptr);
966     session_->SetSessionInfoIsClearSession(false);
967     ASSERT_EQ(false, session_->sessionInfo_.isClearSession);
968 }
969 
970 /**
971  * @tc.name: SetSessionInfoIsClearSession02
972  * @tc.desc: SetSessionInfoIsClearSession return true
973  * @tc.type: FUNC
974  */
975 HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession02, Function | SmallTest | Level2)
976 {
977     ASSERT_NE(session_, nullptr);
978     session_->SetSessionInfoIsClearSession(true);
979     ASSERT_EQ(true, session_->sessionInfo_.isClearSession);
980 }
981 
982 /**
983  * @tc.name: SetSessionInfoAffinity
984  * @tc.desc: SetSessionInfoAffinity
985  * @tc.type: FUNC
986  */
987 HWTEST_F(WindowSessionTest2, SetSessionInfoAffinity, Function | SmallTest | Level2)
988 {
989     ASSERT_NE(session_, nullptr);
990     std::string affinity = "setSessionIofoAffinity";
991     session_->SetSessionInfoAffinity(affinity);
992     ASSERT_EQ(affinity, session_->sessionInfo_.sessionAffinity);
993 }
994 
995 /**
996  * @tc.name: SetSessionInfo
997  * @tc.desc: SetSessionInfo
998  * @tc.type: FUNC
999  */
1000 HWTEST_F(WindowSessionTest2, SetSessionInfo, Function | SmallTest | Level2)
1001 {
1002     ASSERT_NE(session_, nullptr);
1003     SessionInfo info;
1004     info.want = nullptr;
1005     info.callerToken_ = nullptr;
1006     info.requestCode = 1;
1007     info.callerPersistentId_ = 1;
1008     info.callingTokenId_ = 1;
1009     info.uiAbilityId_ = 1;
1010     info.startSetting = nullptr;
1011     info.continueSessionId_ = "";
1012     session_->SetSessionInfo(info);
1013     ASSERT_EQ(nullptr, session_->sessionInfo_.want);
1014     ASSERT_EQ(nullptr, session_->sessionInfo_.callerToken_);
1015     ASSERT_EQ(1, session_->sessionInfo_.requestCode);
1016     ASSERT_EQ(1, session_->sessionInfo_.callerPersistentId_);
1017     ASSERT_EQ(1, session_->sessionInfo_.callingTokenId_);
1018     ASSERT_EQ(1, session_->sessionInfo_.uiAbilityId_);
1019     ASSERT_EQ("", session_->sessionInfo_.continueSessionId_);
1020     ASSERT_EQ(nullptr, session_->sessionInfo_.startSetting);
1021 }
1022 
1023 /**
1024  * @tc.name: SetScreenId
1025  * @tc.desc: SetScreenId
1026  * @tc.type: FUNC
1027  */
1028 HWTEST_F(WindowSessionTest2, SetScreenId, Function | SmallTest | Level2)
1029 {
1030     ASSERT_NE(session_, nullptr);
1031     uint64_t screenId = 0;
1032     session_->SetScreenId(screenId);
1033     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1034 }
1035 
1036 /**
1037  * @tc.name: RegisterLifecycleListener
1038  * @tc.desc: RegisterLifecycleListener
1039  * @tc.type: FUNC
1040  */
1041 HWTEST_F(WindowSessionTest2, RegisterLifecycleListener, Function | SmallTest | Level2)
1042 {
1043     ASSERT_NE(session_, nullptr);
1044     const std::shared_ptr<ILifecycleListener>& listener = nullptr;
1045     bool ret = session_->RegisterLifecycleListener(listener);
1046     ASSERT_EQ(false, ret);
1047 }
1048 
1049 /**
1050  * @tc.name: UnregisterLifecycleListener
1051  * @tc.desc: UnregisterLifecycleListener
1052  * @tc.type: FUNC
1053  */
1054 HWTEST_F(WindowSessionTest2, UnregisterLifecycleListener, Function | SmallTest | Level2)
1055 {
1056     ASSERT_NE(session_, nullptr);
1057     const std::shared_ptr<ILifecycleListener>& listener = nullptr;
1058     bool ret = session_->UnregisterLifecycleListener(listener);
1059     ASSERT_EQ(false, ret);
1060 }
1061 
1062 /**
1063  * @tc.name: NotifyActivation02
1064  * @tc.desc: NotifyActivation
1065  * @tc.type: FUNC
1066  */
1067 HWTEST_F(WindowSessionTest2, NotifyActivation02, Function | SmallTest | Level2)
1068 {
1069     ASSERT_NE(session_, nullptr);
1070     session_->NotifyActivation();
1071     uint64_t screenId = 0;
1072     session_->SetScreenId(screenId);
1073     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1074 }
1075 
1076 /**
1077  * @tc.name: NotifyConnect
1078  * @tc.desc: NotifyConnect
1079  * @tc.type: FUNC
1080  */
1081 HWTEST_F(WindowSessionTest2, NotifyConnect, Function | SmallTest | Level2)
1082 {
1083     ASSERT_NE(session_, nullptr);
1084     session_->NotifyConnect();
1085     uint64_t screenId = 0;
1086     session_->SetScreenId(screenId);
1087     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1088 }
1089 
1090 /**
1091  * @tc.name: NotifyForeground02
1092  * @tc.desc: NotifyForeground
1093  * @tc.type: FUNC
1094  */
1095 HWTEST_F(WindowSessionTest2, NotifyForeground02, Function | SmallTest | Level2)
1096 {
1097     ASSERT_NE(session_, nullptr);
1098     session_->NotifyForeground();
1099     uint64_t screenId = 0;
1100     session_->SetScreenId(screenId);
1101     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1102 }
1103 
1104 /**
1105  * @tc.name: NotifyBackground02
1106  * @tc.desc: NotifyBackground
1107  * @tc.type: FUNC
1108  */
1109 HWTEST_F(WindowSessionTest2, NotifyBackground02, Function | SmallTest | Level2)
1110 {
1111     ASSERT_NE(session_, nullptr);
1112     session_->NotifyBackground();
1113     uint64_t screenId = 0;
1114     session_->SetScreenId(screenId);
1115     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1116 }
1117 
1118 /**
1119  * @tc.name: NotifyDisconnect
1120  * @tc.desc: NotifyDisconnect
1121  * @tc.type: FUNC
1122  */
1123 HWTEST_F(WindowSessionTest2, NotifyDisconnect, Function | SmallTest | Level2)
1124 {
1125     ASSERT_NE(session_, nullptr);
1126     session_->NotifyDisconnect();
1127     uint64_t screenId = 0;
1128     session_->SetScreenId(screenId);
1129     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1130 }
1131 
1132 /**
1133  * @tc.name: NotifyExtensionDied02
1134  * @tc.desc: NotifyExtensionDied
1135  * @tc.type: FUNC
1136  */
1137 HWTEST_F(WindowSessionTest2, NotifyExtensionDied02, Function | SmallTest | Level2)
1138 {
1139     ASSERT_NE(session_, nullptr);
1140     session_->NotifyExtensionDied();
1141 
1142     session_->RegisterLifecycleListener(lifecycleListener_);
1143     session_->NotifyExtensionDied();
1144     uint64_t screenId = 0;
1145     session_->SetScreenId(screenId);
1146     session_->UnregisterLifecycleListener(lifecycleListener_);
1147     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1148 }
1149 
1150 /**
1151  * @tc.name: NotifyTransferAccessibilityEvent
1152  * @tc.desc: NotifyTransferAccessibilityEvent
1153  * @tc.type: FUNC
1154  */
1155 HWTEST_F(WindowSessionTest2, NotifyTransferAccessibilityEvent, Function | SmallTest | Level2)
1156 {
1157     ASSERT_NE(session_, nullptr);
1158     OHOS::Accessibility::AccessibilityEventInfo info1;
1159     int64_t uiExtensionIdLevel = 6;
1160     session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1161 
1162     session_->RegisterLifecycleListener(lifecycleListener_);
1163     session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1164     uint64_t screenId = 0;
1165     session_->SetScreenId(screenId);
1166     session_->UnregisterLifecycleListener(lifecycleListener_);
1167     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1168 }
1169 
1170 /**
1171  * @tc.name: GetAspectRatio
1172  * @tc.desc: GetAspectRatio
1173  * @tc.type: FUNC
1174  */
1175 HWTEST_F(WindowSessionTest2, GetAspectRatio, Function | SmallTest | Level2)
1176 {
1177     ASSERT_NE(session_, nullptr);
1178     float ret = session_->aspectRatio_;
1179     float res = 0.0f;
1180     ASSERT_EQ(ret, res);
1181 }
1182 
1183 /**
1184  * @tc.name: SetAspectRatio02
1185  * @tc.desc: SetAspectRatio
1186  * @tc.type: FUNC
1187  */
1188 HWTEST_F(WindowSessionTest2, SetAspectRatio02, Function | SmallTest | Level2)
1189 {
1190     ASSERT_NE(session_, nullptr);
1191     float radio = 2.0f;
1192     WSError ERR = session_->SetAspectRatio(radio);
1193     float ret = session_->aspectRatio_;
1194     ASSERT_EQ(ret, radio);
1195     ASSERT_EQ(ERR, WSError::WS_OK);
1196 }
1197 
1198 /**
1199  * @tc.name: GetSessionState
1200  * @tc.desc: GetSessionState
1201  * @tc.type: FUNC
1202  */
1203 HWTEST_F(WindowSessionTest2, GetSessionState, Function | SmallTest | Level2)
1204 {
1205     ASSERT_NE(session_, nullptr);
1206     SessionState state = session_->GetSessionState();
1207     ASSERT_EQ(state, session_->state_);
1208 }
1209 
1210 /**
1211  * @tc.name: SetSessionState02
1212  * @tc.desc: SetSessionState
1213  * @tc.type: FUNC
1214  */
1215 HWTEST_F(WindowSessionTest2, SetSessionState02, Function | SmallTest | Level2)
1216 {
1217     ASSERT_NE(session_, nullptr);
1218     SessionState state = SessionState::STATE_CONNECT;
1219     session_->SetSessionState(state);
1220     ASSERT_EQ(state, session_->state_);
1221 }
1222 
1223 /**
1224  * @tc.name: SetChangeSessionVisibilityWithStatusBarEventListener
1225  * @tc.desc: SetChangeSessionVisibilityWithStatusBarEventListener Test
1226  * @tc.type: FUNC
1227  */
1228 HWTEST_F(WindowSessionTest2, SetChangeSessionVisibilityWithStatusBarEventListener, Function | SmallTest | Level2)
1229 {
1230     int resultValue = 0;
__anond2f947a70702(SessionInfo& info, const bool visible) 1231     NotifyChangeSessionVisibilityWithStatusBarFunc func1 = [&resultValue](SessionInfo& info, const bool visible) {
1232         resultValue = 1;
1233     };
__anond2f947a70802(SessionInfo& info, const bool visible) 1234     NotifyChangeSessionVisibilityWithStatusBarFunc func2 = [&resultValue](SessionInfo& info, const bool visible) {
1235         resultValue = 2;
1236     };
1237 
1238     session_->SetChangeSessionVisibilityWithStatusBarEventListener(func1);
1239     ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1240 
1241     SessionInfo info;
1242     session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1243     ASSERT_EQ(resultValue, 1);
1244 
1245     session_->SetChangeSessionVisibilityWithStatusBarEventListener(func2);
1246     ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1247     session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1248     ASSERT_EQ(resultValue, 2);
1249 }
1250 
1251 /**
1252  * @tc.name: UpdateSessionState
1253  * @tc.desc: UpdateSessionState
1254  * @tc.type: FUNC
1255  */
1256 HWTEST_F(WindowSessionTest2, UpdateSessionState, Function | SmallTest | Level2)
1257 {
1258     ASSERT_NE(session_, nullptr);
1259     SessionState state = SessionState::STATE_CONNECT;
1260     session_->UpdateSessionState(state);
1261     ASSERT_EQ(session_->state_, SessionState::STATE_CONNECT);
1262 }
1263 
1264 /**
1265  * @tc.name: GetTouchable
1266  * @tc.desc: GetTouchable
1267  * @tc.type: FUNC
1268  */
1269 HWTEST_F(WindowSessionTest2, GetTouchable, Function | SmallTest | Level2)
1270 {
1271     ASSERT_NE(session_, nullptr);
1272     bool res = session_->GetTouchable();
1273     ASSERT_EQ(true, res);
1274 }
1275 
1276 /**
1277  * @tc.name: SetSystemTouchable
1278  * @tc.desc: SetSystemTouchable
1279  * @tc.type: FUNC
1280  */
1281 HWTEST_F(WindowSessionTest2, SetSystemTouchable, Function | SmallTest | Level2)
1282 {
1283     ASSERT_NE(session_, nullptr);
1284     bool touchable = false;
1285     session_->SetSystemTouchable(touchable);
1286     ASSERT_EQ(session_->systemTouchable_, touchable);
1287 }
1288 
1289 /**
1290  * @tc.name: GetSystemTouchable
1291  * @tc.desc: GetSystemTouchable
1292  * @tc.type: FUNC
1293  */
1294 HWTEST_F(WindowSessionTest2, GetSystemTouchable, Function | SmallTest | Level2)
1295 {
1296     ASSERT_NE(session_, nullptr);
1297     bool res = session_->GetSystemTouchable();
1298     ASSERT_EQ(res, true);
1299 }
1300 
1301 /**
1302  * @tc.name: SetRSVisible
1303  * @tc.desc: SetRSVisible
1304  * @tc.type: FUNC
1305  */
1306 HWTEST_F(WindowSessionTest2, SetVisible, Function | SmallTest | Level2)
1307 {
1308     ASSERT_NE(session_, nullptr);
1309     bool isVisible = false;
1310     ASSERT_EQ(WSError::WS_OK, session_->SetRSVisible(isVisible));
1311 }
1312 
1313 /**
1314  * @tc.name: GetRSVisible02
1315  * @tc.desc: GetRSVisible
1316  * @tc.type: FUNC
1317  */
1318 HWTEST_F(WindowSessionTest2, GetVisible02, Function | SmallTest | Level2)
1319 {
1320     ASSERT_NE(session_, nullptr);
1321     if (!session_->GetRSVisible()) {
1322         ASSERT_EQ(false, session_->GetRSVisible());
1323     }
1324 }
1325 
1326 /**
1327  * @tc.name: SetVisibilityState
1328  * @tc.desc: SetVisibilityState
1329  * @tc.type: FUNC
1330  */
1331 HWTEST_F(WindowSessionTest2, SetVisibilityState, Function | SmallTest | Level2)
1332 {
1333     ASSERT_NE(session_, nullptr);
1334     WindowVisibilityState state { WINDOW_VISIBILITY_STATE_NO_OCCLUSION};
1335     ASSERT_EQ(WSError::WS_OK, session_->SetVisibilityState(state));
1336     ASSERT_EQ(state, session_->visibilityState_);
1337 }
1338 
1339 /**
1340  * @tc.name: GetVisibilityState
1341  * @tc.desc: GetVisibilityState
1342  * @tc.type: FUNC
1343  */
1344 HWTEST_F(WindowSessionTest2, GetVisibilityState, Function | SmallTest | Level2)
1345 {
1346     ASSERT_NE(session_, nullptr);
1347     WindowVisibilityState state { WINDOW_LAYER_STATE_MAX};
1348     ASSERT_EQ(state, session_->GetVisibilityState());
1349 }
1350 
1351 /**
1352  * @tc.name: SetDrawingContentState
1353  * @tc.desc: SetDrawingContentState
1354  * @tc.type: FUNC
1355  */
1356 HWTEST_F(WindowSessionTest2, SetDrawingContentState, Function | SmallTest | Level2)
1357 {
1358     ASSERT_NE(session_, nullptr);
1359     bool isRSDrawing = false;
1360     ASSERT_EQ(WSError::WS_OK, session_->SetDrawingContentState(isRSDrawing));
1361     ASSERT_EQ(false, session_->isRSDrawing_);
1362 }
1363 
1364 /**
1365  * @tc.name: GetDrawingContentState
1366  * @tc.desc: GetDrawingContentState
1367  * @tc.type: FUNC
1368  */
1369 HWTEST_F(WindowSessionTest2, GetDrawingContentState, Function | SmallTest | Level2)
1370 {
1371     ASSERT_NE(session_, nullptr);
1372     bool res = session_->GetDrawingContentState();
1373     ASSERT_EQ(res, false);
1374 }
1375 
1376 /**
1377  * @tc.name: GetBrightness
1378  * @tc.desc: GetBrightness
1379  * @tc.type: FUNC
1380  */
1381 HWTEST_F(WindowSessionTest2, GetBrightness, Function | SmallTest | Level2)
1382 {
1383     ASSERT_NE(session_, nullptr);
1384     session_->state_ = SessionState::STATE_DISCONNECT;
1385     session_->property_ = nullptr;
1386     ASSERT_EQ(UNDEFINED_BRIGHTNESS, session_->GetBrightness());
1387 }
1388 
1389 /**
1390  * @tc.name: IsActive02
1391  * @tc.desc: IsActive
1392  * @tc.type: FUNC
1393  */
1394 HWTEST_F(WindowSessionTest2, IsActive02, Function | SmallTest | Level2)
1395 {
1396     ASSERT_NE(session_, nullptr);
1397     bool res = session_->IsActive();
1398     ASSERT_EQ(res, false);
1399 }
1400 
1401 /**
1402  * @tc.name: IsSystemSession
1403  * @tc.desc: IsSystemSession
1404  * @tc.type: FUNC
1405  */
1406 HWTEST_F(WindowSessionTest2, IsSystemSession, Function | SmallTest | Level2)
1407 {
1408     ASSERT_NE(session_, nullptr);
1409     bool res = session_->IsSystemSession();
1410     ASSERT_EQ(res, false);
1411 }
1412 
1413 /**
1414  * @tc.name: Hide
1415  * @tc.desc: Hide
1416  * @tc.type: FUNC
1417  */
1418 HWTEST_F(WindowSessionTest2, Hide, Function | SmallTest | Level2)
1419 {
1420     ASSERT_NE(session_, nullptr);
1421     auto result = session_->Hide();
1422     ASSERT_EQ(result, WSError::WS_OK);
1423 }
1424 
1425 /**
1426  * @tc.name: Show
1427  * @tc.desc: Show
1428  * @tc.type: FUNC
1429  */
1430 HWTEST_F(WindowSessionTest2, Show, Function | SmallTest | Level2)
1431 {
1432     ASSERT_NE(session_, nullptr);
1433     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1434     ASSERT_NE(nullptr, property);
1435     auto result = session_->Show(property);
1436     ASSERT_EQ(result, WSError::WS_OK);
1437 }
1438 
1439 /**
1440  * @tc.name: DrawingCompleted
1441  * @tc.desc: DrawingCompleled
1442  * @tc.type: FUNC
1443  */
1444 HWTEST_F(WindowSessionTest2, DrawingCompleted, Function | SmallTest | Level2)
1445 {
1446     ASSERT_NE(session_, nullptr);
1447     auto result = session_->DrawingCompleted();
1448     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1449 }
1450 
1451 /**
1452  * @tc.name: RemoveStartingWindow
1453  * @tc.desc: RemoveStartingWindow
1454  * @tc.type: FUNC
1455  */
1456 HWTEST_F(WindowSessionTest2, RemoveStartingWindow, Function | SmallTest | Level2)
1457 {
1458     ASSERT_NE(session_, nullptr);
1459     session_->RegisterLifecycleListener(lifecycleListener_);
1460     session_->RemoveStartingWindow();
1461     uint64_t screenId = 0;
1462     session_->SetScreenId(screenId);
1463     session_->UnregisterLifecycleListener(lifecycleListener_);
1464     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1465 }
1466 
1467 /**
1468  * @tc.name: IsSystemActive
1469  * @tc.desc: IsSystemActive
1470  * @tc.type: FUNC
1471  */
1472 HWTEST_F(WindowSessionTest2, IsSystemActive, Function | SmallTest | Level2)
1473 {
1474     ASSERT_NE(session_, nullptr);
1475     bool res = session_->IsSystemActive();
1476     ASSERT_EQ(res, false);
1477 }
1478 
1479 /**
1480  * @tc.name: SetSystemActive
1481  * @tc.desc: SetSystemActive
1482  * @tc.type: FUNC
1483  */
1484 HWTEST_F(WindowSessionTest2, SetSystemActive, Function | SmallTest | Level2)
1485 {
1486     ASSERT_NE(session_, nullptr);
1487     bool systemActive = false;
1488     session_->SetSystemActive(systemActive);
1489     ASSERT_EQ(systemActive, session_->isSystemActive_);
1490 }
1491 
1492 /**
1493  * @tc.name: IsTerminated
1494  * @tc.desc: IsTerminated
1495  * @tc.type: FUNC
1496  */
1497 HWTEST_F(WindowSessionTest2, IsTerminated, Function | SmallTest | Level2)
1498 {
1499     ASSERT_NE(session_, nullptr);
1500     session_->state_ = SessionState::STATE_DISCONNECT;
1501     bool res = session_->IsTerminated();
1502     ASSERT_EQ(true, res);
1503     session_->state_ = SessionState::STATE_FOREGROUND;
1504     res = session_->IsTerminated();
1505     ASSERT_EQ(false, res);
1506     session_->state_ = SessionState::STATE_ACTIVE;
1507     res = session_->IsTerminated();
1508     ASSERT_EQ(false, res);
1509     session_->state_ = SessionState::STATE_INACTIVE;
1510     res = session_->IsTerminated();
1511     ASSERT_EQ(false, res);
1512     session_->state_ = SessionState::STATE_BACKGROUND;
1513     res = session_->IsTerminated();
1514     ASSERT_EQ(false, res);
1515     session_->state_ = SessionState::STATE_CONNECT;
1516     res = session_->IsTerminated();
1517     ASSERT_EQ(false, res);
1518 }
1519 
1520 /**
1521  * @tc.name: SetAttachState01
1522  * @tc.desc: SetAttachState Test
1523  * @tc.type: FUNC
1524  */
1525 HWTEST_F(WindowSessionTest2, SetAttachState01, Function | SmallTest | Level2)
1526 {
1527     ASSERT_NE(session_, nullptr);
1528     session_->SetAttachState(false);
1529     ASSERT_EQ(session_->isAttach_, false);
1530 }
1531 
1532 /**
1533  * @tc.name: SetAttachState02
1534  * @tc.desc: SetAttachState Test
1535  * @tc.type: FUNC
1536  */
1537 HWTEST_F(WindowSessionTest2, SetAttachState02, Function | SmallTest | Level2)
1538 {
1539     ASSERT_NE(session_, nullptr);
1540     int32_t persistentId = 123;
1541     sptr<PatternDetachCallbackMocker> detachCallback = new PatternDetachCallbackMocker();
1542     EXPECT_CALL(*detachCallback, OnPatternDetach(persistentId)).Times(1);
1543     session_->persistentId_ = persistentId;
1544     session_->SetAttachState(true);
1545     session_->RegisterDetachCallback(detachCallback);
1546     session_->SetAttachState(false);
1547     usleep(WAIT_SYNC_IN_NS);
1548     Mock::VerifyAndClearExpectations(&detachCallback);
1549 }
1550 
1551 /**
1552  * @tc.name: RegisterDetachCallback01
1553  * @tc.desc: RegisterDetachCallback Test
1554  * @tc.type: FUNC
1555  */
1556 HWTEST_F(WindowSessionTest2, RegisterDetachCallback01, Function | SmallTest | Level2)
1557 {
1558     ASSERT_NE(session_, nullptr);
1559     sptr<IPatternDetachCallback> detachCallback;
1560     session_->RegisterDetachCallback(detachCallback);
1561     ASSERT_EQ(session_->detachCallback_, detachCallback);
1562 }
1563 
1564 /**
1565  * @tc.name: RegisterDetachCallback02
1566  * @tc.desc: RegisterDetachCallback Test
1567  * @tc.type: FUNC
1568  */
1569 HWTEST_F(WindowSessionTest2, RegisterDetachCallback02, Function | SmallTest | Level2)
1570 {
1571     ASSERT_NE(session_, nullptr);
1572     sptr<IPatternDetachCallback> detachCallback;
1573     session_->RegisterDetachCallback(detachCallback);
1574     ASSERT_EQ(session_->detachCallback_, detachCallback);
1575     sptr<IPatternDetachCallback> detachCallback2;
1576     session_->RegisterDetachCallback(detachCallback2);
1577     ASSERT_EQ(session_->detachCallback_, detachCallback2);
1578 }
1579 
1580 /**
1581  * @tc.name: RegisterDetachCallback03
1582  * @tc.desc: RegisterDetachCallback Test
1583  * @tc.type: FUNC
1584  */
1585 HWTEST_F(WindowSessionTest2, RegisterDetachCallback03, Function | SmallTest | Level2)
1586 {
1587     ASSERT_NE(session_, nullptr);
1588     int32_t persistentId = 123;
1589     sptr<PatternDetachCallbackMocker> detachCallback = new PatternDetachCallbackMocker();
1590     EXPECT_CALL(*detachCallback, OnPatternDetach(persistentId)).Times(::testing::AtLeast(1));
1591     session_->persistentId_ = persistentId;
1592     session_->SetAttachState(true);
1593     session_->SetAttachState(false);
1594     session_->RegisterDetachCallback(detachCallback);
1595     Mock::VerifyAndClearExpectations(&detachCallback);
1596 }
1597 
1598 /**
1599  * @tc.name: SetContextTransparentFunc
1600  * @tc.desc: SetContextTransparentFunc Test
1601  * @tc.type: FUNC
1602  */
1603 HWTEST_F(WindowSessionTest2, SetContextTransparentFunc, Function | SmallTest | Level2)
1604 {
1605     ASSERT_NE(session_, nullptr);
1606     session_->SetContextTransparentFunc(nullptr);
1607     ASSERT_EQ(session_->contextTransparentFunc_, nullptr);
__anond2f947a70902()1608     NotifyContextTransparentFunc func = [](){};
1609     session_->SetContextTransparentFunc(func);
1610     ASSERT_NE(session_->contextTransparentFunc_, nullptr);
1611 }
1612 
1613 /**
1614  * @tc.name: NeedCheckContextTransparent
1615  * @tc.desc: NeedCheckContextTransparent Test
1616  * @tc.type: FUNC
1617  */
1618 HWTEST_F(WindowSessionTest2, NeedCheckContextTransparent, Function | SmallTest | Level2)
1619 {
1620     ASSERT_NE(session_, nullptr);
1621     session_->SetContextTransparentFunc(nullptr);
1622     ASSERT_EQ(session_->NeedCheckContextTransparent(), false);
__anond2f947a70a02()1623     NotifyContextTransparentFunc func = [](){};
1624     session_->SetContextTransparentFunc(func);
1625     ASSERT_EQ(session_->NeedCheckContextTransparent(), true);
1626 }
1627 
1628 /**
1629  * @tc.name: SetShowRecent001
1630  * @tc.desc: Exist detect task when in recent.
1631  * @tc.type: FUNC
1632  */
1633 HWTEST_F(WindowSessionTest2, SetShowRecent001, Function | SmallTest | Level2)
1634 {
1635     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anond2f947a70b02()1636     auto task = [](){};
1637     int64_t delayTime = 3000;
1638     session_->handler_->PostTask(task, taskName, delayTime);
1639     int32_t beforeTaskNum = GetTaskCount();
1640 
1641     session_->SetShowRecent(true);
1642     ASSERT_EQ(beforeTaskNum, GetTaskCount());
1643     session_->handler_->RemoveTask(taskName);
1644 }
1645 
1646 /**
1647  * @tc.name: SetShowRecent002
1648  * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is false.
1649  * @tc.type: FUNC
1650  */
1651 HWTEST_F(WindowSessionTest2, SetShowRecent002, Function | SmallTest | Level2)
1652 {
1653     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anond2f947a70c02()1654     auto task = [](){};
1655     int64_t delayTime = 3000;
1656     session_->handler_->PostTask(task, taskName, delayTime);
1657     session_->showRecent_ = false;
1658     int32_t beforeTaskNum = GetTaskCount();
1659 
1660     session_->SetShowRecent(false);
1661     ASSERT_EQ(beforeTaskNum, GetTaskCount());
1662     session_->handler_->RemoveTask(taskName);
1663 }
1664 
1665 /**
1666  * @tc.name: SetShowRecent003
1667  * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is true, detach task.
1668  * @tc.type: FUNC
1669  */
1670 HWTEST_F(WindowSessionTest2, SetShowRecent003, Function | SmallTest | Level2)
1671 {
1672     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anond2f947a70d02()1673     auto task = [](){};
1674     int64_t delayTime = 3000;
1675     session_->handler_->PostTask(task, taskName, delayTime);
1676     session_->showRecent_ = true;
1677     session_->isAttach_ = false;
1678     int32_t beforeTaskNum = GetTaskCount();
1679 
1680     session_->SetShowRecent(false);
1681     ASSERT_EQ(beforeTaskNum, GetTaskCount());
1682     session_->handler_->RemoveTask(taskName);
1683 }
1684 
1685 /**
1686  * @tc.name: SetShowRecent004
1687  * @tc.desc: SetShowRecent
1688  * @tc.type: FUNC
1689  */
1690 HWTEST_F(WindowSessionTest2, SetShowRecent004, Function | SmallTest | Level2)
1691 {
1692     session_->systemConfig_.uiType_ = "phone";
1693     ssm_->SetScreenLocked(false);
1694 
1695     session_->property_ = new WindowSessionProperty();
1696     session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1697 
1698     bool showRecent = false;
1699     session_->showRecent_ = true;
1700     session_->SetAttachState(true);
1701     session_->SetShowRecent(showRecent);
1702     ASSERT_EQ(session_->GetShowRecent(), showRecent);
1703 }
1704 
1705 /**
1706  * @tc.name: CreateDetectStateTask001
1707  * @tc.desc: Create detection task when there are no pre_existing tasks.
1708  * @tc.type: FUNC
1709  */
1710 HWTEST_F(WindowSessionTest2, CreateDetectStateTask001, Function | SmallTest | Level2)
1711 {
1712     session_->systemConfig_.uiType_ = "phone";
1713     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1714     DetectTaskInfo detectTaskInfo;
1715     detectTaskInfo.taskState = DetectTaskState::NO_TASK;
1716     int32_t beforeTaskNum = GetTaskCount();
1717     session_->SetDetectTaskInfo(detectTaskInfo);
1718     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1719 
1720     ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1721     ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState);
1722     session_->handler_->RemoveTask(taskName);
1723 
1724     session_->showRecent_ = true;
1725     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1726 }
1727 
1728 /**
1729  * @tc.name: CreateDetectStateTask002
1730  * @tc.desc: Detect state when window mode changed.
1731  * @tc.type: FUNC
1732  */
1733 HWTEST_F(WindowSessionTest2, CreateDetectStateTask002, Function | SmallTest | Level2)
1734 {
1735     session_->systemConfig_.uiType_ = "phone";
1736     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
__anond2f947a70e02()1737     auto task = [](){};
1738     int64_t delayTime = 3000;
1739     session_->handler_->PostTask(task, taskName, delayTime);
1740     int32_t beforeTaskNum = GetTaskCount();
1741 
1742     DetectTaskInfo detectTaskInfo;
1743     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1744     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1745     session_->SetDetectTaskInfo(detectTaskInfo);
1746     session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1747 
1748     ASSERT_EQ(beforeTaskNum - 1, GetTaskCount());
1749     ASSERT_EQ(DetectTaskState::NO_TASK, session_->GetDetectTaskInfo().taskState);
1750     ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, session_->GetDetectTaskInfo().taskWindowMode);
1751     session_->handler_->RemoveTask(taskName);
1752 
1753     session_->showRecent_ = true;
1754     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1755 }
1756 
1757 /**
1758  * @tc.name: CreateDetectStateTask003
1759  * @tc.desc: Detect sup and down tree tasks for the same type.
1760  * @tc.type: FUNC
1761  */
1762 HWTEST_F(WindowSessionTest2, CreateDetectStateTask003, Function | SmallTest | Level2)
1763 {
1764     session_->systemConfig_.uiType_ = "phone";
1765     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1766     DetectTaskInfo detectTaskInfo;
1767     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1768     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1769     int32_t beforeTaskNum = GetTaskCount();
1770     session_->SetDetectTaskInfo(detectTaskInfo);
1771     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1772 
1773     ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1774     ASSERT_EQ(DetectTaskState::DETACH_TASK, session_->GetDetectTaskInfo().taskState);
1775     session_->handler_->RemoveTask(taskName);
1776 
1777     session_->showRecent_ = true;
1778     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
1779 }
1780 
1781 /**
1782  * @tc.name: CreateDetectStateTask004
1783  * @tc.desc: Detection tasks under the same window mode.
1784  * @tc.type: FUNC
1785  */
1786 HWTEST_F(WindowSessionTest2, CreateDetectStateTask004, Function | SmallTest | Level2)
1787 {
1788     session_->systemConfig_.uiType_ = "phone";
1789     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1790     DetectTaskInfo detectTaskInfo;
1791     int32_t beforeTaskNum = GetTaskCount();
1792     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1793     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1794     session_->SetDetectTaskInfo(detectTaskInfo);
1795     session_->CreateDetectStateTask(true, WindowMode::WINDOW_MODE_FULLSCREEN);
1796 
1797     ASSERT_EQ(beforeTaskNum + 1, GetTaskCount());
1798     ASSERT_EQ(DetectTaskState::ATTACH_TASK, session_->GetDetectTaskInfo().taskState);
1799     session_->handler_->RemoveTask(taskName);
1800 
1801     session_->showRecent_ = true;
1802     session_->CreateDetectStateTask(false, WindowMode::WINDOW_MODE_FULLSCREEN);
1803 }
1804 
1805 /**
1806  * @tc.name: GetAttachState001
1807  * @tc.desc: GetAttachState001
1808  * @tc.type: FUNC
1809  */
1810 HWTEST_F(WindowSessionTest2, GetAttachState001, Function | SmallTest | Level2)
1811 {
1812     std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1813     session_->SetAttachState(false);
1814     bool isAttach = session_->GetAttachState();
1815     ASSERT_EQ(false, isAttach);
1816     session_->handler_->RemoveTask(taskName);
1817 }
1818 
1819 /**
1820  * @tc.name: ResetSessionConnectState
1821  * @tc.desc: ResetSessionConnectState
1822  * @tc.type: FUNC
1823  */
1824 HWTEST_F(WindowSessionTest2, ResetSessionConnectState, Function | SmallTest | Level2)
1825 {
1826     ASSERT_NE(session_, nullptr);
1827     session_->ResetSessionConnectState();
1828     ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
1829     ASSERT_EQ(session_->GetCallingPid(), -1);
1830 }
1831 
1832 /**
1833  * @tc.name: ResetIsActive
1834  * @tc.desc: ResetIsActive
1835  * @tc.type: FUNC
1836  */
1837 HWTEST_F(WindowSessionTest2, ResetIsActive, Function | SmallTest | Level2)
1838 {
1839     ASSERT_NE(session_, nullptr);
1840     session_->ResetIsActive();
1841     ASSERT_EQ(session_->isActive_, false);
1842 }
1843 
1844 /**
1845  * @tc.name: PostExportTask02
1846  * @tc.desc: PostExportTask
1847  * @tc.type: FUNC
1848  */
1849 HWTEST_F(WindowSessionTest2, PostExportTask02, Function | SmallTest | Level2)
1850 {
1851     ASSERT_NE(session_, nullptr);
1852     std::string name = "sessionExportTask";
__anond2f947a70f02()1853     auto task = [](){};
1854     int64_t delayTime = 0;
1855 
1856     session_->PostExportTask(task, name, delayTime);
1857     auto result = session_->GetBufferAvailable();
1858     ASSERT_EQ(result, false);
1859 
1860     sptr<SceneSessionManager> sceneSessionManager = new SceneSessionManager();
1861     session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(),
1862         sceneSessionManager->eventHandler_);
1863     session_->PostExportTask(task, name, delayTime);
1864     auto result2 = session_->GetBufferAvailable();
1865     ASSERT_EQ(result2, false);
1866 }
1867 
1868 /**
1869  * @tc.name: SetLeashWinSurfaceNode02
1870  * @tc.desc: SetLeashWinSurfaceNode
1871  * @tc.type: FUNC
1872  */
1873 HWTEST_F(WindowSessionTest2, SetLeashWinSurfaceNode02, Function | SmallTest | Level2)
1874 {
1875     ASSERT_NE(session_, nullptr);
1876     session_->leashWinSurfaceNode_ = WindowSessionTest2::CreateRSSurfaceNode();
1877     session_->SetLeashWinSurfaceNode(nullptr);
1878 
1879     session_->leashWinSurfaceNode_ = nullptr;
1880     session_->SetLeashWinSurfaceNode(nullptr);
1881     auto result = session_->GetBufferAvailable();
1882     ASSERT_EQ(result, false);
1883 }
1884 
1885 /**
1886  * @tc.name: GetCloseAbilityWantAndClean
1887  * @tc.desc: GetCloseAbilityWantAndClean
1888  * @tc.type: FUNC
1889  */
1890 HWTEST_F(WindowSessionTest2, GetCloseAbilityWantAndClean, Function | SmallTest | Level2)
1891 {
1892     ASSERT_NE(session_, nullptr);
1893     AAFwk::Want outWant;
1894     session_->sessionInfo_.closeAbilityWant = std::make_shared<AAFwk::Want>();
1895     session_->GetCloseAbilityWantAndClean(outWant);
1896 
1897     session_->sessionInfo_.closeAbilityWant = nullptr;
1898     session_->GetCloseAbilityWantAndClean(outWant);
1899     auto result = session_->GetBufferAvailable();
1900     ASSERT_EQ(result, false);
1901 }
1902 
1903 /**
1904  * @tc.name: SetScreenId02
1905  * @tc.desc: SetScreenId Test
1906  * @tc.type: FUNC
1907  */
1908 HWTEST_F(WindowSessionTest2, SetScreenId02, Function | SmallTest | Level2)
1909 {
1910     ASSERT_NE(session_, nullptr);
1911     uint64_t screenId = 0;
1912     session_->sessionStage_ = new (std::nothrow) SessionStageMocker();
1913     session_->SetScreenId(screenId);
1914     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1915 }
1916 
1917 /**
1918  * @tc.name: SetSessionState
1919  * @tc.desc: SetSessionState
1920  * @tc.type: FUNC
1921  */
1922 HWTEST_F(WindowSessionTest2, SetSessionState, Function | SmallTest | Level2)
1923 {
1924     ASSERT_NE(session_, nullptr);
1925 
1926     SessionState state03 = SessionState::STATE_CONNECT;
1927     session_->SetSessionState(state03);
1928     ASSERT_EQ(state03, session_->state_);
1929 }
1930 
1931 /**
1932  * @tc.name: SetFocusable03
1933  * @tc.desc: SetFocusable
1934  * @tc.type: FUNC
1935  */
1936 HWTEST_F(WindowSessionTest2, SetFocusable03, Function | SmallTest | Level2)
1937 {
1938     ASSERT_NE(session_, nullptr);
1939     session_->isFocused_ = true;
1940     session_->property_ = new (std::nothrow) WindowSessionProperty();
1941     session_->property_->focusable_ = false;
1942     bool isFocusable = true;
1943 
1944     auto result = session_->SetFocusable(isFocusable);
1945     ASSERT_EQ(result, WSError::WS_OK);
1946 }
1947 
1948 /**
1949  * @tc.name: GetFocused
1950  * @tc.desc: GetFocused Test
1951  * @tc.type: FUNC
1952  */
1953 HWTEST_F(WindowSessionTest2, GetFocused, Function | SmallTest | Level2)
1954 {
1955     ASSERT_NE(session_, nullptr);
1956     bool result = session_->GetFocused();
1957     ASSERT_EQ(result, false);
1958 
1959     session_->isFocused_ = true;
1960     bool result2 = session_->GetFocused();
1961     ASSERT_EQ(result2, true);
1962 }
1963 
1964 /**
1965  * @tc.name: UpdatePointerArea
1966  * @tc.desc: UpdatePointerArea Test
1967  * @tc.type: FUNC
1968  */
1969 HWTEST_F(WindowSessionTest2, UpdatePointerArea, Function | SmallTest | Level2)
1970 {
1971     ASSERT_NE(session_, nullptr);
1972     WSRect rect = { 0, 0, 0, 0 };
1973     session_->preRect_ = rect;
1974     session_->UpdatePointerArea(rect);
1975     ASSERT_EQ(session_->GetFocused(), false);
1976 }
1977 
1978 /**
1979  * @tc.name: UpdateSizeChangeReason02
1980  * @tc.desc: UpdateSizeChangeReason Test
1981  * @tc.type: FUNC
1982  */
1983 HWTEST_F(WindowSessionTest2, UpdateSizeChangeReason02, Function | SmallTest | Level2)
1984 {
1985     ASSERT_NE(session_, nullptr);
1986     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1987     WSError result = session_->UpdateSizeChangeReason(reason);
1988     ASSERT_EQ(result, WSError::WS_DO_NOTHING);
1989 }
1990 
1991 /**
1992  * @tc.name: UpdateDensity
1993  * @tc.desc: UpdateDensity Test
1994  * @tc.type: FUNC
1995  */
1996 HWTEST_F(WindowSessionTest2, UpdateDensity, Function | SmallTest | Level2)
1997 {
1998     ASSERT_NE(session_, nullptr);
1999 
2000     session_->state_ = SessionState::STATE_DISCONNECT;
2001     ASSERT_FALSE(session_->IsSessionValid());
2002     WSError result = session_->UpdateDensity();
2003     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
2004 
2005     session_->state_ = SessionState::STATE_CONNECT;
2006     ASSERT_TRUE(session_->IsSessionValid());
2007     session_->sessionStage_ = nullptr;
2008     WSError result02 = session_->UpdateDensity();
2009     ASSERT_EQ(result02, WSError::WS_ERROR_NULLPTR);
2010 }
2011 
2012 /**
2013  * @tc.name: UpdateSizeChangeReason
2014  * @tc.desc: UpdateSizeChangeReason UpdateDensity
2015  * @tc.type: FUNC
2016  */
2017 HWTEST_F(WindowSessionTest2, UpdateSizeChangeReason, Function | SmallTest | Level2)
2018 {
2019     SizeChangeReason reason = SizeChangeReason{1};
2020     ASSERT_EQ(session_->UpdateSizeChangeReason(reason), WSError::WS_OK);
2021 }
2022 
2023 /**
2024  * @tc.name: SetPendingSessionActivationEventListener
2025  * @tc.desc: SetPendingSessionActivationEventListener
2026  * @tc.type: FUNC
2027  */
2028 HWTEST_F(WindowSessionTest2, SetPendingSessionActivationEventListener, Function | SmallTest | Level2)
2029 {
2030     int resultValue = 0;
__anond2f947a71002(const SessionInfo& info) 2031     session_->SetPendingSessionActivationEventListener([&resultValue](const SessionInfo& info) {
2032         resultValue = 1;
2033     });
2034     usleep(WAIT_SYNC_IN_NS);
__anond2f947a71102(const SessionInfo& info) 2035     session_->SetTerminateSessionListener([&resultValue](const SessionInfo& info) {
2036         resultValue = 2;
2037     });
2038     usleep(WAIT_SYNC_IN_NS);
2039     LifeCycleTaskType taskType = LifeCycleTaskType{0};
2040     session_->RemoveLifeCycleTask(taskType);
2041     ASSERT_EQ(resultValue, 0);
2042 }
2043 
2044 /**
2045  * @tc.name: SetSessionIcon
2046  * @tc.desc: SetSessionIcon UpdateDensity
2047  * @tc.type: FUNC
2048  */
2049 HWTEST_F(WindowSessionTest2, SetSessionIcon, Function | SmallTest | Level2)
2050 {
2051     std::shared_ptr<Media::PixelMap> icon;
2052     session_->SetSessionIcon(icon);
2053     ASSERT_EQ(session_->Clear(), WSError::WS_OK);
2054     session_->SetSessionSnapshotListener(nullptr);
__anond2f947a71202(const SessionInfo& info) 2055     NotifyPendingSessionActivationFunc func = [](const SessionInfo& info) {};
2056     session_->pendingSessionActivationFunc_ = func;
2057     ASSERT_EQ(session_->PendingSessionToForeground(), WSError::WS_OK);
2058 
2059     session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("SetSessionIcon", 1);
2060     session_->updateSessionIconFunc_ = nullptr;
2061     ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
2062 
__anond2f947a71302(const std::string& iconPath) 2063     NofitySessionIconUpdatedFunc func2 = [](const std::string& iconPath) {};
2064     session_->updateSessionIconFunc_ = func2;
2065     ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
2066 
__anond2f947a71402(const SessionInfo& info, bool needStartCaller, bool isFromBroker) 2067     NotifyTerminateSessionFuncNew func3 = [](const SessionInfo& info, bool needStartCaller, bool isFromBroker) {};
2068     session_->terminateSessionFuncNew_ = func3;
2069     ASSERT_EQ(WSError::WS_OK, session_->Clear());
2070 }
2071 
2072 /**
2073  * @tc.name: SetSessionExceptionListener
2074  * @tc.desc: SetSessionExceptionListener
2075  * @tc.type: FUNC
2076  */
2077 HWTEST_F(WindowSessionTest2, SetSessionExceptionListener, Function | SmallTest | Level2)
2078 {
2079     session_->SetSessionExceptionListener(nullptr, true);
__anond2f947a71502(const SessionInfo& info, bool removeSession, bool startFail) 2080     session_->SetSessionExceptionListener([](const SessionInfo& info, bool removeSession, bool startFail) {}, true);
2081     usleep(WAIT_SYNC_IN_NS);
2082     ASSERT_NE(nullptr, session_->jsSceneSessionExceptionFunc_);
2083 }
2084 
2085 /**
2086  * @tc.name: SetRaiseToAppTopForPointDownFunc
2087  * @tc.desc: SetRaiseToAppTopForPointDownFunc Test
2088  * @tc.type: FUNC
2089  */
2090 HWTEST_F(WindowSessionTest2, SetRaiseToAppTopForPointDownFunc, Function | SmallTest | Level2)
2091 {
2092     ASSERT_NE(session_, nullptr);
2093     session_->SetRaiseToAppTopForPointDownFunc(nullptr);
2094 
__anond2f947a71602() 2095     NotifyRaiseToTopForPointDownFunc func = []() {};
2096     session_->raiseToTopForPointDownFunc_ = func;
2097     session_->RaiseToAppTopForPointDown();
2098     session_->HandlePointDownDialog();
2099     session_->ClearDialogVector();
2100 
2101     session_->SetBufferAvailableChangeListener(nullptr);
2102     session_->UnregisterSessionChangeListeners();
2103     session_->SetSessionStateChangeNotifyManagerListener(nullptr);
2104     session_->SetSessionInfoChangeNotifyManagerListener(nullptr);
2105     session_->NotifyFocusStatus(true);
2106 
2107     session_->SetRequestFocusStatusNotifyManagerListener(nullptr);
2108     session_->SetNotifyUIRequestFocusFunc(nullptr);
2109     session_->SetNotifyUILostFocusFunc(nullptr);
2110     session_->UnregisterSessionChangeListeners();
2111 
__anond2f947a71702(const SessionInfo& info, bool shouldBackToCaller) 2112     NotifyPendingSessionToBackgroundForDelegatorFunc func2 = [](const SessionInfo& info, bool shouldBackToCaller) {};
2113     session_->pendingSessionToBackgroundForDelegatorFunc_ = func2;
2114     ASSERT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
2115 }
2116 
2117 /**
2118  * @tc.name: NotifyCloseExistPipWindow
2119  * @tc.desc: check func NotifyCloseExistPipWindow
2120  * @tc.type: FUNC
2121  */
2122 HWTEST_F(WindowSessionTest2, NotifyCloseExistPipWindow, Function | SmallTest | Level2)
2123 {
2124     sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
2125     ASSERT_NE(mockSessionStage, nullptr);
2126     ManagerState key = ManagerState{0};
2127     session_->GetStateFromManager(key);
2128     session_->NotifyUILostFocus();
2129 
__anond2f947a71802() 2130     session_->lostFocusFunc_ = []() {};
2131     session_->NotifyUILostFocus();
2132 
2133     session_->SetSystemSceneBlockingFocus(true);
2134     session_->GetBlockingFocus();
2135     session_->sessionStage_ = mockSessionStage;
2136     EXPECT_CALL(*(mockSessionStage), NotifyCloseExistPipWindow()).Times(1).WillOnce(Return(WSError::WS_OK));
2137     ASSERT_EQ(WSError::WS_OK, session_->NotifyCloseExistPipWindow());
2138     session_->sessionStage_ = nullptr;
2139     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyCloseExistPipWindow());
2140 }
2141 
2142 /**
2143  * @tc.name: SetSystemConfig
2144  * @tc.desc: SetSystemConfig Test
2145  * @tc.type: FUNC
2146  */
2147 HWTEST_F(WindowSessionTest2, SetSystemConfig, Function | SmallTest | Level2)
2148 {
2149     ASSERT_NE(session_, nullptr);
2150     SystemSessionConfig systemConfig;
2151     session_->SetSystemConfig(systemConfig);
2152     float snapshotScale = 0.5;
2153     session_->SetSnapshotScale(snapshotScale);
2154     session_->ProcessBackEvent();
2155     session_->NotifyOccupiedAreaChangeInfo(nullptr);
2156     session_->UpdateMaximizeMode(true);
2157     ASSERT_EQ(session_->GetZOrder(), 0);
2158 
2159     session_->SetUINodeId(0);
2160     session_->GetUINodeId();
2161     session_->SetShowRecent(true);
2162     session_->GetShowRecent();
2163     session_->SetBufferAvailable(true);
2164 
2165     session_->SetNeedSnapshot(true);
2166     session_->SetFloatingScale(0.5);
2167     ASSERT_EQ(session_->GetFloatingScale(), 0.5f);
2168     session_->SetScale(50, 100, 50, 100);
2169     session_->GetScaleX();
2170     session_->GetScaleY();
2171     session_->GetPivotX();
2172     session_->GetPivotY();
2173     session_->SetSCBKeepKeyboard(true);
2174     session_->GetSCBKeepKeyboardFlag();
2175     ASSERT_EQ(WSError::WS_OK, session_->MarkProcessed(11));
2176 }
2177 
2178 /**
2179  * @tc.name: SetOffset
2180  * @tc.desc: SetOffset Test
2181  * @tc.type: FUNC
2182  */
2183 HWTEST_F(WindowSessionTest2, SetOffset, Function | SmallTest | Level2)
2184 {
2185     ASSERT_NE(session_, nullptr);
2186     session_->SetOffset(50, 100);
2187     session_->GetOffsetX();
2188     session_->GetOffsetY();
2189     WSRectF bounds;
2190     session_->SetBounds(bounds);
2191     session_->GetBounds();
2192     session_->UpdateTitleInTargetPos(true, 100);
2193     session_->SetNotifySystemSessionPointerEventFunc(nullptr);
2194     session_->SetNotifySystemSessionKeyEventFunc(nullptr);
2195     ASSERT_EQ(session_->GetBufferAvailable(), false);
2196 }
2197 
2198 /**
2199  * @tc.name: SetBackPressedListenser
2200  * @tc.desc: SetBackPressedListenser Test
2201  * @tc.type: FUNC
2202  */
2203 HWTEST_F(WindowSessionTest2, SetBackPressedListenser, Function | SmallTest | Level2)
2204 {
2205     ASSERT_NE(session_, nullptr);
2206     int32_t result = 0;
__anond2f947a71902(const bool needMoveToBackground) 2207     session_->SetBackPressedListenser([&result](const bool needMoveToBackground) {
2208         result = 1;
2209     });
2210     usleep(WAIT_SYNC_IN_NS);
2211     session_->backPressedFunc_(true);
2212     ASSERT_EQ(result, 1);
2213 }
2214 
2215 /**
2216  * @tc.name: SetUpdateSessionIconListener
2217  * @tc.desc: SetUpdateSessionIconListener Test
2218  * @tc.type: FUNC
2219  */
2220 HWTEST_F(WindowSessionTest2, SetUpdateSessionIconListener, Function | SmallTest | Level2)
2221 {
2222     ASSERT_NE(session_, nullptr);
2223     WLOGFI("SetUpdateSessionIconListener begin!");
2224 
2225     session_->SetUpdateSessionIconListener(session_->updateSessionIconFunc_);
2226 
2227     WLOGFI("SetUpdateSessionIconListener end!");
2228 }
2229 
2230 /**
2231  * @tc.name: NotifyContextTransparent
2232  * @tc.desc: NotifyContextTransparent Test
2233  * @tc.type: FUNC
2234  */
2235 HWTEST_F(WindowSessionTest2, NotifyContextTransparent, Function | SmallTest | Level2)
2236 {
2237     WLOGFI("NotifyContextTransparent begin!");
2238     ASSERT_NE(session_, nullptr);
2239 
2240     NotifyContextTransparentFunc contextTransparentFunc = session_->contextTransparentFunc_;
2241     if (contextTransparentFunc == nullptr) {
__anond2f947a71a02() 2242         contextTransparentFunc = []() {};
2243     }
2244     session_->contextTransparentFunc_ = nullptr;
2245     session_->NotifyContextTransparent();
2246 
2247     session_->SetContextTransparentFunc(contextTransparentFunc);
2248     session_->NotifyContextTransparent();
2249 
2250     WLOGFI("NotifyContextTransparent end!");
2251 }
2252 
2253 /**
2254  * @tc.name: NotifySessionInfoLockedStateChange
2255  * @tc.desc: NotifySessionInfoLockedStateChange Test
2256  * @tc.type: FUNC
2257  */
2258 HWTEST_F(WindowSessionTest2, NotifySessionInfoLockedStateChange, Function | SmallTest | Level2)
2259 {
2260     WLOGFI("NotifySessionInfoLockedStateChange begin!");
2261     ASSERT_NE(session_, nullptr);
2262 
2263     NotifySessionInfoLockedStateChangeFunc sessionInfoLockedStateChangeFunc =
2264         session_->sessionInfoLockedStateChangeFunc_;
2265     if (sessionInfoLockedStateChangeFunc == nullptr) {
__anond2f947a71b02(const bool lockedState) 2266         sessionInfoLockedStateChangeFunc = [](const bool lockedState) {};
2267     }
2268     session_->sessionInfoLockedStateChangeFunc_ = nullptr;
2269     session_->NotifySessionInfoLockedStateChange(true);
2270 
2271     session_->SetSessionInfoLockedStateChangeListener(sessionInfoLockedStateChangeFunc);
2272     session_->NotifySessionInfoLockedStateChange(true);
2273 
2274     WLOGFI("NotifySessionInfoLockedStateChange end!");
2275 }
2276 
2277 /**
2278  * @tc.name: GetMainSession
2279  * @tc.desc: GetMainSession Test
2280  * @tc.type: FUNC
2281  */
2282 HWTEST_F(WindowSessionTest2, GetMainSession, Function | SmallTest | Level2)
2283 {
2284     ASSERT_NE(session_, nullptr);
2285     SessionInfo info;
2286     info.abilityName_ = "getMainSession";
2287     info.moduleName_ = "getMainSession";
2288     info.bundleName_ = "getMainSession";
2289     sptr<Session> session = sptr<Session>::MakeSptr(info);
2290     ASSERT_NE(session, nullptr);
2291     session->property_ = sptr<WindowSessionProperty>::MakeSptr();
2292     ASSERT_NE(session->property_, nullptr);
2293     session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
2294     EXPECT_EQ(session, session->GetMainSession());
2295 
2296     sptr<Session> subSession = sptr<Session>::MakeSptr(info);
2297     ASSERT_NE(subSession, nullptr);
2298     subSession->SetParentSession(session);
2299     subSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
2300     ASSERT_NE(subSession->property_, nullptr);
2301     subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
2302     EXPECT_EQ(session, subSession->GetMainSession());
2303 
2304     sptr<Session> subSubSession = sptr<Session>::MakeSptr(info);
2305     ASSERT_NE(subSubSession, nullptr);
2306     subSubSession->SetParentSession(subSession);
2307     subSubSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
2308     ASSERT_NE(subSubSession->property_, nullptr);
2309     subSubSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
2310     EXPECT_EQ(session, subSubSession->GetMainSession());
2311 }
2312 
2313 /**
2314  * @tc.name: IsSupportDetectWindow
2315  * @tc.desc: IsSupportDetectWindow Test
2316  * @tc.type: FUNC
2317  */
2318 HWTEST_F(WindowSessionTest2, IsSupportDetectWindow, Function | SmallTest | Level2)
2319 {
2320     session_->systemConfig_.uiType_ = "phone";
2321     ssm_->SetScreenLocked(true);
2322     bool ret = session_->IsSupportDetectWindow(true);
2323     ASSERT_EQ(ret, false);
2324 
2325     ssm_->SetScreenLocked(false);
2326     session_->property_ = new WindowSessionProperty();
2327     session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
2328     ret = session_->IsSupportDetectWindow(true);
2329     ASSERT_EQ(ret, false);
2330 
2331     ssm_->SetScreenLocked(false);
2332     session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
2333     session_->systemConfig_.uiType_ = "pc";
2334     ret = session_->IsSupportDetectWindow(false);
2335     ASSERT_EQ(ret, false);
2336 }
2337 
2338 /**
2339  * @tc.name: ShouldCreateDetectTask
2340  * @tc.desc: ShouldCreateDetectTask Test
2341  * @tc.type: FUNC
2342  */
2343 HWTEST_F(WindowSessionTest2, ShouldCreateDetectTask, Function | SmallTest | Level2)
2344 {
2345     DetectTaskInfo detectTaskInfo;
2346     detectTaskInfo.taskState = DetectTaskState::ATTACH_TASK;
2347     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
2348     session_->SetDetectTaskInfo(detectTaskInfo);
2349     bool ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
2350     ASSERT_EQ(ret, true);
2351     detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
2352     session_->SetDetectTaskInfo(detectTaskInfo);
2353     ret = session_->ShouldCreateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
2354     ASSERT_EQ(ret, true);
2355     ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
2356     ASSERT_EQ(ret, false);
2357 }
2358 
2359 /**
2360  * @tc.name: ShouldCreateDetectTaskInRecent
2361  * @tc.desc: ShouldCreateDetectTaskInRecent Test
2362  * @tc.type: FUNC
2363  */
2364 HWTEST_F(WindowSessionTest2, ShouldCreateDetectTaskInRecent, Function | SmallTest | Level2)
2365 {
2366     bool ret = session_->ShouldCreateDetectTaskInRecent(true, true, true);
2367     ASSERT_EQ(ret, false);
2368     ret = session_->ShouldCreateDetectTaskInRecent(false, true, true);
2369     ASSERT_EQ(ret, true);
2370     ret = session_->ShouldCreateDetectTaskInRecent(false, true, false);
2371     ASSERT_EQ(ret, false);
2372     ret = session_->ShouldCreateDetectTaskInRecent(false, false, false);
2373     ASSERT_EQ(ret, false);
2374 }
2375 
2376 /**
2377  * @tc.name: CreateWindowStateDetectTask
2378  * @tc.desc: CreateWindowStateDetectTask Test
2379  * @tc.type: FUNC
2380  */
2381 HWTEST_F(WindowSessionTest2, CreateWindowStateDetectTask, Function | SmallTest | Level2)
2382 {
__anond2f947a71c02() 2383     auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); };
2384     session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
2385     session_->SetSessionState(SessionState::STATE_CONNECT);
2386     bool isAttach = true;
2387     session_->CreateWindowStateDetectTask(isAttach, WindowMode::WINDOW_MODE_UNDEFINED);
2388     ASSERT_EQ(isAttach, true);
2389 
2390     session_->handler_ = nullptr;
2391     session_->CreateWindowStateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
2392     ASSERT_EQ(session_->handler_, nullptr);
2393 }
2394 
2395 /**
2396  * @tc.name: SetOffset01
2397  * @tc.desc: SetOffset Test
2398  * @tc.type: FUNC
2399  */
2400 HWTEST_F(WindowSessionTest2, SetOffset01, Function | SmallTest | Level2)
2401 {
2402     ASSERT_NE(session_, nullptr);
2403     session_->SetOffset(0, 0);
2404     ASSERT_EQ(session_->GetOffsetX(), 0);
2405 }
2406 }
2407 } // namespace Rosen
2408 } // namespace OHOS
2409