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 <bundle_mgr_interface.h>
18 #include <bundlemgr/launcher_service.h>
19 #include "interfaces/include/ws_common.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/host/include/main_session.h"
24 #include "screen_session_manager/include/screen_session_manager_client.h"
25 #include "window_manager_agent.h"
26 #include "session_manager.h"
27 #include "zidl/window_manager_agent_interface.h"
28 #include "mock/mock_session_stage.h"
29 #include "mock/mock_window_event_channel.h"
30 #include "context.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 
35 namespace OHOS {
36 namespace Rosen {
37 class SceneSessionManagerSupplementTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43 
44     static sptr<SceneSessionManager> ssm_;
45     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
46 };
47 
48 sptr<SceneSessionManager> SceneSessionManagerSupplementTest::ssm_ = nullptr;
49 
SetUpTestCase()50 void SceneSessionManagerSupplementTest::SetUpTestCase()
51 {
52     ssm_ = &SceneSessionManager::GetInstance();
53 }
54 
TearDownTestCase()55 void SceneSessionManagerSupplementTest::TearDownTestCase()
56 {
57     ssm_ = nullptr;
58 }
59 
SetUp()60 void SceneSessionManagerSupplementTest::SetUp()
61 {
62     ssm_->sceneSessionMap_.clear();
63 }
64 
TearDown()65 void SceneSessionManagerSupplementTest::TearDown()
66 {
67     ssm_->sceneSessionMap_.clear();
68     usleep(WAIT_SYNC_IN_NS);
69 }
70 
71 namespace {
72 /**
73  * @tc.name: LoadFreeMultiWindowConfig
74  * @tc.desc: SceneSessionManagerSupplementTest LoadFreeMultiWindowConfig
75  * @tc.type: FUNC
76  */
77 HWTEST_F(SceneSessionManagerSupplementTest, LoadFreeMultiWindowConfig, Function | SmallTest | Level3)
78 {
79     ssm_->LoadFreeMultiWindowConfig(true);
80     ssm_->LoadFreeMultiWindowConfig(false);
81     auto config = ssm_->GetSystemSessionConfig();
82     config.freeMultiWindowSupport_ = false;
83     ssm_->SwitchFreeMultiWindow(true);
84     config.freeMultiWindowSupport_ = true;
85     ssm_->SwitchFreeMultiWindow(true);
86     sptr<SceneSession> sceneSession;
87     ssm_->sceneSessionMap_.insert({1, sceneSession});
88     ssm_->SwitchFreeMultiWindow(true);
89     SessionInfo sessionInfo;
90     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
91     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
92     sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
93     ssm_->SwitchFreeMultiWindow(true);
94     sptr<WindowSessionProperty> property = new WindowSessionProperty();
95     property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
96     sceneSession->SetSessionProperty(property);
97     ssm_->SwitchFreeMultiWindow(true);
98     ssm_->SwitchFreeMultiWindow(false);
99     ssm_->SetEnableInputEvent(true);
100     ASSERT_EQ(ssm_->IsInputEventEnabled(), true);
101 }
102 
103 /**
104  * @tc.name: RequestSceneSessionActivationInner
105  * @tc.desc: SceneSessionManagerSupplementTest RequestSceneSessionActivationInner
106  * @tc.type: FUNC
107  */
108 HWTEST_F(SceneSessionManagerSupplementTest, RequestSceneSessionActivationInner,
109     Function | SmallTest | Level3)
110 {
111     int res = 0;
112     SessionInfo sessionInfo;
113     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
114     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
115     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
116     sptr<WindowSessionProperty> property = new WindowSessionProperty();
117     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
118     sceneSession->SetSessionProperty(property);
119     sceneSession->SetCollaboratorType(0);
120     ssm_->RequestSceneSessionActivationInner(sceneSession, true);
121     ssm_->RequestSceneSessionActivationInner(sceneSession, false);
122     sceneSession->SetCollaboratorType(1);
123     ssm_->systemConfig_.backgroundswitch = false;
124     sceneSession->SetSessionState(SessionState::STATE_DISCONNECT);
125     ssm_->RequestSceneSessionActivationInner(sceneSession, true);
126     ssm_->RequestSceneSessionActivationInner(sceneSession, false);
127     ssm_->systemConfig_.backgroundswitch = true;
128     sceneSession->SetSessionState(SessionState::STATE_DISCONNECT);
129     ssm_->RequestSceneSessionActivationInner(sceneSession, true);
130     ssm_->RequestSceneSessionActivationInner(sceneSession, false);
131     sceneSession->SetSessionState(SessionState::STATE_END);
132     ssm_->RequestSceneSessionActivationInner(sceneSession, true);
133     ssm_->RequestSceneSessionActivationInner(sceneSession, false);
134     ASSERT_EQ(res, 0);
135 }
136 
137 /**
138  * @tc.name: NotifyCollaboratorAfterStart
139  * @tc.desc: SceneSessionManagerSupplementTest NotifyCollaboratorAfterStart
140  * @tc.type: FUNC
141  */
142 HWTEST_F(SceneSessionManagerSupplementTest, NotifyCollaboratorAfterStart,
143     Function | SmallTest | Level3)
144 {
145     int res = 0;
146     sptr<SceneSession> sceneSession;
147     sptr<AAFwk::SessionInfo> scnSessionInfo;
148     ssm_->NotifyCollaboratorAfterStart(sceneSession, scnSessionInfo);
149     SessionInfo info;
150     info.bundleName_ = "test1";
151     info.abilityName_ = "test2";
152     ssm_->RequestSceneSessionBackground(sceneSession, true, true);
153     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
154     ssm_->NotifyCollaboratorAfterStart(sceneSession, scnSessionInfo);
155     scnSessionInfo = new AAFwk::SessionInfo();
156     ssm_->NotifyCollaboratorAfterStart(sceneSession, scnSessionInfo);
157     ssm_->NotifyCollaboratorAfterStart(sceneSession, scnSessionInfo);
158     ssm_->RequestSceneSessionBackground(sceneSession, true, true);
159     ssm_->RequestSceneSessionBackground(sceneSession, true, false);
160     ssm_->brightnessSessionId_ = sceneSession->GetPersistentId();
161     ssm_->RequestSceneSessionBackground(sceneSession, false, true);
162     ssm_->RequestSceneSessionBackground(sceneSession, false, false);
163     ssm_->brightnessSessionId_ = 0;
164     ssm_->systemConfig_.backgroundswitch  = true;
165     ssm_->RequestSceneSessionBackground(sceneSession, true, true);
166     ssm_->RequestSceneSessionBackground(sceneSession, true, false);
167     sptr<WindowSessionProperty> property = new WindowSessionProperty();
168     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
169     sceneSession->SetSessionProperty(property);
170     ssm_->RequestSceneSessionBackground(sceneSession, false, true);
171     ssm_->RequestSceneSessionBackground(sceneSession, false, false);
172     ssm_->NotifyForegroundInteractiveStatus(sceneSession, true);
173     ssm_->NotifyForegroundInteractiveStatus(sceneSession, false);
174     ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
175     ssm_->NotifyForegroundInteractiveStatus(sceneSession, true);
176     ASSERT_EQ(res, 0);
177 }
178 
179 /**
180  * @tc.name: DestroyDialogWithMainWindow
181  * @tc.desc: SceneSessionManagerSupplementTest DestroyDialogWithMainWindow
182  * @tc.type: FUNC
183  */
184 HWTEST_F(SceneSessionManagerSupplementTest, DestroyDialogWithMainWindow,
185     Function | SmallTest | Level3)
186 {
187     int res = 0;
188     SessionInfo info;
189     info.bundleName_ = "test1";
190     info.abilityName_ = "test2";
191     sptr<SceneSession> sceneSession;
192     ssm_->DestroyDialogWithMainWindow(sceneSession);
193     ssm_->DestroySubSession(sceneSession);
194     ssm_->RequestSceneSessionDestruction(sceneSession, true);
195     ssm_->RequestSceneSessionDestruction(sceneSession, false);
196     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
197     sptr<WindowSessionProperty> property = new WindowSessionProperty();
198     property->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT);
199     sceneSession->SetSessionProperty(property);
200     ssm_->DestroyDialogWithMainWindow(sceneSession);
201     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
202     sptr<SceneSession> sceneSession2;
203     sceneSession->dialogVec_.push_back(sceneSession2);
204     sceneSession->subSession_.push_back(sceneSession2);
205     ssm_->DestroyDialogWithMainWindow(sceneSession);
206     ssm_->DestroySubSession(sceneSession);
207     sceneSession2 = new (std::nothrow) SceneSession(info, nullptr);
208     ssm_->DestroyDialogWithMainWindow(sceneSession);
209     ssm_->DestroySubSession(sceneSession);
210     ssm_->RequestSceneSessionDestruction(sceneSession, true);
211     ssm_->RequestSceneSessionDestruction(sceneSession, false);
212     ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
213     ssm_->DestroyDialogWithMainWindow(sceneSession);
214     ssm_->EraseSceneSessionMapById(sceneSession2->GetPersistentId());
215     ssm_->RequestSceneSessionDestruction(sceneSession2, true);
216     ssm_->RequestSceneSessionDestruction(sceneSession2, false);
217     ASSERT_EQ(res, 0);
218 }
219 
220 /**
221  * @tc.name: CreateAndConnectSpecificSession
222  * @tc.desc: CreateAndConnectSpecificSession
223  * @tc.type: FUNC
224 */
225 HWTEST_F(SceneSessionManagerSupplementTest, CreateAndConnectSpecificSession, Function | SmallTest | Level3)
226 {
227     int ret = 0;
228     sptr<ISessionStage> sessionStage;
229     sptr<IWindowEventChannel> eventChannel;
230     std::shared_ptr<RSSurfaceNode> node = nullptr;
231     sptr<WindowSessionProperty> property;
232     sptr<ISession> session;
233     SystemSessionConfig systemConfig;
234     sptr<IRemoteObject> token;
235     int32_t id = 0;
236     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
237         systemConfig, token);
238     property = new WindowSessionProperty();
239     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
240         systemConfig, token);
241     property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
242     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
243         systemConfig, token);
244     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
245     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
246         systemConfig, token);
247     property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
248     property->SetFloatingWindowAppType(true);
249     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
250         systemConfig, token);
251     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
252     property->SetExtensionFlag(true);
253     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
254         systemConfig, token);
255     property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
256     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
257         systemConfig, token);
258     property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
259     ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
260         systemConfig, token);
261     ASSERT_EQ(ret, 0);
262 }
263 
264 /**
265  * @tc.name: ClosePipWindowIfExist
266  * @tc.desc: ClosePipWindowIfExist
267  * @tc.type: FUNC
268 */
269 HWTEST_F(SceneSessionManagerSupplementTest, ClosePipWindowIfExist, Function | SmallTest | Level3)
270 {
271     int ret = 0;
272     ssm_->ClosePipWindowIfExist(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
273     ssm_->ClosePipWindowIfExist(WindowType::WINDOW_TYPE_PIP);
274     SessionInfo info;
275     info.bundleName_ = "test1";
276     info.abilityName_ = "test2";
277     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
278     sptr<WindowSessionProperty> property = new WindowSessionProperty();
279     property->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT);
280     sceneSession->SetSessionProperty(property);
281     PiPTemplateInfo pipInfo;
282     pipInfo.priority = 0;
283     ssm_->CheckPiPPriority(pipInfo);
284     ssm_->sceneSessionMap_.insert({0, sceneSession});
285     ssm_->ClosePipWindowIfExist(WindowType::WINDOW_TYPE_PIP);
286     ssm_->CheckPiPPriority(pipInfo);
287     property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
288     PiPTemplateInfo pipInfo1;
289     pipInfo1.priority = 0;
290     sceneSession->SetPiPTemplateInfo(pipInfo1);
291     ssm_->CheckPiPPriority(pipInfo);
292     sceneSession->isVisible_ = true;
293     ssm_->CheckPiPPriority(pipInfo);
294     ASSERT_EQ(ret, 0);
295 }
296 
297 /**
298  * @tc.name: CheckSystemWindowPermission
299  * @tc.desc: CheckSystemWindowPermission
300  * @tc.type: FUNC
301 */
302 HWTEST_F(SceneSessionManagerSupplementTest, CheckSystemWindowPermission, Function | SmallTest | Level3)
303 {
304     int ret = 0;
305     sptr<WindowSessionProperty> property = new WindowSessionProperty();
306     property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
307     ssm_->CheckSystemWindowPermission(property);
308     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
309     ssm_->CheckSystemWindowPermission(property);
310     property->SetWindowType(WindowType::WINDOW_TYPE_DRAGGING_EFFECT);
311     ssm_->CheckSystemWindowPermission(property);
312     property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
313     ssm_->CheckSystemWindowPermission(property);
314     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
315     ssm_->CheckSystemWindowPermission(property);
316     property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
317     ssm_->CheckSystemWindowPermission(property);
318     property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
319     ssm_->CheckSystemWindowPermission(property);
320     std::vector<int32_t> alivePersistentIds;
321     ssm_->SetAlivePersistentIds(alivePersistentIds);
322     ssm_->IsNeedRecover(1);
323     alivePersistentIds.push_back(1);
324     ssm_->SetAlivePersistentIds(alivePersistentIds);
325     ssm_->IsNeedRecover(1);
326     ASSERT_EQ(ret, 0);
327 }
328 
329 /**
330  * @tc.name: RecoverAndConnectSpecificSession
331  * @tc.desc: RecoverAndConnectSpecificSession
332  * @tc.type: FUNC
333 */
334 HWTEST_F(SceneSessionManagerSupplementTest, RecoverAndConnectSpecificSession, Function | SmallTest | Level3)
335 {
336     sptr<ISessionStage> sessionStage;
337     sptr<IWindowEventChannel> eventChannel;
338     std::shared_ptr<RSSurfaceNode> node = nullptr;
339     sptr<WindowSessionProperty> property;
340     sptr<ISession> session;
341     sptr<IRemoteObject> token;
342     auto ret = ssm_->RecoverAndConnectSpecificSession(sessionStage, eventChannel, node, property, session, token);
343     ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
344     property = new WindowSessionProperty();
345     ret = ssm_->RecoverAndConnectSpecificSession(sessionStage, eventChannel, node, property, session, token);
346     ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
347     ssm_->NotifyRecoveringFinished();
348     usleep(WAIT_SYNC_IN_NS);
349     ASSERT_EQ(ssm_->recoveringFinished_, true);
350 }
351 
352 /**
353  * @tc.name: CacheSubSessionForRecovering
354  * @tc.desc: CacheSubSessionForRecovering
355  * @tc.type: FUNC
356 */
357 HWTEST_F(SceneSessionManagerSupplementTest, CacheSubSessionForRecovering, Function | SmallTest | Level3)
358 {
359     sptr<SceneSession> sceneSession;
360     SessionInfo info;
361     info.bundleName_ = "test1";
362     info.abilityName_ = "test2";
363     sptr<WindowSessionProperty> property;
364     ssm_->recoveringFinished_ = false;
365     ssm_->CacheSubSessionForRecovering(sceneSession, property);
366     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
367     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
368     ssm_->CacheSubSessionForRecovering(sceneSession, property);
369     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
370     property = new WindowSessionProperty();
371     ssm_->CacheSubSessionForRecovering(sceneSession, property);
372     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
373     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
374     ssm_->CacheSubSessionForRecovering(sceneSession, property);
375     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
376     property->SetWindowType(WindowType::APP_SUB_WINDOW_END);
377     ssm_->CacheSubSessionForRecovering(sceneSession, property);
378     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
379     property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
380     property->SetParentPersistentId(1);
381     NotifyCreateSubSessionFunc func;
382     ssm_->createSubSessionFuncMap_.insert({1, func});
383     ssm_->CacheSubSessionForRecovering(sceneSession, property);
384     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
385     ssm_->createSubSessionFuncMap_.clear();
386     ssm_->CacheSubSessionForRecovering(sceneSession, property);
387     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 1);
388     ssm_->RecoverCachedSubSession(1);
389     ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
390     std::vector<sptr<SceneSession>> sessions;
391     sessions.push_back(sceneSession);
392     ssm_->recoverSubSessionCacheMap_.insert({1, sessions});
393     ssm_->RecoverCachedSubSession(1);
394     ssm_->recoverSubSessionCacheMap_.clear();
395     ssm_->NotifySessionUnfocusedToClient(1);
396     std::shared_ptr<SessionListenerController> listener = std::make_shared<SessionListenerController>();
397     ssm_->listenerController_ = listener;
398     ssm_->NotifySessionUnfocusedToClient(1);
399     ssm_->listenerController_ = nullptr;
400 }
401 
402 /**
403  * @tc.name: RecoverAndReconnectSceneSession
404  * @tc.desc: RecoverAndReconnectSceneSession
405  * @tc.type: FUNC
406 */
407 HWTEST_F(SceneSessionManagerSupplementTest, RecoverAndReconnectSceneSession, Function | SmallTest | Level3)
408 {
409     int ret = 0;
410     sptr<ISessionStage> sessionStage;
411     sptr<IWindowEventChannel> eventChannel;
412     std::shared_ptr<RSSurfaceNode> node = nullptr;
413     sptr<WindowSessionProperty> property;
414     sptr<ISession> session;
415     sptr<IRemoteObject> token;
416     ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
417     property = new WindowSessionProperty();
418     property->SetPersistentId(1);
419     ssm_->alivePersistentIds_.push_back(1);
420     ssm_->recoveringFinished_ = true;
421     ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
422     ssm_->recoveringFinished_ = false;
423     ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
424     property->SetWindowType(WindowType::APP_SUB_WINDOW_END);
425     ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
426     NotifyRecoverSceneSessionFunc func;
427     ssm_->SetRecoverSceneSessionListener(func);
428     ssm_->alivePersistentIds_.clear();
429     NotifyCreateSubSessionFunc func2;
430     ssm_->RegisterCreateSubSessionListener(1, func2);
431     ssm_->createSubSessionFuncMap_.insert({ 1, func2 });
432     ssm_->RegisterCreateSubSessionListener(1, func2);
433     ssm_->createSubSessionFuncMap_.clear();
434     ASSERT_EQ(ret, 0);
435 }
436 
437 /**
438  * @tc.name: NotifyCreateSpecificSession
439  * @tc.desc: NotifyCreateSpecificSession
440  * @tc.type: FUNC
441 */
442 HWTEST_F(SceneSessionManagerSupplementTest, NotifyCreateSpecificSession, Function | SmallTest | Level3)
443 {
444     int ret = 0;
445     sptr<SceneSession> sceneSession;
446     sptr<WindowSessionProperty> property;
447     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_MAIN_WINDOW_BASE);
448     SessionInfo info;
449     info.bundleName_ = "test1";
450     info.abilityName_ = "test2";
451     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
452     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_MAIN_WINDOW_BASE);
453     property = new WindowSessionProperty();
454     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_MAIN_WINDOW_BASE);
455     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::SYSTEM_SUB_WINDOW_BASE);
456     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_SUB_WINDOW_BASE);
457     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_SCENE_BOARD);
458     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_TOAST);
459     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_FLOAT);
460     property->SetParentPersistentId(1);
461     SessionInfo info1;
462     info1.bundleName_ = "test3";
463     info1.abilityName_ = "test3";
464     sptr<SceneSession> sceneSession2 = new (std::nothrow) SceneSession(info1, nullptr);
465     ssm_->sceneSessionMap_.insert({1, sceneSession2});
466     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_FLOAT);
467     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_DIALOG);
468     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
469     ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::BELOW_APP_SYSTEM_WINDOW_BASE);
470     ASSERT_EQ(ret, 0);
471 }
472 
473 /**
474  * @tc.name: NotifyCreateSubSession
475  * @tc.desc: NotifyCreateSubSession
476  * @tc.type: FUNC
477 */
478 HWTEST_F(SceneSessionManagerSupplementTest, NotifyCreateSubSession, Function | SmallTest | Level3)
479 {
480     int ret = 0;
481     sptr<SceneSession> sceneSession;
482     ssm_->NotifyCreateSubSession(1, sceneSession);
483     SessionInfo info;
484     info.bundleName_ = "test1";
485     info.abilityName_ = "test2";
486     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
487     ssm_->NotifyCreateSubSession(1, sceneSession);
488     ssm_->UnregisterCreateSubSessionListener(1);
489     SessionInfo info1;
490     info1.bundleName_ = "test1";
491     info1.abilityName_ = "test2";
492     sptr<SceneSession> sceneSession1 = new (std::nothrow) SceneSession(info1, nullptr);
493     NotifyCreateSubSessionFunc func;
494     ssm_->createSubSessionFuncMap_.insert({1, func});
495     ssm_->NotifyCreateSubSession(1, sceneSession);
496     ssm_->UnregisterCreateSubSessionListener(1);
497     ssm_->createSubSessionFuncMap_.clear();
498     sptr<WindowSessionProperty> property = new WindowSessionProperty();
499     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
500     sceneSession->SetSessionProperty(property);
501     ssm_->sceneSessionMap_.insert({1, sceneSession});
502     ssm_->NotifySessionTouchOutside(1);
503     sceneSession->state_ = SessionState::STATE_FOREGROUND;
504     ssm_->NotifySessionTouchOutside(1);
505     sceneSession->persistentId_ = property->callingSessionId_;
506     ssm_->NotifySessionTouchOutside(1);
507     sceneSession->persistentId_ = property->callingSessionId_ + 1;
508     ssm_->NotifySessionTouchOutside(1);
509     ASSERT_EQ(ret, 0);
510     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
511     usleep(WAIT_SYNC_IN_NS);
512 }
513 
514 /**
515  * @tc.name: DestroyAndDisconnectSpecificSessionInner
516  * @tc.desc: DestroyAndDisconnectSpecificSessionInner
517  * @tc.type: FUNC
518 */
519 HWTEST_F(SceneSessionManagerSupplementTest, DestroyAndDisconnectSpecificSessionInner, Function | SmallTest | Level3)
520 {
521     int ret = 0;
522     ssm_->DestroyAndDisconnectSpecificSessionInner(1);
523     SessionInfo info;
524     info.bundleName_ = "test1";
525     info.abilityName_ = "test2";
526     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
527     uint32_t uid = 0;
528     ssm_->GetTopWindowId(1, uid);
529     ssm_->sceneSessionMap_.insert({1, sceneSession});
530     ssm_->GetTopWindowId(1, uid);
531     ssm_->DestroyAndDisconnectSpecificSessionInner(1);
532     sptr<WindowSessionProperty> property = new WindowSessionProperty();
533     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
534     sceneSession->SetSessionProperty(property);
535     ssm_->DestroyAndDisconnectSpecificSessionInner(1);
536     property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
537     ssm_->DestroyAndDisconnectSpecificSessionInner(1);
538     ASSERT_EQ(ret, 0);
539 }
540 
541 /**
542  * @tc.name: GetFocusWindowInfo
543  * @tc.desc: GetFocusWindowInfo
544  * @tc.type: FUNC
545 */
546 HWTEST_F(SceneSessionManagerSupplementTest, GetFocusWindowInfo, Function | SmallTest | Level3)
547 {
548     int ret = 0;
549     sptr<WindowSessionProperty> property;
550     sptr<SceneSession> sceneSession;
551     ssm_->NotifySessionForCallback(sceneSession, true);
552     SessionInfo info;
553     info.bundleName_ = "test1";
554     info.abilityName_ = "test2";
555     info.isSystem_ = true;
556     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
557     ssm_->NotifySessionForCallback(sceneSession, true);
558     info.isSystem_ = false;
559     ssm_->NotifySessionForCallback(sceneSession, true);
560     property = new WindowSessionProperty();
561     property->SetBrightness(1.f);
562     ssm_->SetBrightness(sceneSession, 1.f);
563     ssm_->SetBrightness(sceneSession, 2.f);
564     ssm_->displayBrightness_ = 2.f;
565     ssm_->SetBrightness(sceneSession, 2.f);
566     ssm_->displayBrightness_ = 3.f;
567     ssm_->SetBrightness(sceneSession, 2.f);
568     ssm_->sceneSessionMap_.insert({1, sceneSession});
569     ssm_->UpdateBrightness(1);
570     property->SetBrightness(-1.f);
571     ssm_->UpdateBrightness(1);
572     property->SetBrightness(3.f);
573     ssm_->UpdateBrightness(1);
574     FocusChangeInfo changeInfo;
575     ssm_->GetFocusWindowInfo(changeInfo);
576     ASSERT_EQ(ret, 0);
577 }
578 
579 /**
580  * @tc.name: NotifySessionForCallback
581  * @tc.desc: NotifySessionForCallback
582  * @tc.type: FUNC
583 */
584 HWTEST_F(SceneSessionManagerSupplementTest, NotifySessionForCallback, Function | SmallTest | Level3)
585 {
586     int ret = 0;
587     SessionInfo info;
588     info.bundleName_ = "test1";
589     info.abilityName_ = "test2";
590     info.isSystem_ = true;
591     std::shared_ptr<SessionListenerController> listener = std::make_shared<SessionListenerController>();
592     ssm_->listenerController_ = listener;
593     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
594     ssm_->NotifySessionForCallback(sceneSession, true);
595     info.isSystem_ = false;
596     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
597     ssm_->NotifySessionForCallback(sceneSession, true);
598     ssm_->NotifySessionForCallback(sceneSession, true);
599     ssm_->NotifySessionForCallback(sceneSession, false);
600     info.appIndex_ = 1;
601     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
602     ssm_->NotifySessionForCallback(sceneSession, true);
603     ssm_->NotifySessionForCallback(sceneSession, false);
604     info.appIndex_ = 0;
605     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
606     ssm_->NotifySessionForCallback(sceneSession, true);
607     ssm_->NotifySessionForCallback(sceneSession, false);
608     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
609     info.abilityInfo = abilityInfo;
610     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
611     ssm_->NotifySessionForCallback(sceneSession, true);
612     ssm_->NotifySessionForCallback(sceneSession, false);
613     ssm_->NotifyWindowInfoChangeFromSession(1);
614     ssm_->sceneSessionMap_.insert({1, sceneSession});
615     ssm_->NotifyWindowInfoChangeFromSession(1);
616     ASSERT_EQ(ret, 0);
617 }
618 
619 /**
620  * @tc.name: IsSessionVisible
621  * @tc.desc: IsSessionVisible
622  * @tc.type: FUNC
623 */
624 HWTEST_F(SceneSessionManagerSupplementTest, IsSessionVisible, Function | SmallTest | Level3)
625 {
626     int ret = 0;
627     SessionInfo info;
628     info.bundleName_ = "test1";
629     sptr<SceneSession> sceneSession;
630     ssm_->IsSessionVisible(sceneSession);
631     sceneSession = new (std::nothrow) SceneSession(info, nullptr);
632     sptr<WindowSessionProperty> property = new WindowSessionProperty();
633     sceneSession->SetSessionProperty(property);
634     property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
635     ssm_->IsSessionVisible(sceneSession);
636     property->SetParentPersistentId(1);
637     SessionInfo info1;
638     info1.bundleName_ = "test3";
639     sptr<SceneSession> sceneSession1 = new (std::nothrow) SceneSession(info1, nullptr);
640     ssm_->sceneSessionMap_.insert({1, sceneSession1});
641     ssm_->IsSessionVisible(sceneSession);
642     sceneSession->isVisible_ = true;
643     ssm_->IsSessionVisible(sceneSession);
644     sceneSession->isVisible_ = false;
645     sceneSession->state_ = SessionState::STATE_ACTIVE;
646     ssm_->IsSessionVisible(sceneSession);
647     sceneSession1->state_ = SessionState::STATE_ACTIVE;
648     ssm_->IsSessionVisible(sceneSession);
649     sceneSession->state_ = SessionState::STATE_FOREGROUND;
650     ssm_->IsSessionVisible(sceneSession);
651     sceneSession1->state_ = SessionState::STATE_FOREGROUND;
652     ssm_->IsSessionVisible(sceneSession);
653     sceneSession1->state_ = SessionState::STATE_INACTIVE;
654     ssm_->IsSessionVisible(sceneSession);
655     sceneSession->state_ = SessionState::STATE_INACTIVE;
656     ssm_->IsSessionVisible(sceneSession);
657     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
658     ssm_->IsSessionVisible(sceneSession);
659     sceneSession->isVisible_ = true;
660     ssm_->IsSessionVisible(sceneSession);
661     sceneSession->isVisible_ = false;
662     sceneSession->state_ = SessionState::STATE_ACTIVE;
663     ssm_->IsSessionVisible(sceneSession);
664     sceneSession->state_ = SessionState::STATE_FOREGROUND;
665     ssm_->IsSessionVisible(sceneSession);
666     sceneSession->state_ = SessionState::STATE_INACTIVE;
667     ssm_->IsSessionVisible(sceneSession);
668     ASSERT_EQ(ret, 0);
669 }
670 
671 }
672 } // namespace Rosen
673 } // namespace OHOS