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 "screen_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 "common_test_utils.h"
33 #include "mock/mock_session_stage.h"
34 #include "mock/mock_window_event_channel.h"
35 #include "context.h"
36
37
38 using namespace testing;
39 using namespace testing::ext;
40
41 namespace OHOS {
42 namespace Rosen {
43
44 class SceneSessionManagerTest5 : public testing::Test {
45 public:
46 static void SetUpTestCase();
47
48 static void TearDownTestCase();
49
50 void SetUp() override;
51
52 void TearDown() override;
53
54 static bool gestureNavigationEnabled_;
55
56 static ProcessGestureNavigationEnabledChangeFunc callbackFunc_;
57 static sptr<SceneSessionManager> ssm_;
58
59 private:
60 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
61 };
62
63 sptr<SceneSessionManager> SceneSessionManagerTest5::ssm_ = nullptr;
64 bool SceneSessionManagerTest5::gestureNavigationEnabled_ = true;
65
66 ProcessGestureNavigationEnabledChangeFunc SceneSessionManagerTest5::callbackFunc_ = [](bool enable,
67 const std::string& bundleName, GestureBackType type) {
68 gestureNavigationEnabled_ = enable;
69 };
70
71
WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)72 void WindowChangedFuncTest(int32_t persistentId, WindowUpdateType type)
73 {
74 }
75
ProcessStatusBarEnabledChangeFuncTest(bool enable)76 void ProcessStatusBarEnabledChangeFuncTest(bool enable)
77 {
78 }
79
DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)80 void DumpRootSceneElementInfoFuncTest(const std::vector<std::string>& params, std::vector<std::string>& infos)
81 {
82 }
83
SetUpTestCase()84 void SceneSessionManagerTest5::SetUpTestCase()
85 {
86 ssm_ = &SceneSessionManager::GetInstance();
87 }
88
TearDownTestCase()89 void SceneSessionManagerTest5::TearDownTestCase()
90 {
91 ssm_->sceneSessionMap_.clear();
92 ssm_ = nullptr;
93 }
94
SetUp()95 void SceneSessionManagerTest5::SetUp()
96 {
97 ssm_->sceneSessionMap_.clear();
98 }
99
TearDown()100 void SceneSessionManagerTest5::TearDown()
101 {
102 ssm_->sceneSessionMap_.clear();
103 usleep(WAIT_SYNC_IN_NS);
104 }
105
106 namespace {
107 /**
108 * @tc.name: NotifySessionTouchOutside
109 * @tc.desc: SceneSesionManager notify session touch outside
110 * @tc.type: FUNC
111 */
HWTEST_F(SceneSessionManagerTest5, NotifySessionTouchOutside01, Function | SmallTest | Level3)112 HWTEST_F(SceneSessionManagerTest5, NotifySessionTouchOutside01, Function | SmallTest | Level3)
113 {
114 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
115 ASSERT_NE(ssm_, nullptr);
116 ssm_->recoveringFinished_ = false;
117 SessionInfo info;
118 info.abilityName_ = "test1";
119 info.bundleName_ = "test2";
120 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
121 property->SetWindowType(WindowType::APP_WINDOW_BASE);
122 ssm_->NotifySessionTouchOutside(0);
123 property->SetPersistentId(1);
124 ssm_->NotifySessionTouchOutside(1);
125 }
126
127 /**
128 * @tc.name: DestroyAndDisconnectSpecificSessionInner
129 * @tc.desc: check func DestroyAndDisconnectSpecificSessionInner
130 * @tc.type: FUNC
131 */
HWTEST_F(SceneSessionManagerTest5, DestroyAndDisconnectSpecificSessionInner, Function | SmallTest | Level2)132 HWTEST_F(SceneSessionManagerTest5, DestroyAndDisconnectSpecificSessionInner, Function | SmallTest | Level2)
133 {
134 sptr<ISession> session;
135 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
136 ASSERT_NE(nullptr, property);
137 std::vector<int32_t> recoveredPersistentIds = {0, 1, 2};
138 ssm_->SetAlivePersistentIds(recoveredPersistentIds);
139 ProcessShiftFocusFunc shiftFocusFunc_;
140 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
141 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
142 property->SetPersistentId(1);
143 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
144
145 property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
146 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
147 }
148
149
150 /**
151 * @tc.name: DestroyAndDisconnectSpecificSessionWithDetachCallback
152 * @tc.desc: SceneSesionManager destroy and disconnect specific session with detach callback
153 * @tc.type: FUNC
154 */
HWTEST_F(SceneSessionManagerTest5, DestroyAndDetachCallback, Function | SmallTest | Level3)155 HWTEST_F(SceneSessionManagerTest5, DestroyAndDetachCallback, Function | SmallTest | Level3)
156 {
157 int32_t persistentId = 0;
158 ASSERT_NE(ssm_, nullptr);
159 sptr<IRemoteObject> callback = new (std::nothrow) IRemoteObjectMocker();
160 ASSERT_NE(callback, nullptr);
161 ssm_->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
162 sptr<WindowSessionProperty> property;
163 ssm_->recoveringFinished_ = false;
164 SessionInfo info;
165 info.abilityName_ = "test1";
166 info.bundleName_ = "test2";
167 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
168 ssm_->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
169 }
170
171 /**
172 * @tc.name: GetStartupPageFromResource
173 * @tc.desc: GetStartupPageFromResource
174 * @tc.type: FUNC
175 */
HWTEST_F(SceneSessionManagerTest5, GetStartupPageFromResource, Function | SmallTest | Level3)176 HWTEST_F(SceneSessionManagerTest5, GetStartupPageFromResource, Function | SmallTest | Level3)
177 {
178 ASSERT_NE(ssm_, nullptr);
179 AppExecFwk::AbilityInfo info;
180 info.startWindowBackgroundId = 1;
181 std::string path = "path";
182 uint32_t bgColor = 1;
183 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
184 info.startWindowIconId = 0;
185 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
186 info.hapPath = "hapPath";
187 ASSERT_EQ(false, ssm_->GetStartupPageFromResource(info, path, bgColor));
188 }
189
190 /**
191 * @tc.name: GetStartupPage01
192 * @tc.desc: GetStartupPage when resourceMgr is nullptr
193 * @tc.type: FUNC
194 */
HWTEST_F(SceneSessionManagerTest5, GetStartupPage01, Function | SmallTest | Level3)195 HWTEST_F(SceneSessionManagerTest5, GetStartupPage01, Function | SmallTest | Level3)
196 {
197 ASSERT_NE(ssm_, nullptr);
198 /**
199 * @tc.steps: step1. Build input parameter.
200 */
201 SessionInfo info;
202 info.abilityName_ = "test1";
203 info.bundleName_ = "test2";
204 std::string path;
205 uint32_t bgColor = 0x00000000;
206 /**
207 * @tc.steps: step2. Set bundleMgr_ to nullptr.
208 */
209 sptr<AppExecFwk::IBundleMgr> tempBundleMgr = ssm_->bundleMgr_;
210 ssm_->bundleMgr_ = nullptr;
211 /**
212 * @tc.steps: step3. Test and check result.
213 */
214 ssm_->GetStartupPage(info, path, bgColor);
215 ssm_->bundleMgr_ = tempBundleMgr;
216 EXPECT_EQ("", path);
217 EXPECT_EQ(0x00000000, bgColor);
218 }
219
220 /**
221 * @tc.name: GetStartupPage02
222 * @tc.desc: GetStartupPage when info is cached
223 * @tc.type: FUNC
224 */
HWTEST_F(SceneSessionManagerTest5, GetStartupPage02, Function | SmallTest | Level3)225 HWTEST_F(SceneSessionManagerTest5, GetStartupPage02, Function | SmallTest | Level3)
226 {
227 ASSERT_NE(ssm_, nullptr);
228 /**
229 * @tc.steps: step1. Build input parameter.
230 */
231 SessionInfo sessionInfo;
232 sessionInfo.moduleName_ = "moduleName";
233 sessionInfo.abilityName_ = "abilityName";
234 sessionInfo.bundleName_ = "bundleName";
235 uint32_t bgColor = 0x00000000;
236 std::string path;
237 /**
238 * @tc.steps: step2. Cache info.
239 */
240 const uint32_t cachedColor = 0xff000000;
241 const std::string cachedPath = "cachedPath";
242 auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_;
243 StartingWindowInfo startingWindowInfo = {
244 .startingWindowBackgroundId_ = 0,
245 .startingWindowIconId_ = 0,
246 .startingWindowBackgroundColor_ = cachedColor,
247 .startingWindowIconPath_ = cachedPath,
248 };
249 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
250 ssm_->startingWindowMap_.insert({sessionInfo.bundleName_, startingWindowInfoMap});
251 /**
252 * @tc.steps: step3. Test and check result.
253 */
254 ssm_->GetStartupPage(sessionInfo, path, bgColor);
255 EXPECT_EQ(path, cachedPath);
256 EXPECT_EQ(bgColor, cachedColor);
257 }
258
259 /**
260 * @tc.name: CacheStartingWindowInfo01
261 * @tc.desc: Cache new starting window info
262 * @tc.type: FUNC
263 */
HWTEST_F(SceneSessionManagerTest5, CacheStartingWindowInfo01, Function | SmallTest | Level3)264 HWTEST_F(SceneSessionManagerTest5, CacheStartingWindowInfo01, Function | SmallTest | Level3)
265 {
266 ASSERT_NE(ssm_, nullptr);
267 ssm_->startingWindowMap_.clear();
268 /**
269 * @tc.steps: step1. Build input parameter.
270 */
271 AppExecFwk::AbilityInfo abilityInfo;
272 abilityInfo.name = "abilityName";
273 abilityInfo.bundleName = "bundleName";
274 abilityInfo.moduleName = "moduleName";
275 abilityInfo.startWindowBackgroundId = 1;
276 abilityInfo.startWindowIconId = 2;
277 std::string path = "cachedPath";
278 uint32_t bgColor = 0xff000000;
279 /**
280 * @tc.steps: step2. Cache info and check result.
281 */
282 ssm_->CacheStartingWindowInfo(abilityInfo, path, bgColor);
283 auto iter = ssm_->startingWindowMap_.find(abilityInfo.bundleName);
284 ASSERT_NE(iter, ssm_->startingWindowMap_.end());
285 auto& infoMap = iter->second;
286 auto infoIter = infoMap.find(abilityInfo.moduleName + abilityInfo.name);
287 ASSERT_NE(infoIter, infoMap.end());
288 EXPECT_EQ(infoIter->second.startingWindowBackgroundId_, 1);
289 EXPECT_EQ(infoIter->second.startingWindowIconId_, 2);
290 EXPECT_EQ(infoIter->second.startingWindowBackgroundColor_, bgColor);
291 EXPECT_EQ(infoIter->second.startingWindowIconPath_, path);
292 }
293
294 /**
295 * @tc.name: CacheStartingWindowInfo02
296 * @tc.desc: Execute when info is cached
297 * @tc.type: FUNC
298 */
HWTEST_F(SceneSessionManagerTest5, CacheStartingWindowInfo02, Function | SmallTest | Level3)299 HWTEST_F(SceneSessionManagerTest5, CacheStartingWindowInfo02, Function | SmallTest | Level3)
300 {
301 ASSERT_NE(ssm_, nullptr);
302 ssm_->startingWindowMap_.clear();
303 /**
304 * @tc.steps: step1. Build input parameter.
305 */
306 AppExecFwk::AbilityInfo abilityInfo;
307 abilityInfo.name = "abilityName";
308 abilityInfo.bundleName = "bundleName";
309 abilityInfo.moduleName = "moduleName";
310 abilityInfo.startWindowBackgroundId = 1;
311 abilityInfo.startWindowIconId = 2;
312 std::string path = "cachedPath";
313 uint32_t bgColor = 0xff000000;
314 /**
315 * @tc.steps: step2. Insert one item.
316 */
317 auto key = abilityInfo.moduleName + abilityInfo.name;
318 StartingWindowInfo startingWindowInfo = {
319 .startingWindowBackgroundId_ = 0,
320 .startingWindowIconId_ = 0,
321 .startingWindowBackgroundColor_ = 0x00000000,
322 .startingWindowIconPath_ = "path",
323 };
324 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
325 ssm_->startingWindowMap_.insert({abilityInfo.bundleName, startingWindowInfoMap});
326 /**
327 * @tc.steps: step3. Execute and check result.
328 */
329 ssm_->CacheStartingWindowInfo(abilityInfo, path, bgColor);
330 auto iter = ssm_->startingWindowMap_.find(abilityInfo.bundleName);
331 ASSERT_NE(iter, ssm_->startingWindowMap_.end());
332 auto& infoMap = iter->second;
333 auto infoIter = infoMap.find(abilityInfo.moduleName + abilityInfo.name);
334 ASSERT_NE(infoIter, infoMap.end());
335 EXPECT_NE(infoIter->second.startingWindowBackgroundId_, 1);
336 EXPECT_NE(infoIter->second.startingWindowIconId_, 2);
337 EXPECT_NE(infoIter->second.startingWindowBackgroundColor_, bgColor);
338 EXPECT_NE(infoIter->second.startingWindowIconPath_, path);
339 }
340
341 /**
342 * @tc.name: OnBundleUpdated
343 * @tc.desc: Erase cached info when bundle update
344 * @tc.type: FUNC
345 */
HWTEST_F(SceneSessionManagerTest5, OnBundleUpdated, Function | SmallTest | Level3)346 HWTEST_F(SceneSessionManagerTest5, OnBundleUpdated, Function | SmallTest | Level3)
347 {
348 ASSERT_NE(ssm_, nullptr);
349 ssm_->startingWindowMap_.clear();
350 /**
351 * @tc.steps: step1. Insert item to map.
352 */
353 SessionInfo sessionInfo;
354 sessionInfo.moduleName_ = "moduleName";
355 sessionInfo.abilityName_ = "abilityName";
356 sessionInfo.bundleName_ = "bundleName";
357 uint32_t cachedColor = 0xff000000;
358 std::string cachedPath = "cachedPath";
359 auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_;
360 StartingWindowInfo startingWindowInfo = {
361 .startingWindowBackgroundId_ = 0,
362 .startingWindowIconId_ = 0,
363 .startingWindowBackgroundColor_ = cachedColor,
364 .startingWindowIconPath_ = cachedPath,
365 };
366 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
367 ssm_->startingWindowMap_.insert({sessionInfo.bundleName_, startingWindowInfoMap});
368 ASSERT_NE(ssm_->startingWindowMap_.size(), 0);
369 /**
370 * @tc.steps: step2. On bundle updated and check map.
371 */
372 ssm_->OnBundleUpdated(sessionInfo.bundleName_, 0);
373 usleep(WAIT_SYNC_IN_NS);
374 ASSERT_EQ(ssm_->startingWindowMap_.size(), 0);
375 }
376
377 /**
378 * @tc.name: OnConfigurationUpdated
379 * @tc.desc: Clear startingWindowMap when configuration update
380 * @tc.type: FUNC
381 */
HWTEST_F(SceneSessionManagerTest5, OnConfigurationUpdated, Function | SmallTest | Level3)382 HWTEST_F(SceneSessionManagerTest5, OnConfigurationUpdated, Function | SmallTest | Level3)
383 {
384 ASSERT_NE(ssm_, nullptr);
385 ssm_->startingWindowMap_.clear();
386 /**
387 * @tc.steps: step1. Insert item to map.
388 */
389 SessionInfo sessionInfo;
390 sessionInfo.moduleName_ = "moduleName";
391 sessionInfo.abilityName_ = "abilityName";
392 sessionInfo.bundleName_ = "bundleName";
393 uint32_t cachedColor = 0xff000000;
394 std::string cachedPath = "cachedPath";
395 auto key = sessionInfo.moduleName_ + sessionInfo.abilityName_;
396 StartingWindowInfo startingWindowInfo = {
397 .startingWindowBackgroundId_ = 0,
398 .startingWindowIconId_ = 0,
399 .startingWindowBackgroundColor_ = cachedColor,
400 .startingWindowIconPath_ = cachedPath,
401 };
402 std::map<std::string, StartingWindowInfo> startingWindowInfoMap{{ key, startingWindowInfo }};
403 ssm_->startingWindowMap_.insert({sessionInfo.bundleName_, startingWindowInfoMap});
404 ASSERT_NE(ssm_->startingWindowMap_.size(), 0);
405 /**
406 * @tc.steps: step2. On configuration updated and check map.
407 */
408 auto configuration = std::make_shared<AppExecFwk::Configuration>();
409 ssm_->OnConfigurationUpdated(configuration);
410 usleep(WAIT_SYNC_IN_NS);
411 ASSERT_EQ(ssm_->startingWindowMap_.size(), 0);
412 }
413
414 /**
415 * @tc.name: CreateKeyboardPanelSession
416 * @tc.desc: CreateKeyboardPanelSession
417 * @tc.type: FUNC
418 */
HWTEST_F(SceneSessionManagerTest5, CreateKeyboardPanelSession, Function | SmallTest | Level3)419 HWTEST_F(SceneSessionManagerTest5, CreateKeyboardPanelSession, Function | SmallTest | Level3)
420 {
421 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
422 ASSERT_NE(sceneSessionManager, nullptr);
423 SessionInfo info;
424 info.abilityName_ = "test1";
425 info.bundleName_ = "test2";
426 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
427 ASSERT_NE(property, nullptr);
428 property->SetWindowType(WindowType::SYSTEM_SUB_WINDOW_BASE);
429 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
430 sceneSessionManager->CreateKeyboardPanelSession(sceneSession);
431 delete sceneSessionManager;
432 }
433
434 /**
435 * @tc.name: PrepareTerminate
436 * @tc.desc: SceneSesionManager prepare terminate
437 * @tc.type: FUNC
438 */
HWTEST_F(SceneSessionManagerTest5, PrepareTerminate, Function | SmallTest | Level3)439 HWTEST_F(SceneSessionManagerTest5, PrepareTerminate, Function | SmallTest | Level3)
440 {
441 int32_t persistentId = 1;
442 bool isPrepareTerminate = true;
443 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
444 ASSERT_NE(sceneSessionManager, nullptr);
445 ASSERT_EQ(WSError::WS_OK, sceneSessionManager->PrepareTerminate(persistentId, isPrepareTerminate));
446 delete sceneSessionManager;
447 }
448
449 /**
450 * @tc.name: IsKeyboardForeground
451 * @tc.desc: IsKeyboardForeground
452 * @tc.type: FUNC
453 */
HWTEST_F(SceneSessionManagerTest5, IsKeyboardForeground, Function | SmallTest | Level3)454 HWTEST_F(SceneSessionManagerTest5, IsKeyboardForeground, Function | SmallTest | Level3)
455 {
456 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
457 ASSERT_NE(sceneSessionManager, nullptr);
458 SessionInfo info;
459 info.abilityName_ = "test1";
460 info.bundleName_ = "test2";
461 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
462 ASSERT_NE(property, nullptr);
463 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
464 sceneSessionManager->IsKeyboardForeground();
465 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
466 sceneSessionManager->IsKeyboardForeground();
467 delete sceneSessionManager;
468 }
469
470 /**
471 * @tc.name: RequestInputMethodCloseKeyboard
472 * @tc.desc: RequestInputMethodCloseKeyboard
473 * @tc.type: FUNC
474 */
HWTEST_F(SceneSessionManagerTest5, RequestInputMethodCloseKeyboard02, Function | SmallTest | Level3)475 HWTEST_F(SceneSessionManagerTest5, RequestInputMethodCloseKeyboard02, Function | SmallTest | Level3)
476 {
477 int32_t persistentId = -1;
478 bool isPrepareTerminate = true;
479 SceneSessionManager* sceneSessionManager = new SceneSessionManager();
480 ASSERT_NE(sceneSessionManager, nullptr);
481 sceneSessionManager->PrepareTerminate(persistentId, isPrepareTerminate);
482 delete sceneSessionManager;
483 }
484
485 /**
486 * @tc.name: HandleSpecificSystemBarProperty
487 * @tc.desc: HandleSpecificSystemBarProperty
488 * @tc.type: FUNC
489 */
HWTEST_F(SceneSessionManagerTest5, HandleSpecificSystemBarProperty, Function | SmallTest | Level3)490 HWTEST_F(SceneSessionManagerTest5, HandleSpecificSystemBarProperty, Function | SmallTest | Level3)
491 {
492 ASSERT_NE(ssm_, nullptr);
493 SessionInfo info;
494 info.abilityName_ = "test1";
495 info.bundleName_ = "test2";
496 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
497 ASSERT_NE(property, nullptr);
498 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
499 WindowType type = WindowType::WINDOW_TYPE_STATUS_BAR;
500 ssm_->HandleSpecificSystemBarProperty(type, property, sceneSession);
501 }
502
503 /**
504 * @tc.name: UpdateBrightness
505 * @tc.desc: UpdateBrightness
506 * @tc.type: FUNC
507 */
HWTEST_F(SceneSessionManagerTest5, UpdateBrightness, Function | SmallTest | Level3)508 HWTEST_F(SceneSessionManagerTest5, UpdateBrightness, Function | SmallTest | Level3)
509 {
510 ASSERT_NE(ssm_, nullptr);
511 SessionInfo info;
512 info.abilityName_ = "test1";
513 info.bundleName_ = "test2";
514 info.isSystem_ = false;
515 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
516 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
517 ASSERT_NE(property, nullptr);
518 ssm_->UpdateBrightness(1);
519 FocusChangeInfo focusInfo;
520 ssm_->GetCurrentUserId();
521 ssm_->GetFocusWindowInfo(focusInfo);
522 }
523
524 /**
525 * @tc.name: RegisterSessionSnapshotFunc
526 * @tc.desc: RegisterSessionSnapshotFunc
527 * @tc.type: FUNC
528 */
HWTEST_F(SceneSessionManagerTest5, RegisterSessionSnapshotFunc, Function | SmallTest | Level3)529 HWTEST_F(SceneSessionManagerTest5, RegisterSessionSnapshotFunc, Function | SmallTest | Level3)
530 {
531 SessionInfo info;
532 info.abilityName_ = "test1";
533 info.bundleName_ = "test2";
534 sptr<SceneSession> scensession = nullptr;
535 ssm_->RegisterSessionSnapshotFunc(scensession);
536 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
537 ASSERT_NE(property, nullptr);
538 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
539 ASSERT_NE(sceneSession, nullptr);
540 ssm_->RegisterSessionSnapshotFunc(scensession);
541 info.isSystem_ = false;
542 ssm_->RegisterSessionSnapshotFunc(scensession);
543 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo;
544 ssm_->RegisterSessionSnapshotFunc(scensession);
545 }
546
547 /**
548 * @tc.name: RequestAllAppSessionUnfocus
549 * @tc.desc: RequestAllAppSessionUnfocus
550 * @tc.type: FUNC
551 */
HWTEST_F(SceneSessionManagerTest5, RequestAllAppSessionUnfocus, Function | SmallTest | Level3)552 HWTEST_F(SceneSessionManagerTest5, RequestAllAppSessionUnfocus, Function | SmallTest | Level3)
553 {
554 SessionInfo info;
555 info.abilityName_ = "test1";
556 info.bundleName_ = "test2";
557 sptr<SceneSession> scensession = nullptr;
558 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
559 ASSERT_NE(property, nullptr);
560 scensession = new (std::nothrow) SceneSession(info, nullptr);
561 ASSERT_NE(scensession, nullptr);
562 ssm_->HandleHideNonSystemFloatingWindows(property, scensession);
563 ssm_->RequestAllAppSessionUnfocus();
564 }
565
566 /**
567 * @tc.name: RequestFocusStatus
568 * @tc.desc: RequestFocusStatus
569 * @tc.type: FUNC
570 */
HWTEST_F(SceneSessionManagerTest5, RequestFocusStatus, Function | SmallTest | Level3)571 HWTEST_F(SceneSessionManagerTest5, RequestFocusStatus, Function | SmallTest | Level3)
572 {
573 SessionInfo info;
574 info.abilityName_ = "RequestFocusStatus";
575 info.bundleName_ = "RequestFocusStatus";
576 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
577 ASSERT_NE(sceneSession, nullptr);
578 sceneSession->persistentId_ = 1;
579 ssm_->sceneSessionMap_.clear();
580 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
581 WMError ret = ssm_->RequestFocusStatus(1, true, true, FocusChangeReason::DEFAULT);
582 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_CALLING);
583 ssm_->sceneSessionMap_.clear();
584 }
585
586 /**
587 * @tc.name: RequestFocusStatus01
588 * @tc.desc: RequestFocusStatus01
589 * @tc.type: FUNC
590 */
HWTEST_F(SceneSessionManagerTest5, RequestFocusStatus01, Function | SmallTest | Level3)591 HWTEST_F(SceneSessionManagerTest5, RequestFocusStatus01, Function | SmallTest | Level3)
592 {
593 SessionInfo info;
594 info.abilityName_ = "RequestFocusStatus01";
595 info.bundleName_ = "com.ohos.sceneboard";
596 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
597 ASSERT_NE(sceneSession, nullptr);
598 sceneSession->persistentId_ = 1;
599 ssm_->sceneSessionMap_.clear();
600 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
601 WMError ret = ssm_->RequestFocusStatus(1, true, true, FocusChangeReason::DEFAULT);
602 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_CALLING);
603 ret = ssm_->RequestFocusStatus(1, false, true, FocusChangeReason::DEFAULT);
604 EXPECT_EQ(ret, WMError::WM_ERROR_INVALID_CALLING);
605 ssm_->sceneSessionMap_.clear();
606 }
607
608 /**
609 * @tc.name: RequestSessionFocus
610 * @tc.desc: RequestSessionFocus
611 * @tc.type: FUNC
612 */
HWTEST_F(SceneSessionManagerTest5, RequestSessionFocus, Function | SmallTest | Level3)613 HWTEST_F(SceneSessionManagerTest5, RequestSessionFocus, Function | SmallTest | Level3)
614 {
615 FocusChangeReason reason = FocusChangeReason::DEFAULT;
616 WSError ret = ssm_->RequestSessionFocus(0, true, reason);
617 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
618 ret = ssm_->RequestSessionFocus(100, true, reason);
619 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
620
621 SessionInfo info;
622 info.abilityName_ = "test1";
623 info.bundleName_ = "test2";
624 sptr<SceneSession> scensession = nullptr;
625 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
626 ASSERT_NE(property, nullptr);
627 property->SetFocusable(false);
628 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
629 ASSERT_NE(sceneSession, nullptr);
630
631 sceneSession->property_ = property;
632 ASSERT_NE(sceneSession->property_, nullptr);
633 sceneSession->persistentId_ = 1;
634 sceneSession->isVisible_ = true;
635 sceneSession->state_ = SessionState::STATE_ACTIVE;
636 sceneSession->focusedOnShow_ = true;
637 sceneSession->property_->focusable_ = true;
638 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
639 ssm_->focusedSessionId_ = 2;
640 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
641 ret = ssm_->RequestSessionFocus(1, true, reason);
642 ASSERT_EQ(ret, WSError::WS_OK);
643 ASSERT_EQ(ssm_->focusedSessionId_, 1);
644 ssm_->sceneSessionMap_.clear();
645 }
646
647 /**
648 * @tc.name: RequestFocusClient
649 * @tc.desc: RequestFocusClient
650 * @tc.type: FUNC
651 */
HWTEST_F(SceneSessionManagerTest5, RequestFocusClient, Function | SmallTest | Level3)652 HWTEST_F(SceneSessionManagerTest5, RequestFocusClient, Function | SmallTest | Level3)
653 {
654 SessionInfo info;
655 info.abilityName_ = "RequestFocusTest1";
656 info.bundleName_ = "RequestFocusTest1";
657 sptr<SceneSession> sceneSession = nullptr;
658 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
659 ASSERT_NE(property, nullptr);
660 property->SetFocusable(true);
661 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
662 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
663 ASSERT_NE(sceneSession, nullptr);
664 sceneSession->property_ = property;
665 sceneSession->persistentId_ = 1;
666 sceneSession->isVisible_ = true;
667 sceneSession->state_ = SessionState::STATE_ACTIVE;
668 sceneSession->SetZOrder(1);
669
670 SessionInfo info2;
671 info2.abilityName_ = "RequestFocusTest2";
672 info2.bundleName_ = "RequestFocusTest2";
673 sptr<SceneSession> sceneSession2 = nullptr;
674 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
675 ASSERT_NE(property2, nullptr);
676 property2->SetFocusable(true);
677 property2->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
678 sceneSession2 = new (std::nothrow) SceneSession(info2, nullptr);
679 ASSERT_NE(sceneSession2, nullptr);
680 sceneSession2->property_ = property2;
681 sceneSession2->persistentId_ = 2;
682 sceneSession2->isVisible_ = true;
683 sceneSession2->state_ = SessionState::STATE_ACTIVE;
684 sceneSession2->SetZOrder(2);
685 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
686 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
687 FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST;
688
689 ssm_->RequestSessionFocus(1, false, reason);
690 ASSERT_EQ(ssm_->focusedSessionId_, 1);
691 ssm_->RequestSessionFocus(2, false, reason);
692 ASSERT_EQ(ssm_->focusedSessionId_, 2);
693 ssm_->RequestSessionUnfocus(2, reason);
694 ASSERT_EQ(ssm_->focusedSessionId_, 1);
695 ssm_->RequestSessionUnfocus(1, reason);
696 ASSERT_EQ(ssm_->focusedSessionId_, 0);
697 ssm_->sceneSessionMap_.clear();
698 }
699
700 /**
701 * @tc.name: RequestFocusClient
702 * @tc.desc: RequestFocusClient
703 * @tc.type: FUNC
704 */
HWTEST_F(SceneSessionManagerTest5, RequestFocusClient01, Function | SmallTest | Level3)705 HWTEST_F(SceneSessionManagerTest5, RequestFocusClient01, Function | SmallTest | Level3)
706 {
707 SessionInfo info;
708 info.abilityName_ = "RequestFocusTest1";
709 info.bundleName_ = "RequestFocusTest1";
710 sptr<SceneSession> sceneSession = nullptr;
711 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
712 ASSERT_NE(property, nullptr);
713 property->SetFocusable(true);
714 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
715 sceneSession = new (std::nothrow) SceneSession(info, nullptr);
716 ASSERT_NE(sceneSession, nullptr);
717 sceneSession->property_ = property;
718 sceneSession->persistentId_ = 1;
719 sceneSession->isVisible_ = true;
720 sceneSession->state_ = SessionState::STATE_ACTIVE;
721 sceneSession->SetZOrder(1);
722
723 SessionInfo info2;
724 info2.abilityName_ = "RequestFocusTest2";
725 info2.bundleName_ = "RequestFocusTest2";
726 sptr<SceneSession> sceneSession2 = nullptr;
727 sptr<WindowSessionProperty> property2 = new (std::nothrow) WindowSessionProperty();
728 ASSERT_NE(property2, nullptr);
729 property2->SetFocusable(true);
730 property2->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
731 sceneSession2 = new (std::nothrow) SceneSession(info2, nullptr);
732 ASSERT_NE(sceneSession2, nullptr);
733 sceneSession2->property_ = property2;
734 sceneSession2->persistentId_ = 2;
735 sceneSession2->isVisible_ = true;
736 sceneSession2->state_ = SessionState::STATE_ACTIVE;
737 sceneSession2->SetZOrder(2);
738
739 SessionInfo info3;
740 info3.abilityName_ = "RequestFocusTest3";
741 info3.bundleName_ = "RequestFocusTest3";
742 sptr<SceneSession> sceneSession3 = nullptr;
743 sptr<WindowSessionProperty> property3 = new (std::nothrow) WindowSessionProperty();
744 ASSERT_NE(property3, nullptr);
745 property3->SetFocusable(true);
746 property3->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
747 sceneSession3 = new (std::nothrow) SceneSession(info3, nullptr);
748 ASSERT_NE(sceneSession3, nullptr);
749 sceneSession3->property_ = property3;
750 sceneSession3->persistentId_ = 3;
751 sceneSession3->isVisible_ = true;
752 sceneSession3->state_ = SessionState::STATE_ACTIVE;
753 sceneSession3->SetZOrder(3);
754 sceneSession3->blockingFocus_ = true;
755 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
756 ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2});
757 ssm_->sceneSessionMap_.insert({sceneSession3->GetPersistentId(), sceneSession3});
758 FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST;
759
760 ssm_->RequestSessionFocus(1, false, reason);
761 ASSERT_EQ(ssm_->focusedSessionId_, 1);
762 ssm_->RequestSessionFocus(3, false, reason);
763 ASSERT_EQ(ssm_->focusedSessionId_, 3);
764 ssm_->RequestSessionFocus(2, false, reason);
765 ASSERT_EQ(ssm_->focusedSessionId_, 2);
766 auto ret = ssm_->RequestSessionUnfocus(3, reason);
767 ASSERT_EQ(WSError::WS_DO_NOTHING, ret);
768 ssm_->RequestSessionUnfocus(2, reason);
769 ASSERT_EQ(ssm_->focusedSessionId_, 1);
770 ssm_->sceneSessionMap_.clear();
771 }
772
773 /**
774 * @tc.name: SetShiftFocusListener
775 * @tc.desc: SetShiftFocusListener
776 * @tc.type: FUNC
777 */
HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | Level3)778 HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | Level3)
779 {
780 ASSERT_NE(ssm_, nullptr);
781 SessionInfo info;
782 info.abilityName_ = "test1";
783 info.bundleName_ = "test2";
784 FocusChangeReason reason = FocusChangeReason::SPLIT_SCREEN;
785 sptr<SceneSession> scensession = nullptr;
786 ssm_->ShiftFocus(scensession, reason);
787 info.isSystem_ = true;
788 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
789 ASSERT_NE(property, nullptr);
790 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
791 ASSERT_NE(sceneSession, nullptr);
792 ProcessShiftFocusFunc fun;
793 NotifySCBAfterUpdateFocusFunc func;
794 ssm_->SetShiftFocusListener(fun);
795 ssm_->SetSCBFocusedListener(func);
796 ssm_->SetSCBUnfocusedListener(func);
797 ProcessCallingSessionIdChangeFunc func1;
798 ssm_->SetCallingSessionIdSessionListenser(func1);
799 ProcessStartUIAbilityErrorFunc func2;
800 ssm_->SetStartUIAbilityErrorListener(func2);
801 ssm_->ShiftFocus(sceneSession, reason);
802 }
803
804 /**
805 * @tc.name: UpdateFocusStatus
806 * @tc.desc: UpdateFocusStatus
807 * @tc.type: FUNC
808 */
HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus, Function | SmallTest | Level3)809 HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus, Function | SmallTest | Level3)
810 {
811 ASSERT_NE(ssm_, nullptr);
812 SessionInfo info;
813 info.abilityName_ = "test1";
814 info.bundleName_ = "test2";
815 sptr<SceneSession> scensession = nullptr;
816 ssm_->UpdateFocusStatus(scensession, false);
817 ssm_->UpdateFocusStatus(scensession, true);
818
819 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
820 ASSERT_NE(sceneSession, nullptr);
821 ssm_->UpdateFocusStatus(sceneSession, true);
822 ssm_->UpdateFocusStatus(sceneSession, false);
823 }
824
825 /**
826 * @tc.name: RequestSessionUnfocus
827 * @tc.desc: RequestSessionUnfocus
828 * @tc.type: FUNC
829 */
HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus, Function | SmallTest | Level3)830 HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus, Function | SmallTest | Level3)
831 {
832 SessionInfo info;
833 info.abilityName_ = "test1";
834 info.bundleName_ = "test2";
835 sptr<SceneSession> scensession = nullptr;
836 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
837 ASSERT_NE(property, nullptr);
838 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
839 ASSERT_NE(sceneSession, nullptr);
840 FocusChangeReason reason = FocusChangeReason::MOVE_UP;
841 WSError ret = ssm_->RequestSessionUnfocus(0, reason);
842 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
843
844 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info, nullptr);
845 ASSERT_NE(focusedSession, nullptr);
846 focusedSession->property_ = property;
847 ASSERT_NE(focusedSession->property_, nullptr);
848 sceneSession->persistentId_ = 1;
849 focusedSession->persistentId_ = 2;
850 focusedSession->property_->parentPersistentId_ = 1;
851 ssm_->focusedSessionId_ = 1;
852 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
853 ssm_->sceneSessionMap_.insert({focusedSession->GetPersistentId(), focusedSession});
854 ret = ssm_->RequestSessionUnfocus(1, reason);
855 ASSERT_EQ(ret, WSError::WS_OK);
856 ASSERT_NE(ssm_->focusedSessionId_, 1);
857 ssm_->sceneSessionMap_.clear();
858 }
859
860 /**
861 * @tc.name: RequestFocusSpecificCheck
862 * @tc.desc: RequestFocusSpecificCheck
863 * @tc.type: FUNC
864 */
HWTEST_F(SceneSessionManagerTest5, RequestFocusSpecificCheck, Function | SmallTest | Level3)865 HWTEST_F(SceneSessionManagerTest5, RequestFocusSpecificCheck, Function | SmallTest | Level3)
866 {
867 SessionInfo info;
868 info.abilityName_ = "test1";
869 info.bundleName_ = "test2";
870 sptr<SceneSession> scensession = nullptr;
871 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
872 ASSERT_NE(property, nullptr);
873 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
874 ASSERT_NE(sceneSession, nullptr);
875 FocusChangeReason reason = FocusChangeReason::MOVE_UP;
876 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
877 WSError ret = ssm_->RequestFocusSpecificCheck(sceneSession, true, reason);
878 EXPECT_EQ(ret, WSError::WS_OK);
879 FocusChangeReason reason1 = FocusChangeReason::SPLIT_SCREEN;
880 property->SetWindowType(WindowType::APP_WINDOW_BASE);
881 ret = ssm_->RequestFocusSpecificCheck(sceneSession, true, reason1);
882 EXPECT_EQ(ret, WSError::WS_OK);
883 }
884
885 /**
886 * @tc.name: NotifyFocusStatus
887 * @tc.desc: NotifyFocusStatus
888 * @tc.type: FUNC
889 */
HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatus, Function | SmallTest | Level3)890 HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatus, Function | SmallTest | Level3)
891 {
892 SessionInfo info;
893 info.abilityName_ = "test1";
894 info.bundleName_ = "test2";
895 sptr<SceneSession> scensession = nullptr;
896 ssm_->NotifyFocusStatus(scensession, true);
897 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
898 ASSERT_NE(sceneSession, nullptr);
899 ssm_->NotifyFocusStatus(sceneSession, false);
900 info.isSystem_ = true;
901 ssm_->NotifyFocusStatus(sceneSession, true);
902 }
903
904 /**
905 * @tc.name: NotifyFocusStatusByMission
906 * @tc.desc: NotifyFocusStatusByMission
907 * @tc.type: FUNC
908 */
HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatusByMission, Function | SmallTest | Level3)909 HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatusByMission, Function | SmallTest | Level3)
910 {
911 SessionInfo info;
912 info.abilityName_ = "test1";
913 info.bundleName_ = "test2";
914 sptr<SceneSession> scensession = nullptr;
915 sptr<SceneSession> currSession = nullptr;
916 ssm_->NotifyFocusStatusByMission(scensession, currSession);
917 ASSERT_EQ(false, ssm_->MissionChanged(scensession, currSession));
918 scensession = new (std::nothrow) SceneSession(info, nullptr);
919 ASSERT_NE(scensession, nullptr);
920 ssm_->NotifyFocusStatusByMission(scensession, currSession);
921 ssm_->MissionChanged(scensession, currSession);
922 currSession = new (std::nothrow) SceneSession(info, nullptr);
923 ASSERT_NE(currSession, nullptr);
924 ssm_->NotifyFocusStatusByMission(scensession, currSession);
925 ssm_->MissionChanged(scensession, currSession);
926 info.isSystem_ = true;
927 ssm_->NotifyFocusStatusByMission(scensession, currSession);
928 ssm_->MissionChanged(scensession, currSession);
929 }
930
931 /**
932 * @tc.name: UpdateFocus
933 * @tc.desc: UpdateFocus
934 * @tc.type: FUNC
935 */
HWTEST_F(SceneSessionManagerTest5, UpdateFocus, Function | SmallTest | Level3)936 HWTEST_F(SceneSessionManagerTest5, UpdateFocus, Function | SmallTest | Level3)
937 {
938 SessionInfo info;
939 info.abilityName_ = "test1";
940 info.bundleName_ = "test2";
941 sptr<SceneSession> scensession = nullptr;
942 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
943 ASSERT_NE(property, nullptr);
944 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
945 ASSERT_NE(sceneSession, nullptr);
946 ssm_->UpdateFocus(1, true);
947 ssm_->UpdateFocus(0, false);
948 }
949
950 /**
951 * @tc.name: RequestSessionFocusImmediately
952 * @tc.desc: RequestSessionFocusImmediately
953 * @tc.type: FUNC
954 */
HWTEST_F(SceneSessionManagerTest5, RequestSessionFocusImmediately, Function | SmallTest | Level3)955 HWTEST_F(SceneSessionManagerTest5, RequestSessionFocusImmediately, Function | SmallTest | Level3)
956 {
957 SessionInfo info;
958 info.abilityName_ = "test1";
959 info.bundleName_ = "test2";
960 sptr<SceneSession> scensession = nullptr;
961 WSError ret = ssm_->RequestSessionFocusImmediately(0);
962 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
963 ssm_->RequestFocusBasicCheck(0);
964 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
965 ASSERT_NE(property, nullptr);
966 sptr<Session> session = new (std::nothrow) Session(info);
967 session->SetSessionProperty(property);
968 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
969 ASSERT_NE(sceneSession, nullptr);
970 ret = ssm_->RequestSessionFocusImmediately(1);
971 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
972 ssm_->RequestFocusBasicCheck(1);
973 }
974
975 /**
976 * @tc.name: RequestFocusBasicCheck
977 * @tc.desc: RequestFocusBasicCheck
978 * @tc.type: FUNC
979 */
HWTEST_F(SceneSessionManagerTest5, RequestFocusBasicCheck, Function | SmallTest | Level3)980 HWTEST_F(SceneSessionManagerTest5, RequestFocusBasicCheck, Function | SmallTest | Level3)
981 {
982 ssm_->focusedSessionId_ = 1;
983 WSError ret = ssm_->RequestFocusBasicCheck(0);
984 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION);
985 ret = ssm_->RequestFocusBasicCheck(1);
986 ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
987 ret = ssm_->RequestFocusBasicCheck(2);
988 ASSERT_EQ(ret, WSError::WS_OK);
989 }
990
991 /**
992 * @tc.name: CheckFocusIsDownThroughBlockingType
993 * @tc.desc: CheckFocusIsDownThroughBlockingType
994 * @tc.type: FUNC
995 */
HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType, Function | SmallTest | Level3)996 HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType, Function | SmallTest | Level3)
997 {
998 SessionInfo info;
999 info.abilityName_ = "test1";
1000 info.bundleName_ = "test1";
1001 SessionInfo info2;
1002 info2.abilityName_ = "test2";
1003 info2.bundleName_ = "test2";
1004 sptr<SceneSession> scensession = nullptr;
1005 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1006 ASSERT_NE(sceneSession, nullptr);
1007 sptr<SceneSession> sceneSession2 = new (std::nothrow) SceneSession(info2, nullptr);
1008 ASSERT_NE(sceneSession2, nullptr);
1009 bool ret = ssm_->CheckFocusIsDownThroughBlockingType(sceneSession, sceneSession2, true);
1010 ASSERT_EQ(ret, false);
1011 }
1012
1013
1014 /**
1015 * @tc.name: CheckFocusIsDownThroughBlockingType
1016 * @tc.desc: CheckFocusIsDownThroughBlockingType
1017 * @tc.type: FUNC
1018 */
HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType01, Function | SmallTest | Level3)1019 HWTEST_F(SceneSessionManagerTest5, CheckFocusIsDownThroughBlockingType01, Function | SmallTest | Level3)
1020 {
1021 ASSERT_NE(ssm_, nullptr);
1022 SessionInfo info;
1023 info.abilityName_ = "test1";
1024 info.bundleName_ = "test2";
1025 sptr<SceneSession> requestSceneSession = new (std::nothrow) SceneSession(info, nullptr);
1026 ASSERT_NE(requestSceneSession, nullptr);
1027 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info, nullptr);
1028 ASSERT_NE(focusedSession, nullptr);
1029 bool includingAppSession = true;
1030 bool ret = ssm_->CheckFocusIsDownThroughBlockingType(requestSceneSession, focusedSession, includingAppSession);
1031 ASSERT_EQ(ret, false);
1032
1033 requestSceneSession->SetZOrder(0);
1034 focusedSession->SetZOrder(1);
1035 focusedSession->blockingFocus_ = true;
1036 focusedSession->state_ = SessionState::STATE_FOREGROUND;
1037 focusedSession->isVisible_ = true;
1038 ssm_->sceneSessionMap_.insert({0, requestSceneSession});
1039 ssm_->sceneSessionMap_.insert({1, focusedSession});
1040 ret = ssm_->CheckFocusIsDownThroughBlockingType(requestSceneSession, focusedSession, includingAppSession);
1041 ASSERT_EQ(ret, true);
1042 }
1043
1044 /**
1045 * @tc.name: CheckTopmostWindowFocus
1046 * @tc.desc: CheckTopmostWindowFocus
1047 * @tc.type: FUNC
1048 */
HWTEST_F(SceneSessionManagerTest5, CheckTopmostWindowFocus, Function | SmallTest | Level3)1049 HWTEST_F(SceneSessionManagerTest5, CheckTopmostWindowFocus, Function | SmallTest | Level3)
1050 {
1051 ASSERT_NE(ssm_, nullptr);
1052 SessionInfo info;
1053 info.abilityName_ = "test1";
1054 info.bundleName_ = "test2";
1055
1056 sptr<SceneSession> focusedSession = new (std::nothrow) SceneSession(info, nullptr);
1057 ASSERT_NE(focusedSession, nullptr);
1058 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1059 ASSERT_NE(sceneSession, nullptr);
1060
1061 bool ret = ssm_->CheckTopmostWindowFocus(focusedSession, sceneSession);
1062 ASSERT_EQ(ret, false);
1063
1064 focusedSession = new (std::nothrow) MainSession(info, nullptr);
1065 focusedSession->SetTopmost(true);
1066 ret = ssm_->CheckTopmostWindowFocus(focusedSession, sceneSession);
1067 ASSERT_EQ(ret, true);
1068 }
1069
1070 /**
1071 * @tc.name: CheckRequestFocusImmdediately
1072 * @tc.desc: CheckRequestFocusImmdediately
1073 * @tc.type: FUNC
1074 */
HWTEST_F(SceneSessionManagerTest5, CheckRequestFocusImmdediately, Function | SmallTest | Level3)1075 HWTEST_F(SceneSessionManagerTest5, CheckRequestFocusImmdediately, Function | SmallTest | Level3)
1076 {
1077 ASSERT_NE(ssm_, nullptr);
1078 SessionInfo info;
1079 info.abilityName_ = "test1";
1080 info.bundleName_ = "test2";
1081
1082 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1083 ASSERT_NE(sceneSession, nullptr);
1084 bool ret = ssm_->CheckRequestFocusImmdediately(sceneSession);
1085 ASSERT_EQ(ret, false);
1086
1087 sptr<Session> session = new (std::nothrow) Session(info);
1088 session->persistentId_ = 1;
1089 sceneSession->dialogVec_.push_back(session);
1090 ssm_->focusedSessionId_ = 1;
1091 ret = ssm_->CheckRequestFocusImmdediately(sceneSession);
1092 ASSERT_EQ(ret, true);
1093 }
1094
1095 /**
1096 * @tc.name: GetNextFocusableSession
1097 * @tc.desc: GetNextFocusableSession
1098 * @tc.type: FUNC
1099 */
HWTEST_F(SceneSessionManagerTest5, GetNextFocusableSession, Function | SmallTest | Level3)1100 HWTEST_F(SceneSessionManagerTest5, GetNextFocusableSession, Function | SmallTest | Level3)
1101 {
1102 int32_t persistentId = 0;
1103 ASSERT_NE(ssm_, nullptr);
1104 SessionInfo info;
1105 info.abilityName_ = "test1";
1106 info.bundleName_ = "test2";
1107
1108 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1109 ASSERT_NE(sceneSession, nullptr);
1110 sptr<SceneSession> result = ssm_->GetNextFocusableSession(persistentId);
1111 ASSERT_EQ(result, nullptr);
1112
1113 sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
1114 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1115 persistentId = 1;
1116 result = ssm_->GetNextFocusableSession(persistentId);
1117 ASSERT_EQ(result, nullptr);
1118 }
1119
1120 /**
1121 * @tc.name: GetTopNearestBlockingFocusSession
1122 * @tc.desc: GetTopNearestBlockingFocusSession
1123 * @tc.type: FUNC
1124 */
HWTEST_F(SceneSessionManagerTest5, GetTopNearestBlockingFocusSession, Function | SmallTest | Level3)1125 HWTEST_F(SceneSessionManagerTest5, GetTopNearestBlockingFocusSession, Function | SmallTest | Level3)
1126 {
1127 ASSERT_NE(ssm_, nullptr);
1128 SessionInfo info;
1129 info.abilityName_ = "test1";
1130 info.bundleName_ = "test2";
1131
1132 ssm_->GetTopNearestBlockingFocusSession(2, true);
1133 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1134 ASSERT_NE(sceneSession, nullptr);
1135 ssm_->GetTopNearestBlockingFocusSession(0, true);
1136
1137 Session session = Session(info);
1138 session.property_ = nullptr;
1139 ssm_->GetTopNearestBlockingFocusSession(0, true);
1140 sptr<SceneSession> session_ = nullptr;
1141 ssm_->GetTopNearestBlockingFocusSession(0, true);
1142 session_ = new (std::nothrow) SceneSession(info, nullptr);
1143 ASSERT_NE(session_, nullptr);
1144 ssm_->GetTopNearestBlockingFocusSession(0, true);
1145 }
1146
1147 /**
1148 * @tc.name: PreloadInLakeApp、UpdateSessionAvoidAreaListener
1149 * @tc.desc: PreloadInLakeApp、UpdateSessionAvoidAreaListener
1150 * @tc.type: FUNC
1151 */
HWTEST_F(SceneSessionManagerTest5, PreloadInLakeApp, Function | SmallTest | Level3)1152 HWTEST_F(SceneSessionManagerTest5, PreloadInLakeApp, Function | SmallTest | Level3)
1153 {
1154 ASSERT_NE(ssm_, nullptr);
1155 SessionInfo info;
1156 info.abilityName_ = "test1";
1157 info.bundleName_ = "test2";
1158 int32_t persistentId = 0;
1159
1160 ssm_->PreloadInLakeApp("");
1161 sptr<SceneSession> sceneSession = nullptr;
1162
1163 ssm_->UpdateSessionAvoidAreaListener(persistentId, true);
1164 sceneSession = ssm_->CreateSceneSession(info, nullptr);
1165 ASSERT_NE(nullptr, sceneSession);
1166 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1167 ssm_->UpdateSessionAvoidAreaListener(persistentId, true);
1168 }
1169
1170 /**
1171 * @tc.name: NotifyMMIWindowPidChange
1172 * @tc.desc: NotifyMMIWindowPidChange
1173 * @tc.type: FUNC
1174 */
HWTEST_F(SceneSessionManagerTest5, NotifyMMIWindowPidChange, Function | SmallTest | Level3)1175 HWTEST_F(SceneSessionManagerTest5, NotifyMMIWindowPidChange, Function | SmallTest | Level3)
1176 {
1177 ASSERT_NE(ssm_, nullptr);
1178 SessionInfo info;
1179 info.abilityName_ = "test1";
1180 info.bundleName_ = "test2";
1181 sptr<SceneSession> sceneSession = nullptr;
1182 ssm_->NotifyMMIWindowPidChange(0, true);
1183 sceneSession = ssm_->CreateSceneSession(info, nullptr);
1184 ASSERT_NE(nullptr, sceneSession);
1185 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1186 }
1187
1188 /**
1189 * @tc.name: ConfigDecor
1190 * @tc.desc: SceneSesionManager config decor
1191 * @tc.type: FUNC
1192 */
HWTEST_F(SceneSessionManagerTest5, ConfigDecor02, Function | SmallTest | Level3)1193 HWTEST_F(SceneSessionManagerTest5, ConfigDecor02, Function | SmallTest | Level3)
1194 {
1195 ASSERT_NE(ssm_, nullptr);
1196 WindowSceneConfig::ConfigItem* item = new WindowSceneConfig::ConfigItem;
1197 ASSERT_NE(item, nullptr);
1198 ssm_->ConfigDecor(*item, false);
1199 delete item;
1200 }
1201
1202 /**
1203 * @tc.name: SetSkipSelfWhenShowOnVirtualScreen
1204 * @tc.desc: SetSkipSelfWhenShowOnVirtualScreen
1205 * @tc.type: FUNC
1206 */
HWTEST_F(SceneSessionManagerTest5, SetSkipSelfWhenShowOnVirtualScreen, Function | SmallTest | Level3)1207 HWTEST_F(SceneSessionManagerTest5, SetSkipSelfWhenShowOnVirtualScreen, Function | SmallTest | Level3)
1208 {
1209 ASSERT_NE(ssm_, nullptr);
1210 SessionInfo info;
1211 info.abilityName_ = "test1";
1212 info.bundleName_ = "test2";
1213 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1214 ASSERT_NE(property, nullptr);
1215 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1216 uint64_t surfaceNodeId = 1234;
1217 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, false);
1218 ssm_->SetSkipSelfWhenShowOnVirtualScreen(surfaceNodeId, true);
1219 }
1220
1221 /**
1222 * @tc.name: CreateKeyboardPanelSession
1223 * @tc.desc: CreateKeyboardPanelSession
1224 * @tc.type: FUNC
1225 */
HWTEST_F(SceneSessionManagerTest5, CreateKeyboardPanelSession02, Function | SmallTest | Level3)1226 HWTEST_F(SceneSessionManagerTest5, CreateKeyboardPanelSession02, Function | SmallTest | Level3)
1227 {
1228 ASSERT_NE(ssm_, nullptr);
1229 SessionInfo info;
1230 info.abilityName_ = "test1";
1231 info.bundleName_ = "test2";
1232 info.screenId_ = SCREEN_ID_INVALID;
1233 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1234 ASSERT_NE(property, nullptr);
1235 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
1236 sptr<SceneSession> sceneSession = nullptr;
1237 ssm_->CreateKeyboardPanelSession(sceneSession);
1238 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1239 ssm_->CreateKeyboardPanelSession(sceneSession);
1240 }
1241
1242 /**
1243 * @tc.name: InitSceneSession02
1244 * @tc.desc: InitSceneSession02
1245 * @tc.type: FUNC
1246 */
HWTEST_F(SceneSessionManagerTest5, InitSceneSession02, Function | SmallTest | Level3)1247 HWTEST_F(SceneSessionManagerTest5, InitSceneSession02, Function | SmallTest | Level3)
1248 {
1249 ASSERT_NE(nullptr, ssm_);
1250 SessionInfo sessionInfo;
1251 sessionInfo.bundleName_ = "test1";
1252 sessionInfo.abilityName_ = "test2";
1253 sessionInfo.abilityInfo = nullptr;
1254 sessionInfo.isAtomicService_ = true;
1255 sessionInfo.screenId_ = SCREEN_ID_INVALID;
1256 unsigned int flags = 1111;
1257 sessionInfo.want = std::make_shared<AAFwk::Want>();
1258 ASSERT_NE(nullptr, sessionInfo.want);
1259 sessionInfo.want->SetFlags(flags);
1260 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1261 ASSERT_NE(nullptr, sceneSession);
1262 ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession));
1263 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1264 ASSERT_NE(nullptr, property);
1265 sceneSession = new (std::nothrow) SceneSession(sessionInfo, nullptr);
1266 ASSERT_NE(nullptr, sceneSession);
1267 sceneSession->SetSessionProperty(property);
1268
1269 ssm_->InitSceneSession(sceneSession, sessionInfo, nullptr);
1270 ASSERT_EQ(DISPLAY_ID_INVALID, sceneSession->GetSessionInfo().screenId_);
1271 }
1272
1273 /**
1274 * @tc.name: PrepareTerminate
1275 * @tc.desc: SceneSesionManager prepare terminate
1276 * @tc.type: FUNC
1277 */
HWTEST_F(SceneSessionManagerTest5, PrepareTerminate03, Function | SmallTest | Level3)1278 HWTEST_F(SceneSessionManagerTest5, PrepareTerminate03, Function | SmallTest | Level3)
1279 {
1280 ASSERT_NE(nullptr, ssm_);
1281 SessionInfo sessionInfo;
1282 sessionInfo.bundleName_ = "PrepareTerminate";
1283 sessionInfo.abilityName_ = "PrepareTerminate";
1284 sessionInfo.abilityInfo = nullptr;
1285 int32_t persistentId = 1;
1286 bool isPrepareTerminate = true;
1287 ASSERT_EQ(WSError::WS_OK, ssm_->PrepareTerminate(persistentId, isPrepareTerminate));
1288 }
1289
1290 /**
1291 * @tc.name: RequestSceneSessionBackground
1292 * @tc.desc: RequestSceneSessionBackground
1293 * @tc.type: FUNC
1294 */
HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground, Function | SmallTest | Level3)1295 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground, Function | SmallTest | Level3)
1296 {
1297 ASSERT_NE(ssm_, nullptr);
1298 SessionInfo info;
1299 info.abilityName_ = "test1";
1300 info.bundleName_ = "test2";
1301 info.ancoSceneState = 0;
1302 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1303 ASSERT_NE(property, nullptr);
1304 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1305 sptr<SceneSession> sceneSession = nullptr;
1306 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1307 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, true, true, true));
1308 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1309 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, false, false, false));
1310 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, true, false, true));
1311 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, true, true, true));
1312 }
1313
1314 /**
1315 * @tc.name: AddClientDeathRecipient
1316 * @tc.desc: SceneSesionManager add client death recipient
1317 * @tc.type: FUNC
1318 */
HWTEST_F(SceneSessionManagerTest5, AddClientDeathRecipient02, Function | SmallTest | Level3)1319 HWTEST_F(SceneSessionManagerTest5, AddClientDeathRecipient02, Function | SmallTest | Level3)
1320 {
1321 ASSERT_NE(ssm_, nullptr);
1322 SessionInfo info;
1323 info.abilityName_ = "AddClientDeathRecipient";
1324 info.bundleName_ = "AddClientDeathRecipient";
1325 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1326 ASSERT_NE(nullptr, sceneSession);
1327 ssm_->AddClientDeathRecipient(nullptr, sceneSession);
1328 sptr<ISessionStage> sessionStage = new (std::nothrow) SessionStageMocker();
1329 ssm_->AddClientDeathRecipient(sessionStage, sceneSession);
1330 }
1331
1332 /**
1333 * @tc.name: CheckModalSubWindowPermission
1334 * @tc.desc: CheckModalSubWindowPermission
1335 * @tc.type: FUNC
1336 */
HWTEST_F(SceneSessionManagerTest5, CheckModalSubWindowPermission, Function | SmallTest | Level3)1337 HWTEST_F(SceneSessionManagerTest5, CheckModalSubWindowPermission, Function | SmallTest | Level3)
1338 {
1339 ASSERT_NE(ssm_, nullptr);
1340 SessionInfo info;
1341 info.abilityName_ = "test1";
1342 info.bundleName_ = "test2";
1343 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1344 ASSERT_NE(property, nullptr);
1345 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1346 property->SetWindowFlags(123);
1347 ssm_->CheckModalSubWindowPermission(property);
1348 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1349 ssm_->CheckModalSubWindowPermission(property);
1350 }
1351
1352 /**
1353 * @tc.name: CheckSessionPropertyOnRecovery
1354 * @tc.desc: CheckSessionPropertyOnRecovery
1355 * @tc.type: FUNC
1356 */
HWTEST_F(SceneSessionManagerTest5, CheckSessionPropertyOnRecovery, Function | SmallTest | Level3)1357 HWTEST_F(SceneSessionManagerTest5, CheckSessionPropertyOnRecovery, Function | SmallTest | Level3)
1358 {
1359 ASSERT_NE(ssm_, nullptr);
1360 SessionInfo info;
1361 info.abilityName_ = "test1";
1362 info.bundleName_ = "test2";
1363 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1364 ASSERT_NE(property, nullptr);
1365 property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
1366 property->SetWindowFlags(123);
1367 WSError result = ssm_->CheckSessionPropertyOnRecovery(property, false);
1368 ASSERT_EQ(result, WSError::WS_ERROR_NOT_SYSTEM_APP);
1369
1370 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1371 property->SetParentPersistentId(111);
1372 result = ssm_->CheckSessionPropertyOnRecovery(property, true);
1373 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
1374 ssm_->CheckSessionPropertyOnRecovery(property, true);
1375 }
1376
1377 /**
1378 * @tc.name: SetCreateKeyboardSessionListener
1379 * @tc.desc: SetCreateKeyboardSessionListener
1380 * @tc.type: FUNC
1381 */
HWTEST_F(SceneSessionManagerTest5, SetCreateKeyboardSessionListener, Function | SmallTest | Level3)1382 HWTEST_F(SceneSessionManagerTest5, SetCreateKeyboardSessionListener, Function | SmallTest | Level3)
1383 {
1384 ASSERT_NE(ssm_, nullptr);
1385 ssm_->SetCreateSystemSessionListener(nullptr);
1386 SessionInfo sessionInfo;
1387 sessionInfo.bundleName_ = "test1";
1388 sessionInfo.abilityName_ = "test2";
1389 sessionInfo.abilityInfo = nullptr;
1390 sessionInfo.isAtomicService_ = true;
1391 sessionInfo.screenId_ = SCREEN_ID_INVALID;
1392 ssm_->NotifySessionTouchOutside(123);
1393 }
1394
1395 /**
1396 * @tc.name: DestroyAndDisconnectSpecificSessionInner
1397 * @tc.desc: check func DestroyAndDisconnectSpecificSessionInner
1398 * @tc.type: FUNC
1399 */
HWTEST_F(SceneSessionManagerTest5, DestroyAndDisconnectSpecificSessionInner02, Function | SmallTest | Level2)1400 HWTEST_F(SceneSessionManagerTest5, DestroyAndDisconnectSpecificSessionInner02, Function | SmallTest | Level2)
1401 {
1402 ASSERT_NE(ssm_, nullptr);
1403 SessionInfo info;
1404 info.abilityName_ = "test1";
1405 info.bundleName_ = "test2";
1406 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1407 ASSERT_NE(nullptr, property);
1408 std::vector<int32_t> recoveredPersistentIds = {0, 1, 2};
1409 ssm_->SetAlivePersistentIds(recoveredPersistentIds);
1410 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1411 ssm_->DestroyAndDisconnectSpecificSessionInner(1);
1412 }
1413
1414 /**
1415 * @tc.name: DestroyToastSession
1416 * @tc.desc: DestroyToastSession
1417 * @tc.type: FUNC
1418 */
HWTEST_F(SceneSessionManagerTest5, DestroyToastSession, Function | SmallTest | Level3)1419 HWTEST_F(SceneSessionManagerTest5, DestroyToastSession, Function | SmallTest | Level3)
1420 {
1421 ASSERT_NE(ssm_, nullptr);
1422 SessionInfo info;
1423 info.abilityName_ = "test1";
1424 info.bundleName_ = "test2";
1425 info.screenId_ = SCREEN_ID_INVALID;
1426 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1427 ASSERT_NE(property, nullptr);
1428 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
1429 sptr<SceneSession> sceneSession = nullptr;
1430 ssm_->DestroyToastSession(sceneSession);
1431 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1432 ssm_->DestroyToastSession(sceneSession);
1433 ssm_->StartUIAbilityBySCB(sceneSession);
1434 int32_t ret = ssm_->ChangeUIAbilityVisibilityBySCB(sceneSession, true);
1435 EXPECT_NE(ret, ERR_OK);
1436 }
1437
1438 /**
1439 * @tc.name: RequestSceneSessionBackground
1440 * @tc.desc: RequestSceneSessionBackground
1441 * @tc.type: FUNC
1442 */
HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground02, Function | SmallTest | Level3)1443 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground02, Function | SmallTest | Level3)
1444 {
1445 ASSERT_NE(ssm_, nullptr);
1446 SessionInfo info;
1447 info.abilityName_ = "test1";
1448 info.bundleName_ = "test2";
1449 info.ancoSceneState = 0;
1450 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1451 ASSERT_NE(property, nullptr);
1452 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1453 sptr<Session> session = new (std::nothrow) Session(info);
1454 ASSERT_NE(session, nullptr);
1455 sptr<SceneSession> sceneSession = nullptr;
1456 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1457 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1458 session->SetSessionInfoPersistentId(123);
1459 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, false, false, false));
1460 session->SetSessionInfoPersistentId(0);
1461 ASSERT_EQ(WSError::WS_OK, ssm_->RequestSceneSessionBackground(sceneSession, false, false, true));
1462 }
1463
1464 /**
1465 * @tc.name: ConfigAppWindowShadow
1466 * @tc.desc: SceneSesionManager config app window shadow
1467 * @tc.type: FUNC
1468 */
HWTEST_F(SceneSessionManagerTest5, ConfigAppWindowShadow03, Function | SmallTest | Level3)1469 HWTEST_F(SceneSessionManagerTest5, ConfigAppWindowShadow03, Function | SmallTest | Level3)
1470 {
1471 ASSERT_NE(ssm_, nullptr);
1472 WindowSceneConfig::ConfigItem item;
1473 WindowSceneConfig::ConfigItem shadowConfig;
1474 WindowShadowConfig outShadow;
1475 std::vector<float> floatTest = {0.0f, 0.1f, 0.2f, 0.3f};
1476 bool result = ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1477 ASSERT_EQ(result, true);
1478
1479 item.SetValue(floatTest);
1480 shadowConfig.SetValue({{"offsetX", item}});
1481 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1482
1483 shadowConfig.SetValue({{"offsetY", item}});
1484 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1485
1486 item.SetValue(new std::string(""));
1487 shadowConfig.SetValue({{"color", item}});
1488 ssm_->ConfigAppWindowShadow(shadowConfig, outShadow);
1489 }
1490
1491 /**
1492 * @tc.name: CreateAndConnectSpecificSession
1493 * @tc.desc: CreateAndConnectSpecificSession
1494 * @tc.type: FUNC
1495 */
HWTEST_F(SceneSessionManagerTest5, CreateAndConnectSpecificSession02, Function | SmallTest | Level3)1496 HWTEST_F(SceneSessionManagerTest5, CreateAndConnectSpecificSession02, Function | SmallTest | Level3)
1497 {
1498 ASSERT_NE(ssm_, nullptr);
1499 sptr<ISessionStage> sessionStage = new (std::nothrow) SessionStageMocker();
1500 ASSERT_NE(sessionStage, nullptr);
1501 sptr<IWindowEventChannel> eventChannel = new (std::nothrow) WindowEventChannelMocker(sessionStage);
1502 ASSERT_NE(eventChannel, nullptr);
1503 std::shared_ptr<RSSurfaceNode> node = nullptr;
1504 sptr<ISession> session;
1505 SystemSessionConfig systemConfig;
1506 sptr<IRemoteObject> token;
1507 int32_t id = 0;
1508 SessionInfo info;
1509 info.abilityName_ = "test1";
1510 info.bundleName_ = "test2";
1511 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1512 ASSERT_NE(property, nullptr);
1513 CommonTestUtils::GuaranteeFloatWindowPermission("ws_scene_session_manager_test5");
1514 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1515 property->SetWindowFlags(123);
1516 WSError res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1517 systemConfig, token);
1518 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, res); // create main window, property must be nullptr
1519 sessionStage = new (std::nothrow) SessionStageMocker();
1520
1521 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1522 res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1523 systemConfig, token);
1524 ASSERT_EQ(WSError::WS_OK, res);
1525 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1526 res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1527 systemConfig, token);
1528 ASSERT_EQ(WSError::WS_OK, res);
1529 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1530 res = ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,
1531 systemConfig, token);
1532 ASSERT_EQ(WSError::WS_OK, res);
1533 }
1534
1535 /**
1536 * @tc.name: ProcessDialogRequestFocusImmdediately
1537 * @tc.desc: ProcessDialogRequestFocusImmdediately
1538 * @tc.type: FUNC
1539 */
HWTEST_F(SceneSessionManagerTest5, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)1540 HWTEST_F(SceneSessionManagerTest5, ProcessDialogRequestFocusImmdediately02, Function | SmallTest | Level3)
1541 {
1542 ASSERT_NE(ssm_, nullptr);
1543 SessionInfo info;
1544 info.abilityName_ = "test1";
1545 info.bundleName_ = "test2";
1546 info.persistentId_ = 123;
1547 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1548 ASSERT_NE(sceneSession, nullptr);
1549 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1550 ASSERT_NE(property, nullptr);
1551 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1552 auto ret = ssm_->ProcessDialogRequestFocusImmdediately(sceneSession);
1553 EXPECT_EQ(WSError::WS_DO_NOTHING, ret);
1554 }
1555
1556 /**
1557 * @tc.name: RequestSceneSessionByCall
1558 * @tc.desc: SceneSesionManager request scene session by call
1559 * @tc.type: FUNC
1560 */
HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionByCall02, Function | SmallTest | Level3)1561 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionByCall02, Function | SmallTest | Level3)
1562 {
1563 ASSERT_NE(ssm_, nullptr);
1564 sptr<SceneSession> scensession = nullptr;
1565 ssm_->RequestSceneSessionByCall(nullptr);
1566 SessionInfo info;
1567 info.abilityName_ = "test1";
1568 info.bundleName_ = "test2";
1569 scensession = sptr<SceneSession>::MakeSptr(info, nullptr);
1570 ssm_->RequestSceneSessionByCall(scensession);
1571 }
1572
1573 /**
1574 * @tc.name: GetAllAbilityInfos
1575 * @tc.desc: Test if pip window can be created;
1576 * @tc.type: FUNC
1577 */
HWTEST_F(SceneSessionManagerTest5, GetAllAbilityInfos02, Function | SmallTest | Level3)1578 HWTEST_F(SceneSessionManagerTest5, GetAllAbilityInfos02, Function | SmallTest | Level3)
1579 {
1580 ASSERT_NE(ssm_, nullptr);
1581 AAFwk::Want want;
1582 AppExecFwk::ElementName elementName = want.GetElement();
1583 int32_t userId = 1;
1584 std::vector<SCBAbilityInfo> scbAbilityInfos;
1585 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1586
1587 elementName.bundleName_ = "test";
1588 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1589
1590 elementName.abilityName_ = "test";
1591 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1592
1593 elementName.bundleName_ = "";
1594 ssm_->GetAllAbilityInfos(want, userId, scbAbilityInfos);
1595 }
1596
1597 /**
1598 * @tc.name: GetBatchAbilityInfos01
1599 * @tc.desc: GetBatchAbilityInfos01
1600 * @tc.type: FUNC
1601 */
HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos01, Function | SmallTest | Level3)1602 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos01, Function | SmallTest | Level3)
1603 {
1604 ASSERT_NE(ssm_, nullptr);
1605 auto bundleMgr = ssm_->bundleMgr_;
1606 ssm_->bundleMgr_ = nullptr;
1607 int32_t userId = 100;
1608 std::vector<std::string> bundleNames = { "test1", "test2" };
1609 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1610 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1611 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
1612 }
1613
1614 /**
1615 * @tc.name: GetBatchAbilityInfos02
1616 * @tc.desc: GetBatchAbilityInfos02
1617 * @tc.type: FUNC
1618 */
HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos02, Function | SmallTest | Level3)1619 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos02, Function | SmallTest | Level3)
1620 {
1621 ASSERT_NE(ssm_, nullptr);
1622 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1623 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1624 int32_t userId = 100;
1625 std::vector<std::string> bundleNames = {};
1626 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1627 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1628 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1629 }
1630
1631 /**
1632 * @tc.name: GetBatchAbilityInfos03
1633 * @tc.desc: GetBatchAbilityInfos03
1634 * @tc.type: FUNC
1635 */
HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos03, Function | SmallTest | Level3)1636 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos03, Function | SmallTest | Level3)
1637 {
1638 ASSERT_NE(ssm_, nullptr);
1639 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1640 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1641 int32_t userId = 100;
1642 std::vector<std::string> bundleNames = { "" };
1643 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1644 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1645 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1646 }
1647
1648 /**
1649 * @tc.name: GetBatchAbilityInfos04
1650 * @tc.desc: GetBatchAbilityInfos04
1651 * @tc.type: FUNC
1652 */
HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos04, Function | SmallTest | Level3)1653 HWTEST_F(SceneSessionManagerTest5, GetBatchAbilityInfos04, Function | SmallTest | Level3)
1654 {
1655 ASSERT_NE(ssm_, nullptr);
1656 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
1657 ssm_->bundleMgr_ = sptr<AppExecFwk::BundleMgrProxy>::MakeSptr(iRemoteObjectMocker);
1658 int32_t userId = 100;
1659 std::vector<std::string> bundleNames = { "test1", "test2" };
1660 auto scbAbilityInfos = std::make_shared<std::vector<SCBAbilityInfo>>();
1661 WSError ret = ssm_->GetBatchAbilityInfos(bundleNames, userId, *scbAbilityInfos);
1662 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PARAM);
1663 }
1664
1665 /**
1666 * @tc.name: FindMainWindowWithToken
1667 * @tc.desc: SceneSesionManager find main window with token
1668 * @tc.type: FUNC
1669 */
HWTEST_F(SceneSessionManagerTest5, FindMainWindowWithToken02, Function | SmallTest | Level3)1670 HWTEST_F(SceneSessionManagerTest5, FindMainWindowWithToken02, Function | SmallTest | Level3)
1671 {
1672 ASSERT_NE(ssm_, nullptr);
1673 SessionInfo info;
1674 info.abilityName_ = "test1";
1675 info.bundleName_ = "test2";
1676 info.persistentId_ = 123;
1677 sptr<IRemoteObject> targetToken = nullptr;
1678 ssm_->FindMainWindowWithToken(targetToken);
1679 targetToken = new (std::nothrow) IRemoteObjectMocker();
1680 ASSERT_NE(targetToken, nullptr);
1681 ssm_->FindMainWindowWithToken(targetToken);
1682 sptr<SceneSession> scensession = sptr<SceneSession>::MakeSptr(info, nullptr);
1683 ssm_->FindMainWindowWithToken(targetToken);
1684 }
1685
1686 /**
1687 * @tc.name: RequestSceneSessionBackground
1688 * @tc.desc: RequestSceneSessionBackground
1689 * @tc.type: FUNC
1690 */
HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground03, Function | SmallTest | Level3)1691 HWTEST_F(SceneSessionManagerTest5, RequestSceneSessionBackground03, Function | SmallTest | Level3)
1692 {
1693 ASSERT_NE(ssm_, nullptr);
1694 SessionInfo info;
1695 info.abilityName_ = "test1";
1696 info.bundleName_ = "test2";
1697 info.persistentId_ = 0;
1698 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1699 ASSERT_NE(property, nullptr);
1700 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1701 sptr<Session> session = new (std::nothrow) Session(info);
1702 ASSERT_NE(session, nullptr);
1703 std::shared_ptr<std::promise<int32_t>> promise = std::make_shared<std::promise<int32_t>>();
1704 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1705 session->SetSessionInfoPersistentId(0);
1706 ssm_->RequestSceneSessionBackground(sceneSession, false, false, true);
1707 }
1708
1709 /**
1710 * @tc.name: DestroyToastSession
1711 * @tc.desc: DestroyToastSession
1712 * @tc.type: FUNC
1713 */
HWTEST_F(SceneSessionManagerTest5, DestroyToastSession02, Function | SmallTest | Level3)1714 HWTEST_F(SceneSessionManagerTest5, DestroyToastSession02, Function | SmallTest | Level3)
1715 {
1716 ASSERT_NE(ssm_, nullptr);
1717 SessionInfo info;
1718 info.abilityName_ = "test1";
1719 info.bundleName_ = "test2";
1720 info.screenId_ = SCREEN_ID_INVALID;
1721 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1722 ASSERT_NE(property, nullptr);
1723 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
1724 sptr<SceneSession> sceneSession = nullptr;
1725 ssm_->DestroyToastSession(sceneSession);
1726 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1727 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1728 ssm_->DestroyToastSession(sceneSession);
1729 }
1730
1731 /**
1732 * @tc.name: CheckModalSubWindowPermission
1733 * @tc.desc: CheckModalSubWindowPermission
1734 * @tc.type: FUNC
1735 */
HWTEST_F(SceneSessionManagerTest5, CheckModalSubWindowPermission02, Function | SmallTest | Level3)1736 HWTEST_F(SceneSessionManagerTest5, CheckModalSubWindowPermission02, Function | SmallTest | Level3)
1737 {
1738 ASSERT_NE(ssm_, nullptr);
1739 SessionInfo info;
1740 info.abilityName_ = "test1";
1741 info.bundleName_ = "test2";
1742 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1743 ASSERT_NE(property, nullptr);
1744 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1745 property->SetWindowFlags(123);
1746 property->SetTopmost(true);
1747 ssm_->CheckModalSubWindowPermission(property);
1748 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
1749 ssm_->CheckModalSubWindowPermission(property);
1750 }
1751
1752 /**
1753 * @tc.name: RequestFocusStatusBySCB
1754 * @tc.desc: SceneSessionManager request focus status from SCB
1755 * @tc.type: FUNC
1756 */
HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB, Function | SmallTest | Level3)1757 HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB, Function | SmallTest | Level3)
1758 {
1759 ssm_->sceneSessionMap_.clear();
1760 SessionInfo info;
1761 info.abilityName_ = "RequestFocusTest";
1762 info.bundleName_ = "RequestFocusTest";
1763 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1764 property->SetFocusable(true);
1765 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1766 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1767 sceneSession->property_ = property;
1768 sceneSession->persistentId_ = 1;
1769 sceneSession->isVisible_ = true;
1770 sceneSession->state_ = SessionState::STATE_ACTIVE;
1771 ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession});
1772
1773 FocusChangeReason reason = FocusChangeReason::FOREGROUND;
1774 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1775 usleep(WAIT_SYNC_IN_NS);
1776 ASSERT_EQ(ssm_->focusedSessionId_, 1);
1777
1778 reason = FocusChangeReason::CLICK;
1779 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1780 usleep(WAIT_SYNC_IN_NS);
1781 ASSERT_EQ(ssm_->focusedSessionId_, 1);
1782
1783 ssm_->RequestFocusStatusBySCB(1, false, false, reason);
1784 usleep(WAIT_SYNC_IN_NS);
1785 ASSERT_NE(ssm_->focusedSessionId_, 1);
1786
1787 reason = FocusChangeReason::MOVE_UP;
1788 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1789 usleep(WAIT_SYNC_IN_NS);
1790 FocusChangeReason reasonResult = sceneSession->GetPostProcessFocusState().reason_;
1791 ASSERT_EQ(reasonResult, FocusChangeReason::MOVE_UP);
1792
1793 reason = FocusChangeReason::DEFAULT;
1794 ssm_->RequestFocusStatusBySCB(1, true, false, reason);
1795 usleep(WAIT_SYNC_IN_NS);
1796 ASSERT_EQ(ssm_->focusedSessionId_, 1);
1797 }
1798
1799 }
1800 } // namespace Rosen
1801 } // namespace OHOS
1802