1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "application_context.h"
19 #include "display_manager.h"
20 #include "input_event.h"
21 #include "key_event.h"
22 #include "mock/mock_session_stage.h"
23 #include "pointer_event.h"
24
25 #include "session/host/include/main_session.h"
26 #include "session/host/include/keyboard_session.h"
27 #define private public
28 #define protected public
29 #include "session/host/include/scene_session.h"
30 #undef private
31 #undef protected
32 #include "session/host/include/sub_session.h"
33 #include "session/host/include/system_session.h"
34 #include "ui/rs_surface_node.h"
35 #include "window_helper.h"
36 #include "wm_common.h"
37
38 using namespace testing;
39 using namespace testing::ext;
40
41 namespace {
42 std::string logMsg;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)43 void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char* tag,
44 const char* msg)
45 {
46 logMsg = msg;
47 }
48 }
49
50 namespace OHOS {
51 namespace Rosen {
52 namespace {
53 constexpr uint32_t SLEEP_TIME_US = 100000; // 100ms
54 }
55 class SceneSessionTest3 : public testing::Test {
56 public:
57 static void SetUpTestCase();
58 static void TearDownTestCase();
59 void SetUp() override;
60 void TearDown() override;
61 };
62
SetUpTestCase()63 void SceneSessionTest3::SetUpTestCase() {}
64
TearDownTestCase()65 void SceneSessionTest3::TearDownTestCase() {}
66
SetUp()67 void SceneSessionTest3::SetUp() {}
68
TearDown()69 void SceneSessionTest3::TearDown() {}
70
71 namespace {
72 /**
73 * @tc.name: NotifyClientToUpdateRectTask
74 * @tc.desc: normal function
75 * @tc.type: FUNC
76 */
77 HWTEST_F(SceneSessionTest3, NotifyClientToUpdateRectTask, TestSize.Level1)
78 {
79 SessionInfo info;
80 info.abilityName_ = "NotifyClientToUpdateRectTask";
81 info.bundleName_ = "NotifyClientToUpdateRectTask";
82 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
83 EXPECT_NE(sceneSession, nullptr);
84 sceneSession->isActive_ = true;
85
86 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
87 EXPECT_NE(property, nullptr);
88 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
89
90 sceneSession->SetSessionProperty(property);
91 sceneSession->SetSessionState(SessionState::STATE_ACTIVE);
92 auto result = sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", nullptr);
93 ASSERT_EQ(result, WSError::WS_OK);
94
95 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
96 sceneSession->SetSessionProperty(property);
97 sceneSession->isKeyboardPanelEnabled_ = true;
98 sceneSession->state_ = SessionState::STATE_FOREGROUND;
99 sceneSession->isScbCoreEnabled_ = false;
100 sceneSession->SetSessionRect({ 0, 0, 800, 800 });
101 EXPECT_EQ(WSError::WS_OK, sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", nullptr));
102
103 property->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
104 sceneSession->SetSessionProperty(property);
105 sceneSession->isKeyboardPanelEnabled_ = true;
106 EXPECT_EQ(WSError::WS_OK, sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", nullptr));
107
108 std::shared_ptr<RSTransaction> rs;
109 EXPECT_EQ(WSError::WS_OK, sceneSession->NotifyClientToUpdateRectTask("SceneSessionTest3", rs));
110 }
111
112 /**
113 * @tc.name: BindDialogSessionTarget1
114 * @tc.desc: normal function
115 * @tc.type: FUNC
116 */
117 HWTEST_F(SceneSessionTest3, BindDialogSessionTarget1, TestSize.Level1)
118 {
119 SessionInfo info;
120 info.abilityName_ = "BindDialogSessionTarget1";
121 info.bundleName_ = "BindDialogSessionTarget1";
122 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
123 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
124 EXPECT_NE(specificCallback_, nullptr);
125 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
126 EXPECT_NE(sceneSession, nullptr);
127 sceneSession->isActive_ = true;
128
129 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
130 EXPECT_NE(property, nullptr);
131 property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
132 property->keyboardLayoutParams_.gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
133 sceneSession->SetSessionProperty(property);
134
135 sptr<SceneSession> sceneSession1 = nullptr;
136 WSError result = sceneSession->BindDialogSessionTarget(sceneSession1);
137 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
138
139 sptr<SceneSession> sceneSession2 = sceneSession;
140 result = sceneSession->BindDialogSessionTarget(sceneSession2);
141 ASSERT_EQ(result, WSError::WS_OK);
142
__anonbd6cfeff0402(const sptr<SceneSession>&) 143 sceneSession->onBindDialogTarget_ = [](const sptr<SceneSession>&) {};
144 sceneSession1 = sptr<SceneSession>::MakeSptr(info, nullptr);
145 result = sceneSession->BindDialogSessionTarget(sceneSession1);
146 ASSERT_EQ(result, WSError::WS_OK);
147 }
148
149 /**
150 * @tc.name: RegisterBindDialogSessionCallback1
151 * @tc.desc: test RegisterBindDialogSessionCallback
152 * @tc.type: FUNC
153 */
154 HWTEST_F(SceneSessionTest3, RegisterBindDialogSessionCallback1, TestSize.Level1)
155 {
156 SessionInfo info;
157 info.abilityName_ = "RegisterBindDialogSessionCallback1";
158 info.bundleName_ = "RegisterBindDialogSessionCallback1";
159 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
160 sceneSession->onBindDialogTarget_ = nullptr;
__anonbd6cfeff0502(const sptr<SceneSession>& sceneSession) 161 NotifyBindDialogSessionFunc func = [](const sptr<SceneSession>& sceneSession) {};
162 sceneSession->RegisterBindDialogSessionCallback(func);
163 ASSERT_NE(sceneSession->onBindDialogTarget_, nullptr);
164 }
165
166 /**
167 * @tc.name: ClearSpecificSessionCbMap1
168 * @tc.desc: normal function
169 * @tc.type: FUNC
170 */
171 HWTEST_F(SceneSessionTest3, ClearSpecificSessionCbMap1, TestSize.Level1)
172 {
173 SessionInfo info;
174 info.abilityName_ = "ClearSpecificSessionCbMap1";
175 info.bundleName_ = "ClearSpecificSessionCbMap1";
176 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
177 EXPECT_NE(nullptr, sceneSession);
178 sceneSession->ClearSpecificSessionCbMap();
179
__anonbd6cfeff0602(bool) 180 sceneSession->clearCallbackMapFunc_ = [](bool) {};
181 sceneSession->ClearSpecificSessionCbMap();
182 }
183
184 /**
185 * @tc.name: IsMovableWindowType
186 * @tc.desc: normal function
187 * @tc.type: FUNC
188 */
189 HWTEST_F(SceneSessionTest3, IsMovableWindowType, TestSize.Level1)
190 {
191 SessionInfo info;
192 info.abilityName_ = "IsMovableWindowType";
193 info.bundleName_ = "IsMovableWindowType";
194 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
195 EXPECT_NE(nullptr, sceneSession);
196
197 sceneSession->property_ = nullptr;
198 EXPECT_EQ(sceneSession->IsMovableWindowType(), false);
199 }
200
201 /**
202 * @tc.name: SetBlank
203 * @tc.desc: check func SetBlank
204 * @tc.type: FUNC
205 */
206 HWTEST_F(SceneSessionTest3, SetBlank, TestSize.Level1)
207 {
208 SessionInfo info;
209 info.abilityName_ = "SetBlank";
210 info.bundleName_ = "SetBlank";
211 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
212 EXPECT_NE(nullptr, sceneSession);
213
214 bool isAddBlank = true;
215 sceneSession->SetBlank(isAddBlank);
216 ASSERT_EQ(isAddBlank, sceneSession->GetBlank());
217 }
218
219 /**
220 * @tc.name: GetBlank
221 * @tc.desc: check func GetBlank
222 * @tc.type: FUNC
223 */
224 HWTEST_F(SceneSessionTest3, GetBlank, TestSize.Level1)
225 {
226 SessionInfo info;
227 info.abilityName_ = "GetBlank";
228 info.bundleName_ = "GetBlank";
229 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
230 EXPECT_NE(nullptr, sceneSession);
231
232 bool isAddBlank = true;
233 sceneSession->SetBlank(isAddBlank);
234 ASSERT_EQ(isAddBlank, sceneSession->GetBlank());
235 }
236
237 /**
238 * @tc.name: SetBufferAvailableCallbackEnable
239 * @tc.desc: check func SetBufferAvailableCallbackEnable
240 * @tc.type: FUNC
241 */
242 HWTEST_F(SceneSessionTest3, SetBufferAvailableCallbackEnable, TestSize.Level1)
243 {
244 SessionInfo info;
245 info.abilityName_ = "SetBufferAvailableCallbackEnable";
246 info.bundleName_ = "SetBufferAvailableCallbackEnable";
247 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
248 EXPECT_NE(nullptr, sceneSession);
249
250 bool enable = true;
251 sceneSession->SetBufferAvailableCallbackEnable(enable);
252 ASSERT_EQ(enable, sceneSession->GetBufferAvailableCallbackEnable());
253 }
254
255 /**
256 * @tc.name: GetBufferAvailableCallbackEnable
257 * @tc.desc: check func GetBufferAvailableCallbackEnable
258 * @tc.type: FUNC
259 */
260 HWTEST_F(SceneSessionTest3, GetBufferAvailableCallbackEnable, TestSize.Level1)
261 {
262 SessionInfo info;
263 info.abilityName_ = "GetBufferAvailableCallbackEnable";
264 info.bundleName_ = "GetBufferAvailableCallbackEnable";
265 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
266 EXPECT_NE(nullptr, sceneSession);
267
268 bool enable = true;
269 sceneSession->SetBufferAvailableCallbackEnable(enable);
270 ASSERT_EQ(enable, sceneSession->GetBufferAvailableCallbackEnable());
271 }
272
273 /**
274 * @tc.name: NotifyClientToUpdateAvoidArea
275 * @tc.desc: check func NotifyClientToUpdateAvoidArea
276 * @tc.type: FUNC
277 */
278 HWTEST_F(SceneSessionTest3, NotifyClientToUpdateAvoidArea, TestSize.Level1)
279 {
280 SessionInfo info;
281 info.abilityName_ = "NotifyClientToUpdateAvoidArea";
282 info.bundleName_ = "NotifyClientToUpdateAvoidArea";
283 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
284 EXPECT_NE(nullptr, sceneSession);
285
286 sceneSession->NotifyClientToUpdateAvoidArea();
287 EXPECT_EQ(nullptr, sceneSession->specificCallback_);
288
289 sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
290 sceneSession = sptr<SceneSession>::MakeSptr(info, callback);
291 EXPECT_NE(nullptr, sceneSession);
292 sceneSession->persistentId_ = 6;
293 callback->onUpdateAvoidArea_ = nullptr;
294 sceneSession->NotifyClientToUpdateAvoidArea();
295
__anonbd6cfeff0702(int32_t persistentId) 296 UpdateAvoidAreaCallback callbackFun = [&sceneSession](int32_t persistentId) {
297 sceneSession->RemoveToastSession(persistentId);
298 return;
299 };
300 callback->onUpdateAvoidArea_ = callbackFun;
301 sceneSession->NotifyClientToUpdateAvoidArea();
302 EXPECT_EQ(6, sceneSession->GetPersistentId());
303 }
304
305 /**
306 * @tc.name: UpdateScaleInner
307 * @tc.desc: check func UpdateScaleInner
308 * @tc.type: FUNC
309 */
310 HWTEST_F(SceneSessionTest3, UpdateScaleInner, TestSize.Level1)
311 {
312 SessionInfo info;
313 info.abilityName_ = "UpdateScaleInner";
314 info.bundleName_ = "UpdateScaleInner";
315 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
316 EXPECT_NE(nullptr, sceneSession);
317
318 sceneSession->sessionStage_ = nullptr;
319 sceneSession->state_ = SessionState::STATE_FOREGROUND;
320 bool res = sceneSession->UpdateScaleInner(10.0f, 10.0f, 10.0f, 10.0f);
321 EXPECT_EQ(true, res);
322
323 res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 10.0f, 10.0f);
324 res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 9.0f, 10.0f);
325 res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 9.0f, 9.0f);
326 EXPECT_EQ(true, res);
327
328 sceneSession->state_ = SessionState::STATE_BACKGROUND;
329 res = sceneSession->UpdateScaleInner(10.0f, 9.0f, 9.0f, 9.0f);
330 EXPECT_EQ(false, res);
331
332 sceneSession->state_ = SessionState::STATE_FOREGROUND;
333 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
334 ASSERT_NE(mockSessionStage, nullptr);
335 sceneSession->sessionStage_ = mockSessionStage;
336 res = sceneSession->UpdateScaleInner(1.0f, 2.0f, 3.0f, 4.0f);
337 EXPECT_EQ(true, res);
338 res = sceneSession->UpdateScaleInner(1.0f, 2.0f, 3.0f, 4.0f);
339 EXPECT_EQ(false, res);
340 }
341
342 /**
343 * @tc.name: UpdateZOrderInner
344 * @tc.desc: check func UpdateZOrderInner
345 * @tc.type: FUNC
346 */
347 HWTEST_F(SceneSessionTest3, UpdateZOrderInner, TestSize.Level1)
348 {
349 SessionInfo info;
350 info.abilityName_ = "UpdateZOrderInner";
351 info.bundleName_ = "UpdateZOrderInner";
352 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
353 EXPECT_NE(nullptr, sceneSession);
354
355 int res = sceneSession->UpdateZOrderInner(10);
356 EXPECT_EQ(true, res);
357
358 res = sceneSession->UpdateZOrderInner(10);
359 EXPECT_EQ(false, res);
360 }
361
362 /**
363 * @tc.name: GetSubWindowModalType02
364 * @tc.desc: GetSubWindowModalType
365 * @tc.type: FUNC
366 */
367 HWTEST_F(SceneSessionTest3, GetSubWindowModalType02, TestSize.Level1)
368 {
369 SessionInfo info;
370 info.abilityName_ = "ModalType2";
371 info.bundleName_ = "ModalType2";
372 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
373 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
374 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
375 property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_TOAST));
376 sceneSession->SetSessionProperty(property);
377 auto result = sceneSession->GetSubWindowModalType();
378 ASSERT_EQ(result, SubWindowModalType::TYPE_TOAST);
379 }
380
381 /**
382 * @tc.name: GetSubWindowModalType03
383 * @tc.desc: GetSubWindowModalType
384 * @tc.type: FUNC
385 */
386 HWTEST_F(SceneSessionTest3, GetSubWindowModalType03, TestSize.Level1)
387 {
388 SessionInfo info;
389 info.abilityName_ = "ModalType3";
390 info.bundleName_ = "ModalType3";
391 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
392 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
393 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
394 property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_MODAL));
395 sceneSession->SetSessionProperty(property);
396 auto result = sceneSession->GetSubWindowModalType();
397 ASSERT_EQ(result, SubWindowModalType::TYPE_WINDOW_MODALITY);
398 }
399
400 /**
401 * @tc.name: GetSubWindowModalType04
402 * @tc.desc: GetSubWindowModalType
403 * @tc.type: FUNC
404 */
405 HWTEST_F(SceneSessionTest3, GetSubWindowModalType04, TestSize.Level1)
406 {
407 SessionInfo info;
408 info.abilityName_ = "ModalType4";
409 info.bundleName_ = "ModalType4";
410 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
411 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
412 property->SetWindowType(WindowType::APP_SUB_WINDOW_BASE);
413 property->SetWindowFlags(static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID));
414 sceneSession->SetSessionProperty(property);
415 auto result = sceneSession->GetSubWindowModalType();
416 ASSERT_EQ(result, SubWindowModalType::TYPE_NORMAL);
417 }
418
419 /**
420 * @tc.name: RegisterDefaultAnimationFlagChangeCallback
421 * @tc.desc: RegisterDefaultAnimationFlagChangeCallback
422 * @tc.type: FUNC
423 */
424 HWTEST_F(SceneSessionTest3, RegisterDefaultAnimationFlagChangeCallback, TestSize.Level1)
425 {
426 SessionInfo info;
427 info.abilityName_ = "RegisterDefaultAnimationFlagChangeCallback";
428 info.bundleName_ = "RegisterDefaultAnimationFlagChangeCallback";
429 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbd6cfeff0802(const bool flag) 430 sceneSession->RegisterDefaultAnimationFlagChangeCallback([sceneSession](const bool flag) { return; });
431 ASSERT_EQ(WSError::WS_OK, sceneSession->UpdateWindowAnimationFlag(true));
432
__anonbd6cfeff0902(const bool flag) 433 sceneSession->RegisterDefaultAnimationFlagChangeCallback([sceneSession](const bool flag) { return; });
434 ASSERT_EQ(WSError::WS_OK, sceneSession->UpdateWindowAnimationFlag(true));
435 }
436
437 /**
438 * @tc.name: SetMainWindowTopmostChangeCallback
439 * @tc.desc: SetMainWindowTopmostChangeCallback
440 * @tc.type: FUNC
441 */
442 HWTEST_F(SceneSessionTest3, SetMainWindowTopmostChangeCallback, TestSize.Level1)
443 {
444 SessionInfo info;
445 info.abilityName_ = "SetMainWindowTopmostChangeCallback";
446 info.bundleName_ = "SetMainWindowTopmostChangeCallback";
447 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
448
449 NotifyMainWindowTopmostChangeFunc func;
450 sceneSession->SetMainWindowTopmostChangeCallback(std::move(func));
451
__anonbd6cfeff0a02(bool isTopmost) 452 NotifyMainWindowTopmostChangeFunc func1 = [sceneSession](bool isTopmost) { return; };
453 sceneSession->SetMainWindowTopmostChangeCallback(std::move(func1));
454 ASSERT_NE(nullptr, sceneSession->mainWindowTopmostChangeFunc_);
455 }
456
457 /**
458 * @tc.name: SetRestoreMainWindowCallback
459 * @tc.desc: SetRestoreMainWindowCallback
460 * @tc.type: FUNC
461 */
462 HWTEST_F(SceneSessionTest3, SetRestoreMainWindowCallback, TestSize.Level1)
463 {
464 SessionInfo info;
465 info.abilityName_ = "SetRestoreMainWindowCallback";
466 info.bundleName_ = "SetRestoreMainWindowCallback";
467 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
468
__anonbd6cfeff0b02null469 sceneSession->SetRestoreMainWindowCallback([] { return; });
470 ASSERT_NE(nullptr, sceneSession->onRestoreMainWindowFunc_);
471 }
472
473 /**
474 * @tc.name: SetAdjustKeyboardLayoutCallback
475 * @tc.desc: SetAdjustKeyboardLayoutCallback
476 * @tc.type: FUNC
477 */
478 HWTEST_F(SceneSessionTest3, SetAdjustKeyboardLayoutCallback, TestSize.Level1)
479 {
480 SessionInfo info;
481 info.abilityName_ = "SetAdjustKeyboardLayoutCallback";
482 info.bundleName_ = "SetAdjustKeyboardLayoutCallback";
483 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
484 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
485 sceneSession->property_ = windowSessionProperty;
486
487 NotifyKeyboardLayoutAdjustFunc func;
488 sceneSession->SetAdjustKeyboardLayoutCallback(func);
489
__anonbd6cfeff0c02(const KeyboardLayoutParams& params) 490 NotifyKeyboardLayoutAdjustFunc func1 = [sceneSession](const KeyboardLayoutParams& params) { return; };
491 sceneSession->SetAdjustKeyboardLayoutCallback(func1);
492 ASSERT_NE(nullptr, sceneSession->adjustKeyboardLayoutFunc_);
493 }
494
495 /**
496 * @tc.name: IsStartMoving
497 * @tc.desc: get main window move flag, test IsStartMoving
498 * @tc.type: FUNC
499 */
500 HWTEST_F(SceneSessionTest3, IsStartMoving, TestSize.Level1)
501 {
502 SessionInfo info;
503 info.abilityName_ = "IsStartMoving";
504 info.bundleName_ = "IsStartMoving";
505
506 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
507 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1, WindowType::WINDOW_TYPE_FLOAT);
508 ASSERT_EQ(false, sceneSession->IsStartMoving());
509
510 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(1024, WindowType::WINDOW_TYPE_FLOAT);
511 ASSERT_EQ(false, sceneSession->IsStartMoving());
512 }
513
514 /**
515 * @tc.name: SetAppSupportPhoneInPc
516 * @tc.desc: SetAppSupportPhoneInPc
517 * @tc.type: FUNC
518 */
519 HWTEST_F(SceneSessionTest3, SetAppSupportPhoneInPc, TestSize.Level1)
520 {
521 SessionInfo info;
522 info.abilityName_ = "SetAppSupportPhoneInPc";
523 info.bundleName_ = "SetAppSupportPhoneInPc";
524
525 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
526 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
527 sceneSession->property_ = windowSessionProperty;
528 ASSERT_EQ(WSError::WS_OK, sceneSession->SetAppSupportPhoneInPc(false));
529 }
530
531 /**
532 * @tc.name: SetIsMidScene
533 * @tc.desc: SetIsMidScene
534 * @tc.type: FUNC
535 */
536 HWTEST_F(SceneSessionTest3, SetIsMidScene, TestSize.Level1)
537 {
538 SessionInfo info;
539 info.abilityName_ = "SetIsMidScene";
540 info.bundleName_ = "SetIsMidScene";
541 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
542 EXPECT_NE(sceneSession, nullptr);
543
544 sceneSession->SetIsMidScene(true);
545 bool res = sceneSession->GetIsMidScene();
546 EXPECT_EQ(res, true);
547 }
548
549 /**
550 * @tc.name: SetIsPcAppInPad
551 * @tc.desc: SetIsPcAppInPad
552 * @tc.type: FUNC
553 */
554 HWTEST_F(SceneSessionTest3, SetIsPcAppInPad, TestSize.Level1)
555 {
556 SessionInfo info;
557 info.abilityName_ = "SetIsPcAppInPad";
558 info.bundleName_ = "SetIsPcAppInPad";
559
560 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
561
562 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
563 sceneSession->property_ = windowSessionProperty;
564 ASSERT_EQ(WSError::WS_OK, sceneSession->SetIsPcAppInPad(false));
565 }
566
567 /**
568 * @tc.name: SetWindowRectAutoSaveCallback
569 * @tc.desc: SetWindowRectAutoSaveCallback
570 * @tc.type: FUNC
571 */
572 HWTEST_F(SceneSessionTest3, SetWindowRectAutoSaveCallback, TestSize.Level1)
573 {
574 SessionInfo info;
575 info.abilityName_ = "SetWindowRectAutoSaveCallback";
576 info.bundleName_ = "SetWindowRectAutoSaveCallback";
577 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
578 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
579 sceneSession->property_ = windowSessionProperty;
580
__anonbd6cfeff0d02(bool enabled, bool isSaveBySpecifiedFlag) 581 NotifySetWindowRectAutoSaveFunc func1 = [](bool enabled, bool isSaveBySpecifiedFlag) { return; };
582 sceneSession->SetWindowRectAutoSaveCallback(std::move(func1));
583 ASSERT_NE(nullptr, sceneSession->onSetWindowRectAutoSaveFunc_);
584 }
585
586 /**
587 * @tc.name: RegisterSupportWindowModesCallback
588 * @tc.desc: RegisterSupportWindowModesCallback
589 * @tc.type: FUNC
590 */
591 HWTEST_F(SceneSessionTest3, RegisterSupportWindowModesCallback, TestSize.Level1)
592 {
593 SessionInfo info;
594 info.abilityName_ = "RegisterSupportWindowModesCallback";
595 info.bundleName_ = "RegisterSupportWindowModesCallback";
596 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
597
598 NotifySetSupportedWindowModesFunc func1 =
__anonbd6cfeff0e02(std::vector<AppExecFwk::SupportWindowMode>&& supportedWindowModes) 599 [sceneSession](std::vector<AppExecFwk::SupportWindowMode>&& supportedWindowModes) { return; };
600
601 sceneSession->RegisterSupportWindowModesCallback(std::move(func1));
602 ASSERT_NE(nullptr, sceneSession->onSetSupportedWindowModesFunc_);
603 }
604
605 /**
606 * @tc.name: AddExtensionTokenInfo
607 * @tc.desc: AddExtensionTokenInfo
608 * @tc.type: FUNC
609 */
610 HWTEST_F(SceneSessionTest3, AddExtensionTokenInfo, TestSize.Level1)
611 {
612 UIExtensionTokenInfo tokenInfo;
613 tokenInfo.abilityToken = nullptr;
614 SessionInfo info;
615 info.abilityName_ = "AddExtensionTokenInfo";
616 info.bundleName_ = "AddExtensionTokenInfo";
617 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
618
619 sceneSession->AddExtensionTokenInfo(tokenInfo);
620 EXPECT_NE(sceneSession, nullptr);
621 }
622
623 /**
624 * @tc.name: RemoveExtensionTokenInfo
625 * @tc.desc: RemoveExtensionTokenInfo
626 * @tc.type: FUNC
627 */
628 HWTEST_F(SceneSessionTest3, RemoveExtensionTokenInfo, TestSize.Level1)
629 {
630 UIExtensionTokenInfo tokenInfo;
631 tokenInfo.abilityToken = nullptr;
632 SessionInfo info;
633 info.abilityName_ = "RemoveExtensionTokenInfo";
634 info.bundleName_ = "RemoveExtensionTokenInfo";
635 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
636
637 auto res = sceneSession->extensionTokenInfos_.size();
638 sceneSession->RemoveExtensionTokenInfo(tokenInfo.abilityToken);
639 EXPECT_EQ(sceneSession->extensionTokenInfos_.size() <= res, true);
640 }
641
642 /**
643 * @tc.name: OnNotifyAboveLockScreen
644 * @tc.desc: OnNotifyAboveLockScreen
645 * @tc.type: FUNC
646 */
647 HWTEST_F(SceneSessionTest3, OnNotifyAboveLockScreen, TestSize.Level1)
648 {
649 SessionInfo info;
650 info.abilityName_ = "OnNotifyAboveLockScreen";
651 info.bundleName_ = "OnNotifyAboveLockScreen";
652 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
653
654 sceneSession->OnNotifyAboveLockScreen();
655 EXPECT_NE(sceneSession, nullptr);
656 sceneSession->CheckExtensionOnLockScreenToClose();
657 EXPECT_NE(sceneSession, nullptr);
658 }
659
660 /**
661 * @tc.name: CloseExtensionSync
662 * @tc.desc: CloseExtensionSync
663 * @tc.type: FUNC
664 */
665 HWTEST_F(SceneSessionTest3, CloseExtensionSync, TestSize.Level1)
666 {
667 UIExtensionTokenInfo tokenInfo;
668 tokenInfo.abilityToken = nullptr;
669 SessionInfo info;
670 info.abilityName_ = "CloseExtensionSync";
671 info.bundleName_ = "CloseExtensionSync";
672 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
673
674 sceneSession->CloseExtensionSync(tokenInfo);
675 EXPECT_NE(sceneSession, nullptr);
676 }
677
678 /**
679 * @tc.name: SetIsStatusBarVisible
680 * @tc.desc: SetIsStatusBarVisible
681 * @tc.type: FUNC
682 */
683 HWTEST_F(SceneSessionTest3, SetIsStatusBarVisible, TestSize.Level1)
684 {
685 bool isVisible = true;
686 SessionInfo info;
687 info.abilityName_ = "SetIsStatusBarVisible";
688 info.bundleName_ = "SetIsStatusBarVisible";
689 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
690
691 sceneSession->SetIsStatusBarVisible(isVisible);
692 EXPECT_NE(sceneSession, nullptr);
693 }
694
695 /**
696 * @tc.name: GetAllAvoidAreas
697 * @tc.desc: GetAllAvoidAreas
698 * @tc.type: FUNC
699 */
700 HWTEST_F(SceneSessionTest3, GetAllAvoidAreas, TestSize.Level1)
701 {
702 std::map<AvoidAreaType, AvoidArea> avoidAreas;
703 SessionInfo info;
704 info.abilityName_ = "GetAllAvoidAreas";
705 info.bundleName_ = "GetAllAvoidAreas";
706 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
707
708 auto res = sceneSession->GetAllAvoidAreas(avoidAreas);
709 EXPECT_EQ(res, WSError::WS_OK);
710 }
711
712 /**
713 * @tc.name: NotifyPipWindowSizeChange
714 * @tc.desc: NotifyPipWindowSizeChange
715 * @tc.type: FUNC
716 */
717 HWTEST_F(SceneSessionTest3, NotifyPipWindowSizeChange, TestSize.Level1)
718 {
719 uint32_t width = 10;
720 uint32_t height = 10;
721 double scale = 10;
722 SessionInfo info;
723 info.abilityName_ = "NotifyPipWindowSizeChange";
724 info.bundleName_ = "NotifyPipWindowSizeChange";
725 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
726
727 auto res = sceneSession->NotifyPipWindowSizeChange(width, height, scale);
728 EXPECT_EQ(res, WSError::WS_ERROR_NULLPTR);
729 }
730
731 /**
732 * @tc.name: SendPointEventForMoveDrag
733 * @tc.desc: SendPointEventForMoveDrag
734 * @tc.type: FUNC
735 */
736 HWTEST_F(SceneSessionTest3, SendPointEventForMoveDrag, TestSize.Level1)
737 {
738 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
739 bool isExecuteDelayRaise = true;
740 SessionInfo info;
741 info.abilityName_ = "SendPointEventForMoveDrag";
742 info.bundleName_ = "SendPointEventForMoveDrag";
743 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
744
745 auto res = sceneSession->SendPointEventForMoveDrag(pointerEvent, isExecuteDelayRaise);
746 EXPECT_EQ(res, WSError::WS_OK);
747 }
748
749 /**
750 * @tc.name: DisallowActivationFromPendingBackground
751 * @tc.desc: DisallowActivationFromPendingBackground
752 * @tc.type: FUNC
753 */
754 HWTEST_F(SceneSessionTest3, DisallowActivationFromPendingBackground, TestSize.Level1)
755 {
756 SessionInfo info;
757 info.abilityName_ = "DisallowActivationFromPendingBackground";
758 info.bundleName_ = "DisallowActivationFromPendingBackground";
759 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
760
761 auto res = sceneSession->DisallowActivationFromPendingBackground(true, true, true, true);
762 EXPECT_EQ(res, false);
763 }
764
765 /**
766 * @tc.name: UpdateFullScreenWaterfallMode
767 * @tc.desc: UpdateFullScreenWaterfallMode
768 * @tc.type: FUNC
769 */
770 HWTEST_F(SceneSessionTest3, UpdateFullScreenWaterfallMode, TestSize.Level1)
771 {
772 bool isWaterfallMode = true;
773 SessionInfo info;
774 info.abilityName_ = "UpdateFullScreenWaterfallMode";
775 info.bundleName_ = "UpdateFullScreenWaterfallMode";
776 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
777
778 sceneSession->UpdateFullScreenWaterfallMode(isWaterfallMode);
779 EXPECT_NE(sceneSession, nullptr);
780 }
781
782 /**
783 * @tc.name: RegisterFullScreenWaterfallModeChangeCallback
784 * @tc.desc: RegisterFullScreenWaterfallModeChangeCallback
785 * @tc.type: FUNC
786 */
787 HWTEST_F(SceneSessionTest3, RegisterFullScreenWaterfallModeChangeCallback, TestSize.Level1)
788 {
789 SessionInfo info;
790 info.abilityName_ = "RegisterFullScreenWaterfallModeChangeCallback";
791 info.bundleName_ = "RegisterFullScreenWaterfallModeChangeCallback";
792 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
793
__anonbd6cfeff0f02(bool isWaterfallMode) 794 std::function<void(bool isWaterfallMode)> func = [](bool isWaterfallMode) { return; };
795 sceneSession->RegisterFullScreenWaterfallModeChangeCallback(std::move(func));
796 EXPECT_NE(sceneSession, nullptr);
797 }
798
799 /**
800 * @tc.name: RegisterThrowSlipAnimationStateChangeCallback
801 * @tc.desc: RegisterThrowSlipAnimationStateChangeCallback
802 * @tc.type: FUNC
803 */
804 HWTEST_F(SceneSessionTest3, RegisterThrowSlipAnimationStateChangeCallback, TestSize.Level1)
805 {
806 SessionInfo info;
807 info.abilityName_ = "RegisterThrowSlipAnimationStateChangeCallback";
808 info.bundleName_ = "RegisterThrowSlipAnimationStateChangeCallback";
809 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
810
__anonbd6cfeff1002(bool isAnimating, bool isFullScreen) 811 std::function<void(bool isAnimating, bool isFullScreen)> func = [](bool isAnimating, bool isFullScreen) { return; };
812 sceneSession->RegisterThrowSlipAnimationStateChangeCallback(std::move(func));
813 EXPECT_NE(sceneSession, nullptr);
814 }
815
816 /**
817 * @tc.name: MaskSupportEnterWaterfallMode
818 * @tc.desc: MaskSupportEnterWaterfallMode
819 * @tc.type: FUNC
820 */
821 HWTEST_F(SceneSessionTest3, MaskSupportEnterWaterfallMode, TestSize.Level1)
822 {
823 SessionInfo info;
824 info.abilityName_ = "MaskSupportEnterWaterfallMode";
825 info.bundleName_ = "MaskSupportEnterWaterfallMode";
826 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
827
828 sceneSession->MaskSupportEnterWaterfallMode();
829 EXPECT_NE(sceneSession, nullptr);
830 sceneSession->pcFoldScreenController_ = nullptr;
831 sceneSession->MaskSupportEnterWaterfallMode();
832 EXPECT_NE(sceneSession, nullptr);
833 }
834
835 /**
836 * @tc.name: HandleActionUpdateMainWindowTopmost
837 * @tc.desc: HandleActionUpdateMainWindowTopmost
838 * @tc.type: FUNC
839 */
840 HWTEST_F(SceneSessionTest3, HandleActionUpdateMainWindowTopmost, TestSize.Level1)
841 {
842 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS;
843 SessionInfo info;
844 info.abilityName_ = "HandleActionUpdateMainWindowTopmost";
845 info.bundleName_ = "HandleActionUpdateMainWindowTopmost";
846 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
847 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
848 sceneSession->property_ = windowSessionProperty;
849
850 auto res = sceneSession->HandleActionUpdateMainWindowTopmost(windowSessionProperty, action);
851 EXPECT_EQ(res, WMError::WM_OK);
852 }
853
854 /**
855 * @tc.name: HandleActionUpdateSubWindowZLevel
856 * @tc.desc: HandleActionUpdateSubWindowZLevel
857 * @tc.type: FUNC
858 */
859 HWTEST_F(SceneSessionTest3, HandleActionUpdateSubWindowZLevel, TestSize.Level1)
860 {
861 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_SUB_WINDOW_Z_LEVEL;
862 SessionInfo info;
863 info.abilityName_ = "HandleActionUpdateSubWindowZLevel";
864 info.bundleName_ = "HandleActionUpdateSubWindowZLevel";
865 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
866 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
867 sceneSession->property_ = windowSessionProperty;
868
869 auto res = sceneSession->HandleActionUpdateSubWindowZLevel(windowSessionProperty, action);
870 EXPECT_EQ(res, WMError::WM_OK);
871 }
872
873 /**
874 * @tc.name: HandleBackgroundAlpha
875 * @tc.desc: HandleBackgroundAlpha
876 * @tc.type: FUNC
877 */
878 HWTEST_F(SceneSessionTest3, HandleBackgroundAlpha, TestSize.Level1)
879 {
880 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS;
881 SessionInfo info;
882 info.abilityName_ = "HandleBackgroundAlpha";
883 info.bundleName_ = "HandleBackgroundAlpha";
884 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
885 sptr<WindowSessionProperty> windowSessionProperty = sptr<WindowSessionProperty>::MakeSptr();
886 sceneSession->property_ = windowSessionProperty;
887
888 auto res = sceneSession->HandleBackgroundAlpha(windowSessionProperty, action);
889 EXPECT_EQ(res, WMError::WM_OK);
890 }
891
892 /**
893 * @tc.name: SendContainerModalEvent
894 * @tc.desc: SendContainerModalEvent
895 * @tc.type: FUNC
896 */
897 HWTEST_F(SceneSessionTest3, SendContainerModalEvent, TestSize.Level1)
898 {
899 string eventName = "test";
900 string eventValue = "test";
901 SessionInfo info;
902 info.abilityName_ = "SendContainerModalEvent";
903 info.bundleName_ = "SendContainerModalEvent";
904 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
905 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
906
907 auto res = sceneSession->SendContainerModalEvent(eventName, eventValue);
908 EXPECT_EQ(res, sceneSession->sessionStage_->SendContainerModalEvent(eventName, eventValue));
909 }
910
911 /**
912 * @tc.name: RegisterSetLandscapeMultiWindowFunc
913 * @tc.desc: RegisterSetLandscapeMultiWindowFunc
914 * @tc.type: FUNC
915 */
916 HWTEST_F(SceneSessionTest3, RegisterSetLandscapeMultiWindowFunc, TestSize.Level1)
917 {
918 SessionInfo info;
919 info.abilityName_ = "RegisterSetLandscapeMultiWindowFunc";
920 info.bundleName_ = "RegisterSetLandscapeMultiWindowFunc";
921 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
922
__anonbd6cfeff1102(bool isLandscapeMultiWindow) 923 std::function<void(bool isLandscapeMultiWindow)> func = [](bool isLandscapeMultiWindow) { return; };
924 sceneSession->RegisterSetLandscapeMultiWindowFunc(std::move(func));
925 EXPECT_NE(sceneSession, nullptr);
926 }
927
928 /**
929 * @tc.name: IsDirtyDragWindow
930 * @tc.desc: IsDirtyDragWindow
931 * @tc.type: FUNC
932 */
933 HWTEST_F(SceneSessionTest3, IsDirtyDragWindow, TestSize.Level1)
934 {
935 SessionInfo info;
936 info.abilityName_ = "IsDirtyDragWindow";
937 info.bundleName_ = "IsDirtyDragWindow";
938 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
939 sceneSession->dirtyFlags_ = 0;
940
941 auto res = sceneSession->IsDirtyDragWindow();
942 EXPECT_EQ(res,
943 sceneSession->dirtyFlags_ & static_cast<uint32_t>(SessionUIDirtyFlag::DRAG_RECT) ||
944 sceneSession->isDragging_);
945 }
946
947 /**
948 * @tc.name: RequestHideKeyboard
949 * @tc.desc: RequestHideKeyboard
950 * @tc.type: FUNC
951 */
952 HWTEST_F(SceneSessionTest3, RequestHideKeyboard, TestSize.Level1)
953 {
954 bool isAppColdStart = true;
955 SessionInfo info;
956 info.abilityName_ = "RequestHideKeyboard";
957 info.bundleName_ = "RequestHideKeyboard";
958 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
959
960 sceneSession->RequestHideKeyboard(isAppColdStart);
961 EXPECT_NE(sceneSession, nullptr);
962 }
963
964 /**
965 * @tc.name: SetStartingWindowExitAnimationFlag
966 * @tc.desc: SetStartingWindowExitAnimationFlag
967 * @tc.type: FUNC
968 */
969 HWTEST_F(SceneSessionTest3, SetStartingWindowExitAnimationFlag, TestSize.Level1)
970 {
971 bool enable = true;
972 SessionInfo info;
973 info.abilityName_ = "SetStartingWindowExitAnimationFlag";
974 info.bundleName_ = "SetStartingWindowExitAnimationFlag";
975 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
976
977 sceneSession->SetStartingWindowExitAnimationFlag(enable);
978 EXPECT_NE(sceneSession, nullptr);
979 }
980
981 /**
982 * @tc.name: SetSkipSelfWhenShowOnVirtualScreen01
983 * @tc.desc: SetSkipSelfWhenShowOnVirtualScreen
984 * @tc.type: FUNC
985 */
986 HWTEST_F(SceneSessionTest3, SetSkipSelfWhenShowOnVirtualScreen01, TestSize.Level1)
987 {
988 SessionInfo info;
989 info.abilityName_ = "SetSkipSelfWhenShowOnVirtualScreen";
990 info.bundleName_ = "SetSkipSelfWhenShowOnVirtualScreen";
991 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
992 bool skipResult = false;
993
994 sceneSession->SetSkipSelfWhenShowOnVirtualScreen(false);
995 usleep(SLEEP_TIME_US);
996 ASSERT_EQ(skipResult, false);
997
998 struct RSSurfaceNodeConfig config;
999 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
1000 surfaceNode->id_ = 1;
1001 sceneSession->surfaceNode_ = surfaceNode;
1002
1003 sceneSession->SetSkipSelfWhenShowOnVirtualScreen(false);
1004 usleep(SLEEP_TIME_US);
1005 ASSERT_EQ(skipResult, false);
1006 }
1007
1008 /**
1009 * @tc.name: RegisterRequestedOrientationChangeCallback
1010 * @tc.desc: RegisterRequestedOrientationChangeCallback
1011 * @tc.type: FUNC
1012 */
1013 HWTEST_F(SceneSessionTest3, RegisterRequestedOrientationChangeCallback, TestSize.Level1)
1014 {
1015 SessionInfo info;
1016 info.abilityName_ = "RegisterRequestedOrientationChangeCallback";
1017 info.bundleName_ = "RegisterRequestedOrientationChangeCallback";
1018 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1019
__anonbd6cfeff1202(uint32_t orientation, bool needAnimation) 1020 std::function<void(uint32_t orientation, bool needAnimation)> func = [](uint32_t orientation, bool needAnimation) {
1021 return;
1022 };
1023 sceneSession->RegisterRequestedOrientationChangeCallback(std::move(func));
1024 EXPECT_NE(sceneSession, nullptr);
1025 }
1026
1027 /**
1028 * @tc.name: IsShowOnLockScreen
1029 * @tc.desc: IsShowOnLockScreen
1030 * @tc.type: FUNC
1031 */
1032 HWTEST_F(SceneSessionTest3, IsShowOnLockScreen, TestSize.Level1)
1033 {
1034 SessionInfo info;
1035 info.abilityName_ = "IsShowOnLockScreen";
1036 info.bundleName_ = "IsShowOnLockScreen";
1037 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1038 sceneSession->SetZOrder(2005);
1039 sceneSession->GetSessionProperty()->SetDisplayId(-2);
1040 EXPECT_FALSE(sceneSession->IsShowOnLockScreen(2000));
1041 sceneSession->GetSessionProperty()->SetDisplayId(-1);
1042 EXPECT_TRUE(sceneSession->IsShowOnLockScreen(2000));
1043
1044 sceneSession->SetZOrder(0);
1045 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1046 EXPECT_FALSE(sceneSession->IsShowOnLockScreen(2000));
1047
1048 sptr<SceneSession> parentSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1049 parentSession->SetZOrder(2004);
1050 sceneSession->parentSession_ = parentSession;
1051 EXPECT_TRUE(sceneSession->IsShowOnLockScreen(2000));
1052
1053 sceneSession->SetZOrder(1000);
1054 EXPECT_FALSE(sceneSession->IsShowOnLockScreen(2000));
1055
1056 sceneSession->property_ = nullptr;
1057 EXPECT_FALSE(sceneSession->IsShowOnLockScreen(2000));
1058 }
1059
1060 /**
1061 * @tc.name: NotifySetParentSession
1062 * @tc.desc: NotifySetParentSession
1063 * @tc.type: FUNC
1064 */
1065 HWTEST_F(SceneSessionTest3, NotifySetParentSession, TestSize.Level1)
1066 {
1067 SessionInfo info;
1068 info.abilityName_ = "NotifySetParentSession";
1069 info.bundleName_ = "NotifySetParentSession";
1070 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1071 int32_t oldParentWindowId = 1;
1072 int32_t newParentWindowId = 2;
1073 auto res = sceneSession->NotifySetParentSession(oldParentWindowId, newParentWindowId);
1074 EXPECT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW);
1075 }
1076
1077 /**
1078 * @tc.name: UpdateSubWindowLevel
1079 * @tc.desc: UpdateSubWindowLevel
1080 * @tc.type: FUNC
1081 */
1082 HWTEST_F(SceneSessionTest3, UpdateSubWindowLevel, TestSize.Level1)
1083 {
1084 SessionInfo info;
1085 info.abilityName_ = "UpdateSubWindowLevel";
1086 info.bundleName_ = "UpdateSubWindowLevel";
1087 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1088 uint32_t subWindowLevel = 10;
1089 EXPECT_NE(subWindowLevel, sceneSession->GetSessionProperty()->GetSubWindowLevel());
1090 sceneSession->UpdateSubWindowLevel(subWindowLevel);
1091 EXPECT_EQ(subWindowLevel, sceneSession->GetSessionProperty()->GetSubWindowLevel());
1092 }
1093
1094 /**
1095 * @tc.name: UpdateLifecyclePausedInner
1096 * @tc.desc: UpdateLifecyclePausedInner
1097 * @tc.type: FUNC
1098 */
1099 HWTEST_F(SceneSessionTest3, UpdateLifecyclePausedInner, TestSize.Level1)
1100 {
1101 logMsg.clear();
1102 LOG_SetCallback(MyLogCallback);
1103 SessionInfo info;
1104 info.abilityName_ = "UpdateLifecyclePausedInner";
1105 info.bundleName_ = "UpdateLifecyclePausedInner";
1106 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
1107 ASSERT_NE(session, nullptr);
1108 session->UpdateLifecyclePausedInner();
1109 EXPECT_TRUE(logMsg.find("state: ") == std::string::npos);
1110 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1111 ASSERT_NE(mockSessionStage, nullptr);
1112 session->sessionStage_ = mockSessionStage;
1113 session->state_ = SessionState::STATE_ACTIVE;
1114 session->UpdateLifecyclePausedInner();
1115 session->state_ = SessionState::STATE_FOREGROUND;
1116 session->UpdateLifecyclePausedInner();
1117 session->state_ = SessionState::STATE_BACKGROUND;
1118 session->UpdateLifecyclePausedInner();
1119 EXPECT_TRUE(logMsg.find("state: ") != std::string::npos);
1120 LOG_SetCallback(nullptr);
1121 }
1122
1123 /**
1124 * @tc.name: SetUseControlState
1125 * @tc.desc: SetUseControlState and GetUseControlState
1126 * @tc.type: FUNC
1127 */
1128 HWTEST_F(SceneSessionTest3, SetUseControlState, TestSize.Level1)
1129 {
1130 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1131 ASSERT_NE(property, nullptr);
1132 bool isUseControl = true;
1133 property->SetUseControlState(isUseControl);
1134 EXPECT_EQ(true, property->GetUseControlState());
1135 }
1136
1137 /**
1138 * @tc.name: RegisterUpdateAppUseControlCallback
1139 * @tc.desc: RegisterUpdateAppUseControlCallback
1140 * @tc.type: FUNC
1141 */
1142 HWTEST_F(SceneSessionTest3, RegisterUpdateAppUseControlCallback, Function | SmallTest | Level3)
1143 {
1144 ControlInfo controlInfo = {
1145 .isNeedControl = false,
1146 .isControlRecentOnly = true
1147 };
1148 ControlInfo controlInfoSec = {
1149 .isNeedControl = false,
1150 .isControlRecentOnly = false
1151 };
1152 ControlInfo controlInfoThd = {
1153 .isNeedControl = true,
1154 .isControlRecentOnly = false
1155 };
1156 SessionInfo info;
1157 info.bundleName_ = "app";
1158 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbd6cfeff1302(ControlAppType type, bool isNeedControl, bool isControlRecentOnly) 1159 auto callback = [](ControlAppType type, bool isNeedControl, bool isControlRecentOnly) {};
1160
1161 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>> allAppUseMap;
1162 sceneSession->SetGetAllAppUseControlMapFunc([&allAppUseMap]() ->
__anonbd6cfeff1402() 1163 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>>& {return allAppUseMap;});
1164 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1165 std::string key = "app#0";
1166 allAppUseMap[key][ControlAppType::APP_LOCK] = controlInfo;
1167 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1168
1169 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>> allAppUseMapSec;
1170 sceneSession->SetGetAllAppUseControlMapFunc([&allAppUseMapSec]() ->
__anonbd6cfeff1502() 1171 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>>& {return allAppUseMapSec;});
1172 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1173 std::string keySec = "app#0";
1174 allAppUseMapSec[keySec][ControlAppType::APP_LOCK] = controlInfoSec;
1175 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1176
1177 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>> allAppUseMapThd;
1178 sceneSession->SetGetAllAppUseControlMapFunc([&allAppUseMapThd]() ->
__anonbd6cfeff1602() 1179 std::unordered_map<std::string, std::unordered_map<ControlAppType, ControlInfo>>& {return allAppUseMapThd;});
1180 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1181 std::string keyThd = "app#0";
1182 allAppUseMapThd[keyThd][ControlAppType::APP_LOCK] = controlInfoThd;
1183 sceneSession->RegisterUpdateAppUseControlCallback(callback);
1184 ASSERT_NE(nullptr, sceneSession->onUpdateAppUseControlFunc_);
1185 }
1186
1187 /**
1188 * @tc.name: NotifyUpdateAppUseControl
1189 * @tc.desc: NotifyUpdateAppUseControl
1190 * @tc.type: FUNC
1191 */
1192 HWTEST_F(SceneSessionTest3, NotifyUpdateAppUseControl, Function | SmallTest | Level3)
1193 {
1194 logMsg.clear();
1195 LOG_SetCallback(MyLogCallback);
1196 ControlInfo controlInfo = {
1197 .isNeedControl = true,
1198 .isControlRecentOnly = false
1199 };
1200 SessionInfo info;
1201 info.abilityName_ = "NotifyUpdateAppUseControl";
1202 info.bundleName_ = "NotifyUpdateAppUseControl";
1203 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
__anonbd6cfeff1702(ControlAppType type, bool isNeedControl, bool isControlRecentOnly) 1204 auto callback = [](ControlAppType type, bool isNeedControl, bool isControlRecentOnly) {
1205 std::cout << "isNeedControl:" << isNeedControl << ";isControlRecentOnly:" << isControlRecentOnly << std::endl;
1206 };
1207 sceneSession->onUpdateAppUseControlFunc_ = std::move(callback);
1208 sceneSession->sessionStage_ = nullptr;
1209 ControlAppType type = ControlAppType::APP_LOCK;
1210 sceneSession->NotifyUpdateAppUseControl(type, controlInfo);
1211 sceneSession->sessionStage_ = sptr<SessionStageMocker>::MakeSptr();
1212 sceneSession->NotifyUpdateAppUseControl(type, controlInfo);
1213
1214 ControlInfo controlInfoSec = {
1215 .isNeedControl = false,
1216 .isControlRecentOnly = false
1217 };
1218 sceneSession->NotifyUpdateAppUseControl(type, controlInfoSec);
1219 EXPECT_TRUE(logMsg.find("begin call pause") == std::string::npos);
1220 LOG_SetCallback(nullptr);
1221 }
1222
1223 /**
1224 * @tc.name: GetMaxSubWindowLevel
1225 * @tc.desc: GetMaxSubWindowLevel
1226 * @tc.type: FUNC
1227 */
1228 HWTEST_F(SceneSessionTest3, GetMaxSubWindowLevel, TestSize.Level1)
1229 {
1230 SessionInfo info;
1231 info.abilityName_ = "GetMaxSubWindowLevel";
1232 info.bundleName_ = "GetMaxSubWindowLevel";
1233 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1234 EXPECT_EQ(1, sceneSession->GetMaxSubWindowLevel());
1235 }
1236
1237 /**
1238 * @tc.name: NotifyUpdateFlagCallback
1239 * @tc.desc: NotifyUpdateFlagCallback
1240 * @tc.type: FUNC
1241 */
1242 HWTEST_F(SceneSessionTest3, NotifyUpdateFlagCallback, TestSize.Level1)
1243 {
1244 SessionInfo info;
1245 info.abilityName_ = "NotifyUpdateFlagCallback";
1246 info.bundleName_ = "NotifyUpdateFlagCallback";
1247 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1248
__anonbd6cfeff1802(const std::string& flag) 1249 NotifyUpdateFlagFunc func1 = [](const std::string& flag) { return; };
1250 sceneSession->NotifyUpdateFlagCallback(std::move(func1));
1251 ASSERT_NE(nullptr, sceneSession->onUpdateFlagFunc_);
1252 }
1253
1254 /**
1255 * @tc.name: GetKeyboardOccupiedAreaWithRotation1
1256 * @tc.desc: GetKeyboardOccupiedAreaWithRotation
1257 * @tc.type: FUNC
1258 */
1259 HWTEST_F(SceneSessionTest3, GetKeyboardOccupiedAreaWithRotation1, TestSize.Level1)
1260 {
1261 SessionInfo info;
1262 info.abilityName_ = "GetKeyboardOccupiedAreaWithRotation";
1263 info.bundleName_ = "GetKeyboardOccupiedAreaWithRotation";
1264 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1265 sceneSession->specificCallback_ = nullptr;
1266
1267 int32_t persistentId = 1;
1268 std::vector<std::pair<bool, WSRect>> avoidAreas;
1269 std::pair<bool, WSRect> keyboardOccupiedArea = { false, { 0, 0, 0, 0 } };
1270 avoidAreas.emplace_back(keyboardOccupiedArea);
1271 sceneSession->GetKeyboardOccupiedAreaWithRotation(persistentId, Rotation::ROTATION_90, avoidAreas);
1272 uint32_t areaSize = static_cast<uint32_t>(avoidAreas.size());
1273 ASSERT_EQ(1, areaSize);
1274 ASSERT_EQ(false, avoidAreas[0].first);
1275 }
1276
1277 /**
1278 * @tc.name: GetKeyboardOccupiedAreaWithRotation2
1279 * @tc.desc: GetKeyboardOccupiedAreaWithRotation
1280 * @tc.type: FUNC
1281 */
1282 HWTEST_F(SceneSessionTest3, GetKeyboardOccupiedAreaWithRotation2, TestSize.Level1)
1283 {
1284 SessionInfo info;
1285 info.abilityName_ = "GetKeyboardOccupiedAreaWithRotation";
1286 info.bundleName_ = "GetKeyboardOccupiedAreaWithRotation";
1287 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1288 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1289 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1290 sceneSession->specificCallback_ = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1291 sceneSession->specificCallback_->onKeyboardRotationChange_ = nullptr;
1292
1293 int32_t persistentId = 1;
1294 std::vector<std::pair<bool, WSRect>> avoidAreas;
1295 std::pair<bool, WSRect> keyboardOccupiedArea = { true, { 0, 0, 0, 0 } };
1296 avoidAreas.emplace_back(keyboardOccupiedArea);
1297 sceneSession->GetKeyboardOccupiedAreaWithRotation(persistentId, Rotation::ROTATION_90, avoidAreas);
1298 uint32_t areaSize = static_cast<uint32_t>(avoidAreas.size());
1299 ASSERT_EQ(1, areaSize);
1300 ASSERT_EQ(true, avoidAreas[0].first);
1301 }
1302
1303 /**
1304 * @tc.name: SetSkipEventOnCastPlus01
1305 * @tc.desc: check func SetSkipEventOnCastPlus
1306 * @tc.type: FUNC
1307 */
1308 HWTEST_F(SceneSessionTest3, SetSkipEventOnCastPlus01, TestSize.Level1)
1309 {
1310 sptr<SceneSession::SpecificSessionCallback> specificCallback =
1311 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1312 SessionInfo info;
1313 info.abilityName_ = "SetSkipEventOnCastPlus";
1314 info.bundleName_ = "SetSkipEventOnCastPlus";
1315 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1316 sceneSession->SetSkipEventOnCastPlus(false);
1317 ASSERT_EQ(false, sceneSession->GetSessionProperty()->GetSkipEventOnCastPlus());
1318 }
1319 } // namespace
1320 } // namespace Rosen
1321 } // namespace OHOS