• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "key_event.h"
31 #include "wm_common.h"
32 #include "window_event_channel_base.h"
33 #include "window_manager_hilog.h"
34 
35 using namespace testing;
36 using namespace testing::ext;
37 
38 namespace OHOS {
39 namespace Rosen {
40 namespace {
41     const std::string UNDEFINED = "undefined";
42 }
43 
44 class WindowSessionLifecycleTest : public testing::Test {
45 public:
46     static void SetUpTestCase();
47     static void TearDownTestCase();
48     void SetUp() override;
49     void TearDown() override;
50     int32_t GetTaskCount();
51     sptr <SceneSessionManager> ssm_;
52 
53 private:
54     RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
55 
56     sptr <Session> session_ = nullptr;
57     static constexpr uint32_t
58     WAIT_SYNC_IN_NS = 500000;
59 
60     class TLifecycleListener : public ILifecycleListener {
61     public:
~TLifecycleListener()62         virtual ~TLifecycleListener() {}
OnActivation()63         void OnActivation() override {}
OnConnect()64         void OnConnect() override {}
OnForeground()65         void OnForeground() override {}
OnBackground()66         void OnBackground() override {}
OnDisconnect()67         void OnDisconnect() override {}
OnExtensionDied()68         void OnExtensionDied() override {}
OnExtensionTimeout(int32_t errorCode)69         void OnExtensionTimeout(int32_t errorCode) override {}
OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)70         void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
71             int64_t uiExtensionIdLevel) override {}
OnDrawingCompleted()72         void OnDrawingCompleted() override {}
OnAppRemoveStartingWindow()73         void OnAppRemoveStartingWindow() override {}
74     };
75     std::shared_ptr<TLifecycleListener> lifecycleListener_ = std::make_shared<TLifecycleListener>();
76 };
77 
SetUpTestCase()78 void WindowSessionLifecycleTest::SetUpTestCase()
79 {
80 }
81 
TearDownTestCase()82 void WindowSessionLifecycleTest::TearDownTestCase()
83 {
84 }
85 
SetUp()86 void WindowSessionLifecycleTest::SetUp()
87 {
88     SessionInfo info;
89     info.abilityName_ = "testSession1";
90     info.moduleName_ = "testSession2";
91     info.bundleName_ = "testSession3";
92     session_ = sptr<Session>::MakeSptr(info);
93     session_->surfaceNode_ = CreateRSSurfaceNode();
94     EXPECT_NE(nullptr, session_);
95     ssm_ = sptr<SceneSessionManager>::MakeSptr();
96     session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
97     auto isScreenLockedCallback = [this]() {
98         return ssm_->IsScreenLocked();
99     };
100     session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
101 }
102 
TearDown()103 void WindowSessionLifecycleTest::TearDown()
104 {
105     session_ = nullptr;
106     usleep(WAIT_SYNC_IN_NS);
107 }
108 
CreateRSSurfaceNode()109 RSSurfaceNode::SharedPtr WindowSessionLifecycleTest::CreateRSSurfaceNode()
110 {
111     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
112     rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
113     auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
114     if (surfaceNode == nullptr) {
115         GTEST_LOG_(INFO) << "WindowSessionTest::CreateRSSurfaceNode surfaceNode is nullptr";
116     }
117     return surfaceNode;
118 }
119 
GetTaskCount()120 int32_t WindowSessionLifecycleTest::GetTaskCount()
121 {
122     std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
123     std::regex pattern("\\d+");
124     std::smatch matches;
125     int32_t taskNum = 0;
126     while (std::regex_search(dumpInfo, matches, pattern)) {
127         taskNum += std::stoi(matches.str());
128         dumpInfo = matches.suffix();
129     }
130     return taskNum;
131 }
132 
133 namespace {
134 
135 /**
136  * @tc.name: Connect01
137  * @tc.desc: check func Connect
138  * @tc.type: FUNC
139  */
140 HWTEST_F(WindowSessionLifecycleTest, Connect01, Function | SmallTest | Level2)
141 {
142     auto surfaceNode = CreateRSSurfaceNode();
143     session_->state_ = SessionState::STATE_CONNECT;
144     SystemSessionConfig systemConfig;
145     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
146     ASSERT_NE(nullptr, property);
147     auto result = session_->Connect(nullptr, nullptr, nullptr, systemConfig, property);
148     ASSERT_EQ(result, WSError::WS_OK);
149 
150     session_->state_ = SessionState::STATE_DISCONNECT;
151     result = session_->Connect(nullptr, nullptr, nullptr, systemConfig, property);
152     ASSERT_EQ(result, WSError::WS_OK);
153 
154     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
155     EXPECT_NE(nullptr, mockSessionStage);
156     result = session_->Connect(mockSessionStage, nullptr, surfaceNode, systemConfig, property);
157     ASSERT_EQ(result, WSError::WS_OK);
158 
159     sptr<TestWindowEventChannel> testWindowEventChannel = sptr<TestWindowEventChannel>::MakeSptr();
160     EXPECT_NE(nullptr, testWindowEventChannel);
161     result = session_->Connect(mockSessionStage, testWindowEventChannel, surfaceNode, systemConfig, property);
162     ASSERT_EQ(result, WSError::WS_OK);
163 }
164 
165 /**
166  * @tc.name: Reconnect01
167  * @tc.desc: check func Reconnect01
168  * @tc.type: FUNC
169  */
170 HWTEST_F(WindowSessionLifecycleTest, Reconnect01, Function | SmallTest | Level2)
171 {
172     auto surfaceNode = CreateRSSurfaceNode();
173 
174     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
175     ASSERT_NE(nullptr, property);
176     auto result = session_->Reconnect(nullptr, nullptr, nullptr, property);
177     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
178 
179     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
180     EXPECT_NE(nullptr, mockSessionStage);
181     result = session_->Reconnect(mockSessionStage, nullptr, surfaceNode, property);
182     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
183 
184     sptr<TestWindowEventChannel> testWindowEventChannel = sptr<TestWindowEventChannel>::MakeSptr();
185     EXPECT_NE(nullptr, testWindowEventChannel);
186     result = session_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, nullptr);
187     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
188 
189     result = session_->Reconnect(nullptr, testWindowEventChannel, surfaceNode, property);
190     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
191 
192     result = session_->Reconnect(mockSessionStage, testWindowEventChannel, surfaceNode, property);
193     ASSERT_EQ(result, WSError::WS_OK);
194 }
195 
196 /**
197  * @tc.name: Foreground01
198  * @tc.desc: check func Foreground
199  * @tc.type: FUNC
200  */
201 HWTEST_F(WindowSessionLifecycleTest, Foreground01, Function | SmallTest | Level2)
202 {
203     session_->state_ = SessionState::STATE_DISCONNECT;
204     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
205     ASSERT_NE(nullptr, property);
206     auto result = session_->Foreground(property);
207     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
208 
209     session_->state_ = SessionState::STATE_CONNECT;
210     session_->isActive_ = true;
211     result = session_->Foreground(property);
212     ASSERT_EQ(result, WSError::WS_OK);
213 
214     session_->isActive_ = false;
215     ASSERT_EQ(result, WSError::WS_OK);
216 }
217 
218 /**
219  * @tc.name: Foreground02
220  * @tc.desc: Foreground Test
221  * @tc.type: FUNC
222  */
223 HWTEST_F(WindowSessionLifecycleTest, Foreground02, Function | SmallTest | Level2)
224 {
225     ASSERT_NE(session_, nullptr);
226     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
227     ASSERT_NE(nullptr, property);
228     session_->SetSessionState(SessionState::STATE_BACKGROUND);
229     session_->isActive_ = true;
230     auto result = session_->Foreground(property);
231     ASSERT_EQ(result, WSError::WS_OK);
232 
233     session_->SetSessionState(SessionState::STATE_INACTIVE);
234     session_->isActive_ = false;
235     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
236     ASSERT_NE(mockSessionStage, nullptr);
237     session_->sessionStage_ = mockSessionStage;
238     result = session_->Foreground(property);
239     ASSERT_EQ(result, WSError::WS_OK);
240 }
241 
242 /**
243  * @tc.name: Foreground03
244  * @tc.desc: Foreground Test
245  * @tc.type: FUNC
246  */
247 HWTEST_F(WindowSessionLifecycleTest, Foreground03, Function | SmallTest | Level2)
248 {
249     ASSERT_NE(session_, nullptr);
250     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
251     ASSERT_NE(nullptr, property);
252     session_->SetSessionState(SessionState::STATE_BACKGROUND);
253     session_->isActive_ = true;
254 
255     property->type_ = WindowType::WINDOW_TYPE_DIALOG;
256     auto result = session_->Foreground(property);
257     ASSERT_EQ(result, WSError::WS_OK);
258 
259     SessionInfo parentInfo;
260     parentInfo.abilityName_ = "testSession1";
261     parentInfo.moduleName_ = "testSession2";
262     parentInfo.bundleName_ = "testSession3";
263     sptr<Session> parentSession = sptr<Session>::MakeSptr(parentInfo);
264     ASSERT_NE(parentSession, nullptr);
265     session_->SetParentSession(parentSession);
266     session_->SetSessionState(SessionState::STATE_INACTIVE);
267     result = session_->Foreground(property);
268     ASSERT_EQ(result, WSError::WS_OK);
269 }
270 
271 /**
272  * @tc.name: Background01
273  * @tc.desc: check func Background
274  * @tc.type: FUNC
275  */
276 HWTEST_F(WindowSessionLifecycleTest, Background01, Function | SmallTest | Level2)
277 {
278     session_->state_ = SessionState::STATE_CONNECT;
279     auto result = session_->Background();
280     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
281 
282     session_->state_ = SessionState::STATE_INACTIVE;
283     result = session_->Background();
284     ASSERT_EQ(result, WSError::WS_OK);
285     ASSERT_EQ(session_->state_, SessionState::STATE_BACKGROUND);
286 }
287 
288 /**
289  * @tc.name: Background2
290  * @tc.desc: Background2 Test
291  * @tc.type: FUNC
292  */
293 HWTEST_F(WindowSessionLifecycleTest, Background2, Function | SmallTest | Level2)
294 {
295     ASSERT_NE(session_, nullptr);
296     session_->SetSessionState(SessionState::STATE_ACTIVE);
297     auto result = session_->Background();
298     EXPECT_EQ(result, WSError::WS_OK);
299 }
300 
301 /**
302  * @tc.name: Background03
303  * @tc.desc: Background03 Test
304  * @tc.type: FUNC
305  */
306 HWTEST_F(WindowSessionLifecycleTest, Background03, Function | SmallTest | Level2)
307 {
308     ASSERT_NE(session_, nullptr);
309     session_->SetSessionState(SessionState::STATE_ACTIVE);
310     session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
311     EXPECT_NE(session_->property_, nullptr);
312     session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
313     auto result = session_->Background();
314     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
315 }
316 
317 /**
318  * @tc.name: Disconnect01
319  * @tc.desc: check func Disconnect
320  * @tc.type: FUNC
321  */
322 HWTEST_F(WindowSessionLifecycleTest, Disconnect01, Function | SmallTest | Level2)
323 {
324     session_->state_ = SessionState::STATE_CONNECT;
325     auto result = session_->Disconnect();
326     ASSERT_EQ(result, WSError::WS_OK);
327     ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
328 
329     session_->state_ = SessionState::STATE_BACKGROUND;
330     result = session_->Disconnect();
331     ASSERT_EQ(result, WSError::WS_OK);
332     ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
333 }
334 
335 /**
336  * @tc.name: TerminateSessionNew01
337  * @tc.desc: check func TerminateSessionNew
338  * @tc.type: FUNC
339  */
340 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionNew01, Function | SmallTest | Level2)
341 {
342     NotifyTerminateSessionFuncNew callback =
343             [](const SessionInfo& info, bool needStartCaller, bool isFromBroker)
__anon36cad6ac0402(const SessionInfo& info, bool needStartCaller, bool isFromBroker) 344             {
345             };
346 
347     bool needStartCaller = false;
348     bool isFromBroker = false;
349     sptr<AAFwk::SessionInfo> info = sptr<AAFwk::SessionInfo>::MakeSptr();
350     session_->terminateSessionFuncNew_ = nullptr;
351     session_->TerminateSessionNew(info, needStartCaller, isFromBroker);
352 
353     ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION,
354             session_->TerminateSessionNew(nullptr, needStartCaller, isFromBroker));
355 }
356 
357 /**
358  * @tc.name: TerminateSessionNew02
359  * @tc.desc: terminateSessionFuncNew_ is not nullptr
360  * @tc.type: FUNC
361  */
362 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionNew02, Function | SmallTest | Level2)
363 {
364     bool needStartCaller = true;
365     bool isFromBroker = true;
366     sptr<AAFwk::SessionInfo> info = sptr<AAFwk::SessionInfo>::MakeSptr();
__anon36cad6ac0502(const SessionInfo& info, bool needStartCaller, bool isFromBroker) 367     session_->SetTerminateSessionListenerNew([](const SessionInfo& info, bool needStartCaller, bool isFromBroker) {});
368     usleep(WAIT_SYNC_IN_NS);
369     auto result = session_->TerminateSessionNew(info, needStartCaller, isFromBroker);
370     EXPECT_EQ(result, WSError::WS_OK);
371 }
372 
373 /**
374  * @tc.name: NotifyDestroy
375  * @tc.desc: check func NotifyDestroy
376  * @tc.type: FUNC
377  */
378 HWTEST_F(WindowSessionLifecycleTest, NotifyDestroy, Function | SmallTest | Level2)
379 {
380     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
381     ASSERT_NE(mockSessionStage, nullptr);
382     session_->sessionStage_ = mockSessionStage;
383     EXPECT_CALL(*(mockSessionStage), NotifyDestroy()).Times(1).WillOnce(Return(WSError::WS_OK));
384     ASSERT_EQ(WSError::WS_OK, session_->NotifyDestroy());
385     session_->sessionStage_ = nullptr;
386     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyDestroy());
387 }
388 
389 /**
390  * @tc.name: IsActive01
391  * @tc.desc: IsActive, normal scene
392  * @tc.type: FUNC
393  */
394 HWTEST_F(WindowSessionLifecycleTest, IsActive, Function | SmallTest | Level2)
395 {
396     ASSERT_NE(session_, nullptr);
397     session_->isActive_ = false;
398     if (!session_->IsActive()) {
399         ASSERT_EQ(false, session_->IsActive());
400     }
401 }
402 
403 /**
404  * @tc.name: IsActive43
405  * @tc.desc: IsActive
406  * @tc.type: FUNC
407  */
408 HWTEST_F(WindowSessionLifecycleTest, IsActive43, Function | SmallTest | Level2)
409 {
410     ASSERT_NE(session_, nullptr);
411     bool res = session_->IsActive();
412     ASSERT_EQ(res, false);
413 }
414 
415 /**
416  * @tc.name: IsSessionForeground01
417  * @tc.desc: IsSessionForeground, normal scene
418  * @tc.type: FUNC
419  */
420 HWTEST_F(WindowSessionLifecycleTest, IsSessionForeground, Function | SmallTest | Level2)
421 {
422     ASSERT_NE(session_, nullptr);
423     session_->state_ = SessionState::STATE_FOREGROUND;
424     ASSERT_EQ(true, session_->IsSessionForeground());
425     session_->state_ = SessionState::STATE_ACTIVE;
426     ASSERT_EQ(true, session_->IsSessionForeground());
427     session_->state_ = SessionState::STATE_INACTIVE;
428     ASSERT_EQ(false, session_->IsSessionForeground());
429     session_->state_ = SessionState::STATE_BACKGROUND;
430     ASSERT_EQ(false, session_->IsSessionForeground());
431     session_->state_ = SessionState::STATE_DISCONNECT;
432     ASSERT_EQ(false, session_->IsSessionForeground());
433     session_->state_ = SessionState::STATE_CONNECT;
434     ASSERT_EQ(false, session_->IsSessionForeground());
435 }
436 
437 /**
438  * @tc.name: NotifyActivation
439  * @tc.desc: NotifyActivation Test
440  * @tc.type: FUNC
441  */
442 HWTEST_F(WindowSessionLifecycleTest, NotifyActivation, Function | SmallTest | Level2)
443 {
444     ASSERT_NE(session_, nullptr);
445     session_->state_ = SessionState::STATE_DISCONNECT;
446     session_->NotifyActivation();
447 
448     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
449 }
450 
451 /**
452  * @tc.name: NotifyActivation022
453  * @tc.desc: NotifyActivation
454  * @tc.type: FUNC
455  */
456 HWTEST_F(WindowSessionLifecycleTest, NotifyActivation022, Function | SmallTest | Level2)
457 {
458     ASSERT_NE(session_, nullptr);
459     session_->NotifyActivation();
460 
461     session_->RegisterLifecycleListener(lifecycleListener_);
462     session_->NotifyActivation();
463     uint64_t screenId = 0;
464     session_->SetScreenId(screenId);
465     session_->UnregisterLifecycleListener(lifecycleListener_);
466     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
467 }
468 
469 /**
470  * @tc.name: NotifyForeground
471  * @tc.desc: NotifyForeground Test
472  * @tc.type: FUNC
473  */
474 HWTEST_F(WindowSessionLifecycleTest, NotifyForeground, Function | SmallTest | Level2)
475 {
476     ASSERT_NE(session_, nullptr);
477     session_->state_ = SessionState::STATE_DISCONNECT;
478     session_->NotifyForeground();
479 
480     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
481 }
482 
483 /**
484  * @tc.name: NotifyForeground024
485  * @tc.desc: NotifyForeground
486  * @tc.type: FUNC
487  */
488 HWTEST_F(WindowSessionLifecycleTest, NotifyForeground024, Function | SmallTest | Level2)
489 {
490     ASSERT_NE(session_, nullptr);
491     session_->NotifyForeground();
492 
493     session_->RegisterLifecycleListener(lifecycleListener_);
494     session_->NotifyForeground();
495     uint64_t screenId = 0;
496     session_->SetScreenId(screenId);
497     session_->UnregisterLifecycleListener(lifecycleListener_);
498     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
499 }
500 
501 /**
502  * @tc.name: NotifyBackground
503  * @tc.desc: NotifyBackground Test
504  * @tc.type: FUNC
505  */
506 HWTEST_F(WindowSessionLifecycleTest, NotifyBackground, Function | SmallTest | Level2)
507 {
508     ASSERT_NE(session_, nullptr);
509     session_->state_ = SessionState::STATE_DISCONNECT;
510     session_->NotifyBackground();
511 
512     ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
513 }
514 
515 /**
516  * @tc.name: NotifyBackground025
517  * @tc.desc: NotifyBackground
518  * @tc.type: FUNC
519  */
520 HWTEST_F(WindowSessionLifecycleTest, NotifyBackground025, Function | SmallTest | Level2)
521 {
522     ASSERT_NE(session_, nullptr);
523     session_->NotifyBackground();
524 
525     session_->RegisterLifecycleListener(lifecycleListener_);
526     session_->NotifyBackground();
527     uint64_t screenId = 0;
528     session_->SetScreenId(screenId);
529     session_->UnregisterLifecycleListener(lifecycleListener_);
530     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
531 }
532 
533 /**
534  * @tc.name: TerminateSessionTotal01
535  * @tc.desc: abilitySessionInfo is nullptr
536  * @tc.type: FUNC
537  */
538 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionTotal01, Function | SmallTest | Level2)
539 {
540     ASSERT_NE(session_, nullptr);
541     ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION,
542             session_->TerminateSessionTotal(nullptr, TerminateType::CLOSE_AND_KEEP_MULTITASK));
543 }
544 
545 /**
546  * @tc.name: TerminateSessionTotal02
547  * @tc.desc: abilitySessionInfo is not nullptr, isTerminating is true
548  * @tc.type: FUNC
549  */
550 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionTotal02, Function | SmallTest | Level2)
551 {
552     ASSERT_NE(session_, nullptr);
553     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
554     session_->isTerminating_ = true;
555     ASSERT_EQ(WSError::WS_ERROR_INVALID_OPERATION,
556             session_->TerminateSessionTotal(abilitySessionInfo, TerminateType::CLOSE_AND_KEEP_MULTITASK));
557 }
558 
559 /**
560  * @tc.name: TerminateSessionTotal03
561  * @tc.desc: abilitySessionInfo is not nullptr, isTerminating is false
562  * @tc.type: FUNC
563  */
564 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionTotal03, Function | SmallTest | Level2)
565 {
566     ASSERT_NE(session_, nullptr);
567     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
568     session_->isTerminating_ = false;
569     session_->SetTerminateSessionListenerTotal(nullptr);
570     ASSERT_EQ(WSError::WS_OK,
571             session_->TerminateSessionTotal(abilitySessionInfo, TerminateType::CLOSE_AND_KEEP_MULTITASK));
572 }
573 
574 /**
575  * @tc.name: PendingSessionToBackgroundForDelegator
576  * @tc.desc: PendingSessionToBackgroundForDelegator Test
577  * @tc.type: FUNC
578  */
579 HWTEST_F(WindowSessionLifecycleTest, PendingSessionToBackgroundForDelegator, Function | SmallTest | Level2)
580 {
581     ASSERT_NE(session_, nullptr);
582     session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
583     ASSERT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
584 }
585 
586 /**
587  * @tc.name: NotifyConnect023
588  * @tc.desc: NotifyConnect
589  * @tc.type: FUNC
590  */
591 HWTEST_F(WindowSessionLifecycleTest, NotifyConnect023, Function | SmallTest | Level2)
592 {
593     ASSERT_NE(session_, nullptr);
594     session_->NotifyConnect();
595 
596     session_->RegisterLifecycleListener(lifecycleListener_);
597     session_->NotifyConnect();
598     uint64_t screenId = 0;
599     session_->SetScreenId(screenId);
600     session_->UnregisterLifecycleListener(lifecycleListener_);
601     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
602 }
603 
604 /**
605  * @tc.name: NotifyDisconnect026
606  * @tc.desc: NotifyDisconnect
607  * @tc.type: FUNC
608  */
609 HWTEST_F(WindowSessionLifecycleTest, NotifyDisconnect026, Function | SmallTest | Level2)
610 {
611     ASSERT_NE(session_, nullptr);
612     session_->NotifyDisconnect();
613 
614     session_->RegisterLifecycleListener(lifecycleListener_);
615     session_->NotifyDisconnect();
616     uint64_t screenId = 0;
617     session_->SetScreenId(screenId);
618     session_->UnregisterLifecycleListener(lifecycleListener_);
619     ASSERT_EQ(0, session_->sessionInfo_.screenId_);
620 }
621 
622 /**
623  * @tc.name: UpdateSessionState32
624  * @tc.desc: UpdateSessionState
625  * @tc.type: FUNC
626  */
627 HWTEST_F(WindowSessionLifecycleTest, UpdateSessionState32, Function | SmallTest | Level2)
628 {
629     ASSERT_NE(session_, nullptr);
630     SessionState state = SessionState::STATE_CONNECT;
631     session_->UpdateSessionState(state);
632     ASSERT_EQ(session_->state_, SessionState::STATE_CONNECT);
633 }
634 
635 /**
636  * @tc.name: IsSystemSession44
637  * @tc.desc: IsSystemSession
638  * @tc.type: FUNC
639  */
640 HWTEST_F(WindowSessionLifecycleTest, IsSystemSession44, Function | SmallTest | Level2)
641 {
642     ASSERT_NE(session_, nullptr);
643     bool res = session_->IsSystemSession();
644     ASSERT_EQ(res, false);
645 }
646 
647 /**
648  * @tc.name: Hide45
649  * @tc.desc: Hide
650  * @tc.type: FUNC
651  */
652 HWTEST_F(WindowSessionLifecycleTest, Hide45, Function | SmallTest | Level2)
653 {
654     ASSERT_NE(session_, nullptr);
655     auto result = session_->Hide();
656     ASSERT_EQ(result, WSError::WS_OK);
657 }
658 
659 /**
660  * @tc.name: Show46
661  * @tc.desc: Show
662  * @tc.type: FUNC
663  */
664 HWTEST_F(WindowSessionLifecycleTest, Show46, Function | SmallTest | Level2)
665 {
666     ASSERT_NE(session_, nullptr);
667     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
668     ASSERT_NE(nullptr, property);
669     auto result = session_->Show(property);
670     ASSERT_EQ(result, WSError::WS_OK);
671 }
672 
673 /**
674  * @tc.name: IsSystemActive47
675  * @tc.desc: IsSystemActive
676  * @tc.type: FUNC
677  */
678 HWTEST_F(WindowSessionLifecycleTest, IsSystemActive47, Function | SmallTest | Level2)
679 {
680     ASSERT_NE(session_, nullptr);
681     bool res = session_->IsSystemActive();
682     ASSERT_EQ(res, false);
683 }
684 
685 /**
686  * @tc.name: IsTerminated49
687  * @tc.desc: IsTerminated
688  * @tc.type: FUNC
689  */
690 HWTEST_F(WindowSessionLifecycleTest, IsTerminated49, Function | SmallTest | Level2)
691 {
692     ASSERT_NE(session_, nullptr);
693     session_->state_ = SessionState::STATE_DISCONNECT;
694     bool res = session_->IsTerminated();
695     ASSERT_EQ(true, res);
696     session_->state_ = SessionState::STATE_FOREGROUND;
697     res = session_->IsTerminated();
698     ASSERT_EQ(false, res);
699     session_->state_ = SessionState::STATE_ACTIVE;
700     res = session_->IsTerminated();
701     ASSERT_EQ(false, res);
702     session_->state_ = SessionState::STATE_INACTIVE;
703     res = session_->IsTerminated();
704     ASSERT_EQ(false, res);
705     session_->state_ = SessionState::STATE_BACKGROUND;
706     res = session_->IsTerminated();
707     ASSERT_EQ(false, res);
708     session_->state_ = SessionState::STATE_CONNECT;
709     res = session_->IsTerminated();
710     ASSERT_EQ(false, res);
711 }
712 }
713 }
714 }
715