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 <pointer_event.h>
18 #include <ui/rs_surface_node.h>
19
20 #include "display_manager.h"
21 #include "input_event.h"
22 #include "key_event.h"
23 #include "mock/mock_session_stage.h"
24 #include "pointer_event.h"
25 #include "session/host/include/main_session.h"
26 #include "session/host/include/scene_session.h"
27 #include "session/host/include/sub_session.h"
28 #include "session/host/include/system_session.h"
29 #include "session/screen/include/screen_session.h"
30 #include "screen_session_manager/include/screen_session_manager.h"
31 #include "screen_session_manager_client/include/screen_session_manager_client.h"
32 #include "window_helper.h"
33 #include "wm_common.h"
34
35 using namespace testing;
36 using namespace testing::ext;
37 namespace OHOS {
38 namespace Rosen {
39 class SceneSessionLayoutTest : public testing::Test {
40 public:
41 static void SetUpTestCase();
42 static void TearDownTestCase();
43 void SetUp() override;
44 void TearDown() override;
45
46 private:
47 sptr<SessionStageMocker> mockSessionStage_ = nullptr;
48 };
49
SetUpTestCase()50 void SceneSessionLayoutTest::SetUpTestCase() {}
51
TearDownTestCase()52 void SceneSessionLayoutTest::TearDownTestCase() {}
53
SetUp()54 void SceneSessionLayoutTest::SetUp()
55 {
56 mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
57 }
58
TearDown()59 void SceneSessionLayoutTest::TearDown() {}
60
61 namespace {
62 /**
63 * @tc.name: UpdateRect01
64 * @tc.desc: normal function
65 * @tc.type: FUNC
66 */
67 HWTEST_F(SceneSessionLayoutTest, UpdateRect01, TestSize.Level1)
68 {
69 SessionInfo info;
70 info.abilityName_ = "UpdateRect01";
71 info.bundleName_ = "UpdateRect01";
72 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
73 sceneSession->isActive_ = true;
74
75 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
76 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
77
78 sceneSession->SetSessionProperty(property);
79 WSRect rect({ 1, 1, 1, 1 });
80 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
81 WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
82 ASSERT_EQ(result, WSError::WS_OK);
83 }
84
85 /**
86 * @tc.name: UpdateRect02
87 * @tc.desc: normal function
88 * @tc.type: FUNC
89 */
90 HWTEST_F(SceneSessionLayoutTest, UpdateRect02, TestSize.Level0)
91 {
92 SessionInfo info;
93 info.abilityName_ = "UpdateRect02";
94 info.bundleName_ = "UpdateRect02";
95 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
96 sceneSession->isActive_ = true;
97
98 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
99 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
100
101 sceneSession->SetSessionProperty(property);
102 WSRect rect({ 1, 1, 1, 1 });
103 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
104 WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
105 ASSERT_EQ(result, WSError::WS_OK);
106
107 sceneSession->GetLayoutController()->SetSessionRect(rect);
108 result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
109 ASSERT_EQ(result, WSError::WS_OK);
110
111 sceneSession->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_END);
112 result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
113 ASSERT_EQ(result, WSError::WS_OK);
114
115 WSRect rect2({ 0, 0, 0, 0 });
116 result = sceneSession->UpdateRect(rect2, reason, "SceneSessionLayoutTest");
117 ASSERT_EQ(result, WSError::WS_OK);
118 }
119
120 /**
121 * @tc.name: UpdateRect03
122 * @tc.desc: UpdateRect
123 * @tc.type: FUNC
124 */
125 HWTEST_F(SceneSessionLayoutTest, UpdateRect03, TestSize.Level0)
126 {
127 SessionInfo info;
128 info.abilityName_ = "UpdateRect03";
129 info.bundleName_ = "UpdateRect03";
130 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
131 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
132 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
133
134 WSRect rect = { 200, 200, 200, 200 };
135 session->GetLayoutController()->SetSessionRect(rect);
136 session->SetClientRect(rect);
137 EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionLayoutTest"), WSError::WS_OK);
138
139 rect.posX_ = 100;
140 rect.posY_ = 100;
141 rect.width_ = 800;
142 rect.height_ = 800;
143 session->GetLayoutController()->SetSessionRect(rect);
144 EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionLayoutTest"), WSError::WS_OK);
145 }
146
147 /**
148 * @tc.name: NotifyClientToUpdateRect01
149 * @tc.desc: NotifyClientToUpdateRect
150 * @tc.type: FUNC
151 */
152 HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRect01, TestSize.Level0)
153 {
154 SessionInfo info;
155 info.abilityName_ = "NotifyClientToUpdateRect01";
156 info.bundleName_ = "NotifyClientToUpdateRect01";
157 info.windowType_ = 1;
158 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
159 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
160 sceneSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
161 sceneSession->sessionStage_ = mockSessionStage;
162 auto ret = sceneSession->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr);
163 ASSERT_EQ(ret, WSError::WS_OK);
164 }
165
166 /**
167 * @tc.name: UpdateRectInner
168 * @tc.desc: UpdateRectInner
169 * @tc.type: FUNC
170 */
171 HWTEST_F(SceneSessionLayoutTest, UpdateRectInner01, TestSize.Level0)
172 {
173 SessionInfo info;
174 info.abilityName_ = "UpdateRectInner01";
175 info.bundleName_ = "UpdateRectInner01";
176 info.screenId_ = 20;
177 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
178 SessionUIParam uiParam;
179 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
180 sceneSession->SetForegroundInteractiveStatus(true);
181
182 uiParam.needSync_ = true;
183 uiParam.rect_ = { 0, 0, 1, 1 };
184
185 sceneSession->GetLayoutController()->SetSessionRect({ 1, 1, 1, 1 });
186 sceneSession->isVisible_ = true;
187 ASSERT_EQ(false, sceneSession->UpdateRectInner(uiParam, reason));
188 }
189
190 /**
191 * @tc.name: UpdateRectInner02
192 * @tc.desc: UpdateRectInner02
193 * @tc.type: FUNC
194 */
195 HWTEST_F(SceneSessionLayoutTest, UpdateRectInner02, TestSize.Level0)
196 {
197 SessionInfo info;
198 info.abilityName_ = "UpdateRectInner02";
199 info.bundleName_ = "UpdateRectInner02";
200 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
201 SessionUIParam uiParam;
202 sceneSession->isVisible_ = true;
203 sceneSession->state_ = SessionState::STATE_FOREGROUND;
204 SizeChangeReason reason = SizeChangeReason::UNDEFINED;
205 sceneSession->SetForegroundInteractiveStatus(true);
206
207 sceneSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
208 sceneSession->isSubWindowResizingOrMoving_ = true;
209 sceneSession->GetSessionProperty()->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
210 ASSERT_EQ(true, sceneSession->UpdateRectInner(uiParam, reason));
211 ASSERT_EQ(true, sceneSession->isSubWindowResizingOrMoving_);
212
213 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
214 ASSERT_EQ(true, sceneSession->UpdateRectInner(uiParam, reason));
215 ASSERT_EQ(false, sceneSession->isSubWindowResizingOrMoving_);
216 }
217
218 /**
219 * @tc.name: NotifyClientToUpdateRect
220 * @tc.desc: NotifyClientToUpdateRect function01
221 * @tc.type: FUNC
222 */
223 HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRect, TestSize.Level1)
224 {
225 SessionInfo info;
226 info.abilityName_ = "NotifyClientToUpdateRect";
227 info.bundleName_ = "NotifyClientToUpdateRect";
228 info.isSystem_ = false;
229 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
230 session->moveDragController_ = nullptr;
231 session->isKeyboardPanelEnabled_ = false;
232 session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED);
233 session->Session::SetSessionState(SessionState::STATE_CONNECT);
234 session->specificCallback_ = nullptr;
235 session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG);
236 EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr));
237
__anonf12e7c160202(const int32_t& persistentId) 238 UpdateAvoidAreaCallback func = [](const int32_t& persistentId) { return; };
239 auto specificCallback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
240 specificCallback->onUpdateAvoidArea_ = func;
241 session->specificCallback_ = specificCallback;
242 session->Session::UpdateSizeChangeReason(SizeChangeReason::RECOVER);
243 EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr));
244 }
245
246 /**
247 * @tc.name: CheckAspectRatioValid
248 * @tc.desc: CheckAspectRatioValid function01
249 * @tc.type: FUNC
250 */
251 HWTEST_F(SceneSessionLayoutTest, CheckAspectRatioValid, TestSize.Level0)
252 {
253 SessionInfo info;
254 info.abilityName_ = "CheckAspectRatioValid";
255 info.bundleName_ = "CheckAspectRatioValid";
256 info.isSystem_ = false;
257 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
258 WindowLimits windowLimits;
259 ASSERT_NE(session->GetSessionProperty(), nullptr);
260 session->GetSessionProperty()->SetWindowLimits(windowLimits);
261
262 SystemSessionConfig systemConfig;
263 systemConfig.isSystemDecorEnable_ = false;
264 session->SetSystemConfig(systemConfig);
265 EXPECT_EQ(false, session->IsDecorEnable());
266
267 windowLimits.minWidth_ = 0;
268 windowLimits.minHeight_ = 0;
269 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
270
271 windowLimits.minWidth_ = 1;
272 windowLimits.maxHeight_ = 0;
273 windowLimits.minHeight_ = 1;
274 windowLimits.maxWidth_ = 0;
275 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
276
277 windowLimits.maxHeight_ = 1;
278 windowLimits.maxWidth_ = 1;
279 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(1.0f));
280
281 windowLimits.maxHeight_ = 10000;
282 windowLimits.minHeight_ = -10000;
283 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
284
285 windowLimits.maxHeight_ = 10000;
286 windowLimits.minHeight_ = -10000;
287 EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
288
289 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
290 WindowLimits limits = { 8, 1, 6, 1, 1, 1.0f, 1.0f };
291 property->SetWindowLimits(limits);
292 session->SetSessionProperty(property);
293 EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, session->SetAspectRatio(0.1f));
294 EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, session->SetAspectRatio(10.0f));
295 }
296
297 /**
298 * @tc.name: CheckAspectRatioValid02
299 * @tc.desc: CheckAspectRatioValid
300 * @tc.type: FUNC
301 */
302 HWTEST_F(SceneSessionLayoutTest, CheckAspectRatioValid02, TestSize.Level0)
303 {
304 SessionInfo info;
305 info.abilityName_ = "CheckAspectRatioValid02";
306 info.bundleName_ = "CheckAspectRatioValid02";
307 info.isSystem_ = false;
308 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
309 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
310 sceneSession->SetSessionProperty(property);
311
312 WindowLimits windowLimits;
313 sceneSession->GetSessionProperty()->SetWindowLimits(windowLimits);
314
315 SystemSessionConfig systemConfig;
316 systemConfig.isSystemDecorEnable_ = false;
317 sceneSession->SetSystemConfig(systemConfig);
318 EXPECT_EQ(false, sceneSession->IsDecorEnable());
319
320 windowLimits.minWidth_ = 0;
321 windowLimits.minHeight_ = 0;
322 EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f));
323
324 windowLimits.minWidth_ = 1;
325 windowLimits.minHeight_ = 2;
326 EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f));
327
328 windowLimits.minWidth_ = 2;
329 windowLimits.minHeight_ = 1;
330 EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f));
331
332 windowLimits.minWidth_ = 1;
333 windowLimits.minHeight_ = 2;
334 EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(1.0f));
335 }
336
337 /**
338 * @tc.name: NotifyClientToUpdateRectTask
339 * @tc.desc: NotifyClientToUpdateRectTask function
340 * @tc.type: FUNC
341 */
342 HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRectTask, TestSize.Level0)
343 {
344 SessionInfo info;
345 info.abilityName_ = "NotifyClientToUpdateRectTask";
346 info.bundleName_ = "NotifyClientToUpdateRectTask";
347 info.isSystem_ = true;
348
349 sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
350 session->moveDragController_ = nullptr;
351 session->isKeyboardPanelEnabled_ = false;
352 session->SetSessionRect({ 0, 0, 800, 800 });
353
354 session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED);
355 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
356 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
357 session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
358 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
359 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
360 session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE);
361 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
362 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
363 session->Session::UpdateSizeChangeReason(SizeChangeReason::RESIZE);
364 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
365 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
366 session->Session::UpdateSizeChangeReason(SizeChangeReason::RECOVER);
367 EXPECT_EQ(session->GetSizeChangeReason(), SizeChangeReason::RECOVER);
368 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
369 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
370
371 session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
372 session->moveDragController_->isStartDrag_ = true;
373 session->moveDragController_->isStartMove_ = true;
374 session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
375 session->isKeyboardPanelEnabled_ = true;
376 info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
377 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
378 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
379 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
380 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
381 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
382
383 session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED);
384 EXPECT_EQ(WSError::WS_ERROR_REPEAT_OPERATION,
385 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
386
387 session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
388 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
389 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
390 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
391 session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE);
392 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
393 EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
394 session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
395 }
396
397 /**
398 * @tc.name: HandleActionUpdateWindowLimits
399 * @tc.desc: normal function
400 * @tc.type: FUNC
401 */
402 HWTEST_F(SceneSessionLayoutTest, HandleActionUpdateWindowLimits, TestSize.Level1)
403 {
404 SessionInfo info;
405 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
406 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
407
408 WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS;
409 WMError res = sceneSession->HandleActionUpdateWindowLimits(property, action);
410 EXPECT_EQ(WMError::WM_OK, res);
411 }
412
413 /**
414 * @tc.name: SetAspectRatio2
415 * @tc.desc: normal function
416 * @tc.type: FUNC
417 */
418 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio2, TestSize.Level0)
419 {
420 SessionInfo info;
421 info.abilityName_ = "SetAspectRatio2";
422 info.bundleName_ = "SetAspectRatio2";
423 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
424 sceneSession->isActive_ = true;
425
426 float ratio = 0.0001;
427 sceneSession->moveDragController_ = nullptr;
428 auto result = sceneSession->SetAspectRatio(ratio);
429 ASSERT_EQ(result, WSError::WS_OK);
430 ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
431
432 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(0, sceneSession->GetWindowType());
433 result = sceneSession->SetAspectRatio(ratio);
434 ASSERT_EQ(result, WSError::WS_OK);
435 ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
436
437 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
438 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
439 sceneSession->SetSessionProperty(property);
440 result = sceneSession->SetAspectRatio(ratio);
441 ASSERT_EQ(result, WSError::WS_OK);
442 ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
443 }
444
445 /**
446 * @tc.name: SetAspectRatio3
447 * @tc.desc: normal function
448 * @tc.type: FUNC
449 */
450 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio3, TestSize.Level1)
451 {
452 SessionInfo info;
453 info.abilityName_ = "SetAspectRatio3";
454 info.bundleName_ = "SetAspectRatio3";
455 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
456 sceneSession->isActive_ = true;
457
458 float ratio = 0.1;
459 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
460 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
461 sceneSession->SetSessionProperty(property);
462 WindowLimits limits;
463 limits.maxHeight_ = 10;
464 limits.minWidth_ = 1;
465 limits.minHeight_ = 1;
466 property->SetWindowLimits(limits);
467 auto result = sceneSession->SetAspectRatio(ratio);
468 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
469 }
470
471 /**
472 * @tc.name: SetAspectRatio4
473 * @tc.desc: normal function
474 * @tc.type: FUNC
475 */
476 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio4, TestSize.Level1)
477 {
478 SessionInfo info;
479 info.abilityName_ = "SetAspectRatio4";
480 info.bundleName_ = "SetAspectRatio4";
481 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
482 sceneSession->isActive_ = true;
483 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
484 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
485 sceneSession->SetSessionProperty(property);
486
487 float ratio = 0.1;
488 WindowLimits limits;
489 limits.maxHeight_ = 10;
490 limits.minWidth_ = 10;
491 property->SetWindowLimits(limits);
492 auto result = sceneSession->SetAspectRatio(ratio);
493 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
494 }
495
496 /**
497 * @tc.name: SetAspectRatio5
498 * @tc.desc: test for aspectRatio NearZero
499 * @tc.type: FUNC
500 */
501 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio5, TestSize.Level0)
502 {
503 SessionInfo info;
504 info.abilityName_ = "SetAspectRatio5";
505 info.bundleName_ = "SetAspectRatio5";
506 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
507 sceneSession->isActive_ = true;
508
509 float ratio = 0.0001;
510 auto result = sceneSession->SetAspectRatio(ratio);
511 ASSERT_EQ(result, WSError::WS_OK);
512
513 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
514 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
515 sceneSession->SetSessionProperty(property);
516 result = sceneSession->SetAspectRatio(ratio);
517 ASSERT_EQ(result, WSError::WS_OK);
518 ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
519 }
520
521 /**
522 * @tc.name: SetAspectRatio6
523 * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight
524 * @tc.type: FUNC
525 */
526 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio6, TestSize.Level0)
527 {
528 SessionInfo info;
529 info.abilityName_ = "SetAspectRatio6";
530 info.bundleName_ = "SetAspectRatio6";
531 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
532 sceneSession->isActive_ = true;
533
534 float ratio = 2.5;
535 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
536 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
537 WindowLimits limits;
538 limits.maxWidth_ = 3000;
539 limits.maxHeight_ = 3000;
540 limits.minWidth_ = 2000;
541 limits.minHeight_ = 2000;
542 property->SetWindowLimits(limits);
543 sceneSession->SetSessionProperty(property);
544 auto result = sceneSession->SetAspectRatio(ratio);
545 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
546 }
547
548 /**
549 * @tc.name: SetAspectRatio7
550 * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight
551 * @tc.type: FUNC
552 */
553 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio7, TestSize.Level0)
554 {
555 SessionInfo info;
556 info.abilityName_ = "SetAspectRatio7";
557 info.bundleName_ = "SetAspectRatio7";
558 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
559 sceneSession->isActive_ = true;
560
561 float ratio = 0.1;
562 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
563 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
564 WindowLimits limits;
565 limits.maxWidth_ = 3000;
566 limits.maxHeight_ = 3000;
567 limits.minWidth_ = 2000;
568 limits.minHeight_ = 2000;
569 property->SetWindowLimits(limits);
570 sceneSession->SetSessionProperty(property);
571 auto result = sceneSession->SetAspectRatio(ratio);
572 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
573 }
574
575 /**
576 * @tc.name: SetAspectRatio8
577 * @tc.desc: normal function
578 * @tc.type: FUNC
579 */
580 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio8, TestSize.Level1)
581 {
582 SessionInfo info;
583 info.abilityName_ = "SetAspectRatio8";
584 info.bundleName_ = "SetAspectRatio8";
585 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
586 sceneSession->isActive_ = true;
587
588 float ratio = 0.1;
589 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
590 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
591 WindowLimits limits;
592 limits.maxHeight_ = 10;
593 limits.minWidth_ = 0;
594 property->SetWindowLimits(limits);
595 sceneSession->SetSessionProperty(property);
596 auto result = sceneSession->SetAspectRatio(ratio);
597 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
598 }
599
600 /**
601 * @tc.name: SetAspectRatio9
602 * @tc.desc: normal function
603 * @tc.type: FUNC
604 */
605 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio9, TestSize.Level1)
606 {
607 SessionInfo info;
608 info.abilityName_ = "SetAspectRatio9";
609 info.bundleName_ = "SetAspectRatio9";
610 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
611 sceneSession->isActive_ = true;
612
613 float ratio = 0.1;
614 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
615 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
616 WindowLimits limits;
617 limits.maxHeight_ = 10;
618 limits.minWidth_ = 10;
619 property->SetWindowLimits(limits);
620 sceneSession->SetSessionProperty(property);
621 auto result = sceneSession->SetAspectRatio(ratio);
622 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
623 }
624
625 /**
626 * @tc.name: SaveAspectRatio
627 * @tc.desc: SaveAspectRatio
628 * @tc.type: FUNC
629 */
630 HWTEST_F(SceneSessionLayoutTest, SaveAspectRatio, TestSize.Level1)
631 {
632 SessionInfo info;
633 info.abilityName_ = "Background01";
634 info.bundleName_ = "IsFloatingWindowAppType";
635 info.windowType_ = 1;
636 sptr<SceneSession> sceneSession;
637 sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
638 ASSERT_EQ(true, sceneSession->SaveAspectRatio(0.1));
639
640 sceneSession->sessionInfo_.bundleName_ = "";
641 sceneSession->sessionInfo_.moduleName_ = "";
642 sceneSession->sessionInfo_.abilityName_ = "";
643 ASSERT_EQ(false, sceneSession->SaveAspectRatio(0.1));
644 }
645
646 /**
647 * To test the function call
648 *
649 * @tc.name: ActivateDragBySystem
650 * @tc.desc: ActivateDragBySystem function
651 * @tc.type: FUNC
652 */
653 HWTEST_F(SceneSessionLayoutTest, ActivateDragBySystem, TestSize.Level1)
654 {
655 SessionInfo info;
656 info.abilityName_ = "ActivateDragBySystem";
657 info.bundleName_ = "ActivateDragBySystem";
658 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
659 auto ret = sceneSession->ActivateDragBySystem(true);
660 EXPECT_EQ(WMError::WM_OK, ret);
661 }
662
663 /**
664 * To test the drag activated settings, and validate the draggable results.
665 * Expect the results:
666 * enableDrag: true, dragActivated: true => true
667 * enableDrag: false, dragActivated: true => false
668 * enableDrag: true, dragActivated: false => false
669 * enableDrag: false, dragActivated: false => false
670 *
671 * @tc.name: CheckDragActivatedSettings
672 * @tc.desc: CheckDragActivatedSettings
673 * @tc.type: FUNC
674 */
675 HWTEST_F(SceneSessionLayoutTest, CheckDragActivatedSettings, TestSize.Level1)
676 {
677 SessionInfo info;
678 info.abilityName_ = "CheckDragActivatedSettings";
679 info.bundleName_ = "CheckDragActivatedSettings";
680 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
681
682 sceneSession->ActivateDragBySystem(true);
683 sceneSession->GetSessionProperty()->SetDragEnabled(true);
684 ASSERT_EQ(true, sceneSession->IsDragAccessible());
685
686 sceneSession->GetSessionProperty()->SetDragEnabled(false);
687 ASSERT_EQ(false, sceneSession->IsDragAccessible());
688
689 sceneSession->ActivateDragBySystem(false);
690 sceneSession->GetSessionProperty()->SetDragEnabled(true);
691 ASSERT_EQ(false, sceneSession->IsDragAccessible());
692
693 sceneSession->GetSessionProperty()->SetDragEnabled(false);
694 ASSERT_EQ(false, sceneSession->IsDragAccessible());
695 }
696
697 /**
698 * @tc.name: NotifySingleHandTransformChange
699 * @tc.desc: NotifySingleHandTransformChange
700 * @tc.type: FUNC
701 */
702 HWTEST_F(SceneSessionLayoutTest, NotifySingleHandTransformChange, TestSize.Level1)
703 {
704 SessionInfo info;
705 info.abilityName_ = "NotifySingleHandTransformChange";
706 info.bundleName_ = "NotifySingleHandTransformChange";
707 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
708
709 SingleHandTransform testTransform;
710 sceneSession->state_ = SessionState::STATE_BACKGROUND;
711 sceneSession->NotifySingleHandTransformChange(testTransform);
712
713 sceneSession->state_ = SessionState::STATE_FOREGROUND;
714 mockSessionStage_ = nullptr;
715 sceneSession->sessionStage_ = mockSessionStage_;
716 sceneSession->NotifySingleHandTransformChange(testTransform);
717
718 mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
719 sceneSession->sessionStage_ = mockSessionStage_;
720 sceneSession->NotifySingleHandTransformChange(testTransform);
721 ASSERT_NE(100, testTransform.posX);
722 }
723
724 /**
725 * @tc.name: GetSessionGlobalRectWithSingleHandScale
726 * @tc.desc: GetSessionGlobalRectWithSingleHandScale
727 * @tc.type: FUNC
728 */
729 HWTEST_F(SceneSessionLayoutTest, GetSessionGlobalRectWithSingleHandScale, TestSize.Level1)
730 {
731 SessionInfo info;
732 info.abilityName_ = "GetSessionGlobalRectWithSingleHandScale";
733 info.bundleName_ = "GetSessionGlobalRectWithSingleHandScale";
734 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
735
736 SingleHandTransform testTransform;
737 WSRect globalRect = { 100, 100, 800, 800 };
738 sceneSession->SetSessionGlobalRect(globalRect);
739 sceneSession->SetSingleHandTransform(testTransform);
740 ASSERT_EQ(sceneSession->GetSessionGlobalRect().posX_,
741 sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_);
742
743 testTransform.posX = 10;
744 testTransform.posY = 10;
745 testTransform.scaleX = 0.75f;
746 testTransform.scaleY = 0.75f;
747 sceneSession->SetSingleHandTransform(testTransform);
748 ASSERT_NE(sceneSession->GetSessionGlobalRect().posX_,
749 sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_);
750 }
751
752 /**
753 * @tc.name: IsNeedConvertToRelativeRect
754 * @tc.desc: IsNeedConvertToRelativeRect
755 * @tc.type: FUNC
756 */
757 HWTEST_F(SceneSessionLayoutTest, IsNeedConvertToRelativeRect, TestSize.Level1)
758 {
759 SessionInfo info;
760 info.abilityName_ = "IsNeedConvertToRelativeRect";
761 info.bundleName_ = "IsNeedConvertToRelativeRect";
762 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
763 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
764 sceneSession->moveDragController_ =
765 sptr<MoveDragController>::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType());
766 info.abilityName_ = "IsNeedConvertToRelativeRect_subSession";
767 info.bundleName_ = "IsNeedConvertToRelativeRect_subSession";
768 sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
769 subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
770 sceneSession->subSession_.emplace_back(subSceneSession);
771 subSceneSession->parentSession_ = sceneSession;
772
773 EXPECT_EQ(sceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::MAXIMIZE), false);
774 EXPECT_EQ(sceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::DRAG_MOVE), true);
775
776 sceneSession->moveDragController_->isStartMove_ = true;
777 sceneSession->moveDragController_->isStartDrag_ = false;
778 EXPECT_EQ(subSceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::MAXIMIZE), false);
779
780 sceneSession->moveDragController_->isStartMove_ = false;
781 sceneSession->moveDragController_->isStartDrag_ = true;
782 EXPECT_EQ(subSceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::MAXIMIZE), false);
783
784 subSceneSession->windowAnchorInfo_.isAnchorEnabled_ = true;
785 sceneSession->moveDragController_->isStartMove_ = true;
786 sceneSession->moveDragController_->isStartDrag_ = false;
787 EXPECT_EQ(subSceneSession->IsNeedConvertToRelativeRect(SizeChangeReason::MAXIMIZE), true);
788 }
789
790 /**
791 * @tc.name: IsDraggable
792 * @tc.desc: IsDraggable when moveDragController_ is nullptr or not.
793 * @tc.type: FUNC
794 */
795 HWTEST_F(SceneSessionLayoutTest, IsDraggable, TestSize.Level1)
796 {
797 SessionInfo info;
798 info.abilityName_ = "IsDraggable";
799 info.bundleName_ = "IsDraggable";
800 info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
801 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
802 sceneSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
803 sceneSession->GetSessionProperty()->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
804 sceneSession->GetSessionProperty()->SetDragEnabled(true);
805 sceneSession->SetDragActivated(true);
806
807 sceneSession->moveDragController_ = nullptr;
808 EXPECT_EQ(sceneSession->IsDraggable(), false);
809
810 sceneSession->moveDragController_ =
811 sptr<MoveDragController>::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType());
812 EXPECT_EQ(sceneSession->IsDraggable(), true);
813 }
814
815 /**
816 * @tc.name: IsMovable
817 * @tc.desc: Test IsMovable when AnchorEnabled or AnchorDisabled
818 * @tc.type: FUNC
819 */
820 HWTEST_F(SceneSessionLayoutTest, IsMovable, TestSize.Level1)
821 {
822 SessionInfo info;
823 info.abilityName_ = "IsMovable";
824 info.bundleName_ = "IsMovable";
825 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
826 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
827 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2025, WindowType::WINDOW_TYPE_FLOAT);
828 EXPECT_EQ(WSError::WS_OK, sceneSession->UpdateFocus(true));
829 sceneSession->moveDragController_->isStartMove_ = false;
830 sceneSession->moveDragController_->isStartDrag_ = false;
831 sceneSession->moveDragController_->hasPointDown_ = true;
832 sceneSession->moveDragController_->isMovable_ = true;
833
834 sceneSession->windowAnchorInfo_.isAnchorEnabled_ = true;
835 EXPECT_EQ(false, sceneSession->IsMovable());
836 sceneSession->windowAnchorInfo_.isAnchorEnabled_ = false;
837 EXPECT_EQ(true, sceneSession->IsMovable());
838 }
839
840 /**
841 * @tc.name: IsAnyParentSessionDragMoving
842 * @tc.desc: IsAnyParentSessionDragMoving
843 * @tc.type: FUNC
844 */
845 HWTEST_F(SceneSessionLayoutTest, IsAnyParentSessionDragMoving, TestSize.Level1)
846 {
847 SessionInfo info;
848 info.abilityName_ = "IsAnyParentSessionDragMoving";
849 info.bundleName_ = "IsAnyParentSessionDragMoving";
850 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
851 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
852 sceneSession->moveDragController_ =
853 sptr<MoveDragController>::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType());
854 info.abilityName_ = "IsAnyParentSessionDragMoving_subSession";
855 info.bundleName_ = "IsAnyParentSessionDragMoving_subSession";
856 sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
857 subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
858
859 subSceneSession->parentSession_ = nullptr;
860 ASSERT_EQ(subSceneSession->IsAnyParentSessionDragMoving(), false);
861 sceneSession->moveDragController_->isStartMove_ = true;
862 ASSERT_EQ(sceneSession->IsAnyParentSessionDragMoving(), true);
863
864 sceneSession->subSession_.emplace_back(subSceneSession);
865 subSceneSession->parentSession_ = sceneSession;
866 ASSERT_EQ(subSceneSession->IsAnyParentSessionDragMoving(), true);
867 }
868
869 /**
870 * @tc.name: IsAnyParentSessionDragZooming
871 * @tc.desc: IsAnyParentSessionDragZooming
872 * @tc.type: FUNC
873 */
874 HWTEST_F(SceneSessionLayoutTest, IsAnyParentSessionDragZooming, TestSize.Level1)
875 {
876 SessionInfo info;
877 info.abilityName_ = "IsAnyParentSessionDragZooming";
878 info.bundleName_ = "IsAnyParentSessionDragZooming";
879 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
880 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
881 sceneSession->moveDragController_ =
882 sptr<MoveDragController>::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType());
883 info.abilityName_ = "IsAnyParentSessionDragZooming_subSession";
884 info.bundleName_ = "IsAnyParentSessionDragZooming_subSession";
885 sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
886 subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
887
888 subSceneSession->parentSession_ = nullptr;
889 ASSERT_EQ(subSceneSession->IsAnyParentSessionDragZooming(), false);
890 sceneSession->moveDragController_->isStartDrag_ = true;
891 ASSERT_EQ(sceneSession->IsAnyParentSessionDragZooming(), true);
892
893 sceneSession->subSession_.emplace_back(subSceneSession);
894 subSceneSession->parentSession_ = sceneSession;
895 ASSERT_EQ(subSceneSession->IsAnyParentSessionDragZooming(), true);
896 }
897
898 /**
899 * @tc.name: HandleSubSessionSurfaceNode
900 * @tc.desc: HandleSubSessionSurfaceNode
901 * @tc.type: FUNC
902 */
903 HWTEST_F(SceneSessionLayoutTest, HandleSubSessionSurfaceNode, TestSize.Level1)
904 {
905 SessionInfo info;
906 info.abilityName_ = "HandleSubSessionSurfaceNode";
907 info.bundleName_ = "HandleSubSessionSurfaceNode";
908 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
909 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
910 sceneSession->moveDragController_ =
911 sptr<MoveDragController>::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType());
912 info.abilityName_ = "HandleSubSessionSurfaceNode_subSession";
913 info.bundleName_ = "HandleSubSessionSurfaceNode_subSession";
914 sptr<SubSession> subSceneSession = sptr<SubSession>::MakeSptr(info, nullptr);
915 subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
916 sceneSession->subSession_.emplace_back(subSceneSession);
917 subSceneSession->parentSession_ = sceneSession;
918 sceneSession->displayIdSetDuringMoveTo_.insert(888);
919 subSceneSession->displayIdSetDuringMoveTo_.insert(888);
920
921 subSceneSession->NotifyFollowParentMultiScreenPolicy(false);
922 sceneSession->HandleSubSessionSurfaceNode(false, 0);
923 ASSERT_NE(0, subSceneSession->displayIdSetDuringMoveTo_.size());
924 subSceneSession->NotifyFollowParentMultiScreenPolicy(true);
925 sceneSession->HandleSubSessionSurfaceNode(true, 0);
926 ASSERT_NE(0, subSceneSession->displayIdSetDuringMoveTo_.size());
927 sceneSession->HandleSubSessionSurfaceNode(false, 0);
928 ASSERT_EQ(0, subSceneSession->displayIdSetDuringMoveTo_.size());
929 }
930
931 /**
932 * @tc.name: HandleSubSessionCrossNode
933 * @tc.desc: HandleSubSessionCrossNode
934 * @tc.type: FUNC
935 */
936 HWTEST_F(SceneSessionLayoutTest, HandleSubSessionCrossNode, TestSize.Level1)
937 {
938 SessionInfo info;
939 info.abilityName_ = "HandleSubSessionCrossNode";
940 info.bundleName_ = "HandleSubSessionCrossNode";
941 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
942 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
943 info.abilityName_ = "HandleSubSessionCrossNode_subSession";
944 info.bundleName_ = "HandleSubSessionCrossNode_subSession";
945 sptr<SceneSession> subSceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
946 subSceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
947
948 sceneSession->SetDragStart(true);
949 sceneSession->HandleSubSessionCrossNode(SizeChangeReason::UNDEFINED);
950 ASSERT_EQ(sceneSession->IsDragStart(), true);
951 sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG);
952 ASSERT_EQ(sceneSession->IsDragStart(), true);
953 sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG_END);
954 ASSERT_EQ(sceneSession->IsDragStart(), false);
955
956 sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG);
957 ASSERT_EQ(sceneSession->IsDragStart(), true);
958 sceneSession->subSession_.emplace_back(subSceneSession);
959 subSceneSession->parentSession_ = sceneSession;
960 sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG_END);
961 ASSERT_EQ(sceneSession->IsDragStart(), false);
962 sceneSession->HandleSubSessionCrossNode(SizeChangeReason::DRAG_MOVE);
963 ASSERT_EQ(sceneSession->IsDragStart(), true);
964 }
965
966 /**
967 * @tc.name: UpdateWindowModeForUITest01
968 * @tc.desc: UpdateWindowModeForUITest
969 * @tc.type: FUNC
970 */
971 HWTEST_F(SceneSessionLayoutTest, UpdateWindowModeForUITest01, TestSize.Level1)
972 {
973 SessionInfo info;
974 info.abilityName_ = "UpdateWindowModeForUITest";
975 info.bundleName_ = "UpdateWindowModeForUITest";
976 sptr<SceneSession::SpecificSessionCallback> specificCallback =
977 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
978 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback);
979
980 const int32_t updateMode = 1;
981 WMError errCode = sceneSession->UpdateWindowModeForUITest(updateMode);
982 EXPECT_EQ(errCode, WMError::WM_ERROR_NULLPTR);
983
984 sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
985 sceneSession->sessionStage_ = mockSessionStage;
986 errCode = sceneSession->UpdateWindowModeForUITest(updateMode);
987 EXPECT_EQ(errCode, WMError::WM_OK);
988 }
989
990 /**
991 * @tc.name: SetMoveAvailableArea01
992 * @tc.desc: SetMoveAvailableArea01
993 * @tc.type: FUNC
994 */
995 HWTEST_F(SceneSessionLayoutTest, SetMoveAvailableArea01, TestSize.Level1)
996 {
997 SessionInfo info;
998 info.abilityName_ = "SetMoveAvailableArea01";
999 info.bundleName_ = "SetMoveAvailableArea01";
1000 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1001
1002 WSError res = sceneSession->SetMoveAvailableArea(-1);
1003 EXPECT_EQ(res, WSError::WS_ERROR_INVALID_DISPLAY);
1004
1005 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, sceneSession->GetWindowType());
1006 int32_t screenId = 0;
1007 sceneSession->SetScreenId(screenId);
1008 res = sceneSession->SetMoveAvailableArea(0);
1009 EXPECT_EQ(res, WSError::WS_OK);
1010
1011 sptr<ScreenSession> currentScreenSession =
1012 ScreenSessionManager::GetInstance().GetOrCreateScreenSession(0);
1013 ASSERT_NE(currentScreenSession, nullptr);
1014 uint32_t currentScreenHeight = currentScreenSession->GetScreenProperty().GetBounds().rect_.height_;
1015 DMRect statusBarRect = sceneSession->CalcRectForStatusBar();
1016 int32_t dockHeight = sceneSession->GetDockHeight();
1017 if (PcFoldScreenManager::GetInstance().IsHalfFolded(screenId)) {
1018 sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1019 DMRect availableArea;
1020 DMError ret = DisplayManager::GetInstance().GetExpandAvailableArea(
1021 sceneSession->GetSessionProperty()->GetDisplayId(), availableArea);
1022 if (ret != DMError::DM_OK) {
1023 TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to get available area, ret: %{public}d", ret);
1024 }
1025 EXPECT_EQ(sceneSession->moveDragController_->moveAvailableArea_, availableArea);
1026 EXPECT_EQ(sceneSession->moveDragController_->moveAvailableArea_.height_,
1027 currentScreenHeight - statusBarRect.height_ - dockHeight);
1028 }
1029 }
1030
1031 /**
1032 * @tc.name: SetMoveAvailableArea02
1033 * @tc.desc: SetMoveAvailableArea02
1034 * @tc.type: FUNC
1035 */
1036 HWTEST_F(SceneSessionLayoutTest, SetMoveAvailableArea02, TestSize.Level1)
1037 {
1038 SessionInfo info;
1039 info.abilityName_ = "SetMoveAvailableArea02";
1040 info.bundleName_ = "SetMoveAvailableArea02";
1041 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1042 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1043 EXPECT_NE(specificCallback_, nullptr);
1044 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, specificCallback_);
1045
1046 WSRect rect({0, 0, 50, 50});
1047 sceneSession->GetLayoutController()->SetSessionRect(rect);
1048 sceneSession->specificCallback_->onGetSceneSessionVectorByTypeAndDisplayId_ =
__anonf12e7c160302(WindowType type, uint64_t displayId) 1049 [&](WindowType type, uint64_t displayId) -> std::vector<sptr<SceneSession>> {
1050 std::vector<sptr<SceneSession>> vec;
1051 vec.push_back(sceneSession);
1052 return vec;
1053 };
1054
1055 SystemSessionConfig systemConfig;
1056 int32_t screenId = 0;
1057 sceneSession->SetScreenId(screenId);
1058
1059 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1060 property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1061 sceneSession->SetSessionProperty(property);
1062 ScreenSessionConfig config;
1063 sptr<ScreenSession> screenSession =
1064 sptr<ScreenSession>::MakeSptr(config, ScreenSessionReason::CREATE_SESSION_FOR_CLIENT);
1065 ScreenSessionManagerClient::GetInstance().screenSessionMap_.insert(std::make_pair(screenId, screenSession));
1066
1067 systemConfig.windowUIType_ = WindowUIType::PHONE_WINDOW;
1068 sceneSession->SetSystemConfig(systemConfig);
1069 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, sceneSession->GetWindowType());
1070 WSError res = sceneSession->SetMoveAvailableArea(0);
1071 EXPECT_EQ(res, WSError::WS_OK);
1072
1073 systemConfig.windowUIType_ = WindowUIType::PC_WINDOW;
1074 sceneSession->SetSystemConfig(systemConfig);
1075 sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, sceneSession->GetWindowType());
1076 res = sceneSession->SetMoveAvailableArea(0);
1077 EXPECT_EQ(res, WSError::WS_OK);
1078 }
1079
1080 /**
1081 * @tc.name: GetAppHookWindowInfoFromServer
1082 * @tc.desc: GetAppHookWindowInfoFromServer
1083 * @tc.type: FUNC
1084 */
1085 HWTEST_F(SceneSessionLayoutTest, GetAppHookWindowInfoFromServer, TestSize.Level1)
1086 {
1087 SessionInfo info;
1088 info.abilityName_ = "GetAppHookWindowInfoFromServer";
1089 info.bundleName_ = "GetAppHookWindowInfoFromServer";
1090 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1091
1092 sceneSession->getHookWindowInfoFunc_ = nullptr;
1093 HookWindowInfo hookWindowInfo;
1094 WMError errCode = sceneSession->GetAppHookWindowInfoFromServer(hookWindowInfo);
1095 EXPECT_EQ(errCode, WMError::WM_ERROR_NULLPTR);
1096 EXPECT_EQ(hookWindowInfo.enableHookWindow, false);
1097
__anonf12e7c160402(const std::string& bundleName) 1098 sceneSession->getHookWindowInfoFunc_ = [](const std::string& bundleName) -> HookWindowInfo {
1099 HookWindowInfo hookInfo;
1100 hookInfo.enableHookWindow = true;
1101 return hookInfo;
1102 };
1103 HookWindowInfo hookWindowInfo2;
1104 errCode = sceneSession->GetAppHookWindowInfoFromServer(hookWindowInfo2);
1105 EXPECT_EQ(errCode, WMError::WM_OK);
1106 EXPECT_EQ(hookWindowInfo2.enableHookWindow, true);
1107 }
1108
1109 /**
1110 * @tc.name: RegisterAppHookWindowInfoFunc
1111 * @tc.desc: RegisterAppHookWindowInfoFunc
1112 * @tc.type: FUNC
1113 */
1114 HWTEST_F(SceneSessionLayoutTest, RegisterAppHookWindowInfoFunc, TestSize.Level1)
1115 {
1116 SessionInfo info;
1117 info.abilityName_ = "RegisterAppHookWindowInfoFunc";
1118 info.bundleName_ = "RegisterAppHookWindowInfoFunc";
1119 sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1120 sceneSession->getHookWindowInfoFunc_ = nullptr;
1121
1122 // Case 1: func is not nullptr
__anonf12e7c160502(const std::string& bundleName) 1123 sceneSession->RegisterAppHookWindowInfoFunc([](const std::string& bundleName) -> HookWindowInfo {
1124 HookWindowInfo hookInfo;
1125 hookInfo.enableHookWindow = true;
1126 return hookInfo;
1127 });
1128 ASSERT_NE(sceneSession->getHookWindowInfoFunc_, nullptr);
1129 HookWindowInfo hookWindowInfo;
1130 WMError errCode = sceneSession->GetAppHookWindowInfoFromServer(hookWindowInfo);
1131 EXPECT_EQ(errCode, WMError::WM_OK);
1132 EXPECT_EQ(hookWindowInfo.enableHookWindow, true);
1133
1134 // Case 2: func is nullptr
1135 sceneSession->RegisterAppHookWindowInfoFunc(nullptr);
1136 ASSERT_NE(sceneSession->getHookWindowInfoFunc_, nullptr);
1137 }
1138 } // namespace
1139 } // namespace Rosen
1140 } // namespace OHOS