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