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 "interfaces/include/ws_common.h"
19 #include "iremote_object_mocker.h"
20 #include "session_manager/include/scene_session_manager.h"
21 #include "session_info.h"
22 #include "session/host/include/scene_session.h"
23 #include "session_manager.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace Rosen {
30 
31 class SceneSessionManagerTest9 : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 
38     static sptr<SceneSessionManager> ssm_;
39 private:
40     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
41 };
42 
43 sptr<SceneSessionManager> SceneSessionManagerTest9::ssm_ = nullptr;
44 
NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession> & session,const SessionInfo & sessionInfo)45 void NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)
46 {
47 }
48 
TraverseFuncTest(const sptr<SceneSession> & session)49 bool TraverseFuncTest(const sptr<SceneSession>& session)
50 {
51     return true;
52 }
53 
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)54 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
55 {
56 }
57 
ProcessStatusBarEnabledChangeFuncTest(bool enable)58 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
59 {
60 }
61 
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)62 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
63 {
64 }
65 
SetUpTestCase()66 void SceneSessionManagerTest9::SetUpTestCase()
67 {
68     ssm_ = &SceneSessionManager::GetInstance();
69 }
70 
TearDownTestCase()71 void SceneSessionManagerTest9::TearDownTestCase()
72 {
73     ssm_ = nullptr;
74 }
75 
SetUp()76 void SceneSessionManagerTest9::SetUp()
77 {
78 }
79 
TearDown()80 void SceneSessionManagerTest9::TearDown()
81 {
82     usleep(WAIT_SYNC_IN_NS);
83 }
84 
85 namespace {
86 /**
87  * @tc.name: TraverseSessionTreeFromTopToBottom
88  * @tc.desc: TraverseSessionTreeFromTopToBottom
89  * @tc.type: FUNC
90  */
91 HWTEST_F(SceneSessionManagerTest9, TraverseSessionTreeFromTopToBottom, Function | SmallTest | Level3)
92 {
93     ASSERT_NE(nullptr, ssm_);
94     ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest);
95 
96     SessionInfo sessionInfo;
97     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
98     sessionInfo.abilityName_ = "TraverseSessionTreeFromTopToBottom";
99     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
100     ASSERT_NE(nullptr, sceneSession);
101     ssm_->sceneSessionMap_.insert(std::make_pair(1, nullptr));
102     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
103     ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest);
104 }
105 
106 /**
107  * @tc.name: RequestFocusStatus02
108  * @tc.desc: RequestFocusStatus
109  * @tc.type: FUNC
110  */
111 HWTEST_F(SceneSessionManagerTest9, RequestFocusStatus02, Function | SmallTest | Level3)
112 {
113     ASSERT_NE(nullptr, ssm_);
114     EXPECT_EQ(ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE), WMError::WM_ERROR_NULLPTR);
115 
116     SessionInfo sessionInfo;
117     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
118     sessionInfo.abilityName_ = "RequestFocusStatus02";
119     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
120     ASSERT_NE(nullptr, sceneSession);
121     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
122     ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE);
123 }
124 
125 /**
126  * @tc.name: RequestSessionFocusImmediately02
127  * @tc.desc: RequestSessionFocusImmediately
128  * @tc.type: FUNC
129  */
130 HWTEST_F(SceneSessionManagerTest9, RequestSessionFocusImmediately02, Function | SmallTest | Level3)
131 {
132     ASSERT_NE(nullptr, ssm_);
133     EXPECT_NE(ssm_->RequestSessionFocusImmediately(0), WSError::WS_OK);
134 
135     ssm_->RequestSessionFocusImmediately(2);
136 
137     SessionInfo sessionInfo;
138     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
139     sessionInfo.abilityName_ = "RequestSessionFocusImmediately02";
140     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
141 
142     ASSERT_NE(nullptr, sceneSession);
143     sceneSession->SetFocusable(false);
144     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
145     ssm_->RequestSessionFocusImmediately(1);
146 
147     sceneSession->SetFocusable(true);
148     sceneSession->SetFocusedOnShow(false);
149     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
150     ssm_->RequestSessionFocusImmediately(1);
151 
152     sceneSession->SetFocusedOnShow(true);
153     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
154     ssm_->RequestSessionFocusImmediately(1);
155 }
156 
157 /**
158  * @tc.name: RequestSessionFocus02
159  * @tc.desc: RequestSessionFocus
160  * @tc.type: FUNC
161  */
162 HWTEST_F(SceneSessionManagerTest9, RequestSessionFocus02, Function | SmallTest | Level3)
163 {
164     ASSERT_NE(nullptr, ssm_);
165     SessionInfo sessionInfo;
166     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
167     sessionInfo.abilityName_ = "RequestSessionFocus02";
168     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
169     ASSERT_NE(nullptr, sceneSession);
170     sceneSession->SetFocusable(true);
171     sceneSession->UpdateVisibilityInner(true);
172     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
173     sceneSession->SetFocusedOnShow(false);
174     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
175     ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
176 
177     sceneSession->SetFocusedOnShow(true);
178     sceneSession->SetFocusableOnShow(false);
179     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
180     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
181     WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::FOREGROUND);
182     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
183 
184     sceneSession->SetFocusableOnShow(false);
185     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
186     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
187     ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
188 
189     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
190     sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
191     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
192     ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
193 
194     sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
195     sceneSession->SetTopmost(true);
196     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
197     ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
198 }
199 
200 /**
201  * @tc.name: RequestSessionUnfocus02
202  * @tc.desc: RequestSessionUnfocus
203  * @tc.type: FUNC
204  */
205 HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest | Level3)
206 {
207     ASSERT_NE(nullptr, ssm_);
208     ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
209 
210     SessionInfo sessionInfo;
211     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
212     sessionInfo.abilityName_ = "RequestSessionUnfocus02";
213     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
214     ASSERT_NE(nullptr, sceneSession);
215     ssm_->focusedSessionId_ = 2;
216     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
217 
218     SessionInfo sessionInfo1;
219     sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
220     ASSERT_NE(nullptr, sceneSession1);
221     sceneSession1->GetSessionProperty()->SetParentPersistentId(3);
222     sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
223     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
224     ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
225 
226     ssm_->lastFocusedSessionId_ = 4;
227     sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
228     ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
229 
230     SessionInfo sessionInfo2;
231     sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
232     ASSERT_NE(nullptr, sceneSession2);
233     sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
234     ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession1));
235     ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
236 
237     sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
238     ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
239 
240     ssm_->focusedSessionId_ = 5;
241     ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
242 }
243 
244 /**
245  * @tc.name: RequestAllAppSessionUnfocusInner
246  * @tc.desc: RequestAllAppSessionUnfocusInner
247  * @tc.type: FUNC
248  */
249 HWTEST_F(SceneSessionManagerTest9, RequestAllAppSessionUnfocusInner, Function | SmallTest | Level3)
250 {
251     ASSERT_NE(nullptr, ssm_);
252     ssm_->RequestAllAppSessionUnfocusInner();
253 
254     SessionInfo sessionInfo;
255     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
256     sessionInfo.abilityName_ = "RequestAllAppSessionUnfocusInner";
257     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
258     ASSERT_NE(nullptr, sceneSession);
259     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
260     ssm_->focusedSessionId_ = 1;
261     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
262     ssm_->RequestAllAppSessionUnfocusInner();
263 
264     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
265     ssm_->RequestAllAppSessionUnfocusInner();
266 }
267 
268 /**
269  * @tc.name: UpdateFocus04
270  * @tc.desc: UpdateFocus
271  * @tc.type: FUNC
272  */
273 HWTEST_F(SceneSessionManagerTest9, UpdateFocus04, Function | SmallTest | Level3)
274 {
275     ASSERT_NE(nullptr, ssm_);
276     SessionInfo sessionInfo;
277     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
278     sessionInfo.abilityName_ = "UpdateFocus04";
279     sessionInfo.isSystem_ = true;
280     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
281     ASSERT_NE(nullptr, sceneSession);
282     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
283     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
284     ssm_->focusedSessionId_ = 0;
285     sceneSession->UpdateFocus(false);
286     ssm_->UpdateFocus(1, false);
287 
288     ssm_->listenerController_ = nullptr;
289     ssm_->UpdateFocus(1, true);
290 
291     std::shared_ptr<SessionListenerController> listenerController = std::make_shared<SessionListenerController>();
292     ssm_->listenerController_ = listenerController;
293     ssm_->UpdateFocus(1, true);
294 
295     sessionInfo.isSystem_ = false;
296     ssm_->focusedSessionId_ = 1;
297     sceneSession->UpdateFocus(true);
298     ssm_->UpdateFocus(1, false);
299 
300     sceneSession->UpdateFocus(false);
301     ssm_->UpdateFocus(1, true);
302 }
303 
304 /**
305  * @tc.name: ProcessFocusWhenForeground
306  * @tc.desc: ProcessFocusWhenForeground
307  * @tc.type: FUNC
308  */
309 HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground, Function | SmallTest | Level3)
310 {
311     ASSERT_NE(nullptr, ssm_);
312     SessionInfo sessionInfo;
313     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
314     sessionInfo.abilityName_ = "ProcessFocusWhenForeground";
315     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
316     ASSERT_NE(nullptr, sceneSession);
317     sceneSession->persistentId_ = 1;
318     ASSERT_NE(nullptr, sceneSession->property_);
319     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
320     ssm_->focusedSessionId_ = 1;
321     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
322     ssm_->ProcessFocusWhenForeground(sceneSession);
323 
324     sceneSession->isVisible_ = true;
325     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
326     ssm_->ProcessFocusWhenForeground(sceneSession);
327 }
328 
329 /**
330  * @tc.name: ProcessSubSessionForeground03
331  * @tc.desc: ProcessSubSessionForeground
332  * @tc.type: FUNC
333  */
334 HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | SmallTest | Level3)
335 {
336     ASSERT_NE(nullptr, ssm_);
337     SessionInfo sessionInfo;
338     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
339     sessionInfo.abilityName_ = "ProcessSubSessionForeground03";
340     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
341     ASSERT_NE(nullptr, sceneSession);
342 
343     SessionInfo subSessionInfo;
344     sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(subSessionInfo, nullptr);
345     ASSERT_NE(nullptr, subSceneSession);
346     subSceneSession->SetTopmost(true);
347     subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
348     subSceneSession->persistentId_ = 1;
349     sceneSession->GetSubSession().push_back(subSceneSession);
350     ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession));
351 
352     ssm_->focusedSessionId_ = 1;
353     ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
354 
355     SessionInfo subSessionInfo1;
356     sptr<SceneSession> subSceneSession1 = sptr<SceneSession>::MakeSptr(subSessionInfo1, nullptr);
357     ASSERT_NE(nullptr, subSceneSession1);
358     subSceneSession1->SetTopmost(true);
359     subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
360     subSceneSession1->persistentId_ = 0;
361     sceneSession->GetSubSession().push_back(subSceneSession1);
362 
363     SessionInfo subSessionInfo2;
364     sptr<SceneSession> subSceneSession2 = sptr<SceneSession>::MakeSptr(subSessionInfo2, nullptr);
365     ASSERT_NE(nullptr, subSceneSession2);
366     subSceneSession2->SetTopmost(true);
367     subSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
368     sceneSession->GetSubSession().push_back(subSceneSession2);
369 
370     SessionInfo subSessionInfo3;
371     sptr<SceneSession> subSceneSession3 = sptr<SceneSession>::MakeSptr(subSessionInfo3, nullptr);
372     ASSERT_NE(nullptr, subSceneSession3);
373     subSceneSession3->SetTopmost(false);
374     subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE);
375     sceneSession->GetSubSession().push_back(subSceneSession3);
376 
377     sceneSession->GetSubSession().push_back(nullptr);
378 
379     ssm_->ProcessSubSessionForeground(sceneSession);
380 
381     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
382     ssm_->ProcessSubSessionForeground(sceneSession);
383 
384     ssm_->focusedSessionId_ = 2;
385     ssm_->ProcessSubSessionForeground(sceneSession);
386 }
387 
388 /**
389  * @tc.name: ProcessFocusWhenForegroundScbCore
390  * @tc.desc: ProcessFocusWhenForegroundScbCore
391  * @tc.type: FUNC
392  */
393 HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForegroundScbCore, Function | SmallTest | Level3)
394 {
395     ASSERT_NE(nullptr, ssm_);
396     ssm_->focusedSessionId_ = 0;
397     SessionInfo sessionInfo;
398     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
399     sessionInfo.abilityName_ = "ProcessFocusWhenForegroundScbCore";
400     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
401     sceneSession->persistentId_ = 1;
402     ASSERT_NE(nullptr, sceneSession->property_);
403     sceneSession->SetFocusableOnShow(false);
404     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
405     ssm_->ProcessFocusWhenForegroundScbCore(sceneSession);
406     ASSERT_EQ(sceneSession->GetPostProcessFocusState().isFocused_, false);
407     ASSERT_EQ(ssm_->focusedSessionId_, 0);
408 
409     sceneSession->SetFocusableOnShow(true);
410     ssm_->ProcessFocusWhenForegroundScbCore(sceneSession); // SetPostProcessFocusState
411     ASSERT_EQ(sceneSession->GetPostProcessFocusState().isFocused_, true);
412 
413     sceneSession->isVisible_ = true;
414     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
415     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
416     ssm_->ProcessFocusWhenForegroundScbCore(sceneSession); // RequestSessionFocus
417     ASSERT_EQ(ssm_->focusedSessionId_, 1);
418 }
419 
420 /**
421  * @tc.name: ProcessModalTopmostRequestFocusImmdediately02
422  * @tc.desc: ProcessModalTopmostRequestFocusImmdediately
423  * @tc.type: FUNC
424  */
425 HWTEST_F(SceneSessionManagerTest9, ProcessModalTopmostRequestFocusImmdediately02, Function | SmallTest | Level3)
426 {
427     ASSERT_NE(nullptr, ssm_);
428     SessionInfo sessionInfo;
429     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
430     sessionInfo.abilityName_ = "ProcessModalTopmostRequestFocusImmdediately02";
431     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
432     ASSERT_NE(nullptr, sceneSession);
433 
434     SessionInfo subSessionInfo;
435     sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(subSessionInfo, nullptr);
436     ASSERT_NE(nullptr, subSceneSession);
437     subSceneSession->SetTopmost(true);
438     subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
439     subSceneSession->persistentId_ = 1;
440     subSceneSession->SetFocusable(true);
441     subSceneSession->SetFocusedOnShow(true);
442     sceneSession->GetSubSession().push_back(subSceneSession);
443 
444     ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession));
445     ssm_->focusedSessionId_ = 1;
446     ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
447 
448     SessionInfo subSessionInfo1;
449     sptr<SceneSession> subSceneSession1 = sptr<SceneSession>::MakeSptr(subSessionInfo1, nullptr);
450     ASSERT_NE(nullptr, subSceneSession1);
451     subSceneSession1->SetTopmost(true);
452     subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
453     subSceneSession1->persistentId_ = 0;
454     sceneSession->GetSubSession().push_back(subSceneSession1);
455 
456     SessionInfo subSessionInfo2;
457     sptr<SceneSession> subSceneSession2 = sptr<SceneSession>::MakeSptr(subSessionInfo2, nullptr);
458     ASSERT_NE(nullptr, subSceneSession2);
459     subSceneSession2->SetTopmost(true);
460     subSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
461     sceneSession->GetSubSession().push_back(subSceneSession2);
462 
463     SessionInfo subSessionInfo3;
464     sptr<SceneSession> subSceneSession3 = sptr<SceneSession>::MakeSptr(subSessionInfo3, nullptr);
465     ASSERT_NE(nullptr, subSceneSession3);
466     subSceneSession3->SetTopmost(false);
467     subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE);
468     sceneSession->GetSubSession().push_back(subSceneSession3);
469 
470     sceneSession->GetSubSession().push_back(nullptr);
471 
472     ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
473 
474     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
475     ssm_->ProcessSubSessionForeground(sceneSession);
476 
477     subSceneSession->persistentId_ = 0;
478     ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
479 }
480 
481 /**
482  * @tc.name: ProcessDialogRequestFocusImmdediately02
483  * @tc.desc: ProcessDialogRequestFocusImmdediately
484  * @tc.type: FUNC
485  */
486 HWTEST_F(SceneSessionManagerTest9, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)
487 {
488     ASSERT_NE(nullptr, ssm_);
489     SessionInfo sessionInfo;
490     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
491     sessionInfo.abilityName_ = "ProcessDialogRequestFocusImmdediately02";
492     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
493     ASSERT_NE(nullptr, sceneSession);
494     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
495 
496     SessionInfo dialogSessionInfo;
497     sptr<SceneSession> dialogSceneSession = sptr<SceneSession>::MakeSptr(dialogSessionInfo, nullptr);
498     ASSERT_NE(nullptr, dialogSceneSession);
499     dialogSceneSession->SetTopmost(true);
500     dialogSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
501     dialogSceneSession->persistentId_ = 1;
502     dialogSceneSession->SetFocusable(true);
503     dialogSceneSession->SetFocusedOnShow(true);
504     sceneSession->GetDialogVector().push_back(dialogSceneSession);
505 
506     ssm_->sceneSessionMap_.insert(std::make_pair(1, dialogSceneSession));
507     ssm_->focusedSessionId_ = 1;
508     ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
509 
510     SessionInfo dialogSessionInfo1;
511     sptr<SceneSession> dialogSceneSession1 = sptr<SceneSession>::MakeSptr(dialogSessionInfo1, nullptr);
512     ASSERT_NE(nullptr, dialogSceneSession1);
513     dialogSceneSession1->SetTopmost(true);
514     dialogSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
515     dialogSceneSession1->persistentId_ = 0;
516     sceneSession->GetDialogVector().push_back(dialogSceneSession1);
517 
518     SessionInfo dialogSessionInfo2;
519     sptr<SceneSession> dialogSceneSession2 = sptr<SceneSession>::MakeSptr(dialogSessionInfo2, nullptr);
520     ASSERT_NE(nullptr, dialogSceneSession2);
521     dialogSceneSession2->SetTopmost(true);
522     dialogSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
523     sceneSession->GetDialogVector().push_back(dialogSceneSession2);
524 
525     sceneSession->GetDialogVector().push_back(nullptr);
526 
527     ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
528 
529     dialogSceneSession->persistentId_ = 0;
530     ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
531 }
532 
533 /**
534  * @tc.name: NotifyCompleteFirstFrameDrawing03
535  * @tc.desc: NotifyCompleteFirstFrameDrawing
536  * @tc.type: FUNC
537  */
538 HWTEST_F(SceneSessionManagerTest9, NotifyCompleteFirstFrameDrawing03, Function | SmallTest | Level3)
539 {
540     ASSERT_NE(nullptr, ssm_);
541     SessionInfo sessionInfo;
542     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
543     sessionInfo.abilityName_ = "NotifyCompleteFirstFrameDrawing03";
544     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
545     abilityInfo->excludeFromMissions = true;
546     sessionInfo.abilityInfo = abilityInfo;
547     sessionInfo.isSystem_ = true;
548     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
549     ASSERT_NE(nullptr, sceneSession);
550     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
551     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
552     ssm_->listenerController_ = nullptr;
553     ssm_->NotifyCompleteFirstFrameDrawing(1);
554 
555     std::shared_ptr<SessionListenerController> listenerController = std::make_shared<SessionListenerController>();
556     ssm_->listenerController_ = listenerController;
557     sessionInfo.isSystem_ = false;
558     ssm_->eventHandler_ = nullptr;
559     ssm_->NotifyCompleteFirstFrameDrawing(1);
560 
561     std::shared_ptr<AppExecFwk::EventHandler> eventHandler = std::make_shared<AppExecFwk::EventHandler>();
562     ssm_->eventHandler_ = eventHandler;
563     abilityInfo->excludeFromMissions = false;
564     ssm_->NotifyCompleteFirstFrameDrawing(1);
565 }
566 
567 /**
568  * @tc.name: SetSessionLabel02
569  * @tc.desc: SetSessionLabel
570  * @tc.type: FUNC
571  */
572 HWTEST_F(SceneSessionManagerTest9, SetSessionLabel02, Function | SmallTest | Level3)
573 {
574     ASSERT_NE(nullptr, ssm_);
575     SessionInfo sessionInfo;
576     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
577     sessionInfo.abilityName_ = "SetSessionLabel02";
578     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
579     ASSERT_NE(nullptr, sceneSession);
580     sptr<IRemoteObject> token = new (std::nothrow) MockIRemoteObject();
581     ASSERT_NE(nullptr, token);
582     sceneSession->SetAbilityToken(token);
583     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
584     ssm_->listenerController_ = nullptr;
585 
586     std::string label = "testLabel";
587     ssm_->SetSessionLabel(token, label);
588 
589     std::shared_ptr<SessionListenerController> listenerController = std::make_shared<SessionListenerController>();
590     ssm_->listenerController_ = listenerController;
591     sessionInfo.isSystem_ = false;
592     ssm_->SetSessionLabel(token, label);
593 
594     sessionInfo.isSystem_ = true;
595     ssm_->SetSessionLabel(token, label);
596 }
597 
598 /**
599  * @tc.name: RecoverAndReconnectSceneSession02
600  * @tc.desc: RecoverAndReconnectSceneSession
601  * @tc.type: FUNC
602  */
603 HWTEST_F(SceneSessionManagerTest9, RecoverAndReconnectSceneSession02, Function | SmallTest | Level3)
604 {
605     ASSERT_NE(nullptr, ssm_);
606     SessionInfo sessionInfo;
607     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
608     sessionInfo.abilityName_ = "RecoverAndReconnectSceneSession02";
609     sessionInfo.moduleName_ = "moduleTest";
610     sessionInfo.appIndex_ = 10;
611     sessionInfo.persistentId_ = 1;
612     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
613     abilityInfo->excludeFromMissions = true;
614     sessionInfo.abilityInfo = abilityInfo;
615     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
616     ASSERT_NE(nullptr, sceneSession);
617 
618     sptr<WindowSessionProperty> property = sceneSession->GetSessionProperty();
619     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
620     property->SetPersistentId(1);
621     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
622     property->SetWindowState(WindowState::STATE_SHOWN);
623     property->SetRequestedOrientation(Orientation::UNSPECIFIED);
624     ssm_->alivePersistentIds_.push_back(1);
625     ssm_->recoveringFinished_ = false;
626     ssm_->recoverSceneSessionFunc_ = NotifyRecoverSceneSessionFuncTest;
627 
628     sptr<ISession> session;
629     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
630     ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr);
631 
632     property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
633     property->SetPersistentId(0);
634     ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr);
635 }
636 
637 /**
638  * @tc.name: GetSessionRSVisible
639  * @tc.desc: GetSessionRSVisible
640  * @tc.type: FUNC
641  */
642 HWTEST_F(SceneSessionManagerTest9, GetSessionRSVisible, Function | SmallTest | Level3)
643 {
644     ASSERT_NE(nullptr, ssm_);
645     SessionInfo sessionInfo;
646     sessionInfo.bundleName_ = "SceneSessionManagerTest9";
647     sessionInfo.abilityName_ = "GetSessionRSVisible";
648     sessionInfo.moduleName_ = "moduleTest";
649     uint64_t windowId = 10;
650     sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
651     sceneSession01->persistentId_ = windowId;
652     sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
653     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
654     currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
655     currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
656     struct RSSurfaceNodeConfig config;
657     sceneSession02->surfaceNode_ = RSSurfaceNode::Create(config);
658     ASSERT_NE(nullptr, sceneSession02->surfaceNode_);
659     sceneSession02->surfaceNode_->id_ = 0;
660     sceneSession02->persistentId_ = windowId;
661     ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession02));
662 
663     bool actual = ssm_->GetSessionRSVisible(sceneSession01, currVisibleData);
664     EXPECT_EQ(actual, true);
665 }
666 }
667 } // namespace Rosen
668 } // namespace OHOS