• 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 <bundlemgr/launcher_service.h>
19 #include "interfaces/include/ws_common.h"
20 #include "iremote_object_mocker.h"
21 #include "mock/mock_accesstoken_kit.h"
22 #include "session_manager/include/scene_session_manager.h"
23 #include "session_info.h"
24 #include "session/host/include/scene_session.h"
25 #include "session_manager.h"
26 #include "session/host/include/scene_session.h"
27 #include "session/host/include/main_session.h"
28 #include "mock/mock_ibundle_mgr.h"
29 #include "common/include/task_scheduler.h"
30 #include "session/host/include/multi_instance_manager.h"
31 #include "test/mock/mock_session_stage.h"
32 #include "test/mock/mock_window_event_channel.h"
33 
34 using namespace testing;
35 using namespace testing::ext;
36 
37 namespace OHOS {
38 namespace Rosen {
39 namespace {
40 const std::string BUNDLE_NAME = "bundleName";
41 const int32_t USER_ID{ 100 };
42 const int32_t SLEEP_TIME{ 10000 };
43 } // namespace
44 class SceneSessionManagerTest11 : public testing::Test {
45 public:
46     static void SetUpTestCase();
47     static void TearDownTestCase();
48     void SetUp() override;
49     void TearDown() override;
50 
51     sptr<SceneSession> CreateSceneSession(const std::string& bundleName, WindowType windowType);
52 
53     static sptr<SceneSessionManager> ssm_;
54 
55 private:
56     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
57     sptr<SceneSession> GetSceneSession(const std::string& instanceKey = "");
58     void Init(AppExecFwk::MultiAppModeType modeType, uint32_t maxCount);
59     std::shared_ptr<TaskScheduler> GetTaskScheduler();
60 };
61 
62 sptr<SceneSessionManager> SceneSessionManagerTest11::ssm_ = nullptr;
63 
SetUpTestCase()64 void SceneSessionManagerTest11::SetUpTestCase()
65 {
66     ssm_ = &SceneSessionManager::GetInstance();
67     ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
68 }
69 
TearDownTestCase()70 void SceneSessionManagerTest11::TearDownTestCase()
71 {
72     ssm_ = nullptr;
73 }
74 
SetUp()75 void SceneSessionManagerTest11::SetUp() {}
76 
TearDown()77 void SceneSessionManagerTest11::TearDown()
78 {
79     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
80     EXPECT_CALL(*bundleMgrMocker, GetApplicationInfo(_, _, _, _)).WillOnce(Return(false));
81     MultiInstanceManager::GetInstance().Init(bundleMgrMocker, GetTaskScheduler());
82     ssm_->RefreshAppInfo(BUNDLE_NAME);
83     usleep(SLEEP_TIME);
84     MockAccesstokenKit::ChangeMockStateToInit();
85 }
86 
GetSceneSession(const std::string & instanceKey)87 sptr<SceneSession> SceneSessionManagerTest11::GetSceneSession(const std::string& instanceKey)
88 {
89     SessionInfo info;
90     info.bundleName_ = BUNDLE_NAME;
91     info.appInstanceKey_ = instanceKey;
92     info.isNewAppInstance_ = true;
93     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
94     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
95     return sceneSession;
96 }
97 
Init(AppExecFwk::MultiAppModeType modeType,uint32_t maxCount)98 void SceneSessionManagerTest11::Init(AppExecFwk::MultiAppModeType modeType, uint32_t maxCount)
99 {
100     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
101     EXPECT_CALL(*bundleMgrMocker, GetApplicationInfosV9(_, _, _)).WillOnce([modeType, maxCount](
102         int32_t flags, int32_t userId, std::vector<AppExecFwk::ApplicationInfo>& appInfos) {
103         AppExecFwk::ApplicationInfo appInfo;
104         appInfo.bundleName = BUNDLE_NAME;
105         appInfo.multiAppMode.multiAppModeType = modeType;
106         appInfo.multiAppMode.maxCount = maxCount;
107         appInfos.push_back(appInfo);
108         return ERR_OK;
109     });
110     MultiInstanceManager::GetInstance().Init(bundleMgrMocker, GetTaskScheduler());
111     MultiInstanceManager::GetInstance().SetCurrentUserId(USER_ID);
112     usleep(SLEEP_TIME);
113 }
114 
GetTaskScheduler()115 std::shared_ptr<TaskScheduler> SceneSessionManagerTest11::GetTaskScheduler()
116 {
117     std::string threadName = "threadName";
118     std::shared_ptr<TaskScheduler> taskScheduler = std::make_shared<TaskScheduler>(threadName);
119     return taskScheduler;
120 }
121 
CreateSceneSession(const std::string & bundleName,WindowType windowType)122 sptr<SceneSession> SceneSessionManagerTest11::CreateSceneSession(const std::string& bundleName, WindowType windowType)
123 {
124     SessionInfo sessionInfo;
125     sessionInfo.bundleName_ = bundleName;
126 
127     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
128     property->SetWindowType(windowType);
129     property->SetWindowName(bundleName);
130 
131     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
132     sceneSession->property_ = property;
133     return sceneSession;
134 }
135 
136 namespace {
137 /**
138  * @tc.name: GetMainWindowStatesByPid
139  * @tc.desc: SceneSesionManager get main window states by pid
140  * @tc.type: FUNC
141  */
142 HWTEST_F(SceneSessionManagerTest11, GetMainWindowStatesByPid, TestSize.Level1)
143 {
144     int32_t pid = 100;
145     std::vector<MainWindowState> windowStates;
146     WSError result = ssm_->GetMainWindowStatesByPid(pid, windowStates);
147     EXPECT_EQ(result, WSError::WS_OK);
148 }
149 
150 /**
151  * @tc.name: GetMainWindowStatesByPid02
152  * @tc.desc: SceneSesionManager get main window states by pid
153  * @tc.type: FUNC
154  */
155 HWTEST_F(SceneSessionManagerTest11, GetMainWindowStatesByPid02, TestSize.Level1)
156 {
157     int32_t invalidPid = -1;
158     std::vector<MainWindowState> windowStates;
159     WSError result = ssm_->GetMainWindowStatesByPid(invalidPid, windowStates);
160     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
161 }
162 
163 /**
164  * @tc.name: GetMainWindowStatesByPid03
165  * @tc.desc: SceneSesionManager get main window states by pid
166  * @tc.type: FUNC
167  */
168 HWTEST_F(SceneSessionManagerTest11, GetMainWindowStatesByPid03, TestSize.Level1)
169 {
170     SessionState sessionState = SessionState::STATE_FOREGROUND;
171     bool isVisible = true;
172     bool isForegroundInteractive = true;
173     bool isPcOrPadEnableActivation = true;
174     int32_t callingPid = 1001;
175     SessionInfo sessionInfo;
176     int32_t persistentId = 1005;
177     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
178     EXPECT_NE(sceneSession, nullptr);
179     sceneSession->SetSessionState(sessionState);
180     sceneSession->SetRSVisible(isVisible);
181     sceneSession->SetForegroundInteractiveStatus(isForegroundInteractive);
182     sceneSession->GetSessionProperty()->SetIsPcAppInPad(isPcOrPadEnableActivation);
183     sceneSession->SetCallingPid(callingPid);
184     ssm_->sceneSessionMap_.insert({ persistentId, sceneSession });
185     std::vector<MainWindowState> windowStates;
186     WSError result = ssm_->GetMainWindowStatesByPid(callingPid, windowStates);
187     EXPECT_EQ(result, WSError::WS_OK);
188     EXPECT_EQ(windowStates.size(), 1);
189     EXPECT_EQ(windowStates[0].state_, static_cast<int32_t>(sessionState));
190     EXPECT_EQ(windowStates[0].isVisible_, isVisible);
191     EXPECT_EQ(windowStates[0].isForegroundInteractive_, isForegroundInteractive);
192     EXPECT_EQ(windowStates[0].isPcOrPadEnableActivation_, isPcOrPadEnableActivation);
193 }
194 
195 /**
196  * @tc.name: GetMaxInstanceCount
197  * @tc.desc: test function : GetMaxInstanceCount
198  * @tc.type: FUNC
199  */
200 HWTEST_F(SceneSessionManagerTest11, GetMaxInstanceCount, TestSize.Level1)
201 {
202     AppExecFwk::MultiAppModeType modeType = AppExecFwk::MultiAppModeType::MULTI_INSTANCE;
203     uint32_t maxCount = 5;
204     Init(modeType, maxCount);
205     ASSERT_EQ(ssm_->GetMaxInstanceCount(BUNDLE_NAME), maxCount);
206 }
207 
208 /**
209  * @tc.name: GetInstanceCount
210  * @tc.desc: test function : GetInstanceCount
211  * @tc.type: FUNC
212  */
213 HWTEST_F(SceneSessionManagerTest11, GetInstanceCount, TestSize.Level1)
214 {
215     AppExecFwk::MultiAppModeType modeType = AppExecFwk::MultiAppModeType::MULTI_INSTANCE;
216     uint32_t maxCount = 5;
217     Init(modeType, maxCount);
218     ASSERT_EQ(ssm_->GetInstanceCount(BUNDLE_NAME), 0);
219     std::string instanceKey0 = "app_instance_0";
220     sptr<SceneSession> sceneSession = GetSceneSession(instanceKey0);
221     ASSERT_EQ(MultiInstanceManager::GetInstance().CreateNewInstanceKey(BUNDLE_NAME), instanceKey0);
222     MultiInstanceManager::GetInstance().IncreaseInstanceKeyRefCount(sceneSession);
223     ASSERT_EQ(ssm_->GetInstanceCount(BUNDLE_NAME), 1);
224     MultiInstanceManager::GetInstance().DecreaseInstanceKeyRefCount(sceneSession);
225     ASSERT_EQ(ssm_->GetInstanceCount(BUNDLE_NAME), 0);
226 }
227 
228 /**
229  * @tc.name: GetLastInstanceKey
230  * @tc.desc: test function : GetLastInstanceKey
231  * @tc.type: FUNC
232  */
233 HWTEST_F(SceneSessionManagerTest11, GetLastInstanceKey, TestSize.Level1)
234 {
235     AppExecFwk::MultiAppModeType modeType = AppExecFwk::MultiAppModeType::MULTI_INSTANCE;
236     uint32_t maxCount = 5;
237     Init(modeType, maxCount);
238     ASSERT_EQ(ssm_->GetLastInstanceKey(BUNDLE_NAME), "");
239     std::string instanceKey0 = "app_instance_0";
240     sptr<SceneSession> sceneSession = GetSceneSession(instanceKey0);
241     ASSERT_EQ(MultiInstanceManager::GetInstance().CreateNewInstanceKey(BUNDLE_NAME), instanceKey0);
242     MultiInstanceManager::GetInstance().IncreaseInstanceKeyRefCount(sceneSession);
243     ASSERT_EQ(ssm_->GetLastInstanceKey(BUNDLE_NAME), instanceKey0);
244     MultiInstanceManager::GetInstance().DecreaseInstanceKeyRefCount(sceneSession);
245     ASSERT_EQ(ssm_->GetLastInstanceKey(BUNDLE_NAME), "");
246 }
247 
248 /**
249  * @tc.name: GetAbilityInfo
250  * @tc.desc: SceneSesionManager test GetAbilityInfo
251  * @tc.type: FUNC
252  */
253 HWTEST_F(SceneSessionManagerTest11, GetAbilityInfo, TestSize.Level1)
254 {
255     ssm_->bundleMgr_ = nullptr;
256     std::string bundleName = "bundleName";
257     std::string moduleName = "moduleName";
258     std::string abilityName = "abilityName";
259     int32_t userId = 100;
260     SCBAbilityInfo scbAbilityInfo;
261     WSError ret = ssm_->GetAbilityInfo(bundleName, moduleName, abilityName, userId, scbAbilityInfo);
262     ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
263 }
264 
265 /**
266  * @tc.name: GetAbilityInfo02
267  * @tc.desc: SceneSesionManager test GetAbilityInfo
268  * @tc.type: FUNC
269  */
270 HWTEST_F(SceneSessionManagerTest11, GetAbilityInfo02, TestSize.Level1)
271 {
272     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
273     EXPECT_CALL(*bundleMgrMocker, GetBundleInfoV9(_, _, _, _)).WillOnce(Return(1));
274     ssm_->bundleMgr_ = bundleMgrMocker;
275     std::string bundleName = "bundleName";
276     std::string moduleName = "moduleName";
277     std::string abilityName = "abilityName";
278     int32_t userId = 100;
279     SCBAbilityInfo scbAbilityInfo;
280     WSError ret = ssm_->GetAbilityInfo(bundleName, moduleName, abilityName, userId, scbAbilityInfo);
281     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
282 }
283 
284 /**
285  * @tc.name: GetAbilityInfo03
286  * @tc.desc: SceneSesionManager test GetAbilityInfo
287  * @tc.type: FUNC
288  */
289 HWTEST_F(SceneSessionManagerTest11, GetAbilityInfo03, TestSize.Level1)
290 {
291     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
292     EXPECT_CALL(*bundleMgrMocker, GetBundleInfoV9(_, _, _, _))
__anon87c08a680402(const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) 293         .WillOnce([](const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) {
294             bundleInfo.hapModuleInfos = {};
295             return 0;
296         });
297     ssm_->bundleMgr_ = bundleMgrMocker;
298     std::string bundleName = "bundleName";
299     std::string moduleName = "moduleName";
300     std::string abilityName = "abilityName";
301     int32_t userId = 100;
302     SCBAbilityInfo scbAbilityInfo;
303     WSError ret = ssm_->GetAbilityInfo(bundleName, moduleName, abilityName, userId, scbAbilityInfo);
304     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
305 }
306 
307 /**
308  * @tc.name: GetAbilityInfo04
309  * @tc.desc: SceneSesionManager test GetAbilityInfo
310  * @tc.type: FUNC
311  */
312 HWTEST_F(SceneSessionManagerTest11, GetAbilityInfo04, TestSize.Level1)
313 {
314     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
315     EXPECT_CALL(*bundleMgrMocker, GetBundleInfoV9(_, _, _, _))
__anon87c08a680502(const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) 316         .WillOnce([](const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) {
317             AppExecFwk::AbilityInfo abilityInfo;
318             abilityInfo.moduleName = "moduleName";
319             abilityInfo.name = "abilityName";
320             AppExecFwk::HapModuleInfo hapModuleInfo;
321             hapModuleInfo.abilityInfos = { abilityInfo };
322             bundleInfo.hapModuleInfos = { hapModuleInfo };
323             bundleInfo.applicationInfo.codePath = "testCodePath";
324             return 0;
325         });
326     ssm_->bundleMgr_ = bundleMgrMocker;
327     std::string bundleName = "bundleName";
328     std::string moduleName = "moduleName";
329     std::string abilityName = "abilityName";
330     int32_t userId = 100;
331     SCBAbilityInfo scbAbilityInfo;
332     WSError ret = ssm_->GetAbilityInfo(bundleName, moduleName, abilityName, userId, scbAbilityInfo);
333     ASSERT_EQ(ret, WSError::WS_OK);
334     ASSERT_EQ(scbAbilityInfo.codePath_, "testCodePath");
335 }
336 
337 /**
338  * @tc.name: GetAbilityInfo05
339  * @tc.desc: SceneSesionManager test GetAbilityInfo
340  * @tc.type: FUNC
341  */
342 HWTEST_F(SceneSessionManagerTest11, GetAbilityInfo05, TestSize.Level1)
343 {
344     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
345     EXPECT_CALL(*bundleMgrMocker, GetBundleInfoV9(_, _, _, _))
__anon87c08a680602(const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) 346         .WillOnce([](const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) {
347             AppExecFwk::AbilityInfo abilityInfo;
348             abilityInfo.moduleName = "moduleName2";
349             abilityInfo.name = "abilityName2";
350             AppExecFwk::HapModuleInfo hapModuleInfo;
351             hapModuleInfo.abilityInfos = { abilityInfo };
352             bundleInfo.hapModuleInfos = { hapModuleInfo };
353             return 0;
354         });
355     ssm_->bundleMgr_ = bundleMgrMocker;
356     std::string bundleName = "bundleName";
357     std::string moduleName = "moduleName";
358     std::string abilityName = "abilityName";
359     int32_t userId = 100;
360     SCBAbilityInfo scbAbilityInfo;
361     WSError ret = ssm_->GetAbilityInfo(bundleName, moduleName, abilityName, userId, scbAbilityInfo);
362     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
363 }
364 
365 /**
366  * @tc.name: LockSessionByAbilityInfo
367  * @tc.desc: SceneSesionManager test LockSessionByAbilityInfo
368  * @tc.type: FUNC
369  */
370 HWTEST_F(SceneSessionManagerTest11, LockSessionByAbilityInfo, TestSize.Level1)
371 {
372     ASSERT_NE(ssm_, nullptr);
373     AbilityInfoBase abilityInfo;
374     abilityInfo.bundleName = "LockSessionByAbilityInfoBundle";
375     abilityInfo.moduleName = "LockSessionByAbilityInfoModule";
376     abilityInfo.abilityName = "LockSessionByAbilityInfoAbility";
377     abilityInfo.appIndex = 0;
378 
379     MockAccesstokenKit::MockAccessTokenKitRet(-1);
380     auto result = ssm_->LockSessionByAbilityInfo(abilityInfo, true);
381     ASSERT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, result);
382 }
383 
384 /**
385  * @tc.name: NotifyWatchGestureConsumeResult
386  * @tc.desc: SceneSesionManager test NotifyWatchGestureConsumeResult
387  * @tc.type: FUNC
388  */
389 HWTEST_F(SceneSessionManagerTest11, NotifyWatchGestureConsumeResult, TestSize.Level1)
390 {
391     ASSERT_NE(ssm_, nullptr);
392     int32_t keyCode = 0;
393     bool isConsumed = true;
__anon87c08a680702(int32_t keyCode, bool isConsumed) 394     ssm_->onWatchGestureConsumeResultFunc_ = [](int32_t keyCode, bool isConsumed) {};
395     auto ret = ssm_->NotifyWatchGestureConsumeResult(keyCode, isConsumed);
396     ASSERT_EQ(ret, WMError::WM_OK);
397 
398     ssm_->onWatchGestureConsumeResultFunc_ = nullptr;
399     ret = ssm_->NotifyWatchGestureConsumeResult(keyCode, isConsumed);
400     ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
401 }
402 
403 /**
404  * @tc.name: NotifyWatchFocusActiveChange
405  * @tc.desc: SceneSesionManager test NotifyWatchFocusActiveChange
406  * @tc.type: FUNC
407  */
408 HWTEST_F(SceneSessionManagerTest11, NotifyWatchFocusActiveChange, TestSize.Level1)
409 {
410     ASSERT_NE(ssm_, nullptr);
411     bool isActive = true;
__anon87c08a680802(bool isActive) 412     ssm_->onWatchFocusActiveChangeFunc_ = [](bool isActive) {};
413     auto ret = ssm_->NotifyWatchFocusActiveChange(isActive);
414     ASSERT_EQ(ret, WMError::WM_OK);
415 
416     ssm_->onWatchFocusActiveChangeFunc_ = nullptr;
417     ret = ssm_->NotifyWatchFocusActiveChange(isActive);
418     ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
419 }
420 
421 /**
422  * @tc.name: DestroyUIServiceExtensionSubWindow
423  * @tc.desc: SceneSesionManager test DestroyUIServiceExtensionSubWindow
424  * @tc.type: FUNC
425  */
426 HWTEST_F(SceneSessionManagerTest11, DestroyUIServiceExtensionSubWindow, TestSize.Level1)
427 {
428     ASSERT_NE(ssm_, nullptr);
429     sptr<SceneSession> sceneSession = nullptr;
430     ssm_->DestroyUIServiceExtensionSubWindow(sceneSession);
431     SessionInfo sessionInfo = { "bundleName", "moduleName", "abilityName" };
432     sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
433     ssm_->DestroyUIServiceExtensionSubWindow(sceneSession);
434 
435     sptr<WindowSessionProperty> property_ = sptr<WindowSessionProperty>::MakeSptr();
436     property_->isUIExtFirstSubWindow_ = true;
437     ASSERT_EQ(property_->isUIExtAnySubWindow_, false);
438     ssm_->DestroyUIServiceExtensionSubWindow(sceneSession);
439 }
440 
441 /**
442  * @tc.name: FilterForGetAllWindowLayoutInfo
443  * @tc.desc: SceneSesionManager test FilterForGetAllWindowLayoutInfo
444  * @tc.type: FUNC
445  */
446 HWTEST_F(SceneSessionManagerTest11, FilterForGetAllWindowLayoutInfo, TestSize.Level1)
447 {
448     ASSERT_NE(ssm_, nullptr);
449     DisplayId displayId = 0;
450     bool isVirtualDisplay = true;
451     std::vector<sptr<SceneSession>> filteredSessions{};
452     SessionInfo info;
453     info.bundleName_ = BUNDLE_NAME;
454     info.appInstanceKey_ = "instanceKey";
455     info.isNewAppInstance_ = true;
456     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
457     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
458     ssm_->sceneSessionMap_.clear();
459     auto ret = ssm_->sceneSessionMap_.size();
460     ASSERT_EQ(ret, 0);
461     ssm_->FilterForGetAllWindowLayoutInfo(displayId, isVirtualDisplay, filteredSessions);
462     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
463     ssm_->FilterForGetAllWindowLayoutInfo(displayId, isVirtualDisplay, filteredSessions);
464 }
465 
466 /**
467  * @tc.name: ShiftAppWindowPointerEvent
468  * @tc.desc: SceneSesionManager test ShiftAppWindowPointerEvent
469  * @tc.type: FUNC
470  */
471 HWTEST_F(SceneSessionManagerTest11, ShiftAppWindowPointerEvent, TestSize.Level1)
472 {
473     ASSERT_NE(ssm_, nullptr);
474     int32_t sourcePersistentId = 0;
475     int32_t targetPersistentId = 0;
476     ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
477     auto ret = ssm_->systemConfig_.IsPcWindow();
478     ASSERT_EQ(ret, false);
479 
480     int32_t fingerId = 0;
481     auto res = ssm_->ShiftAppWindowPointerEvent(sourcePersistentId, targetPersistentId, fingerId);
482     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_SESSION);
483 
484     SessionInfo sourceInfo;
485     sourceInfo.windowType_ = 1;
486     sptr<SceneSession> sourceSceneSession = sptr<SceneSession>::MakeSptr(sourceInfo, nullptr);
487     ssm_->sceneSessionMap_.insert({ sourceSceneSession->GetPersistentId(), sourceSceneSession });
488     res = ssm_->ShiftAppWindowPointerEvent(sourceSceneSession->GetPersistentId(), targetPersistentId, fingerId);
489     EXPECT_EQ(res, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
490 
491     ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
492     ssm_->systemConfig_.freeMultiWindowEnable_ = true;
493     ssm_->systemConfig_.freeMultiWindowSupport_ = true;
494     res = ssm_->ShiftAppWindowPointerEvent(sourceSceneSession->GetPersistentId(),
495         sourceSceneSession->GetPersistentId(), fingerId);
496     ASSERT_EQ(res, WMError::WM_ERROR_INVALID_CALLING);
497     ssm_->sceneSessionMap_.erase(sourceSceneSession->GetPersistentId());
498 }
499 
500 /**
501  * @tc.name: HasFloatingWindowForeground
502  * @tc.desc: SceneSesionManager test HasFloatingWindowForeground
503  * @tc.type: FUNC
504  */
505 HWTEST_F(SceneSessionManagerTest11, HasFloatingWindowForeground, TestSize.Level1)
506 {
507     ASSERT_NE(ssm_, nullptr);
508     sptr<IRemoteObject> abilityToken = nullptr;
509     bool hasOrNot = true;
510     auto ret = ssm_->HasFloatingWindowForeground(abilityToken, hasOrNot);
511     ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
512 }
513 
514 /**
515  * @tc.name: SetParentWindow
516  * @tc.desc: SceneSesionManager test SetParentWindow
517  * @tc.type: FUNC
518  */
519 HWTEST_F(SceneSessionManagerTest11, SetParentWindow, TestSize.Level1)
520 {
521     ssm_->sceneSessionMap_.clear();
522     ASSERT_NE(ssm_, nullptr);
523     int32_t subWindowId = 1;
524     int32_t newParentWindowId = 3;
525     auto res = ssm_->SetParentWindow(subWindowId, newParentWindowId);
526     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
527     SessionInfo info;
528     info.abilityName_ = "SetParentWindow";
529     info.bundleName_ = "SetParentWindow";
530     sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
531     subSession->property_->SetPersistentId(1);
532     subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
533     ssm_->sceneSessionMap_.insert({ subSession->property_->GetPersistentId(), subSession });
534     res = ssm_->SetParentWindow(subWindowId, newParentWindowId);
535     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARENT);
536 
537     sptr<SceneSession> oldParentSession = sptr<SceneSession>::MakeSptr(info, nullptr);
538     oldParentSession->property_->SetPersistentId(2);
539     oldParentSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
540     ssm_->sceneSessionMap_.insert({ oldParentSession->property_->GetPersistentId(), oldParentSession });
541     subSession->property_->SetParentPersistentId(2);
542     subSession->SetParentSession(oldParentSession);
543     res = ssm_->SetParentWindow(subWindowId, newParentWindowId);
544     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARENT);
545 
546     sptr<SceneSession> newParentSession = sptr<SceneSession>::MakeSptr(info, nullptr);
547     newParentSession->property_->SetPersistentId(3);
548     newParentSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
549     ssm_->sceneSessionMap_.insert({ newParentSession->property_->GetPersistentId(), newParentSession });
550     res = ssm_->SetParentWindow(subWindowId, newParentWindowId);
551     EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARENT);
552 
553     newParentSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
554     res = ssm_->SetParentWindow(subWindowId, newParentWindowId);
555     EXPECT_EQ(res, WMError::WM_OK);
556 }
557 
558 /**
559  * @tc.name: GetMainSessionByBundleNameAndAppIndex
560  * @tc.desc: GetMainSessionByBundleNameAndAppIndex
561  * @tc.type: FUNC
562  */
563 HWTEST_F(SceneSessionManagerTest11, GetMainSessionByBundleNameAndAppIndex, TestSize.Level1)
564 {
565     ASSERT_NE(ssm_, nullptr);
566     std::string bundleName = "bundleName_test";
567     int32_t appIndex = 1;
568     std::vector<sptr<SceneSession>> mainSessions;
569     ssm_->sceneSessionMap_.clear();
570     ssm_->GetMainSessionByBundleNameAndAppIndex(bundleName, appIndex, mainSessions);
571 
572     sptr<SceneSession> sceneSession = GetSceneSession(bundleName);
573     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
574     ssm_->GetMainSessionByBundleNameAndAppIndex(bundleName, appIndex, mainSessions);
575 
576     ssm_->GetMainSessionByBundleNameAndAppIndex(BUNDLE_NAME, appIndex, mainSessions);
577 
578     appIndex = 0;
579     ssm_->GetMainSessionByBundleNameAndAppIndex(BUNDLE_NAME, appIndex, mainSessions);
580     ASSERT_EQ(mainSessions.empty(), false);
581     ssm_->sceneSessionMap_.clear();
582 }
583 
584 /**
585  * @tc.name: GetMainSessionByAbilityInfo
586  * @tc.desc: GetMainSessionByAbilityInfo
587  * @tc.type: FUNC
588  */
589 HWTEST_F(SceneSessionManagerTest11, GetMainSessionByAbilityInfo, TestSize.Level1)
590 {
591     ASSERT_NE(ssm_, nullptr);
592     AbilityInfoBase abilityInfo;
593     abilityInfo.bundleName = "bundleName";
594     abilityInfo.moduleName = "moduleName";
595     abilityInfo.abilityName = "abilityName";
596     abilityInfo.appIndex = 1;
597     std::vector<sptr<SceneSession>> mainSessions;
598     std::string bundleName = "bundleName_test";
599     sptr<SceneSession> sceneSession = GetSceneSession(bundleName);
600     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
601     ssm_->GetMainSessionByAbilityInfo(abilityInfo, mainSessions);
602 
603     abilityInfo.bundleName = BUNDLE_NAME;
604     ssm_->GetMainSessionByAbilityInfo(abilityInfo, mainSessions);
605 
606     abilityInfo.moduleName = "";
607     ssm_->GetMainSessionByAbilityInfo(abilityInfo, mainSessions);
608 
609     abilityInfo.abilityName = "";
610     ssm_->GetMainSessionByAbilityInfo(abilityInfo, mainSessions);
611 
612     abilityInfo.appIndex = 0;
613     ssm_->GetMainSessionByAbilityInfo(abilityInfo, mainSessions);
614     ASSERT_EQ(mainSessions.empty(), false);
615     ssm_->sceneSessionMap_.clear();
616 }
617 
618 /**
619  * @tc.name: GetKeyboardSession
620  * @tc.desc: GetKeyboardSession
621  * @tc.type: FUNC
622  */
623 HWTEST_F(SceneSessionManagerTest11, GetKeyboardSession, TestSize.Level1)
624 {
625     ASSERT_NE(ssm_, nullptr);
626     DisplayId displayId = DISPLAY_ID_INVALID;
627     bool isSystemKeyboard = true;
628     ASSERT_EQ(ssm_->GetKeyboardSession(displayId, isSystemKeyboard), nullptr);
629 
630     displayId = 0;
631     ssm_->GetKeyboardSession(displayId, isSystemKeyboard);
632 
633     SessionInfo info;
634     info.bundleName_ = BUNDLE_NAME;
635     info.screenId_ = 5;
636     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
637     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
638     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
639     ssm_->GetKeyboardSession(displayId, isSystemKeyboard);
640 
641     displayId = 5;
642     ssm_->GetKeyboardSession(displayId, isSystemKeyboard);
643 
644     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
645     ssm_->GetKeyboardSession(displayId, isSystemKeyboard);
646 
647     isSystemKeyboard = false;
648     sptr<SceneSession> keyboardSession = ssm_->GetKeyboardSession(displayId, isSystemKeyboard);
649     ASSERT_EQ(keyboardSession, sceneSession);
650     ssm_->sceneSessionMap_.clear();
651 }
652 
653 /**
654  * @tc.name: DestroyToastSession
655  * @tc.desc: DestroyToastSession
656  * @tc.type: FUNC
657  */
658 HWTEST_F(SceneSessionManagerTest11, DestroyToastSession, TestSize.Level1)
659 {
660     ASSERT_NE(ssm_, nullptr);
661     std::string bundleName = "bundleName_test";
662     sptr<SceneSession> sceneSession = GetSceneSession(bundleName);
663     ssm_->DestroyToastSession(nullptr);
664     ssm_->DestroyToastSession(sceneSession);
665 
666     sptr<SceneSession> sceneSession02 = GetSceneSession(bundleName);
667     sceneSession->toastSession_.emplace_back(sceneSession02);
668     ssm_->DestroyToastSession(sceneSession);
669     ASSERT_EQ(sceneSession->toastSession_.empty(), false);
670 }
671 
672 /**
673  * @tc.name: CreateAndConnectSpecificSession01
674  * @tc.desc: CreateAndConnectSpecificSession
675  * @tc.type: FUNC
676  */
677 HWTEST_F(SceneSessionManagerTest11, CreateAndConnectSpecificSession01, TestSize.Level0)
678 {
679     sptr<ISessionStage> sessionStage = sptr<SessionStageMocker>::MakeSptr();
680     sptr<IWindowEventChannel> eventChannel = sptr<WindowEventChannelMocker>::MakeSptr(sessionStage);
681     std::shared_ptr<RSSurfaceNode> node = nullptr;
682     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
683     int32_t persistentId = 1;
684     sptr<ISession> session = nullptr;
685     SystemSessionConfig systemConfig;
686     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
687 
688     property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
689     auto result = ssm_->CreateAndConnectSpecificSession(
690         sessionStage, eventChannel, node, property, persistentId, session, systemConfig, iRemoteObjectMocker);
691     ASSERT_EQ(result, WSError::WS_ERROR_NOT_SYSTEM_APP);
692 
693     property->SetTopmost(false);
694     property->SetWindowType(WindowType::WINDOW_TYPE_MEDIA);
695     std::string bundleName = "bundleName_test";
696     sptr<SceneSession> parentSession = GetSceneSession(bundleName);
697     parentSession->GetSessionProperty()->SetSubWindowLevel(10);
698     ssm_->sceneSessionMap_.insert({ 1, parentSession });
699     property->SetParentPersistentId(1);
700     result = ssm_->CreateAndConnectSpecificSession(
701         sessionStage, eventChannel, node, property, persistentId, session, systemConfig, iRemoteObjectMocker);
702     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_WINDOW);
703 
704     MockAccesstokenKit::MockAccessTokenKitRet(-1);
705     parentSession->GetSessionProperty()->SetSubWindowLevel(1);
706     property->SetWindowType(WindowType::WINDOW_TYPE_FB);
707     result = ssm_->CreateAndConnectSpecificSession(
708         sessionStage, eventChannel, node, property, persistentId, session, systemConfig, iRemoteObjectMocker);
709     ASSERT_EQ(WSError::WS_ERROR_NOT_SYSTEM_APP, result);
710     MockAccesstokenKit::MockAccessTokenKitRet(0);
711     parentSession->SetSessionState(SessionState::STATE_DISCONNECT);
712     result = ssm_->CreateAndConnectSpecificSession(
713         sessionStage, eventChannel, node, property, persistentId, session, systemConfig, iRemoteObjectMocker);
714     ASSERT_EQ(WSError::WS_ERROR_INVALID_PARENT, result);
715     parentSession->SetSessionState(SessionState::STATE_FOREGROUND);
716     result = ssm_->CreateAndConnectSpecificSession(
717         sessionStage, eventChannel, node, property, persistentId, session, systemConfig, iRemoteObjectMocker);
718     ASSERT_EQ(WSError::WS_OK, result);
719 }
720 
721 /**
722  * @tc.name: IsLastPiPWindowVisible
723  * @tc.desc: IsLastPiPWindowVisible
724  * @tc.type: FUNC
725  */
726 HWTEST_F(SceneSessionManagerTest11, IsLastPiPWindowVisible, TestSize.Level1)
727 {
728     uint64_t surfaceId = 1;
729     WindowVisibilityState lastVisibilityState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION;
730     ssm_->sceneSessionMap_.clear();
731     auto res = ssm_->IsLastPiPWindowVisible(surfaceId, lastVisibilityState);
732     ASSERT_EQ(res, false);
733 }
734 
735 /**
736  * @tc.name: GetIconFromDesk
737  * @tc.desc: GetIconFromDesk
738  * @tc.type: FUNC
739  */
740 HWTEST_F(SceneSessionManagerTest11, GetIconFromDesk, TestSize.Level1)
741 {
742     ASSERT_NE(ssm_, nullptr);
743     SessionInfo sessionInfo;
744     sessionInfo.abilityName_ = BUNDLE_NAME;
745     sessionInfo.bundleName_ = BUNDLE_NAME;
746     std::string startupPagePath = "test";
747     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
748     sessionInfo.want = want;
749     ASSERT_EQ(false, ssm_->GetIconFromDesk(sessionInfo, startupPagePath));
750 }
751 
752 /**
753  * @tc.name: GetTopNearestBlockingFocusSession
754  * @tc.desc: GetTopNearestBlockingFocusSession
755  * @tc.type: FUNC
756  */
757 HWTEST_F(SceneSessionManagerTest11, GetTopNearestBlockingFocusSession, TestSize.Level1)
758 {
759     ASSERT_NE(ssm_, nullptr);
760     ssm_->sceneSessionMap_.clear();
761     DisplayId displayId = DEFAULT_DISPLAY_ID;
762     uint32_t zOrder = 0;
763     bool includingAppSession = true;
764     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
765 
766     SessionInfo info;
767     info.bundleName_ = BUNDLE_NAME;
768     info.isSystem_ = true;
769     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
770     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
771     sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, specificCb);
772     sceneSession->GetSessionProperty()->SetDisplayId(DEFAULT_DISPLAY_ID);
773     sceneSession->zOrder_ = 10;
774     sceneSession->GetSessionProperty()->SetTopmost(true);
775     sceneSession->GetSessionProperty()->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
776     sceneSession->GetSessionProperty()->SetParentPersistentId(2);
777     sceneSession->SetScbCoreEnabled(true);
778     sceneSession->isVisible_ = true;
779     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
780     sceneSession->blockingFocus_ = true;
781     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
782     ssm_->sceneSessionMap_.insert({ 2, sceneSession02 });
783     auto res = ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession);
784     ASSERT_EQ(res, sceneSession);
785     ssm_->sceneSessionMap_.clear();
786 }
787 
788 /**
789  * @tc.name: GetTopNearestBlockingFocusSession_branch02
790  * @tc.desc: GetTopNearestBlockingFocusSession
791  * @tc.type: FUNC
792  */
793 HWTEST_F(SceneSessionManagerTest11, GetTopNearestBlockingFocusSession_branch02, TestSize.Level1)
794 {
795     ASSERT_NE(ssm_, nullptr);
796     ssm_->sceneSessionMap_.clear();
797     DisplayId displayId = DEFAULT_DISPLAY_ID;
798     uint32_t zOrder = 0;
799     bool includingAppSession = true;
800     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
801 
802     SessionInfo info;
803     info.bundleName_ = BUNDLE_NAME;
804     info.isSystem_ = true;
805     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
806     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
807     sceneSession->GetSessionProperty()->SetDisplayId(100);
808     ssm_->windowFocusController_->displayId2GroupIdMap_[100] = 20;
809     ssm_->windowFocusController_->displayId2GroupIdMap_[20] = 20;
810     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
811     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
812     ssm_->sceneSessionMap_.clear();
813 }
814 
815 /**
816  * @tc.name: GetTopNearestBlockingFocusSession_branch03
817  * @tc.desc: GetTopNearestBlockingFocusSession
818  * @tc.type: FUNC
819  */
820 HWTEST_F(SceneSessionManagerTest11, GetTopNearestBlockingFocusSession_branch03, TestSize.Level1)
821 {
822     ASSERT_NE(ssm_, nullptr);
823     ssm_->sceneSessionMap_.clear();
824     DisplayId displayId = DEFAULT_DISPLAY_ID;
825     uint32_t zOrder = 100;
826     bool includingAppSession = true;
827     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
828 
829     SessionInfo info;
830     info.bundleName_ = BUNDLE_NAME;
831     info.isSystem_ = true;
832     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
833     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
834     sceneSession->GetSessionProperty()->SetDisplayId(DEFAULT_DISPLAY_ID);
835     sceneSession->zOrder_ = 10;
836     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
837     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
838     ssm_->sceneSessionMap_.clear();
839 }
840 
841 /**
842  * @tc.name: GetTopNearestBlockingFocusSession_branch04
843  * @tc.desc: GetTopNearestBlockingFocusSession
844  * @tc.type: FUNC
845  */
846 HWTEST_F(SceneSessionManagerTest11, GetTopNearestBlockingFocusSession_branch04, TestSize.Level1)
847 {
848     ASSERT_NE(ssm_, nullptr);
849     ssm_->sceneSessionMap_.clear();
850     DisplayId displayId = DEFAULT_DISPLAY_ID;
851     uint32_t zOrder = 0;
852     bool includingAppSession = true;
853     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
854 
855     SessionInfo info;
856     info.bundleName_ = BUNDLE_NAME;
857     info.isSystem_ = true;
858     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
859     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
860     sceneSession->GetSessionProperty()->SetDisplayId(DEFAULT_DISPLAY_ID);
861     sceneSession->GetSessionProperty()->SetTopmost(true);
862     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
863     sceneSession->zOrder_ = 10;
864     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
865     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
866     ssm_->sceneSessionMap_.clear();
867 }
868 
869 /**
870  * @tc.name: GetTopNearestBlockingFocusSession_branch05
871  * @tc.desc: GetTopNearestBlockingFocusSession
872  * @tc.type: FUNC
873  */
874 HWTEST_F(SceneSessionManagerTest11, GetTopNearestBlockingFocusSession_branch05, TestSize.Level1)
875 {
876     ASSERT_NE(ssm_, nullptr);
877     ssm_->sceneSessionMap_.clear();
878     DisplayId displayId = DEFAULT_DISPLAY_ID;
879     uint32_t zOrder = 0;
880     bool includingAppSession = true;
881     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
882 
883     SessionInfo info;
884     info.bundleName_ = BUNDLE_NAME;
885     info.isSystem_ = true;
886     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
887     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
888     sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, specificCb);
889     sceneSession->GetSessionProperty()->SetDisplayId(DEFAULT_DISPLAY_ID);
890     sceneSession->GetSessionProperty()->SetTopmost(false);
891     sceneSession->zOrder_ = 10;
892     sceneSession->GetSessionProperty()->SetWindowType(WindowType::APP_WINDOW_BASE);
893     sceneSession->GetSessionProperty()->SetParentPersistentId(2);
894     sceneSession02->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
895     sceneSession02->GetSessionProperty()->SetTopmost(true);
896     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
897     ssm_->sceneSessionMap_.insert({ 2, sceneSession02 });
898 
899     ASSERT_EQ(nullptr, ssm_->GetTopNearestBlockingFocusSession(displayId, zOrder, includingAppSession));
900     ssm_->sceneSessionMap_.clear();
901 }
902 
903 /**
904  * @tc.name: AnimateTo01
905  * @tc.desc: AnimateTo
906  * @tc.type: FUNC
907  */
908 HWTEST_F(SceneSessionManagerTest11, AnimateTo01, Function | SmallTest | Level1)
909 {
910     SessionInfo info;
911     info.bundleName_ = "AnimateToTest";
912     sptr<SceneSession::SpecificSessionCallback> specificCb = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
913     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCb);
914     sceneSession->GetSessionProperty()->SetWindowType(WindowType::APP_WINDOW_BASE);
915     float targetScale = 0;
916     WindowAnimationCurve curve = WindowAnimationCurve::LINEAR;
917     sceneSession->RegisterAnimateToCallback([&targetScale, &curve](const WindowAnimationProperty& animationProperty,
__anon87c08a680902(const WindowAnimationProperty& animationProperty, const WindowAnimationOption& animationOption) 918         const WindowAnimationOption& animationOption) {
919         targetScale = animationProperty.targetScale;
920         curve = animationOption.curve;
921     });
922 
923     auto persistenId = sceneSession->GetPersistentId();
924     ssm_->sceneSessionMap_.insert({ persistenId, sceneSession });
925     WindowAnimationProperty animationProperty;
926     animationProperty.targetScale = 10.5f;
927     WindowAnimationOption animationOption;
928     animationOption.curve = WindowAnimationCurve::INTERPOLATION_SPRING;
929     animationOption.duration = 1000;
930 
931     ssm_->AnimateTo(0, animationProperty, animationOption);
932     usleep(SLEEP_TIME);
933     ASSERT_EQ(curve, WindowAnimationCurve::LINEAR);
934     ASSERT_EQ(targetScale, 0);
935 
936     sceneSession->GetSessionProperty()->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
937     ssm_->AnimateTo(persistenId, animationProperty, animationOption);
938     usleep(SLEEP_TIME);
939     ASSERT_EQ(curve, WindowAnimationCurve::LINEAR);
940     ASSERT_EQ(targetScale, 0);
941 
942     sceneSession->GetSessionProperty()->SetWindowType(WindowType::APP_WINDOW_BASE);
943     ssm_->AnimateTo(persistenId, animationProperty, animationOption);
944     usleep(SLEEP_TIME);
945     ASSERT_EQ(curve, WindowAnimationCurve::INTERPOLATION_SPRING);
946     ASSERT_EQ(targetScale, animationProperty.targetScale);
947 }
948 
949 /**
950  * @tc.name: UpdateHighlightStatus
951  * @tc.desc: UpdateHighlightStatus
952  * @tc.type: FUNC
953  */
954 HWTEST_F(SceneSessionManagerTest11, UpdateHighlightStatus, TestSize.Level1)
955 {
956     ASSERT_NE(ssm_, nullptr);
957     SessionInfo info;
958     info.abilityName_ = "UpdateHighlightStatus";
959     info.bundleName_ = "UpdateHighlightStatus";
960     sptr<SceneSession> preSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
961     sptr<SceneSession> currSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
962     preSceneSession->property_->SetPersistentId(1);
963     currSceneSession->property_->SetPersistentId(2);
964 
965     sptr<SceneSession> nullSceneSession1;
966     sptr<SceneSession> nullSceneSession2;
967 
968     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, nullSceneSession1, nullSceneSession2, false);
969     EXPECT_EQ(ssm_->highlightIds_.size(), 0);
970 
971     ssm_->AddHighlightSessionIds(preSceneSession, false);
972     EXPECT_EQ(ssm_->highlightIds_.size(), 1);
973     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, preSceneSession, nullSceneSession2, false);
974     EXPECT_EQ(ssm_->highlightIds_.size(), 1);
975     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, preSceneSession, nullSceneSession2, true);
976     EXPECT_EQ(ssm_->highlightIds_.size(), 0);
977 
978     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, preSceneSession, currSceneSession, true);
979     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, preSceneSession, currSceneSession, false);
980     EXPECT_EQ(ssm_->highlightIds_.size(), 1);
981 
982     currSceneSession->property_->isExclusivelyHighlighted_ = false;
983     preSceneSession->property_->SetPersistentId(2);
984     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, preSceneSession, currSceneSession, false);
985 }
986 
987 /**
988  * @tc.name: UpdateHighlightStatus01
989  * @tc.desc: UpdateHighlightStatus
990  * @tc.type: FUNC
991  */
992 HWTEST_F(SceneSessionManagerTest11, UpdateHighlightStatus01, TestSize.Level1)
993 {
994     ASSERT_NE(ssm_, nullptr);
995     ssm_->highlightIds_.clear();
996     SessionInfo info;
997     info.abilityName_ = "UpdateHighlightStatus01";
998     info.bundleName_ = "UpdateHighlightStatus01";
999     sptr<SceneSession> preSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1000     sptr<SceneSession> currSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1001     preSceneSession->property_->SetPersistentId(1);
1002     currSceneSession->property_->SetPersistentId(2);
1003     currSceneSession->property_->isExclusivelyHighlighted_ = false;
1004     currSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1005     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, preSceneSession, currSceneSession, false);
1006     ASSERT_EQ(ssm_->highlightIds_.size(), 1);
1007     currSceneSession->property_->SetWindowType(WindowType::BELOW_APP_SYSTEM_WINDOW_BASE);
1008     currSceneSession->property_->SetPersistentId(3);
1009     ssm_->UpdateHighlightStatus(DEFAULT_DISPLAY_ID, preSceneSession, currSceneSession, false);
1010     ASSERT_EQ(ssm_->highlightIds_.size(), 2);
1011 }
1012 
1013 /**
1014  * @tc.name: SetHighlightSessionIds
1015  * @tc.desc: SetHighlightSessionIds
1016  * @tc.type: FUNC
1017  */
1018 HWTEST_F(SceneSessionManagerTest11, SetHighlightSessionIds, TestSize.Level1)
1019 {
1020     ASSERT_NE(ssm_, nullptr);
1021     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1022     SessionInfo info1;
1023     info1.abilityName_ = "abilityName_test1";
1024     info1.bundleName_ = "bundleName_test1";
1025 
1026     sptr<SceneSession> currSceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
1027     currSceneSession->property_ = property;
1028     currSceneSession->property_->SetPersistentId(1);
1029     currSceneSession->persistentId_ = 1;
1030     ssm_->highlightIds_.clear();
1031     ssm_->SetHighlightSessionIds(currSceneSession, false);
1032     ASSERT_EQ(ssm_->highlightIds_.count(1) == 1, true);
1033 }
1034 
1035 /**
1036  * @tc.name: AddHighlightSessionIds
1037  * @tc.desc: AddHighlightSessionIds
1038  * @tc.type: FUNC
1039  */
1040 HWTEST_F(SceneSessionManagerTest11, AddHighlightSessionIds, TestSize.Level1)
1041 {
1042     ASSERT_NE(ssm_, nullptr);
1043     sptr<WindowSessionProperty> property1 = sptr<WindowSessionProperty>::MakeSptr();
1044     sptr<WindowSessionProperty> property2 = sptr<WindowSessionProperty>::MakeSptr();
1045 
1046     SessionInfo info1;
1047     info1.abilityName_ = "abilityName_test1";
1048     info1.bundleName_ = "bundleName_test1";
1049 
1050     SessionInfo info2;
1051     info2.abilityName_ = "abilityName_test2";
1052     info2.bundleName_ = "bundleName_test2";
1053 
1054     sptr<SceneSession> preSceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
1055     sptr<SceneSession> currSceneSession = sptr<SceneSession>::MakeSptr(info2, nullptr);
1056 
1057     preSceneSession->property_->SetPersistentId(1);
1058     currSceneSession->property_->SetPersistentId(2);
1059     preSceneSession->persistentId_ = 1;
1060     currSceneSession->persistentId_ = 2;
1061     preSceneSession->property_ = property1;
1062     currSceneSession->property_ = property2;
1063     ssm_->AddHighlightSessionIds(currSceneSession, false);
1064     ssm_->AddHighlightSessionIds(preSceneSession, false);
1065     ASSERT_EQ(ssm_->highlightIds_.count(1) == 1, true);
1066     ASSERT_EQ(ssm_->highlightIds_.count(2) == 1, true);
1067 }
1068 
1069 /**
1070  * @tc.name: RemoveHighlightSessionIds
1071  * @tc.desc: RemoveHighlightSessionIds
1072  * @tc.type: FUNC
1073  */
1074 HWTEST_F(SceneSessionManagerTest11, RemoveHighlightSessionIds, TestSize.Level1)
1075 {
1076     ASSERT_NE(ssm_, nullptr);
1077     sptr<WindowSessionProperty> property1 = sptr<WindowSessionProperty>::MakeSptr();
1078     sptr<WindowSessionProperty> property2 = sptr<WindowSessionProperty>::MakeSptr();
1079 
1080     SessionInfo info1;
1081     info1.abilityName_ = "abilityName_test1";
1082     info1.bundleName_ = "bundleName_test1";
1083 
1084     SessionInfo info2;
1085     info2.abilityName_ = "abilityName_test2";
1086     info2.bundleName_ = "bundleName_test2";
1087 
1088     sptr<SceneSession> preSceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
1089     sptr<SceneSession> currSceneSession = sptr<SceneSession>::MakeSptr(info2, nullptr);
1090 
1091     preSceneSession->property_->SetPersistentId(1);
1092     currSceneSession->property_->SetPersistentId(2);
1093 
1094     preSceneSession->persistentId_ = 1;
1095     currSceneSession->persistentId_ = 2;
1096 
1097     preSceneSession->property_ = property1;
1098     currSceneSession->property_ = property2;
1099     ssm_->AddHighlightSessionIds(currSceneSession, false);
1100     ssm_->AddHighlightSessionIds(preSceneSession, false);
1101     ASSERT_EQ(ssm_->highlightIds_.count(1) == 1, true);
1102     ASSERT_EQ(ssm_->highlightIds_.count(2) == 1, true);
1103     ssm_->RemoveHighlightSessionIds(currSceneSession);
1104     ASSERT_EQ(ssm_->highlightIds_.count(2) == 0, true);
1105     ssm_->RemoveHighlightSessionIds(preSceneSession);
1106     ASSERT_EQ(ssm_->highlightIds_.count(1) == 0, true);
1107 }
1108 
1109 /**
1110  * @tc.name: RemoveLifeCycleTaskByPersistentId
1111  * @tc.desc: test RemoveLifeCycleTaskByPersistentId
1112  * @tc.type: FUNC
1113  */
1114 HWTEST_F(SceneSessionManagerTest11, RemoveLifeCycleTaskByPersistentId, TestSize.Level1)
1115 {
1116     SessionInfo info;
1117     info.abilityName_ = "testAbilityName1";
1118     info.moduleName_ = "testModleName1";
1119     info.bundleName_ = "testBundleName1";
1120     info.persistentId_ = 100;
1121 
1122     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1123     EXPECT_NE(sceneSession, nullptr);
1124     ssm_->sceneSessionMap_.emplace(100, sceneSession);
1125 
__anon87c08a680a02() 1126     auto task = []() {};
1127     sceneSession->PostLifeCycleTask(task, "task1", LifeCycleTaskType::START);
1128     ASSERT_EQ(sceneSession->lifeCycleTaskQueue_.size(), 1);
1129     ssm_->RemoveLifeCycleTaskByPersistentId(100, LifeCycleTaskType::START);
1130     ASSERT_EQ(sceneSession->lifeCycleTaskQueue_.size(), 0);
1131 
1132     sceneSession->PostLifeCycleTask(task, "task1", LifeCycleTaskType::START);
1133     ASSERT_EQ(sceneSession->lifeCycleTaskQueue_.size(), 1);
1134     ssm_->RemoveLifeCycleTaskByPersistentId(3, LifeCycleTaskType::START);
1135     ASSERT_EQ(sceneSession->lifeCycleTaskQueue_.size(), 1);
1136 }
1137 
1138 /**
1139  * @tc.name: SetStatusBarAvoidHeight
1140  * @tc.desc: test function : SetStatusBarAvoidHeight
1141  * @tc.type: FUNC
1142  */
1143 HWTEST_F(SceneSessionManagerTest11, SetStatusBarAvoidHeight, TestSize.Level1)
1144 {
1145     int32_t height = 10;
1146     int32_t height2 = -1;
1147     ssm_->SetStatusBarAvoidHeight(0, height);
1148     ssm_->SetStatusBarAvoidHeight(1, height2);
1149     WSRect barArea = { 0, 0, 100, 100 };
1150     WSRect barArea2 = { 0, 0, 100, 100 };
1151     WSRect barArea3 = { 0, 0, 100, 100 };
1152     ssm_->GetStatusBarAvoidHeight(0, barArea);
1153     EXPECT_EQ(barArea.height_, height);
1154     ssm_->GetStatusBarAvoidHeight(1, barArea2);
1155     EXPECT_EQ(barArea2.height_, 100);
1156     ssm_->GetStatusBarAvoidHeight(2, barArea3);
1157     EXPECT_EQ(barArea3.height_, 100);
1158 }
1159 
1160 /**
1161  * @tc.name: QueryAbilityInfoFromBMSTest
1162  * @tc.desc: SceneSesionManager QueryAbilityInfoFromBMS NotifyStartAbility
1163  * @tc.type: FUNC
1164  */
1165 HWTEST_F(SceneSessionManagerTest11, QueryAbilityInfoFromBMSTest, TestSize.Level1)
1166 {
1167     const int32_t uId = 32;
1168     SessionInfo sessionInfo_;
1169     sessionInfo_.bundleName_ = "BundleName";
1170     sessionInfo_.abilityName_ = "AbilityName";
1171     sessionInfo_.moduleName_ = "ModuleName";
1172     ssm_->bundleMgr_ = nullptr;
1173 
1174     auto res = ssm_->QueryAbilityInfoFromBMS(
1175         uId, sessionInfo_.bundleName_, sessionInfo_.abilityName_, sessionInfo_.moduleName_);
1176     EXPECT_EQ(res, nullptr);
1177 }
1178 
1179 /**
1180  * @tc.name: QueryAbilityInfoFromBMSTest001
1181  * @tc.desc: SceneSesionManager QueryAbilityInfoFromBMS NotifyStartAbility
1182  * @tc.type: FUNC
1183  */
1184 HWTEST_F(SceneSessionManagerTest11, QueryAbilityInfoFromBMSTest001, TestSize.Level1)
1185 {
1186     const int32_t uId = 32;
1187     SessionInfo sessionInfo_;
1188     sessionInfo_.bundleName_ = "BundleName";
1189     sessionInfo_.abilityName_ = "AbilityName";
1190     sessionInfo_.moduleName_ = "ModuleName";
1191     ssm_->bundleMgr_ = ssm_->GetBundleManager();
1192     SceneSessionManager::SessionInfoList listKey = {
1193         .uid_ = uId, .bundleName_ = "BundleName", .abilityName_ = "AbilityName", .moduleName_ = "ModuleName"
1194     };
1195     ssm_->abilityInfoMap_[listKey] = std::make_shared<AppExecFwk::AbilityInfo>();
1196 
1197     auto res = ssm_->QueryAbilityInfoFromBMS(
1198         uId, sessionInfo_.bundleName_, sessionInfo_.abilityName_, sessionInfo_.moduleName_);
1199     EXPECT_NE(res, nullptr);
1200 }
1201 
1202 /**
1203  * @tc.name: QueryAbilityInfoFromBMSTest
1204  * @tc.desc: SceneSesionManager QueryAbilityInfoFromBMS AtomicFreeInstall query failed
1205  * @tc.type: FUNC
1206  */
1207 HWTEST_F(SceneSessionManagerTest11, QueryAbilityInfoFromBMSTest02, TestSize.Level1)
1208 {
1209     const int32_t uId = 32;
1210     SessionInfo sessionInfo_;
1211     sessionInfo_.bundleName_ = "BundleName";
1212     sessionInfo_.abilityName_ = "AbilityName";
1213     sessionInfo_.moduleName_ = "ModuleName";
1214     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
1215     EXPECT_CALL(*bundleMgrMocker, GetBundleInfoV9(_, _, _, _)).WillOnce(Return(1));
1216     ssm_->bundleMgr_ = bundleMgrMocker;
1217 
1218     auto res = ssm_->QueryAbilityInfoFromBMS(
1219         uId, sessionInfo_.bundleName_, sessionInfo_.abilityName_, sessionInfo_.moduleName_, true);
1220     EXPECT_EQ(res, nullptr);
1221 }
1222 
1223 /**
1224  * @tc.name: QueryAbilityInfoFromBMSTest
1225  * @tc.desc: SceneSesionManager QueryAbilityInfoFromBMS AtomicFreeInstall query failed hapModuleInfosis nullptr.
1226  * @tc.type: FUNC
1227  */
1228 HWTEST_F(SceneSessionManagerTest11, QueryAbilityInfoFromBMSTest03, TestSize.Level1)
1229 {
1230     const int32_t uId = 32;
1231     SessionInfo sessionInfo_;
1232     sessionInfo_.bundleName_ = "BundleName";
1233     sessionInfo_.abilityName_ = "AbilityName";
1234     sessionInfo_.moduleName_ = "ModuleName";
1235     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
1236     EXPECT_CALL(*bundleMgrMocker, GetBundleInfoV9(_, _, _, _))
__anon87c08a680b02(const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) 1237         .WillOnce([](const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) {
1238             bundleInfo.hapModuleInfos = {};
1239             return 0;
1240         });
1241     ssm_->bundleMgr_ = bundleMgrMocker;
1242 
1243     auto res = ssm_->QueryAbilityInfoFromBMS(
1244         uId, sessionInfo_.bundleName_, sessionInfo_.abilityName_, sessionInfo_.moduleName_, true);
1245     EXPECT_EQ(res, nullptr);
1246 }
1247 
1248 /**
1249  * @tc.name: QueryAbilityInfoFromBMSTest
1250  * @tc.desc: SceneSesionManager QueryAbilityInfoFromBMS AtomicFreeInstall query success.
1251  * @tc.type: FUNC
1252  */
1253 HWTEST_F(SceneSessionManagerTest11, QueryAbilityInfoFromBMSTest04, TestSize.Level1)
1254 {
1255     const int32_t uId = 32;
1256     SessionInfo sessionInfo_;
1257     sessionInfo_.bundleName_ = "BundleName";
1258     sessionInfo_.abilityName_ = "AbilityName";
1259     sessionInfo_.moduleName_ = "ModuleName";
1260     sptr<IBundleMgrMocker> bundleMgrMocker = sptr<IBundleMgrMocker>::MakeSptr();
1261     EXPECT_CALL(*bundleMgrMocker, GetBundleInfoV9(_, _, _, _))
__anon87c08a680c02(const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) 1262         .WillOnce([](const std::string& bundleName, int32_t flags, AppExecFwk::BundleInfo& bundleInfo, int32_t userId) {
1263             AppExecFwk::AbilityInfo abilityInfo;
1264             abilityInfo.moduleName = "moduleName";
1265             abilityInfo.name = "abilityName";
1266             AppExecFwk::HapModuleInfo hapModuleInfo;
1267             hapModuleInfo.abilityInfos = { abilityInfo };
1268             bundleInfo.hapModuleInfos = { hapModuleInfo };
1269             return 0;
1270         });
1271     ssm_->bundleMgr_ = bundleMgrMocker;
1272 
1273     auto res = ssm_->QueryAbilityInfoFromBMS(
1274         uId, sessionInfo_.bundleName_, sessionInfo_.abilityName_, sessionInfo_.moduleName_, true);
1275     ASSERT_EQ(res, nullptr);
1276     EXPECT_EQ(res->name, "abilityName");
1277     EXPECT_EQ(res->moduleName, "moduleName");
1278 }
1279 
1280 /**
1281  * @tc.name: RequestFocusSpecificCheckTest
1282  * @tc.desc: Test for RequestFocusSpecificCheck
1283  * @tc.type: FUNC
1284  */
1285 HWTEST_F(SceneSessionManagerTest11, RequestFocusSpecificCheckTest, TestSize.Level1)
1286 {
1287     ASSERT_NE(ssm_, nullptr);
1288     SessionInfo info;
1289     info.abilityName_ = "test1";
1290     info.bundleName_ = "test2";
1291     bool byForeground = true;
1292     FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST;
1293 
1294     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1295     sptr<Session> session = sptr<Session>::MakeSptr(info);
1296     session->persistentId_ = 1;
1297     sceneSession->dialogVec_.push_back(session);
1298     ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 1);
1299     sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
1300 
1301     WSError result = ssm_->RequestFocusSpecificCheck(DEFAULT_DISPLAY_ID, sceneSession, byForeground, reason);
1302     EXPECT_EQ(result, WSError::WS_DO_NOTHING);
1303 }
1304 
1305 /**
1306  * @tc.name: NotifyUnFocusedByMissionTest001
1307  * @tc.desc: Test for NotifyUnFocusedByMission
1308  * @tc.type: FUNC
1309  */
1310 HWTEST_F(SceneSessionManagerTest11, NotifyUnFocusedByMissionTest001, TestSize.Level1)
1311 {
1312     sptr<SceneSession> sceneSession;
1313     ssm_->NotifyUnFocusedByMission(sceneSession);
1314     EXPECT_EQ(sceneSession, nullptr);
1315 }
1316 
1317 /**
1318  * @tc.name: NotifyUnFocusedByMissionTest002
1319  * @tc.desc: Test for NotifyUnFocusedByMission
1320  * @tc.type: FUNC
1321  */
1322 HWTEST_F(SceneSessionManagerTest11, NotifyUnFocusedByMissionTest002, TestSize.Level1)
1323 {
1324     SessionInfo info;
1325     info.bundleName_ = "NotifyUnFocusedByMission";
1326     info.abilityName_ = "NotifyUnFocusedByMission";
1327     info.isSystem_ = true;
1328     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1329     ssm_->NotifyUnFocusedByMission(sceneSession);
1330     EXPECT_EQ(sceneSession->GetSessionInfo().isSystem_, true);
1331 }
1332 
1333 /**
1334  * @tc.name: NotifyUnFocusedByMissionTest003
1335  * @tc.desc: Test for NotifyUnFocusedByMission
1336  * @tc.type: FUNC
1337  */
1338 HWTEST_F(SceneSessionManagerTest11, NotifyUnFocusedByMissionTest003, TestSize.Level1)
1339 {
1340     SessionInfo info;
1341     info.bundleName_ = "NotifyUnFocusedByMission";
1342     info.abilityName_ = "NotifyUnFocusedByMission";
1343     info.isSystem_ = false;
1344     ssm_->listenerController_ = std::make_shared<SessionListenerController>();
1345     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1346     ssm_->NotifyUnFocusedByMission(sceneSession);
1347     EXPECT_EQ(sceneSession->GetSessionInfo().isSystem_, false);
1348 }
1349 
1350 /**
1351  * @tc.name: NotifyStackEmptyTest
1352  * @tc.desc: test function : NotifyStackEmpty
1353  * @tc.type: FUNC
1354  */
1355 HWTEST_F(SceneSessionManagerTest11, NotifyStackEmptyTest, TestSize.Level1)
1356 {
1357     SessionInfo info;
1358     info.bundleName_ = "NotifyStackEmpty";
1359     info.abilityName_ = "NotifyStackEmpty";
1360     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1361     int persistentId = 1112;
1362     sceneSession->property_->SetPersistentId(persistentId);
1363     auto ret = ssm_->NotifyStackEmpty(persistentId);
1364     usleep(WAIT_SYNC_IN_NS);
1365     EXPECT_EQ(ret, WSError::WS_OK);
1366 }
1367 
1368 /**
1369  * @tc.name: AddSkipSelfWhenShowOnVirtualScreenList
1370  * @tc.desc: test function : AddSkipSelfWhenShowOnVirtualScreenList
1371  * @tc.type: FUNC
1372  */
1373 HWTEST_F(SceneSessionManagerTest11, AddSkipSelfWhenShowOnVirtualScreenList, Function | SmallTest | Level1)
1374 {
1375     SessionInfo info;
1376     info.bundleName_ = "AddSkipSelfWhenShowOnVirtualScreenList";
1377     info.abilityName_ = "AddSkipSelfWhenShowOnVirtualScreenList";
1378     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1379     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1380     std::vector<int32_t> persistentIds{ sceneSession->GetPersistentId() };
1381     MockAccesstokenKit::MockIsSACalling(false);
1382     MockAccesstokenKit::MockIsSystemApp(false);
1383     auto ret = ssm_->AddSkipSelfWhenShowOnVirtualScreenList(persistentIds);
1384     EXPECT_EQ(ret, WMError::WM_ERROR_NOT_SYSTEM_APP);
1385 
1386     MockAccesstokenKit::MockIsSACalling(true);
1387     MockAccesstokenKit::MockIsSystemApp(true);
1388     ret = ssm_->AddSkipSelfWhenShowOnVirtualScreenList(persistentIds);
1389     usleep(WAIT_SYNC_IN_NS);
1390     EXPECT_EQ(ret, WMError::WM_OK);
1391 }
1392 
1393 /**
1394  * @tc.name: RemoveSkipSelfWhenShowOnVirtualScreenList
1395  * @tc.desc: test function : RemoveSkipSelfWhenShowOnVirtualScreenList
1396  * @tc.type: FUNC
1397  */
1398 HWTEST_F(SceneSessionManagerTest11, RemoveSkipSelfWhenShowOnVirtualScreenList, Function | SmallTest | Level1)
1399 {
1400     SessionInfo info;
1401     info.bundleName_ = "RemoveSkipSelfWhenShowOnVirtualScreenList";
1402     info.abilityName_ = "RemoveSkipSelfWhenShowOnVirtualScreenList";
1403     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1404     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1405     std::vector<int32_t> persistentIds{ sceneSession->GetPersistentId() };
1406     MockAccesstokenKit::MockIsSACalling(false);
1407     MockAccesstokenKit::MockIsSystemApp(false);
1408     auto ret = ssm_->RemoveSkipSelfWhenShowOnVirtualScreenList(persistentIds);
1409     EXPECT_EQ(ret, WMError::WM_ERROR_NOT_SYSTEM_APP);
1410 
1411     MockAccesstokenKit::MockIsSACalling(true);
1412     MockAccesstokenKit::MockIsSystemApp(true);
1413     ret = ssm_->RemoveSkipSelfWhenShowOnVirtualScreenList(persistentIds);
1414     usleep(WAIT_SYNC_IN_NS);
1415     EXPECT_EQ(ret, WMError::WM_OK);
1416 }
1417 
1418 /**
1419  * @tc.name: GetHookedSessionByModuleName
1420  * @tc.desc: test function : GetHookedSessionByModuleName
1421  * @tc.type: FUNC
1422  */
1423 HWTEST_F(SceneSessionManagerTest11, GetHookedSessionByModuleName, Function | SmallTest | Level2)
1424 {
1425     SessionInfo info;
1426     info.bundleName_ = "testBundleName1";
1427     info.moduleName_ = "testModuleName1";
1428     info.appIndex_ = 1;
1429     info.appInstanceKey_ = "";
1430     sptr<SceneSession> sceneSession = sptr<MainSession>::MakeSptr(info, nullptr);
1431     ASSERT_NE(sceneSession, nullptr);
1432     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1433     auto res = ssm_->GetHookedSessionByModuleName(info);
1434     ASSERT_EQ(res, nullptr);
1435 
1436     ssm_->sceneSessionMap_.insert({ 101, sceneSession });
1437     res = ssm_->GetHookedSessionByModuleName(info);
1438     ASSERT_EQ(res, sceneSession);
1439 
1440     info.appInstanceKey_ = "testAppInstanceKey1";
1441     res = ssm_->GetHookedSessionByModuleName(info);
1442     ASSERT_EQ(res, nullptr);
1443 
1444     info.appIndex_ = 2;
1445     res = ssm_->GetHookedSessionByModuleName(info);
1446     ASSERT_EQ(res, nullptr);
1447 
1448     info.moduleName_ = "testModuleName2";
1449     res = ssm_->GetHookedSessionByModuleName(info);
1450     ASSERT_EQ(res, nullptr);
1451 
1452     info.bundleName_ = "testBundleName2";
1453     res = ssm_->GetHookedSessionByModuleName(info);
1454     ASSERT_EQ(res, nullptr);
1455 }
1456 
1457 /**
1458  * @tc.name: RequestSceneSession
1459  * @tc.desc: test function : RequestSceneSession
1460  * @tc.type: FUNC
1461  */
1462 HWTEST_F(SceneSessionManagerTest11, RequestSceneSession, Function | SmallTest | Level2)
1463 {
1464     SessionInfo info;
1465     info.bundleName_ = "request_scene_session_bundle";
1466     info.moduleName_ = "request_scene_session_module";
1467     info.abilityName_ = "request_scene_session_ability";
1468     info.persistentId_ = 101;
1469     info.appIndex_ = 0;
1470     sptr<SceneSession> sceneSession = sptr<MainSession>::MakeSptr(info, nullptr);
1471     ASSERT_NE(sceneSession, nullptr);
1472     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1473     sceneSession->sessionInfo_.isAbilityHook_ = true;
1474     sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
1475     ssm_->sceneSessionMap_[101] = sceneSession;
1476 
1477     auto result = ssm_->RequestSceneSession(info, windowSessionProperty);
1478     ASSERT_NE(result, nullptr);
1479     ASSERT_EQ(result->GetSessionInfo().moduleName_, info.moduleName_);
1480 }
1481 
1482 /**
1483  * @tc.name: UpdateAbilityHookState
1484  * @tc.desc: test function : UpdateAbilityHookState
1485  * @tc.type: FUNC
1486  */
1487 HWTEST_F(SceneSessionManagerTest11, UpdateAbilityHookState, Function | SmallTest | Level2)
1488 {
1489     SessionInfo info;
1490     info.bundleName_ = "UpdateAbilityHookState_bundle";
1491     info.moduleName_ = "UpdateAbilityHookState_module";
1492     info.abilityName_ = "UpdateAbilityHookState_ability";
1493     info.persistentId_ = 101;
1494     sptr<SceneSession> sceneSession = sptr<MainSession>::MakeSptr(info, nullptr);
1495     ASSERT_NE(sceneSession, nullptr);
1496 
1497     ssm_->UpdateAbilityHookState(sceneSession, true);
1498     EXPECT_EQ(true, sceneSession->GetSessionInfo().isAbilityHook_);
1499 }
1500 
1501 /**
1502  * @tc.name: UpdateRecentMainSessionInfos
1503  * @tc.desc: test function : UpdateRecentMainSessionInfos
1504  * @tc.type: FUNC
1505  */
1506 HWTEST_F(SceneSessionManagerTest11, UpdateRecentMainSessionInfos, Function | SmallTest | Level2)
1507 {
1508     const std::vector<int32_t> recentMainSessionIdList = { 101 };
1509     SessionInfo info;
1510     info.bundleName_ = "UpdateRecentMainSessionInfoList BundleName";
1511     info.moduleName_ = "UpdateRecentMainSessionInfoList ModuleName";
1512     info.abilityName_ = "UpdateRecentMainSessionInfoList AbilityName";
1513     info.persistentId_ = 101;
1514     info.appIndex_ = 0;
1515     sptr<SceneSession> sceneSession = sptr<MainSession>::MakeSptr(info, nullptr);
1516     ASSERT_NE(sceneSession, nullptr);
1517     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1518     ssm_->sceneSessionMap_[101] = sceneSession;
1519     ssm_->recentMainSessionInfoList_.clear();
1520     EXPECT_EQ(ssm_->recentMainSessionInfoList_.size(), 0);
1521     ssm_->UpdateRecentMainSessionInfos(recentMainSessionIdList);
1522     usleep(WAIT_SYNC_IN_NS);
1523     EXPECT_EQ(ssm_->recentMainSessionInfoList_.size(), 1);
1524 }
1525 
1526 /**
1527  * @tc.name: GetRecentMainSessionInfoList
1528  * @tc.desc: test function : GetRecentMainSessionInfoList
1529  * @tc.type: FUNC
1530  */
1531 HWTEST_F(SceneSessionManagerTest11, GetRecentMainSessionInfoList, Function | SmallTest | Level2)
1532 {
1533     std::vector<RecentSessionInfo> recentSessionInfoList = {};
1534     auto result = ssm_->GetRecentMainSessionInfoList(recentSessionInfoList);
1535     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1536 }
1537 
1538 /**
1539  * @tc.name: GetVisibilityWindowInfo
1540  * @tc.desc: test whether get the visibility window information
1541  * @tc.type: FUNC
1542  */
1543 HWTEST_F(SceneSessionManagerTest11, GetVisibilityWindowInfo, Function | SmallTest | Level2)
1544 {
1545     auto oldVisibleData = ssm_->lastVisibleData_;
1546     auto oldSessionMap = ssm_->sceneSessionMap_;
1547     SessionInfo sessionInfo;
1548     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1549     struct RSSurfaceNodeConfig surfaceNodeConfig;
1550     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(surfaceNodeConfig, RSSurfaceNodeType::DEFAULT);
1551     ASSERT_NE(surfaceNode, nullptr);
1552     sceneSession->SetSurfaceNode(surfaceNode);
1553     std::map<int32_t, sptr<SceneSession>> currSessionMap;
1554     currSessionMap.insert({ sceneSession->GetPersistentId(), sceneSession });
1555     ssm_->sceneSessionMap_ = currSessionMap;
1556     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
1557     currVisibleData.emplace_back(surfaceNode->GetId(), WindowVisibilityState::START);
1558     ssm_->lastVisibleData_ = currVisibleData;
1559     std::vector<sptr<WindowVisibilityInfo>> infos;
1560     auto result = ssm_->GetVisibilityWindowInfo(infos);
1561     EXPECT_EQ(result, WMError::WM_OK);
1562     EXPECT_EQ(infos.size(), 1);
1563     ssm_->lastVisibleData_ = oldVisibleData;
1564     ssm_->sceneSessionMap_ = oldSessionMap;
1565 }
1566 
1567 /**
1568  * @tc.name: SendPointerEventForHover
1569  * @tc.desc: SendPointerEventForHover
1570  * @tc.type: FUNC
1571  */
1572 HWTEST_F(SceneSessionManagerTest11, SendPointerEventForHover_Vaild, Function | SmallTest | Level2)
1573 {
1574     ASSERT_NE(nullptr, ssm_);
1575     ssm_->sceneSessionMap_.clear();
1576     MockAccesstokenKit::MockIsSACalling(false);
1577     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
1578     WSError ret = ssm_->SendPointerEventForHover(pointerEvent);
1579     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
1580 
1581     MockAccesstokenKit::MockIsSACalling(true);
1582     ret = ssm_->SendPointerEventForHover(pointerEvent);
1583     EXPECT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1584 
1585     pointerEvent = MMI::PointerEvent::Create();
1586     ret = ssm_->SendPointerEventForHover(pointerEvent);
1587     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1588 
1589     pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_HOVER_ENTER;
1590     pointerEvent->sourceType_ = MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
1591     pointerEvent->agentWindowId_ = 1;
1592     ret = ssm_->SendPointerEventForHover(pointerEvent);
1593     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
1594 }
1595 
1596 /**
1597  * @tc.name: SendPointerEventForHover_Success
1598  * @tc.desc: SendPointerEventForHover
1599  * @tc.type: FUNC
1600  */
1601 HWTEST_F(SceneSessionManagerTest11, SendPointerEventForHover_Success, Function | SmallTest | Level2)
1602 {
1603     ASSERT_NE(nullptr, ssm_);
1604     ssm_->sceneSessionMap_.clear();
1605     MockAccesstokenKit::MockIsSACalling(true);
1606     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
1607     pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_HOVER_ENTER;
1608     pointerEvent->sourceType_ = MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
1609     pointerEvent->agentWindowId_ = 1;
1610 
1611     SessionInfo sessionInfo;
1612     sessionInfo.bundleName_ = "SceneSessionManagerTest11";
1613     sessionInfo.abilityName_ = "SendPointerEventForHover";
1614     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1615     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1616     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1617     sceneSession->persistentId_ = 1;
1618     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1619     WSError ret = ssm_->SendPointerEventForHover(pointerEvent);
1620     EXPECT_EQ(ret, WSError::WS_OK);
1621 }
1622 
1623 /**
1624  * @tc.name: TestCheckSystemWindowPermission_Fb
1625  * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_FB then true
1626  * @tc.type: FUNC
1627  */
1628 HWTEST_F(SceneSessionManagerTest11, TestCheckSystemWindowPermission_Fb, TestSize.Level1)
1629 {
1630     ASSERT_NE(nullptr, ssm_);
1631     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1632 
1633     property->SetWindowType(WindowType::WINDOW_TYPE_FB);
1634     ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
1635 }
1636 
1637 /**
1638  * @tc.name: InitFbWindow
1639  * @tc.desc: test function : InitFbWindow
1640  * @tc.type: FUNC
1641  */
1642 HWTEST_F(SceneSessionManagerTest11, InitFbWindow, TestSize.Level1)
1643 {
1644     ASSERT_NE(nullptr, ssm_);
1645     SessionInfo sessionInfo;
1646     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1647     ASSERT_NE(nullptr, sceneSession);
1648 
1649     ssm_->InitFbWindow(sceneSession, nullptr);
1650 
1651     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1652     ASSERT_NE(nullptr, property);
1653     property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
1654     ssm_->InitFbWindow(sceneSession, property);
1655 
1656     property->SetWindowType(WindowType::WINDOW_TYPE_FB);
1657     ssm_->InitFbWindow(sceneSession, property);
1658     EXPECT_EQ(0, sceneSession->GetFbTemplateInfo().template_);
1659 }
1660 
1661 /**
1662  * @tc.name: GetFbPanelWindowId
1663  * @tc.desc: test function : GetFbPanelWindowId
1664  * @tc.type: FUNC
1665  */
1666 HWTEST_F(SceneSessionManagerTest11, GetFbPanelWindowId, TestSize.Level1)
1667 {
1668     ASSERT_NE(nullptr, ssm_);
1669     uint32_t windowId = 0;
1670     EXPECT_EQ(WMError::WM_ERROR_FB_INTERNAL_ERROR, ssm_->GetFbPanelWindowId(windowId));
1671     ssm_->sceneSessionMap_.insert({0, nullptr});
1672     ssm_->sceneSessionMap_.insert({1, CreateSceneSession("", WindowType::WINDOW_TYPE_PIP)});
1673     ssm_->sceneSessionMap_.insert({2, CreateSceneSession("SCBGlobalSearch7", WindowType::WINDOW_TYPE_FB)});
1674     sptr<SceneSession> sceneSession = CreateSceneSession("Fb_panel8", WindowType::WINDOW_TYPE_FB);
1675     ssm_->sceneSessionMap_.insert({3, sceneSession});
1676 
1677     MockAccesstokenKit::MockAccessTokenKitRet(0);
1678     EXPECT_EQ(WMError::WM_OK, ssm_->GetFbPanelWindowId(windowId));
1679     EXPECT_EQ(sceneSession->GetWindowId(), windowId);
1680     MockAccesstokenKit::MockAccessTokenKitRet(-1);
1681     ssm_->sceneSessionMap_.clear();
1682 }
1683 
1684 /**
1685  * @tc.name: ConfigSupportCreateFloatWindow
1686  * @tc.desc: test function : ConfigSupportCreateFloatWindow
1687  * @tc.type: FUNC
1688  */
1689 HWTEST_F(SceneSessionManagerTest11, ConfigSupportCreateFloatWindow, TestSize.Level0)
1690 {
1691     ASSERT_NE(nullptr, ssm_);
1692 
1693     ssm_->ConfigSupportCreateFloatWindow();
1694 
1695     usleep(WAIT_SYNC_IN_NS);
1696     EXPECT_TRUE(ssm_->systemConfig_.supportCreateFloatWindow_);
1697 }
1698 } // namespace
1699 } // namespace Rosen
1700 } // namespace OHOS