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