• 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 "session/host/include/sub_session.h"
18 
19 #include "common/include/session_permission.h"
20 #include "key_event.h"
21 #include "mock/mock_session_stage.h"
22 #include "session/host/include/session.h"
23 #include "session/host/include/main_session.h"
24 #include "session/host/include/system_session.h"
25 #include <ui/rs_surface_node.h>
26 #include "window_event_channel_base.h"
27 #include "window_helper.h"
28 #include "window_manager_hilog.h"
29 #include "window_property.h"
30 #include "window_session_property.h"
31 #include "mock_sub_session.h"
32 
33 using namespace testing;
34 using namespace testing::ext;
35 
36 namespace OHOS {
37 namespace Rosen {
38 class SubSessionTest : public testing::Test {
39 public:
40     static void SetUpTestCase();
41     static void TearDownTestCase();
42     void SetUp() override;
43     void TearDown() override;
44     SessionInfo info;
45     sptr<SubSession::SpecificSessionCallback> specificCallback = nullptr;
46 
47 private:
48     RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
49     sptr<SubSession> subSession_;
50     SystemSessionConfig systemConfig_;
51 };
52 
SetUpTestCase()53 void SubSessionTest::SetUpTestCase() {}
54 
TearDownTestCase()55 void SubSessionTest::TearDownTestCase() {}
56 
SetUp()57 void SubSessionTest::SetUp()
58 {
59     SessionInfo info;
60     info.abilityName_ = "testMainSession1";
61     info.moduleName_ = "testMainSession2";
62     info.bundleName_ = "testMainSession3";
63     subSession_ = sptr<SubSession>::MakeSptr(info, specificCallback);
64     EXPECT_NE(nullptr, subSession_);
65 }
66 
TearDown()67 void SubSessionTest::TearDown()
68 {
69     subSession_ = nullptr;
70 }
71 
CreateRSSurfaceNode()72 RSSurfaceNode::SharedPtr SubSessionTest::CreateRSSurfaceNode()
73 {
74     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
75     rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
76     auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
77     return surfaceNode;
78 }
79 
80 namespace {
81 
82 /**
83  * @tc.name: TransferKeyEvent01
84  * @tc.desc: check func TransferKeyEvent
85  * @tc.type: FUNC
86  */
87 HWTEST_F(SubSessionTest, TransferKeyEvent01, TestSize.Level1)
88 {
89     subSession_->state_ = SessionState::STATE_END;
90 
91     ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, subSession_->TransferKeyEvent(nullptr));
92 }
93 
94 /**
95  * @tc.name: TransferKeyEvent02
96  * @tc.desc: check func TransferKeyEvent
97  * @tc.type: FUNC
98  */
99 HWTEST_F(SubSessionTest, TransferKeyEvent02, TestSize.Level1)
100 {
101     subSession_->state_ = SessionState::STATE_CONNECT;
102     std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
103 
104     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, subSession_->TransferKeyEvent(keyEvent));
105 }
106 
107 /**
108  * @tc.name: TransferKeyEvent03
109  * @tc.desc: check func TransferKeyEvent
110  * @tc.type: FUNC
111  */
112 HWTEST_F(SubSessionTest, TransferKeyEvent03, TestSize.Level1)
113 {
114     ASSERT_NE(subSession_, nullptr);
115     subSession_->state_ = SessionState::STATE_CONNECT;
116     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
117     ASSERT_NE(keyEvent, nullptr);
118     subSession_->SetParentSession(nullptr);
119     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, subSession_->TransferKeyEvent(keyEvent));
120 }
121 
122 /**
123  * @tc.name: TransferKeyEvent04
124  * @tc.desc: check func TransferKeyEvent
125  * @tc.type: FUNC
126  */
127 HWTEST_F(SubSessionTest, TransferKeyEvent04, TestSize.Level1)
128 {
129     SessionInfo sessionInfo;
130     sessionInfo.abilityName_ = "TransferKeyEvent04";
131     sessionInfo.moduleName_ = "TransferKeyEvent04";
132     sessionInfo.bundleName_ = "TransferKeyEvent04";
133     sptr<SubSession> session = sptr<SubSession>::MakeSptr(sessionInfo, specificCallback);
134     ASSERT_NE(session, nullptr);
135     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
136     ASSERT_NE(keyEvent, nullptr);
137 
138     subSession_->SetParentSession(session);
139     subSession_->SetSessionState(SessionState::STATE_ACTIVE);
140     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, subSession_->TransferKeyEvent(keyEvent));
141 }
142 
143 /**
144  * @tc.name: IsTopmost01
145  * @tc.desc: check func IsTopmost
146  * @tc.type: FUNC
147  */
148 HWTEST_F(SubSessionTest, IsTopmost01, TestSize.Level1)
149 {
150     subSession_->GetSessionProperty()->SetTopmost(false);
151     ASSERT_EQ(false, subSession_->IsTopmost());
152 
153     subSession_->GetSessionProperty()->SetTopmost(true);
154     ASSERT_EQ(true, subSession_->IsTopmost());
155 }
156 
157 /**
158  * @tc.name: IsTopmost02
159  * @tc.desc: check func IsTopmost
160  * @tc.type: FUNC
161  */
162 HWTEST_F(SubSessionTest, IsTopmost02, TestSize.Level1)
163 {
164     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
165     subSession_->SetSessionProperty(property);
166     ASSERT_TRUE(subSession_->GetSessionProperty() != nullptr);
167 
168     subSession_->GetSessionProperty()->SetTopmost(true);
169     ASSERT_EQ(true, subSession_->IsTopmost());
170 }
171 
172 /**
173  * @tc.name: CheckPointerEventDispatch01
174  * @tc.desc: check func CheckPointerEventDispatch
175  * @tc.type: FUNC
176  */
177 HWTEST_F(SubSessionTest, CheckPointerEventDispatch01, TestSize.Level1)
178 {
179     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
180     ASSERT_NE(nullptr, pointerEvent);
181     systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
182 
183     ASSERT_TRUE(subSession_ != nullptr);
184     auto result = subSession_->CheckPointerEventDispatch(pointerEvent);
185     ASSERT_TRUE(result);
186 }
187 
188 /**
189  * @tc.name: CheckPointerEventDispatch02
190  * @tc.desc: check func CheckPointerEventDispatch
191  * @tc.type: FUNC
192  */
193 HWTEST_F(SubSessionTest, CheckPointerEventDispatch02, TestSize.Level1)
194 {
195     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
196     ASSERT_NE(nullptr, pointerEvent);
197     systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
198 
199     ASSERT_TRUE(subSession_ != nullptr);
200     subSession_->SetSessionState(SessionState::STATE_FOREGROUND);
201     auto result = subSession_->CheckPointerEventDispatch(pointerEvent);
202     ASSERT_TRUE(result);
203 }
204 
205 /**
206  * @tc.name: CheckPointerEventDispatch03
207  * @tc.desc: check func CheckPointerEventDispatch
208  * @tc.type: FUNC
209  */
210 HWTEST_F(SubSessionTest, CheckPointerEventDispatch03, TestSize.Level1)
211 {
212     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
213     ASSERT_NE(nullptr, pointerEvent);
214     systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
215 
216     ASSERT_TRUE(subSession_ != nullptr);
217     subSession_->SetSessionState(SessionState::STATE_BACKGROUND);
218     subSession_->UpdateSessionState(SessionState::STATE_ACTIVE);
219     auto result = subSession_->CheckPointerEventDispatch(pointerEvent);
220     ASSERT_TRUE(result);
221 }
222 
223 /**
224  * @tc.name: CheckPointerEventDispatch04
225  * @tc.desc: check func CheckPointerEventDispatch
226  * @tc.type: FUNC
227  */
228 HWTEST_F(SubSessionTest, CheckPointerEventDispatch04, TestSize.Level1)
229 {
230     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
231     ASSERT_NE(nullptr, pointerEvent);
232     systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
233 
234     ASSERT_TRUE(subSession_ != nullptr);
235     subSession_->SetSessionState(SessionState::STATE_BACKGROUND);
236     subSession_->UpdateSessionState(SessionState::STATE_INACTIVE);
237     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
238     auto result = subSession_->CheckPointerEventDispatch(pointerEvent);
239     ASSERT_TRUE(result);
240 }
241 
242 /**
243  * @tc.name: CheckPointerEventDispatch05
244  * @tc.desc: check func CheckPointerEventDispatch
245  * @tc.type: FUNC
246  */
247 HWTEST_F(SubSessionTest, CheckPointerEventDispatch05, TestSize.Level1)
248 {
249     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
250     ASSERT_NE(nullptr, pointerEvent);
251     systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
252 
253     ASSERT_TRUE(subSession_ != nullptr);
254     subSession_->SetSessionState(SessionState::STATE_BACKGROUND);
255     subSession_->UpdateSessionState(SessionState::STATE_INACTIVE);
256     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
257     auto result = subSession_->CheckPointerEventDispatch(pointerEvent);
258     ASSERT_TRUE(result);
259 }
260 
261 /**
262  * @tc.name: IsModal01
263  * @tc.desc: check func IsModal
264  * @tc.type: FUNC
265  */
266 HWTEST_F(SubSessionTest, IsModal, TestSize.Level1)
267 {
268     ASSERT_FALSE(subSession_->IsModal());
269 }
270 
271 /**
272  * @tc.name: IsVisibleForeground01
273  * @tc.desc: check func IsVisibleForeground
274  * @tc.type: FUNC
275  */
276 HWTEST_F(SubSessionTest, IsVisibleForeground01, TestSize.Level1)
277 {
278     ASSERT_FALSE(subSession_->IsVisibleForeground());
279 
280     SessionInfo info;
281     info.abilityName_ = "testMainSession1";
282     info.moduleName_ = "testMainSession2";
283     info.bundleName_ = "testMainSession3";
284     auto parentSession = sptr<SubSession>::MakeSptr(info, specificCallback);
285 
286     subSession_->SetParentSession(parentSession);
287     ASSERT_FALSE(subSession_->IsVisibleForeground());
288 }
289 
290 /**
291  * @tc.name: RectCheck
292  * @tc.desc: test function : RectCheck
293  * @tc.type: FUNC
294  */
295 HWTEST_F(SubSessionTest, RectCheck, TestSize.Level1)
296 {
297     ASSERT_NE(subSession_, nullptr);
298     SessionInfo info;
299     info.abilityName_ = "testRectCheck";
300     info.moduleName_ = "testRectCheck";
301     info.bundleName_ = "testRectCheck";
302     sptr<Session> session = sptr<Session>::MakeSptr(info);
303     EXPECT_NE(nullptr, session);
304     subSession_->parentSession_ = session;
305     uint32_t curWidth = 100;
306     uint32_t curHeight = 200;
307     subSession_->RectCheck(curWidth, curHeight);
308 
309     curWidth = 300;
310     curHeight = 200;
311     subSession_->RectCheck(curWidth, curHeight);
312 
313     curWidth = 1930;
314     curHeight = 200;
315     subSession_->RectCheck(curWidth, curHeight);
316 
317     curWidth = 330;
318     curHeight = 200;
319     subSession_->RectCheck(curWidth, curHeight);
320 
321     curWidth = 330;
322     curHeight = 1930;
323     subSession_->RectCheck(curWidth, curHeight);
324 }
325 
326 /**
327  * @tc.name: IsModal
328  * @tc.desc: IsModal function01
329  * @tc.type: FUNC
330  */
331 HWTEST_F(SubSessionTest, IsModal01, TestSize.Level1)
332 {
333     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
334     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
335     property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL);
336     EXPECT_EQ(subSession_->IsModal(), false);
337     subSession_->SetSessionProperty(property);
338     EXPECT_EQ(subSession_->IsModal(), true);
339 }
340 
341 /**
342  * @tc.name: IsApplicationModal
343  * @tc.desc: IsApplicationModal function01
344  * @tc.type: FUNC
345  */
346 HWTEST_F(SubSessionTest, IsApplicationModal, TestSize.Level1)
347 {
348     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
349     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
350     property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL);
351     property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL);
352     EXPECT_EQ(subSession_->IsApplicationModal(), false);
353     subSession_->SetSessionProperty(property);
354     EXPECT_EQ(subSession_->IsApplicationModal(), true);
355 }
356 
357 /**
358  * @tc.name: NotifySessionRectChange
359  * @tc.desc: NotifySessionRectChange function01
360  * @tc.type: FUNC
361  */
362 HWTEST_F(SubSessionTest, NotifySessionRectChange01, TestSize.Level1)
363 {
364     subSession_->shouldFollowParentWhenShow_ = true;
365     WSRect rect;
366     subSession_->NotifySessionRectChange(rect, SizeChangeReason::UNDEFINED, DISPLAY_ID_INVALID);
367     ASSERT_EQ(subSession_->shouldFollowParentWhenShow_, true);
368     subSession_->NotifySessionRectChange(rect, SizeChangeReason::DRAG_END, DISPLAY_ID_INVALID);
369     ASSERT_EQ(subSession_->shouldFollowParentWhenShow_, false);
370 }
371 
372 /**
373  * @tc.name: UpdateSessionRectInner
374  * @tc.desc: UpdateSessionRectInner function01
375  * @tc.type: FUNC
376  */
377 HWTEST_F(SubSessionTest, UpdateSessionRectInner01, TestSize.Level1)
378 {
379     subSession_->shouldFollowParentWhenShow_ = true;
380     WSRect rect;
381     MoveConfiguration config;
382     config.displayId = DISPLAY_ID_INVALID;
383     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::UNDEFINED, config);
384     ASSERT_EQ(subSession_->shouldFollowParentWhenShow_, true);
385     config.displayId = 123;
386     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::DRAG_END, config);
387     ASSERT_EQ(subSession_->shouldFollowParentWhenShow_, false);
388 }
389 
390 /**
391  * @tc.name: IsVisibleForeground
392  * @tc.desc: IsVisibleForeground Test
393  * @tc.type: FUNC
394  */
395 HWTEST_F(SubSessionTest, IsVisibleForeground, TestSize.Level1)
396 {
397     systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
398     subSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
399     EXPECT_EQ(subSession_->IsVisibleForeground(), false);
400     subSession_->SetSessionState(SessionState::STATE_FOREGROUND);
401     EXPECT_EQ(subSession_->IsVisibleForeground(), false);
402     subSession_->isVisible_ = true;
403     EXPECT_EQ(subSession_->IsVisibleForeground(), true);
404 
405     SessionInfo info;
406     info.abilityName_ = "IsVisibleForeground";
407     info.moduleName_ = "IsVisibleForeground";
408     info.bundleName_ = "IsVisibleForeground";
409     sptr<Session> parentSession = sptr<Session>::MakeSptr(info);
410     parentSession->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
411     subSession_->SetParentSession(parentSession);
412     EXPECT_EQ(subSession_->IsVisibleForeground(), false);
413     parentSession->SetSessionState(SessionState::STATE_FOREGROUND);
414     EXPECT_EQ(subSession_->IsVisibleForeground(), false);
415     parentSession->isVisible_ = true;
416     EXPECT_EQ(subSession_->IsVisibleForeground(), true);
417 }
418 
419 /**
420  * @tc.name: SetParentSessionCallback
421  * @tc.desc: SetParentSessionCallback
422  * @tc.type: FUNC
423  */
424 HWTEST_F(SubSessionTest, SetParentSessionCallback, TestSize.Level1)
425 {
426     SessionInfo info;
427     info.abilityName_ = "SetParentSessionCallback";
428     info.bundleName_ = "SetParentSessionCallback";
429     sptr<SubSession> subSession = sptr<SubSession>::MakeSptr(info, nullptr);
430     subSession->SetParentSessionCallback(nullptr);
431     EXPECT_EQ(subSession->setParentSessionFunc_, nullptr);
432 
__anon451c67a80202(int32_t oldParentWindowId, int32_t newParentWindowId) 433     NotifySetParentSessionFunc func = [](int32_t oldParentWindowId, int32_t newParentWindowId) { return; };
434     subSession->SetParentSessionCallback(std::move(func));
435     EXPECT_NE(subSession->setParentSessionFunc_, nullptr);
436 }
437 
438 /**
439  * @tc.name: NotifySetParentSession
440  * @tc.desc: NotifySetParentSession
441  * @tc.type: FUNC
442  */
443 HWTEST_F(SubSessionTest, NotifySetParentSession, TestSize.Level1)
444 {
445     SessionInfo info;
446     info.abilityName_ = "NotifySetParentSession";
447     info.bundleName_ = "NotifySetParentSession";
448     sptr<SubSession> subSession = sptr<SubSession>::MakeSptr(info, nullptr);
449     int32_t oldParentWindowId = 1;
450     int32_t newParentWindowId = 2;
451     auto res = subSession->NotifySetParentSession(oldParentWindowId, newParentWindowId);
452     EXPECT_EQ(res, WMError::WM_OK);
453 
__anon451c67a80302(int32_t oldParentWindowId, int32_t newParentWindowId) 454     NotifySetParentSessionFunc func = [](int32_t oldParentWindowId, int32_t newParentWindowId) { return; };
455     subSession->SetParentSessionCallback(std::move(func));
456     res = subSession->NotifySetParentSession(oldParentWindowId, newParentWindowId);
457     EXPECT_EQ(res, WMError::WM_OK);
458 }
459 
460 /**
461  * @tc.name: NotifyFollowParentMultiScreenPolicy
462  * @tc.desc: NotifyFollowParentMultiScreenPolicy
463  * @tc.type: FUNC
464  */
465 HWTEST_F(SubSessionTest, NotifyFollowParentMultiScreenPolicy, TestSize.Level1)
466 {
467     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
468     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
469     subSession_->SetSessionProperty(property);
470     EXPECT_EQ(subSession_->NotifyFollowParentMultiScreenPolicy(true), WSError::WS_OK);
471     EXPECT_EQ(subSession_->NotifyFollowParentMultiScreenPolicy(false), WSError::WS_OK);
472 }
473 
474 /**
475  * @tc.name: IsFollowParentMultiScreenPolicy
476  * @tc.desc: IsFollowParentMultiScreenPolicy
477  * @tc.type: FUNC
478  */
479 HWTEST_F(SubSessionTest, IsFollowParentMultiScreenPolicy, TestSize.Level1)
480 {
481     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
482     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
483     subSession_->SetSessionProperty(property);
484     EXPECT_EQ(subSession_->IsFollowParentMultiScreenPolicy(), false);
485     EXPECT_EQ(subSession_->NotifyFollowParentMultiScreenPolicy(true), WSError::WS_OK);
486     EXPECT_EQ(subSession_->IsFollowParentMultiScreenPolicy(), true);
487     EXPECT_EQ(subSession_->NotifyFollowParentMultiScreenPolicy(false), WSError::WS_OK);
488     EXPECT_EQ(subSession_->IsFollowParentMultiScreenPolicy(), false);
489 }
490 
491 /**
492  * @tc.name: UpdateSessionRectInner02
493  * @tc.desc: UpdateSessionRectInner Test
494  * @tc.type: FUNC
495  */
496 HWTEST_F(SubSessionTest, UpdateSessionRectInner02, TestSize.Level1)
497 {
498     subSession_->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
499     SessionInfo info;
500     info.abilityName_ = "UpdateSessionRectInner02";
501     info.bundleName_ = "UpdateSessionRectInner02";
502     sptr<SceneSession> parentSession = sptr<SceneSession>::MakeSptr(info, nullptr);
503     parentSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
504     parentSession->moveDragController_ =
505         sptr<MoveDragController>::MakeSptr(parentSession->GetPersistentId(), parentSession->GetWindowType());
506     parentSession->subSession_.emplace_back(subSession_);
507     subSession_->SetParentSession(parentSession);
508 
509     parentSession->moveDragController_->isStartMove_ = false;
510     parentSession->moveDragController_->isStartDrag_ = false;
511     WSRect defaultRect;
512     WSRect rect = { 50, 50, 800, 800 };
513     MoveConfiguration config;
514     config.displayId = DISPLAY_ID_INVALID;
515     subSession_->NotifyFollowParentMultiScreenPolicy(true);
516     parentSession->moveDragController_->isStartMove_ = true;
517     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::MOVE, config);
518     ASSERT_EQ(50, subSession_->GetRequestRectWhenFollowParent().posX_);
519     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::RESIZE, config);
520     ASSERT_EQ(800, subSession_->GetRequestRectWhenFollowParent().width_);
521 
522     subSession_->SetRequestRectWhenFollowParent(defaultRect);
523     parentSession->moveDragController_->isStartMove_ = false;
524     parentSession->moveDragController_->isStartDrag_ = true;
525     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::MOVE, config);
526     ASSERT_EQ(50, subSession_->GetRequestRectWhenFollowParent().posX_);
527     rect.width_ = 0;
528     rect.height_ = 0;
529     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::RESIZE, config);
530     ASSERT_NE(0, subSession_->GetRequestRectWhenFollowParent().width_);
531 }
532 
533 /**
534  * @tc.name: UpdateSessionRectInner03
535  * @tc.desc: UpdateSessionRectInner Test
536  * @tc.type: FUNC
537  */
538 HWTEST_F(SubSessionTest, UpdateSessionRectInner03, TestSize.Level1)
539 {
540     MoveConfiguration config;
541     WSRect rect = { 1, 1, 1, 1 };
542     subSession_->GetLayoutController()->SetSessionRect({ 0, 0, 0, 0 });
543 
544     subSession_->isSubWindowResizingOrMoving_ = false;
545     subSession_->SetSessionState(SessionState::STATE_BACKGROUND);
546     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::MOVE, config);
547     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, false);
548 
549     subSession_->SetSessionState(SessionState::STATE_FOREGROUND);
550     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::UNDEFINED, config);
551     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, false);
552 
553     subSession_->isSubWindowResizingOrMoving_ = false;
554     subSession_->GetLayoutController()->SetSessionRect({ 0, 0, 0, 0 });
555     rect = { 0, 0, 0, 0 };
556     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::MOVE, config);
557     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, false);
558 
559     subSession_->isSubWindowResizingOrMoving_ = false;
560     subSession_->GetLayoutController()->SetSessionRect({ 0, 0, 0, 0 });
561     rect = { 1, 0, 0, 0 };
562     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::MOVE, config);
563     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, true);
564 
565     subSession_->isSubWindowResizingOrMoving_ = false;
566     subSession_->GetLayoutController()->SetSessionRect({ 0, 0, 0, 0 });
567     rect = { 0, 1, 0, 0 };
568     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::MOVE, config);
569     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, true);
570 
571     subSession_->isSubWindowResizingOrMoving_ = false;
572     subSession_->GetLayoutController()->SetSessionRect({ 0, 0, 0, 0 });
573     rect = { 0, 0, 0, 0 };
574     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::RESIZE, config);
575     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, false);
576 
577     subSession_->isSubWindowResizingOrMoving_ = false;
578     subSession_->GetLayoutController()->SetSessionRect({ 0, 0, 0, 0 });
579     rect = { 0, 0, 1, 0 };
580     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::RESIZE, config);
581     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, true);
582 
583     subSession_->isSubWindowResizingOrMoving_ = false;
584     subSession_->GetLayoutController()->SetSessionRect({ 0, 0, 0, 0 });
585     rect = { 0, 0, 0, 1 };
586     subSession_->UpdateSessionRectInner(rect, SizeChangeReason::RESIZE, config);
587     ASSERT_EQ(subSession_->isSubWindowResizingOrMoving_, true);
588 }
589 
590 /**
591  * @tc.name: HandleCrossMoveToSurfaceNode
592  * @tc.desc: HandleCrossMoveToSurfaceNode
593  * @tc.type: FUNC
594  */
595 HWTEST_F(SubSessionTest, HandleCrossMoveToSurfaceNode, TestSize.Level1)
596 {
597     SessionInfo info;
598     info.abilityName_ = "HandleCrossMoveToSurfaceNode";
599     info.bundleName_ = "HandleCrossMoveToSurfaceNode";
600     sptr<SubSession> sceneSession = sptr<SubSession>::MakeSptr(info, nullptr);
601     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
602     sceneSession->displayIdSetDuringMoveTo_.insert(0);
603     WSRect rect = { 50, 50, 800, 800 };
604     sceneSession->HandleCrossMoveToSurfaceNode(rect);
605     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
606     rsSurfaceNodeConfig.SurfaceNodeName = info.abilityName_;
607     RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT;
608     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType);
609     ASSERT_NE(surfaceNode, nullptr);
610     sceneSession->SetSurfaceNode(surfaceNode);
611     sceneSession->HandleCrossMoveToSurfaceNode(rect);
612     ASSERT_NE(0, sceneSession->displayIdSetDuringMoveTo_.size());
613 }
614 
615 /**
616  * @tc.name: AddSurfaceNodeToScreen
617  * @tc.desc: AddSurfaceNodeToScreen
618  * @tc.type: FUNC
619  */
620 HWTEST_F(SubSessionTest, AddSurfaceNodeToScreen, TestSize.Level1)
621 {
622     SessionInfo info;
623     info.abilityName_ = "AddSurfaceNodeToScreen";
624     info.bundleName_ = "AddSurfaceNodeToScreen";
625     sptr<SubSession> sceneSession = sptr<SubSession>::MakeSptr(info, nullptr);
626     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
627     sceneSession->moveDragController_ =
628         sptr<MoveDragController>::MakeSptr(sceneSession->GetPersistentId(), sceneSession->GetWindowType());
629     sceneSession->AddSurfaceNodeToScreen(0);
630     EXPECT_EQ(0, sceneSession->displayIdSetDuringMoveTo_.size());
631     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
632     rsSurfaceNodeConfig.SurfaceNodeName = info.abilityName_;
633     RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT;
634     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType);
635     ASSERT_NE(surfaceNode, nullptr);
636     sceneSession->SetSurfaceNode(surfaceNode);
637     sceneSession->AddSurfaceNodeToScreen(0);
638     EXPECT_EQ(0, sceneSession->displayIdSetDuringMoveTo_.size());
639 
640     sceneSession->SetScreenId(0);
641     sceneSession->AddSurfaceNodeToScreen(0);
642     EXPECT_EQ(0, sceneSession->displayIdSetDuringMoveTo_.size());
643 }
644 
645 /**
646  * @tc.name: RemoveSurfaceNodeFromScreen
647  * @tc.desc: RemoveSurfaceNodeFromScreen
648  * @tc.type: FUNC
649  */
650 HWTEST_F(SubSessionTest, RemoveSurfaceNodeFromScreen, TestSize.Level1)
651 {
652     SessionInfo info;
653     info.abilityName_ = "RemoveSurfaceNodeFromScreen";
654     info.bundleName_ = "RemoveSurfaceNodeFromScreen";
655     sptr<SubSession> sceneSession = sptr<SubSession>::MakeSptr(info, nullptr);
656     sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
657     sceneSession->RemoveSurfaceNodeFromScreen();
658     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
659     rsSurfaceNodeConfig.SurfaceNodeName = info.abilityName_;
660     RSSurfaceNodeType rsSurfaceNodeType = RSSurfaceNodeType::DEFAULT;
661     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig, rsSurfaceNodeType);
662     ASSERT_NE(surfaceNode, nullptr);
663     sceneSession->SetSurfaceNode(surfaceNode);
664     sceneSession->displayIdSetDuringMoveTo_.insert(0);
665     sceneSession->displayIdSetDuringMoveTo_.insert(888);
666     sceneSession->RemoveSurfaceNodeFromScreen();
667     EXPECT_EQ(0, sceneSession->cloneNodeCount_);
668 }
669 
670 /**
671  * @tc.name: SetSubWindowZLevel
672  * @tc.desc: SetSubWindowZLevel
673  * @tc.type: FUNC
674  */
675 HWTEST_F(SubSessionTest, SetSubWindowZLevel, TestSize.Level1)
676 {
677     SessionInfo info;
678     info.abilityName_ = "SetSubWindowZLevel";
679     info.bundleName_ = "SetSubWindowZLevel";
680     sptr<SubSession> subSession = sptr<SubSession>::MakeSptr(info, nullptr);
681     int32_t testZLevel = 0;
__anon451c67a80402(int32_t zLevel) 682     subSession->onSubSessionZLevelChange_ = [&testZLevel](int32_t zLevel) { testZLevel = zLevel; };
683     subSession->property_->zLevel_ = 0;
684     WSError ret = subSession->SetSubWindowZLevel(1);
685     EXPECT_EQ(1, subSession->property_->zLevel_);
686     EXPECT_EQ(1, testZLevel);
687     EXPECT_EQ(ret, WSError::WS_OK);
688 }
689 
690 /**
691  * @tc.name: GetSubWindowZLevel
692  * @tc.desc: GetSubWindowZLevel
693  * @tc.type: FUNC
694  */
695 HWTEST_F(SubSessionTest, GetSubWindowZLevel, TestSize.Level1)
696 {
697     SessionInfo info;
698     info.abilityName_ = "GetSubWindowZLevel";
699     info.bundleName_ = "GetSubWindowZLevel";
700     sptr<SubSession> subSession = sptr<SubSession>::MakeSptr(info, nullptr);
701     subSession->property_->zLevel_ = 1;
702     EXPECT_EQ(1, subSession->GetSubWindowZLevel());
703 }
704 } // namespace
705 } // namespace Rosen
706 } // namespace OHOS