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