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
18 #include "iremote_object_mocker.h"
19 #include "interfaces/include/ws_common.h"
20 #include "mock/mock_session_stage.h"
21 #include "session_manager/include/scene_session_manager.h"
22 #include "session_info.h"
23 #include "session/host/include/scene_session.h"
24 #include "session_manager.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31
32 class SceneSessionManagerTest8 : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp();
37 void TearDown();
38 private:
39 sptr<SceneSessionManager> ssm_;
40 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
41 };
42
SetUpTestCase()43 void SceneSessionManagerTest8::SetUpTestCase()
44 {
45 }
46
TearDownTestCase()47 void SceneSessionManagerTest8::TearDownTestCase()
48 {
49 }
50
SetUp()51 void SceneSessionManagerTest8::SetUp()
52 {
53 ssm_ = &SceneSessionManager::GetInstance();
54 EXPECT_NE(nullptr, ssm_);
55 ssm_->sceneSessionMap_.clear();
56 }
57
TearDown()58 void SceneSessionManagerTest8::TearDown()
59 {
60 ssm_->sceneSessionMap_.clear();
61 usleep(WAIT_SYNC_IN_NS);
62 ssm_ = nullptr;
63 }
64
65 namespace {
66 /**
67 * @tc.name: GetTotalUITreeInfo
68 * @tc.desc: GetTotalUITreeInfo set gesture navigation enabled
69 * @tc.type: FUNC
70 */
71 HWTEST_F(SceneSessionManagerTest8, GetTotalUITreeInfo, Function | SmallTest | Level3)
72 {
73 std::string dumpInfo = "dumpInfo";
74 ssm_->SetDumpUITreeFunc(nullptr);
75 EXPECT_EQ(WSError::WS_OK, ssm_->GetTotalUITreeInfo(dumpInfo));
__anonc166b0dc0202(std::string& dumpInfo) 76 DumpUITreeFunc func = [](std::string& dumpInfo) {
77 return;
78 };
79 ssm_->SetDumpUITreeFunc(func);
80 EXPECT_EQ(WSError::WS_OK, ssm_->GetTotalUITreeInfo(dumpInfo));
81 }
82
83 /**
84 * @tc.name: GetRemoteSessionSnapshotInfo
85 * @tc.desc: GetRemoteSessionSnapshotInfo set gesture navigation enabled
86 * @tc.type: FUNC
87 */
88 HWTEST_F(SceneSessionManagerTest8, GetRemoteSessionSnapshotInfo, Function | SmallTest | Level3)
89 {
90 AAFwk::MissionSnapshot sessionSnapshot;
91 std::string deviceId = "";
92 int res = ssm_->GetRemoteSessionSnapshotInfo(deviceId, 8, sessionSnapshot);
93 EXPECT_EQ(ERR_NULL_OBJECT, res);
94 }
95
96 /**
97 * @tc.name: WindowLayerInfoChangeCallback
98 * @tc.desc: test function : WindowLayerInfoChangeCallback
99 * @tc.type: FUNC
100 */
101 HWTEST_F(SceneSessionManagerTest8, WindowLayerInfoChangeCallback, Function | SmallTest | Level3)
102 {
103 std::shared_ptr<RSOcclusionData> rsData = nullptr;
104 ssm_->WindowLayerInfoChangeCallback(rsData);
105
106 rsData = std::make_shared<RSOcclusionData>();
107 ASSERT_NE(nullptr, rsData);
108 ssm_->WindowLayerInfoChangeCallback(rsData);
109
110 VisibleData visibleData;
111 visibleData.push_back(std::make_pair(0, WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE));
112 visibleData.push_back(std::make_pair(1, WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE));
113 visibleData.push_back(std::make_pair(2, WINDOW_LAYER_INFO_TYPE::INVISIBLE));
114 visibleData.push_back(std::make_pair(3, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_DYNAMIC_STATUS));
115 visibleData.push_back(std::make_pair(4, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_STATIC_STATUS));
116 visibleData.push_back(std::make_pair(5, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_UNKNOWN_TYPE));
117 rsData = std::make_shared<RSOcclusionData>(visibleData);
118 ASSERT_NE(nullptr, rsData);
119 ssm_->WindowLayerInfoChangeCallback(rsData);
120 }
121
122 /**
123 * @tc.name: PostProcessFocus
124 * @tc.desc: test function : PostProcessFocus
125 * @tc.type: FUNC
126 */
127 HWTEST_F(SceneSessionManagerTest8, PostProcessFocus, Function | SmallTest | Level3)
128 {
129 ssm_->sceneSessionMap_.emplace(0, nullptr);
130 ssm_->PostProcessFocus();
131 ssm_->sceneSessionMap_.clear();
132
133 SessionInfo sessionInfo;
134 sessionInfo.bundleName_ = "PostProcessFocus";
135 sessionInfo.abilityName_ = "PostProcessFocus";
136 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
137 ASSERT_NE(nullptr, sceneSession);
138 PostProcessFocusState state;
139 EXPECT_EQ(false, state.enabled_);
140 sceneSession->SetPostProcessFocusState(state);
141 ssm_->sceneSessionMap_.emplace(0, sceneSession);
142 ssm_->PostProcessFocus();
143
144 state.enabled_ = true;
145 state.isFocused_ = false;
146 sceneSession->SetPostProcessFocusState(state);
147 ssm_->PostProcessFocus();
148
149 state.isFocused_ = true;
150 state.reason_ = FocusChangeReason::SCB_START_APP;
151 sceneSession->SetPostProcessFocusState(state);
152 ssm_->PostProcessFocus();
153
154 sceneSession->SetPostProcessFocusState(state);
155 state.reason_ = FocusChangeReason::DEFAULT;
156 ssm_->PostProcessFocus();
157 }
158
159 /**
160 * @tc.name: PostProcessFocus01
161 * @tc.desc: test function : PostProcessFocus with focusableOnShow
162 * @tc.type: FUNC
163 */
164 HWTEST_F(SceneSessionManagerTest8, PostProcessFocus01, Function | SmallTest | Level3)
165 {
166 ssm_->sceneSessionMap_.clear();
167 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
168 focusGroup->SetFocusedSessionId(0);
169
170 SessionInfo sessionInfo;
171 sessionInfo.bundleName_ = "PostProcessFocus01";
172 sessionInfo.abilityName_ = "PostProcessFocus01";
173 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
174 sceneSession->persistentId_ = 1;
175 sceneSession->state_ = SessionState::STATE_FOREGROUND;
176 sceneSession->isVisible_ = true;
177
178 PostProcessFocusState state = {true, true, true, FocusChangeReason::FOREGROUND};
179 sceneSession->SetPostProcessFocusState(state);
180 sceneSession->SetFocusableOnShow(false);
181 ssm_->sceneSessionMap_.emplace(1, sceneSession);
182 ssm_->PostProcessFocus();
183
184 EXPECT_NE(1, focusGroup->GetFocusedSessionId());
185 }
186
187 /**
188 * @tc.name: PostProcessFocus03
189 * @tc.desc: test function : PostProcessFocus
190 * @tc.type: FUNC
191 */
192 HWTEST_F(SceneSessionManagerTest8, PostProcessFocus03, Function | SmallTest | Level3)
193 {
194 ssm_->sceneSessionMap_.clear();
195
196 SessionInfo sessionInfo;
197 sessionInfo.bundleName_ = "PostProcessFocus03";
198 sessionInfo.abilityName_ = "PostProcessFocus03";
199 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
200 sceneSession->persistentId_ = 1;
201
202 sceneSession->SetFocusedOnShow(false);
203 PostProcessFocusState state = {true, true, true, FocusChangeReason::FOREGROUND};
204 sceneSession->SetPostProcessFocusState(state);
205 ssm_->sceneSessionMap_.emplace(1, sceneSession);
206 ssm_->PostProcessFocus();
207 EXPECT_EQ(sceneSession->IsFocusedOnShow(), false);
208
209 sceneSession->state_ = SessionState::STATE_FOREGROUND;
210 sceneSession->isVisible_ = true;
211 state = {true, true, true, FocusChangeReason::FOREGROUND};
212 sceneSession->SetPostProcessFocusState(state);
213 ssm_->sceneSessionMap_.emplace(1, sceneSession);
214 ssm_->PostProcessFocus();
215 EXPECT_EQ(sceneSession->IsFocusedOnShow(), true);
216 }
217
218 /**
219 * @tc.name: PostProcessProperty
220 * @tc.desc: test function : PostProcessProperty
221 * @tc.type: FUNC
222 */
223 HWTEST_F(SceneSessionManagerTest8, PostProcessProperty, Function | SmallTest | Level3)
224 {
225 ssm_->sceneSessionMap_.emplace(0, nullptr);
226 ssm_->PostProcessProperty(static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA));
227 ssm_->PostProcessProperty(~static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA));
228 ssm_->sceneSessionMap_.clear();
229
230 SessionInfo sessionInfo;
231 sessionInfo.bundleName_ = "PostProcessProperty";
232 sessionInfo.abilityName_ = "PostProcessProperty";
233 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DIALOG);
234 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
235 ASSERT_NE(nullptr, sceneSession);
236 PostProcessFocusState state;
237 EXPECT_EQ(false, state.enabled_);
238 sceneSession->SetPostProcessFocusState(state);
239 ssm_->sceneSessionMap_.emplace(0, sceneSession);
240 ssm_->PostProcessFocus();
241
242 state.enabled_ = true;
243 sceneSession->SetPostProcessFocusState(state);
244 ssm_->PostProcessFocus();
245
246 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
247 ssm_->PostProcessFocus();
248 }
249
250 /**
251 * @tc.name: NotifyUpdateRectAfterLayout
252 * @tc.desc: test function : NotifyUpdateRectAfterLayout
253 * @tc.type: FUNC
254 */
255 HWTEST_F(SceneSessionManagerTest8, NotifyUpdateRectAfterLayout, Function | SmallTest | Level3)
256 {
257 ssm_->sceneSessionMap_.emplace(0, nullptr);
258 ssm_->NotifyUpdateRectAfterLayout();
259 ssm_->sceneSessionMap_.clear();
260
261 SessionInfo sessionInfo;
262 sessionInfo.bundleName_ = "NotifyUpdateRectAfterLayout";
263 sessionInfo.abilityName_ = "NotifyUpdateRectAfterLayout";
264 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
265 ASSERT_NE(nullptr, sceneSession);
266 ssm_->sceneSessionMap_.emplace(0, sceneSession);
267 ssm_->NotifyUpdateRectAfterLayout();
268 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
269 usleep(NOT_WAIT_SYNC_IN_NS);
270 }
271
272 /**
273 * @tc.name: DestroyExtensionSession
274 * @tc.desc: test function : DestroyExtensionSession
275 * @tc.type: FUNC
276 */
277 HWTEST_F(SceneSessionManagerTest8, DestroyExtensionSession, Function | SmallTest | Level3)
278 {
279 ssm_->remoteExtSessionMap_.clear();
280 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
281 sptr<IRemoteObject> token = sptr<IRemoteObjectMocker>::MakeSptr();
282 EXPECT_NE(nullptr, iRemoteObjectMocker);
283 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
284 ssm_->remoteExtSessionMap_.emplace(iRemoteObjectMocker, token);
285
286 ssm_->extSessionInfoMap_.clear();
287 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
288
289 ExtensionWindowAbilityInfo extensionWindowAbilituInfo;
290 ssm_->extSessionInfoMap_.emplace(token, extensionWindowAbilituInfo);
291
292 ssm_->sceneSessionMap_.emplace(0, nullptr);
293 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
294 ssm_->sceneSessionMap_.clear();
295
296 SessionInfo sessionInfo;
297 sessionInfo.bundleName_ = "DestroyExtensionSession";
298 sessionInfo.abilityName_ = "DestroyExtensionSession";
299 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
300 ASSERT_NE(nullptr, sceneSession);
301 ssm_->sceneSessionMap_.emplace(0, sceneSession);
302
303 ExtensionWindowFlags extensionWindowFlags;
304 sceneSession->combinedExtWindowFlags_ = extensionWindowFlags;
305 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
306
307 extensionWindowFlags.waterMarkFlag = false;
308 extensionWindowFlags.privacyModeFlag = false;
309 sceneSession->combinedExtWindowFlags_ = extensionWindowFlags;
310 EXPECT_EQ(false, sceneSession->combinedExtWindowFlags_.privacyModeFlag);
311 int len = sceneSession->modalUIExtensionInfoList_.size();
312 ssm_->DestroyExtensionSession(iRemoteObjectMocker, true);
313 constexpr uint32_t DES_WAIT_SYNC_IN_NS = 500000;
314 usleep(DES_WAIT_SYNC_IN_NS);
315 EXPECT_EQ(len, sceneSession->modalUIExtensionInfoList_.size());
316 ssm_->DestroyExtensionSession(iRemoteObjectMocker, false);
317 usleep(DES_WAIT_SYNC_IN_NS);
318 EXPECT_EQ(len, sceneSession->modalUIExtensionInfoList_.size());
319 }
320
321 /**
322 * @tc.name: FilterSceneSessionCovered
323 * @tc.desc: test function : FilterSceneSessionCovered
324 * @tc.type: FUNC
325 */
326 HWTEST_F(SceneSessionManagerTest8, FilterSceneSessionCovered, Function | SmallTest | Level3)
327 {
328 std::vector<sptr<SceneSession>> sceneSessionList;
329 sptr<SceneSession> sceneSession = nullptr;
330 sceneSessionList.emplace_back(sceneSession);
331 EXPECT_EQ(1, sceneSessionList.size());
332 ssm_->FilterSceneSessionCovered(sceneSessionList);
333
334 SessionInfo sessionInfo;
335 sceneSessionList.clear();
336 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
337 EXPECT_NE(nullptr, sceneSession);
338 sceneSessionList.emplace_back(sceneSession);
339 ssm_->FilterSceneSessionCovered(sceneSessionList);
340 }
341
342 /**
343 * @tc.name: UpdateSubWindowVisibility
344 * @tc.desc: test function : UpdateSubWindowVisibility
345 * @tc.type: FUNC
346 */
347 HWTEST_F(SceneSessionManagerTest8, UpdateSubWindowVisibility, Function | SmallTest | Level3)
348 {
349 SessionInfo sessionInfo;
350 sessionInfo.bundleName_ = "UpdateSubWindowVisibility";
351 sessionInfo.abilityName_ = "UpdateSubWindowVisibility";
352 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
353 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
354 EXPECT_NE(nullptr, sceneSession);
355 WindowVisibilityState visibleState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION;
356 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfo;
357 std::vector<sptr<WindowVisibilityInfo>> windowVisibilityInfos;
358 std::string visibilityInfo = "";
359 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
360 sceneSession->persistentId_ = 1998;
361 sceneSession->SetCallingUid(1998);
362 SessionState state = SessionState::STATE_CONNECT;
363 sceneSession->SetSessionState(state);
364 sceneSession->SetParentSession(sceneSession);
365 EXPECT_EQ(1998, sceneSession->GetParentSession()->GetWindowId());
366 ssm_->sceneSessionMap_.emplace(0, sceneSession);
367
368 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
369 EXPECT_NE(nullptr, sceneSession1);
370 sceneSession1->persistentId_ = 1998;
371 sceneSession1->SetCallingUid(1024);
372 SessionState state1 = SessionState::STATE_CONNECT;
373 sceneSession1->SetSessionState(state1);
374 sceneSession1->SetParentSession(sceneSession1);
375 EXPECT_EQ(1998, sceneSession1->GetParentSession()->GetWindowId());
376 ssm_->sceneSessionMap_.emplace(0, sceneSession1);
377
378 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
379 EXPECT_NE(nullptr, sceneSession2);
380 sceneSession2->persistentId_ = 1998;
381 sceneSession2->SetCallingUid(1998);
382 SessionState state2 = SessionState::STATE_FOREGROUND;
383 sceneSession2->SetSessionState(state2);
384 sceneSession2->SetParentSession(sceneSession2);
385 EXPECT_EQ(1998, sceneSession2->GetParentSession()->GetWindowId());
386 ssm_->sceneSessionMap_.emplace(0, sceneSession2);
387 ssm_->UpdateSubWindowVisibility(sceneSession,
388 visibleState, visibilityChangeInfo, windowVisibilityInfos, visibilityInfo, currVisibleData);
389 }
390
391 /**
392 * @tc.name: RegisterSessionChangeByActionNotifyManagerFunc
393 * @tc.desc: test function : RegisterSessionChangeByActionNotifyManagerFunc
394 * @tc.type: FUNC
395 */
396 HWTEST_F(SceneSessionManagerTest8, RegisterSessionChangeByActionNotifyManagerFunc, Function | SmallTest | Level3)
397 {
398 sptr<SceneSession> sceneSession = nullptr;
399 ssm_->RegisterSessionChangeByActionNotifyManagerFunc(sceneSession);
400 SessionInfo sessionInfo;
401 sessionInfo.bundleName_ = "RegisterSessionChangeByActionNotifyManagerFunc";
402 sessionInfo.abilityName_ = "RegisterSessionChangeByActionNotifyManagerFunc";
403 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
404 EXPECT_NE(nullptr, sceneSession);
405 ssm_->RegisterSessionChangeByActionNotifyManagerFunc(sceneSession);
406 EXPECT_NE(nullptr, sceneSession->sessionChangeByActionNotifyManagerFunc_);
407
408 sptr<WindowSessionProperty> property = nullptr;
409 sceneSession->NotifySessionChangeByActionNotifyManager(property,
410 WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
411
412 property = sptr<WindowSessionProperty>::MakeSptr();
413 EXPECT_NE(nullptr, property);
414
415 sceneSession->NotifySessionChangeByActionNotifyManager(property,
416 WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
417 }
418
419 /**
420 * @tc.name: RegisterSessionChangeByActionNotifyManagerFunc1
421 * @tc.desc: test function : RegisterSessionChangeByActionNotifyManagerFunc1
422 * @tc.type: FUNC
423 */
424 HWTEST_F(SceneSessionManagerTest8, RegisterSessionChangeByActionNotifyManagerFunc1, Function | SmallTest | Level3)
425 {
426 SessionInfo sessionInfo;
427 sessionInfo.bundleName_ = "RegisterSessionChangeByActionNotifyManagerFunc1";
428 sessionInfo.abilityName_ = "RegisterSessionChangeByActionNotifyManagerFunc1";
429 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
430 EXPECT_NE(nullptr, sceneSession);
431
432 ssm_->RegisterSessionChangeByActionNotifyManagerFunc(sceneSession);
433 EXPECT_NE(nullptr, sceneSession->sessionChangeByActionNotifyManagerFunc_);
434
435 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
436 EXPECT_NE(nullptr, property);
437
438 sceneSession->NotifySessionChangeByActionNotifyManager(property,
439 WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
440
441 sceneSession->NotifySessionChangeByActionNotifyManager(property,
442 WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_INDICATOR_PROPS);
443
444 sceneSession->NotifySessionChangeByActionNotifyManager(property,
445 WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
446
447 sceneSession->NotifySessionChangeByActionNotifyManager(property,
448 WSPropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
449
450 sceneSession->NotifySessionChangeByActionNotifyManager(property,
451 WSPropertyChangeAction::ACTION_UPDATE_FLAGS);
452
453 sceneSession->NotifySessionChangeByActionNotifyManager(property,
454 WSPropertyChangeAction::ACTION_UPDATE_MODE);
455
456 sceneSession->NotifySessionChangeByActionNotifyManager(property,
457 WSPropertyChangeAction::ACTION_UPDATE_HIDE_NON_SYSTEM_FLOATING_WINDOWS);
458
459 sceneSession->NotifySessionChangeByActionNotifyManager(property,
460 WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK);
461
462 sceneSession->NotifySessionChangeByActionNotifyManager(property,
463 WSPropertyChangeAction::ACTION_UPDATE_TOPMOST);
464 }
465
466 /**
467 * @tc.name: RegisterRequestFocusStatusNotifyManagerFunc
468 * @tc.desc: test function : RegisterRequestFocusStatusNotifyManagerFunc
469 * @tc.type: FUNC
470 */
471 HWTEST_F(SceneSessionManagerTest8, RegisterRequestFocusStatusNotifyManagerFunc, Function | SmallTest | Level3)
472 {
473 sptr<SceneSession> sceneSession = nullptr;
474 ssm_->RegisterRequestFocusStatusNotifyManagerFunc(sceneSession);
475 EXPECT_EQ(nullptr, sceneSession);
476 }
477
478 /**
479 * @tc.name: CheckRequestFocusImmdediately
480 * @tc.desc: test function : CheckRequestFocusImmdediately
481 * @tc.type: FUNC
482 */
483 HWTEST_F(SceneSessionManagerTest8, CheckRequestFocusImmdediately, Function | SmallTest | Level3)
484 {
485 SessionInfo sessionInfo;
486 sessionInfo.bundleName_ = "CheckRequestFocusImmdediately";
487 sessionInfo.abilityName_ = "CheckRequestFocusImmdediately";
488 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
489 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
490 EXPECT_NE(nullptr, sceneSession);
491 EXPECT_EQ(WindowType::APP_SUB_WINDOW_BASE, sceneSession->GetWindowType());
492 bool ret = ssm_->CheckRequestFocusImmdediately(sceneSession);
493 ASSERT_EQ(ret, false);
494 }
495
496 /**
497 * @tc.name: HandleTurnScreenOn
498 * @tc.desc: test function : HandleTurnScreenOn
499 * @tc.type: FUNC
500 */
501 HWTEST_F(SceneSessionManagerTest8, HandleTurnScreenOn, Function | SmallTest | Level3)
502 {
503 sptr<SceneSession> sceneSession = nullptr;
504 ssm_->HandleTurnScreenOn(sceneSession);
505 SessionInfo sessionInfo;
506 sessionInfo.bundleName_ = "HandleTurnScreenOn";
507 sessionInfo.abilityName_ = "HandleTurnScreenOn";
508 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
509 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
510 EXPECT_NE(nullptr, sceneSession);
511 sceneSession->GetSessionProperty()->SetTurnScreenOn(false);
512 ssm_->HandleTurnScreenOn(sceneSession);
513 EXPECT_EQ(false, sceneSession->GetSessionProperty()->IsTurnScreenOn());
514 sceneSession->GetSessionProperty()->SetTurnScreenOn(true);
515 ssm_->HandleTurnScreenOn(sceneSession);
516 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
517 usleep(NOT_WAIT_SYNC_IN_NS);
518 }
519
520 /**
521 * @tc.name: HandleKeepScreenOn
522 * @tc.desc: test function : HandleKeepScreenOn
523 * @tc.type: FUNC
524 */
525 HWTEST_F(SceneSessionManagerTest8, HandleKeepScreenOn, Function | SmallTest | Level3)
526 {
527 SessionInfo sessionInfo;
528 sessionInfo.bundleName_ = "HandleTurnScreenOn";
529 sessionInfo.abilityName_ = "HandleTurnScreenOn";
530 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
531 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
532 EXPECT_NE(nullptr, sceneSession);
533
534 std::string lockName = "windowLock";
535 ssm_->HandleKeepScreenOn(sceneSession, false, lockName, sceneSession->keepScreenLock_);
536 sceneSession->keepScreenLock_ = nullptr;
537 ssm_->HandleKeepScreenOn(sceneSession, true, lockName, sceneSession->keepScreenLock_);
538 bool enable = true;
539 EXPECT_EQ(WSError::WS_OK, ssm_->GetFreeMultiWindowEnableState(enable));
540 }
541
542 /**
543 * @tc.name: SetBrightness
544 * @tc.desc: test function : SetBrightness
545 * @tc.type: FUNC
546 */
547 HWTEST_F(SceneSessionManagerTest8, SetBrightness, Function | SmallTest | Level3)
548 {
549 SessionInfo sessionInfo;
550 sessionInfo.bundleName_ = "SetBrightness";
551 sessionInfo.abilityName_ = "SetBrightness";
552 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
553 EXPECT_NE(nullptr, sceneSession);
554 sceneSession->persistentId_ = 2024;
555
556 ssm_->SetDisplayBrightness(3.14f);
557 std::shared_ptr<AppExecFwk::EventHandler> pipeEventHandler = nullptr;
558 ssm_->eventHandler_ = pipeEventHandler;
559 ASSERT_EQ(nullptr, ssm_->eventHandler_);
560 auto ret = ssm_->SetBrightness(sceneSession, 3.15f);
561 EXPECT_EQ(WSError::WS_OK, ret);
562
563 ssm_->Init();
564 ASSERT_NE(nullptr, ssm_->eventHandler_);
565
566 ssm_->SetFocusedSessionId(2024, DEFAULT_DISPLAY_ID);
567 EXPECT_EQ(2024, ssm_->GetFocusedSessionId());
568
569 ret = ssm_->SetBrightness(sceneSession, 3.15f);
570 EXPECT_EQ(WSError::WS_OK, ret);
571 EXPECT_EQ(3.15f, ssm_->GetDisplayBrightness());
572
573 ret = ssm_->SetBrightness(sceneSession, UNDEFINED_BRIGHTNESS);
574 EXPECT_EQ(WSError::WS_OK, ret);
575 EXPECT_EQ(UNDEFINED_BRIGHTNESS, ssm_->GetDisplayBrightness());
576 }
577
578 /**
579 * @tc.name: TerminateSessionNew
580 * @tc.desc: test function : TerminateSessionNew
581 * @tc.type: FUNC
582 */
583 HWTEST_F(SceneSessionManagerTest8, TerminateSessionNew, Function | SmallTest | Level3)
584 {
585 sptr<AAFwk::SessionInfo> sessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
586 EXPECT_NE(nullptr, sessionInfo);
587 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
588 EXPECT_NE(nullptr, iRemoteObjectMocker);
589 sessionInfo->sessionToken = iRemoteObjectMocker;
590
591 SessionInfo info;
592 info.bundleName_ = "TerminateSessionNew";
593 info.abilityName_ = "TerminateSessionNew";
594 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
595 EXPECT_NE(nullptr, sceneSession);
596 sceneSession->SetAbilityToken(iRemoteObjectMocker);
597 ssm_->sceneSessionMap_.emplace(0, sceneSession);
598 ssm_->TerminateSessionNew(sessionInfo, true, true);
599 }
600
601 /**
602 * @tc.name: IsLastFrameLayoutFinished
603 * @tc.desc: test function : IsLastFrameLayoutFinished
604 * @tc.type: FUNC
605 */
606 HWTEST_F(SceneSessionManagerTest8, IsLastFrameLayoutFinished, Function | SmallTest | Level3)
607 {
608 ssm_->closeTargetFloatWindowFunc_ = nullptr;
609 std::string bundleName = "SetCloseTargetFloatWindowFunc";
__anonc166b0dc0302(const std::string& bundleName1) 610 ProcessCloseTargetFloatWindowFunc func = [](const std::string& bundleName1) {
611 return ;
612 };
613 ssm_->SetCloseTargetFloatWindowFunc(func);
614
__anonc166b0dc0402() 615 IsRootSceneLastFrameLayoutFinishedFunc func1 = []() {
616 return true;
617 };
618 ssm_->isRootSceneLastFrameLayoutFinishedFunc_ = func1;
619 ASSERT_NE(ssm_->isRootSceneLastFrameLayoutFinishedFunc_, nullptr);
620 bool isLayoutFinished = false;
621 auto ret = ssm_->IsLastFrameLayoutFinished(isLayoutFinished);
622 EXPECT_EQ(true, isLayoutFinished);
623 EXPECT_EQ(WSError::WS_OK, ret);
624 }
625
626 /**
627 * @tc.name: ReportScreenFoldStatus
628 * @tc.desc: test function : ReportScreenFoldStatus
629 * @tc.type: FUNC
630 */
631 HWTEST_F(SceneSessionManagerTest8, ReportScreenFoldStatus, Function | SmallTest | Level3)
632 {
633 sptr<SceneSession> sceneSession = nullptr;
634 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession));
635 SessionInfo info;
636 info.bundleName_ = "ReportScreenFoldStatus";
637 info.abilityName_ = "ReportScreenFoldStatus";
638 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
639 ASSERT_NE(sceneSession1, nullptr);
640 sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
641 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession1));
642 SessionInfo info1;
643 info1.bundleName_ = "ReportScreenFoldStatus1";
644 info1.abilityName_ = "ReportScreenFoldStatus1";
645 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info1, nullptr);
646 ASSERT_NE(sceneSession2, nullptr);
647 sceneSession2->SetSessionState(SessionState::STATE_ACTIVE);
648 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession2));
649 SessionInfo info2;
650 info2.bundleName_ = "ReportScreenFoldStatus2";
651 info2.abilityName_ = "ReportScreenFoldStatus2";
652 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(info2, nullptr);
653 ASSERT_NE(sceneSession3, nullptr);
654 sceneSession3->SetSessionState(SessionState::STATE_BACKGROUND);
655 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession3));
656 ssm_->OnScreenshot(1);
657 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
658 usleep(NOT_WAIT_SYNC_IN_NS);
659
660 ScreenFoldData data;
661 data.currentScreenFoldStatus_ = ScreenFoldData::INVALID_VALUE;
662 auto ret = ssm_->ReportScreenFoldStatus(data);
663 EXPECT_EQ(WMError::WM_DO_NOTHING, ret);
664 }
665
666 /**
667 * @tc.name: GetWindowModeType
668 * @tc.desc: test function : GetWindowModeType
669 * @tc.type: FUNC
670 */
671
672 HWTEST_F(SceneSessionManagerTest8, GetWindowModeType, Function | SmallTest | Level3)
673 {
674 SessionInfo info;
675 info.bundleName_ = "GetWindowModeType";
676 info.abilityName_ = "GetWindowModeType";
677 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
678 ASSERT_NE(sceneSession, nullptr);
679 ssm_->NotifySessionBackground(sceneSession, 1, true, true);
680 WindowModeType windowModeType = WindowModeType::WINDOW_MODE_SPLIT_FLOATING;
681 auto ret = ssm_->GetWindowModeType(windowModeType);
682 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
683 }
684
685 /**
686 * @tc.name: GetHostWindowRect
687 * @tc.desc: test function : GetHostWindowRect
688 * @tc.type: FUNC
689 */
690 HWTEST_F(SceneSessionManagerTest8, GetHostWindowRect, Function | SmallTest | Level3)
691 {
692 sptr<IDisplayChangeListener> listener = sptr<DisplayChangeListener>::MakeSptr();
693 ASSERT_NE(nullptr, listener);
694 DisplayId displayId = 1;
695 listener->OnScreenshot(displayId);
696 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
697 usleep(NOT_WAIT_SYNC_IN_NS);
698
699 int32_t hostWindowId = 0;
700 Rect rect = { 0, 0, 0, 0 };
701 SessionInfo info;
702 info.bundleName_ = "GetHostWindowRect";
703 info.abilityName_ = "GetHostWindowRect";
704 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
705 ASSERT_NE(sceneSession, nullptr);
706 sceneSession->sessionInfo_.screenId_ = 0;
707 EXPECT_EQ(sceneSession->GetScreenId(), 0);
708 ssm_->sceneSessionMap_.insert(std::make_pair(hostWindowId, sceneSession));
709 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(0, SuperFoldStatus::EXPANDED,
710 { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
711 auto ret = ssm_->GetHostWindowRect(hostWindowId, rect);
712 EXPECT_EQ(WSError::WS_OK, ret);
713 EXPECT_EQ(rect.posY_, 0);
714 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(0, SuperFoldStatus::KEYBOARD,
715 { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
716 sceneSession->winRect_ = {0, 100, 0, 0};
717 ret = ssm_->GetHostWindowRect(hostWindowId, rect);
718 EXPECT_EQ(WSError::WS_OK, ret);
719 EXPECT_EQ(rect.posY_, 100);
720
721 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(0, SuperFoldStatus::HALF_FOLDED,
722 { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1649, 2472, 40 });
723 sceneSession->winRect_ = {0, 1000, 100, 100};
724 ret = ssm_->GetHostWindowRect(hostWindowId, rect);
725 EXPECT_EQ(WSError::WS_OK, ret);
726 EXPECT_EQ(rect.posY_, 1000);
727 sceneSession->winRect_ = {0, 2000, 100, 100};
728 ret = ssm_->GetHostWindowRect(hostWindowId, rect);
729 WSRect hostRect = {0, 2000, 100, 100};
730 sceneSession->TransformGlobalRectToRelativeRect(hostRect);
731 EXPECT_EQ(WSError::WS_OK, ret);
732 EXPECT_EQ(rect.posY_, hostRect.posY_);
733
734 sceneSession->GetSessionProperty()->SetIsSystemKeyboard(false);
735 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(0, SuperFoldStatus::UNKNOWN,
736 { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
737 sceneSession->winRect_ = {0, 0, 0, 0};
738 ret = ssm_->GetHostWindowRect(hostWindowId, rect);
739 EXPECT_EQ(WSError::WS_OK, ret);
740 EXPECT_EQ(rect.posY_, 0);
741 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(0, SuperFoldStatus::FOLDED,
742 { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
743 sceneSession->winRect_ = {0, 100, 0, 0};
744 ret = ssm_->GetHostWindowRect(hostWindowId, rect);
745 EXPECT_EQ(WSError::WS_OK, ret);
746 EXPECT_EQ(rect.posY_, 100);
747
748 sceneSession->GetSessionProperty()->SetIsSystemKeyboard(true);
749 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(0, SuperFoldStatus::HALF_FOLDED,
750 { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1649, 2472, 40 });
751 sceneSession->winRect_ = {0, 1000, 100, 100};
752 ret = ssm_->GetHostWindowRect(hostWindowId, rect);
753 EXPECT_EQ(WSError::WS_OK, ret);
754 EXPECT_EQ(rect.posY_, 1000);
755 }
756
757 /**
758 * @tc.name: NotifyStackEmpty
759 * @tc.desc: test function : NotifyStackEmpty
760 * @tc.type: FUNC
761 */
762 HWTEST_F(SceneSessionManagerTest8, NotifyStackEmpty, Function | SmallTest | Level3)
763 {
764 SessionInfo info;
765 info.bundleName_ = "NotifyStackEmpty";
766 info.abilityName_ = "NotifyStackEmpty";
767 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
768 ASSERT_NE(sceneSession, nullptr);
769 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
770 auto ret = ssm_->NotifyStackEmpty(0);
771 EXPECT_EQ(ret, WSError::WS_OK);
772 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
773 usleep(NOT_WAIT_SYNC_IN_NS);
774 ret = ssm_->NotifyStackEmpty(1);
775 EXPECT_EQ(WSError::WS_OK, ret);
776 usleep(NOT_WAIT_SYNC_IN_NS);
777 }
778
779 /**
780 * @tc.name: GetAppMainSceneSession
781 * @tc.desc: test function : GetAppMainSceneSession
782 * @tc.type: FUNC
783 */
784 HWTEST_F(SceneSessionManagerTest8, GetAppMainSceneSession, Function | SmallTest | Level3)
785 {
786 ssm_->isUserBackground_ = true;
787 ssm_->FlushWindowInfoToMMI(true);
788
789 SessionInfo info;
790 info.bundleName_ = "GetAppMainSceneSession";
791 info.abilityName_ = "GetAppMainSceneSession";
792 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
793 ASSERT_NE(sceneSession, nullptr);
794 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
795 ASSERT_NE(property, nullptr);
796 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
797 property->SetParentPersistentId(2);
798 sceneSession->property_ = property;
799 ssm_->sceneSessionMap_.clear();
800 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
801 auto ret = ssm_->GetAppMainSceneSession(1, sceneSession);
802 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ret);
803 }
804
805 /**
806 * @tc.name: PostProcessProperty01
807 * @tc.desc: test function : PostProcessProperty
808 * @tc.type: FUNC
809 */
810 HWTEST_F(SceneSessionManagerTest8, PostProcessProperty01, Function | SmallTest | Level3)
811 {
812 SessionInfo info;
813 info.bundleName_ = "PostProcessProperty";
814 info.abilityName_ = "PostProcessProperty";
815 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
816 ASSERT_NE(sceneSession, nullptr);
817 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
818 ASSERT_NE(property, nullptr);
819 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
820 sceneSession->property_ = property;
821 sceneSession->postProcessProperty_ = true;
822 ssm_->sceneSessionMap_.clear();
823 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
824 uint32_t dirty = static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA);
825 ssm_->PostProcessProperty(dirty);
826
827 dirty = static_cast<uint32_t>(SessionUIDirtyFlag::VISIBLE);
828 ssm_->PostProcessProperty(dirty);
829
830 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
831 ssm_->PostProcessProperty(dirty);
832 EXPECT_EQ(false, sceneSession->postProcessProperty_);
833 }
834
835 /**
836 * @tc.name: SetVmaCacheStatus
837 * @tc.desc: test function : SetVmaCacheStatus
838 * @tc.type: FUNC
839 */
840 HWTEST_F(SceneSessionManagerTest8, SetVmaCacheStatus, Function | SmallTest | Level3)
841 {
842 AppExecFwk::AbilityInfo abilityInfo;
843 ssm_->ProcessPreload(abilityInfo);
844
845 auto ret = ssm_->SetVmaCacheStatus(true);
846 EXPECT_EQ(WSError::WS_OK, ret);
847 }
848
849 /**
850 * @tc.name: IsInDefaultScreen
851 * @tc.desc: test function : IsInDefaultScreen
852 * @tc.type: FUNC
853 */
854 HWTEST_F(SceneSessionManagerTest8, IsInDefaultScreen, Function | SmallTest | Level3)
855 {
856 sptr<SceneSession> sceneSession = nullptr;
857 ssm_->ProcessFocusWhenForegroundScbCore(sceneSession);
858
859 SessionInfo info;
860 info.bundleName_ = "IsInDefaultScreen";
861 info.abilityName_ = "IsInDefaultScreen";
862 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
863 ASSERT_NE(sceneSession, nullptr);
864 auto ret = ssm_->IsInDefaultScreen(sceneSession);
865 EXPECT_EQ(false, ret);
866 }
867
868 /**
869 * @tc.name: OnSessionStateChange
870 * @tc.desc: test function : OnSessionStateChange
871 * @tc.type: FUNC
872 */
873 HWTEST_F(SceneSessionManagerTest8, OnSessionStateChange, Function | SmallTest | Level3)
874 {
875 SessionInfo info;
876 info.bundleName_ = "OnSessionStateChange";
877 info.abilityName_ = "OnSessionStateChange";
878 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
879 ASSERT_NE(sceneSession, nullptr);
880 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
881 ASSERT_NE(property, nullptr);
882 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
883 sceneSession->property_ = property;
884 SessionState state = SessionState::STATE_DISCONNECT;
885 ssm_->sceneSessionMap_.clear();
886 ssm_->sceneSessionMap_.insert(std::make_pair(100, sceneSession));
887 ssm_->OnSessionStateChange(100, state);
888 property->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
889 ssm_->OnSessionStateChange(100, state);
890
891 ssm_->isRootSceneLastFrameLayoutFinishedFunc_ = nullptr;
892 bool isLayoutFinished = false;
893 auto ret = ssm_->IsLastFrameLayoutFinished(isLayoutFinished);
894 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret);
895 }
896
897 /**
898 * @tc.name: OnSessionStateChange01
899 * @tc.desc: test function : OnSessionStateChange
900 * @tc.type: FUNC
901 */
902 HWTEST_F(SceneSessionManagerTest8, OnSessionStateChange01, Function | SmallTest | Level3)
903 {
904 SessionInfo info;
905 info.bundleName_ = "OnSessionStateChange01";
906 info.abilityName_ = "OnSessionStateChange01";
907 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
908 ASSERT_NE(sceneSession, nullptr);
909 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
910 ASSERT_NE(property, nullptr);
911 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
912 sceneSession->property_ = property;
913 sceneSession->isScbCoreEnabled_ = true;
914 sceneSession->isVisible_ = true;
915 sceneSession->state_ = SessionState::STATE_FOREGROUND;
916 SessionState state = SessionState::STATE_FOREGROUND;
917 ssm_->sceneSessionMap_.clear();
918 ssm_->sceneSessionMap_.insert(std::make_pair(100, sceneSession));
919 ssm_->OnSessionStateChange(100, state);
920
921 property->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
922 ssm_->OnSessionStateChange(100, state);
923 auto ret = ssm_->UpdateMaximizeMode(1, true);
924 EXPECT_EQ(WSError::WS_OK, ret);
925 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
926 usleep(NOT_WAIT_SYNC_IN_NS);
927 }
928
929 /**
930 * @tc.name: IsWindowSupportCacheForRecovering
931 * @tc.desc: test function : IsWindowSupportCacheForRecovering
932 * @tc.type: FUNC
933 */
934 HWTEST_F(SceneSessionManagerTest8, IsWindowSupportCacheForRecovering, Function | SmallTest | Level3)
935 {
936 std::vector<int32_t> recoveredPersistentIds = {1};
937 ssm_->alivePersistentIds_.clear();
938 ssm_->alivePersistentIds_.push_back(1);
939 ssm_->alivePersistentIds_.push_back(2);
940 ssm_->alivePersistentIds_.push_back(3);
941 SessionInfo info;
942 info.bundleName_ = "IsWindowSupportCacheForRecovering";
943 info.abilityName_ = "IsWindowSupportCacheForRecovering";
944 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
945 ASSERT_NE(sceneSession, nullptr);
946 sceneSession->isRecovered_ = true;
947 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
948 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
949 ASSERT_NE(sceneSession1, nullptr);
950 sceneSession1->isRecovered_ = false;
951 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession1));
952 sptr<SceneSession> sceneSession2 = nullptr;
953 ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession2));
954 ssm_->ClearUnrecoveredSessions(recoveredPersistentIds);
955
956 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
957 ASSERT_NE(property, nullptr);
958 ssm_->recoveringFinished_ = true;
959 auto ret = ssm_->IsWindowSupportCacheForRecovering(sceneSession, property);
960 EXPECT_EQ(false, ret);
961 }
962
963 /**
964 * @tc.name: IsWindowSupportCacheForRecovering01
965 * @tc.desc: test function : IsWindowSupportCacheForRecovering
966 * @tc.type: FUNC
967 */
968 HWTEST_F(SceneSessionManagerTest8, IsWindowSupportCacheForRecovering01, Function | SmallTest | Level3)
969 {
970 std::vector<int32_t> windowIds = {0, 1};
971 sptr<SceneSession> sceneSession = nullptr;
972 ssm_->sceneSessionMap_.clear();
973 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession));
974 ssm_->OnNotifyAboveLockScreen(windowIds);
975
976 SessionInfo info;
977 info.bundleName_ = "IsWindowSupportCacheForRecovering01";
978 info.abilityName_ = "IsWindowSupportCacheForRecovering01";
979 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
980 ASSERT_NE(sceneSession1, nullptr);
981 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession1));
982 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
983 ASSERT_NE(property, nullptr);
984 ssm_->recoveringFinished_ = false;
985 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
986 auto ret = ssm_->IsWindowSupportCacheForRecovering(sceneSession1, property);
987 EXPECT_EQ(true, ret);
988 property->SetWindowType(WindowType::APP_SUB_WINDOW_END);
989 ret = ssm_->IsWindowSupportCacheForRecovering(sceneSession1, property);
990 EXPECT_EQ(false, ret);
991 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
992 ret = ssm_->IsWindowSupportCacheForRecovering(sceneSession1, property);
993 EXPECT_EQ(true, ret);
994 }
995
996 /**
997 * @tc.name: IsWindowSupportCacheForRecovering02
998 * @tc.desc: test function : IsWindowSupportCacheForRecovering
999 * @tc.type: FUNC
1000 */
1001 HWTEST_F(SceneSessionManagerTest8, IsWindowSupportCacheForRecovering02, Function | SmallTest | Level3)
1002 {
1003 SessionInfo info;
1004 info.bundleName_ = "IsWindowSupportCacheForRecovering02";
1005 info.abilityName_ = "IsWindowSupportCacheForRecovering02";
1006 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1007 ASSERT_NE(sceneSession, nullptr);
1008 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1009 ASSERT_NE(property, nullptr);
1010 ssm_->recoveringFinished_ = false;
1011 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1012 property->parentPersistentId_ = 1;
__anonc166b0dc0502(const sptr<SceneSession>& sceneSession) 1013 NotifyBindDialogSessionFunc func = [](const sptr<SceneSession>& sceneSession) {};
1014 ssm_->bindDialogTargetFuncMap_.insert(std::make_pair(1, func));
1015 auto ret = ssm_->IsWindowSupportCacheForRecovering(sceneSession, property);
1016 EXPECT_EQ(false, ret);
1017 }
1018
1019 /**
1020 * @tc.name: UnregisterSpecificSessionCreateListener
1021 * @tc.desc: test function : UnregisterSpecificSessionCreateListener
1022 * @tc.type: FUNC
1023 */
1024 HWTEST_F(SceneSessionManagerTest8, UnregisterSpecificSessionCreateListener, Function | SmallTest | Level3)
1025 {
1026 sptr<SceneSession> sceneSession = nullptr;
1027 ssm_->DestroyUIServiceExtensionSubWindow(sceneSession);
1028 ssm_->RegisterSessionInfoChangeNotifyManagerFunc(sceneSession);
1029
1030 SessionInfo info;
1031 info.bundleName_ = "UnregisterSpecificSessionCreateListener";
1032 info.abilityName_ = "UnregisterSpecificSessionCreateListener";
1033 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1034 ASSERT_NE(sceneSession, nullptr);
1035 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1036 ASSERT_NE(property, nullptr);
1037 ssm_->HandleHideNonSystemFloatingWindows(property, sceneSession);
1038
1039 NotifyCreateKeyboardSessionFunc func = [](const sptr<SceneSession>& keyboardSession,
__anonc166b0dc0602(const sptr<SceneSession>& keyboardSession, const sptr<SceneSession>& panelSession) 1040 const sptr<SceneSession>& panelSession) {};
1041 ssm_->SetCreateKeyboardSessionListener(func);
1042
__anonc166b0dc0702(int32_t x, int32_t y) 1043 ProcessOutsideDownEventFunc func1 = [](int32_t x, int32_t y) {};
1044 ssm_->outsideDownEventFunc_ = func1;
1045 ssm_->OnOutsideDownEvent(0, 0);
1046
1047 ssm_->createSubSessionFuncMap_.clear();
1048 ssm_->bindDialogTargetFuncMap_.clear();
__anonc166b0dc0802(const sptr<SceneSession>& sceneSession) 1049 NotifyBindDialogSessionFunc func2 = [](const sptr<SceneSession>& sceneSession) {};
1050 ssm_->bindDialogTargetFuncMap_.insert(std::make_pair(1, func2));
1051 ssm_->UnregisterSpecificSessionCreateListener(1);
1052 EXPECT_EQ(true, ssm_->bindDialogTargetFuncMap_.empty());
1053 }
1054
1055 /**
1056 * @tc.name: GetIsLayoutFullScreen
1057 * @tc.desc: test function : GetIsLayoutFullScreen
1058 * @tc.type: FUNC
1059 */
1060 HWTEST_F(SceneSessionManagerTest8, GetIsLayoutFullScreen, Function | SmallTest | Level3)
1061 {
1062 std::ostringstream oss;
1063 SessionInfo info;
1064 info.bundleName_ = "GetIsLayoutFullScreen";
1065 info.abilityName_ = "GetIsLayoutFullScreen";
1066 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1067 ASSERT_NE(sceneSession, nullptr);
1068 ssm_->DumpSessionInfo(sceneSession, oss);
1069
1070 ssm_->listenerController_ = std::make_shared<SessionListenerController>();
1071 ASSERT_NE(ssm_->listenerController_, nullptr);
1072 info.isSystem_ = true;
1073 ssm_->NotifyUnFocusedByMission(sceneSession);
1074 info.isSystem_ = false;
1075 ssm_->NotifyUnFocusedByMission(sceneSession);
1076
1077 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1078 ASSERT_NE(property, nullptr);
1079 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1080 property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1081 property->SetIsLayoutFullScreen(true);
1082 sceneSession->property_ = property;
1083 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1084 bool isLayoutFullScreen = true;
1085 auto ret = ssm_->GetIsLayoutFullScreen(isLayoutFullScreen);
1086 EXPECT_EQ(WSError::WS_OK, ret);
1087 property->SetIsLayoutFullScreen(false);
1088 ret = ssm_->GetIsLayoutFullScreen(isLayoutFullScreen);
1089 EXPECT_EQ(WSError::WS_OK, ret);
1090 }
1091 }
1092 } // namespace Rosen
1093 } // namespace OHOS