• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "window_helper.h"
30 #include "wm_common.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 namespace OHOS {
35 namespace Rosen {
36 class SceneSessionLayoutTest : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp() override;
41     void TearDown() override;
42 
43 private:
44     sptr<SessionStageMocker> mockSessionStage_ = nullptr;
45 };
46 
SetUpTestCase()47 void SceneSessionLayoutTest::SetUpTestCase()
48 {
49 }
50 
TearDownTestCase()51 void SceneSessionLayoutTest::TearDownTestCase()
52 {
53 }
54 
SetUp()55 void SceneSessionLayoutTest::SetUp()
56 {
57     mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
58 }
59 
TearDown()60 void SceneSessionLayoutTest::TearDown()
61 {
62 }
63 
64 namespace {
65 /**
66  * @tc.name: UpdateRect01
67  * @tc.desc: normal function
68  * @tc.type: FUNC
69  */
70 HWTEST_F(SceneSessionLayoutTest, UpdateRect01, Function | SmallTest | Level2)
71 {
72     SessionInfo info;
73     info.abilityName_ = "UpdateRect01";
74     info.bundleName_ = "UpdateRect01";
75     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
76     sceneSession->isActive_ = true;
77 
78     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
79     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
80 
81     sceneSession->SetSessionProperty(property);
82     WSRect rect({1, 1, 1, 1});
83     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
84     WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
85     ASSERT_EQ(result, WSError::WS_OK);
86 }
87 
88 
89 /**
90  * @tc.name: UpdateRect02
91  * @tc.desc: normal function
92  * @tc.type: FUNC
93  */
94 HWTEST_F(SceneSessionLayoutTest, UpdateRect02, Function | SmallTest | Level2)
95 {
96     SessionInfo info;
97     info.abilityName_ = "UpdateRect02";
98     info.bundleName_ = "UpdateRect02";
99     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
100     sceneSession->isActive_ = true;
101 
102     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
103     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
104 
105     sceneSession->SetSessionProperty(property);
106     WSRect rect({1, 1, 1, 1});
107     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
108     WSError result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
109     ASSERT_EQ(result, WSError::WS_OK);
110 
111     sceneSession->winRect_ = rect;
112     result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
113     ASSERT_EQ(result, WSError::WS_OK);
114 
115     sceneSession->reason_ = SizeChangeReason::DRAG_END;
116     result = sceneSession->UpdateRect(rect, reason, "SceneSessionLayoutTest");
117     ASSERT_EQ(result, WSError::WS_OK);
118 
119     WSRect rect2({0, 0, 0, 0});
120     result = sceneSession->UpdateRect(rect2, reason, "SceneSessionLayoutTest");
121     ASSERT_EQ(result, WSError::WS_OK);
122 }
123 
124 /**
125  * @tc.name: UpdateRect03
126  * @tc.desc: UpdateRect
127  * @tc.type: FUNC
128  */
129 HWTEST_F(SceneSessionLayoutTest, UpdateRect03, Function | SmallTest | Level2)
130 {
131     SessionInfo info;
132     info.abilityName_ = "UpdateRect03";
133     info.bundleName_ = "UpdateRect03";
134     info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
135     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
136     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
137 
138     WSRect rect = { 200, 200, 200, 200 };
139     session->winRect_ = rect;
140     session->SetClientRect(rect);
141     EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionLayoutTest"), WSError::WS_OK);
142 
143     rect.posX_ = 100;
144     rect.posY_ = 100;
145     rect.width_ = 800;
146     rect.height_ = 800;
147     session->winRect_ = rect;
148     EXPECT_EQ(session->UpdateRect(rect, reason, "SceneSessionLayoutTest"), WSError::WS_OK);
149 }
150 
151 /**
152  * @tc.name: NotifyClientToUpdateRect01
153  * @tc.desc: NotifyClientToUpdateRect
154  * @tc.type: FUNC
155  */
156 HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRect01, Function | SmallTest | Level2)
157 {
158     SessionInfo info;
159     info.abilityName_ = "NotifyClientToUpdateRect01";
160     info.bundleName_ = "NotifyClientToUpdateRect01";
161     info.windowType_ = 1;
162     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
163     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
164     sceneSession->dirtyFlags_ |= static_cast<uint32_t>(SessionUIDirtyFlag::RECT);
165     sceneSession->sessionStage_ = mockSessionStage;
166     auto ret = sceneSession->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr);
167     ASSERT_EQ(ret, WSError::WS_OK);
168 }
169 
170 /**
171  * @tc.name: UpdateRectInner
172  * @tc.desc: UpdateRectInner
173  * @tc.type: FUNC
174  */
175 HWTEST_F(SceneSessionLayoutTest, UpdateRectInner01, Function | SmallTest | Level2)
176 {
177     SessionInfo info;
178     info.abilityName_ = "UpdateRectInner01";
179     info.bundleName_ = "UpdateRectInner01";
180     info.screenId_ = 20;
181     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
182     SessionUIParam uiParam;
183     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
184     sceneSession->SetForegroundInteractiveStatus(true);
185 
186     uiParam.needSync_ = true;
187     uiParam.rect_ = {0, 0, 1, 1};
188 
189     sceneSession->winRect_ = {1, 1, 1, 1};
190     sceneSession->isVisible_ = true;
191     ASSERT_EQ(false, sceneSession->UpdateRectInner(uiParam, reason));
192 }
193 
194 /**
195  * @tc.name: NotifyClientToUpdateRect
196  * @tc.desc: NotifyClientToUpdateRect function01
197  * @tc.type: FUNC
198  */
199 HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRect, Function | SmallTest | Level2)
200 {
201     SessionInfo info;
202     info.abilityName_ = "NotifyClientToUpdateRect";
203     info.bundleName_ = "NotifyClientToUpdateRect";
204     info.isSystem_ = false;
205     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
206     session->moveDragController_ = nullptr;
207     session->isKeyboardPanelEnabled_ = false;
208     session->reason_ = SizeChangeReason::UNDEFINED;
209     session->Session::SetSessionState(SessionState::STATE_CONNECT);
210     session->specificCallback_ = nullptr;
211     session->reason_ = SizeChangeReason::DRAG;
212     EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr));
213 
__anon1700a5e70202(const int32_t& persistentId) 214     UpdateAvoidAreaCallback func = [](const int32_t& persistentId) {
215         return;
216     };
217     auto specificCallback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
218     specificCallback->onUpdateAvoidArea_ = func;
219     session->specificCallback_ = specificCallback;
220     session->reason_ = SizeChangeReason::RECOVER;
221     EXPECT_EQ(WSError::WS_OK, session->NotifyClientToUpdateRect("SceneSessionLayoutTest", nullptr));
222 }
223 
224 /**
225  * @tc.name: CheckAspectRatioValid
226  * @tc.desc: CheckAspectRatioValid function01
227  * @tc.type: FUNC
228  */
229 HWTEST_F(SceneSessionLayoutTest, CheckAspectRatioValid, Function | SmallTest | Level2)
230 {
231     SessionInfo info;
232     info.abilityName_ = "CheckAspectRatioValid";
233     info.bundleName_ = "CheckAspectRatioValid";
234     info.isSystem_ = false;
235     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
236     WindowLimits windowLimits;
237     ASSERT_NE(session->GetSessionProperty(), nullptr);
238     session->GetSessionProperty()->SetWindowLimits(windowLimits);
239 
240     SystemSessionConfig systemConfig;
241     systemConfig.isSystemDecorEnable_ = false;
242     session->SetSystemConfig(systemConfig);
243     EXPECT_EQ(false, session->IsDecorEnable());
244 
245     windowLimits.minWidth_ = 0;
246     windowLimits.minHeight_ = 0;
247     EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
248 
249     windowLimits.minWidth_ = 1;
250     windowLimits.maxHeight_ = 0;
251     windowLimits.minHeight_ = 1;
252     windowLimits.maxWidth_ = 0;
253     EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
254 
255     windowLimits.maxHeight_ = 1;
256     windowLimits.maxWidth_ = 1;
257     EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(1.0f));
258 
259     windowLimits.maxHeight_ = 10000;
260     windowLimits.minHeight_ = -10000;
261     EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
262 
263     windowLimits.maxHeight_ = 10000;
264     windowLimits.minHeight_ = -10000;
265     EXPECT_EQ(WSError::WS_OK, session->SetAspectRatio(0.0f));
266 
267     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
268     WindowLimits limits = {8, 1, 6, 1, 1, 1.0f, 1.0f};
269     property->SetWindowLimits(limits);
270     session->SetSessionProperty(property);
271     EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, session->SetAspectRatio(0.1f));
272     EXPECT_EQ(WSError::WS_ERROR_INVALID_PARAM, session->SetAspectRatio(10.0f));
273 }
274 
275 /**
276  * @tc.name: CheckAspectRatioValid02
277  * @tc.desc: CheckAspectRatioValid
278  * @tc.type: FUNC
279  */
280 HWTEST_F(SceneSessionLayoutTest, CheckAspectRatioValid02, Function | SmallTest | Level2)
281 {
282     SessionInfo info;
283     info.abilityName_ = "CheckAspectRatioValid02";
284     info.bundleName_ = "CheckAspectRatioValid02";
285     info.isSystem_ = false;
286     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
287     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
288     sceneSession->SetSessionProperty(property);
289 
290     WindowLimits windowLimits;
291     sceneSession->GetSessionProperty()->SetWindowLimits(windowLimits);
292 
293     SystemSessionConfig systemConfig;
294     systemConfig.isSystemDecorEnable_ = false;
295     sceneSession->SetSystemConfig(systemConfig);
296     EXPECT_EQ(false, sceneSession->IsDecorEnable());
297 
298     windowLimits.minWidth_ = 0;
299     windowLimits.minHeight_ = 0;
300     EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f));
301 
302     windowLimits.minWidth_ = 1;
303     windowLimits.minHeight_ = 2;
304     EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f));
305 
306     windowLimits.minWidth_ = 2;
307     windowLimits.minHeight_ = 1;
308     EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(0.0f));
309 
310     windowLimits.minWidth_ = 1;
311     windowLimits.minHeight_ = 2;
312     EXPECT_EQ(WSError::WS_OK, sceneSession->SetAspectRatio(1.0f));
313 }
314 
315 /**
316  * @tc.name: NotifyClientToUpdateRectTask
317  * @tc.desc: NotifyClientToUpdateRectTask function
318  * @tc.type: FUNC
319  */
320 HWTEST_F(SceneSessionLayoutTest, NotifyClientToUpdateRectTask, Function | SmallTest | Level2)
321 {
322     SessionInfo info;
323     info.abilityName_ = "NotifyClientToUpdateRectTask";
324     info.bundleName_ = "NotifyClientToUpdateRectTask";
325     info.isSystem_ = true;
326 
327     sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
328     session->moveDragController_ = nullptr;
329     session->isKeyboardPanelEnabled_ = false;
330 
331     session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED);
332     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
333         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
334     session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
335     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
336         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
337     session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE);
338     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
339         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
340     session->Session::UpdateSizeChangeReason(SizeChangeReason::RESIZE);
341     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
342         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
343     session->Session::UpdateSizeChangeReason(SizeChangeReason::RECOVER);
344     EXPECT_EQ(session->reason_, SizeChangeReason::RECOVER);
345     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
346         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
347 
348     session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024, session->GetWindowType());
349     session->moveDragController_->isStartDrag_ = true;
350     session->moveDragController_->isStartMove_ = true;
351     session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
352     session->isKeyboardPanelEnabled_ = true;
353     info.windowType_ = static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE);
354     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
355         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
356     info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
357     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
358         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
359 
360     session->Session::UpdateSizeChangeReason(SizeChangeReason::UNDEFINED);
361     EXPECT_EQ(WSError::WS_ERROR_REPEAT_OPERATION,
362         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
363 
364     session->Session::UpdateSizeChangeReason(SizeChangeReason::MOVE);
365     info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
366     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
367         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
368     session->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG_MOVE);
369     info.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
370     EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION,
371         session->NotifyClientToUpdateRectTask("SceneSessionLayoutTest", nullptr));
372 }
373 
374 /**
375  * @tc.name: HandleActionUpdateWindowLimits
376  * @tc.desc: normal function
377  * @tc.type: FUNC
378  */
379 HWTEST_F(SceneSessionLayoutTest, HandleActionUpdateWindowLimits, Function | SmallTest | Level2)
380 {
381     SessionInfo info;
382     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
383     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
384 
385     WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_WINDOW_LIMITS;
386     WMError res = sceneSession->HandleActionUpdateWindowLimits(property, action);
387     EXPECT_EQ(WMError::WM_OK, res);
388 }
389 
390 /**
391  * @tc.name: SetAspectRatio2
392  * @tc.desc: normal function
393  * @tc.type: FUNC
394  */
395 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio2, Function | SmallTest | Level2)
396 {
397     SessionInfo info;
398     info.abilityName_ = "SetAspectRatio2";
399     info.bundleName_ = "SetAspectRatio2";
400     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
401     sceneSession->isActive_ = true;
402 
403     float ratio = 0.0001;
404     sceneSession->moveDragController_ = nullptr;
405     auto result = sceneSession->SetAspectRatio(ratio);
406     ASSERT_EQ(result, WSError::WS_OK);
407     ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
408 
409     sceneSession->moveDragController_ = sptr<MoveDragController>::MakeSptr(0, sceneSession->GetWindowType());
410     result = sceneSession->SetAspectRatio(ratio);
411     ASSERT_EQ(result, WSError::WS_OK);
412     ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
413 
414     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
415     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
416     sceneSession->SetSessionProperty(property);
417     result = sceneSession->SetAspectRatio(ratio);
418     ASSERT_EQ(result, WSError::WS_OK);
419     ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
420 }
421 
422 /**
423  * @tc.name: SetAspectRatio3
424  * @tc.desc: normal function
425  * @tc.type: FUNC
426  */
427 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio3, Function | SmallTest | Level2)
428 {
429     SessionInfo info;
430     info.abilityName_ = "SetAspectRatio3";
431     info.bundleName_ = "SetAspectRatio3";
432     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
433     sceneSession->isActive_ = true;
434 
435     float ratio = 0.1;
436     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
437     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
438     sceneSession->SetSessionProperty(property);
439     WindowLimits limits;
440     limits.maxHeight_ = 10;
441     limits.minWidth_ = 1;
442     limits.minHeight_ = 1;
443     property->SetWindowLimits(limits);
444     auto result = sceneSession->SetAspectRatio(ratio);
445     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
446 }
447 
448 /**
449  * @tc.name: SetAspectRatio4
450  * @tc.desc: normal function
451  * @tc.type: FUNC
452  */
453 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio4, Function | SmallTest | Level2)
454 {
455     SessionInfo info;
456     info.abilityName_ = "SetAspectRatio4";
457     info.bundleName_ = "SetAspectRatio4";
458     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
459     sceneSession->isActive_ = true;
460     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
461     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
462     sceneSession->SetSessionProperty(property);
463 
464     float ratio = 0.1;
465     WindowLimits limits;
466     limits.maxHeight_ = 10;
467     limits.minWidth_ = 10;
468     property->SetWindowLimits(limits);
469     auto result = sceneSession->SetAspectRatio(ratio);
470     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
471 }
472 
473 /**
474  * @tc.name: SetAspectRatio5
475  * @tc.desc: test for aspectRatio NearZero
476  * @tc.type: FUNC
477  */
478 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio5, Function | SmallTest | Level2)
479 {
480     SessionInfo info;
481     info.abilityName_ = "SetAspectRatio5";
482     info.bundleName_ = "SetAspectRatio5";
483     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
484     sceneSession->isActive_ = true;
485 
486     float ratio = 0.0001;
487     auto result = sceneSession->SetAspectRatio(ratio);
488     ASSERT_EQ(result, WSError::WS_OK);
489 
490     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
491     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
492     sceneSession->SetSessionProperty(property);
493     result = sceneSession->SetAspectRatio(ratio);
494     ASSERT_EQ(result, WSError::WS_OK);
495     ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
496 }
497 
498 /**
499  * @tc.name: SetAspectRatio6
500  * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight
501  * @tc.type: FUNC
502  */
503 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio6, Function | SmallTest | Level2)
504 {
505     SessionInfo info;
506     info.abilityName_ = "SetAspectRatio6";
507     info.bundleName_ = "SetAspectRatio6";
508     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
509     sceneSession->isActive_ = true;
510 
511     float ratio = 2.5;
512     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
513     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
514     WindowLimits limits;
515     limits.maxWidth_ = 3000;
516     limits.maxHeight_ = 3000;
517     limits.minWidth_ = 2000;
518     limits.minHeight_ = 2000;
519     property->SetWindowLimits(limits);
520     sceneSession->SetSessionProperty(property);
521     auto result = sceneSession->SetAspectRatio(ratio);
522     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
523 }
524 
525 /**
526  * @tc.name: SetAspectRatio7
527  * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight
528  * @tc.type: FUNC
529  */
530 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio7, Function | SmallTest | Level2)
531 {
532     SessionInfo info;
533     info.abilityName_ = "SetAspectRatio7";
534     info.bundleName_ = "SetAspectRatio7";
535     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
536     sceneSession->isActive_ = true;
537 
538     float ratio = 0.1;
539     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
540     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
541     WindowLimits limits;
542     limits.maxWidth_ = 3000;
543     limits.maxHeight_ = 3000;
544     limits.minWidth_ = 2000;
545     limits.minHeight_ = 2000;
546     property->SetWindowLimits(limits);
547     sceneSession->SetSessionProperty(property);
548     auto result = sceneSession->SetAspectRatio(ratio);
549     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
550 }
551 
552 /**
553  * @tc.name: SetAspectRatio8
554  * @tc.desc: normal function
555  * @tc.type: FUNC
556  */
557 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio8, Function | SmallTest | Level2)
558 {
559     SessionInfo info;
560     info.abilityName_ = "SetAspectRatio8";
561     info.bundleName_ = "SetAspectRatio8";
562     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
563     sceneSession->isActive_ = true;
564 
565     float ratio = 0.1;
566     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
567     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
568     WindowLimits limits;
569     limits.maxHeight_ = 10;
570     limits.minWidth_ = 0;
571     property->SetWindowLimits(limits);
572     sceneSession->SetSessionProperty(property);
573     auto result = sceneSession->SetAspectRatio(ratio);
574     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
575 }
576 
577 /**
578  * @tc.name: SetAspectRatio9
579  * @tc.desc: normal function
580  * @tc.type: FUNC
581  */
582 HWTEST_F(SceneSessionLayoutTest, SetAspectRatio9, Function | SmallTest | Level2)
583 {
584     SessionInfo info;
585     info.abilityName_ = "SetAspectRatio9";
586     info.bundleName_ = "SetAspectRatio9";
587     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
588     sceneSession->isActive_ = true;
589 
590     float ratio = 0.1;
591     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
592     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
593     WindowLimits limits;
594     limits.maxHeight_ = 10;
595     limits.minWidth_ = 10;
596     property->SetWindowLimits(limits);
597     sceneSession->SetSessionProperty(property);
598     auto result = sceneSession->SetAspectRatio(ratio);
599     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
600 }
601 
602 /**
603  * @tc.name: SaveAspectRatio
604  * @tc.desc: SaveAspectRatio
605  * @tc.type: FUNC
606  */
607 HWTEST_F(SceneSessionLayoutTest, SaveAspectRatio, Function | SmallTest | Level2)
608 {
609     SessionInfo info;
610     info.abilityName_ = "Background01";
611     info.bundleName_ = "IsFloatingWindowAppType";
612     info.windowType_ = 1;
613     sptr<SceneSession> sceneSession;
614     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
615     ASSERT_EQ(true, sceneSession->SaveAspectRatio(0.1));
616 
617     sceneSession->sessionInfo_.bundleName_ = "";
618     sceneSession->sessionInfo_.moduleName_ = "";
619     sceneSession->sessionInfo_.abilityName_ = "";
620     ASSERT_EQ(false, sceneSession->SaveAspectRatio(0.1));
621 }
622 
623 /**
624  * @tc.name: AdjustRectByAspectRatio
625  * @tc.desc: AdjustRectByAspectRatio
626  * @tc.type: FUNC
627  */
628 HWTEST_F(SceneSessionLayoutTest, AdjustRectByAspectRatio, Function | SmallTest | Level2)
629 {
630     SessionInfo info;
631     info.abilityName_ = "Background01";
632     info.bundleName_ = "IsFloatingWindowAppType";
633     info.windowType_ = 1;
634     sptr<SceneSession> sceneSession;
635     sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
636     WSRect originalRect = { 0, 0, 0, 0 };
637     ASSERT_EQ(false, sceneSession->AdjustRectByAspectRatio(originalRect));
638 }
639 
640 /**
641  * To test the function call
642  *
643  * @tc.name: ActivateDragBySystem
644  * @tc.desc: ActivateDragBySystem function
645  * @tc.type: FUNC
646  */
647 HWTEST_F(SceneSessionLayoutTest, ActivateDragBySystem, Function | SmallTest | Level2)
648 {
649     SessionInfo info;
650     info.abilityName_ = "ActivateDragBySystem";
651     info.bundleName_ = "ActivateDragBySystem";
652     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
653     auto ret = sceneSession->ActivateDragBySystem(true);
654     EXPECT_EQ(WMError::WM_OK, ret);
655 }
656 
657 /**
658  * To test the drag activated settings, and validate the draggable results.
659  * Expect the results:
660  * enableDrag: true, dragActivated: true => true
661  * enableDrag: false, dragActivated: true => false
662  * enableDrag: true, dragActivated: false => false
663  * enableDrag: false, dragActivated: false => false
664  *
665  * @tc.name: CheckDragActivatedSettings
666  * @tc.desc: CheckDragActivatedSettings
667  * @tc.type: FUNC
668  */
669 HWTEST_F(SceneSessionLayoutTest, CheckDragActivatedSettings, Function | SmallTest | Level2)
670 {
671     SessionInfo info;
672     info.abilityName_ = "CheckDragActivatedSettings";
673     info.bundleName_ = "CheckDragActivatedSettings";
674     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
675 
676     sceneSession->ActivateDragBySystem(true);
677     sceneSession->GetSessionProperty()->SetDragEnabled(true);
678     ASSERT_EQ(true, sceneSession->IsDragAccessible());
679 
680     sceneSession->GetSessionProperty()->SetDragEnabled(false);
681     ASSERT_EQ(false, sceneSession->IsDragAccessible());
682 
683     sceneSession->ActivateDragBySystem(false);
684     sceneSession->GetSessionProperty()->SetDragEnabled(true);
685     ASSERT_EQ(false, sceneSession->IsDragAccessible());
686 
687     sceneSession->GetSessionProperty()->SetDragEnabled(false);
688     ASSERT_EQ(false, sceneSession->IsDragAccessible());
689 }
690 
691 /**
692  * @tc.name: NotifySingleHandTransformChange
693  * @tc.desc: NotifySingleHandTransformChange
694  * @tc.type: FUNC
695  */
696 HWTEST_F(SceneSessionLayoutTest, NotifySingleHandTransformChange, Function | SmallTest | Level2)
697 {
698     SessionInfo info;
699     info.abilityName_ = "NotifySingleHandTransformChange";
700     info.bundleName_ = "NotifySingleHandTransformChange";
701     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
702 
703     SingleHandTransform testTransform;
704     sceneSession->state_ = SessionState::STATE_BACKGROUND;
705     sceneSession->NotifySingleHandTransformChange(testTransform);
706 
707     sceneSession->state_ = SessionState::STATE_FOREGROUND;
708     mockSessionStage_ = nullptr;
709     sceneSession->sessionStage_ = mockSessionStage_;
710     sceneSession->NotifySingleHandTransformChange(testTransform);
711 
712     mockSessionStage_ = sptr<SessionStageMocker>::MakeSptr();
713     sceneSession->sessionStage_ = mockSessionStage_;
714     sceneSession->NotifySingleHandTransformChange(testTransform);
715     ASSERT_NE(100, testTransform.posX);
716 }
717 
718 /**
719  * @tc.name: GetSessionGlobalRectWithSingleHandScale
720  * @tc.desc: GetSessionGlobalRectWithSingleHandScale
721  * @tc.type: FUNC
722  */
723 HWTEST_F(SceneSessionLayoutTest, GetSessionGlobalRectWithSingleHandScale, Function | SmallTest | Level2)
724 {
725     SessionInfo info;
726     info.abilityName_ = "GetSessionGlobalRectWithSingleHandScale";
727     info.bundleName_ = "GetSessionGlobalRectWithSingleHandScale";
728     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
729 
730     SingleHandTransform testTransform;
731     WSRect globalRect = { 100, 100, 800, 800 };
732     sceneSession->SetSessionGlobalRect(globalRect);
733     sceneSession->SetSingleHandTransform(testTransform);
734     ASSERT_EQ(sceneSession->GetSessionGlobalRect().posX_,
735               sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_);
736 
737     testTransform.posX = 10;
738     testTransform.posY = 10;
739     testTransform.scaleX = 0.75f;
740     testTransform.scaleY = 0.75f;
741     sceneSession->SetSingleHandTransform(testTransform);
742     ASSERT_NE(sceneSession->GetSessionGlobalRect().posX_,
743               sceneSession->GetSessionGlobalRectWithSingleHandScale().posX_);
744 }
745 } // namespace
746 } // Rosen
747 } // OHOS