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 <bundle_mgr_proxy.h>
20 #include <bundlemgr/launcher_service.h>
21 #include "iremote_object_mocker.h"
22 #include "interfaces/include/ws_common.h"
23 #include "iremote_object_mocker.h"
24 #include "session_manager/include/scene_session_manager.h"
25 #include "screen_session_manager/include/screen_session_manager.h"
26 #include "session_info.h"
27 #include "session/host/include/scene_session.h"
28 #include "session/host/include/main_session.h"
29 #include "window_manager_agent.h"
30 #include "session_manager.h"
31 #include "zidl/window_manager_agent_interface.h"
32 #include "common_test_utils.h"
33 #include "mock/mock_session_stage.h"
34 #include "mock/mock_window_event_channel.h"
35 #include "context.h"
36
37
38 using namespace testing;
39 using namespace testing::ext;
40
41 namespace OHOS {
42 namespace Rosen {
43
44 class SceneSessionManagerTest5 : public testing::Test {
45 public:
46 static void SetUpTestCase();
47
48 static void TearDownTestCase();
49
50 void SetUp() override;
51
52 void TearDown() override;
53
54 static bool gestureNavigationEnabled_;
55
56 static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
57 static sptr<SceneSessionManager> ssm_;
58
59 private:
60 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
61 };
62
63 sptr<SceneSessionManager> SceneSessionManagerTest5::ssm_ = nullptr;
64 bool SceneSessionManagerTest5::gestureNavigationEnabled_ = true;
65
66 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest5::callbackFunc_ = [](bool enable,
__anonc13067590102(bool enable, const std::string& bundleName, GestureBackType type) 67 const std::string& bundleName, GestureBackType type) {
68 gestureNavigationEnabled_ = enable;
69 };
70
71
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)72 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
73 {
74 }
75
ProcessStatusBarEnabledChangeFuncTest(bool enable)76 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
77 {
78 }
79
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)80 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
81 {
82 }
83
SetUpTestCase()84 void SceneSessionManagerTest5::SetUpTestCase()
85 {
86 ssm_ = &SceneSessionManager::GetInstance();
87 }
88
TearDownTestCase()89 void SceneSessionManagerTest5::TearDownTestCase()
90 {
91 ssm_->sceneSessionMap_.clear();
92 ssm_ = nullptr;
93 }
94
SetUp()95 void SceneSessionManagerTest5::SetUp()
96 {
97 ssm_->sceneSessionMap_.clear();
98 }
99
TearDown()100 void SceneSessionManagerTest5::TearDown()
101 {
102 ssm_->sceneSessionMap_.clear();
103 usleep(WAIT_SYNC_IN_NS);
104 }
105
106 namespace {
107 /**
108 * @tc.name: NotifySessionTouchOutside
109 * @tc.desc: SceneSesionManager notify session touch outside
110 * @tc.type: FUNC
111 */
112 HWTEST_F(SceneSessionManagerTest5, NotifySessionTouchOutside01, Function | SmallTest | Level3)
113 {
114 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
115 ASSERT_NE(ssm_, nullptr);
116 ssm_->recoveringFinished_ = false;
117 SessionInfo info;
118 info.abilityName_ = "test1";
119 info.bundleName_ = "test2";
120 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
121 property->SetWindowType(WindowType::APP_WINDOW_BASE);
122 ssm_->NotifySessionTouchOutside(0);
123 property->SetPersistentId(1);
124 ssm_->NotifySessionTouchOutside(1);
125 }
126
127 /**
128 * @tc.name: GetStartupPageFromResource
129 * @tc.desc: GetStartupPageFromResource
130 * @tc.type: FUNC
131 */
132 HWTEST_F(SceneSessionManagerTest5, GetStartupPageFromResource, Function | SmallTest | Level3)
133 {
134 ASSERT_NE(ssm_, nullptr);
135 AppExecFwk::AbilityInfo info;
136 info.startWindowBackgroundId = 1;
137 std::string path = "path";
138 uint32_t bgColor = 1;
139 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
140 info.startWindowIconId = 0;
141 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
142 info.hapPath = "hapPath";
143 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
144 }
145
146 /**
147 * @tc.name: GetStartupPage01
148 * @tc.desc: GetStartupPage when resourceMgr is nullptr
149 * @tc.type: FUNC
150 */
151 HWTEST_F(SceneSessionManagerTest5, GetStartupPage01, Function | SmallTest | Level3)
152 {
153 ASSERT_NE(ssm_, nullptr);
154 /**
155 * @tc.steps: step1. Build input parameter.
156 */
157 SessionInfo info;
158 info.abilityName_ = "test1";
159 info.bundleName_ = "test2";
160 std::string path;
161 uint32_t bgColor = 0x00000000;
162
163 /**
164 * @tc.steps: step2. Set bundleMgr_ to nullptr.
165 */
166 sptr<AppExecFwk::IBundleMgr> tempBundleMgr = ssm_->bundleMgr_;
167 ssm_->bundleMgr_ = nullptr;
168
169 /**
170 * @tc.steps: step3. Test and check result.
171 */
172 ssm_->GetStartupPage(info, path, bgColor);
173 ssm_->bundleMgr_ = tempBundleMgr;
174 EXPECT_EQ("", path);
175 EXPECT_EQ(0x00000000, bgColor);
176 }
177
178 /**
179 * @tc.name: GetStartupPage02
180 * @tc.desc: GetStartupPage when info is cached
181 * @tc.type: FUNC
182 */
183 HWTEST_F(SceneSessionManagerTest5, GetStartupPage02, Function | SmallTest | Level3)
184 {
185 ASSERT_NE(ssm_, nullptr);
186 /**
187 * @tc.steps: step1. Build input parameter.
188 */
189 SessionInfo sessionInfo;
190 sessionInfo.moduleName_ = "moduleName";
191 sessionInfo.abilityName_ = "abilityName";
192 sessionInfo.bundleName_ = "bundleName";
193 uint32_t bgColor = 0x00000000;
194 std::string path;
195
196 /**
197 * @tc.steps: step2. Cache info.
198 */
199 const uint32_t cachedColor = 0xff000000;
200 const std::string cachedPath = "cachedPath";
201 auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_;
202 StartingWindowInfo startingWindowInfo = {
203 .startingWindowBackgroundId_ = 0,
204 .startingWindowIconId_ = 0,
205 .startingWindowBackgroundColor_ = cachedColor,
206 .startingWindowIconPath_ = cachedPath,
207 };
208 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
209 ssm_->startingWindowMap_.insert({sessionInfo.bundleName_, startingWindowInfoMap});
210
211 /**
212 * @tc.steps: step3. Test and check result.
213 */
214 ssm_->GetStartupPage(sessionInfo, path, bgColor);
215 EXPECT_EQ(path, cachedPath);
216 EXPECT_EQ(bgColor, cachedColor);
217 }
218
219 /**
220 * @tc.name: CacheStartingWindowInfo01
221 * @tc.desc: Cache new starting window info
222 * @tc.type: FUNC
223 */
224 HWTEST_F(SceneSessionManagerTest5, CacheStartingWindowInfo01, Function | SmallTest | Level3)
225 {
226 ASSERT_NE(ssm_, nullptr);
227 ssm_->startingWindowMap_.clear();
228 /**
229 * @tc.steps: step1. Build input parameter.
230 */
231 AppExecFwk::AbilityInfo abilityInfo;
232 abilityInfo.name = "abilityName";
233 abilityInfo.bundleName = "bundleName";
234 abilityInfo.moduleName = "moduleName";
235 abilityInfo.startWindowBackgroundId = 1;
236 abilityInfo.startWindowIconId = 2;
237 std::string path = "cachedPath";
238 uint32_t bgColor = 0xff000000;
239
240 /**
241 * @tc.steps: step2. Cache info and check result.
242 */
243 ssm_->CacheStartingWindowInfo(abilityInfo, path, bgColor);
244 auto iter = ssm_->startingWindowMap_.find(abilityInfo.bundleName);
245 ASSERT_NE(iter, ssm_->startingWindowMap_.end());
246 auto& infoMap = iter->second;
247 auto infoIter = infoMap.find(abilityInfo.moduleName + abilityInfo.name);
248 ASSERT_NE(infoIter, infoMap.end());
249 EXPECT_EQ(infoIter->second.startingWindowBackgroundId_, 1);
250 EXPECT_EQ(infoIter->second.startingWindowIconId_, 2);
251 EXPECT_EQ(infoIter->second.startingWindowBackgroundColor_, bgColor);
252 EXPECT_EQ(infoIter->second.startingWindowIconPath_, path);
253 }
254
255 /**
256 * @tc.name: CacheStartingWindowInfo02
257 * @tc.desc: Execute when info is cached
258 * @tc.type: FUNC
259 */
260 HWTEST_F(SceneSessionManagerTest5, CacheStartingWindowInfo02, Function | SmallTest | Level3)
261 {
262 ASSERT_NE(ssm_, nullptr);
263 ssm_->startingWindowMap_.clear();
264 /**
265 * @tc.steps: step1. Build input parameter.
266 */
267 AppExecFwk::AbilityInfo abilityInfo;
268 abilityInfo.name = "abilityName";
269 abilityInfo.bundleName = "bundleName";
270 abilityInfo.moduleName = "moduleName";
271 abilityInfo.startWindowBackgroundId = 1;
272 abilityInfo.startWindowIconId = 2;
273 std::string path = "cachedPath";
274 uint32_t bgColor = 0xff000000;
275
276 /**
277 * @tc.steps: step2. Insert one item.
278 */
279 auto key = abilityInfo.moduleName + abilityInfo.name;
280 StartingWindowInfo startingWindowInfo = {
281 .startingWindowBackgroundId_ = 0,
282 .startingWindowIconId_ = 0,
283 .startingWindowBackgroundColor_ = 0x00000000,
284 .startingWindowIconPath_ = "path",
285 };
286 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
287 ssm_->startingWindowMap_.insert({abilityInfo.bundleName, startingWindowInfoMap});
288
289 /**
290 * @tc.steps: step3. Execute and check result.
291 */
292 ssm_->CacheStartingWindowInfo(abilityInfo, path, bgColor);
293 auto iter = ssm_->startingWindowMap_.find(abilityInfo.bundleName);
294 ASSERT_NE(iter, ssm_->startingWindowMap_.end());
295 auto& infoMap = iter->second;
296 auto infoIter = infoMap.find(abilityInfo.moduleName + abilityInfo.name);
297 ASSERT_NE(infoIter, infoMap.end());
298 EXPECT_NE(infoIter->second.startingWindowBackgroundId_, 1);
299 EXPECT_NE(infoIter->second.startingWindowIconId_, 2);
300 EXPECT_NE(infoIter->second.startingWindowBackgroundColor_, bgColor);
301 EXPECT_NE(infoIter->second.startingWindowIconPath_, path);
302 }
303
304 /**
305 * @tc.name: OnBundleUpdated
306 * @tc.desc: Erase cached info when bundle update
307 * @tc.type: FUNC
308 */
309 HWTEST_F(SceneSessionManagerTest5, OnBundleUpdated, Function | SmallTest | Level3)
310 {
311 ASSERT_NE(ssm_, nullptr);
312 ssm_->startingWindowMap_.clear();
313 /**
314 * @tc.steps: step1. Insert item to map.
315 */
316 SessionInfo sessionInfo;
317 sessionInfo.moduleName_ = "moduleName";
318 sessionInfo.abilityName_ = "abilityName";
319 sessionInfo.bundleName_ = "bundleName";
320 uint32_t cachedColor = 0xff000000;
321 std::string cachedPath = "cachedPath";
322 auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_;
323 StartingWindowInfo startingWindowInfo = {
324 .startingWindowBackgroundId_ = 0,
325 .startingWindowIconId_ = 0,
326 .startingWindowBackgroundColor_ = cachedColor,
327 .startingWindowIconPath_ = cachedPath,
328 };
329 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
330 ssm_->startingWindowMap_.insert({sessionInfo.bundleName_, startingWindowInfoMap});
331 ASSERT_NE(ssm_->startingWindowMap_.size(), 0);
332
333 /**
334 * @tc.steps: step2. On bundle updated and check map.
335 */
336 ssm_->OnBundleUpdated(sessionInfo.bundleName_, 0);
337 usleep(WAIT_SYNC_IN_NS);
338 ASSERT_EQ(ssm_->startingWindowMap_.size(), 0);
339 }
340
341 /**
342 * @tc.name: OnConfigurationUpdated
343 * @tc.desc: Clear startingWindowMap when configuration update
344 * @tc.type: FUNC
345 */
346 HWTEST_F(SceneSessionManagerTest5, OnConfigurationUpdated, Function | SmallTest | Level3)
347 {
348 ASSERT_NE(ssm_, nullptr);
349 ssm_->startingWindowMap_.clear();
350 /**
351 * @tc.steps: step1. Insert item to map.
352 */
353 SessionInfo sessionInfo;
354 sessionInfo.moduleName_ = "moduleName";
355 sessionInfo.abilityName_ = "abilityName";
356 sessionInfo.bundleName_ = "bundleName";
357 uint32_t cachedColor = 0xff000000;
358 std::string cachedPath = "cachedPath";
359 auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_;
360 StartingWindowInfo startingWindowInfo = {
361 .startingWindowBackgroundId_ = 0,
362 .startingWindowIconId_ = 0,
363 .startingWindowBackgroundColor_ = cachedColor,
364 .startingWindowIconPath_ = cachedPath,
365 };
366 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
367 ssm_->startingWindowMap_.insert({sessionInfo.bundleName_, startingWindowInfoMap});
368 ASSERT_NE(ssm_->startingWindowMap_.size(), 0);
369
370 /**
371 * @tc.steps: step2. On configuration updated and check map.
372 */
373 auto configuration = std::make_shared<AppExecFwk::Configuration>();
374 ssm_->OnConfigurationUpdated(configuration);
375 usleep(WAIT_SYNC_IN_NS);
376 ASSERT_EQ(ssm_->startingWindowMap_.size(), 0);
377 }
378
379 /**
380 * @tc.name: PrepareTerminate
381 * @tc.desc: SceneSesionManager prepare terminate
382 * @tc.type: FUNC
383 */
384 HWTEST_F(SceneSessionManagerTest5, PrepareTerminate, Function | SmallTest | Level3)
385 {
386 int32_t persistentId = 1;
387 bool isPrepareTerminate = true;
388 sptr<SceneSessionManager> sceneSessionManager = sptr<SceneSessionManager>::MakeSptr();
389 ASSERT_EQ(WSError::WS_OK, sceneSessionManager->PrepareTerminate(persistentId, isPrepareTerminate));
390 }
391
392 /**
393 * @tc.name: RequestInputMethodCloseKeyboard
394 * @tc.desc: RequestInputMethodCloseKeyboard
395 * @tc.type: FUNC
396 */
397 HWTEST_F(SceneSessionManagerTest5, RequestInputMethodCloseKeyboard02, Function | SmallTest | Level3)
398 {
399 int32_t persistentId = -1;
400 bool isPrepareTerminate = true;
401 sptr<SceneSessionManager> sceneSessionManager = sptr<SceneSessionManager>::MakeSptr();
402 ASSERT_NE(sceneSessionManager, nullptr);
403 sceneSessionManager->PrepareTerminate(persistentId, isPrepareTerminate);
404 }
405
406 /**
407 * @tc.name: HandleSpecificSystemBarProperty
408 * @tc.desc: HandleSpecificSystemBarProperty
409 * @tc.type: FUNC
410 */
411 HWTEST_F(SceneSessionManagerTest5, HandleSpecificSystemBarProperty, Function | SmallTest | Level3)
412 {
413 ASSERT_NE(ssm_, nullptr);
414 SessionInfo info;
415 info.abilityName_ = "test1";
416 info.bundleName_ = "test2";
417 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
418 ASSERT_NE(property, nullptr);
419 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
420 WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR;
421 ssm_->HandleSpecificSystemBarProperty(type, property, sceneSession);
422 }
423
424 /**
425 * @tc.name: UpdateBrightness
426 * @tc.desc: UpdateBrightness
427 * @tc.type: FUNC
428 */
429 HWTEST_F(SceneSessionManagerTest5, UpdateBrightness, Function | SmallTest | Level3)
430 {
431 ASSERT_NE(ssm_, nullptr);
432 SessionInfo info;
433 info.abilityName_ = "test1";
434 info.bundleName_ = "test2";
435 info.isSystem_ = false;
436 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
437 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
438 ASSERT_NE(property, nullptr);
439 ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
440 ssm_->UpdateBrightness(1);
441 FocusChangeInfo focusInfo;
442 ssm_->GetCurrentUserId();
443 ssm_->GetFocusWindowInfo(focusInfo);
444 }
445
446 /**
447 * @tc.name: IsNeedUpdateBrightness
448 * @tc.desc: IsNeedUpdateBrightness
449 * @tc.type: FUNC
450 */
451 HWTEST_F(SceneSessionManagerTest5, IsNeedUpdateBrightness, Function | SmallTest | Level3)
452 {
453 ASSERT_NE(ssm_, nullptr);
454 ssm_->displayBrightness_ = -1;
455 bool isNeed = ssm_->IsNeedUpdateBrightness(-1);
456 EXPECT_EQ(isNeed, false);
457 ssm_->displayBrightness_ = 0;
458 ssm_->brightnessSessionId_ = 1;
459 isNeed = ssm_->IsNeedUpdateBrightness(-1);
460 EXPECT_EQ(isNeed, true);
461 SessionInfo info;
462 info.abilityName_ = "test1";
463 info.bundleName_ = "test1";
464 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
465 sceneSession->persistentId_ = 1;
466 sceneSession->state_ = SessionState::STATE_FOREGROUND;
467 ssm_->sceneSessionMap_.clear();
468 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
469 isNeed = ssm_->IsNeedUpdateBrightness(-1);
470 EXPECT_EQ(isNeed, false);
471 ssm_->sceneSessionMap_.clear();
472 }
473
474 /**
475 * @tc.name: RegisterSessionSnapshotFunc
476 * @tc.desc: RegisterSessionSnapshotFunc
477 * @tc.type: FUNC
478 */
479 HWTEST_F(SceneSessionManagerTest5, RegisterSessionSnapshotFunc, Function | SmallTest | Level3)
480 {
481 SessionInfo info;
482 info.abilityName_ = "test1";
483 info.bundleName_ = "test2";
484 sptr<SceneSession> sceneSession = nullptr;
485 ssm_->RegisterSessionSnapshotFunc(sceneSession);
486 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
487 ASSERT_NE(property, nullptr);
488 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
489 ASSERT_NE(sceneSession1, nullptr);
490 ssm_->RegisterSessionSnapshotFunc(sceneSession);
491 info.isSystem_ = false;
492 ssm_->RegisterSessionSnapshotFunc(sceneSession);
493 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo;
494 ssm_->RegisterSessionSnapshotFunc(sceneSession);
495 }
496
497 /**
498 * @tc.name: RequestAllAppSessionUnfocus
499 * @tc.desc: RequestAllAppSessionUnfocus
500 * @tc.type: FUNC
501 */
502 HWTEST_F(SceneSessionManagerTest5, RequestAllAppSessionUnfocus, Function | SmallTest | Level3)
503 {
504 SessionInfo info;
505 info.abilityName_ = "test1";
506 info.bundleName_ = "test2";
507 sptr<SceneSession> sceneSession = nullptr;
508 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
509 ASSERT_NE(property, nullptr);
510 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
511 ASSERT_NE(sceneSession, nullptr);
512 ssm_->HandleHideNonSystemFloatingWindows(property, sceneSession);
513 ssm_->RequestAllAppSessionUnfocus();
514 }
515
516 /**
517 * @tc.name: RequestFocusStatus
518 * @tc.desc: RequestFocusStatus
519 * @tc.type: FUNC
520 */
521 HWTEST_F(SceneSessionManagerTest5, RequestFocusStatus, Function | SmallTest | Level3)
522 {
523 SessionInfo info;
524 info.abilityName_ = "RequestFocusStatus";
525 info.bundleName_ = "RequestFocusStatus";
526 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
527 ASSERT_NE(sceneSession, nullptr);
528 sceneSession->persistentId_ = 1;
529 ssm_->sceneSessionMap_.clear();
530 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
531 WMError ret = ssm_->RequestFocusStatus(1, true, true, FocusChangeReason::DEFAULT);
532 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_CALLING);
533 ssm_->sceneSessionMap_.clear();
534 }
535
536 /**
537 * @tc.name: RequestFocusStatus01
538 * @tc.desc: RequestFocusStatus01
539 * @tc.type: FUNC
540 */
541 HWTEST_F(SceneSessionManagerTest5, RequestFocusStatus01, Function | SmallTest | Level3)
542 {
543 SessionInfo info;
544 info.abilityName_ = "RequestFocusStatus01";
545 info.bundleName_ = "com.ohos.sceneboard";
546 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
547 ASSERT_NE(sceneSession, nullptr);
548 sceneSession->persistentId_ = 1;
549 ssm_->sceneSessionMap_.clear();
550 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
551 WMError ret = ssm_->RequestFocusStatus(1, true, true, FocusChangeReason::DEFAULT);
552 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_CALLING);
553 ret = ssm_->RequestFocusStatus(1, false, true, FocusChangeReason::DEFAULT);
554 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_CALLING);
555 ssm_->sceneSessionMap_.clear();
556 }
557
558 /**
559 * @tc.name: RequestSessionFocus
560 * @tc.desc: RequestSessionFocus
561 * @tc.type: FUNC
562 */
563 HWTEST_F(SceneSessionManagerTest5, RequestSessionFocus, Function | SmallTest | Level3)
564 {
565 FocusChangeReason reason = FocusChangeReason::DEFAULT;
566 WSError ret = ssm_->RequestSessionFocus(0, true, reason);
567 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
568 ret = ssm_->RequestSessionFocus(100, true, reason);
569 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
570
571 SessionInfo info;
572 info.abilityName_ = "test1";
573 info.bundleName_ = "test2";
574 sptr<SceneSession> sceneSession = nullptr;
575 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
576 ASSERT_NE(property, nullptr);
577 property->SetFocusable(false);
578 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
579 ASSERT_NE(sceneSession1, nullptr);
580
581 sceneSession1->property_ = property;
582 ASSERT_NE(sceneSession1->property_, nullptr);
583 sceneSession1->persistentId_ = 1;
584 sceneSession1->isVisible_ = true;
585 sceneSession1->state_ = SessionState::STATE_ACTIVE;
586 sceneSession1->focusedOnShow_ = true;
587 sceneSession1->property_->focusable_ = true;
588 sceneSession1->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
589 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
590 focusGroup->SetFocusedSessionId(2);
591 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
592 ret = ssm_->RequestSessionFocus(1, true, reason);
593 ASSERT_EQ(ret, WSError::WS_OK);
594 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
595 ssm_->sceneSessionMap_.clear();
596 }
597
598 /**
599 * @tc.name: RequestFocusClient
600 * @tc.desc: RequestFocusClient
601 * @tc.type: FUNC
602 */
603 HWTEST_F(SceneSessionManagerTest5, RequestFocusClient, Function | SmallTest | Level3)
604 {
605 SessionInfo info;
606 info.abilityName_ = "RequestFocusTest1";
607 info.bundleName_ = "RequestFocusTest1";
608 sptr<SceneSession> sceneSession = nullptr;
609 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
610 ASSERT_NE(property, nullptr);
611 property->SetFocusable(true);
612 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
613 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
614 ASSERT_NE(sceneSession, nullptr);
615 sceneSession->property_ = property;
616 sceneSession->persistentId_ = 1;
617 sceneSession->isVisible_ = true;
618 sceneSession->state_ = SessionState::STATE_ACTIVE;
619 sceneSession->SetZOrder(1);
620
621 SessionInfo info2;
622 info2.abilityName_ = "RequestFocusTest2";
623 info2.bundleName_ = "RequestFocusTest2";
624 sptr<SceneSession> sceneSession2 = nullptr;
625 sptr<WindowSessionProperty> property2 = sptr<WindowSessionProperty>::MakeSptr();
626 ASSERT_NE(property2, nullptr);
627 property2->SetFocusable(true);
628 property2->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
629 sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
630 ASSERT_NE(sceneSession2, nullptr);
631 sceneSession2->property_ = property2;
632 sceneSession2->persistentId_ = 2;
633 sceneSession2->isVisible_ = true;
634 sceneSession2->state_ = SessionState::STATE_ACTIVE;
635 sceneSession2->SetZOrder(2);
636 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
637 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
638 FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST;
639
640 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
641 ssm_->RequestSessionFocus(1, false, reason);
642 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
643 ssm_->RequestSessionFocus(2, false, reason);
644 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 2);
645 ssm_->RequestSessionUnfocus(2, reason);
646 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
647 ssm_->RequestSessionUnfocus(1, reason);
648 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 0);
649 ssm_->sceneSessionMap_.clear();
650 }
651
652 /**
653 * @tc.name: RequestFocusClient
654 * @tc.desc: RequestFocusClient
655 * @tc.type: FUNC
656 */
657 HWTEST_F(SceneSessionManagerTest5, RequestFocusClient01, Function | SmallTest | Level3)
658 {
659 SessionInfo info;
660 info.abilityName_ = "RequestFocusTest1";
661 info.bundleName_ = "RequestFocusTest1";
662 sptr<SceneSession> sceneSession = nullptr;
663 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
664 ASSERT_NE(property, nullptr);
665 property->SetFocusable(true);
666 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
667 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
668 ASSERT_NE(sceneSession, nullptr);
669 sceneSession->property_ = property;
670 sceneSession->persistentId_ = 1;
671 sceneSession->isVisible_ = true;
672 sceneSession->state_ = SessionState::STATE_ACTIVE;
673 sceneSession->SetZOrder(1);
674
675 SessionInfo info2;
676 info2.abilityName_ = "RequestFocusTest2";
677 info2.bundleName_ = "RequestFocusTest2";
678 sptr<SceneSession> sceneSession2 = nullptr;
679 sptr<WindowSessionProperty> property2 = sptr<WindowSessionProperty>::MakeSptr();
680 ASSERT_NE(property2, nullptr);
681 property2->SetFocusable(true);
682 property2->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
683 sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
684 ASSERT_NE(sceneSession2, nullptr);
685 sceneSession2->property_ = property2;
686 sceneSession2->persistentId_ = 2;
687 sceneSession2->isVisible_ = true;
688 sceneSession2->state_ = SessionState::STATE_ACTIVE;
689 sceneSession2->SetZOrder(2);
690
691 SessionInfo info3;
692 info3.abilityName_ = "RequestFocusTest3";
693 info3.bundleName_ = "RequestFocusTest3";
694 sptr<SceneSession> sceneSession3 = nullptr;
695 sptr<WindowSessionProperty> property3 = sptr<WindowSessionProperty>::MakeSptr();
696 ASSERT_NE(property3, nullptr);
697 property3->SetFocusable(true);
698 property3->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
699 sceneSession3 = sptr<SceneSession>::MakeSptr(info3, nullptr);
700 ASSERT_NE(sceneSession3, nullptr);
701 sceneSession3->property_ = property3;
702 sceneSession3->persistentId_ = 3;
703 sceneSession3->isVisible_ = true;
704 sceneSession3->state_ = SessionState::STATE_ACTIVE;
705 sceneSession3->SetZOrder(3);
706 sceneSession3->blockingFocus_ = true;
707 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
708 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
709 ssm_->sceneSessionMap_.insert({sceneSession3->GetPersistentId(), sceneSession3});
710 FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST;
711
712 ssm_->RequestSessionFocus(1, false, reason);
713 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
714 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
715 ssm_->RequestSessionFocus(3, false, reason);
716 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 3);
717 ssm_->RequestSessionFocus(2, false, reason);
718 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 2);
719 auto ret = ssm_->RequestSessionUnfocus(3, reason);
720 ASSERT_EQ(WSError::WS_DO_NOTHING, ret);
721 ssm_->RequestSessionUnfocus(2, reason);
722 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
723 ssm_->sceneSessionMap_.clear();
724 }
725
726 /**
727 * @tc.name: SetShiftFocusListener
728 * @tc.desc: SetShiftFocusListener
729 * @tc.type: FUNC
730 */
731 HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | Level3)
732 {
733 ASSERT_NE(ssm_, nullptr);
734 SessionInfo info;
735 info.abilityName_ = "test1";
736 info.bundleName_ = "test2";
737 FocusChangeReason reason = FocusChangeReason::SPLIT_SCREEN;
738 sptr<SceneSession> sceneSession = nullptr;
739 ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession, false, reason);
740 info.isSystem_ = true;
741 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
742 ASSERT_NE(property, nullptr);
743 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
744 ASSERT_NE(sceneSession1, nullptr);
745 ProcessShiftFocusFunc fun;
746 NotifySCBAfterUpdateFocusFunc func;
747 ssm_->SetShiftFocusListener(fun);
748 ssm_->SetSCBFocusedListener(func);
749 ssm_->SetSCBUnfocusedListener(func);
750 ProcessCallingSessionIdChangeFunc func1;
751 ssm_->SetCallingSessionIdSessionListenser(func1);
752 ProcessStartUIAbilityErrorFunc func2;
753 ssm_->SetStartUIAbilityErrorListener(func2);
754 ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession1, false, reason);
755 }
756
757 /**
758 * @tc.name: UpdateFocusStatus
759 * @tc.desc: UpdateFocusStatus
760 * @tc.type: FUNC
761 */
762 HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus, Function | SmallTest | Level3)
763 {
764 ASSERT_NE(ssm_, nullptr);
765 SessionInfo info;
766 info.abilityName_ = "test1";
767 info.bundleName_ = "test2";
768 sptr<SceneSession> sceneSession = nullptr;
769 ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, false);
770 ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true);
771
772 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
773 ASSERT_NE(sceneSession1, nullptr);
774 ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession1, true);
775 ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession1, false);
776 }
777
778 /**
779 * @tc.name: UpdateFocusStatus01
780 * @tc.desc: UpdateFocusStatus
781 * @tc.type: FUNC
782 */
783 HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus01, Function | SmallTest | Level3)
784 {
785 ASSERT_NE(ssm_, nullptr);
786 sptr<SceneSession> sceneSession = nullptr;
787 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
788 focusGroup->SetFocusedSessionId(1);
789
790 ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, false);
791 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
792 ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true);
793 ASSERT_NE(focusGroup->GetFocusedSessionId(), 1);
794 }
795
796 /**
797 * @tc.name: UpdateFocusStatus02
798 * @tc.desc: Verify that the NotifyFocusStatusByMission function is called.
799 * @tc.type: FUNC
800 */
801 HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus02, TestSize.Level1)
802 {
803 ASSERT_NE(ssm_, nullptr);
804 SessionInfo info;
805 info.abilityName_ = "UpdateFocusStatus02";
806 info.bundleName_ = "UpdateFocusStatus02";
807 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
808 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
809 focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(true);
810 ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true);
811 }
812
813 /**
814 * @tc.name: RequestSessionUnfocus
815 * @tc.desc: RequestSessionUnfocus
816 * @tc.type: FUNC
817 */
818 HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus, Function | SmallTest | Level3)
819 {
820 SessionInfo info;
821 info.abilityName_ = "test1";
822 info.bundleName_ = "test2";
823 sptr<SceneSession> sceneSession = nullptr;
824 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
825 ASSERT_NE(property, nullptr);
826 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
827 ASSERT_NE(sceneSession1, nullptr);
828 FocusChangeReason reason = FocusChangeReason::MOVE_UP;
829 WSError ret = ssm_->RequestSessionUnfocus(0, reason);
830 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
831
832 sptr<SceneSession> focusedSession = sptr<SceneSession>::MakeSptr(info, nullptr);
833 ASSERT_NE(focusedSession, nullptr);
834 focusedSession->property_ = property;
835 ASSERT_NE(focusedSession->property_, nullptr);
836 sceneSession1->persistentId_ = 1;
837 focusedSession->persistentId_ = 2;
838 focusedSession->property_->parentPersistentId_ = 1;
839 ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 1);
840 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
841 ssm_->sceneSessionMap_.insert({focusedSession->GetPersistentId(), focusedSession});
842 ret = ssm_->RequestSessionUnfocus(1, reason);
843 ASSERT_EQ(ret, WSError::WS_OK);
844 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
845 ASSERT_NE(focusGroup->GetFocusedSessionId(), 1);
846 ssm_->sceneSessionMap_.clear();
847 }
848
849 /**
850 * @tc.name: RequestFocusSpecificCheck
851 * @tc.desc: RequestFocusSpecificCheck
852 * @tc.type: FUNC
853 */
854 HWTEST_F(SceneSessionManagerTest5, RequestFocusSpecificCheck, Function | SmallTest | Level3)
855 {
856 SessionInfo info;
857 info.abilityName_ = "test1";
858 info.bundleName_ = "test2";
859 sptr<SceneSession> sceneSession = nullptr;
860 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
861 ASSERT_NE(property, nullptr);
862 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
863 ASSERT_NE(sceneSession1, nullptr);
864 FocusChangeReason reason = FocusChangeReason::MOVE_UP;
865 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
866 WSError ret = ssm_->RequestFocusSpecificCheck(DEFAULT_DISPLAY_ID, sceneSession1, true, reason);
867 EXPECT_EQ(ret, WSError::WS_OK);
868 FocusChangeReason reason1 = FocusChangeReason::SPLIT_SCREEN;
869 property->SetWindowType(WindowType::APP_WINDOW_BASE);
870 ret = ssm_->RequestFocusSpecificCheck(DEFAULT_DISPLAY_ID, sceneSession1, true, reason1);
871 EXPECT_EQ(ret, WSError::WS_OK);
872 }
873
874 /**
875 * @tc.name: NotifyFocusStatus
876 * @tc.desc: NotifyFocusStatus
877 * @tc.type: FUNC
878 */
879 HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatus, Function | SmallTest | Level3)
880 {
881 SessionInfo info;
882 info.abilityName_ = "test1";
883 info.bundleName_ = "test2";
884 auto focusGroup = sptr<FocusGroup>::MakeSptr(DEFAULT_DISPLAY_ID);
885 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
886 ASSERT_NE(sceneSession1, nullptr);
887 ssm_->NotifyFocusStatus(sceneSession1, false, focusGroup);
888 info.isSystem_ = true;
889 ssm_->NotifyFocusStatus(sceneSession1, true, focusGroup);
890 }
891
892 /**
893 * @tc.name: NotifyFocusStatusByMission
894 * @tc.desc: NotifyFocusStatusByMission
895 * @tc.type: FUNC
896 */
897 HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatusByMission, Function | SmallTest | Level3)
898 {
899 SessionInfo info;
900 info.abilityName_ = "test1";
901 info.bundleName_ = "test2";
902 sptr<SceneSession> sceneSession = nullptr;
903 sptr<SceneSession> currSession = nullptr;
904 ssm_->NotifyFocusStatusByMission(sceneSession, currSession);
905 ASSERT_EQ(false, ssm_->MissionChanged(sceneSession, currSession));
906 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
907 ASSERT_NE(sceneSession, nullptr);
908 ssm_->NotifyFocusStatusByMission(sceneSession, currSession);
909 ssm_->MissionChanged(sceneSession, currSession);
910 currSession = sptr<SceneSession>::MakeSptr(info, nullptr);
911 ASSERT_NE(currSession, nullptr);
912 ssm_->NotifyFocusStatusByMission(sceneSession, currSession);
913 ssm_->MissionChanged(sceneSession, currSession);
914 info.isSystem_ = true;
915 ssm_->NotifyFocusStatusByMission(sceneSession, currSession);
916 ssm_->MissionChanged(sceneSession, currSession);
917 }
918
919 /**
920 * @tc.name: UpdateFocus
921 * @tc.desc: UpdateFocus
922 * @tc.type: FUNC
923 */
924 HWTEST_F(SceneSessionManagerTest5, UpdateFocus, Function | SmallTest | Level3)
925 {
926 SessionInfo info;
927 info.abilityName_ = "test1";
928 info.bundleName_ = "test2";
929 sptr<SceneSession> sceneSession = nullptr;
930 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
931 ASSERT_NE(property, nullptr);
932 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
933 ASSERT_NE(sceneSession1, nullptr);
934 ssm_->UpdateFocus(1, true);
935 ssm_->UpdateFocus(0, false);
936 }
937
938 /**
939 * @tc.name: RequestSessionFocusImmediately
940 * @tc.desc: RequestSessionFocusImmediately
941 * @tc.type: FUNC
942 */
943 HWTEST_F(SceneSessionManagerTest5, RequestSessionFocusImmediately, Function | SmallTest | Level3)
944 {
945 SessionInfo info;
946 info.abilityName_ = "test1";
947 info.bundleName_ = "test2";
948 sptr<SceneSession> sceneSession = nullptr;
949 WSError ret = ssm_->RequestSessionFocusImmediately(0);
950 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
951 auto focusGroup = sptr<FocusGroup>::MakeSptr(DEFAULT_DISPLAY_ID);
952 ssm_->RequestFocusBasicCheck(0, focusGroup);
953 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
954 ASSERT_NE(sceneSession1, nullptr);
955 ret = ssm_->RequestSessionFocusImmediately(1);
956 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
957 ssm_->RequestFocusBasicCheck(1, focusGroup);
958 usleep(WAIT_SYNC_IN_NS);
959 }
960
961 /**
962 * @tc.name: RequestFocusBasicCheck
963 * @tc.desc: RequestFocusBasicCheck
964 * @tc.type: FUNC
965 */
966 HWTEST_F(SceneSessionManagerTest5, RequestFocusBasicCheck, Function | SmallTest | Level3)
967 {
968 sptr<FocusGroup> focusGroup = nullptr;
969 WSError ret = ssm_->RequestFocusBasicCheck(0, focusGroup);
970 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
971 ret = ssm_->RequestFocusBasicCheck(1, focusGroup);
972 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
973 focusGroup = sptr<FocusGroup>::MakeSptr(DEFAULT_DISPLAY_ID);
974 focusGroup->SetFocusedSessionId(1);
975 ret = ssm_->RequestFocusBasicCheck(1, focusGroup);
976 ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
977 ret = ssm_->RequestFocusBasicCheck(2, focusGroup);
978 ASSERT_EQ(ret, WSError::WS_OK);
979 }
980
981 /**
982 * @tc.name: CheckFocusIsDownThroughBlockingType
983 * @tc.desc: CheckFocusIsDownThroughBlockingType
984 * @tc.type: FUNC
985 */
986 HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType, Function | SmallTest | Level3)
987 {
988 SessionInfo info;
989 info.abilityName_ = "test1";
990 info.bundleName_ = "test1";
991 SessionInfo info2;
992 info2.abilityName_ = "test2";
993 info2.bundleName_ = "test2";
994 sptr<SceneSession> sceneSession = nullptr;
995 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
996 ASSERT_NE(sceneSession1, nullptr);
997 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
998 ASSERT_NE(sceneSession2, nullptr);
999 bool ret = ssm_->CheckFocusIsDownThroughBlockingType(sceneSession1, sceneSession2, true);
1000 ASSERT_EQ(ret, false);
1001 }
1002
1003 /**
1004 * @tc.name: CheckFocusIsDownThroughBlockingType
1005 * @tc.desc: CheckFocusIsDownThroughBlockingType
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType01, Function | SmallTest | Level3)
1009 {
1010 ASSERT_NE(ssm_, nullptr);
1011 SessionInfo info;
1012 info.abilityName_ = "test1";
1013 info.bundleName_ = "test2";
1014 sptr<SceneSession> requestSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1015 ASSERT_NE(requestSceneSession, nullptr);
1016 sptr<SceneSession> focusedSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1017 ASSERT_NE(focusedSession, nullptr);
1018 bool includingAppSession = true;
1019 bool ret = ssm_->CheckFocusIsDownThroughBlockingType(requestSceneSession, focusedSession, includingAppSession);
1020 ASSERT_EQ(ret, false);
1021
1022 requestSceneSession->SetZOrder(0);
1023 focusedSession->SetZOrder(1);
1024 focusedSession->blockingFocus_ = true;
1025 focusedSession->state_ = SessionState::STATE_FOREGROUND;
1026 focusedSession->isVisible_ = true;
1027 ssm_->sceneSessionMap_.insert({0, requestSceneSession});
1028 ssm_->sceneSessionMap_.insert({1, focusedSession});
1029 ret = ssm_->CheckFocusIsDownThroughBlockingType(requestSceneSession, focusedSession, includingAppSession);
1030 ASSERT_EQ(ret, true);
1031 }
1032
1033 /**
1034 * @tc.name: CheckTopmostWindowFocus
1035 * @tc.desc: CheckTopmostWindowFocus
1036 * @tc.type: FUNC
1037 */
1038 HWTEST_F(SceneSessionManagerTest5, CheckTopmostWindowFocus, Function | SmallTest | Level3)
1039 {
1040 ASSERT_NE(ssm_, nullptr);
1041 SessionInfo info;
1042 info.abilityName_ = "test1";
1043 info.bundleName_ = "test2";
1044
1045 sptr<SceneSession> focusedSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1046 ASSERT_NE(focusedSession, nullptr);
1047 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1048 ASSERT_NE(sceneSession, nullptr);
1049
1050 bool ret = ssm_->CheckTopmostWindowFocus(focusedSession, sceneSession);
1051 ASSERT_EQ(ret, false);
1052
1053 focusedSession = sptr<MainSession>::MakeSptr(info, nullptr);
1054 focusedSession->SetTopmost(true);
1055 ret = ssm_->CheckTopmostWindowFocus(focusedSession, sceneSession);
1056 ASSERT_EQ(ret, true);
1057 }
1058
1059 /**
1060 * @tc.name: CheckRequestFocusImmdediately
1061 * @tc.desc: CheckRequestFocusImmdediately
1062 * @tc.type: FUNC
1063 */
1064 HWTEST_F(SceneSessionManagerTest5, CheckRequestFocusImmdediately, Function | SmallTest | Level3)
1065 {
1066 ASSERT_NE(ssm_, nullptr);
1067 SessionInfo info;
1068 info.abilityName_ = "test1";
1069 info.bundleName_ = "test2";
1070
1071 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1072 ASSERT_NE(sceneSession, nullptr);
1073 bool ret = ssm_->CheckRequestFocusImmdediately(sceneSession);
1074 ASSERT_EQ(ret, false);
1075
1076 sptr<Session> session = sptr<Session>::MakeSptr(info);
1077 session->persistentId_ = 1;
1078 sceneSession->dialogVec_.push_back(session);
1079 ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 1);
1080 ret = ssm_->CheckRequestFocusImmdediately(sceneSession);
1081 ASSERT_EQ(ret, true);
1082 }
1083
1084 /**
1085 * @tc.name: GetNextFocusableSession
1086 * @tc.desc: GetNextFocusableSession
1087 * @tc.type: FUNC
1088 */
1089 HWTEST_F(SceneSessionManagerTest5, GetNextFocusableSession, Function | SmallTest | Level3)
1090 {
1091 int32_t persistentId = 0;
1092 ASSERT_NE(ssm_, nullptr);
1093 SessionInfo info;
1094 info.abilityName_ = "test1";
1095 info.bundleName_ = "test2";
1096
1097 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1098 ASSERT_NE(sceneSession, nullptr);
1099 sptr<SceneSession> result = ssm_->GetNextFocusableSession(DEFAULT_DISPLAY_ID, persistentId);
1100 ASSERT_EQ(result, nullptr);
1101
1102 sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
1103 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1104 persistentId = 1;
1105 result = ssm_->GetNextFocusableSession(DEFAULT_DISPLAY_ID, persistentId);
1106 ASSERT_EQ(result, nullptr);
1107 }
1108
1109 /**
1110 * @tc.name: GetTopNearestBlockingFocusSession
1111 * @tc.desc: GetTopNearestBlockingFocusSession
1112 * @tc.type: FUNC
1113 */
1114 HWTEST_F(SceneSessionManagerTest5, GetTopNearestBlockingFocusSession, Function | SmallTest | Level3)
1115 {
1116 ASSERT_NE(ssm_, nullptr);
1117 SessionInfo info;
1118 info.abilityName_ = "test1";
1119 info.bundleName_ = "test2";
1120
1121 ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 2, true);
1122 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1123 ASSERT_NE(sceneSession, nullptr);
1124 ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true);
1125
1126 Session session = Session(info);
1127 session.property_ = nullptr;
1128 ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true);
1129 sptr<SceneSession> session_ = nullptr;
1130 ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true);
1131 session_ = sptr<SceneSession>::MakeSptr(info, nullptr);
1132 ASSERT_NE(session_, nullptr);
1133 ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true);
1134 }
1135
1136 /**
1137 * @tc.name: PreloadInLakeApp、UpdateSessionAvoidAreaListener
1138 * @tc.desc: PreloadInLakeApp、UpdateSessionAvoidAreaListener
1139 * @tc.type: FUNC
1140 */
1141 HWTEST_F(SceneSessionManagerTest5, PreloadInLakeApp, Function | SmallTest | Level3)
1142 {
1143 ASSERT_NE(ssm_, nullptr);
1144 SessionInfo info;
1145 info.abilityName_ = "test1";
1146 info.bundleName_ = "test2";
1147 int32_t persistentId = 0;
1148
1149 ssm_->PreloadInLakeApp("");
1150 sptr<SceneSession> sceneSession = nullptr;
1151
1152 ssm_->UpdateSessionAvoidAreaListener(persistentId, true);
1153 sceneSession = ssm_->CreateSceneSession(info, nullptr);
1154 ASSERT_NE(nullptr, sceneSession);
1155 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1156 ssm_->UpdateSessionAvoidAreaListener(persistentId, true);
1157 }
1158
1159 /**
1160 * @tc.name: NotifyMMIWindowPidChange
1161 * @tc.desc: NotifyMMIWindowPidChange
1162 * @tc.type: FUNC
1163 */
1164 HWTEST_F(SceneSessionManagerTest5, NotifyMMIWindowPidChange, Function | SmallTest | Level3)
1165 {
1166 ASSERT_NE(ssm_, nullptr);
1167 SessionInfo info;
1168 info.abilityName_ = "test1";
1169 info.bundleName_ = "test2";
1170 sptr<SceneSession> sceneSession = nullptr;
1171 ssm_->NotifyMMIWindowPidChange(0, true);
1172 sceneSession = ssm_->CreateSceneSession(info, nullptr);
1173 ASSERT_NE(nullptr, sceneSession);
1174 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1175 }
1176
1177 /**
1178 * @tc.name: CheckSessionPropertyOnRecovery
1179 * @tc.desc: CheckSessionPropertyOnRecovery
1180 * @tc.type: FUNC
1181 */
1182 HWTEST_F(SceneSessionManagerTest5, CheckSessionPropertyOnRecovery, Function | SmallTest | Level3)
1183 {
1184 ASSERT_NE(ssm_, nullptr);
1185 SessionInfo info;
1186 info.abilityName_ = "test1";
1187 info.bundleName_ = "test2";
1188 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1189 ASSERT_NE(property, nullptr);
1190 property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1191 property->SetWindowFlags(123);
1192 WSError result = ssm_->CheckSessionPropertyOnRecovery(property, false);
1193 ASSERT_EQ(result, WSError::WS_ERROR_NOT_SYSTEM_APP);
1194
1195 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1196 property->SetParentPersistentId(111);
1197 result = ssm_->CheckSessionPropertyOnRecovery(property, true);
1198 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
1199 }
1200
1201 /**
1202 * @tc.name: InitSnapshotCache
1203 * @tc.desc: InitSnapshotCache
1204 * @tc.type: FUNC
1205 */
1206 HWTEST_F(SceneSessionManagerTest5, InitSnapshotCache, Function | SmallTest | Level3)
1207 {
1208 ASSERT_NE(ssm_, nullptr);
1209 ssm_->InitSnapshotCache();
1210 if (ssm_->systemConfig_.windowUIType_ == WindowUIType::PC_WINDOW) {
1211 ASSERT_EQ(ssm_->snapshotCapacity_, 50);
1212 } else if (ssm_->systemConfig_.windowUIType_ == WindowUIType::PAD_WINDOW) {
1213 ASSERT_EQ(ssm_->snapshotCapacity_, 8);
1214 } else {
1215 ASSERT_EQ(ssm_->snapshotCapacity_, 3);
1216 }
1217 }
1218
1219 /**
1220 * @tc.name: PutSnapshotToCache
1221 * @tc.desc: PutSnapshotToCache
1222 * @tc.type: FUNC
1223 */
1224 HWTEST_F(SceneSessionManagerTest5, PutSnapshotToCache, Function | SmallTest | Level3)
1225 {
1226 ASSERT_NE(ssm_, nullptr);
1227 ssm_->sceneSessionMap_.clear();
1228 SessionInfo info;
1229 info.abilityName_ = "test1";
1230 info.bundleName_ = "test2";
1231 info.persistentId_ = 30;
1232 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1233 std::string bundleName = "testBundleName";
1234 int32_t persistentId = 30;
1235 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
1236 sceneSession->snapshot_ = std::make_shared<Media::PixelMap>();
1237 ssm_->sceneSessionMap_.insert({30, sceneSession});
1238 for (int32_t id = 30; id <= 30 + ssm_->snapshotCapacity_; ++id) {
1239 ssm_->PutSnapshotToCache(id);
1240 }
1241 ASSERT_EQ(sceneSession->snapshot_, nullptr);
1242 }
1243
1244 /**
1245 * @tc.name: VisitSnapshotFromCache
1246 * @tc.desc: VisitSnapshotFromCache
1247 * @tc.type: FUNC
1248 */
1249 HWTEST_F(SceneSessionManagerTest5, VisitSnapshotFromCache, Function | SmallTest | Level3)
1250 {
1251 ASSERT_NE(ssm_, nullptr);
1252 ssm_->sceneSessionMap_.clear();
1253 SessionInfo info;
1254 info.abilityName_ = "test1";
1255 info.bundleName_ = "test2";
1256 info.persistentId_ = 30;
1257 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1258 std::string bundleName = "testBundleName";
1259 int32_t persistentId = 30;
1260 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
1261 ssm_->sceneSessionMap_.insert({30, sceneSession});
1262 sceneSession->snapshot_ = std::make_shared<Media::PixelMap>();
1263 for (int32_t id = 30; id < 30 + ssm_->snapshotCapacity_; ++id) {
1264 ssm_->PutSnapshotToCache(id);
1265 }
1266 ssm_->VisitSnapshotFromCache(30);
1267 ssm_->PutSnapshotToCache(30 + ssm_->snapshotCapacity_);
1268 ASSERT_NE(sceneSession->snapshot_, nullptr);
1269 }
1270
1271 /**
1272 * @tc.name: RemoveSnapshotFromCache
1273 * @tc.desc: RemoveSnapshotFromCache
1274 * @tc.type: FUNC
1275 */
1276 HWTEST_F(SceneSessionManagerTest5, RemoveSnapshotFromCache, Function | SmallTest | Level3)
1277 {
1278 ASSERT_NE(ssm_, nullptr);
1279 ssm_->sceneSessionMap_.clear();
1280 SessionInfo info;
1281 info.abilityName_ = "test1";
1282 info.bundleName_ = "test2";
1283 info.persistentId_ = 30;
1284 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1285 std::string bundleName = "testBundleName";
1286 int32_t persistentId = 30;
1287 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
1288 ssm_->sceneSessionMap_.insert({30, sceneSession});
1289 sceneSession->snapshot_ = std::make_shared<Media::PixelMap>();
1290 for (int32_t id = 30; id < 30 + ssm_->snapshotCapacity_; ++id) {
1291 ssm_->PutSnapshotToCache(id);
1292 }
1293 ssm_->RemoveSnapshotFromCache(31);
1294 ssm_->PutSnapshotToCache(30 + ssm_->snapshotCapacity_);
1295 ASSERT_NE(sceneSession->snapshot_, nullptr);
1296 }
1297
1298 /**
1299 * @tc.name: RequestSceneSessionBackground
1300 * @tc.desc: RequestSceneSessionBackground
1301 * @tc.type: FUNC
1302 */
1303 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground, Function | SmallTest | Level3)
1304 {
1305 ASSERT_NE(ssm_, nullptr);
1306 SessionInfo info;
1307 info.abilityName_ = "test1";
1308 info.bundleName_ = "test2";
1309 info.ancoSceneState = 0;
1310 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1311 ASSERT_NE(property, nullptr);
1312 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1313 sptr<SceneSession> sceneSession = nullptr;
1314 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1315 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, true, true, true));
1316 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1317 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, false, false, false));
1318 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, true, false, true));
1319 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, true, true, true));
1320 }
1321
1322 /**
1323 * @tc.name: RequestSceneSessionBackground
1324 * @tc.desc: RequestSceneSessionBackground
1325 * @tc.type: FUNC
1326 */
1327 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground02, Function | SmallTest | Level3)
1328 {
1329 ASSERT_NE(ssm_, nullptr);
1330 SessionInfo info;
1331 info.abilityName_ = "test1";
1332 info.bundleName_ = "test2";
1333 info.ancoSceneState = 0;
1334 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1335 ASSERT_NE(property, nullptr);
1336 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1337 sptr<Session> session = sptr<Session>::MakeSptr(info);
1338 ASSERT_NE(session, nullptr);
1339 sptr<SceneSession> sceneSession = nullptr;
1340 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1341 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1342 session->SetSessionInfoPersistentId(123);
1343 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, false, false, false));
1344 session->SetSessionInfoPersistentId(0);
1345 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, false, false, true));
1346 }
1347
1348 /**
1349 * @tc.name: ConfigAppWindowShadow
1350 * @tc.desc: SceneSesionManager config app window shadow
1351 * @tc.type: FUNC
1352 */
1353 HWTEST_F(SceneSessionManagerTest5, ConfigAppWindowShadow03, Function | SmallTest | Level3)
1354 {
1355 ASSERT_NE(ssm_, nullptr);
1356 WindowSceneConfig::ConfigItem item;
1357 WindowSceneConfig::ConfigItem shadowConfig;
1358 WindowShadowConfig outShadow;
1359 std::vector<float> floatTest = {0.0f, 0.1f, 0.2f, 0.3f};
1360 bool result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1361 ASSERT_EQ(result, true);
1362
1363 item.SetValue(floatTest);
1364 shadowConfig.SetValue({{"offsetX", item}});
1365 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1366
1367 shadowConfig.SetValue({{"offsetY", item}});
1368 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1369
1370 item.SetValue(new std::string(""));
1371 shadowConfig.SetValue({{"color", item}});
1372 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1373 }
1374
1375 /**
1376 * @tc.name: CreateAndConnectSpecificSession
1377 * @tc.desc: CreateAndConnectSpecificSession
1378 * @tc.type: FUNC
1379 */
1380 HWTEST_F(SceneSessionManagerTest5, CreateAndConnectSpecificSession02, Function | SmallTest | Level3)
1381 {
1382 ASSERT_NE(ssm_, nullptr);
1383 sptr<ISessionStage> sessionStage = sptr<SessionStageMocker>::MakeSptr();
1384 ASSERT_NE(sessionStage, nullptr);
1385 sptr<IWindowEventChannel> eventChannel = sptr<WindowEventChannelMocker>::MakeSptr(sessionStage);
1386 ASSERT_NE(eventChannel, nullptr);
1387 std::shared_ptr<RSSurfaceNode> node = nullptr;
1388 sptr<ISession> session;
1389 SystemSessionConfig systemConfig;
1390 sptr<IRemoteObject> token;
1391 int32_t id = 0;
1392 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1393 ASSERT_NE(property, nullptr);
1394 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1395 property->SetWindowFlags(123);
1396 WSError res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1397 systemConfig, token);
1398 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, res); // create main window, property must be nullptr
1399
1400 sessionStage = sptr<SessionStageMocker>::MakeSptr();
1401 property = sptr<WindowSessionProperty>::MakeSptr();
1402 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1403 property->SetWindowFlags(123);
1404 res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1405 systemConfig, token);
1406 ASSERT_EQ(WSError::WS_OK, res);
1407
1408 sessionStage = sptr<SessionStageMocker>::MakeSptr();
1409 property = sptr<WindowSessionProperty>::MakeSptr();
1410 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1411 property->SetWindowFlags(123);
1412 res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1413 systemConfig, token);
1414 ASSERT_EQ(WSError::WS_ERROR_NOT_SYSTEM_APP, res);
1415
1416 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1417 property->SetFloatingWindowAppType(true);
1418 ssm_->shouldHideNonSecureFloatingWindows_.store(true);
1419 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1420 res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1421 systemConfig, token);
1422 ASSERT_EQ(WSError::WS_ERROR_NOT_SYSTEM_APP, res);
1423 ssm_->shouldHideNonSecureFloatingWindows_.store(false);
1424 ssm_->systemConfig_.windowUIType_ = WindowUIType::INVALID_WINDOW;
1425 }
1426
1427 /**
1428 * @tc.name: CheckSubSessionStartedByExtensionAndSetDisplayId
1429 * @tc.desc: CheckSubSessionStartedByExtensionAndSetDisplayId
1430 * @tc.type: FUNC
1431 */
1432 HWTEST_F(SceneSessionManagerTest5, CheckUIExtensionAndSetDisplayId01, Function | SmallTest | Level3)
1433 {
1434 ASSERT_NE(ssm_, nullptr);
1435 SessionInfo info;
1436 sptr<SceneSession::SpecificSessionCallback> callback = ssm_->CreateSpecificSessionCallback();
1437 sptr<SceneSession> parentSession = sptr<SceneSession>::MakeSptr(info, callback);
1438 ssm_->sceneSessionMap_.insert({ parentSession->GetPersistentId(), parentSession });
1439 sptr<IRemoteObject> token;
1440 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1441 sptr<ISessionStage> sessionStage = sptr<SessionStageMocker>::MakeSptr();
1442 EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage),
1443 WSError::WS_ERROR_NULLPTR);
1444 property->SetParentPersistentId(parentSession->GetPersistentId());
1445 property->SetIsUIExtFirstSubWindow(true);
1446 constexpr DisplayId displayId = 0;
1447 parentSession->GetSessionProperty()->SetDisplayId(displayId);
1448 EXPECT_EQ(ssm_->CheckSubSessionStartedByExtensionAndSetDisplayId(token, property, sessionStage),
1449 WSError::WS_OK);
1450 EXPECT_EQ(property->GetDisplayId(), displayId);
1451 }
1452
1453 /**
1454 * @tc.name: ProcessDialogRequestFocusImmdediately
1455 * @tc.desc: ProcessDialogRequestFocusImmdediately
1456 * @tc.type: FUNC
1457 */
1458 HWTEST_F(SceneSessionManagerTest5, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)
1459 {
1460 ASSERT_NE(ssm_, nullptr);
1461 SessionInfo info;
1462 info.abilityName_ = "test1";
1463 info.bundleName_ = "test2";
1464 info.persistentId_ = 123;
1465 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1466 ASSERT_NE(sceneSession, nullptr);
1467 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1468 ASSERT_NE(property, nullptr);
1469 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1470 auto ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1471 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1472 usleep(WAIT_SYNC_IN_NS);
1473 }
1474
1475 /**
1476 * @tc.name: CheckFloatWindowIsAnco01
1477 * @tc.desc: CheckFloatWindowIsAnco
1478 * @tc.type: FUNC
1479 */
1480 HWTEST_F(SceneSessionManagerTest5, CheckFloatWindowIsAnco01, TestSize.Level1)
1481 {
1482 ASSERT_NE(ssm_, nullptr);
1483 SessionInfo info;
1484 info.abilityName_ = "test1";
1485 info.bundleName_ = "test2";
1486 info.moduleName_ = "test2";
1487 info.persistentId_ = 123;
1488 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1489 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
1490 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1491 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1492 sceneSession->SetCallingPid(123);
1493 ssm_->sceneSessionMap_.insert({ 123, sceneSession });
1494 ssm_->CheckFloatWindowIsAnco(123, sceneSession1);
1495 ASSERT_EQ(sceneSession1->GetIsAncoForFloatingWindow(), false);
1496 ssm_->sceneSessionMap_.erase(123);
1497 usleep(WAIT_SYNC_IN_NS);
1498 }
1499
1500 /**
1501 * @tc.name: RequestSceneSessionByCall
1502 * @tc.desc: SceneSesionManager request scene session by call
1503 * @tc.type: FUNC
1504 */
1505 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionByCall02, Function | SmallTest | Level3)
1506 {
1507 ASSERT_NE(ssm_, nullptr);
1508 sptr<SceneSession> sceneSession = nullptr;
1509 ssm_->RequestSceneSessionByCall(nullptr);
1510 SessionInfo info;
1511 info.abilityName_ = "test1";
1512 info.bundleName_ = "test2";
1513 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1514 ssm_->RequestSceneSessionByCall(sceneSession);
1515 }
1516
1517 /**
1518 * @tc.name: GetAllAbilityInfos
1519 * @tc.desc: Test if pip window can be created;
1520 * @tc.type: FUNC
1521 */
1522 HWTEST_F(SceneSessionManagerTest5, GetAllAbilityInfos02, Function | SmallTest | Level3)
1523 {
1524 ASSERT_NE(ssm_, nullptr);
1525 AAFwk::Want want;
1526 AppExecFwk::ElementName elementName = want.GetElement();
1527 int32_t userId = 1;
1528 std::vector<SCBAbilityInfo> scbAbilityInfos;
1529 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1530
1531 elementName.bundleName_ = "test";
1532 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1533
1534 elementName.abilityName_ = "test";
1535 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1536
1537 elementName.bundleName_ = "";
1538 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1539 }
1540
1541 /**
1542 * @tc.name: GetBatchAbilityInfos01
1543 * @tc.desc: GetBatchAbilityInfos01
1544 * @tc.type: FUNC
1545 */
1546 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos01, Function | SmallTest | Level3)
1547 {
1548 ASSERT_NE(ssm_, nullptr);
1549 auto bundleMgr = ssm_->bundleMgr_;
1550 ssm_->bundleMgr_ = nullptr;
1551 int32_t userId = 100;
1552 std::vector<std::string> bundleNames = { "test1", "test2" };
1553 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1554 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1555 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1556 }
1557
1558 /**
1559 * @tc.name: GetBatchAbilityInfos02
1560 * @tc.desc: GetBatchAbilityInfos02
1561 * @tc.type: FUNC
1562 */
1563 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos02, Function | SmallTest | Level3)
1564 {
1565 ASSERT_NE(ssm_, nullptr);
1566 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1567 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1568 int32_t userId = 100;
1569 std::vector<std::string> bundleNames = {};
1570 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1571 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1572 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1573 }
1574
1575 /**
1576 * @tc.name: GetBatchAbilityInfos03
1577 * @tc.desc: GetBatchAbilityInfos03
1578 * @tc.type: FUNC
1579 */
1580 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos03, Function | SmallTest | Level3)
1581 {
1582 ASSERT_NE(ssm_, nullptr);
1583 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1584 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1585 int32_t userId = 100;
1586 std::vector<std::string> bundleNames = { "" };
1587 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1588 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1589 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1590 }
1591
1592 /**
1593 * @tc.name: GetBatchAbilityInfos04
1594 * @tc.desc: GetBatchAbilityInfos04
1595 * @tc.type: FUNC
1596 */
1597 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos04, Function | SmallTest | Level3)
1598 {
1599 ASSERT_NE(ssm_, nullptr);
1600 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1601 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1602 int32_t userId = 100;
1603 std::vector<std::string> bundleNames = { "test1", "test2" };
1604 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1605 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1606 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1607 }
1608
1609 /**
1610 * @tc.name: FindMainWindowWithToken
1611 * @tc.desc: SceneSesionManager find main window with token
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(SceneSessionManagerTest5, FindMainWindowWithToken02, Function | SmallTest | Level3)
1615 {
1616 ASSERT_NE(ssm_, nullptr);
1617 SessionInfo info;
1618 info.abilityName_ = "test1";
1619 info.bundleName_ = "test2";
1620 info.persistentId_ = 123;
1621 sptr<IRemoteObject> targetToken = nullptr;
1622 ssm_->FindMainWindowWithToken(targetToken);
1623 targetToken = sptr<IRemoteObjectMocker>::MakeSptr();
1624 ASSERT_NE(targetToken, nullptr);
1625 ssm_->FindMainWindowWithToken(targetToken);
1626 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1627 ssm_->FindMainWindowWithToken(targetToken);
1628 }
1629
1630 /**
1631 * @tc.name: FindSessionByToken
1632 * @tc.desc: SceneSesionManager FindSessionByToken
1633 * @tc.type: FUNC
1634 */
1635 HWTEST_F(SceneSessionManagerTest5, FindSessionByToken, Function | SmallTest | Level3)
1636 {
1637 ASSERT_NE(ssm_, nullptr);
1638 SessionInfo info;
1639 info.abilityName_ = "test1";
1640 info.bundleName_ = "test2";
1641 info.persistentId_ = 123;
1642 sptr<IRemoteObject> targetToken = nullptr;
1643 auto result = ssm_->FindSessionByToken(targetToken);
1644 ASSERT_EQ(result, nullptr);
1645
1646 targetToken = sptr<IRemoteObjectMocker>::MakeSptr();
1647 ASSERT_NE(targetToken, nullptr);
1648 result = ssm_->FindSessionByToken(targetToken);
1649 ASSERT_EQ(result, nullptr);
1650
1651 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1652 sceneSession->abilityToken_ = targetToken;
1653 ssm_->sceneSessionMap_.insert({ 123, sceneSession });
1654 result = ssm_->FindSessionByToken(targetToken, sceneSession->GetWindowType());
1655 ASSERT_EQ(result, sceneSession);
1656 }
1657
1658 /**
1659 * @tc.name: RequestSceneSessionBackground
1660 * @tc.desc: RequestSceneSessionBackground
1661 * @tc.type: FUNC
1662 */
1663 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground03, Function | SmallTest | Level3)
1664 {
1665 ASSERT_NE(ssm_, nullptr);
1666 SessionInfo info;
1667 info.abilityName_ = "test1";
1668 info.bundleName_ = "test2";
1669 info.persistentId_ = 0;
1670 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1671 ASSERT_NE(property, nullptr);
1672 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1673 sptr<Session> session = sptr<Session>::MakeSptr(info);
1674 ASSERT_NE(session, nullptr);
1675 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1676 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1677 session->SetSessionInfoPersistentId(0);
1678 ssm_->RequestSceneSessionBackground(sceneSession, false, false, true);
1679
1680 ssm_->sceneSessionMap_.clear();
1681 ssm_->sceneSessionMap_.insert({0, sceneSession});
1682 ssm_->RequestSceneSessionBackground(sceneSession, false, false, true);
1683 ssm_->sceneSessionMap_.clear();
1684 }
1685
1686 /**
1687 * @tc.name: ConfigDecor
1688 * @tc.desc: SceneSesionManager config decor
1689 * @tc.type: FUNC
1690 */
1691 HWTEST_F(SceneSessionManagerTest5, ConfigDecor02, Function | SmallTest | Level3)
1692 {
1693 ASSERT_NE(ssm_, nullptr);
1694 WindowSceneConfig::ConfigItem* item = new WindowSceneConfig::ConfigItem;
1695 ASSERT_NE(item, nullptr);
1696 ssm_->ConfigDecor(*item, false);
1697 }
1698
1699 /**
1700 * @tc.name: SetSkipSelfWhenShowOnVirtualScreen
1701 * @tc.desc: SetSkipSelfWhenShowOnVirtualScreen
1702 * @tc.type: FUNC
1703 */
1704 HWTEST_F(SceneSessionManagerTest5, SetSkipSelfWhenShowOnVirtualScreen, Function | SmallTest | Level3)
1705 {
1706 ASSERT_NE(ssm_, nullptr);
1707 SessionInfo info;
1708 info.abilityName_ = "test1";
1709 info.bundleName_ = "test2";
1710 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1711 ASSERT_NE(property, nullptr);
1712 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1713 uint64_t surfaceNodeId = 1234;
1714 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, false);
1715 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, true);
1716 }
1717
1718 /**
1719 * @tc.name: InitSceneSession02
1720 * @tc.desc: InitSceneSession02
1721 * @tc.type: FUNC
1722 */
1723 HWTEST_F(SceneSessionManagerTest5, InitSceneSession02, Function | SmallTest | Level3)
1724 {
1725 ASSERT_NE(nullptr, ssm_);
1726 SessionInfo sessionInfo;
1727 sessionInfo.bundleName_ = "test1";
1728 sessionInfo.abilityName_ = "test2";
1729 sessionInfo.abilityInfo = nullptr;
1730 sessionInfo.isAtomicService_ = true;
1731 sessionInfo.screenId_ = SCREEN_ID_INVALID;
1732 unsigned int flags = 1111;
1733 sessionInfo.want = std::make_shared<AAFwk::Want>();
1734 ASSERT_NE(nullptr, sessionInfo.want);
1735 sessionInfo.want->SetFlags(flags);
1736 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1737 ASSERT_NE(nullptr, sceneSession);
1738 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1739
1740 ssm_->InitSceneSession(sceneSession, sessionInfo, nullptr);
1741 ASSERT_EQ(DISPLAY_ID_INVALID, sceneSession->GetSessionInfo().screenId_);
1742 }
1743
1744 /**
1745 * @tc.name: PrepareTerminate
1746 * @tc.desc: SceneSesionManager prepare terminate
1747 * @tc.type: FUNC
1748 */
1749 HWTEST_F(SceneSessionManagerTest5, PrepareTerminate03, Function | SmallTest | Level3)
1750 {
1751 ASSERT_NE(nullptr, ssm_);
1752 SessionInfo sessionInfo;
1753 sessionInfo.bundleName_ = "PrepareTerminate";
1754 sessionInfo.abilityName_ = "PrepareTerminate";
1755 sessionInfo.abilityInfo = nullptr;
1756 int32_t persistentId = 1;
1757 bool isPrepareTerminate = true;
1758 ASSERT_EQ(WSError::WS_OK, ssm_->PrepareTerminate(persistentId, isPrepareTerminate));
1759 }
1760
1761 /**
1762 * @tc.name: AddClientDeathRecipient
1763 * @tc.desc: SceneSesionManager add client death recipient
1764 * @tc.type: FUNC
1765 */
1766 HWTEST_F(SceneSessionManagerTest5, AddClientDeathRecipient02, Function | SmallTest | Level3)
1767 {
1768 ASSERT_NE(ssm_, nullptr);
1769 SessionInfo info;
1770 info.abilityName_ = "AddClientDeathRecipient";
1771 info.bundleName_ = "AddClientDeathRecipient";
1772 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1773 ASSERT_NE(nullptr, sceneSession);
1774 ssm_->AddClientDeathRecipient(nullptr, sceneSession);
1775 sptr<ISessionStage> sessionStage = sptr<SessionStageMocker>::MakeSptr();
1776 ssm_->AddClientDeathRecipient(sessionStage, sceneSession);
1777 }
1778
1779 /**
1780 * @tc.name: RequestFocusStatusBySCB
1781 * @tc.desc: SceneSessionManager request focus status from SCB
1782 * @tc.type: FUNC
1783 */
1784 HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB, Function | SmallTest | Level3)
1785 {
1786 ssm_->sceneSessionMap_.clear();
1787 SessionInfo info;
1788 info.abilityName_ = "RequestFocusTest";
1789 info.bundleName_ = "RequestFocusTest";
1790 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1791 property->SetFocusable(true);
1792 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1793 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1794 sceneSession->property_ = property;
1795 sceneSession->persistentId_ = 1;
1796 sceneSession->isVisible_ = true;
1797 sceneSession->state_ = SessionState::STATE_ACTIVE;
1798 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1799
1800 FocusChangeReason reason = FocusChangeReason::FOREGROUND;
1801 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
1802 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1803 usleep(WAIT_SYNC_IN_NS);
1804 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
1805
1806 reason = FocusChangeReason::CLICK;
1807 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1808 usleep(WAIT_SYNC_IN_NS);
1809 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
1810 }
1811
1812 /**
1813 * @tc.name: RequestFocusStatusBySCB01
1814 * @tc.desc: SceneSessionManager request focus status from SCB
1815 * @tc.type: FUNC
1816 */
1817 HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB01, Function | SmallTest | Level3)
1818 {
1819 ssm_->sceneSessionMap_.clear();
1820 SessionInfo info;
1821 info.abilityName_ = "RequestFocusTest";
1822 info.bundleName_ = "RequestFocusTest";
1823 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1824 property->SetFocusable(true);
1825 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1826 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1827 sceneSession->property_ = property;
1828 sceneSession->persistentId_ = 1;
1829 sceneSession->isVisible_ = true;
1830 sceneSession->state_ = SessionState::STATE_ACTIVE;
1831 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1832
1833 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
1834 sceneSession1->property_->SetFocusable(true);
1835 sceneSession1->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1836 sceneSession1->persistentId_ = 2;
1837 sceneSession1->isVisible_ = true;
1838 sceneSession1->state_ = SessionState::STATE_ACTIVE;
1839 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1840 FocusChangeReason reason = FocusChangeReason::FOREGROUND;
1841 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
1842 ssm_->RequestFocusStatusBySCB(2, true, false, reason);
1843 usleep(WAIT_SYNC_IN_NS);
1844 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 2);
1845
1846 ssm_->RequestFocusStatusBySCB(1, false, false, reason);
1847 usleep(WAIT_SYNC_IN_NS);
1848 ASSERT_NE(focusGroup->GetFocusedSessionId(), 1);
1849
1850 reason = FocusChangeReason::MOVE_UP;
1851 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1852 usleep(WAIT_SYNC_IN_NS);
1853 FocusChangeReason reasonResult = sceneSession->GetPostProcessFocusState().reason_;
1854 ASSERT_EQ(reasonResult, FocusChangeReason::MOVE_UP);
1855
1856 reason = FocusChangeReason::DEFAULT;
1857 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1858 usleep(WAIT_SYNC_IN_NS);
1859 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
1860 }
1861
1862 /**
1863 * @tc.name: RequestSessionUnfocus01
1864 * @tc.desc: RequestSessionUnfocus01
1865 * @tc.type: FUNC
1866 */
1867 HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus01, Function | SmallTest | Level3)
1868 {
1869 ssm_->sceneSessionMap_.clear();
1870 SessionInfo info;
1871 info.abilityName_ = "RequestSessionUnfocus01";
1872 info.bundleName_ = "RequestSessionUnfocus01";
1873
1874 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1875 sceneSession->persistentId_ = 1;
1876 sceneSession->zOrder_ = 1;
1877 sceneSession->isVisible_ = true;
1878 sceneSession->state_ = SessionState::STATE_DISCONNECT;
1879 sceneSession->SetFocusable(true);
1880 sceneSession->property_->SetDisplayId(DEFAULT_DISPLAY_ID);
1881
1882 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
1883 sceneSession1->persistentId_ = 2;
1884 sceneSession1->zOrder_ = 2;
1885 sceneSession1->property_->SetDisplayId(DEFAULT_DISPLAY_ID);
1886 sceneSession1->isVisible_ = true;
1887 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1888 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1889 ssm_->SetFocusedSessionId(2, DEFAULT_DISPLAY_ID);
1890 ssm_->RequestSessionUnfocus(2, FocusChangeReason::DEFAULT);
1891 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
1892 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
1893 ASSERT_EQ(focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(), true);
1894 }
1895
1896 /**
1897 * @tc.name: RequestSessionUnfocus02
1898 * @tc.desc: RequestSessionUnfocus02
1899 * @tc.type: FUNC
1900 */
1901 HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus02, Function | SmallTest | Level3)
1902 {
1903 ssm_->sceneSessionMap_.clear();
1904 SessionInfo info;
1905 info.abilityName_ = "RequestSessionUnfocus02";
1906 info.bundleName_ = "RequestSessionUnfocus02";
1907
1908 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1909 sceneSession->persistentId_ = 1;
1910 sceneSession->zOrder_ = 1;
1911 sceneSession->isVisible_ = true;
1912 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1913 sceneSession->SetFocusable(true);
1914 sceneSession->property_->SetDisplayId(DEFAULT_DISPLAY_ID);
1915
1916 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
1917 sceneSession1->persistentId_ = 2;
1918 sceneSession1->zOrder_ = 2;
1919 sceneSession1->property_->SetDisplayId(DEFAULT_DISPLAY_ID);
1920 sceneSession1->isVisible_ = true;
1921 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1922 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1923 ssm_->SetFocusedSessionId(2, DEFAULT_DISPLAY_ID);
1924 ssm_->RequestSessionUnfocus(2, FocusChangeReason::DEFAULT);
1925 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
1926 ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1);
1927 ASSERT_EQ(focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(), false);
1928 }
1929 }
1930 } // namespace Rosen
1931 } // namespace OHOS
1932