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 "interfaces/include/ws_common.h"
19 #include "iremote_object_mocker.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 #include "screen_session_manager_client/include/screen_session_manager_client.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31
32 class SceneSessionManagerTest10 : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 void InitTestSceneSession(DisplayId displayId, int32_t windowId, int32_t zOrder, bool visible, WSRect rect);
39
40 static sptr<SceneSessionManager> ssm_;
41 private:
42 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
43 };
44
45 sptr<SceneSessionManager> SceneSessionManagerTest10::ssm_ = nullptr;
46
NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)47 void NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)
48 {
49 }
50
TraverseFuncTest(const sptr<SceneSession>& session)51 bool TraverseFuncTest(const sptr<SceneSession>& session)
52 {
53 return true;
54 }
55
WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)56 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
57 {
58 }
59
ProcessStatusBarEnabledChangeFuncTest(bool enable)60 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
61 {
62 }
63
DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)64 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
65 {
66 }
67
SetUpTestCase()68 void SceneSessionManagerTest10::SetUpTestCase()
69 {
70 ssm_ = &SceneSessionManager::GetInstance();
71 }
72
TearDownTestCase()73 void SceneSessionManagerTest10::TearDownTestCase()
74 {
75 ssm_ = nullptr;
76 }
77
SetUp()78 void SceneSessionManagerTest10::SetUp()
79 {
80 }
81
TearDown()82 void SceneSessionManagerTest10::TearDown()
83 {
84 usleep(WAIT_SYNC_IN_NS);
85 }
86
InitTestSceneSession(DisplayId displayId, int32_t windowId, int32_t zOrder, bool visible, WSRect rect)87 void SceneSessionManagerTest10::InitTestSceneSession(DisplayId displayId,
88 int32_t windowId, int32_t zOrder, bool visible, WSRect rect)
89 {
90 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
91 property->SetDisplayId(displayId);
92 SessionInfo info;
93 info.bundleName_ = "root";
94 info.persistentId_ = windowId;
95 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, nullptr);
96 ASSERT_NE(nullptr, sceneSession);
97 sceneSession->SetZOrder(zOrder);
98 sceneSession->SetRSVisible(visible);
99 sceneSession->SetSessionRect(rect);
100 sceneSession->SetSessionProperty(property);
101 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
102 EXPECT_EQ(windowId, sceneSession->GetPersistentId());
103 }
104
105 namespace {
106 /**
107 * @tc.name: RequestSceneSessionDestructionInner
108 * @tc.desc: RequestSceneSessionDestructionInner
109 * @tc.type: FUNC
110 */
HWTEST_F(SceneSessionManagerTest10, RequestSceneSessionDestructionInner, Function | SmallTest | Level3)111 HWTEST_F(SceneSessionManagerTest10, RequestSceneSessionDestructionInner, Function | SmallTest | Level3)
112 {
113 ASSERT_NE(ssm_, nullptr);
114
115 SessionInfo info;
116 sptr<SceneSession::SpecificSessionCallback> specificCallback = nullptr;
117 sptr<SceneSession> scnSession = new SceneSession(info, specificCallback);
118 sptr<AAFwk::SessionInfo> scnSessionInfo = new AAFwk::SessionInfo();
119 bool needRemoveSession = true;
120 bool isForceClean = true;
121
122 SessionInfo sessionInfo;
123 sessionInfo.collaboratorType_ = CollaboratorType::RESERVE_TYPE;
124 ssm_->RequestSceneSessionDestructionInner(scnSession, scnSessionInfo, needRemoveSession, isForceClean);
125
126 needRemoveSession = false;
127 isForceClean = false;
128 sessionInfo.collaboratorType_ = CollaboratorType::DEFAULT_TYPE;
129 sessionInfo.want = std::make_shared<AAFwk::Want>();
130 ssm_->RequestSceneSessionDestructionInner(scnSession, scnSessionInfo, needRemoveSession, isForceClean);
131 }
132
133 /**
134 * @tc.name: RegisterWindowManagerAgent
135 * @tc.desc: RegisterWindowManagerAgent
136 * @tc.type: FUNC
137 */
HWTEST_F(SceneSessionManagerTest10, RegisterWindowManagerAgent01, Function | SmallTest | Level3)138 HWTEST_F(SceneSessionManagerTest10, RegisterWindowManagerAgent01, Function | SmallTest | Level3)
139 {
140 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR;
141 sptr<IWindowManagerAgent> windowManagerAgent;
142 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
143
144 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED;
145 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
146
147 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG;
148 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
149
150 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE;
151 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
152
153 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY;
154 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
155
156 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE;
157 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
158
159 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM;
160 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
161
162 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
163 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
164
165 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE;
166 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
167
168 type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT;
169 ASSERT_EQ(windowManagerAgent, nullptr);
170 ssm_->RegisterWindowManagerAgent(type, windowManagerAgent);
171 }
172
173 /**
174 * @tc.name: UpdateRotateAnimationConfig
175 * @tc.desc: UpdateRotateAnimationConfig
176 * @tc.type: FUNC
177 */
HWTEST_F(SceneSessionManagerTest10, UpdateRotateAnimationConfig, Function | SmallTest | Level3)178 HWTEST_F(SceneSessionManagerTest10, UpdateRotateAnimationConfig, Function | SmallTest | Level3)
179 {
180 ASSERT_NE(ssm_, nullptr);
181 RotateAnimationConfig config = { 400 };
182 ssm_->UpdateRotateAnimationConfig(config);
183 usleep(WAIT_SYNC_IN_NS);
184 ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 400);
185
186 config.duration_ = 600;
187 ssm_->UpdateRotateAnimationConfig(config);
188 usleep(WAIT_SYNC_IN_NS);
189 ASSERT_EQ(ssm_->rotateAnimationConfig_.duration_, 600);
190 }
191
192 /**
193 * @tc.name: RegisterAcquireRotateAnimationConfigFunc
194 * @tc.desc: RegisterAcquireRotateAnimationConfigFunc
195 * @tc.type: FUNC
196 */
HWTEST_F(SceneSessionManagerTest10, RegisterAcquireRotateAnimationConfigFunc, Function | SmallTest | Level3)197 HWTEST_F(SceneSessionManagerTest10, RegisterAcquireRotateAnimationConfigFunc, Function | SmallTest | Level3)
198 {
199 ASSERT_NE(ssm_, nullptr);
200 SessionInfo sessionInfo;
201 sessionInfo.bundleName_ = "bundleName";
202 sessionInfo.persistentId_ = 1;
203 sessionInfo.isSystem_ = false;
204 sessionInfo.abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
205 ASSERT_NE(sessionInfo.abilityInfo, nullptr);
206 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
207 ASSERT_NE(sceneSession, nullptr);
208 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("bundleName", 1);
209 ASSERT_NE(sceneSession->scenePersistence_, nullptr);
210 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
211 ssm_->RegisterAcquireRotateAnimationConfigFunc(sceneSession);
212 WSRect rect({1, 1, 1, 1});
213 SizeChangeReason reason = SizeChangeReason::ROTATION;
214 WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionManagerTest10");
215 ASSERT_EQ(result, WSError::WS_OK);
216 }
217
218 /**
219 * @tc.name: CheckLastFocusedAppSessionFocus
220 * @tc.desc: CheckLastFocusedAppSessionFocus
221 * @tc.type: FUNC
222 */
HWTEST_F(SceneSessionManagerTest10, CheckLastFocusedAppSessionFocus, Function | SmallTest | Level3)223 HWTEST_F(SceneSessionManagerTest10, CheckLastFocusedAppSessionFocus, Function | SmallTest | Level3)
224 {
225 ASSERT_NE(ssm_, nullptr);
226
227 SessionInfo info1;
228 info1.abilityName_ = "focusedSession";
229 info1.bundleName_ = "focusedSession";
230 info1.windowType_ = 1;
231 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info1, nullptr);
232 ASSERT_NE(focusedSession, nullptr);
233
234 SessionInfo info2;
235 info2.abilityName_ = "nextSession";
236 info2.bundleName_ = "nextSession";
237 info2.windowType_ = 1;
238 sptr<SceneSession> nextSession = new (std::nothrow) SceneSession(info2, nullptr);
239 ASSERT_NE(nextSession, nullptr);
240
241 ssm_->lastFocusedAppSessionId_ = nextSession->GetPersistentId();
242 ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession));
243
244 ssm_->lastFocusedAppSessionId_ = 124;
245 focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
246 ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession));
247
248 nextSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
249 ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession);
250 ASSERT_EQ(0, ssm_->lastFocusedAppSessionId_);
251 }
252
253 /**
254 * @tc.name: GetWindowIdsByCoordinate01
255 * @tc.desc: GetWindowIdsByCoordinate, displayId invalid
256 * @tc.type: FUNC
257 */
HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate01, Function | SmallTest | Level3)258 HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate01, Function | SmallTest | Level3)
259 {
260 std::vector<int32_t> windowIds;
261 WMError result = ssm_->GetWindowIdsByCoordinate(DISPLAY_ID_INVALID, 0, 0, 0, windowIds);
262 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
263 }
264
265 /**
266 * @tc.name: GetWindowIdsByCoordinate02
267 * @tc.desc: GetWindowIdsByCoordinate, windowNumber 0, x y invalid
268 * @tc.type: FUNC
269 */
HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate02, Function | SmallTest | Level3)270 HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate02, Function | SmallTest | Level3)
271 {
272 ssm_->sceneSessionMap_.clear();
273 InitTestSceneSession(1, 101, 11, true, {100, 100, 200, 200});
274 ssm_->sceneSessionMap_.insert({102, nullptr});
275 InitTestSceneSession(1, 103, 14, true, {120, 120, 220, 220});
276 InitTestSceneSession(1, 104, 12, true, {100, 100, 200, 200});
277 auto it1 = ssm_->sceneSessionMap_.find(104);
278 if (it1 != ssm_->sceneSessionMap_.end()) {
279 it1->second->SetSessionProperty(nullptr);
280 }
281 InitTestSceneSession(1, 105, 12, true, {100, 100, 200, 200});
282 auto it2 = ssm_->sceneSessionMap_.find(105);
283 if (it2 != ssm_->sceneSessionMap_.end()) {
284 it2->second->sessionInfo_.bundleName_ = "other";
285 }
286 InitTestSceneSession(1, 106, 15, true, {140, 140, 240, 240});
287 InitTestSceneSession(2, 107, 15, true, {150, 150, 250, 250});
288 InitTestSceneSession(1, 108, 13, false, {150, 150, 250, 250});
289 InitTestSceneSession(1, 109, 13, true, {160, 160, 260, 260});
290 InitTestSceneSession(1, 110, 12, true, {500, 500, 600, 600});
291
292 std::vector<int32_t> windowIds;
293 WMError result = ssm_->GetWindowIdsByCoordinate(1, 0, -1, -1, windowIds);
294 EXPECT_EQ(result, WMError::WM_OK);
295 EXPECT_EQ(5, windowIds.size());
296 EXPECT_EQ(106, windowIds[0]);
297 EXPECT_EQ(103, windowIds[1]);
298 EXPECT_EQ(109, windowIds[2]);
299 EXPECT_EQ(110, windowIds[3]);
300 EXPECT_EQ(101, windowIds[4]);
301 ssm_->sceneSessionMap_.clear();
302 }
303
304 /**
305 * @tc.name: GetWindowIdsByCoordinate03
306 * @tc.desc: GetWindowIdsByCoordinate, windowNumber 3, x y invalid
307 * @tc.type: FUNC
308 */
HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate03, Function | SmallTest | Level3)309 HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate03, Function | SmallTest | Level3)
310 {
311 ssm_->sceneSessionMap_.clear();
312 InitTestSceneSession(1, 111, 11, true, {100, 100, 200, 200});
313 ssm_->sceneSessionMap_.insert({102, nullptr});
314 InitTestSceneSession(1, 113, 14, true, {120, 120, 220, 220});
315 InitTestSceneSession(1, 114, 12, true, {100, 100, 200, 200});
316 auto it1 = ssm_->sceneSessionMap_.find(114);
317 if (it1 != ssm_->sceneSessionMap_.end()) {
318 it1->second->SetSessionProperty(nullptr);
319 }
320 InitTestSceneSession(1, 115, 12, true, {100, 100, 200, 200});
321 auto it2 = ssm_->sceneSessionMap_.find(115);
322 if (it2 != ssm_->sceneSessionMap_.end()) {
323 it2->second->sessionInfo_.bundleName_ = "other";
324 }
325 InitTestSceneSession(1, 116, 15, true, {140, 140, 240, 240});
326 InitTestSceneSession(2, 117, 15, true, {150, 150, 250, 250});
327 InitTestSceneSession(1, 118, 13, false, {150, 150, 250, 250});
328 InitTestSceneSession(1, 119, 13, true, {160, 160, 260, 260});
329 InitTestSceneSession(1, 120, 12, true, {500, 500, 600, 600});
330
331 std::vector<int32_t> windowIds;
332 WMError result = ssm_->GetWindowIdsByCoordinate(1, 3, -1, -1, windowIds);
333 EXPECT_EQ(result, WMError::WM_OK);
334 EXPECT_EQ(3, windowIds.size());
335 EXPECT_EQ(116, windowIds[0]);
336 EXPECT_EQ(113, windowIds[1]);
337 EXPECT_EQ(119, windowIds[2]);
338 ssm_->sceneSessionMap_.clear();
339 }
340
341 /**
342 * @tc.name: GetWindowIdsByCoordinate04
343 * @tc.desc: GetWindowIdsByCoordinate, windowNumber 0, x y effictive value
344 * @tc.type: FUNC
345 */
HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate04, Function | SmallTest | Level3)346 HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate04, Function | SmallTest | Level3)
347 {
348 ssm_->sceneSessionMap_.clear();
349 InitTestSceneSession(1, 121, 11, true, {100, 100, 200, 200});
350 ssm_->sceneSessionMap_.insert({102, nullptr});
351 InitTestSceneSession(1, 123, 14, true, {120, 120, 220, 220});
352 InitTestSceneSession(1, 124, 12, true, {100, 100, 200, 200});
353 auto it1 = ssm_->sceneSessionMap_.find(124);
354 if (it1 != ssm_->sceneSessionMap_.end()) {
355 it1->second->SetSessionProperty(nullptr);
356 }
357 InitTestSceneSession(1, 125, 12, true, {100, 100, 200, 200});
358 auto it2 = ssm_->sceneSessionMap_.find(125);
359 if (it2 != ssm_->sceneSessionMap_.end()) {
360 it2->second->sessionInfo_.bundleName_ = "other";
361 }
362 InitTestSceneSession(1, 126, 15, true, {140, 140, 240, 240});
363 InitTestSceneSession(2, 127, 15, true, {150, 150, 250, 250});
364 InitTestSceneSession(1, 128, 13, false, {150, 150, 250, 250});
365 InitTestSceneSession(1, 129, 13, true, {160, 160, 260, 260});
366 InitTestSceneSession(1, 130, 12, true, {500, 500, 600, 600});
367
368 std::vector<int32_t> windowIds;
369 WMError result = ssm_->GetWindowIdsByCoordinate(1, 0, 180, 180, windowIds);
370 EXPECT_EQ(result, WMError::WM_OK);
371 EXPECT_EQ(4, windowIds.size());
372 EXPECT_EQ(126, windowIds[0]);
373 EXPECT_EQ(123, windowIds[1]);
374 EXPECT_EQ(129, windowIds[2]);
375 EXPECT_EQ(121, windowIds[3]);
376 ssm_->sceneSessionMap_.clear();
377 }
378
379 /**
380 * @tc.name: GetWindowIdsByCoordinate05
381 * @tc.desc: GetWindowIdsByCoordinate, windowNumber 3, x y effictive value
382 * @tc.type: FUNC
383 */
HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate05, Function | SmallTest | Level3)384 HWTEST_F(SceneSessionManagerTest10, GetWindowIdsByCoordinate05, Function | SmallTest | Level3)
385 {
386 ssm_->sceneSessionMap_.clear();
387 InitTestSceneSession(1, 131, 11, true, {100, 100, 200, 200});
388 ssm_->sceneSessionMap_.insert({102, nullptr});
389 InitTestSceneSession(1, 133, 14, true, {120, 120, 220, 220});
390 InitTestSceneSession(1, 134, 12, true, {100, 100, 200, 200});
391 auto it1 = ssm_->sceneSessionMap_.find(134);
392 if (it1 != ssm_->sceneSessionMap_.end()) {
393 it1->second->SetSessionProperty(nullptr);
394 }
395 InitTestSceneSession(1, 135, 12, true, {100, 100, 200, 200});
396 auto it2 = ssm_->sceneSessionMap_.find(135);
397 if (it2 != ssm_->sceneSessionMap_.end()) {
398 it2->second->sessionInfo_.bundleName_ = "other";
399 }
400 InitTestSceneSession(1, 136, 15, true, {140, 140, 240, 240});
401 InitTestSceneSession(2, 137, 15, true, {150, 150, 250, 250});
402 InitTestSceneSession(1, 138, 13, false, {150, 150, 250, 250});
403 InitTestSceneSession(1, 139, 13, true, {160, 160, 260, 260});
404 InitTestSceneSession(1, 140, 12, true, {500, 500, 600, 600});
405
406 std::vector<int32_t> windowIds;
407 WMError result = ssm_->GetWindowIdsByCoordinate(1, 3, 180, 180, windowIds);
408 EXPECT_EQ(result, WMError::WM_OK);
409 EXPECT_EQ(3, windowIds.size());
410 EXPECT_EQ(136, windowIds[0]);
411 EXPECT_EQ(133, windowIds[1]);
412 EXPECT_EQ(139, windowIds[2]);
413 ssm_->sceneSessionMap_.clear();
414 }
415
416 /**
417 * @tc.name: ProcessFocusZOrderChange
418 * @tc.desc: ProcessFocusZOrderChange
419 * @tc.type: FUNC
420 */
HWTEST_F(SceneSessionManagerTest10, ProcessFocusZOrderChange, Function | SmallTest | Level3)421 HWTEST_F(SceneSessionManagerTest10, ProcessFocusZOrderChange, Function | SmallTest | Level3)
422 {
423 ssm_->sceneSessionMap_.clear();
424 ssm_->ProcessFocusZOrderChange(10);
425 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
426 ssm_->ProcessFocusZOrderChange(97);
427
428 ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
429 ssm_->ProcessFocusZOrderChange(97);
430
431 SessionInfo sessionInfo;
432 sessionInfo.bundleName_ = "focusedSession";
433 sessionInfo.abilityName_ = "focusedSession";
434 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
435 ASSERT_NE(nullptr, sceneSession);
436 ssm_->sceneSessionMap_.emplace(1, sceneSession);
437 ssm_->focusedSessionId_ = 1;
438 ssm_->ProcessFocusZOrderChange(97);
439
440 sceneSession->lastZOrder_ = 2203;
441 sceneSession->zOrder_ = 101;
442 ssm_->ProcessFocusZOrderChange(97);
443
444 SessionInfo sessionInfo1;
445 sessionInfo1.bundleName_ = "voiceInteractionSession";
446 sessionInfo1.abilityName_ = "voiceInteractionSession";
447 sessionInfo1.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_VOICE_INTERACTION);
448 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
449 ASSERT_NE(nullptr, sceneSession1);
450 sceneSession1->zOrder_ = 2109;
451 ssm_->sceneSessionMap_.emplace(2, sceneSession1);
452
453 sceneSession->lastZOrder_ = 103;
454 sceneSession->zOrder_ = 101;
455 ssm_->ProcessFocusZOrderChange(97);
456
457 sceneSession->lastZOrder_ = 2203;
458 sceneSession->zOrder_ = 101;
459 ssm_->ProcessFocusZOrderChange(97);
460 }
461
462 /**
463 * @tc.name: GetAllSceneSessionForAccessibility
464 * @tc.desc: GetAllSceneSessionForAccessibility
465 * @tc.type: FUNC
466 */
HWTEST_F(SceneSessionManagerTest10, GetAllSceneSessionForAccessibility, Function | SmallTest | Level3)467 HWTEST_F(SceneSessionManagerTest10, GetAllSceneSessionForAccessibility, Function | SmallTest | Level3)
468 {
469 ASSERT_NE(ssm_, nullptr);
470 std::vector<sptr<SceneSession>> sceneSessionList;
471 ASSERT_EQ(sceneSessionList.size(), 0);
472 SessionInfo info1;
473 info1.abilityName_ = "test1";
474 info1.bundleName_ = "test1";
475 info1.windowType_ = 1;
476 sptr<SceneSession> sceneSession1 = new (std::nothrow) SceneSession(info1, nullptr);
477 ASSERT_NE(nullptr, sceneSession1);
478 SessionInfo info2;
479 info2.abilityName_ = "test2";
480 info2.bundleName_ = "test2";
481 info2.windowType_ = 1;
482 sptr<SceneSession> sceneSession2 = new (std::nothrow) SceneSession(info2, nullptr);
483 ASSERT_NE(nullptr, sceneSession2);
484 SessionInfo info3;
485 info3.abilityName_ = "test3";
486 info3.bundleName_ = "test3";
487 info3.windowType_ = 1;
488 sptr<SceneSession> sceneSession3 = new (std::nothrow) SceneSession(info3, nullptr);
489 ASSERT_NE(nullptr, sceneSession3);
490 ssm_->sceneSessionMap_.emplace(1, sceneSession1);
491 ssm_->sceneSessionMap_.emplace(2, sceneSession2);
492 ssm_->sceneSessionMap_.emplace(3, sceneSession3);
493 sceneSession1->isScbCoreEnabled_ = false;
494 sceneSession2->isScbCoreEnabled_ = false;
495 sceneSession3->isScbCoreEnabled_ = false;
496 sceneSession1->isVisibleForAccessibility_ = true;
497 sceneSession2->isVisibleForAccessibility_ = false;
498 sceneSession3->isVisibleForAccessibility_ = true;
499 sceneSession1->isVisible_ = true;
500 sceneSession2->isVisible_ = false;
501 sceneSession3->isVisible_ = true;
502 ssm_->GetAllSceneSessionForAccessibility(sceneSessionList);
503 ASSERT_EQ(sceneSessionList.size(), 1);
504 }
505
506 /**
507 * @tc.name: GetMainParentSceneSession001
508 * @tc.desc: test GetMainParentSceneSession
509 * @tc.type: FUNC
510 */
HWTEST_F(SceneSessionManagerTest10, GetMainParentSceneSession001, Function | SmallTest | Level3)511 HWTEST_F(SceneSessionManagerTest10, GetMainParentSceneSession001, Function | SmallTest | Level3)
512 {
513 sptr<SceneSession> ret = ssm_->GetMainParentSceneSession(0, ssm_->sceneSessionMap_);
514 ASSERT_EQ(ret, nullptr);
515
516 ret = ssm_->GetMainParentSceneSession(999, ssm_->sceneSessionMap_);
517 ASSERT_EQ(ret, nullptr);
518
519 SessionInfo info;
520 info.abilityName_ = "GetMainParentSceneSession001";
521 info.bundleName_ = "GetMainParentSceneSession001";
522 sptr<SceneSession> scensession = nullptr;
523 scensession = new (std::nothrow) SceneSession(info, nullptr);
524 ASSERT_NE(scensession, nullptr);
525
526 ssm_->sceneSessionMap_[999] = scensession;
527 ret = ssm_->GetMainParentSceneSession(999, ssm_->sceneSessionMap_);
528 ASSERT_NE(ret, nullptr);
529 }
530
531 /**
532 * @tc.name: GetParentMainWindowId001
533 * @tc.desc: test GetParentMainWindowId
534 * @tc.type: FUNC
535 */
HWTEST_F(SceneSessionManagerTest10, GetParentMainWindowId001, Function | SmallTest | Level3)536 HWTEST_F(SceneSessionManagerTest10, GetParentMainWindowId001, Function | SmallTest | Level3)
537 {
538 int32_t windowId = 0;
539 int32_t mainWindowId = 0;
540 WMError ret = ssm_->GetParentMainWindowId(windowId, mainWindowId);
541 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
542
543 windowId = -1;
544 ret = ssm_->GetParentMainWindowId(windowId, mainWindowId);
545 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
546
547 SessionInfo info;
548 info.abilityName_ = "test";
549 info.bundleName_ = "test";
550 sptr<SceneSession> scensession = nullptr;
551 scensession = new (std::nothrow) SceneSession(info, nullptr);
552
553 ASSERT_NE(scensession, nullptr);
554 windowId = 200;
555 scensession->persistentId_ = windowId;
556 ssm_->sceneSessionMap_[windowId] = scensession;
557 ret = ssm_->GetParentMainWindowId(windowId, mainWindowId);
558 ASSERT_EQ(ret, WMError::WM_OK);
559
560 scensession->property_->type_ = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
561 ret = ssm_->GetParentMainWindowId(windowId, mainWindowId);
562 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
563
564 scensession->property_->type_ = WindowType::WINDOW_TYPE_DIALOG;
565 ret = ssm_->GetParentMainWindowId(windowId, mainWindowId);
566 ASSERT_EQ(ret, WMError::WM_ERROR_NULLPTR);
567 }
568
569 /**
570 * @tc.name: NotifyVisibleChange
571 * @tc.desc: test NotifyVisibleChange
572 * @tc.type: FUNC
573 */
HWTEST_F(SceneSessionManagerTest10, NotifyVisibleChange, Function | SmallTest | Level3)574 HWTEST_F(SceneSessionManagerTest10, NotifyVisibleChange, Function | SmallTest | Level3)
575 {
576 SessionInfo info;
577 info.abilityName_ = "test";
578 info.bundleName_ = "test";
579 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
580 ASSERT_NE(nullptr, sceneSession);
581
582 ASSERT_FALSE(ssm_->NotifyVisibleChange(sceneSession->GetPersistentId()));
583 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
584 ASSERT_TRUE(ssm_->NotifyVisibleChange(sceneSession->GetPersistentId()));
585
586 ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
587 }
588
589 /**
590 * @tc.name: IsInSecondaryScreen
591 * @tc.desc: test IsInSecondaryScreen
592 * @tc.type: FUNC
593 */
HWTEST_F(SceneSessionManagerTest10, IsInSecondaryScreen, Function | SmallTest | Level3)594 HWTEST_F(SceneSessionManagerTest10, IsInSecondaryScreen, Function | SmallTest | Level3)
595 {
596 SessionInfo info;
597 info.abilityName_ = "test";
598 info.bundleName_ = "test";
599 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
600 ASSERT_NE(nullptr, sceneSession);
601 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
602 ASSERT_NE(nullptr, property);
603 DisplayId displayId = ScreenSessionManagerClient::GetInstance().GetDefaultScreenId();
604 property->SetDisplayId(displayId);
605 sceneSession->SetSessionProperty(property);
606 ASSERT_EQ(ssm_->IsInSecondaryScreen(sceneSession), false);
607
608 displayId = 5;
609 property->SetDisplayId(displayId);
610 sceneSession->SetSessionProperty(property);
611 ASSERT_EQ(ssm_->IsInSecondaryScreen(sceneSession), true);
612 }
613 } // namespace
614 }
615 }