1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <regex>
18 #include <application_context.h>
19 #include <bundle_mgr_interface.h>
20 #include <bundlemgr/launcher_service.h>
21
22 #include "context.h"
23 #include "interfaces/include/ws_common.h"
24 #include "iremote_object_mocker.h"
25 #include "mock/mock_session_stage.h"
26 #include "mock/mock_window_event_channel.h"
27 #include "session_info.h"
28 #include "session_manager.h"
29 #include "session_manager/include/scene_session_manager.h"
30 #include "session/host/include/scene_session.h"
31 #include "session/host/include/main_session.h"
32 #include "window_manager_agent.h"
33 #include "zidl/window_manager_agent_interface.h"
34
35 using namespace testing;
36 using namespace testing::ext;
37
38 namespace OHOS {
39 namespace Rosen {
40 class SceneSessionManagerTest4 : public testing::Test {
41 public:
42 static void SetUpTestCase();
43
44 static void TearDownTestCase();
45
46 void SetUp() override;
47
48 void TearDown() override;
49
50 static bool gestureNavigationEnabled_;
51
52 static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
53 static sptr<SceneSessionManager> ssm_;
54
55 private:
56 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
57 };
58
59 sptr<SceneSessionManager> SceneSessionManagerTest4::ssm_ = nullptr;
60 bool SceneSessionManagerTest4::gestureNavigationEnabled_ = true;
61
62 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest4::callbackFunc_ = [](bool enable,
__anon7911f39a0102(bool enable, const std::string& bundleName, GestureBackType type) 63 const std::string& bundleName, GestureBackType type) {
64 gestureNavigationEnabled_ = enable;
65 };
66
67
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)68 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
69 {
70 }
71
ProcessStatusBarEnabledChangeFuncTest(bool enable)72 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
73 {
74 }
75
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)76 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
77 {
78 }
79
SetUpTestCase()80 void SceneSessionManagerTest4::SetUpTestCase()
81 {
82 ssm_ = &SceneSessionManager::GetInstance();
83 }
84
TearDownTestCase()85 void SceneSessionManagerTest4::TearDownTestCase()
86 {
87 ssm_ = nullptr;
88 }
89
SetUp()90 void SceneSessionManagerTest4::SetUp()
91 {
92 ssm_->sceneSessionMap_.clear();
93 }
94
TearDown()95 void SceneSessionManagerTest4::TearDown()
96 {
97 ssm_->sceneSessionMap_.clear();
98 usleep(WAIT_SYNC_IN_NS);
99 }
100
101
102 namespace {
103 /**
104 * @tc.name: UpdateSceneSessionWant01
105 * @tc.desc: SceneSesionManager test UpdateSceneSessionWant
106 * @tc.type: FUNC
107 */
108 HWTEST_F(SceneSessionManagerTest4, UpdateSceneSessionWant01, Function | SmallTest | Level3)
109 {
110 SessionInfo info;
111 info.persistentId_ = 0;
112 ssm_->UpdateSceneSessionWant(info);
113 ASSERT_NE(ssm_, nullptr);
114 }
115
116 /**
117 * @tc.name: UpdateSceneSessionWant02
118 * @tc.desc: SceneSesionManager test UpdateSceneSessionWant
119 * @tc.type: FUNC
120 */
121 HWTEST_F(SceneSessionManagerTest4, UpdateSceneSessionWant02, Function | SmallTest | Level3)
122 {
123 SessionInfo info;
124 info.persistentId_ = 1;
125 ssm_->UpdateSceneSessionWant(info);
126 ASSERT_NE(ssm_, nullptr);
127 }
128
129 /**
130 * @tc.name: UpdateSceneSessionWant03
131 * @tc.desc: SceneSesionManager test UpdateSceneSessionWant
132 * @tc.type: FUNC
133 */
134 HWTEST_F(SceneSessionManagerTest4, UpdateSceneSessionWant03, Function | SmallTest | Level3)
135 {
136 SessionInfo info;
137 info.persistentId_ = 1;
138 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
139 ASSERT_NE(sceneSession, nullptr);
140 ssm_->sceneSessionMap_.insert({1, sceneSession});
141 ssm_->UpdateSceneSessionWant(info);
142 ASSERT_NE(ssm_, nullptr);
143 }
144
145 /**
146 * @tc.name: UpdateSceneSessionWant04
147 * @tc.desc: SceneSesionManager test UpdateSceneSessionWant
148 * @tc.type: FUNC
149 */
150 HWTEST_F(SceneSessionManagerTest4, UpdateSceneSessionWant04, Function | SmallTest | Level3)
151 {
152 SessionInfo info;
153 info.persistentId_ = 1;
154 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
155 info.want = want;
156 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
157 ASSERT_NE(sceneSession, nullptr);
158 ssm_->sceneSessionMap_.insert({1, sceneSession});
159 ssm_->UpdateSceneSessionWant(info);
160 ASSERT_NE(ssm_, nullptr);
161 }
162
163 /**
164 * @tc.name: UpdateSceneSessionWant05
165 * @tc.desc: SceneSesionManager test UpdateSceneSessionWant
166 * @tc.type: FUNC
167 */
168 HWTEST_F(SceneSessionManagerTest4, UpdateSceneSessionWant05, Function | SmallTest | Level3)
169 {
170 SessionInfo info;
171 info.persistentId_ = 1;
172 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
173 info.want = want;
174 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
175 ASSERT_NE(sceneSession, nullptr);
176 int32_t collaboratorType = CollaboratorType::RESERVE_TYPE;
177 sceneSession->SetCollaboratorType(collaboratorType);
178 ssm_->sceneSessionMap_.insert({1, sceneSession});
179 ssm_->UpdateSceneSessionWant(info);
180 ASSERT_NE(ssm_, nullptr);
181 }
182
183 /**
184 * @tc.name: UpdateSceneSessionWant06
185 * @tc.desc: SceneSesionManager test UpdateSceneSessionWant
186 * @tc.type: FUNC
187 */
188 HWTEST_F(SceneSessionManagerTest4, UpdateSceneSessionWant06, Function | SmallTest | Level3)
189 {
190 SessionInfo info;
191 info.persistentId_ = 1;
192 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
193 info.want = want;
194 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
195 ASSERT_NE(sceneSession, nullptr);
196 int32_t collaboratorType = -1;
197 sceneSession->SetCollaboratorType(collaboratorType);
198 ssm_->sceneSessionMap_.insert({1, sceneSession});
199 ssm_->UpdateSceneSessionWant(info);
200 ASSERT_NE(ssm_, nullptr);
201 }
202
203 /**
204 * @tc.name: GetSceneSessionByName01
205 * @tc.desc: SceneSesionManager test GetSceneSessionByName
206 * @tc.type: FUNC
207 */
208 HWTEST_F(SceneSessionManagerTest4, GetSceneSessionByName01, Function | SmallTest | Level3)
209 {
210 std::string abilityName = "test1";
211 std::string bundleName = "test2";
212 std::string moduleName = "test3";
213 int32_t appIndex = 10;
214 SessionInfo info;
215 info.abilityName_ = abilityName;
216 info.bundleName_ = bundleName;
217 info.moduleName_ = moduleName;
218 info.appIndex_ = appIndex;
219 info.persistentId_ = 1;
220 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
221 ASSERT_NE(sceneSession, nullptr);
222 ssm_->sceneSessionMap_.insert({1, sceneSession});
223 ComparedSessionInfo compareSessionInfo = { bundleName, moduleName, abilityName, appIndex };
224 ASSERT_NE(ssm_->GetSceneSessionByName(compareSessionInfo), nullptr);
225 }
226
227 /**
228 * @tc.name: DestroyAndDisconnectSpecificSession01
229 * @tc.desc: SceneSesionManager test DestroyAndDisconnectSpecificSession
230 * @tc.type: FUNC
231 */
232 HWTEST_F(SceneSessionManagerTest4, DestroyAndDisconnectSpecificSession01, Function | SmallTest | Level3)
233 {
234 SessionInfo info;
235 info.abilityName_ = "DestroyAndDisconnectSpecificSession";
236 info.bundleName_ = "DestroyAndDisconnectSpecificSession";
237 info.persistentId_ = 1;
238 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
239 ASSERT_NE(sceneSession, nullptr);
240 ssm_->sceneSessionMap_.insert({1, sceneSession});
241 ASSERT_NE(ssm_->DestroyAndDisconnectSpecificSession(1), WSError::WS_ERROR_NULLPTR);
242 }
243
244 /**
245 * @tc.name: GetAllSessionDumpInfo
246 * @tc.desc: SceneSesionManager test GetAllSessionDumpInfo
247 * @tc.type: FUNC
248 */
249 HWTEST_F(SceneSessionManagerTest4, GetAllSessionDumpInfo, Function | SmallTest | Level3)
250 {
251 SessionInfo info1;
252 info1.abilityName_ = "GetAllSessionDumpInfo1";
253 info1.bundleName_ = "GetAllSessionDumpInfo1";
254 info1.persistentId_ = 1;
255 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
256 ASSERT_NE(sceneSession1, nullptr);
257 sceneSession1->UpdateNativeVisibility(true);
258
259 SessionInfo info2;
260 info2.abilityName_ = "GetAllSessionDumpInfo2";
261 info2.bundleName_ = "GetAllSessionDumpInfo2";
262 info2.persistentId_ = 2;
263 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
264 ASSERT_NE(sceneSession2, nullptr);
265 sceneSession2->UpdateNativeVisibility(false);
266
267 ssm_->sceneSessionMap_.insert({1, sceneSession1});
268 ssm_->sceneSessionMap_.insert({2, sceneSession2});
269 std::string dumpInfo;
270 ASSERT_EQ(ssm_->GetAllSessionDumpInfo(dumpInfo), WSError::WS_OK);
271 }
272
273 /**
274 * @tc.name: GetSpecifiedSessionDumpInfo
275 * @tc.desc: SceneSesionManager test GetSpecifiedSessionDumpInfo
276 * @tc.type: FUNC
277 */
278 HWTEST_F(SceneSessionManagerTest4, GetSpecifiedSessionDumpInfo, Function | SmallTest | Level3)
279 {
280 SessionInfo info;
281 info.abilityName_ = "GetSpecifiedSessionDumpInfo";
282 info.bundleName_ = "GetSpecifiedSessionDumpInfo";
283 info.persistentId_ = 1234;
284 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
285 ASSERT_NE(sceneSession, nullptr);
286 ssm_->sceneSessionMap_.insert({1234, sceneSession});
287 std::string dumpInfo;
288 std::string strId = "1234";
289 std::vector<std::string> params_(5, "");
290 ASSERT_EQ(ssm_->GetSpecifiedSessionDumpInfo(dumpInfo, params_, strId), WSError::WS_OK);
291 }
292
293 /**
294 * @tc.name: NotifyEnterRecentTask02
295 * @tc.desc: NotifyEnterRecentTask
296 * @tc.type: FUNC
297 */
298 HWTEST_F(SceneSessionManagerTest4, NotifyEnterRecentTask02, Function | SmallTest | Level3)
299 {
300 ASSERT_NE(nullptr, ssm_);
301 EXPECT_EQ(ssm_->NotifyEnterRecentTask(false), WSError::WS_OK);
302 }
303
304 /**
305 * @tc.name: GetWindowStatus
306 * @tc.desc: GetWindowStatus
307 * @tc.type: FUNC
308 */
309 HWTEST_F(SceneSessionManagerTest4, GetWindowStatus, Function | SmallTest | Level3)
310 {
311 ASSERT_NE(nullptr, ssm_);
312 WindowMode mode = WindowMode::WINDOW_MODE_FLOATING;
313 SessionState sessionState = SessionState::STATE_FOREGROUND;
314 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
315 ASSERT_NE(property, nullptr);
316 auto result = ssm_->GetWindowStatus(mode, sessionState, nullptr);
317 EXPECT_EQ(result, WindowStatus::WINDOW_STATUS_UNDEFINED);
318
319 property->SetMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR);
320 result = ssm_->GetWindowStatus(mode, sessionState, property);
321 EXPECT_EQ(result, WindowStatus::WINDOW_STATUS_MAXIMIZE);
322
323 property->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
324 result = ssm_->GetWindowStatus(mode, sessionState, property);
325 EXPECT_EQ(result, WindowStatus::WINDOW_STATUS_FLOATING);
326
327 mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY;
328 result = ssm_->GetWindowStatus(mode, sessionState, property);
329 EXPECT_EQ(result, WindowStatus::WINDOW_STATUS_SPLITSCREEN);
330 }
331
332 /**
333 * @tc.name: UpdateDisplayRegion
334 * @tc.desc: UpdateDisplayRegion
335 * @tc.type: FUNC
336 */
337 HWTEST_F(SceneSessionManagerTest4, UpdateDisplayRegion, Function | SmallTest | Level3)
338 {
339 ASSERT_NE(nullptr, ssm_);
340 ssm_->UpdateDisplayRegion(nullptr);
341 sptr<DisplayInfo> displayInfo = sptr<DisplayInfo>::MakeSptr();
342 ASSERT_NE(displayInfo, nullptr);
343 displayInfo->SetWidth(0);
344 ssm_->UpdateDisplayRegion(displayInfo);
345
346 displayInfo->SetWidth(1);
347 displayInfo->SetHeight(0);
348 ssm_->UpdateDisplayRegion(displayInfo);
349
350 displayInfo->SetHeight(1);
351 ssm_->UpdateDisplayRegion(displayInfo);
352 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
353 }
354
355 /**
356 * @tc.name: GetCustomDecorHeight
357 * @tc.desc: GetCustomDecorHeight
358 * @tc.type: FUNC
359 */
360 HWTEST_F(SceneSessionManagerTest4, GetCustomDecorHeight, Function | SmallTest | Level3)
361 {
362 ASSERT_NE(nullptr, ssm_);
363 SessionInfo info;
364 info.abilityName_ = "SetBrightness";
365 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
366 ASSERT_NE(sceneSession, nullptr);
367 sceneSession->SetCustomDecorHeight(50);
368 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
369 ssm_->sceneSessionMap_.insert(std::make_pair(2, nullptr));
370 EXPECT_EQ(0, ssm_->GetCustomDecorHeight(2));
371 EXPECT_EQ(50, ssm_->GetCustomDecorHeight(1));
372 }
373
374 /**
375 * @tc.name: IsVectorSame
376 * @tc.desc: IsVectorSame
377 * @tc.type: FUNC
378 */
379 HWTEST_F(SceneSessionManagerTest4, IsVectorSame, Function | SmallTest | Level3)
380 {
381 ASSERT_NE(nullptr, ssm_);
382 std::vector<VisibleWindowNumInfo> lastInfo;
383 std::vector<VisibleWindowNumInfo> currentInfo;
384 VisibleWindowNumInfo num;
385 lastInfo.push_back(num);
386 EXPECT_EQ(false, ssm_->IsVectorSame(lastInfo, currentInfo));
387 lastInfo.clear();
388
389 lastInfo.reserve(2);
390 VisibleWindowNumInfo oneNum;
391 oneNum.displayId = 0;
392 oneNum.visibleWindowNum = 3;
393 lastInfo.push_back(oneNum);
394 currentInfo.push_back(oneNum);
395 EXPECT_EQ(true, ssm_->IsVectorSame(lastInfo, currentInfo));
396
397 currentInfo.clear();
398 VisibleWindowNumInfo twoNum;
399 twoNum.displayId = 0;
400 twoNum.visibleWindowNum = 2;
401 currentInfo.push_back(twoNum);
402 EXPECT_EQ(false, ssm_->IsVectorSame(lastInfo, currentInfo));
403
404 currentInfo.clear();
405 twoNum.displayId = 1;
406 twoNum.visibleWindowNum = 3;
407 currentInfo.push_back(twoNum);
408 EXPECT_EQ(false, ssm_->IsVectorSame(lastInfo, currentInfo));
409 }
410
411 /**
412 * @tc.name: ReportWindowProfileInfos
413 * @tc.desc: ReportWindowProfileInfos
414 * @tc.type: FUNC
415 */
416 HWTEST_F(SceneSessionManagerTest4, ReportWindowProfileInfos, Function | SmallTest | Level3)
417 {
418 ASSERT_NE(nullptr, ssm_);
419 SessionInfo info;
420 info.abilityName_ = "SetBrightness";
421 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
422 ASSERT_NE(sceneSession, nullptr);
423 sceneSession->sessionInfo_.isSystem_ = false;
424 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
425 ssm_->ReportWindowProfileInfos();
426
427 ssm_->focusedSessionId_ = 123;
428 ssm_->ReportWindowProfileInfos();
429 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
430 }
431
432 /**
433 * @tc.name: ReportWindowProfileInfos02
434 * @tc.desc: ReportWindowProfileInfos
435 * @tc.type: FUNC
436 */
437 HWTEST_F(SceneSessionManagerTest4, ReportWindowProfileInfos02, Function | SmallTest | Level3)
438 {
439 ASSERT_NE(nullptr, ssm_);
440 SessionInfo info;
441 info.abilityName_ = "SetBrightness";
442 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
443 ASSERT_NE(sceneSession, nullptr);
444 sceneSession->sessionInfo_.isSystem_ = false;
445 sptr<Session> session = sptr<Session>::MakeSptr(info);
446 ASSERT_NE(session, nullptr);
447 ASSERT_NE(sceneSession->property_, nullptr);
448 sceneSession->property_->type_ = WindowType::WINDOW_TYPE_MEDIA;
449 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
450 ssm_->ReportWindowProfileInfos();
451 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
452 }
453
454 /**
455 * @tc.name: ReportWindowProfileInfos03
456 * @tc.desc: ReportWindowProfileInfos
457 * @tc.type: FUNC
458 */
459 HWTEST_F(SceneSessionManagerTest4, ReportWindowProfileInfos03, Function | SmallTest | Level3)
460 {
461 ASSERT_NE(nullptr, ssm_);
462 SessionInfo info;
463 info.abilityName_ = "SetBrightness";
464 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
465 ASSERT_NE(sceneSession, nullptr);
466 sceneSession->sessionInfo_.isSystem_ = true;
467 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
468 ssm_->ReportWindowProfileInfos();
469 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
470 }
471
472 /**
473 * @tc.name: ReportWindowProfileInfos04
474 * @tc.desc: ReportWindowProfileInfos
475 * @tc.type: FUNC
476 */
477 HWTEST_F(SceneSessionManagerTest4, ReportWindowProfileInfos04, Function | SmallTest | Level3)
478 {
479 ASSERT_NE(nullptr, ssm_);
480 ssm_->sceneSessionMap_.insert(std::make_pair(1, nullptr));
481 ssm_->ReportWindowProfileInfos();
482 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
483 }
484
485 /**
486 * @tc.name: CacVisibleWindowNum
487 * @tc.desc: CacVisibleWindowNum
488 * @tc.type: FUNC
489 */
490 HWTEST_F(SceneSessionManagerTest4, CacVisibleWindowNum, Function | SmallTest | Level3)
491 {
492 ASSERT_NE(nullptr, ssm_);
493 SessionInfo info;
494 info.abilityName_ = "SetBrightness";
495 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
496 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
497 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(info, nullptr);
498 sptr<SceneSession> sceneSession04 = sptr<SceneSession>::MakeSptr(info, nullptr);
499 ASSERT_NE(sceneSession01, nullptr);
500 ASSERT_NE(sceneSession02, nullptr);
501 ASSERT_NE(sceneSession03, nullptr);
502 ASSERT_NE(sceneSession04, nullptr);
503 ASSERT_NE(sceneSession01->property_, nullptr);
504 sceneSession01->property_->type_ = WindowType::WINDOW_TYPE_WALLPAPER;
505 sceneSession01->SetRSVisible(true);
506 sceneSession02->state_ = SessionState::STATE_BACKGROUND;
507 ASSERT_NE(sceneSession03->property_, nullptr);
508 sceneSession03->property_->type_ = WindowType::APP_MAIN_WINDOW_END;
509 ASSERT_NE(sceneSession04->property_, nullptr);
510 sceneSession04->property_->type_ = WindowType::WINDOW_TYPE_WALLPAPER;
511 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
512 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
513 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
514 ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession04));
515 ssm_->sceneSessionMap_.insert(std::make_pair(5, nullptr));
516
517 ssm_->CacVisibleWindowNum();
518 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
519 }
520
521 /**
522 * @tc.name: GetAppMainSceneSession
523 * @tc.desc: GetAppMainSceneSession
524 * @tc.type: FUNC
525 */
526 HWTEST_F(SceneSessionManagerTest4, GetAppMainSceneSession, Function | SmallTest | Level3)
527 {
528 ASSERT_NE(nullptr, ssm_);
529 SessionInfo info;
530 info.abilityName_ = "SetBrightness";
531 sptr<SceneSession> sceneSession;
532 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
533 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
534 ASSERT_NE(sceneSession01, nullptr);
535 ASSERT_NE(sceneSession02, nullptr);
536 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession));
537 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
538 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
539 EXPECT_EQ(ssm_->GetAppMainSceneSession(sceneSession, 0), WSError::WS_ERROR_INVALID_SESSION);
540
541 EXPECT_EQ(ssm_->GetAppMainSceneSession(sceneSession01, 1), WSError::WS_OK);
542
543 ASSERT_NE(sceneSession01->property_, nullptr);
544 sceneSession01->property_->type_ = WindowType::WINDOW_TYPE_MEDIA;
545 EXPECT_EQ(ssm_->GetAppMainSceneSession(sceneSession01, 1), WSError::WS_ERROR_INVALID_CALLING);
546
547 sceneSession01->property_->type_ = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
548 sceneSession01->property_->SetParentPersistentId(2);
549 EXPECT_EQ(ssm_->GetAppMainSceneSession(sceneSession01, 1), WSError::WS_OK);
550 }
551
552 /**
553 * @tc.name: GetImmersiveState01
554 * @tc.desc: GetImmersiveState
555 * @tc.type: FUNC
556 */
557 HWTEST_F(SceneSessionManagerTest4, GetImmersiveState01, Function | SmallTest | Level3)
558 {
559 ASSERT_NE(nullptr, ssm_);
560 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
561
562 SessionInfo info;
563 info.abilityName_ = "GetImmersiveState01";
564 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
565 ASSERT_NE(sceneSession, nullptr);
566 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
567
568 sceneSession->property_->type_ = WindowType::APP_MAIN_WINDOW_BASE;
569 sceneSession->state_ = SessionState::STATE_ACTIVE;
570 sceneSession->state_ = SessionState::STATE_FOREGROUND;
571 sceneSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
572 EXPECT_EQ(false, ssm_->GetImmersiveState());
573 sceneSession->SetIsLayoutFullScreen(true);
574 EXPECT_EQ(true, ssm_->GetImmersiveState());
575 }
576
577 /**
578 * @tc.name: GetImmersiveState02
579 * @tc.desc: GetImmersiveState
580 * @tc.type: FUNC
581 */
582 HWTEST_F(SceneSessionManagerTest4, GetImmersiveState02, Function | SmallTest | Level3)
583 {
584 ASSERT_NE(nullptr, ssm_);
585
586 SessionInfo info;
587 info.abilityName_ = "GetImmersiveState02";
588 sptr<SceneSession> sceneSession01;
589 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
590 ASSERT_EQ(sceneSession01, nullptr);
591 ASSERT_NE(sceneSession02, nullptr);
592 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
593 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
594
595 EXPECT_EQ(false, ssm_->GetImmersiveState());
596 sceneSession02->property_->type_ = WindowType::APP_MAIN_WINDOW_END;
597 EXPECT_EQ(false, ssm_->GetImmersiveState());
598 sceneSession02->property_->type_ = WindowType::APP_MAIN_WINDOW_BASE;
599 EXPECT_EQ(false, ssm_->GetImmersiveState());
600 sceneSession02->state_ = SessionState::STATE_ACTIVE;
601 EXPECT_EQ(false, ssm_->GetImmersiveState());
602 sceneSession02->state_ = SessionState::STATE_FOREGROUND;
603 EXPECT_EQ(false, ssm_->GetImmersiveState());
604 sceneSession02->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
605 EXPECT_EQ(false, ssm_->GetImmersiveState());
606 sceneSession02->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
607 sceneSession02->property_->sysBarPropMap_[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = false;
608 EXPECT_EQ(true, ssm_->GetImmersiveState());
609 sceneSession02->property_->sysBarPropMap_[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = true;
610 EXPECT_EQ(false, ssm_->GetImmersiveState());
611 }
612
613 /**
614 * @tc.name: UpdateSessionDisplayId
615 * @tc.desc: UpdateSessionDisplayId
616 * @tc.type: FUNC
617 */
618 HWTEST_F(SceneSessionManagerTest4, UpdateSessionDisplayId, Function | SmallTest | Level3)
619 {
620 ASSERT_NE(nullptr, ssm_);
621 auto result = ssm_->UpdateSessionDisplayId(0, 0);
622 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_WINDOW);
623
624 SessionInfo info;
625 info.abilityName_ = "SetBrightness";
626 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
627 ASSERT_NE(sceneSession, nullptr);
628 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
629 sceneSession->sessionInfo_.screenId_ = 6;
630 result = ssm_->UpdateSessionDisplayId(1, 2);
631 EXPECT_EQ(result, WSError::WS_OK);
632
633 sceneSession->property_ = nullptr;
634 result = ssm_->UpdateSessionDisplayId(1, 2);
635 EXPECT_EQ(result, WSError::WS_ERROR_NULLPTR);
636 }
637
638 /**
639 * @tc.name: UpdateSessionWindowVisibilityListener02
640 * @tc.desc: UpdateSessionWindowVisibilityListener
641 * @tc.type: FUNC
642 */
643 HWTEST_F(SceneSessionManagerTest4, UpdateSessionWindowVisibilityListener02, Function | SmallTest | Level3)
644 {
645 ASSERT_NE(nullptr, ssm_);
646 SessionInfo info;
647 info.abilityName_ = "SetBrightness";
648 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
649 ASSERT_NE(sceneSession, nullptr);
650 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
651 int32_t persistentId = 1;
652 auto result = ssm_->UpdateSessionWindowVisibilityListener(persistentId, true);
653 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
654 }
655
656 /**
657 * @tc.name: UpdateDarkColorModeToRS
658 * @tc.desc: UpdateDarkColorModeToRS
659 * @tc.type: FUNC
660 * @tc.require: issueIB1N43
661 */
662 HWTEST_F(SceneSessionManagerTest4, UpdateDarkColorModeToRS, Function | SmallTest | Level3)
663 {
664 ASSERT_NE(nullptr, ssm_);
665 AbilityRuntime::ApplicationContext::applicationContext_ =
666 std::make_shared<AbilityRuntime::ApplicationContext>();
667 ASSERT_NE(nullptr, AbilityRuntime::ApplicationContext::applicationContext_);
668 AbilityRuntime::ApplicationContext::applicationContext_->contextImpl_ =
669 std::make_shared<AbilityRuntime::ContextImpl>();
670 ASSERT_NE(nullptr, AbilityRuntime::ApplicationContext::applicationContext_->contextImpl_);
671 AbilityRuntime::ApplicationContext::applicationContext_->contextImpl_->config_ =
672 std::make_shared<AppExecFwk::Configuration>();
673 ASSERT_NE(nullptr, AbilityRuntime::ApplicationContext::applicationContext_->GetConfiguration());
674 ssm_->UpdateDarkColorModeToRS();
675 }
676
677 /**
678 * @tc.name: NotifySessionAINavigationBarChange
679 * @tc.desc: NotifySessionAINavigationBarChange
680 * @tc.type: FUNC
681 */
682 HWTEST_F(SceneSessionManagerTest4, NotifySessionAINavigationBarChange, Function | SmallTest | Level3)
683 {
684 ASSERT_NE(nullptr, ssm_);
685 SessionInfo info;
686 info.abilityName_ = "SetBrightness";
687 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
688 ASSERT_NE(sceneSession, nullptr);
689 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
690 ssm_->NotifySessionAINavigationBarChange(0);
691 ssm_->NotifySessionAINavigationBarChange(1);
692
693 ASSERT_NE(sceneSession->property_, nullptr);
694 sceneSession->property_->type_ = WindowType::APP_SUB_WINDOW_END;
695 sceneSession->state_ = SessionState::STATE_ACTIVE;
696 ssm_->NotifySessionAINavigationBarChange(1);
697 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
698 }
699
700 /**
701 * @tc.name: UpdateNormalSessionAvoidArea
702 * @tc.desc: UpdateNormalSessionAvoidArea
703 * @tc.type: FUNC
704 */
705 HWTEST_F(SceneSessionManagerTest4, UpdateNormalSessionAvoidArea, Function | SmallTest | Level3)
706 {
707 ASSERT_NE(nullptr, ssm_);
708 int32_t persistentId = 1;
709 sptr<SceneSession> sceneSession = nullptr;
710 bool needUpdate = true;
711 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
712 EXPECT_EQ(needUpdate, false);
713
714 SessionInfo info;
715 info.abilityName_ = "SetBrightness";
716 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
717 ASSERT_NE(sceneSession, nullptr);
718 ASSERT_NE(sceneSession->property_, nullptr);
719 sceneSession->property_->type_ = WindowType::APP_SUB_WINDOW_BASE;
720 needUpdate = true;
721 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
722 EXPECT_EQ(needUpdate, false);
723
724 sceneSession->property_->type_ = WindowType::APP_SUB_WINDOW_END;
725 sceneSession->isVisible_ = true;
726 needUpdate = true;
727 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
728 EXPECT_EQ(needUpdate, false);
729
730 ssm_->avoidAreaListenerSessionSet_.insert(1);
731 ssm_->UpdateNormalSessionAvoidArea(persistentId, sceneSession, needUpdate);
732 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
733 }
734
735 /**
736 * @tc.name: UpdateAvoidSessionAvoidArea
737 * @tc.desc: UpdateAvoidSessionAvoidArea
738 * @tc.type: FUNC
739 */
740 HWTEST_F(SceneSessionManagerTest4, UpdateAvoidSessionAvoidArea, Function | SmallTest | Level3)
741 {
742 ASSERT_NE(nullptr, ssm_);
743 ssm_->avoidAreaListenerSessionSet_.insert(0);
744 ssm_->avoidAreaListenerSessionSet_.insert(1);
745 SessionInfo info;
746 info.abilityName_ = "SetBrightness";
747 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
748 ASSERT_NE(sceneSession, nullptr);
749 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
750 WindowType type = WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT;
751 ssm_->UpdateAvoidSessionAvoidArea(type);
752
753 ASSERT_NE(sceneSession->property_, nullptr);
754 sceneSession->property_->type_ = WindowType::APP_MAIN_WINDOW_END;
755 sceneSession->isVisible_ = true;
756 ssm_->UpdateAvoidSessionAvoidArea(type);
757 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
758 }
759
760 /**
761 * @tc.name: FindSessionByAffinity
762 * @tc.desc: FindSessionByAffinity
763 * @tc.type: FUNC
764 */
765 HWTEST_F(SceneSessionManagerTest4, FindSessionByAffinity, Function | SmallTest | Level3)
766 {
767 ASSERT_NE(nullptr, ssm_);
768 std::string affinity = "";
769 sptr<SceneSession> sceneSession = ssm_->FindSessionByAffinity(affinity);
770 EXPECT_EQ(sceneSession, nullptr);
771 }
772
773 /**
774 * @tc.name: SetSystemAnimatedScenes
775 * @tc.desc: SetSystemAnimatedScenes
776 * @tc.type: FUNC
777 */
778 HWTEST_F(SceneSessionManagerTest4, SetSystemAnimatedScenes, Function | SmallTest | Level3)
779 {
780 ASSERT_NE(nullptr, ssm_);
781 SystemAnimatedSceneType sceneType = SystemAnimatedSceneType::SCENE_ENTER_MISSION_CENTER;
782 auto result = ssm_->SetSystemAnimatedScenes(sceneType);
783 EXPECT_EQ(result, WMError::WM_OK);
784 }
785
786 /**
787 * @tc.name: GetProcessDrawingState
788 * @tc.desc: GetProcessDrawingState
789 * @tc.type: FUNC
790 */
791 HWTEST_F(SceneSessionManagerTest4, GetProcessDrawingState, Function | SmallTest | Level3)
792 {
793 ASSERT_NE(nullptr, ssm_);
794 uint64_t windowId = 10;
795 int32_t pid = 1;
796 bool currentDrawingContentState = true;
797 SessionInfo info;
798 info.abilityName_ = "SetBrightness";
799 sptr<SceneSession> sceneSession01 = nullptr;
800 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
801 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(info, nullptr);
802 sptr<SceneSession> sceneSession04 = sptr<SceneSession>::MakeSptr(info, nullptr);
803 ASSERT_NE(sceneSession02, nullptr);
804 ASSERT_NE(sceneSession03, nullptr);
805 ASSERT_NE(sceneSession04, nullptr);
806 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
807 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
808 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
809 ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession04));
810 sceneSession02->SetCallingPid(pid);
811 struct RSSurfaceNodeConfig config;
812 sceneSession02->surfaceNode_ = RSSurfaceNode::Create(config);
813 ASSERT_NE(sceneSession02->surfaceNode_, nullptr);
814 sceneSession03->SetCallingPid(pid);
815 sceneSession03->surfaceNode_ = nullptr;
816 sceneSession04->SetCallingPid(6);
817 auto result = ssm_->GetProcessDrawingState(windowId, pid, currentDrawingContentState);
818 EXPECT_EQ(result, true);
819 }
820
821 /**
822 * @tc.name: GetPreWindowDrawingState
823 * @tc.desc: GetPreWindowDrawingState
824 * @tc.type: FUNC
825 */
826 HWTEST_F(SceneSessionManagerTest4, GetPreWindowDrawingState, Function | SmallTest | Level3)
827 {
828 ASSERT_NE(nullptr, ssm_);
829 uint64_t surfaceId = 0;
830 int32_t pid = 10;
831 bool result = ssm_->GetPreWindowDrawingState(surfaceId, pid, true);
832 EXPECT_EQ(result, false);
833
834 SessionInfo info;
835 info.abilityName_ = "SetBrightness";
836 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
837 ASSERT_NE(sceneSession01, nullptr);
838 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
839 struct RSSurfaceNodeConfig config;
840 sceneSession01->surfaceNode_ = RSSurfaceNode::Create(config);
841 ASSERT_NE(sceneSession01->surfaceNode_, nullptr);
842 sceneSession01->surfaceNode_->id_ = 10;
843 surfaceId = 10;
844 result = ssm_->GetPreWindowDrawingState(surfaceId, pid, true);
845 EXPECT_EQ(result, false);
846 }
847
848 /**
849 * @tc.name: GetWindowDrawingContentChangeInfo
850 * @tc.desc: GetWindowDrawingContentChangeInfo
851 * @tc.type: FUNC
852 */
853 HWTEST_F(SceneSessionManagerTest4, GetWindowDrawingContentChangeInfo, Function | SmallTest | Level3)
854 {
855 ASSERT_NE(nullptr, ssm_);
856 SessionInfo info;
857 info.abilityName_ = "SetBrightness";
858 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
859 ASSERT_NE(sceneSession, nullptr);
860 ssm_->sceneSessionMap_.insert(std::make_pair(0, nullptr));
861 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
862
863 std::vector<std::pair<uint64_t, bool>> currDrawingContentData;
864 currDrawingContentData.push_back(std::make_pair(0, false));
865 currDrawingContentData.push_back(std::make_pair(1, true));
866
867 struct RSSurfaceNodeConfig config;
868 sceneSession->surfaceNode_ = RSSurfaceNode::Create(config);
869 ASSERT_NE(sceneSession->surfaceNode_, nullptr);
870 sceneSession->surfaceNode_->id_ = 0;
871 sceneSession->SetCallingPid(0);
872 sceneSession->SetDrawingContentState(true);
873
874 auto result = ssm_->GetWindowDrawingContentChangeInfo(currDrawingContentData);
875 EXPECT_EQ(result, currDrawingContentData);
876
877 sceneSession->SetCallingPid(2);
878 result = ssm_->GetWindowDrawingContentChangeInfo(currDrawingContentData);
879 EXPECT_NE(result, currDrawingContentData);
880 }
881
882 /**
883 * @tc.name: DealwithDrawingContentChange
884 * @tc.desc: DealwithDrawingContentChange
885 * @tc.type: FUNC
886 */
887 HWTEST_F(SceneSessionManagerTest4, DealwithDrawingContentChange, Function | SmallTest | Level3)
888 {
889 ASSERT_NE(nullptr, ssm_);
890 SessionInfo info;
891 info.abilityName_ = "SetBrightness";
892 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
893 ASSERT_NE(sceneSession, nullptr);
894 ssm_->sceneSessionMap_.insert(std::make_pair(0, nullptr));
895
896 std::vector<std::pair<uint64_t, bool>> drawingContentChangeInfo;
897 drawingContentChangeInfo.push_back(std::make_pair(0, true));
898 drawingContentChangeInfo.push_back(std::make_pair(1, true));
899 ssm_->DealwithDrawingContentChange(drawingContentChangeInfo);
900
901 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
902 struct RSSurfaceNodeConfig config;
903 sceneSession->surfaceNode_ = RSSurfaceNode::Create(config);
904 ASSERT_NE(sceneSession->surfaceNode_, nullptr);
905 sceneSession->surfaceNode_->id_ = 1;
906 ssm_->DealwithDrawingContentChange(drawingContentChangeInfo);
907
908 ssm_->openDebugTrace = true;
909 ssm_->DealwithDrawingContentChange(drawingContentChangeInfo);
910 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
911 }
912
913 /**
914 * @tc.name: GetSubSceneSession
915 * @tc.desc: GetSubSceneSession
916 * @tc.type: FUNC
917 */
918 HWTEST_F(SceneSessionManagerTest4, GetSubSceneSession, Function | SmallTest | Level3)
919 {
920 ASSERT_NE(nullptr, ssm_);
921 SessionInfo info;
922 info.abilityName_ = "SetBrightness";
923 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
924 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
925 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(info, nullptr);
926 sptr<Session> session04 = sptr<Session>::MakeSptr(info);
927 sptr<Session> session05 = sptr<Session>::MakeSptr(info);
928 ASSERT_NE(sceneSession01, nullptr);
929 ASSERT_NE(sceneSession02, nullptr);
930 ASSERT_NE(sceneSession03, nullptr);
931 ASSERT_NE(session04, nullptr);
932 ASSERT_NE(session05, nullptr);
933 ssm_->sceneSessionMap_.insert(std::make_pair(0, nullptr));
934 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
935 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
936 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
937 int32_t parentWindowId = INVALID_SESSION_ID;
938 sceneSession01->parentSession_ = session04;
939 sceneSession02->parentSession_ = session05;
940 session05->persistentId_ = 5;
941 std::vector<sptr<SceneSession>> subSessions = ssm_->GetSubSceneSession(parentWindowId);
942 EXPECT_EQ(subSessions.size(), 1);
943 }
944
945 /**
946 * @tc.name: RemoveDuplicateSubSession
947 * @tc.desc: RemoveDuplicateSubSession
948 * @tc.type: FUNC
949 */
950 HWTEST_F(SceneSessionManagerTest4, RemoveDuplicateSubSession, Function | SmallTest | Level3)
951 {
952 ASSERT_NE(nullptr, ssm_);
953 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfo;
954 std::vector<sptr<SceneSession>> subSessions;
955 visibilityChangeInfo.push_back(std::make_pair(0, WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
956 visibilityChangeInfo.push_back(std::make_pair(1, WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
957
958 SessionInfo info;
959 info.abilityName_ = "SetBrightness";
960 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
961 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
962 sptr<SceneSession> sceneSession03 = nullptr;
963 ASSERT_NE(sceneSession01, nullptr);
964 ASSERT_NE(sceneSession02, nullptr);
965 struct RSSurfaceNodeConfig config;
966 sceneSession01->surfaceNode_ = RSSurfaceNode::Create(config);
967 ASSERT_NE(sceneSession01->surfaceNode_, nullptr);
968 sceneSession01->surfaceNode_->id_ = 0;
969
970 ssm_->sceneSessionMap_.insert(std::make_pair(0, nullptr));
971 ssm_->RemoveDuplicateSubSession(visibilityChangeInfo, subSessions);
972
973 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
974 sceneSession02->persistentId_ = 2;
975 subSessions.push_back(sceneSession01);
976 subSessions.push_back(sceneSession02);
977 subSessions.push_back(sceneSession03);
978 ssm_->RemoveDuplicateSubSession(visibilityChangeInfo, subSessions);
979 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
980 }
981
982 /**
983 * @tc.name: UpdateSubWindowVisibility
984 * @tc.desc: UpdateSubWindowVisibility
985 * @tc.type: FUNC
986 */
987 HWTEST_F(SceneSessionManagerTest4, UpdateSubWindowVisibility, Function | SmallTest | Level3)
988 {
989 ASSERT_NE(nullptr, ssm_);
990 SessionInfo info;
991 info.abilityName_ = "SetBrightness";
992 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
993 ASSERT_NE(sceneSession, nullptr);
994 WindowVisibilityState visibleState = WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION;
995 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfo;
996 std::vector<sptr<WindowVisibilityInfo>> windowVisibilityInfos;
997 std::string visibilityInfo = "";
998 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
999 ssm_->UpdateSubWindowVisibility(sceneSession, visibleState, visibilityChangeInfo,
1000 windowVisibilityInfos, visibilityInfo, currVisibleData);
1001
1002 ASSERT_NE(sceneSession->property_, nullptr);
1003 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
1004 ssm_->UpdateSubWindowVisibility(sceneSession, visibleState, visibilityChangeInfo,
1005 windowVisibilityInfos, visibilityInfo, currVisibleData);
1006
1007 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1008 visibleState = WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION;
1009 ssm_->sceneSessionMap_.insert(std::make_pair(0, nullptr));
1010 ssm_->UpdateSubWindowVisibility(sceneSession, visibleState, visibilityChangeInfo,
1011 windowVisibilityInfos, visibilityInfo, currVisibleData);
1012
1013 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
1014 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
1015 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(info, nullptr);
1016 sptr<Session> session03 = sptr<Session>::MakeSptr(info);
1017 ASSERT_NE(sceneSession01, nullptr);
1018 ASSERT_NE(sceneSession02, nullptr);
1019 ASSERT_NE(sceneSession03, nullptr);
1020 ASSERT_NE(session03, nullptr);
1021 sceneSession01->SetParentSession(session03);
1022 sceneSession02->SetParentSession(session03);
1023 sceneSession03->SetParentSession(session03);
1024 sceneSession02->SetCallingPid(2);
1025 sceneSession03->SetCallingPid(3);
1026 sceneSession03->state_ = SessionState::STATE_FOREGROUND;
1027 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
1028 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
1029 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
1030 ssm_->UpdateSubWindowVisibility(sceneSession, visibleState, visibilityChangeInfo,
1031 windowVisibilityInfos, visibilityInfo, currVisibleData);
1032 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr));
1033 }
1034
1035 /**
1036 * @tc.name: SelectSesssionFromMap
1037 * @tc.desc: SelectSesssionFromMap
1038 * @tc.type: FUNC
1039 */
1040 HWTEST_F(SceneSessionManagerTest4, SelectSesssionFromMap, Function | SmallTest | Level3)
1041 {
1042 ASSERT_NE(nullptr, ssm_);
1043 uint64_t surfaceId = 6;
1044 uint64_t surfaceId02 = 7;
1045 SessionInfo info;
1046 info.abilityName_ = "SetBrightness";
1047 sptr<SceneSession> sceneSession;
1048 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
1049 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
1050 ASSERT_NE(sceneSession01, nullptr);
1051 ASSERT_NE(sceneSession02, nullptr);
1052 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession));
1053 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
1054 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
1055 sceneSession01->surfaceNode_ = nullptr;
1056 struct RSSurfaceNodeConfig config;
1057 sceneSession02->surfaceNode_ = RSSurfaceNode::Create(config);
1058 ASSERT_NE(sceneSession02->surfaceNode_, nullptr);
1059 NodeId id = 6;
1060 sceneSession02->surfaceNode_->SetId(id);
1061 EXPECT_EQ(sceneSession02->surfaceNode_->id_, 6);
1062
1063 sptr<SceneSession> result = ssm_->SelectSesssionFromMap(surfaceId);
1064 EXPECT_EQ(result, sceneSession02);
1065 result = ssm_->SelectSesssionFromMap(surfaceId02);
1066 EXPECT_EQ(result, nullptr);
1067 }
1068
1069 /**
1070 * @tc.name: GetAccessibilityWindowInfo
1071 * @tc.desc: GetAccessibilityWindowInfo
1072 * @tc.type: FUNC
1073 */
1074 HWTEST_F(SceneSessionManagerTest4, GetAccessibilityWindowInfo, Function | SmallTest | Level3)
1075 {
1076 ASSERT_NE(nullptr, ssm_);
1077 SessionInfo info;
1078 info.abilityName_ = "SetBrightness";
1079 sptr<SceneSession> sceneSession;
1080 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
1081 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
1082 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(info, nullptr);
1083 sptr<SceneSession> sceneSession04 = sptr<SceneSession>::MakeSptr(info, nullptr);
1084 ASSERT_NE(sceneSession01, nullptr);
1085 ASSERT_NE(sceneSession02, nullptr);
1086 ASSERT_NE(sceneSession03, nullptr);
1087 ASSERT_NE(sceneSession04, nullptr);
1088 sceneSession01->SetForceTouchable(true);
1089 sceneSession01->isVisible_ = true;
1090 ASSERT_NE(sceneSession01->property_, nullptr);
1091 sceneSession01->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1092 sceneSession01->property_->SetParentPersistentId(4);
1093 sceneSession02->SetForceTouchable(false);
1094 sceneSession03->SetForceTouchable(true);
1095 sceneSession03->isVisible_ = true;
1096 ASSERT_NE(sceneSession03->property_, nullptr);
1097 sceneSession03->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1098 sceneSession03->property_->SetParentPersistentId(6);
1099 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession));
1100 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
1101 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
1102 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
1103 ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession04));
1104 std::vector<sptr<AccessibilityWindowInfo>> accessibilityInfo;
1105 auto result = ssm_->GetAccessibilityWindowInfo(accessibilityInfo);
1106 EXPECT_EQ(result, WMError::WM_OK);
1107 }
1108
1109 /**
1110 * @tc.name: ShiftAppWindowFocus02
1111 * @tc.desc: ShiftAppWindowFocus
1112 * @tc.type: FUNC
1113 */
1114 HWTEST_F(SceneSessionManagerTest4, ShiftAppWindowFocus02, Function | SmallTest | Level3)
1115 {
1116 ASSERT_NE(ssm_, nullptr);
1117 ssm_->SetFocusedSessionId(INVALID_SESSION_ID);
1118 int32_t sourcePersistentId = INVALID_SESSION_ID;
1119 int32_t targetPersistentId = INVALID_SESSION_ID;
1120 auto result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1121 EXPECT_EQ(result, WSError::WS_DO_NOTHING);
1122
1123 targetPersistentId = 1;
1124 result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1125 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1126
1127 SessionInfo info;
1128 info.abilityName_ = "abilityName";
1129 info.bundleName_ = "bundleName";
1130 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1131 ASSERT_NE(sceneSession, nullptr);
1132 ssm_->sceneSessionMap_.insert(std::make_pair(INVALID_SESSION_ID, sceneSession));
1133 ASSERT_NE(sceneSession->property_, nullptr);
1134 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1135 result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1136 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1137
1138 SessionInfo info01;
1139 info01.abilityName_ = "abilityName01";
1140 info01.bundleName_ = "bundleName01";
1141 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info01, nullptr);
1142 ASSERT_NE(sceneSession01, nullptr);
1143 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
1144 ASSERT_NE(sceneSession01->property_, nullptr);
1145 sceneSession01->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1146 result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1147 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_CALLING);
1148 }
1149
1150 /**
1151 * @tc.name: UpdateTitleInTargetPos
1152 * @tc.desc: UpdateTitleInTargetPos
1153 * @tc.type: FUNC
1154 */
1155 HWTEST_F(SceneSessionManagerTest4, UpdateTitleInTargetPos, Function | SmallTest | Level3)
1156 {
1157 ASSERT_NE(ssm_, nullptr);
1158 SessionInfo info;
1159 info.abilityName_ = "abilityName";
1160 info.bundleName_ = "bundleName";
1161 info.isSystem_ = true;
1162 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1163 ASSERT_NE(sceneSession, nullptr);
1164 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession));
1165 auto result = ssm_->UpdateTitleInTargetPos(1, true, 1);
1166 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_WINDOW);
1167
1168 result = ssm_->UpdateTitleInTargetPos(0, true, 1);
1169 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1170 }
1171
1172 /**
1173 * @tc.name: GetIsLayoutFullScreen
1174 * @tc.desc: GetIsLayoutFullScreen
1175 * @tc.type: FUNC
1176 */
1177 HWTEST_F(SceneSessionManagerTest4, GetIsLayoutFullScreen, Function | SmallTest | Level3)
1178 {
1179 ASSERT_NE(ssm_, nullptr);
1180 SessionInfo info;
1181 info.abilityName_ = "abilityName";
1182 info.bundleName_ = "bundleName";
1183 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(info, nullptr);
1184 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(info, nullptr);
1185 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(info, nullptr);
1186 sptr<SceneSession> sceneSession04 = sptr<SceneSession>::MakeSptr(info, nullptr);
1187 ASSERT_NE(sceneSession01, nullptr);
1188 ASSERT_NE(sceneSession02, nullptr);
1189 ASSERT_NE(sceneSession03, nullptr);
1190 ASSERT_NE(sceneSession04, nullptr);
1191 ASSERT_NE(sceneSession01->property_, nullptr);
1192 sceneSession01->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
1193
1194 ASSERT_NE(sceneSession02->property_, nullptr);
1195 sceneSession02->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1196 sceneSession02->SetSessionState(SessionState::STATE_DISCONNECT);
1197
1198 ASSERT_NE(sceneSession03->property_, nullptr);
1199 sceneSession03->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1200 sceneSession03->SetSessionState(SessionState::STATE_ACTIVE);
1201 sceneSession03->property_->SetWindowMode(WindowMode::WINDOW_MODE_UNDEFINED);
1202
1203 ASSERT_NE(sceneSession04->property_, nullptr);
1204 sceneSession04->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1205 sceneSession04->SetSessionState(SessionState::STATE_FOREGROUND);
1206 sceneSession04->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1207 sceneSession04->property_->SetIsLayoutFullScreen(true);
1208
1209 ASSERT_NE(sceneSession04->property_, nullptr);
1210 sceneSession04->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1211 sceneSession04->SetSessionState(SessionState::STATE_FOREGROUND);
1212 sceneSession04->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1213 sceneSession04->property_->SetIsLayoutFullScreen(false);
1214
1215 ssm_->sceneSessionMap_.insert(std::make_pair(0, nullptr));
1216 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
1217 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
1218 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
1219 bool isLayoutFullScreen = true;
1220 auto result = ssm_->GetIsLayoutFullScreen(isLayoutFullScreen);
1221 EXPECT_EQ(result, WSError::WS_OK);
1222 }
1223
1224 HWTEST_F(SceneSessionManagerTest4, UpdateExtWindowFlags, Function | SmallTest | Level3)
1225 {
1226 ASSERT_NE(ssm_, nullptr);
1227 uint32_t extWindowFlags = 0;
1228 uint32_t extWindowActions = 0;
1229 auto ret = ssm_->UpdateExtWindowFlags(nullptr, extWindowFlags, extWindowActions);
1230 EXPECT_EQ(ret, WSError::WS_OK);
1231 }
1232
1233 /**
1234 * @tc.name: AddOrRemoveSecureSession02
1235 * @tc.desc: AddOrRemoveSecureSession
1236 * @tc.type: FUNC
1237 */
1238 HWTEST_F(SceneSessionManagerTest4, AddOrRemoveSecureSession02, Function | SmallTest | Level3)
1239 {
1240 ASSERT_NE(ssm_, nullptr);
1241 int32_t persistentId = 1;
1242 bool shouldHide = true;
1243 SessionInfo info;
1244 info.abilityName_ = "secureSession";
1245 info.bundleName_ = "secureSession";
1246 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1247 ASSERT_NE(sceneSession, nullptr);
1248 ssm_->sceneSessionMap_.insert(std::make_pair(0, nullptr));
1249 ssm_->sceneSessionMap_.insert(std::make_pair(persistentId, sceneSession));
1250 auto result = ssm_->AddOrRemoveSecureSession(0, shouldHide);
1251 EXPECT_EQ(result, WSError::WS_OK);
1252 result = ssm_->AddOrRemoveSecureSession(persistentId, shouldHide);
1253 EXPECT_EQ(result, WSError::WS_OK);
1254 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
1255 usleep(WAIT_SYNC_IN_NS);
1256 }
1257
1258 /**
1259 * @tc.name: GetSessionSnapshotPixelMap
1260 * @tc.desc: GetSessionSnapshotPixelMap
1261 * @tc.type: FUNC
1262 */
1263 HWTEST_F(SceneSessionManagerTest4, GetSessionSnapshotPixelMap, Function | SmallTest | Level3)
1264 {
1265 ASSERT_NE(ssm_, nullptr);
1266 SessionInfo info;
1267 info.abilityName_ = "GetPixelMap";
1268 info.bundleName_ = "GetPixelMap1";
1269 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1270 ASSERT_NE(sceneSession, nullptr);
1271 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
1272 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1273 int32_t persistentId = 1;
1274 float scaleParam = 0.5f;
1275 auto result = ssm_->GetSessionSnapshotPixelMap(persistentId, scaleParam);
1276 EXPECT_EQ(result, nullptr);
1277
1278 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
1279 std::string bundleName = "testBundleName";
1280 int32_t testpersistentId = 1;
1281 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, testpersistentId);
1282 ASSERT_NE(sceneSession->scenePersistence_, nullptr);
1283 struct RSSurfaceNodeConfig config;
1284 sceneSession->surfaceNode_ = RSSurfaceNode::Create(config);
1285 ASSERT_NE(sceneSession->surfaceNode_, nullptr);
1286 sceneSession->bufferAvailable_ = true;
1287 result = ssm_->GetSessionSnapshotPixelMap(persistentId, scaleParam);
1288 EXPECT_EQ(result, nullptr);
1289 }
1290
1291 /**
1292 * @tc.name: GetStartupPageFromResource
1293 * @tc.desc: GetStartupPageFromResource
1294 * @tc.type: FUNC
1295 */
1296 HWTEST_F(SceneSessionManagerTest4, GetStartupPageFromResource, Function | SmallTest | Level3)
1297 {
1298 ASSERT_NE(ssm_, nullptr);
1299 AppExecFwk::AbilityInfo abilityInfo;
1300 EXPECT_EQ(ssm_->GetResourceManager(abilityInfo), nullptr);
1301 std::string path = "testPath";
1302 uint32_t bgColor = 0;
1303 bool result = ssm_->GetStartupPageFromResource(abilityInfo, path, bgColor);
1304 EXPECT_EQ(result, false);
1305 }
1306
1307 /**
1308 * @tc.name: GetStartupPage
1309 * @tc.desc: GetStartupPage
1310 * @tc.type: FUNC
1311 */
1312 HWTEST_F(SceneSessionManagerTest4, GetStartupPage, Function | SmallTest | Level3)
1313 {
1314 ASSERT_NE(ssm_, nullptr);
1315 SessionInfo sessionInfo;
1316 sessionInfo.moduleName_ = "moduleName";
1317 sessionInfo.abilityName_ = "abilityName";
1318 sessionInfo.bundleName_ = "bundleName";
1319 std::string path = "testPath";
1320 uint32_t bgColor = 0;
1321 bool result = ssm_->GetStartingWindowInfoFromCache(sessionInfo, path, bgColor);
1322 EXPECT_EQ(result, false);
1323
1324 std::map<std::string, StartingWindowInfo> startingWindowInfoMap;
1325 StartingWindowInfo startingWindowInfo;
1326 auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_;
1327 startingWindowInfoMap.insert(std::make_pair(key, startingWindowInfo));
1328 ssm_->startingWindowMap_.insert({sessionInfo.bundleName_, startingWindowInfoMap});
1329 result = ssm_->GetStartingWindowInfoFromCache(sessionInfo, path, bgColor);
1330 ssm_->GetStartupPage(sessionInfo, path, bgColor);
1331 EXPECT_EQ(result, true);
1332 }
1333
1334 /**
1335 * @tc.name: HandleHideNonSystemFloatingWindows
1336 * @tc.desc: HandleHideNonSystemFloatingWindows
1337 * @tc.type: FUNC
1338 */
1339 HWTEST_F(SceneSessionManagerTest4, HandleHideNonSystemFloatingWindows, Function | SmallTest | Level3)
1340 {
1341 ASSERT_NE(ssm_, nullptr);
1342 SessionInfo info;
1343 info.abilityName_ = "abilityName";
1344 info.bundleName_ = "bundleName";
1345 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1346 ASSERT_NE(property, nullptr);
1347 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1348 ASSERT_NE(sceneSession, nullptr);
1349
1350 sceneSession->property_->hideNonSystemFloatingWindows_ = true;
1351 property->SetHideNonSystemFloatingWindows(false);
1352 sceneSession->isVisible_ = true;
1353 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1354 ssm_->HandleHideNonSystemFloatingWindows(property, sceneSession);
1355
1356 sceneSession->property_->hideNonSystemFloatingWindows_ = false;
1357 property->SetHideNonSystemFloatingWindows(true);
1358 ssm_->HandleHideNonSystemFloatingWindows(property, sceneSession);
1359
1360 sceneSession->isVisible_ = false;
1361 ssm_->HandleHideNonSystemFloatingWindows(property, sceneSession);
1362 EXPECT_EQ(Session::IsScbCoreEnabled(), true);
1363 }
1364
1365 /**
1366 * @tc.name: GetAllClearableSessions
1367 * @tc.desc: GetAllClearableSessions
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(SceneSessionManagerTest4, GetAllClearableSessions, Function | SmallTest | Level3)
1371 {
1372 SessionInfo sessionInfo;
1373 sessionInfo.bundleName_ = "bundleName";
1374 sessionInfo.abilityName_ = "abilityName";
1375 sessionInfo.abilityInfo = nullptr;
1376 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1377 ASSERT_NE(nullptr, ssm_);
1378 ASSERT_NE(nullptr, sceneSession);
1379 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
1380 SessionInfo sessionInfo1;
1381 sessionInfo1.bundleName_ = "bundleName";
1382 sessionInfo1.abilityName_ = "abilityName";
1383 sessionInfo1.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1384 ASSERT_NE(nullptr, sessionInfo1.abilityInfo);
1385 sessionInfo1.abilityInfo->excludeFromMissions = false;
1386 sessionInfo1.abilityInfo->unclearableMission = false;
1387 sessionInfo1.isSystem_ = false;
1388 sessionInfo1.lockedState = false;
1389 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1390 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession1));
1391 std::vector<sptr<SceneSession>> sessionVector;
1392 sessionVector.clear();
1393 ssm_->GetAllClearableSessions(sessionVector);
1394 EXPECT_FALSE(sessionVector.empty());
1395 }
1396
1397 /**
1398 * @tc.name: UpdateBrightness
1399 * @tc.desc: UpdateBrightness
1400 * @tc.type: FUNC
1401 */
1402 HWTEST_F(SceneSessionManagerTest4, UpdateBrightness, Function | SmallTest | Level3)
1403 {
1404 ASSERT_NE(ssm_, nullptr);
1405 SessionInfo sessionInfo;
1406 sessionInfo.isSystem_ = false;
1407 sessionInfo.bundleName_ = "bundleName";
1408 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1409 ASSERT_NE(sceneSession, nullptr);
1410 ASSERT_NE(sceneSession->property_, nullptr);
1411 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
1412 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1413 WSError result = ssm_->UpdateBrightness(1);
1414 EXPECT_EQ(result, WSError::WS_DO_NOTHING);
1415
1416 SessionInfo sessionInfo02;
1417 sessionInfo02.isSystem_ = true;
1418 sessionInfo02.bundleName_ = "bundleName";
1419 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(sessionInfo02, nullptr);
1420 ASSERT_NE(sceneSession02, nullptr);
1421 ASSERT_NE(sceneSession02->property_, nullptr);
1422 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
1423 sceneSession02->property_->SetBrightness(50.f);
1424 ssm_->SetDisplayBrightness(40.f);
1425 result = ssm_->UpdateBrightness(2);
1426 EXPECT_EQ(ssm_->displayBrightness_, 50);
1427 EXPECT_EQ(result, WSError::WS_OK);
1428 }
1429
1430 /**
1431 * @tc.name: RegisterSessionExceptionFunc
1432 * @tc.desc: RegisterSessionExceptionFunc
1433 * @tc.type: FUNC
1434 */
1435 HWTEST_F(SceneSessionManagerTest4, RegisterSessionExceptionFunc, Function | SmallTest | Level3)
1436 {
1437 ASSERT_NE(ssm_, nullptr);
1438 SessionInfo sessionInfo;
1439 sessionInfo.bundleName_ = "bundleName";
1440 sessionInfo.persistentId_ = 1;
1441 sessionInfo.isSystem_ = true;
1442 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1443 ASSERT_NE(sceneSession, nullptr);
1444 ssm_->sceneSessionMap_.insert(std::make_pair(sessionInfo.persistentId_, sceneSession));
1445 std::shared_ptr<SessionListenerController> listenerController =
1446 std::make_shared<SessionListenerController>();
1447 ssm_->listenerController_ = listenerController;
1448 ASSERT_NE(ssm_->listenerController_, nullptr);
1449 ssm_->RegisterSessionExceptionFunc(sceneSession);
1450
1451 sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
1452 ASSERT_NE(abilitySessionInfo, nullptr);
1453 WSError result = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, false, false);
1454 EXPECT_EQ(result, WSError::WS_OK);
1455
1456 abilitySessionInfo->errorCode = 1;
1457 result = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, false, false);
1458 EXPECT_EQ(result, WSError::WS_OK);
1459
1460 abilitySessionInfo->errorCode = 0;
1461 result = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, false, false);
1462 EXPECT_EQ(result, WSError::WS_OK);
1463
1464 sessionInfo.isSystem_ = false;
1465 result = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, false, false);
1466 EXPECT_EQ(result, WSError::WS_OK);
1467
1468 ssm_->listenerController_ = nullptr;
1469 result = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, false, false);
1470 EXPECT_EQ(result, WSError::WS_OK);
1471
1472 sessionInfo.persistentId_ = 2;
1473 result = sceneSession->NotifySessionExceptionInner(abilitySessionInfo, false, false);
1474 EXPECT_EQ(result, WSError::WS_OK);
1475 usleep(WAIT_SYNC_IN_NS);
1476 }
1477
1478 /**
1479 * @tc.name: RegisterSessionSnapshotFunc
1480 * @tc.desc: RegisterSessionSnapshotFunc
1481 * @tc.type: FUNC
1482 */
1483 HWTEST_F(SceneSessionManagerTest4, RegisterSessionSnapshotFunc, Function | SmallTest | Level3)
1484 {
1485 ASSERT_NE(ssm_, nullptr);
1486 SessionInfo sessionInfo;
1487 sessionInfo.bundleName_ = "bundleName";
1488 sessionInfo.persistentId_ = 1;
1489 sessionInfo.isSystem_ = false;
1490 sessionInfo.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
1491 ASSERT_NE(sessionInfo.abilityInfo, nullptr);
1492 sessionInfo.abilityInfo->excludeFromMissions = true;
1493 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1494 ASSERT_NE(sceneSession, nullptr);
1495 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("bundleName", 1);
1496 ASSERT_NE(sceneSession->scenePersistence_, nullptr);
1497 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
1498 sceneSession->surfaceNode_ = std::make_shared<RSSurfaceNode>(rsSurfaceNodeConfig, true, 0);
1499 ASSERT_NE(sceneSession->surfaceNode_, nullptr);
1500 sceneSession->surfaceNode_->bufferAvailable_ = true;
1501 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1502 ssm_->listenerController_ = std::make_shared<SessionListenerController>();
1503 ASSERT_NE(ssm_->listenerController_, nullptr);
1504 ssm_->RegisterSessionSnapshotFunc(sceneSession);
1505 EXPECT_EQ(sceneSession->Snapshot(1.f), nullptr);
1506
1507 sessionInfo.abilityInfo->excludeFromMissions = false;
1508 EXPECT_EQ(sceneSession->Snapshot(1.f), nullptr);
1509
1510 ssm_->listenerController_ = nullptr;
1511 EXPECT_EQ(sceneSession->Snapshot(1.f), nullptr);
1512
1513 sessionInfo.abilityInfo = nullptr;
1514 EXPECT_EQ(sceneSession->Snapshot(1.f), nullptr);
1515
1516 sessionInfo.isSystem_ = true;
1517 EXPECT_EQ(sceneSession->Snapshot(1.f), nullptr);
1518
1519 sessionInfo.persistentId_ = 2;
1520 EXPECT_EQ(sceneSession->Snapshot(1.f), nullptr);
1521 usleep(WAIT_SYNC_IN_NS);
1522 }
1523
1524 /**
1525 * @tc.name: GetSessionDumpInfo
1526 * @tc.desc: GetSessionDumpInfo
1527 * @tc.type: FUNC
1528 */
1529 HWTEST_F(SceneSessionManagerTest4, GetSessionDumpInfo, Function | SmallTest | Level3)
1530 {
1531 ASSERT_NE(ssm_, nullptr);
1532 std::string dumpInfo = "testDumpInfo";
1533 std::vector<std::string> params = {"testDumpInfo"};
1534 WSError result = ssm_->GetSessionDumpInfo(params, dumpInfo);
1535 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_OPERATION);
1536
1537 params.clear();
1538 params.push_back("-w");
1539 params.push_back("a");
1540 result = ssm_->GetSessionDumpInfo(params, dumpInfo);
1541 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_OPERATION);
1542
1543 params.clear();
1544 params.push_back("-b");
1545 params.push_back("a");
1546 result = ssm_->GetSessionDumpInfo(params, dumpInfo);
1547 EXPECT_EQ(result, WSError::WS_OK);
1548
1549 params.clear();
1550 params.push_back("-p");
1551 params.push_back("1");
1552 result = ssm_->GetSessionDumpInfo(params, dumpInfo);
1553 EXPECT_EQ(result, WSError::WS_OK);
1554
1555 params.clear();
1556 params.push_back("-b");
1557 params.push_back("a");
1558 result = ssm_->GetSessionDumpInfo(params, dumpInfo);
1559 EXPECT_EQ(result, WSError::WS_OK);
1560
1561 params.clear();
1562 params.push_back("testDumpInfo");
1563 params.push_back("a");
1564 result = ssm_->GetSessionDumpInfo(params, dumpInfo);
1565 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_OPERATION);
1566 }
1567
1568 /**
1569 * @tc.name: CheckParentSessionVisible
1570 * @tc.desc: CheckParentSessionVisible
1571 * @tc.type: FUNC
1572 */
1573 HWTEST_F(SceneSessionManagerTest4, CheckParentSessionVisible, Function | SmallTest | Level3)
1574 {
1575 ASSERT_NE(ssm_, nullptr);
1576 SessionInfo sessionInfo;
1577 sessionInfo.bundleName_ = "bundleName";
1578 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1579 ASSERT_NE(sceneSession, nullptr);
1580 ASSERT_NE(sceneSession->property_, nullptr);
1581 sceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1582 sceneSession->property_->SetParentPersistentId(1);
1583 sceneSession->isVisible_ = false;
1584 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1585 bool result = ssm_->CheckParentSessionVisible(sceneSession);
1586 EXPECT_EQ(result, false);
1587
1588 bool testRet = sceneSession->IsScbCoreEnabled();
1589 EXPECT_EQ(testRet, true);
1590
1591 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1592 sceneSession->isVisible_ = true;
1593 result = ssm_->CheckParentSessionVisible(sceneSession);
1594 EXPECT_EQ(result, true);
1595
1596 sceneSession->property_->SetParentPersistentId(2);
1597 result = ssm_->CheckParentSessionVisible(sceneSession);
1598 EXPECT_EQ(result, true);
1599
1600 sceneSession->property_->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1601 result = ssm_->CheckParentSessionVisible(sceneSession);
1602 EXPECT_EQ(result, true);
1603 }
1604
1605 /**
1606 * @tc.name: GetTopFocusableNonAppSession
1607 * @tc.desc: GetTopFocusableNonAppSession
1608 * @tc.type: FUNC
1609 */
1610 HWTEST_F(SceneSessionManagerTest4, GetTopFocusableNonAppSession, Function | SmallTest | Level3)
1611 {
1612 ASSERT_NE(ssm_, nullptr);
1613 SessionInfo sessionInfo;
1614 sessionInfo.bundleName_ = "bundleName";
1615 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1616 ASSERT_NE(sceneSession, nullptr);
1617 ASSERT_NE(sceneSession->property_, nullptr);
1618
1619 sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
1620 sceneSession->property_->SetFocusable(true);
1621 sceneSession->isVisible_ = true;
1622 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1623 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1624 sptr<SceneSession> result = ssm_->GetTopFocusableNonAppSession();
1625 EXPECT_EQ(result, sceneSession);
1626
1627 sceneSession->isVisible_ = false;
1628 result = ssm_->GetTopFocusableNonAppSession();
1629 EXPECT_EQ(result, nullptr);
1630
1631 sceneSession->property_->SetFocusable(false);
1632 result = ssm_->GetTopFocusableNonAppSession();
1633 EXPECT_EQ(result, nullptr);
1634
1635 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1636 result = ssm_->GetTopFocusableNonAppSession();
1637 EXPECT_EQ(result, nullptr);
1638 }
1639
1640 /**
1641 * @tc.name: GetNextFocusableSession
1642 * @tc.desc: GetNextFocusableSession
1643 * @tc.type: FUNC
1644 */
1645 HWTEST_F(SceneSessionManagerTest4, GetNextFocusableSession, Function | SmallTest | Level3)
1646 {
1647 ASSERT_NE(ssm_, nullptr);
1648 SessionInfo sessionInfo;
1649 sessionInfo.bundleName_ = "bundleName";
1650 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1651 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1652 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1653 sptr<SceneSession> sceneSession04 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1654 sptr<SceneSession> sceneSession05 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1655 ASSERT_NE(sceneSession, nullptr);
1656 ASSERT_NE(sceneSession02, nullptr);
1657 ASSERT_NE(sceneSession03, nullptr);
1658 ASSERT_NE(sceneSession04, nullptr);
1659 ASSERT_NE(sceneSession05, nullptr);
1660 ASSERT_NE(sceneSession->property_, nullptr);
1661
1662 sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
1663 sceneSession->property_->SetFocusable(true);
1664 sceneSession->property_->SetWindowType(WindowType::SYSTEM_WINDOW_BASE);
1665 sceneSession->isVisible_ = true;
1666 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1667 sceneSession->SetZOrder(1);
1668
1669 sceneSession02->SetFocusable(false);
1670 sceneSession02->SetZOrder(2);
1671
1672 sceneSession03->SetZOrder(3);
1673
1674 sceneSession04->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
1675 sceneSession04->SetZOrder(4);
1676
1677 sceneSession05->persistentId_ = 1;
1678 sceneSession05->SetZOrder(5);
1679
1680 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1681 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
1682 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
1683 ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession04));
1684 ssm_->sceneSessionMap_.insert(std::make_pair(5, sceneSession05));
1685 sptr<SceneSession> result = ssm_->GetNextFocusableSession(1);
1686 EXPECT_EQ(result, sceneSession);
1687 }
1688
1689 /**
1690 * @tc.name: GetTopNearestBlockingFocusSession
1691 * @tc.desc: GetTopNearestBlockingFocusSession
1692 * @tc.type: FUNC
1693 */
1694 HWTEST_F(SceneSessionManagerTest4, GetTopNearestBlockingFocusSession, Function | SmallTest | Level3)
1695 {
1696 ASSERT_NE(ssm_, nullptr);
1697 SessionInfo sessionInfo;
1698 sessionInfo.bundleName_ = "bundleName";
1699 sessionInfo.isSystem_ = true;
1700 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1701 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1702 sptr<SceneSession> sceneSession03 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1703 sptr<SceneSession> sceneSession04 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1704 sptr<SceneSession> parentSceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1705 ASSERT_NE(sceneSession01, nullptr);
1706 ASSERT_NE(sceneSession02, nullptr);
1707 ASSERT_NE(sceneSession03, nullptr);
1708 ASSERT_NE(sceneSession04, nullptr);
1709 ASSERT_NE(parentSceneSession, nullptr);
1710
1711 sceneSession01->SetZOrder(1);
1712 sceneSession01->isVisible_ = true;
1713 sceneSession01->SetSessionState(SessionState::STATE_FOREGROUND);
1714
1715 sceneSession02->SetZOrder(2);
1716 sceneSession02->isVisible_ = true;
1717 sceneSession02->SetSessionState(SessionState::STATE_FOREGROUND);
1718 sceneSession02->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1719 sceneSession02->blockingFocus_ = false;
1720
1721 sceneSession03->SetZOrder(3);
1722 sceneSession03->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1723 parentSceneSession->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1724 sceneSession03->property_->SetParentPersistentId(8);
1725
1726 sceneSession04->SetZOrder(4);
1727 sceneSession04->property_->SetParentPersistentId(1);
1728
1729 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01));
1730 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession02));
1731 ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03));
1732 ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession04));
1733 ssm_->sceneSessionMap_.insert(std::make_pair(8, parentSceneSession));
1734
1735 sptr<SceneSession> ret = ssm_->GetTopNearestBlockingFocusSession(0, true);
1736 EXPECT_EQ(ret, sceneSession01);
1737
1738 ret = ssm_->GetTopNearestBlockingFocusSession(10, true);
1739 EXPECT_EQ(ret, nullptr);
1740 }
1741
1742 /**
1743 * @tc.name: RequestFocusSpecificCheck
1744 * @tc.desc: RequestFocusSpecificCheck
1745 * @tc.type: FUNC
1746 */
1747 HWTEST_F(SceneSessionManagerTest4, RequestFocusSpecificCheck, Function | SmallTest | Level3)
1748 {
1749 ASSERT_NE(ssm_, nullptr);
1750 SessionInfo sessionInfo;
1751 sessionInfo.bundleName_ = "bundleName";
1752 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1753 ASSERT_NE(sceneSession, nullptr);
1754 bool byForeground = true;
1755 FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST;
1756 sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
1757 WSError result = ssm_->RequestFocusSpecificCheck(sceneSession, byForeground, reason);
1758 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_OPERATION);
1759
1760 sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
1761 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1762 ASSERT_NE(sceneSession01, nullptr);
1763 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession01));
1764 sceneSession01->parentSession_ = sceneSession;
1765 result = ssm_->RequestFocusSpecificCheck(sceneSession, byForeground, reason);
1766 EXPECT_EQ(result, WSError::WS_OK);
1767 }
1768
1769 /**
1770 * @tc.name: ProcessModalExtensionPointDown
1771 * @tc.desc: ProcessModalExtensionPointDown
1772 * @tc.type: FUNC
1773 */
1774 HWTEST_F(SceneSessionManagerTest4, ProcessModalExtensionPointDown, Function | SmallTest | Level3)
1775 {
1776 ASSERT_NE(ssm_, nullptr);
1777 sptr<IRemoteObject> token = sptr<IRemoteObjectMocker>::MakeSptr();
1778 ASSERT_NE(token, nullptr);
1779 int32_t posX = 1;
1780 int32_t posY = 1;
1781 ExtensionWindowAbilityInfo extensionWindowAbilityInfo;
1782 extensionWindowAbilityInfo.persistentId = 1;
1783 extensionWindowAbilityInfo.parentId = 2;
1784 ssm_->extSessionInfoMap_.insert(std::make_pair(token, extensionWindowAbilityInfo));
1785
1786 SessionInfo sessionInfo;
1787 sessionInfo.bundleName_ = "bundleName";
1788 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1789 ASSERT_NE(sceneSession, nullptr);
1790 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
1791 ssm_->ProcessModalExtensionPointDown(token, posX, posY);
1792
1793 ExtensionWindowEventInfo eventInfo;
1794 eventInfo.pid = 0;
1795 eventInfo.persistentId = 1;
1796 sceneSession->modalUIExtensionInfoList_.push_back(eventInfo);
1797 ssm_->ProcessModalExtensionPointDown(token, posX, posY);
1798
1799 eventInfo.persistentId = 4;
1800 ssm_->ProcessModalExtensionPointDown(token, posX, posY);
1801
1802 eventInfo.pid = 4;
1803 ssm_->ProcessModalExtensionPointDown(token, posX, posY);
1804
1805 sceneSession->modalUIExtensionInfoList_.clear();
1806 ssm_->ProcessModalExtensionPointDown(token, posX, posY);
1807 bool result = true;
1808 EXPECT_EQ(WSError::WS_OK, ssm_->GetFreeMultiWindowEnableState(result));
1809 usleep(WAIT_SYNC_IN_NS);
1810 }
1811 }
1812 } // namespace Rosen
1813 } // namespace OHOS
1814