1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <regex>
18 #include <bundle_mgr_interface.h>
19 #include <bundlemgr/launcher_service.h>
20 #include "interfaces/include/ws_common.h"
21 #include "screen_fold_data.h"
22 #include "session_manager/include/scene_session_manager.h"
23 #include "session_info.h"
24 #include "session/host/include/scene_session.h"
25 #include "session/host/include/main_session.h"
26 #include "window_manager_agent.h"
27 #include "session_manager.h"
28 #include "zidl/window_manager_agent_interface.h"
29 #include "mock/mock_session_stage.h"
30 #include "mock/mock_window_event_channel.h"
31 #include "application_info.h"
32 #include "context.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36
37 namespace OHOS {
38 namespace Rosen {
39 namespace {
40 const std::string EMPTY_DEVICE_ID = "";
41 }
42 class SceneSessionManagerTest : public testing::Test {
43 public:
44 static void SetUpTestCase();
45 static void TearDownTestCase();
46 void SetUp() override;
47 void TearDown() override;
48 static void SetVisibleForAccessibility(sptr<SceneSession>& sceneSession);
49 int32_t GetTaskCount(sptr<SceneSession>& session);
50 static bool gestureNavigationEnabled_;
51 static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
52 static sptr<SceneSessionManager> ssm_;
53 private:
54 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
55 };
56
57 sptr<SceneSessionManager> SceneSessionManagerTest::ssm_ = nullptr;
58
59 bool SceneSessionManagerTest::gestureNavigationEnabled_ = true;
60 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest::callbackFunc_ = [](bool enable,
__anon6b601e040202(bool enable, const std::string& bundleName, GestureBackType type) 61 const std::string& bundleName, GestureBackType type) {
62 gestureNavigationEnabled_ = enable;
63 };
64
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)65 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
66 {
67 }
68
ProcessStatusBarEnabledChangeFuncTest(bool enable)69 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
70 {
71 }
72
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)73 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
74 {
75 }
76
SetUpTestCase()77 void SceneSessionManagerTest::SetUpTestCase()
78 {
79 ssm_ = &SceneSessionManager::GetInstance();
80 }
81
TearDownTestCase()82 void SceneSessionManagerTest::TearDownTestCase()
83 {
84 ssm_ = nullptr;
85 }
86
SetUp()87 void SceneSessionManagerTest::SetUp()
88 {
89 ssm_->sceneSessionMap_.clear();
90 }
91
TearDown()92 void SceneSessionManagerTest::TearDown()
93 {
94 usleep(WAIT_SYNC_IN_NS);
95 ssm_->sceneSessionMap_.clear();
96 }
97
SetVisibleForAccessibility(sptr<SceneSession> & sceneSession)98 void SceneSessionManagerTest::SetVisibleForAccessibility(sptr<SceneSession>& sceneSession)
99 {
100 sceneSession->SetTouchable(true);
101 sceneSession->forceTouchable_ = true;
102 sceneSession->systemTouchable_ = true;
103 sceneSession->state_ = SessionState::STATE_FOREGROUND;
104 sceneSession->foregroundInteractiveStatus_.store(true);
105 sceneSession->isVisible_ = true;
106 }
107
GetTaskCount(sptr<SceneSession> & session)108 int32_t SceneSessionManagerTest::GetTaskCount(sptr<SceneSession>& session)
109 {
110 std::string dumpInfo = session->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
111 std::regex pattern("\\d+");
112 std::smatch matches;
113 int32_t taskNum = 0;
114 while (std::regex_search(dumpInfo, matches, pattern)) {
115 taskNum += std::stoi(matches.str());
116 dumpInfo = matches.suffix();
117 }
118 return taskNum;
119 }
120
121 namespace {
122 /**
123 * @tc.name: SetBrightness
124 * @tc.desc: ScreenSesionManager set session brightness
125 * @tc.type: FUNC
126 */
127 HWTEST_F(SceneSessionManagerTest, SetBrightness, Function | SmallTest | Level3)
128 {
129 SessionInfo info;
130 info.abilityName_ = "SetBrightness";
131 info.bundleName_ = "SetBrightness1";
132 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
133 ASSERT_NE(nullptr, sceneSession);
134 WSError result = ssm_->SetBrightness(sceneSession, 0.5);
135 ASSERT_EQ(result, WSError::WS_OK);
136 }
137
138 /**
139 * @tc.name: GerPrivacyBundleListTwoWindow
140 * @tc.desc: get privacy bundle list when two windows exist.
141 * @tc.type: FUNC
142 */
143 HWTEST_F(SceneSessionManagerTest, GerPrivacyBundleListTwoWindow, Function | SmallTest | Level3)
144 {
145 SessionInfo sessionInfoFirst;
146 sessionInfoFirst.bundleName_ = "privacy.test.first";
147 sessionInfoFirst.abilityName_ = "privacyAbilityName";
148 sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfoFirst, nullptr);
149 ASSERT_NE(sceneSessionFirst, nullptr);
150 ssm_->sceneSessionMap_.insert({sceneSessionFirst->GetPersistentId(), sceneSessionFirst});
151
152 SessionInfo sessionInfoSecond;
153 sessionInfoSecond.bundleName_ = "privacy.test.second";
154 sessionInfoSecond.abilityName_ = "privacyAbilityName";
155 sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfoSecond, nullptr);
156 ASSERT_NE(sceneSessionSecond, nullptr);
157 ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond});
158
159 sceneSessionFirst->GetSessionProperty()->displayId_ = 0;
160 sceneSessionFirst->GetSessionProperty()->isPrivacyMode_ = true;
161 sceneSessionFirst->state_ = SessionState::STATE_FOREGROUND;
162
163 sceneSessionSecond->GetSessionProperty()->displayId_ = 0;
164 sceneSessionSecond->GetSessionProperty()->isPrivacyMode_ = true;
165 sceneSessionSecond->state_ = SessionState::STATE_FOREGROUND;
166
167 std::unordered_set<std::string> privacyBundleList;
168 ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
169 EXPECT_EQ(privacyBundleList.size(), 2);
170
171 sceneSessionSecond->GetSessionProperty()->displayId_ = 1;
172 privacyBundleList.clear();
173 ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
174 EXPECT_EQ(privacyBundleList.size(), 1);
175
176 privacyBundleList.clear();
177 ssm_->GetSceneSessionPrivacyModeBundles(1, privacyBundleList);
178 EXPECT_EQ(privacyBundleList.size(), 1);
179 }
180
181 /**
182 * @tc.name: SetWindowFlags
183 * @tc.desc: SceneSesionManager set window flags
184 * @tc.type: FUNC
185 */
186 HWTEST_F(SceneSessionManagerTest, SetWindowFlags, Function | SmallTest | Level3)
187 {
188 SessionInfo info;
189 info.bundleName_ = "bundleName";
190 sptr<WindowSessionProperty> property = new WindowSessionProperty();
191 uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
192 property->SetWindowFlags(flags);
193 sptr<SceneSession> scensession = nullptr;
194 WSError result01 = ssm_->SetWindowFlags(scensession, property);
195 EXPECT_EQ(result01, WSError::WS_ERROR_NULLPTR);
196 scensession = new (std::nothrow) SceneSession(info, nullptr);
197 WSError result02 = ssm_->SetWindowFlags(scensession, property);
198 EXPECT_EQ(result02, WSError::WS_ERROR_NOT_SYSTEM_APP);
199 property->SetSystemCalling(true);
200 WSError result03 = ssm_->SetWindowFlags(scensession, property);
201 ASSERT_EQ(result03, WSError::WS_OK);
202 scensession = nullptr;
203 delete scensession;
204 }
205
206 /**
207 * @tc.name: NotifyWaterMarkFlagChangedResult
208 * @tc.desc: SceneSesionManager notify water mark flag changed result
209 * @tc.type: FUNC
210 */
211 HWTEST_F(SceneSessionManagerTest, NotifyWaterMarkFlagChangedResult, Function | SmallTest | Level3)
212 {
213 int32_t persistentId = 10086;
214 ssm_->NotifyCompleteFirstFrameDrawing(persistentId);
215 bool hasWaterMark = true;
216 AppExecFwk::AbilityInfo abilityInfo;
217 WSError result01 = ssm_->NotifyWaterMarkFlagChangedResult(hasWaterMark);
218 EXPECT_EQ(result01, WSError::WS_OK);
219 ssm_->CheckAndNotifyWaterMarkChangedResult();
220 ssm_->ProcessPreload(abilityInfo);
221 }
222
223 /**
224 * @tc.name: IsValidSessionIds
225 * @tc.desc: SceneSesionManager is valid session id
226 * @tc.type: FUNC
227 */
228 HWTEST_F(SceneSessionManagerTest, IsValidSessionIds, Function | SmallTest | Level3)
229 {
230 std::vector<int32_t> sessionIds = {0, 1, 2, 3, 4, 5, 24, 10086};
231 std::vector<bool> results = {};
232 WSError result = ssm_->IsValidSessionIds(sessionIds, results);
233 EXPECT_EQ(result, WSError::WS_OK);
234 }
235
236 /**
237 * @tc.name: UnRegisterSessionListener
238 * @tc.desc: SceneSesionManager un register session listener
239 * @tc.type: FUNC
240 */
241 HWTEST_F(SceneSessionManagerTest, UnRegisterSessionListener, Function | SmallTest | Level3)
242 {
243 OHOS::MessageParcel data;
244 sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
245 WSError result = ssm_->UnRegisterSessionListener(listener);
246 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
247 }
248
249 /**
250 * @tc.name: GetSessionInfos
251 * @tc.desc: SceneSesionManager get session infos
252 * @tc.type: FUNC
253 */
254 HWTEST_F(SceneSessionManagerTest, GetSessionInfos, Function | SmallTest | Level3)
255 {
256 std::string deviceId = "1245";
257 int32_t numMax = 1024;
258 AAFwk::MissionInfo infoFrist;
259 infoFrist.label = "fristBundleName";
260 AAFwk::MissionInfo infoSecond;
261 infoSecond.label = "secondBundleName";
262 std::vector<SessionInfoBean> sessionInfos = {infoFrist, infoSecond};
263 WSError result = ssm_->GetSessionInfos(deviceId, numMax, sessionInfos);
264 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
265 int32_t persistentId = 24;
266 SessionInfoBean sessionInfo;
267 int result01 = ssm_->GetRemoteSessionInfo(deviceId, persistentId, sessionInfo);
268 ASSERT_NE(result01, ERR_OK);
269 }
270
271 /**
272 * @tc.name: GetUnreliableWindowInfo
273 * @tc.desc: SceneSesionManager get unreliable window info
274 * @tc.type: FUNC
275 */
276 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo, Function | SmallTest | Level3)
277 {
278 int32_t windowId = 0;
279 std::vector<sptr<UnreliableWindowInfo>> infos;
280 WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
281 EXPECT_EQ(WMError::WM_OK, result);
282 }
283
284 /**
285 * @tc.name: GetMainWindowStatesByPid
286 * @tc.desc: SceneSesionManager get main window states
287 * @tc.type: FUNC
288 */
289 HWTEST_F(SceneSessionManagerTest, GetMainWindowStatesByPid, Function | SmallTest | Level3)
290 {
291 int32_t pid = 100;
292 std::vector<MainWindowState> windowStates;
293 WSError result = ssm_->GetMainWindowStatesByPid(pid, windowStates);
294 EXPECT_EQ(result, WSError::WS_OK);
295 }
296
297 /**
298 * @tc.name: CheckIsRemote
299 * @tc.desc: SceneSesionManager check is remote
300 * @tc.type: FUNC
301 */
302 HWTEST_F(SceneSessionManagerTest, CheckIsRemote, Function | SmallTest | Level3)
303 {
304 std::string deviceId;
305 bool result = ssm_->CheckIsRemote(deviceId);
306 EXPECT_FALSE(result);
307 deviceId.assign("deviceId");
308 result = ssm_->CheckIsRemote(deviceId);
309 EXPECT_FALSE(result);
310 }
311
312 /**
313 * @tc.name: AnonymizeDeviceId
314 * @tc.desc: SceneSesionManager anonymize deviceId
315 * @tc.type: FUNC
316 */
317 HWTEST_F(SceneSessionManagerTest, AnonymizeDeviceId, Function | SmallTest | Level3)
318 {
319 std::string deviceId;
320 std::string result(ssm_->AnonymizeDeviceId(deviceId));
321 EXPECT_EQ(result, EMPTY_DEVICE_ID);
322 deviceId.assign("100964857");
323 std::string result01 = "100964******";
324 ASSERT_EQ(ssm_->AnonymizeDeviceId(deviceId), result01);
325 }
326
327 /**
328 * @tc.name: TerminateSessionNew
329 * @tc.desc: SceneSesionManager terminate session new
330 * @tc.type: FUNC
331 */
332 HWTEST_F(SceneSessionManagerTest, TerminateSessionNew, Function | SmallTest | Level3)
333 {
334 sptr<AAFwk::SessionInfo> info = nullptr;
335 bool needStartCaller = true;
336 WSError result01 = ssm_->TerminateSessionNew(info, needStartCaller);
337 EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, result01);
338 info = new (std::nothrow) AAFwk::SessionInfo();
339 WSError result02 = ssm_->TerminateSessionNew(info, needStartCaller);
340 EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, result02);
341 }
342
343 /**
344 * @tc.name: RegisterSessionListener01
345 * @tc.desc: SceneSesionManager register session listener
346 * @tc.type: FUNC
347 */
348 HWTEST_F(SceneSessionManagerTest, RegisterSessionListener01, Function | SmallTest | Level3)
349 {
350 OHOS::MessageParcel data;
351 sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
352 WSError result = ssm_->RegisterSessionListener(listener);
353 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
354 }
355
356 /**
357 * @tc.name: ClearDisplayStatusBarTemporarilyFlags
358 * @tc.desc: check ClearDisplayStatusBarTemporarilyFlags
359 * @tc.type: FUNC
360 */
361 HWTEST_F(SceneSessionManagerTest, ClearDisplayStatusBarTemporarilyFlags, Function | SmallTest | Level3)
362 {
363 SessionInfo sessionInfo;
364 sessionInfo.bundleName_ = "ClearDisplayStatusBarTemporarilyFlags";
365 sessionInfo.abilityName_ = "ClearDisplayStatusBarTemporarilyFlags";
366 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
367 sptr<SceneSession> sceneSession = ssm_->RequestSceneSession(sessionInfo, nullptr);
368 ASSERT_NE(nullptr, sceneSession);
369 sceneSession->SetIsDisplayStatusBarTemporarily(true);
370 ASSERT_EQ(true, sceneSession->GetIsDisplayStatusBarTemporarily());
371 ssm_->ClearDisplayStatusBarTemporarilyFlags();
372 ASSERT_EQ(true, sceneSession->GetIsDisplayStatusBarTemporarily());
373 }
374
375 /**
376 * @tc.name: RequestSceneSessionByCall
377 * @tc.desc: SceneSesionManager request scene session by call
378 * @tc.type: FUNC
379 */
380 HWTEST_F(SceneSessionManagerTest, RequestSceneSessionByCall, Function | SmallTest | Level3)
381 {
382 sptr<SceneSession> scensession = nullptr;
383 WSError result01 = ssm_->RequestSceneSessionByCall(nullptr);
384 EXPECT_EQ(result01, WSError::WS_OK);
385 SessionInfo info;
386 info.bundleName_ = "bundleName";
387 scensession = new (std::nothrow) SceneSession(info, nullptr);
388 WSError result02 = ssm_->RequestSceneSessionByCall(scensession);
389 ASSERT_EQ(result02, WSError::WS_OK);
390 scensession = nullptr;
391 delete scensession;
392 }
393
394 /**
395 * @tc.name: StartAbilityBySpecified
396 * @tc.desc: SceneSesionManager start ability by specified
397 * @tc.type: FUNC
398 */
399 HWTEST_F(SceneSessionManagerTest, StartAbilityBySpecified, Function | SmallTest | Level3)
400 {
401 int ret = 0;
402 SessionInfo info;
403 ssm_->StartAbilityBySpecified(info);
404
405 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
406 AAFwk::WantParams wantParams;
407 want->SetParams(wantParams);
408 info.want = want;
409 ssm_->StartAbilityBySpecified(info);
410 ASSERT_EQ(ret, 0);
411 }
412
413 /**
414 * @tc.name: FindMainWindowWithToken
415 * @tc.desc: SceneSesionManager find main window with token
416 * @tc.type: FUNC
417 */
418 HWTEST_F(SceneSessionManagerTest, FindMainWindowWithToken, Function | SmallTest | Level3)
419 {
420 sptr<IRemoteObject> targetToken = nullptr;
421 sptr<SceneSession> result = ssm_->FindMainWindowWithToken(targetToken);
422 EXPECT_EQ(result, nullptr);
423 uint64_t persistentId = 1423;
424 WSError result01 = ssm_->BindDialogSessionTarget(persistentId, targetToken);
425 EXPECT_EQ(result01, WSError::WS_ERROR_NULLPTR);
426 }
427
428 /**
429 * @tc.name: UpdateParentSessionForDialog001
430 * @tc.desc: SceneSesionManager update parent session for dialog
431 * @tc.type: FUNC
432 */
433 HWTEST_F(SceneSessionManagerTest, UpdateParentSessionForDialog001, Function | SmallTest | Level3)
434 {
435 SessionInfo dialogInfo;
436 dialogInfo.abilityName_ = "DialogWindows";
437 dialogInfo.bundleName_ = "DialogWindows";
438 SessionInfo parentInfo;
439 parentInfo.abilityName_ = "ParentWindows";
440 parentInfo.bundleName_ = "ParentWindows";
441
442 int32_t persistentId = 1005;
443 sptr<SceneSession> parentSession = new (std::nothrow) SceneSession(parentInfo, nullptr);
444 EXPECT_NE(parentSession, nullptr);
445 ssm_->sceneSessionMap_.insert({ persistentId, parentSession });
446
447 sptr<SceneSession> dialogSession = new (std::nothrow) SceneSession(dialogInfo, nullptr);
448 EXPECT_NE(dialogSession, nullptr);
449
450 sptr<WindowSessionProperty> property = new WindowSessionProperty();
451 property->SetParentPersistentId(persistentId);
452 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
453
454 WSError result = ssm_->UpdateParentSessionForDialog(dialogSession, property);
455 EXPECT_EQ(dialogSession->GetParentPersistentId(), persistentId);
456 EXPECT_NE(dialogSession->GetParentSession(), nullptr);
457 EXPECT_EQ(result, WSError::WS_OK);
458 }
459
460 /**
461 * @tc.name: MoveSessionsToBackground
462 * @tc.desc: SceneSesionManager move sessions to background
463 * @tc.type: FUNC
464 */
465 HWTEST_F(SceneSessionManagerTest, MoveSessionsToBackground, Function | SmallTest | Level3)
466 {
467 int32_t type = CollaboratorType::RESERVE_TYPE;
468 WSError result01 = ssm_->UnregisterIAbilityManagerCollaborator(type);
469 EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_PERMISSION);
470 std::vector<std::int32_t> sessionIds = {1, 2, 3, 15, 1423};
471 std::vector<int32_t> res = {1, 2, 3, 15, 1423};
472 WSError result03 = ssm_->MoveSessionsToBackground(sessionIds, res);
473 ASSERT_EQ(result03, WSError::WS_ERROR_INVALID_PERMISSION);
474 }
475
476 /**
477 * @tc.name: MoveSessionsToForeground
478 * @tc.desc: SceneSesionManager move sessions to foreground
479 * @tc.type: FUNC
480 */
481 HWTEST_F(SceneSessionManagerTest, MoveSessionsToForeground, Function | SmallTest | Level3)
482 {
483 std::vector<std::int32_t> sessionIds = {1, 2, 3, 15, 1423};
484 int32_t topSessionId = 1;
485 WSError result = ssm_->MoveSessionsToForeground(sessionIds, topSessionId);
486 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
487 }
488
489 /**
490 * @tc.name: UnlockSession
491 * @tc.desc: SceneSesionManager unlock session
492 * @tc.type: FUNC
493 */
494 HWTEST_F(SceneSessionManagerTest, UnlockSession, Function | SmallTest | Level3)
495 {
496 int32_t sessionId = 1;
497 WSError result = ssm_->UnlockSession(sessionId);
498 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
499 result = ssm_->LockSession(sessionId);
500 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
501 }
502
503 /**
504 * @tc.name: GetImmersiveState
505 * @tc.desc: test GetImmersiveState
506 * @tc.type: FUNC
507 */
508 HWTEST_F(SceneSessionManagerTest, GetImmersiveState, Function | SmallTest | Level3)
509 {
510 int ret = 0;
511 ssm_->GetImmersiveState();
512 ASSERT_EQ(ret, 0);
513 }
514
515 /**
516 * @tc.name: NotifyAINavigationBarShowStatus
517 * @tc.desc: test NotifyAINavigationBarShowStatus
518 * @tc.type: FUNC
519 */
520 HWTEST_F(SceneSessionManagerTest, NotifyAINavigationBarShowStatus, Function | SmallTest | Level3)
521 {
522 bool isVisible = false;
523 WSRect barArea = { 0, 0, 320, 240}; // width: 320, height: 240
524 uint64_t displayId = 0;
525 WSError result = ssm_->NotifyAINavigationBarShowStatus(isVisible, barArea, displayId);
526 ASSERT_EQ(result, WSError::WS_OK);
527 }
528
529 /**
530 * @tc.name: NotifyWindowExtensionVisibilityChange
531 * @tc.desc: test NotifyWindowExtensionVisibilityChange
532 * @tc.type: FUNC
533 */
534 HWTEST_F(SceneSessionManagerTest, NotifyWindowExtensionVisibilityChange, Function | SmallTest | Level3)
535 {
536 int32_t pid = getprocpid();
537 int32_t uid = getuid();
538 bool isVisible = false;
539 WSError result = ssm_->NotifyWindowExtensionVisibilityChange(pid, uid, isVisible);
540 ASSERT_EQ(result, WSError::WS_OK);
541
542 pid = INVALID_PID;
543 uid = INVALID_USER_ID;
544 result = ssm_->NotifyWindowExtensionVisibilityChange(pid, uid, isVisible);
545 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
546 }
547
548 /**
549 * @tc.name: UpdateTopmostProperty
550 * @tc.desc: test UpdateTopmostProperty
551 * @tc.type: FUNC
552 */
553 HWTEST_F(SceneSessionManagerTest, UpdateTopmostProperty, Function | SmallTest | Level3)
554 {
555 SessionInfo info;
556 info.abilityName_ = "UpdateTopmostProperty";
557 info.bundleName_ = "UpdateTopmostProperty";
558 sptr<WindowSessionProperty> property = new WindowSessionProperty();
559 property->SetTopmost(true);
560 property->SetSystemCalling(true);
561 sptr<SceneSession> scenesession = new (std::nothrow) MainSession(info, nullptr);
562 scenesession->SetSessionProperty(property);
563 WMError result = ssm_->UpdateTopmostProperty(property, scenesession);
564 ASSERT_EQ(WMError::WM_OK, result);
565 }
566
567 /**
568 * @tc.name: UpdateSessionWindowVisibilityListener
569 * @tc.desc: SceneSesionManager update window visibility listener
570 * @tc.type: FUNC
571 */
572 HWTEST_F(SceneSessionManagerTest, UpdateSessionWindowVisibilityListener, Function | SmallTest | Level3)
573 {
574 int32_t persistentId = 10086;
575 bool haveListener = true;
576 WSError result = ssm_->UpdateSessionWindowVisibilityListener(persistentId, haveListener);
577 ASSERT_EQ(result, WSError::WS_DO_NOTHING);
578 }
579
580 /**
581 * @tc.name: GetSessionSnapshotPixelMap
582 * @tc.desc: SceneSesionManager get session snapshot pixelmap
583 * @tc.type: FUNC
584 */
585 HWTEST_F(SceneSessionManagerTest, GetSessionSnapshotPixelMap, Function | SmallTest | Level3)
586 {
587 SessionInfo info;
588 info.abilityName_ = "GetPixelMap";
589 info.bundleName_ = "GetPixelMap1";
590 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
591 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
592
593 int32_t persistentId = 65535;
594 float scaleValue = 0.5f;
595 auto pixelMap = ssm_->GetSessionSnapshotPixelMap(persistentId, scaleValue);
596 EXPECT_EQ(pixelMap, nullptr);
597
598 persistentId = 1;
599 pixelMap = ssm_->GetSessionSnapshotPixelMap(persistentId, scaleValue);
600 EXPECT_EQ(pixelMap, nullptr);
601 }
602
603 /**
604 * @tc.name: GetSessionSnapshotById
605 * @tc.desc: test GetSessionSnapshotById
606 * @tc.type: FUNC
607 */
608 HWTEST_F(SceneSessionManagerTest, GetSessionSnapshotById, Function | SmallTest | Level3)
609 {
610 int32_t persistentId = -1;
611 SessionSnapshot snapshot;
612 WMError ret = ssm_->GetSessionSnapshotById(persistentId, snapshot);
613 EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret);
614 }
615
616 /**
617 * @tc.name: GetUIContentRemoteObj
618 * @tc.desc: SceneSesionManager GetUIContentRemoteObj
619 * @tc.type: FUNC
620 */
621 HWTEST_F(SceneSessionManagerTest, GetUIContentRemoteObj, Function | SmallTest | Level3)
622 {
623 sptr<IRemoteObject> remoteObj;
624 EXPECT_EQ(ssm_->GetUIContentRemoteObj(65535, remoteObj), WSError::WS_ERROR_INVALID_PERMISSION);
625 SessionInfo info;
626 info.abilityName_ = "GetUIContentRemoteObj";
627 info.bundleName_ = "GetUIContentRemoteObj";
628 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
629 ASSERT_NE(sceneSession, nullptr);
630 ssm_->sceneSessionMap_.insert({65535, sceneSession});
631 EXPECT_EQ(ssm_->GetUIContentRemoteObj(65535, remoteObj), WSError::WS_ERROR_INVALID_PERMISSION);
632 }
633
634 /**
635 * @tc.name: CalculateCombinedExtWindowFlags
636 * @tc.desc: SceneSesionManager calculate combined extension window flags
637 * @tc.type: FUNC
638 */
639 HWTEST_F(SceneSessionManagerTest, CalculateCombinedExtWindowFlags, Function | SmallTest | Level3)
640 {
641 EXPECT_EQ(ssm_->combinedExtWindowFlags_.bitData, 0);
642 ssm_->UpdateSpecialExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3));
643 ssm_->UpdateSpecialExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4));
644 ssm_->CalculateCombinedExtWindowFlags();
645 EXPECT_EQ(ssm_->combinedExtWindowFlags_.bitData, 7);
646 ssm_->extWindowFlagsMap_.clear();
647 }
648
649 /**
650 * @tc.name: UpdateSpecialExtWindowFlags
651 * @tc.desc: SceneSesionManager update special extension window flags
652 * @tc.type: FUNC
653 */
654 HWTEST_F(SceneSessionManagerTest, UpdateSpecialExtWindowFlags, Function | SmallTest | Level3)
655 {
656 int32_t persistentId = 12345;
657 EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
658 ssm_->UpdateSpecialExtWindowFlags(persistentId, 3, 3);
659 EXPECT_EQ(ssm_->extWindowFlagsMap_.size(), 1);
660 EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->first, persistentId);
661 EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->second.bitData, 3);
662 ssm_->UpdateSpecialExtWindowFlags(persistentId, 0, 3);
663 EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
664 ssm_->extWindowFlagsMap_.clear();
665 }
666
667 /**
668 * @tc.name: HideNonSecureFloatingWindows
669 * @tc.desc: SceneSesionManager hide non-secure floating windows
670 * @tc.type: FUNC
671 */
672 HWTEST_F(SceneSessionManagerTest, HideNonSecureFloatingWindows, Function | SmallTest | Level3)
673 {
674 SessionInfo info;
675 info.abilityName_ = "HideNonSecureFloatingWindows";
676 info.bundleName_ = "HideNonSecureFloatingWindows";
677
678 sptr<SceneSession> sceneSession;
679 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
680 EXPECT_NE(sceneSession, nullptr);
681 sceneSession->state_ = SessionState::STATE_FOREGROUND;
682 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
683
684 sptr<SceneSession> floatSession;
685 floatSession = new (std::nothrow) SceneSession(info, nullptr);
686 EXPECT_NE(floatSession, nullptr);
687 floatSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
688 ssm_->nonSystemFloatSceneSessionMap_.insert(std::make_pair(floatSession->GetPersistentId(), floatSession));
689
690 EXPECT_FALSE(ssm_->shouldHideNonSecureFloatingWindows_.load());
691 EXPECT_FALSE(floatSession->GetSessionProperty()->GetForceHide());
692 sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
693 ssm_->HideNonSecureFloatingWindows();
694 EXPECT_TRUE(floatSession->GetSessionProperty()->GetForceHide());
695 sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = false;
696 ssm_->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
697 ssm_->HideNonSecureFloatingWindows();
698 EXPECT_TRUE(floatSession->GetSessionProperty()->GetForceHide());
699 ssm_->shouldHideNonSecureFloatingWindows_.store(false);
700 ssm_->sceneSessionMap_.clear();
701 ssm_->nonSystemFloatSceneSessionMap_.clear();
702 }
703
704 /**
705 * @tc.name: HideNonSecureSubWindows
706 * @tc.desc: SceneSesionManager hide non-secure sub windows
707 * @tc.type: FUNC
708 */
709 HWTEST_F(SceneSessionManagerTest, HideNonSecureSubWindows, Function | SmallTest | Level3)
710 {
711 SessionInfo info;
712 info.abilityName_ = "HideNonSecureSubWindows";
713 info.bundleName_ = "HideNonSecureSubWindows";
714
715 sptr<SceneSession> sceneSession;
716 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
717 ASSERT_NE(sceneSession, nullptr);
718 sceneSession->state_ = SessionState::STATE_FOREGROUND;
719 sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
720
721 sptr<SceneSession> subSession;
722 subSession = new (std::nothrow) SceneSession(info, nullptr);
723 ASSERT_NE(subSession, nullptr);
724 ASSERT_NE(subSession->GetSessionProperty(), nullptr);
725 sceneSession->AddSubSession(subSession);
726 subSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
727 subSession->GetSessionProperty()->SetParentPersistentId(sceneSession->GetPersistentId());
728 ssm_->sceneSessionMap_.insert(std::make_pair(subSession->GetPersistentId(), subSession));
729
730 EXPECT_FALSE(subSession->GetSessionProperty()->GetForceHide());
731 sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
732 ssm_->HideNonSecureSubWindows(sceneSession);
733 EXPECT_TRUE(subSession->GetSessionProperty()->GetForceHide());
734 ssm_->sceneSessionMap_.clear();
735 }
736
737 /**
738 * @tc.name: HandleSecureSessionShouldHide
739 * @tc.desc: SceneSesionManager handle secure session should hide
740 * @tc.type: FUNC
741 */
742 HWTEST_F(SceneSessionManagerTest, HandleSecureSessionShouldHide, Function | SmallTest | Level3)
743 {
744 SessionInfo info;
745 info.abilityName_ = "HandleSecureSessionShouldHide";
746 info.bundleName_ = "HandleSecureSessionShouldHide";
747
748 sptr<SceneSession> sceneSession;
749 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
750 ASSERT_NE(sceneSession, nullptr);
751 sceneSession->state_ = SessionState::STATE_FOREGROUND;
752 sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
753
754 sptr<SceneSession> subSession;
755 subSession = new (std::nothrow) SceneSession(info, nullptr);
756 ASSERT_NE(subSession, nullptr);
757 ASSERT_NE(subSession->GetSessionProperty(), nullptr);
758 sceneSession->AddSubSession(subSession);
759 subSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
760 subSession->GetSessionProperty()->SetParentPersistentId(sceneSession->GetPersistentId());
761 ssm_->sceneSessionMap_.insert(std::make_pair(subSession->GetPersistentId(), subSession));
762
763 sptr<SceneSession> floatSession;
764 floatSession = new (std::nothrow) SceneSession(info, nullptr);
765 ASSERT_NE(floatSession, nullptr);
766 ASSERT_NE(floatSession->GetSessionProperty(), nullptr);
767 floatSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
768 ssm_->nonSystemFloatSceneSessionMap_.insert(std::make_pair(floatSession->GetPersistentId(), floatSession));
769
770 sceneSession->SetShouldHideNonSecureWindows(true);
771 auto ret = ssm_->HandleSecureSessionShouldHide(sceneSession);
772 EXPECT_EQ(ret, WSError::WS_OK);
773 EXPECT_TRUE(subSession->GetSessionProperty()->GetForceHide());
774 EXPECT_TRUE(floatSession->GetSessionProperty()->GetForceHide());
775 EXPECT_TRUE(ssm_->shouldHideNonSecureFloatingWindows_.load());
776 ssm_->sceneSessionMap_.clear();
777 ssm_->nonSystemFloatSceneSessionMap_.clear();
778 }
779
780 /**
781 * @tc.name: HandleSpecialExtWindowFlagsChange
782 * @tc.desc: SceneSesionManager handle special uiextension window flags change
783 * @tc.type: FUNC
784 */
785 HWTEST_F(SceneSessionManagerTest, HandleSpecialExtWindowFlagsChange, Function | SmallTest | Level3)
786 {
787 int32_t persistentId = 12345;
788 EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
789 ssm_->HandleSpecialExtWindowFlagsChange(persistentId, 3, 3);
790 EXPECT_EQ(ssm_->extWindowFlagsMap_.size(), 1);
791 EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->first, persistentId);
792 EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->second.bitData, 3);
793 ssm_->HandleSpecialExtWindowFlagsChange(persistentId, 0, 3);
794 EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
795 ssm_->extWindowFlagsMap_.clear();
796 }
797
798 /**
799 * @tc.name: UpdateModalExtensionRect
800 * @tc.desc: SceneSesionManager update modal extension rect
801 * @tc.type: FUNC
802 */
803 HWTEST_F(SceneSessionManagerTest, UpdateModalExtensionRect, Function | SmallTest | Level3)
804 {
805 SessionInfo info;
806 info.abilityName_ = "UpdateModalExtensionRect";
807 info.bundleName_ = "UpdateModalExtensionRect";
808 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
809 ASSERT_NE(sceneSession, nullptr);
810 Rect rect { 1, 2, 3, 4 };
811 ssm_->UpdateModalExtensionRect(nullptr, rect);
812 EXPECT_FALSE(sceneSession->HasModalUIExtension());
813 }
814
815 /**
816 * @tc.name: ProcessModalExtensionPointDown
817 * @tc.desc: SceneSesionManager process modal extension point down
818 * @tc.type: FUNC
819 */
820 HWTEST_F(SceneSessionManagerTest, ProcessModalExtensionPointDown, Function | SmallTest | Level3)
821 {
822 SessionInfo info;
823 info.abilityName_ = "ProcessModalExtensionPointDown";
824 info.bundleName_ = "ProcessModalExtensionPointDown";
825 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
826 ASSERT_NE(sceneSession, nullptr);
827
828 ssm_->ProcessModalExtensionPointDown(nullptr, 0, 0);
829 EXPECT_FALSE(sceneSession->HasModalUIExtension());
830 }
831
832 /**
833 * @tc.name: GetExtensionWindowIds
834 * @tc.desc: SceneSesionManager get extension window ids
835 * @tc.type: FUNC
836 */
837 HWTEST_F(SceneSessionManagerTest, GetExtensionWindowIds, Function | SmallTest | Level3)
838 {
839 SessionInfo info;
840 info.abilityName_ = "GetExtensionWindowIds";
841 info.bundleName_ = "GetExtensionWindowIds";
842 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
843 ASSERT_NE(sceneSession, nullptr);
844
845 int32_t persistentId = 0;
846 int32_t parentId = 0;
847 EXPECT_FALSE(ssm_->GetExtensionWindowIds(nullptr, persistentId, parentId));
848 }
849
850 /**
851 * @tc.name: AddOrRemoveSecureSession
852 * @tc.desc: SceneSesionManager hide non-secure windows by scene session
853 * @tc.type: FUNC
854 */
855 HWTEST_F(SceneSessionManagerTest, AddOrRemoveSecureSession, Function | SmallTest | Level3)
856 {
857 SessionInfo info;
858 info.abilityName_ = "AddOrRemoveSecureSession";
859 info.bundleName_ = "AddOrRemoveSecureSession1";
860
861 int32_t persistentId = 12345;
862 auto ret = ssm_->AddOrRemoveSecureSession(persistentId, true);
863 EXPECT_EQ(ret, WSError::WS_OK);
864 }
865
866 /**
867 * @tc.name: UpdateExtWindowFlags
868 * @tc.desc: SceneSesionManager update uiextension window flags
869 * @tc.type: FUNC
870 */
871 HWTEST_F(SceneSessionManagerTest, UpdateExtWindowFlags, Function | SmallTest | Level3)
872 {
873 SessionInfo info;
874 info.abilityName_ = "UpdateExtWindowFlags";
875 info.bundleName_ = "UpdateExtWindowFlags";
876
877 auto ret = ssm_->UpdateExtWindowFlags(nullptr, 7, 7);
878 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
879 }
880
881 /**
882 * @tc.name: SetScreenLocked001
883 * @tc.desc: SetScreenLocked001
884 * @tc.type: FUNC
885 */
886 HWTEST_F(SceneSessionManagerTest, SetScreenLocked001, Function | SmallTest | Level3)
887 {
888 sptr<SceneSession> sceneSession = nullptr;
889 SessionInfo info;
890 info.bundleName_ = "bundleName";
891 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
892 ASSERT_NE(nullptr, sceneSession);
893 sceneSession->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
894 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
895 DetectTaskInfo detectTaskInfo;
896 detectTaskInfo.taskState = DetectTaskState::ATTACH_TASK;
897 detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_UNDEFINED;
898 sceneSession->SetDetectTaskInfo(detectTaskInfo);
899 std::string taskName = "wms:WindowStateDetect" + std::to_string(sceneSession->persistentId_);
__anon6b601e040402()900 auto task = [](){};
901 int64_t delayTime = 3000;
902 sceneSession->handler_->PostTask(task, taskName, delayTime);
903 int32_t beforeTaskNum = GetTaskCount(sceneSession);
904 ssm_->SetScreenLocked(true);
905 ASSERT_EQ(beforeTaskNum - 1, GetTaskCount(sceneSession));
906 ASSERT_EQ(DetectTaskState::NO_TASK, sceneSession->detectTaskInfo_.taskState);
907 ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, sceneSession->detectTaskInfo_.taskWindowMode);
908 }
909
910 /**
911 * @tc.name: AccessibilityFillEmptySceneSessionListToNotifyList
912 * @tc.desc: SceneSesionManager fill empty scene session list to accessibilityList;
913 * @tc.type: FUNC
914 */
915 HWTEST_F(SceneSessionManagerTest, AccessibilityFillEmptySceneSessionListToNotifyList, Function | SmallTest | Level3)
916 {
917 std::vector<sptr<SceneSession>> sceneSessionList;
918 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
919
920 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
921 EXPECT_EQ(accessibilityInfo.size(), 0);
922 }
923
924 /**
925 * @tc.name: AccessibilityFillOneSceneSessionListToNotifyList
926 * @tc.desc: SceneSesionManager fill one sceneSession to accessibilityList;
927 * @tc.type: FUNC
928 */
929 HWTEST_F(SceneSessionManagerTest, AccessibilityFillOneSceneSessionListToNotifyList, Function | SmallTest | Level3)
930 {
931 SessionInfo sessionInfo;
932 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
933 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
934
935 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
936 ASSERT_NE(sceneSession, nullptr);
937 SetVisibleForAccessibility(sceneSession);
938 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
939
940 std::vector<sptr<SceneSession>> sceneSessionList;
941 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
942 ASSERT_EQ(sceneSessionList.size(), 1);
943
944 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
945 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
946 ASSERT_EQ(accessibilityInfo.size(), 1);
947 }
948
949 /**
950 * @tc.name: AccessibilityFillTwoSceneSessionListToNotifyList
951 * @tc.desc: SceneSesionManager fill two sceneSessions to accessibilityList;
952 * @tc.type: FUNC
953 */
954 HWTEST_F(SceneSessionManagerTest, AccessibilityFillTwoSceneSessionListToNotifyList, Function | SmallTest | Level3)
955 {
956 SessionInfo sessionInfo;
957 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
958 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
959
960 sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr);
961 ASSERT_NE(sceneSessionFirst, nullptr);
962 SetVisibleForAccessibility(sceneSessionFirst);
963
964 sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr);
965 ASSERT_NE(sceneSessionSecond, nullptr);
966 SetVisibleForAccessibility(sceneSessionSecond);
967
968 ssm_->sceneSessionMap_.insert({sceneSessionFirst->GetPersistentId(), sceneSessionFirst});
969 ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond});
970
971 std::vector<sptr<SceneSession>> sceneSessionList;
972 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
973 ASSERT_EQ(sceneSessionList.size(), 2);
974
975 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
976 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
977 ASSERT_EQ(accessibilityInfo.size(), 2);
978 }
979
980 /**
981 * @tc.name: AccessibilityFillEmptyBundleName
982 * @tc.desc: SceneSesionManager fill empty bundle name to accessibilityInfo;
983 * @tc.type: FUNC
984 */
985 HWTEST_F(SceneSessionManagerTest, AccessibilityFillEmptyBundleName, Function | SmallTest | Level3)
986 {
987 SessionInfo sessionInfo;
988 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
989
990 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
991 ASSERT_NE(sceneSession, nullptr);
992 SetVisibleForAccessibility(sceneSession);
993 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
994
995 std::vector<sptr<SceneSession>> sceneSessionList;
996 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
997 ASSERT_EQ(sceneSessionList.size(), 1);
998
999 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1000 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1001 ASSERT_EQ(accessibilityInfo.size(), 1);
1002
1003 ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, "");
1004 ASSERT_EQ(sceneSessionList.at(0)->GetSessionInfo().bundleName_, "");
1005 ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, sceneSessionList.at(0)->GetSessionInfo().bundleName_);
1006 }
1007
1008 /**
1009 * @tc.name: AccessibilityFillBundleName
1010 * @tc.desc: SceneSesionManager fill bundle name to accessibilityInfo;
1011 * @tc.type: FUNC
1012 */
1013 HWTEST_F(SceneSessionManagerTest, AccessibilityFillBundleName, Function | SmallTest | Level3)
1014 {
1015 SessionInfo sessionInfo;
1016 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1017 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1018
1019 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1020 ASSERT_NE(sceneSession, nullptr);
1021 SetVisibleForAccessibility(sceneSession);
1022 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1023
1024 std::vector<sptr<SceneSession>> sceneSessionList;
1025 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1026 ASSERT_EQ(sceneSessionList.size(), 1);
1027
1028 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1029 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1030 ASSERT_EQ(accessibilityInfo.size(), 1);
1031
1032 ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, "accessibilityNotifyTesterBundleName");
1033 ASSERT_EQ(sceneSessionList.at(0)->GetSessionInfo().bundleName_, "accessibilityNotifyTesterBundleName");
1034 ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, sceneSessionList.at(0)->GetSessionInfo().bundleName_);
1035 }
1036
1037 /**
1038 * @tc.name: AccessibilityFillFilterBundleName
1039 * @tc.desc: SceneSesionManager fill filter bundle name to accessibilityInfo;
1040 * @tc.type: FUNC
1041 */
1042 HWTEST_F(SceneSessionManagerTest, AccessibilityFillFilterBundleName, Function | SmallTest | Level3)
1043 {
1044 SessionInfo sessionInfo;
1045 sessionInfo.bundleName_ = "SCBGestureTopBar";
1046 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1047
1048 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1049 ASSERT_NE(sceneSession, nullptr);
1050 SetVisibleForAccessibility(sceneSession);
1051 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1052
1053 std::vector<sptr<SceneSession>> sceneSessionList;
1054 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1055 ASSERT_EQ(sceneSessionList.size(), 0);
1056
1057 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1058 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1059 ASSERT_EQ(accessibilityInfo.size(), 0);
1060 }
1061
1062 /**
1063 * @tc.name: AccessibilityFillEmptyHotAreas
1064 * @tc.desc: SceneSesionManager fill empty hot areas to accessibilityInfo;
1065 * @tc.type: FUNC
1066 */
1067 HWTEST_F(SceneSessionManagerTest, AccessibilityFillEmptyHotAreas, Function | SmallTest | Level3)
1068 {
1069 SessionInfo sessionInfo;
1070 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1071 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1072
1073 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1074 ASSERT_NE(sceneSession, nullptr);
1075 SetVisibleForAccessibility(sceneSession);
1076 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1077
1078 std::vector<sptr<SceneSession>> sceneSessionList;
1079 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1080
1081 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1082 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1083 ASSERT_EQ(accessibilityInfo.size(), 1);
1084
1085 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size());
1086 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 0);
1087 }
1088
1089 /**
1090 * @tc.name: AccessibilityFillOneHotAreas
1091 * @tc.desc: SceneSesionManager fill one hot areas to accessibilityInfo;
1092 * @tc.type: FUNC
1093 */
1094 HWTEST_F(SceneSessionManagerTest, AccessibilityFillOneHotAreas, Function | SmallTest | Level3)
1095 {
1096 SessionInfo sessionInfo;
1097 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1098 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1099
1100 Rect rect = {100, 200, 100, 200};
1101 std::vector<Rect> hotAreas;
1102 hotAreas.push_back(rect);
1103 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1104 ASSERT_NE(sceneSession, nullptr);
1105 sceneSession->SetTouchHotAreas(hotAreas);
1106 SetVisibleForAccessibility(sceneSession);
1107 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1108
1109 std::vector<sptr<SceneSession>> sceneSessionList;
1110 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1111
1112 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1113 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1114 ASSERT_EQ(accessibilityInfo.size(), 1);
1115
1116 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size());
1117 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 1);
1118
1119 ASSERT_EQ(rect.posX_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).posX_);
1120 ASSERT_EQ(rect.posY_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).posY_);
1121 ASSERT_EQ(rect.width_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).width_);
1122 ASSERT_EQ(rect.height_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).height_);
1123
1124 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posX_, rect.posX_);
1125 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posY_, rect.posY_);
1126 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).width_, rect.width_);
1127 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).height_, rect.height_);
1128 }
1129
1130 /**
1131 * @tc.name: AccessibilityFillTwoHotAreas
1132 * @tc.desc: SceneSesionManager fill two hot areas to accessibilityInfo;
1133 * @tc.type: FUNC
1134 */
1135 HWTEST_F(SceneSessionManagerTest, AccessibilityFillTwoHotAreas, Function | SmallTest | Level3)
1136 {
1137 SessionInfo sessionInfo;
1138 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1139 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1140
1141 sptr<WindowSessionProperty> property = new WindowSessionProperty();
1142 std::vector<Rect> hotAreas;
1143 Rect rectFitst = {100, 200, 100, 200};
1144 Rect rectSecond = {50, 50, 20, 30};
1145 hotAreas.push_back(rectFitst);
1146 hotAreas.push_back(rectSecond);
1147 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1148 ASSERT_NE(sceneSession, nullptr);
1149 sceneSession->SetTouchHotAreas(hotAreas);
1150 SetVisibleForAccessibility(sceneSession);
1151 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1152
1153 std::vector<sptr<SceneSession>> sceneSessionList;
1154 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1155
1156 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1157 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1158 ASSERT_EQ(accessibilityInfo.size(), 1);
1159
1160 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size());
1161 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 2);
1162
1163 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posX_, rectFitst.posX_);
1164 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posY_, rectFitst.posY_);
1165 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).width_, rectFitst.width_);
1166 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).height_, rectFitst.height_);
1167
1168 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).posX_, rectSecond.posX_);
1169 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).posY_, rectSecond.posY_);
1170 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).width_, rectSecond.width_);
1171 ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).height_, rectSecond.height_);
1172 }
1173
1174 /**
1175 * @tc.name: AccessibilityFilterEmptySceneSessionList
1176 * @tc.desc: SceneSesionManager filter empty scene session list;
1177 * @tc.type: FUNC
1178 */
1179 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterEmptySceneSessionList, Function | SmallTest | Level3)
1180 {
1181 std::vector<sptr<SceneSession>> sceneSessionList;
1182
1183 ssm_->FilterSceneSessionCovered(sceneSessionList);
1184 ASSERT_EQ(sceneSessionList.size(), 0);
1185 }
1186
1187 /**
1188 * @tc.name: AccessibilityFilterOneWindow
1189 * @tc.desc: SceneSesionManager filter one window;
1190 * @tc.type: FUNC
1191 */
1192 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterOneWindow, Function | SmallTest | Level3)
1193 {
1194 SessionInfo sessionInfo;
1195 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1196 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1197
1198 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1199 ASSERT_NE(sceneSession, nullptr);
1200 sceneSession->SetSessionRect({100, 100, 200, 200});
1201 SetVisibleForAccessibility(sceneSession);
1202 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1203
1204 std::vector<sptr<SceneSession>> sceneSessionList;
1205 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1206 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1207 ssm_->FilterSceneSessionCovered(sceneSessionList);
1208 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1209 ASSERT_EQ(accessibilityInfo.size(), 1);
1210 }
1211
1212 /**
1213 * @tc.name: AccessibilityFilterTwoWindowNotCovered
1214 * @tc.desc: SceneSesionManager filter two windows that not covered each other;
1215 * @tc.type: FUNC
1216 */
1217 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterTwoWindowNotCovered, Function | SmallTest | Level3)
1218 {
1219 SessionInfo sessionInfo;
1220 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1221 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1222
1223 sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr);
1224 ASSERT_NE(sceneSessionFirst, nullptr);
1225 sceneSessionFirst->SetSessionRect({0, 0, 200, 200});
1226 SetVisibleForAccessibility(sceneSessionFirst);
1227 ssm_->sceneSessionMap_.insert({sceneSessionFirst->GetPersistentId(), sceneSessionFirst});
1228
1229 sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr);
1230 ASSERT_NE(sceneSessionSecond, nullptr);
1231 sceneSessionSecond->SetSessionRect({300, 300, 200, 200});
1232 SetVisibleForAccessibility(sceneSessionSecond);
1233 ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond});
1234
1235 std::vector<sptr<SceneSession>> sceneSessionList;
1236 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1237 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1238 ssm_->FilterSceneSessionCovered(sceneSessionList);
1239 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1240 ASSERT_EQ(accessibilityInfo.size(), 2);
1241 }
1242
1243 /**
1244 * @tc.name: AccessibilityFilterTwoWindowCovered
1245 * @tc.desc: SceneSesionManager filter two windows that covered each other;
1246 * @tc.type: FUNC
1247 */
1248 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterTwoWindowCovered, Function | SmallTest | Level3)
1249 {
1250 SessionInfo sessionInfo;
1251 sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1252 sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1253
1254 sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr);
1255 ASSERT_NE(sceneSessionFirst, nullptr);
1256 sceneSessionFirst->SetSessionRect({0, 0, 200, 200});
1257 SetVisibleForAccessibility(sceneSessionFirst);
1258 sceneSessionFirst->SetZOrder(20);
1259 ssm_->sceneSessionMap_.insert({sceneSessionFirst->GetPersistentId(), sceneSessionFirst});
1260
1261 sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr);
1262 ASSERT_NE(sceneSessionSecond, nullptr);
1263 sceneSessionSecond->SetSessionRect({50, 50, 50, 50});
1264 SetVisibleForAccessibility(sceneSessionSecond);
1265 sceneSessionSecond->SetZOrder(10);
1266 ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond});
1267
1268 std::vector<sptr<SceneSession>> sceneSessionList;
1269 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1270 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1271 ssm_->FilterSceneSessionCovered(sceneSessionList);
1272 ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1273 ASSERT_EQ(accessibilityInfo.size(), 1);
1274 }
1275
1276 /**
1277 * @tc.name: TestNotifyEnterRecentTask
1278 * @tc.desc: Test whether the enterRecent_ is set correctly;
1279 * @tc.type: FUNC
1280 */
1281 HWTEST_F(SceneSessionManagerTest, TestNotifyEnterRecentTask, Function | SmallTest | Level3)
1282 {
1283 GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestNotifyEnterRecentTask start";
1284 sptr<SceneSessionManager> sceneSessionManager = new SceneSessionManager();
1285 ASSERT_NE(nullptr, sceneSessionManager);
1286
1287 ASSERT_EQ(sceneSessionManager->NotifyEnterRecentTask(true), WSError::WS_OK);
1288 ASSERT_EQ(sceneSessionManager->enterRecent_.load(), true);
1289 }
1290
1291 /**
1292 * @tc.name: GetAllWindowVisibilityInfos
1293 * @tc.desc: SceneSesionManager get all window visibility infos;
1294 * @tc.type: FUNC
1295 */
1296 HWTEST_F(SceneSessionManagerTest, GetAllWindowVisibilityInfos, Function | SmallTest | Level3)
1297 {
1298 ASSERT_NE(ssm_, nullptr);
1299 ssm_->sceneSessionMap_.clear();
1300 SessionInfo info;
1301 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, nullptr);
1302 ASSERT_NE(nullptr, sceneSession);
1303 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1304 std::vector<std::pair<int32_t, uint32_t>> windowVisibilityInfos;
1305 ssm_->GetAllWindowVisibilityInfos(windowVisibilityInfos);
1306 EXPECT_NE(windowVisibilityInfos.size(), 0);
1307 }
1308
1309 /**
1310 * @tc.name: TestNotifyEnterRecentTask
1311 * @tc.desc: Test whether the enterRecent_ is set correctly;
1312 * @tc.type: FUNC
1313 */
1314 HWTEST_F(SceneSessionManagerTest, TestNotifyEnterRecentTask01, Function | SmallTest | Level3)
1315 {
1316 GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestNotifyEnterRecentTask start";
1317 sptr<SceneSessionManager> sceneSessionManager = new SceneSessionManager();
1318 ASSERT_NE(nullptr, sceneSessionManager);
1319
1320 ASSERT_EQ(sceneSessionManager->NotifyEnterRecentTask(true), WSError::WS_OK);
1321 ASSERT_EQ(sceneSessionManager->enterRecent_.load(), true);
1322 }
1323
1324 /**
1325 * @tc.name: TestIsEnablePiPCreate
1326 * @tc.desc: Test if pip window can be created;
1327 * @tc.type: FUNC
1328 */
1329 HWTEST_F(SceneSessionManagerTest, TestIsEnablePiPCreate, Function | SmallTest | Level3)
1330 {
1331 GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestIsEnablePiPCreate start";
1332 ssm_->isScreenLocked_ = true;
1333 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1334 ASSERT_TRUE(!ssm_->isEnablePiPCreate(property));
1335
1336 ssm_->isScreenLocked_ = false;
1337 Rect reqRect = { 0, 0, 0, 0 };
1338 property->SetRequestRect(reqRect);
1339 ASSERT_TRUE(!ssm_->isEnablePiPCreate(property));
1340
1341 reqRect = { 0, 0, 10, 0 };
1342 property->SetRequestRect(reqRect);
1343 ASSERT_TRUE(!ssm_->isEnablePiPCreate(property));
1344
1345 reqRect = { 0, 0, 10, 10 };
1346 property->SetRequestRect(reqRect);
1347 PiPTemplateInfo info = {0, 0, {}};
1348 property->SetPiPTemplateInfo(info);
1349 SessionInfo info1;
1350 info1.abilityName_ = "test1";
1351 info1.bundleName_ = "test2";
1352 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info1, nullptr);
1353 ASSERT_NE(nullptr, sceneSession);
1354 property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1355 sceneSession->pipTemplateInfo_ = {0, 100, {}};
1356 ssm_->sceneSessionMap_.insert({0, sceneSession});
1357 ASSERT_TRUE(!ssm_->isEnablePiPCreate(property));
1358 ssm_->sceneSessionMap_.clear();
1359 ASSERT_TRUE(!ssm_->isEnablePiPCreate(property));
1360
1361 property->SetParentPersistentId(100);
1362 ASSERT_TRUE(!ssm_->isEnablePiPCreate(property));
1363
1364 ssm_->sceneSessionMap_.insert({100, sceneSession});
1365 ASSERT_TRUE(!ssm_->isEnablePiPCreate(property));
1366
1367 ssm_->sceneSessionMap_.clear();
1368 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1369 ssm_->sceneSessionMap_.insert({100, sceneSession});
1370 ASSERT_TRUE(ssm_->isEnablePiPCreate(property));
1371 }
1372
1373 /**
1374 * @tc.name: GetUnreliableWindowInfo01
1375 * @tc.desc: SceneSesionManager get unreliable window info, windowId correct
1376 * @tc.type: FUNC
1377 */
1378 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo01, Function | SmallTest | Level3)
1379 {
1380 ssm_->sceneSessionMap_.clear();
1381 SessionInfo info;
1382 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, nullptr);
1383 ASSERT_NE(nullptr, sceneSession);
1384 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1385
1386 int32_t windowId = sceneSession->GetPersistentId();
1387 std::vector<sptr<UnreliableWindowInfo>> infos;
1388 WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1389 EXPECT_EQ(WMError::WM_OK, result);
1390 EXPECT_EQ(1, infos.size());
1391 }
1392
1393 /**
1394 * @tc.name: GetUnreliableWindowInfo02
1395 * @tc.desc: SceneSesionManager get unreliable window info, toast window
1396 * @tc.type: FUNC
1397 */
1398 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo02, Function | SmallTest | Level3)
1399 {
1400 ssm_->sceneSessionMap_.clear();
1401 SessionInfo info;
1402 info.windowType_ = 2107;
1403 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1404 ASSERT_NE(nullptr, property);
1405 property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
1406 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1407 ASSERT_NE(nullptr, sceneSession);
1408 sceneSession->SetRSVisible(true);
1409 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1410
1411 int32_t windowId = 0;
1412 std::vector<sptr<UnreliableWindowInfo>> infos;
1413 WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1414 EXPECT_EQ(WMError::WM_OK, result);
1415 EXPECT_EQ(1, infos.size());
1416 }
1417
1418 /**
1419 * @tc.name: GetUnreliableWindowInfo03
1420 * @tc.desc: SceneSesionManager get unreliable window info, app sub window
1421 * @tc.type: FUNC
1422 */
1423 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo03, Function | SmallTest | Level3)
1424 {
1425 ssm_->sceneSessionMap_.clear();
1426 SessionInfo info;
1427 info.windowType_ = 1000;
1428 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1429 ASSERT_NE(nullptr, property);
1430 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1431 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1432 ASSERT_NE(nullptr, sceneSession);
1433 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1434
1435 SessionInfo info2;
1436 info2.windowType_ = 1001;
1437 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
1438 ASSERT_NE(nullptr, property2);
1439 property2->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1440 property2->SetParentId(sceneSession->GetPersistentId());
1441 sptr<SceneSession> sceneSession2 = ssm_->CreateSceneSession(info2, property2);
1442 ASSERT_NE(nullptr, sceneSession2);
1443 sceneSession2->SetRSVisible(true);
1444 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
1445
1446 int32_t windowId = 0;
1447 std::vector<sptr<UnreliableWindowInfo>> infos;
1448 WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1449 EXPECT_EQ(WMError::WM_OK, result);
1450 EXPECT_EQ(1, infos.size());
1451 }
1452
1453 /**
1454 * @tc.name: GetUnreliableWindowInfo04
1455 * @tc.desc: SceneSesionManager get unreliable window info, input method window
1456 * @tc.type: FUNC
1457 */
1458 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo04, Function | SmallTest | Level3)
1459 {
1460 ssm_->sceneSessionMap_.clear();
1461 SessionInfo info;
1462 info.windowType_ = 2105;
1463 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1464 ASSERT_NE(nullptr, property);
1465 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1466 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1467 ASSERT_NE(nullptr, sceneSession);
1468 sceneSession->SetRSVisible(true);
1469 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1470
1471 int32_t windowId = 0;
1472 std::vector<sptr<UnreliableWindowInfo>> infos;
1473 WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1474 EXPECT_EQ(WMError::WM_OK, result);
1475 EXPECT_EQ(1, infos.size());
1476 }
1477
1478 /**
1479 * @tc.name: GetUnreliableWindowInfo05
1480 * @tc.desc: SceneSesionManager get unreliable window info, not correct window type, not visible
1481 * @tc.type: FUNC
1482 */
1483 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo05, Function | SmallTest | Level3)
1484 {
1485 ssm_->sceneSessionMap_.clear();
1486 SessionInfo info;
1487 info.windowType_ = 2122;
1488 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1489 ASSERT_NE(nullptr, property);
1490 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1491 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1492 ASSERT_NE(nullptr, sceneSession);
1493 sceneSession->SetRSVisible(true);
1494 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1495 ssm_->sceneSessionMap_.insert({0, nullptr});
1496
1497 int32_t windowId = 0;
1498 std::vector<sptr<UnreliableWindowInfo>> infos;
1499 WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1500 EXPECT_EQ(WMError::WM_OK, result);
1501 sceneSession->SetRSVisible(false);
1502 result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1503 EXPECT_EQ(WMError::WM_OK, result);
1504 EXPECT_EQ(0, infos.size());
1505 }
1506
1507 /**
1508 * @tc.name: GetUnreliableWindowInfo06
1509 * @tc.desc: SceneSesionManager satisfy FillUnreliableWindowInfo branches coverage
1510 * @tc.type: FUNC
1511 */
1512 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo06, Function | SmallTest | Level3)
1513 {
1514 ssm_->sceneSessionMap_.clear();
1515 SessionInfo info1;
1516 info1.bundleName_ = "SCBGestureBack";
1517 sptr<SceneSession> sceneSession1 = ssm_->CreateSceneSession(info1, nullptr);
1518 ASSERT_NE(nullptr, sceneSession1);
1519 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1520
1521 SessionInfo info2;
1522 info2.bundleName_ = "SCBGestureNavBar";
1523 sptr<SceneSession> sceneSession2 = ssm_->CreateSceneSession(info2, nullptr);
1524 ASSERT_NE(nullptr, sceneSession2);
1525 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
1526
1527 SessionInfo info3;
1528 info3.bundleName_ = "SCBGestureTopBar";
1529 sptr<SceneSession> sceneSession3 = ssm_->CreateSceneSession(info3, nullptr);
1530 ASSERT_NE(nullptr, sceneSession3);
1531 ssm_->sceneSessionMap_.insert({sceneSession3->GetPersistentId(), sceneSession3});
1532
1533 std::vector<sptr<UnreliableWindowInfo>> infos;
1534 ssm_->GetUnreliableWindowInfo(sceneSession1->GetPersistentId(), infos);
1535 ssm_->GetUnreliableWindowInfo(sceneSession2->GetPersistentId(), infos);
1536 ssm_->GetUnreliableWindowInfo(sceneSession3->GetPersistentId(), infos);
1537 EXPECT_EQ(0, infos.size());
1538 }
1539
1540 /**
1541 * @tc.name: GetAllMainWindowInfos001
1542 * @tc.desc: SceneSessionManager get all main window infos.
1543 * @tc.type: FUNC
1544 */
1545 HWTEST_F(SceneSessionManagerTest, GetAllMainWindowInfos001, Function | SmallTest | Level3)
1546 {
1547 SessionInfo info;
1548 info.abilityName_ = "test1";
1549 info.bundleName_ = "test1";
1550 info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1551 info.persistentId_ = 1;
1552 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1553 AppExecFwk::ApplicationInfo applicationInfo;
1554 applicationInfo.bundleType = AppExecFwk::BundleType::ATOMIC_SERVICE;
1555 abilityInfo->applicationInfo = applicationInfo;
1556 info.abilityInfo = abilityInfo;
1557 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1558 if (sceneSession == nullptr) {
1559 return;
1560 }
1561 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1562 std::vector<MainWindowInfo> infos;
1563 WMError result = ssm_->GetAllMainWindowInfos(infos);
1564 EXPECT_EQ(result, WMError::WM_OK);
1565 ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
1566 }
1567
1568 /**
1569 * @tc.name: GetAllMainWindowInfos002
1570 * @tc.desc: SceneSessionManager get all main window infos, input params are not empty.
1571 * @tc.type: FUNC
1572 */
1573 HWTEST_F(SceneSessionManagerTest, GetAllMainWindowInfos002, Function | SmallTest | Level3)
1574 {
1575 std::vector<MainWindowInfo> infos;
1576 MainWindowInfo info;
1577 info.pid_ = 1000;
1578 info.bundleName_ = "test";
1579 infos.push_back(info);
1580 WMError result = ssm_->GetAllMainWindowInfos(infos);
1581 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
1582 }
1583
1584 /**
1585 * @tc.name: TestReportCorrectScreenFoldStatusChangeEvent
1586 * @tc.desc: Test whether report the correct screen fold status events
1587 * @tc.type: FUNC
1588 */
1589 HWTEST_F(SceneSessionManagerTest, TestReportCorrectScreenFoldStatusChangeEvent, Function | SmallTest | Level3)
1590 {
1591 GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestReportCorrectScreenFoldStatusChangeEvent start";
1592 ScreenFoldData screenFoldData1;
1593 screenFoldData1.currentScreenFoldStatus_ = 1; // 1: current screen fold status
1594 screenFoldData1.nextScreenFoldStatus_ = 3; // 3: next screen fold status
1595 screenFoldData1.currentScreenFoldStatusDuration_ = 18; // 18: current duration
1596 screenFoldData1.postureAngle_ = 47.1f; // 47.1: posture angle (type: float)
1597 screenFoldData1.screenRotation_ = 1; // 1: screen rotation
1598 screenFoldData1.typeCThermal_ = 3000; // 3000: typec port thermal
1599 screenFoldData1.focusedPackageName_ = "Developer Test: (1, 3, 18, 47.1, 1, 3000)";
1600 WMError result = ssm_->CheckAndReportScreenFoldStatus(screenFoldData1);
1601 ASSERT_EQ(result, WMError::WM_DO_NOTHING); // not report half-fold event until next change
1602
1603 ScreenFoldData screenFoldData2;
1604 screenFoldData2.currentScreenFoldStatus_ = 3; // 3: current screen fold status
1605 screenFoldData2.nextScreenFoldStatus_ = 2; // 2: next screen fold status
1606 screenFoldData2.currentScreenFoldStatusDuration_ = 20; // 20: current duration
1607 screenFoldData2.postureAngle_ = 143.7f; // 143.7: posture angle (type: float)
1608 screenFoldData2.screenRotation_ = 2; // 2: screen rotation
1609 screenFoldData2.typeCThermal_ = 3005; // 3005: typec port thermal
1610 screenFoldData2.focusedPackageName_ = "Developer Test: (3, 2, 20, 143.7, 2, 3005)";
1611 result = ssm_->CheckAndReportScreenFoldStatus(screenFoldData2);
1612 ASSERT_EQ(result, WMError::WM_OK);
1613 }
1614
1615 /**
1616 * @tc.name: TestReportIncompleteScreenFoldStatusChangeEvent
1617 * @tc.desc: Test whether block the incomplete screen fold status events
1618 * @tc.type: FUNC
1619 */
1620 HWTEST_F(SceneSessionManagerTest, TestReportIncompleteScreenFoldStatusChangeEvent, Function | SmallTest | Level3)
1621 {
1622 GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestReportIncompleteScreenFoldStatusChangeEvent start";
1623 // screen fold status changes from -1: invalid to 3: half_fold, duration = 0, angle = 67.0, rotation = 0
1624 std::vector<std::string> screenFoldInfo {"-1", "3", "0", "67.0", "0"};
1625 WMError result = ssm_->ReportScreenFoldStatusChange(screenFoldInfo);
1626 ASSERT_EQ(result, WMError::WM_DO_NOTHING);
1627
1628 screenFoldInfo.clear();
1629 result = ssm_->ReportScreenFoldStatusChange(screenFoldInfo);
1630 ASSERT_EQ(result, WMError::WM_DO_NOTHING);
1631
1632 // screen fold status changes from 2: folded to 3: half_fold, duration = 0, angle = 67.0, rotation = 0
1633 screenFoldInfo = {"2", "3", "0", "67.0", "0"};
1634 result = ssm_->ReportScreenFoldStatusChange(screenFoldInfo);
1635 ASSERT_EQ(result, WMError::WM_DO_NOTHING);
1636
1637 // screen fold status changes from 3: half_fold to 1: expand, duration = 18, angle = 147.3, rotation = 2
1638 screenFoldInfo = {"3", "1", "18", "147.3", "2"};
1639 result = ssm_->ReportScreenFoldStatusChange(screenFoldInfo);
1640 ASSERT_EQ(result, WMError::WM_DO_NOTHING);
1641 }
1642
1643 /**
1644 * @tc.name: ReleaseForegroundSessionScreenLock
1645 * @tc.desc: release screen lock of foreground session
1646 * @tc.type: FUNC
1647 */
1648 HWTEST_F(SceneSessionManagerTest, ReleaseForegroundSessionScreenLock, Function | SmallTest | Level3)
1649 {
1650 auto result = ssm_->ReleaseForegroundSessionScreenLock();
1651 ASSERT_EQ(result, WMError::WM_OK);
1652 }
1653
1654 /**
1655 * @tc.name: SetAppForceLandscapeConfig
1656 * @tc.desc: SceneSesionManager SetAppForceLandscapeConfig
1657 * @tc.type: FUNC
1658 */
1659 HWTEST_F(SceneSessionManagerTest, SetAppForceLandscapeConfig, Function | SmallTest | Level3)
1660 {
1661 std::string bundleName = "SetAppForceLandscapeConfig";
1662 AppForceLandscapeConfig config = { 0, "MainPage" };
1663 WSError result = ssm_->SetAppForceLandscapeConfig(bundleName, config);
1664 ASSERT_EQ(result, WSError::WS_OK);
1665 }
1666
1667 /**
1668 * @tc.name: GetAppForceLandscapeConfig
1669 * @tc.desc: SceneSesionManager GetAppForceLandscapeConfig
1670 * @tc.type: FUNC
1671 */
1672 HWTEST_F(SceneSessionManagerTest, GetAppForceLandscapeConfig, Function | SmallTest | Level3)
1673 {
1674 std::string bundleName = "GetAppForceLandscapeConfig";
1675 AppForceLandscapeConfig config = ssm_->GetAppForceLandscapeConfig(bundleName);
1676 ASSERT_EQ(config.mode_, 0);
1677 ASSERT_EQ(config.homePage_, "");
1678 }
1679
1680 /**
1681 * @tc.name: CloseTargetFloatWindow
1682 * @tc.desc: SceneSesionManager CloseTargetFloatWindow
1683 * @tc.type: FUNC
1684 */
1685 HWTEST_F(SceneSessionManagerTest, CloseTargetFloatWindow, Function | SmallTest | Level3)
1686 {
1687 std::string bundleName = "testClose";
1688 auto result = ssm_->CloseTargetFloatWindow(bundleName);
1689 ASSERT_EQ(result, WMError::WM_OK);
1690 }
1691
1692 /**
1693 * @tc.name: CloseTargetPiPWindow
1694 * @tc.desc: SceneSesionManager CloseTargetPiPWindow
1695 * @tc.type: FUNC
1696 */
1697 HWTEST_F(SceneSessionManagerTest, CloseTargetPiPWindow, Function | SmallTest | Level3)
1698 {
1699 std::string bundleName = "CloseTargetPiPWindow";
1700 auto result = ssm_->CloseTargetPiPWindow(bundleName);
1701 ASSERT_EQ(result, WMError::WM_OK);
1702 }
1703
1704 /**
1705 * @tc.name: GetCurrentPiPWindowInfo01
1706 * @tc.desc: SceneSesionManager GetCurrentPiPWindowInfo
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(SceneSessionManagerTest, GetCurrentPiPWindowInfo01, Function | SmallTest | Level3)
1710 {
1711 std::string bundleName;
1712 auto result = ssm_->GetCurrentPiPWindowInfo(bundleName);
1713 ASSERT_EQ(result, WMError::WM_OK);
1714 ASSERT_EQ("", bundleName);
1715 }
1716
1717 /**
1718 * @tc.name: GetCurrentPiPWindowInfo02
1719 * @tc.desc: SceneSesionManager GetCurrentPiPWindowInfo
1720 * @tc.type: FUNC
1721 */
1722 HWTEST_F(SceneSessionManagerTest, GetCurrentPiPWindowInfo02, Function | SmallTest | Level3)
1723 {
1724 SessionInfo info1;
1725 info1.abilityName_ = "test1";
1726 info1.bundleName_ = "test1";
1727 info1.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_PIP);
1728 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
1729 ASSERT_NE(nullptr, sceneSession1);
1730 SessionInfo info2;
1731 info2.abilityName_ = "test2";
1732 info2.bundleName_ = "test2";
1733 info2.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DIALOG);
1734 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
1735 ASSERT_NE(nullptr, sceneSession2);
1736
1737 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1738 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
1739 std::string bundleName;
1740 auto result = ssm_->GetCurrentPiPWindowInfo(bundleName);
1741 ASSERT_EQ(result, WMError::WM_OK);
1742 ASSERT_EQ(info1.abilityName_, bundleName);
1743 }
1744
1745 /**
1746 * @tc.name: GetDisplayIdByWindowId
1747 * @tc.desc: test function : GetDisplayIdByWindowId
1748 * @tc.type: FUNC
1749 */
1750 HWTEST_F(SceneSessionManagerTest, GetDisplayIdByWindowId, Function | SmallTest | Level3)
1751 {
1752 SessionInfo info;
1753 info.abilityName_ = "test";
1754 info.bundleName_ = "test";
1755 sptr<SceneSession> sceneSession1 = new (std::nothrow) SceneSession(info, nullptr);
1756 ASSERT_NE(nullptr, sceneSession1);
1757 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1758 sptr<SceneSession> sceneSession2 = new (std::nothrow) SceneSession(info, nullptr);
1759 ASSERT_NE(nullptr, sceneSession2);
1760 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
1761
1762 sptr<WindowSessionProperty> property = new WindowSessionProperty();
1763 DisplayId displayId = 0;
1764 property->SetDisplayId(displayId);
1765 sceneSession1->SetSessionProperty(property);
1766
1767 const std::vector<uint64_t> windowIds = {1001, sceneSession1->GetPersistentId(), sceneSession2->GetPersistentId()};
1768 std::unordered_map<uint64_t, DisplayId> windowDisplayIdMap;
1769 ASSERT_EQ(ssm_->GetDisplayIdByWindowId(windowIds, windowDisplayIdMap), WMError::WM_OK);
1770 }
1771 }
1772 } // namespace Rosen
1773 } // namespace OHOS