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 "interfaces/include/ws_common.h"
19 #include "iremote_object_mocker.h"
20 #include "session_manager/include/scene_session_manager.h"
21 #include "session_info.h"
22 #include "session/host/include/scene_session.h"
23 #include "session_manager.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 namespace {
31 const std::string EMPTY_DEVICE_ID = "";
32 using ConfigItem = WindowSceneConfig::ConfigItem;
33 }
34 class SceneSessionManagerTest7 : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp() override;
39 void TearDown() override;
40
41 static bool gestureNavigationEnabled_;
42 static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
43 static sptr<SceneSessionManager> ssm_;
44 private:
45 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
46 };
47
48 sptr<SceneSessionManager> SceneSessionManagerTest7::ssm_ = nullptr;
49
50 bool SceneSessionManagerTest7::gestureNavigationEnabled_ = true;
51 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest7::callbackFunc_ = [](bool enable,
__anon3b3891530202(bool enable, const std::string& bundleName, GestureBackType type) 52 const std::string& bundleName, GestureBackType type) {
53 gestureNavigationEnabled_ = enable;
54 };
55
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)56 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
57 {
58 }
59
ProcessStatusBarEnabledChangeFuncTest(bool enable)60 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
61 {
62 }
63
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)64 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
65 {
66 }
67
SetUpTestCase()68 void SceneSessionManagerTest7::SetUpTestCase()
69 {
70 ssm_ = &SceneSessionManager::GetInstance();
71 }
72
TearDownTestCase()73 void SceneSessionManagerTest7::TearDownTestCase()
74 {
75 ssm_ = nullptr;
76 }
77
SetUp()78 void SceneSessionManagerTest7::SetUp()
79 {
80 ssm_->sceneSessionMap_.clear();
81 }
82
TearDown()83 void SceneSessionManagerTest7::TearDown()
84 {
85 usleep(WAIT_SYNC_IN_NS);
86 ssm_->sceneSessionMap_.clear();
87 }
88
89 namespace {
90 /**
91 * @tc.name: UpdateSessionWindowVisibilityListener
92 * @tc.desc: UpdateSessionWindowVisibilityListener
93 * @tc.type: FUNC
94 */
95 HWTEST_F(SceneSessionManagerTest7, UpdateSessionWindowVisibilityListener, Function | SmallTest | Level3)
96 {
97 int32_t persistentId = 1;
98 bool haveListener = true;
99 ASSERT_NE(nullptr, ssm_);
100 ssm_->sceneSessionMap_.clear();
101 auto ret = ssm_->UpdateSessionWindowVisibilityListener(persistentId, haveListener);
102 EXPECT_EQ(ret, WSError::WS_DO_NOTHING);
103 SessionInfo sessionInfo;
104 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
105 sessionInfo.abilityName_ = "UpdateSessionWindowVisibilityListener";
106 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
107 ASSERT_NE(nullptr, sceneSession);
108 sceneSession->callingPid_ = 65535;
109 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
110 ret = ssm_->UpdateSessionWindowVisibilityListener(persistentId, haveListener);
111 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
112 }
113
114 /**
115 * @tc.name: ProcessVirtualPixelRatioChange
116 * @tc.desc: ProcessVirtualPixelRatioChange
117 * @tc.type: FUNC
118 */
119 HWTEST_F(SceneSessionManagerTest7, ProcessVirtualPixelRatioChange, Function | SmallTest | Level3)
120 {
121 DisplayId defaultDisplayId = 0;
122 sptr<DisplayInfo> displayInfo = nullptr;
123 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
124 DisplayStateChangeType type = DisplayStateChangeType::BEFORE_SUSPEND;
125 ASSERT_NE(nullptr, ssm_);
126 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
127 displayInfo = sptr<DisplayInfo>::MakeSptr();
128 ASSERT_NE(nullptr, displayInfo);
129 ssm_->sceneSessionMap_.clear();
130 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
131 SessionInfo sessionInfo;
132 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
133 sessionInfo.abilityName_ = "UpdateAvoidArea";
134 sessionInfo.isSystem_ = true;
135 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
136 ASSERT_NE(nullptr, sceneSession);
137 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
138 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
139 sessionInfo.isSystem_ = false;
140 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
141 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
142 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
143 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
144 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
145 sceneSession->SetSessionState(SessionState::STATE_INACTIVE);
146 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
147 sceneSession = nullptr;
148 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
149 }
150
151 /**
152 * @tc.name: ProcessVirtualPixelRatioChange01
153 * @tc.desc: ProcessVirtualPixelRatioChange
154 * @tc.type: FUNC
155 */
156 HWTEST_F(SceneSessionManagerTest7, ProcessVirtualPixelRatioChange01, Function | SmallTest | Level3)
157 {
158 DisplayId defaultDisplayId = 0;
159 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
160 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
161 DisplayStateChangeType type = DisplayStateChangeType::BEFORE_SUSPEND;
162 ASSERT_NE(nullptr, displayInfo);
163 ASSERT_NE(nullptr, ssm_);
164 ssm_->processVirtualPixelRatioChangeFunc_ = nullptr;
165 displayInfo->SetVirtualPixelRatio(0.1f);
166 displayInfo->SetDensityInCurResolution(0.1f);
167 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
__anon3b3891530402(float ratio, const OHOS::Rosen::Rect& rect) 168 ProcessVirtualPixelRatioChangeFunc func = [](float ratio, const OHOS::Rosen::Rect& rect) {};
169 ssm_->SetVirtualPixelRatioChangeListener(func);
170 ASSERT_NE(nullptr, ssm_->processVirtualPixelRatioChangeFunc_);
171 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
172 displayInfo->SetDensityInCurResolution(0.2f);
173 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
174 ssm_->processVirtualPixelRatioChangeFunc_ = nullptr;
175 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
176 }
177
178 /**
179 * @tc.name: ProcessUpdateRotationChange
180 * @tc.desc: ProcessUpdateRotationChange
181 * @tc.type: FUNC
182 */
183 HWTEST_F(SceneSessionManagerTest7, ProcessUpdateRotationChange, Function | SmallTest | Level3)
184 {
185 DisplayId defaultDisplayId = 0;
186 sptr<DisplayInfo> displayInfo = nullptr;
187 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
188 DisplayStateChangeType type = DisplayStateChangeType::BEFORE_SUSPEND;
189 ASSERT_NE(nullptr, ssm_);
190 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
191 displayInfo = sptr<DisplayInfo>::MakeSptr();
192 ASSERT_NE(nullptr, displayInfo);
193 SessionInfo sessionInfo;
194 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
195 sessionInfo.abilityName_ = "UpdateAvoidArea";
196 sessionInfo.isSystem_ = true;
197 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
198 ASSERT_NE(nullptr, sceneSession);
199 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
200 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
201 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
202 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
203 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
204 sceneSession->SetSessionState(SessionState::STATE_INACTIVE);
205 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
206 WSRectF bounds = { 0, 0, 0, 0 };
207 sceneSession->SetBounds(bounds);
208 displayInfo->width_ = 0;
209 displayInfo->height_ = 0;
210 Rotation rotation = Rotation::ROTATION_0;
211 sceneSession->SetRotation(rotation);
212 displayInfo->SetRotation(rotation);
213 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
214 }
215
216 /**
217 * @tc.name: FlushUIParams
218 * @tc.desc: FlushUIParams
219 * @tc.type: FUNC
220 */
221 HWTEST_F(SceneSessionManagerTest7, FlushUIParams, Function | SmallTest | Level3)
222 {
223 SessionInfo sessionInfo;
224 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
225 sessionInfo.abilityName_ = "FlushUIParams";
226 sessionInfo.screenId_ = 1;
227 ScreenId screenId = 2;
228 std::unordered_map<int32_t, SessionUIParam> uiParams;
229 uiParams.clear();
230 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
231 ASSERT_NE(nullptr, sceneSession);
232 ASSERT_NE(nullptr, sceneSession->property_);
233 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
234 ASSERT_NE(nullptr, ssm_);
235 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
236 ssm_->FlushUIParams(screenId, std::move(uiParams));
237 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
238 ssm_->FlushUIParams(screenId, std::move(uiParams));
239 }
240
241 /**
242 * @tc.name: FlushUIParams01
243 * @tc.desc: FlushUIParams
244 * @tc.type: FUNC
245 */
246 HWTEST_F(SceneSessionManagerTest7, FlushUIParams01, Function | SmallTest | Level3)
247 {
248 SessionInfo sessionInfo;
249 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
250 sessionInfo.abilityName_ = "FlushUIParams01";
251 sessionInfo.screenId_ = 2;
252 ScreenId screenId = 2;
253 std::unordered_map<int32_t, SessionUIParam> uiParams;
254 uiParams.clear();
255 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
256 ASSERT_NE(nullptr, sceneSession);
257 ASSERT_NE(nullptr, sceneSession->property_);
258 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
259 sceneSession->persistentId_ = 1;
260 ASSERT_NE(nullptr, ssm_);
261 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
262 SessionUIParam sessionUIParam;
263 uiParams.insert(std::make_pair(1, sessionUIParam));
264 ssm_->FlushUIParams(screenId, std::move(uiParams));
265 sessionInfo.screenId_ = -1ULL;
266 ssm_->FlushUIParams(screenId, std::move(uiParams));
267 }
268
269 /**
270 * @tc.name: RegisterIAbilityManagerCollaborator
271 * @tc.desc: RegisterIAbilityManagerCollaborator
272 * @tc.type: FUNC
273 */
274 HWTEST_F(SceneSessionManagerTest7, RegisterIAbilityManagerCollaborator, Function | SmallTest | Level3)
275 {
276 int32_t type = 0;
277 sptr<AAFwk::IAbilityManagerCollaborator> impl = nullptr;
278 ASSERT_NE(nullptr, ssm_);
279 auto ret = ssm_->RegisterIAbilityManagerCollaborator(type, impl);
280 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
281 }
282
283 /**
284 * @tc.name: ProcessBackEvent
285 * @tc.desc: ProcessBackEvent
286 * @tc.type: FUNC
287 */
288 HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent, Function | SmallTest | Level3)
289 {
290 SessionInfo sessionInfo;
291 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
292 sessionInfo.abilityName_ = "FlushUIParams01";
293 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
294 ASSERT_NE(nullptr, sceneSession);
295 ASSERT_NE(nullptr, ssm_);
296 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
297 ssm_->focusedSessionId_ = 1;
298 ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
299 auto ret = ssm_->ProcessBackEvent();
300 EXPECT_EQ(ret, WSError::WS_OK);
301 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
302 sessionInfo.isSystem_ = true;
303 ssm_->rootSceneProcessBackEventFunc_ = nullptr;
304 ret = ssm_->ProcessBackEvent();
305 EXPECT_EQ(ret, WSError::WS_OK);
__anon3b3891530502()306 RootSceneProcessBackEventFunc func = [](){};
307 ssm_->rootSceneProcessBackEventFunc_ = func;
308 ASSERT_NE(nullptr, ssm_->rootSceneProcessBackEventFunc_);
309 ret = ssm_->ProcessBackEvent();
310 EXPECT_EQ(ret, WSError::WS_OK);
311 sessionInfo.isSystem_ = false;
312 ret = ssm_->ProcessBackEvent();
313 EXPECT_EQ(ret, WSError::WS_OK);
314 ssm_->rootSceneProcessBackEventFunc_ = nullptr;
315 ret = ssm_->ProcessBackEvent();
316 EXPECT_EQ(ret, WSError::WS_OK);
317 }
318
319 /**
320 * @tc.name: DestroySpecificSession
321 * @tc.desc: DestroySpecificSession
322 * @tc.type: FUNC
323 */
324 HWTEST_F(SceneSessionManagerTest7, DestroySpecificSession, Function | SmallTest | Level3)
325 {
326 ASSERT_NE(nullptr, ssm_);
327 ssm_->remoteObjectMap_.clear();
328 sptr<IRemoteObject> remoteObject = sptr<IRemoteObjectMocker>::MakeSptr();
329 ASSERT_NE(nullptr, remoteObject);
330 ssm_->DestroySpecificSession(remoteObject);
331 ssm_->remoteObjectMap_.insert(std::make_pair(remoteObject, 1));
332 SessionInfo sessionInfo;
333 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
334 sessionInfo.abilityName_ = "DestroySpecificSession";
335 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
336 ASSERT_NE(nullptr, sceneSession);
337 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
338 ssm_->DestroySpecificSession(remoteObject);
339 sceneSession = nullptr;
340 ssm_->DestroySpecificSession(remoteObject);
341 }
342
343 /**
344 * @tc.name: DestroyAndDisconnectSpecificSessionWithDetachCallback
345 * @tc.desc: DestroyAndDisconnectSpecificSessionWithDetachCallback
346 * @tc.type: FUNC
347 */
348 HWTEST_F(SceneSessionManagerTest7, DestroyAndDisconnectSpecificSessionWithDetachCallback,
349 Function | SmallTest | Level3)
350 {
351 int32_t persistentId = 1;
352 sptr<IRemoteObject> callback = sptr<IRemoteObjectMocker>::MakeSptr();
353 ASSERT_NE(nullptr, callback);
354 SessionInfo sessionInfo;
355 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
356 sessionInfo.abilityName_ = "DestroyAndDisconnectSpecificSessionWithDetachCallback";
357 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
358 ASSERT_NE(nullptr, sceneSession);
359 sceneSession->SetCallingUid(1);
360 ASSERT_NE(nullptr, ssm_);
361 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
362 auto ret = ssm_->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
363 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
364 }
365
366 /**
367 * @tc.name: DestroyAndDisconnectSpecificSessionInner
368 * @tc.desc: DestroyAndDisconnectSpecificSessionInner
369 * @tc.type: FUNC
370 */
371 HWTEST_F(SceneSessionManagerTest7, DestroyAndDisconnectSpecificSessionInner, Function | SmallTest | Level3)
372 {
373 SessionInfo sessionInfo;
374 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
375 sessionInfo.abilityName_ = "DestroyAndDisconnectSpecificSessionInner";
376 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
377 ASSERT_NE(nullptr, sceneSession);
378 ASSERT_NE(nullptr, sceneSession->property_);
379 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
380 sceneSession->SetParentPersistentId(2);
381 SessionInfo sessionInfo1;
382 sessionInfo1.bundleName_ = "SceneSessionManagerTest7";
383 sessionInfo1.abilityName_ = "ParentSceneSession";
384 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
385 ASSERT_NE(nullptr, sceneSession1);
386 ASSERT_NE(nullptr, ssm_);
387 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
388 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
389 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
390 EXPECT_EQ(ret, WSError::WS_OK);
391 sceneSession1 = nullptr;
392 ret = ssm_->DestroyAndDisconnectSpecificSessionInner(2);
393 EXPECT_EQ(ret, WSError::WS_OK);
394 }
395
396 /**
397 * @tc.name: DestroyAndDisconnectSpecificSessionInner01
398 * @tc.desc: DestroyAndDisconnectSpecificSessionInner
399 * @tc.type: FUNC
400 */
401 HWTEST_F(SceneSessionManagerTest7, DestroyAndDisconnectSpecificSessionInner01, Function | SmallTest | Level3)
402 {
403 SessionInfo sessionInfo;
404 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
405 sessionInfo.abilityName_ = "DestroyAndDisconnectSpecificSessionInner";
406 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
407 ASSERT_NE(nullptr, sceneSession);
408 ASSERT_NE(nullptr, sceneSession->property_);
409 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
410 sceneSession->SetParentPersistentId(2);
411 SessionInfo sessionInfo1;
412 sessionInfo1.bundleName_ = "SceneSessionManagerTest7";
413 sessionInfo1.abilityName_ = "ParentSceneSession";
414 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
415 ASSERT_NE(nullptr, sceneSession1);
416 ASSERT_NE(nullptr, ssm_);
417 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
418 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
419 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
420 EXPECT_EQ(ret, WSError::WS_OK);
421 sceneSession1 = nullptr;
422 ret = ssm_->DestroyAndDisconnectSpecificSessionInner(2);
423 EXPECT_EQ(ret, WSError::WS_OK);
424 }
425
426 /**
427 * @tc.name: DestroyAndDisconnectSpecificSessionInner02
428 * @tc.desc: DestroyAndDisconnectSpecificSessionInner
429 * @tc.type: FUNC
430 */
431 HWTEST_F(SceneSessionManagerTest7, DestroyAndDisconnectSpecificSessionInner02, Function | SmallTest | Level3)
432 {
433 SessionInfo sessionInfo;
434 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
435 sessionInfo.abilityName_ = "DestroyAndDisconnectSpecificSessionInner";
436 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
437 ASSERT_NE(nullptr, sceneSession);
438 ASSERT_NE(nullptr, sceneSession->property_);
439 sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
440 sceneSession->SetParentPersistentId(2);
441 SessionInfo sessionInfo1;
442 sessionInfo1.bundleName_ = "SceneSessionManagerTest7";
443 sessionInfo1.abilityName_ = "ParentSceneSession";
444 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
445 ASSERT_NE(nullptr, sceneSession1);
446 ASSERT_NE(nullptr, ssm_);
447 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
448 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
449 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
450 EXPECT_EQ(ret, WSError::WS_OK);
451 sceneSession1 = nullptr;
452 ret = ssm_->DestroyAndDisconnectSpecificSessionInner(2);
453 EXPECT_EQ(ret, WSError::WS_OK);
454 }
455
456 /**
457 * @tc.name: CheckPiPPriority
458 * @tc.desc: CheckPiPPriority
459 * @tc.type: FUNC
460 */
461 HWTEST_F(SceneSessionManagerTest7, CheckPiPPriority, Function | SmallTest | Level3)
462 {
463 SessionInfo sessionInfo;
464 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
465 sessionInfo.abilityName_ = "CheckPiPPriority";
466 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
467 ASSERT_NE(nullptr, sceneSession);
468 ASSERT_NE(nullptr, sceneSession->property_);
469 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
470 PiPTemplateInfo pipTemplateInfo;
471 pipTemplateInfo.priority = 0;
472 sceneSession->pipTemplateInfo_.priority = 1;
473 sceneSession->state_ = SessionState::STATE_FOREGROUND;
474 ASSERT_NE(nullptr, ssm_);
475 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
476 auto ret = ssm_->CheckPiPPriority(pipTemplateInfo);
477 EXPECT_EQ(ret, false);
478 sceneSession->state_ = SessionState::STATE_ACTIVE;
479 ret = ssm_->CheckPiPPriority(pipTemplateInfo);
480 EXPECT_EQ(ret, false);
481 pipTemplateInfo.priority = 1;
482 ret = ssm_->CheckPiPPriority(pipTemplateInfo);
483 EXPECT_EQ(ret, true);
484 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
485 ret = ssm_->CheckPiPPriority(pipTemplateInfo);
486 EXPECT_EQ(ret, true);
487 sceneSession = nullptr;
488 ret = ssm_->CheckPiPPriority(pipTemplateInfo);
489 EXPECT_EQ(ret, true);
490 }
491
492 /**
493 * @tc.name: IsSessionVisibleForeground
494 * @tc.desc: IsSessionVisibleForeground
495 * @tc.type: FUNC
496 */
497 HWTEST_F(SceneSessionManagerTest7, IsSessionVisibleForeground, Function | SmallTest | Level3)
498 {
499 sptr<SceneSession> session = nullptr;
500 ASSERT_NE(nullptr, ssm_);
501 auto ret = ssm_->IsSessionVisibleForeground(session);
502 EXPECT_EQ(ret, false);
503 SessionInfo sessionInfo;
504 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
505 sessionInfo.abilityName_ = "IsSessionVisibleForeground";
506 session = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
507 ASSERT_NE(nullptr, session);
508 session->isVisible_ = false;
509 ret = ssm_->IsSessionVisibleForeground(session);
510 EXPECT_EQ(ret, false);
511 }
512
513 /**
514 * @tc.name: GetAllSessionDumpInfo
515 * @tc.desc: GetAllSessionDumpInfo
516 * @tc.type: FUNC
517 */
518 HWTEST_F(SceneSessionManagerTest7, GetAllSessionDumpInfo, Function | SmallTest | Level3)
519 {
520 SessionInfo sessionInfo;
521 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
522 sessionInfo.abilityName_ = "GetAllSessionDumpInfo";
523 sessionInfo.isSystem_ = false;
524 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
525 ASSERT_NE(nullptr, sceneSession);
526 sceneSession->state_ = SessionState::STATE_DISCONNECT;
527 ASSERT_NE(nullptr, ssm_);
528 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
529 std::string dumpInfo = "";
530 auto ret = ssm_->GetAllSessionDumpInfo(dumpInfo);
531 EXPECT_EQ(ret, WSError::WS_OK);
532 sceneSession->state_ = SessionState::STATE_END;
533 ret = ssm_->GetAllSessionDumpInfo(dumpInfo);
534 EXPECT_EQ(ret, WSError::WS_OK);
535 sceneSession->state_ = SessionState::STATE_ACTIVE;
536 ret = ssm_->GetAllSessionDumpInfo(dumpInfo);
537 EXPECT_EQ(ret, WSError::WS_OK);
538 sessionInfo.isSystem_ = true;
539 ret = ssm_->GetAllSessionDumpInfo(dumpInfo);
540 EXPECT_EQ(ret, WSError::WS_OK);
541 sceneSession = nullptr;
542 ret = ssm_->GetAllSessionDumpInfo(dumpInfo);
543 EXPECT_EQ(ret, WSError::WS_OK);
544 }
545
546 /**
547 * @tc.name: GetAllSessionDumpInfo01
548 * @tc.desc: GetAllSessionDumpInfo
549 * @tc.type: FUNC
550 */
551 HWTEST_F(SceneSessionManagerTest7, GetAllSessionDumpInfo01, Function | SmallTest | Level3)
552 {
553 SessionInfo sessionInfo;
554 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
555 sessionInfo.abilityName_ = "GetAllSessionDumpInfo01";
556 sessionInfo.isSystem_ = true;
557 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
558 ASSERT_NE(nullptr, sceneSession);
559 sceneSession->isVisible_ = true;
560 ASSERT_NE(nullptr, ssm_);
561 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
562 std::string dumpInfo = "";
563 auto ret = ssm_->GetAllSessionDumpInfo(dumpInfo);
564 EXPECT_EQ(ret, WSError::WS_OK);
565 sceneSession->isVisible_ = false;
566 ret = ssm_->GetAllSessionDumpInfo(dumpInfo);
567 EXPECT_EQ(ret, WSError::WS_OK);
568 }
569
570 /**
571 * @tc.name: UpdateNormalSessionAvoidArea
572 * @tc.desc: UpdateNormalSessionAvoidArea
573 * @tc.type: FUNC
574 */
575 HWTEST_F(SceneSessionManagerTest7, UpdateNormalSessionAvoidArea, Function | SmallTest | Level3)
576 {
577 SessionInfo sessionInfo;
578 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
579 sessionInfo.abilityName_ = "UpdateNormalSessionAvoidArea";
580 sessionInfo.isSystem_ = true;
581 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
582 ASSERT_NE(nullptr, sceneSession);
583 sceneSession->isVisible_ = true;
584 sceneSession->state_ = SessionState::STATE_FOREGROUND;
585 int32_t persistentId = 1;
586 bool needUpdate = true;
587 ASSERT_NE(nullptr, ssm_);
588 ssm_->avoidAreaListenerSessionSet_.clear();
589 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
590 sceneSession->isVisible_ = false;
591 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
592 }
593
594 /**
595 * @tc.name: UpdateNormalSessionAvoidArea01
596 * @tc.desc: UpdateNormalSessionAvoidArea
597 * @tc.type: FUNC
598 */
599 HWTEST_F(SceneSessionManagerTest7, UpdateNormalSessionAvoidArea01, Function | SmallTest | Level3)
600 {
601 SessionInfo sessionInfo;
602 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
603 sessionInfo.abilityName_ = "UpdateNormalSessionAvoidArea01";
604 sessionInfo.isSystem_ = true;
605 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
606 ASSERT_NE(nullptr, sceneSession);
607 sceneSession->isVisible_ = true;
608 sceneSession->state_ = SessionState::STATE_FOREGROUND;
609 int32_t persistentId = 1;
610 bool needUpdate = true;
611 ASSERT_NE(nullptr, ssm_);
612 ssm_->avoidAreaListenerSessionSet_.clear();
613 ssm_->avoidAreaListenerSessionSet_.insert(persistentId);
614 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
615 sceneSession = nullptr;
616 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
617 }
618
619 /**
620 * @tc.name: UnregisterWindowManagerAgent
621 * @tc.desc: UnregisterWindowManagerAgent
622 * @tc.type: FUNC
623 */
624 HWTEST_F(SceneSessionManagerTest7, UnregisterWindowManagerAgent, Function | SmallTest | Level3)
625 {
626 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR;
627 sptr<IWindowManagerAgent> windowManagerAgent = nullptr;
628 ASSERT_NE(nullptr, ssm_);
629 auto ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
630 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
631 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED;
632 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
633 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
634 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG;
635 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
636 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
637 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY;
638 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
639 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_PERMISSION);
640 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE;
641 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
642 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_PERMISSION);
643 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM;
644 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
645 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_PERMISSION);
646 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
647 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
648 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_PERMISSION);
649 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE;
650 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
651 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_PERMISSION);
652 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE;
653 ret = ssm_->UnregisterWindowManagerAgent(type, windowManagerAgent);
654 EXPECT_EQ(ret, WMError::WM_ERROR_NULLPTR);
655 }
656
657 /**
658 * @tc.name: FindSessionByAffinity
659 * @tc.desc: FindSessionByAffinity
660 * @tc.type: FUNC
661 */
662 HWTEST_F(SceneSessionManagerTest7, FindSessionByAffinity, Function | SmallTest | Level3)
663 {
664 std::string affinity = "";
665 ASSERT_NE(nullptr, ssm_);
666 auto ret = ssm_->FindSessionByAffinity(affinity);
667 EXPECT_EQ(ret, nullptr);
668 affinity = "Test";
669 SessionInfo sessionInfo;
670 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
671 sessionInfo.abilityName_ = "FindSessionByAffinity";
672 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
673 ASSERT_NE(nullptr, sceneSession);
674 sceneSession->SetCollaboratorType(CollaboratorType::DEFAULT_TYPE);
675 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
676 ret = ssm_->FindSessionByAffinity(affinity);
677 EXPECT_EQ(ret, nullptr);
678 sceneSession->SetCollaboratorType(CollaboratorType::OTHERS_TYPE);
679 sceneSession->sessionInfo_.sessionAffinity = "Test";
680 ret = ssm_->FindSessionByAffinity(affinity);
681 EXPECT_EQ(ret, sceneSession);
682 }
683
684 /**
685 * @tc.name: FindSessionByAffinity01
686 * @tc.desc: FindSessionByAffinity
687 * @tc.type: FUNC
688 */
689 HWTEST_F(SceneSessionManagerTest7, FindSessionByAffinity01, Function | SmallTest | Level3)
690 {
691 std::string affinity = "Test";
692 sptr<SceneSession> sceneSession = nullptr;
693 ASSERT_NE(nullptr, ssm_);
694 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
695 auto ret = ssm_->FindSessionByAffinity(affinity);
696 EXPECT_EQ(ret, nullptr);
697 }
698
699 /**
700 * @tc.name: ProcessUpdateRotationChange01
701 * @tc.desc: ProcessUpdateRotationChange
702 * @tc.type: FUNC
703 */
704 HWTEST_F(SceneSessionManagerTest7, ProcessUpdateRotationChange01, Function | SmallTest | Level3)
705 {
706 DisplayId defaultDisplayId = 0;
707 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
708 ASSERT_NE(nullptr, displayInfo);
709 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
710 DisplayStateChangeType type = DisplayStateChangeType::BEFORE_SUSPEND;
711 sptr<SceneSession> sceneSession = nullptr;
712 ASSERT_NE(nullptr, ssm_);
713 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
714 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
715 }
716
717 /**
718 * @tc.name: ProcessUpdateRotationChange02
719 * @tc.desc: ProcessUpdateRotationChange
720 * @tc.type: FUNC
721 */
722 HWTEST_F(SceneSessionManagerTest7, ProcessUpdateRotationChange02, Function | SmallTest | Level3)
723 {
724 DisplayId defaultDisplayId = 0;
725 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
726 ASSERT_NE(nullptr, displayInfo);
727 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
728 DisplayStateChangeType type = DisplayStateChangeType::BEFORE_SUSPEND;
729 SessionInfo sessionInfo;
730 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
731 sessionInfo.abilityName_ = "UpdateAvoidArea";
732 sessionInfo.isSystem_ = true;
733 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
734 ASSERT_NE(nullptr, sceneSession);
735 ASSERT_NE(nullptr, ssm_);
736 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
737 sceneSession->SetSessionState(SessionState::STATE_INACTIVE);
738 WSRectF bounds = { 0, 0, 0, 0 };
739 sceneSession->SetBounds(bounds);
740 displayInfo->width_ = 0;
741 displayInfo->height_ = 0;
742 sceneSession->SetRotation(Rotation::ROTATION_0);
743 displayInfo->SetRotation(Rotation::ROTATION_90);
744 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
745 displayInfo->height_ = 1;
746 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
747 displayInfo->width_ = 1;
748 ssm_->ProcessUpdateRotationChange(defaultDisplayId, displayInfo, displayInfoMap, type);
749 }
750
751 /**
752 * @tc.name: SetSkipSelfWhenShowOnVirtualScreen
753 * @tc.desc: SetSkipSelfWhenShowOnVirtualScreen
754 * @tc.type: FUNC
755 */
756 HWTEST_F(SceneSessionManagerTest7, SetSkipSelfWhenShowOnVirtualScreen, Function | SmallTest | Level3)
757 {
758 uint64_t surfaceNodeId = 0;
759 bool isSkip = true;
760 ASSERT_NE(nullptr, ssm_);
761 ssm_->skipSurfaceNodeIds_.clear();
762 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, isSkip);
763 ssm_->skipSurfaceNodeIds_.push_back(surfaceNodeId);
764 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, isSkip);
765 }
766
767 /**
768 * @tc.name: SetSkipSelfWhenShowOnVirtualScreen01
769 * @tc.desc: SetSkipSelfWhenShowOnVirtualScreen
770 * @tc.type: FUNC
771 */
772 HWTEST_F(SceneSessionManagerTest7, SetSkipSelfWhenShowOnVirtualScreen01, Function | SmallTest | Level3)
773 {
774 uint64_t surfaceNodeId = 0;
775 bool isSkip = false;
776 ASSERT_NE(nullptr, ssm_);
777 ssm_->skipSurfaceNodeIds_.clear();
778 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, isSkip);
779 ssm_->skipSurfaceNodeIds_.push_back(surfaceNodeId);
780 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, isSkip);
781 }
782
783 /**
784 * @tc.name: GetMainWindowInfos
785 * @tc.desc: GetMainWindowInfos
786 * @tc.type: FUNC
787 */
788 HWTEST_F(SceneSessionManagerTest7, GetMainWindowInfos, Function | SmallTest | Level3)
789 {
790 int32_t topNum = 1;
791 std::vector<MainWindowInfo> topNInfo;
792 topNInfo.clear();
793 SessionInfo sessionInfo;
794 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
795 sessionInfo.abilityName_ = "GetMainWindowInfos";
796 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
797 ASSERT_NE(nullptr, sceneSession);
798 ASSERT_NE(nullptr, sceneSession->property_);
799 sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
800 sceneSession->isVisible_ = true;
801 sceneSession->state_ = SessionState::STATE_FOREGROUND;
802 ASSERT_NE(nullptr, ssm_);
803 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
804 auto ret = ssm_->GetMainWindowInfos(topNum, topNInfo);
805 EXPECT_EQ(ret, WMError::WM_OK);
806 sceneSession->isVisible_ = false;
807 ret = ssm_->GetMainWindowInfos(topNum, topNInfo);
808 EXPECT_EQ(ret, WMError::WM_OK);
809 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
810 ret = ssm_->GetMainWindowInfos(topNum, topNInfo);
811 EXPECT_EQ(ret, WMError::WM_OK);
812 sceneSession->isVisible_ = true;
813 ret = ssm_->GetMainWindowInfos(topNum, topNInfo);
814 EXPECT_EQ(ret, WMError::WM_OK);
815 }
816
817 /**
818 * @tc.name: WindowLayerInfoChangeCallback
819 * @tc.desc: WindowLayerInfoChangeCallback
820 * @tc.type: FUNC
821 */
822 HWTEST_F(SceneSessionManagerTest7, WindowLayerInfoChangeCallback, Function | SmallTest | Level3)
823 {
824 std::shared_ptr<RSOcclusionData> occlusiontionData = nullptr;
825 ASSERT_NE(nullptr, ssm_);
826 ssm_->WindowLayerInfoChangeCallback(occlusiontionData);
827 VisibleData visibleData;
828 visibleData.push_back(std::make_pair(0, WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE));
829 visibleData.push_back(std::make_pair(1, WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE));
830 visibleData.push_back(std::make_pair(2, WINDOW_LAYER_INFO_TYPE::INVISIBLE));
831 visibleData.push_back(std::make_pair(3, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_DYNAMIC_STATUS));
832 visibleData.push_back(std::make_pair(4, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_STATIC_STATUS));
833 visibleData.push_back(std::make_pair(5, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_UNKNOWN_TYPE));
834 occlusiontionData = std::make_shared<RSOcclusionData>(visibleData);
835 ASSERT_NE(nullptr, occlusiontionData);
836 ssm_->WindowLayerInfoChangeCallback(occlusiontionData);
837 }
838
839 /**
840 * @tc.name: NotifySessionMovedToFront
841 * @tc.desc: NotifySessionMovedToFront
842 * @tc.type: FUNC
843 */
844 HWTEST_F(SceneSessionManagerTest7, NotifySessionMovedToFront, Function | SmallTest | Level3)
845 {
846 int32_t persistentId = 1;
847 SessionInfo sessionInfo;
848 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
849 sessionInfo.abilityName_ = "GetMainWindowInfos";
850 sessionInfo.isSystem_ = false;
851 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
852 ASSERT_NE(nullptr, sceneSession);
853 ASSERT_NE(nullptr, ssm_);
854 ssm_->listenerController_ = std::make_shared<SessionListenerController>();
855 ASSERT_NE(nullptr, ssm_->listenerController_);
856 sceneSession->sessionInfo_.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
857 ASSERT_NE(nullptr, sceneSession->sessionInfo_.abilityInfo);
858 sceneSession->sessionInfo_.abilityInfo->excludeFromMissions = false;
859 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
860 ssm_->NotifySessionMovedToFront(persistentId);
861 sceneSession->sessionInfo_.abilityInfo->excludeFromMissions = true;
862 ssm_->NotifySessionMovedToFront(persistentId);
863 sceneSession->sessionInfo_.abilityInfo = nullptr;
864 ssm_->NotifySessionMovedToFront(persistentId);
865 sceneSession->sessionInfo_.isSystem_ = true;
866 ssm_->NotifySessionMovedToFront(persistentId);
867 ssm_->listenerController_ = nullptr;
868 ssm_->NotifySessionMovedToFront(persistentId);
869 }
870
871 /**
872 * @tc.name: ProcessVirtualPixelRatioChange02
873 * @tc.desc: ProcessVirtualPixelRatioChange
874 * @tc.type: FUNC
875 */
876 HWTEST_F(SceneSessionManagerTest7, ProcessVirtualPixelRatioChange02, Function | SmallTest | Level3)
877 {
878 DisplayId defaultDisplayId = 0;
879 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
880 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
881 DisplayStateChangeType type = DisplayStateChangeType::BEFORE_SUSPEND;
882 ASSERT_NE(nullptr, displayInfo);
883 SessionInfo sessionInfo;
884 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
885 sessionInfo.abilityName_ = "ProcessVirtualPixelRatioChange02";
886 sessionInfo.isSystem_ = true;
887 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
888 ASSERT_NE(nullptr, sceneSession);
889 ASSERT_NE(nullptr, ssm_);
890 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
891 sptr<SceneSession> sceneSession1 = nullptr;
892 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
893 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
894 }
895
896 /**
897 * @tc.name: ProcessVirtualPixelRatioChange03
898 * @tc.desc: ProcessVirtualPixelRatioChange
899 * @tc.type: FUNC
900 */
901 HWTEST_F(SceneSessionManagerTest7, ProcessVirtualPixelRatioChange03, Function | SmallTest | Level3)
902 {
903 DisplayId defaultDisplayId = 0;
904 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
905 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
906 DisplayStateChangeType type = DisplayStateChangeType::BEFORE_SUSPEND;
907 ASSERT_NE(nullptr, displayInfo);
908 SessionInfo sessionInfo;
909 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
910 sessionInfo.abilityName_ = "ProcessVirtualPixelRatioChange03";
911 sessionInfo.isSystem_ = false;
912 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
913 ASSERT_NE(nullptr, sceneSession);
914 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
915 ASSERT_NE(nullptr, ssm_);
916 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
917 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
918 ASSERT_NE(nullptr, sceneSession1);
919 sceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
920 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
921 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
922 ASSERT_NE(nullptr, sceneSession2);
923 sceneSession2->SetSessionState(SessionState::STATE_INACTIVE);
924 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession2));
925 ssm_->ProcessVirtualPixelRatioChange(defaultDisplayId, displayInfo, displayInfoMap, type);
926 }
927
928 /**
929 * @tc.name: ProcessBackEvent01
930 * @tc.desc: ProcessBackEvent
931 * @tc.type: FUNC
932 */
933 HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent01, Function | SmallTest | Level3)
934 {
935 SessionInfo sessionInfo;
936 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
937 sessionInfo.abilityName_ = "ProcessBackEvent01";
938 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
939 ASSERT_NE(nullptr, sceneSession);
940 ASSERT_NE(nullptr, ssm_);
941 ssm_->focusedSessionId_ = 1;
942 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
943 ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
944 auto ret = ssm_->ProcessBackEvent();
945 EXPECT_EQ(ret, WSError::WS_OK);
946 }
947
948 /**
949 * @tc.name: ProcessBackEvent02
950 * @tc.desc: ProcessBackEvent
951 * @tc.type: FUNC
952 */
953 HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent02, Function | SmallTest | Level3)
954 {
955 SessionInfo sessionInfo;
956 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
957 sessionInfo.abilityName_ = "ProcessBackEvent02";
958 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
959 ASSERT_NE(nullptr, sceneSession);
960 sceneSession->sessionInfo_.isSystem_ = true;
961 ASSERT_NE(nullptr, ssm_);
962 ssm_->focusedSessionId_ = 1;
963 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
964 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
965 ssm_->rootSceneProcessBackEventFunc_ = nullptr;
966 auto ret = ssm_->ProcessBackEvent();
967 EXPECT_EQ(ret, WSError::WS_OK);
968 }
969
970 /**
971 * @tc.name: ProcessBackEvent03
972 * @tc.desc: ProcessBackEvent
973 * @tc.type: FUNC
974 */
975 HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent03, Function | SmallTest | Level3)
976 {
977 SessionInfo sessionInfo;
978 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
979 sessionInfo.abilityName_ = "ProcessBackEvent03";
980 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
981 ASSERT_NE(nullptr, sceneSession);
982 sceneSession->sessionInfo_.isSystem_ = true;
983 ASSERT_NE(nullptr, ssm_);
984 ssm_->focusedSessionId_ = 1;
985 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
986 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
__anon3b3891530602()987 RootSceneProcessBackEventFunc func = [](){};
988 ssm_->rootSceneProcessBackEventFunc_ = func;
989 ASSERT_NE(nullptr, ssm_->rootSceneProcessBackEventFunc_);
990 auto ret = ssm_->ProcessBackEvent();
991 EXPECT_EQ(ret, WSError::WS_OK);
992 }
993
994 /**
995 * @tc.name: ProcessBackEvent02
996 * @tc.desc: ProcessBackEvent
997 * @tc.type: FUNC
998 */
999 HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent04, Function | SmallTest | Level3)
1000 {
1001 SessionInfo sessionInfo;
1002 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1003 sessionInfo.abilityName_ = "ProcessBackEvent04";
1004 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1005 ASSERT_NE(nullptr, sceneSession);
1006 sceneSession->sessionInfo_.isSystem_ = false;
1007 ASSERT_NE(nullptr, ssm_);
1008 ssm_->focusedSessionId_ = 1;
1009 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1010 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
1011 ssm_->rootSceneProcessBackEventFunc_ = nullptr;
1012 auto ret = ssm_->ProcessBackEvent();
1013 EXPECT_EQ(ret, WSError::WS_OK);
1014 }
1015
1016 /**
1017 * @tc.name: ProcessBackEvent05
1018 * @tc.desc: ProcessBackEvent
1019 * @tc.type: FUNC
1020 */
1021 HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent05, Function | SmallTest | Level3)
1022 {
1023 SessionInfo sessionInfo;
1024 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1025 sessionInfo.abilityName_ = "ProcessBackEvent03";
1026 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1027 ASSERT_NE(nullptr, sceneSession);
1028 sceneSession->sessionInfo_.isSystem_ = false;
1029 ASSERT_NE(nullptr, ssm_);
1030 ssm_->focusedSessionId_ = 1;
1031 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1032 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
__anon3b3891530702()1033 RootSceneProcessBackEventFunc func = [](){};
1034 ssm_->rootSceneProcessBackEventFunc_ = func;
1035 ASSERT_NE(nullptr, ssm_->rootSceneProcessBackEventFunc_);
1036 auto ret = ssm_->ProcessBackEvent();
1037 EXPECT_EQ(ret, WSError::WS_OK);
1038 }
1039
1040 /**
1041 * @tc.name: GetWindowVisibilityChangeInfo
1042 * @tc.desc: GetWindowVisibilityChangeInfo
1043 * @tc.type: FUNC
1044 */
1045 HWTEST_F(SceneSessionManagerTest7, GetWindowVisibilityChangeInfo, Function | SmallTest | Level3)
1046 {
1047 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
1048 currVisibleData.emplace_back(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1049 currVisibleData.emplace_back(4, WindowVisibilityState::WINDOW_LAYER_STATE_MAX);
1050 currVisibleData.emplace_back(5, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1051 currVisibleData.emplace_back(7, WindowVisibilityState::WINDOW_LAYER_STATE_MAX);
1052 currVisibleData.emplace_back(9, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1053 ASSERT_NE(nullptr, ssm_);
1054 ssm_->lastVisibleData_.emplace_back(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1055 ssm_->lastVisibleData_.emplace_back(4, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION);
1056 ssm_->lastVisibleData_.emplace_back(5, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1057 ssm_->lastVisibleData_.emplace_back(6, WindowVisibilityState::WINDOW_LAYER_STATE_MAX);
1058 ssm_->GetWindowVisibilityChangeInfo(currVisibleData);
1059 }
1060
1061 /**
1062 * @tc.name: UpdateAvoidArea
1063 * @tc.desc: UpdateAvoidArea
1064 * @tc.type: FUNC
1065 */
1066 HWTEST_F(SceneSessionManagerTest7, UpdateAvoidArea, Function | SmallTest | Level3)
1067 {
1068 int32_t persistentId = 0;
1069 ASSERT_NE(nullptr, ssm_);
1070 ssm_->sceneSessionMap_.clear();
1071 ssm_->UpdateAvoidArea(persistentId);
1072 }
1073
1074 /**
1075 * @tc.name: UpdateAvoidArea01
1076 * @tc.desc: UpdateAvoidArea
1077 * @tc.type: FUNC
1078 */
1079 HWTEST_F(SceneSessionManagerTest7, UpdateAvoidArea01, Function | SmallTest | Level3)
1080 {
1081 int32_t persistentId = 0;
1082 ASSERT_NE(nullptr, ssm_);
1083 ssm_->sceneSessionMap_.clear();
1084 ssm_->UpdateAvoidArea(persistentId);
1085 SessionInfo sessionInfo;
1086 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1087 sessionInfo.abilityName_ = "UpdateAvoidArea01";
1088 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1089 ASSERT_NE(nullptr, sceneSession);
1090 ASSERT_NE(nullptr, sceneSession->property_);
1091 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
1092 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1093 ssm_->UpdateAvoidArea(persistentId);
1094 }
1095
1096 /**
1097 * @tc.name: UpdateAvoidArea02
1098 * @tc.desc: UpdateAvoidArea
1099 * @tc.type: FUNC
1100 */
1101 HWTEST_F(SceneSessionManagerTest7, UpdateAvoidArea02, Function | SmallTest | Level3)
1102 {
1103 int32_t persistentId = 0;
1104 ASSERT_NE(nullptr, ssm_);
1105 ssm_->sceneSessionMap_.clear();
1106 ssm_->UpdateAvoidArea(persistentId);
1107 SessionInfo sessionInfo;
1108 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1109 sessionInfo.abilityName_ = "UpdateAvoidArea02";
1110 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1111 ASSERT_NE(nullptr, sceneSession);
1112 ASSERT_NE(nullptr, sceneSession->property_);
1113 sceneSession->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
1114 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1115 ssm_->UpdateAvoidArea(persistentId);
1116 }
1117
1118 /**
1119 * @tc.name: NotifySessionMovedToFront01
1120 * @tc.desc: NotifySessionMovedToFront
1121 * @tc.type: FUNC
1122 */
1123 HWTEST_F(SceneSessionManagerTest7, NotifySessionMovedToFront01, Function | SmallTest | Level3)
1124 {
1125 int32_t persistentId = 1;
1126 SessionInfo sessionInfo;
1127 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1128 sessionInfo.abilityName_ = "NotifySessionMovedToFront01";
1129 sessionInfo.isSystem_ = false;
1130 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1131 ASSERT_NE(nullptr, sceneSession);
1132 ASSERT_NE(nullptr, ssm_);
1133 ssm_->listenerController_ = std::make_shared<SessionListenerController>();
1134 ASSERT_NE(nullptr, ssm_->listenerController_);
1135 sceneSession->sessionInfo_.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1136 ASSERT_NE(nullptr, sceneSession->sessionInfo_.abilityInfo);
1137 sceneSession->sessionInfo_.abilityInfo->excludeFromMissions = true;
1138 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1139 ssm_->NotifySessionMovedToFront(persistentId);
1140 }
1141
1142 /**
1143 * @tc.name: NotifySessionMovedToFront02
1144 * @tc.desc: NotifySessionMovedToFront
1145 * @tc.type: FUNC
1146 */
1147 HWTEST_F(SceneSessionManagerTest7, NotifySessionMovedToFront02, Function | SmallTest | Level3)
1148 {
1149 int32_t persistentId = 1;
1150 SessionInfo sessionInfo;
1151 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1152 sessionInfo.abilityName_ = "NotifySessionMovedToFront02";
1153 sessionInfo.isSystem_ = false;
1154 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1155 ASSERT_NE(nullptr, sceneSession);
1156 ASSERT_NE(nullptr, ssm_);
1157 ssm_->listenerController_ = std::make_shared<SessionListenerController>();
1158 ASSERT_NE(nullptr, ssm_->listenerController_);
1159 sceneSession->sessionInfo_.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1160 ASSERT_NE(nullptr, sceneSession->sessionInfo_.abilityInfo);
1161 sceneSession->sessionInfo_.abilityInfo->excludeFromMissions = false;
1162 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1163 ssm_->NotifySessionMovedToFront(persistentId);
1164 }
1165
1166 /**
1167 * @tc.name: NotifySessionMovedToFront03
1168 * @tc.desc: NotifySessionMovedToFront
1169 * @tc.type: FUNC
1170 */
1171 HWTEST_F(SceneSessionManagerTest7, NotifySessionMovedToFront03, Function | SmallTest | Level3)
1172 {
1173 int32_t persistentId = 1;
1174 SessionInfo sessionInfo;
1175 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1176 sessionInfo.abilityName_ = "NotifySessionMovedToFront03";
1177 sessionInfo.isSystem_ = false;
1178 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1179 ASSERT_NE(nullptr, sceneSession);
1180 ASSERT_NE(nullptr, ssm_);
1181 ssm_->listenerController_ = std::make_shared<SessionListenerController>();
1182 ASSERT_NE(nullptr, ssm_->listenerController_);
1183 sceneSession->sessionInfo_.abilityInfo = nullptr;
1184 ssm_->NotifySessionMovedToFront(persistentId);
1185 }
1186
1187 /**
1188 * @tc.name: NotifySessionMovedToFront04
1189 * @tc.desc: NotifySessionMovedToFront
1190 * @tc.type: FUNC
1191 */
1192 HWTEST_F(SceneSessionManagerTest7, NotifySessionMovedToFront04, Function | SmallTest | Level3)
1193 {
1194 int32_t persistentId = 1;
1195 SessionInfo sessionInfo;
1196 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1197 sessionInfo.abilityName_ = "NotifySessionMovedToFront04";
1198 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1199 ASSERT_NE(nullptr, sceneSession);
1200 ASSERT_NE(nullptr, ssm_);
1201 ssm_->listenerController_ = std::make_shared<SessionListenerController>();
1202 ASSERT_NE(nullptr, ssm_->listenerController_);
1203 sceneSession->sessionInfo_.isSystem_ = true;
1204 ssm_->NotifySessionMovedToFront(persistentId);
1205 }
1206
1207 /**
1208 * @tc.name: NotifySessionMovedToFront05
1209 * @tc.desc: NotifySessionMovedToFront
1210 * @tc.type: FUNC
1211 */
1212 HWTEST_F(SceneSessionManagerTest7, NotifySessionMovedToFront05, Function | SmallTest | Level3)
1213 {
1214 int32_t persistentId = 1;
1215 SessionInfo sessionInfo;
1216 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1217 sessionInfo.abilityName_ = "NotifySessionMovedToFront05";
1218 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1219 ASSERT_NE(nullptr, sceneSession);
1220 ASSERT_NE(nullptr, ssm_);
1221 ssm_->listenerController_ = nullptr;
1222 ssm_->NotifySessionMovedToFront(persistentId);
1223 }
1224
1225 /**
1226 * @tc.name: UpdateNormalSessionAvoidArea02
1227 * @tc.desc: UpdateNormalSessionAvoidArea
1228 * @tc.type: FUNC
1229 */
1230 HWTEST_F(SceneSessionManagerTest7, UpdateNormalSessionAvoidArea02, Function | SmallTest | Level3)
1231 {
1232 SessionInfo sessionInfo;
1233 sessionInfo.bundleName_ = "SceneSessionManagerTest7";
1234 sessionInfo.abilityName_ = "UpdateNormalSessionAvoidArea02";
1235 sessionInfo.isSystem_ = true;
1236 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1237 ASSERT_NE(nullptr, sceneSession);
1238 sceneSession->isVisible_ = true;
1239 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1240 sceneSession->winRect_ = { 1, 1, 1, 1 };
1241 int32_t persistentId = 1;
1242 bool needUpdate = true;
1243 ASSERT_NE(nullptr, ssm_);
1244 ssm_->avoidAreaListenerSessionSet_.clear();
1245 ssm_->avoidAreaListenerSessionSet_.insert(persistentId);
1246 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
1247 }
1248 }
1249 } // namespace Rosen
1250 } // namespace OHOS