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_ = new (std::nothrow) Session(info);
93 session_->surfaceNode_ = CreateRSSurfaceNode();
94 EXPECT_NE(nullptr, session_);
95 ssm_ = new SceneSessionManager();
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 = new (std::nothrow) WindowSessionProperty();
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 = new (std::nothrow) SessionStageMocker();
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 = new (std::nothrow) TestWindowEventChannel();
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 = new (std::nothrow) WindowSessionProperty();
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 = new (std::nothrow) SessionStageMocker();
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 = new (std::nothrow) TestWindowEventChannel();
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 = new (std::nothrow) WindowSessionProperty();
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 /**
273 * @tc.name: Background01
274 * @tc.desc: check func Background
275 * @tc.type: FUNC
276 */
277 HWTEST_F(WindowSessionLifecycleTest, Background01, Function | SmallTest | Level2)
278 {
279 session_->state_ = SessionState::STATE_CONNECT;
280 auto result = session_->Background();
281 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
282
283 session_->state_ = SessionState::STATE_INACTIVE;
284 result = session_->Background();
285 ASSERT_EQ(result, WSError::WS_OK);
286 ASSERT_EQ(session_->state_, SessionState::STATE_BACKGROUND);
287 }
288
289 /**
290 * @tc.name: Background2
291 * @tc.desc: Background2 Test
292 * @tc.type: FUNC
293 */
294 HWTEST_F(WindowSessionLifecycleTest, Background2, Function | SmallTest | Level2)
295 {
296 ASSERT_NE(session_, nullptr);
297 session_->SetSessionState(SessionState::STATE_ACTIVE);
298 auto result = session_->Background();
299 EXPECT_EQ(result, WSError::WS_OK);
300 }
301
302 /**
303 * @tc.name: Background03
304 * @tc.desc: Background03 Test
305 * @tc.type: FUNC
306 */
307 HWTEST_F(WindowSessionLifecycleTest, Background03, Function | SmallTest | Level2)
308 {
309 ASSERT_NE(session_, nullptr);
310 session_->SetSessionState(SessionState::STATE_ACTIVE);
311 session_->property_ = sptr<WindowSessionProperty>::MakeSptr();
312 EXPECT_NE(session_->property_, nullptr);
313 session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
314 auto result = session_->Background();
315 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
316 }
317
318 /**
319 * @tc.name: Disconnect01
320 * @tc.desc: check func Disconnect
321 * @tc.type: FUNC
322 */
323 HWTEST_F(WindowSessionLifecycleTest, Disconnect01, Function | SmallTest | Level2)
324 {
325 session_->state_ = SessionState::STATE_CONNECT;
326 auto result = session_->Disconnect();
327 ASSERT_EQ(result, WSError::WS_OK);
328 ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
329
330 session_->state_ = SessionState::STATE_BACKGROUND;
331 result = session_->Disconnect();
332 ASSERT_EQ(result, WSError::WS_OK);
333 ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
334 }
335
336 /**
337 * @tc.name: TerminateSessionNew01
338 * @tc.desc: check func TerminateSessionNew
339 * @tc.type: FUNC
340 */
341 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionNew01, Function | SmallTest | Level2)
342 {
343 NotifyTerminateSessionFuncNew callback =
344 [](const SessionInfo& info, bool needStartCaller, bool isFromBroker)
__anon889954a40402(const SessionInfo& info, bool needStartCaller, bool isFromBroker) 345 {
346 };
347
348 bool needStartCaller = false;
349 bool isFromBroker = false;
350 sptr<AAFwk::SessionInfo> info = new (std::nothrow)AAFwk::SessionInfo();
351 session_->terminateSessionFuncNew_ = nullptr;
352 session_->TerminateSessionNew(info, needStartCaller, isFromBroker);
353
354 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION,
355 session_->TerminateSessionNew(nullptr, needStartCaller, isFromBroker));
356 }
357
358 /**
359 * @tc.name: TerminateSessionNew02
360 * @tc.desc: terminateSessionFuncNew_ is not nullptr
361 * @tc.type: FUNC
362 */
363 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionNew02, Function | SmallTest | Level2)
364 {
365 bool needStartCaller = true;
366 bool isFromBroker = true;
367 sptr<AAFwk::SessionInfo> info = new (std::nothrow)AAFwk::SessionInfo();
__anon889954a40502(const SessionInfo& info, bool needStartCaller, bool isFromBroker) 368 session_->SetTerminateSessionListenerNew([](const SessionInfo& info, bool needStartCaller, bool isFromBroker) {});
369 usleep(WAIT_SYNC_IN_NS);
370 auto result = session_->TerminateSessionNew(info, needStartCaller, isFromBroker);
371 EXPECT_EQ(result, WSError::WS_OK);
372 }
373
374 /**
375 * @tc.name: NotifyDestroy
376 * @tc.desc: check func NotifyDestroy
377 * @tc.type: FUNC
378 */
379 HWTEST_F(WindowSessionLifecycleTest, NotifyDestroy, Function | SmallTest | Level2)
380 {
381 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
382 ASSERT_NE(mockSessionStage, nullptr);
383 session_->sessionStage_ = mockSessionStage;
384 EXPECT_CALL(*(mockSessionStage), NotifyDestroy()).Times(1).WillOnce(Return(WSError::WS_OK));
385 ASSERT_EQ(WSError::WS_OK, session_->NotifyDestroy());
386 session_->sessionStage_ = nullptr;
387 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyDestroy());
388 }
389
390 /**
391 * @tc.name: IsActive01
392 * @tc.desc: IsActive, normal scene
393 * @tc.type: FUNC
394 */
395 HWTEST_F(WindowSessionLifecycleTest, IsActive, Function | SmallTest | Level2)
396 {
397 ASSERT_NE(session_, nullptr);
398 session_->isActive_ = false;
399 if (!session_->IsActive()) {
400 ASSERT_EQ(false, session_->IsActive());
401 }
402 }
403
404 /**
405 * @tc.name: IsActive43
406 * @tc.desc: IsActive
407 * @tc.type: FUNC
408 */
409 HWTEST_F(WindowSessionLifecycleTest, IsActive43, Function | SmallTest | Level2)
410 {
411 ASSERT_NE(session_, nullptr);
412 bool res = session_->IsActive();
413 ASSERT_EQ(res, false);
414 }
415
416 /**
417 * @tc.name: IsSessionForeground01
418 * @tc.desc: IsSessionForeground, normal scene
419 * @tc.type: FUNC
420 */
421 HWTEST_F(WindowSessionLifecycleTest, IsSessionForeground, Function | SmallTest | Level2)
422 {
423 ASSERT_NE(session_, nullptr);
424 session_->state_ = SessionState::STATE_FOREGROUND;
425 ASSERT_EQ(true, session_->IsSessionForeground());
426 session_->state_ = SessionState::STATE_ACTIVE;
427 ASSERT_EQ(true, session_->IsSessionForeground());
428 session_->state_ = SessionState::STATE_INACTIVE;
429 ASSERT_EQ(false, session_->IsSessionForeground());
430 session_->state_ = SessionState::STATE_BACKGROUND;
431 ASSERT_EQ(false, session_->IsSessionForeground());
432 session_->state_ = SessionState::STATE_DISCONNECT;
433 ASSERT_EQ(false, session_->IsSessionForeground());
434 session_->state_ = SessionState::STATE_CONNECT;
435 ASSERT_EQ(false, session_->IsSessionForeground());
436 }
437
438 /**
439 * @tc.name: NotifyActivation
440 * @tc.desc: NotifyActivation Test
441 * @tc.type: FUNC
442 */
443 HWTEST_F(WindowSessionLifecycleTest, NotifyActivation, Function | SmallTest | Level2)
444 {
445 ASSERT_NE(session_, nullptr);
446 session_->state_ = SessionState::STATE_DISCONNECT;
447 session_->NotifyActivation();
448
449 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
450 }
451
452 /**
453 * @tc.name: NotifyActivation022
454 * @tc.desc: NotifyActivation
455 * @tc.type: FUNC
456 */
457 HWTEST_F(WindowSessionLifecycleTest, NotifyActivation022, Function | SmallTest | Level2)
458 {
459 ASSERT_NE(session_, nullptr);
460 session_->NotifyActivation();
461
462 session_->RegisterLifecycleListener(lifecycleListener_);
463 session_->NotifyActivation();
464 uint64_t screenId = 0;
465 session_->SetScreenId(screenId);
466 session_->UnregisterLifecycleListener(lifecycleListener_);
467 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
468 }
469
470 /**
471 * @tc.name: NotifyForeground
472 * @tc.desc: NotifyForeground Test
473 * @tc.type: FUNC
474 */
475 HWTEST_F(WindowSessionLifecycleTest, NotifyForeground, Function | SmallTest | Level2)
476 {
477 ASSERT_NE(session_, nullptr);
478 session_->state_ = SessionState::STATE_DISCONNECT;
479 session_->NotifyForeground();
480
481 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
482 }
483
484 /**
485 * @tc.name: NotifyForeground024
486 * @tc.desc: NotifyForeground
487 * @tc.type: FUNC
488 */
489 HWTEST_F(WindowSessionLifecycleTest, NotifyForeground024, Function | SmallTest | Level2)
490 {
491 ASSERT_NE(session_, nullptr);
492 session_->NotifyForeground();
493
494 session_->RegisterLifecycleListener(lifecycleListener_);
495 session_->NotifyForeground();
496 uint64_t screenId = 0;
497 session_->SetScreenId(screenId);
498 session_->UnregisterLifecycleListener(lifecycleListener_);
499 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
500 }
501
502 /**
503 * @tc.name: NotifyBackground
504 * @tc.desc: NotifyBackground Test
505 * @tc.type: FUNC
506 */
507 HWTEST_F(WindowSessionLifecycleTest, NotifyBackground, Function | SmallTest | Level2)
508 {
509 ASSERT_NE(session_, nullptr);
510 session_->state_ = SessionState::STATE_DISCONNECT;
511 session_->NotifyBackground();
512
513 ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
514 }
515
516 /**
517 * @tc.name: NotifyBackground025
518 * @tc.desc: NotifyBackground
519 * @tc.type: FUNC
520 */
521 HWTEST_F(WindowSessionLifecycleTest, NotifyBackground025, Function | SmallTest | Level2)
522 {
523 ASSERT_NE(session_, nullptr);
524 session_->NotifyBackground();
525
526 session_->RegisterLifecycleListener(lifecycleListener_);
527 session_->NotifyBackground();
528 uint64_t screenId = 0;
529 session_->SetScreenId(screenId);
530 session_->UnregisterLifecycleListener(lifecycleListener_);
531 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
532 }
533
534 /**
535 * @tc.name: TerminateSessionTotal01
536 * @tc.desc: abilitySessionInfo is nullptr
537 * @tc.type: FUNC
538 */
539 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionTotal01, Function | SmallTest | Level2)
540 {
541 ASSERT_NE(session_, nullptr);
542 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION,
543 session_->TerminateSessionTotal(nullptr, TerminateType::CLOSE_AND_KEEP_MULTITASK));
544 }
545
546 /**
547 * @tc.name: TerminateSessionTotal02
548 * @tc.desc: abilitySessionInfo is not nullptr, isTerminating is true
549 * @tc.type: FUNC
550 */
551 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionTotal02, Function | SmallTest | Level2)
552 {
553 ASSERT_NE(session_, nullptr);
554 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
555 session_->isTerminating_ = true;
556 ASSERT_EQ(WSError::WS_ERROR_INVALID_OPERATION,
557 session_->TerminateSessionTotal(abilitySessionInfo, TerminateType::CLOSE_AND_KEEP_MULTITASK));
558 }
559
560 /**
561 * @tc.name: TerminateSessionTotal03
562 * @tc.desc: abilitySessionInfo is not nullptr, isTerminating is false
563 * @tc.type: FUNC
564 */
565 HWTEST_F(WindowSessionLifecycleTest, TerminateSessionTotal03, Function | SmallTest | Level2)
566 {
567 ASSERT_NE(session_, nullptr);
568 sptr<AAFwk::SessionInfo> abilitySessionInfo = new AAFwk::SessionInfo();
569 session_->isTerminating_ = false;
570 session_->SetTerminateSessionListenerTotal(nullptr);
571 ASSERT_EQ(WSError::WS_OK,
572 session_->TerminateSessionTotal(abilitySessionInfo, TerminateType::CLOSE_AND_KEEP_MULTITASK));
573 }
574
575 /**
576 * @tc.name: PendingSessionToBackgroundForDelegator
577 * @tc.desc: PendingSessionToBackgroundForDelegator Test
578 * @tc.type: FUNC
579 */
580 HWTEST_F(WindowSessionLifecycleTest, PendingSessionToBackgroundForDelegator, Function | SmallTest | Level2)
581 {
582 ASSERT_NE(session_, nullptr);
583 session_->SetPendingSessionToBackgroundForDelegatorListener(nullptr);
584 ASSERT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
585 }
586
587 /**
588 * @tc.name: NotifyConnect023
589 * @tc.desc: NotifyConnect
590 * @tc.type: FUNC
591 */
592 HWTEST_F(WindowSessionLifecycleTest, NotifyConnect023, Function | SmallTest | Level2)
593 {
594 ASSERT_NE(session_, nullptr);
595 session_->NotifyConnect();
596
597 session_->RegisterLifecycleListener(lifecycleListener_);
598 session_->NotifyConnect();
599 uint64_t screenId = 0;
600 session_->SetScreenId(screenId);
601 session_->UnregisterLifecycleListener(lifecycleListener_);
602 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
603 }
604
605 /**
606 * @tc.name: NotifyDisconnect026
607 * @tc.desc: NotifyDisconnect
608 * @tc.type: FUNC
609 */
610 HWTEST_F(WindowSessionLifecycleTest, NotifyDisconnect026, Function | SmallTest | Level2)
611 {
612 ASSERT_NE(session_, nullptr);
613 session_->NotifyDisconnect();
614
615 session_->RegisterLifecycleListener(lifecycleListener_);
616 session_->NotifyDisconnect();
617 uint64_t screenId = 0;
618 session_->SetScreenId(screenId);
619 session_->UnregisterLifecycleListener(lifecycleListener_);
620 ASSERT_EQ(0, session_->sessionInfo_.screenId_);
621 }
622
623 /**
624 * @tc.name: UpdateSessionState32
625 * @tc.desc: UpdateSessionState
626 * @tc.type: FUNC
627 */
628 HWTEST_F(WindowSessionLifecycleTest, UpdateSessionState32, Function | SmallTest | Level2)
629 {
630 ASSERT_NE(session_, nullptr);
631 SessionState state = SessionState::STATE_CONNECT;
632 session_->UpdateSessionState(state);
633 ASSERT_EQ(session_->state_, SessionState::STATE_CONNECT);
634 }
635
636 /**
637 * @tc.name: IsSystemSession44
638 * @tc.desc: IsSystemSession
639 * @tc.type: FUNC
640 */
641 HWTEST_F(WindowSessionLifecycleTest, IsSystemSession44, Function | SmallTest | Level2)
642 {
643 ASSERT_NE(session_, nullptr);
644 bool res = session_->IsSystemSession();
645 ASSERT_EQ(res, false);
646 }
647
648 /**
649 * @tc.name: Hide45
650 * @tc.desc: Hide
651 * @tc.type: FUNC
652 */
653 HWTEST_F(WindowSessionLifecycleTest, Hide45, Function | SmallTest | Level2)
654 {
655 ASSERT_NE(session_, nullptr);
656 auto result = session_->Hide();
657 ASSERT_EQ(result, WSError::WS_OK);
658 }
659
660 /**
661 * @tc.name: Show46
662 * @tc.desc: Show
663 * @tc.type: FUNC
664 */
665 HWTEST_F(WindowSessionLifecycleTest, Show46, Function | SmallTest | Level2)
666 {
667 ASSERT_NE(session_, nullptr);
668 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
669 ASSERT_NE(nullptr, property);
670 auto result = session_->Show(property);
671 ASSERT_EQ(result, WSError::WS_OK);
672 }
673
674 /**
675 * @tc.name: IsSystemActive47
676 * @tc.desc: IsSystemActive
677 * @tc.type: FUNC
678 */
679 HWTEST_F(WindowSessionLifecycleTest, IsSystemActive47, Function | SmallTest | Level2)
680 {
681 ASSERT_NE(session_, nullptr);
682 bool res = session_->IsSystemActive();
683 ASSERT_EQ(res, false);
684 }
685
686 /**
687 * @tc.name: IsTerminated49
688 * @tc.desc: IsTerminated
689 * @tc.type: FUNC
690 */
691 HWTEST_F(WindowSessionLifecycleTest, IsTerminated49, Function | SmallTest | Level2)
692 {
693 ASSERT_NE(session_, nullptr);
694 session_->state_ = SessionState::STATE_DISCONNECT;
695 bool res = session_->IsTerminated();
696 ASSERT_EQ(true, res);
697 session_->state_ = SessionState::STATE_FOREGROUND;
698 res = session_->IsTerminated();
699 ASSERT_EQ(false, res);
700 session_->state_ = SessionState::STATE_ACTIVE;
701 res = session_->IsTerminated();
702 ASSERT_EQ(false, res);
703 session_->state_ = SessionState::STATE_INACTIVE;
704 res = session_->IsTerminated();
705 ASSERT_EQ(false, res);
706 session_->state_ = SessionState::STATE_BACKGROUND;
707 res = session_->IsTerminated();
708 ASSERT_EQ(false, res);
709 session_->state_ = SessionState::STATE_CONNECT;
710 res = session_->IsTerminated();
711 ASSERT_EQ(false, res);
712 }
713 }
714 }
715 }
716