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
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30
31 class SceneSessionManagerTest9 : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37
38 static sptr<SceneSessionManager> ssm_;
39 private:
40 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
41 };
42
43 sptr<SceneSessionManager> SceneSessionManagerTest9::ssm_ = nullptr;
44
NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)45 void NotifyRecoverSceneSessionFuncTest(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)
46 {
47 }
48
TraverseFuncTest(const sptr<SceneSession>& session)49 bool TraverseFuncTest(const sptr<SceneSession>& session)
50 {
51 return true;
52 }
53
WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)54 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
55 {
56 }
57
ProcessStatusBarEnabledChangeFuncTest(bool enable)58 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
59 {
60 }
61
DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)62 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
63 {
64 }
65
SetUpTestCase()66 void SceneSessionManagerTest9::SetUpTestCase()
67 {
68 ssm_ = &SceneSessionManager::GetInstance();
69 }
70
TearDownTestCase()71 void SceneSessionManagerTest9::TearDownTestCase()
72 {
73 ssm_ = nullptr;
74 }
75
SetUp()76 void SceneSessionManagerTest9::SetUp()
77 {
78 }
79
TearDown()80 void SceneSessionManagerTest9::TearDown()
81 {
82 usleep(WAIT_SYNC_IN_NS);
83 }
84
85 namespace {
86 /**
87 * @tc.name: TraverseSessionTreeFromTopToBottom
88 * @tc.desc: TraverseSessionTreeFromTopToBottom
89 * @tc.type: FUNC
90 */
HWTEST_F(SceneSessionManagerTest9, TraverseSessionTreeFromTopToBottom, Function | SmallTest | Level3)91 HWTEST_F(SceneSessionManagerTest9, TraverseSessionTreeFromTopToBottom, Function | SmallTest | Level3)
92 {
93 ASSERT_NE(nullptr, ssm_);
94 ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest);
95
96 SessionInfo sessionInfo;
97 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
98 sessionInfo.abilityName_ = "TraverseSessionTreeFromTopToBottom";
99 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
100 ASSERT_NE(nullptr, sceneSession);
101 ssm_->sceneSessionMap_.insert(std::make_pair(1, nullptr));
102 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession));
103 ssm_->TraverseSessionTreeFromTopToBottom(TraverseFuncTest);
104 }
105
106 /**
107 * @tc.name: RequestFocusStatus02
108 * @tc.desc: RequestFocusStatus
109 * @tc.type: FUNC
110 */
HWTEST_F(SceneSessionManagerTest9, RequestFocusStatus02, Function | SmallTest | Level3)111 HWTEST_F(SceneSessionManagerTest9, RequestFocusStatus02, Function | SmallTest | Level3)
112 {
113 ASSERT_NE(nullptr, ssm_);
114 EXPECT_EQ(ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE), WMError::WM_ERROR_NULLPTR);
115
116 SessionInfo sessionInfo;
117 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
118 sessionInfo.abilityName_ = "RequestFocusStatus02";
119 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
120 ASSERT_NE(nullptr, sceneSession);
121 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
122 ssm_->RequestFocusStatus(1, false, false, FocusChangeReason::FLOATING_SCENE);
123 }
124
125 /**
126 * @tc.name: RequestSessionFocusImmediately02
127 * @tc.desc: RequestSessionFocusImmediately
128 * @tc.type: FUNC
129 */
HWTEST_F(SceneSessionManagerTest9, RequestSessionFocusImmediately02, Function | SmallTest | Level3)130 HWTEST_F(SceneSessionManagerTest9, RequestSessionFocusImmediately02, Function | SmallTest | Level3)
131 {
132 ASSERT_NE(nullptr, ssm_);
133 ssm_->sceneSessionMap_.clear();
134 WSError ret = ssm_->RequestSessionFocusImmediately(0);
135 EXPECT_NE(ret, WSError::WS_OK);
136
137 ret = ssm_->RequestSessionFocusImmediately(2);
138 EXPECT_NE(ret, WSError::WS_OK);
139
140 SessionInfo sessionInfo;
141 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
142 sessionInfo.abilityName_ = "RequestSessionFocusImmediately02";
143 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
144
145 ASSERT_NE(nullptr, sceneSession);
146 sceneSession->SetFocusable(false);
147 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
148 ret = ssm_->RequestSessionFocusImmediately(1);
149 EXPECT_EQ(ret, WSError::WS_DO_NOTHING);
150
151 sceneSession->SetFocusable(true);
152 sceneSession->SetFocusedOnShow(false);
153 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
154 ret = ssm_->RequestSessionFocusImmediately(1);
155 EXPECT_EQ(ret, WSError::WS_DO_NOTHING);
156
157 sceneSession->SetFocusedOnShow(true);
158 sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
159 ret = ssm_->RequestSessionFocusImmediately(1);
160 EXPECT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
161
162 sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
163 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
164 ret = ssm_->RequestSessionFocusImmediately(1);
165 EXPECT_EQ(ret, WSError::WS_OK);
166 }
167
168 /**
169 * @tc.name: RequestSessionFocus02
170 * @tc.desc: RequestSessionFocus
171 * @tc.type: FUNC
172 */
HWTEST_F(SceneSessionManagerTest9, RequestSessionFocus02, Function | SmallTest | Level3)173 HWTEST_F(SceneSessionManagerTest9, RequestSessionFocus02, Function | SmallTest | Level3)
174 {
175 ASSERT_NE(nullptr, ssm_);
176 ssm_->sceneSessionMap_.clear();
177 SessionInfo sessionInfo;
178 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
179 sessionInfo.abilityName_ = "RequestSessionFocus02";
180 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
181 ASSERT_NE(nullptr, sceneSession);
182 sceneSession->SetFocusable(true);
183 sceneSession->UpdateVisibilityInner(true);
184 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
185 sceneSession->SetFocusedOnShow(false);
186 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
187 WSError ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
188 ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
189
190 sceneSession->SetFocusedOnShow(true);
191 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
192 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
193 ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
194 ASSERT_EQ(ret, WSError::WS_OK);
195
196 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
197 sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
198 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
199 ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
200 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_OPERATION);
201
202 sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
203 sceneSession->SetTopmost(true);
204 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
205 ret = ssm_->RequestSessionFocus(1, false, FocusChangeReason::DEFAULT);
206 ASSERT_EQ(ret, WSError::WS_OK);
207 ASSERT_EQ(sceneSession->isFocused_, true);
208 }
209
210 /**
211 * @tc.name: RequestSessionUnfocus02
212 * @tc.desc: RequestSessionUnfocus
213 * @tc.type: FUNC
214 */
HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest | Level3)215 HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest | Level3)
216 {
217 ASSERT_NE(nullptr, ssm_);
218 ssm_->sceneSessionMap_.clear();
219 WSError ret = ssm_->RequestSessionUnfocus(0, FocusChangeReason::DEFAULT);
220 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
221 ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
222 ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
223
224 SessionInfo sessionInfo;
225 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
226 sessionInfo.abilityName_ = "RequestSessionUnfocus02";
227 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
228 ASSERT_NE(nullptr, sceneSession);
229 ssm_->focusedSessionId_ = 2;
230 sceneSession->persistentId_ = 1;
231 sceneSession->SetZOrder(50);
232 sceneSession->state_ = SessionState::STATE_FOREGROUND;
233 sceneSession->isVisible_ = true;
234 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
235
236 SessionInfo sessionInfo1;
237 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
238 ASSERT_NE(nullptr, sceneSession1);
239 sceneSession1->GetSessionProperty()->SetParentPersistentId(1);
240 sceneSession1->persistentId_ = 2;
241 sceneSession1->SetZOrder(100);
242 ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1));
243 ret = ssm_->RequestSessionUnfocus(2, FocusChangeReason::DEFAULT);
244 ASSERT_EQ(ret, WSError::WS_OK);
245 ASSERT_EQ(ssm_->focusedSessionId_, 1);
246
247 ssm_->lastFocusedSessionId_ = 4;
248 sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
249 SessionInfo sessionInfo2;
250 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
251 ASSERT_NE(nullptr, sceneSession2);
252 sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_DESKTOP);
253 sceneSession2->SetZOrder(20);
254 sceneSession2->state_ = SessionState::STATE_FOREGROUND;
255 sceneSession2->isVisible_ = true;
256 sceneSession2->persistentId_ = 4;
257 ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession2));
258 ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT);
259 ASSERT_EQ(ret, WSError::WS_OK);
260 ASSERT_EQ(ssm_->focusedSessionId_, 4);
261 }
262
263 /**
264 * @tc.name: RequestAllAppSessionUnfocusInner
265 * @tc.desc: RequestAllAppSessionUnfocusInner
266 * @tc.type: FUNC
267 */
HWTEST_F(SceneSessionManagerTest9, RequestAllAppSessionUnfocusInner, Function | SmallTest | Level3)268 HWTEST_F(SceneSessionManagerTest9, RequestAllAppSessionUnfocusInner, Function | SmallTest | Level3)
269 {
270 ASSERT_NE(nullptr, ssm_);
271 ssm_->RequestAllAppSessionUnfocusInner();
272
273 SessionInfo sessionInfo;
274 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
275 sessionInfo.abilityName_ = "RequestAllAppSessionUnfocusInner";
276 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
277 ASSERT_NE(nullptr, sceneSession);
278 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
279 ssm_->focusedSessionId_ = 1;
280 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
281 ssm_->RequestAllAppSessionUnfocusInner();
282
283 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
284 ssm_->RequestAllAppSessionUnfocusInner();
285 }
286
287 /**
288 * @tc.name: UpdateFocus04
289 * @tc.desc: UpdateFocus
290 * @tc.type: FUNC
291 */
HWTEST_F(SceneSessionManagerTest9, UpdateFocus04, Function | SmallTest | Level3)292 HWTEST_F(SceneSessionManagerTest9, UpdateFocus04, Function | SmallTest | Level3)
293 {
294 ASSERT_NE(nullptr, ssm_);
295 SessionInfo sessionInfo;
296 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
297 sessionInfo.abilityName_ = "UpdateFocus04";
298 sessionInfo.isSystem_ = true;
299 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
300 ASSERT_NE(nullptr, sceneSession);
301 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
302 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
303 ssm_->focusedSessionId_ = 0;
304 sceneSession->UpdateFocus(false);
305 ssm_->UpdateFocus(1, false);
306
307 sessionInfo.isSystem_ = false;
308 ssm_->focusedSessionId_ = 1;
309 sceneSession->UpdateFocus(true);
310 ssm_->UpdateFocus(1, false);
311
312 sceneSession->UpdateFocus(false);
313 ssm_->UpdateFocus(1, true);
314 }
315
316 /**
317 * @tc.name: ProcessFocusWhenForeground
318 * @tc.desc: ProcessFocusWhenForeground
319 * @tc.type: FUNC
320 */
HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground, Function | SmallTest | Level3)321 HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground, Function | SmallTest | Level3)
322 {
323 ASSERT_NE(nullptr, ssm_);
324 SessionInfo sessionInfo;
325 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
326 sessionInfo.abilityName_ = "ProcessFocusWhenForeground";
327 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
328 ASSERT_NE(nullptr, sceneSession);
329 sceneSession->persistentId_ = 1;
330 ASSERT_NE(nullptr, sceneSession->property_);
331 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
332 ssm_->focusedSessionId_ = 1;
333 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
334 ssm_->ProcessFocusWhenForeground(sceneSession);
335
336 sceneSession->isVisible_ = true;
337 sceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
338 ssm_->ProcessFocusWhenForeground(sceneSession);
339 }
340
341 /**
342 * @tc.name: ProcessSubSessionForeground03
343 * @tc.desc: ProcessSubSessionForeground
344 * @tc.type: FUNC
345 */
HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | SmallTest | Level3)346 HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | SmallTest | Level3)
347 {
348 ASSERT_NE(nullptr, ssm_);
349 SessionInfo sessionInfo;
350 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
351 sessionInfo.abilityName_ = "ProcessSubSessionForeground03";
352 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
353 ASSERT_NE(nullptr, sceneSession);
354
355 SessionInfo subSessionInfo;
356 sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(subSessionInfo, nullptr);
357 ASSERT_NE(nullptr, subSceneSession);
358 subSceneSession->SetTopmost(true);
359 subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
360 subSceneSession->persistentId_ = 1;
361 sceneSession->GetSubSession().push_back(subSceneSession);
362 ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession));
363
364 ssm_->focusedSessionId_ = 1;
365 ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
366
367 SessionInfo subSessionInfo1;
368 sptr<SceneSession> subSceneSession1 = sptr<SceneSession>::MakeSptr(subSessionInfo1, nullptr);
369 ASSERT_NE(nullptr, subSceneSession1);
370 subSceneSession1->SetTopmost(true);
371 subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
372 subSceneSession1->persistentId_ = 0;
373 sceneSession->GetSubSession().push_back(subSceneSession1);
374
375 SessionInfo subSessionInfo2;
376 sptr<SceneSession> subSceneSession2 = sptr<SceneSession>::MakeSptr(subSessionInfo2, nullptr);
377 ASSERT_NE(nullptr, subSceneSession2);
378 subSceneSession2->SetTopmost(true);
379 subSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
380 sceneSession->GetSubSession().push_back(subSceneSession2);
381
382 SessionInfo subSessionInfo3;
383 sptr<SceneSession> subSceneSession3 = sptr<SceneSession>::MakeSptr(subSessionInfo3, nullptr);
384 ASSERT_NE(nullptr, subSceneSession3);
385 subSceneSession3->SetTopmost(false);
386 subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE);
387 sceneSession->GetSubSession().push_back(subSceneSession3);
388
389 sceneSession->GetSubSession().push_back(nullptr);
390
391 ssm_->ProcessSubSessionForeground(sceneSession);
392
393 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
394 ssm_->ProcessSubSessionForeground(sceneSession);
395
396 ssm_->focusedSessionId_ = 2;
397 ssm_->ProcessSubSessionForeground(sceneSession);
398 }
399
400 /**
401 * @tc.name: ProcessModalTopmostRequestFocusImmdediately02
402 * @tc.desc: ProcessModalTopmostRequestFocusImmdediately
403 * @tc.type: FUNC
404 */
HWTEST_F(SceneSessionManagerTest9, ProcessModalTopmostRequestFocusImmdediately02, Function | SmallTest | Level3)405 HWTEST_F(SceneSessionManagerTest9, ProcessModalTopmostRequestFocusImmdediately02, Function | SmallTest | Level3)
406 {
407 ASSERT_NE(nullptr, ssm_);
408 SessionInfo sessionInfo;
409 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
410 sessionInfo.abilityName_ = "ProcessModalTopmostRequestFocusImmdediately02";
411 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
412 ASSERT_NE(nullptr, sceneSession);
413
414 SessionInfo subSessionInfo;
415 sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(subSessionInfo, nullptr);
416 ASSERT_NE(nullptr, subSceneSession);
417 subSceneSession->SetTopmost(true);
418 subSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
419 subSceneSession->persistentId_ = 1;
420 subSceneSession->SetFocusable(true);
421 subSceneSession->SetFocusedOnShow(true);
422 sceneSession->GetSubSession().push_back(subSceneSession);
423
424 ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession));
425 ssm_->focusedSessionId_ = 1;
426 ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
427
428 SessionInfo subSessionInfo1;
429 sptr<SceneSession> subSceneSession1 = sptr<SceneSession>::MakeSptr(subSessionInfo1, nullptr);
430 ASSERT_NE(nullptr, subSceneSession1);
431 subSceneSession1->SetTopmost(true);
432 subSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
433 subSceneSession1->persistentId_ = 0;
434 sceneSession->GetSubSession().push_back(subSceneSession1);
435
436 SessionInfo subSessionInfo2;
437 sptr<SceneSession> subSceneSession2 = sptr<SceneSession>::MakeSptr(subSessionInfo2, nullptr);
438 ASSERT_NE(nullptr, subSceneSession2);
439 subSceneSession2->SetTopmost(true);
440 subSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
441 sceneSession->GetSubSession().push_back(subSceneSession2);
442
443 SessionInfo subSessionInfo3;
444 sptr<SceneSession> subSceneSession3 = sptr<SceneSession>::MakeSptr(subSessionInfo3, nullptr);
445 ASSERT_NE(nullptr, subSceneSession3);
446 subSceneSession3->SetTopmost(false);
447 subSceneSession3->SetSessionState(SessionState::STATE_ACTIVE);
448 sceneSession->GetSubSession().push_back(subSceneSession3);
449
450 sceneSession->GetSubSession().push_back(nullptr);
451
452 WSError ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
453 ASSERT_NE(ret, WSError::WS_OK);
454
455 ssm_->needBlockNotifyFocusStatusUntilForeground_ = false;
456 ssm_->ProcessSubSessionForeground(sceneSession);
457
458 subSceneSession->persistentId_ = 0;
459 ret = ssm_->ProcessModalTopmostRequestFocusImmdediately(sceneSession);
460 ASSERT_NE(ret, WSError::WS_OK);
461 }
462
463 /**
464 * @tc.name: ProcessDialogRequestFocusImmdediately02
465 * @tc.desc: ProcessDialogRequestFocusImmdediately
466 * @tc.type: FUNC
467 */
HWTEST_F(SceneSessionManagerTest9, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)468 HWTEST_F(SceneSessionManagerTest9, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)
469 {
470 ASSERT_NE(nullptr, ssm_);
471 SessionInfo sessionInfo;
472 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
473 sessionInfo.abilityName_ = "ProcessDialogRequestFocusImmdediately02";
474 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
475 ASSERT_NE(nullptr, sceneSession);
476 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
477
478 SessionInfo dialogSessionInfo;
479 sptr<SceneSession> dialogSceneSession = sptr<SceneSession>::MakeSptr(dialogSessionInfo, nullptr);
480 ASSERT_NE(nullptr, dialogSceneSession);
481 dialogSceneSession->SetTopmost(true);
482 dialogSceneSession->SetSessionState(SessionState::STATE_FOREGROUND);
483 dialogSceneSession->persistentId_ = 1;
484 dialogSceneSession->SetFocusable(true);
485 dialogSceneSession->SetFocusedOnShow(true);
486 sceneSession->GetDialogVector().push_back(dialogSceneSession);
487
488 ssm_->sceneSessionMap_.insert(std::make_pair(1, dialogSceneSession));
489 ssm_->focusedSessionId_ = 1;
490 ssm_->needBlockNotifyFocusStatusUntilForeground_ = true;
491
492 SessionInfo dialogSessionInfo1;
493 sptr<SceneSession> dialogSceneSession1 = sptr<SceneSession>::MakeSptr(dialogSessionInfo1, nullptr);
494 ASSERT_NE(nullptr, dialogSceneSession1);
495 dialogSceneSession1->SetTopmost(true);
496 dialogSceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
497 dialogSceneSession1->persistentId_ = 0;
498 sceneSession->GetDialogVector().push_back(dialogSceneSession1);
499
500 SessionInfo dialogSessionInfo2;
501 sptr<SceneSession> dialogSceneSession2 = sptr<SceneSession>::MakeSptr(dialogSessionInfo2, nullptr);
502 ASSERT_NE(nullptr, dialogSceneSession2);
503 dialogSceneSession2->SetTopmost(true);
504 dialogSceneSession2->SetSessionState(SessionState::STATE_CONNECT);
505 sceneSession->GetDialogVector().push_back(dialogSceneSession2);
506
507 sceneSession->GetDialogVector().push_back(nullptr);
508
509 WSError ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
510 ASSERT_NE(ret, WSError::WS_OK);
511
512 dialogSceneSession->persistentId_ = 0;
513 ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
514 ASSERT_NE(ret, WSError::WS_OK);
515 }
516
517 /**
518 * @tc.name: NotifyCompleteFirstFrameDrawing03
519 * @tc.desc: NotifyCompleteFirstFrameDrawing
520 * @tc.type: FUNC
521 */
HWTEST_F(SceneSessionManagerTest9, NotifyCompleteFirstFrameDrawing03, Function | SmallTest | Level3)522 HWTEST_F(SceneSessionManagerTest9, NotifyCompleteFirstFrameDrawing03, Function | SmallTest | Level3)
523 {
524 ASSERT_NE(nullptr, ssm_);
525 SessionInfo sessionInfo;
526 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
527 sessionInfo.abilityName_ = "NotifyCompleteFirstFrameDrawing03";
528 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
529 abilityInfo->excludeFromMissions = true;
530 sessionInfo.abilityInfo = abilityInfo;
531 sessionInfo.isSystem_ = true;
532 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
533 ASSERT_NE(nullptr, sceneSession);
534 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
535 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
536 ssm_->NotifyCompleteFirstFrameDrawing(1);
537
538 sessionInfo.isSystem_ = false;
539 ssm_->eventHandler_ = nullptr;
540 ssm_->NotifyCompleteFirstFrameDrawing(1);
541
542 std::shared_ptr<AppExecFwk::EventHandler> eventHandler = std::make_shared<AppExecFwk::EventHandler>();
543 ssm_->eventHandler_ = eventHandler;
544 abilityInfo->excludeFromMissions = false;
545 ssm_->NotifyCompleteFirstFrameDrawing(1);
546 }
547
548 /**
549 * @tc.name: SetSessionLabel02
550 * @tc.desc: SetSessionLabel
551 * @tc.type: FUNC
552 */
HWTEST_F(SceneSessionManagerTest9, SetSessionLabel02, Function | SmallTest | Level3)553 HWTEST_F(SceneSessionManagerTest9, SetSessionLabel02, Function | SmallTest | Level3)
554 {
555 ASSERT_NE(nullptr, ssm_);
556 SessionInfo sessionInfo;
557 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
558 sessionInfo.abilityName_ = "SetSessionLabel02";
559 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
560 ASSERT_NE(nullptr, sceneSession);
561 sptr<IRemoteObject> token = new (std::nothrow) MockIRemoteObject();
562 ASSERT_NE(nullptr, token);
563 sceneSession->SetAbilityToken(token);
564 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
565
566 std::string label = "testLabel";
567 ssm_->SetSessionLabel(token, label);
568
569 sessionInfo.isSystem_ = false;
570 ssm_->SetSessionLabel(token, label);
571
572 sessionInfo.isSystem_ = true;
573 ssm_->SetSessionLabel(token, label);
574 }
575
576 /**
577 * @tc.name: RecoverAndReconnectSceneSession02
578 * @tc.desc: RecoverAndReconnectSceneSession
579 * @tc.type: FUNC
580 */
HWTEST_F(SceneSessionManagerTest9, RecoverAndReconnectSceneSession02, Function | SmallTest | Level3)581 HWTEST_F(SceneSessionManagerTest9, RecoverAndReconnectSceneSession02, Function | SmallTest | Level3)
582 {
583 ASSERT_NE(nullptr, ssm_);
584 SessionInfo sessionInfo;
585 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
586 sessionInfo.abilityName_ = "RecoverAndReconnectSceneSession02";
587 sessionInfo.moduleName_ = "moduleTest";
588 sessionInfo.appIndex_ = 10;
589 sessionInfo.persistentId_ = 1;
590 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
591 abilityInfo->excludeFromMissions = true;
592 sessionInfo.abilityInfo = abilityInfo;
593 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
594 ASSERT_NE(nullptr, sceneSession);
595
596 sptr<WindowSessionProperty> property = sceneSession->GetSessionProperty();
597 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
598 property->SetPersistentId(1);
599 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
600 property->SetWindowState(WindowState::STATE_SHOWN);
601 property->SetRequestedOrientation(Orientation::UNSPECIFIED);
602 ssm_->alivePersistentIds_.push_back(1);
603 ssm_->recoveringFinished_ = false;
604 ssm_->recoverSceneSessionFunc_ = NotifyRecoverSceneSessionFuncTest;
605
606 sptr<ISession> session;
607 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
608 auto result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr);
609 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
610
611 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
612 property->SetPersistentId(0);
613 result = ssm_->RecoverAndReconnectSceneSession(nullptr, nullptr, nullptr, session, property, nullptr);
614 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
615 }
616
617 /**
618 * @tc.name: RefreshPcZorder
619 * @tc.desc: RefreshPcZorder
620 * @tc.type: FUNC
621 */
HWTEST_F(SceneSessionManagerTest9, RefreshPcZorder, Function | SmallTest | Level3)622 HWTEST_F(SceneSessionManagerTest9, RefreshPcZorder, Function | SmallTest | Level3) {
623 std::vector<int32_t> persistentIds;
624 SessionInfo info1;
625 info1.abilityName_ = "RefreshPcZorder1";
626 info1.bundleName_ = "RefreshPcZorder1";
627 sptr<SceneSession> session1 = sptr<SceneSession>::MakeSptr(info1, nullptr);
628 ASSERT_NE(session1, nullptr);
629 persistentIds.push_back(session1->GetPersistentId());
630 ssm_->sceneSessionMap_.insert({session1->GetPersistentId(), session1});
631 SessionInfo info2;
632 info2.abilityName_ = "RefreshPcZorder2";
633 info2.bundleName_ = "RefreshPcZorder2";
634 sptr<SceneSession> session2 = sptr<SceneSession>::MakeSptr(info2, nullptr);
635 ASSERT_NE(session2, nullptr);
636 persistentIds.push_back(session2->GetPersistentId());
637 ssm_->sceneSessionMap_.insert({session2->GetPersistentId(), session2});
638 SessionInfo info3;
639 info3.abilityName_ = "RefreshPcZorder3";
640 info3.bundleName_ = "RefreshPcZorder3";
641 sptr<SceneSession> session3 = sptr<SceneSession>::MakeSptr(info3, nullptr);
642 ASSERT_NE(session3, nullptr);
643 session3->SetZOrder(404);
644 ssm_->sceneSessionMap_.insert({session3->GetPersistentId(), session3});
645 persistentIds.push_back(999);
646 uint32_t startZOrder = 100;
647 std::vector<int32_t> newPersistentIds = persistentIds;
648 ssm_->RefreshPcZOrderList(startZOrder, std::move(persistentIds));
649 ssm_->RefreshPcZOrderList(UINT32_MAX, std::move(newPersistentIds));
650 auto start = std::chrono::system_clock::now();
651 // Due to RefreshPcZOrderList being asynchronous, spin lock is added.
652 // The spin lock itself is set with a timeout escape time of 3 seconds
653 while (true) {
654 if ((session1->GetZOrder() != 0 && session2->GetZOrder() != 0 && session1->GetZOrder() != 100) ||
655 std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - start).count() >= 3) {
656 break;
657 }
658 std::this_thread::sleep_for(std::chrono::milliseconds(100));
659 }
660 ASSERT_EQ(session2->GetZOrder(), 101);
661 ASSERT_EQ(session3->GetZOrder(), 404);
662 ASSERT_EQ(session1->GetZOrder(), UINT32_MAX);
663 }
664
665 /**
666 * @tc.name: GetSessionRSVisible
667 * @tc.desc: GetSessionRSVisible
668 * @tc.type: FUNC
669 */
HWTEST_F(SceneSessionManagerTest9, GetSessionRSVisible, Function | SmallTest | Level3)670 HWTEST_F(SceneSessionManagerTest9, GetSessionRSVisible, Function | SmallTest | Level3)
671 {
672 ASSERT_NE(nullptr, ssm_);
673 SessionInfo sessionInfo;
674 sessionInfo.bundleName_ = "SceneSessionManagerTest9";
675 sessionInfo.abilityName_ = "GetSessionRSVisible";
676 sessionInfo.moduleName_ = "moduleTest";
677 uint64_t windowId = 10;
678 sptr<SceneSession> sceneSession01 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
679 sceneSession01->persistentId_ = windowId;
680 sptr<SceneSession> sceneSession02 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
681 std::vector<std::pair<uint64_t, WindowVisibilityState>> currVisibleData;
682 currVisibleData.push_back(std::make_pair(0, WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION));
683 currVisibleData.push_back(std::make_pair(1, WindowVisibilityState::WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION));
684 struct RSSurfaceNodeConfig config;
685 sceneSession02->surfaceNode_ = RSSurfaceNode::Create(config);
686 ASSERT_NE(nullptr, sceneSession02->surfaceNode_);
687 sceneSession02->surfaceNode_->id_ = 0;
688 sceneSession02->persistentId_ = windowId;
689 ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession02));
690
691 bool actual = ssm_->GetSessionRSVisible(sceneSession01, currVisibleData);
692 EXPECT_EQ(actual, true);
693 }
694
695 /**
696 * @tc.name: CheckClickFocusIsDownThroughFullScreen
697 * @tc.desc: CheckClickFocusIsDownThroughFullScreen
698 * @tc.type: FUNC
699 */
HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen, Function | SmallTest | Level3)700 HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen, Function | SmallTest | Level3)
701 {
702 ASSERT_NE(ssm_, nullptr);
703 SessionInfo info;
704 info.abilityName_ = "test1";
705 info.bundleName_ = "test2";
706
707 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info, nullptr);
708 ASSERT_NE(focusedSession, nullptr);
709 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
710 ASSERT_NE(sceneSession, nullptr);
711 bool ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT);
712 ASSERT_EQ(ret, false);
713
714 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
715 ASSERT_NE(property, nullptr);
716 property->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
717 focusedSession->SetSessionProperty(property);
718 ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT);
719 ASSERT_EQ(ret, false);
720
721 sceneSession->SetZOrder(50);
722 focusedSession->SetZOrder(100);
723 focusedSession->blockingFocus_ = true;
724 ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::CLICK);
725 ASSERT_EQ(ret, true);
726 }
727
728 /**
729 * @tc.name: ShiftFocus
730 * @tc.desc: ShiftFocus
731 * @tc.type: FUNC
732 */
HWTEST_F(SceneSessionManagerTest9, ShiftFocus, Function | SmallTest | Level3)733 HWTEST_F(SceneSessionManagerTest9, ShiftFocus, Function | SmallTest | Level3)
734 {
735 ASSERT_NE(ssm_, nullptr);
736 ssm_->sceneSessionMap_.clear();
737 SessionInfo info;
738 info.abilityName_ = "test1";
739 info.bundleName_ = "test2";
740 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info, nullptr);
741 ASSERT_NE(focusedSession, nullptr);
742 sptr<SceneSession> nextSession = new (std::nothrow) SceneSession(info, nullptr);
743 ASSERT_NE(nextSession, nullptr);
744 focusedSession->persistentId_ = 1;
745 nextSession->persistentId_ = 4;
746 ssm_->sceneSessionMap_.insert({1, focusedSession});
747 ssm_->sceneSessionMap_.insert({4, nextSession});
748 ssm_->focusedSessionId_ = 1;
749 WSError ret = ssm_->ShiftFocus(nextSession, FocusChangeReason::DEFAULT);
750 ASSERT_EQ(ret, WSError::WS_OK);
751 ASSERT_EQ(focusedSession->isFocused_, false);
752 ASSERT_EQ(nextSession->isFocused_, true);
753 }
754 }
755 } // namespace Rosen
756 } // namespace OHOS