• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "iremote_object_mocker.h"
22 #include "screen_fold_data.h"
23 #include "screen_session_manager_client/include/screen_session_manager_client.h"
24 #include "session_manager/include/scene_session_manager.h"
25 #include "session_info.h"
26 #include "session/host/include/scene_session.h"
27 #include "session/host/include/main_session.h"
28 #include "window_manager_agent.h"
29 #include "window_manager_hilog.h"
30 #include "session_manager.h"
31 #include "zidl/window_manager_agent_interface.h"
32 #include "mock/mock_accesstoken_kit.h"
33 #include "mock/mock_session_stage.h"
34 #include "mock/mock_window_event_channel.h"
35 #include "application_info.h"
36 #include "context.h"
37 
38 using namespace testing;
39 using namespace testing::ext;
40 
41 namespace OHOS {
42 namespace Rosen {
43 namespace {
44     std::string g_logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)45     void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
46         const char *msg)
47     {
48         g_logMsg = msg;
49     }
50 }
51 namespace {
52 const std::string EMPTY_DEVICE_ID = "";
53 }
54 class SceneSessionManagerTest : public testing::Test {
55 public:
56     static void SetUpTestCase();
57     static void TearDownTestCase();
58     void SetUp() override;
59     void TearDown() override;
60     static void SetVisibleForAccessibility(sptr<SceneSession>& sceneSession);
61     int32_t GetTaskCount(sptr<SceneSession>& session);
62     static bool gestureNavigationEnabled_;
63     static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
64     static sptr<SceneSessionManager> ssm_;
65 
66 private:
67     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
68     static constexpr uint32_t WAIT_SYNC_FOR_SNAPSHOT_SKIP_IN_NS = 500000;
69     static constexpr uint32_t WAIT_SYNC_FOR_TEST_END_IN_NS = 1000000;
70 };
71 
72 sptr<SceneSessionManager> SceneSessionManagerTest::ssm_ = nullptr;
73 
74 bool SceneSessionManagerTest::gestureNavigationEnabled_ = true;
75 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest::callbackFunc_ =
__anone0db31a60302(bool enable, const std::string& bundleName, GestureBackType type) 76     [](bool enable, const std::string& bundleName, GestureBackType type) { gestureNavigationEnabled_ = enable; };
77 
SetUpTestCase()78 void SceneSessionManagerTest::SetUpTestCase()
79 {
80     ssm_ = &SceneSessionManager::GetInstance();
81 }
82 
TearDownTestCase()83 void SceneSessionManagerTest::TearDownTestCase()
84 {
85     ssm_ = nullptr;
86 }
87 
SetUp()88 void SceneSessionManagerTest::SetUp()
89 {
90     ssm_->sceneSessionMap_.clear();
91 }
92 
TearDown()93 void SceneSessionManagerTest::TearDown()
94 {
95     MockAccesstokenKit::ChangeMockStateToInit();
96     usleep(WAIT_SYNC_IN_NS);
97     ssm_->sceneSessionMap_.clear();
98 }
99 
SetVisibleForAccessibility(sptr<SceneSession> & sceneSession)100 void SceneSessionManagerTest::SetVisibleForAccessibility(sptr<SceneSession>& sceneSession)
101 {
102     sceneSession->SetTouchable(true);
103     sceneSession->forceTouchable_ = true;
104     sceneSession->systemTouchable_ = true;
105     sceneSession->state_ = SessionState::STATE_FOREGROUND;
106     sceneSession->foregroundInteractiveStatus_.store(true);
107     sceneSession->isVisible_ = true;
108 }
109 
GetTaskCount(sptr<SceneSession> & session)110 int32_t SceneSessionManagerTest::GetTaskCount(sptr<SceneSession>& session)
111 {
112     std::string dumpInfo = session->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
113     std::regex pattern("\\d+");
114     std::smatch matches;
115     int32_t taskNum = 0;
116     while (std::regex_search(dumpInfo, matches, pattern)) {
117         taskNum += std::stoi(matches.str());
118         dumpInfo = matches.suffix();
119     }
120     return taskNum;
121 }
122 
123 namespace {
124 /**
125  * @tc.name: SetBrightness
126  * @tc.desc: ScreenSesionManager set session brightness
127  * @tc.type: FUNC
128  */
129 HWTEST_F(SceneSessionManagerTest, SetBrightness, TestSize.Level1)
130 {
131     SessionInfo info;
132     info.abilityName_ = "SetBrightness";
133     info.bundleName_ = "SetBrightness1";
134     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
135     ASSERT_NE(nullptr, sceneSession);
136     float brightness = 0.5;
137     WSError result = ssm_->SetBrightness(sceneSession, brightness);
138     ASSERT_EQ(result, WSError::WS_OK);
139     ASSERT_NE(brightness, ssm_->GetDisplayBrightness());
140 }
141 
142 /**
143  * @tc.name: GerPrivacyBundleListTwoWindow
144  * @tc.desc: get privacy bundle list when two windows exist.
145  * @tc.type: FUNC
146  */
147 HWTEST_F(SceneSessionManagerTest, GerPrivacyBundleListTwoWindow, TestSize.Level1)
148 {
149     SessionInfo sessionInfoFirst;
150     sessionInfoFirst.bundleName_ = "privacy.test.first";
151     sessionInfoFirst.abilityName_ = "privacyAbilityName";
152     sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfoFirst, nullptr);
153     ASSERT_NE(sceneSessionFirst, nullptr);
154     ssm_->sceneSessionMap_.insert({ sceneSessionFirst->GetPersistentId(), sceneSessionFirst });
155 
156     SessionInfo sessionInfoSecond;
157     sessionInfoSecond.bundleName_ = "privacy.test.second";
158     sessionInfoSecond.abilityName_ = "privacyAbilityName";
159     sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfoSecond, nullptr);
160     ASSERT_NE(sceneSessionSecond, nullptr);
161     ssm_->sceneSessionMap_.insert({ sceneSessionSecond->GetPersistentId(), sceneSessionSecond });
162 
163     sceneSessionFirst->GetSessionProperty()->displayId_ = 0;
164     sceneSessionFirst->GetSessionProperty()->isPrivacyMode_ = true;
165     sceneSessionFirst->state_ = SessionState::STATE_FOREGROUND;
166 
167     sceneSessionSecond->GetSessionProperty()->displayId_ = 0;
168     sceneSessionSecond->GetSessionProperty()->isPrivacyMode_ = true;
169     sceneSessionSecond->state_ = SessionState::STATE_FOREGROUND;
170 
171     std::unordered_set<std::string> privacyBundleList;
172     ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
173     EXPECT_EQ(privacyBundleList.size(), 2);
174 
175     sceneSessionSecond->GetSessionProperty()->displayId_ = 1;
176     privacyBundleList.clear();
177     ssm_->GetSceneSessionPrivacyModeBundles(0, privacyBundleList);
178     EXPECT_EQ(privacyBundleList.size(), 1);
179 
180     privacyBundleList.clear();
181     ssm_->GetSceneSessionPrivacyModeBundles(1, privacyBundleList);
182     EXPECT_EQ(privacyBundleList.size(), 1);
183 }
184 
185 /**
186  * @tc.name: SetWindowFlags01
187  * @tc.desc: SceneSesionManager set window flags
188  * @tc.type: FUNC
189  */
190 HWTEST_F(SceneSessionManagerTest, SetWindowFlags01, TestSize.Level1)
191 {
192     SessionInfo info;
193     info.bundleName_ = "bundleName";
194     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
195     uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
196     property->SetWindowFlags(flags);
197     sptr<SceneSession> sceneSession = nullptr;
198     WSError result01 = ssm_->SetWindowFlags(sceneSession, property);
199     EXPECT_EQ(result01, WSError::WS_ERROR_NULLPTR);
200 }
201 
202 /**
203  * @tc.name: SetWindowFlags02
204  * @tc.desc: SceneSesionManager set window flags
205  * @tc.type: FUNC
206  */
207 HWTEST_F(SceneSessionManagerTest, SetWindowFlags02, TestSize.Level1)
208 {
209     SessionInfo info;
210     info.bundleName_ = "bundleName";
211     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
212     uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
213     property->SetWindowFlags(flags);
214     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
215     WSError result02 = ssm_->SetWindowFlags(sceneSession, property);
216     EXPECT_EQ(result02, WSError::WS_ERROR_NOT_SYSTEM_APP);
217 }
218 
219 /**
220  * @tc.name: SetWindowFlags03
221  * @tc.desc: SceneSesionManager set window flags
222  * @tc.type: FUNC
223  */
224 HWTEST_F(SceneSessionManagerTest, SetWindowFlags03, TestSize.Level1)
225 {
226     SessionInfo info;
227     info.bundleName_ = "bundleName";
228     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
229     uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
230     property->SetWindowFlags(flags);
231     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
232     property->SetSystemCalling(true);
233     WSError result03 = ssm_->SetWindowFlags(sceneSession, property);
234     ASSERT_EQ(result03, WSError::WS_OK);
235 }
236 
237 /**
238  * @tc.name: NotifyWaterMarkFlagChangedResult
239  * @tc.desc: SceneSesionManager notify water mark flag changed result
240  * @tc.type: FUNC
241  */
242 HWTEST_F(SceneSessionManagerTest, NotifyWaterMarkFlagChangedResult, TestSize.Level1)
243 {
244     int32_t persistentId = 10086;
245     ssm_->NotifyCompleteFirstFrameDrawing(persistentId);
246     bool hasWaterMark = true;
247     AppExecFwk::AbilityInfo abilityInfo;
248     WSError result01 = ssm_->NotifyWaterMarkFlagChangedResult(hasWaterMark);
249     EXPECT_EQ(result01, WSError::WS_OK);
250     ssm_->CheckAndNotifyWaterMarkChangedResult();
251     ssm_->ProcessPreload(abilityInfo);
252 }
253 
254 /**
255  * @tc.name: IsValidSessionIds
256  * @tc.desc: SceneSesionManager is valid session id
257  * @tc.type: FUNC
258  */
259 HWTEST_F(SceneSessionManagerTest, IsValidSessionIds, TestSize.Level1)
260 {
261     std::vector<int32_t> sessionIds = { 0, 1, 2, 3, 4, 5, 24, 10086 };
262     std::vector<bool> results = {};
263     WSError result = ssm_->IsValidSessionIds(sessionIds, results);
264     EXPECT_EQ(result, WSError::WS_OK);
265 }
266 
267 /**
268  * @tc.name: UnRegisterSessionListener
269  * @tc.desc: SceneSesionManager un register session listener
270  * @tc.type: FUNC
271  */
272 HWTEST_F(SceneSessionManagerTest, UnRegisterSessionListener, TestSize.Level1)
273 {
274     MockAccesstokenKit::MockAccessTokenKitRet(-1);
275     OHOS::MessageParcel data;
276     sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
277     WSError result = ssm_->UnRegisterSessionListener(listener);
278     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
279 }
280 
281 /**
282  * @tc.name: GetSessionInfos01
283  * @tc.desc: SceneSesionManager get session infos
284  * @tc.type: FUNC
285  */
286 HWTEST_F(SceneSessionManagerTest, GetSessionInfos01, TestSize.Level1)
287 {
288     MockAccesstokenKit::MockIsSACalling(false);
289     std::string deviceId = "1245";
290     int32_t numMax = 1024;
291     AAFwk::MissionInfo infoFrist;
292     infoFrist.label = "fristBundleName";
293     AAFwk::MissionInfo infoSecond;
294     infoSecond.label = "secondBundleName";
295     std::vector<SessionInfoBean> sessionInfos = { infoFrist, infoSecond };
296     MockAccesstokenKit::MockAccessTokenKitRet(-1);
297     WSError result = ssm_->GetSessionInfos(deviceId, numMax, sessionInfos);
298     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
299 }
300 
301 /**
302  * @tc.name: GetSessionInfos02
303  * @tc.desc: SceneSesionManager get session infos
304  * @tc.type: FUNC
305  */
306 HWTEST_F(SceneSessionManagerTest, GetSessionInfos02, TestSize.Level1)
307 {
308     MockAccesstokenKit::MockIsSACalling(false);
309     std::string deviceId = "1245";
310     AAFwk::MissionInfo infoFrist;
311     infoFrist.label = "fristBundleName";
312     AAFwk::MissionInfo infoSecond;
313     infoSecond.label = "secondBundleName";
314     std::vector<SessionInfoBean> sessionInfos = { infoFrist, infoSecond };
315     MockAccesstokenKit::MockAccessTokenKitRet(0);
316     int32_t persistentId = 24;
317     SessionInfoBean sessionInfo;
318     int result01 = ssm_->GetRemoteSessionInfo(deviceId, persistentId, sessionInfo);
319     ASSERT_NE(result01, ERR_OK);
320 }
321 
322 /**
323  * @tc.name: GetUnreliableWindowInfo
324  * @tc.desc: SceneSesionManager get unreliable window info
325  * @tc.type: FUNC
326  */
327 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo, TestSize.Level1)
328 {
329     int32_t windowId = 0;
330     std::vector<sptr<UnreliableWindowInfo>> infos;
331     WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
332     EXPECT_EQ(WMError::WM_OK, result);
333 }
334 
335 /**
336  * @tc.name: GetMainWindowStatesByPid
337  * @tc.desc: SceneSesionManager get main window states
338  * @tc.type: FUNC
339  */
340 HWTEST_F(SceneSessionManagerTest, GetMainWindowStatesByPid, TestSize.Level1)
341 {
342     int32_t pid = 100;
343     std::vector<MainWindowState> windowStates;
344     WSError result = ssm_->GetMainWindowStatesByPid(pid, windowStates);
345     EXPECT_EQ(result, WSError::WS_OK);
346 }
347 
348 /**
349  * @tc.name: CheckIsRemote01
350  * @tc.desc: DeviceId is empty
351  * @tc.type: FUNC
352  */
353 HWTEST_F(SceneSessionManagerTest, CheckIsRemote01, TestSize.Level1)
354 {
355     std::string deviceId;
356     EXPECT_EQ(deviceId.empty(), true);
357     bool result = ssm_->CheckIsRemote(deviceId);
358     EXPECT_FALSE(result);
359 }
360 
361 /**
362  * @tc.name: CheckIsRemote02
363  * @tc.desc: SceneSesionManager check is remote
364  * @tc.type: FUNC
365  */
366 HWTEST_F(SceneSessionManagerTest, CheckIsRemote02, TestSize.Level1)
367 {
368     std::string deviceId = "abc";
369     EXPECT_EQ(deviceId.empty(), false);
370     bool result = ssm_->CheckIsRemote(deviceId);
371     EXPECT_FALSE(result);
372 }
373 
374 /**
375  * @tc.name: AnonymizeDeviceId01
376  * @tc.desc: SceneSesionManager anonymize deviceId
377  * @tc.type: FUNC
378  */
379 HWTEST_F(SceneSessionManagerTest, AnonymizeDeviceId01, TestSize.Level1)
380 {
381     std::string deviceId;
382     std::string result(ssm_->AnonymizeDeviceId(deviceId));
383     EXPECT_EQ(result, EMPTY_DEVICE_ID);
384 }
385 
386 /**
387  * @tc.name: AnonymizeDeviceId02
388  * @tc.desc: SceneSesionManager anonymize deviceId
389  * @tc.type: FUNC
390  */
391 HWTEST_F(SceneSessionManagerTest, AnonymizeDeviceId02, TestSize.Level1)
392 {
393     std::string deviceId;
394     deviceId.assign("100964857");
395     std::string result01 = "100964******";
396     ASSERT_EQ(ssm_->AnonymizeDeviceId(deviceId), result01);
397 }
398 
399 /**
400  * @tc.name: TerminateSessionNew01
401  * @tc.desc: SceneSesionManager terminate session new
402  * @tc.type: FUNC
403  */
404 HWTEST_F(SceneSessionManagerTest, TerminateSessionNew01, TestSize.Level1)
405 {
406     sptr<AAFwk::SessionInfo> info = nullptr;
407     bool needStartCaller = true;
408     WSError result01 = ssm_->TerminateSessionNew(info, needStartCaller);
409     EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, result01);
410 }
411 
412 /**
413  * @tc.name: TerminateSessionNew02
414  * @tc.desc: SceneSesionManager terminate session new
415  * @tc.type: FUNC
416  */
417 HWTEST_F(SceneSessionManagerTest, TerminateSessionNew, TestSize.Level1)
418 {
419     bool needStartCaller = true;
420     sptr<AAFwk::SessionInfo> info = sptr<AAFwk::SessionInfo>::MakeSptr();
421     WSError result02 = ssm_->TerminateSessionNew(info, needStartCaller);
422     EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, result02);
423 }
424 
425 /**
426  * @tc.name: RegisterSessionListener01
427  * @tc.desc: SceneSesionManager register session listener
428  * @tc.type: FUNC
429  */
430 HWTEST_F(SceneSessionManagerTest, RegisterSessionListener01, TestSize.Level1)
431 {
432     MockAccesstokenKit::MockAccessTokenKitRet(-1);
433     OHOS::MessageParcel data;
434     sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
435     WSError result = ssm_->RegisterSessionListener(listener);
436     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
437 }
438 
439 /**
440  * @tc.name: ClearDisplayStatusBarTemporarilyFlags01
441  * @tc.desc: check ClearDisplayStatusBarTemporarilyFlags
442  * @tc.type: FUNC
443  */
444 HWTEST_F(SceneSessionManagerTest, ClearDisplayStatusBarTemporarilyFlags01, TestSize.Level1)
445 {
446     SessionInfo sessionInfo;
447     sessionInfo.bundleName_ = "ClearDisplayStatusBarTemporarilyFlags";
448     sessionInfo.abilityName_ = "ClearDisplayStatusBarTemporarilyFlags";
449     sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
450     sptr<SceneSession> sceneSession = ssm_->RequestSceneSession(sessionInfo, nullptr);
451     ASSERT_NE(nullptr, sceneSession);
452 }
453 
454 /**
455  * @tc.name: ClearDisplayStatusBarTemporarilyFlags02
456  * @tc.desc: check ClearDisplayStatusBarTemporarilyFlags
457  * @tc.type: FUNC
458  */
459 HWTEST_F(SceneSessionManagerTest, ClearDisplayStatusBarTemporarilyFlags02, TestSize.Level1)
460 {
461     SessionInfo sessionInfo;
462     sessionInfo.bundleName_ = "ClearDisplayStatusBarTemporarilyFlags";
463     sessionInfo.abilityName_ = "ClearDisplayStatusBarTemporarilyFlags";
464     sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
465     sptr<SceneSession> sceneSession = ssm_->RequestSceneSession(sessionInfo, nullptr);
466     sceneSession->SetIsDisplayStatusBarTemporarily(true);
467     ASSERT_EQ(true, sceneSession->GetIsDisplayStatusBarTemporarily());
468 }
469 
470 /**
471  * @tc.name: ClearDisplayStatusBarTemporarilyFlags03
472  * @tc.desc: check ClearDisplayStatusBarTemporarilyFlags
473  * @tc.type: FUNC
474  */
475 HWTEST_F(SceneSessionManagerTest, ClearDisplayStatusBarTemporarilyFlags03, TestSize.Level1)
476 {
477     SessionInfo sessionInfo;
478     sessionInfo.bundleName_ = "ClearDisplayStatusBarTemporarilyFlags";
479     sessionInfo.abilityName_ = "ClearDisplayStatusBarTemporarilyFlags";
480     sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
481     sptr<SceneSession> sceneSession = ssm_->RequestSceneSession(sessionInfo, nullptr);
482     sceneSession->SetIsDisplayStatusBarTemporarily(true);
483     ssm_->ClearDisplayStatusBarTemporarilyFlags();
484     ASSERT_EQ(true, sceneSession->GetIsDisplayStatusBarTemporarily());
485 }
486 
487 /**
488  * @tc.name: RequestSceneSessionByCall01
489  * @tc.desc: SceneSesionManager request scene session by call
490  * @tc.type: FUNC
491  */
492 HWTEST_F(SceneSessionManagerTest, RequestSceneSessionByCall01, TestSize.Level1)
493 {
494     sptr<SceneSession> sceneSession = nullptr;
495     WSError result01 = ssm_->RequestSceneSessionByCall(nullptr);
496     EXPECT_EQ(result01, WSError::WS_OK);
497 }
498 
499 /**
500  * @tc.name: RequestSceneSessionByCall02
501  * @tc.desc: SceneSesionManager request scene session by call
502  * @tc.type: FUNC
503  */
504 HWTEST_F(SceneSessionManagerTest, RequestSceneSessionByCall02, TestSize.Level1)
505 {
506     sptr<SceneSession> sceneSession = nullptr;
507     SessionInfo info;
508     info.bundleName_ = "bundleName";
509     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
510     WSError result02 = ssm_->RequestSceneSessionByCall(sceneSession);
511     ASSERT_EQ(result02, WSError::WS_OK);
512 }
513 
514 /**
515  * @tc.name: StartAbilityBySpecified
516  * @tc.desc: SceneSesionManager start ability by specified
517  * @tc.type: FUNC
518  */
519 HWTEST_F(SceneSessionManagerTest, StartAbilityBySpecified, TestSize.Level1)
520 {
521     g_logMsg.clear();
522     LOG_SetCallback(MyLogCallback);
523     SessionInfo info;
524     ssm_->StartAbilityBySpecified(info);
525 
526     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
527     AAFwk::WantParams wantParams;
528     want->SetParams(wantParams);
529     info.want = want;
530     ssm_->StartAbilityBySpecified(info);
531     EXPECT_FALSE(g_logMsg.find("start specified ability by SCB result") != std::string::npos);
532     LOG_SetCallback(nullptr);
533 }
534 
535 /**
536  * @tc.name: FindMainWindowWithToken01
537  * @tc.desc: SceneSesionManager find main window with token
538  * @tc.type: FUNC
539  */
540 HWTEST_F(SceneSessionManagerTest, FindMainWindowWithToken01, TestSize.Level1)
541 {
542     sptr<IRemoteObject> targetToken = nullptr;
543     sptr<SceneSession> result = ssm_->FindMainWindowWithToken(targetToken);
544     EXPECT_EQ(result, nullptr);
545 
546     uint64_t persistentId = 1423;
547     WSError result01 = ssm_->BindDialogSessionTarget(persistentId, targetToken);
548     EXPECT_EQ(result01, WSError::WS_ERROR_NULLPTR);
549 }
550 
551 /**
552  * @tc.name: FindMainWindowWithToken02
553  * @tc.desc: SceneSesionManager find main window with token
554  * @tc.type: FUNC
555  */
556 HWTEST_F(SceneSessionManagerTest, FindMainWindowWithToken02, TestSize.Level1)
557 {
558     SessionInfo info;
559     info.abilityName_ = "test1";
560     info.bundleName_ = "test2";
561     info.moduleName_ = "test3";
562     info.persistentId_ = 1;
563     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
564     ASSERT_NE(nullptr, sceneSession);
565     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
566     ASSERT_NE(nullptr, property);
567 }
568 
569 /**
570  * @tc.name: FindMainWindowWithToken03
571  * @tc.desc: SceneSesionManager find main window with token
572  * @tc.type: FUNC
573  */
574 HWTEST_F(SceneSessionManagerTest, FindMainWindowWithToken03, TestSize.Level1)
575 {
576     sptr<IRemoteObject> targetToken = sptr<IRemoteObjectMocker>::MakeSptr();
577     uint64_t persistentId = 1423;
578     SessionInfo info;
579     info.abilityName_ = "test1";
580     info.bundleName_ = "test2";
581     info.moduleName_ = "test3";
582     info.persistentId_ = 1;
583     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
584     ssm_->sceneSessionMap_.insert({ 1, sceneSession });
585     persistentId = 1;
586     WSError result02 = ssm_->BindDialogSessionTarget(persistentId, targetToken);
587     EXPECT_EQ(result02, WSError::WS_OK);
588 
589     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
590     WSError result03 = ssm_->BindDialogSessionTarget(persistentId, targetToken);
591     EXPECT_EQ(result03, WSError::WS_OK);
592 }
593 
594 /**
595  * @tc.name: UpdateParentSessionForDialog001
596  * @tc.desc: SceneSesionManager update parent session for dialog
597  * @tc.type: FUNC
598  */
599 HWTEST_F(SceneSessionManagerTest, UpdateParentSessionForDialog001, TestSize.Level1)
600 {
601     SessionInfo dialogInfo;
602     dialogInfo.abilityName_ = "DialogWindows";
603     dialogInfo.bundleName_ = "DialogWindows";
604     SessionInfo parentInfo;
605     parentInfo.abilityName_ = "ParentWindows";
606     parentInfo.bundleName_ = "ParentWindows";
607 
608     int32_t persistentId = 1005;
609     sptr<SceneSession> parentSession = sptr<SceneSession>::MakeSptr(parentInfo, nullptr);
610     EXPECT_NE(parentSession, nullptr);
611     ssm_->sceneSessionMap_.insert({ persistentId, parentSession });
612 
613     sptr<SceneSession> dialogSession = sptr<SceneSession>::MakeSptr(dialogInfo, nullptr);
614     EXPECT_NE(dialogSession, nullptr);
615 
616     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
617     property->SetParentPersistentId(persistentId);
618     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
619 
620     WSError result = ssm_->UpdateParentSessionForDialog(dialogSession, property);
621     EXPECT_EQ(dialogSession->GetParentPersistentId(), persistentId);
622     EXPECT_NE(dialogSession->GetParentSession(), nullptr);
623     EXPECT_EQ(result, WSError::WS_OK);
624 }
625 
626 /**
627  * @tc.name: IsFreeMultiWindow
628  * @tc.desc: IsFreeMultiWindow
629  * @tc.type: FUNC
630  */
631 HWTEST_F(SceneSessionManagerTest, IsFreeMultiWindow, TestSize.Level1)
632 {
633     bool isFreeMultiWindow = false;
634     // freeMultiWindowEnable false
635     ssm_->systemConfig_.freeMultiWindowEnable_ = false;
636     auto result = ssm_->IsFreeMultiWindow(isFreeMultiWindow);
637     ASSERT_EQ(result, WMError::WM_OK);
638 
639     // freeMultiWindowEnable true
640     ssm_->systemConfig_.freeMultiWindowEnable_ = true;
641     result = ssm_->IsFreeMultiWindow(isFreeMultiWindow);
642     ASSERT_EQ(result, WMError::WM_OK);
643 }
644 
645 /**
646  * @tc.name: MoveSessionsToBackground01
647  * @tc.desc: SceneSesionManager move sessions to background
648  * @tc.type: FUNC
649  */
650 HWTEST_F(SceneSessionManagerTest, MoveSessionsToBackground01, TestSize.Level1)
651 {
652     MockAccesstokenKit::MockIsSACalling(false);
653     int32_t type = CollaboratorType::RESERVE_TYPE;
654     WSError result01 = ssm_->UnregisterIAbilityManagerCollaborator(type);
655     EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_PERMISSION);
656 }
657 
658 /**
659  * @tc.name: MoveSessionsToBackground02
660  * @tc.desc: SceneSesionManager move sessions to background
661  * @tc.type: FUNC
662  */
663 HWTEST_F(SceneSessionManagerTest, MoveSessionsToBackground02, TestSize.Level1)
664 {
665     MockAccesstokenKit::MockIsSACalling(false);
666     std::vector<std::int32_t> sessionIds = { 1, 2, 3, 15, 1423 };
667     std::vector<int32_t> res = { 1, 2, 3, 15, 1423 };
668     MockAccesstokenKit::MockAccessTokenKitRet(-1);
669     WSError result03 = ssm_->MoveSessionsToBackground(sessionIds, res);
670     ASSERT_EQ(result03, WSError::WS_ERROR_INVALID_PERMISSION);
671 }
672 
673 /**
674  * @tc.name: ClearAllCollaboratorSessions
675  * @tc.desc: SceneSesionManager clear all collaborator sessions
676  * @tc.type: FUNC
677  */
678 HWTEST_F(SceneSessionManagerTest, ClearAllCollaboratorSessions, TestSize.Level1)
679 {
680     std::string bundleName = "bundleName";
681     std::string abilityName = "abilityName";
682     int32_t persistentId = 1200;
683     SessionInfo info;
684     info.bundleName_ = bundleName;
685     info.abilityName_ = abilityName;
686     info.persistentId_ = persistentId;
687     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
688     ASSERT_NE(sceneSession, nullptr);
689     sceneSession->SetCollaboratorType(CollaboratorType::DEFAULT_TYPE);
690     sceneSession->SetTerminateSessionListenerNew(
__anone0db31a60502(const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) 691         [](const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) {
692         ssm_->sceneSessionMap_.erase(info.persistentId_);
693     });
694     usleep(WAIT_SYNC_IN_NS);
695     ssm_->sceneSessionMap_.insert({ persistentId, sceneSession });
696     ssm_->ClearAllCollaboratorSessions();
697     ASSERT_EQ(ssm_->sceneSessionMap_[persistentId], sceneSession);
698 }
699 
700 /**
701  * @tc.name: ClearAllCollaboratorSessions02
702  * @tc.desc: SceneSesionManager clear all collaborator sessions
703  * @tc.type: FUNC
704  */
705 HWTEST_F(SceneSessionManagerTest, ClearAllCollaboratorSessions02, TestSize.Level1)
706 {
707     std::string bundleName = "bundleName";
708     std::string abilityName = "abilityName";
709     int32_t persistentId = 1201;
710     SessionInfo info;
711     info.bundleName_ = bundleName;
712     info.abilityName_ = abilityName;
713     info.persistentId_ = persistentId;
714     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
715     ASSERT_NE(sceneSession, nullptr);
716     sceneSession->SetCollaboratorType(CollaboratorType::RESERVE_TYPE);
717     sceneSession->SetTerminateSessionListenerNew(
__anone0db31a60602(const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) 718         [](const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) {
719         ssm_->sceneSessionMap_.erase(info.persistentId_);
720     });
721     usleep(WAIT_SYNC_IN_NS);
722     ssm_->sceneSessionMap_.insert({ persistentId, sceneSession });
723     ssm_->ClearAllCollaboratorSessions();
724     ASSERT_EQ(ssm_->sceneSessionMap_[persistentId], nullptr);
725 }
726 
727 /**
728  * @tc.name: ClearAllCollaboratorSessions03
729  * @tc.desc: SceneSesionManager clear all collaborator sessions
730  * @tc.type: FUNC
731  */
732 HWTEST_F(SceneSessionManagerTest, ClearAllCollaboratorSessions03, TestSize.Level1)
733 {
734     std::string bundleName = "bundleName";
735     std::string abilityName = "abilityName";
736     int32_t persistentId = 1202;
737     SessionInfo info;
738     info.bundleName_ = bundleName;
739     info.abilityName_ = abilityName;
740     info.persistentId_ = persistentId;
741     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
742     ASSERT_NE(sceneSession, nullptr);
743     sceneSession->SetCollaboratorType(CollaboratorType::OTHERS_TYPE);
744     sceneSession->SetTerminateSessionListenerNew(
__anone0db31a60702(const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) 745         [](const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean) {
746         ssm_->sceneSessionMap_.erase(info.persistentId_);
747     });
748     usleep(WAIT_SYNC_IN_NS);
749     ssm_->sceneSessionMap_.insert({ persistentId, sceneSession });
750     ssm_->ClearAllCollaboratorSessions();
751     ASSERT_EQ(ssm_->sceneSessionMap_[persistentId], nullptr);
752 }
753 
754 /**
755  * @tc.name: MoveSessionsToForeground
756  * @tc.desc: SceneSesionManager move sessions to foreground
757  * @tc.type: FUNC
758  */
759 HWTEST_F(SceneSessionManagerTest, MoveSessionsToForeground, TestSize.Level1)
760 {
761     MockAccesstokenKit::MockIsSACalling(false);
762     std::vector<std::int32_t> sessionIds = { 1, 2, 3, 15, 1423 };
763     int32_t topSessionId = 1;
764     MockAccesstokenKit::MockAccessTokenKitRet(-1);
765     WSError result = ssm_->MoveSessionsToForeground(sessionIds, topSessionId);
766     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
767 }
768 
769 /**
770  * @tc.name: UnlockSession
771  * @tc.desc: SceneSesionManager unlock session
772  * @tc.type: FUNC
773  */
774 HWTEST_F(SceneSessionManagerTest, UnlockSession, TestSize.Level1)
775 {
776     MockAccesstokenKit::MockAccessTokenKitRet(-1);
777     int32_t sessionId = 1;
778     WSError result = ssm_->UnlockSession(sessionId);
779     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
780     result = ssm_->LockSession(sessionId);
781     EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
782 }
783 
784 /**
785  * @tc.name: GetImmersiveState
786  * @tc.desc: test GetImmersiveState
787  * @tc.type: FUNC
788  */
789 HWTEST_F(SceneSessionManagerTest, GetImmersiveState, TestSize.Level1)
790 {
791     g_logMsg.clear();
792     LOG_SetCallback(MyLogCallback);
793     ScreenId screenId = 1;
794     auto ret = ssm_->GetImmersiveState(screenId);
795     EXPECT_NE(ret, true);
796     EXPECT_FALSE(g_logMsg.find("session is nullptr") != std::string::npos);
797     LOG_SetCallback(nullptr);
798 }
799 
800 /**
801  * @tc.name: NotifyAINavigationBarShowStatus
802  * @tc.desc: test NotifyAINavigationBarShowStatus
803  * @tc.type: FUNC
804  */
805 HWTEST_F(SceneSessionManagerTest, NotifyAINavigationBarShowStatus, TestSize.Level1)
806 {
807     bool isVisible = false;
808     WSRect barArea = { 0, 0, 320, 240 }; // width: 320, height: 240
809     uint64_t displayId = 0;
810     ssm_->rootSceneSession_ = sptr<RootSceneSession>::MakeSptr();
811     WSError result = ssm_->NotifyAINavigationBarShowStatus(isVisible, barArea, displayId);
812     ASSERT_EQ(result, WSError::WS_OK);
813 }
814 
815 /**
816  * @tc.name: NotifyWindowExtensionVisibilityChange
817  * @tc.desc: test NotifyWindowExtensionVisibilityChange
818  * @tc.type: FUNC
819  */
820 HWTEST_F(SceneSessionManagerTest, NotifyWindowExtensionVisibilityChange, TestSize.Level1)
821 {
822     int32_t pid = getprocpid();
823     int32_t uid = getuid();
824     bool isVisible = false;
825     WSError result = ssm_->NotifyWindowExtensionVisibilityChange(pid, uid, isVisible);
826     ASSERT_EQ(result, WSError::WS_OK);
827 
828     pid = INVALID_PID;
829     uid = INVALID_USER_ID;
830     result = ssm_->NotifyWindowExtensionVisibilityChange(pid, uid, isVisible);
831     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
832 }
833 
834 /**
835  * @tc.name: UpdateTopmostProperty
836  * @tc.desc: test UpdateTopmostProperty
837  * @tc.type: FUNC
838  */
839 HWTEST_F(SceneSessionManagerTest, UpdateTopmostProperty, TestSize.Level1)
840 {
841     SessionInfo info;
842     info.abilityName_ = "UpdateTopmostProperty";
843     info.bundleName_ = "UpdateTopmostProperty";
844     sptr<SceneSession> sceneSession = sptr<MainSession>::MakeSptr(info, nullptr);
845     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
846     property->SetTopmost(true);
847     property->SetSystemCalling(true);
848     WMError result = ssm_->UpdateTopmostProperty(property, sceneSession);
849     ASSERT_EQ(WMError::WM_OK, result);
850 }
851 
852 /**
853  * @tc.name: UpdateSessionWindowVisibilityListener
854  * @tc.desc: SceneSesionManager update window visibility listener
855  * @tc.type: FUNC
856  */
857 HWTEST_F(SceneSessionManagerTest, UpdateSessionWindowVisibilityListener, TestSize.Level1)
858 {
859     int32_t persistentId = 10086;
860     bool haveListener = true;
861     WSError result = ssm_->UpdateSessionWindowVisibilityListener(persistentId, haveListener);
862     ASSERT_EQ(result, WSError::WS_DO_NOTHING);
863 }
864 
865 /**
866  * @tc.name: GetSessionSnapshotPixelMap01
867  * @tc.desc: SceneSesionManager get session snapshot pixelmap
868  * @tc.type: FUNC
869  */
870 HWTEST_F(SceneSessionManagerTest, GetSessionSnapshotPixelMap01, TestSize.Level1)
871 {
872     SessionInfo info;
873     info.abilityName_ = "GetPixelMap";
874     info.bundleName_ = "GetPixelMap1";
875     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
876     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
877 
878     int32_t persistentId = 65535;
879     float scaleValue = 0.5f;
880     auto pixelMap = ssm_->GetSessionSnapshotPixelMap(persistentId, scaleValue);
881     EXPECT_EQ(pixelMap, nullptr);
882 }
883 
884 /**
885  * @tc.name: GetSessionSnapshotPixelMap02
886  * @tc.desc: SceneSesionManager get session snapshot pixelmap
887  * @tc.type: FUNC
888  */
889 HWTEST_F(SceneSessionManagerTest, GetSessionSnapshotPixelMap02, TestSize.Level1)
890 {
891     SessionInfo info;
892     info.abilityName_ = "GetPixelMap";
893     info.bundleName_ = "GetPixelMap1";
894     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
895     sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
896 
897     float scaleValue = 0.5f;
898     int32_t persistentId = 1;
899     auto pixelMap = ssm_->GetSessionSnapshotPixelMap(persistentId, scaleValue);
900     EXPECT_EQ(pixelMap, nullptr);
901 }
902 
903 /**
904  * @tc.name: GetSessionSnapshotById
905  * @tc.desc: test GetSessionSnapshotById
906  * @tc.type: FUNC
907  */
908 HWTEST_F(SceneSessionManagerTest, GetSessionSnapshotById, TestSize.Level1)
909 {
910     int32_t persistentId = -1;
911     SessionSnapshot snapshot;
912     WMError ret = ssm_->GetSessionSnapshotById(persistentId, snapshot);
913     EXPECT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret);
914 }
915 
916 /**
917  * @tc.name: GetUIContentRemoteObj
918  * @tc.desc: SceneSesionManager GetUIContentRemoteObj
919  * @tc.type: FUNC
920  */
921 HWTEST_F(SceneSessionManagerTest, GetUIContentRemoteObj, TestSize.Level1)
922 {
923     sptr<IRemoteObject> remoteObj;
924     EXPECT_EQ(ssm_->GetUIContentRemoteObj(65535, remoteObj), WSError::WS_ERROR_INVALID_PERMISSION);
925     SessionInfo info;
926     info.abilityName_ = "GetUIContentRemoteObj";
927     info.bundleName_ = "GetUIContentRemoteObj";
928     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
929     ASSERT_NE(sceneSession, nullptr);
930     ssm_->sceneSessionMap_.insert({ 65535, sceneSession });
931     EXPECT_EQ(ssm_->GetUIContentRemoteObj(65535, remoteObj), WSError::WS_ERROR_INVALID_PERMISSION);
932 }
933 
934 /**
935  * @tc.name: CalculateCombinedExtWindowFlags
936  * @tc.desc: SceneSesionManager calculate combined extension window flags
937  * @tc.type: FUNC
938  */
939 HWTEST_F(SceneSessionManagerTest, CalculateCombinedExtWindowFlags, TestSize.Level1)
940 {
941     EXPECT_EQ(ssm_->combinedExtWindowFlags_.bitData, 0);
942     ssm_->UpdateSpecialExtWindowFlags(1234, ExtensionWindowFlags(3), ExtensionWindowFlags(3));
943     ssm_->UpdateSpecialExtWindowFlags(5678, ExtensionWindowFlags(4), ExtensionWindowFlags(4));
944     ssm_->CalculateCombinedExtWindowFlags();
945     EXPECT_EQ(ssm_->combinedExtWindowFlags_.bitData, 7);
946     ssm_->extWindowFlagsMap_.clear();
947 }
948 
949 /**
950  * @tc.name: UpdateSpecialExtWindowFlags
951  * @tc.desc: SceneSesionManager update special extension window flags
952  * @tc.type: FUNC
953  */
954 HWTEST_F(SceneSessionManagerTest, UpdateSpecialExtWindowFlags, TestSize.Level1)
955 {
956     int32_t persistentId = 12345;
957     EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
958     ssm_->UpdateSpecialExtWindowFlags(persistentId, 3, 3);
959     EXPECT_EQ(ssm_->extWindowFlagsMap_.size(), 1);
960     EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->first, persistentId);
961     EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->second.bitData, 3);
962     ssm_->UpdateSpecialExtWindowFlags(persistentId, 0, 3);
963     EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
964     ssm_->extWindowFlagsMap_.clear();
965 }
966 
967 /**
968  * @tc.name: HideNonSecureFloatingWindows
969  * @tc.desc: SceneSesionManager hide non-secure floating windows
970  * @tc.type: FUNC
971  */
972 HWTEST_F(SceneSessionManagerTest, HideNonSecureFloatingWindows, TestSize.Level1)
973 {
974     SessionInfo info;
975     info.abilityName_ = "HideNonSecureFloatingWindows";
976     info.bundleName_ = "HideNonSecureFloatingWindows";
977 
978     sptr<SceneSession> sceneSession;
979     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
980     EXPECT_NE(sceneSession, nullptr);
981     sceneSession->state_ = SessionState::STATE_FOREGROUND;
982     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
983 
984     sptr<SceneSession> floatSession;
985     floatSession = sptr<SceneSession>::MakeSptr(info, nullptr);
986     EXPECT_NE(floatSession, nullptr);
987     floatSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
988     ssm_->nonSystemFloatSceneSessionMap_.insert(std::make_pair(floatSession->GetPersistentId(), floatSession));
989 
990     EXPECT_FALSE(ssm_->shouldHideNonSecureFloatingWindows_.load());
991     EXPECT_FALSE(floatSession->GetSessionProperty()->GetForceHide());
992     sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
993     ssm_->HideNonSecureFloatingWindows();
994     EXPECT_TRUE(floatSession->GetSessionProperty()->GetForceHide());
995     sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = false;
996     ssm_->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
997     ssm_->HideNonSecureFloatingWindows();
998     EXPECT_TRUE(floatSession->GetSessionProperty()->GetForceHide());
999 
1000     ssm_->combinedExtWindowFlags_.hideNonSecureWindowsFlag = false;
1001     ssm_->HideNonSecureFloatingWindows();
1002     ssm_->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
1003     ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1004     ssm_->HideNonSecureFloatingWindows();
1005     EXPECT_FALSE(floatSession->GetSessionProperty()->GetForceHide());
1006     ssm_->systemConfig_.windowUIType_ = WindowUIType::INVALID_WINDOW;
1007 
1008     ssm_->shouldHideNonSecureFloatingWindows_.store(false);
1009     ssm_->sceneSessionMap_.clear();
1010     ssm_->nonSystemFloatSceneSessionMap_.clear();
1011 }
1012 
1013 /**
1014  * @tc.name: HideNonSecureSubWindows
1015  * @tc.desc: SceneSesionManager hide non-secure sub windows
1016  * @tc.type: FUNC
1017  */
1018 HWTEST_F(SceneSessionManagerTest, HideNonSecureSubWindows, TestSize.Level1)
1019 {
1020     SessionInfo info;
1021     info.abilityName_ = "HideNonSecureSubWindows";
1022     info.bundleName_ = "HideNonSecureSubWindows";
1023 
1024     sptr<SceneSession> sceneSession;
1025     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1026     ASSERT_NE(sceneSession, nullptr);
1027     sceneSession->state_ = SessionState::STATE_FOREGROUND;
1028     sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
1029 
1030     sptr<SceneSession> subSession;
1031     subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1032     ASSERT_NE(subSession, nullptr);
1033     ASSERT_NE(subSession->GetSessionProperty(), nullptr);
1034     sceneSession->AddSubSession(subSession);
1035     subSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1036     subSession->GetSessionProperty()->SetParentPersistentId(sceneSession->GetPersistentId());
1037     ssm_->sceneSessionMap_.insert(std::make_pair(subSession->GetPersistentId(), subSession));
1038 
1039     EXPECT_FALSE(subSession->GetSessionProperty()->GetForceHide());
1040     sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
1041     ssm_->HideNonSecureSubWindows(sceneSession);
1042     EXPECT_TRUE(subSession->GetSessionProperty()->GetForceHide());
1043     ssm_->sceneSessionMap_.clear();
1044 }
1045 
1046 /**
1047  * @tc.name: HandleSecureSessionShouldHide
1048  * @tc.desc: SceneSesionManager handle secure session should hide
1049  * @tc.type: FUNC
1050  */
1051 HWTEST_F(SceneSessionManagerTest, HandleSecureSessionShouldHide, TestSize.Level1)
1052 {
1053     SessionInfo info;
1054     info.abilityName_ = "HandleSecureSessionShouldHide";
1055     info.bundleName_ = "HandleSecureSessionShouldHide";
1056 
1057     sptr<SceneSession> sceneSession;
1058     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1059     ASSERT_NE(sceneSession, nullptr);
1060     sceneSession->state_ = SessionState::STATE_FOREGROUND;
1061     sceneSession->combinedExtWindowFlags_.hideNonSecureWindowsFlag = true;
1062 
1063     sptr<SceneSession> subSession;
1064     subSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1065     ASSERT_NE(subSession, nullptr);
1066     ASSERT_NE(subSession->GetSessionProperty(), nullptr);
1067     sceneSession->AddSubSession(subSession);
1068     subSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1069     subSession->GetSessionProperty()->SetParentPersistentId(sceneSession->GetPersistentId());
1070     ssm_->sceneSessionMap_.insert(std::make_pair(subSession->GetPersistentId(), subSession));
1071 
1072     sptr<SceneSession> floatSession;
1073     floatSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1074     ASSERT_NE(floatSession, nullptr);
1075     ASSERT_NE(floatSession->GetSessionProperty(), nullptr);
1076     floatSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1077     ssm_->nonSystemFloatSceneSessionMap_.insert(std::make_pair(floatSession->GetPersistentId(), floatSession));
1078 
1079     sceneSession->SetShouldHideNonSecureWindows(true);
1080     auto ret = ssm_->HandleSecureSessionShouldHide(sceneSession);
1081     EXPECT_EQ(ret, WSError::WS_OK);
1082     EXPECT_TRUE(subSession->GetSessionProperty()->GetForceHide());
1083     EXPECT_TRUE(floatSession->GetSessionProperty()->GetForceHide());
1084     EXPECT_TRUE(ssm_->shouldHideNonSecureFloatingWindows_.load());
1085     ssm_->sceneSessionMap_.clear();
1086     ssm_->nonSystemFloatSceneSessionMap_.clear();
1087 }
1088 
1089 /**
1090  * @tc.name: HandleSpecialExtWindowFlagsChange
1091  * @tc.desc: SceneSesionManager handle special uiextension window flags change
1092  * @tc.type: FUNC
1093  */
1094 HWTEST_F(SceneSessionManagerTest, HandleSpecialExtWindowFlagsChange, TestSize.Level1)
1095 {
1096     int32_t persistentId = 12345;
1097     EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
1098     ssm_->HandleSpecialExtWindowFlagsChange(persistentId, 3, 3);
1099     EXPECT_EQ(ssm_->extWindowFlagsMap_.size(), 1);
1100     EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->first, persistentId);
1101     EXPECT_EQ(ssm_->extWindowFlagsMap_.begin()->second.bitData, 3);
1102     ssm_->HandleSpecialExtWindowFlagsChange(persistentId, 0, 3);
1103     EXPECT_TRUE(ssm_->extWindowFlagsMap_.empty());
1104     ssm_->extWindowFlagsMap_.clear();
1105 }
1106 
1107 /**
1108  * @tc.name: UpdateModalExtensionRect
1109  * @tc.desc: SceneSesionManager update modal extension rect
1110  * @tc.type: FUNC
1111  */
1112 HWTEST_F(SceneSessionManagerTest, UpdateModalExtensionRect, TestSize.Level1)
1113 {
1114     SessionInfo info;
1115     info.abilityName_ = "UpdateModalExtensionRect";
1116     info.bundleName_ = "UpdateModalExtensionRect";
1117     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1118     ASSERT_NE(sceneSession, nullptr);
1119     Rect rect{ 1, 2, 3, 4 };
1120     ssm_->UpdateModalExtensionRect(nullptr, rect);
1121     EXPECT_FALSE(sceneSession->GetLastModalUIExtensionEventInfo());
1122 }
1123 
1124 /**
1125  * @tc.name: ProcessModalExtensionPointDown
1126  * @tc.desc: SceneSesionManager process modal extension point down
1127  * @tc.type: FUNC
1128  */
1129 HWTEST_F(SceneSessionManagerTest, ProcessModalExtensionPointDown, TestSize.Level1)
1130 {
1131     SessionInfo info;
1132     info.abilityName_ = "ProcessModalExtensionPointDown";
1133     info.bundleName_ = "ProcessModalExtensionPointDown";
1134     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1135     ASSERT_NE(sceneSession, nullptr);
1136 
1137     ssm_->ProcessModalExtensionPointDown(nullptr, 0, 0);
1138     EXPECT_FALSE(sceneSession->GetLastModalUIExtensionEventInfo());
1139 }
1140 
1141 /**
1142  * @tc.name: GetExtensionWindowIds
1143  * @tc.desc: SceneSesionManager get extension window ids
1144  * @tc.type: FUNC
1145  */
1146 HWTEST_F(SceneSessionManagerTest, GetExtensionWindowIds, TestSize.Level1)
1147 {
1148     SessionInfo info;
1149     info.abilityName_ = "GetExtensionWindowIds";
1150     info.bundleName_ = "GetExtensionWindowIds";
1151     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1152     ASSERT_NE(sceneSession, nullptr);
1153 
1154     int32_t persistentId = 0;
1155     int32_t parentId = 0;
1156     EXPECT_FALSE(ssm_->GetExtensionWindowIds(nullptr, persistentId, parentId));
1157 }
1158 
1159 /**
1160  * @tc.name: AddOrRemoveSecureSession
1161  * @tc.desc: SceneSesionManager hide non-secure windows by scene session
1162  * @tc.type: FUNC
1163  */
1164 HWTEST_F(SceneSessionManagerTest, AddOrRemoveSecureSession, TestSize.Level1)
1165 {
1166     SessionInfo info;
1167     info.abilityName_ = "AddOrRemoveSecureSession";
1168     info.bundleName_ = "AddOrRemoveSecureSession1";
1169 
1170     int32_t persistentId = 12345;
1171     auto ret = ssm_->AddOrRemoveSecureSession(persistentId, true);
1172     EXPECT_EQ(ret, WSError::WS_OK);
1173 }
1174 
1175 /**
1176  * @tc.name: UpdateExtWindowFlags
1177  * @tc.desc: SceneSesionManager update uiextension window flags
1178  * @tc.type: FUNC
1179  */
1180 HWTEST_F(SceneSessionManagerTest, UpdateExtWindowFlags, TestSize.Level1)
1181 {
1182     MockAccesstokenKit::MockAccessTokenKitRet(-1);
1183     SessionInfo info;
1184     info.abilityName_ = "UpdateExtWindowFlags";
1185     info.bundleName_ = "UpdateExtWindowFlags";
1186 
1187     auto ret = ssm_->UpdateExtWindowFlags(nullptr, 7, 7);
1188     EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
1189 }
1190 
1191 /**
1192  * @tc.name: SetScreenLocked001
1193  * @tc.desc: SetScreenLocked001
1194  * @tc.type: FUNC
1195  */
1196 HWTEST_F(SceneSessionManagerTest, SetScreenLocked001, TestSize.Level1)
1197 {
1198     sptr<SceneSession> sceneSession = nullptr;
1199     SessionInfo info;
1200     info.bundleName_ = "bundleName";
1201     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1202     ASSERT_NE(nullptr, sceneSession);
1203     sceneSession->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
1204     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
1205     DetectTaskInfo detectTaskInfo;
1206     detectTaskInfo.taskState = DetectTaskState::ATTACH_TASK;
1207     detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_UNDEFINED;
1208     sceneSession->SetDetectTaskInfo(detectTaskInfo);
1209     std::string taskName = "wms:WindowStateDetect" + std::to_string(sceneSession->persistentId_);
__anone0db31a60802() 1210     auto task = []() {};
1211     int64_t delayTime = 3000;
1212     sceneSession->handler_->PostTask(task, taskName, delayTime);
1213     int32_t beforeTaskNum = GetTaskCount(sceneSession);
1214     ssm_->SetScreenLocked(true);
1215     sleep(1);
1216     ASSERT_EQ(beforeTaskNum - 1, GetTaskCount(sceneSession));
1217     ASSERT_EQ(DetectTaskState::NO_TASK, sceneSession->detectTaskInfo_.taskState);
1218     ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, sceneSession->detectTaskInfo_.taskWindowMode);
1219 }
1220 
1221 /**
1222  * @tc.name: AccessibilityFillEmptySceneSessionListToNotifyList
1223  * @tc.desc: SceneSesionManager fill empty scene session list to accessibilityList;
1224  * @tc.type: FUNC
1225  */
1226 HWTEST_F(SceneSessionManagerTest, AccessibilityFillEmptySceneSessionListToNotifyList, TestSize.Level1)
1227 {
1228     std::vector<sptr<SceneSession>> sceneSessionList;
1229     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1230 
1231     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1232     EXPECT_EQ(accessibilityInfo.size(), 0);
1233 }
1234 
1235 /**
1236  * @tc.name: AccessibilityFillOneSceneSessionListToNotifyList
1237  * @tc.desc: SceneSesionManager fill one sceneSession to accessibilityList;
1238  * @tc.type: FUNC
1239  */
1240 HWTEST_F(SceneSessionManagerTest, AccessibilityFillOneSceneSessionListToNotifyList, TestSize.Level1)
1241 {
1242     SessionInfo sessionInfo;
1243     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1244     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1245 
1246     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1247     ASSERT_NE(sceneSession, nullptr);
1248     SetVisibleForAccessibility(sceneSession);
1249     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1250 
1251     std::vector<sptr<SceneSession>> sceneSessionList;
1252     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1253     ASSERT_EQ(sceneSessionList.size(), 1);
1254 
1255     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1256     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1257     ASSERT_EQ(accessibilityInfo.size(), 1);
1258 }
1259 
1260 /**
1261  * @tc.name: AccessibilityFillTwoSceneSessionListToNotifyList
1262  * @tc.desc: SceneSesionManager fill two sceneSessions to accessibilityList;
1263  * @tc.type: FUNC
1264  */
1265 HWTEST_F(SceneSessionManagerTest, AccessibilityFillTwoSceneSessionListToNotifyList, TestSize.Level1)
1266 {
1267     SessionInfo sessionInfo;
1268     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1269     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1270 
1271     sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr);
1272     ASSERT_NE(sceneSessionFirst, nullptr);
1273     SetVisibleForAccessibility(sceneSessionFirst);
1274 
1275     sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr);
1276     ASSERT_NE(sceneSessionSecond, nullptr);
1277     SetVisibleForAccessibility(sceneSessionSecond);
1278 
1279     ssm_->sceneSessionMap_.insert({ sceneSessionFirst->GetPersistentId(), sceneSessionFirst });
1280     ssm_->sceneSessionMap_.insert({ sceneSessionSecond->GetPersistentId(), sceneSessionSecond });
1281 
1282     std::vector<sptr<SceneSession>> sceneSessionList;
1283     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1284     ASSERT_EQ(sceneSessionList.size(), 2);
1285 
1286     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1287     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1288     ASSERT_EQ(accessibilityInfo.size(), 2);
1289 }
1290 
1291 /**
1292  * @tc.name: AccessibilityFillEmptyBundleName
1293  * @tc.desc: SceneSesionManager fill empty bundle name to accessibilityInfo;
1294  * @tc.type: FUNC
1295  */
1296 HWTEST_F(SceneSessionManagerTest, AccessibilityFillEmptyBundleName, TestSize.Level1)
1297 {
1298     SessionInfo sessionInfo;
1299     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1300 
1301     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1302     ASSERT_NE(sceneSession, nullptr);
1303     SetVisibleForAccessibility(sceneSession);
1304     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1305 
1306     std::vector<sptr<SceneSession>> sceneSessionList;
1307     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1308     ASSERT_EQ(sceneSessionList.size(), 1);
1309 
1310     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1311     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1312     ASSERT_EQ(accessibilityInfo.size(), 1);
1313 
1314     ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, "");
1315     ASSERT_EQ(sceneSessionList.at(0)->GetSessionInfo().bundleName_, "");
1316     ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, sceneSessionList.at(0)->GetSessionInfo().bundleName_);
1317 }
1318 
1319 /**
1320  * @tc.name: AccessibilityFillBundleName
1321  * @tc.desc: SceneSesionManager fill bundle name to accessibilityInfo;
1322  * @tc.type: FUNC
1323  */
1324 HWTEST_F(SceneSessionManagerTest, AccessibilityFillBundleName, TestSize.Level1)
1325 {
1326     SessionInfo sessionInfo;
1327     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1328     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1329 
1330     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1331     ASSERT_NE(sceneSession, nullptr);
1332     SetVisibleForAccessibility(sceneSession);
1333     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1334 
1335     std::vector<sptr<SceneSession>> sceneSessionList;
1336     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1337     ASSERT_EQ(sceneSessionList.size(), 1);
1338 
1339     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1340     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1341     ASSERT_EQ(accessibilityInfo.size(), 1);
1342 
1343     ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, "accessibilityNotifyTesterBundleName");
1344     ASSERT_EQ(sceneSessionList.at(0)->GetSessionInfo().bundleName_, "accessibilityNotifyTesterBundleName");
1345     ASSERT_EQ(accessibilityInfo.at(0)->bundleName_, sceneSessionList.at(0)->GetSessionInfo().bundleName_);
1346 }
1347 
1348 /**
1349  * @tc.name: AccessibilityFillFilterBundleName
1350  * @tc.desc: SceneSesionManager fill filter bundle name to accessibilityInfo;
1351  * @tc.type: FUNC
1352  */
1353 HWTEST_F(SceneSessionManagerTest, AccessibilityFillFilterBundleName, TestSize.Level1)
1354 {
1355     SessionInfo sessionInfo;
1356     sessionInfo.bundleName_ = "SCBGestureTopBar";
1357     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1358 
1359     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1360     ASSERT_NE(sceneSession, nullptr);
1361     SetVisibleForAccessibility(sceneSession);
1362     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1363 
1364     std::vector<sptr<SceneSession>> sceneSessionList;
1365     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1366     ASSERT_EQ(sceneSessionList.size(), 0);
1367 
1368     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1369     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1370     ASSERT_EQ(accessibilityInfo.size(), 0);
1371 }
1372 
1373 /**
1374  * @tc.name: AccessibilityFillEmptyHotAreas
1375  * @tc.desc: SceneSesionManager fill empty hot areas to accessibilityInfo;
1376  * @tc.type: FUNC
1377  */
1378 HWTEST_F(SceneSessionManagerTest, AccessibilityFillEmptyHotAreas, TestSize.Level1)
1379 {
1380     SessionInfo sessionInfo;
1381     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1382     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1383 
1384     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1385     ASSERT_NE(sceneSession, nullptr);
1386     SetVisibleForAccessibility(sceneSession);
1387     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1388 
1389     std::vector<sptr<SceneSession>> sceneSessionList;
1390     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1391 
1392     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1393     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1394     ASSERT_EQ(accessibilityInfo.size(), 1);
1395 
1396     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size());
1397     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 0);
1398 }
1399 
1400 /**
1401  * @tc.name: AccessibilityFillOneHotAreas
1402  * @tc.desc: SceneSesionManager fill one hot areas to accessibilityInfo;
1403  * @tc.type: FUNC
1404  */
1405 HWTEST_F(SceneSessionManagerTest, AccessibilityFillOneHotAreas, TestSize.Level1)
1406 {
1407     SessionInfo sessionInfo;
1408     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1409     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1410 
1411     Rect rect = { 100, 200, 100, 200 };
1412     std::vector<Rect> hotAreas;
1413     hotAreas.push_back(rect);
1414     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1415     ASSERT_NE(sceneSession, nullptr);
1416     sceneSession->SetTouchHotAreas(hotAreas);
1417     SetVisibleForAccessibility(sceneSession);
1418     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1419 
1420     std::vector<sptr<SceneSession>> sceneSessionList;
1421     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1422 
1423     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1424     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1425     ASSERT_EQ(accessibilityInfo.size(), 1);
1426 
1427     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size());
1428     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 1);
1429 
1430     ASSERT_EQ(rect.posX_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).posX_);
1431     ASSERT_EQ(rect.posY_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).posY_);
1432     ASSERT_EQ(rect.width_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).width_);
1433     ASSERT_EQ(rect.height_, sceneSessionList.at(0)->GetTouchHotAreas().at(0).height_);
1434 
1435     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posX_, rect.posX_);
1436     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posY_, rect.posY_);
1437     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).width_, rect.width_);
1438     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).height_, rect.height_);
1439 }
1440 
1441 /**
1442  * @tc.name: AccessibilityFillTwoHotAreas
1443  * @tc.desc: SceneSesionManager fill two hot areas to accessibilityInfo;
1444  * @tc.type: FUNC
1445  */
1446 HWTEST_F(SceneSessionManagerTest, AccessibilityFillTwoHotAreas, TestSize.Level1)
1447 {
1448     SessionInfo sessionInfo;
1449     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1450     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1451 
1452     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1453     std::vector<Rect> hotAreas;
1454     Rect rectFitst = { 100, 200, 100, 200 };
1455     Rect rectSecond = { 50, 50, 20, 30 };
1456     hotAreas.push_back(rectFitst);
1457     hotAreas.push_back(rectSecond);
1458     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1459     ASSERT_NE(sceneSession, nullptr);
1460     sceneSession->SetTouchHotAreas(hotAreas);
1461     SetVisibleForAccessibility(sceneSession);
1462     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1463 
1464     std::vector<sptr<SceneSession>> sceneSessionList;
1465     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1466 
1467     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1468     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1469     ASSERT_EQ(accessibilityInfo.size(), 1);
1470 
1471     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), sceneSessionList.at(0)->GetTouchHotAreas().size());
1472     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.size(), 2);
1473 
1474     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posX_, rectFitst.posX_);
1475     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).posY_, rectFitst.posY_);
1476     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).width_, rectFitst.width_);
1477     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(0).height_, rectFitst.height_);
1478 
1479     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).posX_, rectSecond.posX_);
1480     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).posY_, rectSecond.posY_);
1481     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).width_, rectSecond.width_);
1482     ASSERT_EQ(accessibilityInfo.at(0)->touchHotAreas_.at(1).height_, rectSecond.height_);
1483 }
1484 
1485 /**
1486  * @tc.name: AccessibilityFilterEmptySceneSessionList
1487  * @tc.desc: SceneSesionManager filter empty scene session list;
1488  * @tc.type: FUNC
1489  */
1490 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterEmptySceneSessionList, TestSize.Level1)
1491 {
1492     std::vector<sptr<SceneSession>> sceneSessionList;
1493 
1494     ssm_->FilterSceneSessionCovered(sceneSessionList);
1495     ASSERT_EQ(sceneSessionList.size(), 0);
1496 }
1497 
1498 /**
1499  * @tc.name: AccessibilityFilterOneWindow
1500  * @tc.desc: SceneSesionManager filter one window;
1501  * @tc.type: FUNC
1502  */
1503 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterOneWindow, TestSize.Level1)
1504 {
1505     SessionInfo sessionInfo;
1506     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1507     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1508 
1509     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(sessionInfo, nullptr);
1510     ASSERT_NE(sceneSession, nullptr);
1511     sceneSession->SetSessionRect({ 100, 100, 200, 200 });
1512     SetVisibleForAccessibility(sceneSession);
1513     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1514 
1515     std::vector<sptr<SceneSession>> sceneSessionList;
1516     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1517     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1518     ssm_->FilterSceneSessionCovered(sceneSessionList);
1519     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1520     ASSERT_EQ(accessibilityInfo.size(), 1);
1521 }
1522 
1523 /**
1524  * @tc.name: AccessibilityFilterTwoWindowNotCovered
1525  * @tc.desc: SceneSesionManager filter two windows that not covered each other;
1526  * @tc.type: FUNC
1527  */
1528 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterTwoWindowNotCovered, TestSize.Level1)
1529 {
1530     SessionInfo sessionInfo;
1531     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1532     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1533 
1534     sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr);
1535     ASSERT_NE(sceneSessionFirst, nullptr);
1536     sceneSessionFirst->SetSessionRect({ 0, 0, 200, 200 });
1537     SetVisibleForAccessibility(sceneSessionFirst);
1538     ssm_->sceneSessionMap_.insert({ sceneSessionFirst->GetPersistentId(), sceneSessionFirst });
1539 
1540     sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr);
1541     ASSERT_NE(sceneSessionSecond, nullptr);
1542     sceneSessionSecond->SetSessionRect({ 300, 300, 200, 200 });
1543     SetVisibleForAccessibility(sceneSessionSecond);
1544     ssm_->sceneSessionMap_.insert({ sceneSessionSecond->GetPersistentId(), sceneSessionSecond });
1545 
1546     std::vector<sptr<SceneSession>> sceneSessionList;
1547     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1548     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1549     ssm_->FilterSceneSessionCovered(sceneSessionList);
1550     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1551     ASSERT_EQ(accessibilityInfo.size(), 2);
1552 }
1553 
1554 /**
1555  * @tc.name: AccessibilityFilterTwoWindowCovered
1556  * @tc.desc: SceneSesionManager filter two windows that covered each other;
1557  * @tc.type: FUNC
1558  */
1559 HWTEST_F(SceneSessionManagerTest, AccessibilityFilterTwoWindowCovered, TestSize.Level1)
1560 {
1561     SessionInfo sessionInfo;
1562     sessionInfo.bundleName_ = "accessibilityNotifyTesterBundleName";
1563     sessionInfo.abilityName_ = "accessibilityNotifyTesterAbilityName";
1564 
1565     sptr<SceneSession> sceneSessionFirst = ssm_->CreateSceneSession(sessionInfo, nullptr);
1566     ASSERT_NE(sceneSessionFirst, nullptr);
1567     sceneSessionFirst->SetSessionRect({ 0, 0, 200, 200 });
1568     SetVisibleForAccessibility(sceneSessionFirst);
1569     sceneSessionFirst->SetZOrder(20);
1570     ssm_->sceneSessionMap_.insert({ sceneSessionFirst->GetPersistentId(), sceneSessionFirst });
1571 
1572     sptr<SceneSession> sceneSessionSecond = ssm_->CreateSceneSession(sessionInfo, nullptr);
1573     ASSERT_NE(sceneSessionSecond, nullptr);
1574     sceneSessionSecond->SetSessionRect({ 50, 50, 50, 50 });
1575     SetVisibleForAccessibility(sceneSessionSecond);
1576     sceneSessionSecond->SetZOrder(10);
1577     ssm_->sceneSessionMap_.insert({ sceneSessionSecond->GetPersistentId(), sceneSessionSecond });
1578 
1579     std::vector<sptr<SceneSession>> sceneSessionList;
1580     std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1581     ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
1582     ssm_->FilterSceneSessionCovered(sceneSessionList);
1583     ssm_->FillAccessibilityInfo(sceneSessionList, accessibilityInfo);
1584     ASSERT_EQ(accessibilityInfo.size(), 1);
1585 }
1586 
1587 /**
1588  * @tc.name: GetMainWindowInfos
1589  * @tc.desc: SceneSesionManager get topN main window infos;
1590  * @tc.type: FUNC
1591  */
1592 HWTEST_F(SceneSessionManagerTest, GetMainWindowInfos, TestSize.Level1)
1593 {
1594     int32_t topNum = 1024;
1595     std::vector<MainWindowInfo> topNInfos;
1596     auto result = ssm_->GetMainWindowInfos(topNum, topNInfos);
1597     EXPECT_EQ(result, WMError::WM_OK);
1598 
1599     topNum = 0;
1600     ssm_->GetMainWindowInfos(topNum, topNInfos);
1601 
1602     topNum = 1000;
1603     MainWindowInfo info;
1604     topNInfos.push_back(info);
1605     ssm_->GetMainWindowInfos(topNum, topNInfos);
1606 }
1607 
1608 /**
1609  * @tc.name: GetAllWindowVisibilityInfos
1610  * @tc.desc: SceneSesionManager get all window visibility infos;
1611  * @tc.type: FUNC
1612  */
1613 HWTEST_F(SceneSessionManagerTest, GetAllWindowVisibilityInfos, TestSize.Level1)
1614 {
1615     ASSERT_NE(ssm_, nullptr);
1616     ssm_->sceneSessionMap_.clear();
1617     SessionInfo info;
1618     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, nullptr);
1619     ASSERT_NE(nullptr, sceneSession);
1620     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1621     std::vector<std::pair<int32_t, uint32_t>> windowVisibilityInfos;
1622     ssm_->GetAllWindowVisibilityInfos(windowVisibilityInfos);
1623     EXPECT_NE(windowVisibilityInfos.size(), 0);
1624 }
1625 
1626 /**
1627  * @tc.name: TestNotifyEnterRecentTask
1628  * @tc.desc: Test whether the enterRecent_ is set correctly;
1629  * @tc.type: FUNC
1630  */
1631 HWTEST_F(SceneSessionManagerTest, TestNotifyEnterRecentTask, TestSize.Level1)
1632 {
1633     GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestNotifyEnterRecentTask start";
1634     sptr<SceneSessionManager> sceneSessionManager = sptr<SceneSessionManager>::MakeSptr();
1635     ASSERT_NE(nullptr, sceneSessionManager);
1636 
1637     ASSERT_EQ(sceneSessionManager->NotifyEnterRecentTask(true), WSError::WS_OK);
1638     ASSERT_EQ(sceneSessionManager->enterRecent_.load(), true);
1639 }
1640 
1641 /**
1642  * @tc.name: TestIsEnablePiPCreate
1643  * @tc.desc: Test if pip window can be created;
1644  * @tc.type: FUNC
1645  */
1646 HWTEST_F(SceneSessionManagerTest, TestIsEnablePiPCreate, TestSize.Level1)
1647 {
1648     GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestIsEnablePiPCreate start";
1649     ssm_->isScreenLocked_ = true;
1650     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1651     ASSERT_TRUE(!ssm_->IsEnablePiPCreate(property));
1652 
1653     ssm_->isScreenLocked_ = false;
1654     Rect reqRect = { 0, 0, 0, 0 };
1655     property->SetRequestRect(reqRect);
1656     ASSERT_TRUE(!ssm_->IsEnablePiPCreate(property));
1657 
1658     reqRect = { 0, 0, 10, 0 };
1659     property->SetRequestRect(reqRect);
1660     ASSERT_TRUE(!ssm_->IsEnablePiPCreate(property));
1661 
1662     reqRect = { 0, 0, 10, 10 };
1663     property->SetRequestRect(reqRect);
1664     PiPTemplateInfo info = {};
1665     property->SetPiPTemplateInfo(info);
1666     SessionInfo info1;
1667     info1.abilityName_ = "test1";
1668     info1.bundleName_ = "test2";
1669     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
1670     ASSERT_NE(nullptr, sceneSession);
1671     property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1672     sceneSession->pipTemplateInfo_ = {};
1673     sceneSession->pipTemplateInfo_.priority = 100;
1674     ssm_->sceneSessionMap_.insert({ 0, sceneSession });
1675     ASSERT_TRUE(!ssm_->IsEnablePiPCreate(property));
1676     ssm_->sceneSessionMap_.clear();
1677     ASSERT_TRUE(!ssm_->IsEnablePiPCreate(property));
1678 
1679     property->SetParentPersistentId(100);
1680     ASSERT_TRUE(!ssm_->IsEnablePiPCreate(property));
1681 
1682     ssm_->sceneSessionMap_.insert({ 100, sceneSession });
1683     ASSERT_TRUE(!ssm_->IsEnablePiPCreate(property));
1684 
1685     ssm_->sceneSessionMap_.clear();
1686     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1687     ssm_->sceneSessionMap_.insert({ 100, sceneSession });
1688     ASSERT_TRUE(ssm_->IsEnablePiPCreate(property));
1689 }
1690 
1691 /**
1692  * @tc.name: TestIsPiPForbidden
1693  * @tc.desc: Test if pip window is forbidden to use;
1694  * @tc.type: FUNC
1695  */
1696 HWTEST_F(SceneSessionManagerTest, TestIsPiPForbidden, TestSize.Level1)
1697 {
1698     GTEST_LOG_(INFO) << "SceneSessionManagerTest: TestIsPiPForbidden start";
1699     int32_t persistentId = 1001;
1700     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1701     ASSERT_NE(nullptr, property);
1702     property->SetParentPersistentId(persistentId);
1703     ASSERT_TRUE(!ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_PIP));
1704 
1705     SessionInfo sessionInfo;
1706     sessionInfo.persistentId_ = persistentId;
1707     sessionInfo.bundleName_ = "test1";
1708     sessionInfo.abilityName_ = "test2";
1709     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1710     ASSERT_NE(nullptr, sceneSession);
1711     property->SetDisplayId(-1ULL);
1712     sceneSession->SetSessionProperty(property);
1713     ssm_->sceneSessionMap_.insert({ persistentId, sceneSession });
1714     ASSERT_TRUE(!ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_PIP));
1715 
1716     uint64_t displayId = 1001;
1717     property->SetDisplayId(displayId);
1718     sceneSession->SetSessionProperty(property);
1719     ssm_->sceneSessionMap_[persistentId] = sceneSession;
1720     sptr<ScreenSession> screenSession = new ScreenSession();
1721     screenSession->SetName("HiCar");
1722     ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert({ displayId, screenSession });
1723     ASSERT_TRUE(ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_PIP));
1724     ASSERT_TRUE(!ssm_->IsPiPForbidden(property, WindowType::WINDOW_TYPE_FLOAT));
1725 }
1726 
1727 /**
1728  * @tc.name: GetAllMainWindowInfos
1729  * @tc.desc: GetAllMainWindowInfos
1730  * @tc.type: FUNC
1731  */
1732 HWTEST_F(SceneSessionManagerTest, GetAllMainWindowInfos, TestSize.Level1)
1733 {
1734     SessionInfo info;
1735     info.abilityName_ = "test";
1736     info.bundleName_ = "test";
1737     info.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
1738     info.persistentId_ = 100;
1739     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1740     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1741     std::vector<MainWindowInfo> infos;
1742     WMError result = ssm_->GetAllMainWindowInfos(infos);
1743     ASSERT_EQ(result, WMError::WM_OK);
1744     ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
1745 }
1746 
1747 /**
1748  * @tc.name: GetAllMainWindowInfos001
1749  * @tc.desc: SceneSessionManager get all main window infos.
1750  * @tc.type: FUNC
1751  */
1752 HWTEST_F(SceneSessionManagerTest, GetAllMainWindowInfos001, TestSize.Level1)
1753 {
1754     SessionInfo info;
1755     info.abilityName_ = "test1";
1756     info.bundleName_ = "test1";
1757     info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1758     info.persistentId_ = 1;
1759     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1760     AppExecFwk::ApplicationInfo applicationInfo;
1761     applicationInfo.bundleType = AppExecFwk::BundleType::ATOMIC_SERVICE;
1762     abilityInfo->applicationInfo = applicationInfo;
1763     info.abilityInfo = abilityInfo;
1764     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1765     ASSERT_NE(nullptr, sceneSession);
1766     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1767     std::vector<MainWindowInfo> infos;
1768     WMError result = ssm_->GetAllMainWindowInfos(infos);
1769     EXPECT_EQ(result, WMError::WM_OK);
1770     ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
1771 }
1772 
1773 /**
1774  * @tc.name: GetAllMainWindowInfos002
1775  * @tc.desc: SceneSessionManager get all main window infos, input params are not empty.
1776  * @tc.type: FUNC
1777  */
1778 HWTEST_F(SceneSessionManagerTest, GetAllMainWindowInfos002, TestSize.Level1)
1779 {
1780     std::vector<MainWindowInfo> infos;
1781     MainWindowInfo info;
1782     info.pid_ = 1000;
1783     info.bundleName_ = "test";
1784     infos.push_back(info);
1785     WMError result = ssm_->GetAllMainWindowInfos(infos);
1786     EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
1787 }
1788 
1789 /**
1790  * @tc.name: GetUnreliableWindowInfo01
1791  * @tc.desc: SceneSesionManager get unreliable window info, windowId correct
1792  * @tc.type: FUNC
1793  */
1794 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo01, TestSize.Level1)
1795 {
1796     ssm_->sceneSessionMap_.clear();
1797     SessionInfo info;
1798     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, nullptr);
1799     ASSERT_NE(nullptr, sceneSession);
1800     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1801 
1802     int32_t windowId = sceneSession->GetPersistentId();
1803     std::vector<sptr<UnreliableWindowInfo>> infos;
1804     WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1805     EXPECT_EQ(WMError::WM_OK, result);
1806     EXPECT_EQ(1, infos.size());
1807 }
1808 
1809 /**
1810  * @tc.name: GetUnreliableWindowInfo02
1811  * @tc.desc: SceneSesionManager get unreliable window info, toast window
1812  * @tc.type: FUNC
1813  */
1814 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo02, TestSize.Level1)
1815 {
1816     ssm_->sceneSessionMap_.clear();
1817     SessionInfo info;
1818     info.windowType_ = 2107;
1819     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1820     ASSERT_NE(nullptr, property);
1821     property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
1822     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1823     ASSERT_NE(nullptr, sceneSession);
1824     sceneSession->SetRSVisible(true);
1825     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1826 
1827     int32_t windowId = 0;
1828     std::vector<sptr<UnreliableWindowInfo>> infos;
1829     WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1830     EXPECT_EQ(WMError::WM_OK, result);
1831     EXPECT_EQ(1, infos.size());
1832 }
1833 
1834 /**
1835  * @tc.name: GetUnreliableWindowInfo03
1836  * @tc.desc: SceneSesionManager get unreliable window info, app sub window
1837  * @tc.type: FUNC
1838  */
1839 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo03, TestSize.Level1)
1840 {
1841     ssm_->sceneSessionMap_.clear();
1842     SessionInfo info;
1843     info.windowType_ = 1000;
1844     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1845     ASSERT_NE(nullptr, property);
1846     property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1847     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1848     ASSERT_NE(nullptr, sceneSession);
1849     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1850 
1851     SessionInfo info2;
1852     info2.windowType_ = 1001;
1853     sptr<WindowSessionProperty> property2 = sptr<WindowSessionProperty>::MakeSptr();
1854     ASSERT_NE(nullptr, property2);
1855     property2->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1856     property2->SetParentId(sceneSession->GetPersistentId());
1857     sptr<SceneSession> sceneSession2 = ssm_->CreateSceneSession(info2, property2);
1858     ASSERT_NE(nullptr, sceneSession2);
1859     sceneSession2->SetRSVisible(true);
1860     ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1861 
1862     int32_t windowId = 0;
1863     std::vector<sptr<UnreliableWindowInfo>> infos;
1864     WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1865     EXPECT_EQ(WMError::WM_OK, result);
1866     EXPECT_EQ(1, infos.size());
1867 }
1868 
1869 /**
1870  * @tc.name: GetUnreliableWindowInfo04
1871  * @tc.desc: SceneSesionManager get unreliable window info, input method window
1872  * @tc.type: FUNC
1873  */
1874 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo04, TestSize.Level1)
1875 {
1876     ssm_->sceneSessionMap_.clear();
1877     SessionInfo info;
1878     info.windowType_ = 2105;
1879     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1880     ASSERT_NE(nullptr, property);
1881     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1882     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1883     ASSERT_NE(nullptr, sceneSession);
1884     sceneSession->SetRSVisible(true);
1885     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1886 
1887     int32_t windowId = 0;
1888     std::vector<sptr<UnreliableWindowInfo>> infos;
1889     WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1890     EXPECT_EQ(WMError::WM_OK, result);
1891     EXPECT_EQ(1, infos.size());
1892 }
1893 
1894 /**
1895  * @tc.name: GetUnreliableWindowInfo05
1896  * @tc.desc: SceneSesionManager get unreliable window info, not correct window type, not visible
1897  * @tc.type: FUNC
1898  */
1899 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo05, TestSize.Level1)
1900 {
1901     ssm_->sceneSessionMap_.clear();
1902     SessionInfo info;
1903     info.windowType_ = 2122;
1904     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1905     ASSERT_NE(nullptr, property);
1906     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1907     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1908     ASSERT_NE(nullptr, sceneSession);
1909     sceneSession->SetRSVisible(true);
1910     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1911     ssm_->sceneSessionMap_.insert({ 0, nullptr });
1912 
1913     int32_t windowId = 0;
1914     std::vector<sptr<UnreliableWindowInfo>> infos;
1915     WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1916     EXPECT_EQ(WMError::WM_OK, result);
1917     sceneSession->SetRSVisible(false);
1918     result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1919     EXPECT_EQ(WMError::WM_OK, result);
1920     EXPECT_EQ(0, infos.size());
1921 }
1922 
1923 /**
1924  * @tc.name: GetUnreliableWindowInfo06
1925  * @tc.desc: SceneSesionManager satisfy FillUnreliableWindowInfo branches coverage
1926  * @tc.type: FUNC
1927  */
1928 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo06, TestSize.Level1)
1929 {
1930     ssm_->sceneSessionMap_.clear();
1931     SessionInfo info1;
1932     info1.bundleName_ = "SCBGestureBack";
1933     sptr<SceneSession> sceneSession1 = ssm_->CreateSceneSession(info1, nullptr);
1934     ASSERT_NE(nullptr, sceneSession1);
1935     ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1936 
1937     SessionInfo info2;
1938     info2.bundleName_ = "SCBGestureNavBar";
1939     sptr<SceneSession> sceneSession2 = ssm_->CreateSceneSession(info2, nullptr);
1940     ASSERT_NE(nullptr, sceneSession2);
1941     ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1942 
1943     SessionInfo info3;
1944     info3.bundleName_ = "SCBGestureTopBar";
1945     sptr<SceneSession> sceneSession3 = ssm_->CreateSceneSession(info3, nullptr);
1946     ASSERT_NE(nullptr, sceneSession3);
1947     ssm_->sceneSessionMap_.insert({ sceneSession3->GetPersistentId(), sceneSession3 });
1948 
1949     std::vector<sptr<UnreliableWindowInfo>> infos;
1950     ssm_->GetUnreliableWindowInfo(sceneSession1->GetPersistentId(), infos);
1951     ssm_->GetUnreliableWindowInfo(sceneSession2->GetPersistentId(), infos);
1952     ssm_->GetUnreliableWindowInfo(sceneSession3->GetPersistentId(), infos);
1953     EXPECT_EQ(0, infos.size());
1954 }
1955 
1956 /**
1957  * @tc.name: GetUnreliableWindowInfo07
1958  * @tc.desc: system touchable
1959  * @tc.type: FUNC
1960  */
1961 HWTEST_F(SceneSessionManagerTest, GetUnreliableWindowInfo07, TestSize.Level1)
1962 {
1963     ssm_->sceneSessionMap_.clear();
1964     SessionInfo info;
1965     info.windowType_ = 2122;
1966     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1967     ASSERT_NE(nullptr, property);
1968     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1969     sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
1970     ASSERT_NE(nullptr, sceneSession);
1971     sceneSession->SetRSVisible(true);
1972     sceneSession->SetSystemTouchable(false);
1973     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1974     ssm_->sceneSessionMap_.insert({ 0, nullptr });
1975 
1976     int32_t windowId = 0;
1977     std::vector<sptr<UnreliableWindowInfo>> infos;
1978     WMError result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1979     EXPECT_EQ(WMError::WM_OK, result);
1980     sceneSession->SetRSVisible(false);
1981     result = ssm_->GetUnreliableWindowInfo(windowId, infos);
1982     EXPECT_EQ(WMError::WM_OK, result);
1983     EXPECT_EQ(0, infos.size());
1984 }
1985 
1986 /**
1987  * @tc.name: SkipSnapshotForAppProcess
1988  * @tc.desc: add or cancel snapshot skip for app process
1989  * @tc.type: FUNC
1990  */
1991 HWTEST_F(SceneSessionManagerTest, SkipSnapshotForAppProcess, TestSize.Level1)
1992 {
1993     int32_t pid = 1000;
1994     bool skip = true;
1995     auto result = ssm_->SkipSnapshotForAppProcess(pid, skip);
1996     ASSERT_EQ(result, WMError::WM_OK);
1997     usleep(WAIT_SYNC_FOR_SNAPSHOT_SKIP_IN_NS);
1998     ASSERT_NE(ssm_->snapshotSkipPidSet_.find(pid), ssm_->snapshotSkipPidSet_.end());
1999 
2000     skip = false;
2001     result = ssm_->SkipSnapshotForAppProcess(pid, skip);
2002     ASSERT_EQ(result, WMError::WM_OK);
2003     usleep(WAIT_SYNC_FOR_SNAPSHOT_SKIP_IN_NS);
2004     ASSERT_EQ(ssm_->snapshotSkipPidSet_.find(pid), ssm_->snapshotSkipPidSet_.end());
2005 
2006     SessionInfo info;
2007     sptr<SceneSession> sceneSession1 = ssm_->CreateSceneSession(info, nullptr);
2008     sptr<SceneSession> sceneSession2 = ssm_->CreateSceneSession(info, nullptr);
2009     ASSERT_NE(nullptr, sceneSession1);
2010     ASSERT_NE(nullptr, sceneSession2);
2011     sceneSession1->SetCallingPid(1000);
2012     sceneSession2->SetCallingPid(1001);
2013     ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
2014     ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
2015     ssm_->sceneSessionMap_.insert({ -1, nullptr });
2016     skip = true;
2017     result = ssm_->SkipSnapshotForAppProcess(pid, skip);
2018     usleep(WAIT_SYNC_FOR_SNAPSHOT_SKIP_IN_NS);
2019     ASSERT_EQ(result, WMError::WM_OK);
2020     skip = false;
2021     result = ssm_->SkipSnapshotForAppProcess(pid, skip);
2022     ASSERT_EQ(result, WMError::WM_OK);
2023     ssm_->sceneSessionMap_.erase(sceneSession1->GetPersistentId());
2024     ssm_->sceneSessionMap_.erase(sceneSession2->GetPersistentId());
2025     ssm_->sceneSessionMap_.erase(-1);
2026     usleep(WAIT_SYNC_FOR_TEST_END_IN_NS);
2027 }
2028 
2029 /**
2030  * @tc.name: NotifySessionTransferToTargetScreenEvent001
2031  * @tc.desc: NotifySessionTransferToTargetScreenEventTest persistentId is invalid
2032  * @tc.type: FUNC
2033  */
2034 HWTEST_F(SceneSessionManagerTest, NotifySessionTransferToTargetScreenEvent001, TestSize.Level1)
2035 {
2036     g_logMsg.clear();
2037     int32_t persistentId = -1;
2038     uint32_t resultCode = 1;
2039     uint64_t fromScreenId = 1;
2040     uint64_t toScreenId = 1;
2041     ssm_->NotifySessionTransferToTargetScreenEvent(persistentId, resultCode, fromScreenId, toScreenId);
2042     EXPECT_TRUE(g_logMsg.find("sceneSession is nullptr") != std::string::npos);
2043 }
2044 
2045 /**
2046  * @tc.name: NotifySessionTransferToTargetScreenEvent002
2047  * @tc.desc: NotifySessionTransferToTargetScreenEventTest persistentId is valid
2048  * @tc.type: FUNC
2049  */
2050 HWTEST_F(SceneSessionManagerTest, NotifySessionTransferToTargetScreenEvent002, TestSize.Level1)
2051 {
2052     ssm_->sceneSessionMap_.clear();
2053     SessionInfo info;
2054     info.abilityName_ = "test";
2055     info.bundleName_ = "test";
2056     info.persistentId_ = 9527;
2057     info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
2058     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2059     ASSERT_NE(sceneSession, nullptr);
2060     ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
2061 
2062     g_logMsg.clear();
2063     ssm_->NotifySessionTransferToTargetScreenEvent(sceneSession->GetPersistentId(), 1, 1, 2);
2064     EXPECT_FALSE(g_logMsg.find("sceneSession is nullptr") != std::string::npos);
2065 }
2066 } // namespace
2067 } // namespace Rosen
2068 } // namespace OHOS
2069