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,
__anonc1427fda0202(bool enable, const std::string& bundleName, GestureBackType type) 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 */
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 */
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 */
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 */
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 */
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 */
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 currVisibleData.clear();
237 ssm_->lastVisibleData_.clear();
238 currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
239 ssm_->lastVisibleData_.push_back(
240 std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
241 visibilityChangeInfos = ssm_->GetWindowVisibilityChangeInfo(currVisibleData);
242 ASSERT_EQ(visibilityChangeInfos.size(), 1);
243 ASSERT_EQ(visibilityChangeInfos[0].first, 2);
244 }
245
246 /**
247 * @tc.name: GetWindowVisibilityChangeInfo04
248 * @tc.desc: GetWindowVisibilityChangeInfo04
249 * @tc.type: FUNC
250 */
251 HWTEST_F(SceneSessionManagerTest6, GetWindowVisibilityChangeInfo04, Function | SmallTest | Level3)
252 {
253 ASSERT_NE(nullptr, ssm_);
254 ssm_->lastVisibleData_.clear();
255 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
256 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
257 ssm_->lastVisibleData_.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
258 currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
259 currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
260 visibilityChangeInfos = ssm_->GetWindowVisibilityChangeInfo(currVisibleData);
261 ASSERT_EQ(visibilityChangeInfos.size(), 1);
262
263 currVisibleData.clear();
264 currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
265 visibilityChangeInfos = ssm_->GetWindowVisibilityChangeInfo(currVisibleData);
266 ASSERT_EQ(visibilityChangeInfos.size(), 0);
267 }
268
269 /**
270 * @tc.name: DealwithVisibilityChange01
271 * @tc.desc: DealwithVisibilityChange01
272 * @tc.type: FUNC
273 */
274 HWTEST_F(SceneSessionManagerTest6, DealwithVisibilityChange01, Function | SmallTest | Level3)
275 {
276 ASSERT_NE(nullptr, ssm_);
277 ssm_->sceneSessionMap_.clear();
278 SessionInfo sessionInfo;
279 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
280 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
281 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession1->GetPersistentId(), sceneSession1));
282 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession2->GetPersistentId(), sceneSession2));
283 struct RSSurfaceNodeConfig config;
284 std::shared_ptr<RSSurfaceNode> surfaceNode1 = RSSurfaceNode::Create(config);
285 std::shared_ptr<RSSurfaceNode> surfaceNode2 = RSSurfaceNode::Create(config);
286 ASSERT_NE(nullptr, surfaceNode1);
287 ASSERT_NE(nullptr, surfaceNode2);
288 surfaceNode1->SetId(1);
289 surfaceNode2->SetId(2);
290 ASSERT_NE(nullptr, sceneSession1);
291 ASSERT_NE(nullptr, sceneSession2);
292 sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
293 sceneSession1->surfaceNode_ = surfaceNode1;
294 sceneSession1->SetCallingPid(1);
295 sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
296 sceneSession2->SetParentSession(sceneSession1);
297 sceneSession2->surfaceNode_ = surfaceNode2;
298 sceneSession2->SetCallingPid(2);
299 ASSERT_NE(nullptr, sceneSession1->property_);
300 ASSERT_NE(nullptr, sceneSession2->property_);
301 sceneSession1->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
302 sceneSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
303 sceneSession1->property_->SetWindowName("visibility1");
304 sceneSession2->property_->SetWindowName("visibility2");
305 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
306 visibilityChangeInfos.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
307 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
308 currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
309 ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
310 ASSERT_EQ(sceneSession1->GetRSVisible(), true);
311 ASSERT_EQ(sceneSession2->GetRSVisible(), false);
312 sceneSession2->SetSessionState(SessionState::STATE_BACKGROUND);
313 sceneSession1->SetRSVisible(false);
314 sceneSession2->SetRSVisible(false);
315 ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
316 ASSERT_EQ(sceneSession1->GetRSVisible(), true);
317 ASSERT_EQ(sceneSession2->GetRSVisible(), false);
318 }
319
320 /**
321 * @tc.name: DealwithVisibilityChange02
322 * @tc.desc: DealwithVisibilityChange02
323 * @tc.type: FUNC
324 */
325 HWTEST_F(SceneSessionManagerTest6, DealwithVisibilityChange02, Function | SmallTest | Level3)
326 {
327 ASSERT_NE(nullptr, ssm_);
328 ssm_->sceneSessionMap_.clear();
329 SessionInfo sessionInfo;
330 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
331 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
332 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession1->GetPersistentId(), sceneSession1));
333 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession2->GetPersistentId(), sceneSession2));
334 struct RSSurfaceNodeConfig config;
335 std::shared_ptr<RSSurfaceNode> surfaceNode1 = RSSurfaceNode::Create(config);
336 std::shared_ptr<RSSurfaceNode> surfaceNode2 = RSSurfaceNode::Create(config);
337 ASSERT_NE(nullptr, surfaceNode1);
338 ASSERT_NE(nullptr, surfaceNode2);
339 surfaceNode1->SetId(1);
340 surfaceNode2->SetId(2);
341 ASSERT_NE(nullptr, sceneSession1);
342 ASSERT_NE(nullptr, sceneSession2);
343 sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
344 sceneSession1->surfaceNode_ = surfaceNode1;
345 sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
346 sceneSession2->SetParentSession(sceneSession1);
347 sceneSession2->surfaceNode_ = surfaceNode2;
348 ASSERT_NE(nullptr, sceneSession1->property_);
349 ASSERT_NE(nullptr, sceneSession2->property_);
350 sceneSession1->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
351 sceneSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
352 sceneSession1->property_->SetWindowName("visibility1");
353 sceneSession2->property_->SetWindowName("visibility2");
354 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfos;
355 visibilityChangeInfos.push_back(std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
356 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
357 currVisibleData.push_back(std::make_pair(3, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
358 sceneSession1->SetRSVisible(true);
359 ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
360 ASSERT_EQ(sceneSession2->GetRSVisible(), true);
361 sceneSession2->SetSessionState(SessionState::STATE_BACKGROUND);
362 sceneSession1->SetRSVisible(false);
363 sceneSession2->SetRSVisible(false);
364 sceneSession1->SetSessionState(SessionState::STATE_BACKGROUND);
365 ssm_->DealwithVisibilityChange(visibilityChangeInfos, currVisibleData);
366 ASSERT_EQ(sceneSession2->GetRSVisible(), false);
367 }
368
369 /**
370 * @tc.name: UpdateWindowMode
371 * @tc.desc: UpdateWindowMode
372 * @tc.type: FUNC
373 */
374 HWTEST_F(SceneSessionManagerTest6, UpdateWindowMode, Function | SmallTest | Level3)
375 {
376 SessionInfo sessionInfo;
377 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
378 sessionInfo.abilityName_ = "DumpSessionWithId";
379 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
380 ASSERT_NE(nullptr, ssm_);
381 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
382 ASSERT_NE(nullptr, ssm_);
383 auto ret = ssm_->UpdateWindowMode(0, 0);
384 EXPECT_EQ(WSError::WS_ERROR_INVALID_WINDOW, ret);
385 ASSERT_NE(nullptr, ssm_);
386 ret = ssm_->UpdateWindowMode(2, 0);
387 EXPECT_EQ(WSError::WS_OK, ret);
388 }
389
390 /**
391 * @tc.name: SetScreenLocked && IsScreenLocked
392 * @tc.desc: SceneSesionManager update screen locked state
393 * @tc.type: FUNC
394 */
395 HWTEST_F(SceneSessionManagerTest6, IsScreenLocked, Function | SmallTest | Level3)
396 {
397 ASSERT_NE(nullptr, ssm_);
398 ssm_->SetScreenLocked(true);
399 sleep(1);
400 ASSERT_NE(nullptr, ssm_);
401 EXPECT_TRUE(ssm_->IsScreenLocked());
402 ASSERT_NE(nullptr, ssm_);
403 ssm_->ProcessWindowModeType();
404 ASSERT_NE(nullptr, ssm_);
405 ssm_->SetScreenLocked(false);
406 sleep(1);
407 ASSERT_NE(nullptr, ssm_);
408 EXPECT_FALSE(ssm_->IsScreenLocked());
409 ASSERT_NE(nullptr, ssm_);
410 ssm_->ProcessWindowModeType();
411 }
412
413 /**
414 * @tc.name: CheckWindowModeType
415 * @tc.desc: CheckWindowModeType
416 * @tc.type: FUNC
417 */
418 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType, Function | SmallTest | Level3)
419 {
420 ASSERT_NE(nullptr, ssm_);
421 ssm_->sceneSessionMap_.clear();
422 auto ret = ssm_->CheckWindowModeType();
423 EXPECT_EQ(WindowModeType::WINDOW_MODE_OTHER, ret);
424 SessionInfo sessionInfo;
425 sessionInfo.bundleName_ = "privacy.test.first";
426 sessionInfo.abilityName_ = "privacyAbilityName";
427 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
428 ASSERT_NE(nullptr, sceneSession);
429 ASSERT_NE(nullptr, sceneSession->property_);
430 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
431 DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
432 sceneSession->property_->SetDisplayId(displayId);
433 ASSERT_NE(nullptr, ssm_);
434 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
435 ASSERT_NE(nullptr, ssm_);
436 ret = ssm_->CheckWindowModeType();
437 EXPECT_EQ(WindowModeType::WINDOW_MODE_OTHER, ret);
438 ASSERT_NE(nullptr, sceneSession->property_);
439 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
440 sceneSession->isVisible_ = false;
441 sceneSession->isRSVisible_ = false;
442 sceneSession->state_ = SessionState::STATE_DISCONNECT;
443 ASSERT_NE(nullptr, ssm_);
444 ret = ssm_->CheckWindowModeType();
445 EXPECT_EQ(WindowModeType::WINDOW_MODE_OTHER, ret);
446 }
447
448 /**
449 * @tc.name: CheckWindowModeType01
450 * @tc.desc: CheckWindowModeType
451 * @tc.type: FUNC
452 */
453 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType01, Function | SmallTest | Level3)
454 {
455 DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
456 SessionInfo sessionInfo;
457 sessionInfo.bundleName_ = "privacy.test.first";
458 sessionInfo.abilityName_ = "privacyAbilityName";
459 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
460 ASSERT_NE(nullptr, sceneSession);
461 ASSERT_NE(nullptr, sceneSession->property_);
462 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
463 ASSERT_NE(nullptr, sceneSession->property_);
464 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
465 sceneSession->property_->SetDisplayId(displayId);
466 sceneSession->isVisible_ = true;
467 sceneSession->isRSVisible_ = true;
468 sceneSession->state_ = SessionState::STATE_ACTIVE;
469 ASSERT_NE(nullptr, ssm_);
470 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
471 SessionInfo sessionInfo1;
472 sessionInfo1.bundleName_ = "privacy.test.first";
473 sessionInfo1.abilityName_ = "privacyAbilityName";
474 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
475 ASSERT_NE(nullptr, sceneSession1);
476 ASSERT_NE(nullptr, sceneSession1->property_);
477 sceneSession1->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
478 ASSERT_NE(nullptr, sceneSession1->property_);
479 sceneSession1->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
480 sceneSession1->property_->SetDisplayId(displayId);
481 sceneSession1->isVisible_ = true;
482 sceneSession1->isRSVisible_ = true;
483 sceneSession1->state_ = SessionState::STATE_ACTIVE;
484 ASSERT_NE(nullptr, ssm_);
485 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
486 ASSERT_NE(nullptr, ssm_);
487 auto ret = ssm_->CheckWindowModeType();
488 EXPECT_EQ(WindowModeType::WINDOW_MODE_SPLIT_FLOATING, ret);
489 ASSERT_NE(nullptr, sceneSession);
490 ASSERT_NE(nullptr, sceneSession->property_);
491 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
492 ASSERT_NE(nullptr, ssm_);
493 ret = ssm_->CheckWindowModeType();
494 EXPECT_EQ(WindowModeType::WINDOW_MODE_FULLSCREEN_FLOATING, ret);
495 }
496
497 /**
498 * @tc.name: CheckWindowModeType02
499 * @tc.desc: CheckWindowModeType
500 * @tc.type: FUNC
501 */
502 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType02, Function | SmallTest | Level3)
503 {
504 DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
505 SessionInfo sessionInfo;
506 sessionInfo.bundleName_ = "privacy.test.first";
507 sessionInfo.abilityName_ = "privacyAbilityName";
508 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
509 ASSERT_NE(nullptr, sceneSession);
510 ASSERT_NE(nullptr, sceneSession->property_);
511 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
512 ASSERT_NE(nullptr, sceneSession->property_);
513 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
514 sceneSession->property_->SetDisplayId(displayId);
515 sceneSession->isVisible_ = true;
516 sceneSession->isRSVisible_ = true;
517 sceneSession->state_ = SessionState::STATE_ACTIVE;
518 ASSERT_NE(nullptr, ssm_);
519 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
520 ASSERT_NE(nullptr, ssm_);
521 ssm_->lastWindowModeType_ = WindowModeType::WINDOW_MODE_FULLSCREEN;
522 auto ret = ssm_->CheckWindowModeType();
523 EXPECT_EQ(WindowModeType::WINDOW_MODE_FLOATING, ret);
524 ASSERT_NE(nullptr, ssm_);
525 ssm_->NotifyRSSWindowModeTypeUpdate();
526 ASSERT_NE(nullptr, sceneSession->property_);
527 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
528 ASSERT_NE(nullptr, ssm_);
529 ret = ssm_->CheckWindowModeType();
530 EXPECT_EQ(WindowModeType::WINDOW_MODE_FULLSCREEN, ret);
531 ASSERT_NE(nullptr, ssm_);
532 ssm_->NotifyRSSWindowModeTypeUpdate();
533 }
534
535 /**
536 * @tc.name: CheckWindowModeType03
537 * @tc.desc: CheckWindowModeType
538 * @tc.type: FUNC
539 */
540 HWTEST_F(SceneSessionManagerTest6, CheckWindowModeType03, Function | SmallTest | Level3)
541 {
542 DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
543 SessionInfo sessionInfo;
544 sessionInfo.bundleName_ = "privacy.test.first";
545 sessionInfo.abilityName_ = "privacyAbilityName";
546 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
547 ASSERT_NE(nullptr, sceneSession);
548 ASSERT_NE(nullptr, sceneSession->property_);
549 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
550 sceneSession->property_->SetDisplayId(displayId);
551 sceneSession->isVisible_ = true;
552 sceneSession->isRSVisible_ = true;
553 sceneSession->state_ = SessionState::STATE_ACTIVE;
554 ASSERT_NE(nullptr, ssm_);
555 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
556 ASSERT_NE(nullptr, sceneSession);
557 ASSERT_NE(nullptr, sceneSession->property_);
558 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
559 sceneSession->isVisible_ = true;
560 sceneSession->isRSVisible_ = true;
561 sceneSession->state_ = SessionState::STATE_ACTIVE;
562 ASSERT_NE(nullptr, ssm_);
563 auto ret = ssm_->CheckWindowModeType();
564 EXPECT_EQ(WindowModeType::WINDOW_MODE_SPLIT, ret);
565 ASSERT_NE(nullptr, sceneSession);
566 ASSERT_NE(nullptr, sceneSession->property_);
567 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
568 ASSERT_NE(nullptr, ssm_);
569 ret = ssm_->CheckWindowModeType();
570 EXPECT_EQ(WindowModeType::WINDOW_MODE_SPLIT, ret);
571 }
572
573 /**
574 * @tc.name: GetSceneSessionPrivacyModeBundles
575 * @tc.desc: GetSceneSessionPrivacyModeBundles
576 * @tc.type: FUNC
577 */
578 HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles, Function | SmallTest | Level3)
579 {
580 ASSERT_NE(nullptr, ssm_);
581 ssm_->sceneSessionMap_.clear();
582 DisplayId displayId = 0;
583 std::unordered_set<std::string> privacyBundles;
584 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
585 SessionInfo sessionInfoFirst;
586 sessionInfoFirst.bundleName_ = "";
587 sessionInfoFirst.abilityName_ = "privacyAbilityName";
588 sptr<SceneSession> sceneSessionFirst = sptr<SceneSession>::MakeSptr(sessionInfoFirst, nullptr);
589 ASSERT_NE(sceneSessionFirst, nullptr);
590 sceneSessionFirst->property_ = nullptr;
591 ASSERT_NE(nullptr, ssm_);
592 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
593 sceneSessionFirst->property_ = sptr<WindowSessionProperty>::MakeSptr();
594 ASSERT_NE(nullptr, sceneSessionFirst->property_);
595 sceneSessionFirst->property_->SetDisplayId(0);
596 ASSERT_NE(nullptr, ssm_);
597 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
598 sessionInfoFirst.bundleName_ = "privacy.test.first";
599 sceneSessionFirst->state_ = SessionState::STATE_FOREGROUND;
600 ASSERT_NE(nullptr, ssm_);
601 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
602 sceneSessionFirst->state_ = SessionState::STATE_CONNECT;
603 ASSERT_NE(nullptr, ssm_);
604 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
605 }
606
607 /**
608 * @tc.name: GetSceneSessionPrivacyModeBundles01
609 * @tc.desc: GetSceneSessionPrivacyModeBundles
610 * @tc.type: FUNC
611 */
612 HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles01, Function | SmallTest | Level3)
613 {
614 DisplayId displayId = 0;
615 std::unordered_set<std::string> privacyBundles;
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 ASSERT_NE(nullptr, ssm_);
627 SessionInfo sessionInfoSecond;
628 sessionInfoSecond.bundleName_ = "privacy.test.second";
629 sessionInfoSecond.abilityName_ = "privacyAbilityName";
630 sptr<SceneSession> sceneSessionSecond = sptr<SceneSession>::MakeSptr(sessionInfoSecond, nullptr);
631 ASSERT_NE(nullptr, sceneSessionSecond);
632 ssm_->sceneSessionMap_.insert({sceneSessionSecond->GetPersistentId(), sceneSessionSecond});
633 ASSERT_NE(nullptr, sceneSessionSecond->property_);
634 sceneSessionSecond->property_->displayId_ = 1;
635 sceneSessionSecond->state_ = SessionState::STATE_ACTIVE;
636 sceneSessionSecond->parentSession_ = sceneSessionFirst;
637 ASSERT_NE(nullptr, ssm_);
638 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
639 sceneSessionSecond->state_ = SessionState::STATE_FOREGROUND;
640 sceneSessionSecond->state_ = SessionState::STATE_CONNECT;
641 ASSERT_NE(nullptr, ssm_);
642 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
643 }
644
645 /**
646 * @tc.name: GetSceneSessionPrivacyModeBundles02
647 * @tc.desc: GetSceneSessionPrivacyModeBundles
648 * @tc.type: FUNC
649 */
650 HWTEST_F(SceneSessionManagerTest6, GetSceneSessionPrivacyModeBundles02, Function | SmallTest | Level3)
651 {
652 DisplayId displayId = 0;
653 std::unordered_set<std::string> privacyBundles;
654 ASSERT_NE(nullptr, ssm_);
655 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
656 SessionInfo sessionInfoFirst;
657 sessionInfoFirst.bundleName_ = "privacy.test.first";
658 sessionInfoFirst.abilityName_ = "privacyAbilityName";
659 sptr<SceneSession> sceneSessionFirst = sptr<SceneSession>::MakeSptr(sessionInfoFirst, nullptr);
660 ASSERT_NE(sceneSessionFirst, nullptr);
661 sceneSessionFirst->property_ = sptr<WindowSessionProperty>::MakeSptr();
662 ASSERT_NE(nullptr, sceneSessionFirst->property_);
663 sceneSessionFirst->property_->SetDisplayId(0);
664 sceneSessionFirst->state_ = SessionState::STATE_ACTIVE;
665 sceneSessionFirst->property_->isPrivacyMode_ = false;
666 ASSERT_NE(nullptr, ssm_);
667 ssm_->GetSceneSessionPrivacyModeBundles(displayId, privacyBundles);
668 }
669
670 /**
671 * @tc.name: RegisterWindowManagerAgent
672 * @tc.desc: RegisterWindowManagerAgent
673 * @tc.type: FUNC
674 */
675 HWTEST_F(SceneSessionManagerTest6, RegisterWindowManagerAgent, Function | SmallTest | Level3)
676 {
677 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR;
678 sptr<IWindowManagerAgent> windowManagerAgent = nullptr;
679 ASSERT_NE(nullptr, ssm_);
680 auto ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
681 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
682 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED;
683 ASSERT_NE(nullptr, ssm_);
684 ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
685 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
686 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG;
687 ASSERT_NE(nullptr, ssm_);
688 ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
689 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
690 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY;
691 ASSERT_NE(nullptr, ssm_);
692 ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
693 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
694 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE;
695 ASSERT_NE(nullptr, ssm_);
696 ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
697 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
698 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM;
699 ASSERT_NE(nullptr, ssm_);
700 ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
701 EXPECT_EQ(WMError::WM_ERROR_INVALID_PERMISSION, ret);
702 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT;
703 ASSERT_NE(nullptr, ssm_);
704 ret = ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
705 EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret);
706 }
707
708 /**
709 * @tc.name: OnSessionStateChange
710 * @tc.desc: OnSessionStateChange
711 * @tc.type: FUNC
712 */
713 HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange, Function | SmallTest | Level3)
714 {
715 SessionState state = SessionState::STATE_FOREGROUND;
716 ASSERT_NE(nullptr, ssm_);
717 ssm_->sceneSessionMap_.clear();
718 ssm_->OnSessionStateChange(1, state);
719 SessionInfo sessionInfo;
720 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
721 sessionInfo.abilityName_ = "DumpSessionWithId";
722 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
723 ASSERT_NE(nullptr, ssm_);
724 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
725 ASSERT_NE(nullptr, sceneSession);
726 ASSERT_NE(nullptr, sceneSession->property_);
727 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
728 ASSERT_NE(nullptr, ssm_);
729 ssm_->OnSessionStateChange(1, state);
730 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
731 focusGroup->SetFocusedSessionId(1);
732 ssm_->OnSessionStateChange(1, state);
733 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
734 ASSERT_NE(nullptr, ssm_);
735 ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
736 ssm_->OnSessionStateChange(1, state);
737 ASSERT_NE(nullptr, ssm_);
738 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
739 ssm_->OnSessionStateChange(1, state);
740 focusGroup->SetFocusedSessionId(0);
741 ASSERT_NE(nullptr, ssm_);
742 ssm_->OnSessionStateChange(1, state);
743 }
744
745 /**
746 * @tc.name: OnSessionStateChange01
747 * @tc.desc: OnSessionStateChange01
748 * @tc.type: FUNC
749 */
750 HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange01, Function | SmallTest | Level3)
751 {
752 SessionState state = SessionState::STATE_BACKGROUND;
753 ASSERT_NE(nullptr, ssm_);
754 ssm_->sceneSessionMap_.clear();
755 SessionInfo sessionInfo;
756 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
757 sessionInfo.abilityName_ = "DumpSessionWithId";
758 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
759 ASSERT_NE(nullptr, ssm_);
760 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
761 ASSERT_NE(nullptr, sceneSession);
762 ASSERT_NE(nullptr, sceneSession->property_);
763 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
764 ASSERT_NE(nullptr, ssm_);
765 ssm_->OnSessionStateChange(1, state);
766 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
767 ASSERT_NE(nullptr, ssm_);
768 ssm_->OnSessionStateChange(1, state);
769 state = SessionState::STATE_END;
770 ASSERT_NE(nullptr, ssm_);
771 ssm_->OnSessionStateChange(1, state);
772 }
773
774 /**
775 * @tc.name: OnSessionStateChange02
776 * @tc.desc: OnSessionStateChange02
777 * @tc.type: FUNC
778 */
779 HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange02, Function | SmallTest | Level3)
780 {
781 SessionState state = SessionState::STATE_FOREGROUND;
782 ASSERT_NE(nullptr, ssm_);
783 ssm_->sceneSessionMap_.clear();
784 SessionInfo sessionInfo;
785 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
786 sessionInfo.abilityName_ = "DumpSessionWithId";
787 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
788 ASSERT_NE(nullptr, ssm_);
789 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
790 ASSERT_NE(nullptr, sceneSession);
791 ASSERT_NE(nullptr, sceneSession->property_);
792 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
793 sceneSession->SetFocusedOnShow(true);
794 ASSERT_NE(nullptr, ssm_);
795 ssm_->OnSessionStateChange(1, state);
796 sceneSession->SetFocusedOnShow(false);
797 ASSERT_NE(nullptr, ssm_);
798 ssm_->OnSessionStateChange(1, state);
799 }
800
801 /**
802 * @tc.name: ProcessModalTopmostRequestFocusImmdediately
803 * @tc.desc: ProcessModalTopmostRequestFocusImmdediately
804 * @tc.type: FUNC
805 */
806 HWTEST_F(SceneSessionManagerTest6, ProcessModalTopmostRequestFocusImmdediately, Function | SmallTest | Level3)
807 {
808 SessionInfo sessionInfo;
809 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
810 sessionInfo.abilityName_ = "DumpSessionWithId";
811 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
812 ASSERT_NE(nullptr, sceneSession->property_);
813 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
814 ASSERT_NE(nullptr, ssm_);
815 auto ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
816 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
817 ASSERT_NE(nullptr, sceneSession->property_);
818 sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
819 ASSERT_NE(nullptr, ssm_);
820 ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
821 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
822 ASSERT_NE(nullptr, sceneSession->property_);
823 sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_END);
824 ASSERT_NE(nullptr, ssm_);
825 ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
826 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
827 }
828
829 /**
830 * @tc.name: GetAbilityInfosFromBundleInfo
831 * @tc.desc: GetAbilityInfosFromBundleInfo
832 * @tc.type: FUNC
833 */
834 HWTEST_F(SceneSessionManagerTest6, GetAbilityInfosFromBundleInfo, Function | SmallTest | Level3)
835 {
836 std::vector<AppExecFwk::BundleInfo> bundleInfos;
837 std::vector<SCBAbilityInfo> scbAbilityInfos;
838 ASSERT_NE(nullptr, ssm_);
839 auto ret = ssm_->GetAbilityInfosFromBundleInfo(bundleInfos, scbAbilityInfos);
840 EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, ret);
841 OHOS::AppExecFwk::BundleInfo bundleInfo;
842 bundleInfo.name = "com.ix.residentservcie";
843 bundleInfo.isKeepAlive = true;
844 bundleInfo.applicationInfo.process = "com.ix.residentservcie";
845 OHOS::AppExecFwk::HapModuleInfo hapModuleInfo;
846 hapModuleInfo.isModuleJson = true;
847 hapModuleInfo.mainElementName = "residentServiceAbility";
848 hapModuleInfo.process = "com.ix.residentservcie";
849 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo);
850 bundleInfos.emplace_back(bundleInfo);
851 ASSERT_NE(nullptr, ssm_);
852 ret = ssm_->GetAbilityInfosFromBundleInfo(bundleInfos, scbAbilityInfos);
853 EXPECT_EQ(WSError::WS_OK, ret);
854 }
855
856 /**
857 * @tc.name: GetOrientationFromResourceManager
858 * @tc.desc: GetOrientationFromResourceManager
859 * @tc.type: FUNC
860 */
861 HWTEST_F(SceneSessionManagerTest6, GetOrientationFromResourceManager, Function | SmallTest | Level3)
862 {
863 ASSERT_NE(nullptr, ssm_);
864 OHOS::AppExecFwk::AbilityInfo abilityInfo;
865 abilityInfo.bundleName = "testBundleName";
866 abilityInfo.moduleName = "testModuleName";
867 abilityInfo.orientationId = 123456;
868 ssm_->GetOrientationFromResourceManager(abilityInfo);
869 EXPECT_EQ(OHOS::AppExecFwk::DisplayOrientation::UNSPECIFIED, abilityInfo.orientation);
870 }
871
872 /**
873 * @tc.name: NotifyCompleteFirstFrameDrawing
874 * @tc.desc: NotifyCompleteFirstFrameDrawing
875 * @tc.type: FUNC
876 */
877 HWTEST_F(SceneSessionManagerTest6, NotifyCompleteFirstFrameDrawing, Function | SmallTest | Level3)
878 {
879 ASSERT_NE(nullptr, ssm_);
880 ssm_->sceneSessionMap_.clear();
881 SessionInfo sessionInfo;
882 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
883 sessionInfo.abilityName_ = "DumpSessionWithId";
884 sessionInfo.abilityInfo = nullptr;
885 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
886 ASSERT_NE(nullptr, ssm_);
887 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
888 ASSERT_NE(nullptr, ssm_);
889 ssm_->NotifyCompleteFirstFrameDrawing(1);
890 sessionInfo.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
891 ASSERT_NE(nullptr, sessionInfo.abilityInfo);
892 ASSERT_NE(nullptr, ssm_);
893 ssm_->eventHandler_ = nullptr;
894 ssm_->NotifyCompleteFirstFrameDrawing(1);
895 ssm_->eventHandler_ = std::make_shared<AppExecFwk::EventHandler>();
896 ASSERT_NE(nullptr, ssm_->eventHandler_);
897 ASSERT_NE(nullptr, ssm_);
898 ssm_->NotifyCompleteFirstFrameDrawing(1);
899 ASSERT_NE(nullptr, ssm_);
900 ssm_->taskScheduler_ = nullptr;
901 ssm_->NotifyCompleteFirstFrameDrawing(1);
902 ssm_->taskScheduler_ = std::make_shared<TaskScheduler>("OS_SceneSessionManager");
903 ASSERT_NE(nullptr, ssm_->taskScheduler_);
904 ASSERT_NE(nullptr, ssm_);
905 ssm_->NotifyCompleteFirstFrameDrawing(1);
906 }
907
908 /**
909 * @tc.name: NotifyCompleteFirstFrameDrawing02
910 * @tc.desc: NotifyCompleteFirstFrameDrawing02:AtomicService free-install start.
911 * @tc.type: FUNC
912 */
913 HWTEST_F(SceneSessionManagerTest6, NotifyCompleteFirstFrameDrawing02, Function | SmallTest | Level3)
914 {
915 ASSERT_NE(nullptr, ssm_);
916 ssm_->sceneSessionMap_.clear();
917 SessionInfo sessionInfo;
918 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
919 sessionInfo.abilityName_ = "DumpSessionWithId";
920 sessionInfo.abilityInfo = nullptr;
921 sessionInfo.isAtomicService_ = true;
922 sessionInfo.isBackTransition_ = false;
923 unsigned int flags = 11111111;
924 sessionInfo.want = std::make_shared<AAFwk::Want>();
925 ASSERT_NE(nullptr, sessionInfo.want);
926 sessionInfo.want->SetFlags(flags);
927 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
928 ASSERT_NE(nullptr, sceneSession);
929 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
930 ssm_->NotifyCompleteFirstFrameDrawing(1);
931 ASSERT_EQ(nullptr, sessionInfo.abilityInfo);
932 }
933
934 /**
935 * @tc.name: InitSceneSession01
936 * @tc.desc: InitSceneSession01:AtomicService free-install start.
937 * @tc.type: FUNC
938 */
939 HWTEST_F(SceneSessionManagerTest6, InitSceneSession01, Function | SmallTest | Level3)
940 {
941 ASSERT_NE(nullptr, ssm_);
942 ssm_->sceneSessionMap_.clear();
943 SessionInfo sessionInfo;
944 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
945 sessionInfo.abilityName_ = "DumpSessionWithId";
946 sessionInfo.abilityInfo = nullptr;
947 sessionInfo.isAtomicService_ = true;
948 sessionInfo.isBackTransition_ = false;
949 sessionInfo.screenId_ = 100;
950 unsigned int flags = 11111111;
951 sessionInfo.want = std::make_shared<AAFwk::Want>();
952 ASSERT_NE(nullptr, sessionInfo.want);
953 sessionInfo.want->SetFlags(flags);
954 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
955 ASSERT_NE(nullptr, sceneSession);
956 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
957
958 ssm_->InitSceneSession(sceneSession, sessionInfo, nullptr);
959 ASSERT_EQ(100, sceneSession->GetSessionInfo().screenId_);
960 }
961
962 /**
963 * @tc.name: CheckAndNotifyWaterMarkChangedResult
964 * @tc.desc: CheckAndNotifyWaterMarkChangedResult
965 * @tc.type: FUNC
966 */
967 HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult, Function | SmallTest | Level3)
968 {
969 ASSERT_NE(nullptr, ssm_);
970 ssm_->sceneSessionMap_.clear();
971 ssm_->CheckAndNotifyWaterMarkChangedResult();
972 SessionInfo sessionInfo;
973 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
974 sessionInfo.abilityName_ = "DumpSessionWithId";
975 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
976 ASSERT_NE(nullptr, sceneSession);
977 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
978 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
979 ASSERT_NE(nullptr, sceneSession->property_);
980 sceneSession->property_->flags_ = 1 << 4;
981 sceneSession->isRSVisible_ = true;
982 sceneSession->combinedExtWindowFlags_.waterMarkFlag = true;
983 ssm_->CheckAndNotifyWaterMarkChangedResult();
984 sceneSession->isRSVisible_ = false;
985 ssm_->CheckAndNotifyWaterMarkChangedResult();
986 sceneSession->property_->flags_ = 0;
987 sceneSession->isRSVisible_ = false;
988 ssm_->CheckAndNotifyWaterMarkChangedResult();
989 sceneSession->isRSVisible_ = true;
990 ssm_->CheckAndNotifyWaterMarkChangedResult();
991 }
992
993 /**
994 * @tc.name: CheckAndNotifyWaterMarkChangedResult01
995 * @tc.desc: CheckAndNotifyWaterMarkChangedResult01
996 * @tc.type: FUNC
997 */
998 HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult01, Function | SmallTest | Level3)
999 {
1000 ASSERT_NE(nullptr, ssm_);
1001 ssm_->sceneSessionMap_.clear();
1002 SessionInfo sessionInfo;
1003 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1004 sessionInfo.abilityName_ = "DumpSessionWithId";
1005 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1006 ASSERT_NE(nullptr, sceneSession);
1007 ASSERT_NE(nullptr, ssm_);
1008 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1009 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1010 ASSERT_NE(nullptr, sceneSession->property_);
1011 sceneSession->property_->flags_ = 1 << 4;
1012 sceneSession->isRSVisible_ = true;
1013 sceneSession->combinedExtWindowFlags_.waterMarkFlag = false;
1014 ASSERT_NE(nullptr, ssm_);
1015 ssm_->CheckAndNotifyWaterMarkChangedResult();
1016 sceneSession->isRSVisible_ = false;
1017 ASSERT_NE(nullptr, ssm_);
1018 ssm_->CheckAndNotifyWaterMarkChangedResult();
1019 sceneSession->property_->flags_ = 0;
1020 sceneSession->isRSVisible_ = false;
1021 ASSERT_NE(nullptr, ssm_);
1022 ssm_->CheckAndNotifyWaterMarkChangedResult();
1023 sceneSession->isRSVisible_ = true;
1024 ASSERT_NE(nullptr, ssm_);
1025 ssm_->CheckAndNotifyWaterMarkChangedResult();
1026 }
1027
1028 /**
1029 * @tc.name: CheckAndNotifyWaterMarkChangedResult02
1030 * @tc.desc: CheckAndNotifyWaterMarkChangedResult02
1031 * @tc.type: FUNC
1032 */
1033 HWTEST_F(SceneSessionManagerTest6, CheckAndNotifyWaterMarkChangedResult02, Function | SmallTest | Level3)
1034 {
1035 ASSERT_NE(nullptr, ssm_);
1036 ssm_->sceneSessionMap_.clear();
1037 ssm_->lastWaterMarkShowState_ = true;
1038 ssm_->CheckAndNotifyWaterMarkChangedResult();
1039 ASSERT_NE(nullptr, ssm_);
1040 ssm_->lastWaterMarkShowState_ = false;
1041 ssm_->CheckAndNotifyWaterMarkChangedResult();
1042 }
1043
1044 /**
1045 * @tc.name: FillWindowInfo01
1046 * @tc.desc: FillWindowInfo01
1047 * @tc.type: FUNC
1048 */
1049 HWTEST_F(SceneSessionManagerTest6, FillWindowInfo01, Function | SmallTest | Level3)
1050 {
1051 ASSERT_NE(nullptr, ssm_);
1052 std::vector<sptr<AccessibilityWindowInfo>> infos;
1053 sptr<SceneSession> sceneSession = nullptr;
1054 auto ret = ssm_->FillWindowInfo(infos, sceneSession);
1055 EXPECT_EQ(false, ret);
1056 SessionInfo sessionInfo;
1057 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1058 sessionInfo.abilityName_ = "FillWindowInfo01";
1059 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1060 ASSERT_NE(nullptr, sceneSession);
1061 ret = ssm_->FillWindowInfo(infos, sceneSession);
1062 EXPECT_EQ(true, ret);
1063 EXPECT_EQ(1, infos.size());
1064 }
1065
1066 /**
1067 * @tc.name: FillWindowInfo02
1068 * @tc.desc: FillWindowInfo02
1069 * @tc.type: FUNC
1070 */
1071 HWTEST_F(SceneSessionManagerTest6, FillWindowInfo02, Function | SmallTest | Level3)
1072 {
1073 ASSERT_NE(nullptr, ssm_);
1074 std::vector<sptr<AccessibilityWindowInfo>> infos;
1075 SessionInfo sessionInfo;
1076 sessionInfo.bundleName_ = "SCBGestureBack";
1077 sessionInfo.abilityName_ = "FillWindowInfo02";
1078 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1079 ASSERT_NE(nullptr, sceneSession);
1080 auto ret = ssm_->FillWindowInfo(infos, sceneSession);
1081 EXPECT_EQ(false, ret);
1082 EXPECT_EQ(0, infos.size());
1083 }
1084
1085 /**
1086 * @tc.name: FillWindowInfo03
1087 * @tc.desc: FillWindowInfo03
1088 * @tc.type: FUNC
1089 */
1090 HWTEST_F(SceneSessionManagerTest6, FillWindowInfo03, Function | SmallTest | Level3)
1091 {
1092 ASSERT_NE(nullptr, ssm_);
1093 std::vector<sptr<AccessibilityWindowInfo>> infos;
1094 SessionInfo sessionInfo;
1095 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1096 sessionInfo.abilityName_ = "FillWindowInfo03";
1097 sessionInfo.isSystem_ = true;
1098 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1099 ASSERT_NE(nullptr, sceneSession);
1100 auto ret = ssm_->FillWindowInfo(infos, sceneSession);
1101 EXPECT_EQ(true, ret);
1102 EXPECT_EQ(1, infos.size());
1103 EXPECT_EQ(1, infos[0]->wid_);
1104 }
1105
1106 /**
1107 * @tc.name: FillWindowInfo04
1108 * @tc.desc: FillWindowInfo04
1109 * @tc.type: FUNC
1110 */
1111 HWTEST_F(SceneSessionManagerTest6, FillWindowInfo04, Function | SmallTest | Level3)
1112 {
1113 ASSERT_NE(nullptr, ssm_);
1114 std::vector<sptr<AccessibilityWindowInfo>> infos;
1115 SessionInfo sessionInfo;
1116 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1117 sessionInfo.abilityName_ = "FillWindowInfo04";
1118 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1119 ASSERT_NE(nullptr, sceneSession);
1120 sceneSession->property_->SetDisplayId(1);
1121 auto ret = ssm_->FillWindowInfo(infos, sceneSession);
1122 EXPECT_EQ(true, ret);
1123 EXPECT_EQ(1, infos.size());
1124 EXPECT_EQ(1, infos[0]->displayId_);
1125 }
1126
1127 /**
1128 * @tc.name: SetSessionVisibilityInfo
1129 * @tc.desc: SetSessionVisibilityInfo
1130 * @tc.type: FUNC
1131 */
1132 HWTEST_F(SceneSessionManagerTest6, SetSessionVisibilityInfo, Function | SmallTest | Level3)
1133 {
1134 sptr<SceneSession> session = nullptr;
1135 WindowVisibilityState visibleState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION;
1136 std::vector<sptr<WindowVisibilityInfo>> windowVisibilityInfos;
1137 std::string visibilityInfo = "";
1138 ASSERT_NE(nullptr, ssm_);
1139 ssm_->SetSessionVisibilityInfo(session, visibleState, windowVisibilityInfos, visibilityInfo);
1140 SessionInfo sessionInfo;
1141 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1142 sessionInfo.abilityName_ = "DumpSessionWithId";
1143 session = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1144 ASSERT_NE(nullptr, ssm_);
1145 ASSERT_NE(nullptr, session);
1146 session->persistentId_ = 1;
1147 ssm_->windowVisibilityListenerSessionSet_.clear();
1148 ssm_->SetSessionVisibilityInfo(session, visibleState, windowVisibilityInfos, visibilityInfo);
1149 ssm_->windowVisibilityListenerSessionSet_.insert(1);
1150 ssm_->SetSessionVisibilityInfo(session, visibleState, windowVisibilityInfos, visibilityInfo);
1151 }
1152
1153 /**
1154 * @tc.name: SendTouchEvent
1155 * @tc.desc: SendTouchEvent
1156 * @tc.type: FUNC
1157 */
1158 HWTEST_F(SceneSessionManagerTest6, SendTouchEvent, Function | SmallTest | Level3)
1159 {
1160 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
1161 ASSERT_NE(nullptr, ssm_);
1162 auto ret = ssm_->SendTouchEvent(pointerEvent, 0);
1163 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret);
1164 MMI::PointerEvent::PointerItem pointerItem;
1165 pointerItem.pointerId_ = 0;
1166 pointerEvent = MMI::PointerEvent::Create();
1167 ASSERT_NE(nullptr, pointerEvent);
1168 pointerEvent->pointerId_ = 0;
1169 pointerEvent->AddPointerItem(pointerItem);
1170 ASSERT_NE(nullptr, ssm_);
1171 ret = ssm_->SendTouchEvent(pointerEvent, 0);
1172 EXPECT_EQ(WSError::WS_OK, ret);
1173 pointerEvent->pointerId_ = 1;
1174 ASSERT_NE(nullptr, ssm_);
1175 ret = ssm_->SendTouchEvent(pointerEvent, 0);
1176 EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, ret);
1177 ASSERT_NE(nullptr, ssm_);
1178 ssm_->RegisterWindowChanged(WindowChangedFuncTest);
1179 }
1180
1181 /**
1182 * @tc.name: JudgeNeedNotifyPrivacyInfo
1183 * @tc.desc: JudgeNeedNotifyPrivacyInfo
1184 * @tc.type: FUNC
1185 */
1186 HWTEST_F(SceneSessionManagerTest6, JudgeNeedNotifyPrivacyInfo, Function | SmallTest | Level3)
1187 {
1188 DisplayId displayId = 1;
1189 std::unordered_set<std::string> privacyBundles;
1190 ssm_->privacyBundleMap_.clear();
1191 ASSERT_NE(nullptr, ssm_);
1192 auto ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1193 EXPECT_EQ(true, ret);
1194 privacyBundles.insert("bundle1");
1195 ASSERT_NE(nullptr, ssm_);
1196 ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1197 EXPECT_EQ(true, ret);
1198 std::unordered_set<std::string> privacyBundles1;
1199 privacyBundles1.insert("bundle2");
1200 ASSERT_NE(nullptr, ssm_);
1201 ssm_->privacyBundleMap_.insert({displayId, privacyBundles1});
1202 ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1203 EXPECT_EQ(true, ret);
1204 privacyBundles.insert("bundle2");
1205 ASSERT_NE(nullptr, ssm_);
1206 ret = ssm_->JudgeNeedNotifyPrivacyInfo(displayId, privacyBundles);
1207 EXPECT_EQ(true, ret);
1208 ASSERT_NE(nullptr, ssm_);
1209 ssm_->InitPersistentStorage();
1210 ASSERT_NE(nullptr, ssm_);
1211 ssm_->UpdateCameraFloatWindowStatus(0, true);
1212 ASSERT_NE(nullptr, ssm_);
1213 ssm_->UpdateCameraWindowStatus(0, true);
1214 }
1215
1216 /**
1217 * @tc.name: UpdatePrivateStateAndNotify
1218 * @tc.desc: UpdatePrivateStateAndNotify
1219 * @tc.type: FUNC
1220 */
1221 HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify, Function | SmallTest | Level3)
1222 {
1223 ASSERT_NE(nullptr, ssm_);
1224 ssm_->sceneSessionMap_.clear();
1225 ssm_->privacyBundleMap_.clear();
1226 SessionInfo sessionInfo;
1227 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1228 sessionInfo.abilityName_ = "DumpSessionWithId";
1229 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1230 ASSERT_NE(nullptr, sceneSession);
1231 ASSERT_NE(nullptr, ssm_);
1232 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1233 ssm_->UpdatePrivateStateAndNotify(1);
1234 ASSERT_EQ(ssm_->privacyBundleMap_[1].size(), 0);
1235 ssm_->UpdatePrivateStateAndNotifyForAllScreens();
1236 }
1237
1238 /**
1239 * @tc.name: UpdatePrivateStateAndNotify2
1240 * @tc.desc: UpdatePrivateStateAndNotify2
1241 * @tc.type: FUNC
1242 */
1243 HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify2, Function | SmallTest | Level3)
1244 {
1245 ASSERT_NE(nullptr, ssm_);
1246 ssm_->sceneSessionMap_.clear();
1247 ssm_->privacyBundleMap_.clear();
1248 SessionInfo sessionInfo;
1249 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1250 sessionInfo.abilityName_ = "DumpSessionWithId";
1251 sessionInfo.isSystem_ = true;
1252 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1253 ASSERT_NE(nullptr, sceneSession);
1254 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1255 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1256 ASSERT_NE(nullptr, sceneSession->property_);
1257 sceneSession->property_->SetPrivacyMode(true);
1258 sceneSession->property_->SetDisplayId(1);
1259 sceneSession->isVisible_ = false;
1260 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1261 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
1262 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession));
1263 ssm_->UpdatePrivateStateAndNotify(1);
1264 ASSERT_EQ(ssm_->privacyBundleMap_[1].size(), 1);
1265 sceneSession->SetSessionState(SessionState::STATE_BACKGROUND);
1266 sceneSession->property_->SetPrivacyMode(true);
1267 sceneSession->property_->SetDisplayId(2);
1268 sceneSession->isVisible_ = true;
1269 ssm_->UpdatePrivateStateAndNotify(2);
1270 ASSERT_EQ(ssm_->privacyBundleMap_[2].size(), 1);
1271 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1272 sceneSession->property_->SetPrivacyMode(false);
1273 sceneSession->property_->SetDisplayId(3);
1274 ssm_->UpdatePrivateStateAndNotify(3);
1275 ASSERT_EQ(ssm_->privacyBundleMap_[3].size(), 0);
1276 }
1277
1278 /**
1279 * @tc.name: UpdatePrivateStateAndNotify3
1280 * @tc.desc: UpdatePrivateStateAndNotify3
1281 * @tc.type: FUNC
1282 */
1283 HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify3, Function | SmallTest | Level3)
1284 {
1285 ASSERT_NE(nullptr, ssm_);
1286 ssm_->sceneSessionMap_.clear();
1287 ssm_->privacyBundleMap_.clear();
1288 SessionInfo sessionInfo;
1289 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1290 sessionInfo.abilityName_ = "DumpSessionWithId";
1291 sessionInfo.isSystem_ = true;
1292 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1293 ASSERT_NE(nullptr, sceneSession);
1294 sceneSession->isVisible_ = true;
1295 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1296 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1297 ASSERT_NE(nullptr, sceneSession->property_);
1298 sceneSession->property_->SetPrivacyMode(true);
1299 sceneSession->property_->SetDisplayId(1);
1300 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1301 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
1302 ssm_->UpdatePrivateStateAndNotify(1);
1303 ASSERT_EQ(ssm_->privacyBundleMap_[1].size(), 1);
1304 sceneSession->property_->SetPrivacyMode(false);
1305 sceneSession->combinedExtWindowFlags_.privacyModeFlag = true;
1306 sceneSession->property_->SetDisplayId(2);
1307 ssm_->UpdatePrivateStateAndNotify(2);
1308 ASSERT_EQ(ssm_->privacyBundleMap_[2].size(), 1);
1309 }
1310
1311 /**
1312 * @tc.name: UpdatePrivateStateAndNotify4
1313 * @tc.desc: UpdatePrivateStateAndNotify4
1314 * @tc.type: FUNC
1315 */
1316 HWTEST_F(SceneSessionManagerTest6, UpdatePrivateStateAndNotify4, Function | SmallTest | Level3)
1317 {
1318 ASSERT_NE(nullptr, ssm_);
1319 ssm_->sceneSessionMap_.clear();
1320 ssm_->privacyBundleMap_.clear();
1321 SessionInfo sessionInfo;
1322 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1323 sessionInfo.abilityName_ = "DumpSessionWithId";
1324 sessionInfo.isSystem_ = false;
1325 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1326 ASSERT_NE(nullptr, sceneSession2);
1327 sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
1328 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1329 ASSERT_NE(nullptr, sceneSession);
1330 sceneSession->SetParentSession(sceneSession2);
1331 ASSERT_NE(nullptr, sceneSession->GetParentSession());
1332 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1333 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1334 ASSERT_NE(nullptr, sceneSession->property_);
1335 sceneSession->property_->SetPrivacyMode(true);
1336 sceneSession->property_->SetDisplayId(1);
1337 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1338 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
1339 ssm_->UpdatePrivateStateAndNotify(1);
1340 ASSERT_EQ(ssm_->privacyBundleMap_[1].size(), 1);
1341 sceneSession->property_->SetDisplayId(2);
1342 sceneSession->GetParentSession()->SetSessionState(SessionState::STATE_BACKGROUND);
1343 ssm_->UpdatePrivateStateAndNotify(2);
1344 ASSERT_EQ(ssm_->privacyBundleMap_[2].size(), 0);
1345 }
1346
1347 /**
1348 * @tc.name: GetCollaboratorByType
1349 * @tc.desc: GetCollaboratorByType
1350 * @tc.type: FUNC
1351 */
1352 HWTEST_F(SceneSessionManagerTest6, GetCollaboratorByType, Function | SmallTest | Level3)
1353 {
1354 ASSERT_NE(nullptr, ssm_);
1355 ssm_->collaboratorMap_.clear();
1356 auto ret = ssm_->GetCollaboratorByType(0);
1357 EXPECT_EQ(nullptr, ret);
1358 sptr<AAFwk::IAbilityManagerCollaborator> collaborator = nullptr;
1359 ASSERT_NE(nullptr, ssm_);
1360 ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator));
1361 ret = ssm_->GetCollaboratorByType(1);
1362 EXPECT_EQ(nullptr, ret);
1363 }
1364
1365 /**
1366 * @tc.name: RegisterGetStateFromManagerFunc
1367 * @tc.desc: RegisterGetStateFromManagerFunc
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(SceneSessionManagerTest6, RegisterGetStateFromManagerFunc, Function | SmallTest | Level3)
1371 {
1372 SessionInfo sessionInfo;
1373 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1374 sessionInfo.abilityName_ = "DumpSessionWithId";
1375 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1376 ASSERT_NE(nullptr, ssm_);
1377 ASSERT_NE(nullptr, sceneSession);
1378 ssm_->RegisterGetStateFromManagerFunc(sceneSession);
1379 sceneSession = nullptr;
1380 ASSERT_NE(nullptr, ssm_);
1381 ssm_->RegisterGetStateFromManagerFunc(sceneSession);
1382 }
1383
1384 /**
1385 * @tc.name: ProcessDialogRequestFocusImmdediately
1386 * @tc.desc: ProcessDialogRequestFocusImmdediately
1387 * @tc.type: FUNC
1388 */
1389 HWTEST_F(SceneSessionManagerTest6, ProcessDialogRequestFocusImmdediately, Function | SmallTest | Level3)
1390 {
1391 SessionInfo sessionInfo;
1392 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1393 sessionInfo.abilityName_ = "DumpSessionWithId";
1394 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1395 ASSERT_NE(nullptr, sceneSession->property_);
1396 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1397 ASSERT_NE(nullptr, ssm_);
1398 auto ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1399 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1400 ASSERT_NE(nullptr, sceneSession->property_);
1401 sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1402 ASSERT_NE(nullptr, ssm_);
1403 ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1404 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1405 ASSERT_NE(nullptr, sceneSession->property_);
1406 sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_END);
1407 ASSERT_NE(nullptr, ssm_);
1408 ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1409 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1410 }
1411
1412 /**
1413 * @tc.name: IsValidSessionIds
1414 * @tc.desc: IsValidSessionIds
1415 * @tc.type: FUNC
1416 */
1417 HWTEST_F(SceneSessionManagerTest6, IsValidSessionIds, Function | SmallTest | Level3)
1418 {
1419 std::vector<int32_t> sessionIds = {1, 2, 3, 4};
1420 std::vector<bool> results;
1421 results.clear();
1422 SessionInfo sessionInfo;
1423 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1424 sessionInfo.abilityName_ = "DumpSessionWithId";
1425 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1426 ASSERT_NE(nullptr, sceneSession);
1427 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1428 sptr<SceneSession> sceneSession1 = nullptr;
1429 ASSERT_NE(nullptr, ssm_);
1430 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
1431 ssm_->IsValidSessionIds(sessionIds, results);
1432 EXPECT_FALSE(results.empty());
1433 DisplayChangeListener listener;
1434 std::vector<uint64_t> missionIds;
1435 std::vector<uint64_t> surfaceNodeIds;
1436 listener.OnGetSurfaceNodeIdsFromMissionIds(missionIds, surfaceNodeIds);
1437 }
1438
1439 /**
1440 * @tc.name: DeleteStateDetectTask
1441 * @tc.desc: DeleteStateDetectTask
1442 * @tc.type: FUNC
1443 */
1444 HWTEST_F(SceneSessionManagerTest6, DeleteStateDetectTask, Function | SmallTest | Level3)
1445 {
1446 ASSERT_NE(nullptr, ssm_);
1447 ssm_->SetScreenLocked(true);
1448 sleep(1);
1449 EXPECT_EQ(true, ssm_->isScreenLocked_);
1450 ssm_->sceneSessionMap_.clear();
1451 ASSERT_NE(nullptr, ssm_);
1452 ssm_->DeleteStateDetectTask();
1453 SessionInfo sessionInfo;
1454 sessionInfo.bundleName_ = "SceneSessionManagerTest2";
1455 sessionInfo.abilityName_ = "DumpSessionWithId";
1456 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1457 ASSERT_NE(nullptr, sceneSession);
1458 sceneSession->detectTaskInfo_.taskState = DetectTaskState::NO_TASK;
1459 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1460 ASSERT_NE(nullptr, ssm_);
1461 ssm_->DeleteStateDetectTask();
1462 sceneSession->detectTaskInfo_.taskState = DetectTaskState::ATTACH_TASK;
1463 ASSERT_NE(nullptr, ssm_);
1464 ssm_->DeleteStateDetectTask();
1465 }
1466
1467 /**
1468 * @tc.name: GetWindowStyleType
1469 * @tc.desc: GetWindowStyleType
1470 * @tc.type: FUNC
1471 */
1472 HWTEST_F(SceneSessionManagerTest6, GetWindowStyleType, Function | SmallTest | Level3)
1473 {
1474 ASSERT_NE(nullptr, ssm_);
1475 WindowStyleType windowModeType = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
1476 ssm_->GetWindowStyleType(windowModeType);
1477 ASSERT_EQ(windowModeType, Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT);
1478 }
1479
1480 /**
1481 * @tc.name: TerminateSessionByPersistentId
1482 * @tc.desc: Success to terminate session by persistentId.
1483 * @tc.type: FUNC
1484 */
1485 HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId001, Function | SmallTest | Level3)
1486 {
1487 SessionInfo info;
1488 info.abilityName_ = "test1";
1489 info.bundleName_ = "test1";
1490 info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1491 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1492 ASSERT_NE(nullptr, sceneSession);
1493 ASSERT_NE(nullptr, ssm_);
1494 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
1495 auto result = ssm_->TerminateSessionByPersistentId(sceneSession->GetPersistentId());
1496 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
1497 }
1498
1499 /**
1500 * @tc.name: TerminateSessionByPersistentId
1501 * @tc.desc: Fail to terminate session by persistentId, invalid persistentId.
1502 * @tc.type: FUNC
1503 */
1504 HWTEST_F(SceneSessionManagerTest6, TerminateSessionByPersistentId002, Function | SmallTest | Level3)
1505 {
1506 SessionInfo info;
1507 info.abilityName_ = "test1";
1508 info.bundleName_ = "test1";
1509 info.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1510 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1511 ASSERT_NE(nullptr, sceneSession);
1512 ASSERT_NE(nullptr, ssm_);
1513 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
1514 auto result = ssm_->TerminateSessionByPersistentId(INVALID_SESSION_ID);
1515 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
1516 }
1517
1518 /**
1519 * @tc.name: SetRootSceneProcessBackEventFunc
1520 * @tc.desc: test function : SetRootSceneProcessBackEventFunc
1521 * @tc.type: FUNC
1522 */
1523 HWTEST_F(SceneSessionManagerTest6, SetRootSceneProcessBackEventFunc, Function | SmallTest | Level3)
1524 {
1525 SessionInfo sessionInfo;
1526 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1527 sessionInfo.abilityName_ = "SetRootSceneProcessBackEventFunc";
1528 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_WINDOW_BASE);
1529 sessionInfo.isSystem_ = true;
1530 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1531 ASSERT_NE(nullptr, sceneSession);
1532 ASSERT_NE(nullptr, ssm_);
1533 ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession));
1534 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
1535 focusGroup->SetFocusedSessionId(sceneSession->GetPersistentId());
1536 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
1537 ssm_->ProcessBackEvent();
1538
__anonc1427fda0402() 1539 RootSceneProcessBackEventFunc func = []() {};
1540 ssm_->SetRootSceneProcessBackEventFunc(func);
1541 ssm_->ProcessBackEvent();
1542 }
1543
1544 /**
1545 * @tc.name: RequestInputMethodCloseKeyboard
1546 * @tc.desc: RequestInputMethodCloseKeyboard
1547 * @tc.type: FUNC
1548 */
1549 HWTEST_F(SceneSessionManagerTest6, RequestInputMethodCloseKeyboard, Function | SmallTest | Level3)
1550 {
1551 ASSERT_NE(nullptr, ssm_);
1552 SessionInfo info;
1553 sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1554 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback);
1555 ssm_->sceneSessionMap_.insert({0, sceneSession});
1556 int32_t persistentId = 10;
1557 ssm_->RequestInputMethodCloseKeyboard(persistentId);
1558
1559 persistentId = 0;
1560 sptr<Session> session = sptr<Session>::MakeSptr(info);
1561 session->property_ = nullptr;
1562 ssm_->RequestInputMethodCloseKeyboard(persistentId);
1563
1564 bool enable = true;
1565 auto result = ssm_->GetFreeMultiWindowEnableState(enable);
1566 ASSERT_EQ(result, WSError::WS_OK);
1567 }
1568
1569 /**
1570 * @tc.name: RequestSceneSession
1571 * @tc.desc: RequestSceneSession
1572 * @tc.type: FUNC
1573 */
1574 HWTEST_F(SceneSessionManagerTest6, RequestSceneSession, Function | SmallTest | Level3)
1575 {
1576 SessionInfo info1;
1577 info1.persistentId_ = 1;
1578 info1.isPersistentRecover_ = false;
1579 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
1580
1581 SessionInfo info2;
1582 info2.abilityName_ = "RequestSceneSession";
1583 info2.bundleName_ = "RequestSceneSession";
1584 info2.persistentId_ = 1;
1585
1586 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info1, nullptr);
1587 ASSERT_NE(sceneSession, nullptr);
1588 ssm_->sceneSessionMap_.insert({1, sceneSession});
1589 sptr<SceneSession> getSceneSession1 = ssm_->RequestSceneSession(info1, windowSessionProperty);
1590 ASSERT_EQ(info1.bundleName_, getSceneSession1->GetSessionInfo().bundleName_);
1591
1592 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
1593 ssm_->sceneSessionMap_.insert({2, sceneSession2});
1594 sptr<SceneSession> getSceneSession2 = ssm_->RequestSceneSession(info2, windowSessionProperty);
1595 ASSERT_NE(info2.bundleName_, getSceneSession2->GetSessionInfo().bundleName_);
1596 }
1597
1598 /**
1599 * @tc.name: GetSceneSessionBySessionInfo
1600 * @tc.desc: GetSceneSessionBySessionInfo
1601 * @tc.type: FUNC
1602 */
1603 HWTEST_F(SceneSessionManagerTest6, GetSceneSessionBySessionInfo, Function | SmallTest | Level3)
1604 {
1605 SessionInfo info1;
1606 info1.persistentId_ = 1;
1607 info1.isPersistentRecover_ = false;
1608 info1.windowType_ = 1000;
1609 info1.appInstanceKey_ = "";
1610 ASSERT_EQ(ssm_->GetSceneSessionBySessionInfo(info1), nullptr);
1611
1612 SessionInfo info2;
1613 info2.persistentId_ = 1;
1614 info2.isPersistentRecover_ = false;
1615 info2.windowType_ = 1;
1616 info2.bundleName_ = "GetSceneSessionBySessionInfoBundle";
1617 info2.abilityName_ = "GetSceneSessionBySessionInfoAbility";
1618 info2.appInstanceKey_ = "";
1619 info2.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1620 ASSERT_NE(nullptr, info2.abilityInfo);
1621 info2.abilityInfo->launchMode = AppExecFwk::LaunchMode::SINGLETON;
1622 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info2, nullptr);
1623 ASSERT_NE(sceneSession, nullptr);
1624 ssm_->sceneSessionMap_.insert({1, sceneSession});
1625 sptr<SceneSession> getSceneSession = ssm_->GetSceneSessionBySessionInfo(info2);
1626 ASSERT_EQ(sceneSession, getSceneSession);
1627
1628 SessionInfo info3;
1629 info3.persistentId_ = 2;
1630 info3.isPersistentRecover_ = false;
1631 info3.windowType_ = 1;
1632 info3.bundleName_ = "GetSceneSessionBySessionInfoBundle2";
1633 info3.abilityName_ = "GetSceneSessionBySessionInfoAbility2";
1634 info3.appInstanceKey_ = "";
1635 info3.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1636 info3.abilityInfo->launchMode = AppExecFwk::LaunchMode::SPECIFIED;
1637 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info3, nullptr);
1638 ASSERT_NE(sceneSession2, nullptr);
1639 ssm_->sceneSessionMap_.insert({2, sceneSession2});
1640 info3.persistentId_ = 1000;
1641 ASSERT_EQ(ssm_->GetSceneSessionBySessionInfo(info3), nullptr);
1642
1643 SessionInfo info4;
1644 info4.persistentId_ = 0;
1645 info4.isPersistentRecover_ = false;
1646 ASSERT_EQ(ssm_->GetSceneSessionBySessionInfo(info4), nullptr);
1647
1648 SessionInfo info5;
1649 info5.persistentId_ = 5;
1650 info5.isPersistentRecover_ = true;
1651 ASSERT_EQ(ssm_->GetSceneSessionBySessionInfo(info5), nullptr);
1652 }
1653
1654 /**
1655 * @tc.name: RequestSceneSessionDestruction
1656 * @tc.desc: RequestSceneSessionDestruction
1657 * @tc.type: FUNC
1658 */
1659 HWTEST_F(SceneSessionManagerTest6, RequestSceneSessionDestruction, Function | SmallTest | Level3)
1660 {
1661 sptr<SceneSession> sceneSession;
1662 ASSERT_EQ(sceneSession, nullptr);
1663 bool needRemoveSession = true;
1664 bool isSaveSnapshot = true;
1665 bool isForceClean = true;
1666 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionDestruction(
1667 sceneSession, needRemoveSession, isSaveSnapshot, isForceClean));
1668
1669 SessionInfo info;
1670 sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1671 sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback);
1672 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1673 ASSERT_NE(property, nullptr);
1674 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1675 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionDestruction(
1676 sceneSession, needRemoveSession, isSaveSnapshot, isForceClean));
1677 }
1678
1679 /**
1680 * @tc.name: NotifySessionAINavigationBarChange
1681 * @tc.desc: NotifySessionAINavigationBarChange
1682 * @tc.type: FUNC
1683 */
1684 HWTEST_F(SceneSessionManagerTest6, NotifySessionAINavigationBarChange, Function | SmallTest | Level3)
1685 {
1686 ASSERT_NE(nullptr, ssm_);
1687 int32_t persistentId = 1;
1688 SessionInfo info;
1689 sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1690 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback);
1691 ssm_->sceneSessionMap_.insert({0, sceneSession});
1692 ssm_->NotifySessionAINavigationBarChange(persistentId);
1693
1694 persistentId = 0;
1695 Session session(info);
1696 session.isVisible_ = true;
1697 session.state_ = SessionState::STATE_FOREGROUND;
1698 ssm_->NotifySessionAINavigationBarChange(persistentId);
1699 }
1700
1701 /**
1702 * @tc.name: GetProcessSurfaceNodeIdByPersistentId
1703 * @tc.desc: GetProcessSurfaceNodeIdByPersistentId
1704 * @tc.type: FUNC
1705 */
1706 HWTEST_F(SceneSessionManagerTest6, GetProcessSurfaceNodeIdByPersistentId, Function | SmallTest | Level3)
1707 {
1708 ASSERT_NE(nullptr, ssm_);
1709 SessionInfo info;
1710 sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
1711 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info, specificCallback);
1712 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info, specificCallback);
1713 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(info, specificCallback);
1714 sceneSession1->SetCallingPid(123);
1715 sceneSession2->SetCallingPid(123);
1716 sceneSession3->SetCallingPid(111);
1717
1718 int32_t pid = 123;
1719 std::vector<int32_t> persistentIds;
1720 std::vector<uint64_t> surfaceNodeIds;
1721 persistentIds.push_back(sceneSession1->GetPersistentId());
1722 persistentIds.push_back(sceneSession2->GetPersistentId());
1723 persistentIds.push_back(sceneSession3->GetPersistentId());
1724 ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1});
1725 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
1726 ssm_->sceneSessionMap_.insert({sceneSession3->GetPersistentId(), sceneSession3});
1727
1728 ASSERT_EQ(WMError::WM_OK, ssm_->GetProcessSurfaceNodeIdByPersistentId(pid, persistentIds, surfaceNodeIds));
1729 ASSERT_EQ(0, surfaceNodeIds.size());
1730 }
1731
1732 /**
1733 * @tc.name: OnScreenFoldStatusChanged
1734 * @tc.desc: OnScreenFoldStatusChanged
1735 * @tc.type: FUNC
1736 */
1737 HWTEST_F(SceneSessionManagerTest6, OnScreenFoldStatusChanged, Function | SmallTest | Level3)
1738 {
1739 std::vector<std::string> screenFoldInfo;
1740 sptr<IDisplayChangeListener> listener = sptr<DisplayChangeListener>::MakeSptr();
1741 ASSERT_NE(nullptr, listener);
1742 listener->OnScreenFoldStatusChanged(screenFoldInfo);
1743 ASSERT_NE(nullptr, ssm_);
1744 auto ret = ssm_->UpdateDisplayHookInfo(0, 50, 50, 0.0f, true);
1745 EXPECT_EQ(ret, WMError::WM_OK);
1746 ssm_->CheckSceneZOrder();
1747 }
1748
1749 /**
1750 * @tc.name: NotifySessionForeground
1751 * @tc.desc: NotifySessionForeground
1752 * @tc.type: FUNC
1753 */
1754 HWTEST_F(SceneSessionManagerTest6, NotifySessionForeground, Function | SmallTest | Level3)
1755 {
1756 SessionInfo sessionInfo;
1757 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1758 sessionInfo.abilityName_ = "NotifySessionForeground";
1759 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1760 uint32_t reason = 0;
1761 bool withAnimation = false;
1762 ASSERT_NE(nullptr, ssm_);
1763 ssm_->NotifySessionForeground(sceneSession, reason, withAnimation);
1764 WSRect area = { 0, 0, 0, 0 };
1765 uint32_t type = 0;
1766 uint64_t displayId = 0;
1767 ssm_->AddWindowDragHotArea(displayId, type, area);
1768 ssm_->currAINavigationBarAreaMap_.clear();
1769 ssm_->currAINavigationBarAreaMap_.insert(std::make_pair(displayId, area));
1770 auto ret = ssm_->GetAINavigationBarArea(1);
1771 EXPECT_TRUE(ret.IsEmpty());
1772 ret = ssm_->GetAINavigationBarArea(displayId);
1773 EXPECT_EQ(ret, area);
1774 }
1775
1776 /**
1777 * @tc.name: OnDisplayStateChange
1778 * @tc.desc: OnDisplayStateChange
1779 * @tc.type: FUNC
1780 */
1781 HWTEST_F(SceneSessionManagerTest6, OnDisplayStateChange, Function | SmallTest | Level3)
1782 {
1783 DisplayChangeListener listener;
1784 DisplayId displayId = 0;
1785 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
1786 ASSERT_NE(nullptr, displayInfo);
1787 std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap;
1788 displayInfoMap.insert(std::make_pair(displayId, displayInfo));
1789 DisplayStateChangeType type = DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE;
1790 listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1791 type = DisplayStateChangeType::UPDATE_ROTATION;
1792 listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1793 type = DisplayStateChangeType::UPDATE_SCALE;
1794 listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1795 type = DisplayStateChangeType::UNKNOWN;
1796 listener.OnDisplayStateChange(displayId, displayInfo, displayInfoMap, type);
1797 }
1798
1799 /**
1800 * @tc.name: CheckIfReuseSession
1801 * @tc.desc: CheckIfReuseSession
1802 * @tc.type: FUNC
1803 */
1804 HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession, Function | SmallTest | Level3)
1805 {
1806 SessionInfo sessionInfo;
1807 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1808 sessionInfo.abilityName_ = "CheckIfReuseSession";
1809 ASSERT_NE(nullptr, ssm_);
1810 auto ret = ssm_->CheckIfReuseSession(sessionInfo);
1811 EXPECT_EQ(ret, BrokerStates::BROKER_UNKOWN);
1812 ScreenId screenId = 0;
1813 std::unordered_map<int32_t, SessionUIParam> uiParams;
1814 ssm_->FlushUIParams(screenId, std::move(uiParams));
1815 }
1816
1817 /**
1818 * @tc.name: CheckIfReuseSession02
1819 * @tc.desc: Test if CollaboratorType not exist and collaboratorMap_ not exist
1820 * @tc.type: FUNC
1821 */
1822 HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession02, Function | SmallTest | Level3)
1823 {
1824 ASSERT_NE(ssm_, nullptr);
1825 ssm_->bundleMgr_ = ssm_->GetBundleManager();
1826 ssm_->currentUserId_ = 123;
1827
1828 SessionInfo sessionInfo;
1829 sessionInfo.moduleName_ = "SceneSessionManager";
1830 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1831 sessionInfo.abilityName_ = "CheckIfReuseSession02";
1832 sessionInfo.want = std::make_shared<AAFwk::Want>();
1833
1834 SceneSessionManager::SessionInfoList list = {
1835 .uid_ = 123, .bundleName_ = "SceneSessionManagerTest6",
1836 .abilityName_ = "CheckIfReuseSession02", .moduleName_ = "SceneSessionManager"
1837 };
1838
1839 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1840 ASSERT_NE(abilityInfo, nullptr);
1841 ssm_->abilityInfoMap_[list] = abilityInfo;
1842 auto ret1 = ssm_->CheckIfReuseSession(sessionInfo);
1843 ASSERT_EQ(ret1, BrokerStates::BROKER_UNKOWN);
1844 ssm_->abilityInfoMap_.erase(list);
1845 }
1846
1847 /**
1848 * @tc.name: CheckIfReuseSession03
1849 * @tc.desc: Test if CollaboratorType is RESERVE_TYPE and collaboratorMap_ not exist
1850 * @tc.type: FUNC
1851 */
1852 HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession03, Function | SmallTest | Level3)
1853 {
1854 ASSERT_NE(ssm_, nullptr);
1855 ssm_->bundleMgr_ = ssm_->GetBundleManager();
1856 ssm_->currentUserId_ = 123;
1857
1858 SessionInfo sessionInfo;
1859 sessionInfo.moduleName_ = "SceneSessionManager";
1860 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1861 sessionInfo.abilityName_ = "CheckIfReuseSession03";
1862 sessionInfo.want = std::make_shared<AAFwk::Want>();
1863
1864 SceneSessionManager::SessionInfoList list = {
1865 .uid_ = 123, .bundleName_ = "SceneSessionManagerTest6",
1866 .abilityName_ = "CheckIfReuseSession03", .moduleName_ = "SceneSessionManager"
1867 };
1868
1869 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1870 ASSERT_NE(abilityInfo, nullptr);
1871 abilityInfo->applicationInfo.codePath = std::to_string(CollaboratorType::RESERVE_TYPE);
1872 ssm_->abilityInfoMap_[list] = abilityInfo;
1873 auto ret2 = ssm_->CheckIfReuseSession(sessionInfo);
1874 ASSERT_EQ(ret2, BrokerStates::BROKER_UNKOWN);
1875 ssm_->abilityInfoMap_.erase(list);
1876 }
1877
1878 /**
1879 * @tc.name: CheckIfReuseSession04
1880 * @tc.desc: Test if CollaboratorType is RESERVE_TYPE and collaboratorMap_ exist
1881 * @tc.type: FUNC
1882 */
1883 HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession04, Function | SmallTest | Level3)
1884 {
1885 ASSERT_NE(ssm_, nullptr);
1886 ssm_->bundleMgr_ = ssm_->GetBundleManager();
1887 ssm_->currentUserId_ = 123;
1888
1889 SessionInfo sessionInfo;
1890 sessionInfo.moduleName_ = "SceneSessionManager";
1891 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1892 sessionInfo.abilityName_ = "CheckIfReuseSession04";
1893 sessionInfo.want = std::make_shared<AAFwk::Want>();
1894
1895 SceneSessionManager::SessionInfoList list = {
1896 .uid_ = 123, .bundleName_ = "SceneSessionManagerTest6",
1897 .abilityName_ = "CheckIfReuseSession04", .moduleName_ = "SceneSessionManager"
1898 };
1899
1900 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1901 ASSERT_NE(abilityInfo, nullptr);
1902 abilityInfo->applicationInfo.codePath = std::to_string(CollaboratorType::RESERVE_TYPE);
1903 ssm_->abilityInfoMap_[list] = abilityInfo;
1904
1905 sptr<AAFwk::IAbilityManagerCollaborator> collaborator =
1906 iface_cast<AAFwk::IAbilityManagerCollaborator>(nullptr);
1907 ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator));
1908 auto ret3 = ssm_->CheckIfReuseSession(sessionInfo);
1909 ASSERT_EQ(ret3, BrokerStates::BROKER_UNKOWN);
1910 ssm_->abilityInfoMap_.erase(list);
1911 ssm_->collaboratorMap_.erase(1);
1912 }
1913
1914 /**
1915 * @tc.name: CheckIfReuseSession05
1916 * @tc.desc: Test if CollaboratorType is OTHERS_TYPE and collaboratorMap_ exist
1917 * @tc.type: FUNC
1918 */
1919 HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession05, Function | SmallTest | Level3)
1920 {
1921 ASSERT_NE(ssm_, nullptr);
1922 ssm_->bundleMgr_ = ssm_->GetBundleManager();
1923 ssm_->currentUserId_ = 123;
1924
1925 SessionInfo sessionInfo;
1926 sessionInfo.moduleName_ = "SceneSessionManager";
1927 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1928 sessionInfo.abilityName_ = "CheckIfReuseSession05";
1929 sessionInfo.want = std::make_shared<AAFwk::Want>();
1930
1931 SceneSessionManager::SessionInfoList list = {
1932 .uid_ = 123, .bundleName_ = "SceneSessionManagerTest6",
1933 .abilityName_ = "CheckIfReuseSession05", .moduleName_ = "SceneSessionManager"
1934 };
1935
1936 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1937 ASSERT_NE(abilityInfo, nullptr);
1938 abilityInfo->applicationInfo.codePath = std::to_string(CollaboratorType::OTHERS_TYPE);
1939 ssm_->abilityInfoMap_[list] = abilityInfo;
1940
1941 sptr<AAFwk::IAbilityManagerCollaborator> collaborator =
1942 iface_cast<AAFwk::IAbilityManagerCollaborator>(nullptr);
1943 ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator));
1944 auto ret4 = ssm_->CheckIfReuseSession(sessionInfo);
1945 ASSERT_EQ(ret4, BrokerStates::BROKER_UNKOWN);
1946 ssm_->abilityInfoMap_.erase(list);
1947 ssm_->collaboratorMap_.erase(1);
1948 }
1949
1950 /**
1951 * @tc.name: UpdateAvoidArea
1952 * @tc.desc: UpdateAvoidArea
1953 * @tc.type: FUNC
1954 */
1955 HWTEST_F(SceneSessionManagerTest6, UpdateAvoidArea, Function | SmallTest | Level3)
1956 {
1957 int32_t persistentId = 0;
1958 ASSERT_NE(nullptr, ssm_);
1959 ssm_->sceneSessionMap_.clear();
1960 ssm_->rootSceneSession_ = sptr<RootSceneSession>::MakeSptr();
1961 ssm_->UpdateAvoidArea(persistentId);
1962 SessionInfo sessionInfo;
1963 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1964 sessionInfo.abilityName_ = "UpdateAvoidArea";
1965 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1966 ASSERT_NE(nullptr, sceneSession);
1967 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1968 ASSERT_NE(nullptr, sceneSession->property_);
1969 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_STATUS_BAR);
1970 ssm_->UpdateAvoidArea(persistentId);
1971 sceneSession->property_->SetWindowType(WindowType::APP_WINDOW_BASE);
1972 ssm_->UpdateAvoidArea(persistentId);
1973 }
1974
1975 /**
1976 * @tc.name: UpdateMaximizeMode
1977 * @tc.desc: UpdateMaximizeMode
1978 * @tc.type: FUNC
1979 */
1980 HWTEST_F(SceneSessionManagerTest6, UpdateMaximizeMode, Function | SmallTest | Level3)
1981 {
1982 int32_t persistentId = 0;
1983 bool isMaximize = true;
1984 ASSERT_NE(nullptr, ssm_);
1985 ssm_->sceneSessionMap_.clear();
1986 auto ret = ssm_->UpdateMaximizeMode(persistentId, isMaximize);
1987 EXPECT_EQ(ret, WSError::WS_OK);
1988 SessionInfo sessionInfo;
1989 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
1990 sessionInfo.abilityName_ = "UpdateMaximizeMode";
1991 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1992 ASSERT_NE(nullptr, sceneSession);
1993 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1994 EXPECT_EQ(ret, WSError::WS_OK);
1995 sptr<DisplayInfo> displayInfo = nullptr;
1996 ssm_->ProcessDisplayScale(displayInfo);
1997 displayInfo = sptr<DisplayInfo>::MakeSptr();
1998 ASSERT_NE(nullptr, displayInfo);
1999 ssm_->ProcessDisplayScale(displayInfo);
2000 ProcessVirtualPixelRatioChangeFunc func = nullptr;
2001 ssm_->SetVirtualPixelRatioChangeListener(func);
2002 }
2003
2004 /**
2005 * @tc.name: WindowDestroyNotifyVisibility
2006 * @tc.desc: WindowDestroyNotifyVisibility
2007 * @tc.type: FUNC
2008 */
2009 HWTEST_F(SceneSessionManagerTest6, WindowDestroyNotifyVisibility, Function | SmallTest | Level3)
2010 {
2011 SessionInfo sessionInfo;
2012 sessionInfo.bundleName_ = "SceneSessionManagerTest6";
2013 sessionInfo.abilityName_ = "WindowDestroyNotifyVisibility";
2014 sptr<SceneSession> sceneSession = nullptr;
2015 ssm_->WindowDestroyNotifyVisibility(sceneSession);
2016 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
2017 ASSERT_NE(nullptr, sceneSession);
2018 sceneSession->SetRSVisible(false);
2019 ssm_->WindowDestroyNotifyVisibility(sceneSession);
2020 sceneSession->SetRSVisible(true);
2021 ASSERT_NE(nullptr, ssm_);
2022 ssm_->WindowDestroyNotifyVisibility(sceneSession);
2023 ASSERT_FALSE(sceneSession->GetRSVisible());
2024 }
2025 }
2026 } // namespace Rosen
2027 } // namespace OHOS