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,
__anond7a112170202(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 {
__anond7a112170402(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->GetModeSupportInfo();
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 sceneSession->UpdateNativeVisibility(true);
1420 bool result02 = ssm_->IsSessionVisibleForeground(sceneSession);
1421 EXPECT_TRUE(result02);
1422 }
1423
1424 /**
1425 * @tc.name: DumpSessionInfo
1426 * @tc.desc: SceneSesionManager dump session info
1427 * @tc.type: FUNC
1428 */
1429 HWTEST_F(SceneSessionManagerTest3, DumpSessionInfo, Function | SmallTest | Level3)
1430 {
1431 SessionInfo info;
1432 std::ostringstream oss;
1433 std::string dumpInfo;
1434 info.abilityName_ = "DumpSessionInfo";
1435 info.bundleName_ = "DumpSessionInfo";
1436 info.isSystem_ = false;
1437 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1438 ASSERT_NE(nullptr, sceneSession);
1439 ssm_->DumpSessionInfo(sceneSession, oss);
1440 EXPECT_FALSE(sceneSession->IsVisible());
1441
1442 sptr<SceneSession::SpecificSessionCallback> specific = new SceneSession::SpecificSessionCallback();
1443 EXPECT_NE(nullptr, specific);
1444 sceneSession = new (std::nothrow) SceneSession(info, specific);
1445 ASSERT_NE(nullptr, sceneSession);
1446 ssm_->DumpSessionInfo(sceneSession, oss);
1447 EXPECT_FALSE(sceneSession->IsVisible());
1448 sceneSession = nullptr;
1449 info.isSystem_ = true;
1450 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1451 ssm_->DumpSessionInfo(sceneSession, oss);
1452 }
1453
1454 /**
1455 * @tc.name: DumpSessionElementInfo
1456 * @tc.desc: SceneSesionManager dump session element info
1457 * @tc.type: FUNC
1458 */
1459 HWTEST_F(SceneSessionManagerTest3, DumpSessionElementInfo, Function | SmallTest | Level3)
1460 {
1461 DumpRootSceneElementInfoFunc func_ = DumpRootSceneElementInfoFuncTest;
1462 ssm_->SetDumpRootSceneElementInfoListener(func_);
1463 SessionInfo info;
1464 info.abilityName_ = "DumpSessionElementInfo";
1465 info.bundleName_ = "DumpSessionElementInfo";
1466 info.isSystem_ = false;
1467 std::string strId = "10086";
1468 sptr<SceneSession> sceneSession = nullptr;
1469 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1470 ASSERT_NE(nullptr, sceneSession);
1471 std::vector<std::string> params_(5, "");
1472 std::string dumpInfo;
1473 ssm_->DumpSessionElementInfo(sceneSession, params_, dumpInfo);
1474 sceneSession = nullptr;
1475 info.isSystem_ = true;
1476 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1477 ASSERT_NE(nullptr, sceneSession);
1478 ssm_->DumpSessionElementInfo(sceneSession, params_, dumpInfo);
1479 WSError result01 = ssm_->GetSpecifiedSessionDumpInfo(dumpInfo, params_, strId);
1480 EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_PARAM);
1481 }
1482
1483 /**
1484 * @tc.name: NotifyDumpInfoResult
1485 * @tc.desc: SceneSesionManager notify dump info result
1486 * @tc.type: FUNC
1487 */
1488 HWTEST_F(SceneSessionManagerTest3, NotifyDumpInfoResult, Function | SmallTest | Level3)
1489 {
1490 std::vector<std::string> info = {"std::", "vector", "<std::string>"};
1491 ssm_->NotifyDumpInfoResult(info);
1492 std::vector<std::string> params = {"-a"};
1493 std::string dumpInfo = "";
1494 WSError result01 = ssm_->GetSessionDumpInfo(params, dumpInfo);
1495 EXPECT_EQ(result01, WSError::WS_OK);
1496 params.clear();
1497 params.push_back("-w");
1498 params.push_back("23456");
1499 WSError result02 = ssm_->GetSessionDumpInfo(params, dumpInfo);
1500 EXPECT_NE(result02, WSError::WS_OK);
1501 params.clear();
1502 WSError result03 = ssm_->GetSessionDumpInfo(params, dumpInfo);
1503 EXPECT_NE(result03, WSError::WS_OK);
1504 }
1505
1506 /**
1507 * @tc.name: UpdateFocus
1508 * @tc.desc: SceneSesionManager update focus
1509 * @tc.type: FUNC
1510 */
1511 HWTEST_F(SceneSessionManagerTest3, UpdateFocus, Function | SmallTest | Level3)
1512 {
1513 int32_t persistentId = 10086;
1514 SessionInfo info;
1515 info.bundleName_ = "bundleName_";
1516 bool isFocused = true;
1517 WSError result = ssm_->UpdateFocus(persistentId, isFocused);
1518 ASSERT_EQ(result, WSError::WS_OK);
1519 }
1520
1521 /**
1522 * @tc.name: UpdateWindowMode
1523 * @tc.desc: SceneSesionManager update window mode
1524 * @tc.type: FUNC
1525 */
1526 HWTEST_F(SceneSessionManagerTest3, UpdateWindowMode, Function | SmallTest | Level3)
1527 {
1528 int32_t persistentId = 10086;
1529 int32_t windowMode = 3;
1530 WSError result = ssm_->UpdateWindowMode(persistentId, windowMode);
1531 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_WINDOW);
__anond7a112170502(int32_t persistentId, WindowUpdateType type) 1532 WindowChangedFunc func = [](int32_t persistentId, WindowUpdateType type) {
1533 OHOS::Rosen::WindowChangedFuncTest(persistentId, type);
1534 };
1535 ssm_->RegisterWindowChanged(func);
1536 }
1537
1538 /**
1539 * @tc.name: SetScreenLocked && IsScreenLocked
1540 * @tc.desc: SceneSesionManager update screen locked state
1541 * @tc.type: FUNC
1542 */
1543 HWTEST_F(SceneSessionManagerTest3, IsScreenLocked, Function | SmallTest | Level3)
1544 {
1545 ssm_->sceneSessionMap_.clear();
1546 ssm_->SetScreenLocked(true);
1547 EXPECT_TRUE(ssm_->IsScreenLocked());
1548 ssm_->SetScreenLocked(false);
1549 EXPECT_FALSE(ssm_->IsScreenLocked());
1550 }
1551
1552 /**
1553 * @tc.name: UpdatePrivateStateAndNotify
1554 * @tc.desc: SceneSesionManager update private state and notify
1555 * @tc.type: FUNC
1556 */
1557 HWTEST_F(SceneSessionManagerTest3, UpdatePrivateStateAndNotify, Function | SmallTest | Level3)
1558 {
1559 int32_t persistentId = 10086;
1560 SessionInfo info;
1561 info.bundleName_ = "bundleName";
1562 sptr<SceneSession> sceneSession = nullptr;
1563 ssm_->RegisterSessionStateChangeNotifyManagerFunc(sceneSession);
1564 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1565 ASSERT_NE(sceneSession, nullptr);
1566 ssm_->RegisterSessionStateChangeNotifyManagerFunc(sceneSession);
1567 ssm_->UpdatePrivateStateAndNotify(persistentId);
1568 auto displayId = sceneSession->GetSessionProperty()->GetDisplayId();
1569 std::unordered_set<string> privacyBundleList;
1570 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundleList);
1571 EXPECT_EQ(privacyBundleList.size(), 0);
1572 }
1573
1574 /**
1575 * @tc.name: UpdatePrivateStateAndNotifyForAllScreens
1576 * @tc.desc: SceneSesionManager update private state and notify for all screens
1577 * @tc.type: FUNC
1578 */
1579 HWTEST_F(SceneSessionManagerTest3, UpdatePrivateStateAndNotifyForAllScreens, Function | SmallTest | Level3)
1580 {
1581 SessionInfo info;
1582 info.bundleName_ = "bundleName";
1583 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1584 ASSERT_NE(sceneSession, nullptr);
1585
1586 ssm_->UpdatePrivateStateAndNotifyForAllScreens();
1587 auto displayId = sceneSession->GetSessionProperty()->GetDisplayId();
1588 std::unordered_set<std::string> privacyBundleList;
1589 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundleList);
1590 EXPECT_EQ(privacyBundleList.size(), 0);
1591 }
1592
1593 /**
1594 * @tc.name: GerPrivacyBundleListOneWindow
1595 * @tc.desc: get privacy bundle list when one window exist only.
1596 * @tc.type: FUNC
1597 */
1598 HWTEST_F(SceneSessionManagerTest3, GerPrivacyBundleListOneWindow, Function | SmallTest | Level3)
1599 {
1600 SessionInfo sessionInfo;
1601 sessionInfo.bundleName_ = "privacy.test";
1602 sessionInfo.abilityName_ = "privacyAbilityName";
1603 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1604 ASSERT_NE(sceneSession, nullptr);
1605
1606 sceneSession->GetSessionProperty()->displayId_ = 0;
1607 sceneSession->GetSessionProperty()->isPrivacyMode_ = true;
1608 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1609 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1610
1611 std::unordered_set<std::string> privacyBundleList;
1612 sceneSession->GetSessionProperty()->isPrivacyMode_ = false;
1613 privacyBundleList.clear();
1614 ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
1615 EXPECT_EQ(privacyBundleList.size(), 0);
1616
1617 sceneSession->GetSessionProperty()->isPrivacyMode_ = true;
1618 sceneSession->state_ = SessionState::STATE_BACKGROUND;
1619 privacyBundleList.clear();
1620 ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
1621 EXPECT_EQ(privacyBundleList.size(), 0);
1622
1623 sceneSession->GetSessionProperty()->isPrivacyMode_ = true;
1624 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1625 privacyBundleList.clear();
1626 ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
1627 EXPECT_EQ(privacyBundleList.size(), 1);
1628
1629 privacyBundleList.clear();
1630 ssm_->GetSceneSessionPrivacyModeBundles(1, privacyBundleList);
1631 EXPECT_EQ(privacyBundleList.size(), 0);
1632 }
1633
1634 /**
1635 * @tc.name: GetTopWindowId
1636 * @tc.desc: get top window id by main window id.
1637 * @tc.type: FUNC
1638 */
1639 HWTEST_F(SceneSessionManagerTest3, GetTopWindowId, Function | SmallTest | Level3)
1640 {
1641 SessionInfo sessionInfo1;
1642 sessionInfo1.bundleName_ = "mainWin";
1643 sessionInfo1.abilityName_ = "mainAbilityName";
1644 sessionInfo1.persistentId_ = 100;
1645 auto sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1646 ASSERT_NE(sceneSession1, nullptr);
1647 sceneSession1->SetCallingPid(65534);
1648 ssm_->sceneSessionMap_.insert({100, sceneSession1});
1649
1650 SessionInfo sessionInfo2;
1651 sessionInfo2.bundleName_ = "subWin1";
1652 sessionInfo2.abilityName_ = "subAbilityName1";
1653 sessionInfo2.persistentId_ = 101;
1654 auto sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1655 ASSERT_NE(sceneSession2, nullptr);
1656 sceneSession2->SetCallingPid(65535);
1657 ssm_->sceneSessionMap_.insert({101, sceneSession2});
1658
1659 SessionInfo sessionInfo3;
1660 sessionInfo3.bundleName_ = "subWin2";
1661 sessionInfo3.abilityName_ = "subAbilityName2";
1662 sessionInfo3.persistentId_ = 102;
1663 auto sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo3, nullptr);
1664 ASSERT_NE(sceneSession3, nullptr);
1665 sceneSession3->SetCallingPid(65534);
1666 ssm_->sceneSessionMap_.insert({102, sceneSession3});
1667
1668 sceneSession1->AddSubSession(sceneSession2);
1669 sceneSession1->AddSubSession(sceneSession3);
1670 uint32_t topWinId;
1671 ASSERT_NE(ssm_->GetTopWindowId(static_cast<uint32_t>(sceneSession1->GetPersistentId()), topWinId),
1672 WMError::WM_ERROR_INVALID_WINDOW);
1673 }
1674
1675 /**
1676 * @tc.name: ConfigWindowImmersive
1677 * @tc.desc: ConfigWindowImmersive SwitchFreeMultiWindow
1678 * @tc.type: FUNC
1679 */
1680 HWTEST_F(SceneSessionManagerTest3, ConfigWindowImmersive01, Function | SmallTest | Level3)
1681 {
1682 WindowSceneConfig::ConfigItem immersiveConfig;
1683 immersiveConfig.boolValue_ = false;
1684 ASSERT_NE(ssm_, nullptr);
1685 ssm_->ConfigWindowImmersive(immersiveConfig);
1686
1687 ASSERT_NE(ssm_->SwitchFreeMultiWindow(false), WSError::WS_OK);
1688 SystemSessionConfig systemConfig;
1689 systemConfig.freeMultiWindowSupport_ = true;
1690 ssm_->SwitchFreeMultiWindow(false);
1691 }
1692
1693 /**
1694 * @tc.name: ConfigDecor
1695 * @tc.desc: SceneSesionManager config decor
1696 * @tc.type: FUNC
1697 */
1698 HWTEST_F(SceneSessionManagerTest3, ConfigDecor02, Function | SmallTest | Level3)
1699 {
1700 ASSERT_NE(ssm_, nullptr);
1701 WindowSceneConfig::ConfigItem* item = new WindowSceneConfig::ConfigItem;
1702 ASSERT_NE(item, nullptr);
1703 ssm_->ConfigDecor(*item, false);
1704 delete item;
1705 }
1706
1707 /**
1708 * @tc.name: ConfigAppWindowShadow
1709 * @tc.desc: SceneSesionManager config app window shadow
1710 * @tc.type: FUNC
1711 */
1712 HWTEST_F(SceneSessionManagerTest3, ConfigAppWindowShadow02, Function | SmallTest | Level3)
1713 {
1714 WindowSceneConfig::ConfigItem item;
1715 WindowSceneConfig::ConfigItem shadowConfig;
1716 WindowShadowConfig outShadow;
1717 std::vector<float> floatTest = {};
1718 bool result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1719 ASSERT_EQ(result, true);
1720
1721 item.SetValue(floatTest);
1722 shadowConfig.SetValue({{"radius", item}});
1723 result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1724 ASSERT_EQ(result, false);
1725
1726 item.SetValue(new std::string(""));
1727 shadowConfig.SetValue({{"", item}});
1728 result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1729 ASSERT_EQ(result, true);
1730 }
1731
1732 /**
1733 * @tc.name: ConfigWindowAnimation
1734 * @tc.desc: SceneSesionManager config window animation
1735 * @tc.type: FUNC
1736 */
1737 HWTEST_F(SceneSessionManagerTest3, ConfigWindowAnimation02, Function | SmallTest | Level3)
1738 {
1739 WindowSceneConfig::ConfigItem windowAnimationConfig;
1740 WindowSceneConfig::ConfigItem item;
1741 std::vector<float> rotation = {0.1f, 0.2f, 0.3f, 0.4f};
1742 ASSERT_NE(ssm_, nullptr);
1743
1744 item.SetValue(rotation);
1745 item.SetValue({{"curve", item}});
1746 windowAnimationConfig.SetValue({{"timing", item}});
1747 ssm_->ConfigWindowAnimation(windowAnimationConfig);
1748 }
1749
1750 /**
1751 * @tc.name: ConfigStartingWindowAnimation
1752 * @tc.desc: SceneSesionManager config start window animation
1753 * @tc.type: FUNC
1754 */
1755 HWTEST_F(SceneSessionManagerTest3, ConfigStartingWindowAnimation02, Function | SmallTest | Level3)
1756 {
1757 std::vector<float> midFloat = {0.1f};
1758 std::vector<int> midInt = {1};
1759 ASSERT_NE(ssm_, nullptr);
1760 WindowSceneConfig::ConfigItem middleFloat;
1761 middleFloat.SetValue(midFloat);
1762 ssm_->ConfigStartingWindowAnimation(middleFloat);
1763 WindowSceneConfig::ConfigItem middleInt;
1764 middleInt.SetValue(midInt);
1765 ssm_->ConfigStartingWindowAnimation(middleInt);
1766
1767 WindowSceneConfig::ConfigItem curve;
1768 curve.SetValue(midFloat);
1769 curve.SetValue({{"curve", curve}});
1770 ssm_->ConfigStartingWindowAnimation(curve);
1771 }
1772
1773 /**
1774 * @tc.name: ConfigMainWindowSizeLimits
1775 * @tc.desc: call ConfigMainWindowSizeLimits and check the systemConfig_.
1776 * @tc.type: FUNC
1777 */
1778 HWTEST_F(SceneSessionManagerTest3, ConfigMainWindowSizeLimits02, Function | SmallTest | Level3)
1779 {
1780 ASSERT_NE(ssm_, nullptr);
1781 std::vector<int> maInt = {1, 2, 3, 4};
1782 WindowSceneConfig::ConfigItem mainleInt;
1783 mainleInt.SetValue(maInt);
1784 mainleInt.SetValue({{"miniWidth", mainleInt}});
1785 ssm_->ConfigMainWindowSizeLimits(mainleInt);
1786 mainleInt.ClearValue();
1787
1788 std::vector<float> maFloat = {0.1f};
1789 WindowSceneConfig::ConfigItem mainFloat;
1790 mainFloat.SetValue(maFloat);
1791 mainFloat.SetValue({{"miniWidth", mainFloat}});
1792 ssm_->ConfigMainWindowSizeLimits(mainFloat);
1793 mainFloat.ClearValue();
1794
1795 WindowSceneConfig::ConfigItem mainleInt02;
1796 mainleInt02.SetValue(maInt);
1797 mainleInt02.SetValue({{"miniHeight", mainleInt02}});
1798 ssm_->ConfigMainWindowSizeLimits(mainleInt02);
1799
1800 WindowSceneConfig::ConfigItem mainFloat02;
1801 mainFloat02.SetValue(maFloat);
1802 mainFloat02.SetValue({{"miniHeight", mainFloat02}});
1803 ssm_->ConfigMainWindowSizeLimits(mainFloat02);
1804 }
1805
1806 /**
1807 * @tc.name: ConfigSubWindowSizeLimits
1808 * @tc.desc: call ConfigSubWindowSizeLimits
1809 * @tc.type: FUNC
1810 */
1811 HWTEST_F(SceneSessionManagerTest3, ConfigSubWindowSizeLimits02, Function | SmallTest | Level3)
1812 {
1813 ASSERT_NE(ssm_, nullptr);
1814 std::vector<int> subInt = {1, 2, 3, 4};
1815 WindowSceneConfig::ConfigItem subleInt;
1816 subleInt.SetValue(subInt);
1817 subleInt.SetValue({{"miniWidth", subleInt}});
1818 ssm_->ConfigSubWindowSizeLimits(subleInt);
1819 subleInt.ClearValue();
1820
1821 std::vector<float> subFloat = {0.1f};
1822 WindowSceneConfig::ConfigItem mainFloat;
1823 mainFloat.SetValue(subFloat);
1824 mainFloat.SetValue({{"miniWidth", mainFloat}});
1825 ssm_->ConfigSubWindowSizeLimits(mainFloat);
1826 mainFloat.ClearValue();
1827
1828 WindowSceneConfig::ConfigItem subleInt02;
1829 subleInt02.SetValue(subInt);
1830 subleInt02.SetValue({{"miniHeight", subleInt02}});
1831 ssm_->ConfigSubWindowSizeLimits(subleInt02);
1832
1833 WindowSceneConfig::ConfigItem mainFloat02;
1834 mainFloat02.SetValue(subFloat);
1835 mainFloat02.SetValue({{"miniHeight", mainFloat02}});
1836 ssm_->ConfigSubWindowSizeLimits(mainFloat02);
1837 }
1838
1839 }
1840 } // namespace Rosen
1841 } // namespace OHOS