• 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 #include <regex>
18 #include <bundle_mgr_interface.h>
19 #include <bundlemgr/launcher_service.h>
20 #include "interfaces/include/ws_common.h"
21 #include "libxml/parser.h"
22 #include "libxml/tree.h"
23 #include "session_manager/include/scene_session_manager.h"
24 #include "session_info.h"
25 #include "session/host/include/scene_session.h"
26 #include "session/host/include/main_session.h"
27 #include "window_manager_agent.h"
28 #include "window_manager_hilog.h"
29 #include "session_manager.h"
30 #include "zidl/window_manager_agent_interface.h"
31 #include "mock/mock_accesstoken_kit.h"
32 #include "mock/mock_session_stage.h"
33 #include "mock/mock_window_event_channel.h"
34 #include "context.h"
35 #include "session_manager/include/scene_session_dirty_manager.h"
36 
37 using namespace testing;
38 using namespace testing::ext;
39 
40 namespace OHOS {
41 namespace Rosen {
42 namespace {
43     std::string g_logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)44     void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
45         const char *msg)
46     {
47         g_logMsg = msg;
48     }
49 }
50 namespace {
51 const std::string EMPTY_DEVICE_ID = "";
52 using ConfigItem = WindowSceneConfig::ConfigItem;
ReadConfig(const std::string & xmlStr)53 ConfigItem ReadConfig(const std::string& xmlStr)
54 {
55     ConfigItem config;
56     xmlDocPtr docPtr = xmlParseMemory(xmlStr.c_str(), xmlStr.length());
57     if (docPtr == nullptr) {
58         return config;
59     }
60 
61     xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
62     if (rootPtr == nullptr || rootPtr->name == nullptr ||
63         xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
64         xmlFreeDoc(docPtr);
65         return config;
66     }
67 
68     std::map<std::string, ConfigItem> configMap;
69     config.SetValue(configMap);
70     WindowSceneConfig::ReadConfig(rootPtr, *config.mapValue_);
71     xmlFreeDoc(docPtr);
72     return config;
73 }
74 } // namespace
75 class SceneSessionManagerTest3 : public testing::Test {
76 public:
77     static void SetUpTestCase();
78     static void TearDownTestCase();
79     void SetUp() override;
80     void TearDown() override;
81 
82     static bool gestureNavigationEnabled_;
83     static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
84     static sptr<SceneSessionManager> ssm_;
85 
86 private:
87     static constexpr uint32_t WAIT_SYNC_IN_NS = 50000;
88 };
89 
90 sptr<SceneSessionManager> SceneSessionManagerTest3::ssm_ = nullptr;
91 
92 bool SceneSessionManagerTest3::gestureNavigationEnabled_ = true;
93 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest3::callbackFunc_ =
__anonfc7e99f90302(bool enable, const std::string& bundleName, GestureBackType type) 94     [](bool enable, const std::string& bundleName, GestureBackType type) { gestureNavigationEnabled_ = enable; };
95 
WindowChangedFuncTest3(int32_t persistentId,WindowUpdateType type)96 void WindowChangedFuncTest3(int32_t persistentId, WindowUpdateType type) {}
97 
ProcessStatusBarEnabledChangeFuncTest(bool enable,const std::string & bundleName)98 void ProcessStatusBarEnabledChangeFuncTest(bool enable, const std::string& bundleName) {}
99 
SetUpTestCase()100 void SceneSessionManagerTest3::SetUpTestCase()
101 {
102     ssm_ = &SceneSessionManager::GetInstance();
103 }
104 
TearDownTestCase()105 void SceneSessionManagerTest3::TearDownTestCase()
106 {
107     ssm_ = nullptr;
108     usleep(WAIT_SYNC_IN_NS);
109 }
110 
SetUp()111 void SceneSessionManagerTest3::SetUp()
112 {
113     ssm_->sceneSessionMap_.clear();
114 }
115 
TearDown()116 void SceneSessionManagerTest3::TearDown()
117 {
118     MockAccesstokenKit::ChangeMockStateToInit();
119     ssm_->sceneSessionMap_.clear();
120     usleep(WAIT_SYNC_IN_NS);
121 }
122 
123 namespace {
124 /**
125  * @tc.name: ConfigDecor
126  * @tc.desc: SceneSesionManager config decor
127  * @tc.type: FUNC
128  */
129 HWTEST_F(SceneSessionManagerTest3, ConfigDecor, TestSize.Level1)
130 {
131     WindowSceneConfig::ConfigItem* item = new (std::nothrow) WindowSceneConfig::ConfigItem;
132     ASSERT_NE(nullptr, item);
133     int ret = 0;
134     ssm_->ConfigDecor(*item);
135     ASSERT_EQ(ret, 0);
136     delete item;
137 }
138 
139 /**
140  * @tc.name: ConfigWindowEffect
141  * @tc.desc: SceneSesionManager config window effect
142  * @tc.type: FUNC
143  */
144 HWTEST_F(SceneSessionManagerTest3, ConfigWindowEffect, TestSize.Level1)
145 {
146     WindowSceneConfig::ConfigItem* item = new (std::nothrow) WindowSceneConfig::ConfigItem;
147     ASSERT_NE(nullptr, item);
148     int ret = 0;
149     ssm_->ConfigWindowEffect(*item);
150     ASSERT_EQ(ret, 0);
151     delete item;
152 }
153 
154 /**
155  * @tc.name: ConfigAppWindowCornerRadius
156  * @tc.desc: SceneSesionManager config app window coener radius
157  * @tc.type: FUNC
158  */
159 HWTEST_F(SceneSessionManagerTest3, ConfigAppWindowCornerRadius, TestSize.Level1)
160 {
161     float out = 0.0f;
162     WindowSceneConfig::ConfigItem item01;
163     std::string str = "defaultCornerRadiusM";
164     item01.SetValue(str);
165     bool result01 = ssm_->ConfigAppWindowCornerRadius(item01, out);
166     ASSERT_EQ(result01, true);
167 
168     WindowSceneConfig::ConfigItem item02;
169     item02.SetValue(new string("defaultCornerRadiusS"));
170     bool result02 = ssm_->ConfigAppWindowCornerRadius(item02, out);
171     ASSERT_EQ(result02, false);
172     ASSERT_EQ(out, 12.0f);
173 }
174 
175 /**
176  * @tc.name: ConfigAppWindowShadow
177  * @tc.desc: SceneSesionManager config app window shadow
178  * @tc.type: FUNC
179  */
180 HWTEST_F(SceneSessionManagerTest3, ConfigAppWindowShadow, TestSize.Level1)
181 {
182     WindowSceneConfig::ConfigItem item;
183     WindowSceneConfig::ConfigItem shadowConfig;
184     WindowShadowConfig outShadow;
185     std::vector<float> floatTest = { 0.0f, 0.1f, 0.2f, 0.3f };
186     bool result01 = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
187     ASSERT_EQ(result01, true);
188 
189     item.SetValue(floatTest);
190     shadowConfig.SetValue({ { "radius", item } });
191     bool result02 = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
192     ASSERT_EQ(result02, false);
193     shadowConfig.SetValue({ { "alpha", item } });
194     bool result03 = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
195     ASSERT_EQ(result03, false);
196     shadowConfig.SetValue({ { "sffsetY", item } });
197     bool result04 = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
198     ASSERT_EQ(result04, true);
199     shadowConfig.SetValue({ { "sffsetX", item } });
200     bool result05 = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
201     ASSERT_EQ(result05, true);
202 
203     item.SetValue(new std::string("color"));
204     shadowConfig.SetValue({ { "color", item } });
205     bool result06 = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
206     ASSERT_EQ(result06, true);
207 }
208 
209 /**
210  * @tc.name: ConfigStatusBar
211  * @tc.desc: ConfigStatusBar config window immersive status bar
212  * @tc.type: FUNC
213  */
214 HWTEST_F(SceneSessionManagerTest3, ConfigStatusBar, TestSize.Level1)
215 {
216     StatusBarConfig out;
217     WindowSceneConfig::ConfigItem enable;
218     enable.SetValue(true);
219     WindowSceneConfig::ConfigItem showHide;
220     showHide.SetProperty({ { "enable", enable } });
221     WindowSceneConfig::ConfigItem item01;
222     WindowSceneConfig::ConfigItem contentColor;
223     contentColor.SetValue(std::string("#12345678"));
224     WindowSceneConfig::ConfigItem backgroundColor;
225     backgroundColor.SetValue(std::string("#12345678"));
226     item01.SetValue(
227         { { "showHide", showHide }, { "contentColor", contentColor }, { "backgroundColor", backgroundColor } });
228     bool result01 = ssm_->ConfigStatusBar(item01, out);
229     ASSERT_EQ(result01, true);
230     ASSERT_EQ(out.showHide_, true);
231     ASSERT_EQ(out.contentColor_, "#12345678");
232     ASSERT_EQ(out.backgroundColor_, "#12345678");
233 }
234 
235 /**
236  * @tc.name: ConfigKeyboardAnimation
237  * @tc.desc: SceneSesionManager config keyboard animation
238  * @tc.type: FUNC
239  */
240 HWTEST_F(SceneSessionManagerTest3, ConfigWindowImmersive, TestSize.Level1)
241 {
242     std::string xmlStr =
243         "<?xml version='1.0' encoding=\"utf-8\"?>"
244         "<Configs>"
245         "<immersive>"
246         "<inDesktopStatusBarConfig>"
247         "<showHide enable=\"true\"/>"
248         "<backgroundColor>#12341234</backgroundColor>"
249         "<contentColor>#12341234</contentColor>"
250         "</inDesktopStatusBarConfig>"
251         "<inSplitStatusBarConfig>"
252         "<upDownSplit>"
253         "<showHide enable=\"true\"/>"
254         "<backgroundColor>#12341234</backgroundColor>"
255         "<contentColor>#12341234</contentColor>"
256         "</upDownSplit>"
257         "<leftRightSplit>"
258         "<showHide enable=\"true\"/>"
259         "<backgroundColor>#12341234</backgroundColor>"
260         "<contentColor>#12341234</contentColor>"
261         "</leftRightSplit>"
262         "</inSplitStatusBarConfig>"
263         "</immersive>"
264         "</Configs>";
265     WindowSceneConfig::config_ = ReadConfig(xmlStr);
266     ssm_->ConfigWindowSceneXml();
267     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.desktopStatusBarConfig_.showHide_, true);
268     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.desktopStatusBarConfig_.backgroundColor_, "#12341234");
269     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.desktopStatusBarConfig_.contentColor_, "#12341234");
270     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.upDownStatusBarConfig_.showHide_, true);
271     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.upDownStatusBarConfig_.backgroundColor_, "#12341234");
272     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.upDownStatusBarConfig_.contentColor_, "#12341234");
273     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.leftRightStatusBarConfig_.showHide_, true);
274     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.leftRightStatusBarConfig_.backgroundColor_, "#12341234");
275     ASSERT_EQ(ssm_->appWindowSceneConfig_.windowImmersive_.leftRightStatusBarConfig_.contentColor_, "#12341234");
276 }
277 
278 /**
279  * @tc.name: ConfigWindowAnimation
280  * @tc.desc: SceneSesionManager config window animation
281  * @tc.type: FUNC
282  */
283 HWTEST_F(SceneSessionManagerTest3, ConfigWindowAnimation, TestSize.Level1)
284 {
285     WindowSceneConfig::ConfigItem windowAnimationConfig;
286     WindowSceneConfig::ConfigItem item;
287     std::vector<float> opacity = { 0.1f };
288     std::vector<float> translate = { 0.1f, 0.2f };
289     std::vector<float> rotation = { 0.1f, 0.2f, 0.3f, 0.4f };
290     std::vector<float> scale = { 0.1f, 0.2f };
291     std::vector<int> duration = { 39 };
292 
293     item.SetValue(opacity);
294     windowAnimationConfig.SetValue({ { "opacity", item } });
295     int ret = 0;
296     ssm_->ConfigWindowAnimation(windowAnimationConfig);
297     ASSERT_EQ(ret, 0);
298 
299     item.SetValue(rotation);
300     windowAnimationConfig.SetValue({ { "rotation", item } });
301     ssm_->ConfigWindowAnimation(windowAnimationConfig);
302     ASSERT_EQ(ret, 0);
303 
304     item.SetValue(translate);
305     windowAnimationConfig.SetValue({ { "translate", item } });
306     ssm_->ConfigWindowAnimation(windowAnimationConfig);
307     ASSERT_EQ(ret, 0);
308 
309     item.SetValue(scale);
310     windowAnimationConfig.SetValue({ { "scale", item } });
311     ssm_->ConfigWindowAnimation(windowAnimationConfig);
312     ASSERT_EQ(ret, 0);
313 
314     item.SetValue(duration);
315     item.SetValue({ { "duration", item } });
316     windowAnimationConfig.SetValue({ { "timing", item } });
317     ssm_->ConfigWindowAnimation(windowAnimationConfig);
318     ASSERT_EQ(ret, 0);
319 
320     item.SetValue(duration);
321     item.SetValue({ { "curve", item } });
322     windowAnimationConfig.SetValue({ { "timing", item } });
323     ssm_->ConfigWindowAnimation(windowAnimationConfig);
324     ASSERT_EQ(ret, 0);
325 }
326 
327 /**
328  * @tc.name: RecoverAndReconnectSceneSession
329  * @tc.desc: check func RecoverAndReconnectSceneSession
330  * @tc.type: FUNC
331  */
332 HWTEST_F(SceneSessionManagerTest3, RecoverAndReconnectSceneSession, TestSize.Level1)
333 {
334     sptr<ISession> session;
335     auto result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, nullptr, nullptr);
336     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
337 
338     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
339     ASSERT_NE(nullptr, property);
340     std::vector<int32_t> recoveredPersistentIds = { 0, 1, 2 };
341     ssm_->SetAlivePersistentIds(recoveredPersistentIds);
342     property->SetPersistentId(1);
343     result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr);
344     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
345 }
346 
347 /**
348  * @tc.name: ConfigStartingWindowAnimation
349  * @tc.desc: SceneSesionManager config start window animation
350  * @tc.type: FUNC
351  */
352 HWTEST_F(SceneSessionManagerTest3, ConfigStartingWindowAnimation, TestSize.Level1)
353 {
354     std::vector<float> midFloat = { 0.1f };
355     std::vector<int> midInt = { 1 };
356     WindowSceneConfig::ConfigItem middleFloat;
357     middleFloat.SetValue(midFloat);
358     WindowSceneConfig::ConfigItem middleInt;
359     middleInt.SetValue(midInt);
360     WindowSceneConfig::ConfigItem curve;
361     curve.SetValue(midFloat);
362     curve.SetValue({ { "curve", curve } });
363     WindowSceneConfig::ConfigItem enableConfigItem;
364     enableConfigItem.SetValue(false);
365     std::map<std::string, WindowSceneConfig::ConfigItem> midMap = { { "duration", middleInt }, { "curve", curve } };
366     WindowSceneConfig::ConfigItem timing;
367     timing.SetValue(midMap);
368     std::map<std::string, WindowSceneConfig::ConfigItem> middleMap = { { "enable", enableConfigItem },
369                                                                        { "timing", timing },
370                                                                        { "opacityStart", middleFloat },
371                                                                        { "opacityEnd", middleFloat } };
372     WindowSceneConfig::ConfigItem configItem;
373     configItem.SetValue(middleMap);
374     int ret = 0;
375     ssm_->ConfigStartingWindowAnimation(configItem);
376     ASSERT_EQ(ret, 0);
377     midMap.clear();
378     middleMap.clear();
379 }
380 
381 /**
382  * @tc.name: CreateCurve
383  * @tc.desc: SceneSesionManager create curve
384  * @tc.type: FUNC
385  */
386 HWTEST_F(SceneSessionManagerTest3, CreateCurve, TestSize.Level1)
387 {
388     WindowSceneConfig::ConfigItem curveConfig;
389     std::string result01 = std::get<std::string>(ssm_->CreateCurve(curveConfig));
390     ASSERT_EQ(result01, "easeOut");
391 
392     std::string value02 = "userName";
393     curveConfig.SetValue(value02);
394     curveConfig.SetValue({ { "name", curveConfig } });
395     std::string result02 = std::get<std::string>(ssm_->CreateCurve(curveConfig));
396     ASSERT_EQ(result02, "easeOut");
397 
398     std::string value03 = "interactiveSpring";
399     curveConfig.SetValue(value03);
400     curveConfig.SetValue({ { "name", curveConfig } });
401     std::string result03 = std::get<std::string>(ssm_->CreateCurve(curveConfig));
402     ASSERT_EQ(result03, "easeOut");
403 
404     std::string value04 = "cubic";
405     curveConfig.SetValue(value04);
406     curveConfig.SetValue({ { "name", curveConfig } });
407     std::string result04 = std::get<std::string>(ssm_->CreateCurve(curveConfig));
408     ASSERT_EQ(result04, "easeOut");
409 }
410 
411 /**
412  * @tc.name: SetRootSceneContext
413  * @tc.desc: SceneSesionManager set root scene context
414  * @tc.type: FUNC
415  */
416 HWTEST_F(SceneSessionManagerTest3, SetRootSceneContext, TestSize.Level1)
417 {
418     int ret = 0;
419     std::weak_ptr<AbilityRuntime::Context> contextWeakPtr;
420     ssm_->SetRootSceneContext(contextWeakPtr);
421     ASSERT_EQ(ret, 0);
422 }
423 
424 /**
425  * @tc.name: GetRootSceneSession
426  * @tc.desc: SceneSesionManager get root scene session
427  * @tc.type: FUNC
428  */
429 HWTEST_F(SceneSessionManagerTest3, GetRootSceneSession, TestSize.Level1)
430 {
431     int ret = 0;
432     ssm_->GetRootSceneSession();
433     ssm_->GetRootSceneSession();
434     ASSERT_EQ(ret, 0);
435 }
436 
437 /**
438  * @tc.name: GetSceneSession
439  * @tc.desc: SceneSesionManager get scene session
440  * @tc.type: FUNC
441  */
442 HWTEST_F(SceneSessionManagerTest3, GetSceneSession, TestSize.Level1)
443 {
444     int32_t persistentId = 65535;
445     ASSERT_EQ(ssm_->GetSceneSession(persistentId), nullptr);
446 }
447 
448 /**
449  * @tc.name: GetSceneSession002
450  * @tc.desc: SceneSesionManager get scene session
451  * @tc.type: FUNC
452  */
453 HWTEST_F(SceneSessionManagerTest3, GetSceneSession002, TestSize.Level1)
454 {
455     SessionInfo info;
456     info.abilityName_ = "test1";
457     info.bundleName_ = "test2";
458     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
459     ASSERT_NE(sceneSession, nullptr);
460     ssm_->sceneSessionMap_.insert({ 65535, sceneSession });
461     int32_t persistentId = 65535;
462     ASSERT_NE(ssm_->GetSceneSession(persistentId), nullptr);
463 }
464 
465 /**
466  * @tc.name: GetSceneSessionByIdentityInfo
467  * @tc.desc: SceneSesionManager get scene session by name
468  * @tc.type: FUNC
469  */
470 HWTEST_F(SceneSessionManagerTest3, GetSceneSessionByIdentityInfo, TestSize.Level1)
471 {
472     SessionInfo info;
473     info.abilityName_ = "test1";
474     info.bundleName_ = "test2";
475     info.moduleName_ = "test3";
476     info.appIndex_ = 10;
477     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
478     ASSERT_NE(sceneSession, nullptr);
479     std::string bundleName1 = "test1";
480     std::string moduleName1 = "test2";
481     std::string abilityName1 = "test3";
482     int32_t appIndex1 = 10;
483     SessionIdentityInfo identityInfo = { bundleName1, moduleName1, abilityName1, appIndex1 };
484     ASSERT_EQ(ssm_->GetSceneSessionByIdentityInfo(identityInfo), nullptr);
485     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
486     std::string bundleName2 = "test11";
487     std::string moduleName2 = "test22";
488     std::string abilityName2 = "test33";
489     int32_t appIndex2 = 100;
490     ASSERT_EQ(ssm_->GetSceneSessionByIdentityInfo(identityInfo), nullptr);
491     identityInfo = { bundleName1, moduleName2, abilityName2, appIndex2 };
492     ASSERT_EQ(ssm_->GetSceneSessionByIdentityInfo(identityInfo), nullptr);
493     identityInfo = { bundleName2, moduleName1, abilityName2, appIndex2 };
494     ASSERT_EQ(ssm_->GetSceneSessionByIdentityInfo(identityInfo), nullptr);
495     identityInfo = { bundleName2, moduleName2, abilityName1, appIndex2 };
496     ASSERT_EQ(ssm_->GetSceneSessionByIdentityInfo(identityInfo), nullptr);
497     identityInfo = { bundleName2, moduleName2, abilityName2, appIndex1 };
498     ASSERT_EQ(ssm_->GetSceneSessionByIdentityInfo(identityInfo), nullptr);
499     ssm_->sceneSessionMap_.erase(1);
500 }
501 
502 /**
503  * @tc.name: GetSceneSessionVectorByTypeAndDisplayId
504  * @tc.desc: SceneSesionManager get scene session vector by type
505  * @tc.type: FUNC
506  */
507 HWTEST_F(SceneSessionManagerTest3, GetSceneSessionVectorByTypeAndDisplayId, TestSize.Level1)
508 {
509     g_logMsg.clear();
510     LOG_SetCallback(MyLogCallback);
511     uint64_t displayId = -1ULL;
512     ssm_->GetSceneSessionVectorByTypeAndDisplayId(WindowType::APP_MAIN_WINDOW_BASE, displayId);
513     displayId = 1;
514     ssm_->GetSceneSessionVectorByTypeAndDisplayId(WindowType::APP_MAIN_WINDOW_BASE, displayId);
515     SessionInfo info;
516     info.abilityName_ = "test1";
517     info.bundleName_ = "test2";
518     info.moduleName_ = "test3";
519     info.appIndex_ = 10;
520     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
521     ASSERT_NE(sceneSession, nullptr);
522     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
523     ssm_->GetSceneSessionVectorByTypeAndDisplayId(WindowType::APP_MAIN_WINDOW_BASE, displayId);
524     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
525     ssm_->GetSceneSessionVectorByTypeAndDisplayId(WindowType::APP_MAIN_WINDOW_BASE, displayId);
526     sceneSession->property_->SetDisplayId(1);
527     ssm_->GetSceneSessionVectorByTypeAndDisplayId(WindowType::APP_MAIN_WINDOW_BASE, displayId);
528     ssm_->sceneSessionMap_.erase(1);
529     EXPECT_FALSE(g_logMsg.find("displayId is invalid") != std::string::npos);
530     LOG_SetCallback(nullptr);
531 }
532 
533 /**
534  * @tc.name: GetWindowLimits
535  * @tc.desc: GetWindowLimits
536  * @tc.type: FUNC
537  */
538 HWTEST_F(SceneSessionManagerTest3, GetWindowLimits, TestSize.Level1)
539 {
540     SessionInfo info;
541     info.abilityName_ = "test1";
542     info.bundleName_ = "test2";
543     info.moduleName_ = "test3";
544     info.appIndex_ = 10;
545     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
546     ASSERT_NE(nullptr, sceneSession);
547     WindowLimits limits;
548     limits.maxHeight_ = 1000;
549     limits.minHeight_ = 500;
550     limits.maxWidth_ = 1000;
551     limits.minWidth_ = 500;
552     sceneSession->property_->SetWindowLimits(limits);
553 
554     int32_t windowId = 1;
555     WindowLimits windowlimits;
556     ssm_->sceneSessionMap_.insert({ windowId, sceneSession });
557     auto defaultUIType = ssm_->systemConfig_.windowUIType_;
558     ssm_->systemConfig_.windowUIType_ = WindowUIType::INVALID_WINDOW;
559     ssm_->systemConfig_.freeMultiWindowEnable_ = false;
560     ssm_->systemConfig_.freeMultiWindowSupport_ = false;
561     auto ret = ssm_->GetWindowLimits(windowId, windowlimits);
562     ASSERT_EQ(ret, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
563 
564     ssm_->systemConfig_.freeMultiWindowEnable_ = true;
565     ssm_->systemConfig_.freeMultiWindowSupport_ = true;
566     ret = ssm_->GetWindowLimits(windowId, windowlimits);
567     ASSERT_EQ(ret, WMError::WM_OK);
568 
569     ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
570     ret = ssm_->GetWindowLimits(windowId, windowlimits);
571     ssm_->sceneSessionMap_.erase(windowId);
572     ssm_->systemConfig_.windowUIType_ = defaultUIType;
573     ASSERT_EQ(ret, WMError::WM_OK);
574     ASSERT_EQ(windowlimits.maxHeight_, 1000);
575     ASSERT_EQ(windowlimits.minHeight_, 500);
576     ASSERT_EQ(windowlimits.maxWidth_, 1000);
577     ASSERT_EQ(windowlimits.minWidth_, 500);
578 }
579 
580 /**
581  * @tc.name: CheckWindowId
582  * @tc.desc: CheckWindowId
583  * @tc.type: FUNC
584  */
585 HWTEST_F(SceneSessionManagerTest3, CheckWindowId, TestSize.Level1)
586 {
587     int ret = 0;
588     int32_t windowId = 1;
589     int32_t pid = 2;
590     ssm_->CheckWindowId(windowId, pid);
591     ssm_->sceneSessionMap_.insert({ windowId, nullptr });
592     ssm_->CheckWindowId(windowId, pid);
593     SessionInfo info;
594     info.abilityName_ = "test1";
595     info.bundleName_ = "test2";
596     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
597     ASSERT_NE(nullptr, sceneSession);
598     ssm_->sceneSessionMap_.insert({ windowId, sceneSession });
599     ssm_->CheckWindowId(windowId, pid);
600     ssm_->PerformRegisterInRequestSceneSession(sceneSession);
601     ssm_->sceneSessionMap_.erase(windowId);
602     ASSERT_EQ(ret, 0);
603 }
604 
605 /**
606  * @tc.name: CheckAppIsInDisplay
607  * @tc.desc: CheckAppIsInDisplay
608  * @tc.type: FUNC
609  */
610 HWTEST_F(SceneSessionManagerTest3, CheckAppIsInDisplay, TestSize.Level1)
611 {
612     int ret = 0;
613     sptr<SceneSession> sceneSession;
614     ssm_->RequestSceneSessionActivation(sceneSession, true);
615     SessionInfo info;
616     ret++;
617     ssm_->DestroyDialogWithMainWindow(sceneSession);
618     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
619     ASSERT_NE(nullptr, sceneSession);
620     ssm_->DestroyDialogWithMainWindow(sceneSession);
621     ssm_->DestroySubSession(sceneSession);
622     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
623     ASSERT_NE(nullptr, property);
624     sceneSession->SetSessionProperty(property);
625     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
626     property->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
627     AppExecFwk::Configuration config;
628     ssm_->SetAbilitySessionInfo(sceneSession);
629     bool res = true;
630     ssm_->PrepareTerminate(1, res);
631     ssm_->isPrepareTerminateEnable_ = true;
632     ssm_->PrepareTerminate(1, res);
633     ssm_->isPrepareTerminateEnable_ = false;
634     ssm_->PrepareTerminate(1, res);
635     ssm_->StartUIAbilityBySCB(sceneSession);
636     ssm_->sceneSessionMap_.insert({ 1, nullptr });
637     ssm_->IsKeyboardForeground();
638     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
639     ssm_->NotifyForegroundInteractiveStatus(sceneSession, true);
640     ssm_->NotifyForegroundInteractiveStatus(sceneSession, false);
641     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
642     ssm_->IsKeyboardForeground();
643     ssm_->StartUIAbilityBySCB(sceneSession);
644     ssm_->PrepareTerminate(1, res);
645     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
646     ssm_->DestroyDialogWithMainWindow(sceneSession);
647     ssm_->sceneSessionMap_.erase(1);
648     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
649     ASSERT_NE(nullptr, abilitySessionInfo);
650     ssm_->StartUIAbilityBySCB(abilitySessionInfo, sceneSession);
651     ssm_->DestroySubSession(sceneSession);
652     ssm_->EraseSceneSessionMapById(2);
653     ASSERT_EQ(ret, 1);
654 }
655 
656 /**
657  * @tc.name: StartUIAbilityBySCB
658  * @tc.desc: StartUIAbilityBySCB
659  * @tc.type: FUNC
660  */
661 HWTEST_F(SceneSessionManagerTest3, StartUIAbilityBySCB, TestSize.Level1)
662 {
663     SessionInfo info;
664     info.abilityName_ = "StartUIAbilityBySCB";
665     info.bundleName_ = "StartUIAbilityBySCB";
666     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
667     ASSERT_NE(nullptr, sceneSession);
668     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
669     int32_t ret = ssm_->StartUIAbilityBySCB(sceneSession);
670     EXPECT_NE(ret, ERR_OK);
671 }
672 
673 /**
674  * @tc.name: ChangeUIAbilityVisibilityBySCB
675  * @tc.desc: ChangeUIAbilityVisibilityBySCB
676  * @tc.type: FUNC
677  */
678 HWTEST_F(SceneSessionManagerTest3, ChangeUIAbilityVisibilityBySCB, TestSize.Level1)
679 {
680     SessionInfo info;
681     info.abilityName_ = "ChangeUIAbilityVisibilityBySCB";
682     info.bundleName_ = "ChangeUIAbilityVisibilityBySCB";
683     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
684     ASSERT_NE(nullptr, sceneSession);
685     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
686     int32_t ret = ssm_->ChangeUIAbilityVisibilityBySCB(sceneSession, true, false);
687     EXPECT_EQ(ret, 2097202);
688     ret = ssm_->ChangeUIAbilityVisibilityBySCB(sceneSession, true, false, false);
689     EXPECT_EQ(ret, 2097202);
690     ret = ssm_->ChangeUIAbilityVisibilityBySCB(sceneSession, true, false, true);
691     EXPECT_EQ(ret, 2097202);
692 }
693 
694 /**
695  * @tc.name: SetAbilitySessionInfo
696  * @tc.desc: SceneSesionManager set ability session info
697  * @tc.type: FUNC
698  */
699 HWTEST_F(SceneSessionManagerTest3, SetAbilitySessionInfo, TestSize.Level1)
700 {
701     SessionInfo info;
702     info.abilityName_ = "SetAbilitySessionInfo";
703     info.bundleName_ = "SetAbilitySessionInfo";
704     sptr<SceneSession> sceneSession;
705     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
706     ASSERT_NE(nullptr, sceneSession);
707     sptr<OHOS::AAFwk::SessionInfo> ret = ssm_->SetAbilitySessionInfo(sceneSession);
708     OHOS::AppExecFwk::ElementName retElementName = ret->want.GetElement();
709     ASSERT_EQ(retElementName.GetAbilityName(), info.abilityName_);
710     ASSERT_EQ(retElementName.GetBundleName(), info.bundleName_);
711 }
712 
713 /**
714  * @tc.name: PrepareTerminate
715  * @tc.desc: SceneSesionManager prepare terminate
716  * @tc.type: FUNC
717  */
718 HWTEST_F(SceneSessionManagerTest3, PrepareTerminate, TestSize.Level1)
719 {
720     int32_t persistentId = 0;
721     bool isPrepareTerminate = false;
722     ASSERT_EQ(WSError::WS_OK, ssm_->PrepareTerminate(persistentId, isPrepareTerminate));
723 }
724 
725 /**
726  * @tc.name: DestroyDialogWithMainWindow
727  * @tc.desc: SceneSesionManager destroy dialog with main window
728  * @tc.type: FUNC
729  */
730 HWTEST_F(SceneSessionManagerTest3, DestroyDialogWithMainWindow, TestSize.Level1)
731 {
732     SessionInfo info;
733     info.abilityName_ = "DestroyDialogWithMainWindow";
734     info.bundleName_ = "DestroyDialogWithMainWindow";
735     sptr<SceneSession> sceneSession;
736     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
737     ASSERT_NE(nullptr, sceneSession);
738     ASSERT_EQ(WSError::WS_OK, ssm_->DestroyDialogWithMainWindow(sceneSession));
739 }
740 
741 /**
742  * @tc.name: AddClientDeathRecipient
743  * @tc.desc: SceneSesionManager add client death recipient
744  * @tc.type: FUNC
745  */
746 HWTEST_F(SceneSessionManagerTest3, AddClientDeathRecipient, TestSize.Level1)
747 {
748     SessionInfo info;
749     info.abilityName_ = "AddClientDeathRecipient";
750     info.bundleName_ = "AddClientDeathRecipient";
751     sptr<SceneSession> sceneSession;
752     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
753     ASSERT_NE(nullptr, sceneSession);
754     int ret = 0;
755     ssm_->AddClientDeathRecipient(nullptr, sceneSession);
756     ASSERT_EQ(ret, 0);
757 }
758 
759 /**
760  * @tc.name: DestroySpecificSession
761  * @tc.desc: SceneSesionManager destroy specific session
762  * @tc.type: FUNC
763  */
764 HWTEST_F(SceneSessionManagerTest3, DestroySpecificSession, TestSize.Level1)
765 {
766     sptr<IRemoteObject> remoteObject = nullptr;
767     int ret = 0;
768     ssm_->DestroySpecificSession(remoteObject);
769     ASSERT_EQ(ret, 0);
770 }
771 
772 /**
773  * @tc.name: SetCreateSystemSessionListener
774  * @tc.desc: SceneSesionManager set create specific session listener
775  * @tc.type: FUNC
776  */
777 HWTEST_F(SceneSessionManagerTest3, SetCreateSystemSessionListener, TestSize.Level1)
778 {
779     int ret = 0;
780     ssm_->SetCreateSystemSessionListener(nullptr);
781     ASSERT_EQ(ret, 0);
782 }
783 
784 /**
785  * @tc.name: SetGestureNavigationEnabledChangeListener
786  * @tc.desc: SceneSesionManager set gesture navigation enabled change listener
787  * @tc.type: FUNC
788  */
789 HWTEST_F(SceneSessionManagerTest3, SetGestureNavigationEnabledChangeListener, TestSize.Level1)
790 {
791     int ret = 0;
792     ssm_->SetGestureNavigationEnabledChangeListener(nullptr);
793     ASSERT_EQ(ret, 0);
794 }
795 
796 /**
797  * @tc.name: OnOutsideDownEvent
798  * @tc.desc: SceneSesionManager on out side down event
799  * @tc.type: FUNC
800  */
801 HWTEST_F(SceneSessionManagerTest3, OnOutsideDownEvent, TestSize.Level1)
802 {
803     int32_t x = 32;
804     int32_t y = 32;
805     int ret = 0;
806     ssm_->OnOutsideDownEvent(x, y);
807     ASSERT_EQ(ret, 0);
808 }
809 
810 /**
811  * @tc.name: NotifySessionTouchOutside
812  * @tc.desc: SceneSesionManager notify session touch outside
813  * @tc.type: FUNC
814  */
815 HWTEST_F(SceneSessionManagerTest3, NotifySessionTouchOutside, TestSize.Level1)
816 {
817     int ret = 0;
818     ssm_->NotifySessionTouchOutside(0, 0);
819     ASSERT_EQ(ret, 0);
820 }
821 
822 /**
823  * @tc.name: IsSameDisplayGroupId
824  * @tc.desc: test IsSameDisplayGroupId01
825  * @tc.type: FUNC
826  */
827 HWTEST_F(SceneSessionManagerTest3, IsSameDisplayGroupId01, TestSize.Level1)
828 {
829     bool result = ssm_->IsSameDisplayGroupId(nullptr, 0);
830     ASSERT_EQ(result, false);
831 }
832 
833 /**
834  * @tc.name: IsSameDisplayGroupId
835  * @tc.desc: test IsSameDisplayGroupId02
836  * @tc.type: FUNC
837  */
838 HWTEST_F(SceneSessionManagerTest3, IsSameDisplayGroupId02, TestSize.Level1)
839 {
840     SessionInfo info;
841     info.abilityName_ = "IsSameDisplayGroupId02";
842     info.bundleName_ = "IsSameDisplayGroupId02";
843     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
844     property->SetDisplayId(DEFAULT_DISPLAY_ID);
845     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
846     sceneSession->SetSessionProperty(property);
847     bool result = ssm_->IsSameDisplayGroupId(sceneSession, 0);
848     ASSERT_EQ(result, true);
849 }
850 
851 /**
852  * @tc.name: SetOutsideDownEventListener
853  * @tc.desc: SceneSesionManager set outside down event listener
854  * @tc.type: FUNC
855  */
856 HWTEST_F(SceneSessionManagerTest3, SetOutsideDownEventListener, TestSize.Level1)
857 {
__anonfc7e99f90502(int32_t x, int32_t y) 858     ProcessOutsideDownEventFunc func = [](int32_t x, int32_t y) { ssm_->OnOutsideDownEvent(x, y); };
859     int ret = 0;
860     ssm_->SetOutsideDownEventListener(func);
861     ASSERT_EQ(ret, 0);
862 }
863 
864 /**
865  * @tc.name: GetWindowSceneConfig
866  * @tc.desc: SceneSesionManager get window scene config
867  * @tc.type: FUNC
868  */
869 HWTEST_F(SceneSessionManagerTest3, GetWindowSceneConfig, TestSize.Level1)
870 {
871     int ret = 0;
872     AppWindowSceneConfig appWindowSceneConfig_ = ssm_->GetWindowSceneConfig();
873     ASSERT_EQ(ret, 0);
874 }
875 
876 /**
877  * @tc.name: ProcessBackEvent
878  * @tc.desc: SceneSesionManager process back event
879  * @tc.type: FUNC
880  */
881 HWTEST_F(SceneSessionManagerTest3, ProcessBackEvent, TestSize.Level1)
882 {
883     WSError result = ssm_->ProcessBackEvent();
884     ASSERT_EQ(result, WSError::WS_OK);
885 }
886 
887 /**
888  * @tc.name: HandleUserSwitch
889  * @tc.desc: SceneSesionManager notify switching user
890  * @tc.type: FUNC
891  */
892 HWTEST_F(SceneSessionManagerTest3, HandleUserSwitch, TestSize.Level1)
893 {
894     int ret = 0;
895     ssm_->HandleUserSwitch(UserSwitchEventType::SWITCHING, true);
896     ssm_->HandleUserSwitch(UserSwitchEventType::SWITCHED, true);
897     ssm_->HandleUserSwitch(UserSwitchEventType::SWITCHING, false);
898     ssm_->HandleUserSwitch(UserSwitchEventType::SWITCHED, false);
899     ASSERT_EQ(ret, 0);
900 }
901 
902 /**
903  * @tc.name: HandleUserSwitch1
904  * @tc.desc: notify switching user on PC
905  * @tc.type: FUNC
906  */
907 HWTEST_F(SceneSessionManagerTest3, HandleUserSwitch1, TestSize.Level1)
908 {
909     ASSERT_NE(nullptr, ssm_);
910     ssm_->systemConfig_.backgroundswitch = true;
911     SessionInfo info;
912     info.abilityName_ = "IsNeedChangeLifeCycleOnUserSwitch3";
913     info.bundleName_ = "IsNeedChangeLifeCycleOnUserSwitch3";
914     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
915     ASSERT_NE(nullptr, sceneSession);
916     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
917     ASSERT_NE(nullptr, property);
918     sceneSession->SetSessionProperty(property);
919     sceneSession->SetCallingPid(45678);
920     property->SetIsAppSupportPhoneInPc(false);
921     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
922     sceneSession->SetSessionState(SessionState::STATE_BACKGROUND);
923     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
924     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), nullptr });
925     ssm_->HandleUserSwitch(UserSwitchEventType::SWITCHING, false);
926     ssm_->HandleUserSwitch(UserSwitchEventType::SWITCHED, false);
927 }
928 
929 /**
930  * @tc.name: GetSessionInfoByContinueSessionId
931  * @tc.desc: SceneSesionManager GetSessionInfoByContinueSessionId
932  * @tc.type: FUNC
933  */
934 HWTEST_F(SceneSessionManagerTest3, GetSessionInfoByContinueSessionId, TestSize.Level1)
935 {
936     MockAccesstokenKit::MockIsSACalling(false);
937     MockAccesstokenKit::MockAccessTokenKitRet(-1);
938     std::string continueSessionId = "";
939     SessionInfoBean missionInfo;
940     EXPECT_EQ(ssm_->GetSessionInfoByContinueSessionId(continueSessionId, missionInfo),
941               WSError::WS_ERROR_INVALID_PERMISSION);
942 }
943 
944 /**
945  * @tc.name: PreHandleCollaborator
946  * @tc.desc: SceneSesionManager prehandle collaborator
947  * @tc.type: FUNC
948  */
949 HWTEST_F(SceneSessionManagerTest3, PreHandleCollaborator, TestSize.Level1)
950 {
951     SessionInfo info;
952     info.abilityName_ = "PreHandleCollaborator";
953     info.bundleName_ = "PreHandleCollaborator";
954     sptr<SceneSession> sceneSession = nullptr;
955     bool result = ssm_->PreHandleCollaborator(sceneSession);
956     EXPECT_FALSE(result);
957 
958     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
959     ASSERT_NE(nullptr, sceneSession);
960     result = ssm_->PreHandleCollaborator(sceneSession);
961     EXPECT_TRUE(result);
962 
963     sceneSession = nullptr;
964     AppExecFwk::ApplicationInfo applicationInfo_;
965     applicationInfo_.codePath = std::to_string(CollaboratorType::RESERVE_TYPE);
966     AppExecFwk::AbilityInfo abilityInfo_;
967     abilityInfo_.applicationInfo = applicationInfo_;
968     info.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>(abilityInfo_);
969     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
970     ASSERT_NE(nullptr, sceneSession);
971     result = ssm_->PreHandleCollaborator(sceneSession);
972     EXPECT_TRUE(result);
973 
974     sceneSession = nullptr;
975     applicationInfo_.codePath = std::to_string(CollaboratorType::OTHERS_TYPE);
976     abilityInfo_.applicationInfo = applicationInfo_;
977     info.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>(abilityInfo_);
978     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
979     ASSERT_NE(nullptr, sceneSession);
980     result = ssm_->PreHandleCollaborator(sceneSession);
981     EXPECT_TRUE(result);
982 
983     EXPECT_EQ(sceneSession->GetSessionInfo().want, nullptr);
984     sceneSession = nullptr;
985     info.want = std::make_shared<AAFwk::Want>();
986     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
987     ASSERT_NE(nullptr, sceneSession);
988     result = ssm_->PreHandleCollaborator(sceneSession);
989     EXPECT_TRUE(result);
990 }
991 
992 /**
993  * @tc.name: CheckCollaboratorType
994  * @tc.desc: SceneSesionManager check collborator type
995  * @tc.type: FUNC
996  */
997 HWTEST_F(SceneSessionManagerTest3, CheckCollaboratorType, TestSize.Level1)
998 {
999     int32_t type = CollaboratorType::RESERVE_TYPE;
1000     EXPECT_TRUE(ssm_->CheckCollaboratorType(type));
1001     type = CollaboratorType::OTHERS_TYPE;
1002     EXPECT_TRUE(ssm_->CheckCollaboratorType(type));
1003     type = CollaboratorType::DEFAULT_TYPE;
1004     ASSERT_FALSE(ssm_->CheckCollaboratorType(type));
1005 }
1006 
1007 /**
1008  * @tc.name: NotifyUpdateSessionInfo
1009  * @tc.desc: SceneSesionManager notify update session info
1010  * @tc.type: FUNC
1011  */
1012 HWTEST_F(SceneSessionManagerTest3, NotifyUpdateSessionInfo, TestSize.Level1)
1013 {
1014     SessionInfo info;
1015     info.abilityName_ = "NotifyUpdateSessionInfo";
1016     info.bundleName_ = "NotifyUpdateSessionInfo";
1017     sptr<SceneSession> sceneSession;
1018     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1019     ASSERT_NE(nullptr, sceneSession);
1020     ssm_->NotifyUpdateSessionInfo(nullptr);
1021     ASSERT_EQ(sceneSession->GetSessionInfo().want, nullptr);
1022     ssm_->NotifyUpdateSessionInfo(sceneSession);
1023     int32_t collaboratorType = CollaboratorType::RESERVE_TYPE;
1024     int32_t persistentId = 10086;
1025     ssm_->NotifyMoveSessionToForeground(collaboratorType, persistentId);
1026     ssm_->NotifyClearSession(collaboratorType, persistentId);
1027 }
1028 
1029 /**
1030  * @tc.name: QueryAbilityInfoFromBMS
1031  * @tc.desc: SceneSesionManager QueryAbilityInfoFromBMS NotifyStartAbility
1032  * @tc.type: FUNC
1033  */
1034 HWTEST_F(SceneSessionManagerTest3, QueryAbilityInfoFromBMS, TestSize.Level1)
1035 {
1036     const int32_t uId = 32;
1037     SessionInfo sessionInfo_;
1038     sessionInfo_.bundleName_ = "BundleName";
1039     sessionInfo_.abilityName_ = "AbilityName";
1040     sessionInfo_.moduleName_ = "ModuleName";
1041     AppExecFwk::AbilityInfo abilityInfo;
1042     int32_t collaboratorType = CollaboratorType::RESERVE_TYPE;
1043     ssm_->QueryAbilityInfoFromBMS(uId, sessionInfo_.bundleName_, sessionInfo_.abilityName_, sessionInfo_.moduleName_);
1044     EXPECT_EQ(sessionInfo_.want, nullptr);
1045     ssm_->Init();
1046     ssm_->QueryAbilityInfoFromBMS(uId, sessionInfo_.bundleName_, sessionInfo_.abilityName_, sessionInfo_.moduleName_);
1047     ssm_->NotifyStartAbility(collaboratorType, sessionInfo_);
1048     sessionInfo_.want = std::make_shared<AAFwk::Want>();
1049     collaboratorType = CollaboratorType::OTHERS_TYPE;
1050     ssm_->NotifyStartAbility(collaboratorType, sessionInfo_);
1051     ASSERT_NE(sessionInfo_.want, nullptr);
1052 }
1053 
1054 /**
1055  * @tc.name: NotifyStartAbility
1056  * @tc.desc: SceneSesionManager NotifyStartAbility
1057  * @tc.type: FUNC
1058  */
1059 HWTEST_F(SceneSessionManagerTest3, NotifyStartAbility, TestSize.Level1)
1060 {
1061     SessionInfo sessionInfo;
1062     sessionInfo.moduleName_ = "SceneSessionManagerTest";
1063     sessionInfo.bundleName_ = "SceneSessionManagerTest3";
1064     sessionInfo.abilityName_ = "NotifyStartAbility";
1065     sptr<AAFwk::IAbilityManagerCollaborator> collaborator = iface_cast<AAFwk::IAbilityManagerCollaborator>(nullptr);
1066     ssm_->collaboratorMap_.clear();
1067     ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator));
1068     int32_t collaboratorType = 1;
1069     auto ret1 = ssm_->NotifyStartAbility(collaboratorType, sessionInfo);
1070     ASSERT_EQ(ret1, BrokerStates::BROKER_UNKOWN);
1071 
1072     sessionInfo.want = std::make_shared<AAFwk::Want>();
1073     auto ret2 = ssm_->NotifyStartAbility(collaboratorType, sessionInfo);
1074     ASSERT_EQ(ret2, BrokerStates::BROKER_UNKOWN);
1075     ssm_->collaboratorMap_.clear();
1076 }
1077 
1078 /**
1079  * @tc.name: IsSessionClearable
1080  * @tc.desc: SceneSesionManager is session clearable
1081  * @tc.type: FUNC
1082  */
1083 HWTEST_F(SceneSessionManagerTest3, IsSessionClearable, TestSize.Level1)
1084 {
1085     SessionInfo info;
1086     info.abilityName_ = "IsSessionClearable";
1087     info.bundleName_ = "IsSessionClearable";
1088     sptr<SceneSession> sceneSession;
1089     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1090     ASSERT_NE(nullptr, sceneSession);
1091     EXPECT_FALSE(ssm_->IsSessionClearable(nullptr));
1092     EXPECT_FALSE(ssm_->IsSessionClearable(sceneSession));
1093     AppExecFwk::AbilityInfo abilityInfo_;
1094     abilityInfo_.excludeFromMissions = true;
1095     info.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>(abilityInfo_);
1096     sceneSession = nullptr;
1097     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1098     ASSERT_NE(nullptr, sceneSession);
1099     EXPECT_FALSE(ssm_->IsSessionClearable(sceneSession));
1100     abilityInfo_.excludeFromMissions = false;
1101     abilityInfo_.unclearableMission = true;
1102     info.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>(abilityInfo_);
1103     sceneSession = nullptr;
1104     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1105     ASSERT_NE(nullptr, sceneSession);
1106     EXPECT_FALSE(ssm_->IsSessionClearable(sceneSession));
1107     abilityInfo_.unclearableMission = false;
1108     info.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>(abilityInfo_);
1109     info.lockedState = true;
1110     sceneSession = nullptr;
1111     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1112     ASSERT_NE(nullptr, sceneSession);
1113     EXPECT_FALSE(ssm_->IsSessionClearable(sceneSession));
1114     info.lockedState = false;
1115     info.isSystem_ = true;
1116     sceneSession = nullptr;
1117     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1118     ASSERT_NE(nullptr, sceneSession);
1119     EXPECT_FALSE(ssm_->IsSessionClearable(sceneSession));
1120     info.isSystem_ = false;
1121     sceneSession = nullptr;
1122     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1123     ASSERT_NE(nullptr, sceneSession);
1124     ASSERT_TRUE(ssm_->IsSessionClearable(sceneSession));
1125 }
1126 
1127 /**
1128  * @tc.name: HandleTurnScreenOn
1129  * @tc.desc: SceneSesionManager handle turn screen on and keep screen on
1130  * @tc.type: FUNC
1131  */
1132 HWTEST_F(SceneSessionManagerTest3, HandleTurnScreenOn, TestSize.Level0)
1133 {
1134     SessionInfo info;
1135     info.abilityName_ = "HandleTurnScreenOn";
1136     info.bundleName_ = "HandleTurnScreenOn";
1137     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1138     ASSERT_NE(sceneSession, nullptr);
1139     ssm_->HandleTurnScreenOn(sceneSession);
1140     std::string lockName = "windowLock";
1141     bool requireLock = true;
1142     ssm_->HandleKeepScreenOn(sceneSession, requireLock, lockName, sceneSession->keepScreenLock_);
1143     requireLock = false;
1144     ssm_->HandleKeepScreenOn(sceneSession, requireLock, lockName, sceneSession->keepScreenLock_);
1145 }
1146 
1147 /**
1148  * @tc.name: HandleHideNonSystemFloatingWindows
1149  * @tc.desc: SceneSesionManager update hide non system floating windows
1150  * @tc.type: FUNC
1151  */
1152 HWTEST_F(SceneSessionManagerTest3, HandleHideNonSystemFloatingWindows, TestSize.Level1)
1153 {
1154     SessionInfo info;
1155     info.abilityName_ = "HandleHideNonSystemFloatingWindows";
1156     info.bundleName_ = "HandleHideNonSystemFloatingWindows";
1157     sptr<SceneSession> sceneSession;
1158     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1159     ASSERT_NE(nullptr, sceneSession);
1160     sptr<WindowSessionProperty> property = nullptr;
1161     ssm_->UpdateForceHideState(sceneSession, property, true);
1162     property = sptr<WindowSessionProperty>::MakeSptr();
1163     ASSERT_NE(nullptr, property);
1164     ssm_->HandleHideNonSystemFloatingWindows(property, sceneSession);
1165     property->SetHideNonSystemFloatingWindows(true);
1166     ssm_->UpdateForceHideState(sceneSession, property, true);
1167     ssm_->UpdateForceHideState(sceneSession, property, false);
1168     property->SetHideNonSystemFloatingWindows(false);
1169     property->SetFloatingWindowAppType(true);
1170     ssm_->UpdateForceHideState(sceneSession, property, true);
1171     ssm_->UpdateForceHideState(sceneSession, property, false);
1172     uint32_t result = property->GetWindowModeSupportType();
1173     ASSERT_EQ(result, WindowModeSupport::WINDOW_MODE_SUPPORT_ALL);
1174 }
1175 
1176 /**
1177  * @tc.name: UpdateBrightness01
1178  * @tc.desc: SceneSesionManager update brightness
1179  * @tc.type: FUNC
1180  */
1181 HWTEST_F(SceneSessionManagerTest3, UpdateBrightness01, TestSize.Level1)
1182 {
1183     int32_t persistentId = 10086;
1184     ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1185     WSError result01 = ssm_->UpdateBrightness(persistentId);
1186     EXPECT_EQ(result01, WSError::WS_ERROR_NULLPTR);
1187     ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1188     result01 = ssm_->UpdateBrightness(persistentId);
1189     EXPECT_EQ(result01, WSError::WS_OK);
1190 }
1191 
1192 /**
1193  * @tc.name: UpdateBrightness02
1194  * @tc.desc: WINDOW_TYPE_WALLET_SWIPE_CARD
1195  * @tc.type: FUNC
1196  */
1197 HWTEST_F(SceneSessionManagerTest3, UpdateBrightness02, TestSize.Level1)
1198 {
1199     int32_t persistentId = 10086;
1200     SessionInfo info;
1201     info.abilityName_ = "UpdateBrightness";
1202     info.bundleName_ = "UpdateBrightness";
1203     info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_WALLET_SWIPE_CARD);
1204     info.isSystem_ = true;
1205     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1206     ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, session));
1207     ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1208     auto  result01 = ssm_->UpdateBrightness(persistentId);
1209     EXPECT_EQ(result01, WSError::WS_OK);
1210 }
1211 
1212 /**
1213  * @tc.name: SetDisplayBrightness
1214  * @tc.desc: SceneSesionManager set display brightness
1215  * @tc.type: FUNC
1216  */
1217 HWTEST_F(SceneSessionManagerTest3, SetDisplayBrightness, TestSize.Level1)
1218 {
1219     float brightness = 2.0f;
1220     ssm_->SetDisplayBrightness(brightness);
1221     float result02 = ssm_->GetDisplayBrightness();
1222     ASSERT_EQ(result02, 2.0f);
1223 }
1224 
1225 /**
1226  * @tc.name: SetGestureNavigationEnabled02
1227  * @tc.desc: SceneSesionManager set gesture navigation enable
1228  * @tc.type: FUNC
1229  */
1230 HWTEST_F(SceneSessionManagerTest3, SetGestureNavigationEnabled02, TestSize.Level1)
1231 {
1232     bool enable = true;
1233     WMError result01 = ssm_->SetGestureNavigationEnabled(enable);
1234     EXPECT_EQ(result01, WMError::WM_OK);
1235     ProcessGestureNavigationEnabledChangeFunc funcGesture_ = SceneSessionManagerTest3::callbackFunc_;
1236     ssm_->SetGestureNavigationEnabledChangeListener(funcGesture_);
1237     WMError result02 = ssm_->SetGestureNavigationEnabled(enable);
1238     EXPECT_EQ(result02, WMError::WM_OK);
1239     ProcessStatusBarEnabledChangeFunc funcStatus_ = ProcessStatusBarEnabledChangeFuncTest;
1240     ssm_->SetStatusBarEnabledChangeListener(funcStatus_);
1241     WMError result03 = ssm_->SetGestureNavigationEnabled(enable);
1242     ASSERT_EQ(result03, WMError::WM_OK);
1243 }
1244 
1245 /**
1246  * @tc.name: SetFocusedSessionId
1247  * @tc.desc: SceneSesionManager set focused session id
1248  * @tc.type: FUNC
1249  */
1250 HWTEST_F(SceneSessionManagerTest3, SetFocusedSessionId, TestSize.Level1)
1251 {
1252     int32_t focusedSession = ssm_->GetFocusedSessionId();
1253     EXPECT_EQ(focusedSession, INVALID_SESSION_ID);
1254     int32_t persistentId = INVALID_SESSION_ID;
1255     WSError result01 = ssm_->SetFocusedSessionId(persistentId, DEFAULT_DISPLAY_ID);
1256     EXPECT_EQ(result01, WSError::WS_DO_NOTHING);
1257     persistentId = 10086;
1258     WSError result02 = ssm_->SetFocusedSessionId(persistentId, DEFAULT_DISPLAY_ID);
1259     EXPECT_EQ(result02, WSError::WS_OK);
1260     ASSERT_EQ(ssm_->GetFocusedSessionId(), 10086);
1261 }
1262 
1263 /**
1264  * @tc.name: RequestFocusStatus
1265  * @tc.desc: SceneSesionManager request focus status
1266  * @tc.type: FUNC
1267  */
1268 HWTEST_F(SceneSessionManagerTest3, RequestFocusStatus, TestSize.Level1)
1269 {
1270     int32_t focusedSession = ssm_->GetFocusedSessionId();
1271     EXPECT_EQ(focusedSession, 10086);
1272 
1273     int32_t persistentId = INVALID_SESSION_ID;
1274     WMError result01 = ssm_->RequestFocusStatus(persistentId, true);
1275     EXPECT_EQ(result01, WMError::WM_ERROR_NULLPTR);
1276     FocusChangeReason reasonResult = ssm_->GetFocusChangeReason();
1277     EXPECT_EQ(reasonResult, FocusChangeReason::DEFAULT);
1278 
1279     persistentId = 10000;
1280     FocusChangeReason reasonInput = FocusChangeReason::SCB_SESSION_REQUEST;
1281     WMError result02 = ssm_->RequestFocusStatus(persistentId, true, true, reasonInput);
1282     EXPECT_EQ(result02, WMError::WM_ERROR_NULLPTR);
1283     reasonResult = ssm_->GetFocusChangeReason();
1284     EXPECT_EQ(reasonResult, FocusChangeReason::DEFAULT);
1285 
1286     reasonInput = FocusChangeReason::SPLIT_SCREEN;
1287     WMError result03 = ssm_->RequestFocusStatus(persistentId, false, true, reasonInput);
1288     EXPECT_EQ(result03, WMError::WM_ERROR_NULLPTR);
1289     reasonResult = ssm_->GetFocusChangeReason();
1290     EXPECT_EQ(reasonResult, FocusChangeReason::DEFAULT);
1291 }
1292 
1293 /**
1294  * @tc.name: RequestFocusStatusBySA
1295  * @tc.desc: SceneSesionManager request focus status by SA
1296  * @tc.type: FUNC
1297  */
1298 HWTEST_F(SceneSessionManagerTest3, RequestFocusStatusBySA, TestSize.Level1)
1299 {
1300     int32_t persistentId = 3;
1301     bool isFocused = true;
1302     bool byForeground = true;
1303     FocusChangeReason reason = FocusChangeReason::CLICK;
1304     auto result = ssm_->SceneSessionManager::RequestFocusStatusBySA(persistentId, isFocused, byForeground, reason);
1305     ASSERT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
1306 }
1307 
1308 /**
1309  * @tc.name: NotifyRequestFocusStatusNotifyManager
1310  * @tc.desc: NotifyRequestFocusStatusNotifyManager test.
1311  * @tc.type: FUNC
1312  */
1313 HWTEST_F(SceneSessionManagerTest3, NotifyRequestFocusStatusNotifyManager, TestSize.Level1)
1314 {
1315     SessionInfo info;
1316     info.abilityName_ = "NotifyRequestFocusStatusNotifyManager";
1317     info.bundleName_ = "NotifyRequestFocusStatusNotifyManager";
1318     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1319     EXPECT_NE(sceneSession, nullptr);
1320     ssm_->RegisterRequestFocusStatusNotifyManagerFunc(sceneSession);
1321 
1322     FocusChangeReason reasonInput = FocusChangeReason::DEFAULT;
1323     sceneSession->NotifyRequestFocusStatusNotifyManager(true, true, reasonInput);
1324     FocusChangeReason reasonResult = ssm_->GetFocusChangeReason();
1325 
1326     ASSERT_EQ(reasonInput, reasonResult);
1327 }
1328 
1329 /**
1330  * @tc.name: GetTopNearestBlockingFocusSession
1331  * @tc.desc: SceneSesionManager Gets the most recent session whose blockingType property is true
1332  * @tc.type: FUNC
1333  */
1334 HWTEST_F(SceneSessionManagerTest3, GetTopNearestBlockingFocusSession, TestSize.Level1)
1335 {
1336     uint32_t zOrder = 9999;
1337     sptr<SceneSession> session = ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, zOrder, true);
1338     EXPECT_EQ(session, nullptr);
1339 
1340     session = ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, zOrder, false);
1341     EXPECT_EQ(session, nullptr);
1342 }
1343 
1344 /**
1345  * @tc.name: RaiseWindowToTop
1346  * @tc.desc: SceneSesionManager raise window to top
1347  * @tc.type: FUNC
1348  */
1349 HWTEST_F(SceneSessionManagerTest3, RaiseWindowToTop, TestSize.Level1)
1350 {
1351     int32_t focusedSession = ssm_->GetFocusedSessionId();
1352     EXPECT_EQ(focusedSession, 10086);
1353     int32_t persistentId = INVALID_SESSION_ID;
1354     WSError result01 = ssm_->RaiseWindowToTop(persistentId);
1355     EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_PERMISSION);
1356     persistentId = 10000;
1357     WSError result02 = ssm_->RaiseWindowToTop(persistentId);
1358     EXPECT_EQ(result02, WSError::WS_ERROR_INVALID_PERMISSION);
1359     WSError result03 = ssm_->RaiseWindowToTop(persistentId);
1360     EXPECT_EQ(result03, WSError::WS_ERROR_INVALID_PERMISSION);
1361 }
1362 
1363 /**
1364  * @tc.name: ShiftAppWindowFocus
1365  * @tc.desc: SceneSesionManager shift app window focus
1366  * @tc.type: FUNC
1367  */
1368 HWTEST_F(SceneSessionManagerTest3, ShiftAppWindowFocus, TestSize.Level1)
1369 {
1370     int32_t focusedSession = ssm_->GetFocusedSessionId();
1371     EXPECT_EQ(focusedSession, 10086);
1372     int32_t sourcePersistentId = 1;
1373     int32_t targetPersistentId = 10086;
1374     WSError result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1375     EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_SESSION);
1376     SessionInfo info;
1377     info.abilityName_ = "ShiftAppWindowFocus";
1378     info.bundleName_ = "ShiftAppWindowFocus";
1379     auto sourceSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1380     sourceSceneSession->persistentId_ = 1;
1381     sourceSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1382     ssm_->sceneSessionMap_.insert(std::make_pair(1, sourceSceneSession));
1383     result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1384     EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_OPERATION);
1385 
1386     auto targetSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1387     targetSceneSession->persistentId_ = 10086;
1388     targetSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1389     ssm_->sceneSessionMap_.insert(std::make_pair(10086, targetSceneSession));
1390     result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1391     EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_OPERATION);
1392     sourcePersistentId = 10086;
1393     WSError result02 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1394     EXPECT_EQ(result02, WSError::WS_DO_NOTHING);
1395 }
1396 
1397 /**
1398  * @tc.name: RegisterSessionExceptionFunc
1399  * @tc.desc: SceneSesionManager register session expection func
1400  * @tc.type: FUNC
1401  */
1402 HWTEST_F(SceneSessionManagerTest3, RegisterSessionExceptionFunc, TestSize.Level1)
1403 {
1404     SessionInfo info;
1405     info.abilityName_ = "RegisterSessionExceptionFunc";
1406     info.bundleName_ = "RegisterSessionExceptionFunc";
1407     sptr<SceneSession> sceneSession = nullptr;
1408     ssm_->RegisterSessionExceptionFunc(sceneSession);
1409     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1410     ASSERT_NE(nullptr, sceneSession);
1411     ssm_->RegisterSessionExceptionFunc(sceneSession);
1412     bool result01 = ssm_->IsSessionVisibleForeground(sceneSession);
1413     EXPECT_FALSE(result01);
1414 }
1415 
1416 /**
1417  * @tc.name: UpdateFocus
1418  * @tc.desc: SceneSesionManager update focus
1419  * @tc.type: FUNC
1420  */
1421 HWTEST_F(SceneSessionManagerTest3, UpdateFocus, TestSize.Level1)
1422 {
1423     int32_t persistentId = 10086;
1424     SessionInfo info;
1425     info.bundleName_ = "bundleName_";
1426     bool isFocused = true;
1427     WSError result = ssm_->UpdateFocus(persistentId, isFocused);
1428     ASSERT_EQ(result, WSError::WS_OK);
1429 }
1430 
1431 /**
1432  * @tc.name: UpdateWindowMode
1433  * @tc.desc: SceneSesionManager update window mode
1434  * @tc.type: FUNC
1435  */
1436 HWTEST_F(SceneSessionManagerTest3, UpdateWindowMode, TestSize.Level1)
1437 {
1438     int32_t persistentId = 10086;
1439     int32_t windowMode = 3;
1440     WSError result = ssm_->UpdateWindowMode(persistentId, windowMode);
1441     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_WINDOW);
__anonfc7e99f90602(int32_t persistentId, WindowUpdateType type) 1442     WindowChangedFunc func = [](int32_t persistentId, WindowUpdateType type) {
1443         OHOS::Rosen::WindowChangedFuncTest3(persistentId, type);
1444     };
1445     ssm_->RegisterWindowChanged(func);
1446 }
1447 
1448 /**
1449  * @tc.name: SetScreenLocked && IsScreenLocked
1450  * @tc.desc: SceneSesionManager update screen locked state
1451  * @tc.type: FUNC
1452  */
1453 HWTEST_F(SceneSessionManagerTest3, IsScreenLocked, TestSize.Level1)
1454 {
1455     ssm_->sceneSessionMap_.clear();
1456     ssm_->SetScreenLocked(true);
1457     sleep(1);
1458     EXPECT_TRUE(ssm_->IsScreenLocked());
1459     ssm_->SetScreenLocked(false);
1460     sleep(1);
1461     EXPECT_FALSE(ssm_->IsScreenLocked());
1462 }
1463 
1464 /**
1465  * @tc.name: UpdatePrivateStateAndNotify
1466  * @tc.desc: SceneSesionManager update private state and notify
1467  * @tc.type: FUNC
1468  */
1469 HWTEST_F(SceneSessionManagerTest3, UpdatePrivateStateAndNotify, TestSize.Level1)
1470 {
1471     int32_t persistentId = 10086;
1472     SessionInfo info;
1473     info.bundleName_ = "bundleName";
1474     sptr<SceneSession> sceneSession = nullptr;
1475     ssm_->RegisterSessionStateChangeNotifyManagerFunc(sceneSession);
1476     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1477     ASSERT_NE(sceneSession, nullptr);
1478     ssm_->RegisterSessionStateChangeNotifyManagerFunc(sceneSession);
1479     ssm_->UpdatePrivateStateAndNotify(persistentId);
1480     auto displayId = sceneSession->GetSessionProperty()->GetDisplayId();
1481     std::unordered_set<string> privacyBundleList;
1482     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundleList);
1483     EXPECT_EQ(privacyBundleList.size(), 0);
1484 }
1485 
1486 /**
1487  * @tc.name: UpdatePrivateStateAndNotifyForAllScreens
1488  * @tc.desc: SceneSesionManager update private state and notify for all screens
1489  * @tc.type: FUNC
1490  */
1491 HWTEST_F(SceneSessionManagerTest3, UpdatePrivateStateAndNotifyForAllScreens, TestSize.Level1)
1492 {
1493     SessionInfo info;
1494     info.bundleName_ = "bundleName";
1495     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1496     ASSERT_NE(sceneSession, nullptr);
1497 
1498     ssm_->UpdatePrivateStateAndNotifyForAllScreens();
1499     auto displayId = sceneSession->GetSessionProperty()->GetDisplayId();
1500     std::unordered_set<std::string> privacyBundleList;
1501     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundleList);
1502     EXPECT_EQ(privacyBundleList.size(), 0);
1503 }
1504 
1505 /**
1506  * @tc.name: GerPrivacyBundleListOneWindow
1507  * @tc.desc: get privacy bundle list when one window exist only.
1508  * @tc.type: FUNC
1509  */
1510 HWTEST_F(SceneSessionManagerTest3, GerPrivacyBundleListOneWindow, TestSize.Level1)
1511 {
1512     SessionInfo sessionInfo;
1513     sessionInfo.bundleName_ = "privacy.test";
1514     sessionInfo.abilityName_ = "privacyAbilityName";
1515     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1516     ASSERT_NE(sceneSession, nullptr);
1517 
1518     sceneSession->GetSessionProperty()->displayId_ = 0;
1519     sceneSession->GetSessionProperty()->isPrivacyMode_ = true;
1520     sceneSession->state_ = SessionState::STATE_FOREGROUND;
1521     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1522 
1523     std::unordered_set<std::string> privacyBundleList;
1524     sceneSession->GetSessionProperty()->isPrivacyMode_ = false;
1525     privacyBundleList.clear();
1526     ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
1527     EXPECT_EQ(privacyBundleList.size(), 0);
1528 
1529     sceneSession->GetSessionProperty()->isPrivacyMode_ = true;
1530     sceneSession->state_ = SessionState::STATE_BACKGROUND;
1531     privacyBundleList.clear();
1532     ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
1533     EXPECT_EQ(privacyBundleList.size(), 0);
1534 
1535     sceneSession->GetSessionProperty()->isPrivacyMode_ = true;
1536     sceneSession->state_ = SessionState::STATE_FOREGROUND;
1537     privacyBundleList.clear();
1538     ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
1539     EXPECT_EQ(privacyBundleList.size(), 1);
1540 
1541     privacyBundleList.clear();
1542     ssm_->GetSceneSessionPrivacyModeBundles(1, privacyBundleList);
1543     EXPECT_EQ(privacyBundleList.size(), 0);
1544 }
1545 
1546 /**
1547  * @tc.name: GetTopWindowId
1548  * @tc.desc: get top window id by main window id.
1549  * @tc.type: FUNC
1550  */
1551 HWTEST_F(SceneSessionManagerTest3, GetTopWindowId, TestSize.Level1)
1552 {
1553     SessionInfo sessionInfo1;
1554     sessionInfo1.bundleName_ = "mainWin";
1555     sessionInfo1.abilityName_ = "mainAbilityName";
1556     sessionInfo1.persistentId_ = 100;
1557     auto sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1558     ASSERT_NE(sceneSession1, nullptr);
1559     sceneSession1->SetCallingPid(65534);
1560     ssm_->sceneSessionMap_.insert({ 100, sceneSession1 });
1561 
1562     SessionInfo sessionInfo2;
1563     sessionInfo2.bundleName_ = "subWin1";
1564     sessionInfo2.abilityName_ = "subAbilityName1";
1565     sessionInfo2.persistentId_ = 101;
1566     auto sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1567     ASSERT_NE(sceneSession2, nullptr);
1568     sceneSession2->SetCallingPid(65535);
1569     ssm_->sceneSessionMap_.insert({ 101, sceneSession2 });
1570 
1571     SessionInfo sessionInfo3;
1572     sessionInfo3.bundleName_ = "subWin2";
1573     sessionInfo3.abilityName_ = "subAbilityName2";
1574     sessionInfo3.persistentId_ = 102;
1575     auto sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo3, nullptr);
1576     ASSERT_NE(sceneSession3, nullptr);
1577     sceneSession3->SetCallingPid(65534);
1578     ssm_->sceneSessionMap_.insert({ 102, sceneSession3 });
1579 
1580     sceneSession1->AddSubSession(sceneSession2);
1581     sceneSession1->AddSubSession(sceneSession3);
1582     uint32_t topWinId;
1583     ASSERT_EQ(ssm_->GetTopWindowId(static_cast<uint32_t>(sceneSession1->GetPersistentId()), topWinId),
1584               WMError::WM_ERROR_INVALID_PERMISSION);
1585 }
1586 
1587 /**
1588  * @tc.name: ConfigWindowImmersive
1589  * @tc.desc: ConfigWindowImmersive SwitchFreeMultiWindow
1590  * @tc.type: FUNC
1591  */
1592 HWTEST_F(SceneSessionManagerTest3, ConfigWindowImmersive01, TestSize.Level1)
1593 {
1594     WindowSceneConfig::ConfigItem immersiveConfig;
1595     immersiveConfig.boolValue_ = false;
1596     ASSERT_NE(ssm_, nullptr);
1597     ssm_->ConfigWindowImmersive(immersiveConfig);
1598 
1599     ASSERT_EQ(ssm_->SwitchFreeMultiWindow(false), WSError::WS_OK);
1600     SystemSessionConfig systemConfig;
1601     systemConfig.freeMultiWindowSupport_ = true;
1602     ssm_->SwitchFreeMultiWindow(false);
1603 }
1604 
1605 /**
1606  * @tc.name: ConfigDecor
1607  * @tc.desc: SceneSesionManager config decor
1608  * @tc.type: FUNC
1609  */
1610 HWTEST_F(SceneSessionManagerTest3, ConfigDecor02, TestSize.Level1)
1611 {
1612     ASSERT_NE(ssm_, nullptr);
1613     WindowSceneConfig::ConfigItem* item = new WindowSceneConfig::ConfigItem;
1614     ASSERT_NE(item, nullptr);
1615     ssm_->ConfigDecor(*item, false);
1616     delete item;
1617 }
1618 
1619 /**
1620  * @tc.name: ConfigAppWindowShadow
1621  * @tc.desc: SceneSesionManager config app window shadow
1622  * @tc.type: FUNC
1623  */
1624 HWTEST_F(SceneSessionManagerTest3, ConfigAppWindowShadow02, TestSize.Level1)
1625 {
1626     WindowSceneConfig::ConfigItem item;
1627     WindowSceneConfig::ConfigItem shadowConfig;
1628     WindowShadowConfig outShadow;
1629     std::vector<float> floatTest = {};
1630     bool result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1631     ASSERT_EQ(result, true);
1632 
1633     item.SetValue(floatTest);
1634     shadowConfig.SetValue({ { "radius", item } });
1635     result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1636     ASSERT_EQ(result, false);
1637 
1638     item.SetValue(new std::string(""));
1639     shadowConfig.SetValue({ { "", item } });
1640     result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1641     ASSERT_EQ(result, true);
1642 }
1643 
1644 /**
1645  * @tc.name: ConfigWindowAnimation
1646  * @tc.desc: SceneSesionManager config window animation
1647  * @tc.type: FUNC
1648  */
1649 HWTEST_F(SceneSessionManagerTest3, ConfigWindowAnimation02, TestSize.Level1)
1650 {
1651     WindowSceneConfig::ConfigItem windowAnimationConfig;
1652     WindowSceneConfig::ConfigItem item;
1653     std::vector<float> rotation = { 0.1f, 0.2f, 0.3f, 0.4f };
1654     ASSERT_NE(ssm_, nullptr);
1655 
1656     item.SetValue(rotation);
1657     item.SetValue({ { "curve", item } });
1658     windowAnimationConfig.SetValue({ { "timing", item } });
1659     ssm_->ConfigWindowAnimation(windowAnimationConfig);
1660 }
1661 
1662 /**
1663  * @tc.name: ConfigStartingWindowAnimation
1664  * @tc.desc: SceneSesionManager config start window animation
1665  * @tc.type: FUNC
1666  */
1667 HWTEST_F(SceneSessionManagerTest3, ConfigStartingWindowAnimation02, TestSize.Level1)
1668 {
1669     std::vector<float> midFloat = { 0.1f };
1670     std::vector<int> midInt = { 1 };
1671     ASSERT_NE(ssm_, nullptr);
1672     WindowSceneConfig::ConfigItem middleFloat;
1673     middleFloat.SetValue(midFloat);
1674     ssm_->ConfigStartingWindowAnimation(middleFloat);
1675     WindowSceneConfig::ConfigItem middleInt;
1676     middleInt.SetValue(midInt);
1677     ssm_->ConfigStartingWindowAnimation(middleInt);
1678 
1679     WindowSceneConfig::ConfigItem curve;
1680     curve.SetValue(midFloat);
1681     curve.SetValue({ { "curve", curve } });
1682     ssm_->ConfigStartingWindowAnimation(curve);
1683 }
1684 
1685 /**
1686  * @tc.name: ConfigMainWindowSizeLimits
1687  * @tc.desc: call ConfigMainWindowSizeLimits and check the systemConfig_.
1688  * @tc.type: FUNC
1689  */
1690 HWTEST_F(SceneSessionManagerTest3, ConfigMainWindowSizeLimits02, TestSize.Level1)
1691 {
1692     ASSERT_NE(ssm_, nullptr);
1693     std::vector<int> maInt = { 1, 2, 3, 4 };
1694     WindowSceneConfig::ConfigItem mainleInt;
1695     mainleInt.SetValue(maInt);
1696     mainleInt.SetValue({ { "miniWidth", mainleInt } });
1697     ssm_->ConfigMainWindowSizeLimits(mainleInt);
1698     mainleInt.ClearValue();
1699 
1700     std::vector<float> maFloat = { 0.1f };
1701     WindowSceneConfig::ConfigItem mainFloat;
1702     mainFloat.SetValue(maFloat);
1703     mainFloat.SetValue({ { "miniWidth", mainFloat } });
1704     ssm_->ConfigMainWindowSizeLimits(mainFloat);
1705     mainFloat.ClearValue();
1706 
1707     WindowSceneConfig::ConfigItem mainleInt02;
1708     mainleInt02.SetValue(maInt);
1709     mainleInt02.SetValue({ { "miniHeight", mainleInt02 } });
1710     ssm_->ConfigMainWindowSizeLimits(mainleInt02);
1711 
1712     WindowSceneConfig::ConfigItem mainFloat02;
1713     mainFloat02.SetValue(maFloat);
1714     mainFloat02.SetValue({ { "miniHeight", mainFloat02 } });
1715     ssm_->ConfigMainWindowSizeLimits(mainFloat02);
1716 }
1717 
1718 /**
1719  * @tc.name: ConfigSubWindowSizeLimits
1720  * @tc.desc: call ConfigSubWindowSizeLimits
1721  * @tc.type: FUNC
1722  */
1723 HWTEST_F(SceneSessionManagerTest3, ConfigSubWindowSizeLimits02, TestSize.Level1)
1724 {
1725     ASSERT_NE(ssm_, nullptr);
1726     std::vector<int> subInt = { 1, 2, 3, 4 };
1727     WindowSceneConfig::ConfigItem subleInt;
1728     subleInt.SetValue(subInt);
1729     subleInt.SetValue({ { "miniWidth", subleInt } });
1730     ssm_->ConfigSubWindowSizeLimits(subleInt);
1731     subleInt.ClearValue();
1732 
1733     std::vector<float> subFloat = { 0.1f };
1734     WindowSceneConfig::ConfigItem mainFloat;
1735     mainFloat.SetValue(subFloat);
1736     mainFloat.SetValue({ { "miniWidth", mainFloat } });
1737     ssm_->ConfigSubWindowSizeLimits(mainFloat);
1738     mainFloat.ClearValue();
1739 
1740     WindowSceneConfig::ConfigItem subleInt02;
1741     subleInt02.SetValue(subInt);
1742     subleInt02.SetValue({ { "miniHeight", subleInt02 } });
1743     ssm_->ConfigSubWindowSizeLimits(subleInt02);
1744 
1745     WindowSceneConfig::ConfigItem mainFloat02;
1746     mainFloat02.SetValue(subFloat);
1747     mainFloat02.SetValue({ { "miniHeight", mainFloat02 } });
1748     ssm_->ConfigSubWindowSizeLimits(mainFloat02);
1749 }
1750 
1751 /**
1752  * @tc.name: ConfigDialogWindowSizeLimits
1753  * @tc.desc: call ConfigDialogWindowSizeLimits
1754  * @tc.type: FUNC
1755  */
1756 HWTEST_F(SceneSessionManagerTest3, ConfigDialogWindowSizeLimits01, TestSize.Level1)
1757 {
1758     ASSERT_NE(ssm_, nullptr);
1759     std::vector<int> subInt = { 1, 2, 3, 4 };
1760     WindowSceneConfig::ConfigItem subleInt;
1761     subleInt.SetValue(subInt);
1762     subleInt.SetValue({ { "miniWidth", subleInt } });
1763     ssm_->ConfigDialogWindowSizeLimits(subleInt);
1764     subleInt.ClearValue();
1765 
1766     std::vector<float> subFloat = { 0.1f };
1767     WindowSceneConfig::ConfigItem mainFloat;
1768     mainFloat.SetValue(subFloat);
1769     mainFloat.SetValue({ { "miniWidth", mainFloat } });
1770     ssm_->ConfigDialogWindowSizeLimits(mainFloat);
1771     mainFloat.ClearValue();
1772 
1773     WindowSceneConfig::ConfigItem subleInt02;
1774     subleInt02.SetValue(subInt);
1775     subleInt02.SetValue({ { "miniHeight", subleInt02 } });
1776     ssm_->ConfigDialogWindowSizeLimits(subleInt02);
1777 
1778     WindowSceneConfig::ConfigItem mainFloat02;
1779     mainFloat02.SetValue(subFloat);
1780     mainFloat02.SetValue({ { "miniHeight", mainFloat02 } });
1781     ssm_->ConfigDialogWindowSizeLimits(mainFloat02);
1782 }
1783 
1784 /**
1785  * @tc.name: RegisterSetForegroundWindowNumCallback
1786  * @tc.desc: call RegisterSetForegroundWindowNumCallback
1787  * @tc.type: FUNC
1788  */
1789 HWTEST_F(SceneSessionManagerTest3, RegisterSetForegroundWindowNumCallback, TestSize.Level1)
1790 {
1791     EXPECT_NE(ssm_, nullptr);
__anonfc7e99f90702(uint32_t windowNum) 1792     std::function<void(uint32_t windowNum)> func = [](uint32_t windowNum) {
1793         return;
1794     };
1795     ssm_->RegisterSetForegroundWindowNumCallback(std::move(func));
1796     EXPECT_NE(ssm_->setForegroundWindowNumFunc_, nullptr);
1797 }
1798 
1799 /**
1800  * @tc.name: ConfigSingleHandCompatibleMode
1801  * @tc.desc: call ConfigSingleHandCompatibleMode
1802  * @tc.type: FUNC
1803  */
1804 HWTEST_F(SceneSessionManagerTest3, ConfigSingleHandCompatibleMode, TestSize.Level1)
1805 {
1806     EXPECT_NE(ssm_, nullptr);
1807     WindowSceneConfig::ConfigItem configItem;
1808     configItem.SetValue(true);
1809     configItem.SetValue({ { "test", configItem } });
1810     ssm_->ConfigSingleHandCompatibleMode(configItem);
1811     EXPECT_EQ(ssm_->singleHandCompatibleModeConfig_.enabled, configItem.boolValue_);
1812 }
1813 
1814 /**
1815  * @tc.name: UpdateRootSceneAvoidArea
1816  * @tc.desc: call UpdateRootSceneAvoidArea
1817  * @tc.type: FUNC
1818  */
1819 HWTEST_F(SceneSessionManagerTest3, UpdateRootSceneAvoidArea, TestSize.Level1)
1820 {
1821     EXPECT_NE(ssm_, nullptr);
1822     SessionInfo sessionInfo;
1823     sessionInfo.bundleName_ = "testbundleName";
1824     sessionInfo.abilityName_ = "testabilityName";
1825     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1826     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1827     ssm_->rootSceneSession_->specificCallback_ = nullptr;
1828     ssm_->UpdateRootSceneAvoidArea();
1829     auto res = ssm_->rootSceneSession_->GetPersistentId();
1830     EXPECT_NE(res, 0);
1831 }
1832 
1833 /**
1834  * @tc.name: NotifySessionTouchOutside
1835  * @tc.desc: call NotifySessionTouchOutside02
1836  * @tc.type: FUNC
1837  */
1838 HWTEST_F(SceneSessionManagerTest3, NotifySessionTouchOutside02, TestSize.Level1)
1839 {
1840     ASSERT_NE(ssm_, nullptr);
1841     auto ssm = ssm_;
1842     SessionInfo info;
1843     info.bundleName_ = "test1";
1844     info.abilityName_ = "test2";
1845     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1846     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1847     property->SetDisplayId(DEFAULT_DISPLAY_ID);
1848     sceneSession->SetSessionProperty(property);
1849     ssm->sceneSessionMap_.insert({1, sceneSession});
1850     ssm->windowFocusController_->displayId2GroupIdMap_[20] = 20;
1851 
1852     SessionInfo info02;
1853     info02.abilityName_ = "test1";
1854     info02.bundleName_ = "test2";
1855     info02.windowInputType_ = static_cast<uint32_t>(MMI::WindowInputType::NORMAL);
1856     sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info02, nullptr);
1857     sceneSession02->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1858 
__anonfc7e99f90802(int32_t persistentId, DisplayId displayId) 1859     auto sessionTouchOutsideFun = [ssm](int32_t persistentId, DisplayId displayId) {
1860         ssm->NotifySessionTouchOutside(persistentId, 20);
1861     };
__anonfc7e99f90902(int32_t x, int32_t y) 1862     auto outsideDownEventFun = [sceneSession02](int32_t x, int32_t y) {
1863         int z = x + y;
1864         sceneSession02->SetCollaboratorType(z);
1865     };
1866     sceneSession02->specificCallback_->onSessionTouchOutside_ = sessionTouchOutsideFun;
1867     sceneSession02->specificCallback_->onOutsideDownEvent_ = outsideDownEventFun;
1868     sceneSession02->SetSessionProperty(property);
1869     ssm->sceneSessionMap_.insert({2, sceneSession02});
1870     sceneSession->isVisible_ = true;
1871     sceneSession02->isVisible_ = true;
1872     ssm->NotifySessionTouchOutside(1, 20);
1873     ssm->NotifySessionTouchOutside(1, 0);
1874     EXPECT_EQ(true, sceneSession->IsVisible());
1875     EXPECT_EQ(true, sceneSession02->IsVisible());
1876     EXPECT_EQ(0, sceneSession->GetDisplayId());
1877     EXPECT_EQ(0, sceneSession02->GetDisplayId());
1878     EXPECT_EQ(20, ssm->GetDisplayGroupId(20));
1879     EXPECT_EQ(false, ssm->IsSameDisplayGroupId(sceneSession, 20));
1880     EXPECT_EQ(false, ssm->IsSameDisplayGroupId(sceneSession02, 20));
1881     EXPECT_EQ(0, ssm->GetDisplayGroupId(sceneSession->GetDisplayId()));
1882     EXPECT_EQ(0, ssm->GetDisplayGroupId(sceneSession02->GetDisplayId()));
1883     EXPECT_EQ(WSError::WS_OK, sceneSession02->ProcessPointDownSession(3, 4));
1884     ssm->sceneSessionMap_.erase(1);
1885     ssm->sceneSessionMap_.erase(2);
1886 }
1887 } // namespace
1888 } // namespace Rosen
1889 } // namespace OHOS