1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <bundle_mgr_interface.h>
17 #include <bundlemgr/launcher_service.h>
18 #include <gtest/gtest.h>
19 #include <regex>
20 #include "context.h"
21 #include "interfaces/include/ws_common.h"
22 #include "mock/mock_session_stage.h"
23 #include "mock/mock_window_event_channel.h"
24 #include "session/host/include/scene_session.h"
25 #include "session/host/include/main_session.h"
26 #include "session_info.h"
27 #include "session_manager.h"
28 #include "session_manager/include/scene_session_manager.h"
29 #include "window_manager_agent.h"
30 #include "zidl/window_manager_agent_interface.h"
31 #include "screen_session_manager_client/include/screen_session_manager_client.h"
32 
33 using namespace testing;
34 using namespace testing::ext;
35 
36 namespace OHOS {
37 namespace Rosen {
38 namespace {
39 const std::string EMPTY_DEVICE_ID = "";
40 using ConfigItem = WindowSceneConfig::ConfigItem;
41 }
42 class SceneSessionManagerTest6 : public testing::Test {
43 public:
44     static void SetUpTestCase();
45     static void TearDownTestCase();
46     void SetUp() override;
47     void TearDown() override;
48 
49     static bool gestureNavigationEnabled_;
50     static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
51     static sptr<SceneSessionManager> ssm_;
52 private:
53     static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
54 };
55 
56 sptr<SceneSessionManager> SceneSessionManagerTest6::ssm_ = nullptr;
57 
58 bool SceneSessionManagerTest6::gestureNavigationEnabled_ = true;
59 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest6::callbackFunc_ = [](bool enable,
60     const std::string& bundleName, GestureBackType type) {
61     gestureNavigationEnabled_ = enable;
62 };
63 
WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)64 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
65 {
66 }
67 
ProcessStatusBarEnabledChangeFuncTest(bool enable)68 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
69 {
70 }
71 
DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)72 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
73 {
74 }
75 
SetUpTestCase()76 void SceneSessionManagerTest6::SetUpTestCase()
77 {
78     ssm_ = &SceneSessionManager::GetInstance();
79 }
80 
TearDownTestCase()81 void SceneSessionManagerTest6::TearDownTestCase()
82 {
83     ssm_ = nullptr;
84 }
85 
SetUp()86 void SceneSessionManagerTest6::SetUp()
87 {
88     ssm_->sceneSessionMap_.clear();
89 }
90 
TearDown()91 void SceneSessionManagerTest6::TearDown()
92 {
93     usleep(WAIT_SYNC_IN_NS);
94     ssm_->sceneSessionMap_.clear();
95 }
96 
97 namespace {
98 /**
99  * @tc.name: MissionChanged
100  * @tc.desc: MissionChanged
101  * @tc.type: FUNC
102  */
HWTEST_F(SceneSessionManagerTest6, MissionChanged, Function | SmallTest | Level3)103 HWTEST_F(SceneSessionManagerTest6, MissionChanged, Function | SmallTest | Level3)
104 {
105     sptr<SceneSession> prevSession = nullptr;
106     sptr<SceneSession> currSession = nullptr;
107     ASSERT_NE(nullptr, ssm_);
108     auto ret = ssm_->MissionChanged(prevSession, currSession);
109     EXPECT_EQ(false, ret);
110     SessionInfo sessionInfoFirst;
111     sessionInfoFirst.bundleName_ = "privacy.test.first";
112     sessionInfoFirst.abilityName_ = "privacyAbilityName";
113     prevSession = sptr<SceneSession>::MakeSptr(sessionInfoFirst, nullptr);
114     ASSERT_NE(nullptr, prevSession);
115     ASSERT_NE(nullptr, ssm_);
116     ret = ssm_->MissionChanged(prevSession, currSession);
117     EXPECT_EQ(true, ret);
118     SessionInfo sessionInfoSecond;
119     sessionInfoSecond.bundleName_ = "privacy.test.second";
120     sessionInfoSecond.abilityName_ = "privacyAbilityName";
121     currSession= sptr<SceneSession>::MakeSptr(sessionInfoSecond, nullptr);
122     ASSERT_NE(nullptr, currSession);
123     prevSession->persistentId_ = 0;
124     currSession->persistentId_ = 0;
125     ASSERT_NE(nullptr, ssm_);
126     ret = ssm_->MissionChanged(prevSession, currSession);
127     EXPECT_EQ(false, ret);
128     prevSession = nullptr;
129     ASSERT_NE(nullptr, ssm_);
130     ret = ssm_->MissionChanged(prevSession, currSession);
131     EXPECT_EQ(true, ret);
132 }
133 
134 /**
135  * @tc.name: UpdateSecSurfaceInfo
136  * @tc.desc: UpdateSecSurfaceInfo
137  * @tc.type: FUNC
138  */
HWTEST_F(SceneSessionManagerTest6, UpdateSecSurfaceInfo, Function | SmallTest | Level3)139 HWTEST_F(SceneSessionManagerTest6, UpdateSecSurfaceInfo, Function | SmallTest | Level3)
140 {
141     ASSERT_NE(ssm_, nullptr);
142     std::map<NodeId, std::vector<SecSurfaceInfo>> callbackData;
143     std::shared_ptr<RSUIExtensionData> secExtData = std::make_shared<RSUIExtensionData>(callbackData);
144     ssm_->currentUserId_ = 101;
145     ssm_->UpdateSecSurfaceInfo(secExtData, 100);
146 
147     ssm_->currentUserId_ = 100;
148     ssm_->UpdateSecSurfaceInfo(secExtData, 100);
149 }
150 
151 /**
152  * @tc.name: GetWindowLayerChangeInfo
153  * @tc.desc: Simulate window Layer change
154  * @tc.type: FUNC
155  */
HWTEST_F(SceneSessionManagerTest6, GetWindowLayerChangeInfo, Function | SmallTest | Level3)156 HWTEST_F(SceneSessionManagerTest6, GetWindowLayerChangeInfo, Function | SmallTest | Level3)
157 {
158     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
159     currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
160     currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
161     currVisibleData.push_back(std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
162     currVisibleData.push_back(std::make_pair(3, WindowVisibilityState::WINDOW_LAYER_STATE_MAX));
163     std::vector<std::pair<uint64_t, bool>> currDrawingContentData;
164     currDrawingContentData.push_back(std::make_pair(0, true));
165     currDrawingContentData.push_back(std::make_pair(1, false));
166     VisibleData visibleData;
167     visibleData.push_back(std::make_pair(0, WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE));
168     visibleData.push_back(std::make_pair(1, WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE));
169     visibleData.push_back(std::make_pair(2, WINDOW_LAYER_INFO_TYPE::INVISIBLE));
170     visibleData.push_back(std::make_pair(3, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_DYNAMIC_STATUS));
171     visibleData.push_back(std::make_pair(4, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_STATIC_STATUS));
172     visibleData.push_back(std::make_pair(5, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_UNKNOWN_TYPE));
173     std::shared_ptr<RSOcclusionData> occlusionDataPtr = std::make_shared<RSOcclusionData>(visibleData);
174     ASSERT_NE(nullptr, occlusionDataPtr);
175     ASSERT_NE(nullptr, ssm_);
176     ssm_->GetWindowLayerChangeInfo(occlusionDataPtr, currVisibleData, currDrawingContentData);
177     ASSERT_EQ(currVisibleData.size(), 7);
178     ASSERT_EQ(currDrawingContentData.size(), 4);
179 }
180 
181 /**
182  * @tc.name: GetWindowVisibilityChangeInfo01
183  * @tc.desc: GetWindowVisibilityChangeInfo01
184  * @tc.type: FUNC
185  */
HWTEST_F(SceneSessionManagerTest6, GetWindowVisibilityChangeInfo01, Function | SmallTest | Level3)186 HWTEST_F(SceneSessionManagerTest6, GetWindowVisibilityChangeInfo01, Function | SmallTest | Level3)
187 {
188     ASSERT_NE(nullptr, ssm_);
189     ssm_->lastVisibleData_.clear();
190     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
191     std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
192     currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
193     currVisibleData.push_back(std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
194     currVisibleData.push_back(std::make_pair(3, WindowVisibilityState::WINDOW_LAYER_STATE_MAX));
195     ssm_->lastVisibleData_.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
196     visibilityChangeInfos = ssm_->GetWindowVisibilityChangeInfo(currVisibleData);
197     ASSERT_EQ(visibilityChangeInfos.size(), 3);
198 }
199 
200 /**
201  * @tc.name: GetWindowVisibilityChangeInfo02
202  * @tc.desc: GetWindowVisibilityChangeInfo02
203  * @tc.type: FUNC
204  */
HWTEST_F(SceneSessionManagerTest6, GetWindowVisibilityChangeInfo02, Function | SmallTest | Level3)205 HWTEST_F(SceneSessionManagerTest6, GetWindowVisibilityChangeInfo02, Function | SmallTest | Level3)
206 {
207     ASSERT_NE(nullptr, ssm_);
208     ssm_->lastVisibleData_.clear();
209     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
210     std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
211     currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
212     ssm_->lastVisibleData_.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
213     visibilityChangeInfos = ssm_->GetWindowVisibilityChangeInfo(currVisibleData);
214     ASSERT_EQ(visibilityChangeInfos.size(), 2);
215 }
216 
217 /**
218  * @tc.name: GetWindowVisibilityChangeInfo03
219  * @tc.desc: GetWindowVisibilityChangeInfo03
220  * @tc.type: FUNC
221  */
HWTEST_F(SceneSessionManagerTest6, GetWindowVisibilityChangeInfo03, Function | SmallTest | Level3)222 HWTEST_F(SceneSessionManagerTest6, GetWindowVisibilityChangeInfo03, Function | SmallTest | Level3)
223 {
224     ASSERT_NE(nullptr, ssm_);
225     ssm_->lastVisibleData_.clear();
226     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
227     std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
228     currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
229     currVisibleData.push_back(std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
230     ssm_->lastVisibleData_.push_back(
231         std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
232     ssm_->lastVisibleData_.push_back(
233         std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
234     visibilityChangeInfos = ssm_->GetWindowVisibilityChangeInfo(currVisibleData);
235     ASSERT_EQ(visibilityChangeInfos.size(), 1);
236 }
237 
238 /**
239  * @tc.name: DealwithVisibilityChange01
240  * @tc.desc: DealwithVisibilityChange01
241  * @tc.type: FUNC
242  */
HWTEST_F(SceneSessionManagerTest6, DealwithVisibilityChange01, Function | SmallTest | Level3)243 HWTEST_F(SceneSessionManagerTest6, DealwithVisibilityChange01, Function | SmallTest | Level3)
244 {
245     ASSERT_NE(nullptr, ssm_);
246     ssm_->sceneSessionMap_.clear();
247     SessionInfo sessionInfo;
248     sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
249     sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
250     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession1->GetPersistentId(), sceneSession1));
251     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession2->GetPersistentId(), sceneSession2));
252     struct RSSurfaceNodeConfig config;
253     std::shared_ptr<RSSurfaceNode> surfaceNode1 = RSSurfaceNode::Create(config);
254     std::shared_ptr<RSSurfaceNode> surfaceNode2 = RSSurfaceNode::Create(config);
255     ASSERT_NE(nullptr, surfaceNode1);
256     ASSERT_NE(nullptr, surfaceNode2);
257     surfaceNode1->SetId(1);
258     surfaceNode2->SetId(2);
259     ASSERT_NE(nullptr, sceneSession1);
260     ASSERT_NE(nullptr, sceneSession2);
261     sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
262     sceneSession1->surfaceNode_ = surfaceNode1;
263     sceneSession1->SetCallingPid(1);
264     sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
265     sceneSession2->SetParentSession(sceneSession1);
266     sceneSession2->surfaceNode_ = surfaceNode2;
267     sceneSession2->SetCallingPid(2);
268     ASSERT_NE(nullptr, sceneSession1->property_);
269     ASSERT_NE(nullptr, sceneSession2->property_);
270     sceneSession1->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
271     sceneSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
272     sceneSession1->property_->SetWindowName("visibility1");
273     sceneSession2->property_->SetWindowName("visibility2");
274     std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
275     visibilityChangeInfos.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
276     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
277     currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
278     ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
279     ASSERT_EQ(sceneSession1->GetRSVisible(), true);
280     ASSERT_EQ(sceneSession2->GetRSVisible(), true);
281     sceneSession2->SetSessionState(SessionState::STATE_BACKGROUND);
282     sceneSession1->SetRSVisible(false);
283     sceneSession2->SetRSVisible(false);
284     ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
285     ASSERT_EQ(sceneSession1->GetRSVisible(), true);
286     ASSERT_EQ(sceneSession2->GetRSVisible(), false);
287 }
288 
289 /**
290  * @tc.name: DealwithVisibilityChange02
291  * @tc.desc: DealwithVisibilityChange02
292  * @tc.type: FUNC
293  */
HWTEST_F(SceneSessionManagerTest6, DealwithVisibilityChange02, Function | SmallTest | Level3)294 HWTEST_F(SceneSessionManagerTest6, DealwithVisibilityChange02, Function | SmallTest | Level3)
295 {
296     ASSERT_NE(nullptr, ssm_);
297     ssm_->sceneSessionMap_.clear();
298     SessionInfo sessionInfo;
299     sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
300     sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
301     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession1->GetPersistentId(), sceneSession1));
302     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession2->GetPersistentId(), sceneSession2));
303     struct RSSurfaceNodeConfig config;
304     std::shared_ptr<RSSurfaceNode> surfaceNode1 = RSSurfaceNode::Create(config);
305     std::shared_ptr<RSSurfaceNode> surfaceNode2 = RSSurfaceNode::Create(config);
306     ASSERT_NE(nullptr, surfaceNode1);
307     ASSERT_NE(nullptr, surfaceNode2);
308     surfaceNode1->SetId(1);
309     surfaceNode2->SetId(2);
310     ASSERT_NE(nullptr, sceneSession1);
311     ASSERT_NE(nullptr, sceneSession2);
312     sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
313     sceneSession1->surfaceNode_ = surfaceNode1;
314     sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
315     sceneSession2->SetParentSession(sceneSession1);
316     sceneSession2->surfaceNode_ = surfaceNode2;
317     ASSERT_NE(nullptr, sceneSession1->property_);
318     ASSERT_NE(nullptr, sceneSession2->property_);
319     sceneSession1->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
320     sceneSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
321     sceneSession1->property_->SetWindowName("visibility1");
322     sceneSession2->property_->SetWindowName("visibility2");
323     std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
324     visibilityChangeInfos.push_back(std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
325     std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
326     currVisibleData.push_back(std::make_pair(3, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
327     sceneSession1->SetRSVisible(true);
328     ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
329     ASSERT_EQ(sceneSession2->GetRSVisible(), true);
330     sceneSession2->SetSessionState(SessionState::STATE_BACKGROUND);
331     sceneSession1->SetRSVisible(false);
332     sceneSession2->SetRSVisible(false);
333     sceneSession1->SetSessionState(SessionState::STATE_BACKGROUND);
334     ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
335     ASSERT_EQ(sceneSession2->GetRSVisible(), false);
336 }
337 
338 /**
339  * @tc.name: UpdateWindowMode
340  * @tc.desc: UpdateWindowMode
341  * @tc.type: FUNC
342  */
HWTEST_F(SceneSessionManagerTest6, UpdateWindowMode, Function | SmallTest | Level3)343 HWTEST_F(SceneSessionManagerTest6, UpdateWindowMode, Function | SmallTest | Level3)
344 {
345     SessionInfo sessionInfo;
346     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
347     sessionInfo.abilityName_ = "DumpSessionWithId";
348     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
349     ASSERT_NE(nullptr, ssm_);
350     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
351     ASSERT_NE(nullptr, ssm_);
352     auto ret = ssm_->UpdateWindowMode(0, 0);
353     EXPECT_EQ(WSError::WS_ERROR_INVALID_WINDOW, ret);
354     ASSERT_NE(nullptr, ssm_);
355     ret = ssm_->UpdateWindowMode(2, 0);
356     EXPECT_EQ(WSError::WS_OK, ret);
357 }
358 
359 /**
360  * @tc.name: SetScreenLocked && IsScreenLocked
361  * @tc.desc: SceneSesionManager update screen locked state
362  * @tc.type: FUNC
363  */
HWTEST_F(SceneSessionManagerTest6, IsScreenLocked, Function | SmallTest | Level3)364 HWTEST_F(SceneSessionManagerTest6, IsScreenLocked, Function | SmallTest | Level3)
365 {
366     ASSERT_NE(nullptr, ssm_);
367     ssm_->SetScreenLocked(true);
368     ASSERT_NE(nullptr, ssm_);
369     EXPECT_TRUE(ssm_->IsScreenLocked());
370     ASSERT_NE(nullptr, ssm_);
371     ssm_->ProcessWindowModeType();
372     ASSERT_NE(nullptr, ssm_);
373     ssm_->SetScreenLocked(false);
374     ASSERT_NE(nullptr, ssm_);
375     EXPECT_FALSE(ssm_->IsScreenLocked());
376     ASSERT_NE(nullptr, ssm_);
377     ssm_->ProcessWindowModeType();
378 }
379 
380 /**
381  * @tc.name: CheckWindowModeType
382  * @tc.desc: CheckWindowModeType
383  * @tc.type: FUNC
384  */
HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType, Function | SmallTest | Level3)385 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType, Function | SmallTest | Level3)
386 {
387     ASSERT_NE(nullptr, ssm_);
388     ssm_->sceneSessionMap_.clear();
389     auto ret = ssm_->CheckWindowModeType();
390     EXPECT_EQ(WindowModeType::WINDOW_MODE_OTHER, ret);
391     SessionInfo sessionInfo;
392     sessionInfo.bundleName_ = "privacy.test.first";
393     sessionInfo.abilityName_ = "privacyAbilityName";
394     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
395     ASSERT_NE(nullptr, sceneSession);
396     ASSERT_NE(nullptr, sceneSession->property_);
397     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
398     DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
399     sceneSession->property_->SetDisplayId(displayId);
400     ASSERT_NE(nullptr, ssm_);
401     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
402     ASSERT_NE(nullptr, ssm_);
403     ret = ssm_->CheckWindowModeType();
404     EXPECT_EQ(WindowModeType::WINDOW_MODE_OTHER, ret);
405     ASSERT_NE(nullptr, sceneSession->property_);
406     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
407     sceneSession->isVisible_ = false;
408     sceneSession->state_ = SessionState::STATE_DISCONNECT;
409     ASSERT_NE(nullptr, ssm_);
410     ret = ssm_->CheckWindowModeType();
411     EXPECT_EQ(WindowModeType::WINDOW_MODE_OTHER, ret);
412 }
413 
414 /**
415  * @tc.name: CheckWindowModeType01
416  * @tc.desc: CheckWindowModeType
417  * @tc.type: FUNC
418  */
HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType01, Function | SmallTest | Level3)419 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType01, Function | SmallTest | Level3)
420 {
421     DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
422     SessionInfo sessionInfo;
423     sessionInfo.bundleName_ = "privacy.test.first";
424     sessionInfo.abilityName_ = "privacyAbilityName";
425     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
426     ASSERT_NE(nullptr, sceneSession);
427     ASSERT_NE(nullptr, sceneSession->property_);
428     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
429     ASSERT_NE(nullptr, sceneSession->property_);
430     sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
431     sceneSession->property_->SetDisplayId(displayId);
432     sceneSession->isVisible_ = true;
433     sceneSession->state_ = SessionState::STATE_ACTIVE;
434     ASSERT_NE(nullptr, ssm_);
435     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
436     SessionInfo sessionInfo1;
437     sessionInfo1.bundleName_ = "privacy.test.first";
438     sessionInfo1.abilityName_ = "privacyAbilityName";
439     sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
440     ASSERT_NE(nullptr, sceneSession1);
441     ASSERT_NE(nullptr, sceneSession1->property_);
442     sceneSession1->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
443     ASSERT_NE(nullptr, sceneSession1->property_);
444     sceneSession1->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
445     sceneSession1->property_->SetDisplayId(displayId);
446     sceneSession1->isVisible_ = true;
447     sceneSession1->state_ = SessionState::STATE_ACTIVE;
448     ASSERT_NE(nullptr, ssm_);
449     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
450     ASSERT_NE(nullptr, ssm_);
451     auto ret = ssm_->CheckWindowModeType();
452     EXPECT_EQ(WindowModeType::WINDOW_MODE_SPLIT_FLOATING, ret);
453     ASSERT_NE(nullptr, sceneSession);
454     ASSERT_NE(nullptr, sceneSession->property_);
455     sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
456     ASSERT_NE(nullptr, ssm_);
457     ret = ssm_->CheckWindowModeType();
458     EXPECT_EQ(WindowModeType::WINDOW_MODE_FULLSCREEN_FLOATING, ret);
459 }
460 
461 /**
462  * @tc.name: CheckWindowModeType02
463  * @tc.desc: CheckWindowModeType
464  * @tc.type: FUNC
465  */
HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType02, Function | SmallTest | Level3)466 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType02, Function | SmallTest | Level3)
467 {
468     DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
469     SessionInfo sessionInfo;
470     sessionInfo.bundleName_ = "privacy.test.first";
471     sessionInfo.abilityName_ = "privacyAbilityName";
472     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
473     ASSERT_NE(nullptr, sceneSession);
474     ASSERT_NE(nullptr, sceneSession->property_);
475     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
476     ASSERT_NE(nullptr, sceneSession->property_);
477     sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
478     sceneSession->property_->SetDisplayId(displayId);
479     sceneSession->isVisible_ = true;
480     sceneSession->state_ = SessionState::STATE_ACTIVE;
481     ASSERT_NE(nullptr, ssm_);
482     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
483     ASSERT_NE(nullptr, ssm_);
484     ssm_->lastWindowModeType_ = WindowModeType::WINDOW_MODE_FULLSCREEN;
485     auto ret = ssm_->CheckWindowModeType();
486     EXPECT_EQ(WindowModeType::WINDOW_MODE_FLOATING, ret);
487     ASSERT_NE(nullptr, ssm_);
488     ssm_->NotifyRSSWindowModeTypeUpdate();
489     ASSERT_NE(nullptr, sceneSession->property_);
490     sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
491     ASSERT_NE(nullptr, ssm_);
492     ret = ssm_->CheckWindowModeType();
493     EXPECT_EQ(WindowModeType::WINDOW_MODE_FULLSCREEN, ret);
494     ASSERT_NE(nullptr, ssm_);
495     ssm_->NotifyRSSWindowModeTypeUpdate();
496 }
497 
498 /**
499  * @tc.name: CheckWindowModeType03
500  * @tc.desc: CheckWindowModeType
501  * @tc.type: FUNC
502  */
HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType03, Function | SmallTest | Level3)503 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType03, Function | SmallTest | Level3)
504 {
505     DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
506     SessionInfo sessionInfo;
507     sessionInfo.bundleName_ = "privacy.test.first";
508     sessionInfo.abilityName_ = "privacyAbilityName";
509     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
510     ASSERT_NE(nullptr, sceneSession);
511     ASSERT_NE(nullptr, sceneSession->property_);
512     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
513     sceneSession->property_->SetDisplayId(displayId);
514     sceneSession->isVisible_ = true;
515     sceneSession->state_ = SessionState::STATE_ACTIVE;
516     ASSERT_NE(nullptr, ssm_);
517     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
518     ASSERT_NE(nullptr, sceneSession);
519     ASSERT_NE(nullptr, sceneSession->property_);
520     sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
521     sceneSession->isVisible_ = true;
522     sceneSession->state_ = SessionState::STATE_ACTIVE;
523     ASSERT_NE(nullptr, ssm_);
524     auto ret = ssm_->CheckWindowModeType();
525     EXPECT_EQ(WindowModeType::WINDOW_MODE_SPLIT, ret);
526     ASSERT_NE(nullptr, sceneSession);
527     ASSERT_NE(nullptr, sceneSession->property_);
528     sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
529     ASSERT_NE(nullptr, ssm_);
530     ret = ssm_->CheckWindowModeType();
531     EXPECT_EQ(WindowModeType::WINDOW_MODE_SPLIT, ret);
532 }
533 
534 /**
535  * @tc.name: GetSceneSessionPrivacyModeBundles
536  * @tc.desc: GetSceneSessionPrivacyModeBundles
537  * @tc.type: FUNC
538  */
HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles, Function | SmallTest | Level3)539 HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles, Function | SmallTest | Level3)
540 {
541     ASSERT_NE(nullptr, ssm_);
542     ssm_->sceneSessionMap_.clear();
543     DisplayId displayId = 0;
544     std::unordered_set<std::string> privacyBundles;
545     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
546     SessionInfo sessionInfoFirst;
547     sessionInfoFirst.bundleName_ = "";
548     sessionInfoFirst.abilityName_ = "privacyAbilityName";
549     sptr<SceneSession> sceneSessionFirst = sptr<SceneSession>::MakeSptr(sessionInfoFirst, nullptr);
550     ASSERT_NE(sceneSessionFirst, nullptr);
551     sceneSessionFirst->property_ = nullptr;
552     ASSERT_NE(nullptr, ssm_);
553     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
554     sceneSessionFirst->property_ = sptr<WindowSessionProperty>::MakeSptr();
555     ASSERT_NE(nullptr, sceneSessionFirst->property_);
556     sceneSessionFirst->property_->SetDisplayId(0);
557     ASSERT_NE(nullptr, ssm_);
558     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
559     sessionInfoFirst.bundleName_ = "privacy.test.first";
560     sceneSessionFirst->state_ = SessionState::STATE_FOREGROUND;
561     ASSERT_NE(nullptr, ssm_);
562     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
563     sceneSessionFirst->state_ = SessionState::STATE_CONNECT;
564     ASSERT_NE(nullptr, ssm_);
565     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
566 }
567 
568 /**
569  * @tc.name: GetSceneSessionPrivacyModeBundles01
570  * @tc.desc: GetSceneSessionPrivacyModeBundles
571  * @tc.type: FUNC
572  */
HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles01, Function | SmallTest | Level3)573 HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles01, Function | SmallTest | Level3)
574 {
575     DisplayId displayId = 0;
576     std::unordered_set<std::string> privacyBundles;
577     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
578     SessionInfo sessionInfoFirst;
579     sessionInfoFirst.bundleName_ = "privacy.test.first";
580     sessionInfoFirst.abilityName_ = "privacyAbilityName";
581     sptr<SceneSession> sceneSessionFirst = sptr<SceneSession>::MakeSptr(sessionInfoFirst, nullptr);
582     ASSERT_NE(sceneSessionFirst, nullptr);
583     sceneSessionFirst->property_ = sptr<WindowSessionProperty>::MakeSptr();
584     ASSERT_NE(nullptr, sceneSessionFirst->property_);
585     sceneSessionFirst->property_->SetDisplayId(0);
586     sceneSessionFirst->state_ = SessionState::STATE_ACTIVE;
587     ASSERT_NE(nullptr, ssm_);
588     SessionInfo sessionInfoSecond;
589     sessionInfoSecond.bundleName_ = "privacy.test.second";
590     sessionInfoSecond.abilityName_ = "privacyAbilityName";
591     sptr<SceneSession> sceneSessionSecond = sptr<SceneSession>::MakeSptr(sessionInfoSecond, nullptr);
592     ASSERT_NE(nullptr, sceneSessionSecond);
593     ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond});
594     ASSERT_NE(nullptr, sceneSessionSecond->property_);
595     sceneSessionSecond->property_->displayId_ = 1;
596     sceneSessionSecond->state_ = SessionState::STATE_ACTIVE;
597     sceneSessionSecond->parentSession_ = sceneSessionFirst;
598     ASSERT_NE(nullptr, ssm_);
599     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
600     sceneSessionSecond->state_ = SessionState::STATE_FOREGROUND;
601     sceneSessionSecond->state_ = SessionState::STATE_CONNECT;
602     ASSERT_NE(nullptr, ssm_);
603     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
604 }
605 
606 /**
607  * @tc.name: GetSceneSessionPrivacyModeBundles02
608  * @tc.desc: GetSceneSessionPrivacyModeBundles
609  * @tc.type: FUNC
610  */
HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles02, Function | SmallTest | Level3)611 HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles02, Function | SmallTest | Level3)
612 {
613     DisplayId displayId = 0;
614     std::unordered_set<std::string> privacyBundles;
615     ASSERT_NE(nullptr, ssm_);
616     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
617     SessionInfo sessionInfoFirst;
618     sessionInfoFirst.bundleName_ = "privacy.test.first";
619     sessionInfoFirst.abilityName_ = "privacyAbilityName";
620     sptr<SceneSession> sceneSessionFirst = sptr<SceneSession>::MakeSptr(sessionInfoFirst, nullptr);
621     ASSERT_NE(sceneSessionFirst, nullptr);
622     sceneSessionFirst->property_ = sptr<WindowSessionProperty>::MakeSptr();
623     ASSERT_NE(nullptr, sceneSessionFirst->property_);
624     sceneSessionFirst->property_->SetDisplayId(0);
625     sceneSessionFirst->state_ = SessionState::STATE_ACTIVE;
626     sceneSessionFirst->property_->isPrivacyMode_ = false;
627     ASSERT_NE(nullptr, ssm_);
628     ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
629 }
630 
631 /**
632  * @tc.name: RegisterWindowManagerAgent
633  * @tc.desc: RegisterWindowManagerAgent
634  * @tc.type: FUNC
635  */
HWTEST_F(SceneSessionManagerTest6, RegisterWindowManagerAgent, Function | SmallTest | Level3)636 HWTEST_F(SceneSessionManagerTest6, RegisterWindowManagerAgent, Function | SmallTest | Level3)
637 {
638     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR;
639     sptr<IWindowManagerAgent> windowManagerAgent = nullptr;
640     ASSERT_NE(nullptr, ssm_);
641     auto ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
642     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
643     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED;
644     ASSERT_NE(nullptr, ssm_);
645     ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
646     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
647     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG;
648     ASSERT_NE(nullptr, ssm_);
649     ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
650     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
651     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY;
652     ASSERT_NE(nullptr, ssm_);
653     ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
654     EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
655     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE;
656     ASSERT_NE(nullptr, ssm_);
657     ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
658     EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
659     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM;
660     ASSERT_NE(nullptr, ssm_);
661     ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
662     EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
663     type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT;
664     ASSERT_NE(nullptr, ssm_);
665     ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
666     EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
667 }
668 
669 /**
670  * @tc.name: OnSessionStateChange
671  * @tc.desc: OnSessionStateChange
672  * @tc.type: FUNC
673  */
HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange, Function | SmallTest | Level3)674 HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange, Function | SmallTest | Level3)
675 {
676     SessionState state = SessionState::STATE_FOREGROUND;
677     ASSERT_NE(nullptr, ssm_);
678     ssm_->sceneSessionMap_.clear();
679     ssm_->OnSessionStateChange(1, state);
680     SessionInfo sessionInfo;
681     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
682     sessionInfo.abilityName_ = "DumpSessionWithId";
683     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
684     ASSERT_NE(nullptr, ssm_);
685     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
686     ASSERT_NE(nullptr, sceneSession);
687     ASSERT_NE(nullptr, sceneSession->property_);
688     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
689     ASSERT_NE(nullptr, ssm_);
690     ssm_->OnSessionStateChange(1, state);
691     ssm_->focusedSessionId_ = 1;
692     ssm_->OnSessionStateChange(1, state);
693     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
694     ASSERT_NE(nullptr, ssm_);
695     ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
696     ssm_->OnSessionStateChange(1, state);
697     ASSERT_NE(nullptr, ssm_);
698     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
699     ssm_->OnSessionStateChange(1, state);
700     ssm_->focusedSessionId_ = 0;
701     ASSERT_NE(nullptr, ssm_);
702     ssm_->OnSessionStateChange(1, state);
703 }
704 
705 /**
706  * @tc.name: OnSessionStateChange01
707  * @tc.desc: OnSessionStateChange01
708  * @tc.type: FUNC
709  */
HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange01, Function | SmallTest | Level3)710 HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange01, Function | SmallTest | Level3)
711 {
712     SessionState state = SessionState::STATE_BACKGROUND;
713     ASSERT_NE(nullptr, ssm_);
714     ssm_->sceneSessionMap_.clear();
715     SessionInfo sessionInfo;
716     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
717     sessionInfo.abilityName_ = "DumpSessionWithId";
718     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
719     ASSERT_NE(nullptr, ssm_);
720     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
721     ASSERT_NE(nullptr, sceneSession);
722     ASSERT_NE(nullptr, sceneSession->property_);
723     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
724     ASSERT_NE(nullptr, ssm_);
725     ssm_->OnSessionStateChange(1, state);
726     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
727     ASSERT_NE(nullptr, ssm_);
728     ssm_->OnSessionStateChange(1, state);
729     state = SessionState::STATE_END;
730     ASSERT_NE(nullptr, ssm_);
731     ssm_->OnSessionStateChange(1, state);
732 }
733 
734 /**
735  * @tc.name: OnSessionStateChange02
736  * @tc.desc: OnSessionStateChange02
737  * @tc.type: FUNC
738  */
HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange02, Function | SmallTest | Level3)739 HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange02, Function | SmallTest | Level3)
740 {
741     SessionState state = SessionState::STATE_FOREGROUND;
742     ASSERT_NE(nullptr, ssm_);
743     ssm_->sceneSessionMap_.clear();
744     SessionInfo sessionInfo;
745     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
746     sessionInfo.abilityName_ = "DumpSessionWithId";
747     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
748     ASSERT_NE(nullptr, ssm_);
749     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
750     ASSERT_NE(nullptr, sceneSession);
751     ASSERT_NE(nullptr, sceneSession->property_);
752     sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
753     sceneSession->SetFocusedOnShow(true);
754     ASSERT_NE(nullptr, ssm_);
755     ssm_->OnSessionStateChange(1, state);
756     sceneSession->SetFocusedOnShow(false);
757     ASSERT_NE(nullptr, ssm_);
758     ssm_->OnSessionStateChange(1, state);
759 }
760 
761 /**
762  * @tc.name: SetWindowFlags
763  * @tc.desc: SetWindowFlags
764  * @tc.type: FUNC
765  */
HWTEST_F(SceneSessionManagerTest6, SetWindowFlags, Function | SmallTest | Level3)766 HWTEST_F(SceneSessionManagerTest6, SetWindowFlags, Function | SmallTest | Level3)
767 {
768     SessionInfo sessionInfo;
769     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
770     sessionInfo.abilityName_ = "DumpSessionWithId";
771     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
772     sptr<WindowSessionProperty> property = nullptr;
773     sceneSession->property_ = nullptr;
774     ASSERT_NE(nullptr, ssm_);
775     auto ret = ssm_->SetWindowFlags(sceneSession, property);
776     EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret);
777 }
778 
779 /**
780  * @tc.name: ProcessSubSessionForeground
781  * @tc.desc: ProcessSubSessionForeground
782  * @tc.type: FUNC
783  */
HWTEST_F(SceneSessionManagerTest6, ProcessSubSessionForeground, Function | SmallTest | Level3)784 HWTEST_F(SceneSessionManagerTest6, ProcessSubSessionForeground, Function | SmallTest | Level3)
785 {
786     sptr<SceneSession> sceneSession = nullptr;
787     ASSERT_NE(nullptr, ssm_);
788     ssm_->ProcessSubSessionForeground(sceneSession);
789     SessionInfo sessionInfo;
790     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
791     sessionInfo.abilityName_ = "DumpSessionWithId";
792     sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
793     ASSERT_NE(nullptr, sceneSession);
794     ASSERT_NE(nullptr, ssm_);
795     ssm_->ProcessSubSessionForeground(sceneSession);
796     sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
797     ASSERT_NE(nullptr, sceneSession);
798     ASSERT_NE(nullptr, subSession);
799     sceneSession->AddSubSession(subSession);
800     ASSERT_NE(nullptr, ssm_);
801     ssm_->ProcessSubSessionForeground(sceneSession);
802     ASSERT_NE(nullptr, subSession);
803     subSession->SetSessionState(SessionState::STATE_FOREGROUND);
804     ASSERT_NE(nullptr, ssm_);
805     ssm_->ProcessSubSessionForeground(sceneSession);
806     ASSERT_NE(nullptr, subSession);
807     subSession->SetSessionState(SessionState::STATE_ACTIVE);
808     ASSERT_NE(nullptr, ssm_);
809     ssm_->ProcessSubSessionForeground(sceneSession);
810     ASSERT_NE(nullptr, subSession);
811     subSession->SetSessionState(SessionState::STATE_INACTIVE);
812     ASSERT_NE(nullptr, ssm_);
813     ssm_->ProcessSubSessionForeground(sceneSession);
814 }
815 
816 /**
817  * @tc.name: ProcessModalTopmostRequestFocusImmdediately
818  * @tc.desc: ProcessModalTopmostRequestFocusImmdediately
819  * @tc.type: FUNC
820  */
HWTEST_F(SceneSessionManagerTest6, ProcessModalTopmostRequestFocusImmdediately, Function | SmallTest | Level3)821 HWTEST_F(SceneSessionManagerTest6, ProcessModalTopmostRequestFocusImmdediately, Function | SmallTest | Level3)
822 {
823     SessionInfo sessionInfo;
824     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
825     sessionInfo.abilityName_ = "DumpSessionWithId";
826     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
827     ASSERT_NE(nullptr, sceneSession->property_);
828     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
829     ASSERT_NE(nullptr, ssm_);
830     auto ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
831     EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
832     ASSERT_NE(nullptr, sceneSession->property_);
833     sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
834     ASSERT_NE(nullptr, ssm_);
835     ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
836     EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
837     ASSERT_NE(nullptr, sceneSession->property_);
838     sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_END);
839     ASSERT_NE(nullptr, ssm_);
840     ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
841     EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
842 }
843 
844 /**
845  * @tc.name: GetAbilityInfosFromBundleInfo
846  * @tc.desc: GetAbilityInfosFromBundleInfo
847  * @tc.type: FUNC
848  */
HWTEST_F(SceneSessionManagerTest6, GetAbilityInfosFromBundleInfo, Function | SmallTest | Level3)849 HWTEST_F(SceneSessionManagerTest6, GetAbilityInfosFromBundleInfo, Function | SmallTest | Level3)
850 {
851     std::vector<AppExecFwk::BundleInfo> bundleInfos;
852     std::vector<SCBAbilityInfo> scbAbilityInfos;
853     ASSERT_NE(nullptr, ssm_);
854     auto ret = ssm_->GetAbilityInfosFromBundleInfo(bundleInfos, scbAbilityInfos);
855     EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, ret);
856     OHOS::AppExecFwk::BundleInfo bundleInfo;
857     bundleInfo.name = "com.ix.residentservcie";
858     bundleInfo.isKeepAlive = true;
859     bundleInfo.applicationInfo.process = "com.ix.residentservcie";
860     OHOS::AppExecFwk::HapModuleInfo hapModuleInfo;
861     hapModuleInfo.isModuleJson = true;
862     hapModuleInfo.mainElementName = "residentServiceAbility";
863     hapModuleInfo.process = "com.ix.residentservcie";
864     bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo);
865     bundleInfos.emplace_back(bundleInfo);
866     ASSERT_NE(nullptr, ssm_);
867     ret = ssm_->GetAbilityInfosFromBundleInfo(bundleInfos, scbAbilityInfos);
868     EXPECT_EQ(WSError::WS_OK, ret);
869 }
870 
871 /**
872  * @tc.name: GetOrientationFromResourceManager
873  * @tc.desc: GetOrientationFromResourceManager
874  * @tc.type: FUNC
875  */
HWTEST_F(SceneSessionManagerTest6, GetOrientationFromResourceManager, Function | SmallTest | Level3)876 HWTEST_F(SceneSessionManagerTest6, GetOrientationFromResourceManager, Function | SmallTest | Level3)
877 {
878     ASSERT_NE(nullptr, ssm_);
879     OHOS::AppExecFwk::AbilityInfo abilityInfo;
880     abilityInfo.bundleName = "testBundleName";
881     abilityInfo.moduleName = "testModuleName";
882     abilityInfo.orientationId = 123456;
883     ssm_->GetOrientationFromResourceManager(abilityInfo);
884     EXPECT_EQ(OHOS::AppExecFwk::DisplayOrientation::UNSPECIFIED, abilityInfo.orientation);
885 }
886 
887 /**
888  * @tc.name: NotifyCompleteFirstFrameDrawing
889  * @tc.desc: NotifyCompleteFirstFrameDrawing
890  * @tc.type: FUNC
891  */
HWTEST_F(SceneSessionManagerTest6, NotifyCompleteFirstFrameDrawing, Function | SmallTest | Level3)892 HWTEST_F(SceneSessionManagerTest6, NotifyCompleteFirstFrameDrawing, Function | SmallTest | Level3)
893 {
894     ASSERT_NE(nullptr, ssm_);
895     ssm_->sceneSessionMap_.clear();
896     SessionInfo sessionInfo;
897     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
898     sessionInfo.abilityName_ = "DumpSessionWithId";
899     sessionInfo.abilityInfo = nullptr;
900     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
901     ASSERT_NE(nullptr, ssm_);
902     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
903     ASSERT_NE(nullptr, ssm_);
904     ssm_->NotifyCompleteFirstFrameDrawing(1);
905     sessionInfo.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
906     ASSERT_NE(nullptr, sessionInfo.abilityInfo);
907     ASSERT_NE(nullptr, ssm_);
908     ssm_->eventHandler_ = nullptr;
909     ssm_->NotifyCompleteFirstFrameDrawing(1);
910     ssm_->eventHandler_ = std::make_shared<AppExecFwk::EventHandler>();
911     ASSERT_NE(nullptr, ssm_->eventHandler_);
912     ASSERT_NE(nullptr, ssm_);
913     ssm_->NotifyCompleteFirstFrameDrawing(1);
914     ASSERT_NE(nullptr, ssm_);
915     ssm_->taskScheduler_ = nullptr;
916     ssm_->NotifyCompleteFirstFrameDrawing(1);
917     ssm_->taskScheduler_ = std::make_shared<TaskScheduler>("OS_SceneSessionManager");
918     ASSERT_NE(nullptr, ssm_->taskScheduler_);
919     ASSERT_NE(nullptr, ssm_);
920     ssm_->NotifyCompleteFirstFrameDrawing(1);
921 }
922 
923 /**
924  * @tc.name: NotifyCompleteFirstFrameDrawing02
925  * @tc.desc: NotifyCompleteFirstFrameDrawing02:AtomicService free-install start.
926  * @tc.type: FUNC
927  */
HWTEST_F(SceneSessionManagerTest6, NotifyCompleteFirstFrameDrawing02, Function | SmallTest | Level3)928 HWTEST_F(SceneSessionManagerTest6, NotifyCompleteFirstFrameDrawing02, Function | SmallTest | Level3)
929 {
930     ASSERT_NE(nullptr, ssm_);
931     ssm_->sceneSessionMap_.clear();
932     SessionInfo sessionInfo;
933     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
934     sessionInfo.abilityName_ = "DumpSessionWithId";
935     sessionInfo.abilityInfo = nullptr;
936     sessionInfo.isAtomicService_ = true;
937     sessionInfo.isBackTransition_ = false;
938     unsigned int flags = 11111111;
939     sessionInfo.want = std::make_shared<AAFwk::Want>();
940     ASSERT_NE(nullptr, sessionInfo.want);
941     sessionInfo.want->SetFlags(flags);
942     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
943     ASSERT_NE(nullptr, sceneSession);
944     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
945     ssm_->NotifyCompleteFirstFrameDrawing(1);
946     ASSERT_EQ(nullptr, sessionInfo.abilityInfo);
947 }
948 
949 /**
950  * @tc.name: InitSceneSession01
951  * @tc.desc: InitSceneSession01:AtomicService free-install start.
952  * @tc.type: FUNC
953  */
HWTEST_F(SceneSessionManagerTest6, InitSceneSession01, Function | SmallTest | Level3)954 HWTEST_F(SceneSessionManagerTest6, InitSceneSession01, Function | SmallTest | Level3)
955 {
956     ASSERT_NE(nullptr, ssm_);
957     ssm_->sceneSessionMap_.clear();
958     SessionInfo sessionInfo;
959     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
960     sessionInfo.abilityName_ = "DumpSessionWithId";
961     sessionInfo.abilityInfo = nullptr;
962     sessionInfo.isAtomicService_ = true;
963     sessionInfo.isBackTransition_ = false;
964     sessionInfo.screenId_ = 100;
965     unsigned int flags = 11111111;
966     sessionInfo.want = std::make_shared<AAFwk::Want>();
967     ASSERT_NE(nullptr, sessionInfo.want);
968     sessionInfo.want->SetFlags(flags);
969     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
970     ASSERT_NE(nullptr, sceneSession);
971     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
972     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
973     sceneSession->SetSessionProperty(property);
974 
975     ssm_->InitSceneSession(sceneSession, sessionInfo, nullptr);
976     ASSERT_EQ(100, sceneSession->GetSessionInfo().screenId_);
977 }
978 
979 /**
980  * @tc.name: CheckAndNotifyWaterMarkChangedResult
981  * @tc.desc: CheckAndNotifyWaterMarkChangedResult
982  * @tc.type: FUNC
983  */
HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult, Function | SmallTest | Level3)984 HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult, Function | SmallTest | Level3)
985 {
986     ASSERT_NE(nullptr, ssm_);
987     ssm_->sceneSessionMap_.clear();
988     ssm_->CheckAndNotifyWaterMarkChangedResult();
989     SessionInfo sessionInfo;
990     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
991     sessionInfo.abilityName_ = "DumpSessionWithId";
992     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
993     ASSERT_NE(nullptr, sceneSession);
994     sceneSession->property_ = nullptr;
995     ASSERT_NE(nullptr, ssm_);
996     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
997     sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
998     ASSERT_NE(nullptr, sceneSession->property_);
999     sceneSession->property_->flags_ = 1 << 4;
1000     sceneSession->isRSVisible_ = true;
1001     sceneSession->combinedExtWindowFlags_.waterMarkFlag = true;
1002     ASSERT_NE(nullptr, ssm_);
1003     ssm_->CheckAndNotifyWaterMarkChangedResult();
1004     sceneSession->isRSVisible_ = false;
1005     ASSERT_NE(nullptr, ssm_);
1006     ssm_->CheckAndNotifyWaterMarkChangedResult();
1007     sceneSession->property_->flags_ = 0;
1008     sceneSession->isRSVisible_ = false;
1009     ASSERT_NE(nullptr, ssm_);
1010     ssm_->CheckAndNotifyWaterMarkChangedResult();
1011     sceneSession->isRSVisible_ = true;
1012     ASSERT_NE(nullptr, ssm_);
1013     ssm_->CheckAndNotifyWaterMarkChangedResult();
1014 }
1015 
1016 /**
1017  * @tc.name: CheckAndNotifyWaterMarkChangedResult01
1018  * @tc.desc: CheckAndNotifyWaterMarkChangedResult01
1019  * @tc.type: FUNC
1020  */
HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult01, Function | SmallTest | Level3)1021 HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult01, Function | SmallTest | Level3)
1022 {
1023     ASSERT_NE(nullptr, ssm_);
1024     ssm_->sceneSessionMap_.clear();
1025     SessionInfo sessionInfo;
1026     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1027     sessionInfo.abilityName_ = "DumpSessionWithId";
1028     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1029     ASSERT_NE(nullptr, sceneSession);
1030     ASSERT_NE(nullptr, ssm_);
1031     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1032     sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1033     ASSERT_NE(nullptr, sceneSession->property_);
1034     sceneSession->property_->flags_ = 1 << 4;
1035     sceneSession->isRSVisible_ = true;
1036     sceneSession->combinedExtWindowFlags_.waterMarkFlag = false;
1037     ASSERT_NE(nullptr, ssm_);
1038     ssm_->CheckAndNotifyWaterMarkChangedResult();
1039     sceneSession->isRSVisible_ = false;
1040     ASSERT_NE(nullptr, ssm_);
1041     ssm_->CheckAndNotifyWaterMarkChangedResult();
1042     sceneSession->property_->flags_ = 0;
1043     sceneSession->isRSVisible_ = false;
1044     ASSERT_NE(nullptr, ssm_);
1045     ssm_->CheckAndNotifyWaterMarkChangedResult();
1046     sceneSession->isRSVisible_ = true;
1047     ASSERT_NE(nullptr, ssm_);
1048     ssm_->CheckAndNotifyWaterMarkChangedResult();
1049 }
1050 
1051 /**
1052  * @tc.name: CheckAndNotifyWaterMarkChangedResult02
1053  * @tc.desc: CheckAndNotifyWaterMarkChangedResult02
1054  * @tc.type: FUNC
1055  */
HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult02, Function | SmallTest | Level3)1056 HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult02, Function | SmallTest | Level3)
1057 {
1058     ASSERT_NE(nullptr, ssm_);
1059     ssm_->sceneSessionMap_.clear();
1060     ssm_->lastWaterMarkShowState_ = true;
1061     ssm_->CheckAndNotifyWaterMarkChangedResult();
1062     ASSERT_NE(nullptr, ssm_);
1063     ssm_->lastWaterMarkShowState_ = false;
1064     ssm_->CheckAndNotifyWaterMarkChangedResult();
1065 }
1066 
1067 /**
1068  * @tc.name: FillWindowInfo
1069  * @tc.desc: FillWindowInfo
1070  * @tc.type: FUNC
1071  */
HWTEST_F(SceneSessionManagerTest6, FillWindowInfo, Function | SmallTest | Level3)1072 HWTEST_F(SceneSessionManagerTest6, FillWindowInfo, Function | SmallTest | Level3)
1073 {
1074     std::vector<sptr<AccessibilityWindowInfo>> infos;
1075     sptr<SceneSession> sceneSession = nullptr;
1076     ASSERT_NE(nullptr, ssm_);
1077     auto ret = ssm_->FillWindowInfo(infos, sceneSession);
1078     EXPECT_EQ(false, ret);
1079     SessionInfo sessionInfo;
1080     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1081     sessionInfo.abilityName_ = "DumpSessionWithId";
1082     sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1083     ASSERT_NE(nullptr, ssm_);
1084     ASSERT_NE(nullptr, sceneSession);
1085     ret = ssm_->FillWindowInfo(infos, sceneSession);
1086     EXPECT_EQ(true, ret);
1087     sessionInfo.bundleName_ = "SCBGestureBack";
1088     sessionInfo.isSystem_ = true;
1089     ASSERT_NE(nullptr, ssm_);
1090     ret = ssm_->FillWindowInfo(infos, sceneSession);
1091     EXPECT_EQ(true, ret);
1092     sessionInfo.isSystem_ = false;
1093     ASSERT_NE(nullptr, ssm_);
1094     ret = ssm_->FillWindowInfo(infos, sceneSession);
1095     EXPECT_EQ(true, ret);
1096     sceneSession->property_ = nullptr;
1097     ASSERT_NE(nullptr, ssm_);
1098     ret = ssm_->FillWindowInfo(infos, sceneSession);
1099     EXPECT_EQ(true, ret);
1100     sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1101     ASSERT_NE(nullptr, sceneSession->property_);
1102     ASSERT_NE(nullptr, ssm_);
1103     ret = ssm_->FillWindowInfo(infos, sceneSession);
1104     EXPECT_EQ(true, ret);
1105 }
1106 
1107 /**
1108  * @tc.name: SetSessionVisibilityInfo
1109  * @tc.desc: SetSessionVisibilityInfo
1110  * @tc.type: FUNC
1111  */
HWTEST_F(SceneSessionManagerTest6, SetSessionVisibilityInfo, Function | SmallTest | Level3)1112 HWTEST_F(SceneSessionManagerTest6, SetSessionVisibilityInfo, Function | SmallTest | Level3)
1113 {
1114     sptr<SceneSession> session = nullptr;
1115     WindowVisibilityState visibleState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION;
1116     std::vector<sptr<WindowVisibilityInfo>> windowVisibilityInfos;
1117     std::string visibilityInfo = "";
1118     ASSERT_NE(nullptr, ssm_);
1119     ssm_->SetSessionVisibilityInfo(session, visibleState, windowVisibilityInfos, visibilityInfo);
1120     SessionInfo sessionInfo;
1121     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1122     sessionInfo.abilityName_ = "DumpSessionWithId";
1123     session = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1124     ASSERT_NE(nullptr, ssm_);
1125     ASSERT_NE(nullptr, session);
1126     session->persistentId_ = 1;
1127     ssm_->windowVisibilityListenerSessionSet_.clear();
1128     ssm_->SetSessionVisibilityInfo(session, visibleState, windowVisibilityInfos, visibilityInfo);
1129     ssm_->windowVisibilityListenerSessionSet_.insert(1);
1130     ssm_->SetSessionVisibilityInfo(session, visibleState, windowVisibilityInfos, visibilityInfo);
1131 }
1132 
1133 /**
1134  * @tc.name: SendTouchEvent
1135  * @tc.desc: SendTouchEvent
1136  * @tc.type: FUNC
1137  */
HWTEST_F(SceneSessionManagerTest6, SendTouchEvent, Function | SmallTest | Level3)1138 HWTEST_F(SceneSessionManagerTest6, SendTouchEvent, Function | SmallTest | Level3)
1139 {
1140     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
1141     ASSERT_NE(nullptr, ssm_);
1142     auto ret = ssm_->SendTouchEvent(pointerEvent, 0);
1143     EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret);
1144     MMI::PointerEvent::PointerItem pointerItem;
1145     pointerItem.pointerId_ = 0;
1146     pointerEvent = MMI::PointerEvent::Create();
1147     ASSERT_NE(nullptr, pointerEvent);
1148     pointerEvent->pointerId_ = 0;
1149     pointerEvent->AddPointerItem(pointerItem);
1150     ASSERT_NE(nullptr, ssm_);
1151     ret = ssm_->SendTouchEvent(pointerEvent, 0);
1152     EXPECT_EQ(WSError::WS_OK, ret);
1153     pointerEvent->pointerId_ = 1;
1154     ASSERT_NE(nullptr, ssm_);
1155     ret = ssm_->SendTouchEvent(pointerEvent, 0);
1156     EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, ret);
1157     ASSERT_NE(nullptr, ssm_);
1158     ssm_->RegisterWindowChanged(WindowChangedFuncTest);
1159 }
1160 
1161 /**
1162  * @tc.name: JudgeNeedNotifyPrivacyInfo
1163  * @tc.desc: JudgeNeedNotifyPrivacyInfo
1164  * @tc.type: FUNC
1165  */
HWTEST_F(SceneSessionManagerTest6, JudgeNeedNotifyPrivacyInfo, Function | SmallTest | Level3)1166 HWTEST_F(SceneSessionManagerTest6, JudgeNeedNotifyPrivacyInfo, Function | SmallTest | Level3)
1167 {
1168     DisplayId displayId = 1;
1169     std::unordered_set<std::string> privacyBundles;
1170     ssm_->privacyBundleMap_.clear();
1171     ASSERT_NE(nullptr, ssm_);
1172     auto ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1173     EXPECT_EQ(true, ret);
1174     privacyBundles.insert("bundle1");
1175     ASSERT_NE(nullptr, ssm_);
1176     ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1177     EXPECT_EQ(true, ret);
1178     std::unordered_set<std::string> privacyBundles1;
1179     privacyBundles1.insert("bundle2");
1180     ASSERT_NE(nullptr, ssm_);
1181     ssm_->privacyBundleMap_.insert({displayId, privacyBundles1});
1182     ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1183     EXPECT_EQ(true, ret);
1184     privacyBundles.insert("bundle2");
1185     ASSERT_NE(nullptr, ssm_);
1186     ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1187     EXPECT_EQ(true, ret);
1188     ASSERT_NE(nullptr, ssm_);
1189     ssm_->InitPersistentStorage();
1190     ASSERT_NE(nullptr, ssm_);
1191     ssm_->UpdateCameraFloatWindowStatus(0, true);
1192     ASSERT_NE(nullptr, ssm_);
1193     ssm_->UpdateCameraWindowStatus(0, true);
1194 }
1195 
1196 /**
1197  * @tc.name: UpdatePrivateStateAndNotify
1198  * @tc.desc: UpdatePrivateStateAndNotify
1199  * @tc.type: FUNC
1200  */
HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify, Function | SmallTest | Level3)1201 HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify, Function | SmallTest | Level3)
1202 {
1203     ASSERT_NE(nullptr, ssm_);
1204     ssm_->sceneSessionMap_.clear();
1205     ssm_->privacyBundleMap_.clear();
1206     SessionInfo sessionInfo;
1207     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1208     sessionInfo.abilityName_ = "DumpSessionWithId";
1209     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1210     ASSERT_NE(nullptr, sceneSession);
1211     ASSERT_NE(nullptr, ssm_);
1212     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1213     sceneSession->property_ = nullptr;
1214     ASSERT_NE(nullptr, ssm_);
1215     ssm_->UpdatePrivateStateAndNotify(1);
1216     ASSERT_EQ(ssm_->privacyBundleMap_[1].size(), 0);
1217     ASSERT_NE(nullptr, ssm_);
1218     ssm_->UpdatePrivateStateAndNotifyForAllScreens();
1219 }
1220 
1221 /**
1222  * @tc.name: UpdatePrivateStateAndNotify2
1223  * @tc.desc: UpdatePrivateStateAndNotify2
1224  * @tc.type: FUNC
1225  */
HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify2, Function | SmallTest | Level3)1226 HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify2, Function | SmallTest | Level3)
1227 {
1228     ASSERT_NE(nullptr, ssm_);
1229     ssm_->sceneSessionMap_.clear();
1230     ssm_->privacyBundleMap_.clear();
1231     SessionInfo sessionInfo;
1232     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1233     sessionInfo.abilityName_ = "DumpSessionWithId";
1234     sessionInfo.isSystem_ = true;
1235     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1236     ASSERT_NE(nullptr, sceneSession);
1237     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1238     sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1239     ASSERT_NE(nullptr, sceneSession->property_);
1240     sceneSession->property_->SetPrivacyMode(true);
1241     sceneSession->property_->SetDisplayId(1);
1242     sceneSession->isVisible_ = false;
1243     std::unordered_set<std::string> privacyBundles1;
1244     std::unordered_set<std::string> privacyBundles2;
1245     std::unordered_set<std::string> privacyBundles3;
1246     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1247     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
1248     ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession));
1249     ssm_->UpdatePrivateStateAndNotify(1);
1250     ASSERT_EQ(ssm_->privacyBundleMap_[1].size(), 1);
1251     sceneSession->SetSessionState(SessionState::STATE_BACKGROUND);
1252     sceneSession->property_->SetPrivacyMode(true);
1253     sceneSession->property_->SetDisplayId(2);
1254     sceneSession->isVisible_ = true;
1255     ssm_->UpdatePrivateStateAndNotify(2);
1256     ASSERT_EQ(ssm_->privacyBundleMap_[2].size(), 1);
1257     sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1258     sceneSession->property_->SetPrivacyMode(false);
1259     sceneSession->property_->SetDisplayId(3);
1260     ssm_->UpdatePrivateStateAndNotify(3);
1261     ASSERT_EQ(ssm_->privacyBundleMap_[3].size(), 0);
1262 }
1263 
1264 /**
1265  * @tc.name: GetCollaboratorByType
1266  * @tc.desc: GetCollaboratorByType
1267  * @tc.type: FUNC
1268  */
HWTEST_F(SceneSessionManagerTest6, GetCollaboratorByType, Function | SmallTest | Level3)1269 HWTEST_F(SceneSessionManagerTest6, GetCollaboratorByType, Function | SmallTest | Level3)
1270 {
1271     ASSERT_NE(nullptr, ssm_);
1272     ssm_->collaboratorMap_.clear();
1273     auto ret = ssm_->GetCollaboratorByType(0);
1274     EXPECT_EQ(nullptr, ret);
1275     sptr<AAFwk::IAbilityManagerCollaborator> collaborator = nullptr;
1276     ASSERT_NE(nullptr, ssm_);
1277     ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator));
1278     ret = ssm_->GetCollaboratorByType(1);
1279     EXPECT_EQ(nullptr, ret);
1280 }
1281 
1282 /**
1283  * @tc.name: RegisterGetStateFromManagerFunc
1284  * @tc.desc: RegisterGetStateFromManagerFunc
1285  * @tc.type: FUNC
1286  */
HWTEST_F(SceneSessionManagerTest6, RegisterGetStateFromManagerFunc, Function | SmallTest | Level3)1287 HWTEST_F(SceneSessionManagerTest6, RegisterGetStateFromManagerFunc, Function | SmallTest | Level3)
1288 {
1289     SessionInfo sessionInfo;
1290     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1291     sessionInfo.abilityName_ = "DumpSessionWithId";
1292     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1293     ASSERT_NE(nullptr, ssm_);
1294     ASSERT_NE(nullptr, sceneSession);
1295     ssm_->RegisterGetStateFromManagerFunc(sceneSession);
1296     sceneSession = nullptr;
1297     ASSERT_NE(nullptr, ssm_);
1298     ssm_->RegisterGetStateFromManagerFunc(sceneSession);
1299 }
1300 
1301 /**
1302  * @tc.name: ProcessDialogRequestFocusImmdediately
1303  * @tc.desc: ProcessDialogRequestFocusImmdediately
1304  * @tc.type: FUNC
1305  */
HWTEST_F(SceneSessionManagerTest6, ProcessDialogRequestFocusImmdediately, Function | SmallTest | Level3)1306 HWTEST_F(SceneSessionManagerTest6, ProcessDialogRequestFocusImmdediately, Function | SmallTest | Level3)
1307 {
1308     SessionInfo sessionInfo;
1309     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1310     sessionInfo.abilityName_ = "DumpSessionWithId";
1311     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1312     ASSERT_NE(nullptr, sceneSession->property_);
1313     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1314     ASSERT_NE(nullptr, ssm_);
1315     auto ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1316     EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1317     ASSERT_NE(nullptr, sceneSession->property_);
1318     sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1319     ASSERT_NE(nullptr, ssm_);
1320     ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1321     EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1322     ASSERT_NE(nullptr, sceneSession->property_);
1323     sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_END);
1324     ASSERT_NE(nullptr, ssm_);
1325     ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1326     EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1327 }
1328 
1329 /**
1330  * @tc.name: ProcessSubSessionBackground
1331  * @tc.desc: ProcessSubSessionBackground
1332  * @tc.type: FUNC
1333  */
HWTEST_F(SceneSessionManagerTest6, ProcessSubSessionBackground, Function | SmallTest | Level3)1334 HWTEST_F(SceneSessionManagerTest6, ProcessSubSessionBackground, Function | SmallTest | Level3)
1335 {
1336     sptr<SceneSession> sceneSession = nullptr;
1337     ASSERT_NE(nullptr, ssm_);
1338     ssm_->ProcessSubSessionBackground(sceneSession);
1339     SessionInfo sessionInfo;
1340     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1341     sessionInfo.abilityName_ = "DumpSessionWithId";
1342     sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1343     ASSERT_NE(nullptr, sceneSession);
1344     ASSERT_NE(nullptr, ssm_);
1345     ssm_->ProcessSubSessionBackground(sceneSession);
1346     sptr<SceneSession> subSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1347     ASSERT_NE(nullptr, sceneSession);
1348     ASSERT_NE(nullptr, subSession);
1349     sceneSession->AddSubSession(subSession);
1350     subSession->state_ = SessionState::STATE_FOREGROUND;
1351     ASSERT_NE(nullptr, ssm_);
1352     ssm_->ProcessSubSessionBackground(sceneSession);
1353     ASSERT_NE(nullptr, subSession);
1354     subSession->state_ = SessionState::STATE_ACTIVE;
1355     ASSERT_NE(nullptr, ssm_);
1356     ssm_->ProcessSubSessionBackground(sceneSession);
1357     ASSERT_NE(nullptr, subSession);
1358     subSession->state_ = SessionState::STATE_INACTIVE;
1359     ASSERT_NE(nullptr, ssm_);
1360     ssm_->ProcessSubSessionBackground(sceneSession);
1361 }
1362 
1363 /**
1364  * @tc.name: ProcessSubSessionBackground01
1365  * @tc.desc: ProcessSubSessionBackground01
1366  * @tc.type: FUNC
1367  */
HWTEST_F(SceneSessionManagerTest6, ProcessSubSessionBackground01, Function | SmallTest | Level3)1368 HWTEST_F(SceneSessionManagerTest6, ProcessSubSessionBackground01, Function | SmallTest | Level3)
1369 {
1370     SessionInfo sessionInfo;
1371     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1372     sessionInfo.abilityName_ = "DumpSessionWithId";
1373     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1374     ASSERT_NE(nullptr, sceneSession);
1375     sceneSession->dialogVec_.clear();
1376     ASSERT_NE(nullptr, ssm_);
1377     ssm_->ProcessSubSessionBackground(sceneSession);
1378     sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1379     ASSERT_NE(nullptr, sceneSession1);
1380     ASSERT_NE(nullptr, sceneSession);
1381     sceneSession->dialogVec_.push_back(sceneSession1);
1382     ASSERT_NE(nullptr, ssm_);
1383     ssm_->sceneSessionMap_.clear();
1384     sceneSession1->persistentId_ = 1;
1385     ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession));
1386     ssm_->ProcessSubSessionBackground(sceneSession);
1387     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1388     ssm_->ProcessSubSessionBackground(sceneSession);
1389     sptr<SceneSession> toastSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1390     ASSERT_NE(nullptr, toastSession);
1391     ASSERT_NE(nullptr, sceneSession);
1392     sceneSession->AddToastSession(toastSession);
1393     toastSession->state_ = SessionState::STATE_FOREGROUND;
1394     ASSERT_NE(nullptr, ssm_);
1395     ssm_->ProcessSubSessionBackground(sceneSession);
1396     toastSession->state_ = SessionState::STATE_ACTIVE;
1397     ssm_->ProcessSubSessionBackground(sceneSession);
1398     toastSession->state_ = SessionState::STATE_INACTIVE;
1399     ssm_->ProcessSubSessionBackground(sceneSession);
1400 }
1401 
1402 /**
1403  * @tc.name: IsValidSessionIds
1404  * @tc.desc: IsValidSessionIds
1405  * @tc.type: FUNC
1406  */
HWTEST_F(SceneSessionManagerTest6, IsValidSessionIds, Function | SmallTest | Level3)1407 HWTEST_F(SceneSessionManagerTest6, IsValidSessionIds, Function | SmallTest | Level3)
1408 {
1409     std::vector<int32_t> sessionIds = {1, 2, 3, 4};
1410     std::vector<bool> results;
1411     results.clear();
1412     SessionInfo sessionInfo;
1413     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1414     sessionInfo.abilityName_ = "DumpSessionWithId";
1415     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1416     ASSERT_NE(nullptr, sceneSession);
1417     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1418     sptr<SceneSession> sceneSession1 = nullptr;
1419     ASSERT_NE(nullptr, ssm_);
1420     ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
1421     ssm_->IsValidSessionIds(sessionIds, results);
1422     EXPECT_FALSE(results.empty());
1423     DisplayChangeListener listener;
1424     std::vector<uint64_t> missionIds;
1425     std::vector<uint64_t> surfaceNodeIds;
1426     listener.OnGetSurfaceNodeIdsFromMissionIds(missionIds, surfaceNodeIds);
1427 }
1428 
1429 /**
1430  * @tc.name: DeleteStateDetectTask
1431  * @tc.desc: DeleteStateDetectTask
1432  * @tc.type: FUNC
1433  */
HWTEST_F(SceneSessionManagerTest6, DeleteStateDetectTask, Function | SmallTest | Level3)1434 HWTEST_F(SceneSessionManagerTest6, DeleteStateDetectTask, Function | SmallTest | Level3)
1435 {
1436     ASSERT_NE(nullptr, ssm_);
1437     ssm_->SetScreenLocked(true);
1438     EXPECT_EQ(true, ssm_->isScreenLocked_);
1439     ssm_->sceneSessionMap_.clear();
1440     ASSERT_NE(nullptr, ssm_);
1441     ssm_->DeleteStateDetectTask();
1442     SessionInfo sessionInfo;
1443     sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1444     sessionInfo.abilityName_ = "DumpSessionWithId";
1445     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1446     ASSERT_NE(nullptr, sceneSession);
1447     sceneSession->detectTaskInfo_.taskState = DetectTaskState::NO_TASK;
1448     ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1449     ASSERT_NE(nullptr, ssm_);
1450     ssm_->DeleteStateDetectTask();
1451     sceneSession->detectTaskInfo_.taskState = DetectTaskState::ATTACH_TASK;
1452     ASSERT_NE(nullptr, ssm_);
1453     ssm_->DeleteStateDetectTask();
1454 }
1455 
1456 /**
1457  * @tc.name: GetWindowStyleType
1458  * @tc.desc: GetWindowStyleType
1459  * @tc.type: FUNC
1460 */
HWTEST_F(SceneSessionManagerTest6, GetWindowStyleType, Function | SmallTest | Level3)1461 HWTEST_F(SceneSessionManagerTest6, GetWindowStyleType, Function | SmallTest | Level3)
1462 {
1463     ASSERT_NE(nullptr, ssm_);
1464     WindowStyleType windowModeType = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
1465     ssm_->GetWindowStyleType(windowModeType);
1466     ASSERT_EQ(windowModeType, Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT);
1467 }
1468 
1469 /**
1470  * @tc.name: TerminateSessionByPersistentId
1471  * @tc.desc: Success to terminate session by persistentId.
1472  * @tc.type: FUNC
1473  */
HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId001, Function | SmallTest | Level3)1474 HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId001, Function | SmallTest | Level3)
1475 {
1476     SessionInfo info;
1477     info.abilityName_ = "test1";
1478     info.bundleName_ = "test1";
1479     info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1480     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1481     ASSERT_NE(nullptr, sceneSession);
1482     ASSERT_NE(nullptr, ssm_);
1483     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
1484     auto result = ssm_->TerminateSessionByPersistentId(sceneSession->GetPersistentId());
1485     EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
1486 }
1487 
1488 /**
1489  * @tc.name: TerminateSessionByPersistentId
1490  * @tc.desc: Fail to terminate session by persistentId, invalid persistentId.
1491  * @tc.type: FUNC
1492  */
HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId002, Function | SmallTest | Level3)1493 HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId002, Function | SmallTest | Level3)
1494 {
1495     SessionInfo info;
1496     info.abilityName_ = "test1";
1497     info.bundleName_ = "test1";
1498     info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1499     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1500     ASSERT_NE(nullptr, sceneSession);
1501     ASSERT_NE(nullptr, ssm_);
1502     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
1503     auto result = ssm_->TerminateSessionByPersistentId(INVALID_SESSION_ID);
1504     EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
1505 }
1506 
1507 /**
1508  * @tc.name: SetRootSceneProcessBackEventFunc
1509  * @tc.desc: test function : SetRootSceneProcessBackEventFunc
1510  * @tc.type: FUNC
1511  */
HWTEST_F(SceneSessionManagerTest6, SetRootSceneProcessBackEventFunc, Function | SmallTest | Level3)1512 HWTEST_F(SceneSessionManagerTest6, SetRootSceneProcessBackEventFunc, Function | SmallTest | Level3)
1513 {
1514     SessionInfo sessionInfo;
1515     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1516     sessionInfo.abilityName_ = "SetRootSceneProcessBackEventFunc";
1517     sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1518     sessionInfo.isSystem_ = true;
1519     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1520     ASSERT_NE(nullptr, sceneSession);
1521     ASSERT_NE(nullptr, ssm_);
1522     ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
1523     ssm_->focusedSessionId_ = sceneSession->GetPersistentId();
1524     ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
1525     ssm_->ProcessBackEvent();
1526 
1527     RootSceneProcessBackEventFunc func = []() {};
1528     ssm_->SetRootSceneProcessBackEventFunc(func);
1529     ssm_->ProcessBackEvent();
1530 }
1531 
1532 /**
1533  * @tc.name: OnScreenFoldStatusChanged
1534  * @tc.desc: OnScreenFoldStatusChanged
1535  * @tc.type: FUNC
1536  */
HWTEST_F(SceneSessionManagerTest6, OnScreenFoldStatusChanged, Function | SmallTest | Level3)1537 HWTEST_F(SceneSessionManagerTest6, OnScreenFoldStatusChanged, Function | SmallTest | Level3)
1538 {
1539     std::vector<std::string> screenFoldInfo;
1540     sptr<IDisplayChangeListener> listener = sptr<DisplayChangeListener>::MakeSptr();
1541     ASSERT_NE(nullptr, listener);
1542     listener->OnScreenFoldStatusChanged(screenFoldInfo);
1543     ASSERT_NE(nullptr, ssm_);
1544     auto ret = ssm_->UpdateDisplayHookInfo(0, 50, 50, 0.0f, true);
1545     EXPECT_EQ(ret, WMError::WM_OK);
1546     ssm_->CheckSceneZOrder();
1547 }
1548 
1549 /**
1550  * @tc.name: NotifySessionForeground
1551  * @tc.desc: NotifySessionForeground
1552  * @tc.type: FUNC
1553  */
HWTEST_F(SceneSessionManagerTest6, NotifySessionForeground, Function | SmallTest | Level3)1554 HWTEST_F(SceneSessionManagerTest6, NotifySessionForeground, Function | SmallTest | Level3)
1555 {
1556     SessionInfo sessionInfo;
1557     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1558     sessionInfo.abilityName_ = "NotifySessionForeground";
1559     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1560     uint32_t reason = 0;
1561     bool withAnimation = false;
1562     ASSERT_NE(nullptr, ssm_);
1563     ssm_->NotifySessionForeground(sceneSession, reason, withAnimation);
1564     WSRect area = { 0, 0, 0, 0 };
1565     uint32_t type = 0;
1566     uint64_t displayId = 0;
1567     ssm_->AddWindowDragHotArea(displayId, type, area);
1568     ssm_->currAINavigationBarAreaMap_.clear();
1569     ssm_->currAINavigationBarAreaMap_.insert(std::make_pair(displayId, area));
1570     auto ret = ssm_->GetAINavigationBarArea(1);
1571     EXPECT_TRUE(ret.IsEmpty());
1572     ret = ssm_->GetAINavigationBarArea(displayId);
1573     EXPECT_EQ(ret, area);
1574 }
1575 
1576 /**
1577  * @tc.name: OnDisplayStateChange
1578  * @tc.desc: OnDisplayStateChange
1579  * @tc.type: FUNC
1580  */
HWTEST_F(SceneSessionManagerTest6, OnDisplayStateChange, Function | SmallTest | Level3)1581 HWTEST_F(SceneSessionManagerTest6, OnDisplayStateChange, Function | SmallTest | Level3)
1582 {
1583     DisplayChangeListener listener;
1584     DisplayId displayId = 0;
1585     sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
1586     ASSERT_NE(nullptr, displayInfo);
1587     std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
1588     displayInfoMap.insert(std::make_pair(displayId, displayInfo));
1589     DisplayStateChangeType type = DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE;
1590     listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1591     type = DisplayStateChangeType::UPDATE_ROTATION;
1592     listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1593     type = DisplayStateChangeType::UPDATE_SCALE;
1594     listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1595     type = DisplayStateChangeType::UNKNOWN;
1596     listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1597 }
1598 
1599 /**
1600  * @tc.name: UpdateSessionAvoidAreaIfNeed
1601  * @tc.desc: UpdateSessionAvoidAreaIfNeed
1602  * @tc.type: FUNC
1603  */
HWTEST_F(SceneSessionManagerTest6, UpdateSessionAvoidAreaIfNeed, Function | SmallTest | Level3)1604 HWTEST_F(SceneSessionManagerTest6, UpdateSessionAvoidAreaIfNeed, Function | SmallTest | Level3)
1605 {
1606     int32_t persistentId = 0;
1607     sptr<SceneSession> sceneSession = nullptr;
1608     AvoidArea avoidArea;
1609     AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_KEYBOARD;
1610     ASSERT_NE(nullptr, ssm_);
1611     ssm_->enterRecent_ = false;
1612     auto ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1613     EXPECT_EQ(ret, false);
1614     ssm_->enterRecent_ = true;
1615     ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1616     EXPECT_EQ(ret, false);
1617     SessionInfo sessionInfo;
1618     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1619     sessionInfo.abilityName_ = "UpdateSessionAvoidAreaIfNeed";
1620     sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1621     ASSERT_NE(nullptr, sceneSession);
1622     ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1623     EXPECT_EQ(ret, false);
1624     ssm_->enterRecent_ = false;
1625     ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1626     EXPECT_EQ(ret, false);
1627     ssm_->lastUpdatedAvoidArea_.clear();
1628     ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1629     EXPECT_EQ(ret, false);
1630 }
1631 
1632 /**
1633  * @tc.name: UpdateSessionAvoidAreaIfNeed01
1634  * @tc.desc: UpdateSessionAvoidAreaIfNeed
1635  * @tc.type: FUNC
1636  */
HWTEST_F(SceneSessionManagerTest6, UpdateSessionAvoidAreaIfNeed01, Function | SmallTest | Level3)1637 HWTEST_F(SceneSessionManagerTest6, UpdateSessionAvoidAreaIfNeed01, Function | SmallTest | Level3)
1638 {
1639     int32_t persistentId = 0;
1640     AvoidArea avoidArea;
1641     AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_KEYBOARD;
1642     SessionInfo sessionInfo;
1643     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1644     sessionInfo.abilityName_ = "UpdateSessionAvoidAreaIfNeed";
1645     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1646     ASSERT_NE(nullptr, sceneSession);
1647     ASSERT_NE(nullptr, ssm_);
1648     ssm_->enterRecent_ = false;
1649     std::map<AvoidAreaType, AvoidArea> mapAvoidAreaType;
1650     mapAvoidAreaType.insert(std::make_pair(avoidAreaType, avoidArea));
1651     ssm_->lastUpdatedAvoidArea_.insert(std::make_pair(persistentId, mapAvoidAreaType));
1652     auto ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1653     EXPECT_EQ(ret, false);
1654     avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
1655     ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1656     EXPECT_EQ(ret, false);
1657     avoidArea.topRect_.posX_ = 1;
1658     ret = ssm_->UpdateSessionAvoidAreaIfNeed(persistentId, sceneSession, avoidArea, avoidAreaType);
1659     EXPECT_EQ(ret, true);
1660 }
1661 
1662 /**
1663  * @tc.name: CheckIfReuseSession
1664  * @tc.desc: CheckIfReuseSession
1665  * @tc.type: FUNC
1666  */
HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession, Function | SmallTest | Level3)1667 HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession, Function | SmallTest | Level3)
1668 {
1669     SessionInfo sessionInfo;
1670     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1671     sessionInfo.abilityName_ = "CheckIfReuseSession";
1672     ASSERT_NE(nullptr, ssm_);
1673     auto ret = ssm_->CheckIfReuseSession(sessionInfo);
1674     EXPECT_EQ(ret, BrokerStates::BROKER_UNKOWN);
1675     ScreenId screenId = 0;
1676     std::unordered_map<int32_t, SessionUIParam> uiParams;
1677     ssm_->FlushUIParams(screenId, std::move(uiParams));
1678 }
1679 
1680 /**
1681  * @tc.name: UpdateAvoidArea
1682  * @tc.desc: UpdateAvoidArea
1683  * @tc.type: FUNC
1684  */
HWTEST_F(SceneSessionManagerTest6, UpdateAvoidArea, Function | SmallTest | Level3)1685 HWTEST_F(SceneSessionManagerTest6, UpdateAvoidArea, Function | SmallTest | Level3)
1686 {
1687     int32_t persistentId = 0;
1688     ASSERT_NE(nullptr, ssm_);
1689     ssm_->sceneSessionMap_.clear();
1690     ssm_->UpdateAvoidArea(persistentId);
1691     SessionInfo sessionInfo;
1692     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1693     sessionInfo.abilityName_ = "UpdateAvoidArea";
1694     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1695     ASSERT_NE(nullptr, sceneSession);
1696     ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1697     ASSERT_NE(nullptr, sceneSession->property_);
1698     sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
1699     ssm_->UpdateAvoidArea(persistentId);
1700     sceneSession->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
1701     ssm_->UpdateAvoidArea(persistentId);
1702 }
1703 
1704 /**
1705  * @tc.name: UpdateMaximizeMode
1706  * @tc.desc: UpdateMaximizeMode
1707  * @tc.type: FUNC
1708  */
HWTEST_F(SceneSessionManagerTest6, UpdateMaximizeMode, Function | SmallTest | Level3)1709 HWTEST_F(SceneSessionManagerTest6, UpdateMaximizeMode, Function | SmallTest | Level3)
1710 {
1711     int32_t persistentId = 0;
1712     bool isMaximize = true;
1713     ASSERT_NE(nullptr, ssm_);
1714     ssm_->sceneSessionMap_.clear();
1715     auto ret = ssm_->UpdateMaximizeMode(persistentId, isMaximize);
1716     EXPECT_EQ(ret, WSError::WS_OK);
1717     SessionInfo sessionInfo;
1718     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1719     sessionInfo.abilityName_ = "UpdateMaximizeMode";
1720     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1721     ASSERT_NE(nullptr, sceneSession);
1722     ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1723     EXPECT_EQ(ret, WSError::WS_OK);
1724     sptr<DisplayInfo> displayInfo = nullptr;
1725     ssm_->ProcessDisplayScale(displayInfo);
1726     displayInfo = sptr<DisplayInfo>::MakeSptr();
1727     ASSERT_NE(nullptr, displayInfo);
1728     ssm_->ProcessDisplayScale(displayInfo);
1729     ProcessVirtualPixelRatioChangeFunc func = nullptr;
1730     ssm_->SetVirtualPixelRatioChangeListener(func);
1731 }
1732 
1733 /**
1734  * @tc.name: WindowDestroyNotifyVisibility
1735  * @tc.desc: WindowDestroyNotifyVisibility
1736  * @tc.type: FUNC
1737  */
HWTEST_F(SceneSessionManagerTest6, WindowDestroyNotifyVisibility, Function | SmallTest | Level3)1738 HWTEST_F(SceneSessionManagerTest6, WindowDestroyNotifyVisibility, Function | SmallTest | Level3)
1739 {
1740     SessionInfo sessionInfo;
1741     sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1742     sessionInfo.abilityName_ = "WindowDestroyNotifyVisibility";
1743     sptr<SceneSession> sceneSession = nullptr;
1744     ssm_->WindowDestroyNotifyVisibility(sceneSession);
1745     sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1746     ASSERT_NE(nullptr, sceneSession);
1747     sceneSession->SetRSVisible(false);
1748     ssm_->WindowDestroyNotifyVisibility(sceneSession);
1749     sceneSession->SetRSVisible(true);
1750     ASSERT_NE(nullptr, ssm_);
1751     ssm_->WindowDestroyNotifyVisibility(sceneSession);
1752     ASSERT_FALSE(sceneSession->GetRSVisible());
1753 }
1754 
1755 /**
1756  * @tc.name: RequestInputMethodCloseKeyboard
1757  * @tc.desc: RequestInputMethodCloseKeyboard
1758  * @tc.type: FUNC
1759  */
HWTEST_F(SceneSessionManagerTest6, RequestInputMethodCloseKeyboard, Function | SmallTest | Level3)1760 HWTEST_F(SceneSessionManagerTest6, RequestInputMethodCloseKeyboard, Function | SmallTest | Level3)
1761 {
1762     ASSERT_NE(nullptr, ssm_);
1763     SessionInfo info;
1764     sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1765     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
1766     ssm_->sceneSessionMap_.insert({0, sceneSession});
1767     int32_t persistentId = 10;
1768     ssm_->RequestInputMethodCloseKeyboard(persistentId);
1769 
1770     persistentId = 0;
1771     sptr<Session> session = new Session(info);
1772     session->property_ = nullptr;
1773     ssm_->RequestInputMethodCloseKeyboard(persistentId);
1774 
1775     bool enable = true;
1776     auto result = ssm_->GetFreeMultiWindowEnableState(enable);
1777     ASSERT_EQ(result, WSError::WS_OK);
1778 }
1779 
1780 /**
1781  * @tc.name: RequestSceneSession
1782  * @tc.desc: RequestSceneSession
1783  * @tc.type: FUNC
1784  */
HWTEST_F(SceneSessionManagerTest6, RequestSceneSession, Function | SmallTest | Level3)1785 HWTEST_F(SceneSessionManagerTest6, RequestSceneSession, Function | SmallTest | Level3)
1786 {
1787     SessionInfo info1;
1788     info1.persistentId_ = 1;
1789     info1.isPersistentRecover_ = false;
1790     sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
1791 
1792     SessionInfo info2;
1793     info2.abilityName_ = "RequestSceneSession";
1794     info2.bundleName_ = "RequestSceneSession";
1795     info2.persistentId_ = 1;
1796 
1797     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
1798     ASSERT_NE(sceneSession, nullptr);
1799     ssm_->sceneSessionMap_.insert({1, sceneSession});
1800     sptr<SceneSession> getSceneSession1 = ssm_->RequestSceneSession(info1, windowSessionProperty);
1801     ASSERT_EQ(info1.bundleName_, getSceneSession1->GetSessionInfo().bundleName_);
1802 
1803     sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
1804     ssm_->sceneSessionMap_.insert({2, sceneSession2});
1805     sptr<SceneSession> getSceneSession2 = ssm_->RequestSceneSession(info2, windowSessionProperty);
1806     ASSERT_NE(info2.bundleName_, getSceneSession2->GetSessionInfo().bundleName_);
1807 }
1808 
1809 /**
1810  * @tc.name: IsKeyboardForeground
1811  * @tc.desc: IsKeyboardForeground
1812  * @tc.type: FUNC
1813  */
HWTEST_F(SceneSessionManagerTest6, IsKeyboardForeground, Function | SmallTest | Level3)1814 HWTEST_F(SceneSessionManagerTest6, IsKeyboardForeground, Function | SmallTest | Level3)
1815 {
1816     ASSERT_NE(nullptr, ssm_);
1817     SessionInfo info;
1818     sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1819     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
1820     ASSERT_NE(sceneSession, nullptr);
1821     sptr<Session> session = new Session(info);
1822     ASSERT_NE(session, nullptr);
1823     session->property_ = nullptr;
1824     auto result = ssm_->IsKeyboardForeground();
1825     ASSERT_EQ(result, false);
1826 
1827     ssm_->sceneSessionMap_.insert({0, sceneSession});
1828     session->property_ = new WindowSessionProperty();
1829     ASSERT_NE(session->property_, nullptr);
1830 
1831     if (session->property_) {
1832         auto result1 = session->GetWindowType();
1833         result1 = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT;
1834         ASSERT_EQ(result1, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1835     }
1836     result = ssm_->IsKeyboardForeground();
1837     ASSERT_EQ(result, false);
1838 }
1839 
1840 /**
1841  * @tc.name: DestroyDialogWithMainWindow
1842  * @tc.desc: DestroyDialogWithMainWindow
1843  * @tc.type: FUNC
1844  */
HWTEST_F(SceneSessionManagerTest6, DestroyDialogWithMainWindow, Function | SmallTest | Level3)1845 HWTEST_F(SceneSessionManagerTest6, DestroyDialogWithMainWindow, Function | SmallTest | Level3)
1846 {
1847     sptr<SceneSession> scnSession = nullptr;
1848     auto result = ssm_->DestroyDialogWithMainWindow(scnSession);
1849     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
1850 
1851     SessionInfo info;
1852     sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1853     scnSession = new (std::nothrow) SceneSession(info, specificCallback);
1854     ASSERT_NE(scnSession, nullptr);
1855 
1856     sptr<Session> session = new Session(info);
1857     ASSERT_NE(session, nullptr);
1858     session->GetDialogVector().clear();
1859     result = ssm_->DestroyDialogWithMainWindow(scnSession);
1860     ASSERT_EQ(result, WSError::WS_OK);
1861 
1862     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
1863     ASSERT_NE(sceneSession, nullptr);
1864     ssm_->sceneSessionMap_.insert({0, sceneSession});
1865     ssm_->GetSceneSession(1);
1866     result = ssm_->DestroyDialogWithMainWindow(scnSession);
1867     ASSERT_EQ(result, WSError::WS_OK);
1868 
1869     WindowVisibilityInfo windowVisibilityInfo;
1870     windowVisibilityInfo.windowType_ = WindowType::APP_WINDOW_BASE;
1871     result = ssm_->DestroyDialogWithMainWindow(scnSession);
1872     ASSERT_EQ(result, WSError::WS_OK);
1873 }
1874 
1875 /**
1876  * @tc.name: RequestSceneSessionDestruction
1877  * @tc.desc: RequestSceneSessionDestruction
1878  * @tc.type: FUNC
1879  */
HWTEST_F(SceneSessionManagerTest6, RequestSceneSessionDestruction, Function | SmallTest | Level3)1880 HWTEST_F(SceneSessionManagerTest6, RequestSceneSessionDestruction, Function | SmallTest | Level3)
1881 {
1882     sptr<SceneSession> sceneSession;
1883     ASSERT_EQ(sceneSession, nullptr);
1884     bool needRemoveSession = true;
1885     bool isSaveSnapshot = true;
1886     bool isForceClean = true;
1887     ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionDestruction(
1888         sceneSession, needRemoveSession, isSaveSnapshot, isForceClean));
1889 
1890     SessionInfo info;
1891     sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1892     sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
1893     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1894     ASSERT_NE(property, nullptr);
1895     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1896     ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionDestruction(
1897         sceneSession, needRemoveSession, isSaveSnapshot, isForceClean));
1898 }
1899 
1900 /**
1901  * @tc.name: NotifySessionAINavigationBarChange
1902  * @tc.desc: NotifySessionAINavigationBarChange
1903  * @tc.type: FUNC
1904  */
HWTEST_F(SceneSessionManagerTest6, NotifySessionAINavigationBarChange, Function | SmallTest | Level3)1905 HWTEST_F(SceneSessionManagerTest6, NotifySessionAINavigationBarChange, Function | SmallTest | Level3)
1906 {
1907     ASSERT_NE(nullptr, ssm_);
1908     int32_t persistentId = 1;
1909     SessionInfo info;
1910     sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1911     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, specificCallback);
1912     ssm_->sceneSessionMap_.insert({0, sceneSession});
1913     ssm_->NotifySessionAINavigationBarChange(persistentId);
1914 
1915     persistentId = 0;
1916     Session session(info);
1917     session.isVisible_ = true;
1918     session.state_ = SessionState::STATE_FOREGROUND;
1919     ssm_->NotifySessionAINavigationBarChange(persistentId);
1920 }
1921 
1922 /**
1923  * @tc.name: GetProcessSurfaceNodeIdByPersistentId
1924  * @tc.desc: GetProcessSurfaceNodeIdByPersistentId
1925  * @tc.type: FUNC
1926  */
HWTEST_F(SceneSessionManagerTest6, GetProcessSurfaceNodeIdByPersistentId, Function | SmallTest | Level3)1927 HWTEST_F(SceneSessionManagerTest6, GetProcessSurfaceNodeIdByPersistentId, Function | SmallTest | Level3)
1928 {
1929     ASSERT_NE(nullptr, ssm_);
1930     SessionInfo info;
1931     sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1932     sptr<SceneSession> sceneSession1 = new (std::nothrow) SceneSession(info, specificCallback);
1933     sptr<SceneSession> sceneSession2 = new (std::nothrow) SceneSession(info, specificCallback);
1934     sptr<SceneSession> sceneSession3 = new (std::nothrow) SceneSession(info, specificCallback);
1935     sceneSession1->SetCallingPid(123);
1936     sceneSession2->SetCallingPid(123);
1937     sceneSession3->SetCallingPid(111);
1938 
1939     int32_t pid = 123;
1940     std::vector<int32_t> persistentIds;
1941     std::vector<uint64_t> surfaceNodeIds;
1942     persistentIds.push_back(sceneSession1->GetPersistentId());
1943     persistentIds.push_back(sceneSession2->GetPersistentId());
1944     persistentIds.push_back(sceneSession3->GetPersistentId());
1945     ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1946     ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
1947     ssm_->sceneSessionMap_.insert({sceneSession3->GetPersistentId(), sceneSession3});
1948 
1949     ASSERT_EQ(WMError::WM_OK, ssm_->GetProcessSurfaceNodeIdByPersistentId(pid, persistentIds, surfaceNodeIds));
1950     ASSERT_EQ(0, surfaceNodeIds.size());
1951 }
1952 }
1953 } // namespace Rosen
1954 } // namespace OHOS