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