1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <bundle_mgr_interface.h>
18 #include <bundlemgr/launcher_service.h>
19
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 "scene_board_judgement.h"
26 #include "screen_session_manager/include/screen_session_manager.h"
27 #include "window_manager_agent.h"
28 #include "session_manager.h"
29 #include "zidl/window_manager_agent_interface.h"
30 #include "mock/mock_session_stage.h"
31 #include "mock/mock_window_event_channel.h"
32 #include "context.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36
37 namespace OHOS {
38 namespace Rosen {
39 class SceneSessionManagerSupplementTest : public testing::Test {
40 public:
41 static void SetUpTestCase();
42 static void TearDownTestCase();
43 void SetUp() override;
44 void TearDown() override;
45
46 static sptr<SceneSessionManager> ssm_;
47 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
48 };
49
50 sptr<SceneSessionManager> SceneSessionManagerSupplementTest::ssm_ = nullptr;
51
SetUpTestCase()52 void SceneSessionManagerSupplementTest::SetUpTestCase()
53 {
54 ssm_ = &SceneSessionManager::GetInstance();
55 }
56
TearDownTestCase()57 void SceneSessionManagerSupplementTest::TearDownTestCase()
58 {
59 ssm_ = nullptr;
60 }
61
SetUp()62 void SceneSessionManagerSupplementTest::SetUp()
63 {
64 ssm_->sceneSessionMap_.clear();
65 }
66
TearDown()67 void SceneSessionManagerSupplementTest::TearDown()
68 {
69 ssm_->sceneSessionMap_.clear();
70 usleep(WAIT_SYNC_IN_NS);
71 }
72
73 namespace {
74 /**
75 * @tc.name: LoadFreeMultiWindowConfigWithTrue
76 * @tc.desc: Test LoadFreeMultiWindowConfig for input true
77 * @tc.type: FUNC
78 */
79 HWTEST_F(SceneSessionManagerSupplementTest, LoadFreeMultiWindowConfigWithTrue, Function | SmallTest | Level3)
80 {
81 ssm_->systemConfig_.freeMultiWindowEnable_ = false;
82 ssm_->LoadFreeMultiWindowConfig(true);
83 auto config = ssm_->GetSystemSessionConfig();
84 ASSERT_EQ(config.freeMultiWindowEnable_, true);
85 }
86
87 /**
88 * @tc.name: LoadFreeMultiWindowConfigWithFalse
89 * @tc.desc: Test LoadFreeMultiWindowConfig for input false
90 * @tc.type: FUNC
91 */
92 HWTEST_F(SceneSessionManagerSupplementTest, LoadFreeMultiWindowConfigWithFalse, Function | SmallTest | Level3)
93 {
94 ssm_->systemConfig_.freeMultiWindowEnable_ = true;
95 ssm_->LoadFreeMultiWindowConfig(false);
96 auto config = ssm_->GetSystemSessionConfig();
97 ASSERT_EQ(config.freeMultiWindowEnable_, false);
98 }
99
100 /**
101 * @tc.name: SwitchFreeMultiWindowWithTrue
102 * @tc.desc: Test LoadFreeMultiWindowConfig for input false
103 * @tc.type: FUNC
104 */
105 HWTEST_F(SceneSessionManagerSupplementTest, SwitchFreeMultiWindowWithTrue, Function | SmallTest | Level3)
106 {
107 ssm_->systemConfig_.freeMultiWindowSupport_ = false;
108 auto res = ssm_->SwitchFreeMultiWindow(true);
109 ASSERT_EQ(res, WSError::WS_ERROR_DEVICE_NOT_SUPPORT);
110 }
111
112 /**
113 * @tc.name: SwitchFreeMultiWindowWithFalse
114 * @tc.desc: Test LoadFreeMultiWindowConfig for input false
115 * @tc.type: FUNC
116 */
117 HWTEST_F(SceneSessionManagerSupplementTest, SwitchFreeMultiWindowWithFalse, Function | SmallTest | Level3)
118 {
119 ssm_->systemConfig_.freeMultiWindowSupport_ = true;
120
121 auto res = ssm_->SwitchFreeMultiWindow(true);
122 ASSERT_EQ(res, WSError::WS_OK);
123 auto config = ssm_->GetSystemSessionConfig();
124 ASSERT_EQ(config.freeMultiWindowEnable_, true);
125 }
126
127 /**
128 * @tc.name: TestSwitchWindowWithNullSceneSession
129 * @tc.desc: Test LoadFreeMultiWindowConfig with sceneSession is nullptr
130 * @tc.type: FUNC
131 */
132 HWTEST_F(SceneSessionManagerSupplementTest, TestSwitchWindowWithNullSceneSession, Function | SmallTest | Level3)
133 {
134 ssm_->systemConfig_.freeMultiWindowSupport_ = true;
135 sptr<SceneSession> sceneSession;
136 ssm_->sceneSessionMap_.insert({1, sceneSession});
137
138 auto res = ssm_->SwitchFreeMultiWindow(false);
139 ASSERT_EQ(res, WSError::WS_OK);
140 auto config = ssm_->GetSystemSessionConfig();
141 ASSERT_EQ(config.freeMultiWindowEnable_, false);
142 }
143
144 /**
145 * @tc.name: TestSwitchWindowWithSceneSession
146 * @tc.desc: Test LoadFreeMultiWindowConfig with sceneSession is not nullptr
147 * @tc.type: FUNC
148 */
149 HWTEST_F(SceneSessionManagerSupplementTest, TestSwitchWindowWithSceneSession, Function | SmallTest | Level3)
150 {
151 ssm_->systemConfig_.freeMultiWindowSupport_ = true;
152 SessionInfo sessionInfo;
153 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
154 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
155 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
156 ssm_->sceneSessionMap_.insert({1, sceneSession});
157
158 auto res = ssm_->SwitchFreeMultiWindow(false);
159 ASSERT_EQ(res, WSError::WS_OK);
160 auto config = ssm_->GetSystemSessionConfig();
161 ASSERT_EQ(config.freeMultiWindowEnable_, false);
162 }
163
164 /**
165 * @tc.name: TestSwitchWindowWithProperty
166 * @tc.desc: Test LoadFreeMultiWindowConfig with property is not nullptr
167 * @tc.type: FUNC
168 */
169 HWTEST_F(SceneSessionManagerSupplementTest, TestSwitchWindowWithProperty, Function | SmallTest | Level3)
170 {
171 ssm_->systemConfig_.freeMultiWindowSupport_ = true;
172 SessionInfo sessionInfo;
173 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
174 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
175 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
176 ssm_->sceneSessionMap_.insert({1, sceneSession});
177 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
178 ASSERT_NE(property, nullptr);
179 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
180 sceneSession->SetSessionProperty(property);
181
182 auto res = ssm_->SwitchFreeMultiWindow(false);
183 ASSERT_EQ(res, WSError::WS_OK);
184 auto config = ssm_->GetSystemSessionConfig();
185 ASSERT_EQ(config.freeMultiWindowEnable_, false);
186 }
187
188 /**
189 * @tc.name: TestSwitchWindowWithPropertyInputTrue
190 * @tc.desc: Test LoadFreeMultiWindowConfig with property is not nullptr
191 * @tc.type: FUNC
192 */
193 HWTEST_F(SceneSessionManagerSupplementTest, TestSwitchWindowWithPropertyInputTrue, Function | SmallTest | Level3)
194 {
195 ssm_->systemConfig_.freeMultiWindowSupport_ = true;
196 SessionInfo sessionInfo;
197 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
198 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
199 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
200 ssm_->sceneSessionMap_.insert({1, sceneSession});
201 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
202 ASSERT_NE(property, nullptr);
203 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
204 sceneSession->SetSessionProperty(property);
205
206 auto res = ssm_->SwitchFreeMultiWindow(true);
207 ASSERT_EQ(res, WSError::WS_OK);
208 auto config = ssm_->GetSystemSessionConfig();
209 ASSERT_EQ(config.freeMultiWindowEnable_, true);
210 }
211
212 /**
213 * @tc.name: TestSetEnableInputEventWithInputTrue
214 * @tc.desc: Test LoadFreeMultiWindowConfig for input true
215 * @tc.type: FUNC
216 */
217 HWTEST_F(SceneSessionManagerSupplementTest, TestSetEnableInputEventWithInputTrue, Function | SmallTest | Level3)
218 {
219 ssm_->enableInputEvent_ = false;
220 ssm_->SetEnableInputEvent(true);
221 ASSERT_EQ(ssm_->enableInputEvent_, true);
222 auto res = ssm_->IsInputEventEnabled();
223 ASSERT_EQ(res, true);
224 }
225
226 /**
227 * @tc.name: RequestSceneSessionActivationInner
228 * @tc.desc: SceneSessionManagerSupplementTest RequestSceneSessionActivationInner
229 * @tc.type: FUNC
230 */
231 HWTEST_F(SceneSessionManagerSupplementTest, RequestSceneSessionActivationInner,
232 Function | SmallTest | Level3)
233 {
234 SessionInfo sessionInfo;
235 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
236 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
237 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
238 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
239 ASSERT_NE(property, nullptr);
240 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
241 sceneSession->SetSessionProperty(property);
242 sceneSession->SetCollaboratorType(0);
243 auto ret = ssm_->RequestSceneSessionActivationInner(sceneSession, true);
244 ASSERT_EQ(ret, WSError::WS_OK);
245 ret = ssm_->RequestSceneSessionActivationInner(sceneSession, false);
246 ASSERT_EQ(ret, WSError::WS_OK);
247 }
248
249 /**
250 * @tc.name: RequestSceneSessionActivationInnerTest01
251 * @tc.desc: SceneSessionManagerSupplementTest RequestSceneSessionActivationInner
252 * @tc.type: FUNC
253 */
254 HWTEST_F(SceneSessionManagerSupplementTest, RequestSceneSessionActivationInnerTest_01,
255 Function | SmallTest | Level3)
256 {
257 SessionInfo sessionInfo;
258 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
259 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
260 sessionInfo.ancoSceneState = AncoSceneState::NOTIFY_FOREGROUND;
261 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
262 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
263 ASSERT_NE(property, nullptr);
264 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
265 sceneSession->SetSessionProperty(property);
266 sceneSession->SetScbCoreEnabled(true);
267 auto ret = ssm_->RequestSceneSessionActivationInner(sceneSession, true);
268 ASSERT_EQ(ret, WSError::WS_OK);
269 ret = ssm_->RequestSceneSessionActivationInner(sceneSession, false);
270 ASSERT_EQ(ret, WSError::WS_OK);
271 }
272
273 /**
274 * @tc.name: NotifyCollaboratorAfterStart
275 * @tc.desc: SceneSessionManagerSupplementTest NotifyCollaboratorAfterStart
276 * @tc.type: FUNC
277 */
278 HWTEST_F(SceneSessionManagerSupplementTest, NotifyCollaboratorAfterStart,
279 Function | SmallTest | Level3)
280 {
281 sptr<SceneSession> sceneSession;
282 sptr<AAFwk::SessionInfo> sceneSessionInfo;
283 ssm_->NotifyCollaboratorAfterStart(sceneSession, sceneSessionInfo);
284 SessionInfo info;
285 info.bundleName_ = "test1";
286 info.abilityName_ = "test2";
287 auto ret = ssm_->RequestSceneSessionBackground(sceneSession, true, true);
288 ASSERT_EQ(ret, WSError::WS_OK);
289 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
290 ASSERT_NE(sceneSession, nullptr);
291 ssm_->NotifyCollaboratorAfterStart(sceneSession, sceneSessionInfo);
292 sceneSessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
293 ssm_->NotifyCollaboratorAfterStart(sceneSession, sceneSessionInfo);
294 ssm_->NotifyCollaboratorAfterStart(sceneSession, sceneSessionInfo);
295 ret = ssm_->RequestSceneSessionBackground(sceneSession, true, true);
296 ASSERT_EQ(ret, WSError::WS_OK);
297 ret = ssm_->RequestSceneSessionBackground(sceneSession, true, false);
298 ASSERT_EQ(ret, WSError::WS_OK);
299 ssm_->brightnessSessionId_ = sceneSession->GetPersistentId();
300 ret = ssm_->RequestSceneSessionBackground(sceneSession, false, true);
301 ASSERT_EQ(ret, WSError::WS_OK);
302 ret = ssm_->RequestSceneSessionBackground(sceneSession, false, false);
303 ASSERT_EQ(ret, WSError::WS_OK);
304 ssm_->brightnessSessionId_ = 0;
305 ssm_->systemConfig_.backgroundswitch = true;
306 ret = ssm_->RequestSceneSessionBackground(sceneSession, true, true);
307 ASSERT_EQ(ret, WSError::WS_OK);
308 ret = ssm_->RequestSceneSessionBackground(sceneSession, true, false);
309 ASSERT_EQ(ret, WSError::WS_OK);
310 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
311 ASSERT_NE(property, nullptr);
312 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
313 sceneSession->SetSessionProperty(property);
314 ret = ssm_->RequestSceneSessionBackground(sceneSession, false, true);
315 ASSERT_EQ(ret, WSError::WS_OK);
316 ret = ssm_->RequestSceneSessionBackground(sceneSession, false, false);
317 ASSERT_EQ(ret, WSError::WS_OK);
318 ssm_->NotifyForegroundInteractiveStatus(sceneSession, true);
319 ssm_->NotifyForegroundInteractiveStatus(sceneSession, false);
320 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
321 ssm_->NotifyForegroundInteractiveStatus(sceneSession, true);
322 }
323
324 /**
325 * @tc.name: TestDestroyDialogWithMainWindow_01
326 * @tc.desc: Test DestroyDialogWithMainWindow with sceneSession is null
327 * @tc.type: FUNC
328 */
329 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyDialogWithMainWindow_01, Function | SmallTest | Level3)
330 {
331 SessionInfo info;
332 info.bundleName_ = "test1";
333 info.abilityName_ = "test2";
334 sptr<SceneSession> sceneSession;
335 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
336 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
337 }
338
339 /**
340 * @tc.name: TestDestroyDialogWithMainWindow_02
341 * @tc.desc: Test DestroyDialogWithMainWindow with window type is WINDOW_TYPE_APP_COMPONENT
342 * @tc.type: FUNC
343 */
344 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyDialogWithMainWindow_02, Function | SmallTest | Level3)
345 {
346 SessionInfo info;
347 info.bundleName_ = "test1";
348 info.abilityName_ = "test2";
349 sptr<SceneSession> sceneSession;
350 ASSERT_NE(ssm_, nullptr);
351 ssm_->DestroySubSession(sceneSession);
352 ssm_->RequestSceneSessionDestruction(sceneSession, true);
353 ssm_->RequestSceneSessionDestruction(sceneSession, false);
354 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
355 ASSERT_NE(sceneSession, nullptr);
356 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
357 ASSERT_NE(property, nullptr);
358 property->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT);
359 sceneSession->SetSessionProperty(property);
360 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
361 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION);
362 }
363
364 /**
365 * @tc.name: TestDestroyDialogWithMainWindow_03
366 * @tc.desc: Test DestroyDialogWithMainWindow with subSession is null
367 * @tc.type: FUNC
368 */
369 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyDialogWithMainWindow_03, Function | SmallTest | Level3)
370 {
371 SessionInfo info;
372 info.bundleName_ = "test1";
373 info.abilityName_ = "test2";
374 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
375 ASSERT_NE(sceneSession, nullptr);
376 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
377 ASSERT_NE(property, nullptr);
378 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
379 sceneSession->SetSessionProperty(property);
380 sptr<SceneSession> sceneSession2;
381 sceneSession->dialogVec_.push_back(sceneSession2);
382 sceneSession->subSession_.push_back(sceneSession2);
383 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
384 ASSERT_EQ(res, WSError::WS_OK);
385 }
386
387 /**
388 * @tc.name: TestDestroyDialogWithMainWindow_04
389 * @tc.desc: Test DestroyDialogWithMainWindow with subSession is not null
390 * @tc.type: FUNC
391 */
392 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyDialogWithMainWindow_04, Function | SmallTest | Level3)
393 {
394 SessionInfo info;
395 info.bundleName_ = "test1";
396 info.abilityName_ = "test2";
397 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
398 ASSERT_NE(sceneSession, nullptr);
399 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
400 ASSERT_NE(property, nullptr);
401 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
402 sceneSession->SetSessionProperty(property);
403 sptr<SceneSession> sceneSession2;
404 sceneSession->dialogVec_.push_back(sceneSession2);
405 sceneSession->subSession_.push_back(sceneSession2);
406 sceneSession2 = sptr<SceneSession>::MakeSptr(info, nullptr);
407 ASSERT_NE(sceneSession2, nullptr);
408 ssm_->DestroySubSession(sceneSession);
409 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
410 ASSERT_EQ(res, WSError::WS_OK);
411 }
412
413 /**
414 * @tc.name: TestDestroyDialogWithMainWindow_05
415 * @tc.desc: Test DestroyDialogWithMainWindow with insert sceneSession2 in sceneSessionMap_
416 * @tc.type: FUNC
417 */
418 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyDialogWithMainWindow_05, Function | SmallTest | Level3)
419 {
420 SessionInfo info;
421 info.bundleName_ = "test1";
422 info.abilityName_ = "test2";
423 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
424 ASSERT_NE(sceneSession, nullptr);
425 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
426 ASSERT_NE(property, nullptr);
427 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
428 sceneSession->SetSessionProperty(property);
429 sptr<SceneSession> sceneSession2;
430 sceneSession->dialogVec_.push_back(sceneSession2);
431 sceneSession->subSession_.push_back(sceneSession2);
432 sceneSession2 = sptr<SceneSession>::MakeSptr(info, nullptr);
433 ASSERT_NE(sceneSession2, nullptr);
434 ssm_->DestroySubSession(sceneSession);
435 ssm_->RequestSceneSessionDestruction(sceneSession, true);
436 ssm_->RequestSceneSessionDestruction(sceneSession, false);
437 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
438 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
439 ASSERT_EQ(res, WSError::WS_OK);
440 }
441
442 /**
443 * @tc.name: DestroyDialogWithSessionIsNull
444 * @tc.desc: DestroyDialogWithMainWindow with with session is nullptr
445 * @tc.type: FUNC
446 */
447 HWTEST_F(SceneSessionManagerSupplementTest, DestroyDialogWithSessionIsNull, Function | SmallTest | Level3)
448 {
449 sptr<SceneSession> sceneSession;
450 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
451 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
452 }
453
454 /**
455 * @tc.name: DestroyDialogWithFalseType
456 * @tc.desc: DestroyDialogWithMainWindow with type is WINDOW_TYPE_APP_COMPONENT
457 * @tc.type: FUNC
458 */
459 HWTEST_F(SceneSessionManagerSupplementTest, DestroyDialogWithFalseType, Function | SmallTest | Level3)
460 {
461 SessionInfo info;
462 info.bundleName_ = "test1";
463 info.abilityName_ = "test2";
464 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
465 ASSERT_NE(sceneSession, nullptr);
466 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
467 ASSERT_NE(property, nullptr);
468 property->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT);
469 sceneSession->SetSessionProperty(property);
470 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
471 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_SESSION);
472 }
473
474 /**
475 * @tc.name: DestroyDialogWithTrueType
476 * @tc.desc: DestroyDialogWithMainWindow with type is WINDOW_TYPE_APP_MAIN_WINDOW
477 * @tc.type: FUNC
478 */
479 HWTEST_F(SceneSessionManagerSupplementTest, DestroyDialogWithTrueType, Function | SmallTest | Level3)
480 {
481 SessionInfo info;
482 info.bundleName_ = "test1";
483 info.abilityName_ = "test2";
484 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
485 ASSERT_NE(sceneSession, nullptr);
486 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
487 ASSERT_NE(property, nullptr);
488 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
489 sceneSession->SetSessionProperty(property);
490 sptr<SceneSession> sceneSession2;
491 sceneSession->dialogVec_.push_back(sceneSession2);
492 sceneSession->subSession_.push_back(sceneSession2);
493 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
494 ASSERT_EQ(res, WSError::WS_OK);
495 }
496
497 /**
498 * @tc.name: DestroyDialogWithTrueType_01
499 * @tc.desc: DestroyDialogWithMainWindow with type is WINDOW_TYPE_APP_MAIN_WINDOW
500 * @tc.type: FUNC
501 */
502 HWTEST_F(SceneSessionManagerSupplementTest, DestroyDialogWithTrueType_01, Function | SmallTest | Level3)
503 {
504 SessionInfo info;
505 info.bundleName_ = "test1";
506 info.abilityName_ = "test2";
507 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
508 ASSERT_NE(sceneSession, nullptr);
509 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
510 ASSERT_NE(property, nullptr);
511 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
512 sceneSession->SetSessionProperty(property);
513 sptr<SceneSession> sceneSession2;
514 sceneSession->dialogVec_.push_back(sceneSession2);
515 sceneSession->subSession_.push_back(sceneSession2);
516 sceneSession2 = sptr<SceneSession>::MakeSptr(info, nullptr);
517 ASSERT_NE(sceneSession2, nullptr);
518 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
519 auto res = ssm_->DestroyDialogWithMainWindow(sceneSession);
520 ASSERT_EQ(res, WSError::WS_OK);
521 }
522
523 /**
524 * @tc.name: TestCreateAndConnectSession_01
525 * @tc.desc: Test for CreateAndConnectSpecificSession with property is nullptr
526 * @tc.type: FUNC
527 */
528 HWTEST_F(SceneSessionManagerSupplementTest, TestCreateAndConnectSession_01, Function | SmallTest | Level3)
529 {
530 sptr<ISessionStage> sessionStage;
531 sptr<IWindowEventChannel> eventChannel;
532 std::shared_ptr<RSSurfaceNode> node = nullptr;
533 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
534 sptr<ISession> session;
535 SystemSessionConfig systemConfig;
536 sptr<IRemoteObject> token;
537 int32_t id = 0;
538
539 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
540 systemConfig, token);
541 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
542 }
543
544 /**
545 * @tc.name: TestCreateAndConnectSession_02
546 * @tc.desc: Test for CreateAndConnectSpecificSession with WindowType is WINDOW_TYPE_UI_EXTENSION
547 * @tc.type: FUNC
548 */
549 HWTEST_F(SceneSessionManagerSupplementTest, TestCreateAndConnectSession_02, Function | SmallTest | Level3)
550 {
551 sptr<ISessionStage> sessionStage;
552 sptr<IWindowEventChannel> eventChannel;
553 std::shared_ptr<RSSurfaceNode> node = nullptr;
554 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
555 ASSERT_NE(property, nullptr);
556 sptr<ISession> session;
557 SystemSessionConfig systemConfig;
558 sptr<IRemoteObject> token;
559 int32_t id = 0;
560 property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
561
562 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
563 systemConfig, token);
564 ASSERT_EQ(res, WSError::WS_ERROR_NOT_SYSTEM_APP);
565 }
566
567 /**
568 * @tc.name: TestCreateAndConnectSession_03
569 * @tc.desc: Test for CreateAndConnectSpecificSession with WindowType is WINDOW_TYPE_INPUT_METHOD_FLOAT
570 * @tc.type: FUNC
571 */
572 HWTEST_F(SceneSessionManagerSupplementTest, TestCreateAndConnectSession_03, Function | SmallTest | Level3)
573 {
574 sptr<ISessionStage> sessionStage;
575 sptr<IWindowEventChannel> eventChannel;
576 std::shared_ptr<RSSurfaceNode> node = nullptr;
577 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
578 ASSERT_NE(property, nullptr);
579 sptr<ISession> session;
580 SystemSessionConfig systemConfig;
581 sptr<IRemoteObject> token;
582 int32_t id = 0;
583 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
584
585 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
586 systemConfig, token);
587 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
588 }
589
590 /**
591 * @tc.name: TestCreateAndConnectSession_04
592 * @tc.desc: Test for CreateAndConnectSpecificSession with WindowType is WINDOW_TYPE_FLOAT
593 * @tc.type: FUNC
594 */
595 HWTEST_F(SceneSessionManagerSupplementTest, TestCreateAndConnectSession_04, Function | SmallTest | Level3)
596 {
597 sptr<ISessionStage> sessionStage;
598 sptr<IWindowEventChannel> eventChannel;
599 std::shared_ptr<RSSurfaceNode> node = nullptr;
600 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
601 ASSERT_NE(property, nullptr);
602 sptr<ISession> session;
603 SystemSessionConfig systemConfig;
604 sptr<IRemoteObject> token;
605 int32_t id = 0;
606 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
607 property->SetFloatingWindowAppType(true);
608
609 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
610 systemConfig, token);
611 ASSERT_EQ(res, WSError::WS_ERROR_NOT_SYSTEM_APP);
612 }
613
614 /**
615 * @tc.name: TestCreateAndConnectSession_05
616 * @tc.desc: Test for CreateAndConnectSpecificSession with WindowType is WINDOW_TYPE_APP_SUB_WINDOW
617 * @tc.type: FUNC
618 */
619 HWTEST_F(SceneSessionManagerSupplementTest, TestCreateAndConnectSession_05, Function | SmallTest | Level3)
620 {
621 sptr<ISessionStage> sessionStage;
622 sptr<IWindowEventChannel> eventChannel;
623 std::shared_ptr<RSSurfaceNode> node = nullptr;
624 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
625 ASSERT_NE(property, nullptr);
626 sptr<ISession> session;
627 SystemSessionConfig systemConfig;
628 sptr<IRemoteObject> token;
629 int32_t id = 0;
630 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
631 property->SetFloatingWindowAppType(true);
632 property->SetIsUIExtFirstSubWindow(true);
633
634 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
635 systemConfig, token);
636 ASSERT_EQ(res, WSError::WS_ERROR_NULLPTR);
637 }
638
639 /**
640 * @tc.name: TestCreateAndConnectSession_06
641 * @tc.desc: Test for CreateAndConnectSpecificSession with WindowType is WINDOW_TYPE_SYSTEM_ALARM_WINDOW
642 * @tc.type: FUNC
643 */
644 HWTEST_F(SceneSessionManagerSupplementTest, TestCreateAndConnectSession_06, Function | SmallTest | Level3)
645 {
646 sptr<ISessionStage> sessionStage;
647 sptr<IWindowEventChannel> eventChannel;
648 std::shared_ptr<RSSurfaceNode> node = nullptr;
649 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
650 ASSERT_NE(property, nullptr);
651 sptr<ISession> session;
652 SystemSessionConfig systemConfig;
653 sptr<IRemoteObject> token;
654 int32_t id = 0;
655 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
656 property->SetFloatingWindowAppType(true);
657 property->SetIsUIExtFirstSubWindow(true);
658
659 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
660 systemConfig, token);
661 ASSERT_EQ(res, WSError::WS_ERROR_INVALID_WINDOW);
662 }
663
664 /**
665 * @tc.name: TestCreateAndConnectSession_07
666 * @tc.desc: Test for CreateAndConnectSpecificSession with WindowType is WINDOW_TYPE_PIP
667 * @tc.type: FUNC
668 */
669 HWTEST_F(SceneSessionManagerSupplementTest, TestCreateAndConnectSession_07, Function | SmallTest | Level3)
670 {
671 sptr<ISessionStage> sessionStage;
672 sptr<IWindowEventChannel> eventChannel;
673 std::shared_ptr<RSSurfaceNode> node = nullptr;
674 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
675 ASSERT_NE(property, nullptr);
676 sptr<ISession> session;
677 SystemSessionConfig systemConfig;
678 sptr<IRemoteObject> token;
679 int32_t id = 0;
680 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
681 property->SetFloatingWindowAppType(true);
682 property->SetIsUIExtFirstSubWindow(true);
683
684 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
685 systemConfig, token);
686 ASSERT_EQ(res, WSError::WS_DO_NOTHING);
687 }
688
689 /**
690 * @tc.name: ClosePipWindowIfExist
691 * @tc.desc: ClosePipWindowIfExist
692 * @tc.type: FUNC
693 */
694 HWTEST_F(SceneSessionManagerSupplementTest, ClosePipWindowIfExist, Function | SmallTest | Level3)
695 {
696 ssm_->ClosePipWindowIfExist(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
697 ssm_->ClosePipWindowIfExist(WindowType::WINDOW_TYPE_PIP);
698 SessionInfo info;
699 info.bundleName_ = "test1";
700 info.abilityName_ = "test2";
701 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
702 ASSERT_NE(sceneSession, nullptr);
703 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
704 ASSERT_NE(property, nullptr);
705 property->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT);
706 sceneSession->SetSessionProperty(property);
707 PiPTemplateInfo pipInfo;
708 pipInfo.priority = 0;
709 auto res = ssm_->CheckPiPPriority(pipInfo);
710 ASSERT_EQ(res, true);
711 ssm_->sceneSessionMap_.insert({0, sceneSession});
712 ssm_->ClosePipWindowIfExist(WindowType::WINDOW_TYPE_PIP);
713 res = ssm_->CheckPiPPriority(pipInfo);
714 ASSERT_EQ(res, true);
715 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
716 PiPTemplateInfo pipInfo1;
717 pipInfo1.priority = 0;
718 sceneSession->SetPiPTemplateInfo(pipInfo1);
719 res = ssm_->CheckPiPPriority(pipInfo);
720 ASSERT_EQ(res, true);
721 sceneSession->isVisible_ = true;
722 res = ssm_->CheckPiPPriority(pipInfo);
723 ASSERT_EQ(res, true);
724 }
725
726 /**
727 * @tc.name: CheckSysWinPermissionWithUIExtTypeThenFalse
728 * @tc.desc: Check system window permission while type is WINDOW_TYPE_UI_EXTENSION return false
729 * @tc.type: FUNC
730 */
731 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermissionWithUIExtTypeThenFalse, Function | SmallTest | Level1)
732 {
733 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
734 ASSERT_NE(property, nullptr);
735 property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
736
737 ASSERT_NE(ssm_, nullptr);
738 bool res = ssm_->CheckSystemWindowPermission(property);
739 ASSERT_EQ(res, false);
740 }
741
742 /**
743 * @tc.name: CheckSysWinPermissionWithInputTypeThenFalse
744 * @tc.desc: Check system window permission while type is WINDOW_TYPE_INPUT_METHOD_FLOAT return false
745 * @tc.type: FUNC
746 */
747 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermissionWithInputTypeThenFalse, Function | SmallTest | Level1)
748 {
749 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
750 ASSERT_NE(property, nullptr);
751 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
752
753 ASSERT_NE(ssm_, nullptr);
754 bool res = ssm_->CheckSystemWindowPermission(property);
755 ASSERT_EQ(res, true);
756 }
757
758 /**
759 * @tc.name: CheckSysWinPermWithInputStatusTypeThenFalse
760 * @tc.desc: Check system window permission while type is WINDOW_TYPE_INPUT_METHOD_STATUS_BAR return false
761 * @tc.type: FUNC
762 */
763 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermWithInputStatusTypeThenFalse, Function | SmallTest | Level1)
764 {
765 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
766 ASSERT_NE(property, nullptr);
767 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR);
768
769 ASSERT_NE(ssm_, nullptr);
770 bool res = ssm_->CheckSystemWindowPermission(property);
771 ASSERT_EQ(res, true);
772 }
773
774 /**
775 * @tc.name: CheckSysWinPermWithDraggingTypeThenTrue
776 * @tc.desc: Check system window permission while type is WINDOW_TYPE_DRAGGING_EFFECT return false
777 * @tc.type: FUNC
778 */
779 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermWithDraggingTypeThenTrue, Function | SmallTest | Level1)
780 {
781 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
782 ASSERT_NE(property, nullptr);
783 property->SetWindowType(WindowType::WINDOW_TYPE_DRAGGING_EFFECT);
784
785 ASSERT_NE(ssm_, nullptr);
786 bool res = ssm_->CheckSystemWindowPermission(property);
787 ASSERT_EQ(res, true);
788 }
789
790 /**
791 * @tc.name: CheckSysWinPermWithToastTypeThenTrue
792 * @tc.desc: Check system window permission while type is WINDOW_TYPE_TOAST return false
793 * @tc.type: FUNC
794 */
795 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermWithToastTypeThenTrue, Function | SmallTest | Level1)
796 {
797 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
798 ASSERT_NE(property, nullptr);
799 property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
800
801 ASSERT_NE(ssm_, nullptr);
802 bool res = ssm_->CheckSystemWindowPermission(property);
803 ASSERT_EQ(res, true);
804 }
805
806 /**
807 * @tc.name: CheckSysWinPermWithDialgTypeThenTrue
808 * @tc.desc: Check system window permission while type is WINDOW_TYPE_DIALOG return true
809 * @tc.type: FUNC
810 */
811 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermWithDialgTypeThenTrue, Function | SmallTest | Level1)
812 {
813 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
814 ASSERT_NE(property, nullptr);
815 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
816
817 ASSERT_NE(ssm_, nullptr);
818 bool res = ssm_->CheckSystemWindowPermission(property);
819 ASSERT_EQ(res, true);
820 }
821
822 /**
823 * @tc.name: CheckSysWinPermWithPipTypeThenTrue
824 * @tc.desc: Check system window permission while type is WINDOW_TYPE_DIALOG return true
825 * @tc.type: FUNC
826 */
827 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermWithPipTypeThenTrue, Function | SmallTest | Level1)
828 {
829 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
830 ASSERT_NE(property, nullptr);
831 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
832
833 ASSERT_NE(ssm_, nullptr);
834 bool res = ssm_->CheckSystemWindowPermission(property);
835 ASSERT_EQ(res, true);
836 }
837
838 /**
839 * @tc.name: CheckSysWinPermWithFloatTypeThenFalse
840 * @tc.desc: Check system window permission while type is WINDOW_TYPE_FLOAT return false
841 * @tc.type: FUNC
842 */
843 HWTEST_F(SceneSessionManagerSupplementTest, CheckSysWinPermWithFloatTypeThenFalse, Function | SmallTest | Level1)
844 {
845 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
846 ASSERT_NE(property, nullptr);
847 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
848
849 ASSERT_NE(ssm_, nullptr);
850 bool res = ssm_->CheckSystemWindowPermission(property);
851 ASSERT_EQ(res, false);
852 }
853
854 /**
855 * @tc.name: SetAlivePersistentIdsWithNoId
856 * @tc.desc: Set Alive Persistent Ids With no persistentId then IsNeedRecover check return false
857 * @tc.type: FUNC
858 */
859 HWTEST_F(SceneSessionManagerSupplementTest, SetAlivePersistentIdsWithNoId, Function | SmallTest | Level1)
860 {
861 std::vector<int32_t> alivePersistentIds;
862 ASSERT_NE(ssm_, nullptr);
863 ssm_->SetAlivePersistentIds(alivePersistentIds);
864
865 int persistentId = 1;
866 bool res = ssm_->IsNeedRecover(persistentId);
867 ASSERT_EQ(res, false);
868 }
869
870 /**
871 * @tc.name: SetAlivePersistentIdsWithIds
872 * @tc.desc: Set Alive Persistent Ids With persistentIds then IsNeedRecover check return true
873 * @tc.type: FUNC
874 */
875 HWTEST_F(SceneSessionManagerSupplementTest, SetAlivePersistentIdsWithIds, Function | SmallTest | Level1)
876 {
877 std::vector<int32_t> alivePersistentIds = {0, 1, 2};
878 ASSERT_NE(ssm_, nullptr);
879 ssm_->SetAlivePersistentIds(alivePersistentIds);
880 ASSERT_EQ(ssm_->alivePersistentIds_, alivePersistentIds);
881
882 bool res = ssm_->IsNeedRecover(0);
883 ASSERT_EQ(res, true);
884 res = ssm_->IsNeedRecover(1);
885 ASSERT_EQ(res, true);
886 res = ssm_->IsNeedRecover(2);
887 ASSERT_EQ(res, true);
888 }
889
890 /**
891 * @tc.name: RecoverAndConnectSpecificSession
892 * @tc.desc: RecoverAndConnectSpecificSession
893 * @tc.type: FUNC
894 */
895 HWTEST_F(SceneSessionManagerSupplementTest, RecoverAndConnectSpecificSession, Function | SmallTest | Level3)
896 {
897 sptr<ISessionStage> sessionStage;
898 sptr<IWindowEventChannel> eventChannel;
899 std::shared_ptr<RSSurfaceNode> node = nullptr;
900 sptr<WindowSessionProperty> property;
901 sptr<ISession> session;
902 sptr<IRemoteObject> token;
903 auto ret = ssm_->RecoverAndConnectSpecificSession(sessionStage, eventChannel, node, property, session, token);
904 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
905 property = sptr<WindowSessionProperty>::MakeSptr();
906 ASSERT_NE(property, nullptr);
907 ret = ssm_->RecoverAndConnectSpecificSession(sessionStage, eventChannel, node, property, session, token);
908 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
909 ssm_->NotifyRecoveringFinished();
910 usleep(WAIT_SYNC_IN_NS);
911 ASSERT_EQ(ssm_->recoveringFinished_, true);
912 }
913
914 /**
915 * @tc.name: TestCacheSpecificSessionForRecovering_01
916 * @tc.desc: Test CacheSpecificSessionForRecovering with recoveringFinished_ is false
917 * @tc.type: FUNC
918 */
919 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_01, Function | SmallTest | Level3)
920 {
921 sptr<SceneSession> sceneSession;
922 SessionInfo info;
923 info.bundleName_ = "test1";
924 info.abilityName_ = "test2";
925 sptr<WindowSessionProperty> property;
926 ssm_->recoveringFinished_ = true;
927 ssm_->recoverSubSessionCacheMap_.clear();
928 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
929 ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
930 }
931
932 /**
933 * @tc.name: TestCacheSpecificSessionForRecovering_02
934 * @tc.desc: Test CacheSpecificSessionForRecovering with property is null
935 * @tc.type: FUNC
936 */
937 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_02, Function | SmallTest | Level3)
938 {
939 SessionInfo info;
940 info.bundleName_ = "test1";
941 info.abilityName_ = "test2";
942 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
943 sptr<WindowSessionProperty> property;
944 ssm_->recoveringFinished_ = false;
945 ssm_->recoverSubSessionCacheMap_.clear();
946 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
947 ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
948 }
949
950 /**
951 * @tc.name: TestCacheSpecificSessionForRecovering_03
952 * @tc.desc: Test CacheSpecificSessionForRecovering with sceneSession is null
953 * @tc.type: FUNC
954 */
955 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_03, Function | SmallTest | Level3)
956 {
957 SessionInfo info;
958 info.bundleName_ = "test1";
959 info.abilityName_ = "test2";
960 sptr<SceneSession> sceneSession;
961 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
962 ssm_->recoveringFinished_ = false;
963 ssm_->recoverSubSessionCacheMap_.clear();
964 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
965 ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
966 }
967
968 /**
969 * @tc.name: TestCacheSpecificSessionForRecovering_04
970 * @tc.desc: Test CacheSpecificSessionForRecovering with windowType is WINDOW_TYPE_APP_MAIN_WINDOW
971 * @tc.type: FUNC
972 */
973 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_04, Function | SmallTest | Level3)
974 {
975 SessionInfo info;
976 info.bundleName_ = "test1";
977 info.abilityName_ = "test2";
978 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
979 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
980 ssm_->recoveringFinished_ = false;
981 ssm_->recoverSubSessionCacheMap_.clear();
982 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
983 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
984 ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
985 }
986
987 /**
988 * @tc.name: TestCacheSpecificSessionForRecovering_05
989 * @tc.desc: Test CacheSpecificSessionForRecovering with windowType is APP_SUB_WINDOW_END and no parentId in map
990 * @tc.type: FUNC
991 */
992 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_05, Function | SmallTest | Level3)
993 {
994 SessionInfo info;
995 info.bundleName_ = "test1";
996 info.abilityName_ = "test2";
997 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
998 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
999 ssm_->recoveringFinished_ = false;
1000 ssm_->recoverSubSessionCacheMap_.clear();
1001 property->SetWindowType(WindowType::APP_SUB_WINDOW_END);
1002 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
1003 ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
1004 }
1005
1006 /**
1007 * @tc.name: TestCacheSpecificSessionForRecovering_06
1008 * @tc.desc: Test CacheSpecificSessionForRecovering with windowType is WINDOW_TYPE_APP_SUB_WINDOW
1009 * @tc.type: FUNC
1010 */
1011 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_06, Function | SmallTest | Level3)
1012 {
1013 SessionInfo info;
1014 info.bundleName_ = "test1";
1015 info.abilityName_ = "test2";
1016 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1017 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1018 ssm_->recoveringFinished_ = false;
1019 ssm_->recoverSubSessionCacheMap_.clear();
1020 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1021 property->SetParentPersistentId(1);
1022 NotifyCreateSubSessionFunc func;
1023 ssm_->createSubSessionFuncMap_.clear();
1024 ssm_->createSubSessionFuncMap_.insert({1, func});
1025 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
1026 ASSERT_EQ(ssm_->recoverSubSessionCacheMap_.size(), 0);
1027 ssm_->createSubSessionFuncMap_.clear();
1028 }
1029
1030 /**
1031 * @tc.name: TestCacheSpecificSessionForRecovering_07
1032 * @tc.desc: Test CacheSpecificSessionForRecovering with windowType is WINDOW_TYPE_DIALOG
1033 * @tc.type: FUNC
1034 */
1035 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_07, Function | SmallTest | Level3)
1036 {
1037 SessionInfo info;
1038 info.bundleName_ = "test1";
1039 info.abilityName_ = "test2";
1040 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1041 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1042 ssm_->recoveringFinished_ = false;
1043 ssm_->recoverDialogSessionCacheMap_.clear();
1044 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1045 property->SetParentPersistentId(1);
1046 NotifyCreateSubSessionFunc func;
1047 ssm_->bindDialogTargetFuncMap_.clear();
1048 ssm_->bindDialogTargetFuncMap_.insert({1, func});
1049 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
1050 ASSERT_EQ(ssm_->recoverDialogSessionCacheMap_.size(), 0);
1051 }
1052
1053 /**
1054 * @tc.name: TestCacheSpecificSessionForRecovering_08
1055 * @tc.desc: Test CacheSpecificSessionForRecovering with windowType is WINDOW_TYPE_DIALOG and no parentId in map
1056 * @tc.type: FUNC
1057 */
1058 HWTEST_F(SceneSessionManagerSupplementTest, TestCacheSpecificSessionForRecovering_08, Function | SmallTest | Level3)
1059 {
1060 SessionInfo info;
1061 info.bundleName_ = "test1";
1062 info.abilityName_ = "test2";
1063 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1064 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1065 ssm_->recoveringFinished_ = false;
1066 ssm_->recoverDialogSessionCacheMap_.clear();
1067 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1068 NotifyCreateSubSessionFunc func;
1069 ssm_->CacheSpecificSessionForRecovering(sceneSession, property);
1070 ASSERT_EQ(ssm_->recoverDialogSessionCacheMap_.size(), 1);
1071 }
1072
1073 /**
1074 * @tc.name: TestRecoverAndReconnectSceneSession_01
1075 * @tc.desc: Test RecoverAndReconnectSceneSession with property is null
1076 * @tc.type: FUNC
1077 */
1078 HWTEST_F(SceneSessionManagerSupplementTest, TestRecoverAndReconnectSceneSession_01, Function | SmallTest | Level3)
1079 {
1080 sptr<ISessionStage> sessionStage;
1081 sptr<IWindowEventChannel> eventChannel;
1082 std::shared_ptr<RSSurfaceNode> node = nullptr;
1083 sptr<WindowSessionProperty> property;
1084 sptr<ISession> session;
1085 sptr<IRemoteObject> token;
1086
1087 auto ret = ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
1088 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1089 }
1090
1091 /**
1092 * @tc.name: TestRecoverAndReconnectSceneSession_02
1093 * @tc.desc: Test RecoverAndReconnectSceneSession with recoveringFinished_ is true
1094 * @tc.type: FUNC
1095 */
1096 HWTEST_F(SceneSessionManagerSupplementTest, TestRecoverAndReconnectSceneSession_02, Function | SmallTest | Level3)
1097 {
1098 sptr<ISessionStage> sessionStage;
1099 sptr<IWindowEventChannel> eventChannel;
1100 std::shared_ptr<RSSurfaceNode> node = nullptr;
1101 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1102 sptr<ISession> session;
1103 sptr<IRemoteObject> token;
1104
1105 property->SetPersistentId(1);
1106 ssm_->alivePersistentIds_.push_back(1);
1107 ssm_->recoveringFinished_ = true;
1108 auto ret = ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
1109 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
1110 ssm_->alivePersistentIds_.clear();
1111 }
1112
1113 /**
1114 * @tc.name: TestRecoverAndReconnectSceneSession_03
1115 * @tc.desc: Test RecoverAndReconnectSceneSession with recoveringFinished_ is false
1116 * @tc.type: FUNC
1117 */
1118 HWTEST_F(SceneSessionManagerSupplementTest, TestRecoverAndReconnectSceneSession_03, Function | SmallTest | Level3)
1119 {
1120 sptr<ISessionStage> sessionStage;
1121 sptr<IWindowEventChannel> eventChannel;
1122 std::shared_ptr<RSSurfaceNode> node = nullptr;
1123 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1124 sptr<ISession> session;
1125 sptr<IRemoteObject> token;
1126
1127 property->SetPersistentId(1);
1128 ssm_->alivePersistentIds_.push_back(1);
1129 ssm_->recoveringFinished_ = false;
1130 auto ret = ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
1131 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1132 ssm_->alivePersistentIds_.clear();
1133 }
1134
1135 /**
1136 * @tc.name: TestRecoverAndReconnectSceneSession_04
1137 * @tc.desc: Test RecoverAndReconnectSceneSession with windowType is APP_SUB_WINDOW_END
1138 * @tc.type: FUNC
1139 */
1140 HWTEST_F(SceneSessionManagerSupplementTest, TestRecoverAndReconnectSceneSession_04, Function | SmallTest | Level3)
1141 {
1142 sptr<ISessionStage> sessionStage;
1143 sptr<IWindowEventChannel> eventChannel;
1144 std::shared_ptr<RSSurfaceNode> node = nullptr;
1145 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1146 sptr<ISession> session;
1147 sptr<IRemoteObject> token;
1148
1149 property->SetPersistentId(1);
1150 ssm_->alivePersistentIds_.push_back(1);
1151 ssm_->recoveringFinished_ = false;
1152 property->SetWindowType(WindowType::APP_SUB_WINDOW_END);
1153 auto ret = ssm_->RecoverAndReconnectSceneSession(sessionStage, eventChannel, node, session, property, token);
1154 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1155 ssm_->alivePersistentIds_.clear();
1156 }
1157
1158 /**
1159 * @tc.name: NotifyCreateSpecificSession
1160 * @tc.desc: NotifyCreateSpecificSession
1161 * @tc.type: FUNC
1162 */
1163 HWTEST_F(SceneSessionManagerSupplementTest, NotifyCreateSpecificSession, Function | SmallTest | Level3)
1164 {
1165 sptr<SceneSession> sceneSession;
1166 sptr<WindowSessionProperty> property;
1167 ASSERT_NE(ssm_, nullptr);
1168 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_MAIN_WINDOW_BASE);
1169 SessionInfo info;
1170 info.bundleName_ = "test1";
1171 info.abilityName_ = "test2";
1172 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1173 ASSERT_NE(sceneSession, nullptr);
1174 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_MAIN_WINDOW_BASE);
1175 property = sptr<WindowSessionProperty>::MakeSptr();
1176 ASSERT_NE(property, nullptr);
1177 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_MAIN_WINDOW_BASE);
1178 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::SYSTEM_SUB_WINDOW_BASE);
1179 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::APP_SUB_WINDOW_BASE);
1180 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_SCENE_BOARD);
1181 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_TOAST);
1182 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_FLOAT);
1183 property->SetParentPersistentId(1);
1184 ASSERT_EQ(property->GetParentPersistentId(), 1);
1185 SessionInfo info1;
1186 info1.bundleName_ = "test3";
1187 info1.abilityName_ = "test3";
1188 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1189 ssm_->sceneSessionMap_.insert({1, sceneSession2});
1190 ASSERT_TRUE(ssm_->sceneSessionMap_.find(1) != ssm_->sceneSessionMap_.end());
1191 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_FLOAT);
1192 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_DIALOG);
1193 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1194 ssm_->NotifyCreateSpecificSession(sceneSession, property, WindowType::BELOW_APP_SYSTEM_WINDOW_BASE);
1195 }
1196
1197 /**
1198 * @tc.name: NotifyCreateSubSession
1199 * @tc.desc: NotifyCreateSubSession
1200 * @tc.type: FUNC
1201 */
1202 HWTEST_F(SceneSessionManagerSupplementTest, NotifyCreateSubSession, Function | SmallTest | Level3)
1203 {
1204 sptr<SceneSession> sceneSession;
1205 ssm_->NotifyCreateSubSession(1, sceneSession);
1206 SessionInfo info;
1207 info.bundleName_ = "test1";
1208 info.abilityName_ = "test2";
1209 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1210 ASSERT_NE(sceneSession, nullptr);
1211 ssm_->NotifyCreateSubSession(1, sceneSession);
1212 ssm_->UnregisterSpecificSessionCreateListener(1);
1213 ASSERT_TRUE(ssm_->createSubSessionFuncMap_.find(1) == ssm_->createSubSessionFuncMap_.end());
1214 SessionInfo info1;
1215 info1.bundleName_ = "test1";
1216 info1.abilityName_ = "test2";
1217 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1218 ASSERT_NE(sceneSession1, nullptr);
1219 NotifyCreateSubSessionFunc func;
1220 ssm_->createSubSessionFuncMap_.insert({1, func});
1221 ssm_->NotifyCreateSubSession(1, sceneSession);
1222 ssm_->UnregisterSpecificSessionCreateListener(1);
1223 ssm_->createSubSessionFuncMap_.clear();
1224 ASSERT_TRUE(ssm_->createSubSessionFuncMap_.find(1) == ssm_->createSubSessionFuncMap_.end());
1225 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1226 ASSERT_NE(property, nullptr);
1227 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1228 sceneSession->SetSessionProperty(property);
1229 ssm_->sceneSessionMap_.insert({1, sceneSession});
1230 ASSERT_TRUE(ssm_->sceneSessionMap_.find(1) != ssm_->sceneSessionMap_.end());
1231 ssm_->NotifySessionTouchOutside(1);
1232 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1233 ssm_->NotifySessionTouchOutside(1);
1234 sceneSession->persistentId_ = property->callingSessionId_;
1235 ssm_->NotifySessionTouchOutside(1);
1236 sceneSession->persistentId_ = property->callingSessionId_ + 1;
1237 ssm_->NotifySessionTouchOutside(1);
1238 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
1239 usleep(WAIT_SYNC_IN_NS);
1240 }
1241
1242 /**
1243 * @tc.name: TestDestroyAndDisconSpecSessionInner_01
1244 * @tc.desc: Test DestroyAndDisconnectSpecificSessionInner with invaild persistentId
1245 * @tc.type: FUNC
1246 */
1247 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyAndDisconSpecSessionInner_01, Function | SmallTest | Level3)
1248 {
1249 ssm_->sceneSessionMap_.clear();
1250 int invaildPersistentId = -1;
1251 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(invaildPersistentId);
1252 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1253 }
1254
1255 /**
1256 * @tc.name: TestDestroyAndDisconSpecSessionInner_02
1257 * @tc.desc: Test DestroyAndDisconnectSpecificSessionInner with true persistentId
1258 * @tc.type: FUNC
1259 */
1260 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyAndDisconSpecSessionInner_02, Function | SmallTest | Level3)
1261 {
1262 ssm_->sceneSessionMap_.clear();
1263 SessionInfo info;
1264 info.bundleName_ = "test1";
1265 info.abilityName_ = "test2";
1266 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1267 uint32_t uid = 0;
1268 ssm_->GetTopWindowId(1, uid);
1269 ssm_->sceneSessionMap_.insert({1, sceneSession});
1270 ssm_->GetTopWindowId(1, uid);
1271 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
1272 ASSERT_EQ(ret, WSError::WS_OK);
1273 }
1274
1275 /**
1276 * @tc.name: TestDestroyAndDisconSpecSessionInner_03
1277 * @tc.desc: Test DestroyAndDisconnectSpecificSessionInner with WindowType APP_SUB_WINDOW_BASE
1278 * @tc.type: FUNC
1279 */
1280 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyAndDisconSpecSessionInner_03, Function | SmallTest | Level3)
1281 {
1282 ssm_->sceneSessionMap_.clear();
1283 SessionInfo info;
1284 info.bundleName_ = "test1";
1285 info.abilityName_ = "test2";
1286 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1287 uint32_t uid = 0;
1288 ssm_->GetTopWindowId(1, uid);
1289 ssm_->sceneSessionMap_.insert({1, sceneSession});
1290 ssm_->GetTopWindowId(1, uid);
1291 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1292 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1293 property->SetParentPersistentId(100);
1294 ASSERT_EQ(property->GetParentPersistentId(), 100);
1295 sceneSession->SetSessionProperty(property);
1296 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
1297 ASSERT_EQ(ret, WSError::WS_OK);
1298 }
1299
1300 /**
1301 * @tc.name: TestDestroyAndDisconSpecSessionInner_04
1302 * @tc.desc: Test DestroyAndDisconnectSpecificSessionInner with WindowType WINDOW_TYPE_DIALOG
1303 * @tc.type: FUNC
1304 */
1305 HWTEST_F(SceneSessionManagerSupplementTest, TestDestroyAndDisconSpecSessionInner_04, Function | SmallTest | Level3)
1306 {
1307 ssm_->sceneSessionMap_.clear();
1308 SessionInfo info;
1309 info.bundleName_ = "test1";
1310 info.abilityName_ = "test2";
1311 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1312 uint32_t uid = 0;
1313 ssm_->GetTopWindowId(1, uid);
1314 ssm_->sceneSessionMap_.insert({1, sceneSession});
1315 ssm_->GetTopWindowId(1, uid);
1316 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1317 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1318 property->SetParentPersistentId(100);
1319 ASSERT_EQ(property->GetParentPersistentId(), 100);
1320 sceneSession->SetSessionProperty(property);
1321 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
1322 ASSERT_EQ(ret, WSError::WS_OK);
1323 }
1324
1325 /**
1326 * @tc.name: GetFocusWindowInfo
1327 * @tc.desc: GetFocusWindowInfo
1328 * @tc.type: FUNC
1329 */
1330 HWTEST_F(SceneSessionManagerSupplementTest, GetFocusWindowInfo, Function | SmallTest | Level3)
1331 {
1332 sptr<WindowSessionProperty> property;
1333 sptr<SceneSession> sceneSession;
1334 ssm_->NotifySessionForCallback(sceneSession, true);
1335 SessionInfo info;
1336 info.bundleName_ = "test1";
1337 info.abilityName_ = "test2";
1338 info.isSystem_ = true;
1339 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1340 ASSERT_NE(sceneSession, nullptr);
1341 ssm_->NotifySessionForCallback(sceneSession, true);
1342 info.isSystem_ = false;
1343 ssm_->NotifySessionForCallback(sceneSession, true);
1344 property = sptr<WindowSessionProperty>::MakeSptr();
1345 ASSERT_NE(property, nullptr);
1346 property->SetBrightness(1.f);
1347 auto ret = ssm_->SetBrightness(sceneSession, 1.f);
1348 ASSERT_EQ(ret, WSError::WS_OK);
1349 ret = ssm_->SetBrightness(sceneSession, 2.f);
1350 ASSERT_EQ(ret, WSError::WS_OK);
1351 ssm_->displayBrightness_ = 2.f;
1352 ret = ssm_->SetBrightness(sceneSession, 2.f);
1353 ASSERT_EQ(ret, WSError::WS_OK);
1354 ssm_->displayBrightness_ = 3.f;
1355 ret = ssm_->SetBrightness(sceneSession, 2.f);
1356 ASSERT_EQ(ret, WSError::WS_OK);
1357 ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1358 ret = ssm_->UpdateBrightness(1);
1359 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1360 ssm_->sceneSessionMap_.insert({1, sceneSession});
1361 property->SetBrightness(-1.f);
1362 property->SetWindowType(WindowType::APP_WINDOW_BASE);
1363 sceneSession->SetSessionProperty(property);
1364 ret = ssm_->UpdateBrightness(1);
1365 ASSERT_EQ(ret, WSError::WS_OK);
1366 property->SetBrightness(3.f);
1367 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1368 sceneSession->SetSessionProperty(property);
1369 ret = ssm_->UpdateBrightness(1);
1370 ASSERT_EQ(ret, WSError::WS_OK);
1371 FocusChangeInfo changeInfo;
1372 ssm_->GetFocusWindowInfo(changeInfo);
1373 }
1374
1375 /**
1376 * @tc.name: TestIsSessionVisible_01
1377 * @tc.desc: Test IsSessionVisible with session is null then false
1378 * @tc.type: FUNC
1379 */
1380 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_01, Function | SmallTest | Level3)
1381 {
1382 sptr<SceneSession> sceneSession;
1383 bool ret = ssm_->IsSessionVisible(sceneSession);
1384 ASSERT_EQ(ret, false);
1385 }
1386
1387 /**
1388 * @tc.name: TestIsSessionVisible_02
1389 * @tc.desc: Test IsSessionVisible with isScbCoreEnabled_ is true then false
1390 * @tc.type: FUNC
1391 */
1392 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_02, Function | SmallTest | Level3)
1393 {
1394 SessionInfo info;
1395 info.bundleName_ = "test1";
1396 info.abilityName_ = "test2";
1397 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1398 sceneSession->SetScbCoreEnabled(true);
1399 sceneSession->isVisible_ = false;
1400
1401 bool ret = ssm_->IsSessionVisible(sceneSession);
1402 ASSERT_EQ(ret, false);
1403 }
1404
1405 /**
1406 * @tc.name: TestIsSessionVisible_03
1407 * @tc.desc: Test IsSessionVisible with WindowType is APP_SUB_WINDOW_BASE then false
1408 * @tc.type: FUNC
1409 */
1410 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_03, Function | SmallTest | Level3)
1411 {
1412 SessionInfo info;
1413 info.bundleName_ = "test1";
1414 info.abilityName_ = "test2";
1415 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1416 sceneSession->SetScbCoreEnabled(false);
1417 sceneSession->isVisible_ = true;
1418 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1419 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1420 sceneSession->SetSessionProperty(property);
1421
1422 bool ret = ssm_->IsSessionVisible(sceneSession);
1423 ASSERT_EQ(ret, false);
1424 }
1425
1426 /**
1427 * @tc.name: TestIsSessionVisible_04
1428 * @tc.desc: Test IsSessionVisible with mainSession is not null then true
1429 * @tc.type: FUNC
1430 */
1431 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_04, Function | SmallTest | Level3)
1432 {
1433 ssm_->sceneSessionMap_.clear();
1434 SessionInfo info;
1435 info.bundleName_ = "test1";
1436 info.abilityName_ = "test2";
1437 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1438 sceneSession->SetScbCoreEnabled(false);
1439 sceneSession->isVisible_ = true;
1440 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1441 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1442 SessionInfo info1;
1443 info1.bundleName_ = "test3";
1444 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1445 ssm_->sceneSessionMap_.insert({100, sceneSession1});
1446 property->SetParentPersistentId(100);
1447 sceneSession->SetSessionProperty(property);
1448 sceneSession->SetParentSession(sceneSession1);
1449
1450 bool ret = ssm_->IsSessionVisible(sceneSession);
1451 ASSERT_EQ(ret, true);
1452 }
1453
1454 /**
1455 * @tc.name: TestIsSessionVisible_05
1456 * @tc.desc: Test IsSessionVisible with session and mainSession state is STATE_ACTIVE then true
1457 * @tc.type: FUNC
1458 */
1459 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_05, Function | SmallTest | Level3)
1460 {
1461 ssm_->sceneSessionMap_.clear();
1462 SessionInfo info;
1463 info.bundleName_ = "test1";
1464 info.abilityName_ = "test2";
1465 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1466 sceneSession->SetScbCoreEnabled(false);
1467 sceneSession->isVisible_ = true;
1468 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1469 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1470 SessionInfo info1;
1471 info1.bundleName_ = "test3";
1472 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1473 ssm_->sceneSessionMap_.insert({1, sceneSession1});
1474 property->SetParentPersistentId(1);
1475 sceneSession->SetSessionProperty(property);
1476 sceneSession->SetParentSession(sceneSession1);
1477 sceneSession1->state_ = SessionState::STATE_ACTIVE;
1478 sceneSession->state_ = SessionState::STATE_ACTIVE;
1479
1480 bool ret = ssm_->IsSessionVisible(sceneSession);
1481 ASSERT_EQ(ret, true);
1482 }
1483
1484 /**
1485 * @tc.name: TestIsSessionVisible_06
1486 * @tc.desc: Test IsSessionVisible with session state is STATE_ACTIVE and mainSession state is STATE_INACTIVE then false
1487 * @tc.type: FUNC
1488 */
1489 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_06, Function | SmallTest | Level3)
1490 {
1491 ssm_->sceneSessionMap_.clear();
1492 SessionInfo info;
1493 info.bundleName_ = "test1";
1494 info.abilityName_ = "test2";
1495 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1496 sceneSession->SetScbCoreEnabled(false);
1497 sceneSession->isVisible_ = true;
1498 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1499 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1500 SessionInfo info1;
1501 info1.bundleName_ = "test3";
1502 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1503 ssm_->sceneSessionMap_.insert({1, sceneSession1});
1504 property->SetParentPersistentId(1);
1505 sceneSession->SetSessionProperty(property);
1506 sceneSession->SetParentSession(sceneSession1);
1507 sceneSession1->state_ = SessionState::STATE_INACTIVE;
1508 sceneSession->state_ = SessionState::STATE_ACTIVE;
1509
1510 bool ret = ssm_->IsSessionVisible(sceneSession);
1511 ASSERT_EQ(ret, false);
1512 }
1513
1514 /**
1515 * @tc.name: TestIsSessionVisible_07
1516 * @tc.desc: Test IsSessionVisible with session state is STATE_INACTIVE and isVisible_ is false then false
1517 * @tc.type: FUNC
1518 */
1519 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_07, Function | SmallTest | Level3)
1520 {
1521 ssm_->sceneSessionMap_.clear();
1522 SessionInfo info;
1523 info.bundleName_ = "test1";
1524 info.abilityName_ = "test2";
1525 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1526 sceneSession->SetScbCoreEnabled(false);
1527 sceneSession->isVisible_ = false;
1528 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1529 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1530 SessionInfo info1;
1531 info1.bundleName_ = "test3";
1532 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1533 ssm_->sceneSessionMap_.insert({1, sceneSession1});
1534 property->SetParentPersistentId(1);
1535 sceneSession->SetSessionProperty(property);
1536 sceneSession->SetParentSession(sceneSession1);
1537 sceneSession->state_ = SessionState::STATE_INACTIVE;
1538
1539 bool ret = ssm_->IsSessionVisible(sceneSession);
1540 ASSERT_EQ(ret, false);
1541 }
1542
1543 /**
1544 * @tc.name: TestIsSessionVisible_08
1545 * @tc.desc: Test IsSessionVisible with window type is WINDOW_TYPE_APP_MAIN_WINDOW and isVisible_ is true then true
1546 * @tc.type: FUNC
1547 */
1548 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_08, Function | SmallTest | Level3)
1549 {
1550 ssm_->sceneSessionMap_.clear();
1551 SessionInfo info;
1552 info.bundleName_ = "test1";
1553 info.abilityName_ = "test2";
1554 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1555 sceneSession->SetScbCoreEnabled(false);
1556 sceneSession->isVisible_ = true;
1557 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1558 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1559 sceneSession->SetSessionProperty(property);
1560 sceneSession->state_ = SessionState::STATE_INACTIVE;
1561
1562 bool ret = ssm_->IsSessionVisible(sceneSession);
1563 ASSERT_EQ(ret, true);
1564 }
1565
1566 /**
1567 * @tc.name: TestIsSessionVisible_09
1568 * @tc.desc: Test IsSessionVisible with window type is WINDOW_TYPE_APP_MAIN_WINDOW and isVisible_ is false then true
1569 * @tc.type: FUNC
1570 */
1571 HWTEST_F(SceneSessionManagerSupplementTest, TestIsSessionVisible_09, Function | SmallTest | Level3)
1572 {
1573 ssm_->sceneSessionMap_.clear();
1574 SessionInfo info;
1575 info.bundleName_ = "test1";
1576 info.abilityName_ = "test2";
1577 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1578 sceneSession->SetScbCoreEnabled(false);
1579 sceneSession->isVisible_ = false;
1580 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1581 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1582 sceneSession->SetSessionProperty(property);
1583 sceneSession->state_ = SessionState::STATE_ACTIVE;
1584
1585 bool ret = ssm_->IsSessionVisible(sceneSession);
1586 ASSERT_EQ(ret, true);
1587 }
1588
1589 /**
1590 * @tc.name: RegisterBindDialogTargetListener
1591 * @tc.desc: RegisterBindDialogTargetListener
1592 * @tc.type: FUNC
1593 */
1594 HWTEST_F(SceneSessionManagerSupplementTest, RegisterBindDialogTargetListener, Function | SmallTest | Level3)
1595 {
1596 SessionInfo info;
1597 info.bundleName_ = "test1";
1598 info.abilityName_ = "test2";
1599 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1600 ASSERT_NE(sceneSession, nullptr);
1601
1602 int32_t persistentId = 1;
1603 ssm_->UnregisterSpecificSessionCreateListener(persistentId);
1604 NotifyBindDialogSessionFunc func1;
1605 ssm_->RegisterBindDialogTargetListener(sceneSession, std::move(func1));
1606 ssm_->UnregisterSpecificSessionCreateListener(persistentId);
1607
1608 NotifyBindDialogSessionFunc func2;
1609 ssm_->bindDialogTargetFuncMap_.insert({ persistentId, func2 });
1610 ASSERT_NE(ssm_->bindDialogTargetFuncMap_.find(persistentId), ssm_->bindDialogTargetFuncMap_.end());
1611 ssm_->bindDialogTargetFuncMap_.erase(persistentId);
1612 ASSERT_EQ(ssm_->bindDialogTargetFuncMap_.find(persistentId), ssm_->bindDialogTargetFuncMap_.end());
1613 ssm_->bindDialogTargetFuncMap_.insert({ persistentId, func2 });
1614 ASSERT_NE(ssm_->bindDialogTargetFuncMap_.find(persistentId), ssm_->bindDialogTargetFuncMap_.end());
1615 ssm_->bindDialogTargetFuncMap_.clear();
1616 ASSERT_EQ(ssm_->bindDialogTargetFuncMap_.find(persistentId), ssm_->bindDialogTargetFuncMap_.end());
1617 }
1618 }
1619 } // namespace Rosen
1620 } // namespace OHOS