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 <bundlemgr/launcher_service.h>
20
21 #include "common_test_utils.h"
22 #include "context.h"
23 #include "interfaces/include/ws_common.h"
24 #include "iremote_object_mocker.h"
25 #include "mock/mock_accesstoken_kit.h"
26 #include "mock/mock_session_stage.h"
27 #include "mock/mock_scene_session.h"
28 #include "mock/mock_window_event_channel.h"
29 #include "mock/mock_accesstoken_kit.h"
30 #include "session_info.h"
31 #include "session_manager.h"
32 #include "session_manager/include/scene_session_manager.h"
33 #include "session/host/include/scene_session.h"
34 #include "session/host/include/main_session.h"
35 #include "window_manager_agent.h"
36 #include "zidl/window_manager_agent_interface.h"
37 #include "mock/mock_window_manager_agent_lite.h"
38 #include "session_manager/include/session_manager_agent_controller.h"
39 #include "session_manager/include/zidl/session_router_stack_listener_stub.h"
40 #include "ui_effect_manager.h"
41 #include "ui_effect_controller_client_proxy.h"
42
43 using namespace testing;
44 using namespace testing::ext;
45
46 namespace OHOS {
47 namespace Rosen {
48 class KeyboardTestData;
49 class SceneSessionManagerTest12 : public testing::Test {
50 public:
51 static void SetUpTestCase();
52 static void TearDownTestCase();
53 void SetUp() override;
54 void TearDown() override;
55
56 // keyboard
57 void ConstructKeyboardCallingWindowTestData(const KeyboardTestData& keyboardTestData);
58 bool CheckKeyboardOccupiedAreaInfo(const Rect& desiredRect, const WSRect& actualRect);
59 void GetKeyboardOccupiedAreaWithRotationTestData(WindowUIType windowType,
60 DisplayId cDisplayId,
61 DisplayId kDisplayId,
62 SessionState keyboardState,
63 WindowGravity gravity);
64 WSError NotifyDisplayIdChanged(int32_t persistentId, uint64_t displayId);
65
66 static sptr<SceneSessionManager> ssm_;
67
68 private:
69 static constexpr uint32_t WAIT_SYNC_IN_NS = 200000;
70 };
71
72 sptr<SceneSessionManager> SceneSessionManagerTest12::ssm_ = nullptr;
73
SetUpTestCase()74 void SceneSessionManagerTest12::SetUpTestCase()
75 {
76 ssm_ = &SceneSessionManager::GetInstance();
77 }
78
TearDownTestCase()79 void SceneSessionManagerTest12::TearDownTestCase()
80 {
81 ssm_ = nullptr;
82 }
83
SetUp()84 void SceneSessionManagerTest12::SetUp() {}
85
TearDown()86 void SceneSessionManagerTest12::TearDown()
87 {
88 usleep(WAIT_SYNC_IN_NS);
89 MockAccesstokenKit::ChangeMockStateToInit();
90 }
91
92 const Rect landscapePanelRect_ = { 0, 538, 2720, 722 };
93 const Rect portraitPanelRect_ = { 0, 1700, 1260, 1020 };
94 std::vector<std::pair<bool, WSRect>> avoidAreas_ = {};
CheckKeyboardOccupiedAreaInfo(const Rect & desiredRect,const WSRect & actualRect)95 bool SceneSessionManagerTest12::CheckKeyboardOccupiedAreaInfo(const Rect& desiredRect, const WSRect& actualRect)
96 {
97 return desiredRect.posX_ == actualRect.posX_ && desiredRect.posY_ == actualRect.posY_ &&
98 static_cast<int32_t>(desiredRect.width_) == actualRect.width_ &&
99 static_cast<int32_t>(desiredRect.height_) == actualRect.height_;
100 }
101
GetKeyboardOccupiedAreaWithRotationTestData(WindowUIType windowType,DisplayId cDisplayId,DisplayId kDisplayId,SessionState keyboardState,WindowGravity gravity)102 void SceneSessionManagerTest12::GetKeyboardOccupiedAreaWithRotationTestData(WindowUIType windowType,
103 DisplayId cDisplayId,
104 DisplayId kDisplayId,
105 SessionState keyboardState,
106 WindowGravity gravity)
107 {
108 ssm_->sceneSessionMap_.clear();
109 avoidAreas_.clear();
110 ssm_->systemConfig_.windowUIType_ = windowType;
111 SessionInfo callingSessionInfo;
112 callingSessionInfo.abilityName_ = "callingSession";
113 callingSessionInfo.bundleName_ = "callingSession";
114 sptr<SceneSession> callingSession = sptr<SceneSession>::MakeSptr(callingSessionInfo, nullptr);
115 sptr<WindowSessionProperty> callingSessionProperties = sptr<WindowSessionProperty>::MakeSptr();
116 callingSessionProperties->SetDisplayId(cDisplayId);
117 callingSession->SetSessionProperty(callingSessionProperties);
118
119 SessionInfo keyboardSessionInfo;
120 keyboardSessionInfo.abilityName_ = "keyboardSession";
121 keyboardSessionInfo.bundleName_ = "keyboardSession";
122 sptr<SceneSession> keyboardSession = sptr<SceneSession>::MakeSptr(keyboardSessionInfo, nullptr);
123 keyboardSession->SetScreenId(kDisplayId);
124 sptr<WindowSessionProperty> keyboardProperties = sptr<WindowSessionProperty>::MakeSptr();
125 keyboardProperties->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
126 keyboardProperties->SetIsSystemKeyboard(false);
127 KeyboardLayoutParams params;
128 params.LandscapePanelRect_ = landscapePanelRect_;
129 params.PortraitPanelRect_ = portraitPanelRect_;
130 params.gravity_ = gravity;
131 keyboardProperties->SetKeyboardLayoutParams(params);
132 keyboardSession->SetSessionState(keyboardState);
133 keyboardSession->SetSessionProperty(keyboardProperties);
134
135 ssm_->sceneSessionMap_.insert({ 1, callingSession });
136 ssm_->sceneSessionMap_.insert({ 2, keyboardSession });
137 }
138
139 class KeyboardTestData {
140 public:
KeyboardTestData(uint64_t cScreenId,int32_t cPid,int32_t kScreenId,WindowType keyboardWindowType,bool isSysKeyboard)141 KeyboardTestData(uint64_t cScreenId,
142 int32_t cPid,
143 int32_t kScreenId,
144 WindowType keyboardWindowType,
145 bool isSysKeyboard)
146 : cScreenId_(cScreenId),
147 cPid_(cPid),
148 kScreenId_(kScreenId),
149 keyboardWindowType_(keyboardWindowType),
150 isSysKeyboard_(isSysKeyboard)
151 {
152 }
153
SetCallingSessionId(uint32_t callingSessionId)154 void SetCallingSessionId(uint32_t callingSessionId)
155 {
156 callingSessionId_ = callingSessionId;
157 }
158
159 private:
160 uint64_t cScreenId_; // screenId of callingWindow
161 int32_t cPid_; // callingPid of callingWindow
162 int32_t kScreenId_; // screenId of keyboard
163 WindowType keyboardWindowType_;
164 bool isSysKeyboard_;
165 uint32_t callingSessionId_;
166 };
167
ConstructKeyboardCallingWindowTestData(const KeyboardTestData & keyboardTestData)168 void SceneSessionManagerTest12::ConstructKeyboardCallingWindowTestData(const KeyboardTestData& keyboardTestData)
169 {
170 ssm_->sceneSessionMap_.clear();
171 SessionInfo callingSessionInfo;
172 callingSessionInfo.abilityName_ = "callingSession";
173 callingSessionInfo.bundleName_ = "callingSession";
174 callingSessionInfo.screenId_ = keyboardTestData.cScreenId_;
175 sptr<SceneSession> callingSession = sptr<SceneSession>::MakeSptr(callingSessionInfo, nullptr);
176 callingSession->callingPid_ = keyboardTestData.cPid_;
177 sptr<WindowSessionProperty> callingSessionProperties = sptr<WindowSessionProperty>::MakeSptr();
178 callingSessionProperties->SetDisplayId(keyboardTestData.cScreenId_);
179 callingSession->SetSessionProperty(callingSessionProperties);
180
181 SessionInfo keyboardSessionInfo;
182 keyboardSessionInfo.abilityName_ = "keyboardSession";
183 keyboardSessionInfo.bundleName_ = "keyboardSession";
184 sptr<SceneSession> keyboardSession = sptr<SceneSession>::MakeSptr(keyboardSessionInfo, nullptr);
185
186 keyboardSession->SetScreenId(keyboardTestData.kScreenId_);
187 sptr<WindowSessionProperty> keyboardProperties = sptr<WindowSessionProperty>::MakeSptr();
188 keyboardProperties->SetWindowType(keyboardTestData.keyboardWindowType_);
189 keyboardProperties->SetIsSystemKeyboard(keyboardTestData.isSysKeyboard_);
190 keyboardProperties->SetCallingSessionId(keyboardTestData.callingSessionId_);
191 keyboardSession->SetSessionProperty(keyboardProperties);
192
193 ssm_->sceneSessionMap_.insert({ keyboardTestData.callingSessionId_, callingSession });
194 ssm_->sceneSessionMap_.insert({ 2, keyboardSession });
195 }
196
NotifyDisplayIdChanged(int32_t persistentId,uint64_t displayId)197 WSError SceneSessionManagerTest12::NotifyDisplayIdChanged(int32_t persistentId, uint64_t displayId)
198 {
199 return WSError::WS_OK;
200 }
201
202 namespace {
203
204 std::string g_logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)205 void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag,
206 const char* msg)
207 {
208 g_logMsg = msg;
209 }
210
211 /**
212 * @tc.name: GetResourceManager
213 * @tc.desc: GetResourceManager
214 * @tc.type: FUNC
215 */
216 HWTEST_F(SceneSessionManagerTest12, GetResourceManager, TestSize.Level1)
217 {
218 ASSERT_NE(ssm_, nullptr);
219 AppExecFwk::AbilityInfo abilityInfo;
220 auto result = ssm_->GetResourceManager(abilityInfo);
221 EXPECT_EQ(result, nullptr);
222 }
223
224 /**
225 * @tc.name: RequestKeyboardPanelSession
226 * @tc.desc: test RequestKeyboardPanelSession
227 * @tc.type: FUNC
228 */
229 HWTEST_F(SceneSessionManagerTest12, RequestKeyboardPanelSession, TestSize.Level1)
230 {
231 sptr<SceneSessionManager> ssm = sptr<SceneSessionManager>::MakeSptr();
232 std::string panelName = "SystemKeyboardPanel";
233 ASSERT_NE(nullptr, ssm->RequestKeyboardPanelSession(panelName, 0)); // 0 is screenId
234 ssm->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
235 ASSERT_NE(nullptr, ssm->RequestKeyboardPanelSession(panelName, 0)); // 0 is screenId
236 }
237
238 /**
239 * @tc.name: CreateKeyboardPanelSession
240 * @tc.desc: CreateKeyboardPanelSession
241 * @tc.type: FUNC
242 */
243 HWTEST_F(SceneSessionManagerTest12, CreateKeyboardPanelSession02, TestSize.Level1)
244 {
245 ASSERT_NE(ssm_, nullptr);
246 SessionInfo info;
247 info.abilityName_ = "test1";
248 info.bundleName_ = "test2";
249 info.screenId_ = SCREEN_ID_INVALID;
250 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
251 ASSERT_NE(property, nullptr);
252 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
253 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
254 ssm_->CreateKeyboardPanelSession(sceneSession);
255 }
256
257 /**
258 * @tc.name: CreateKeyboardPanelSession03
259 * @tc.desc: test CreateKeyboardPanelSession
260 * @tc.type: FUNC
261 */
262 HWTEST_F(SceneSessionManagerTest12, CreateKeyboardPanelSession03, TestSize.Level1)
263 {
264 SessionInfo keyboardInfo;
265 keyboardInfo.abilityName_ = "CreateKeyboardPanelSession03";
266 keyboardInfo.bundleName_ = "CreateKeyboardPanelSession03";
267 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(keyboardInfo, nullptr, nullptr);
268 ASSERT_EQ(nullptr, keyboardSession->GetKeyboardPanelSession());
269 sptr<SceneSessionManager> ssm = sptr<SceneSessionManager>::MakeSptr();
270
271 // the keyboard panel enabled flag of ssm is false
272 ssm->CreateKeyboardPanelSession(keyboardSession);
273 ASSERT_EQ(nullptr, keyboardSession->GetKeyboardPanelSession());
274
275 // keyboard session is nullptr
276 ssm->isKeyboardPanelEnabled_ = true;
277 ssm->CreateKeyboardPanelSession(nullptr);
278 ASSERT_EQ(nullptr, keyboardSession->GetKeyboardPanelSession());
279
280 // the keyboard session is system keyboard
281 keyboardSession->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
282 ASSERT_NE(nullptr, keyboardSession->GetSessionProperty());
283 keyboardSession->SetIsSystemKeyboard(true);
284 ASSERT_EQ(true, keyboardSession->IsSystemKeyboard());
285 ssm->CreateKeyboardPanelSession(keyboardSession);
286 ASSERT_NE(nullptr, keyboardSession->GetKeyboardPanelSession());
287 }
288
289 /**
290 * @tc.name: CreateKeyboardPanelSession04
291 * @tc.desc: test CreateKeyboardPanelSession
292 * @tc.type: FUNC
293 */
294 HWTEST_F(SceneSessionManagerTest12, CreateKeyboardPanelSession04, TestSize.Level1)
295 {
296 SessionInfo keyboardInfo;
297 keyboardInfo.abilityName_ = "CreateKeyboardPanelSession04";
298 keyboardInfo.bundleName_ = "CreateKeyboardPanelSession04";
299 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(keyboardInfo, nullptr, nullptr);
300 ASSERT_EQ(nullptr, keyboardSession->GetKeyboardPanelSession());
301 sptr<SceneSessionManager> ssm = sptr<SceneSessionManager>::MakeSptr();
302
303 // the keyboard panel enabled flag of ssm is true
304 ssm->isKeyboardPanelEnabled_ = true;
305 ASSERT_NE(nullptr, keyboardSession->GetSessionProperty());
306 ASSERT_EQ(false, keyboardSession->IsSystemKeyboard());
307 ssm->CreateKeyboardPanelSession(keyboardSession);
308 ASSERT_NE(nullptr, keyboardSession->GetKeyboardPanelSession());
309
310 // keyboard panel session is already exists
311 ssm->CreateKeyboardPanelSession(keyboardSession);
312 ASSERT_NE(nullptr, keyboardSession->GetKeyboardPanelSession());
313 }
314
315 /**
316 * @tc.name: TestCheckSystemWindowPermission_01
317 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_UI_EXTENSION then false
318 * @tc.type: FUNC
319 */
320 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_01, TestSize.Level1)
321 {
322 ASSERT_NE(nullptr, ssm_);
323 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
324
325 property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
326 ASSERT_EQ(false, ssm_->CheckSystemWindowPermission(property));
327 }
328
329 /**
330 * @tc.name: TestCheckSystemWindowPermission_02
331 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_APP_MAIN_WINDOW then true
332 * @tc.type: FUNC
333 */
334 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_02, TestSize.Level1)
335 {
336 ASSERT_NE(nullptr, ssm_);
337 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
338
339 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); // main window is not system window
340 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
341 }
342
343 /**
344 * @tc.name: TestCheckSystemWindowPermission_03
345 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_INPUT_METHOD_FLOAT then true
346 * @tc.type: FUNC
347 */
348 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_03, TestSize.Level1)
349 {
350 ASSERT_NE(nullptr, ssm_);
351 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
352
353 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
354 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
355 }
356
357 /**
358 * @tc.name: TestCheckSystemWindowPermission_04
359 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_INPUT_METHOD_STATUS_BAR then true
360 * @tc.type: FUNC
361 */
362 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_04, TestSize.Level1)
363 {
364 ASSERT_NE(nullptr, ssm_);
365 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
366
367 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_STATUS_BAR);
368 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
369 }
370
371 /**
372 * @tc.name: TestCheckSystemWindowPermission_05
373 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_INPUT_METHOD_FLOAT then false
374 * @tc.type: FUNC
375 */
376 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_05, TestSize.Level1)
377 {
378 ASSERT_NE(nullptr, ssm_);
379 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
380
381 property->SetIsSystemKeyboard(true);
382 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
383 MockAccesstokenKit::MockAccessTokenKitRet(-1);
384 ASSERT_EQ(false, ssm_->CheckSystemWindowPermission(property));
385 }
386
387 /**
388 * @tc.name: TestCheckSystemWindowPermission_06
389 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_DIALOG then true
390 * @tc.type: FUNC
391 */
392 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_06, TestSize.Level1)
393 {
394 ASSERT_NE(nullptr, ssm_);
395 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
396
397 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
398 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
399 }
400
401 /**
402 * @tc.name: TestCheckSystemWindowPermission_07
403 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_PIP then true
404 * @tc.type: FUNC
405 */
406 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_07, TestSize.Level1)
407 {
408 ASSERT_NE(nullptr, ssm_);
409 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
410
411 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
412 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
413 }
414
415 /**
416 * @tc.name: TestCheckSystemWindowPermission_08
417 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_FLOAT then true
418 * @tc.type: FUNC
419 */
420 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_08, TestSize.Level1)
421 {
422 ASSERT_NE(nullptr, ssm_);
423 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
424
425 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
426 MockAccesstokenKit::MockAccessTokenKitRet(-1);
427 ASSERT_EQ(false, ssm_->CheckSystemWindowPermission(property));
428 }
429
430 /**
431 * @tc.name: TestCheckSystemWindowPermission_09
432 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_TOAST then true
433 * @tc.type: FUNC
434 */
435 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_09, TestSize.Level1)
436 {
437 ASSERT_NE(nullptr, ssm_);
438 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
439
440 property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
441 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
442 }
443
444 /**
445 * @tc.name: TestCheckSystemWindowPermission_010
446 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_SYSTEM_SUB_WINDOW
447 * @tc.type: FUNC
448 */
449 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_010, TestSize.Level1)
450 {
451 ASSERT_NE(nullptr, ssm_);
452 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
453 property->SetParentPersistentId(100101);
454 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
455 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
456 }
457
458 /**
459 * @tc.name: TestCheckSystemWindowPermission_011
460 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_SYSTEM_SUB_WINDOW
461 * @tc.type: FUNC
462 */
463 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_011, TestSize.Level1)
464 {
465 ASSERT_NE(nullptr, ssm_);
466 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
467 property->SetParentPersistentId(100101);
468 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
469
470 sptr<WindowSessionProperty> parentProperty = sptr<WindowSessionProperty>::MakeSptr();
471 parentProperty->SetPersistentId(100101);
472 parentProperty->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
473 SessionInfo info;
474 info.abilityName_ = "CheckSystemWindowPermission";
475 info.bundleName_ = "CheckSystemWindowPermission";
476 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
477 sceneSession->SetSessionProperty(parentProperty);
478
479 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
480 }
481
482 /**
483 * @tc.name: TestCheckSystemWindowPermission_012
484 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_SYSTEM_SUB_WINDOW
485 * @tc.type: FUNC
486 */
487 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_012, TestSize.Level1)
488 {
489 ASSERT_NE(nullptr, ssm_);
490 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
491 property->SetParentPersistentId(100101);
492 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
493
494 sptr<WindowSessionProperty> parentProperty = sptr<WindowSessionProperty>::MakeSptr();
495 parentProperty->SetPersistentId(100101);
496 parentProperty->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
497 SessionInfo info;
498 info.abilityName_ = "CheckSystemWindowPermission";
499 info.bundleName_ = "CheckSystemWindowPermission";
500 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
501 sceneSession->SetSessionProperty(parentProperty);
502
503 ASSERT_EQ(true, ssm_->CheckSystemWindowPermission(property));
504 }
505
506 /**
507 * @tc.name: TestCheckSystemWindowPermission_013
508 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_SELECTION
509 * @tc.type: FUNC
510 */
511 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_013, TestSize.Level1)
512 {
513 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
514 property->SetWindowType(WindowType::WINDOW_TYPE_SELECTION);
515
516 MockAccesstokenKit::MockIsSACalling(false);
517 EXPECT_EQ(false, ssm_->CheckSystemWindowPermission(property));
518
519 MockAccesstokenKit::MockIsSACalling(true);
520 EXPECT_EQ(true, ssm_->CheckSystemWindowPermission(property));
521 }
522
523 /**
524 * @tc.name: TestCheckSystemWindowPermission_014
525 * @tc.desc: Test CheckSystemWindowPermission with windowType WINDOW_TYPE_MAGNIFICATION
526 * @tc.type: FUNC
527 */
528 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_014, TestSize.Level1)
529 {
530 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
531 property->SetWindowType(WindowType::WINDOW_TYPE_MAGNIFICATION);
532
533 MockAccesstokenKit::MockIsSACalling(false);
534 EXPECT_EQ(false, ssm_->CheckSystemWindowPermission(property));
535
536 MockAccesstokenKit::MockIsSACalling(true);
537 EXPECT_EQ(true, ssm_->CheckSystemWindowPermission(property));
538
539 property->SetWindowType(WindowType::WINDOW_TYPE_MAGNIFICATION_MENU);
540 MockAccesstokenKit::MockIsSACalling(false);
541 EXPECT_EQ(false, ssm_->CheckSystemWindowPermission(property));
542
543 MockAccesstokenKit::MockIsSACalling(true);
544 EXPECT_EQ(true, ssm_->CheckSystemWindowPermission(property));
545 }
546
547 /**
548 * @tc.name: TestCheckSystemWindowPermission_014
549 * @tc.desc: Test CheckSystemWindowPermission with windowType FLOAT in phone
550 * @tc.type: FUNC
551 */
552 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_015, TestSize.Level1)
553 {
554 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
555 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
556
557 MockAccesstokenKit::MockIsSACalling(false);
558 WindowUIType oldType = ssm_->systemConfig_.windowUIType_;
559 ssm_->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
560 MockAccesstokenKit::MockAccessTokenKitRet(0);
561
562 EXPECT_EQ(true, ssm_->CheckSystemWindowPermission(property));
563 ssm_->systemConfig_.windowUIType_ = oldType;
564 }
565
566 /**
567 * @tc.name: TestCheckSystemWindowPermission_014
568 * @tc.desc: Test CheckSystemWindowPermission with windowType FLOAT in pad
569 * @tc.type: FUNC
570 */
571 HWTEST_F(SceneSessionManagerTest12, TestCheckSystemWindowPermission_016, TestSize.Level1)
572 {
573 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
574 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
575
576 MockAccesstokenKit::MockIsSACalling(false);
577 WindowUIType oldType = ssm_->systemConfig_.windowUIType_;
578 ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
579 MockAccesstokenKit::MockAccessTokenKitRet(0);
580
581 EXPECT_EQ(true, ssm_->CheckSystemWindowPermission(property));
582 ssm_->systemConfig_.windowUIType_ = oldType;
583 }
584
585 /**
586 * @tc.name: CreateAndConnectSpecificSession
587 * @tc.desc: CreateAndConnectSpecificSession
588 * @tc.type: FUNC
589 */
590 HWTEST_F(SceneSessionManagerTest12, CreateAndConnectSpecificSession03, TestSize.Level1)
591 {
592 sptr<ISessionStage> sessionStage;
593 sptr<IWindowEventChannel> eventChannel;
594 std::shared_ptr<RSSurfaceNode> node = nullptr;
595 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
596 sptr<ISession> session;
597 SystemSessionConfig systemConfig;
598 sptr<IRemoteObject> token;
599 int32_t id = 0;
600 ASSERT_NE(ssm_, nullptr);
601
602 property->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION);
603 auto res = ssm_->CreateAndConnectSpecificSession(
604 sessionStage, eventChannel, node, property, id, session, systemConfig, token);
605 EXPECT_EQ(WSError::WS_ERROR_NOT_SYSTEM_APP, res);
606
607 property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
608 property->SetTopmost(true);
609 uint32_t flags = property->GetWindowFlags() & (~(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_MODAL)));
610 property->SetWindowFlags(flags);
611 res = ssm_->CreateAndConnectSpecificSession(
612 sessionStage, eventChannel, node, property, id, session, systemConfig, token);
613 EXPECT_EQ(WSError::WS_ERROR_NOT_SYSTEM_APP, res);
614
615 property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
616 property->SetFloatingWindowAppType(true);
617 ssm_->shouldHideNonSecureFloatingWindows_.store(true);
618 res = ssm_->CreateAndConnectSpecificSession(
619 sessionStage, eventChannel, node, property, id, session, systemConfig, token);
620 EXPECT_EQ(WSError::WS_ERROR_NULLPTR, res);
621
622 property->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
623 res = ssm_->CreateAndConnectSpecificSession(
624 sessionStage, eventChannel, node, property, id, session, systemConfig, token);
625 EXPECT_EQ(WSError::WS_ERROR_INVALID_WINDOW, res);
626
627 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
628 ssm_->isScreenLocked_ = true;
629 res = ssm_->CreateAndConnectSpecificSession(
630 sessionStage, eventChannel, node, property, id, session, systemConfig, token);
631 EXPECT_EQ(WSError::WS_DO_NOTHING, res);
632 }
633
634 /**
635 * @tc.name: SetCreateKeyboardSessionListener
636 * @tc.desc: SetCreateKeyboardSessionListener
637 * @tc.type: FUNC
638 */
639 HWTEST_F(SceneSessionManagerTest12, SetCreateKeyboardSessionListener, TestSize.Level1)
640 {
641 ASSERT_NE(ssm_, nullptr);
642 ssm_->SetCreateSystemSessionListener(nullptr);
643 SessionInfo sessionInfo;
644 sessionInfo.bundleName_ = "test1";
645 sessionInfo.abilityName_ = "test2";
646 sessionInfo.abilityInfo = nullptr;
647 sessionInfo.isAtomicService_ = true;
648 sessionInfo.screenId_ = SCREEN_ID_INVALID;
649 ssm_->NotifySessionTouchOutside(123, 0);
650 }
651
652 /**
653 * @tc.name: DestroyAndDisconnectSpecificSessionInner
654 * @tc.desc: check func DestroyAndDisconnectSpecificSessionInner
655 * @tc.type: FUNC
656 */
657 HWTEST_F(SceneSessionManagerTest12, DestroyAndDisconnectSpecificSessionInner02, TestSize.Level1)
658 {
659 ASSERT_NE(ssm_, nullptr);
660 SessionInfo info;
661 info.abilityName_ = "test1";
662 info.bundleName_ = "test2";
663 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
664 ASSERT_NE(nullptr, property);
665 std::vector<int32_t> recoveredPersistentIds = { 0, 1, 2 };
666 ssm_->SetAlivePersistentIds(recoveredPersistentIds);
667 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
668 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
669 EXPECT_EQ(ret, WSError::WS_OK);
670 }
671
672 /**
673 * @tc.name: DestroyToastSession
674 * @tc.desc: DestroyToastSession
675 * @tc.type: FUNC
676 */
677 HWTEST_F(SceneSessionManagerTest12, DestroyToastSession, TestSize.Level1)
678 {
679 ASSERT_NE(ssm_, nullptr);
680 SessionInfo info;
681 info.abilityName_ = "test1";
682 info.bundleName_ = "test2";
683 info.screenId_ = SCREEN_ID_INVALID;
684 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
685 ASSERT_NE(property, nullptr);
686 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
687 sptr<SceneSession> sceneSession = nullptr;
688 ssm_->DestroyToastSession(sceneSession);
689 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
690 ssm_->DestroyToastSession(sceneSession);
691 ssm_->StartUIAbilityBySCB(sceneSession);
692 int32_t ret = ssm_->ChangeUIAbilityVisibilityBySCB(sceneSession, true, false);
693 EXPECT_NE(ret, ERR_OK);
694 }
695
696 /**
697 * @tc.name: DestroyToastSession
698 * @tc.desc: DestroyToastSession
699 * @tc.type: FUNC
700 */
701 HWTEST_F(SceneSessionManagerTest12, DestroyToastSession02, TestSize.Level1)
702 {
703 ASSERT_NE(ssm_, nullptr);
704 SessionInfo info;
705 info.abilityName_ = "test1";
706 info.bundleName_ = "test2";
707 info.screenId_ = SCREEN_ID_INVALID;
708 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
709 ASSERT_NE(property, nullptr);
710 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
711 sptr<SceneSession> sceneSession = nullptr;
712 ssm_->DestroyToastSession(sceneSession);
713 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
714 sceneSession->state_ = SessionState::STATE_FOREGROUND;
715 ssm_->DestroyToastSession(sceneSession);
716 }
717
718 /**
719 * @tc.name: CheckModalSubWindowPermission
720 * @tc.desc: CheckModalSubWindowPermission
721 * @tc.type: FUNC
722 */
723 HWTEST_F(SceneSessionManagerTest12, CheckModalSubWindowPermission, TestSize.Level1)
724 {
725 ASSERT_NE(ssm_, nullptr);
726 SessionInfo info;
727 info.abilityName_ = "test1";
728 info.bundleName_ = "test2";
729 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
730 ASSERT_NE(property, nullptr);
731 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
732 property->SetWindowFlags(123);
733 ssm_->CheckModalSubWindowPermission(property);
734 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
735 ssm_->CheckModalSubWindowPermission(property);
736 }
737
738 /**
739 * @tc.name: CheckModalSubWindowPermission
740 * @tc.desc: CheckModalSubWindowPermission
741 * @tc.type: FUNC
742 */
743 HWTEST_F(SceneSessionManagerTest12, CheckModalSubWindowPermission02, TestSize.Level1)
744 {
745 ASSERT_NE(ssm_, nullptr);
746 SessionInfo info;
747 info.abilityName_ = "test1";
748 info.bundleName_ = "test2";
749 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
750 ASSERT_NE(property, nullptr);
751 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
752 property->SetWindowFlags(123);
753 property->SetTopmost(true);
754 ssm_->CheckModalSubWindowPermission(property);
755 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
756 ssm_->CheckModalSubWindowPermission(property);
757 }
758
759 /**
760 * @tc.name: DestroyAndDisconnectSpecificSessionInner
761 * @tc.desc: check func DestroyAndDisconnectSpecificSessionInner
762 * @tc.type: FUNC
763 */
764 HWTEST_F(SceneSessionManagerTest12, DestroyAndDisconnectSpecificSessionInner, TestSize.Level1)
765 {
766 sptr<ISession> session;
767 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
768 ASSERT_NE(nullptr, property);
769 std::vector<int32_t> recoveredPersistentIds = { 0, 1, 2 };
770 ssm_->SetAlivePersistentIds(recoveredPersistentIds);
771 ProcessShiftFocusFunc shiftFocusFunc_;
772 property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
773 auto ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
774 EXPECT_EQ(ret, WSError::WS_ERROR_NULLPTR);
775 property->SetPersistentId(1);
776 ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
777 EXPECT_EQ(ret, WSError::WS_ERROR_NULLPTR);
778
779 property->SetWindowType(WindowType::WINDOW_TYPE_TOAST);
780 ret = ssm_->DestroyAndDisconnectSpecificSessionInner(1);
781 EXPECT_EQ(ret, WSError::WS_ERROR_NULLPTR);
782 }
783
784 /**
785 * @tc.name: DestroyAndDisconnectSpecificSessionWithDetachCallback
786 * @tc.desc: SceneSesionManager destroy and disconnect specific session with detach callback
787 * @tc.type: FUNC
788 */
789 HWTEST_F(SceneSessionManagerTest12, DestroyAndDetachCallback, TestSize.Level1)
790 {
791 int32_t persistentId = 0;
792 ASSERT_NE(ssm_, nullptr);
793 sptr<IRemoteObject> callback = sptr<IRemoteObjectMocker>::MakeSptr();
794 ASSERT_NE(callback, nullptr);
795 ssm_->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
796 sptr<WindowSessionProperty> property;
797 ssm_->recoveringFinished_ = false;
798 SessionInfo info;
799 info.abilityName_ = "test1";
800 info.bundleName_ = "test2";
801 sptr<SceneSession> sceneSession = ssm_->CreateSceneSession(info, property);
802 ssm_->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
803 }
804
805 /**
806 * @tc.name: IsKeyboardForeground
807 * @tc.desc: IsKeyboardForeground
808 * @tc.type: FUNC
809 */
810 HWTEST_F(SceneSessionManagerTest12, IsKeyboardForeground, TestSize.Level1)
811 {
812 auto sceneSessionManager = sptr<SceneSessionManager>::MakeSptr();
813 SessionInfo info;
814 info.abilityName_ = "test1";
815 info.bundleName_ = "test2";
816 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
817 sceneSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
818 sceneSessionManager->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
819
820 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
821 sceneSession->state_ = SessionState::STATE_FOREGROUND;
822 ASSERT_EQ(true, sceneSessionManager->IsKeyboardForeground());
823 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW);
824 ASSERT_EQ(false, sceneSessionManager->IsKeyboardForeground());
825 sceneSessionManager->sceneSessionMap_.clear();
826 ASSERT_EQ(false, sceneSessionManager->IsKeyboardForeground());
827 }
828
829 /**
830 * @tc.name: RegisterWatchGestureConsumeResultCallback
831 * @tc.desc: RegisterWatchGestureConsumeResultCallback
832 * @tc.type: FUNC
833 */
834 HWTEST_F(SceneSessionManagerTest12, RegisterWatchGestureConsumeResultCallback, TestSize.Level1)
835 {
__anon87d2a2e90202(int32_t keyCode, bool isConsumed) 836 NotifyWatchGestureConsumeResultFunc func = [](int32_t keyCode, bool isConsumed) {};
837 ssm_->RegisterWatchGestureConsumeResultCallback(std::move(func));
838 ASSERT_NE(ssm_->onWatchGestureConsumeResultFunc_, nullptr);
839 }
840
841 /**
842 * @tc.name: RegisterWatchFocusActiveChangeCallback
843 * @tc.desc: RegisterWatchFocusActiveChangeCallback
844 * @tc.type: FUNC
845 */
846 HWTEST_F(SceneSessionManagerTest12, RegisterWatchFocusActiveChangeCallback, TestSize.Level1)
847 {
__anon87d2a2e90302(bool isActive) 848 NotifyWatchFocusActiveChangeFunc func = [](bool isActive) {};
849 ssm_->RegisterWatchFocusActiveChangeCallback(std::move(func));
850 ASSERT_NE(ssm_->onWatchFocusActiveChangeFunc_, nullptr);
851 }
852
853 /**
854 * @tc.name: NotifyWatchGestureConsumeResult
855 * @tc.desc: NotifyWatchGestureConsumeResult
856 * @tc.type: FUNC
857 */
858 HWTEST_F(SceneSessionManagerTest12, NotifyWatchGestureConsumeResult, TestSize.Level1)
859 {
860 int32_t keyCode = 2049;
861 bool isConsumed = true;
__anon87d2a2e90402(int32_t keyCode, bool isConsumed) 862 ssm_->onWatchGestureConsumeResultFunc_ = [](int32_t keyCode, bool isConsumed) {};
863 auto ret = ssm_->NotifyWatchGestureConsumeResult(keyCode, isConsumed);
864 ASSERT_EQ(WMError::WM_OK, ret);
865 ssm_->onWatchGestureConsumeResultFunc_ = nullptr;
866 ret = ssm_->NotifyWatchGestureConsumeResult(keyCode, isConsumed);
867 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
868 }
869
870 /**
871 * @tc.name: NotifyWatchFocusActiveChange
872 * @tc.desc: NotifyWatchFocusActiveChange
873 * @tc.type: FUNC
874 */
875 HWTEST_F(SceneSessionManagerTest12, NotifyWatchFocusActiveChange, TestSize.Level1)
876 {
877 bool isActive = true;
__anon87d2a2e90502(bool isActive) 878 ssm_->onWatchFocusActiveChangeFunc_ = [](bool isActive) {};
879 auto ret = ssm_->NotifyWatchFocusActiveChange(isActive);
880 ASSERT_EQ(WMError::WM_OK, ret);
881 ssm_->onWatchFocusActiveChangeFunc_ = nullptr;
882 ret = ssm_->NotifyWatchFocusActiveChange(isActive);
883 ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
884 }
885
886 /**
887 * @tc.name: ShiftAppWindowPointerEvent01
888 * @tc.desc: ShiftAppWindowPointerEvent,
889 * @tc.type: FUNC
890 */
891 HWTEST_F(SceneSessionManagerTest12, ShiftAppWindowPointerEvent_01, TestSize.Level1)
892 {
893 SessionInfo sourceInfo;
894 sourceInfo.windowType_ = 1;
895 sptr<SceneSession> sourceSceneSession = sptr<SceneSession>::MakeSptr(sourceInfo, nullptr);
896 ssm_->sceneSessionMap_.insert({ sourceSceneSession->GetPersistentId(), sourceSceneSession });
897
898 SessionInfo targetInfo;
899 targetInfo.windowType_ = 1;
900 sptr<SceneSession> targetSceneSession = sptr<SceneSession>::MakeSptr(targetInfo, nullptr);
901 ssm_->sceneSessionMap_.insert({ targetSceneSession->GetPersistentId(), targetSceneSession });
902
903 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
904 int32_t fingerId = 0;
905 WMError result = ssm_->ShiftAppWindowPointerEvent(INVALID_SESSION_ID, targetSceneSession->GetPersistentId(),
906 fingerId);
907 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_SESSION);
908 result = ssm_->ShiftAppWindowPointerEvent(sourceSceneSession->GetPersistentId(), INVALID_SESSION_ID, fingerId);
909 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_SESSION);
910
911 sourceSceneSession->GetSessionProperty()->SetPcAppInpadCompatibleMode(true);
912 ssm_->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
913 ssm_->systemConfig_.freeMultiWindowSupport_ = false;
914 result = ssm_->ShiftAppWindowPointerEvent(sourceSceneSession->GetPersistentId(), INVALID_SESSION_ID, fingerId);
915 EXPECT_EQ(result, WMError::WM_OK);
916 ssm_->sceneSessionMap_.erase(sourceSceneSession->GetPersistentId());
917 ssm_->sceneSessionMap_.erase(targetSceneSession->GetPersistentId());
918 }
919
920 /**
921 * @tc.name: ShiftAppWindowPointerEvent02
922 * @tc.desc: ShiftAppWindowPointerEvent,
923 * @tc.type: FUNC
924 */
925 HWTEST_F(SceneSessionManagerTest12, ShiftAppWindowPointerEvent_02, TestSize.Level1)
926 {
927 SessionInfo systemWindowInfo;
928 systemWindowInfo.windowType_ = 2000;
929 sptr<SceneSession> systemWindowSession = sptr<SceneSession>::MakeSptr(systemWindowInfo, nullptr);
930 ssm_->sceneSessionMap_.insert({ systemWindowSession->GetPersistentId(), systemWindowSession });
931
932 SessionInfo mainWindowInfo;
933 mainWindowInfo.windowType_ = 1;
934 sptr<SceneSession> mainWindowSession = sptr<SceneSession>::MakeSptr(mainWindowInfo, nullptr);
935 ssm_->sceneSessionMap_.insert({ mainWindowSession->GetPersistentId(), mainWindowSession });
936
937 int mainWindowPersistentId = mainWindowSession->GetPersistentId();
938 int systemWindowPersistentId = systemWindowSession->GetPersistentId();
939 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
940 int32_t fingerId = 0;
941 WMError result = ssm_->ShiftAppWindowPointerEvent(mainWindowPersistentId, systemWindowPersistentId, fingerId);
942 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_CALLING);
943 result = ssm_->ShiftAppWindowPointerEvent(systemWindowPersistentId, mainWindowPersistentId, fingerId);
944 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_CALLING);
945 ssm_->sceneSessionMap_.erase(systemWindowSession->GetPersistentId());
946 ssm_->sceneSessionMap_.erase(mainWindowSession->GetPersistentId());
947 }
948
949 /**
950 * @tc.name: ShiftAppWindowPointerEvent03
951 * @tc.desc: ShiftAppWindowPointerEvent,
952 * @tc.type: FUNC
953 */
954 HWTEST_F(SceneSessionManagerTest12, ShiftAppWindowPointerEvent_03, TestSize.Level1)
955 {
956 SessionInfo sourceInfo;
957 sourceInfo.windowType_ = 1;
958 sptr<SceneSession> sourceSceneSession = sptr<SceneSession>::MakeSptr(sourceInfo, nullptr);
959 ssm_->sceneSessionMap_.insert({ sourceSceneSession->GetPersistentId(), sourceSceneSession });
960
961 int32_t sourcePersistentId = sourceSceneSession->GetPersistentId();
962 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
963 int32_t fingerId = 0;
964 WMError result = ssm_->ShiftAppWindowPointerEvent(sourcePersistentId, sourcePersistentId, fingerId);
965 EXPECT_EQ(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
966
967 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
968 result = ssm_->ShiftAppWindowPointerEvent(sourcePersistentId, sourcePersistentId, fingerId);
969 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_CALLING);
970 ssm_->sceneSessionMap_.erase(sourceSceneSession->GetPersistentId());
971 }
972
973 /**
974 * @tc.name: ShiftAppWindowPointerEvent04
975 * @tc.desc: ShiftAppWindowPointerEvent,
976 * @tc.type: FUNC
977 */
978 HWTEST_F(SceneSessionManagerTest12, ShiftAppWindowPointerEvent_04, TestSize.Level1)
979 {
980 SessionInfo sourceInfo;
981 sourceInfo.windowType_ = 1;
982 sptr<SceneSession> sourceSceneSession = sptr<SceneSession>::MakeSptr(sourceInfo, nullptr);
983 ssm_->sceneSessionMap_.insert({ sourceSceneSession->GetPersistentId(), sourceSceneSession });
984
985 SessionInfo otherSourceInfo;
986 otherSourceInfo.bundleName_ = "other";
987 otherSourceInfo.windowType_ = 1;
988 sptr<SceneSession> otherSourceSession = sptr<SceneSession>::MakeSptr(otherSourceInfo, nullptr);
989 ssm_->sceneSessionMap_.insert({ otherSourceSession->GetPersistentId(), otherSourceSession });
990
991 SessionInfo otherTargetInfo;
992 otherTargetInfo.bundleName_ = "other";
993 otherTargetInfo.windowType_ = 1;
994 sptr<SceneSession> otherTargetSession = sptr<SceneSession>::MakeSptr(otherTargetInfo, nullptr);
995 ssm_->sceneSessionMap_.insert({ otherTargetSession->GetPersistentId(), otherTargetSession });
996
997 int32_t sourcePersistentId = sourceSceneSession->GetPersistentId();
998 int32_t otherSourcePersistentId = otherSourceSession->GetPersistentId();
999 int32_t otherTargetPersistentId = otherTargetSession->GetPersistentId();
1000 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1001 int32_t fingerId = 0;
1002 WMError result = ssm_->ShiftAppWindowPointerEvent(sourcePersistentId, otherTargetPersistentId, fingerId);
1003 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_CALLING);
1004 result = ssm_->ShiftAppWindowPointerEvent(otherSourcePersistentId, otherTargetPersistentId, fingerId);
1005 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_CALLING);
1006 ssm_->sceneSessionMap_.erase(sourceSceneSession->GetPersistentId());
1007 ssm_->sceneSessionMap_.erase(otherSourceSession->GetPersistentId());
1008 ssm_->sceneSessionMap_.erase(otherTargetSession->GetPersistentId());
1009 }
1010
1011 /**
1012 * @tc.name: ShiftAppWindowPointerEventInner01
1013 * @tc.desc: ShiftAppWindowPointerEventInner
1014 * @tc.type: FUNC
1015 */
1016 HWTEST_F(SceneSessionManagerTest12, ShiftAppWindowPointerEventInner01, TestSize.Level1)
1017 {
1018 SessionInfo sourceInfo;
1019 sourceInfo.windowType_ = 1;
1020 sptr<SceneSession> sourceSceneSession = sptr<SceneSession>::MakeSptr(sourceInfo, nullptr);
1021 ssm_->sceneSessionMap_.insert({ sourceSceneSession->GetPersistentId(), sourceSceneSession });
1022
1023 SessionInfo targetInfo;
1024 targetInfo.windowType_ = 1;
1025 sptr<SceneSession> targetSceneSession = sptr<SceneSession>::MakeSptr(targetInfo, nullptr);
1026 ssm_->sceneSessionMap_.insert({ targetSceneSession->GetPersistentId(), targetSceneSession });
1027
1028 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1029 int32_t fingerId = 0;
1030 WMError result = ssm_->ShiftAppWindowPointerEventInner(
1031 sourceSceneSession->GetPersistentId(), targetSceneSession->GetPersistentId(), DISPLAY_ID_INVALID, fingerId);
1032 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_CALLING);
1033 ssm_->sceneSessionMap_.erase(sourceSceneSession->GetPersistentId());
1034 ssm_->sceneSessionMap_.erase(targetSceneSession->GetPersistentId());
1035 }
1036
1037 /**
1038 * @tc.name: ShiftAppWindowPointerEventInner02
1039 * @tc.desc: ShiftAppWindowPointerEventInner
1040 * @tc.type: FUNC
1041 */
1042 HWTEST_F(SceneSessionManagerTest12, ShiftAppWindowPointerEventInner02, TestSize.Level1)
1043 {
1044 SessionInfo sourceInfo;
1045 sourceInfo.windowType_ = 1;
1046 sptr<SceneSession> sourceSceneSession = sptr<SceneSession>::MakeSptr(sourceInfo, nullptr);
1047 ssm_->sceneSessionMap_.insert({ sourceSceneSession->GetPersistentId(), sourceSceneSession });
1048
1049 SessionInfo targetInfo;
1050 targetInfo.windowType_ = 1;
1051 sptr<SceneSession> targetSceneSession = sptr<SceneSession>::MakeSptr(targetInfo, nullptr);
1052 ssm_->sceneSessionMap_.insert({ targetSceneSession->GetPersistentId(), targetSceneSession });
1053
1054 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1055 int32_t fingerId = 0;
1056 WMError result = ssm_->ShiftAppWindowPointerEventInner(
1057 sourceSceneSession->GetPersistentId(), targetSceneSession->GetPersistentId(), 0, fingerId);
1058 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_CALLING);
1059 ssm_->sceneSessionMap_.erase(sourceSceneSession->GetPersistentId());
1060 ssm_->sceneSessionMap_.erase(targetSceneSession->GetPersistentId());
1061 }
1062
1063 /**
1064 * @tc.name: GetKeyboardSession
1065 * @tc.desc: test GetKeyboardSession
1066 * @tc.type: FUNC
1067 */
1068 HWTEST_F(SceneSessionManagerTest12, GetKeyboardSession, TestSize.Level1)
1069 {
1070 sptr<SceneSessionManager> ssm = sptr<SceneSessionManager>::MakeSptr();
1071 SessionInfo info;
1072 info.abilityName_ = "GetKeyboardSession";
1073 info.bundleName_ = "GetKeyboardSession";
1074 info.windowType_ = 2105; // 2105 is WINDOW_TYPE_INPUT_METHOD_FLOAT
1075 info.screenId_ = 1; // 1 is screenId
1076 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1077 ASSERT_EQ(false, keyboardSession->IsSystemKeyboard());
1078 ssm->sceneSessionMap_.insert({ keyboardSession->GetPersistentId(), keyboardSession });
1079 sptr<KeyboardSession> systemKeyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1080 systemKeyboardSession->SetIsSystemKeyboard(true);
1081 ASSERT_EQ(true, systemKeyboardSession->IsSystemKeyboard());
1082 ssm->sceneSessionMap_.insert({ systemKeyboardSession->GetPersistentId(), systemKeyboardSession });
1083
1084 ASSERT_EQ(nullptr, ssm->GetKeyboardSession(DISPLAY_ID_INVALID, false));
1085 ASSERT_NE(nullptr, ssm->GetKeyboardSession(keyboardSession->GetScreenId(), false));
1086 ASSERT_NE(nullptr, ssm->GetKeyboardSession(systemKeyboardSession->GetScreenId(), true));
1087 }
1088
1089 /**
1090 * @tc.name: UpdateKeyboardAvoidAreaActive
1091 * @tc.desc: test UpdateKeyboardAvoidAreaActive
1092 * @tc.type: FUNC
1093 */
1094 HWTEST_F(SceneSessionManagerTest12, UpdateKeyboardAvoidAreaActive, TestSize.Level1)
1095 {
1096 sptr<SceneSessionManager> ssm = sptr<SceneSessionManager>::MakeSptr();
1097 SessionInfo info;
1098 info.abilityName_ = "UpdateKeyboardAvoidAreaActive";
1099 info.bundleName_ = "UpdateKeyboardAvoidAreaActive";
1100 info.windowType_ = 2105; // 2105 is WINDOW_TYPE_INPUT_METHOD_FLOAT
1101 info.screenId_ = 1; // 1 is screenId
1102 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1103 ASSERT_NE(nullptr, keyboardSession->GetSessionProperty());
1104 keyboardSession->GetSessionProperty()->SetDisplayId(info.screenId_);
1105 ASSERT_EQ(false, keyboardSession->IsSystemKeyboard());
1106 ssm->sceneSessionMap_.insert({ keyboardSession->GetPersistentId(), keyboardSession });
1107 sptr<KeyboardSession> systemKeyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1108 ASSERT_NE(nullptr, systemKeyboardSession->GetSessionProperty());
1109 systemKeyboardSession->GetSessionProperty()->SetDisplayId(info.screenId_);
1110 systemKeyboardSession->SetIsSystemKeyboard(true);
1111 ASSERT_EQ(true, systemKeyboardSession->IsSystemKeyboard());
1112 ssm->sceneSessionMap_.insert({ systemKeyboardSession->GetPersistentId(), systemKeyboardSession });
1113
1114 ssm->UpdateKeyboardAvoidAreaActive(false);
1115 ASSERT_EQ(true, keyboardSession->keyboardAvoidAreaActive_);
1116 ASSERT_EQ(false, systemKeyboardSession->keyboardAvoidAreaActive_);
1117 ssm->UpdateKeyboardAvoidAreaActive(true);
1118 ASSERT_EQ(false, keyboardSession->keyboardAvoidAreaActive_);
1119 ASSERT_EQ(true, systemKeyboardSession->keyboardAvoidAreaActive_);
1120 }
1121
1122 /**
1123 * @tc.name: HandleKeyboardAvoidChange
1124 * @tc.desc: test HandleKeyboardAvoidChange
1125 * @tc.type: FUNC
1126 */
1127 HWTEST_F(SceneSessionManagerTest12, HandleKeyboardAvoidChange, TestSize.Level1)
1128 {
1129 sptr<SceneSessionManager> ssm = sptr<SceneSessionManager>::MakeSptr();
1130 SessionInfo info;
1131 info.abilityName_ = "HandleKeyboardAvoidChange";
1132 info.bundleName_ = "HandleKeyboardAvoidChange";
1133 info.windowType_ = 2105; // 2105 is WINDOW_TYPE_INPUT_METHOD_FLOAT
1134 info.screenId_ = 1; // 1 is screenId
1135 sptr<KeyboardSession> keyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1136 ASSERT_NE(nullptr, keyboardSession->GetSessionProperty());
1137 keyboardSession->GetSessionProperty()->SetDisplayId(info.screenId_);
1138 ASSERT_EQ(false, keyboardSession->IsSystemKeyboard());
1139 ssm->sceneSessionMap_.insert({ keyboardSession->GetPersistentId(), keyboardSession });
1140 sptr<KeyboardSession> systemKeyboardSession = sptr<KeyboardSession>::MakeSptr(info, nullptr, nullptr);
1141 ASSERT_NE(nullptr, systemKeyboardSession->GetSessionProperty());
1142 systemKeyboardSession->GetSessionProperty()->SetDisplayId(info.screenId_);
1143 systemKeyboardSession->SetIsSystemKeyboard(true);
1144 ASSERT_EQ(true, systemKeyboardSession->IsSystemKeyboard());
1145 ssm->sceneSessionMap_.insert({ systemKeyboardSession->GetPersistentId(), systemKeyboardSession });
1146
1147 ssm->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1148 ssm->HandleKeyboardAvoidChange(
1149 keyboardSession, keyboardSession->GetScreenId(), SystemKeyboardAvoidChangeReason::KEYBOARD_CREATED);
1150 ASSERT_EQ(true, keyboardSession->keyboardAvoidAreaActive_);
1151
1152 ssm->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1153 ssm->HandleKeyboardAvoidChange(
1154 keyboardSession, keyboardSession->GetScreenId(), SystemKeyboardAvoidChangeReason::KEYBOARD_CREATED);
1155 ASSERT_EQ(true, keyboardSession->keyboardAvoidAreaActive_);
1156
1157 ssm->HandleKeyboardAvoidChange(
1158 systemKeyboardSession, systemKeyboardSession->GetScreenId(), SystemKeyboardAvoidChangeReason::KEYBOARD_SHOW);
1159 ASSERT_EQ(false, keyboardSession->keyboardAvoidAreaActive_);
1160 ASSERT_EQ(true, systemKeyboardSession->keyboardAvoidAreaActive_);
1161
1162 ssm->HandleKeyboardAvoidChange(systemKeyboardSession,
1163 systemKeyboardSession->GetScreenId(),
1164 SystemKeyboardAvoidChangeReason::KEYBOARD_GRAVITY_BOTTOM);
1165 ASSERT_EQ(false, keyboardSession->keyboardAvoidAreaActive_);
1166 ASSERT_EQ(true, systemKeyboardSession->keyboardAvoidAreaActive_);
1167
1168 ssm->HandleKeyboardAvoidChange(
1169 systemKeyboardSession, systemKeyboardSession->GetScreenId(), SystemKeyboardAvoidChangeReason::KEYBOARD_HIDE);
1170 ASSERT_EQ(true, keyboardSession->keyboardAvoidAreaActive_);
1171 ASSERT_EQ(false, systemKeyboardSession->keyboardAvoidAreaActive_);
1172
1173 ssm->HandleKeyboardAvoidChange(systemKeyboardSession,
1174 systemKeyboardSession->GetScreenId(),
1175 SystemKeyboardAvoidChangeReason::KEYBOARD_DISCONNECT);
1176 ASSERT_EQ(true, keyboardSession->keyboardAvoidAreaActive_);
1177 ASSERT_EQ(false, systemKeyboardSession->keyboardAvoidAreaActive_);
1178
1179 ssm->HandleKeyboardAvoidChange(systemKeyboardSession,
1180 systemKeyboardSession->GetScreenId(),
1181 SystemKeyboardAvoidChangeReason::KEYBOARD_GRAVITY_FLOAT);
1182 ASSERT_EQ(true, keyboardSession->keyboardAvoidAreaActive_);
1183 ASSERT_EQ(false, systemKeyboardSession->keyboardAvoidAreaActive_);
1184 }
1185
1186 /**
1187 * @tc.name: GetAllWindowLayoutInfo01
1188 * @tc.desc: HALF_FOLDED
1189 * @tc.type: FUNC
1190 */
1191 HWTEST_F(SceneSessionManagerTest12, GetAllWindowLayoutInfo01, TestSize.Level0)
1192 {
1193 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1194 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
1195 SessionInfo sessionInfo;
1196 sessionInfo.isSystem_ = false;
1197
1198 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1199 sceneSession1->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1200 WSRect rect = { 0, 1500, 120, 1000 };
1201 sceneSession1->SetSessionRect(rect);
1202 sceneSession1->SetSessionGlobalRect(rect);
1203 int32_t zOrder = 100;
1204 sceneSession1->SetZOrder(zOrder);
1205 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1206
1207 constexpr DisplayId VIRTUAL_DISPLAY_ID = 999;
1208 std::vector<sptr<WindowLayoutInfo>> info;
1209 ssm_->GetAllWindowLayoutInfo(VIRTUAL_DISPLAY_ID, info);
1210 ssm_->sceneSessionMap_.clear();
1211 ASSERT_NE(info.size(), 0);
1212 ASSERT_EQ(-972, info[0]->rect.posY_);
1213 }
1214
1215 /**
1216 * @tc.name: FilterForGetAllWindowLayoutInfo01
1217 * @tc.desc: test return by zOrder
1218 * @tc.type: FUNC
1219 */
1220 HWTEST_F(SceneSessionManagerTest12, FilterForGetAllWindowLayoutInfo01, TestSize.Level0)
1221 {
1222 SessionInfo sessionInfo;
1223 sessionInfo.isSystem_ = false;
1224
1225 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1226 sceneSession1->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1227 WSRect rect = { 0, 0, 120, 120 };
1228 sceneSession1->SetSessionRect(rect);
1229 sceneSession1->SetSessionGlobalRect(rect);
1230 int32_t zOrder = 100;
1231 sceneSession1->SetZOrder(zOrder);
1232 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1233
1234 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1235 sceneSession2->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1236 rect = { 0, 130, 120, 120 };
1237 sceneSession2->SetSessionRect(rect);
1238 sceneSession2->SetSessionGlobalRect(rect);
1239 zOrder = 101;
1240 sceneSession2->SetZOrder(zOrder);
1241 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1242
1243 constexpr DisplayId DEFAULT_DISPLAY_ID = 0;
1244 std::vector<sptr<SceneSession>> filteredSessions;
1245 ssm_->FilterForGetAllWindowLayoutInfo(DEFAULT_DISPLAY_ID, false, filteredSessions);
1246 ssm_->sceneSessionMap_.clear();
1247 ASSERT_NE(filteredSessions.size(), 0);
1248 ASSERT_EQ(130, filteredSessions[0]->GetSessionRect().posY_);
1249 }
1250
1251 /**
1252 * @tc.name: FilterForGetAllWindowLayoutInfo02
1253 * @tc.desc: test system window
1254 * @tc.type: FUNC
1255 */
1256 HWTEST_F(SceneSessionManagerTest12, FilterForGetAllWindowLayoutInfo02, TestSize.Level0)
1257 {
1258 SessionInfo sessionInfo;
1259 sessionInfo.isSystem_ = false;
1260 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1261 sceneSession1->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1262 WSRect rect = { 0, 0, 120, 120 };
1263 sceneSession1->SetSessionRect(rect);
1264 sceneSession1->SetSessionGlobalRect(rect);
1265 int32_t zOrder = 100;
1266 sceneSession1->SetZOrder(zOrder);
1267 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1268
1269 sessionInfo.isSystem_ = true;
1270 sessionInfo.abilityName_ = "SCBSmartDock";
1271 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1272 sceneSession2->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1273 rect = { 0, 130, 120, 120 };
1274 sceneSession2->SetSessionRect(rect);
1275 sceneSession2->SetSessionGlobalRect(rect);
1276 zOrder = 101;
1277 sceneSession2->SetZOrder(zOrder);
1278 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1279
1280 sessionInfo.abilityName_ = "TestAbility";
1281 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1282 sceneSession3->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1283 rect = { 0, 250, 120, 120 };
1284 sceneSession3->SetSessionRect(rect);
1285 sceneSession3->SetSessionGlobalRect(rect);
1286 zOrder = 102;
1287 sceneSession3->SetZOrder(zOrder);
1288 ssm_->sceneSessionMap_.insert({ sceneSession3->GetPersistentId(), sceneSession3 });
1289
1290 constexpr DisplayId DEFAULT_DISPLAY_ID = 0;
1291 std::vector<sptr<SceneSession>> filteredSessions;
1292 ssm_->FilterForGetAllWindowLayoutInfo(DEFAULT_DISPLAY_ID, false, filteredSessions);
1293 ssm_->sceneSessionMap_.clear();
1294 ASSERT_EQ(2, filteredSessions.size());
1295 }
1296
1297 /**
1298 * @tc.name: FilterForGetAllWindowLayoutInfo03
1299 * @tc.desc: test VisibilityState
1300 * @tc.type: FUNC
1301 */
1302 HWTEST_F(SceneSessionManagerTest12, FilterForGetAllWindowLayoutInfo03, TestSize.Level0)
1303 {
1304 SessionInfo sessionInfo;
1305 sessionInfo.isSystem_ = false;
1306 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1307 sceneSession1->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1308 WSRect rect = { 0, 0, 120, 120 };
1309 sceneSession1->SetSessionRect(rect);
1310 sceneSession1->SetSessionGlobalRect(rect);
1311 int32_t zOrder = 101;
1312 sceneSession1->SetZOrder(zOrder);
1313 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1314
1315 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1316 sceneSession2->SetVisibilityState(WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION);
1317 rect = { 0, 0, 130, 120 };
1318 sceneSession2->SetSessionRect(rect);
1319 sceneSession2->SetSessionGlobalRect(rect);
1320 zOrder = 100;
1321 sceneSession2->SetZOrder(zOrder);
1322 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1323
1324 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1325 sceneSession3->SetVisibilityState(WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION);
1326 rect = { 0, 0, 100, 100 };
1327 sceneSession3->SetSessionRect(rect);
1328 sceneSession3->SetSessionGlobalRect(rect);
1329 zOrder = 99;
1330 sceneSession3->SetZOrder(zOrder);
1331 ssm_->sceneSessionMap_.insert({ sceneSession3->GetPersistentId(), sceneSession3 });
1332
1333 constexpr DisplayId DEFAULT_DISPLAY_ID = 0;
1334 std::vector<sptr<SceneSession>> filteredSessions;
1335 ssm_->FilterForGetAllWindowLayoutInfo(DEFAULT_DISPLAY_ID, false, filteredSessions);
1336 ssm_->sceneSessionMap_.clear();
1337 ASSERT_EQ(2, filteredSessions.size());
1338 }
1339
1340 /**
1341 * @tc.name: FilterForGetAllWindowLayoutInfo04
1342 * @tc.desc: HALF_FOLDED
1343 * @tc.type: FUNC
1344 */
1345 HWTEST_F(SceneSessionManagerTest12, FilterForGetAllWindowLayoutInfo04, TestSize.Level0)
1346 {
1347 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1348 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
1349 SessionInfo sessionInfo;
1350 sessionInfo.isSystem_ = false;
1351
1352 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1353 sceneSession1->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1354 WSRect rect = { 0, 0, 120, 120 };
1355 sceneSession1->SetSessionRect(rect);
1356 sceneSession1->SetSessionGlobalRect(rect);
1357 int32_t zOrder = 100;
1358 sceneSession1->SetZOrder(zOrder);
1359 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1360
1361 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1362 sceneSession2->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1363 rect = { 0, 4000, 120, 120 };
1364 sceneSession2->SetSessionRect(rect);
1365 sceneSession2->SetSessionGlobalRect(rect);
1366 zOrder = 101;
1367 sceneSession2->SetZOrder(zOrder);
1368 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1369
1370 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1371 sceneSession3->SetVisibilityState(WINDOW_VISIBILITY_STATE_NO_OCCLUSION);
1372 rect = { 0, 1500, 120, 1000 };
1373 sceneSession3->SetSessionRect(rect);
1374 sceneSession3->SetSessionGlobalRect(rect);
1375 zOrder = 102;
1376 sceneSession3->SetZOrder(zOrder);
1377 ssm_->sceneSessionMap_.insert({ sceneSession3->GetPersistentId(), sceneSession3 });
1378
1379 constexpr DisplayId DEFAULT_DISPLAY_ID = 0;
1380 std::vector<sptr<SceneSession>> filteredSessions1;
1381 ssm_->FilterForGetAllWindowLayoutInfo(DEFAULT_DISPLAY_ID, false, filteredSessions1);
1382 EXPECT_EQ(2, filteredSessions1.size());
1383 std::vector<sptr<SceneSession>> filteredSessions2;
1384 ssm_->FilterForGetAllWindowLayoutInfo(DEFAULT_DISPLAY_ID, true, filteredSessions2);
1385 ssm_->sceneSessionMap_.clear();
1386 ASSERT_EQ(2, filteredSessions2.size());
1387 }
1388
1389 /**
1390 * @tc.name: FilterForGetAllWindowLayoutInfo05
1391 * @tc.desc: session is nullptr
1392 * @tc.type: FUNC
1393 */
1394 HWTEST_F(SceneSessionManagerTest12, FilterForGetAllWindowLayoutInfo05, TestSize.Level0)
1395 {
1396 sptr<SceneSession> sceneSession = nullptr;
1397 ssm_->sceneSessionMap_.insert({ 1, sceneSession });
1398 constexpr DisplayId DEFAULT_DISPLAY_ID = 0;
1399 std::vector<sptr<SceneSession>> filteredSessions;
1400 ssm_->FilterForGetAllWindowLayoutInfo(DEFAULT_DISPLAY_ID, false, filteredSessions);
1401 ssm_->sceneSessionMap_.clear();
1402 ASSERT_EQ(0, filteredSessions.size());
1403 }
1404
1405 /**
1406 * @tc.name: GetFoldLowerScreenPosY01
1407 * @tc.desc: test get fold lower screen posY
1408 * @tc.type: FUNC
1409 */
1410 HWTEST_F(SceneSessionManagerTest12, GetFoldLowerScreenPosY01, TestSize.Level0)
1411 {
1412 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1413 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1624, 2472, 1648 });
1414 ASSERT_EQ(2472, ssm_->GetFoldLowerScreenPosY());
1415 }
1416
1417 /**
1418 * @tc.name: IsGetWindowLayoutInfoNeeded01
1419 * @tc.desc: not System
1420 * @tc.type: FUNC
1421 */
1422 HWTEST_F(SceneSessionManagerTest12, IsGetWindowLayoutInfoNeeded01, TestSize.Level1)
1423 {
1424 SessionInfo sessionInfo;
1425 sessionInfo.isSystem_ = false;
1426 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1427 ASSERT_EQ(true, ssm_->IsGetWindowLayoutInfoNeeded(sceneSession));
1428 }
1429
1430 /**
1431 * @tc.name: IsGetWindowLayoutInfoNeeded02
1432 * @tc.desc: is System, not in whitelist
1433 * @tc.type: FUNC
1434 */
1435 HWTEST_F(SceneSessionManagerTest12, IsGetWindowLayoutInfoNeeded02, TestSize.Level1)
1436 {
1437 SessionInfo sessionInfo;
1438 sessionInfo.isSystem_ = true;
1439 sessionInfo.abilityName_ = "TestAbility";
1440 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1441 ASSERT_EQ(false, ssm_->IsGetWindowLayoutInfoNeeded(sceneSession));
1442 }
1443
1444 /**
1445 * @tc.name: IsGetWindowLayoutInfoNeeded03
1446 * @tc.desc: is System, in whitelist
1447 * @tc.type: FUNC
1448 */
1449 HWTEST_F(SceneSessionManagerTest12, IsGetWindowLayoutInfoNeeded03, TestSize.Level1)
1450 {
1451 SessionInfo sessionInfo;
1452 sessionInfo.isSystem_ = true;
1453 sessionInfo.abilityName_ = "SCBSmartDock021";
1454 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1455 ASSERT_EQ(true, ssm_->IsGetWindowLayoutInfoNeeded(sceneSession));
1456 }
1457
1458 /**
1459 * @tc.name: GetGlobalWindowMode01
1460 * @tc.desc: test window of type fullscreen
1461 * @tc.type: FUNC
1462 */
1463 HWTEST_F(SceneSessionManagerTest12, GetGlobalWindowMode01, TestSize.Level0)
1464 {
1465 SessionInfo sessionInfo1;
1466 sessionInfo1.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1467 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1468 sceneSession1->SetRSVisible(true);
1469 sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
1470 WSRect rect1 = { 0, 100, 1200, 1000 };
1471 sceneSession1->SetSessionRect(rect1);
1472 sceneSession1->SetSessionGlobalRect(rect1);
1473 sceneSession1->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1474 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1475
1476 SessionInfo sessionInfo2;
1477 sessionInfo2.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1478 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1479 sceneSession2->SetRSVisible(true);
1480 sceneSession2->SetSessionState(SessionState::STATE_BACKGROUND);
1481 WSRect rect2 = { 0, 2100, 200, 100 };
1482 sceneSession2->SetSessionRect(rect2);
1483 sceneSession2->SetSessionGlobalRect(rect2);
1484 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1485
1486 SessionInfo sessionInfo3;
1487 sessionInfo3.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1488 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo3, nullptr);
1489 sceneSession3->GetSessionProperty()->SetDisplayId(100);
1490 ssm_->sceneSessionMap_.insert({ sceneSession3->GetPersistentId(), sceneSession3 });
1491
1492 SessionInfo sessionInfo4;
1493 sessionInfo4.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1494 sptr<SceneSession> sceneSession4 = sptr<SceneSession>::MakeSptr(sessionInfo4, nullptr);
1495 sceneSession4->SetSessionState(SessionState::STATE_BACKGROUND);
1496 sceneSession4->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1497 ssm_->sceneSessionMap_.insert({ sceneSession4->GetPersistentId(), sceneSession4 });
1498
1499 GlobalWindowMode globalWinMode = GlobalWindowMode::UNKNOWN;
1500 ssm_->sceneSessionMap_.insert({ -1, nullptr });
1501 ssm_->GetGlobalWindowMode(DEFAULT_DISPLAY_ID, globalWinMode);
1502 EXPECT_EQ(static_cast<uint32_t>(globalWinMode), 1);
1503 ssm_->sceneSessionMap_.clear();
1504 }
1505
1506 /**
1507 * @tc.name: GetGlobalWindowMode02
1508 * @tc.desc: test all window modes except for fullscreen
1509 * @tc.type: FUNC
1510 */
1511 HWTEST_F(SceneSessionManagerTest12, GetGlobalWindowMode02, TestSize.Level0)
1512 {
1513 SessionInfo sessionInfo1;
1514 sessionInfo1.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1515 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1516 sceneSession1->SetRSVisible(true);
1517 sceneSession1->SetSessionState(SessionState::STATE_FOREGROUND);
1518 WSRect rect1 = { 0, 0, 100, 100 };
1519 sceneSession1->SetSessionRect(rect1);
1520 sceneSession1->SetSessionGlobalRect(rect1);
1521 sceneSession1->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY);
1522 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1523 GlobalWindowMode globalWinMode1 = GlobalWindowMode::UNKNOWN;
1524 ssm_->GetGlobalWindowMode(DEFAULT_DISPLAY_ID, globalWinMode1);
1525 EXPECT_EQ(static_cast<uint32_t>(globalWinMode1), 2);
1526
1527 SessionInfo sessionInfo2;
1528 sessionInfo2.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1529 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1530 sceneSession2->SetRSVisible(true);
1531 sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
1532 WSRect rect2 = { 100, 0, 100, 100 };
1533 sceneSession2->SetSessionRect(rect2);
1534 sceneSession2->SetSessionGlobalRect(rect2);
1535 sceneSession2->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1536 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1537 GlobalWindowMode globalWinMode2 = GlobalWindowMode::UNKNOWN;
1538 ssm_->GetGlobalWindowMode(DEFAULT_DISPLAY_ID, globalWinMode2);
1539 EXPECT_EQ(static_cast<uint32_t>(globalWinMode2), 6);
1540
1541 SessionInfo sessionInfo3;
1542 sessionInfo3.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_PIP);
1543 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo3, nullptr);
1544 sceneSession3->SetRSVisible(true);
1545 sceneSession3->SetSessionState(SessionState::STATE_FOREGROUND);
1546 WSRect rect3 = { 0, 200, 1200, 1000 };
1547 sceneSession3->SetSessionRect(rect3);
1548 sceneSession3->SetSessionGlobalRect(rect3);
1549 sceneSession3->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1550 ssm_->sceneSessionMap_.insert({ sceneSession3->GetPersistentId(), sceneSession3 });
1551 GlobalWindowMode globalWinMode3 = GlobalWindowMode::UNKNOWN;
1552 ssm_->GetGlobalWindowMode(DEFAULT_DISPLAY_ID, globalWinMode3);
1553 EXPECT_EQ(static_cast<uint32_t>(globalWinMode3), 14);
1554
1555 ssm_->sceneSessionMap_.clear();
1556 }
1557
1558 /**
1559 * @tc.name: IsSessionInSpecificDisplay01
1560 * @tc.desc: test IsSessionInSpecificDisplay01
1561 * @tc.type: FUNC
1562 */
1563 HWTEST_F(SceneSessionManagerTest12, IsSessionInSpecificDisplay01, TestSize.Level0)
1564 {
1565 PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(
1566 0, SuperFoldStatus::HALF_FOLDED, { 0, 0, 2472, 1648 }, { 0, 1648, 2472, 1648 }, { 0, 1648, 2472, 0 });
1567 bool ret = ssm_->IsSessionInSpecificDisplay(nullptr, DEFAULT_DISPLAY_ID);
1568 EXPECT_EQ(ret, false);
1569
1570 SessionInfo sessionInfo1;
1571 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1572 WSRect rect1 = { 0, 0, 100, 100 };
1573 sceneSession1->SetSessionRect(rect1);
1574 sceneSession1->SetSessionGlobalRect(rect1);
1575 constexpr DisplayId VIRTUAL_DISPLAY_ID = 999;
1576 bool ret1 = ssm_->IsSessionInSpecificDisplay(sceneSession1, VIRTUAL_DISPLAY_ID);
1577 EXPECT_EQ(ret1, false);
1578
1579 SessionInfo sessionInfo2;
1580 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1581 WSRect rect2 = { 0, 1700, 100, 100 };
1582 sceneSession2->SetSessionRect(rect2);
1583 sceneSession2->SetSessionGlobalRect(rect2);
1584 bool ret2 = ssm_->IsSessionInSpecificDisplay(sceneSession2, DEFAULT_DISPLAY_ID);
1585 EXPECT_EQ(ret2, false);
1586
1587 SessionInfo sessionInfo3;
1588 sptr<SceneSession> sceneSession3 = sptr<SceneSession>::MakeSptr(sessionInfo3, nullptr);
1589 WSRect rect3 = { 0, 200, 1200, 1000 };
1590 sceneSession3->SetSessionRect(rect3);
1591 sceneSession3->SetSessionGlobalRect(rect3);
1592 bool ret3 = ssm_->IsSessionInSpecificDisplay(sceneSession3, DEFAULT_DISPLAY_ID);
1593 EXPECT_EQ(ret3, true);
1594 }
1595
1596 /**
1597 * @tc.name: HasFloatingWindowForeground01
1598 * @tc.desc: test HasFloatingWindowForeground with null abilityToken
1599 * @tc.type: FUNC
1600 */
1601 HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground01, TestSize.Level1)
1602 {
1603 bool hasFloatWindowForeground = false;
1604 WMError result = ssm_->HasFloatingWindowForeground(nullptr, hasFloatWindowForeground);
1605 EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR);
1606 EXPECT_EQ(hasFloatWindowForeground, false);
1607 }
1608
1609 /**
1610 * @tc.name: ConfigSupportFollowRelativePositionToParent
1611 * @tc.desc: test ConfigSupportFollowRelativePositionToParent
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(SceneSessionManagerTest12, ConfigSupportFollowRelativePositionToParent01, TestSize.Level1)
1615 {
1616 ASSERT_NE(ssm_, nullptr);
1617 ssm_->ConfigSupportFollowRelativePositionToParent();
1618 EXPECT_EQ(ssm_->systemConfig_.supportFollowRelativePositionToParent_, false);
1619 }
1620
1621 /**
1622 * @tc.name: HasFloatingWindowForeground02
1623 * @tc.desc: test HasFloatingWindowForeground with not existed abilityToken
1624 * @tc.type: FUNC
1625 */
1626 HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground02, TestSize.Level1)
1627 {
1628 SessionInfo sessionInfo;
1629 sessionInfo.sessionState_ = SessionState::STATE_ACTIVE;
1630 sessionInfo.persistentId_ = 1;
1631 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1632
1633 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1634 sptr<IRemoteObject> token1 = sptr<MockIRemoteObject>::MakeSptr();
1635 sceneSession->SetAbilityToken(token1);
1636 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
1637 ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1638
1639 bool hasFloatWindowForeground = false;
1640 sptr<IRemoteObject> token2 = sptr<MockIRemoteObject>::MakeSptr();
1641 WMError result = ssm_->HasFloatingWindowForeground(token2, hasFloatWindowForeground);
1642 EXPECT_EQ(result, WMError::WM_OK);
1643 EXPECT_EQ(hasFloatWindowForeground, false);
1644 }
1645
1646 /**
1647 * @tc.name: HasFloatingWindowForeground03
1648 * @tc.desc: test HasFloatingWindowForeground with existed foreground float window
1649 * @tc.type: FUNC
1650 */
1651 HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground03, TestSize.Level1)
1652 {
1653 // create first test sceneSession
1654 SessionInfo sessionInfo1;
1655 sessionInfo1.sessionState_ = SessionState::STATE_ACTIVE;
1656 sessionInfo1.persistentId_ = 1;
1657
1658 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1659 sptr<IRemoteObject> token1 = sptr<MockIRemoteObject>::MakeSptr();
1660 sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1661 sceneSession1->SetAbilityToken(token1);
1662 sceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
1663
1664 // create second test sceneSession
1665 SessionInfo sessionInfo2;
1666 sessionInfo2.sessionState_ = SessionState::STATE_FOREGROUND;
1667 sessionInfo2.persistentId_ = 2;
1668
1669 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1670 sptr<IRemoteObject> token2 = sptr<MockIRemoteObject>::MakeSptr();
1671 sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1672 sceneSession2->SetAbilityToken(token2);
1673 sceneSession2->SetSessionState(SessionState::STATE_FOREGROUND);
1674
1675 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1676 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1677
1678 bool hasFloatWindowForeground = false;
1679 WMError result = ssm_->HasFloatingWindowForeground(token1, hasFloatWindowForeground);
1680 EXPECT_EQ(result, WMError::WM_OK);
1681 EXPECT_EQ(hasFloatWindowForeground, true);
1682
1683 hasFloatWindowForeground = false;
1684 result = ssm_->HasFloatingWindowForeground(token2, hasFloatWindowForeground);
1685 EXPECT_EQ(result, WMError::WM_OK);
1686 EXPECT_EQ(hasFloatWindowForeground, true);
1687 }
1688
1689 /**
1690 * @tc.name: HasFloatingWindowForeground04
1691 * @tc.desc: test HasFloatingWindowForeground with existed background float window
1692 * @tc.type: FUNC
1693 */
1694 HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground04, TestSize.Level1)
1695 {
1696 // create first test sceneSession
1697 SessionInfo sessionInfo1;
1698 sessionInfo1.sessionState_ = SessionState::STATE_INACTIVE;
1699 sessionInfo1.persistentId_ = 1;
1700
1701 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1702 sptr<IRemoteObject> token1 = sptr<MockIRemoteObject>::MakeSptr();
1703 sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1704 sceneSession1->SetAbilityToken(token1);
1705 sceneSession1->SetSessionState(SessionState::STATE_INACTIVE);
1706
1707 // create second test sceneSession
1708 SessionInfo sessionInfo2;
1709 sessionInfo2.sessionState_ = SessionState::STATE_BACKGROUND;
1710 sessionInfo2.persistentId_ = 2;
1711
1712 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1713 sptr<IRemoteObject> token2 = sptr<MockIRemoteObject>::MakeSptr();
1714 sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1715 sceneSession2->SetAbilityToken(token2);
1716 sceneSession2->SetSessionState(SessionState::STATE_BACKGROUND);
1717
1718 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1719 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1720
1721 bool hasFloatWindowForeground = false;
1722 WMError result = ssm_->HasFloatingWindowForeground(token1, hasFloatWindowForeground);
1723 EXPECT_EQ(result, WMError::WM_OK);
1724 EXPECT_EQ(hasFloatWindowForeground, false);
1725
1726 hasFloatWindowForeground = false;
1727 result = ssm_->HasFloatingWindowForeground(token2, hasFloatWindowForeground);
1728 EXPECT_EQ(result, WMError::WM_OK);
1729 EXPECT_EQ(hasFloatWindowForeground, false);
1730 }
1731
1732 /**
1733 * @tc.name: HasFloatingWindowForeground05
1734 * @tc.desc: test HasFloatingWindowForeground with existed forground toast window
1735 * @tc.type: FUNC
1736 */
1737 HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground05, TestSize.Level1)
1738 {
1739 // create first test sceneSession
1740 SessionInfo sessionInfo;
1741 sessionInfo.sessionState_ = SessionState::STATE_INACTIVE;
1742 sessionInfo.persistentId_ = 1;
1743
1744 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
1745 sptr<IRemoteObject> token = sptr<MockIRemoteObject>::MakeSptr();
1746 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1747 sceneSession->SetAbilityToken(token);
1748 sceneSession->SetSessionState(SessionState::STATE_INACTIVE);
1749
1750 ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1751
1752 bool hasFloatWindowForeground = false;
1753 WMError result = ssm_->HasFloatingWindowForeground(token, hasFloatWindowForeground);
1754 EXPECT_EQ(result, WMError::WM_OK);
1755 EXPECT_EQ(hasFloatWindowForeground, false);
1756 }
1757
1758 /**
1759 * @tc.name: HasFloatingWindowForeground06
1760 * @tc.desc: test HasFloatingWindowForeground with other foreground float window
1761 * @tc.type: FUNC
1762 */
1763 HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground06, TestSize.Level1)
1764 {
1765 // create first test sceneSession
1766 SessionInfo sessionInfo1;
1767 sessionInfo1.sessionState_ = SessionState::STATE_ACTIVE;
1768 sessionInfo1.persistentId_ = 1;
1769
1770 sptr<SceneSession> sceneSession1 = sptr<SceneSession>::MakeSptr(sessionInfo1, nullptr);
1771 sptr<IRemoteObject> token1 = sptr<MockIRemoteObject>::MakeSptr();
1772 sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1773 sceneSession1->SetAbilityToken(token1);
1774 sceneSession1->SetSessionState(SessionState::STATE_ACTIVE);
1775
1776 // create second test sceneSession
1777 SessionInfo sessionInfo2;
1778 sessionInfo2.sessionState_ = SessionState::STATE_BACKGROUND;
1779 sessionInfo2.persistentId_ = 2;
1780
1781 sptr<SceneSession> sceneSession2 = sptr<SceneSession>::MakeSptr(sessionInfo2, nullptr);
1782 sptr<IRemoteObject> token2 = sptr<MockIRemoteObject>::MakeSptr();
1783 sceneSession2->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
1784 sceneSession2->SetAbilityToken(token2);
1785 sceneSession2->SetSessionState(SessionState::STATE_BACKGROUND);
1786
1787 ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 });
1788 ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 });
1789
1790 bool hasFloatWindowForeground = false;
1791 WMError result = ssm_->HasFloatingWindowForeground(token2, hasFloatWindowForeground);
1792 EXPECT_EQ(result, WMError::WM_OK);
1793 EXPECT_EQ(hasFloatWindowForeground, false);
1794 }
1795
1796 /**
1797 * @tc.name: UpdateSessionWithFoldStateChange
1798 * @tc.desc: test function : UpdateSessionWithFoldStateChange
1799 * @tc.type: FUNC
1800 */
1801 HWTEST_F(SceneSessionManagerTest12, UpdateSessionWithFoldStateChange, TestSize.Level1)
1802 {
1803 SessionInfo info;
1804 info.abilityName_ = "test1";
1805 info.bundleName_ = "test1";
1806 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1807 sptr<SceneSessionMocker> sceneSession = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
1808 ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1809 EXPECT_CALL(*sceneSession, UpdateCrossAxis()).Times(1);
1810 ssm_->UpdateSessionWithFoldStateChange(10, SuperFoldStatus::HALF_FOLDED, SuperFoldStatus::FOLDED);
1811 }
1812
1813 /**
1814 * @tc.name: SetFocusedSessionDisplayIdIfNeededTest
1815 * @tc.desc: test function : SetFocusedSessionDisplayIdIfNeeded
1816 * @tc.type: FUNC
1817 */
1818 HWTEST_F(SceneSessionManagerTest12, SetFocusedSessionDisplayIdIfNeededTest, TestSize.Level1)
1819 {
1820 SessionInfo info;
1821 info.abilityName_ = "test1";
1822 info.bundleName_ = "test1";
1823 sptr<SceneSessionMocker> sceneSessionMock = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
1824 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1825 property->SetDisplayId(DISPLAY_ID_INVALID);
1826 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1827 sceneSessionMock->SetSessionProperty(property);
1828
1829 EXPECT_CALL(*sceneSessionMock, SetScreenId(_)).Times(1);
1830 sptr<SceneSession> sceneSession = static_cast<sptr<SceneSession>>(sceneSessionMock);
1831 ssm_->SetFocusedSessionDisplayIdIfNeeded(sceneSession);
1832 }
1833
1834 /**
1835 * @tc.name: SetFocusedSessionDisplayIdIfNeededTest001
1836 * @tc.desc: test function : SetFocusedSessionDisplayIdIfNeeded
1837 * @tc.type: FUNC
1838 */
1839 HWTEST_F(SceneSessionManagerTest12, SetFocusedSessionDisplayIdIfNeededTest001, TestSize.Level1)
1840 {
1841 SessionInfo info;
1842 info.abilityName_ = "test1";
1843 info.bundleName_ = "test1";
1844 sptr<SceneSessionMocker> sceneSessionMock = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
1845 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1846 property->SetDisplayId(DISPLAY_ID_INVALID + 1);
1847 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1848 sceneSessionMock->SetSessionProperty(property);
1849
1850 EXPECT_CALL(*sceneSessionMock, SetScreenId(_)).Times(0);
1851 sptr<SceneSession> sceneSession = static_cast<sptr<SceneSession>>(sceneSessionMock);
1852 ssm_->SetFocusedSessionDisplayIdIfNeeded(sceneSession);
1853 }
1854
1855 /**
1856 * @tc.name: GetActiveSceneSessionCopy
1857 * @tc.desc: test function : GetActiveSceneSessionCopy
1858 * @tc.type: FUNC
1859 */
1860 HWTEST_F(SceneSessionManagerTest12, GetActiveSceneSessionCopy, Function | SmallTest | Level2)
1861 {
1862 SessionInfo info;
1863 info.abilityName_ = "GetActiveSceneSessionCopy";
1864 info.bundleName_ = "GetActiveSceneSessionCopy";
1865 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1866 sptr<SceneSessionMocker> sceneSession = sptr<SceneSessionMocker>::MakeSptr(info, nullptr);
1867 sceneSession->state_ = SessionState::STATE_FOREGROUND;
1868 ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
1869 std::vector<sptr<SceneSession>> activeSession = ssm_->GetActiveSceneSessionCopy();
1870 EXPECT_EQ(activeSession.empty(), false);
1871 }
1872
1873 /**
1874 * @tc.name: GetKeyboardOccupiedAreaWithRotation1
1875 * @tc.desc: PC device is not compatible
1876 * @tc.type: FUNC
1877 */
1878 HWTEST_F(SceneSessionManagerTest12, GetKeyboardOccupiedAreaWithRotation1, TestSize.Level1)
1879 {
1880 GetKeyboardOccupiedAreaWithRotationTestData(
1881 WindowUIType::PHONE_WINDOW, 0, 0, SessionState::STATE_FOREGROUND, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1882 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_0, avoidAreas_);
1883 ASSERT_EQ(1, static_cast<uint32_t>(avoidAreas_.size()));
1884 ASSERT_EQ(true, avoidAreas_[0].first);
1885 ASSERT_EQ(true, CheckKeyboardOccupiedAreaInfo(portraitPanelRect_, avoidAreas_[0].second));
1886
1887 GetKeyboardOccupiedAreaWithRotationTestData(
1888 WindowUIType::PAD_WINDOW, 0, 0, SessionState::STATE_FOREGROUND, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1889 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_90, avoidAreas_);
1890 ASSERT_EQ(1, static_cast<uint32_t>(avoidAreas_.size()));
1891 ASSERT_EQ(true, avoidAreas_[0].first);
1892 ASSERT_EQ(true, CheckKeyboardOccupiedAreaInfo(landscapePanelRect_, avoidAreas_[0].second));
1893
1894 GetKeyboardOccupiedAreaWithRotationTestData(
1895 WindowUIType::PC_WINDOW, 0, 0, SessionState::STATE_FOREGROUND, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1896 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_0, avoidAreas_);
1897 ASSERT_EQ(0, static_cast<uint32_t>(avoidAreas_.size()));
1898 }
1899
1900 /**
1901 * @tc.name: GetKeyboardOccupiedAreaWithRotation2
1902 * @tc.desc: test function : GetKeyboardOccupiedAreaWithRotation
1903 * @tc.type: FUNC
1904 */
1905 HWTEST_F(SceneSessionManagerTest12, GetKeyboardOccupiedAreaWithRotation2, TestSize.Level1)
1906 {
1907 GetKeyboardOccupiedAreaWithRotationTestData(
1908 WindowUIType::PHONE_WINDOW, 0, 0, SessionState::STATE_FOREGROUND, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1909
1910 ssm_->GetKeyboardOccupiedAreaWithRotation(-1, Rotation::ROTATION_0, avoidAreas_);
1911 ASSERT_EQ(0, static_cast<uint32_t>(avoidAreas_.size()));
1912
1913 ssm_->GetKeyboardOccupiedAreaWithRotation(0, Rotation::ROTATION_0, avoidAreas_);
1914 ASSERT_EQ(0, static_cast<uint32_t>(avoidAreas_.size()));
1915
1916 GetKeyboardOccupiedAreaWithRotationTestData(
1917 WindowUIType::PHONE_WINDOW, 12, 0, SessionState::STATE_FOREGROUND, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1918 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_0, avoidAreas_);
1919 ASSERT_EQ(0, static_cast<uint32_t>(avoidAreas_.size()));
1920 }
1921
1922 /**
1923 * @tc.name: GetKeyboardOccupiedAreaWithRotation4
1924 * @tc.desc: test function : GetKeyboardOccupiedAreaWithRotation
1925 * @tc.type: FUNC
1926 */
1927 HWTEST_F(SceneSessionManagerTest12, GetKeyboardOccupiedAreaWithRotation4, TestSize.Level1)
1928 {
1929 GetKeyboardOccupiedAreaWithRotationTestData(
1930 WindowUIType::PHONE_WINDOW, 0, 0, SessionState::STATE_FOREGROUND, WindowGravity::WINDOW_GRAVITY_FLOAT);
1931
1932 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_0, avoidAreas_);
1933 ASSERT_EQ(1, static_cast<uint32_t>(avoidAreas_.size()));
1934 ASSERT_EQ(false, avoidAreas_[0].first);
1935 ASSERT_EQ(true, CheckKeyboardOccupiedAreaInfo(portraitPanelRect_, avoidAreas_[0].second));
1936 }
1937
1938 /**
1939 * @tc.name: GetKeyboardOccupiedAreaWithRotation5
1940 * @tc.desc: test function : GetKeyboardOccupiedAreaWithRotation
1941 * @tc.type: FUNC
1942 */
1943 HWTEST_F(SceneSessionManagerTest12, GetKeyboardOccupiedAreaWithRotation5, TestSize.Level1)
1944 {
1945 GetKeyboardOccupiedAreaWithRotationTestData(
1946 WindowUIType::PHONE_WINDOW, 0, 0, SessionState::STATE_BACKGROUND, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1947
1948 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_90, avoidAreas_);
1949 ASSERT_EQ(1, static_cast<uint32_t>(avoidAreas_.size()));
1950 ASSERT_EQ(false, avoidAreas_[0].first);
1951 ASSERT_EQ(true, CheckKeyboardOccupiedAreaInfo(landscapePanelRect_, avoidAreas_[0].second));
1952 }
1953
1954 /**
1955 * @tc.name: GetKeyboardOccupiedAreaWithRotation6
1956 * @tc.desc: test function : GetKeyboardOccupiedAreaWithRotation
1957 * @tc.type: FUNC
1958 */
1959 HWTEST_F(SceneSessionManagerTest12, GetKeyboardOccupiedAreaWithRotation6, TestSize.Level1)
1960 {
1961 GetKeyboardOccupiedAreaWithRotationTestData(
1962 WindowUIType::PHONE_WINDOW, 0, 0, SessionState::STATE_FOREGROUND, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1963
1964 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_180, avoidAreas_);
1965 ASSERT_EQ(1, static_cast<uint32_t>(avoidAreas_.size()));
1966 ASSERT_EQ(true, avoidAreas_[0].first);
1967 ASSERT_EQ(true, CheckKeyboardOccupiedAreaInfo(portraitPanelRect_, avoidAreas_[0].second));
1968
1969 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_0, avoidAreas_);
1970 ASSERT_EQ(2, static_cast<uint32_t>(avoidAreas_.size()));
1971 ASSERT_EQ(true, avoidAreas_[1].first);
1972 ASSERT_EQ(true, CheckKeyboardOccupiedAreaInfo(portraitPanelRect_, avoidAreas_[1].second));
1973 }
1974
1975 /**
1976 * @tc.name: GetKeyboardOccupiedAreaWithRotation7
1977 * @tc.desc: test function : GetKeyboardOccupiedAreaWithRotation
1978 * @tc.type: FUNC
1979 */
1980 HWTEST_F(SceneSessionManagerTest12, GetKeyboardOccupiedAreaWithRotation7, TestSize.Level1)
1981 {
1982 GetKeyboardOccupiedAreaWithRotationTestData(
1983 WindowUIType::PHONE_WINDOW, 0, 0, SessionState::STATE_ACTIVE, WindowGravity::WINDOW_GRAVITY_BOTTOM);
1984 ssm_->GetKeyboardOccupiedAreaWithRotation(1, Rotation::ROTATION_270, avoidAreas_);
1985
1986 ASSERT_EQ(1, static_cast<uint32_t>(avoidAreas_.size()));
1987 ASSERT_EQ(true, avoidAreas_[0].first);
1988 ASSERT_EQ(true, CheckKeyboardOccupiedAreaInfo(landscapePanelRect_, avoidAreas_[0].second));
1989 }
1990
1991 /**
1992 * @tc.name: GetCallingWindowInfo1
1993 * @tc.desc: test function : GetCallingWindowInfo
1994 * @tc.type: FUNC
1995 */
1996 HWTEST_F(SceneSessionManagerTest12, GetCallingWindowInfo1, TestSize.Level1)
1997 {
1998 KeyboardTestData keyboardTestData(0, 57256, 0, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, false);
1999 keyboardTestData.SetCallingSessionId(86);
2000 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2001 // Invalid callingWindowId
2002 CallingWindowInfo info(0, -1, 0, GetUserIdByUid(getuid())); // windowId_ callingPid_ displayId_ userId_
2003 WMError ret = ssm_->GetCallingWindowInfo(info);
2004 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret);
2005 }
2006
2007 /**
2008 * @tc.name: GetCallingWindowInfo2
2009 * @tc.desc: test function : GetCallingWindowInfo
2010 * @tc.type: FUNC
2011 */
2012 HWTEST_F(SceneSessionManagerTest12, GetCallingWindowInfo2, TestSize.Level1)
2013 {
2014 KeyboardTestData keyboardTestData(0, 57256, 0, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, false);
2015 keyboardTestData.SetCallingSessionId(86);
2016 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2017 // Invalid userId
2018 int32_t userId = GetUserIdByUid(getuid()) + 1;
2019 CallingWindowInfo info(86, -1, 0, userId); // windowId_ callingPid_ displayId_ userId_
2020 WMError ret = ssm_->GetCallingWindowInfo(info);
2021 ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, ret);
2022 }
2023
2024 /**
2025 * @tc.name: GetCallingWindowInfo3
2026 * @tc.desc: test function : GetCallingWindowInfo
2027 * @tc.type: FUNC
2028 */
2029 HWTEST_F(SceneSessionManagerTest12, GetCallingWindowInfo3, TestSize.Level1)
2030 {
2031 KeyboardTestData keyboardTestData(12, 57256, 0, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, false);
2032 keyboardTestData.SetCallingSessionId(86);
2033 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2034 int32_t userId = GetUserIdByUid(getuid());
2035 CallingWindowInfo info(86, -1, 0, userId); // windowId_ callingPid_ displayId_ userId_
2036 WMError ret = ssm_->GetCallingWindowInfo(info);
2037 ASSERT_EQ(WMError::WM_OK, ret);
2038 ASSERT_EQ(57256, info.callingPid_);
2039 ASSERT_EQ(12, info.displayId_);
2040 }
2041
2042 /**
2043 * @tc.name: UpdateSessionDisplayId1
2044 * @tc.desc: test function : UpdateSessionDisplayId
2045 * @tc.type: FUNC
2046 */
2047 HWTEST_F(SceneSessionManagerTest12, UpdateSessionDisplayId1, TestSize.Level0)
2048 {
2049 sptr<WindowManagerAgentLiteMocker> wmAgentLiteMocker = sptr<WindowManagerAgentLiteMocker>::MakeSptr();
2050 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
2051 wmAgentLiteMocker, WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, 12345);
2052 KeyboardTestData keyboardTestData(0, 57256, 0, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, false);
2053 keyboardTestData.SetCallingSessionId(86);
2054 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2055 EXPECT_CALL(*wmAgentLiteMocker, NotifyCallingWindowDisplayChanged(_)).Times(0);
2056 ssm_->UpdateSessionDisplayId(86, 12);
2057
2058 keyboardTestData = { 0, 57256, 0, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, true };
2059 keyboardTestData.SetCallingSessionId(86);
2060 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2061 EXPECT_CALL(*wmAgentLiteMocker, NotifyCallingWindowDisplayChanged(_)).Times(0);
2062 ssm_->UpdateSessionDisplayId(86, 12);
2063 }
2064
2065 /**
2066 * @tc.name: UpdateSessionDisplayId2
2067 * @tc.desc: test function : UpdateSessionDisplayId
2068 * @tc.type: FUNC
2069 */
2070 HWTEST_F(SceneSessionManagerTest12, UpdateSessionDisplayId2, TestSize.Level0)
2071 {
2072 sptr<WindowManagerAgentLiteMocker> wmAgentLiteMocker = sptr<WindowManagerAgentLiteMocker>::MakeSptr();
2073 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
2074 wmAgentLiteMocker, WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, 12345);
2075 KeyboardTestData keyboardTestData(0, 57256, 0, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, false);
2076 keyboardTestData.SetCallingSessionId(86);
2077 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2078 SessionInfo info;
2079 info.abilityName_ = "non-callingSession";
2080 info.bundleName_ = "non-callingSession";
2081 info.screenId_ = 0;
2082 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2083 sceneSession->callingPid_ = 54321;
2084 sptr<WindowSessionProperty> sceneSessionProperties = sptr<WindowSessionProperty>::MakeSptr();
2085 sceneSessionProperties->SetDisplayId(0);
2086 sceneSession->SetSessionProperty(sceneSessionProperties);
2087 // Add non-callingWindow
2088 ssm_->sceneSessionMap_.insert({ 90, sceneSession });
2089 // Change display id of non-callingWindow
2090 EXPECT_CALL(*wmAgentLiteMocker, NotifyCallingWindowDisplayChanged(_)).Times(0);
2091 ssm_->UpdateSessionDisplayId(90, 12);
2092 }
2093
2094 /**
2095 * @tc.name: UpdateSessionDisplayId3
2096 * @tc.desc: test function : UpdateSessionDisplayId
2097 * @tc.type: FUNC
2098 */
2099 HWTEST_F(SceneSessionManagerTest12, UpdateSessionDisplayId3, TestSize.Level1)
2100 {
2101 sptr<WindowManagerAgentLiteMocker> wmAgentLiteMocker = sptr<WindowManagerAgentLiteMocker>::MakeSptr();
2102 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
2103 wmAgentLiteMocker, WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, 12345);
2104 KeyboardTestData keyboardTestData(0, 57256, 0, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, false);
2105 keyboardTestData.SetCallingSessionId(86);
2106 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2107 EXPECT_CALL(*wmAgentLiteMocker, NotifyCallingWindowDisplayChanged(_)).Times(0);
2108 ssm_->UpdateSessionDisplayId(86, 12);
2109 }
2110
2111 /**
2112 * @tc.name: NotifyDisplayIdChanged
2113 * @tc.desc: test function : NotifyDisplayIdChanged
2114 * @tc.type: FUNC
2115 */
2116 HWTEST_F(SceneSessionManagerTest12, NotifyDisplayIdChanged, TestSize.Level1)
2117 {
2118 sptr<WindowManagerAgentLiteMocker> wmAgentLiteMocker = sptr<WindowManagerAgentLiteMocker>::MakeSptr();
2119 SessionManagerAgentController::GetInstance().RegisterWindowManagerAgent(
2120 wmAgentLiteMocker, WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, 12345);
2121 KeyboardTestData keyboardTestData(0, 57256, 0, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, false);
2122 keyboardTestData.SetCallingSessionId(86);
2123 ConstructKeyboardCallingWindowTestData(keyboardTestData);
2124 EXPECT_CALL(*wmAgentLiteMocker, NotifyCallingWindowDisplayChanged(_)).Times(0);
2125 ssm_->NotifyDisplayIdChanged(85, 12);
2126 EXPECT_CALL(*wmAgentLiteMocker, NotifyCallingWindowDisplayChanged(_)).Times(1);
2127 ssm_->NotifyDisplayIdChanged(86, 12);
2128 }
2129
2130 /**
2131 * @tc.name: RegisterDisplayIdChangedNotifyManagerFunc
2132 * @tc.desc: test function : RegisterDisplayIdChangedNotifyManagerFunc
2133 * @tc.type: FUNC
2134 */
2135 HWTEST_F(SceneSessionManagerTest12, RegisterDisplayIdChangedNotifyManagerFunc, TestSize.Level1)
2136 {
2137 sptr<SceneSession> sceneSession = nullptr;
2138 ssm_->RegisterDisplayIdChangedNotifyManagerFunc(sceneSession);
2139 SessionInfo sessionInfo;
2140 sessionInfo.bundleName_ = "RegisterDisplayIdChangedNotifyManagerFunc";
2141 sessionInfo.abilityName_ = "RegisterDisplayIdChangedNotifyManagerFunc";
2142 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
2143 ssm_->RegisterDisplayIdChangedNotifyManagerFunc(sceneSession);
2144 EXPECT_NE(nullptr, sceneSession->displayIdChangedNotifyManagerFunc_);
2145 }
2146
2147 /**
2148 * @tc.name: SetDisplayIdChangedNotifyManagerListener
2149 * @tc.desc: test function : SetDisplayIdChangedNotifyManagerListener
2150 * @tc.type: FUNC
2151 */
2152 HWTEST_F(SceneSessionManagerTest12, SetDisplayIdChangedNotifyManagerListener, TestSize.Level1)
2153 {
2154 sptr<SceneSession> sceneSession = nullptr;
2155 SessionInfo sessionInfo;
2156 sessionInfo.bundleName_ = "SetDisplayIdChangedNotifyManagerListener";
2157 sessionInfo.abilityName_ = "SetDisplayIdChangedNotifyManagerListener";
2158 sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
__anon87d2a2e90602(int32_t persistentId, uint64_t displayId) 2159 sceneSession->SetDisplayIdChangedNotifyManagerListener([this](int32_t persistentId, uint64_t displayId) {
2160 NotifyDisplayIdChanged(persistentId, displayId);
2161 });
2162 EXPECT_NE(nullptr, sceneSession->displayIdChangedNotifyManagerFunc_);
2163 }
2164
2165 /**
2166 * @tc.name: TerminateSessionByPersistentIdWhenNoPermission
2167 * @tc.desc: test function : TerminateSessionByPersistentIdWhenNoPermission
2168 * @tc.type: FUNC
2169 */
2170 HWTEST_F(SceneSessionManagerTest12, TerminateSessionByPersistentIdWhenNoPermission, Function | SmallTest | Level3)
2171 {
2172 const int32_t persistentId = 1;
2173 MockAccesstokenKit::MockAccessTokenKitRet(-1);
2174 auto result = ssm_->TerminateSessionByPersistentId(persistentId);
2175 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
2176 MockAccesstokenKit::MockAccessTokenKitRet(0);
2177
2178 MockAccesstokenKit::MockIsSystemApp(false);
2179 result = ssm_->TerminateSessionByPersistentId(persistentId);
2180 EXPECT_EQ(result, WMError::WM_ERROR_NOT_SYSTEM_APP);
2181 MockAccesstokenKit::MockIsSystemApp(true);
2182
2183 MockAccesstokenKit::MockIsSACalling(false);
2184 result = ssm_->TerminateSessionByPersistentId(persistentId);
2185 EXPECT_EQ(result, WMError::WM_ERROR_NOT_SYSTEM_APP);
2186 MockAccesstokenKit::MockIsSACalling(true);
2187
2188 result = ssm_->TerminateSessionByPersistentId(persistentId);
2189 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
2190 }
2191
2192 /**
2193 * @tc.name: PendingSessionToBackgroundByPersistentId
2194 * @tc.desc: test function : PendingSessionToBackgroundByPersistentId
2195 * @tc.type: FUNC
2196 */
2197 HWTEST_F(SceneSessionManagerTest12, PendingSessionToBackgroundByPersistentId, Function | SmallTest | Level3)
2198 {
2199 const int32_t persistentId = 1;
2200 bool shouldBackToCaller = true;
2201 MockAccesstokenKit::MockIsSystemApp(false);
2202 MockAccesstokenKit::MockIsSACalling(false);
2203 auto result = ssm_->PendingSessionToBackgroundByPersistentId(persistentId, shouldBackToCaller);
2204 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
2205
2206 MockAccesstokenKit::MockIsSystemApp(false);
2207 result = ssm_->PendingSessionToBackgroundByPersistentId(persistentId, shouldBackToCaller);
2208 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
2209 MockAccesstokenKit::MockIsSystemApp(true);
2210
2211 MockAccesstokenKit::MockIsSACalling(false);
2212 result = ssm_->PendingSessionToBackgroundByPersistentId(persistentId, shouldBackToCaller);
2213 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
2214 MockAccesstokenKit::MockIsSACalling(true);
2215
2216 MockAccesstokenKit::MockAccessTokenKitRet(-1);
2217 result = ssm_->PendingSessionToBackgroundByPersistentId(persistentId, shouldBackToCaller);
2218 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
2219 MockAccesstokenKit::MockAccessTokenKitRet(0);
2220
2221 result = ssm_->PendingSessionToBackgroundByPersistentId(persistentId, shouldBackToCaller);
2222 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
2223
2224 SessionInfo targetInfo;
2225 targetInfo.persistentId_ = persistentId;
2226 targetInfo.windowType_ = 1000;
2227 sptr<SceneSession> targetSceneSession = sptr<SceneSession>::MakeSptr(targetInfo, nullptr);
2228 ssm_->sceneSessionMap_.insert({ persistentId, targetSceneSession });
2229 result = ssm_->PendingSessionToBackgroundByPersistentId(persistentId, shouldBackToCaller);
2230 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
2231
2232 targetInfo.windowType_ = 1;
2233 targetSceneSession = sptr<SceneSession>::MakeSptr(targetInfo, nullptr);
2234 ssm_->sceneSessionMap_.insert({ persistentId, targetSceneSession });
2235 result = ssm_->PendingSessionToBackgroundByPersistentId(persistentId, shouldBackToCaller);
2236 EXPECT_EQ(result, WSError::WS_OK);
2237 }
2238
2239 /**
2240 * @tc.name: GetRecentMainSessionInfoList_Invalid_Permission
2241 * @tc.desc: test function : UpdateSessionDisplayId
2242 * @tc.type: FUNC
2243 */
2244 HWTEST_F(SceneSessionManagerTest12, GetRecentMainSessionInfoList_Invalid_Permission, TestSize.Level1)
2245 {
2246 std::vector<RecentSessionInfo> recentSessionInfoList = {};
2247 MockAccesstokenKit::MockIsSystemApp(false);
2248 MockAccesstokenKit::MockIsSACalling(false);
2249 auto result = ssm_->GetRecentMainSessionInfoList(recentSessionInfoList);
2250 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
2251 }
2252
2253 /**
2254 * @tc.name: GetRecentMainSessionInfoList_Invalid_Param
2255 * @tc.desc: test function : UpdateSessionDisplayId
2256 * @tc.type: FUNC
2257 */
2258 HWTEST_F(SceneSessionManagerTest12, GetRecentMainSessionInfoList_Invalid_Param, TestSize.Level1)
2259 {
2260 std::vector<RecentSessionInfo> recentSessionInfoList = {};
2261 RecentSessionInfo(101);
2262 recentSessionInfoList.emplace_back(101);
2263 MockAccesstokenKit::MockIsSystemApp(true);
2264 MockAccesstokenKit::MockIsSACalling(false);
2265 auto result = ssm_->GetRecentMainSessionInfoList(recentSessionInfoList);
2266 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
2267 }
2268
2269 /**
2270 * @tc.name: GetRecentMainSessionInfoList_OK
2271 * @tc.desc: test function : UpdateSessionDisplayId
2272 * @tc.type: FUNC
2273 */
2274 HWTEST_F(SceneSessionManagerTest12, GetRecentMainSessionInfoList_OK, TestSize.Level1)
2275 {
2276 std::vector<RecentSessionInfo> recentSessionInfoList = {};
2277 SessionInfo info;
2278 info.bundleName_ = "mockBundleName";
2279 info.moduleName_ = "mockModuleName";
2280 info.abilityName_ = "mockAbilityName";
2281 info.persistentId_ = 101;
2282 info.appIndex_ = 0;
2283 sptr<SceneSession> sceneSession = sptr<MainSession>::MakeSptr(info, nullptr);
2284 ASSERT_NE(sceneSession, nullptr);
2285 sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
2286 sceneSession->state_ = SessionState::STATE_CONNECT;
2287 ssm_->sceneSessionMap_[101] = sceneSession;
2288 const std::vector<int32_t> idList = { 101 };
2289 MockAccesstokenKit::MockIsSystemApp(true);
2290 MockAccesstokenKit::MockIsSACalling(false);
2291 ssm_->UpdateRecentMainSessionInfos(idList);
2292 auto result = ssm_->GetRecentMainSessionInfoList(recentSessionInfoList);
2293 EXPECT_EQ(recentSessionInfoList[0].missionId, 101);
2294 }
2295
2296 /**
2297 * @tc.name: CreateNewInstanceKey_No_Permission
2298 * @tc.desc: test function : UpdateSessionDisplayId
2299 * @tc.type: FUNC
2300 */
2301 HWTEST_F(SceneSessionManagerTest12, CreateNewInstanceKey_No_Permission, TestSize.Level1)
2302 {
2303 const std::string bundleName = "bundleName";
2304 std::string instanceKey = "1";
2305 MockAccesstokenKit::MockIsSystemApp(false);
2306 MockAccesstokenKit::MockIsSACalling(false);
2307 auto result = ssm_->CreateNewInstanceKey(bundleName, instanceKey);
2308 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
2309 }
2310
2311 /**
2312 * @tc.name: CreateNewInstanceKey_Invalid_Param
2313 * @tc.desc: test function : UpdateSessionDisplayId
2314 * @tc.type: FUNC
2315 */
2316 HWTEST_F(SceneSessionManagerTest12, CreateNewInstanceKey_Invalid_Param, TestSize.Level1)
2317 {
2318 const std::string bundleName = "bundleName";
2319 std::string instanceKey = "1";
2320
2321 MockAccesstokenKit::MockIsSystemApp(false);
2322 MockAccesstokenKit::MockIsSACalling(true);
2323 auto result = ssm_->CreateNewInstanceKey("", instanceKey);
2324 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
2325
2326 MockAccesstokenKit::MockIsSystemApp(true);
2327 MockAccesstokenKit::MockIsSACalling(false);
2328 result = ssm_->CreateNewInstanceKey("", instanceKey);
2329 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
2330 }
2331
2332 /**
2333 * @tc.name: CreateNewInstanceKey_OK
2334 * @tc.desc: test function : UpdateSessionDisplayId
2335 * @tc.type: FUNC
2336 */
2337 HWTEST_F(SceneSessionManagerTest12, CreateNewInstanceKey_OK, TestSize.Level1)
2338 {
2339 const std::string bundleName = "bundleName";
2340 std::string instanceKey = "1";
2341
2342 MockAccesstokenKit::MockIsSystemApp(true);
2343 MockAccesstokenKit::MockIsSACalling(true);
2344 auto result = ssm_->CreateNewInstanceKey(bundleName, instanceKey);
2345 EXPECT_EQ(result, WMError::WM_OK);
2346 }
2347
2348 /**
2349 * @tc.name: RemoveInstanceKey_No_Permission
2350 * @tc.desc: test function : UpdateSessionDisplayId
2351 * @tc.type: FUNC
2352 */
2353 HWTEST_F(SceneSessionManagerTest12, RemoveInstanceKey_No_Permission, TestSize.Level1)
2354 {
2355 const std::string bundleName = "bundleName";
2356 std::string instanceKey = "1";
2357 MockAccesstokenKit::MockIsSystemApp(false);
2358 MockAccesstokenKit::MockIsSACalling(false);
2359 auto result = ssm_->RemoveInstanceKey(bundleName, instanceKey);
2360 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
2361 }
2362
2363 /**
2364 * @tc.name: RemoveInstanceKey_Invalid_Param
2365 * @tc.desc: test function : UpdateSessionDisplayId
2366 * @tc.type: FUNC
2367 */
2368 HWTEST_F(SceneSessionManagerTest12, RemoveInstanceKey_Invalid_Param, TestSize.Level1)
2369 {
2370 const std::string bundleName = "bundleName";
2371 std::string instanceKey = "1";
2372
2373 MockAccesstokenKit::MockIsSystemApp(false);
2374 MockAccesstokenKit::MockIsSACalling(true);
2375 auto result = ssm_->RemoveInstanceKey("", instanceKey);
2376 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
2377
2378 MockAccesstokenKit::MockIsSystemApp(true);
2379 MockAccesstokenKit::MockIsSACalling(false);
2380 result = ssm_->RemoveInstanceKey(bundleName, "");
2381 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
2382 }
2383
2384 /**
2385 * @tc.name: UpdateWindowModeByIdForUITest01
2386 * @tc.desc: test function : UpdateWindowModeByIdForUITest
2387 * @tc.type: FUNC
2388 */
2389 HWTEST_F(SceneSessionManagerTest12, UpdateWindowModeByIdForUITest01, TestSize.Level1)
2390 {
2391 const int32_t windowId = 123456;
2392 const int32_t updateMode = 1;
2393
2394 MockAccesstokenKit::MockIsSACalling(false);
2395 auto result = ssm_->UpdateWindowModeByIdForUITest(windowId, updateMode);
2396 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PERMISSION);
2397 MockAccesstokenKit::MockIsSACalling(true);
2398
2399 result = ssm_->UpdateWindowModeByIdForUITest(windowId, updateMode);
2400 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_WINDOW);
2401 }
2402
2403 /**
2404 * @tc.name: RemoveInstanceKey_OK
2405 * @tc.desc: test function : UpdateSessionDisplayId
2406 * @tc.type: FUNC
2407 */
2408 HWTEST_F(SceneSessionManagerTest12, RemoveInstanceKey_OK, TestSize.Level1)
2409 {
2410 const std::string bundleName = "bundleName";
2411 std::string instanceKey = "1";
2412
2413 MockAccesstokenKit::MockIsSystemApp(true);
2414 MockAccesstokenKit::MockIsSACalling(true);
2415 auto result = ssm_->RemoveInstanceKey(bundleName, instanceKey);
2416 EXPECT_EQ(result, WMError::WM_OK);
2417 }
2418
2419 /**
2420 * @tc.name: SetSessionInfoStartWindowType01
2421 * @tc.desc: test function : SetSessionInfoStartWindowType
2422 * @tc.type: FUNC
2423 */
2424 HWTEST_F(SceneSessionManagerTest12, SetSessionInfoStartWindowType01, TestSize.Level1)
2425 {
2426 ASSERT_NE(ssm_, nullptr);
2427 SessionInfo info;
2428 info.abilityName_ = "SetSessionInfoStartWindowType01";
2429 info.bundleName_ = "SetSessionInfoStartWindowType01";
2430 info.isSetStartWindowType_ = false;
2431 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2432 auto oldUIType = ssm_->systemConfig_.windowUIType_;
2433 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
2434
2435 ssm_->SetSessionInfoStartWindowType(sceneSession);
2436
2437 EXPECT_EQ(sceneSession->GetSessionInfo().startWindowType_, StartWindowType::DEFAULT);
2438 ssm_->systemConfig_.windowUIType_ = oldUIType;
2439 }
2440
2441 /**
2442 * @tc.name: SetSessionInfoStartWindowType02
2443 * @tc.desc: test function : SetSessionInfoStartWindowType
2444 * @tc.type: FUNC
2445 */
2446 HWTEST_F(SceneSessionManagerTest12, SetSessionInfoStartWindowType02, TestSize.Level1)
2447 {
2448 ASSERT_NE(ssm_, nullptr);
2449 SessionInfo info;
2450 info.abilityName_ = "SetSessionInfoStartWindowType02";
2451 info.bundleName_ = "SetSessionInfoStartWindowType02";
2452 info.isSetStartWindowType_ = false;
2453 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2454 auto oldUIType = ssm_->systemConfig_.windowUIType_;
2455 ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
2456
2457 ssm_->SetSessionInfoStartWindowType(sceneSession);
2458
2459 EXPECT_EQ(sceneSession->GetSessionInfo().startWindowType_, StartWindowType::DEFAULT);
2460 ssm_->systemConfig_.windowUIType_ = oldUIType;
2461 }
2462
2463 /**
2464 * @tc.name: SetSessionInfoStartWindowType03
2465 * @tc.desc: test function : SetSessionInfoStartWindowType
2466 * @tc.type: FUNC
2467 */
2468 HWTEST_F(SceneSessionManagerTest12, SetSessionInfoStartWindowType03, TestSize.Level1)
2469 {
2470 ASSERT_NE(ssm_, nullptr);
2471 SessionInfo info;
2472 info.abilityName_ = "SetSessionInfoStartWindowType03";
2473 info.bundleName_ = "SetSessionInfoStartWindowType03";
2474 info.isSetStartWindowType_ = true;
2475 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2476 auto oldUIType = ssm_->systemConfig_.windowUIType_;
2477 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
2478
2479 ssm_->SetSessionInfoStartWindowType(sceneSession);
2480
2481 EXPECT_EQ(sceneSession->GetSessionInfo().startWindowType_, StartWindowType::DEFAULT);
2482 ssm_->systemConfig_.windowUIType_ = oldUIType;
2483 }
2484
2485 /**
2486 * @tc.name: RegisterGetStartWindowConfigCallback
2487 * @tc.desc: test function : RegisterGetStartWindowConfigCallback
2488 * @tc.type: FUNC
2489 */
2490 HWTEST_F(SceneSessionManagerTest12, RegisterGetStartWindowConfigCallback, TestSize.Level1)
2491 {
2492 ASSERT_NE(ssm_, nullptr);
2493 SessionInfo info;
2494 info.abilityName_ = "RegisterGetStartWindowConfigCallback";
2495 info.bundleName_ = "RegisterGetStartWindowConfigCallback";
2496 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2497
2498 ssm_->RegisterGetStartWindowConfigCallback(sceneSession);
2499
2500 EXPECT_NE(sceneSession->getStartWindowConfigFunc_, nullptr);
2501
2502 g_logMsg.clear();
2503 ssm_->RegisterGetStartWindowConfigCallback(nullptr);
2504 EXPECT_TRUE(g_logMsg.find("session is nullptr") != std::string::npos);
2505 }
2506
2507 /**
2508 * @tc.name: NotifyHookOrientationChange01
2509 * @tc.desc: test function : NotifyHookOrientationChange
2510 * @tc.type: FUNC
2511 */
2512 HWTEST_F(SceneSessionManagerTest12, NotifyHookOrientationChange01, TestSize.Level1)
2513 {
2514 ssm_->sceneSessionMap_.clear();
2515 WMError result = ssm_->NotifyHookOrientationChange(INVALID_SESSION_ID);
2516 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
2517 }
2518
2519 /**
2520 * @tc.name: NotifyHookOrientationChange02
2521 * @tc.desc: test function : NotifyHookOrientationChange
2522 * @tc.type: FUNC
2523 */
2524 HWTEST_F(SceneSessionManagerTest12, NotifyHookOrientationChange02, TestSize.Level1)
2525 {
2526 ssm_->sceneSessionMap_.clear();
2527 SessionInfo sessionInfo;
2528 sessionInfo.bundleName_ = "testBundleName";
2529 sessionInfo.moduleName_ = "testModuleName";
2530 sessionInfo.abilityName_ = "testAbilityName";
2531 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
2532 ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession });
2533 WMError result = ssm_->NotifyHookOrientationChange(sceneSession->GetPersistentId());
2534 EXPECT_EQ(result, WMError::WM_OK);
2535 ssm_->sceneSessionMap_.erase(sceneSession->GetPersistentId());
2536 }
2537
2538 /**
2539 * @tc.name: TestGetSceneSessions
2540 * @tc.desc: Verify that GetSceneSessions correctly filters sessions by screenId
2541 * @tc.type: FUNC
2542 */
2543 HWTEST_F(SceneSessionManagerTest12, TestGetSceneSessions, TestSize.Level1)
2544 {
2545 constexpr ScreenId screenId = 1001;
2546 SessionInfo info;
2547 auto session1 = sptr<SceneSession>::MakeSptr(info, nullptr);
2548 session1->SetScreenId(screenId);
2549 auto session2 = sptr<SceneSession>::MakeSptr(info, nullptr);
2550 session2->SetScreenId(screenId);
2551 auto session3 = sptr<SceneSession>::MakeSptr(info, nullptr);
2552 session3->SetScreenId(1000); // 1000: different screenId
2553
2554 {
2555 std::unique_lock<std::shared_mutex> lock(ssm_->sceneSessionMapMutex_);
2556 auto& sessionMap = ssm_->sceneSessionMap_;
2557 sessionMap.clear();
2558 sessionMap.emplace(1, session1);
2559 sessionMap.emplace(2, session2);
2560 sessionMap.emplace(3, session3);
2561 sessionMap.emplace(4, nullptr);
2562 }
2563
2564 auto result = ssm_->GetSceneSessions(screenId);
2565 EXPECT_EQ(result.size(), 2u);
2566 EXPECT_NE(std::find(result.begin(), result.end(), session1), result.end());
2567 EXPECT_NE(std::find(result.begin(), result.end(), session2), result.end());
2568 EXPECT_EQ(std::find(result.begin(), result.end(), session3), result.end());
2569
2570 {
2571 std::unique_lock<std::shared_mutex> lock(ssm_->sceneSessionMapMutex_);
2572 ssm_->sceneSessionMap_.clear();
2573 }
2574 }
2575
2576 /**
2577 * @tc.name: CreateUIEffectController
2578 * @tc.desc: test function : CreateUIEffectController
2579 * @tc.type: FUNC
2580 */
2581 HWTEST_F(SceneSessionManagerTest12, CreateUIEffectController, TestSize.Level1)
2582 {
2583 sptr<MockIRemoteObject> mocker = sptr<MockIRemoteObject>::MakeSptr();
2584 sptr<UIEffectControllerClientProxy> controllerClient = sptr<UIEffectControllerClientProxy>::MakeSptr(mocker);
2585 sptr<IUIEffectController> controller = sptr<UIEffectController>::MakeSptr(0, nullptr, nullptr);
2586 int32_t controllerId = 10;
2587 MockAccesstokenKit::MockIsSystemApp(false);
2588 MockAccesstokenKit::MockIsSACalling(false);
2589 EXPECT_EQ(ssm_->CreateUIEffectController(controllerClient, controller, controllerId),
2590 WMError::WM_ERROR_NOT_SYSTEM_APP);
2591 MockAccesstokenKit::MockIsSystemApp(true);
2592 MockAccesstokenKit::MockIsSACalling(true);
2593 ssm_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
2594 EXPECT_NE(ssm_->CreateUIEffectController(controllerClient, controller, controllerId),
2595 WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2596 ssm_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
2597 EXPECT_EQ(ssm_->CreateUIEffectController(controllerClient, controller, controllerId),
2598 WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2599 ssm_->systemConfig_.windowUIType_ = WindowUIType::PAD_WINDOW;
2600 ssm_->systemConfig_.freeMultiWindowEnable_ = true;
2601 ssm_->systemConfig_.freeMultiWindowSupport_ = true;
2602 EXPECT_EQ(ssm_->CreateUIEffectController(controllerClient, controller, controllerId),
2603 WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2604 ssm_->systemConfig_.freeMultiWindowSupport_ = false;
2605 EXPECT_NE(ssm_->CreateUIEffectController(controllerClient, controller, controllerId),
2606 WMError::WM_ERROR_DEVICE_NOT_SUPPORT);
2607 }
2608
2609 /**
2610 * @tc.name: PendingSessionToBackground
2611 * @tc.desc: test function : PendingSessionToBackground
2612 * @tc.type: FUNC
2613 */
2614 HWTEST_F(SceneSessionManagerTest12, PendingSessionToBackground01, Function | SmallTest | Level2)
2615 {
2616 //准备测试数据
2617 sptr<IRemoteObject> token = nullptr;
2618 BackgroundParams params;
2619 MockAccesstokenKit::MockIsSACalling(false);
2620 WSError result = ssm_->PendingSessionToBackground(token, params);
2621 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
2622
2623 MockAccesstokenKit::MockIsSACalling(true);
2624 result = ssm_->PendingSessionToBackground(token, params);
2625 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
2626 }
2627
2628 /**
2629 * @tc.name: PendingSessionToBackground
2630 * @tc.desc: test function : PendingSessionToBackground
2631 * @tc.type: FUNC
2632 */
2633 HWTEST_F(SceneSessionManagerTest12, PendingSessionToBackground02, Function | SmallTest | Level2)
2634 {
2635 // 准备测试数据
2636 sptr<IRemoteObject> token = nullptr;
2637 BackgroundParams params;
2638 params.persistentId = 1;
2639 MockAccesstokenKit::MockIsSACalling(true);
2640 WSError result = ssm_->PendingSessionToBackground(token, params);
2641 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
2642
2643 params.persistentId = -1;
2644 token = sptr<IRemoteObjectMocker>::MakeSptr();
2645 ASSERT_NE(token, nullptr);
2646 MockAccesstokenKit::MockIsSACalling(true);
2647 result = ssm_->PendingSessionToBackground(token, params);
2648 EXPECT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
2649 }
2650
2651 /**
2652 * @tc.name: PendingSessionToBackground
2653 * @tc.desc: test function : PendingSessionToBackground
2654 * @tc.type: FUNC
2655 */
2656 HWTEST_F(SceneSessionManagerTest12, PendingSessionToBackground03, Function | SmallTest | Level2)
2657 {
2658 // 准备测试数据
2659 SessionInfo info;
2660 info.abilityName_ = "test1";
2661 info.bundleName_ = "test2";
2662 info.persistentId_ = 123;
2663 sptr<IRemoteObject> token = sptr<IRemoteObjectMocker>::MakeSptr();
2664 ASSERT_NE(token, nullptr);
2665 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2666 ASSERT_NE(sceneSession, nullptr);
2667 sceneSession->abilityToken_ = token;
2668 ASSERT_NE(ssm_, nullptr);
2669 ssm_->sceneSessionMap_.insert({ 123, sceneSession });
2670 BackgroundParams params;
2671 params.persistentId = info.persistentId_;
2672 MockAccesstokenKit::MockIsSACalling(true);
2673 WSError result = ssm_->PendingSessionToBackground(nullptr, params);
2674 EXPECT_EQ(result, WSError::WS_OK);
2675
2676 params.persistentId = -1;
2677 result = ssm_->PendingSessionToBackground(token, params);
2678 EXPECT_EQ(result, WSError::WS_OK);
2679 }
2680
2681 /**
2682 * @tc.name: SetPiPSettingSwitchStatus
2683 * @tc.desc: test function : SetPiPSettingSwitchStatus
2684 * @tc.type: FUNC
2685 */
2686 HWTEST_F(SceneSessionManagerTest12, SetPiPSettingSwitchStatus, Function | SmallTest | Level2)
2687 {
2688 ssm_->SetPiPSettingSwitchStatus(true);
2689 EXPECT_EQ(ssm_->pipSwitchStatus_, true);
2690 ssm_->SetPiPSettingSwitchStatus(false);
2691 EXPECT_EQ(ssm_->pipSwitchStatus_, false);
2692 }
2693
2694 /**
2695 * @tc.name: GetPiPSettingSwitchStatus
2696 * @tc.desc: test function : GetPiPSettingSwitchStatus
2697 * @tc.type: FUNC
2698 */
2699 HWTEST_F(SceneSessionManagerTest12, GetPiPSettingSwitchStatus, Function | SmallTest | Level2)
2700 {
2701 bool switchStatus = false;
2702 ssm_->SetPiPSettingSwitchStatus(true);
2703 WMError ret = ssm_->GetPiPSettingSwitchStatus(switchStatus);
2704 EXPECT_EQ(switchStatus, true);
2705 EXPECT_EQ(ret, WMError::WM_OK);
2706
2707 ssm_->SetPiPSettingSwitchStatus(false);
2708 ret = ssm_->GetPiPSettingSwitchStatus(switchStatus);
2709 EXPECT_EQ(switchStatus, false);
2710 EXPECT_EQ(ret, WMError::WM_OK);
2711 }
2712
2713 /**
2714 * @tc.name: UpdateScreenLockState
2715 * @tc.desc: test function : UpdateScreenLockState
2716 * @tc.type: FUNC
2717 */
2718 HWTEST_F(SceneSessionManagerTest12, UpdateScreenLockState, Function | SmallTest | Level2)
2719 {
2720 int32_t persistentId = -1;
2721 auto result = ssm_->UpdateScreenLockState(persistentId);
2722 EXPECT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
2723
2724 persistentId = 11;
2725 result = ssm_->UpdateScreenLockState(persistentId);
2726 EXPECT_EQ(result, WMError::WM_OK);
2727 }
2728
2729 /**
2730 * @tc.name: UpdateScreenLockState
2731 * @tc.desc: test function : UpdateScreenLockState
2732 * @tc.type: FUNC
2733 */
2734 HWTEST_F(SceneSessionManagerTest12, UpdateSystemDecorEnable, Function | SmallTest | Level2)
2735 {
2736 bool enable = false;
2737 auto result = ssm_->UpdateSystemDecorEnable(enable);
2738 EXPECT_EQ(result, WMError::WM_OK);
2739 EXPECT_EQ(ssm_->systemConfig_.isSystemDecorEnable_, enable);
2740 }
2741
2742 /**
2743 * @tc.name: IsFocusWindowParent
2744 * @tc.desc: test function : IsFocusWindowParent
2745 * @tc.type: FUNC
2746 */
2747 HWTEST_F(SceneSessionManagerTest12, IsFocusWindowParent, Function | SmallTest | Level2)
2748 {
2749 sptr<IRemoteObject> token = sptr<MockIRemoteObject>::MakeSptr();
2750 bool isParent = false;
2751 MockAccesstokenKit::MockIsSACalling(false);
2752 EXPECT_EQ(WSError::WS_ERROR_INVALID_PERMISSION, ssm_->IsFocusWindowParent(token, isParent));
2753
2754 MockAccesstokenKit::MockIsSACalling(true);
2755 ssm_->sceneSessionMap_.clear();
2756
2757 SessionInfo sessionInfo;
2758 sessionInfo.bundleName_ = "IsFocusWindowParent";
2759 sessionInfo.abilityName_ = "IsFocusWindowParent";
2760 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(sessionInfo, nullptr);
2761 sceneSession->property_->SetPersistentId(1);
2762 auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID);
2763 focusGroup->SetFocusedSessionId(1);
2764
2765 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->IsFocusWindowParent(token, isParent));
2766
2767 ssm_->sceneSessionMap_.emplace(1, sceneSession);
2768 sceneSession->SetAbilityToken(token);
2769
2770 EXPECT_EQ(WSError::WS_OK, ssm_->IsFocusWindowParent(token, isParent));
2771 EXPECT_EQ(true, isParent);
2772
2773 sceneSession->SetAbilityToken(nullptr);
2774 EXPECT_EQ(WSError::WS_OK, ssm_->IsFocusWindowParent(token, isParent));
2775 EXPECT_EQ(false, isParent);
2776 }
2777 } // namespace
2778 } // namespace Rosen
2779 } // namespace OHOS
2780