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_session.h"
22 #include "mock/mock_session_stage.h"
23 #include "session/host/include/session.h"
24 #include <ui/rs_surface_node.h>
25 #include "window_event_channel_base.h"
26 #include "window_helper.h"
27 #include "window_manager_hilog.h"
28 #include "pointer_event.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32
33 namespace OHOS {
34 namespace Rosen {
35 constexpr int WAIT_ASYNC_US = 1000000;
36 class SystemSessionTest : public testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp() override;
41 void TearDown() override;
42 SessionInfo info;
43 sptr<SystemSession::SpecificSessionCallback> specificCallback = nullptr;
44 sptr<SystemSession> systemSession_;
45 private:
46 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
47 sptr<SystemSession> GetSystemSession(const std::string& name);
48 sptr<SceneSession> GetSceneSession(const std::string& name);
49 };
50
SetUpTestCase()51 void SystemSessionTest::SetUpTestCase()
52 {
53 }
54
TearDownTestCase()55 void SystemSessionTest::TearDownTestCase()
56 {
57 }
58
SetUp()59 void SystemSessionTest::SetUp()
60 {
61 SessionInfo info;
62 info.abilityName_ = "testSystemSession1";
63 info.moduleName_ = "testSystemSession2";
64 info.bundleName_ = "testSystemSession3";
65 systemSession_ = sptr<SystemSession>::MakeSptr(info, specificCallback);
66 EXPECT_NE(nullptr, systemSession_);
67 }
68
TearDown()69 void SystemSessionTest::TearDown()
70 {
71 systemSession_ = nullptr;
72 }
73
CreateRSSurfaceNode()74 RSSurfaceNode::SharedPtr SystemSessionTest::CreateRSSurfaceNode()
75 {
76 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
77 rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
78 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
79 return surfaceNode;
80 }
81
GetSystemSession(const std::string & name)82 sptr<SystemSession> SystemSessionTest::GetSystemSession(const std::string& name)
83 {
84 SessionInfo info;
85 info.abilityName_ = name;
86 info.moduleName_ = name;
87 info.bundleName_ = name;
88 auto sysSession = sptr<SystemSession>::MakeSptr(info, nullptr);
89 return sysSession;
90 }
91
GetSceneSession(const std::string & name)92 sptr<SceneSession> SystemSessionTest::GetSceneSession(const std::string& name)
93 {
94 SessionInfo info;
95 info.abilityName_ = name;
96 info.moduleName_ = name;
97 info.bundleName_ = name;
98 auto sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
99 return sceneSession;
100 }
101
102 namespace {
103
104 /**
105 * @tc.name: TransferKeyEvent01
106 * @tc.desc: check func TransferKeyEvent
107 * @tc.type: FUNC
108 */
109 HWTEST_F(SystemSessionTest, TransferKeyEvent01, Function | SmallTest | Level1)
110 {
111 systemSession_->state_ = SessionState::STATE_END;
112
113 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, systemSession_->TransferKeyEvent(nullptr));
114 }
115
116 /**
117 * @tc.name: TransferKeyEvent02
118 * @tc.desc: check func TransferKeyEvent
119 * @tc.type: FUNC
120 */
121 HWTEST_F(SystemSessionTest, TransferKeyEvent02, Function | SmallTest | Level1)
122 {
123 systemSession_->state_ = SessionState::STATE_CONNECT;
124 std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
125
126 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, systemSession_->TransferKeyEvent(keyEvent));
127 }
128
129 /**
130 * @tc.name: ProcessBackEvent01
131 * @tc.desc: check func ProcessBackEvent
132 * @tc.type: FUNC
133 */
134 HWTEST_F(SystemSessionTest, ProcessBackEvent01, Function | SmallTest | Level1)
135 {
136 systemSession_->state_ = SessionState::STATE_END;
137
138 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, systemSession_->ProcessBackEvent());
139 }
140
141 /**
142 * @tc.name: NotifyClientToUpdateRect01
143 * @tc.desc: check func NotifyClientToUpdateRect
144 * @tc.type: FUNC
145 */
146 HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect01, Function | SmallTest | Level1)
147 {
148 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
149 ASSERT_NE(mockSessionStage, nullptr);
150 systemSession_->sessionStage_ = mockSessionStage;
151 auto ret = systemSession_->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
152 ASSERT_EQ(WSError::WS_OK, ret);
153 }
154
155 /**
156 * @tc.name: CheckPointerEventDispatch
157 * @tc.desc: check func CheckPointerEventDispatch
158 * @tc.type: FUNC
159 */
160 HWTEST_F(SystemSessionTest, CheckPointerEventDispatch, Function | SmallTest | Level1)
161 {
162 std::shared_ptr<MMI::PointerEvent> pointerEvent_ = MMI::PointerEvent::Create();
163 SessionInfo info;
164 info.abilityName_ = "CheckPointerEventDispatch";
165 info.bundleName_ = "CheckPointerEventDispatchBundleName";
166 info.windowType_ = 2122;
167 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
168 new (std::nothrow) SceneSession::SpecificSessionCallback();
169 sptr<SystemSession> sysSession =
170 new (std::nothrow) SystemSession(info, specificCallback_);
171 sysSession->SetSessionState(SessionState::STATE_FOREGROUND);
172 bool ret1 = sysSession->CheckPointerEventDispatch(pointerEvent_);
173 ASSERT_EQ(true, ret1);
174 }
175
176 /**
177 * @tc.name: UpdatePointerArea
178 * @tc.desc: check func UpdatePointerArea
179 * @tc.type: FUNC
180 */
181 HWTEST_F(SystemSessionTest, UpdatePointerArea, Function | SmallTest | Level1)
182 {
183 WSRect rect = { 1, 1, 1, 1 };
184 SessionInfo info;
185 info.abilityName_ = "UpdatePointerArea";
186 info.bundleName_ = "UpdatePointerAreaBundleName";
187 info.windowType_ = 2122;
188 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
189 new (std::nothrow) SceneSession::SpecificSessionCallback();
190 sptr<SystemSession> sysSession =
191 new (std::nothrow) SystemSession(info, specificCallback_);
192 sysSession->UpdatePointerArea(rect);
193
194 sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
195 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
196 property->SetDecorEnable(true);
197 sysSession->property_ = property;
198 sysSession->UpdatePointerArea(rect);
199 ASSERT_EQ(sysSession->preRect_, rect);
200 }
201
202 /**
203 * @tc.name: ProcessPointDownSession
204 * @tc.desc: test function : ProcessPointDownSession
205 * @tc.type: FUNC
206 */
207 HWTEST_F(SystemSessionTest, ProcessPointDownSession, Function | SmallTest | Level1)
208 {
209 ASSERT_TRUE(systemSession_ != nullptr);
210
211 int32_t posX = 2;
212 int32_t posY = 3;
213 auto ret = systemSession_->ProcessPointDownSession(posX, posY);
214 ASSERT_EQ(WSError::WS_OK, ret);
215 }
216
217 /**
218 * @tc.name: GetMissionId
219 * @tc.desc: test function : GetMissionId
220 * @tc.type: FUNC
221 */
222 HWTEST_F(SystemSessionTest, GetMissionId, Function | SmallTest | Level1)
223 {
224 ASSERT_TRUE(systemSession_ != nullptr);
225 SessionInfo info;
226 info.abilityName_ = "testSystemSession1";
227 info.moduleName_ = "testSystemSession2";
228 info.bundleName_ = "testSystemSession3";
229 sptr<Session> session = new (std::nothrow) Session(info);
230 systemSession_->parentSession_ = session;
231 auto ret = systemSession_->GetMissionId();
232 ASSERT_EQ(0, ret);
233 }
234
235 /**
236 * @tc.name: RectCheck
237 * @tc.desc: test function : RectCheck
238 * @tc.type: FUNC
239 */
240 HWTEST_F(SystemSessionTest, RectCheck, Function | SmallTest | Level1)
241 {
242 ASSERT_TRUE(systemSession_ != nullptr);
243 SessionInfo info;
244 info.abilityName_ = "testRectCheck";
245 info.moduleName_ = "testRectCheck";
246 info.bundleName_ = "testRectCheck";
247 sptr<Session> session = new (std::nothrow) Session(info);
248 EXPECT_NE(nullptr, session);
249 systemSession_->parentSession_ = session;
250 uint32_t curWidth = 100;
251 uint32_t curHeight = 200;
252 systemSession_->RectCheck(curWidth, curHeight);
253
254 curWidth = 0;
255 curHeight = 0;
256 systemSession_->RectCheck(curWidth, curHeight);
257
258 curWidth = 1930;
259 curHeight = 0;
260 systemSession_->RectCheck(curWidth, curHeight);
261
262 curWidth = 330;
263 curHeight = 0;
264 systemSession_->RectCheck(curWidth, curHeight);
265
266 curWidth = 330;
267 curHeight = 1930;
268 systemSession_->RectCheck(curWidth, curHeight);
269 }
270
271 /**
272 * @tc.name: SetDialogSessionBackGestureEnabled01
273 * @tc.desc: test function : SetDialogSessionBackGestureEnabled
274 * @tc.type: FUNC
275 */
276 HWTEST_F(SystemSessionTest, SetDialogSessionBackGestureEnabled01, Function | SmallTest | Level1)
277 {
278 ASSERT_TRUE(systemSession_ != nullptr);
279 SessionInfo info;
280 info.abilityName_ = "SetDialogSessionBackGestureEnabled";
281 info.moduleName_ = "SetDialogSessionBackGestureEnabled";
282 info.bundleName_ = "SetDialogSessionBackGestureEnabled";
283 sptr<Session> session = new (std::nothrow) Session(info);
284 EXPECT_NE(nullptr, session);
285
286 systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
287 auto ret = systemSession_->SetDialogSessionBackGestureEnabled(true);
288 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_CALLING);
289 }
290
291 /**
292 * @tc.name: SetDialogSessionBackGestureEnabled02
293 * @tc.desc: test function : SetDialogSessionBackGestureEnabled
294 * @tc.type: FUNC
295 */
296 HWTEST_F(SystemSessionTest, SetDialogSessionBackGestureEnabled02, Function | SmallTest | Level1)
297 {
298 ASSERT_TRUE(systemSession_ != nullptr);
299 SessionInfo info;
300 info.abilityName_ = "SetDialogSessionBackGestureEnabled02";
301 info.moduleName_ = "SetDialogSessionBackGestureEnabled02";
302 info.bundleName_ = "SetDialogSessionBackGestureEnabled02";
303 sptr<Session> session = new (std::nothrow) Session(info);
304 EXPECT_NE(nullptr, session);
305
306 systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
307 auto ret = systemSession_->SetDialogSessionBackGestureEnabled(true);
308 ASSERT_EQ(ret, WSError::WS_OK);
309 }
310
311 /**
312 * @tc.name: UpdateCameraWindowStatus01
313 * @tc.desc: test function : UpdateCameraWindowStatus
314 * @tc.type: FUNC
315 */
316 HWTEST_F(SystemSessionTest, UpdateCameraWindowStatus01, Function | SmallTest | Level1)
317 {
318 sptr<SceneSession::SpecificSessionCallback> specificCallback =
319 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
320 ASSERT_NE(specificCallback, nullptr);
321 bool result = false;
322
323 systemSession_->UpdateCameraWindowStatus(true);
324 ASSERT_EQ(result, false);
325
326 systemSession_->specificCallback_ = specificCallback;
327 systemSession_->UpdateCameraWindowStatus(true);
328 ASSERT_EQ(result, false);
329
330 systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
331 systemSession_->UpdateCameraWindowStatus(true);
332 ASSERT_EQ(result, false);
333
334 systemSession_->specificCallback_->onCameraFloatSessionChange_ =
__anon83b86f990202(uint32_t accessTokenId, bool isShowing) 335 [&result] (uint32_t accessTokenId, bool isShowing) {
336 result = isShowing;
337 };
338 systemSession_->UpdateCameraWindowStatus(true);
339 ASSERT_EQ(result, true);
340 }
341
342 /**
343 * @tc.name: UpdateCameraWindowStatus02
344 * @tc.desc: test function : UpdateCameraWindowStatus
345 * @tc.type: FUNC
346 */
347 HWTEST_F(SystemSessionTest, UpdateCameraWindowStatus02, Function | SmallTest | Level1)
348 {
349 auto sysSession = GetSystemSession("UpdateCameraWindowStatus02");
350 ASSERT_NE(sysSession, nullptr);
351 sptr<SceneSession::SpecificSessionCallback> specificCallback =
352 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
353 ASSERT_NE(specificCallback, nullptr);
354 bool result = false;
355 sysSession->specificCallback_ = specificCallback;
356
357 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP);
358 sysSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
359 sysSession->UpdateCameraWindowStatus(true);
360 ASSERT_EQ(result, false);
361
362 sysSession->specificCallback_->onCameraSessionChange_ =
__anon83b86f990302(uint32_t accessTokenId, bool isShowing) 363 [&result](uint32_t accessTokenId, bool isShowing) {
364 result = isShowing;
365 };
366
367 result = false;
368 sysSession->pipTemplateInfo_.pipTemplateType =
369 static_cast<uint32_t>(PiPTemplateType::VIDEO_CALL);
370 sysSession->UpdateCameraWindowStatus(true);
371 ASSERT_EQ(result, true);
372
373 result = false;
374 sysSession->pipTemplateInfo_.pipTemplateType =
375 static_cast<uint32_t>(PiPTemplateType::VIDEO_MEETING);
376 sysSession->UpdateCameraWindowStatus(true);
377 ASSERT_EQ(result, true);
378
379 result = false;
380 sysSession->pipTemplateInfo_.pipTemplateType =
381 static_cast<uint32_t>(PiPTemplateType::VIDEO_LIVE);
382 sysSession->UpdateCameraWindowStatus(true);
383 ASSERT_EQ(result, false);
384 }
385
386 /**
387 * @tc.name: Show01
388 * @tc.desc: test function : Show
389 * @tc.type: FUNC
390 */
391 HWTEST_F(SystemSessionTest, Show01, Function | SmallTest | Level1)
392 {
393 // for CheckPermissionWithPropertyAnimation;
394 auto windowProperty = sptr<WindowSessionProperty>::MakeSptr();
395 ASSERT_NE(windowProperty, nullptr);
396 windowProperty->animationFlag_ = static_cast<uint32_t>(WindowAnimation::CUSTOM);
397
398 // for TOAST or FLOAT permission
399 systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
400
401 systemSession_->Show(windowProperty);
402 usleep(WAIT_ASYNC_US);
403 ASSERT_EQ(systemSession_->property_->animationFlag_, static_cast<uint32_t>(WindowAnimation::CUSTOM));
404 }
405
406 /**
407 * @tc.name: Hide01
408 * @tc.desc: test function : Hide
409 * @tc.type: FUNC
410 */
411 HWTEST_F(SystemSessionTest, Hide01, Function | SmallTest | Level1)
412 {
413 auto sysSession = GetSystemSession("Hide01");
414 ASSERT_NE(sysSession, nullptr);
415
416 // for CheckPermissionWithPropertyAnimation;
417 auto windowProperty = sptr<WindowSessionProperty>::MakeSptr();
418 ASSERT_NE(windowProperty, nullptr);
419 windowProperty->animationFlag_ = static_cast<uint32_t>(WindowAnimation::CUSTOM);
420
421 sysSession->property_ = windowProperty;
422 // for TOAST or FLOAT permission
423 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT);
424
425 // for IsSessionValid
426 sysSession->sessionInfo_.isSystem_ = false;
427 sysSession->state_ = SessionState::STATE_CONNECT;
428 sysSession->isActive_ = true;
429
430 auto ret = sysSession->Hide();
431 usleep(WAIT_ASYNC_US);
432 ASSERT_EQ(ret, WSError::WS_OK);
433
434 windowProperty->animationFlag_ = static_cast<uint32_t>(WindowAnimation::DEFAULT);
435 ret = sysSession->Hide();
436 usleep(WAIT_ASYNC_US);
437 ASSERT_EQ(ret, WSError::WS_OK);
438
439 ret = sysSession->Hide();
440 sysSession->property_ = nullptr;
441 usleep(WAIT_ASYNC_US);
442 ASSERT_EQ(ret, WSError::WS_OK);
443 }
444
445 /**
446 * @tc.name: ProcessPointDownSession01
447 * @tc.desc: test function : ProcessPointDownSession
448 * @tc.type: FUNC
449 */
450 HWTEST_F(SystemSessionTest, ProcessPointDownSession01, Function | SmallTest | Level1)
451 {
452 auto sysSession = GetSystemSession("ProcessPointDownSession01");
453 ASSERT_NE(sysSession, nullptr);
454 sysSession->persistentId_ = 1;
455 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
456 sysSession->state_ = SessionState::STATE_ACTIVE;
457
458 auto parentSesssion = GetSceneSession("parentSession");
459 ASSERT_NE(parentSesssion, nullptr);
460 sysSession->parentSession_ = parentSesssion;
461
462 parentSesssion->dialogVec_.push_back(sysSession);
463 auto ret = sysSession->ProcessPointDownSession(0, 0);
464 ASSERT_EQ(ret, WSError::WS_OK);
465
466 // for IsTopDialog true
467 auto topDialog = GetSystemSession("TopDialogSession");
468 ASSERT_NE(topDialog, nullptr);
469 topDialog->persistentId_ = 2;
470 topDialog->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
471 topDialog->state_ = SessionState::STATE_ACTIVE;
472 parentSesssion->dialogVec_.push_back(topDialog);
473
474 ret = sysSession->ProcessPointDownSession(0, 0);
475 ASSERT_EQ(ret, WSError::WS_OK);
476 }
477
478 /**
479 * @tc.name: ProcessPointDownSession02
480 * @tc.desc: test function : ProcessPointDownSession
481 * @tc.type: FUNC
482 */
483 HWTEST_F(SystemSessionTest, ProcessPointDownSession02, Function | SmallTest | Level1)
484 {
485 auto sysSession = GetSystemSession("ProcessPointDownSession02");
486 ASSERT_NE(sysSession, nullptr);
487 sysSession->persistentId_ = 1;
488 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
489 sysSession->state_ = SessionState::STATE_ACTIVE;
490
491 sysSession->property_->raiseEnabled_ = false;
492 auto ret = sysSession->ProcessPointDownSession(0, 0);
493 ASSERT_EQ(ret, WSError::WS_OK);
494
495 sysSession->property_->raiseEnabled_ = true;
496 ret = sysSession->ProcessPointDownSession(0, 0);
497 ASSERT_EQ(ret, WSError::WS_OK);
498 }
499
500 /**
501 * @tc.name: TransferKeyEvent04
502 * @tc.desc: test function : TransferKeyEvent
503 * @tc.type: FUNC
504 */
505 HWTEST_F(SystemSessionTest, TransferKeyEvent04, Function | SmallTest | Level1)
506 {
507 auto sysSession = GetSystemSession("TransferKeyEvent04");
508 ASSERT_NE(sysSession, nullptr);
509 sysSession->persistentId_ = 1;
510 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
511 sysSession->state_ = SessionState::STATE_ACTIVE;
512
513 std::shared_ptr<MMI::KeyEvent> keyEvent;
514
515 auto ret = sysSession->TransferKeyEvent(nullptr);
516 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
517
518 ret = sysSession->TransferKeyEvent(keyEvent);
519 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
520 }
521
522 /**
523 * @tc.name: TransferKeyEvent05
524 * @tc.desc: test function : TransferKeyEvent
525 * @tc.type: FUNC
526 */
527 HWTEST_F(SystemSessionTest, TransferKeyEvent05, Function | SmallTest | Level1)
528 {
529 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
530
531 auto sysSession = GetSystemSession("TransferKeyEvent05");
532 ASSERT_NE(sysSession, nullptr);
533 sysSession->persistentId_ = 1;
534 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
535 sysSession->state_ = SessionState::STATE_ACTIVE;
536
537 auto ret = sysSession->TransferKeyEvent(keyEvent);
538 ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
539
540 auto parentSesssion = GetSceneSession("parentSession");
541 ASSERT_NE(parentSesssion, nullptr);
542 sysSession->parentSession_ = parentSesssion;
543
544 // for CheckKeyEventDispatch return true;
545 parentSesssion->state_ = SessionState::STATE_FOREGROUND;
546 ret = sysSession->TransferKeyEvent(keyEvent);
547 ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
548
549 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
550 ret = sysSession->TransferKeyEvent(keyEvent);
551 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
552
553 keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_HOME);
554 parentSesssion->dialogVec_.push_back(sysSession);
555 ret = sysSession->TransferKeyEvent(keyEvent);
556 ASSERT_EQ(ret, WSError::WS_DO_NOTHING);
557
558 auto topDialog = GetSystemSession("TopDialogSession");
559 ASSERT_NE(topDialog, nullptr);
560 topDialog->persistentId_ = 2;
561 topDialog->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
562 topDialog->state_ = SessionState::STATE_ACTIVE;
563 parentSesssion->dialogVec_.push_back(topDialog);
564 ret = sysSession->TransferKeyEvent(keyEvent);
565 ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_PERMISSION);
566 }
567
568 /**
569 * @tc.name: ProcessBackEvent02
570 * @tc.desc: test function : ProcessBackEvent
571 * @tc.type: FUNC
572 */
573 HWTEST_F(SystemSessionTest, ProcessBackEvent02, Function | SmallTest | Level1)
574 {
575 auto sysSession = GetSystemSession("ProcessBackEvent02");
576 ASSERT_NE(sysSession, nullptr);
577 sysSession->persistentId_ = 1;
578 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
579 sysSession->state_ = SessionState::STATE_ACTIVE;
580
581 sysSession->dialogSessionBackGestureEnabled_ = false;
582 auto ret = sysSession->ProcessBackEvent();
583 ASSERT_EQ(ret, WSError::WS_OK);
584
585 sysSession->dialogSessionBackGestureEnabled_ = true;
586 ret = sysSession->ProcessBackEvent();
587 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
588
589 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
590 ret = sysSession->ProcessBackEvent();
591 ASSERT_EQ(ret, WSError::WS_ERROR_NULLPTR);
592 }
593
594 /**
595 * @tc.name: CheckKeyEventDispatch03
596 * @tc.desc: test function : CheckKeyEventDispatch
597 * @tc.type: FUNC
598 */
599 HWTEST_F(SystemSessionTest, CheckKeyEventDispatch03, Function | SmallTest | Level1)
600 {
601 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
602 auto sysSession = GetSystemSession("CheckKeyEventDispatch03");
603 ASSERT_NE(sysSession, nullptr);
604 sysSession->persistentId_ = 1;
605 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
606 sysSession->state_ = SessionState::STATE_ACTIVE;
607 sysSession->isRSVisible_ = false;
608
609 auto ret = sysSession->CheckKeyEventDispatch(keyEvent);
610 ASSERT_EQ(ret, false);
611
612 sysSession->isRSVisible_ = true;
613 sysSession->winRect_.width_ = 0;
614 ret = sysSession->CheckKeyEventDispatch(keyEvent);
615 ASSERT_EQ(ret, false);
616
617 sysSession->isRSVisible_ = true;
618 sysSession->winRect_.width_ = 1;
619 sysSession->winRect_.height_ = 0;
620 ret = sysSession->CheckKeyEventDispatch(keyEvent);
621 ASSERT_EQ(ret, false);
622
623 sysSession->isRSVisible_ = true;
624 sysSession->winRect_.width_ = 1;
625 sysSession->winRect_.height_ = 1;
626 ret = sysSession->CheckKeyEventDispatch(keyEvent);
627 ASSERT_EQ(ret, false);
628 }
629
630 /**
631 * @tc.name: CheckKeyEventDispatch04
632 * @tc.desc: test function : CheckKeyEventDispatch
633 * @tc.type: FUNC
634 */
635 HWTEST_F(SystemSessionTest, CheckKeyEventDispatch04, Function | SmallTest | Level1)
636 {
637 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
638 auto sysSession = GetSystemSession("CheckKeyEventDispatch04");
639 ASSERT_NE(sysSession, nullptr);
640 sysSession->persistentId_ = 1;
641 sysSession->isRSVisible_ = true;
642 sysSession->winRect_.width_ = 1;
643 sysSession->winRect_.height_ = 1;
644 sysSession->state_ = SessionState::STATE_DISCONNECT;
645
646 auto parentSesssion = GetSceneSession("parentSession");
647 ASSERT_NE(parentSesssion, nullptr);
648 sysSession->parentSession_ = parentSesssion;
649
650 parentSesssion->state_ = SessionState::STATE_FOREGROUND;
651 auto ret = sysSession->CheckKeyEventDispatch(keyEvent);
652 ASSERT_EQ(ret, false);
653
654 parentSesssion->state_ = SessionState::STATE_ACTIVE;
655 ret = sysSession->CheckKeyEventDispatch(keyEvent);
656 ASSERT_EQ(ret, false);
657
658 parentSesssion->state_ = SessionState::STATE_DISCONNECT;
659 sysSession->state_ = SessionState::STATE_FOREGROUND;
660 ret = sysSession->CheckKeyEventDispatch(keyEvent);
661 ASSERT_EQ(ret, false);
662
663 sysSession->state_ = SessionState::STATE_ACTIVE;
664 ret = sysSession->CheckKeyEventDispatch(keyEvent);
665 ASSERT_EQ(ret, false);
666
667 parentSesssion->state_ = SessionState::STATE_DISCONNECT;
668 sysSession->state_ = SessionState::STATE_DISCONNECT;
669 ret = sysSession->CheckKeyEventDispatch(keyEvent);
670 ASSERT_EQ(ret, false);
671 }
672
673 /**
674 * @tc.name: NotifyClientToUpdateRect03
675 * @tc.desc: test function : NotifyClientToUpdateRect
676 * @tc.type: FUNC
677 */
678 HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect03, Function | SmallTest | Level1)
679 {
680 auto sysSession = GetSystemSession("NotifyClientToUpdateRect03");
681 ASSERT_NE(sysSession, nullptr);
682 sysSession->persistentId_ = 1;
683 sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYBOARD_PANEL);
684 sysSession->state_ = SessionState::STATE_ACTIVE;
685
686 sysSession->dirtyFlags_ = 0;
687 sysSession->isKeyboardPanelEnabled_ = true;
688 sysSession->reason_ = SizeChangeReason::MAXIMIZE;
689
690 sptr<SceneSession::SpecificSessionCallback> specificCallback =
691 sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
692 ASSERT_NE(specificCallback, nullptr);
693 sysSession->specificCallback_ = specificCallback;
694 sysSession->specificCallback_->onUpdateAvoidArea_ = nullptr;
695 sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
696 usleep(WAIT_ASYNC_US);
697 EXPECT_EQ(sysSession->dirtyFlags_, 0);
698
699 sysSession->dirtyFlags_ = 0;
700 sysSession->SetScbCoreEnabled(true);
701 sysSession->reason_ = SizeChangeReason::MAXIMIZE;
__anon83b86f990402(const int32_t& persistentId) 702 sysSession->specificCallback_->onUpdateAvoidArea_ = [](const int32_t& persistentId) {};
703 sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr);
704 usleep(WAIT_ASYNC_US);
705 EXPECT_EQ(sysSession->dirtyFlags_, static_cast<uint32_t>(SessionUIDirtyFlag::AVOID_AREA));
706 }
707
708 } // namespace
709 } // namespace Rosen
710 } // namespace OHOS
711