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
18 #include "iremote_object_mocker.h"
19 #include "interfaces/include/ws_common.h"
20 #include "session_manager/include/scene_session_manager.h"
21 #include "session_info.h"
22 #include "session/host/include/scene_session.h"
23 #include "session_manager.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30
31 class SceneSessionManagerTest8 : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp();
36 void TearDown();
37 private:
38 sptr<SceneSessionManager> ssm_;
39 static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
40 };
41
SetUpTestCase()42 void SceneSessionManagerTest8::SetUpTestCase()
43 {
44 }
45
TearDownTestCase()46 void SceneSessionManagerTest8::TearDownTestCase()
47 {
48 }
49
SetUp()50 void SceneSessionManagerTest8::SetUp()
51 {
52 ssm_ = sptr<SceneSessionManager>::MakeSptr();
53 EXPECT_NE(nullptr, ssm_);
54 ssm_->sceneSessionMap_.clear();
55 }
56
TearDown()57 void SceneSessionManagerTest8::TearDown()
58 {
59 ssm_->sceneSessionMap_.clear();
60 usleep(WAIT_SYNC_IN_NS);
61 ssm_ = nullptr;
62 }
63
64 namespace {
65 /**
66 * @tc.name: GetTotalUITreeInfo
67 * @tc.desc: GetTotalUITreeInfo set gesture navigation enabled
68 * @tc.type: FUNC
69 */
HWTEST_F(SceneSessionManagerTest8, GetTotalUITreeInfo, Function | SmallTest | Level3)70 HWTEST_F(SceneSessionManagerTest8, GetTotalUITreeInfo, Function | SmallTest | Level3)
71 {
72 std::string strId = "1234";
73 std::string dumpInfo = "dumpInfo";
74 ssm_->SetDumpUITreeFunc(nullptr);
75 EXPECT_EQ(WSError::WS_OK, ssm_->GetTotalUITreeInfo(strId, dumpInfo));
76 DumpUITreeFunc func = [](uint64_t, std::string& dumpInfo) {
77 return;
78 };
79 ssm_->SetDumpUITreeFunc(func);
80 EXPECT_EQ(WSError::WS_OK, ssm_->GetTotalUITreeInfo(strId, dumpInfo));
81 }
82
83
84 /**
85 * @tc.name: GetRemoteSessionSnapshotInfo
86 * @tc.desc: GetRemoteSessionSnapshotInfo set gesture navigation enabled
87 * @tc.type: FUNC
88 */
HWTEST_F(SceneSessionManagerTest8, GetRemoteSessionSnapshotInfo, Function | SmallTest | Level3)89 HWTEST_F(SceneSessionManagerTest8, GetRemoteSessionSnapshotInfo, Function | SmallTest | Level3)
90 {
91 AAFwk::MissionSnapshot sessionSnapshot;
92 std::string deviceId = "";
93 int res = ssm_->GetRemoteSessionSnapshotInfo(deviceId, 8, sessionSnapshot);
94 EXPECT_EQ(ERR_NULL_OBJECT, res);
95 }
96
97 /**
98 * @tc.name: WindowLayerInfoChangeCallback
99 * @tc.desc: test function : WindowLayerInfoChangeCallback
100 * @tc.type: FUNC
101 */
HWTEST_F(SceneSessionManagerTest8, WindowLayerInfoChangeCallback, Function | SmallTest | Level3)102 HWTEST_F(SceneSessionManagerTest8, WindowLayerInfoChangeCallback, Function | SmallTest | Level3)
103 {
104 std::shared_ptr<RSOcclusionData> rsData = nullptr;
105 ssm_->WindowLayerInfoChangeCallback(rsData);
106
107 rsData = std::make_shared<RSOcclusionData>();
108 ASSERT_NE(nullptr, rsData);
109 ssm_->WindowLayerInfoChangeCallback(rsData);
110
111 VisibleData visibleData;
112 visibleData.push_back(std::make_pair(0, WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE));
113 visibleData.push_back(std::make_pair(1, WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE));
114 visibleData.push_back(std::make_pair(2, WINDOW_LAYER_INFO_TYPE::INVISIBLE));
115 visibleData.push_back(std::make_pair(3, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_DYNAMIC_STATUS));
116 visibleData.push_back(std::make_pair(4, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_STATIC_STATUS));
117 visibleData.push_back(std::make_pair(5, WINDOW_LAYER_INFO_TYPE::WINDOW_LAYER_UNKNOWN_TYPE));
118 rsData = std::make_shared<RSOcclusionData>(visibleData);
119 ASSERT_NE(nullptr, rsData);
120 ssm_->WindowLayerInfoChangeCallback(rsData);
121 }
122
123 /**
124 * @tc.name: DealwithVisibilityChange
125 * @tc.desc: test function : DealwithVisibilityChange
126 * @tc.type: FUNC
127 */
HWTEST_F(SceneSessionManagerTest8, DealwithVisibilityChange, Function | SmallTest | Level3)128 HWTEST_F(SceneSessionManagerTest8, DealwithVisibilityChange, Function | SmallTest | Level3)
129 {
130 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfo;
131 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
132 ssm_->DealwithVisibilityChange(visibilityChangeInfo, currVisibleData);
133
134 visibilityChangeInfo.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
135 currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
136 ssm_->DealwithVisibilityChange(visibilityChangeInfo, currVisibleData);
137
138 visibilityChangeInfo.push_back(std::make_pair(2, WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION));
139
140 SessionInfo sessionInfo;
141 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_END);
142 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
143 ASSERT_NE(nullptr, sceneSession);
144 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
145 sceneSession->surfaceNode_ = std::make_shared<RSSurfaceNode>(rsSurfaceNodeConfig, true, 0);
146 EXPECT_EQ(WindowType::APP_SUB_WINDOW_END, sceneSession->GetWindowType());
147 ssm_->sceneSessionMap_.emplace(0, sceneSession);
148
149 SessionInfo sessionInfo1;
150 sessionInfo1.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
151 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
152 ASSERT_NE(nullptr, sceneSession1);
153 sceneSession1->surfaceNode_ = std::make_shared<RSSurfaceNode>(rsSurfaceNodeConfig, true, 2);
154 EXPECT_EQ(WindowType::APP_SUB_WINDOW_BASE, sceneSession1->GetWindowType());
155 ssm_->sceneSessionMap_.emplace(2, sceneSession);
156 ssm_->DealwithVisibilityChange(visibilityChangeInfo, currVisibleData);
157 ASSERT_EQ(sceneSession1->GetRSVisible(), false);
158 }
159
160 /**
161 * @tc.name: DealwithVisibilityChange1
162 * @tc.desc: test function : DealwithVisibilityChange1
163 * @tc.type: FUNC
164 */
HWTEST_F(SceneSessionManagerTest8, DealwithVisibilityChange1, Function | SmallTest | Level3)165 HWTEST_F(SceneSessionManagerTest8, DealwithVisibilityChange1, Function | SmallTest | Level3)
166 {
167 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfo;
168 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
169 visibilityChangeInfo.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
170 visibilityChangeInfo.push_back(std::make_pair(1,
171 WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
172 currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
173
174 SessionInfo sessionInfo;
175 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DIALOG);
176 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
177 ASSERT_NE(nullptr, sceneSession);
178 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
179 sceneSession->surfaceNode_ = std::make_shared<RSSurfaceNode>(rsSurfaceNodeConfig, true, 0);
180 EXPECT_EQ(WindowType::WINDOW_TYPE_DIALOG, sceneSession->GetWindowType());
181 sceneSession->SetParentSession(nullptr);
182 ssm_->sceneSessionMap_.emplace(0, sceneSession);
183
184 SessionInfo sessionInfo1;
185 sessionInfo1.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DIALOG);
186 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
187 ASSERT_NE(nullptr, sceneSession1);
188 sceneSession1->surfaceNode_ = std::make_shared<RSSurfaceNode>(rsSurfaceNodeConfig, true, 1);
189 sceneSession1->SetParentSession(sceneSession1);
190 ssm_->sceneSessionMap_.emplace(1, sceneSession);
191 ssm_->DealwithVisibilityChange(visibilityChangeInfo, currVisibleData);
192 ASSERT_EQ(sceneSession1->GetRSVisible(), false);
193 }
194
195 /**
196 * @tc.name: PostProcessFocus
197 * @tc.desc: test function : PostProcessFocus
198 * @tc.type: FUNC
199 */
HWTEST_F(SceneSessionManagerTest8, PostProcessFocus, Function | SmallTest | Level3)200 HWTEST_F(SceneSessionManagerTest8, PostProcessFocus, Function | SmallTest | Level3)
201 {
202 ssm_->sceneSessionMap_.emplace(0, nullptr);
203 ssm_->PostProcessFocus();
204 ssm_->sceneSessionMap_.clear();
205
206 SessionInfo sessionInfo;
207 sessionInfo.bundleName_ = "PostProcessFocus";
208 sessionInfo.abilityName_ = "PostProcessFocus";
209 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
210 ASSERT_NE(nullptr, sceneSession);
211 PostProcessFocusState state;
212 EXPECT_EQ(false, state.enabled_);
213 sceneSession->SetPostProcessFocusState(state);
214 ssm_->sceneSessionMap_.emplace(0, sceneSession);
215 ssm_->PostProcessFocus();
216
217 state.enabled_ = true;
218 state.isFocused_ = false;
219 sceneSession->SetPostProcessFocusState(state);
220 ssm_->PostProcessFocus();
221
222 state.isFocused_ = true;
223 state.reason_ = FocusChangeReason::SCB_START_APP;
224 sceneSession->SetPostProcessFocusState(state);
225 ssm_->PostProcessFocus();
226
227 sceneSession->SetPostProcessFocusState(state);
228 state.reason_ = FocusChangeReason::DEFAULT;
229 ssm_->PostProcessFocus();
230 }
231
232 /**
233 * @tc.name: PostProcessFocus01
234 * @tc.desc: test function : PostProcessFocus with focusableOnShow
235 * @tc.type: FUNC
236 */
HWTEST_F(SceneSessionManagerTest8, PostProcessFocus01, Function | SmallTest | Level3)237 HWTEST_F(SceneSessionManagerTest8, PostProcessFocus01, Function | SmallTest | Level3)
238 {
239 ssm_->sceneSessionMap_.clear();
240 ssm_->focusedSessionId_ = 0;
241
242 SessionInfo sessionInfo;
243 sessionInfo.bundleName_ = "PostProcessFocus01";
244 sessionInfo.abilityName_ = "PostProcessFocus01";
245 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
246 sceneSession->persistentId_ = 1;
247 sceneSession->state_ = SessionState::STATE_FOREGROUND;
248 sceneSession->isVisible_ = true;
249
250 PostProcessFocusState state = {true, true, true, FocusChangeReason::FOREGROUND};
251 sceneSession->SetPostProcessFocusState(state);
252 sceneSession->SetFocusableOnShow(false);
253 ssm_->sceneSessionMap_.emplace(1, sceneSession);
254 ssm_->PostProcessFocus();
255
256 EXPECT_NE(1, ssm_->focusedSessionId_);
257 }
258
259 /**
260 * @tc.name: PostProcessFocus02
261 * @tc.desc: test function : PostProcessFocus
262 * @tc.type: FUNC
263 */
HWTEST_F(SceneSessionManagerTest8, PostProcessFocus02, Function | SmallTest | Level3)264 HWTEST_F(SceneSessionManagerTest8, PostProcessFocus02, Function | SmallTest | Level3)
265 {
266 ssm_->sceneSessionMap_.clear();
267 ssm_->focusedSessionId_ = 0;
268
269 SessionInfo sessionInfo;
270 sessionInfo.bundleName_ = "PostProcessFocus02";
271 sessionInfo.abilityName_ = "PostProcessFocus02";
272 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
273 sceneSession->persistentId_ = 1;
274 sceneSession->state_ = SessionState::STATE_FOREGROUND;
275 sceneSession->isVisible_ = true;
276
277 PostProcessFocusState state = {true, true, true, FocusChangeReason::RECENT};
278 sceneSession->SetPostProcessFocusState(state);
279 ssm_->sceneSessionMap_.emplace(1, sceneSession);
280 ssm_->PostProcessFocus();
281
282 EXPECT_EQ(1, ssm_->focusedSessionId_);
283 }
284
285 /**
286 * @tc.name: PostProcessProperty
287 * @tc.desc: test function : PostProcessProperty
288 * @tc.type: FUNC
289 */
HWTEST_F(SceneSessionManagerTest8, PostProcessProperty, Function | SmallTest | Level3)290 HWTEST_F(SceneSessionManagerTest8, PostProcessProperty, Function | SmallTest | Level3)
291 {
292 ssm_->sceneSessionMap_.emplace(0, nullptr);
293 ssm_->PostProcessProperty(static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA));
294 ssm_->PostProcessProperty(~static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA));
295 ssm_->sceneSessionMap_.clear();
296
297 SessionInfo sessionInfo;
298 sessionInfo.bundleName_ = "PostProcessProperty";
299 sessionInfo.abilityName_ = "PostProcessProperty";
300 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_DIALOG);
301 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
302 ASSERT_NE(nullptr, sceneSession);
303 PostProcessFocusState state;
304 EXPECT_EQ(false, state.enabled_);
305 sceneSession->SetPostProcessFocusState(state);
306 ssm_->sceneSessionMap_.emplace(0, sceneSession);
307 ssm_->PostProcessFocus();
308
309 state.enabled_ = true;
310 sceneSession->SetPostProcessFocusState(state);
311 ssm_->PostProcessFocus();
312
313 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
314 ssm_->PostProcessFocus();
315 }
316
317 /**
318 * @tc.name: NotifyUpdateRectAfterLayout
319 * @tc.desc: test function : NotifyUpdateRectAfterLayout
320 * @tc.type: FUNC
321 */
HWTEST_F(SceneSessionManagerTest8, NotifyUpdateRectAfterLayout, Function | SmallTest | Level3)322 HWTEST_F(SceneSessionManagerTest8, NotifyUpdateRectAfterLayout, Function | SmallTest | Level3)
323 {
324 ssm_->sceneSessionMap_.emplace(0, nullptr);
325 ssm_->NotifyUpdateRectAfterLayout();
326 ssm_->sceneSessionMap_.clear();
327
328 SessionInfo sessionInfo;
329 sessionInfo.bundleName_ = "NotifyUpdateRectAfterLayout";
330 sessionInfo.abilityName_ = "NotifyUpdateRectAfterLayout";
331 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
332 ASSERT_NE(nullptr, sceneSession);
333 ssm_->sceneSessionMap_.emplace(0, sceneSession);
334 ssm_->NotifyUpdateRectAfterLayout();
335 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
336 usleep(NOT_WAIT_SYNC_IN_NS);
337 }
338
339 /**
340 * @tc.name: DestroyExtensionSession
341 * @tc.desc: test function : DestroyExtensionSession
342 * @tc.type: FUNC
343 */
HWTEST_F(SceneSessionManagerTest8, DestroyExtensionSession, Function | SmallTest | Level3)344 HWTEST_F(SceneSessionManagerTest8, DestroyExtensionSession, Function | SmallTest | Level3)
345 {
346 ssm_->remoteExtSessionMap_.clear();
347 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
348 sptr<IRemoteObject> token = new IRemoteObjectMocker();
349 EXPECT_NE(nullptr, iRemoteObjectMocker);
350 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
351 ssm_->remoteExtSessionMap_.emplace(iRemoteObjectMocker, token);
352
353 ssm_->extSessionInfoMap_.clear();
354 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
355
356 ExtensionWindowAbilityInfo extensionWindowAbilituInfo;
357 ssm_->extSessionInfoMap_.emplace(token, extensionWindowAbilituInfo);
358
359 ssm_->sceneSessionMap_.emplace(0, nullptr);
360 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
361 ssm_->sceneSessionMap_.clear();
362
363 SessionInfo sessionInfo;
364 sessionInfo.bundleName_ = "DestroyExtensionSession";
365 sessionInfo.abilityName_ = "DestroyExtensionSession";
366 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
367 ASSERT_NE(nullptr, sceneSession);
368 ssm_->sceneSessionMap_.emplace(0, sceneSession);
369
370 ExtensionWindowFlags extensionWindowFlags;
371 sceneSession->combinedExtWindowFlags_ = extensionWindowFlags;
372 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
373
374 extensionWindowFlags.waterMarkFlag = false;
375 extensionWindowFlags.privacyModeFlag = false;
376 sceneSession->combinedExtWindowFlags_ = extensionWindowFlags;
377 EXPECT_EQ(false, sceneSession->combinedExtWindowFlags_.privacyModeFlag);
378 ssm_->DestroyExtensionSession(iRemoteObjectMocker);
379 constexpr uint32_t DES_WAIT_SYNC_IN_NS = 500000;
380 usleep(DES_WAIT_SYNC_IN_NS);
381 }
382
383 /**
384 * @tc.name: FilterSceneSessionCovered
385 * @tc.desc: test function : FilterSceneSessionCovered
386 * @tc.type: FUNC
387 */
HWTEST_F(SceneSessionManagerTest8, FilterSceneSessionCovered, Function | SmallTest | Level3)388 HWTEST_F(SceneSessionManagerTest8, FilterSceneSessionCovered, Function | SmallTest | Level3)
389 {
390 std::vector<sptr<SceneSession>> sceneSessionList;
391 sptr<SceneSession> sceneSession = nullptr;
392 sceneSessionList.emplace_back(sceneSession);
393 EXPECT_EQ(1, sceneSessionList.size());
394 ssm_->FilterSceneSessionCovered(sceneSessionList);
395
396 SessionInfo sessionInfo;
397 sceneSessionList.clear();
398 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
399 EXPECT_NE(nullptr, sceneSession);
400 EXPECT_EQ(WSError::WS_OK, sceneSession->SetSessionProperty(nullptr));
401 sceneSessionList.emplace_back(sceneSession);
402 ssm_->FilterSceneSessionCovered(sceneSessionList);
403 }
404
405 /**
406 * @tc.name: UpdateSubWindowVisibility
407 * @tc.desc: test function : UpdateSubWindowVisibility
408 * @tc.type: FUNC
409 */
HWTEST_F(SceneSessionManagerTest8, UpdateSubWindowVisibility, Function | SmallTest | Level3)410 HWTEST_F(SceneSessionManagerTest8, UpdateSubWindowVisibility, Function | SmallTest | Level3)
411 {
412 SessionInfo sessionInfo;
413 sessionInfo.bundleName_ = "UpdateSubWindowVisibility";
414 sessionInfo.abilityName_ = "UpdateSubWindowVisibility";
415 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
416 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
417 EXPECT_NE(nullptr, sceneSession);
418 WindowVisibilityState visibleState = WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION;
419 std::vector<std::pair<uint64_t, WindowVisibilityState>> visibilityChangeInfo;
420 std::vector<sptr<WindowVisibilityInfo>> windowVisibilityInfos;
421 std::string visibilityInfo = "";
422 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
423 sceneSession->persistentId_ = 1998;
424 sceneSession->SetCallingUid(1998);
425 SessionState state = SessionState::STATE_CONNECT;
426 sceneSession->SetSessionState(state);
427 sceneSession->SetParentSession(sceneSession);
428 EXPECT_EQ(1998, sceneSession->GetParentSession()->GetWindowId());
429 ssm_->sceneSessionMap_.emplace(0, sceneSession);
430
431 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
432 EXPECT_NE(nullptr, sceneSession1);
433 sceneSession1->persistentId_ = 1998;
434 sceneSession1->SetCallingUid(1024);
435 SessionState state1 = SessionState::STATE_CONNECT;
436 sceneSession1->SetSessionState(state1);
437 sceneSession1->SetParentSession(sceneSession1);
438 EXPECT_EQ(1998, sceneSession1->GetParentSession()->GetWindowId());
439 ssm_->sceneSessionMap_.emplace(0, sceneSession1);
440
441 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
442 EXPECT_NE(nullptr, sceneSession2);
443 sceneSession2->persistentId_ = 1998;
444 sceneSession2->SetCallingUid(1998);
445 SessionState state2 = SessionState::STATE_FOREGROUND;
446 sceneSession2->SetSessionState(state2);
447 sceneSession2->SetParentSession(sceneSession2);
448 EXPECT_EQ(1998, sceneSession2->GetParentSession()->GetWindowId());
449 ssm_->sceneSessionMap_.emplace(0, sceneSession2);
450 ssm_->UpdateSubWindowVisibility(sceneSession,
451 visibleState, visibilityChangeInfo, windowVisibilityInfos, visibilityInfo, currVisibleData);
452 }
453
454 /**
455 * @tc.name: GetOrientationFromResourceManager
456 * @tc.desc: test function : GetOrientationFromResourceManager
457 * @tc.type: FUNC
458 */
HWTEST_F(SceneSessionManagerTest8, GetOrientationFromResourceManager, Function | SmallTest | Level3)459 HWTEST_F(SceneSessionManagerTest8, GetOrientationFromResourceManager, Function | SmallTest | Level3)
460 {
461 AppExecFwk::AbilityInfo abilityInfo;
462 abilityInfo.orientationId = 0;
463 ssm_->GetOrientationFromResourceManager(abilityInfo);
464
465 abilityInfo.orientationId = 20;
466 abilityInfo.hapPath = "";
467 ssm_->GetOrientationFromResourceManager(abilityInfo);
468 EXPECT_EQ(true, abilityInfo.hapPath.empty());
469 }
470
471 /**
472 * @tc.name: RegisterSessionChangeByActionNotifyManagerFunc
473 * @tc.desc: test function : RegisterSessionChangeByActionNotifyManagerFunc
474 * @tc.type: FUNC
475 */
HWTEST_F(SceneSessionManagerTest8, RegisterSessionChangeByActionNotifyManagerFunc, Function | SmallTest | Level3)476 HWTEST_F(SceneSessionManagerTest8, RegisterSessionChangeByActionNotifyManagerFunc, Function | SmallTest | Level3)
477 {
478 sptr<SceneSession> sceneSession = nullptr;
479 ssm_->RegisterSessionChangeByActionNotifyManagerFunc(sceneSession);
480 SessionInfo sessionInfo;
481 sessionInfo.bundleName_ = "RegisterSessionChangeByActionNotifyManagerFunc";
482 sessionInfo.abilityName_ = "RegisterSessionChangeByActionNotifyManagerFunc";
483 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
484 EXPECT_NE(nullptr, sceneSession);
485 ssm_->RegisterSessionChangeByActionNotifyManagerFunc(sceneSession);
486 EXPECT_NE(nullptr, sceneSession->sessionChangeByActionNotifyManagerFunc_);
487
488 sptr<WindowSessionProperty> property = nullptr;
489 sceneSession->NotifySessionChangeByActionNotifyManager(property,
490 WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
491
492 property = sptr<WindowSessionProperty>::MakeSptr();
493 EXPECT_NE(nullptr, property);
494
495 sceneSession->NotifySessionChangeByActionNotifyManager(property,
496 WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
497 }
498
499 /**
500 * @tc.name: RegisterSessionChangeByActionNotifyManagerFunc1
501 * @tc.desc: test function : RegisterSessionChangeByActionNotifyManagerFunc1
502 * @tc.type: FUNC
503 */
HWTEST_F(SceneSessionManagerTest8, RegisterSessionChangeByActionNotifyManagerFunc1, Function | SmallTest | Level3)504 HWTEST_F(SceneSessionManagerTest8, RegisterSessionChangeByActionNotifyManagerFunc1, Function | SmallTest | Level3)
505 {
506 SessionInfo sessionInfo;
507 sessionInfo.bundleName_ = "RegisterSessionChangeByActionNotifyManagerFunc1";
508 sessionInfo.abilityName_ = "RegisterSessionChangeByActionNotifyManagerFunc1";
509 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
510 EXPECT_NE(nullptr, sceneSession);
511
512 ssm_->RegisterSessionChangeByActionNotifyManagerFunc(sceneSession);
513 EXPECT_NE(nullptr, sceneSession->sessionChangeByActionNotifyManagerFunc_);
514
515 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
516 EXPECT_NE(nullptr, property);
517
518 sceneSession->NotifySessionChangeByActionNotifyManager(property,
519 WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
520
521 sceneSession->NotifySessionChangeByActionNotifyManager(property,
522 WSPropertyChangeAction::ACTION_UPDATE_NAVIGATION_INDICATOR_PROPS);
523
524 sceneSession->NotifySessionChangeByActionNotifyManager(property,
525 WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
526
527 sceneSession->NotifySessionChangeByActionNotifyManager(property,
528 WSPropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
529
530 sceneSession->NotifySessionChangeByActionNotifyManager(property,
531 WSPropertyChangeAction::ACTION_UPDATE_FLAGS);
532
533 sceneSession->NotifySessionChangeByActionNotifyManager(property,
534 WSPropertyChangeAction::ACTION_UPDATE_MODE);
535
536 sceneSession->NotifySessionChangeByActionNotifyManager(property,
537 WSPropertyChangeAction::ACTION_UPDATE_HIDE_NON_SYSTEM_FLOATING_WINDOWS);
538
539 sceneSession->NotifySessionChangeByActionNotifyManager(property,
540 WSPropertyChangeAction::ACTION_UPDATE_WINDOW_MASK);
541
542 sceneSession->NotifySessionChangeByActionNotifyManager(property,
543 WSPropertyChangeAction::ACTION_UPDATE_TOPMOST);
544 }
545
546 /**
547 * @tc.name: RegisterRequestFocusStatusNotifyManagerFunc
548 * @tc.desc: test function : RegisterRequestFocusStatusNotifyManagerFunc
549 * @tc.type: FUNC
550 */
HWTEST_F(SceneSessionManagerTest8, RegisterRequestFocusStatusNotifyManagerFunc, Function | SmallTest | Level3)551 HWTEST_F(SceneSessionManagerTest8, RegisterRequestFocusStatusNotifyManagerFunc, Function | SmallTest | Level3)
552 {
553 sptr<SceneSession> sceneSession = nullptr;
554 ssm_->RegisterRequestFocusStatusNotifyManagerFunc(sceneSession);
555 EXPECT_EQ(nullptr, sceneSession);
556 }
557
558 /**
559 * @tc.name: CheckRequestFocusImmdediately
560 * @tc.desc: test function : CheckRequestFocusImmdediately
561 * @tc.type: FUNC
562 */
HWTEST_F(SceneSessionManagerTest8, CheckRequestFocusImmdediately, Function | SmallTest | Level3)563 HWTEST_F(SceneSessionManagerTest8, CheckRequestFocusImmdediately, Function | SmallTest | Level3)
564 {
565 SessionInfo sessionInfo;
566 sessionInfo.bundleName_ = "CheckRequestFocusImmdediately";
567 sessionInfo.abilityName_ = "CheckRequestFocusImmdediately";
568 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
569 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
570 EXPECT_NE(nullptr, sceneSession);
571 EXPECT_EQ(WindowType::APP_SUB_WINDOW_BASE, sceneSession->GetWindowType());
572 bool ret = ssm_->CheckRequestFocusImmdediately(sceneSession);
573 ASSERT_EQ(ret, false);
574 }
575
576 /**
577 * @tc.name: HandleTurnScreenOn
578 * @tc.desc: test function : HandleTurnScreenOn
579 * @tc.type: FUNC
580 */
HWTEST_F(SceneSessionManagerTest8, HandleTurnScreenOn, Function | SmallTest | Level3)581 HWTEST_F(SceneSessionManagerTest8, HandleTurnScreenOn, Function | SmallTest | Level3)
582 {
583 sptr<SceneSession> sceneSession = nullptr;
584 ssm_->HandleTurnScreenOn(sceneSession);
585 SessionInfo sessionInfo;
586 sessionInfo.bundleName_ = "HandleTurnScreenOn";
587 sessionInfo.abilityName_ = "HandleTurnScreenOn";
588 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
589 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
590 EXPECT_NE(nullptr, sceneSession);
591 sceneSession->GetSessionProperty()->SetTurnScreenOn(false);
592 ssm_->HandleTurnScreenOn(sceneSession);
593 EXPECT_EQ(false, sceneSession->GetSessionProperty()->IsTurnScreenOn());
594 sceneSession->GetSessionProperty()->SetTurnScreenOn(true);
595 ssm_->HandleTurnScreenOn(sceneSession);
596 constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000;
597 usleep(NOT_WAIT_SYNC_IN_NS);
598 }
599 /**
600 * @tc.name: HandleKeepScreenOn
601 * @tc.desc: test function : HandleKeepScreenOn
602 * @tc.type: FUNC
603 */
HWTEST_F(SceneSessionManagerTest8, HandleKeepScreenOn, Function | SmallTest | Level3)604 HWTEST_F(SceneSessionManagerTest8, HandleKeepScreenOn, Function | SmallTest | Level3)
605 {
606 SessionInfo sessionInfo;
607 sessionInfo.bundleName_ = "HandleTurnScreenOn";
608 sessionInfo.abilityName_ = "HandleTurnScreenOn";
609 sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_SUB_WINDOW_BASE);
610 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
611 EXPECT_NE(nullptr, sceneSession);
612
613 ssm_->HandleKeepScreenOn(sceneSession, false);
614 sceneSession->keepScreenLock_ = nullptr;
615 ssm_->HandleKeepScreenOn(sceneSession, true);
616 bool enable = true;
617 EXPECT_EQ(WSError::WS_OK, ssm_->GetFreeMultiWindowEnableState(enable));
618 }
619
620 /**
621 * @tc.name: SetBrightness
622 * @tc.desc: test function : SetBrightness
623 * @tc.type: FUNC
624 */
HWTEST_F(SceneSessionManagerTest8, SetBrightness, Function | SmallTest | Level3)625 HWTEST_F(SceneSessionManagerTest8, SetBrightness, Function | SmallTest | Level3)
626 {
627 SessionInfo sessionInfo;
628 sessionInfo.bundleName_ = "SetBrightness";
629 sessionInfo.abilityName_ = "SetBrightness";
630 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
631 EXPECT_NE(nullptr, sceneSession);
632 sceneSession->persistentId_ = 2024;
633
634 ssm_->SetDisplayBrightness(3.14f);
635 std::shared_ptr<AppExecFwk::EventHandler> pipeEventHandler = nullptr;
636 ssm_->eventHandler_ = pipeEventHandler;
637 ASSERT_EQ(nullptr, ssm_->eventHandler_);
638 auto ret = ssm_->SetBrightness(sceneSession, 3.15f);
639 EXPECT_EQ(WSError::WS_OK, ret);
640
641 ssm_->Init();
642 ASSERT_NE(nullptr, ssm_->eventHandler_);
643
644 ssm_->SetFocusedSessionId(2024);
645 EXPECT_EQ(2024, ssm_->GetFocusedSessionId());
646
647 ret = ssm_->SetBrightness(sceneSession, 3.15f);
648 EXPECT_EQ(WSError::WS_OK, ret);
649 EXPECT_EQ(3.15f, ssm_->GetDisplayBrightness());
650
651 ret = ssm_->SetBrightness(sceneSession, UNDEFINED_BRIGHTNESS);
652 EXPECT_EQ(WSError::WS_OK, ret);
653 EXPECT_EQ(UNDEFINED_BRIGHTNESS, ssm_->GetDisplayBrightness());
654 }
655
656 /**
657 * @tc.name: TerminateSessionNew
658 * @tc.desc: test function : TerminateSessionNew
659 * @tc.type: FUNC
660 */
HWTEST_F(SceneSessionManagerTest8, TerminateSessionNew, Function | SmallTest | Level3)661 HWTEST_F(SceneSessionManagerTest8, TerminateSessionNew, Function | SmallTest | Level3)
662 {
663 sptr<AAFwk::SessionInfo> sessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
664 EXPECT_NE(nullptr, sessionInfo);
665 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
666 EXPECT_NE(nullptr, iRemoteObjectMocker);
667 sessionInfo->sessionToken = iRemoteObjectMocker;
668
669 SessionInfo info;
670 info.bundleName_ = "TerminateSessionNew";
671 info.abilityName_ = "TerminateSessionNew";
672 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
673 EXPECT_NE(nullptr, sceneSession);
674 sceneSession->SetAbilityToken(iRemoteObjectMocker);
675 ssm_->sceneSessionMap_.emplace(0, sceneSession);
676 ssm_->TerminateSessionNew(sessionInfo, true, true);
677 }
678
679 }
680 } // namespace Rosen
681 } // namespace OHOS