• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "common/include/session_permission.h"
19 #include "interfaces/include/ws_common.h"
20 #include "iremote_object_mocker.h"
21 #include "session_manager/include/scene_session_manager.h"
22 #include "session_info.h"
23 #include "session/host/include/scene_session.h"
24 #include "session_manager.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 
32 class SceneSessionManagerTest9 : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 
39     static sptr<SceneSessionManager> ssm_;
40 private:
41     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
42 };
43 
44 sptr<SceneSessionManager> SceneSessionManagerTest9::ssm_ = nullptr;
45 
NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession> & session,const SessionInfo & sessionInfo)46 void NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)
47 {
48 }
49 
getStateFalse(const ManagerState key)50 bool getStateFalse(const ManagerState key)
51 {
52     return false;
53 }
54 
getStateTrue(const ManagerState key)55 bool getStateTrue(const ManagerState key)
56 {
57     return true;
58 }
59 
TraverseFuncTest(const sptr<SceneSession> & session)60 bool TraverseFuncTest(const sptr<SceneSession>& session)
61 {
62     return true;
63 }
64 
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)65 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
66 {
67 }
68 
ProcessStatusBarEnabledChangeFuncTest(bool enable)69 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
70 {
71 }
72 
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)73 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
74 {
75 }
76 
SetUpTestCase()77 void SceneSessionManagerTest9::SetUpTestCase()
78 {
79     ssm_ = &SceneSessionManager::GetInstance();
80 }
81 
TearDownTestCase()82 void SceneSessionManagerTest9::TearDownTestCase()
83 {
84     ssm_ = nullptr;
85 }
86 
SetUp()87 void SceneSessionManagerTest9::SetUp()
88 {
89 }
90 
TearDown()91 void SceneSessionManagerTest9::TearDown()
92 {
93     usleep(WAIT_SYNC_IN_NS);
94 }
95 
96 namespace {
97 /**
98  * @tc.name: TraverseSessionTreeFromTopToBottom
99  * @tc.desc: TraverseSessionTreeFromTopToBottom
100  * @tc.type: FUNC
101  */
102 HWTEST_F(SceneSessionManagerTest9, TraverseSessionTreeFromTopToBottom, Function | SmallTest | Level3)
103 {
104     ASSERT_NE(nullptr, ssm_);
105     ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest);
106 
107     SessionInfo sessionInfo;
108     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
109     sessionInfo.abilityName_ = "TraverseSessionTreeFromTopToBottom";
110     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
111     ASSERT_NE(nullptr, sceneSession);
112     ssm_->sceneSessionMap_.insert(std::make_pair(1, nullptr));
113     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
114     ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest);
115 }
116 
117 /**
118  * @tc.name: TestRequestFocusStatus_01
119  * @tc.desc: Test RequestFocusStatus with sceneSession is nullptr
120  * @tc.type: FUNC
121  */
122 HWTEST_F(SceneSessionManagerTest9, TestRequestFocusStatus_01, Function | SmallTest | Level3)
123 {
124     ASSERT_NE(nullptr, ssm_);
125     auto res = ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE);
126     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
127 }
128 
129 /**
130  * @tc.name: TestRequestFocusStatus_02
131  * @tc.desc: Test RequestFocusStatus with not call by the same process
132  * @tc.type: FUNC
133  */
134 HWTEST_F(SceneSessionManagerTest9, TestRequestFocusStatus_02, Function | SmallTest | Level3)
135 {
136     ASSERT_NE(nullptr, ssm_);
137 
138     SessionInfo sessionInfo;
139     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
140     sessionInfo.abilityName_ = "RequestFocusStatus02";
141     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
142     sceneSession->SetCallingPid(0);
143     sceneSession->isVisible_ = false;
144     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
145     auto res = ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE);
146     ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR);
147 }
148 
149 /**
150  * @tc.name: TestRequestSessionFocusImmediately_01
151  * @tc.desc: Test RequestSessionFocusImmediately with invalid persistentId
152  * @tc.type: FUNC
153  */
154 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_01, Function | SmallTest | Level3)
155 {
156     ASSERT_NE(nullptr, ssm_);
157     ssm_->sceneSessionMap_.clear();
158 
159     WSError ret = ssm_->RequestSessionFocusImmediately(0);
160     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
161 }
162 
163 /**
164  * @tc.name: TestRequestSessionFocusImmediately_02
165  * @tc.desc: Test RequestSessionFocusImmediately with session is nullptr
166  * @tc.type: FUNC
167  */
168 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_02, Function | SmallTest | Level3)
169 {
170     ASSERT_NE(nullptr, ssm_);
171     ssm_->sceneSessionMap_.clear();
172 
173     WSError ret = ssm_->RequestSessionFocusImmediately(2);
174     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
175 }
176 
177 /**
178  * @tc.name: TestRequestSessionFocusImmediately_03
179  * @tc.desc: Test RequestSessionFocusImmediately with session is not focusable
180  * @tc.type: FUNC
181  */
182 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_03, Function | SmallTest | Level3)
183 {
184     ASSERT_NE(nullptr, ssm_);
185     ssm_->sceneSessionMap_.clear();
186 
187     SessionInfo sessionInfo;
188     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
189     sessionInfo.abilityName_ = "RequestSessionFocusImmediately02";
190     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
191     sceneSession->SetFocusable(false);
192     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
193 
194     auto ret = ssm_->RequestSessionFocusImmediately(1);
195     EXPECT_EQ(ret, WSError::WS_DO_NOTHING);
196 }
197 
198 /**
199  * @tc.name: TestRequestSessionFocusImmediately_04
200  * @tc.desc: Test RequestSessionFocusImmediately with session is not focused on show
201  * @tc.type: FUNC
202  */
203 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_04, Function | SmallTest | Level3)
204 {
205     ASSERT_NE(nullptr, ssm_);
206     ssm_->sceneSessionMap_.clear();
207 
208     SessionInfo sessionInfo;
209     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
210     sessionInfo.abilityName_ = "RequestSessionFocusImmediately02";
211     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
212     sceneSession->SetFocusable(true);
213     sceneSession->SetFocusedOnShow(false);
214     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
215     auto ret = ssm_->RequestSessionFocusImmediately(1);
216     EXPECT_EQ(ret, WSError::WS_DO_NOTHING);
217 }
218 
219 /**
220  * @tc.name: TestRequestSessionFocusImmediately_05
221  * @tc.desc: Test RequestSessionFocusImmediately with ForceHideState HIDDEN_WHEN_FOCUSED
222  * @tc.type: FUNC
223  */
224 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_05, Function | SmallTest | Level3)
225 {
226     ASSERT_NE(nullptr, ssm_);
227     ssm_->sceneSessionMap_.clear();
228 
229     SessionInfo sessionInfo;
230     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
231     sessionInfo.abilityName_ = "RequestSessionFocusImmediately02";
232     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
233     sceneSession->SetFocusable(true);
234     sceneSession->SetFocusedOnShow(true);
235     sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
236     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
237     auto ret = ssm_->RequestSessionFocusImmediately(1);
238     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
239 }
240 
241 /**
242  * @tc.name: TestRequestSessionFocusImmediately_06
243  * @tc.desc: Test RequestSessionFocusImmediately with ForceHideState NOT_HIDDEN
244  * @tc.type: FUNC
245  */
246 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_06, Function | SmallTest | Level3)
247 {
248     ASSERT_NE(nullptr, ssm_);
249     ssm_->sceneSessionMap_.clear();
250 
251     SessionInfo sessionInfo;
252     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
253     sessionInfo.abilityName_ = "RequestSessionFocusImmediately02";
254     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
255     sceneSession->SetFocusable(true);
256     sceneSession->SetFocusedOnShow(true);
257     sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
258     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
259     WSError ret = ssm_->RequestSessionFocusImmediately(1);
260     EXPECT_EQ(ret, WSError::WS_OK);
261 }
262 
263 /**
264  * @tc.name: Test RequestSessionFocus_01
265  * @tc.desc: Test RequestSessionFocus invalid persistentId
266  * @tc.type: FUNC
267  */
268 HWTEST_F(SceneSessionManagerTest9, RequestSessionFocus_01, Function | SmallTest | Level3)
269 {
270     ASSERT_NE(nullptr, ssm_);
271     ssm_->sceneSessionMap_.clear();
272 
273     WSError ret = ssm_->RequestSessionFocus(0);
274     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
275 }
276 
277 /**
278  * @tc.name: RequestSessionFocus_02
279  * @tc.desc: Test RequestSessionFocus with session is nullptr
280  * @tc.type: FUNC
281  */
282 HWTEST_F(SceneSessionManagerTest9, RequestSessionFocus_02, Function | SmallTest | Level3)
283 {
284     ASSERT_NE(nullptr, ssm_);
285     ssm_->sceneSessionMap_.clear();
286 
287     WSError ret = ssm_->RequestSessionFocus(2);
288     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
289 }
290 
291 /**
292  * @tc.name: TestRequestSessionFocus_03
293  * @tc.desc: Test RequestSessionFocus with session is not focusable
294  * @tc.type: FUNC
295  */
296 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_03, Function | SmallTest | Level3)
297 {
298     ASSERT_NE(nullptr, ssm_);
299     ssm_->sceneSessionMap_.clear();
300     SessionInfo sessionInfo;
301     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
302     sessionInfo.abilityName_ = "TestRequestSessionFocus_03";
303     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
304     ASSERT_NE(nullptr, sceneSession);
305     sceneSession->SetFocusable(false);
306     sceneSession->UpdateVisibilityInner(true);
307     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
308 
309     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
310     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
311 }
312 
313 /**
314  * @tc.name: TestRequestSessionFocus_04
315  * @tc.desc: Test RequestSessionFocus with session is not visible
316  * @tc.type: FUNC
317  */
318 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_04, Function | SmallTest | Level3)
319 {
320     ASSERT_NE(nullptr, ssm_);
321     ssm_->sceneSessionMap_.clear();
322     SessionInfo sessionInfo;
323     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
324     sessionInfo.abilityName_ = "TestRequestSessionFocus_04";
325     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
326     ASSERT_NE(nullptr, sceneSession);
327     sceneSession->SetFocusable(true);
328     sceneSession->UpdateVisibilityInner(false);
329     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
330 
331     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
332     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
333 }
334 
335 /**
336  * @tc.name: TestRequestSessionFocus_05
337  * @tc.desc: Test RequestSessionFocus with session is not focused on show
338  * @tc.type: FUNC
339  */
340 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_05, Function | SmallTest | Level3)
341 {
342     ASSERT_NE(nullptr, ssm_);
343     ssm_->sceneSessionMap_.clear();
344     SessionInfo sessionInfo;
345     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
346     sessionInfo.abilityName_ = "TestRequestSessionFocus_05";
347     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
348     ASSERT_NE(nullptr, sceneSession);
349     sceneSession->SetFocusable(true);
350     sceneSession->UpdateVisibilityInner(true);
351     sceneSession->SetFocusedOnShow(false);
352     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
353 
354     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
355     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
356 }
357 
358 /**
359  * @tc.name: TestRequestSessionFocus_06
360  * @tc.desc: Test RequestSessionFocus with session is not focusable on show
361  * @tc.type: FUNC
362  */
363 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_06, Function | SmallTest | Level3)
364 {
365     ASSERT_NE(nullptr, ssm_);
366     ssm_->sceneSessionMap_.clear();
367     SessionInfo sessionInfo;
368     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
369     sessionInfo.abilityName_ = "TestRequestSessionFocus_06";
370     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
371     ASSERT_NE(nullptr, sceneSession);
372     sceneSession->SetFocusable(true);
373     sceneSession->UpdateVisibilityInner(true);
374     sceneSession->SetFocusedOnShow(true);
375     sceneSession->SetFocusableOnShow(false);
376     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
377 
378     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::FOREGROUND);
379     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
380 }
381 
382 /**
383  * @tc.name: TestRequestSessionFocus_07
384  * @tc.desc: Test RequestSessionFocus with windowType is APP_SUB_WINDOW_BASE
385  * @tc.type: FUNC
386  */
387 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_07, Function | SmallTest | Level3)
388 {
389     ASSERT_NE(nullptr, ssm_);
390     ssm_->sceneSessionMap_.clear();
391     SessionInfo sessionInfo;
392     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
393     sessionInfo.abilityName_ = "TestRequestSessionFocus_07";
394     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
395     ASSERT_NE(nullptr, sceneSession);
396     sceneSession->SetFocusable(true);
397     sceneSession->UpdateVisibilityInner(true);
398     sceneSession->SetFocusedOnShow(true);
399     sceneSession->SetFocusableOnShow(true);
400     sceneSession->GetSessionProperty()->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
401     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
402 
403     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
404     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
405 }
406 
407 /**
408  * @tc.name: TestRequestSessionFocus_08
409  * @tc.desc: Test RequestSessionFocus with windowType is WINDOW_TYPE_DIALOG
410  * @tc.type: FUNC
411  */
412 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_08, Function | SmallTest | Level3)
413 {
414     ASSERT_NE(nullptr, ssm_);
415     ssm_->sceneSessionMap_.clear();
416     SessionInfo sessionInfo;
417     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
418     sessionInfo.abilityName_ = "TestRequestSessionFocus_08";
419     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
420     ASSERT_NE(nullptr, sceneSession);
421     sceneSession->SetFocusable(true);
422     sceneSession->UpdateVisibilityInner(true);
423     sceneSession->SetFocusedOnShow(true);
424     sceneSession->SetFocusableOnShow(true);
425     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
426     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
427     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
428 
429     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
430     ASSERT_EQ(ret, WSError::WS_OK);
431 }
432 
433 /**
434  * @tc.name: TestRequestSessionFocus_09
435  * @tc.desc: Test RequestSessionFocus with ForceHideState HIDDEN_WHEN_FOCUSED
436  * @tc.type: FUNC
437  */
438 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_09, Function | SmallTest | Level3)
439 {
440     ASSERT_NE(nullptr, ssm_);
441     ssm_->sceneSessionMap_.clear();
442     SessionInfo sessionInfo;
443     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
444     sessionInfo.abilityName_ = "TestRequestSessionFocus_08";
445     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
446     ASSERT_NE(nullptr, sceneSession);
447     sceneSession->SetFocusable(true);
448     sceneSession->UpdateVisibilityInner(true);
449     sceneSession->SetFocusedOnShow(true);
450     sceneSession->SetFocusableOnShow(true);
451     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
452     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
453     sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
454     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
455 
456     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
457     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
458 }
459 
460 /**
461  * @tc.name: TestRequestSessionFocus_010
462  * @tc.desc: Test RequestSessionFocus with ForceHideState HIDDEN_WHEN_FOCUSED
463  * @tc.type: FUNC
464  */
465 HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocus_010, Function | SmallTest | Level3)
466 {
467     ASSERT_NE(nullptr, ssm_);
468     ssm_->sceneSessionMap_.clear();
469     SessionInfo sessionInfo;
470     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
471     sessionInfo.abilityName_ = "RequestSessionFocus02";
472     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
473     ASSERT_NE(nullptr, sceneSession);
474     sceneSession->SetFocusable(true);
475     sceneSession->UpdateVisibilityInner(true);
476     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
477     sceneSession->SetFocusedOnShow(true);
478     sceneSession->SetFocusableOnShow(false);
479     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
480     sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
481     sceneSession->SetTopmost(true);
482     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
483 
484     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
485     ASSERT_EQ(ret, WSError::WS_OK);
486     ASSERT_EQ(sceneSession->isFocused_, true);
487 }
488 
489 /**
490  * @tc.name: RequestSessionUnfocus02
491  * @tc.desc: RequestSessionUnfocus
492  * @tc.type: FUNC
493  */
494 HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest | Level3)
495 {
496     ASSERT_NE(nullptr, ssm_);
497     ssm_->sceneSessionMap_.clear();
498     WSError ret = ssm_->RequestSessionUnfocus(0, FocusChangeReason::DEFAULT);
499     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
500 
501     SessionInfo sessionInfo;
502     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
503     sessionInfo.abilityName_ = "RequestSessionUnfocus02";
504     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
505     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
506     ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 0);
507     ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
508     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
509     ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 2);
510     sceneSession->persistentId_ = 1;
511     sceneSession->SetZOrder(50);
512     sceneSession->state_ = SessionState::STATE_FOREGROUND;
513     sceneSession->isVisible_ = true;
514     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
515 
516     SessionInfo sessionInfo1;
517     sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
518     ASSERT_NE(nullptr, sceneSession1);
519     sceneSession1->GetSessionProperty()->SetParentPersistentId(1);
520     sceneSession1->persistentId_ = 2;
521     sceneSession1->SetZOrder(100);
522     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
523     ret = ssm_->RequestSessionUnfocus(2, FocusChangeReason::DEFAULT);
524     ASSERT_EQ(ret, WSError::WS_OK);
525     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
526     ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
527 
528     focusGroup->SetLastFocusedSessionId(4);
529     sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
530     SessionInfo sessionInfo2;
531     sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
532     ASSERT_NE(nullptr, sceneSession2);
533     sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
534     sceneSession2->SetZOrder(20);
535     sceneSession2->state_ = SessionState::STATE_FOREGROUND;
536     sceneSession2->isVisible_ = true;
537     sceneSession2->persistentId_ = 4;
538     ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession2));
539     ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
540     ASSERT_EQ(ret, WSError::WS_OK);
541     ASSERT_EQ(focusGroup->GetFocusedSessionId(), 4);
542 }
543 
544 /**
545  * @tc.name: RequestAllAppSessionUnfocusInner
546  * @tc.desc: RequestAllAppSessionUnfocusInner
547  * @tc.type: FUNC
548  */
549 HWTEST_F(SceneSessionManagerTest9, RequestAllAppSessionUnfocusInner, Function | SmallTest | Level3)
550 {
551     ASSERT_NE(nullptr, ssm_);
552     ssm_->RequestAllAppSessionUnfocusInner();
553 
554     SessionInfo sessionInfo;
555     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
556     sessionInfo.abilityName_ = "RequestAllAppSessionUnfocusInner";
557     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
558     ASSERT_NE(nullptr, sceneSession);
559     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
560     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
561     focusGroup->SetFocusedSessionId(1);
562     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
563     ssm_->RequestAllAppSessionUnfocusInner();
564 
565     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
566     ssm_->RequestAllAppSessionUnfocusInner();
567 }
568 
569 /**
570  * @tc.name: UpdateFocus04
571  * @tc.desc: UpdateFocus
572  * @tc.type: FUNC
573  */
574 HWTEST_F(SceneSessionManagerTest9, UpdateFocus04, Function | SmallTest | Level3)
575 {
576     ASSERT_NE(nullptr, ssm_);
577     SessionInfo sessionInfo;
578     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
579     sessionInfo.abilityName_ = "UpdateFocus04";
580     sessionInfo.isSystem_ = true;
581     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
582     ASSERT_NE(nullptr, sceneSession);
583     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
584     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
585     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
586     focusGroup->SetFocusedSessionId(0);
587     sceneSession->UpdateFocus(false);
588     ssm_->UpdateFocus(1, false);
589 
590     ssm_->listenerController_ = nullptr;
591     ssm_->UpdateFocus(1, true);
592 
593     std::shared_ptr<SessionListenerController> listenerController = std::make_shared<SessionListenerController>();
594     ssm_->listenerController_ = listenerController;
595     ssm_->UpdateFocus(1, true);
596 
597     sessionInfo.isSystem_ = false;
598     focusGroup->SetFocusedSessionId(1);
599     sceneSession->UpdateFocus(true);
600     ssm_->UpdateFocus(1, false);
601 
602     sceneSession->UpdateFocus(false);
603     ssm_->UpdateFocus(1, true);
604 }
605 
606 /**
607  * @tc.name: ProcessFocusWhenForeground
608  * @tc.desc: ProcessFocusWhenForeground
609  * @tc.type: FUNC
610  */
611 HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground, Function | SmallTest | Level3)
612 {
613     ASSERT_NE(nullptr, ssm_);
614     SessionInfo sessionInfo;
615     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
616     sessionInfo.abilityName_ = "ProcessFocusWhenForeground";
617     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
618     ASSERT_NE(nullptr, sceneSession);
619     sceneSession->persistentId_ = 1;
620     ASSERT_NE(nullptr, sceneSession->property_);
621     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
622     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
623     focusGroup->SetFocusedSessionId(1);
624     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
625     ssm_->ProcessFocusWhenForeground(sceneSession);
626 
627     sceneSession->isVisible_ = true;
628     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
629     ssm_->ProcessFocusWhenForeground(sceneSession);
630 }
631 
632 /**
633  * @tc.name: ProcessFocusWhenForeground01
634  * @tc.desc: ProcessFocusWhenForeground
635  * @tc.type: FUNC
636  */
637 HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground01, Function | SmallTest | Level3)
638 {
639     ASSERT_NE(nullptr, ssm_);
640     SessionInfo sessionInfo;
641     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
642     sessionInfo.abilityName_ = "ProcessFocusWhenForeground";
643     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
644     sceneSession->persistentId_ = 1;
645     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
646     focusGroup->SetFocusedSessionId(2);
647     sceneSession->SetFocusedOnShow(false);
648     ssm_->ProcessFocusWhenForeground(sceneSession);
649     EXPECT_EQ(sceneSession->IsFocusedOnShow(), false);
650 
651     sceneSession->isVisible_ = true;
652     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
653     ssm_->ProcessFocusWhenForeground(sceneSession);
654     EXPECT_EQ(sceneSession->IsFocusedOnShow(), true);
655 }
656 
657 /**
658  * @tc.name: ProcessSubSessionForeground03
659  * @tc.desc: ProcessSubSessionForeground
660  * @tc.type: FUNC
661  */
662 HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | SmallTest | Level3)
663 {
664     ASSERT_NE(nullptr, ssm_);
665     SessionInfo sessionInfo;
666     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
667     sessionInfo.abilityName_ = "ProcessSubSessionForeground03";
668     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
669     ASSERT_NE(nullptr, sceneSession);
670 
671     SessionInfo subSessionInfo;
672     sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(subSessionInfo, nullptr);
673     ASSERT_NE(nullptr, subSceneSession);
674     subSceneSession->SetTopmost(true);
675     subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
676     subSceneSession->persistentId_ = 1;
677     sceneSession->GetSubSession().push_back(subSceneSession);
678     ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession));
679 
680     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
681     focusGroup->SetFocusedSessionId(1);
682     ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
683 
684     SessionInfo subSessionInfo1;
685     sptr<SceneSession> subSceneSession1 = sptr<SceneSession>::MakeSptr(subSessionInfo1, nullptr);
686     ASSERT_NE(nullptr, subSceneSession1);
687     subSceneSession1->SetTopmost(true);
688     subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
689     subSceneSession1->persistentId_ = 0;
690     sceneSession->GetSubSession().push_back(subSceneSession1);
691 
692     SessionInfo subSessionInfo2;
693     sptr<SceneSession> subSceneSession2 = sptr<SceneSession>::MakeSptr(subSessionInfo2, nullptr);
694     ASSERT_NE(nullptr, subSceneSession2);
695     subSceneSession2->SetTopmost(true);
696     subSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
697     sceneSession->GetSubSession().push_back(subSceneSession2);
698 
699     SessionInfo subSessionInfo3;
700     sptr<SceneSession> subSceneSession3 = sptr<SceneSession>::MakeSptr(subSessionInfo3, nullptr);
701     ASSERT_NE(nullptr, subSceneSession3);
702     subSceneSession3->SetTopmost(false);
703     subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE);
704     sceneSession->GetSubSession().push_back(subSceneSession3);
705 
706     sceneSession->GetSubSession().push_back(nullptr);
707 
708     ssm_->ProcessSubSessionForeground(sceneSession);
709 
710     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
711     ssm_->ProcessSubSessionForeground(sceneSession);
712 
713     focusGroup->SetFocusedSessionId(2);
714     ssm_->ProcessSubSessionForeground(sceneSession);
715 }
716 
717 /**
718  * @tc.name: ProcessFocusWhenForegroundScbCore
719  * @tc.desc: ProcessFocusWhenForegroundScbCore
720  * @tc.type: FUNC
721  */
722 HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForegroundScbCore, Function | SmallTest | Level3)
723 {
724     ASSERT_NE(nullptr, ssm_);
725     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
726     focusGroup->SetFocusedSessionId(0);
727     SessionInfo sessionInfo;
728     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
729     sessionInfo.abilityName_ = "ProcessFocusWhenForegroundScbCore";
730     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
731     sceneSession->persistentId_ = 1;
732     ASSERT_NE(nullptr, sceneSession->property_);
733     sceneSession->SetFocusableOnShow(false);
734     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
735     ssm_->ProcessFocusWhenForegroundScbCore(sceneSession);
736     ASSERT_EQ(sceneSession->GetPostProcessFocusState().isFocused_, false);
737     ASSERT_EQ(focusGroup->GetFocusedSessionId(), 0);
738 
739     sceneSession->SetFocusableOnShow(true);
740     ssm_->ProcessFocusWhenForegroundScbCore(sceneSession); // SetPostProcessFocusState
741     ASSERT_EQ(sceneSession->GetPostProcessFocusState().isFocused_, true);
742 
743     sceneSession->isVisible_ = true;
744     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
745     ssm_->ProcessFocusWhenForegroundScbCore(sceneSession); // RequestSessionFocus
746     ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
747 }
748 
749 /**
750  * @tc.name: ProcessModalTopmostRequestFocusImmdediately02
751  * @tc.desc: ProcessModalTopmostRequestFocusImmdediately
752  * @tc.type: FUNC
753  */
754 HWTEST_F(SceneSessionManagerTest9, ProcessModalTopmostRequestFocusImmdediately02, Function | SmallTest | Level3)
755 {
756     ASSERT_NE(nullptr, ssm_);
757     SessionInfo sessionInfo;
758     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
759     sessionInfo.abilityName_ = "ProcessModalTopmostRequestFocusImmdediately02";
760     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
761     ASSERT_NE(nullptr, sceneSession);
762 
763     SessionInfo subSessionInfo;
764     sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(subSessionInfo, nullptr);
765     ASSERT_NE(nullptr, subSceneSession);
766     subSceneSession->SetTopmost(true);
767     subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
768     subSceneSession->persistentId_ = 1;
769     subSceneSession->SetFocusable(true);
770     subSceneSession->SetFocusedOnShow(true);
771     sceneSession->GetSubSession().push_back(subSceneSession);
772 
773     ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession));
774     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
775     focusGroup->SetFocusedSessionId(1);
776     ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
777 
778     SessionInfo subSessionInfo1;
779     sptr<SceneSession> subSceneSession1 = sptr<SceneSession>::MakeSptr(subSessionInfo1, nullptr);
780     ASSERT_NE(nullptr, subSceneSession1);
781     subSceneSession1->SetTopmost(true);
782     subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
783     subSceneSession1->persistentId_ = 0;
784     sceneSession->GetSubSession().push_back(subSceneSession1);
785 
786     SessionInfo subSessionInfo2;
787     sptr<SceneSession> subSceneSession2 = sptr<SceneSession>::MakeSptr(subSessionInfo2, nullptr);
788     ASSERT_NE(nullptr, subSceneSession2);
789     subSceneSession2->SetTopmost(true);
790     subSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
791     sceneSession->GetSubSession().push_back(subSceneSession2);
792 
793     SessionInfo subSessionInfo3;
794     sptr<SceneSession> subSceneSession3 = sptr<SceneSession>::MakeSptr(subSessionInfo3, nullptr);
795     ASSERT_NE(nullptr, subSceneSession3);
796     subSceneSession3->SetTopmost(false);
797     subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE);
798     sceneSession->GetSubSession().push_back(subSceneSession3);
799 
800     sceneSession->GetSubSession().push_back(nullptr);
801 
802     WSError ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
803     ASSERT_NE(ret, WSError::WS_OK);
804 
805     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
806     ssm_->ProcessSubSessionForeground(sceneSession);
807 
808     subSceneSession->persistentId_ = 0;
809     ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
810     ASSERT_NE(ret, WSError::WS_OK);
811 }
812 
813 /**
814  * @tc.name: ProcessDialogRequestFocusImmdediately02
815  * @tc.desc: ProcessDialogRequestFocusImmdediately
816  * @tc.type: FUNC
817  */
818 HWTEST_F(SceneSessionManagerTest9, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)
819 {
820     ASSERT_NE(nullptr, ssm_);
821     SessionInfo sessionInfo;
822     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
823     sessionInfo.abilityName_ = "ProcessDialogRequestFocusImmdediately02";
824     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
825     ASSERT_NE(nullptr, sceneSession);
826     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
827 
828     SessionInfo dialogSessionInfo;
829     sptr<SceneSession> dialogSceneSession = sptr<SceneSession>::MakeSptr(dialogSessionInfo, nullptr);
830     ASSERT_NE(nullptr, dialogSceneSession);
831     dialogSceneSession->SetTopmost(true);
832     dialogSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
833     dialogSceneSession->persistentId_ = 1;
834     dialogSceneSession->SetFocusable(true);
835     dialogSceneSession->SetFocusedOnShow(true);
836     sceneSession->GetDialogVector().push_back(dialogSceneSession);
837 
838     ssm_->sceneSessionMap_.insert(std::make_pair(1, dialogSceneSession));
839     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
840     focusGroup->SetFocusedSessionId(1);
841     ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
842 
843     SessionInfo dialogSessionInfo1;
844     sptr<SceneSession> dialogSceneSession1 = sptr<SceneSession>::MakeSptr(dialogSessionInfo1, nullptr);
845     ASSERT_NE(nullptr, dialogSceneSession1);
846     dialogSceneSession1->SetTopmost(true);
847     dialogSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
848     dialogSceneSession1->persistentId_ = 0;
849     sceneSession->GetDialogVector().push_back(dialogSceneSession1);
850 
851     SessionInfo dialogSessionInfo2;
852     sptr<SceneSession> dialogSceneSession2 = sptr<SceneSession>::MakeSptr(dialogSessionInfo2, nullptr);
853     ASSERT_NE(nullptr, dialogSceneSession2);
854     dialogSceneSession2->SetTopmost(true);
855     dialogSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
856     sceneSession->GetDialogVector().push_back(dialogSceneSession2);
857 
858     sceneSession->GetDialogVector().push_back(nullptr);
859 
860     WSError ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
861     ASSERT_NE(ret, WSError::WS_OK);
862 
863     dialogSceneSession->persistentId_ = 0;
864     ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
865     ASSERT_NE(ret, WSError::WS_OK);
866 }
867 
868 /**
869  * @tc.name: NotifyCompleteFirstFrameDrawing03
870  * @tc.desc: NotifyCompleteFirstFrameDrawing
871  * @tc.type: FUNC
872  */
873 HWTEST_F(SceneSessionManagerTest9, NotifyCompleteFirstFrameDrawing03, Function | SmallTest | Level3)
874 {
875     ASSERT_NE(nullptr, ssm_);
876     SessionInfo sessionInfo;
877     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
878     sessionInfo.abilityName_ = "NotifyCompleteFirstFrameDrawing03";
879     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
880     abilityInfo->excludeFromMissions = true;
881     sessionInfo.abilityInfo = abilityInfo;
882     sessionInfo.isSystem_ = true;
883     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
884     ASSERT_NE(nullptr, sceneSession);
885     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
886     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
887     ssm_->listenerController_ = nullptr;
888     ssm_->NotifyCompleteFirstFrameDrawing(1);
889 
890     std::shared_ptr<SessionListenerController> listenerController = std::make_shared<SessionListenerController>();
891     ssm_->listenerController_ = listenerController;
892     sessionInfo.isSystem_ = false;
893     ssm_->eventHandler_ = nullptr;
894     ssm_->NotifyCompleteFirstFrameDrawing(1);
895 
896     std::shared_ptr<AppExecFwk::EventHandler> eventHandler = std::make_shared<AppExecFwk::EventHandler>();
897     ssm_->eventHandler_ = eventHandler;
898     abilityInfo->excludeFromMissions = false;
899     ssm_->NotifyCompleteFirstFrameDrawing(1);
900 }
901 
902 /**
903  * @tc.name: SetSessionLabel02
904  * @tc.desc: SetSessionLabel
905  * @tc.type: FUNC
906  */
907 HWTEST_F(SceneSessionManagerTest9, SetSessionLabel02, Function | SmallTest | Level3)
908 {
909     ASSERT_NE(nullptr, ssm_);
910     SessionInfo sessionInfo;
911     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
912     sessionInfo.abilityName_ = "SetSessionLabel02";
913     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
914     ASSERT_NE(nullptr, sceneSession);
915     sptr<IRemoteObject> token = sptr<MockIRemoteObject>::MakeSptr();
916     ASSERT_NE(nullptr, token);
917     sceneSession->SetAbilityToken(token);
918     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
919     ssm_->listenerController_ = nullptr;
920 
921     std::string label = "testLabel";
922     ssm_->SetSessionLabel(token, label);
923 
924     std::shared_ptr<SessionListenerController> listenerController = std::make_shared<SessionListenerController>();
925     ssm_->listenerController_ = listenerController;
926     sessionInfo.isSystem_ = false;
927     ssm_->SetSessionLabel(token, label);
928 
929     sessionInfo.isSystem_ = true;
930     ssm_->SetSessionLabel(token, label);
931 }
932 
933 /**
934  * @tc.name: RecoverAndReconnectSceneSession02
935  * @tc.desc: RecoverAndReconnectSceneSession
936  * @tc.type: FUNC
937  */
938 HWTEST_F(SceneSessionManagerTest9, RecoverAndReconnectSceneSession02, Function | SmallTest | Level3)
939 {
940     ASSERT_NE(nullptr, ssm_);
941     SessionInfo sessionInfo;
942     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
943     sessionInfo.abilityName_ = "RecoverAndReconnectSceneSession02";
944     sessionInfo.moduleName_ = "moduleTest";
945     sessionInfo.appIndex_ = 10;
946     sessionInfo.persistentId_ = 1;
947     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
948     abilityInfo->excludeFromMissions = true;
949     sessionInfo.abilityInfo = abilityInfo;
950     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
951     ASSERT_NE(nullptr, sceneSession);
952 
953     sptr<WindowSessionProperty> property = sceneSession->GetSessionProperty();
954     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
955     property->SetPersistentId(1);
956     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
957     property->SetWindowState(WindowState::STATE_SHOWN);
958     property->SetRequestedOrientation(Orientation::UNSPECIFIED);
959     ssm_->alivePersistentIds_.push_back(1);
960     ssm_->recoveringFinished_ = false;
961     ssm_->recoverSceneSessionFunc_ = NotifyRecoverSceneSessionFuncTest;
962 
963     sptr<ISession> session;
964     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
965     auto result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr);
966     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
967 
968     property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
969     property->SetPersistentId(2);
970     result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr);
971     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
972 }
973 
974 /**
975  * @tc.name: RefreshPcZorder
976  * @tc.desc: RefreshPcZorder
977  * @tc.type: FUNC
978  */
979 HWTEST_F(SceneSessionManagerTest9, RefreshPcZorder, Function | SmallTest | Level3) {
980     std::vector<int32_t> persistentIds;
981     SessionInfo info1;
982     info1.abilityName_ = "RefreshPcZorder1";
983     info1.bundleName_ = "RefreshPcZorder1";
984     sptr<SceneSession> session1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
985     ASSERT_NE(session1, nullptr);
986     persistentIds.push_back(session1->GetPersistentId());
987     ssm_->sceneSessionMap_.insert({session1->GetPersistentId(), session1});
988     SessionInfo info2;
989     info2.abilityName_ = "RefreshPcZorder2";
990     info2.bundleName_ = "RefreshPcZorder2";
991     sptr<SceneSession> session2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
992     ASSERT_NE(session2, nullptr);
993     persistentIds.push_back(session2->GetPersistentId());
994     ssm_->sceneSessionMap_.insert({session2->GetPersistentId(), session2});
995     SessionInfo info3;
996     info3.abilityName_ = "RefreshPcZorder3";
997     info3.bundleName_ = "RefreshPcZorder3";
998     sptr<SceneSession> session3 = sptr<SceneSession>::MakeSptr(info3, nullptr);
999     ASSERT_NE(session3, nullptr);
1000     session3->SetZOrder(404);
1001     ssm_->sceneSessionMap_.insert({session3->GetPersistentId(), session3});
1002     persistentIds.push_back(999);
1003     uint32_t startZOrder = 100;
1004     std::vector<int32_t> newPersistentIds = persistentIds;
1005     ssm_->RefreshPcZOrderList(startZOrder, std::move(persistentIds));
1006     ssm_->RefreshPcZOrderList(UINT32_MAX, std::move(newPersistentIds));
1007     auto start = std::chrono::system_clock::now();
1008     // Due to RefreshPcZOrderList being asynchronous, spin lock is added.
1009     // The spin lock itself is set with a timeout escape time of 3 seconds
1010     while (true) {
1011         if ((session1->GetZOrder() != 0 && session2->GetZOrder() != 0 && session1->GetZOrder() != 100) ||
1012             std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - start).count() >= 3) {
1013             break;
1014         }
1015         std::this_thread::sleep_for(std::chrono::milliseconds(100));
1016     }
1017     ASSERT_EQ(session2->GetZOrder(), 101);
1018     ASSERT_EQ(session3->GetZOrder(), 404);
1019     ASSERT_EQ(session1->GetZOrder(), UINT32_MAX);
1020 }
1021 
1022 /**
1023  * @tc.name: GetSessionRSVisible
1024  * @tc.desc: GetSessionRSVisible
1025  * @tc.type: FUNC
1026  */
1027 HWTEST_F(SceneSessionManagerTest9, GetSessionRSVisible, Function | SmallTest | Level3)
1028 {
1029     ASSERT_NE(nullptr, ssm_);
1030     SessionInfo sessionInfo;
1031     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
1032     sessionInfo.abilityName_ = "GetSessionRSVisible";
1033     sessionInfo.moduleName_ = "moduleTest";
1034     uint64_t windowId = 10;
1035     sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1036     sceneSession01->persistentId_ = windowId;
1037     sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1038     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
1039     currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
1040     currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
1041     struct RSSurfaceNodeConfig config;
1042     sceneSession02->surfaceNode_ = RSSurfaceNode::Create(config);
1043     ASSERT_NE(nullptr, sceneSession02->surfaceNode_);
1044     sceneSession02->surfaceNode_->id_ = 0;
1045     sceneSession02->persistentId_ = windowId;
1046     ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession02));
1047 
1048     bool actual = ssm_->GetSessionRSVisible(sceneSession01, currVisibleData);
1049     EXPECT_EQ(actual, true);
1050 }
1051 
1052 /**
1053  * @tc.name: CheckClickFocusIsDownThroughFullScreen
1054  * @tc.desc: CheckClickFocusIsDownThroughFullScreen
1055  * @tc.type: FUNC
1056  */
1057 HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen, Function | SmallTest | Level3)
1058 {
1059     ASSERT_NE(ssm_, nullptr);
1060     SessionInfo info;
1061     info.abilityName_ = "test1";
1062     info.bundleName_ = "test2";
1063 
1064     sptr<SceneSession> focusedSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1065     ASSERT_NE(focusedSession, nullptr);
1066     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1067     ASSERT_NE(sceneSession, nullptr);
1068     bool ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT);
1069     ASSERT_EQ(ret, false);
1070 
1071     focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
1072     ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT);
1073     ASSERT_EQ(ret, false);
1074     sceneSession->SetZOrder(50);
1075     focusedSession->SetZOrder(100);
1076     focusedSession->blockingFocus_ = true;
1077     ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::CLICK);
1078     ASSERT_EQ(ret, true);
1079 }
1080 
1081 /**
1082  * @tc.name: ShiftFocus
1083  * @tc.desc: ShiftFocus
1084  * @tc.type: FUNC
1085  */
1086 HWTEST_F(SceneSessionManagerTest9, ShiftFocus, Function | SmallTest | Level3)
1087 {
1088     ASSERT_NE(ssm_, nullptr);
1089     ssm_->sceneSessionMap_.clear();
1090     SessionInfo info;
1091     info.abilityName_ = "test1";
1092     info.bundleName_ = "test2";
1093     sptr<SceneSession> focusedSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1094     ASSERT_NE(focusedSession, nullptr);
1095     sptr<SceneSession> nextSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1096     ASSERT_NE(nextSession, nullptr);
1097     focusedSession->persistentId_ = 1;
1098     nextSession->persistentId_ = 4;
1099     ssm_->sceneSessionMap_.insert({1, focusedSession});
1100     ssm_->sceneSessionMap_.insert({4, nextSession});
1101     auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
1102     focusGroup->SetFocusedSessionId(1);
1103     WSError ret = ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, false, FocusChangeReason::DEFAULT);
1104     ASSERT_EQ(ret, WSError::WS_OK);
1105     ASSERT_EQ(focusedSession->isFocused_, false);
1106     ASSERT_EQ(nextSession->isFocused_, true);
1107 }
1108 
1109 /**
1110  * @tc.name: CheckUIExtensionCreation
1111  * @tc.desc: CheckUIExtensionCreation
1112  * @tc.type: FUNC
1113  */
1114 HWTEST_F(SceneSessionManagerTest9, CheckUIExtensionCreation, Function | SmallTest | Level3)
1115 {
1116     ASSERT_NE(ssm_, nullptr);
1117     AppExecFwk::ElementName element;
1118     int32_t windowId = 5;
1119     uint32_t callingTokenId = 0;
1120     int32_t pid = 0;
1121     bool isSystemCalling = SessionPermission::IsSystemCalling();
1122     AppExecFwk::ExtensionAbilityType extensionAbilityType = AppExecFwk::ExtensionAbilityType::ACTION;
1123     auto ret = ssm_->CheckUIExtensionCreation(windowId, callingTokenId, element, extensionAbilityType, pid);
1124     ASSERT_EQ(ret, isSystemCalling ? WMError::WM_ERROR_INVALID_WINDOW : WMError::WM_ERROR_NOT_SYSTEM_APP);
1125 
1126     SessionInfo info;
1127     sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1128     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, callback);
1129     ssm_->sceneSessionMap_.insert(std::pair<int32_t, sptr<SceneSession>>(0, sceneSession));
1130     windowId = 0;
1131 
1132     Session session(info);
1133     session.getStateFromManagerFunc_ = getStateFalse;
1134     ret = ssm_->CheckUIExtensionCreation(windowId, callingTokenId, element, extensionAbilityType, pid);
1135     ASSERT_EQ(ret, isSystemCalling ? WMError::WM_OK : WMError::WM_ERROR_NOT_SYSTEM_APP);
1136 
1137     session.getStateFromManagerFunc_ = getStateTrue;
1138     ssm_->CheckUIExtensionCreation(windowId, callingTokenId, element, extensionAbilityType, pid);
1139 }
1140 
1141 /**
1142  * @tc.name: CheckUIExtensionCreation01
1143  * @tc.desc: CheckUIExtensionCreation
1144  * @tc.type: FUNC
1145  */
1146 HWTEST_F(SceneSessionManagerTest9, CheckUIExtensionCreation01, Function | SmallTest | Level3)
1147 {
1148     ASSERT_NE(ssm_, nullptr);
1149     AppExecFwk::ElementName element;
1150     int32_t windowId = 0;
1151     uint32_t callingTokenId = 0;
1152     int32_t pid = 0;
1153     bool isSystemCalling = SessionPermission::IsSystemCalling();
1154     AppExecFwk::ExtensionAbilityType extensionAbilityType = AppExecFwk::ExtensionAbilityType::ACTION;
1155 
1156     SessionInfo info;
1157     sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1158     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, callback);
1159     ssm_->sceneSessionMap_.insert(std::pair<int32_t, sptr<SceneSession>>(0, sceneSession));
1160     Session session(info);
1161     session.getStateFromManagerFunc_ = getStateTrue;
1162     auto ret = ssm_->CheckUIExtensionCreation(windowId, callingTokenId, element, extensionAbilityType, pid);
1163 
1164     session.property_ = nullptr;
1165     ret = ssm_->CheckUIExtensionCreation(windowId, callingTokenId, element, extensionAbilityType, pid);
1166     ASSERT_EQ(ret, isSystemCalling ? WMError::WM_OK : WMError::WM_ERROR_NOT_SYSTEM_APP);
1167 
1168     sceneSession->IsShowOnLockScreen(0);
1169     session.zOrder_ = 1;
1170     ssm_->CheckUIExtensionCreation(windowId, callingTokenId, element, extensionAbilityType, pid);
1171     ASSERT_EQ(ret, isSystemCalling ? WMError::WM_OK : WMError::WM_ERROR_NOT_SYSTEM_APP);
1172 }
1173 
1174 /**
1175  * @tc.name: GetLockScreenZOrder
1176  * @tc.desc: GetLockScreenZOrder
1177  * @tc.type: FUNC
1178  */
1179 HWTEST_F(SceneSessionManagerTest9, GetLockScreenZOrder, Function | SmallTest | Level3)
1180 {
1181     ASSERT_NE(ssm_, nullptr);
1182     ssm_->sceneSessionMap_.clear();
1183     SessionInfo info;
1184     sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1185     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, callback);
1186     constexpr uint32_t DEFAULT_LOCK_SCREEN_ZORDER = 2000;
1187     constexpr uint32_t LOCK_SCREEN_ZORDER = 2003;
1188     ssm_->sceneSessionMap_.insert(std::pair<int32_t, sptr<SceneSession>>(0, sceneSession));
1189     ASSERT_EQ(ssm_->GetLockScreenZOrder(), DEFAULT_LOCK_SCREEN_ZORDER);
1190     ASSERT_EQ(sceneSession->IsScreenLockWindow(), false);
1191     ASSERT_EQ(sceneSession->GetZOrder(), 0);
1192 
1193     info.bundleName_ = "SCBScreenLock2";
1194     sptr<SceneSession> lockScreenSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1195     ssm_->sceneSessionMap_.insert(std::pair<int32_t, sptr<SceneSession>>(1, lockScreenSession));
1196     lockScreenSession->SetZOrder(0);
1197     ASSERT_EQ(ssm_->GetLockScreenZOrder(), DEFAULT_LOCK_SCREEN_ZORDER);
1198     lockScreenSession->SetZOrder(DEFAULT_LOCK_SCREEN_ZORDER);
1199     ASSERT_EQ(ssm_->GetLockScreenZOrder(), DEFAULT_LOCK_SCREEN_ZORDER);
1200     lockScreenSession->SetZOrder(DEFAULT_LOCK_SCREEN_ZORDER - 1);
1201     ASSERT_EQ(ssm_->GetLockScreenZOrder(), DEFAULT_LOCK_SCREEN_ZORDER);
1202     lockScreenSession->SetZOrder(LOCK_SCREEN_ZORDER);
1203     ASSERT_EQ(lockScreenSession->IsScreenLockWindow(), true);
1204     ASSERT_EQ(lockScreenSession->GetZOrder(), LOCK_SCREEN_ZORDER);
1205     ASSERT_EQ(ssm_->sceneSessionMap_.size(), 2);
1206     ASSERT_EQ(ssm_->GetLockScreenZOrder(), LOCK_SCREEN_ZORDER);
1207 }
1208 
1209 /**
1210  * @tc.name: IsLastPiPWindowVisible
1211  * @tc.desc: IsLastPiPWindowVisible
1212  * @tc.type: FUNC
1213  */
1214 HWTEST_F(SceneSessionManagerTest9, IsLastPiPWindowVisible, Function | SmallTest | Level3)
1215 {
1216     uint64_t surfaceId = 0;
1217     WindowVisibilityState lastVisibilityState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION;
1218     ssm_->sceneSessionMap_.insert(std::pair<int32_t, sptr<SceneSession>>(0, nullptr));
1219     auto ret = ssm_->IsLastPiPWindowVisible(surfaceId, lastVisibilityState);
1220     ASSERT_EQ(ret, false);
1221 }
1222 
1223 /**
1224  * @tc.name: IsLastPiPWindowVisible01
1225  * @tc.desc: IsLastPiPWindowVisible
1226  * @tc.type: FUNC
1227  */
1228 HWTEST_F(SceneSessionManagerTest9, IsLastPiPWindowVisible01, Function | SmallTest | Level3)
1229 {
1230     uint64_t surfaceId = 0;
1231     WindowVisibilityState lastVisibilityState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION;
1232 
1233     SessionInfo info;
1234     sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1235     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, callback);
1236     ssm_->sceneSessionMap_.insert(std::pair<int32_t, sptr<SceneSession>>(0, nullptr));
1237 
1238     struct RSSurfaceNodeConfig config;
1239     sceneSession->surfaceNode_ = RSSurfaceNode::Create(config);
1240     ASSERT_NE(nullptr, sceneSession->surfaceNode_);
1241     sceneSession->surfaceNode_->id_ = 0;
1242     ssm_->SelectSesssionFromMap(0);
1243     sptr<WindowSessionProperty> property = sceneSession->GetSessionProperty();
1244     property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1245 
1246     auto ret = ssm_->IsLastPiPWindowVisible(surfaceId, lastVisibilityState);
1247     ASSERT_EQ(ret, false);
1248     ssm_->isScreenLocked_ = true;
1249     ret = ssm_->IsLastPiPWindowVisible(surfaceId, lastVisibilityState);
1250     ASSERT_EQ(ret, false);
1251     lastVisibilityState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION;
1252     ret = ssm_->IsLastPiPWindowVisible(surfaceId, lastVisibilityState);
1253     ASSERT_EQ(ret, false);
1254 }
1255 }
1256 } // namespace Rosen
1257 } // namespace OHOS