1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <regex>
18 #include <bundle_mgr_interface.h>
19 #include <bundle_mgr_proxy.h>
20 #include <bundlemgr/launcher_service.h>
21 #include "iremote_object_mocker.h"
22 #include "interfaces/include/ws_common.h"
23 #include "iremote_object_mocker.h"
24 #include "session_manager/include/scene_session_manager.h"
25 #include "session_manager/include/screen_session_manager.h"
26 #include "session_info.h"
27 #include "session/host/include/scene_session.h"
28 #include "session/host/include/main_session.h"
29 #include "window_manager_agent.h"
30 #include "session_manager.h"
31 #include "zidl/window_manager_agent_interface.h"
32 #include "mock/mock_session_stage.h"
33 #include "mock/mock_window_event_channel.h"
34 #include "context.h"
35
36 using namespace testing;
37 using namespace testing::ext;
38
39 namespace OHOS {
40 namespace Rosen {
41
42 class SceneSessionManagerTest5 : public testing::Test {
43 public:
44 static void SetUpTestCase();
45
46 static void TearDownTestCase();
47
48 void SetUp() override;
49
50 void TearDown() override;
51
52 static bool gestureNavigationEnabled_;
53
54 static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
55 static sptr<SceneSessionManager> ssm_;
56
57 private:
58 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
59 };
60
61 sptr<SceneSessionManager> SceneSessionManagerTest5::ssm_ = nullptr;
62 bool SceneSessionManagerTest5::gestureNavigationEnabled_ = true;
63
64 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest5::callbackFunc_ = [](bool enable,
__anon79240c1b0102(bool enable, const std::string& bundleName, GestureBackType type) 65 const std::string& bundleName, GestureBackType type) {
66 gestureNavigationEnabled_ = enable;
67 };
68
69
WindowChangedFuncTest(int32_t persistentId,WindowUpdateType type)70 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
71 {
72 }
73
ProcessStatusBarEnabledChangeFuncTest(bool enable)74 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
75 {
76 }
77
DumpRootSceneElementInfoFuncTest(const std::vector<std::string> & params,std::vector<std::string> & infos)78 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
79 {
80 }
81
SetUpTestCase()82 void SceneSessionManagerTest5::SetUpTestCase()
83 {
84 ssm_ = &SceneSessionManager::GetInstance();
85 }
86
TearDownTestCase()87 void SceneSessionManagerTest5::TearDownTestCase()
88 {
89 ssm_->sceneSessionMap_.clear();
90 ssm_ = nullptr;
91 }
92
SetUp()93 void SceneSessionManagerTest5::SetUp()
94 {
95 ssm_->sceneSessionMap_.clear();
96 }
97
TearDown()98 void SceneSessionManagerTest5::TearDown()
99 {
100 ssm_->sceneSessionMap_.clear();
101 usleep(WAIT_SYNC_IN_NS);
102 }
103
104 namespace {
105 /**
106 * @tc.name: NotifySessionTouchOutside
107 * @tc.desc: SceneSesionManager notify session touch outside
108 * @tc.type: FUNC
109 */
110 HWTEST_F(SceneSessionManagerTest5, NotifySessionTouchOutside01, Function | SmallTest | Level3)
111 {
112 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
113 ASSERT_NE(ssm_, nullptr);
114 ssm_->recoveringFinished_ = false;
115 SessionInfo info;
116 info.abilityName_ = "test1";
117 info.bundleName_ = "test2";
118 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
119 property->SetWindowType(WindowType::APP_WINDOW_BASE);
120 ssm_->NotifySessionTouchOutside(0);
121 property->SetPersistentId(1);
122 ssm_->NotifySessionTouchOutside(1);
123 }
124
125 /**
126 * @tc.name: DestroyAndDisconnectSpecificSessionInner
127 * @tc.desc: check func DestroyAndDisconnectSpecificSessionInner
128 * @tc.type: FUNC
129 */
130 HWTEST_F(SceneSessionManagerTest5, DestroyAndDisconnectSpecificSessionInner, Function | SmallTest | Level2)
131 {
132 sptr<ISession> session;
133 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
134 ASSERT_NE(nullptr, property);
135 std::vector<int32_t> recoveredPersistentIds = {0, 1, 2};
136 ssm_->SetAlivePersistentIds(recoveredPersistentIds);
137 ProcessShiftFocusFunc shiftFocusFunc_;
138 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
139 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
140 property->SetPersistentId(1);
141 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
142
143 property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
144 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
145 }
146
147
148 /**
149 * @tc.name: DestroyAndDisconnectSpecificSessionWithDetachCallback
150 * @tc.desc: SceneSesionManager destroy and disconnect specific session with detach callback
151 * @tc.type: FUNC
152 */
153 HWTEST_F(SceneSessionManagerTest5, DestroyAndDetachCallback, Function | SmallTest | Level3)
154 {
155 int32_t persistentId = 0;
156 ASSERT_NE(ssm_, nullptr);
157 sptr<IRemoteObject> callback = new (std::nothrow) IRemoteObjectMocker();
158 ASSERT_NE(callback, nullptr);
159 ssm_->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
160 sptr<WindowSessionProperty> property;
161 ssm_->recoveringFinished_ = false;
162 SessionInfo info;
163 info.abilityName_ = "test1";
164 info.bundleName_ = "test2";
165 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
166 ssm_->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
167 }
168
169 /**
170 * @tc.name: GetStartupPageFromResource
171 * @tc.desc: GetStartupPageFromResource
172 * @tc.type: FUNC
173 */
174 HWTEST_F(SceneSessionManagerTest5, GetStartupPageFromResource, Function | SmallTest | Level3)
175 {
176 ASSERT_NE(ssm_, nullptr);
177 AppExecFwk::AbilityInfo info;
178 info.startWindowBackgroundId = 1;
179 std::string path = "path";
180 uint32_t bgColor = 1;
181 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
182 info.startWindowIconId = 0;
183 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
184 info.hapPath = "hapPath";
185 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
186 }
187
188 /**
189 * @tc.name: GetStartupPage
190 * @tc.desc: GetStartupPage
191 * @tc.type: FUNC
192 */
193 HWTEST_F(SceneSessionManagerTest5, GetStartupPage, Function | SmallTest | Level3)
194 {
195 ASSERT_NE(ssm_, nullptr);
196 SessionInfo info;
197 info.abilityName_ = "test1";
198 info.bundleName_ = "test2";
199 sptr<AppExecFwk::IBundleMgr> bundleMgr_ = nullptr;
200 std::string path = "path";
201 uint32_t bgColor = 1;
202 ssm_->GetStartupPage(info, path, bgColor);
203 }
204
205 /**
206 * @tc.name: OnSCBSystemSessionBufferAvailable
207 * @tc.desc: OnSCBSystemSessionBufferAvailable
208 * @tc.type: FUNC
209 */
210 HWTEST_F(SceneSessionManagerTest5, OnSCBSystemSessionBufferAvailable02, Function | SmallTest | Level3)
211 {
212 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
213 ASSERT_NE(sceneSessionManager, nullptr);
214 sceneSessionManager->OnSCBSystemSessionBufferAvailable(WindowType::WINDOW_TYPE_FLOAT);
215 delete sceneSessionManager;
216 }
217
218 /**
219 * @tc.name: CreateKeyboardPanelSession
220 * @tc.desc: CreateKeyboardPanelSession
221 * @tc.type: FUNC
222 */
223 HWTEST_F(SceneSessionManagerTest5, CreateKeyboardPanelSession, Function | SmallTest | Level3)
224 {
225 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
226 ASSERT_NE(sceneSessionManager, nullptr);
227 SessionInfo info;
228 info.abilityName_ = "test1";
229 info.bundleName_ = "test2";
230 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
231 ASSERT_NE(property, nullptr);
232 property->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
233 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
234 sceneSessionManager->CreateKeyboardPanelSession(sceneSession);
235 delete sceneSessionManager;
236 }
237
238 /**
239 * @tc.name: PrepareTerminate
240 * @tc.desc: SceneSesionManager prepare terminate
241 * @tc.type: FUNC
242 */
243 HWTEST_F(SceneSessionManagerTest5, PrepareTerminate, Function | SmallTest | Level3)
244 {
245 int32_t persistentId = 1;
246 bool isPrepareTerminate = true;
247 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
248 ASSERT_NE(sceneSessionManager, nullptr);
249 ASSERT_EQ(WSError::WS_OK, sceneSessionManager->PrepareTerminate(persistentId, isPrepareTerminate));
250 delete sceneSessionManager;
251 }
252
253 /**
254 * @tc.name: IsKeyboardForeground
255 * @tc.desc: IsKeyboardForeground
256 * @tc.type: FUNC
257 */
258 HWTEST_F(SceneSessionManagerTest5, IsKeyboardForeground, Function | SmallTest | Level3)
259 {
260 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
261 ASSERT_NE(sceneSessionManager, nullptr);
262 SessionInfo info;
263 info.abilityName_ = "test1";
264 info.bundleName_ = "test2";
265 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
266 ASSERT_NE(property, nullptr);
267 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
268 sceneSessionManager->IsKeyboardForeground();
269 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
270 sceneSessionManager->IsKeyboardForeground();
271 delete sceneSessionManager;
272 }
273
274 /**
275 * @tc.name: RequestInputMethodCloseKeyboard
276 * @tc.desc: RequestInputMethodCloseKeyboard
277 * @tc.type: FUNC
278 */
279 HWTEST_F(SceneSessionManagerTest5, RequestInputMethodCloseKeyboard02, Function | SmallTest | Level3)
280 {
281 int32_t persistentId = -1;
282 bool isPrepareTerminate = true;
283 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
284 ASSERT_NE(sceneSessionManager, nullptr);
285 sceneSessionManager->PrepareTerminate(persistentId, isPrepareTerminate);
286 delete sceneSessionManager;
287 }
288
289 /**
290 * @tc.name: HandleSpecificSystemBarProperty
291 * @tc.desc: HandleSpecificSystemBarProperty
292 * @tc.type: FUNC
293 */
294 HWTEST_F(SceneSessionManagerTest5, HandleSpecificSystemBarProperty, Function | SmallTest | Level3)
295 {
296 ASSERT_NE(ssm_, nullptr);
297 SessionInfo info;
298 info.abilityName_ = "test1";
299 info.bundleName_ = "test2";
300 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
301 ASSERT_NE(property, nullptr);
302 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
303 WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR;
304 ssm_->HandleSpecificSystemBarProperty(type, property, sceneSession);
305 }
306
307 /**
308 * @tc.name: UpdateBrightness
309 * @tc.desc: UpdateBrightness
310 * @tc.type: FUNC
311 */
312 HWTEST_F(SceneSessionManagerTest5, UpdateBrightness, Function | SmallTest | Level3)
313 {
314 ASSERT_NE(ssm_, nullptr);
315 SessionInfo info;
316 info.abilityName_ = "test1";
317 info.bundleName_ = "test2";
318 info.isSystem_ = false;
319 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
320 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
321 ASSERT_NE(property, nullptr);
322 ssm_->UpdateBrightness(1);
323 FocusChangeInfo focusInfo;
324 ssm_->GetCurrentUserId();
325 ssm_->GetFocusWindowInfo(focusInfo);
326 }
327
328 /**
329 * @tc.name: RegisterSessionSnapshotFunc
330 * @tc.desc: RegisterSessionSnapshotFunc
331 * @tc.type: FUNC
332 */
333 HWTEST_F(SceneSessionManagerTest5, RegisterSessionSnapshotFunc, Function | SmallTest | Level3)
334 {
335 SessionInfo info;
336 info.abilityName_ = "test1";
337 info.bundleName_ = "test2";
338 sptr<SceneSession> scensession = nullptr;
339 ssm_->RegisterSessionSnapshotFunc(scensession);
340 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
341 ASSERT_NE(property, nullptr);
342 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
343 ASSERT_NE(sceneSession, nullptr);
344 ssm_->RegisterSessionSnapshotFunc(scensession);
345 info.isSystem_ = false;
346 ssm_->RegisterSessionSnapshotFunc(scensession);
347 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo;
348 ssm_->RegisterSessionSnapshotFunc(scensession);
349 }
350
351 /**
352 * @tc.name: RequestAllAppSessionUnfocus
353 * @tc.desc: RequestAllAppSessionUnfocus
354 * @tc.type: FUNC
355 */
356 HWTEST_F(SceneSessionManagerTest5, RequestAllAppSessionUnfocus, Function | SmallTest | Level3)
357 {
358 SessionInfo info;
359 info.abilityName_ = "test1";
360 info.bundleName_ = "test2";
361 sptr<SceneSession> scensession = nullptr;
362 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
363 ASSERT_NE(property, nullptr);
364 scensession = new (std::nothrow) SceneSession(info, nullptr);
365 ASSERT_NE(scensession, nullptr);
366 ssm_->HandleHideNonSystemFloatingWindows(property, scensession);
367 ssm_->RequestAllAppSessionUnfocus();
368 }
369
370 /**
371 * @tc.name: RequestSessionFocus
372 * @tc.desc: RequestSessionFocus
373 * @tc.type: FUNC
374 */
375 HWTEST_F(SceneSessionManagerTest5, RequestSessionFocus, Function | SmallTest | Level3)
376 {
377 SessionInfo info;
378 info.abilityName_ = "test1";
379 info.bundleName_ = "test2";
380 sptr<SceneSession> scensession = nullptr;
381 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
382 ASSERT_NE(property, nullptr);
383 property->SetFocusable(false);
384 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
385 ASSERT_NE(sceneSession, nullptr);
386 FocusChangeReason reason = FocusChangeReason::DEFAULT;
387 ssm_->RequestSessionFocus(0, true, reason);
388 ssm_->RequestSessionFocus(100, true, reason);
389 }
390
391 /**
392 * @tc.name: SetShiftFocusListener
393 * @tc.desc: SetShiftFocusListener
394 * @tc.type: FUNC
395 */
396 HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | Level3)
397 {
398 ASSERT_NE(ssm_, nullptr);
399 SessionInfo info;
400 info.abilityName_ = "test1";
401 info.bundleName_ = "test2";
402 FocusChangeReason reason = FocusChangeReason::SPLIT_SCREEN;
403 sptr<SceneSession> scensession = nullptr;
404 ssm_->ShiftFocus(scensession, false, reason);
405 info.isSystem_ = true;
406 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
407 ASSERT_NE(property, nullptr);
408 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
409 ASSERT_NE(sceneSession, nullptr);
410 ProcessShiftFocusFunc fun;
411 NotifySCBAfterUpdateFocusFunc func;
412 ssm_->SetShiftFocusListener(fun);
413 ssm_->SetSCBFocusedListener(func);
414 ssm_->SetSCBUnfocusedListener(func);
415 ProcessCallingSessionIdChangeFunc func1;
416 ssm_->SetCallingSessionIdSessionListenser(func1);
417 ProcessStartUIAbilityErrorFunc func2;
418 ssm_->SetStartUIAbilityErrorListener(func2);
419 ssm_->ShiftFocus(sceneSession, false, reason);
420 }
421
422 /**
423 * @tc.name: UpdateFocusStatus
424 * @tc.desc: UpdateFocusStatus
425 * @tc.type: FUNC
426 */
427 HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus, Function | SmallTest | Level3)
428 {
429 ASSERT_NE(ssm_, nullptr);
430 SessionInfo info;
431 info.abilityName_ = "test1";
432 info.bundleName_ = "test2";
433 sptr<SceneSession> scensession = nullptr;
434 ssm_->UpdateFocusStatus(scensession, false);
435 ssm_->UpdateFocusStatus(scensession, true);
436
437 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
438 ASSERT_NE(property, nullptr);
439 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
440 ASSERT_NE(sceneSession, nullptr);
441 ssm_->UpdateFocusStatus(sceneSession, true);
442 ssm_->UpdateFocusStatus(sceneSession, false);
443 }
444
445 /**
446 * @tc.name: RequestSessionUnfocus
447 * @tc.desc: RequestSessionUnfocus
448 * @tc.type: FUNC
449 */
450 HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus, Function | SmallTest | Level3)
451 {
452 SessionInfo info;
453 info.abilityName_ = "test1";
454 info.bundleName_ = "test2";
455 sptr<SceneSession> scensession = nullptr;
456 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
457 ASSERT_NE(property, nullptr);
458 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
459 ASSERT_NE(sceneSession, nullptr);
460 FocusChangeReason reason = FocusChangeReason::MOVE_UP;
461 ssm_->RequestSessionUnfocus(0, reason);
462 }
463
464 /**
465 * @tc.name: RequestFocusSpecificCheck
466 * @tc.desc: RequestFocusSpecificCheck
467 * @tc.type: FUNC
468 */
469 HWTEST_F(SceneSessionManagerTest5, RequestFocusSpecificCheck, Function | SmallTest | Level3)
470 {
471 SessionInfo info;
472 info.abilityName_ = "test1";
473 info.bundleName_ = "test2";
474 sptr<SceneSession> scensession = nullptr;
475 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
476 ASSERT_NE(property, nullptr);
477 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
478 ASSERT_NE(sceneSession, nullptr);
479 FocusChangeReason reason = FocusChangeReason::MOVE_UP;
480 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
481 ssm_->RequestFocusSpecificCheck(sceneSession, true, reason);
482
483 FocusChangeReason reason1 = FocusChangeReason::SPLIT_SCREEN;
484 property->SetWindowType(WindowType::APP_WINDOW_BASE);
485 ssm_->RequestFocusSpecificCheck(sceneSession, true, reason1);
486 }
487
488 /**
489 * @tc.name: NotifyFocusStatus
490 * @tc.desc: NotifyFocusStatus
491 * @tc.type: FUNC
492 */
493 HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatus, Function | SmallTest | Level3)
494 {
495 SessionInfo info;
496 info.abilityName_ = "test1";
497 info.bundleName_ = "test2";
498 sptr<SceneSession> scensession = nullptr;
499 ssm_->NotifyFocusStatus(scensession, true);
500 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
501 ASSERT_NE(property, nullptr);
502 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
503 ASSERT_NE(sceneSession, nullptr);
504 ssm_->NotifyFocusStatus(sceneSession, false);
505 info.isSystem_ = true;
506 ssm_->NotifyFocusStatus(sceneSession, true);
507 }
508
509 /**
510 * @tc.name: NotifyFocusStatusByMission
511 * @tc.desc: NotifyFocusStatusByMission
512 * @tc.type: FUNC
513 */
514 HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatusByMission, Function | SmallTest | Level3)
515 {
516 SessionInfo info;
517 info.abilityName_ = "test1";
518 info.bundleName_ = "test2";
519 sptr<SceneSession> scensession = nullptr;
520 sptr<SceneSession> currSession = nullptr;
521 ssm_->NotifyFocusStatusByMission(scensession, currSession);
522 ASSERT_EQ(false, ssm_->MissionChanged(scensession, currSession));
523 std::shared_ptr<SessionListenerController> listenerController =
524 std::make_shared<SessionListenerController>();
525 ssm_->listenerController_ = listenerController;
526 scensession = new (std::nothrow) SceneSession(info, nullptr);
527 ASSERT_NE(scensession, nullptr);
528 ssm_->NotifyFocusStatusByMission(scensession, currSession);
529 ssm_->MissionChanged(scensession, currSession);
530 currSession = new (std::nothrow) SceneSession(info, nullptr);
531 ASSERT_NE(currSession, nullptr);
532 ssm_->NotifyFocusStatusByMission(scensession, currSession);
533 ssm_->MissionChanged(scensession, currSession);
534 info.isSystem_ = true;
535 ssm_->NotifyFocusStatusByMission(scensession, currSession);
536 ssm_->MissionChanged(scensession, currSession);
537 }
538
539 /**
540 * @tc.name: UpdateFocus
541 * @tc.desc: UpdateFocus
542 * @tc.type: FUNC
543 */
544 HWTEST_F(SceneSessionManagerTest5, UpdateFocus, Function | SmallTest | Level3)
545 {
546 SessionInfo info;
547 info.abilityName_ = "test1";
548 info.bundleName_ = "test2";
549 sptr<SceneSession> scensession = nullptr;
550 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
551 ASSERT_NE(property, nullptr);
552 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
553 ASSERT_NE(sceneSession, nullptr);
554 ssm_->UpdateFocus(1, true);
555 ssm_->UpdateFocus(0, false);
556 }
557
558 /**
559 * @tc.name: RequestSessionFocusImmediately
560 * @tc.desc: RequestSessionFocusImmediately
561 * @tc.type: FUNC
562 */
563 HWTEST_F(SceneSessionManagerTest5, RequestSessionFocusImmediately, Function | SmallTest | Level3)
564 {
565 SessionInfo info;
566 info.abilityName_ = "test1";
567 info.bundleName_ = "test2";
568 sptr<SceneSession> scensession = nullptr;
569 ssm_->RequestSessionFocusImmediately(0);
570 ssm_->RequestFocusBasicCheck(0);
571 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
572 ASSERT_NE(property, nullptr);
573 sptr<Session> session = new (std::nothrow) Session(info);
574 session->SetSessionProperty(property);
575 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
576 ASSERT_NE(sceneSession, nullptr);
577 ssm_->RequestSessionFocusImmediately(1);
578 ssm_->RequestFocusBasicCheck(1);
579 }
580 /**
581 * @tc.name: CheckFocusIsDownThroughBlockingType
582 * @tc.desc: CheckFocusIsDownThroughBlockingType
583 * @tc.type: FUNC
584 */
585 HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType, Function | SmallTest | Level3)
586 {
587 SessionInfo info;
588 info.abilityName_ = "test1";
589 info.bundleName_ = "test1";
590 SessionInfo info2;
591 info2.abilityName_ = "test2";
592 info2.bundleName_ = "test2";
593 sptr<SceneSession> scensession = nullptr;
594 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
595 ASSERT_NE(property, nullptr);
596 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info2, nullptr);
597 ASSERT_NE(sceneSession, nullptr);
598 sptr<SceneSession> sceneSession2 = new (std::nothrow) SceneSession(info2, nullptr);
599 ASSERT_NE(sceneSession2, nullptr);
600 ssm_->CheckFocusIsDownThroughBlockingType(sceneSession, sceneSession2, true);
601 }
602
603
604 /**
605 * @tc.name: CheckFocusIsDownThroughBlockingType
606 * @tc.desc: CheckFocusIsDownThroughBlockingType
607 * @tc.type: FUNC
608 */
609 HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType01, Function | SmallTest | Level3)
610 {
611 ASSERT_NE(ssm_, nullptr);
612 SessionInfo info;
613 info.abilityName_ = "test1";
614 info.bundleName_ = "test2";
615 sptr<SceneSession> requestSceneSession = new (std::nothrow) SceneSession(info, nullptr);
616 ASSERT_NE(requestSceneSession, nullptr);
617 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info, nullptr);
618 ASSERT_NE(focusedSession, nullptr);
619 bool includingAppSession = true;
620 ssm_->CheckFocusIsDownThroughBlockingType(requestSceneSession, focusedSession, includingAppSession);
621
622 requestSceneSession->SetZOrder(0);
623 focusedSession->SetZOrder(1);
624 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
625 ASSERT_NE(sceneSession, nullptr);
626 Session session = Session(info);
627 session.property_ = nullptr;
628 session.SetZOrder(2);
629
630 session.property_ = new WindowSessionProperty();
631 session.isVisible_ = true;
632 ssm_->CheckFocusIsDownThroughBlockingType(requestSceneSession, focusedSession, includingAppSession);
633 }
634
635 /**
636 * @tc.name: CheckTopmostWindowFocus
637 * @tc.desc: CheckTopmostWindowFocus
638 * @tc.type: FUNC
639 */
640 HWTEST_F(SceneSessionManagerTest5, CheckTopmostWindowFocus, Function | SmallTest | Level3)
641 {
642 ASSERT_NE(ssm_, nullptr);
643 SessionInfo info;
644 info.abilityName_ = "test1";
645 info.bundleName_ = "test2";
646
647 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info, nullptr);
648 ASSERT_NE(focusedSession, nullptr);
649 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
650 ASSERT_NE(sceneSession, nullptr);
651 Session session = Session(info);
652 session.property_ = nullptr;
653
654 session.persistentId_ = 1;
655 focusedSession->GetMissionId();
656 ssm_->CheckTopmostWindowFocus(focusedSession, sceneSession);
657 }
658
659 /**
660 * @tc.name: CheckRequestFocusImmdediately
661 * @tc.desc: CheckRequestFocusImmdediately
662 * @tc.type: FUNC
663 */
664 HWTEST_F(SceneSessionManagerTest5, CheckRequestFocusImmdediately, Function | SmallTest | Level3)
665 {
666 ASSERT_NE(ssm_, nullptr);
667 SessionInfo info;
668 info.abilityName_ = "test1";
669 info.bundleName_ = "test2";
670
671 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
672 ASSERT_NE(sceneSession, nullptr);
673 Session session = Session(info);
674 session.property_ = nullptr;
675 ssm_->CheckRequestFocusImmdediately(sceneSession);
676 }
677
678 /**
679 * @tc.name: GetNextFocusableSession
680 * @tc.desc: GetNextFocusableSession
681 * @tc.type: FUNC
682 */
683 HWTEST_F(SceneSessionManagerTest5, GetNextFocusableSession, Function | SmallTest | Level3)
684 {
685 int32_t persistentId = 0;
686 ASSERT_NE(ssm_, nullptr);
687 SessionInfo info;
688 info.abilityName_ = "test1";
689 info.bundleName_ = "test2";
690
691 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
692 ASSERT_NE(sceneSession, nullptr);
693 ssm_->GetNextFocusableSession(persistentId);
694 sceneSession->GetForceHideState();
695 Session session = Session(info);
696 session.property_ = new WindowSessionProperty();
697 sptr<WindowSessionProperty> windowSessionProperty = new WindowSessionProperty();
698 ASSERT_NE(windowSessionProperty, nullptr);
699 ssm_->GetNextFocusableSession(persistentId);
700 }
701
702 /**
703 * @tc.name: GetTopNearestBlockingFocusSession
704 * @tc.desc: GetTopNearestBlockingFocusSession
705 * @tc.type: FUNC
706 */
707 HWTEST_F(SceneSessionManagerTest5, GetTopNearestBlockingFocusSession, Function | SmallTest | Level3)
708 {
709 ASSERT_NE(ssm_, nullptr);
710 SessionInfo info;
711 info.abilityName_ = "test1";
712 info.bundleName_ = "test2";
713
714 ssm_->GetTopNearestBlockingFocusSession(2, true);
715 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
716 ASSERT_NE(sceneSession, nullptr);
717 ssm_->GetTopNearestBlockingFocusSession(0, true);
718
719 Session session = Session(info);
720 session.property_ = nullptr;
721 ssm_->GetTopNearestBlockingFocusSession(0, true);
722 sptr<SceneSession> session_ = nullptr;
723 ssm_->GetTopNearestBlockingFocusSession(0, true);
724 session_ = new (std::nothrow) SceneSession(info, nullptr);
725 ASSERT_NE(session_, nullptr);
726 ssm_->GetTopNearestBlockingFocusSession(0, true);
727 }
728
729 /**
730 * @tc.name: PreloadInLakeApp、UpdateSessionAvoidAreaListener
731 * @tc.desc: PreloadInLakeApp、UpdateSessionAvoidAreaListener
732 * @tc.type: FUNC
733 */
734 HWTEST_F(SceneSessionManagerTest5, PreloadInLakeApp, Function | SmallTest | Level3)
735 {
736 ASSERT_NE(ssm_, nullptr);
737 SessionInfo info;
738 info.abilityName_ = "test1";
739 info.bundleName_ = "test2";
740 int32_t persistentId = 0;
741
742 ssm_->PreloadInLakeApp("");
743 sptr<SceneSession> sceneSession = nullptr;
744
745 ssm_->UpdateSessionAvoidAreaListener(persistentId, true);
746 sceneSession = ssm_->CreateSceneSession(info, nullptr);
747 ASSERT_NE(nullptr, sceneSession);
748 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
749 ssm_->UpdateSessionAvoidAreaListener(persistentId, true);
750 }
751
752 /**
753 * @tc.name: NotifyMMIWindowPidChange
754 * @tc.desc: NotifyMMIWindowPidChange
755 * @tc.type: FUNC
756 */
757 HWTEST_F(SceneSessionManagerTest5, NotifyMMIWindowPidChange, Function | SmallTest | Level3)
758 {
759 ASSERT_NE(ssm_, nullptr);
760 SessionInfo info;
761 info.abilityName_ = "test1";
762 info.bundleName_ = "test2";
763 sptr<SceneSession> sceneSession = nullptr;
764 ssm_->NotifyMMIWindowPidChange(0, true);
765 sceneSession = ssm_->CreateSceneSession(info, nullptr);
766 ASSERT_NE(nullptr, sceneSession);
767 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
768 }
769
770 /**
771 * @tc.name: CheckModalSubWindowPermission
772 * @tc.desc: CheckModalSubWindowPermission
773 * @tc.type: FUNC
774 */
775 HWTEST_F(SceneSessionManagerTest5, CheckModalSubWindowPermission, Function | SmallTest | Level3)
776 {
777 ASSERT_NE(ssm_, nullptr);
778 SessionInfo info;
779 info.abilityName_ = "test1";
780 info.bundleName_ = "test2";
781 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
782 ASSERT_NE(property, nullptr);
783 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
784 property->SetWindowFlags(123);
785 ssm_->CheckModalSubWindowPermission(property);
786 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
787 ssm_->CheckModalSubWindowPermission(property);
788 }
789
790 /**
791 * @tc.name: CheckSessionPropertyOnRecovery
792 * @tc.desc: CheckSessionPropertyOnRecovery
793 * @tc.type: FUNC
794 */
795 HWTEST_F(SceneSessionManagerTest5, CheckSessionPropertyOnRecovery, Function | SmallTest | Level3)
796 {
797 ASSERT_NE(ssm_, nullptr);
798 SessionInfo info;
799 info.abilityName_ = "test1";
800 info.bundleName_ = "test2";
801 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
802 ASSERT_NE(property, nullptr);
803 property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
804 property->SetWindowFlags(123);
805 ssm_->CheckSessionPropertyOnRecovery(property, false);
806 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
807 property->SetParentPersistentId(111);
808 ssm_->CheckSessionPropertyOnRecovery(property, true);
809 }
810
811 /**
812 * @tc.name: SetCreateKeyboardSessionListener
813 * @tc.desc: SetCreateKeyboardSessionListener
814 * @tc.type: FUNC
815 */
816 HWTEST_F(SceneSessionManagerTest5, SetCreateKeyboardSessionListener, Function | SmallTest | Level3)
817 {
818 ASSERT_NE(ssm_, nullptr);
819 ssm_->SetCreateSystemSessionListener(nullptr);
820 SessionInfo sessionInfo;
821 sessionInfo.bundleName_ = "test1";
822 sessionInfo.abilityName_ = "test2";
823 sessionInfo.abilityInfo = nullptr;
824 sessionInfo.isAtomicService_ = true;
825 sessionInfo.screenId_ = SCREEN_ID_INVALID;
826 ssm_->NotifySessionTouchOutside(123);
827 }
828
829 /**
830 * @tc.name: DestroyAndDisconnectSpecificSessionInner
831 * @tc.desc: check func DestroyAndDisconnectSpecificSessionInner
832 * @tc.type: FUNC
833 */
834 HWTEST_F(SceneSessionManagerTest5, DestroyAndDisconnectSpecificSessionInner02, Function | SmallTest | Level2)
835 {
836 ASSERT_NE(ssm_, nullptr);
837 SessionInfo info;
838 info.abilityName_ = "test1";
839 info.bundleName_ = "test2";
840 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
841 ASSERT_NE(nullptr, property);
842 std::vector<int32_t> recoveredPersistentIds = {0, 1, 2};
843 ssm_->SetAlivePersistentIds(recoveredPersistentIds);
844 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
845 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
846 }
847
848 /**
849 * @tc.name: DestroyToastSession
850 * @tc.desc: DestroyToastSession
851 * @tc.type: FUNC
852 */
853 HWTEST_F(SceneSessionManagerTest5, DestroyToastSession, Function | SmallTest | Level3)
854 {
855 ASSERT_NE(ssm_, nullptr);
856 SessionInfo info;
857 info.abilityName_ = "test1";
858 info.bundleName_ = "test2";
859 info.screenId_ = SCREEN_ID_INVALID;
860 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
861 ASSERT_NE(property, nullptr);
862 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
863 sptr<SceneSession> sceneSession = nullptr;
864 ssm_->DestroyToastSession(sceneSession);
865 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
866 ssm_->DestroyToastSession(sceneSession);
867 ssm_->StartUIAbilityBySCB(sceneSession);
868 ssm_->ChangeUIAbilityVisibilityBySCB(sceneSession, true);
869 }
870
871 /**
872 * @tc.name: InitSnapshotCache
873 * @tc.desc: InitSnapshotCache
874 * @tc.type: FUNC
875 */
876 HWTEST_F(SceneSessionManagerTest5, InitSnapshotCache, Function | SmallTest | Level3)
877 {
878 ASSERT_NE(ssm_, nullptr);
879 ssm_->InitSnapshotCache();
880 if (ssm_->systemConfig_.uiType_ == UI_TYPE_PC) {
881 ASSERT_EQ(ssm_->snapshotCapacity_, 50);
882 } else if (ssm_->systemConfig_.uiType_ == UI_TYPE_PAD) {
883 ASSERT_EQ(ssm_->snapshotCapacity_, 8);
884 } else {
885 ASSERT_EQ(ssm_->snapshotCapacity_, 3);
886 }
887 }
888
889 /**
890 * @tc.name: PutSnapshotToCache
891 * @tc.desc: PutSnapshotToCache
892 * @tc.type: FUNC
893 */
894 HWTEST_F(SceneSessionManagerTest5, PutSnapshotToCache, Function | SmallTest | Level3)
895 {
896 ASSERT_NE(ssm_, nullptr);
897 ssm_->sceneSessionMap_.clear();
898 SessionInfo info;
899 info.abilityName_ = "test1";
900 info.bundleName_ = "test2";
901 info.persistentId_ = 30;
902 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
903 std::string bundleName = "testBundleName";
904 int32_t persistentId = 30;
905 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
906 sceneSession->snapshot_ = std::make_shared<Media::PixelMap>();
907 ssm_->sceneSessionMap_.insert({30, sceneSession});
908 for (int32_t id = 30; id <= 30 + ssm_->snapshotCapacity_; ++id) {
909 ssm_->PutSnapshotToCache(id);
910 }
911 ASSERT_EQ(sceneSession->snapshot_, nullptr);
912 }
913
914 /**
915 * @tc.name: VisitSnapshotFromCache
916 * @tc.desc: VisitSnapshotFromCache
917 * @tc.type: FUNC
918 */
919 HWTEST_F(SceneSessionManagerTest5, VisitSnapshotFromCache, Function | SmallTest | Level3)
920 {
921 ASSERT_NE(ssm_, nullptr);
922 ssm_->sceneSessionMap_.clear();
923 SessionInfo info;
924 info.abilityName_ = "test1";
925 info.bundleName_ = "test2";
926 info.persistentId_ = 30;
927 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
928 std::string bundleName = "testBundleName";
929 int32_t persistentId = 30;
930 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
931 ssm_->sceneSessionMap_.insert({30, sceneSession});
932 sceneSession->snapshot_ = std::make_shared<Media::PixelMap>();
933 for (int32_t id = 30; id < 0 + ssm_->snapshotCapacity_; ++id) {
934 ssm_->PutSnapshotToCache(id);
935 }
936 ssm_->VisitSnapshotFromCache(30);
937 ssm_->PutSnapshotToCache(30 + ssm_->snapshotCapacity_);
938 ASSERT_NE(sceneSession->snapshot_, nullptr);
939 }
940
941 /**
942 * @tc.name: RemoveSnapshotFromCache
943 * @tc.desc: RemoveSnapshotFromCache
944 * @tc.type: FUNC
945 */
946 HWTEST_F(SceneSessionManagerTest5, RemoveSnapshotFromCache, Function | SmallTest | Level3)
947 {
948 ASSERT_NE(ssm_, nullptr);
949 ssm_->sceneSessionMap_.clear();
950 SessionInfo info;
951 info.abilityName_ = "test1";
952 info.bundleName_ = "test2";
953 info.persistentId_ = 30;
954 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
955 std::string bundleName = "testBundleName";
956 int32_t persistentId = 30;
957 sceneSession->scenePersistence_ = sptr<ScenePersistence>::MakeSptr(bundleName, persistentId);
958 ssm_->sceneSessionMap_.insert({30, sceneSession});
959 sceneSession->snapshot_ = std::make_shared<Media::PixelMap>();
960 for (int32_t id = 30; id < 0 + ssm_->snapshotCapacity_; ++id) {
961 ssm_->PutSnapshotToCache(id);
962 }
963 ssm_->RemoveSnapshotFromCache(31);
964 ssm_->PutSnapshotToCache(30 + ssm_->snapshotCapacity_);
965 ASSERT_NE(sceneSession->snapshot_, nullptr);
966 }
967
968 /**
969 * @tc.name: RequestSceneSessionBackground
970 * @tc.desc: RequestSceneSessionBackground
971 * @tc.type: FUNC
972 */
973 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground, Function | SmallTest | Level3)
974 {
975 ASSERT_NE(ssm_, nullptr);
976 SessionInfo info;
977 info.abilityName_ = "test1";
978 info.bundleName_ = "test2";
979 info.ancoSceneState = 0;
980 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
981 ASSERT_NE(property, nullptr);
982 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
983 sptr<SceneSession> sceneSession = nullptr;
984 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
985 ssm_->RequestSceneSessionBackground(sceneSession, true, true, true);
986 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
987 ssm_->RequestSceneSessionBackground(sceneSession, false, false, false);
988 ssm_->RequestSceneSessionBackground(sceneSession, true, false, true);
989 ssm_->RequestSceneSessionBackground(sceneSession, true, true, true);
990 }
991
992 /**
993 * @tc.name: RequestSceneSessionBackground
994 * @tc.desc: RequestSceneSessionBackground
995 * @tc.type: FUNC
996 */
997 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground02, Function | SmallTest | Level3)
998 {
999 ASSERT_NE(ssm_, nullptr);
1000 SessionInfo info;
1001 info.abilityName_ = "test1";
1002 info.bundleName_ = "test2";
1003 info.ancoSceneState = 0;
1004 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1005 ASSERT_NE(property, nullptr);
1006 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1007 sptr<Session> session = new (std::nothrow) Session(info);
1008 ASSERT_NE(session, nullptr);
1009 sptr<SceneSession> sceneSession = nullptr;
1010 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1011 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1012 session->SetSessionInfoPersistentId(123);
1013 ssm_->RequestSceneSessionBackground(sceneSession, false, false, false);
1014 session->SetSessionInfoPersistentId(0);
1015 ssm_->RequestSceneSessionBackground(sceneSession, false, false, true);
1016 }
1017
1018 /**
1019 * @tc.name: ConfigAppWindowShadow
1020 * @tc.desc: SceneSesionManager config app window shadow
1021 * @tc.type: FUNC
1022 */
1023 HWTEST_F(SceneSessionManagerTest5, ConfigAppWindowShadow03, Function | SmallTest | Level3)
1024 {
1025 ASSERT_NE(ssm_, nullptr);
1026 WindowSceneConfig::ConfigItem item;
1027 WindowSceneConfig::ConfigItem shadowConfig;
1028 WindowShadowConfig outShadow;
1029 std::vector<float> floatTest = {0.0f, 0.1f, 0.2f, 0.3f};
1030 bool result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1031 ASSERT_EQ(result, true);
1032
1033 item.SetValue(floatTest);
1034 shadowConfig.SetValue({{"offsetX", item}});
1035 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1036
1037 shadowConfig.SetValue({{"offsetY", item}});
1038 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1039
1040 item.SetValue(new std::string(""));
1041 shadowConfig.SetValue({{"color", item}});
1042 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1043 }
1044
1045 /**
1046 * @tc.name: CreateAndConnectSpecificSession
1047 * @tc.desc: CreateAndConnectSpecificSession
1048 * @tc.type: FUNC
1049 */
1050 HWTEST_F(SceneSessionManagerTest5, CreateAndConnectSpecificSession02, Function | SmallTest | Level3)
1051 {
1052 ASSERT_NE(ssm_, nullptr);
1053 sptr<ISessionStage> sessionStage;
1054 sptr<IWindowEventChannel> eventChannel;
1055 std::shared_ptr<RSSurfaceNode> node = nullptr;
1056 sptr<ISession> session;
1057 SystemSessionConfig systemConfig;
1058 sptr<IRemoteObject> token;
1059 int32_t id = 0;
1060 SessionInfo info;
1061 info.abilityName_ = "test1";
1062 info.bundleName_ = "test2";
1063 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1064 ASSERT_NE(property, nullptr);
1065 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1066 property->SetWindowFlags(123);
1067 ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1068 systemConfig, token);
1069 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1070 ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1071 systemConfig, token);
1072 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1073 ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1074 systemConfig, token);
1075 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1076 ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1077 systemConfig, token);
1078
1079 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1080 property->SetFloatingWindowAppType(true);
1081 ssm_->shouldHideNonSecureFloatingWindows_.store(true);
1082 ssm_->systemConfig_.uiType_ = UI_TYPE_PC;
1083 auto res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1084 systemConfig, token);
1085 ASSERT_NE(WSError::WS_ERROR_INVALID_OPERATION, res);
1086 ssm_->shouldHideNonSecureFloatingWindows_.store(false);
1087 ssm_->systemConfig_.uiType_ = UI_TYPE_PHONE;
1088 }
1089
1090 /**
1091 * @tc.name: ProcessDialogRequestFocusImmdediately
1092 * @tc.desc: ProcessDialogRequestFocusImmdediately
1093 * @tc.type: FUNC
1094 */
1095 HWTEST_F(SceneSessionManagerTest5, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)
1096 {
1097 ASSERT_NE(ssm_, nullptr);
1098 SessionInfo info;
1099 info.abilityName_ = "test1";
1100 info.bundleName_ = "test2";
1101 info.persistentId_ = 123;
1102 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1103 ASSERT_NE(sceneSession, nullptr);
1104 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1105 ASSERT_NE(property, nullptr);
1106 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1107 auto ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1108 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1109 ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1110 }
1111
1112 /**
1113 * @tc.name: RequestSceneSessionByCall
1114 * @tc.desc: SceneSesionManager request scene session by call
1115 * @tc.type: FUNC
1116 */
1117 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionByCall02, Function | SmallTest | Level3)
1118 {
1119 ASSERT_NE(ssm_, nullptr);
1120 sptr<SceneSession> scensession = nullptr;
1121 ssm_->RequestSceneSessionByCall(nullptr);
1122 SessionInfo info;
1123 info.abilityName_ = "test1";
1124 info.bundleName_ = "test2";
1125 scensession = sptr<SceneSession>::MakeSptr(info, nullptr);
1126 ssm_->RequestSceneSessionByCall(scensession);
1127 }
1128
1129 /**
1130 * @tc.name: GetAllAbilityInfos
1131 * @tc.desc: Test if pip window can be created;
1132 * @tc.type: FUNC
1133 */
1134 HWTEST_F(SceneSessionManagerTest5, GetAllAbilityInfos02, Function | SmallTest | Level3)
1135 {
1136 ASSERT_NE(ssm_, nullptr);
1137 AAFwk::Want want;
1138 AppExecFwk::ElementName elementName = want.GetElement();
1139 int32_t userId = 1;
1140 std::vector<SCBAbilityInfo> scbAbilityInfos;
1141 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1142
1143 elementName.bundleName_ = "test";
1144 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1145
1146 elementName.abilityName_ = "test";
1147 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1148
1149 elementName.bundleName_ = "";
1150 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1151 }
1152
1153 /**
1154 * @tc.name: GetBatchAbilityInfos01
1155 * @tc.desc: GetBatchAbilityInfos01
1156 * @tc.type: FUNC
1157 */
1158 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos01, Function | SmallTest | Level3)
1159 {
1160 ASSERT_NE(ssm_, nullptr);
1161 auto bundleMgr = ssm_->bundleMgr_;
1162 ssm_->bundleMgr_ = nullptr;
1163 int32_t userId = 100;
1164 std::vector<std::string> bundleNames = { "test1", "test2" };
1165 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1166 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1167 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1168 }
1169
1170 /**
1171 * @tc.name: GetBatchAbilityInfos02
1172 * @tc.desc: GetBatchAbilityInfos02
1173 * @tc.type: FUNC
1174 */
1175 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos02, Function | SmallTest | Level3)
1176 {
1177 ASSERT_NE(ssm_, nullptr);
1178 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1179 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1180 int32_t userId = 100;
1181 std::vector<std::string> bundleNames = {};
1182 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1183 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1184 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1185 }
1186
1187 /**
1188 * @tc.name: GetBatchAbilityInfos03
1189 * @tc.desc: GetBatchAbilityInfos03
1190 * @tc.type: FUNC
1191 */
1192 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos03, Function | SmallTest | Level3)
1193 {
1194 ASSERT_NE(ssm_, nullptr);
1195 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1196 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1197 int32_t userId = 100;
1198 std::vector<std::string> bundleNames = { "" };
1199 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1200 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1201 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1202 }
1203
1204 /**
1205 * @tc.name: GetBatchAbilityInfos04
1206 * @tc.desc: GetBatchAbilityInfos04
1207 * @tc.type: FUNC
1208 */
1209 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos04, Function | SmallTest | Level3)
1210 {
1211 ASSERT_NE(ssm_, nullptr);
1212 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1213 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1214 int32_t userId = 100;
1215 std::vector<std::string> bundleNames = { "test1", "test2" };
1216 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1217 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1218 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1219 }
1220
1221 /**
1222 * @tc.name: FindMainWindowWithToken
1223 * @tc.desc: SceneSesionManager find main window with token
1224 * @tc.type: FUNC
1225 */
1226 HWTEST_F(SceneSessionManagerTest5, FindMainWindowWithToken02, Function | SmallTest | Level3)
1227 {
1228 ASSERT_NE(ssm_, nullptr);
1229 SessionInfo info;
1230 info.abilityName_ = "test1";
1231 info.bundleName_ = "test2";
1232 info.persistentId_ = 123;
1233 sptr<IRemoteObject> targetToken = nullptr;
1234 ssm_->FindMainWindowWithToken(targetToken);
1235 targetToken = new (std::nothrow) IRemoteObjectMocker();
1236 ASSERT_NE(targetToken, nullptr);
1237 ssm_->FindMainWindowWithToken(targetToken);
1238 sptr<SceneSession> scensession = sptr<SceneSession>::MakeSptr(info, nullptr);
1239 ssm_->FindMainWindowWithToken(targetToken);
1240 }
1241
1242 /**
1243 * @tc.name: RequestSceneSessionBackground
1244 * @tc.desc: RequestSceneSessionBackground
1245 * @tc.type: FUNC
1246 */
1247 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground03, Function | SmallTest | Level3)
1248 {
1249 ASSERT_NE(ssm_, nullptr);
1250 SessionInfo info;
1251 info.abilityName_ = "test1";
1252 info.bundleName_ = "test2";
1253 info.persistentId_ = 0;
1254 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1255 ASSERT_NE(property, nullptr);
1256 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1257 sptr<Session> session = new (std::nothrow) Session(info);
1258 ASSERT_NE(session, nullptr);
1259 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1260 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1261 session->SetSessionInfoPersistentId(0);
1262 ssm_->RequestSceneSessionBackground(sceneSession, false, false, true);
1263 }
1264
1265 /**
1266 * @tc.name: DestroyToastSession
1267 * @tc.desc: DestroyToastSession
1268 * @tc.type: FUNC
1269 */
1270 HWTEST_F(SceneSessionManagerTest5, DestroyToastSession02, Function | SmallTest | Level3)
1271 {
1272 ASSERT_NE(ssm_, nullptr);
1273 SessionInfo info;
1274 info.abilityName_ = "test1";
1275 info.bundleName_ = "test2";
1276 info.screenId_ = SCREEN_ID_INVALID;
1277 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1278 ASSERT_NE(property, nullptr);
1279 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
1280 sptr<SceneSession> sceneSession = nullptr;
1281 ssm_->DestroyToastSession(sceneSession);
1282 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1283 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1284 ssm_->DestroyToastSession(sceneSession);
1285 }
1286
1287 /**
1288 * @tc.name: CheckModalSubWindowPermission
1289 * @tc.desc: CheckModalSubWindowPermission
1290 * @tc.type: FUNC
1291 */
1292 HWTEST_F(SceneSessionManagerTest5, CheckModalSubWindowPermission02, Function | SmallTest | Level3)
1293 {
1294 ASSERT_NE(ssm_, nullptr);
1295 SessionInfo info;
1296 info.abilityName_ = "test1";
1297 info.bundleName_ = "test2";
1298 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1299 ASSERT_NE(property, nullptr);
1300 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1301 property->SetWindowFlags(123);
1302 property->SetTopmost(true);
1303 ssm_->CheckModalSubWindowPermission(property);
1304 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1305 ssm_->CheckModalSubWindowPermission(property);
1306 }
1307
1308 /**
1309 * @tc.name: ConfigDecor
1310 * @tc.desc: SceneSesionManager config decor
1311 * @tc.type: FUNC
1312 */
1313 HWTEST_F(SceneSessionManagerTest5, ConfigDecor02, Function | SmallTest | Level3)
1314 {
1315 ASSERT_NE(ssm_, nullptr);
1316 WindowSceneConfig::ConfigItem* item = new WindowSceneConfig::ConfigItem;
1317 ASSERT_NE(item, nullptr);
1318 ssm_->ConfigDecor(*item, false);
1319 delete item;
1320 }
1321
1322 /**
1323 * @tc.name: SetSkipSelfWhenShowOnVirtualScreen
1324 * @tc.desc: SetSkipSelfWhenShowOnVirtualScreen
1325 * @tc.type: FUNC
1326 */
1327 HWTEST_F(SceneSessionManagerTest5, SetSkipSelfWhenShowOnVirtualScreen, Function | SmallTest | Level3)
1328 {
1329 ASSERT_NE(ssm_, nullptr);
1330 SessionInfo info;
1331 info.abilityName_ = "test1";
1332 info.bundleName_ = "test2";
1333 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1334 ASSERT_NE(property, nullptr);
1335 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1336 uint64_t surfaceNodeId = 1234;
1337 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, false);
1338 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, true);
1339 }
1340
1341 /**
1342 * @tc.name: CreateKeyboardPanelSession
1343 * @tc.desc: CreateKeyboardPanelSession
1344 * @tc.type: FUNC
1345 */
1346 HWTEST_F(SceneSessionManagerTest5, CreateKeyboardPanelSession02, Function | SmallTest | Level3)
1347 {
1348 ASSERT_NE(ssm_, nullptr);
1349 SessionInfo info;
1350 info.abilityName_ = "test1";
1351 info.bundleName_ = "test2";
1352 info.screenId_ = SCREEN_ID_INVALID;
1353 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1354 ASSERT_NE(property, nullptr);
1355 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
1356 sptr<SceneSession> sceneSession = nullptr;
1357 ssm_->CreateKeyboardPanelSession(sceneSession);
1358 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1359 ssm_->CreateKeyboardPanelSession(sceneSession);
1360 }
1361
1362 /**
1363 * @tc.name: InitSceneSession02
1364 * @tc.desc: InitSceneSession02
1365 * @tc.type: FUNC
1366 */
1367 HWTEST_F(SceneSessionManagerTest5, InitSceneSession02, Function | SmallTest | Level3)
1368 {
1369 ASSERT_NE(nullptr, ssm_);
1370 SessionInfo sessionInfo;
1371 sessionInfo.bundleName_ = "test1";
1372 sessionInfo.abilityName_ = "test2";
1373 sessionInfo.abilityInfo = nullptr;
1374 sessionInfo.isAtomicService_ = true;
1375 sessionInfo.screenId_ = SCREEN_ID_INVALID;
1376 unsigned int flags = 1111;
1377 sessionInfo.want = std::make_shared<AAFwk::Want>();
1378 ASSERT_NE(nullptr, sessionInfo.want);
1379 sessionInfo.want->SetFlags(flags);
1380 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1381 ASSERT_NE(nullptr, sceneSession);
1382 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1383 ssm_->InitSceneSession(sceneSession, sessionInfo, nullptr);
1384 ASSERT_EQ(nullptr, sessionInfo.abilityInfo);
1385 }
1386
1387 /**
1388 * @tc.name: PrepareTerminate
1389 * @tc.desc: SceneSesionManager prepare terminate
1390 * @tc.type: FUNC
1391 */
1392 HWTEST_F(SceneSessionManagerTest5, PrepareTerminate03, Function | SmallTest | Level3)
1393 {
1394 ASSERT_NE(nullptr, ssm_);
1395 SessionInfo sessionInfo;
1396 sessionInfo.bundleName_ = "PrepareTerminate";
1397 sessionInfo.abilityName_ = "PrepareTerminate";
1398 sessionInfo.abilityInfo = nullptr;
1399 int32_t persistentId = 1;
1400 bool isPrepareTerminate = true;
1401 ASSERT_EQ(WSError::WS_OK, ssm_->PrepareTerminate(persistentId, isPrepareTerminate));
1402 }
1403
1404 /**
1405 * @tc.name: AddClientDeathRecipient
1406 * @tc.desc: SceneSesionManager add client death recipient
1407 * @tc.type: FUNC
1408 */
1409 HWTEST_F(SceneSessionManagerTest5, AddClientDeathRecipient02, Function | SmallTest | Level3)
1410 {
1411 ASSERT_NE(ssm_, nullptr);
1412 SessionInfo info;
1413 info.abilityName_ = "AddClientDeathRecipient";
1414 info.bundleName_ = "AddClientDeathRecipient";
1415 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1416 ASSERT_NE(nullptr, sceneSession);
1417 ssm_->AddClientDeathRecipient(nullptr, sceneSession);
1418 sptr<ISessionStage> sessionStage = new (std::nothrow) SessionStageMocker();
1419 ssm_->AddClientDeathRecipient(sessionStage, sceneSession);
1420 }
1421 }
1422 } // namespace Rosen
1423 } // namespace OHOS
1424