• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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/system_session.h"
18 
19 #include "common/include/session_permission.h"
20 #include "key_event.h"
21 #include "mock/mock_accesstoken_kit.h"
22 #include "mock/mock_session.h"
23 #include "mock/mock_session_stage.h"
24 #include "session/host/include/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 "pointer_event.h"
30 
31 using namespace testing;
32 using namespace testing::ext;
33 
34 namespace OHOS {
35 namespace Rosen {
36 constexpr int WAIT_ASYNC_US = 1000000;
37 class SystemSessionTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp() override;
42     void TearDown() override;
43     SessionInfo info;
44     sptr<SystemSession::SpecificSessionCallback> specificCallback = nullptr;
45     sptr<SystemSession> systemSession_;
46 
47 private:
48     RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
49     sptr<SystemSession> GetSystemSession(const std::string& name);
50     sptr<SceneSession> GetSceneSession(const std::string& name);
51 };
52 
SetUpTestCase()53 void SystemSessionTest::SetUpTestCase() {}
54 
TearDownTestCase()55 void SystemSessionTest::TearDownTestCase() {}
56 
SetUp()57 void SystemSessionTest::SetUp()
58 {
59     SessionInfo info;
60     info.abilityName_ = "testSystemSession1";
61     info.moduleName_ = "testSystemSession2";
62     info.bundleName_ = "testSystemSession3";
63     systemSession_ = sptr<SystemSession>::MakeSptr(info, specificCallback);
64     EXPECT_NE(nullptr, systemSession_);
65 }
66 
TearDown()67 void SystemSessionTest::TearDown()
68 {
69     systemSession_ = nullptr;
70 }
71 
CreateRSSurfaceNode()72 RSSurfaceNode::SharedPtr SystemSessionTest::CreateRSSurfaceNode()
73 {
74     struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
75     rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
76     auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
77     return surfaceNode;
78 }
79 
GetSystemSession(const std::string & name)80 sptr<SystemSession> SystemSessionTest::GetSystemSession(const std::string& name)
81 {
82     SessionInfo info;
83     info.abilityName_ = name;
84     info.moduleName_ = name;
85     info.bundleName_ = name;
86     auto sysSession = sptr<SystemSession>::MakeSptr(info, nullptr);
87     return sysSession;
88 }
89 
GetSceneSession(const std::string & name)90 sptr<SceneSession> SystemSessionTest::GetSceneSession(const std::string& name)
91 {
92     SessionInfo info;
93     info.abilityName_ = name;
94     info.moduleName_ = name;
95     info.bundleName_ = name;
96     auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
97     return sceneSession;
98 }
99 
100 namespace {
101 
102 /**
103  * @tc.name: TransferKeyEvent01
104  * @tc.desc: check func TransferKeyEvent
105  * @tc.type: FUNC
106  */
107 HWTEST_F(SystemSessionTest, TransferKeyEvent01, TestSize.Level1)
108 {
109     systemSession_->state_ = SessionState::STATE_END;
110 
111     ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, systemSession_->TransferKeyEvent(nullptr));
112 }
113 
114 /**
115  * @tc.name: TransferKeyEvent02
116  * @tc.desc: check func TransferKeyEvent
117  * @tc.type: FUNC
118  */
119 HWTEST_F(SystemSessionTest, TransferKeyEvent02, TestSize.Level1)
120 {
121     systemSession_->state_ = SessionState::STATE_CONNECT;
122     std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
123 
124     ASSERT_EQ(WSError::WS_ERROR_NULLPTR, systemSession_->TransferKeyEvent(keyEvent));
125 }
126 
127 /**
128  * @tc.name: ProcessBackEvent01
129  * @tc.desc: check func ProcessBackEvent
130  * @tc.type: FUNC
131  */
132 HWTEST_F(SystemSessionTest, ProcessBackEvent01, TestSize.Level1)
133 {
134     systemSession_->state_ = SessionState::STATE_END;
135 
136     ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, systemSession_->ProcessBackEvent());
137 }
138 
139 /**
140  * @tc.name: NotifyClientToUpdateRect01
141  * @tc.desc: check func NotifyClientToUpdateRect
142  * @tc.type: FUNC
143  */
144 HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect01, TestSize.Level1)
145 {
146     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
147     ASSERT_NE(mockSessionStage, nullptr);
148     systemSession_->sessionStage_ = mockSessionStage;
149     auto ret = systemSession_->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
150     ASSERT_EQ(WSError::WS_OK, ret);
151 }
152 
153 /**
154  * @tc.name: CheckPointerEventDispatch
155  * @tc.desc: check func CheckPointerEventDispatch
156  * @tc.type: FUNC
157  */
158 HWTEST_F(SystemSessionTest, CheckPointerEventDispatch, TestSize.Level1)
159 {
160     std::shared_ptr<MMI::PointerEvent> pointerEvent_ = MMI::PointerEvent::Create();
161     SessionInfo info;
162     info.abilityName_ = "CheckPointerEventDispatch";
163     info.bundleName_ = "CheckPointerEventDispatchBundleName";
164     info.windowType_ = 2122;
165     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
166         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
167     sptr<SystemSession> sysSession = sptr<SystemSession>::MakeSptr(info, specificCallback_);
168     sysSession->SetSessionState(SessionState::STATE_FOREGROUND);
169     bool ret1 = sysSession->CheckPointerEventDispatch(pointerEvent_);
170     ASSERT_EQ(true, ret1);
171 }
172 
173 /**
174  * @tc.name: UpdatePointerArea
175  * @tc.desc: check func UpdatePointerArea
176  * @tc.type: FUNC
177  */
178 HWTEST_F(SystemSessionTest, UpdatePointerArea, TestSize.Level1)
179 {
180     WSRect rect = { 1, 1, 1, 1 };
181     SessionInfo info;
182     info.abilityName_ = "UpdatePointerArea";
183     info.bundleName_ = "UpdatePointerAreaBundleName";
184     info.windowType_ = 2122;
185     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
186         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
187     sptr<SystemSession> sysSession = sptr<SystemSession>::MakeSptr(info, specificCallback_);
188     sysSession->UpdatePointerArea(rect);
189     ASSERT_NE(sysSession->preRect_, rect);
190 
191     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
192     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
193     property->SetDecorEnable(true);
194     sysSession->property_ = property;
195     sysSession->UpdatePointerArea(rect);
196     ASSERT_EQ(sysSession->preRect_, rect);
197 }
198 
199 /**
200  * @tc.name: ProcessPointDownSession
201  * @tc.desc: test function : ProcessPointDownSession
202  * @tc.type: FUNC
203  */
204 HWTEST_F(SystemSessionTest, ProcessPointDownSession, TestSize.Level1)
205 {
206     ASSERT_TRUE(systemSession_ != nullptr);
207 
208     int32_t posX = 2;
209     int32_t posY = 3;
210     auto ret = systemSession_->ProcessPointDownSession(posX, posY);
211     ASSERT_EQ(WSError::WS_OK, ret);
212 }
213 
214 /**
215  * @tc.name: GetMissionId
216  * @tc.desc: test function : GetMissionId
217  * @tc.type: FUNC
218  */
219 HWTEST_F(SystemSessionTest, GetMissionId, TestSize.Level1)
220 {
221     ASSERT_TRUE(systemSession_ != nullptr);
222     SessionInfo info;
223     info.abilityName_ = "testSystemSession1";
224     info.moduleName_ = "testSystemSession2";
225     info.bundleName_ = "testSystemSession3";
226     sptr<Session> session = sptr<Session>::MakeSptr(info);
227     systemSession_->parentSession_ = session;
228     auto ret = systemSession_->GetMissionId();
229     ASSERT_EQ(0, ret);
230 }
231 
232 /**
233  * @tc.name: RectCheck
234  * @tc.desc: test function : RectCheck
235  * @tc.type: FUNC
236  */
237 HWTEST_F(SystemSessionTest, RectCheck, TestSize.Level1)
238 {
239     ASSERT_TRUE(systemSession_ != nullptr);
240     SessionInfo info;
241     info.abilityName_ = "testRectCheck";
242     info.moduleName_ = "testRectCheck";
243     info.bundleName_ = "testRectCheck";
244     sptr<Session> session = sptr<Session>::MakeSptr(info);
245     EXPECT_NE(nullptr, session);
246     systemSession_->parentSession_ = session;
247     uint32_t curWidth = 100;
248     uint32_t curHeight = 200;
249     systemSession_->RectCheck(curWidth, curHeight);
250 
251     curWidth = 0;
252     curHeight = 0;
253     systemSession_->RectCheck(curWidth, curHeight);
254 
255     curWidth = 1930;
256     curHeight = 0;
257     systemSession_->RectCheck(curWidth, curHeight);
258 
259     curWidth = 330;
260     curHeight = 0;
261     systemSession_->RectCheck(curWidth, curHeight);
262 
263     curWidth = 330;
264     curHeight = 1930;
265     systemSession_->RectCheck(curWidth, curHeight);
266 }
267 
268 /**
269  * @tc.name: SetDialogSessionBackGestureEnabled01
270  * @tc.desc: test function : SetDialogSessionBackGestureEnabled
271  * @tc.type: FUNC
272  */
273 HWTEST_F(SystemSessionTest, SetDialogSessionBackGestureEnabled01, TestSize.Level1)
274 {
275     ASSERT_TRUE(systemSession_ != nullptr);
276     SessionInfo info;
277     info.abilityName_ = "SetDialogSessionBackGestureEnabled";
278     info.moduleName_ = "SetDialogSessionBackGestureEnabled";
279     info.bundleName_ = "SetDialogSessionBackGestureEnabled";
280     sptr<Session> session = sptr<Session>::MakeSptr(info);
281     EXPECT_NE(nullptr, session);
282 
283     systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
284     auto ret = systemSession_->SetDialogSessionBackGestureEnabled(true);
285     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_CALLING);
286 }
287 
288 /**
289  * @tc.name: SetDialogSessionBackGestureEnabled02
290  * @tc.desc: test function : SetDialogSessionBackGestureEnabled
291  * @tc.type: FUNC
292  */
293 HWTEST_F(SystemSessionTest, SetDialogSessionBackGestureEnabled02, TestSize.Level1)
294 {
295     ASSERT_TRUE(systemSession_ != nullptr);
296     SessionInfo info;
297     info.abilityName_ = "SetDialogSessionBackGestureEnabled02";
298     info.moduleName_ = "SetDialogSessionBackGestureEnabled02";
299     info.bundleName_ = "SetDialogSessionBackGestureEnabled02";
300     sptr<Session> session = sptr<Session>::MakeSptr(info);
301     EXPECT_NE(nullptr, session);
302 
303     systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
304     auto ret = systemSession_->SetDialogSessionBackGestureEnabled(true);
305     ASSERT_EQ(ret, WSError::WS_OK);
306 }
307 
308 /**
309  * @tc.name: UpdateCameraWindowStatus01
310  * @tc.desc: test function : UpdateCameraWindowStatus
311  * @tc.type: FUNC
312  */
313 HWTEST_F(SystemSessionTest, UpdateCameraWindowStatus01, TestSize.Level1)
314 {
315     sptr<SceneSession::SpecificSessionCallback> specificCallback =
316         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
317     ASSERT_NE(specificCallback, nullptr);
318     bool result = false;
319 
320     systemSession_->UpdateCameraWindowStatus(true);
321     ASSERT_EQ(result, false);
322 
323     systemSession_->specificCallback_ = specificCallback;
324     systemSession_->UpdateCameraWindowStatus(true);
325     ASSERT_EQ(result, false);
326 
327     systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
328     systemSession_->UpdateCameraWindowStatus(true);
329     ASSERT_EQ(result, false);
330 
__anone543d0430202(uint32_t accessTokenId, bool isShowing) 331     systemSession_->specificCallback_->onCameraFloatSessionChange_ = [&result](uint32_t accessTokenId, bool isShowing) {
332         result = isShowing;
333     };
334     systemSession_->UpdateCameraWindowStatus(true);
335     ASSERT_EQ(result, true);
336 }
337 
338 /**
339  * @tc.name: UpdateCameraWindowStatus02
340  * @tc.desc: test function : UpdateCameraWindowStatus
341  * @tc.type: FUNC
342  */
343 HWTEST_F(SystemSessionTest, UpdateCameraWindowStatus02, TestSize.Level1)
344 {
345     auto sysSession = GetSystemSession("UpdateCameraWindowStatus02");
346     ASSERT_NE(sysSession, nullptr);
347     sptr<SceneSession::SpecificSessionCallback> specificCallback =
348         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
349     ASSERT_NE(specificCallback, nullptr);
350     bool result = false;
351     sysSession->specificCallback_ = specificCallback;
352 
353     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP);
354     sysSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
355     sysSession->UpdateCameraWindowStatus(true);
356     ASSERT_EQ(result, false);
357 
__anone543d0430302(uint32_t accessTokenId, bool isShowing) 358     sysSession->specificCallback_->onCameraSessionChange_ = [&result](uint32_t accessTokenId, bool isShowing) {
359         result = isShowing;
360     };
361 
362     result = false;
363     sysSession->pipTemplateInfo_.pipTemplateType = static_cast<uint32_t>(PiPTemplateType::VIDEO_CALL);
364     sysSession->UpdateCameraWindowStatus(true);
365     ASSERT_EQ(result, true);
366 
367     result = false;
368     sysSession->pipTemplateInfo_.pipTemplateType = static_cast<uint32_t>(PiPTemplateType::VIDEO_MEETING);
369     sysSession->UpdateCameraWindowStatus(true);
370     ASSERT_EQ(result, true);
371 
372     result = false;
373     sysSession->pipTemplateInfo_.pipTemplateType = static_cast<uint32_t>(PiPTemplateType::VIDEO_LIVE);
374     sysSession->UpdateCameraWindowStatus(true);
375     ASSERT_EQ(result, false);
376 }
377 
378 /**
379  * @tc.name: Show01
380  * @tc.desc: test function : Show
381  * @tc.type: FUNC
382  */
383 HWTEST_F(SystemSessionTest, Show01, TestSize.Level1)
384 {
385     // for CheckPermissionWithPropertyAnimation;
386     auto windowProperty = sptr<WindowSessionProperty>::MakeSptr();
387     ASSERT_NE(windowProperty, nullptr);
388     windowProperty->animationFlag_ = static_cast<uint32_t>(WindowAnimation::CUSTOM);
389 
390     // for TOAST or FLOAT permission
391     systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
392 
393     systemSession_->Show(windowProperty);
394     usleep(WAIT_ASYNC_US);
395     ASSERT_EQ(systemSession_->property_->animationFlag_, static_cast<uint32_t>(WindowAnimation::CUSTOM));
396 }
397 
398 /**
399  * @tc.name: Hide01
400  * @tc.desc: test function : Hide
401  * @tc.type: FUNC
402  */
403 HWTEST_F(SystemSessionTest, Hide01, TestSize.Level0)
404 {
405     auto sysSession = GetSystemSession("Hide01");
406     ASSERT_NE(sysSession, nullptr);
407 
408     // for CheckPermissionWithPropertyAnimation;
409     auto windowProperty = sptr<WindowSessionProperty>::MakeSptr();
410     ASSERT_NE(windowProperty, nullptr);
411     windowProperty->animationFlag_ = static_cast<uint32_t>(WindowAnimation::CUSTOM);
412 
413     sysSession->property_ = windowProperty;
414     // for TOAST or FLOAT permission
415     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
416 
417     // for IsSessionValid
418     sysSession->sessionInfo_.isSystem_ = false;
419     sysSession->state_ = SessionState::STATE_CONNECT;
420     sysSession->isActive_ = true;
421 
422     auto ret = sysSession->Hide();
423     usleep(WAIT_ASYNC_US);
424     ASSERT_EQ(ret, WSError::WS_OK);
425 
426     windowProperty->animationFlag_ = static_cast<uint32_t>(WindowAnimation::DEFAULT);
427     ret = sysSession->Hide();
428     usleep(WAIT_ASYNC_US);
429     ASSERT_EQ(ret, WSError::WS_OK);
430 
431     ret = sysSession->Hide();
432     sysSession->property_ = nullptr;
433     usleep(WAIT_ASYNC_US);
434     ASSERT_EQ(ret, WSError::WS_OK);
435 }
436 
437 /**
438  * @tc.name: ProcessPointDownSession01
439  * @tc.desc: test function : ProcessPointDownSession
440  * @tc.type: FUNC
441  */
442 HWTEST_F(SystemSessionTest, ProcessPointDownSession01, TestSize.Level1)
443 {
444     auto sysSession = GetSystemSession("ProcessPointDownSession01");
445     ASSERT_NE(sysSession, nullptr);
446     sysSession->persistentId_ = 1;
447     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
448     sysSession->state_ = SessionState::STATE_ACTIVE;
449 
450     auto parentSesssion = GetSceneSession("parentSession");
451     ASSERT_NE(parentSesssion, nullptr);
452     sysSession->parentSession_ = parentSesssion;
453 
454     parentSesssion->dialogVec_.push_back(sysSession);
455     auto ret = sysSession->ProcessPointDownSession(0, 0);
456     ASSERT_EQ(ret, WSError::WS_OK);
457 
458     // for IsTopDialog true
459     auto topDialog = GetSystemSession("TopDialogSession");
460     ASSERT_NE(topDialog, nullptr);
461     topDialog->persistentId_ = 2;
462     topDialog->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
463     topDialog->state_ = SessionState::STATE_ACTIVE;
464     parentSesssion->dialogVec_.push_back(topDialog);
465 
466     ret = sysSession->ProcessPointDownSession(0, 0);
467     ASSERT_EQ(ret, WSError::WS_OK);
468 }
469 
470 /**
471  * @tc.name: ProcessPointDownSession02
472  * @tc.desc: test function : ProcessPointDownSession
473  * @tc.type: FUNC
474  */
475 HWTEST_F(SystemSessionTest, ProcessPointDownSession02, TestSize.Level1)
476 {
477     auto sysSession = GetSystemSession("ProcessPointDownSession02");
478     ASSERT_NE(sysSession, nullptr);
479     sysSession->persistentId_ = 1;
480     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
481     sysSession->state_ = SessionState::STATE_ACTIVE;
482 
483     sysSession->property_->raiseEnabled_ = false;
484     auto ret = sysSession->ProcessPointDownSession(0, 0);
485     ASSERT_EQ(ret, WSError::WS_OK);
486 
487     sysSession->property_->raiseEnabled_ = true;
488     ret = sysSession->ProcessPointDownSession(0, 0);
489     ASSERT_EQ(ret, WSError::WS_OK);
490 }
491 
492 /**
493  * @tc.name: TransferKeyEvent04
494  * @tc.desc: test function : TransferKeyEvent
495  * @tc.type: FUNC
496  */
497 HWTEST_F(SystemSessionTest, TransferKeyEvent04, TestSize.Level1)
498 {
499     auto sysSession = GetSystemSession("TransferKeyEvent04");
500     ASSERT_NE(sysSession, nullptr);
501     sysSession->persistentId_ = 1;
502     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
503     sysSession->state_ = SessionState::STATE_ACTIVE;
504 
505     std::shared_ptr<MMI::KeyEvent> keyEvent;
506 
507     auto ret = sysSession->TransferKeyEvent(nullptr);
508     ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
509 
510     ret = sysSession->TransferKeyEvent(keyEvent);
511     ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
512 }
513 
514 /**
515  * @tc.name: TransferKeyEvent05
516  * @tc.desc: test function : TransferKeyEvent
517  * @tc.type: FUNC
518  */
519 HWTEST_F(SystemSessionTest, TransferKeyEvent05, TestSize.Level1)
520 {
521     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
522 
523     auto sysSession = GetSystemSession("TransferKeyEvent05");
524     ASSERT_NE(sysSession, nullptr);
525     sysSession->persistentId_ = 1;
526     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
527     sysSession->state_ = SessionState::STATE_ACTIVE;
528 
529     auto ret = sysSession->TransferKeyEvent(keyEvent);
530     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
531 
532     auto parentSesssion = GetSceneSession("parentSession");
533     ASSERT_NE(parentSesssion, nullptr);
534     sysSession->parentSession_ = parentSesssion;
535 
536     // for CheckKeyEventDispatch return true;
537     parentSesssion->state_ = SessionState::STATE_FOREGROUND;
538     ret = sysSession->TransferKeyEvent(keyEvent);
539     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
540 
541     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
542     ret = sysSession->TransferKeyEvent(keyEvent);
543     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
544 
545     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_HOME);
546     parentSesssion->dialogVec_.push_back(sysSession);
547     ret = sysSession->TransferKeyEvent(keyEvent);
548     ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
549 
550     auto topDialog = GetSystemSession("TopDialogSession");
551     ASSERT_NE(topDialog, nullptr);
552     topDialog->persistentId_ = 2;
553     topDialog->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
554     topDialog->state_ = SessionState::STATE_ACTIVE;
555     parentSesssion->dialogVec_.push_back(topDialog);
556     ret = sysSession->TransferKeyEvent(keyEvent);
557     ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
558 }
559 
560 /**
561  * @tc.name: ProcessBackEvent02
562  * @tc.desc: test function : ProcessBackEvent
563  * @tc.type: FUNC
564  */
565 HWTEST_F(SystemSessionTest, ProcessBackEvent02, TestSize.Level1)
566 {
567     auto sysSession = GetSystemSession("ProcessBackEvent02");
568     ASSERT_NE(sysSession, nullptr);
569     sysSession->persistentId_ = 1;
570     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
571     sysSession->state_ = SessionState::STATE_ACTIVE;
572 
573     sysSession->dialogSessionBackGestureEnabled_ = false;
574     auto ret = sysSession->ProcessBackEvent();
575     ASSERT_EQ(ret, WSError::WS_OK);
576 
577     sysSession->dialogSessionBackGestureEnabled_ = true;
578     ret = sysSession->ProcessBackEvent();
579     ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
580 
581     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
582     ret = sysSession->ProcessBackEvent();
583     ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
584 }
585 
586 /**
587  * @tc.name: CheckKeyEventDispatch03
588  * @tc.desc: test function : CheckKeyEventDispatch
589  * @tc.type: FUNC
590  */
591 HWTEST_F(SystemSessionTest, CheckKeyEventDispatch03, TestSize.Level1)
592 {
593     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
594     auto sysSession = GetSystemSession("CheckKeyEventDispatch03");
595     ASSERT_NE(sysSession, nullptr);
596     sysSession->persistentId_ = 1;
597     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
598     sysSession->state_ = SessionState::STATE_ACTIVE;
599     sysSession->isRSVisible_ = false;
600 
601     auto ret = sysSession->CheckKeyEventDispatch(keyEvent);
602     ASSERT_EQ(ret, false);
603 
604     sysSession->isRSVisible_ = true;
605     WSRect curRect = sysSession->GetSessionRect();
606     sysSession->GetLayoutController()->SetSessionRect({ curRect.posX_, curRect.posY_, 0, curRect.height_ });
607     ret = sysSession->CheckKeyEventDispatch(keyEvent);
608     ASSERT_EQ(ret, false);
609 
610     sysSession->isRSVisible_ = true;
611     curRect = sysSession->GetSessionRect();
612     sysSession->GetLayoutController()->SetSessionRect({ curRect.posX_, curRect.posY_, 1, 0 });
613     ret = sysSession->CheckKeyEventDispatch(keyEvent);
614     ASSERT_EQ(ret, false);
615 
616     sysSession->isRSVisible_ = true;
617     curRect = sysSession->GetSessionRect();
618     sysSession->GetLayoutController()->SetSessionRect({ curRect.posX_, curRect.posY_, 1, 1 });
619     ret = sysSession->CheckKeyEventDispatch(keyEvent);
620     ASSERT_EQ(ret, false);
621 }
622 
623 /**
624  * @tc.name: CheckKeyEventDispatch04
625  * @tc.desc: test function : CheckKeyEventDispatch
626  * @tc.type: FUNC
627  */
628 HWTEST_F(SystemSessionTest, CheckKeyEventDispatch04, TestSize.Level1)
629 {
630     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
631     auto sysSession = GetSystemSession("CheckKeyEventDispatch04");
632     ASSERT_NE(sysSession, nullptr);
633     sysSession->persistentId_ = 1;
634     sysSession->isRSVisible_ = true;
635     WSRect curRect = sysSession->GetSessionRect();
636     sysSession->GetLayoutController()->SetSessionRect({ curRect.posX_, curRect.posY_, 1, 1 });
637     sysSession->state_ = SessionState::STATE_DISCONNECT;
638 
639     auto parentSesssion = GetSceneSession("parentSession");
640     ASSERT_NE(parentSesssion, nullptr);
641     sysSession->parentSession_ = parentSesssion;
642 
643     parentSesssion->state_ = SessionState::STATE_FOREGROUND;
644     auto ret = sysSession->CheckKeyEventDispatch(keyEvent);
645     ASSERT_EQ(ret, false);
646 
647     parentSesssion->state_ = SessionState::STATE_ACTIVE;
648     ret = sysSession->CheckKeyEventDispatch(keyEvent);
649     ASSERT_EQ(ret, false);
650 
651     parentSesssion->state_ = SessionState::STATE_DISCONNECT;
652     sysSession->state_ = SessionState::STATE_FOREGROUND;
653     ret = sysSession->CheckKeyEventDispatch(keyEvent);
654     ASSERT_EQ(ret, false);
655 
656     sysSession->state_ = SessionState::STATE_ACTIVE;
657     ret = sysSession->CheckKeyEventDispatch(keyEvent);
658     ASSERT_EQ(ret, false);
659 
660     parentSesssion->state_ = SessionState::STATE_DISCONNECT;
661     sysSession->state_ = SessionState::STATE_DISCONNECT;
662     ret = sysSession->CheckKeyEventDispatch(keyEvent);
663     ASSERT_EQ(ret, false);
664 }
665 
666 /**
667  * @tc.name: NotifyClientToUpdateRect02
668  * @tc.desc: test function : NotifyClientToUpdateRect
669  * @tc.type: FUNC
670  */
671 HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect02, TestSize.Level1)
672 {
673     auto sysSession = GetSystemSession("NotifyClientToUpdateRect02");
674     ASSERT_NE(sysSession, nullptr);
675     sysSession->persistentId_ = 1;
676     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
677     sysSession->state_ = SessionState::STATE_ACTIVE;
678 
679     // for NotifyClientToUpdateRectTask
680     sysSession->isKeyboardPanelEnabled_ = true;
681 
682     sysSession->dirtyFlags_ = 0;
683     sysSession->Session::UpdateSizeChangeReason(SizeChangeReason::MAXIMIZE);
684     sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
685     usleep(WAIT_ASYNC_US);
686     ASSERT_EQ(sysSession->GetSizeChangeReason(), SizeChangeReason::UNDEFINED);
687 
688     sysSession->Session::UpdateSizeChangeReason(SizeChangeReason::DRAG);
689     sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
690     usleep(WAIT_ASYNC_US);
691     ASSERT_EQ(sysSession->GetSizeChangeReason(), SizeChangeReason::DRAG);
692 }
693 
694 /**
695  * @tc.name: NotifyClientToUpdateRect03
696  * @tc.desc: test function : NotifyClientToUpdateRect
697  * @tc.type: FUNC
698  */
699 HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect03, TestSize.Level1)
700 {
701     auto sysSession = GetSystemSession("NotifyClientToUpdateRect03");
702     ASSERT_NE(sysSession, nullptr);
703     sysSession->persistentId_ = 1;
704     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
705     sysSession->state_ = SessionState::STATE_ACTIVE;
706 
707     sysSession->dirtyFlags_ = 0;
708     sysSession->isKeyboardPanelEnabled_ = true;
709     sysSession->Session::UpdateSizeChangeReason(SizeChangeReason::MAXIMIZE);
710 
711     sptr<SceneSession::SpecificSessionCallback> specificCallback =
712         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
713     ASSERT_NE(specificCallback, nullptr);
714     sysSession->specificCallback_ = specificCallback;
715     sysSession->specificCallback_->onUpdateAvoidArea_ = nullptr;
716     sysSession->GetLayoutController()->SetSessionRect({ 0, 0, 800, 800 });
717     sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
718     usleep(WAIT_ASYNC_US);
719     EXPECT_EQ(sysSession->dirtyFlags_, 0);
720 
721     sysSession->dirtyFlags_ = 0;
722     sysSession->SetScbCoreEnabled(true);
723     sysSession->Session::UpdateSizeChangeReason(SizeChangeReason::MAXIMIZE);
__anone543d0430402(const int32_t& persistentId) 724     sysSession->specificCallback_->onUpdateAvoidArea_ = [](const int32_t& persistentId) {};
725     sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
726     usleep(WAIT_ASYNC_US);
727     EXPECT_EQ(sysSession->dirtyFlags_, static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA));
728 }
729 
730 /**
731  * @tc.name: IsVisibleForeground01
732  * @tc.desc: test function : IsVisibleForeground
733  * @tc.type: FUNC
734  */
735 HWTEST_F(SystemSessionTest, IsVisibleForeground01, TestSize.Level1)
736 {
737     auto sysSession = GetSystemSession("IsVisibleForeground01");
738     ASSERT_NE(sysSession, nullptr);
739     sysSession->persistentId_ = 1;
740     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
741     sysSession->state_ = SessionState::STATE_ACTIVE;
742     sysSession->isVisible_ = false;
743 
744     auto ret = sysSession->IsVisibleForeground();
745     ASSERT_EQ(ret, false);
746 
747     sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
748     ret = sysSession->IsVisibleForeground();
749     ASSERT_EQ(ret, false);
750 
751     auto parentSesssion = GetSceneSession("parentSession");
752     ASSERT_NE(parentSesssion, nullptr);
753     sysSession->parentSession_ = parentSesssion;
754     parentSesssion->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
755     ret = sysSession->IsVisibleForeground();
756     ASSERT_EQ(ret, false);
757 
758     parentSesssion->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
759     ret = sysSession->IsVisibleForeground();
760     ASSERT_EQ(ret, false);
761 }
762 
763 /**
764  * @tc.name: UpdatePiPWindowStateChanged
765  * @tc.desc: test function : UpdatePiPWindowStateChanged
766  * @tc.type: FUNC
767  */
768 HWTEST_F(SystemSessionTest, UpdatePiPWindowStateChanged, TestSize.Level1)
769 {
770     SessionInfo sessionInfo;
771     sessionInfo.abilityName_ = "UpdatePiPWindowStateChanged";
772     sessionInfo.moduleName_ = "UpdatePiPWindowStateChanged";
773     sessionInfo.bundleName_ = "UpdatePiPWindowStateChanged";
774     sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::APP_MAIN_WINDOW_BASE);
775     sptr<SceneSession::SpecificSessionCallback> callback = sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
776     EXPECT_NE(nullptr, callback);
777     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(sessionInfo, callback);
778     EXPECT_NE(nullptr, systemSession);
__anone543d0430502(const std::string& bundleName, bool isForeground) 779     PiPStateChangeCallback callbackFun = [](const std::string& bundleName, bool isForeground) { return; };
780     callback->onPiPStateChange_ = callbackFun;
781     EXPECT_EQ(WindowType::APP_MAIN_WINDOW_BASE, systemSession->GetWindowType());
782     systemSession->UpdatePiPWindowStateChanged(true);
783 
784     sessionInfo.windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_PIP);
785     sptr<SystemSession> system = sptr<SystemSession>::MakeSptr(sessionInfo, callback);
786     EXPECT_NE(nullptr, system);
787     EXPECT_EQ(WindowType::WINDOW_TYPE_PIP, system->GetWindowType());
788     system->UpdatePiPWindowStateChanged(true);
789 }
790 
791 /**
792  * @tc.name: GetSubWindowZLevel
793  * @tc.desc: GetSubWindowZLevel
794  * @tc.type: FUNC
795  */
796 HWTEST_F(SystemSessionTest, GetSubWindowZLevel, TestSize.Level1)
797 {
798     SessionInfo info;
799     info.abilityName_ = "GetSubWindowZLevel";
800     info.bundleName_ = "GetSubWindowZLevel";
801     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, nullptr);
802     systemSession->property_->zLevel_ = 1;
803     EXPECT_EQ(1, systemSession->GetSubWindowZLevel());
804 }
805 
806 /**
807  * @tc.name: IsVisibleNotBackground
808  * @tc.desc: IsVisibleNotBackground
809  * @tc.type: FUNC
810  */
811 HWTEST_F(SystemSessionTest, IsVisibleNotBackground, TestSize.Level1)
812 {
813     SessionInfo info;
814     info.abilityName_ = "IsVisibleNotBackground";
815     info.bundleName_ = "IsVisibleNotBackground";
816     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, nullptr);
817     EXPECT_EQ(false, systemSession->IsVisibleNotBackground());
818     systemSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
819     sptr<Session> parentSession = sptr<Session>::MakeSptr(info);
820     parentSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
821     systemSession->SetParentSession(parentSession);
822     EXPECT_EQ(false, systemSession->IsVisibleNotBackground());
823     systemSession->SetSessionState(SessionState::STATE_FOREGROUND);
824     systemSession->isVisible_ = true;
825     parentSession->SetSessionState(SessionState::STATE_FOREGROUND);
826     parentSession->isVisible_ = true;
827     EXPECT_EQ(true, systemSession->IsVisibleNotBackground());
828 }
829 
830 /**
831  * @tc.name: SetAndGetFbTemplateInfo
832  * @tc.desc: SetAndGetFbTemplateInfo Test
833  * @tc.type: FUNC
834  */
835 HWTEST_F(SystemSessionTest, SetAndGetFbTemplateInfo, TestSize.Level1)
836 {
837     SessionInfo info;
838     info.abilityName_ = "Background01";
839     info.bundleName_ = "Background01";
840 
841     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, nullptr);
842     ASSERT_NE(systemSession, nullptr);
843     systemSession->isActive_ = true;
844     FloatingBallTemplateInfo fbTemplateInfo;
845     fbTemplateInfo.template_ = 1;
846     systemSession->SetFbTemplateInfo(fbTemplateInfo);
847     EXPECT_EQ(systemSession->GetFbTemplateInfo().template_, fbTemplateInfo.template_);
848 }
849 
850 /**
851  * @tc.name: GetFbWindowId
852  * @tc.desc: GetFbWindowId Test
853  * @tc.type: FUNC
854  */
855 HWTEST_F(SystemSessionTest, GetFbWindowId, TestSize.Level1)
856 {
857     SessionInfo info;
858     info.abilityName_ = "SetAndGetFbWindowId";
859     info.bundleName_ = "SetAndGetFbWindowId";
860 
861     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, nullptr);
862     ASSERT_NE(systemSession, nullptr);
863 
864     EXPECT_EQ(systemSession->GetFbWindowId(), 0);
865 
866     uint32_t testWindowId = 100;
__anone543d0430602(uint32_t& windowId) 867     auto func = [testWindowId](uint32_t& windowId) {
868         windowId = testWindowId;
869         return WMError::WM_OK;
870     };
871     systemSession->RegisterGetFbPanelWindowIdFunc(func);
872     EXPECT_EQ(systemSession->GetFbWindowId(), testWindowId);
873 }
874 
875 /**
876  * @tc.name: UpdateFloatingBall
877  * @tc.desc: UpdateFloatingBall
878  * @tc.type: FUNC
879  */
880 HWTEST_F(SystemSessionTest, UpdateFloatingBall, Function | SmallTest | Level2)
881 {
882     SessionInfo info;
883     sptr<SceneSession::SpecificSessionCallback> specificCallback =
884         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
885     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
886 
887     FloatingBallTemplateInfo fbTemplateInfo;
888     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
889     EXPECT_NE(property, nullptr);
890     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
891     systemSession->SetSessionProperty(property);
892     EXPECT_EQ(systemSession->UpdateFloatingBall(fbTemplateInfo), WMError::WM_DO_NOTHING);
893 
894     property->SetWindowType(WindowType::WINDOW_TYPE_FB);
895     systemSession->SetSessionProperty(property);
896     EXPECT_EQ(systemSession->UpdateFloatingBall(fbTemplateInfo), WMError::WM_OK);
897 
898     LOCK_GUARD_EXPR(SCENE_GUARD, systemSession->SetCallingPid(IPCSkeleton::GetCallingPid()));
899     EXPECT_EQ(systemSession->UpdateFloatingBall(fbTemplateInfo), WMError::WM_OK);
900 
901     FloatingBallTemplateInfo fbTmpInfo {static_cast<uint32_t>(FloatingBallTemplate::STATIC), "", "", "", nullptr};
902     systemSession->SetFbTemplateInfo(fbTmpInfo);
903     EXPECT_EQ(systemSession->UpdateFloatingBall(fbTemplateInfo), WMError::WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED);
904 
905     fbTmpInfo.template_ = static_cast<uint32_t>(FloatingBallTemplate::NORMAL);
906     systemSession->SetFbTemplateInfo(fbTmpInfo);
907     EXPECT_EQ(systemSession->UpdateFloatingBall(fbTemplateInfo), WMError::WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED);
908 
909     fbTemplateInfo.template_ = static_cast<uint32_t>(FloatingBallTemplate::NORMAL);
910     EXPECT_EQ(systemSession->UpdateFloatingBall(fbTemplateInfo), WMError::WM_OK);
911 }
912 
913 /**
914  * @tc.name: StopFloatingBall
915  * @tc.desc: StopFloatingBall
916  * @tc.type: FUNC
917  */
918 HWTEST_F(SystemSessionTest, StopFloatingBall, Function | SmallTest | Level2)
919 {
920     SessionInfo info;
921     sptr<SceneSession::SpecificSessionCallback> specificCallback =
922         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
923     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
924 
925     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
926     EXPECT_NE(property, nullptr);
927     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
928     systemSession->SetSessionProperty(property);
929     EXPECT_EQ(systemSession->StopFloatingBall(), WSError::WS_DO_NOTHING);
930 
931     property->SetWindowType(WindowType::WINDOW_TYPE_FB);
932     systemSession->SetSessionProperty(property);
933     EXPECT_EQ(systemSession->StopFloatingBall(), WSError::WS_OK);
934 
935     LOCK_GUARD_EXPR(SCENE_GUARD, systemSession->SetCallingPid(IPCSkeleton::GetCallingPid()));
936     EXPECT_EQ(systemSession->StopFloatingBall(), WSError::WS_OK);
937 }
938 
939 /**
940  * @tc.name: RestoreFbMainWindow
941  * @tc.desc: RestoreFbMainWindow
942  * @tc.type: FUNC
943  */
944 HWTEST_F(SystemSessionTest, RestoreFbMainWindow, Function | SmallTest | Level2)
945 {
946     SessionInfo info;
947     sptr<SceneSession::SpecificSessionCallback> specificCallback =
948         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
949     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
950 
951     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
952     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
953     EXPECT_NE(property, nullptr);
954     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
955     systemSession->SetSessionProperty(property);
956     EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_DO_NOTHING);
957 
958     property->SetWindowType(WindowType::WINDOW_TYPE_FB);
959     systemSession->SetSessionProperty(property);
960 
961     MockAccesstokenKit::MockAccessTokenKitRet(-1);
962     EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_INVALID_PERMISSION);
963 
964     MockAccesstokenKit::MockAccessTokenKitRet(0);
965     EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_INVALID_CALLING);
966 
967     LOCK_GUARD_EXPR(SCENE_GUARD, systemSession->SetCallingPid(IPCSkeleton::GetCallingPid()));
968     EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED);
969 
970     std::string bundle = "testBundle";
971     want->SetBundle(bundle);
972     EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED);
973     systemSession->EditSessionInfo().bundleName_ = bundle;
974     uint64_t nowTime = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
975         std::chrono::system_clock::now().time_since_epoch()).count());
976     systemSession->fbClickTime_ = nowTime - 1000;
977     EXPECT_EQ(systemSession->RestoreFbMainWindow(want), WMError::WM_OK);
978 }
979 
980 /**
981  * @tc.name: GetFloatingBallWindowId
982  * @tc.desc: GetFloatingBallWindowId
983  * @tc.type: FUNC
984  */
985 HWTEST_F(SystemSessionTest, GetFloatingBallWindowId, Function | SmallTest | Level2)
986 {
987     SessionInfo info;
988     sptr<SceneSession::SpecificSessionCallback> specificCallback =
989         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
990     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
991     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
992     EXPECT_NE(property, nullptr);
993 
994     uint32_t windowId = 0;
995     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
996     systemSession->SetSessionProperty(property);
997     EXPECT_EQ(systemSession->GetFloatingBallWindowId(windowId), WMError::WM_DO_NOTHING);
998 
999     property->SetWindowType(WindowType::WINDOW_TYPE_FB);
1000     systemSession->SetSessionProperty(property);
1001     EXPECT_EQ(systemSession->GetFloatingBallWindowId(windowId), WMError::WM_ERROR_INVALID_CALLING);
1002 
1003     LOCK_GUARD_EXPR(SCENE_GUARD, systemSession->SetCallingPid(IPCSkeleton::GetCallingPid()));
1004     EXPECT_EQ(systemSession->GetFloatingBallWindowId(windowId), WMError::WM_OK);
1005 }
1006 
1007 /**
1008  * @tc.name: NotifyUpdateFloatingBall
1009  * @tc.desc: NotifyUpdateFloatingBall
1010  * @tc.type: FUNC
1011  */
1012 HWTEST_F(SystemSessionTest, NotifyUpdateFloatingBall, Function | SmallTest | Level2)
1013 {
1014     SessionInfo info;
1015     sptr<SceneSession::SpecificSessionCallback> specificCallback =
1016         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1017     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
1018 
1019     FloatingBallTemplateInfo fbTemplateInfo {1, "fb", "fb_content", "red", nullptr};
1020     FloatingBallTemplateInfo newFbTemplateInfo {2, "fb_new", "fb_content_new", "red", nullptr};
1021     systemSession->SetFloatingBallUpdateCallback(nullptr);
1022     systemSession->NotifyUpdateFloatingBall(newFbTemplateInfo);
1023     EXPECT_NE(fbTemplateInfo.template_, newFbTemplateInfo.template_);
1024 
__anone543d0430702(const FloatingBallTemplateInfo& newFbTemplateInfo) 1025     auto updateFbFuncCb = [&fbTemplateInfo] (const FloatingBallTemplateInfo& newFbTemplateInfo) {
1026         fbTemplateInfo.template_ = newFbTemplateInfo.template_;
1027     };
1028     systemSession->SetFloatingBallUpdateCallback(updateFbFuncCb);
1029     systemSession->NotifyUpdateFloatingBall(newFbTemplateInfo);
1030     EXPECT_EQ(fbTemplateInfo.template_, newFbTemplateInfo.template_);
1031 }
1032 
1033 /**
1034  * @tc.name: NotifyStopFloatingBall
1035  * @tc.desc: NotifyStopFloatingBall
1036  * @tc.type: FUNC
1037  */
1038 HWTEST_F(SystemSessionTest, NotifyStopFloatingBall, Function | SmallTest | Level2)
1039 {
1040     SessionInfo info;
1041     sptr<SceneSession::SpecificSessionCallback> specificCallback =
1042         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1043     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
1044 
1045     uint32_t stopFuncCallTimes = 0;
__anone543d0430802() 1046     auto fbStopFuncCb = [&stopFuncCallTimes] () {
1047         stopFuncCallTimes++;
1048     };
1049 
1050     systemSession->SetFloatingBallStopCallback(nullptr);
1051     systemSession->NotifyStopFloatingBall();
1052 
1053     systemSession->SetFloatingBallStopCallback(fbStopFuncCb);
1054     systemSession->NotifyStopFloatingBall();
1055     EXPECT_EQ(stopFuncCallTimes, 2);
1056 }
1057 
1058 /**
1059  * @tc.name: NotifyRestoreFloatingBallMainWindow
1060  * @tc.desc: NotifyRestoreFloatingBallMainWindow
1061  * @tc.type: FUNC
1062  */
1063 HWTEST_F(SystemSessionTest, NotifyRestoreFloatingBallMainWindow, Function | SmallTest | Level2)
1064 {
1065     SessionInfo info;
1066     sptr<SceneSession::SpecificSessionCallback> specificCallback =
1067         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1068     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, specificCallback);
1069 
1070     std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
1071     want->SetParam("NotifyRestoreFloatingBallMainWindow", 100);
1072     int res = -1;
1073     systemSession->SetFloatingBallRestoreMainWindowCallback(nullptr);
1074     systemSession->NotifyRestoreFloatingBallMainWindow(want);
1075 
__anone543d0430902(const std::shared_ptr<AAFwk::Want>& want) 1076     auto fbStopFuncCb = [&res] (const std::shared_ptr<AAFwk::Want>& want) {
1077         res = want->GetIntParam("NotifyRestoreFloatingBallMainWindow", -1);
1078     };
1079     systemSession->SetFloatingBallRestoreMainWindowCallback(fbStopFuncCb);
1080     systemSession->NotifyRestoreFloatingBallMainWindow(want);
1081     EXPECT_EQ(res, 100);
1082 }
1083 
1084 /**
1085  * @tc.name: SendFbActionEvent
1086  * @tc.desc: SendFbActionEvent
1087  * @tc.type: FUNC
1088  */
1089 HWTEST_F(SystemSessionTest, SendFbActionEvent, Function | SmallTest | Level2)
1090 {
1091     SessionInfo info;
1092     sptr<SystemSession> systemSession = sptr<SystemSession>::MakeSptr(info, nullptr);
1093 
1094     systemSession_->sessionStage_ = nullptr;
1095     EXPECT_EQ(systemSession->SendFbActionEvent(""), WSError::WS_ERROR_NULLPTR);
1096 
1097     sptr<SessionStageMocker> mockSessionStage = sptr<SessionStageMocker>::MakeSptr();
1098     ASSERT_NE(mockSessionStage, nullptr);
1099     systemSession_->sessionStage_ = mockSessionStage;
1100     auto ret = systemSession_->SendFbActionEvent("click");
1101     ASSERT_EQ(WSError::WS_OK, ret);
1102 
1103     ret = systemSession_->SendFbActionEvent("on");
1104     ASSERT_EQ(WSError::WS_OK, ret);
1105 }
1106 } // namespace
1107 } // namespace Rosen
1108 } // namespace OHOS
1109