1 /* 2 * Copyright (c) 2021-2022 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 18 #include "anr_manager.h" 19 #include "define_multimodal.h" 20 #include "event_dispatch_handler.h" 21 #include "i_input_windows_manager.h" 22 #include "input_event_handler.h" 23 #include "pointer_event.h" 24 25 namespace OHOS { 26 namespace MMI { 27 namespace { 28 using namespace testing::ext; 29 constexpr int32_t UID_ROOT { 0 }; 30 static constexpr char PROGRAM_NAME[] { "uds_sesion_test" }; 31 int32_t g_moduleType { 3 }; 32 int32_t g_pid { 0 }; 33 int32_t g_writeFd { -1 }; 34 } // namespace 35 36 class EventDispatchTest : public testing::Test { 37 public: SetUpTestCase(void)38 static void SetUpTestCase(void) {} TearDownTestCase(void)39 static void TearDownTestCase(void) {} 40 }; 41 42 /** 43 * @tc.name: DispatchPointerEventInner_06 44 * @tc.desc: Test the funcation DispatchKeyEvent 45 * @tc.type: FUNC 46 * @tc.require: 47 */ 48 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_06, TestSize.Level1) 49 { 50 EventDispatchHandler handler; 51 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 52 ASSERT_NE(point, nullptr); 53 int32_t fd = -5; 54 auto inputEvent = InputEvent::Create(); 55 ASSERT_NE(inputEvent, nullptr); 56 inputEvent->actionTime_ = 3100; 57 handler.eventTime_ = 10; 58 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 59 inputEvent->actionTime_ = 200; 60 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 61 fd = 5; 62 bool status = true; 63 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, 1, 1, 100, 100); 64 session->SetTokenType(TokenType::TOKEN_HAP); 65 session->SetAnrStatus(0, status); 66 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 67 status = false; 68 point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 69 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 70 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 71 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 72 point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN; 73 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 74 point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP; 75 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 76 point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_MOVE; 77 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 78 point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 79 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 80 point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW; 81 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 82 point->pointerAction_ = PointerEvent::POINTER_ACTION_AXIS_END; 83 ASSERT_NO_FATAL_FAILURE(handler.DispatchPointerEventInner(point, fd)); 84 } 85 86 /** 87 * @tc.name: EventDispatchTest_DispatchKeyEvent_001 88 * @tc.desc: Test the funcation DispatchKeyEvent 89 * @tc.type: FUNC 90 * @tc.require: 91 */ 92 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_001, TestSize.Level1) 93 { 94 EventDispatchHandler handler; 95 int32_t fd = -2; 96 UDSServer udsServer; 97 std::shared_ptr<KeyEvent> key = KeyEvent::Create(); 98 ASSERT_NE(key, nullptr); 99 auto inputEvent = InputEvent::Create(); 100 ASSERT_NE(inputEvent, nullptr); 101 inputEvent->actionTime_ = 4000; 102 handler.eventTime_ = 200; 103 int32_t ret = handler.DispatchKeyEvent(fd, udsServer, key); 104 EXPECT_EQ(ret, RET_ERR); 105 inputEvent->actionTime_ = 2000; 106 ret = handler.DispatchKeyEvent(fd, udsServer, key); 107 EXPECT_EQ(ret, RET_ERR); 108 fd = 9; 109 bool status = true; 110 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, 1, 1, 100, 100); 111 session->SetTokenType(TokenType::TOKEN_HAP); 112 session->SetAnrStatus(0, status); 113 ret = handler.DispatchKeyEvent(fd, udsServer, key); 114 EXPECT_EQ(ret, RET_ERR); 115 status = false; 116 StreamBuffer streamBuffer; 117 streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ; 118 ret = handler.DispatchKeyEvent(fd, udsServer, key); 119 EXPECT_EQ(ret, RET_ERR); 120 streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK; 121 udsServer.pid_ = 1; 122 ret = handler.DispatchKeyEvent(fd, udsServer, key); 123 EXPECT_EQ(ret, RET_ERR); 124 udsServer.pid_ = -1; 125 ret = handler.DispatchKeyEvent(fd, udsServer, key); 126 EXPECT_EQ(ret, RET_ERR); 127 } 128 129 /** 130 * @tc.name: EventDispatchTest_DispatchKeyEventPid_01 131 * @tc.desc: Test DispatchKeyEventPid 132 * @tc.type: FUNC 133 * @tc.require: 134 */ 135 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_01, TestSize.Level1) 136 { 137 EventDispatchHandler dispatch; 138 UDSServer udsServer; 139 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 140 ASSERT_NE(keyEvent, nullptr); 141 std::vector<std::pair<int32_t, TargetInfo>> vecTarget; 142 143 TargetInfo target1; 144 target1.privacyMode = SecureFlag::PRIVACY_MODE; 145 target1.id = 1; 146 target1.agentWindowId = 3; 147 vecTarget.push_back(std::make_pair(1, target1)); 148 149 TargetInfo target2; 150 target2.privacyMode = SecureFlag::PRIVACY_MODE; 151 target2.id = 2; 152 target2.agentWindowId = 5; 153 vecTarget.push_back(std::make_pair(2, target2)); 154 155 int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent); 156 EXPECT_EQ(ret, RET_OK); 157 } 158 159 /** 160 * @tc.name: EventDispatchTest_DispatchKeyEventPid_02 161 * @tc.desc: Test DispatchKeyEventPid 162 * @tc.type: FUNC 163 * @tc.require: 164 */ 165 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_02, TestSize.Level1) 166 { 167 EventDispatchHandler dispatch; 168 UDSServer udsServer; 169 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 170 ASSERT_NE(keyEvent, nullptr); 171 std::vector<std::pair<int32_t, TargetInfo>> vecTarget; 172 173 TargetInfo target1; 174 target1.privacyMode = SecureFlag::DEFAULT_MODE; 175 target1.id = 2; 176 target1.agentWindowId = 5; 177 vecTarget.push_back(std::make_pair(1, target1)); 178 179 TargetInfo target2; 180 target2.privacyMode = SecureFlag::DEFAULT_MODE; 181 target2.id = 3; 182 target2.agentWindowId = 6; 183 vecTarget.push_back(std::make_pair(2, target2)); 184 185 int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent); 186 EXPECT_EQ(ret, RET_OK); 187 } 188 189 /** 190 * @tc.name: DispatchPointerEventInner_01 191 * @tc.desc: Test DispatchKeyEvent 192 * @tc.type: FUNC 193 * @tc.require: 194 */ 195 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_01, TestSize.Level1) 196 { 197 EventDispatchHandler dispatch; 198 UDSServer udsServer; 199 int32_t fd = 2; 200 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 201 ASSERT_NE(pointerEvent, nullptr); 202 auto currentTime = GetSysClockTime(); 203 auto session = udsServer.GetSession(fd); 204 bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session); 205 EXPECT_FALSE(ret); 206 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 207 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 208 } 209 210 /** 211 * @tc.name: DispatchPointerEventInner_02 212 * @tc.desc: Test DispatchKeyEvent 213 * @tc.type: FUNC 214 * @tc.require: 215 */ 216 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_02, TestSize.Level1) 217 { 218 EventDispatchHandler dispatch; 219 UDSServer udsServer; 220 int32_t fd = 3; 221 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 222 ASSERT_NE(pointerEvent, nullptr); 223 auto currentTime = GetSysClockTime(); 224 auto session = udsServer.GetSession(fd); 225 bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session); 226 EXPECT_FALSE(ret); 227 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 228 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 229 } 230 231 /** 232 * @tc.name: DispatchPointerEventInner_03 233 * @tc.desc: Test DispatchKeyEvent 234 * @tc.type: FUNC 235 * @tc.require: 236 */ 237 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_03, TestSize.Level1) 238 { 239 EventDispatchHandler dispatch; 240 UDSServer udsServer; 241 int32_t fd = 3; 242 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 243 ASSERT_NE(pointerEvent, nullptr); 244 auto currentTime = GetSysClockTime(); 245 auto session = udsServer.GetSession(fd); 246 bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session); 247 EXPECT_FALSE(ret); 248 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN; 249 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 250 } 251 252 /** 253 * @tc.name: DispatchPointerEventInner_04 254 * @tc.desc: Test DispatchKeyEvent 255 * @tc.type: FUNC 256 * @tc.require: 257 */ 258 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_04, TestSize.Level1) 259 { 260 EventDispatchHandler dispatch; 261 UDSServer udsServer; 262 int32_t fd = 3; 263 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 264 ASSERT_NE(pointerEvent, nullptr); 265 auto currentTime = GetSysClockTime(); 266 auto session = udsServer.GetSession(fd); 267 bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session); 268 EXPECT_FALSE(ret); 269 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP; 270 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 271 } 272 273 /** 274 * @tc.name: DispatchPointerEventInner_05 275 * @tc.desc: Test DispatchKeyEvent 276 * @tc.type: FUNC 277 * @tc.require: 278 */ 279 HWTEST_F(EventDispatchTest, DispatchPointerEventInner_05, TestSize.Level1) 280 { 281 EventDispatchHandler dispatch; 282 UDSServer udsServer; 283 int32_t fd = 3; 284 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 285 ASSERT_NE(pointerEvent, nullptr); 286 auto currentTime = GetSysClockTime(); 287 auto session = udsServer.GetSession(fd); 288 bool ret = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session); 289 EXPECT_FALSE(ret); 290 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 291 292 NetPacket pkt(MmiMessageId::INVALID); 293 EXPECT_FALSE(udsServer.SendMsg(fd, pkt)); 294 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 295 } 296 297 /** 298 * @tc.name: EventDispatchTest_DispatchKeyEvent_01 299 * @tc.desc: Test DispatchKeyEvent 300 * @tc.type: FUNC 301 * @tc.require: 302 */ 303 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_01, TestSize.Level1) 304 { 305 EventDispatchHandler dispatch; 306 UDSServer udsServer; 307 int32_t fd; 308 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 309 ASSERT_NE(keyEvent, nullptr); 310 311 int32_t currentTime = dispatch.currentTime_; 312 int32_t eventTime = dispatch.eventTime_; 313 int32_t INTERVAL_TIME = 3000; 314 currentTime = 6000; 315 eventTime = 1000; 316 EXPECT_TRUE(currentTime - eventTime > INTERVAL_TIME); 317 fd = -1; 318 int32_t ret = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent); 319 EXPECT_EQ(ret, RET_ERR); 320 } 321 322 /** 323 * @tc.name: EventDispatchTest_DispatchKeyEvent_02 324 * @tc.desc: Test DispatchKeyEvent 325 * @tc.type: FUNC 326 * @tc.require: 327 */ 328 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_02, TestSize.Level1) 329 { 330 EventDispatchHandler dispatch; 331 UDSServer udsServer; 332 int32_t fd; 333 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 334 ASSERT_NE(keyEvent, nullptr); 335 336 int32_t currentTime = dispatch.currentTime_; 337 int32_t eventTime = dispatch.eventTime_; 338 int32_t INTERVAL_TIME = 3000; 339 currentTime = 2000; 340 eventTime = 1000; 341 EXPECT_FALSE(currentTime - eventTime > INTERVAL_TIME); 342 fd = 1; 343 int32_t ret = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent); 344 EXPECT_EQ(ret, RET_ERR); 345 } 346 347 /** 348 * @tc.name: EventDispatchTest_DispatchKeyEvent_03 349 * @tc.desc: Test DispatchKeyEvent 350 * @tc.type: FUNC 351 * @tc.require: 352 */ 353 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_03, TestSize.Level1) 354 { 355 EventDispatchHandler dispatch; 356 UDSServer udsServer; 357 int32_t fd = 2; 358 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 359 ASSERT_NE(keyEvent, nullptr); 360 auto currentTime = GetSysClockTime(); 361 auto session = udsServer.GetSession(fd); 362 363 bool ret1 = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session); 364 EXPECT_FALSE(ret1); 365 int32_t ret2 = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent); 366 EXPECT_EQ(ret2, RET_ERR); 367 } 368 369 /** 370 * @tc.name: EventDispatchTest_DispatchKeyEvent_04 371 * @tc.desc: Test DispatchKeyEvent 372 * @tc.type: FUNC 373 * @tc.require: 374 */ 375 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_04, TestSize.Level1) 376 { 377 EventDispatchHandler dispatch; 378 UDSServer udsServer; 379 int32_t fd = -1; 380 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 381 ASSERT_NE(keyEvent, nullptr); 382 383 int32_t currentTime = dispatch.currentTime_; 384 int32_t eventTime = dispatch.eventTime_; 385 int32_t INTERVAL_TIME = 3000; 386 currentTime = 2000; 387 eventTime = 1000; 388 EXPECT_FALSE(currentTime - eventTime > INTERVAL_TIME); 389 390 auto currentTime1 = GetSysClockTime(); 391 auto session = udsServer.GetSession(fd); 392 bool ret1 = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime1, session); 393 EXPECT_FALSE(ret1); 394 int32_t ret2 = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent); 395 EXPECT_EQ(ret2, RET_ERR); 396 } 397 398 /** 399 * @tc.name: EventDispatchTest_DispatchKeyEvent_05 400 * @tc.desc: Test DispatchKeyEvent 401 * @tc.type: FUNC 402 * @tc.require: 403 */ 404 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_05, TestSize.Level1) 405 { 406 EventDispatchHandler dispatch; 407 UDSServer udsServer; 408 int32_t fd = 2; 409 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 410 ASSERT_NE(keyEvent, nullptr); 411 auto currentTime = GetSysClockTime(); 412 auto session = udsServer.GetSession(fd); 413 bool ret1 = ANRMgr->TriggerANR(ANR_DISPATCH, currentTime, session); 414 EXPECT_FALSE(ret1); 415 NetPacket pkt(MmiMessageId::INVALID); 416 EXPECT_FALSE(pkt.ChkRWError()); 417 EXPECT_FALSE(udsServer.SendMsg(fd, pkt)); 418 int32_t ret2 = dispatch.DispatchKeyEvent(fd, udsServer, keyEvent); 419 EXPECT_EQ(ret2, RET_ERR); 420 } 421 422 /** 423 * @tc.name: FilterInvalidPointerItem_01 424 * @tc.desc: Test the function FilterInvalidPointerItem 425 * @tc.type: FUNC 426 * @tc.require: 427 */ 428 HWTEST_F(EventDispatchTest, FilterInvalidPointerItem_01, TestSize.Level1) 429 { 430 EventDispatchHandler eventdispatchhandler; 431 int32_t fd = 1; 432 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 433 ASSERT_NE(pointerEvent, nullptr); 434 435 std::vector<int32_t> pointerIdList; 436 pointerEvent->pointerId_ = 3; 437 pointerIdList.push_back(pointerEvent->pointerId_); 438 pointerEvent->pointerId_ = 5; 439 pointerIdList.push_back(pointerEvent->pointerId_); 440 EXPECT_TRUE(pointerIdList.size() > 1); 441 442 PointerEvent::PointerItem pointeritem; 443 pointeritem.SetWindowX(10); 444 pointeritem.SetWindowY(20); 445 pointeritem.SetTargetWindowId(2); 446 int32_t id = 1; 447 EXPECT_FALSE(pointerEvent->GetPointerItem(id, pointeritem)); 448 449 pointeritem.targetWindowId_ = 3; 450 auto itemPid = WIN_MGR->GetWindowPid(pointeritem.targetWindowId_); 451 EXPECT_FALSE(itemPid >= 0); 452 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd)); 453 } 454 455 /** 456 * @tc.name: EventDispatchTest_HandleTouchEvent_001 457 * @tc.desc: Test the function HandleTouchEvent 458 * @tc.type: FUNC 459 * @tc.require: 460 */ 461 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleTouchEvent_001, TestSize.Level1) 462 { 463 EventDispatchHandler eventdispatchhandler; 464 int32_t eventType = 3; 465 std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType); 466 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleTouchEvent(sharedPointerEvent)); 467 } 468 469 /** 470 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_001 471 * @tc.desc: Test the function FilterInvalidPointerItem 472 * @tc.type: FUNC 473 * @tc.require: 474 */ 475 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_001, TestSize.Level1) 476 { 477 EventDispatchHandler eventdispatchhandler; 478 int32_t fd = 1; 479 int32_t eventType = 3; 480 std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType); 481 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd)); 482 } 483 484 /** 485 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_002 486 * @tc.desc: Test the function FilterInvalidPointerItem 487 * @tc.type: FUNC 488 * @tc.require: 489 */ 490 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_002, TestSize.Level1) 491 { 492 EventDispatchHandler eventdispatchhandler; 493 int32_t fd = 1; 494 int32_t eventType = 3; 495 std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType); 496 EXPECT_NE(sharedPointerEvent, nullptr); 497 498 std::vector<int32_t> pointerIdList; 499 pointerIdList.push_back(1); 500 pointerIdList.push_back(2); 501 EXPECT_TRUE(pointerIdList.size() > 1); 502 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd)); 503 } 504 505 /** 506 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_003 507 * @tc.desc: Test the function FilterInvalidPointerItem 508 * @tc.type: FUNC 509 * @tc.require: 510 */ 511 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_003, TestSize.Level1) 512 { 513 EventDispatchHandler eventdispatchhandler; 514 int32_t fd = 1; 515 int32_t eventType = 3; 516 std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType); 517 EXPECT_NE(sharedPointerEvent, nullptr); 518 519 std::vector<int32_t> pointerIdList; 520 pointerIdList.push_back(1); 521 pointerIdList.push_back(2); 522 pointerIdList.push_back(3); 523 EXPECT_TRUE(pointerIdList.size() > 1); 524 525 int32_t itemPid = 5; 526 EXPECT_TRUE(itemPid >= 0); 527 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd)); 528 } 529 530 /** 531 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_001 532 * @tc.desc: Test HandleMultiWindowPointerEvent 533 * @tc.type: FUNC 534 * @tc.require: 535 */ 536 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_001, TestSize.Level1) 537 { 538 EventDispatchHandler eventdispatchhandler; 539 int32_t eventType = 3; 540 std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType); 541 EXPECT_NE(point, nullptr); 542 543 std::vector<int32_t> windowIds; 544 windowIds.push_back(1); 545 windowIds.push_back(2); 546 windowIds.push_back(3); 547 548 PointerEvent::PointerItem pointerItem; 549 pointerItem.SetWindowX(10); 550 pointerItem.SetWindowY(20); 551 pointerItem.SetTargetWindowId(2); 552 553 std::optional<WindowInfo> windowInfo; 554 windowInfo = std::nullopt; 555 EXPECT_TRUE(windowInfo == std::nullopt); 556 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 557 } 558 559 /** 560 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_002 561 * @tc.desc: Test HandleMultiWindowPointerEvent 562 * @tc.type: FUNC 563 * @tc.require: 564 */ 565 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_002, TestSize.Level1) 566 { 567 EventDispatchHandler eventdispatchhandler; 568 int32_t eventType = 2; 569 std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType); 570 EXPECT_NE(point, nullptr); 571 572 std::vector<int32_t> windowIds; 573 windowIds.push_back(1); 574 windowIds.push_back(2); 575 windowIds.push_back(3); 576 577 PointerEvent::PointerItem pointerItem; 578 pointerItem.SetWindowX(20); 579 pointerItem.SetWindowY(30); 580 pointerItem.SetTargetWindowId(3); 581 582 std::optional<WindowInfo> windowInfo; 583 EXPECT_TRUE(windowInfo->transform.empty()); 584 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 585 } 586 587 /** 588 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_003 589 * @tc.desc: Test HandleMultiWindowPointerEvent 590 * @tc.type: FUNC 591 * @tc.require: 592 */ 593 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_003, TestSize.Level1) 594 { 595 EventDispatchHandler eventdispatchhandler; 596 int32_t eventType = 5; 597 std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType); 598 EXPECT_NE(point, nullptr); 599 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 600 601 std::vector<int32_t> windowIds; 602 windowIds.push_back(1); 603 windowIds.push_back(2); 604 windowIds.push_back(3); 605 606 PointerEvent::PointerItem pointerItem; 607 pointerItem.SetWindowX(30); 608 pointerItem.SetWindowY(40); 609 pointerItem.SetTargetWindowId(5); 610 611 std::optional<WindowInfo> windowInfo; 612 windowInfo = std::nullopt; 613 int32_t windowId = 2; 614 bool ret = eventdispatchhandler.ReissueEvent(point, windowId, windowInfo); 615 EXPECT_FALSE(ret); 616 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 617 } 618 619 /** 620 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_004 621 * @tc.desc: Test HandleMultiWindowPointerEvent 622 * @tc.type: FUNC 623 * @tc.require: 624 */ 625 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_004, TestSize.Level1) 626 { 627 EventDispatchHandler eventdispatchhandler; 628 int32_t eventType = 6; 629 std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType); 630 EXPECT_NE(point, nullptr); 631 point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 632 point->pointerId_ = 2; 633 634 std::vector<int32_t> windowIds; 635 windowIds.push_back(1); 636 windowIds.push_back(2); 637 windowIds.push_back(3); 638 639 PointerEvent::PointerItem pointerItem; 640 pointerItem.SetWindowX(40); 641 pointerItem.SetWindowY(50); 642 pointerItem.SetTargetWindowId(5); 643 644 std::optional<WindowInfo> windowInfo; 645 windowInfo = std::nullopt; 646 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 647 } 648 649 /** 650 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_005 651 * @tc.desc: Test HandleMultiWindowPointerEvent 652 * @tc.type: FUNC 653 * @tc.require: 654 */ 655 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_005, TestSize.Level1) 656 { 657 EventDispatchHandler eventdispatchhandler; 658 int32_t eventType = 6; 659 std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType); 660 EXPECT_NE(point, nullptr); 661 point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP; 662 663 std::vector<int32_t> windowIds; 664 windowIds.push_back(1); 665 windowIds.push_back(2); 666 windowIds.push_back(3); 667 668 PointerEvent::PointerItem pointerItem; 669 pointerItem.SetWindowX(45); 670 pointerItem.SetWindowY(55); 671 pointerItem.SetTargetWindowId(3); 672 673 std::optional<WindowInfo> windowInfo; 674 windowInfo = std::nullopt; 675 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 676 } 677 678 /** 679 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_006 680 * @tc.desc: Test HandleMultiWindowPointerEvent 681 * @tc.type: FUNC 682 * @tc.require: 683 */ 684 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_006, TestSize.Level1) 685 { 686 EventDispatchHandler eventdispatchhandler; 687 int32_t eventType = 6; 688 std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType); 689 EXPECT_NE(point, nullptr); 690 point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL; 691 692 std::vector<int32_t> windowIds; 693 windowIds.push_back(1); 694 windowIds.push_back(2); 695 windowIds.push_back(3); 696 697 PointerEvent::PointerItem pointerItem; 698 pointerItem.SetWindowX(35); 699 pointerItem.SetWindowY(50); 700 pointerItem.SetTargetWindowId(2); 701 702 std::optional<WindowInfo> windowInfo; 703 windowInfo = std::nullopt; 704 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 705 } 706 707 /** 708 * @tc.name: EventDispatchTest_NotifyPointerEventToRS_001 709 * @tc.desc: Test the function NotifyPointerEventToRS 710 * @tc.type: FUNC 711 * @tc.require: 712 */ 713 HWTEST_F(EventDispatchTest, EventDispatchTest_NotifyPointerEventToRS_001, TestSize.Level1) 714 { 715 EventDispatchHandler eventdispatchhandler; 716 int32_t action = 1; 717 std::string name = "ExampleProgram"; 718 uint32_t processId = 12345; 719 int32_t touchCnt = 0; 720 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.NotifyPointerEventToRS(action, name, processId, touchCnt)); 721 } 722 723 /** 724 * @tc.name: EventDispatchTest_HandlePointerEventInner_001 725 * @tc.desc: Test the function HandlePointerEventInner 726 * @tc.type: FUNC 727 * @tc.require: 728 */ 729 HWTEST_F(EventDispatchTest, EventDispatchTest_HandlePointerEventInner_001, TestSize.Level1) 730 { 731 EventDispatchHandler eventdispatchhandler; 732 int32_t eventType = 3; 733 PointerEvent* pointerEvent = new PointerEvent(eventType); 734 std::shared_ptr<PointerEvent> sharedPointerEvent(pointerEvent); 735 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandlePointerEventInner(sharedPointerEvent)); 736 } 737 738 /** 739 * @tc.name: EventDispatchTest_HandlePointerEventInner_002 740 * @tc.desc: Test the function HandlePointerEventInner 741 * @tc.type: FUNC 742 * @tc.require: 743 */ 744 HWTEST_F(EventDispatchTest, EventDispatchTest_HandlePointerEventInner_002, TestSize.Level1) 745 { 746 EventDispatchHandler eventdispatchhandler; 747 int32_t eventType = 3; 748 std::shared_ptr<PointerEvent> point = std::make_shared<PointerEvent>(eventType); 749 EXPECT_NE(point, nullptr); 750 std::vector<int32_t> windowIds; 751 windowIds.push_back(1); 752 windowIds.push_back(2); 753 EXPECT_FALSE(windowIds.empty()); 754 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandlePointerEventInner(point)); 755 } 756 757 /** 758 * @tc.name: EventDispatchTest_DispatchKeyEventPid_001 759 * @tc.desc: Test the function DispatchKeyEventPid 760 * @tc.type: FUNC 761 * @tc.require: 762 */ 763 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_001, TestSize.Level1) 764 { 765 EventDispatchHandler eventdispatchhandler; 766 UDSServer udsServer; 767 int32_t keyevent = 3; 768 KeyEvent* keyEvent = new KeyEvent(keyevent); 769 std::shared_ptr<KeyEvent> sharedKeyEvent(keyEvent); 770 int32_t ret = eventdispatchhandler.DispatchKeyEventPid(udsServer, sharedKeyEvent); 771 EXPECT_EQ(ret, 0); 772 } 773 774 /** 775 * @tc.name: EventDispatchTest_AcquireEnableMark 776 * @tc.desc: Test Acquire Enable Mark 777 * @tc.type: FUNC 778 * @tc.require: 779 */ 780 HWTEST_F(EventDispatchTest, EventDispatchTest_AcquireEnableMark, TestSize.Level1) 781 { 782 EventDispatchHandler dispatch; 783 std::shared_ptr<PointerEvent> event = PointerEvent::Create(); 784 ASSERT_NE(event, nullptr); 785 event->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); 786 ASSERT_FALSE(dispatch.AcquireEnableMark(event)); 787 event->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); 788 ASSERT_TRUE(dispatch.AcquireEnableMark(event)); 789 } 790 791 /** 792 * @tc.name: EventDispatchTest_DispatchPointerEventInner_001 793 * @tc.desc: Test Dispatch Pointer Event Inner 794 * @tc.type: FUNC 795 * @tc.require: 796 */ 797 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_001, TestSize.Level1) 798 { 799 EventDispatchHandler dispatch; 800 int32_t fd = -1; 801 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 802 ASSERT_NE(pointerEvent, nullptr); 803 dispatch.eventTime_ = 1000; 804 pointerEvent->SetActionTime(5000); 805 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 806 } 807 808 /** 809 * @tc.name: EventDispatchTest_DispatchPointerEventInner_002 810 * @tc.desc: Test Dispatch Pointer Event Inner 811 * @tc.type: FUNC 812 * @tc.require: 813 */ 814 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_002, TestSize.Level1) 815 { 816 EventDispatchHandler dispatch; 817 int32_t fd = -1; 818 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 819 ASSERT_NE(pointerEvent, nullptr); 820 int32_t currentTime = dispatch.currentTime_; 821 int32_t eventTime = dispatch.eventTime_; 822 int32_t INTERVAL_TIME = 3000; 823 currentTime = 6000; 824 eventTime = 1000; 825 EXPECT_TRUE(currentTime - eventTime > INTERVAL_TIME); 826 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 827 } 828 829 /** 830 * @tc.name: EventDispatchTest_DispatchPointerEventInner_003 831 * @tc.desc: Test Dispatch Pointer Event Inner 832 * @tc.type: FUNC 833 * @tc.require: 834 */ 835 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_003, TestSize.Level1) 836 { 837 EventDispatchHandler dispatch; 838 int32_t fd = 1; 839 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 840 ASSERT_NE(point, nullptr); 841 int32_t pointerAction; 842 pointerAction = PointerEvent::POINTER_ACTION_DOWN; 843 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(point, fd)); 844 } 845 846 /** 847 * @tc.name: EventDispatchTest_DispatchPointerEventInner_004 848 * @tc.desc: Test Dispatch Pointer Event Inner 849 * @tc.type: FUNC 850 * @tc.require: 851 */ 852 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_004, TestSize.Level1) 853 { 854 EventDispatchHandler dispatch; 855 SessionPtr sess = nullptr; 856 int32_t fd = 1; 857 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 858 ASSERT_NE(pointerEvent, nullptr); 859 860 int32_t type = 0; 861 int64_t time = 3000; 862 sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 863 bool ret = ANRMgr->TriggerANR(type, time, sess); 864 EXPECT_FALSE(ret); 865 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 866 } 867 868 /** 869 * @tc.name: EventDispatchTest_DispatchPointerEventInner_005 870 * @tc.desc: Test Dispatch Pointer Event Inner 871 * @tc.type: FUNC 872 * @tc.require: 873 */ 874 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_005, TestSize.Level1) 875 { 876 EventDispatchHandler dispatch; 877 SessionPtr sess = nullptr; 878 int32_t fd = 1; 879 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 880 ASSERT_NE(pointerEvent, nullptr); 881 882 int32_t type = 0; 883 int64_t time = 3000; 884 sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 885 bool ret = ANRMgr->TriggerANR(type, time, sess); 886 EXPECT_FALSE(ret); 887 888 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 889 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 890 } 891 892 /** 893 * @tc.name: EventDispatchTest_DispatchPointerEventInner_006 894 * @tc.desc: Test Dispatch Pointer Event Inner 895 * @tc.type: FUNC 896 * @tc.require: 897 */ 898 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_006, TestSize.Level1) 899 { 900 EventDispatchHandler dispatch; 901 SessionPtr sess = nullptr; 902 int32_t fd = 2; 903 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 904 ASSERT_NE(pointerEvent, nullptr); 905 906 int32_t type = 0; 907 int64_t time = 3000; 908 sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 909 bool ret = ANRMgr->TriggerANR(type, time, sess); 910 EXPECT_FALSE(ret); 911 912 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 913 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 914 } 915 916 /** 917 * @tc.name: EventDispatchTest_DispatchPointerEventInner_007 918 * @tc.desc: Test Dispatch Pointer Event Inner 919 * @tc.type: FUNC 920 * @tc.require: 921 */ 922 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_007, TestSize.Level1) 923 { 924 EventDispatchHandler dispatch; 925 SessionPtr sess = nullptr; 926 int32_t fd = 2; 927 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 928 ASSERT_NE(pointerEvent, nullptr); 929 930 int32_t type = 0; 931 int64_t time = 3000; 932 sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 933 bool ret = ANRMgr->TriggerANR(type, time, sess); 934 EXPECT_FALSE(ret); 935 936 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN; 937 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 938 } 939 940 /** 941 * @tc.name: EventDispatchTest_DispatchPointerEventInner_008 942 * @tc.desc: Test Dispatch Pointer Event Inner 943 * @tc.type: FUNC 944 * @tc.require: 945 */ 946 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_008, TestSize.Level1) 947 { 948 EventDispatchHandler dispatch; 949 SessionPtr sess = nullptr; 950 int32_t fd = 2; 951 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 952 ASSERT_NE(pointerEvent, nullptr); 953 954 int32_t type = 0; 955 int64_t time = 3000; 956 sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 957 bool ret = ANRMgr->TriggerANR(type, time, sess); 958 EXPECT_FALSE(ret); 959 960 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP; 961 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 962 } 963 964 /** 965 * @tc.name: EventDispatchTest_DispatchPointerEventInner_009 966 * @tc.desc: Test Dispatch Pointer Event Inner 967 * @tc.type: FUNC 968 * @tc.require: 969 */ 970 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_009, TestSize.Level1) 971 { 972 EventDispatchHandler dispatch; 973 SessionPtr sess = nullptr; 974 int32_t fd = 2; 975 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 976 ASSERT_NE(pointerEvent, nullptr); 977 978 int32_t type = 0; 979 int64_t time = 3000; 980 sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 981 bool ret = ANRMgr->TriggerANR(type, time, sess); 982 EXPECT_FALSE(ret); 983 984 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 985 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 986 } 987 988 /** 989 * @tc.name: EventDispatchTest_DispatchKeyEventPid_002 990 * @tc.desc: Test Dispatch Key Event Pid 991 * @tc.type: FUNC 992 * @tc.require: 993 */ 994 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_002, TestSize.Level1) 995 { 996 EventDispatchHandler dispatch; 997 UDSServer udsServer; 998 std::shared_ptr<KeyEvent> KeyEvent = KeyEvent::Create(); 999 ASSERT_NE(KeyEvent, nullptr); 1000 dispatch.eventTime_ = 1000; 1001 KeyEvent->SetActionTime(5000); 1002 ASSERT_EQ(dispatch.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK); 1003 } 1004 1005 /** 1006 * @tc.name: EventDispatchTest_DispatchKeyEventPid_003 1007 * @tc.desc: Test DispatchKeyEventPid 1008 * @tc.type: FUNC 1009 * @tc.require: 1010 */ 1011 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_003, TestSize.Level1) 1012 { 1013 EventDispatchHandler dispatch; 1014 UDSServer udsServer; 1015 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 1016 ASSERT_NE(keyEvent, nullptr); 1017 int32_t currentTime = dispatch.currentTime_; 1018 int32_t eventTime = dispatch.eventTime_; 1019 int32_t INTERVAL_TIME = 3000; 1020 currentTime = 6000; 1021 eventTime = 1000; 1022 EXPECT_TRUE(currentTime - eventTime > INTERVAL_TIME); 1023 int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent); 1024 EXPECT_EQ(ret, RET_OK); 1025 } 1026 1027 /** 1028 * @tc.name: EventDispatchTest_DispatchKeyEventPid_004 1029 * @tc.desc: Test DispatchKeyEventPid 1030 * @tc.type: FUNC 1031 * @tc.require: 1032 */ 1033 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_004, TestSize.Level1) 1034 { 1035 EventDispatchHandler dispatch; 1036 UDSServer udsServer; 1037 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 1038 ASSERT_NE(keyEvent, nullptr); 1039 1040 NetPacket pkt(MmiMessageId::INVALID); 1041 EXPECT_FALSE(pkt.ChkRWError()); 1042 int32_t ret = dispatch.DispatchKeyEventPid(udsServer, keyEvent); 1043 EXPECT_EQ(ret, RET_OK); 1044 } 1045 1046 /** 1047 * @tc.name: EventDispatchTest_DispatchKeyEventPid_005 1048 * @tc.desc: Test DispatchKeyEventPid 1049 * @tc.type: FUNC 1050 * @tc.require: 1051 */ 1052 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_005, TestSize.Level1) 1053 { 1054 EventDispatchHandler dispatch; 1055 UDSServer udsServer; 1056 SessionPtr sess = nullptr; 1057 std::shared_ptr<KeyEvent> KeyEvent = KeyEvent::Create(); 1058 ASSERT_NE(KeyEvent, nullptr); 1059 dispatch.eventTime_ = 1000; 1060 KeyEvent->SetActionTime(2000); 1061 1062 int32_t type = 0; 1063 int64_t time = 2000; 1064 sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1065 bool ret = ANRMgr->TriggerANR(type, time, sess); 1066 EXPECT_FALSE(ret); 1067 1068 ASSERT_EQ(dispatch.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK); 1069 } 1070 1071 /** 1072 * @tc.name: EventDispatchTest_ReissueEvent_001 1073 * @tc.desc: Test ReissueEvent 1074 * @tc.type: FUNC 1075 * @tc.require: 1076 */ 1077 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_001, TestSize.Level1) 1078 { 1079 EventDispatchHandler dispatch; 1080 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1081 ASSERT_NE(point, nullptr); 1082 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1083 int32_t windowId = 100; 1084 std::optional<WindowInfo> windowInfo = std::nullopt; 1085 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1086 EXPECT_FALSE(result); 1087 } 1088 1089 /** 1090 * @tc.name: EventDispatchTest_ReissueEvent_002 1091 * @tc.desc: Test ReissueEvent 1092 * @tc.type: FUNC 1093 * @tc.require: 1094 */ 1095 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_002, TestSize.Level1) 1096 { 1097 EventDispatchHandler dispatch; 1098 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1099 ASSERT_NE(point, nullptr); 1100 point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 1101 int32_t windowId = 100; 1102 std::optional<WindowInfo> windowInfo = std::nullopt; 1103 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1104 EXPECT_FALSE(result); 1105 } 1106 1107 /** 1108 * @tc.name: EventDispatchTest_ReissueEvent_003 1109 * @tc.desc: Test ReissueEvent 1110 * @tc.type: FUNC 1111 * @tc.require: 1112 */ 1113 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_003, TestSize.Level1) 1114 { 1115 EventDispatchHandler handler; 1116 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1117 ASSERT_NE(point, nullptr); 1118 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1119 int32_t windowId = 1; 1120 point->pointerId_ = 1; 1121 point->SetPointerId(point->pointerId_); 1122 std::optional<WindowInfo> windowInfo = std::nullopt; 1123 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1124 windowInfo1->id = 1; 1125 handler.cancelEventList_[1].push_back(windowInfo1); 1126 bool result = handler.ReissueEvent(point, windowId, windowInfo); 1127 EXPECT_TRUE(result); 1128 } 1129 1130 /** 1131 * @tc.name: EventDispatchTest_ReissueEvent_004 1132 * @tc.desc: Test ReissueEvent 1133 * @tc.type: FUNC 1134 * @tc.require: 1135 */ 1136 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_004, TestSize.Level1) 1137 { 1138 EventDispatchHandler handler; 1139 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1140 ASSERT_NE(point, nullptr); 1141 point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 1142 int32_t windowId = 1; 1143 point->pointerId_ = 1; 1144 point->SetPointerId(point->pointerId_); 1145 std::optional<WindowInfo> windowInfo = std::nullopt; 1146 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1147 windowInfo1->id = 1; 1148 handler.cancelEventList_[1].push_back(windowInfo1); 1149 bool result = handler.ReissueEvent(point, windowId, windowInfo); 1150 EXPECT_FALSE(result); 1151 } 1152 1153 /** 1154 * @tc.name: EventDispatchTest_ReissueEvent_005 1155 * @tc.desc: Test ReissueEvent 1156 * @tc.type: FUNC 1157 * @tc.require: 1158 */ 1159 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_005, TestSize.Level1) 1160 { 1161 EventDispatchHandler dispatch; 1162 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1163 ASSERT_NE(point, nullptr); 1164 point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 1165 int32_t windowId = 100; 1166 std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>(); 1167 ASSERT_NE(windowInfo, std::nullopt); 1168 point->pointerId_ = 1; 1169 point->SetPointerId(point->pointerId_); 1170 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1171 windowInfo1->id = 1; 1172 dispatch.cancelEventList_[1].push_back(windowInfo1); 1173 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1174 EXPECT_TRUE(result); 1175 } 1176 1177 /** 1178 * @tc.name: EventDispatchTest_ReissueEvent_006 1179 * @tc.desc: Test ReissueEvent 1180 * @tc.type: FUNC 1181 * @tc.require: 1182 */ 1183 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_006, TestSize.Level1) 1184 { 1185 EventDispatchHandler dispatch; 1186 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1187 ASSERT_NE(point, nullptr); 1188 point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 1189 int32_t windowId = 100; 1190 std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>(); 1191 ASSERT_NE(windowInfo, std::nullopt); 1192 point->pointerId_ = 5; 1193 point->SetPointerId(point->pointerId_); 1194 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1195 windowInfo1->id = 1; 1196 dispatch.cancelEventList_[1].push_back(windowInfo1); 1197 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1198 EXPECT_TRUE(result); 1199 } 1200 1201 /** 1202 * @tc.name: EventDispatchTest_ReissueEvent_007 1203 * @tc.desc: Test ReissueEvent 1204 * @tc.type: FUNC 1205 * @tc.require: 1206 */ 1207 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_007, TestSize.Level1) 1208 { 1209 EventDispatchHandler dispatch; 1210 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1211 ASSERT_NE(point, nullptr); 1212 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1213 int32_t windowId = 100; 1214 std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>(); 1215 ASSERT_NE(windowInfo, std::nullopt); 1216 point->pointerId_ = 1; 1217 point->SetPointerId(point->pointerId_); 1218 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1219 windowInfo1->id = 1; 1220 dispatch.cancelEventList_[1].push_back(windowInfo1); 1221 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1222 EXPECT_FALSE(result); 1223 } 1224 1225 /** 1226 * @tc.name: EventDispatchTest_ReissueEvent_008 1227 * @tc.desc: Test ReissueEvent 1228 * @tc.type: FUNC 1229 * @tc.require: 1230 */ 1231 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_008, TestSize.Level1) 1232 { 1233 EventDispatchHandler dispatch; 1234 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1235 ASSERT_NE(point, nullptr); 1236 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1237 int32_t windowId = 100; 1238 std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>(); 1239 ASSERT_NE(windowInfo, std::nullopt); 1240 point->pointerId_ = 5; 1241 point->SetPointerId(point->pointerId_); 1242 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1243 windowInfo1->id = 1; 1244 dispatch.cancelEventList_[1].push_back(windowInfo1); 1245 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1246 EXPECT_FALSE(result); 1247 } 1248 1249 /** 1250 * @tc.name: EventDispatchTest_ReissueEvent_009 1251 * @tc.desc: Test ReissueEvent 1252 * @tc.type: FUNC 1253 * @tc.require: 1254 */ 1255 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_009, TestSize.Level1) 1256 { 1257 EventDispatchHandler dispatch; 1258 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1259 ASSERT_NE(point, nullptr); 1260 point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL; 1261 int32_t windowId = 100; 1262 std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>(); 1263 ASSERT_NE(windowInfo, std::nullopt); 1264 point->pointerId_ = 5; 1265 point->SetPointerId(point->pointerId_); 1266 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1267 windowInfo1->id = 1; 1268 dispatch.cancelEventList_[1].push_back(windowInfo1); 1269 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1270 EXPECT_FALSE(result); 1271 } 1272 1273 /** 1274 * @tc.name: EventDispatchTest_ReissueEvent_010 1275 * @tc.desc: Test ReissueEvent 1276 * @tc.type: FUNC 1277 * @tc.require: 1278 */ 1279 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_010, TestSize.Level1) 1280 { 1281 EventDispatchHandler dispatch; 1282 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1283 ASSERT_NE(point, nullptr); 1284 point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL; 1285 int32_t windowId = 100; 1286 std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>(); 1287 ASSERT_NE(windowInfo, std::nullopt); 1288 point->pointerId_ = 1; 1289 point->SetPointerId(point->pointerId_); 1290 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1291 windowInfo1->id = 1; 1292 dispatch.cancelEventList_[1].push_back(windowInfo1); 1293 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1294 EXPECT_FALSE(result); 1295 } 1296 1297 /** 1298 * @tc.name: EventDispatchTest_ReissueEvent_011 1299 * @tc.desc: Test ReissueEvent 1300 * @tc.type: FUNC 1301 * @tc.require: 1302 */ 1303 HWTEST_F(EventDispatchTest, EventDispatchTest_ReissueEvent_011, TestSize.Level1) 1304 { 1305 EventDispatchHandler dispatch; 1306 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1307 ASSERT_NE(point, nullptr); 1308 point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 1309 int32_t windowId = 100; 1310 std::optional<WindowInfo> windowInfo = std::make_optional<WindowInfo>(); 1311 ASSERT_NE(windowInfo, std::nullopt); 1312 point->pointerId_ = 1; 1313 point->SetPointerId(point->pointerId_); 1314 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1315 windowInfo1->id = 1; 1316 dispatch.cancelEventList_[1].push_back(windowInfo1); 1317 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1318 EXPECT_TRUE(result); 1319 } 1320 1321 /** 1322 * @tc.name: EventDispatchTest_SearchCancelList_001 1323 * @tc.desc: Test SearchCancelList 1324 * @tc.type: FUNC 1325 * @tc.require: 1326 */ 1327 HWTEST_F(EventDispatchTest, EventDispatchTest_SearchCancelList_001, TestSize.Level1) 1328 { 1329 EventDispatchHandler handler; 1330 int32_t pointerId = 1; 1331 int32_t windowId = 2; 1332 std::shared_ptr<WindowInfo> result = handler.SearchCancelList(pointerId, windowId); 1333 ASSERT_EQ(result, nullptr); 1334 } 1335 1336 /** 1337 * @tc.name: EventDispatchTest_SearchCancelList_002 1338 * @tc.desc: Test SearchCancelList 1339 * @tc.type: FUNC 1340 * @tc.require: 1341 */ 1342 HWTEST_F(EventDispatchTest, EventDispatchTest_SearchCancelList_002, TestSize.Level1) 1343 { 1344 EventDispatchHandler handler; 1345 int32_t pointerId = 5; 1346 int32_t windowId = 2; 1347 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1348 windowInfo1->id = 1; 1349 handler.cancelEventList_[1].push_back(windowInfo1); 1350 std::shared_ptr<WindowInfo> result = handler.SearchCancelList(pointerId, windowId); 1351 ASSERT_EQ(result, nullptr); 1352 } 1353 1354 /** 1355 * @tc.name: EventDispatchTest_SearchCancelList_003 1356 * @tc.desc: Test SearchCancelList 1357 * @tc.type: FUNC 1358 * @tc.require: 1359 */ 1360 HWTEST_F(EventDispatchTest, EventDispatchTest_SearchCancelList_003, TestSize.Level1) 1361 { 1362 EventDispatchHandler handler; 1363 int32_t pointerId = 1; 1364 int32_t windowId = 1; 1365 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1366 windowInfo1->id = 1; 1367 handler.cancelEventList_[1].push_back(windowInfo1); 1368 std::shared_ptr<WindowInfo> result = handler.SearchCancelList(pointerId, windowId); 1369 ASSERT_NE(result, nullptr); 1370 } 1371 1372 /** 1373 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_004 1374 * @tc.desc: Test the function FilterInvalidPointerItem 1375 * @tc.type: FUNC 1376 * @tc.require: 1377 */ 1378 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_004, TestSize.Level1) 1379 { 1380 EventDispatchHandler eventdispatchhandler; 1381 int32_t fd = 1; 1382 int32_t eventType = 3; 1383 UDSServer* udsServer = new UDSServer(); 1384 InputHandler->udsServer_ = udsServer; 1385 std::shared_ptr<PointerEvent> sharedPointerEvent = std::make_shared<PointerEvent>(eventType); 1386 EXPECT_NE(sharedPointerEvent, nullptr); 1387 std::vector<int32_t> pointerIdList; 1388 EXPECT_FALSE(pointerIdList.size() > 1); 1389 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(sharedPointerEvent, fd)); 1390 } 1391 1392 /** 1393 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_005 1394 * @tc.desc: Test the function FilterInvalidPointerItem 1395 * @tc.type: FUNC 1396 * @tc.require: 1397 */ 1398 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_005, TestSize.Level1) 1399 { 1400 EventDispatchHandler eventdispatchhandler; 1401 PointerEvent::PointerItem testPointerItem; 1402 UDSServer* udsServer = new UDSServer(); 1403 InputHandler->udsServer_ = udsServer; 1404 int32_t fd = 1; 1405 int32_t eventType = 3; 1406 std::shared_ptr<PointerEvent> event = std::make_shared<PointerEvent>(eventType); 1407 event->pointers_.push_back(PointerEvent::PointerItem()); 1408 event->pointers_.push_back(PointerEvent::PointerItem()); 1409 std::vector<int32_t> pointerIds = event->GetPointerIds(); 1410 ASSERT_TRUE(pointerIds.size() > 1); 1411 event->AddPointerItem(testPointerItem); 1412 int32_t testPointerId = 1; 1413 testPointerItem.SetPointerId(testPointerId); 1414 event->AddPointerItem(testPointerItem); 1415 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(event, fd)); 1416 } 1417 1418 /** 1419 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_006 1420 * @tc.desc: Test the function FilterInvalidPointerItem 1421 * @tc.type: FUNC 1422 * @tc.require: 1423 */ 1424 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_006, TestSize.Level1) 1425 { 1426 EventDispatchHandler eventdispatchhandler; 1427 PointerEvent::PointerItem testPointerItem; 1428 UDSServer* udsServer = new UDSServer(); 1429 InputHandler->udsServer_ = udsServer; 1430 int32_t fd = 1; 1431 int32_t eventType = 3; 1432 std::shared_ptr<PointerEvent> event = std::make_shared<PointerEvent>(eventType); 1433 event->pointers_.push_back(PointerEvent::PointerItem()); 1434 event->pointers_.push_back(PointerEvent::PointerItem()); 1435 std::vector<int32_t> pointerIds = event->GetPointerIds(); 1436 ASSERT_TRUE(pointerIds.size() > 1); 1437 event->AddPointerItem(testPointerItem); 1438 int32_t testPointerId = 1; 1439 testPointerItem.SetPointerId(testPointerId + 1); 1440 event->AddPointerItem(testPointerItem); 1441 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(event, fd)); 1442 } 1443 1444 /** 1445 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_007 1446 * @tc.desc: Test the function FilterInvalidPointerItem 1447 * @tc.type: FUNC 1448 * @tc.require: 1449 */ 1450 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_007, TestSize.Level1) 1451 { 1452 EventDispatchHandler eventdispatchhandler; 1453 int32_t fd = 1; 1454 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1455 ASSERT_NE(pointerEvent, nullptr); 1456 UDSServer udsServer; 1457 InputHandler->udsServer_ = &udsServer; 1458 PointerEvent::PointerItem testPointerItem; 1459 testPointerItem.pointerId_ = -1; 1460 pointerEvent->pointers_.push_back(testPointerItem); 1461 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd)); 1462 testPointerItem.pressed_ = false; 1463 testPointerItem.displayX_ = 50; 1464 testPointerItem.displayY_ = 100; 1465 pointerEvent->pointers_.push_back(testPointerItem); 1466 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd)); 1467 } 1468 1469 /** 1470 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_007 1471 * @tc.desc: Test the function HandleMultiWindowPointerEvent 1472 * @tc.type: FUNC 1473 * @tc.require: 1474 */ 1475 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_007, TestSize.Level1) 1476 { 1477 EventDispatchHandler eventdispatchhandler; 1478 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1479 ASSERT_NE(point, nullptr); 1480 PointerEvent::PointerItem pointerItem; 1481 pointerItem.SetWindowX(35); 1482 pointerItem.SetWindowY(50); 1483 pointerItem.SetTargetWindowId(2); 1484 point->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 1485 point->pointerId_ = 1; 1486 std::shared_ptr<WindowInfo> windowInfo = std::make_shared<WindowInfo>(); 1487 windowInfo->id = 5; 1488 eventdispatchhandler.cancelEventList_[1].push_back(windowInfo); 1489 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1490 windowInfo->id = 1; 1491 eventdispatchhandler.cancelEventList_[2].push_back(windowInfo); 1492 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1493 point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 1494 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1495 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1496 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1497 point->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP; 1498 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1499 point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL; 1500 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1501 } 1502 1503 /** 1504 * @tc.name: EventDispatchTest_DispatchPointerEventInner_010 1505 * @tc.desc: Test the function DispatchPointerEventInner 1506 * @tc.type: FUNC 1507 * @tc.require: 1508 */ 1509 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_010, TestSize.Level1) 1510 { 1511 EventDispatchHandler eventDispatchHandler; 1512 int32_t fd = 2; 1513 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1514 ASSERT_NE(pointerEvent, nullptr); 1515 UDSServer udsServer; 1516 InputHandler->udsServer_ = &udsServer; 1517 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1518 udsServer.sessionsMap_.insert(std::make_pair(fd, session)); 1519 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 1520 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1521 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1522 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1523 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN; 1524 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1525 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP; 1526 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1527 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW; 1528 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1529 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 1530 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1531 fd = -2; 1532 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1533 fd = 5; 1534 udsServer.sessionsMap_.insert(std::make_pair(5, session)); 1535 ASSERT_NO_FATAL_FAILURE(eventDispatchHandler.DispatchPointerEventInner(pointerEvent, fd)); 1536 } 1537 1538 /** 1539 * @tc.name: EventDispatchTest_DispatchKeyEventPid_006 1540 * @tc.desc: Test the function DispatchKeyEventPid 1541 * @tc.type: FUNC 1542 * @tc.require: 1543 */ 1544 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEventPid_006, TestSize.Level1) 1545 { 1546 EventDispatchHandler eventDispatchHandler; 1547 UDSServer udsServer; 1548 std::shared_ptr<KeyEvent> KeyEvent = KeyEvent::Create(); 1549 ASSERT_NE(KeyEvent, nullptr); 1550 ASSERT_EQ(eventDispatchHandler.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK); 1551 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1552 udsServer.sessionsMap_.insert(std::make_pair(-1, session)); 1553 StreamBuffer streamBuffer; 1554 streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ; 1555 eventDispatchHandler.DispatchKeyEventPid(udsServer, KeyEvent); 1556 streamBuffer.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ; 1557 ASSERT_EQ(eventDispatchHandler.DispatchKeyEventPid(udsServer, KeyEvent), RET_OK); 1558 } 1559 1560 /** 1561 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_01 1562 * @tc.desc: Test HandleMultiWindowPointerEvent 1563 * @tc.type: FUNC 1564 * @tc.require: 1565 */ 1566 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_01, TestSize.Level1) 1567 { 1568 EventDispatchHandler dispatch; 1569 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1570 ASSERT_NE(point, nullptr); 1571 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1572 int32_t windowId = 1; 1573 point->pointerId_ = 1; 1574 point->SetPointerId(point->pointerId_); 1575 std::optional<WindowInfo> windowInfo = std::nullopt; 1576 std::shared_ptr<WindowInfo> windowInfo1 = std::make_shared<WindowInfo>(); 1577 windowInfo1->id = 1; 1578 dispatch.cancelEventList_[1].push_back(windowInfo1); 1579 bool result = dispatch.ReissueEvent(point, windowId, windowInfo); 1580 EXPECT_TRUE(result); 1581 1582 std::vector<int32_t> windowIds; 1583 windowIds.push_back(1); 1584 windowIds.push_back(2); 1585 windowIds.push_back(3); 1586 1587 PointerEvent::PointerItem pointerItem; 1588 pointerItem.SetWindowX(10); 1589 pointerItem.SetWindowY(20); 1590 pointerItem.SetTargetWindowId(2); 1591 1592 ASSERT_NO_FATAL_FAILURE(dispatch.HandleMultiWindowPointerEvent(point, pointerItem)); 1593 } 1594 1595 /** 1596 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_02 1597 * @tc.desc: Test HandleMultiWindowPointerEvent 1598 * @tc.type: FUNC 1599 * @tc.require: 1600 */ 1601 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_02, TestSize.Level1) 1602 { 1603 EventDispatchHandler dispatch; 1604 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1605 ASSERT_NE(pointerEvent, nullptr); 1606 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1607 int32_t windowId = 10; 1608 std::optional<WindowInfo> windowInfo = std::nullopt; 1609 bool result = dispatch.ReissueEvent(pointerEvent, windowId, windowInfo); 1610 EXPECT_FALSE(result); 1611 1612 std::vector<int32_t> windowIds; 1613 windowIds.push_back(1); 1614 windowIds.push_back(2); 1615 windowIds.push_back(3); 1616 1617 PointerEvent::PointerItem pointerItem; 1618 pointerItem.SetWindowX(10); 1619 pointerItem.SetWindowY(20); 1620 pointerItem.SetTargetWindowId(2); 1621 1622 ASSERT_NO_FATAL_FAILURE(dispatch.HandleMultiWindowPointerEvent(pointerEvent, pointerItem)); 1623 } 1624 1625 /** 1626 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_03 1627 * @tc.desc: Test HandleMultiWindowPointerEvent 1628 * @tc.type: FUNC 1629 * @tc.require: 1630 */ 1631 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_03, TestSize.Level1) 1632 { 1633 EventDispatchHandler dispatch; 1634 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1635 ASSERT_NE(pointerEvent, nullptr); 1636 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1637 int32_t windowId = 10; 1638 std::optional<WindowInfo> windowInfo = std::nullopt; 1639 bool result = dispatch.ReissueEvent(pointerEvent, windowId, windowInfo); 1640 EXPECT_FALSE(result); 1641 1642 std::vector<int32_t> windowIds; 1643 windowIds.push_back(1); 1644 windowIds.push_back(2); 1645 windowIds.push_back(3); 1646 1647 PointerEvent::PointerItem pointerItem; 1648 pointerItem.SetWindowX(10); 1649 pointerItem.SetWindowY(20); 1650 pointerItem.SetTargetWindowId(2); 1651 1652 auto fd = WIN_MGR->GetClientFd(pointerEvent, windowId); 1653 EXPECT_TRUE(fd < 0); 1654 ASSERT_NO_FATAL_FAILURE(dispatch.HandleMultiWindowPointerEvent(pointerEvent, pointerItem)); 1655 } 1656 1657 /** 1658 * @tc.name: EventDispatchTest_DispatchPointerEventInner_01 1659 * @tc.desc: Test DispatchPointerEventInner 1660 * @tc.type: FUNC 1661 * @tc.require: 1662 */ 1663 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_01, TestSize.Level1) 1664 { 1665 EventDispatchHandler dispatch; 1666 int32_t fd = 1; 1667 int32_t type = 2; 1668 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1669 ASSERT_NE(pointerEvent, nullptr); 1670 1671 auto session = InputHandler->udsServer_->GetSession(fd); 1672 int64_t currentTime = GetSysClockTime(); 1673 EXPECT_FALSE(ANRMgr->TriggerANR(type, currentTime, session)); 1674 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_DOWN; 1675 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 1676 } 1677 1678 /** 1679 * @tc.name: EventDispatchTest_DispatchPointerEventInner_02 1680 * @tc.desc: Test DispatchPointerEventInner 1681 * @tc.type: FUNC 1682 * @tc.require: 1683 */ 1684 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_02, TestSize.Level1) 1685 { 1686 EventDispatchHandler dispatch; 1687 int32_t fd = 1; 1688 int32_t type = 2; 1689 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1690 ASSERT_NE(pointerEvent, nullptr); 1691 1692 auto session = InputHandler->udsServer_->GetSession(fd); 1693 int64_t currentTime = GetSysClockTime(); 1694 EXPECT_FALSE(ANRMgr->TriggerANR(type, currentTime, session)); 1695 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1696 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 1697 } 1698 1699 /** 1700 * @tc.name: EventDispatchTest_DispatchPointerEventInner_03 1701 * @tc.desc: Test DispatchPointerEventInner 1702 * @tc.type: FUNC 1703 * @tc.require: 1704 */ 1705 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_03, TestSize.Level1) 1706 { 1707 EventDispatchHandler dispatch; 1708 int32_t fd = 1; 1709 int32_t type = 2; 1710 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1711 ASSERT_NE(pointerEvent, nullptr); 1712 1713 auto session = InputHandler->udsServer_->GetSession(fd); 1714 int64_t currentTime = GetSysClockTime(); 1715 EXPECT_FALSE(ANRMgr->TriggerANR(type, currentTime, session)); 1716 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_DOWN; 1717 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 1718 } 1719 1720 /** 1721 * @tc.name: EventDispatchTest_DispatchPointerEventInner_04 1722 * @tc.desc: Test DispatchPointerEventInner 1723 * @tc.type: FUNC 1724 * @tc.require: 1725 */ 1726 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_04, TestSize.Level1) 1727 { 1728 EventDispatchHandler dispatch; 1729 int32_t fd = 1; 1730 int32_t type = 2; 1731 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1732 ASSERT_NE(pointerEvent, nullptr); 1733 1734 auto session = InputHandler->udsServer_->GetSession(fd); 1735 int64_t currentTime = GetSysClockTime(); 1736 EXPECT_FALSE(ANRMgr->TriggerANR(type, currentTime, session)); 1737 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_PULL_UP; 1738 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 1739 } 1740 1741 /** 1742 * @tc.name: EventDispatchTest_DispatchPointerEventInner_05 1743 * @tc.desc: Test DispatchPointerEventInner 1744 * @tc.type: FUNC 1745 * @tc.require: 1746 */ 1747 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_05, TestSize.Level1) 1748 { 1749 EventDispatchHandler dispatch; 1750 int32_t fd = 1; 1751 int32_t type = 2; 1752 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1753 ASSERT_NE(pointerEvent, nullptr); 1754 1755 auto session = InputHandler->udsServer_->GetSession(fd); 1756 int64_t currentTime = GetSysClockTime(); 1757 EXPECT_FALSE(ANRMgr->TriggerANR(type, currentTime, session)); 1758 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 1759 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 1760 } 1761 1762 /** 1763 * @tc.name: EventDispatchTest_DispatchPointerEventInner_06 1764 * @tc.desc: Test DispatchPointerEventInner 1765 * @tc.type: FUNC 1766 * @tc.require: 1767 */ 1768 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_06, TestSize.Level1) 1769 { 1770 EventDispatchHandler dispatch; 1771 int32_t fd = 1; 1772 int32_t type = 2; 1773 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1774 ASSERT_NE(pointerEvent, nullptr); 1775 1776 auto session = InputHandler->udsServer_->GetSession(fd); 1777 int64_t currentTime = GetSysClockTime(); 1778 EXPECT_FALSE(ANRMgr->TriggerANR(type, currentTime, session)); 1779 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 1780 1781 NetPacket pkt(MmiMessageId::ON_POINTER_EVENT); 1782 EXPECT_FALSE(InputHandler->udsServer_->SendMsg(fd, pkt)); 1783 pointerEvent->markEnabled_ = true; 1784 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 1785 } 1786 1787 /** 1788 * @tc.name: EventDispatchTest_DispatchPointerEventInner_07 1789 * @tc.desc: Test DispatchPointerEventInner 1790 * @tc.type: FUNC 1791 * @tc.require: 1792 */ 1793 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchPointerEventInner_07, TestSize.Level1) 1794 { 1795 EventDispatchHandler dispatch; 1796 int32_t fd = 3; 1797 int32_t type = 4; 1798 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1799 ASSERT_NE(pointerEvent, nullptr); 1800 1801 auto session = InputHandler->udsServer_->GetSession(fd); 1802 int64_t currentTime = GetSysClockTime(); 1803 EXPECT_FALSE(ANRMgr->TriggerANR(type, currentTime, session)); 1804 pointerEvent->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 1805 1806 NetPacket pkt(MmiMessageId::ON_POINTER_EVENT); 1807 EXPECT_FALSE(InputHandler->udsServer_->SendMsg(fd, pkt)); 1808 pointerEvent->markEnabled_ = false; 1809 ASSERT_NO_FATAL_FAILURE(dispatch.DispatchPointerEventInner(pointerEvent, fd)); 1810 } 1811 1812 /** 1813 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_01 1814 * @tc.desc: Test the function FilterInvalidPointerItem 1815 * @tc.type: FUNC 1816 * @tc.require: 1817 */ 1818 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_01, TestSize.Level1) 1819 { 1820 EventDispatchHandler dispatch; 1821 int32_t fd = 1; 1822 int32_t id = 2; 1823 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1824 EXPECT_NE(pointerEvent, nullptr); 1825 1826 std::vector<int32_t> pointerIdList; 1827 pointerIdList.push_back(1); 1828 pointerIdList.push_back(2); 1829 EXPECT_TRUE(pointerIdList.size() > 1); 1830 1831 PointerEvent::PointerItem pointerItem; 1832 pointerItem.SetWindowX(10); 1833 pointerItem.SetWindowY(20); 1834 pointerItem.SetTargetWindowId(2); 1835 1836 EXPECT_FALSE(pointerEvent->GetPointerItem(id, pointerItem)); 1837 ASSERT_NO_FATAL_FAILURE(dispatch.FilterInvalidPointerItem(pointerEvent, fd)); 1838 } 1839 1840 /** 1841 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_02 1842 * @tc.desc: Test the function FilterInvalidPointerItem 1843 * @tc.type: FUNC 1844 * @tc.require: 1845 */ 1846 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_02, TestSize.Level1) 1847 { 1848 EventDispatchHandler dispatch; 1849 int32_t fd = 1; 1850 int32_t windowId = 3; 1851 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1852 EXPECT_NE(pointerEvent, nullptr); 1853 1854 std::vector<int32_t> pointerIdList; 1855 pointerIdList.push_back(1); 1856 pointerIdList.push_back(2); 1857 pointerIdList.push_back(3); 1858 EXPECT_TRUE(pointerIdList.size() > 1); 1859 1860 PointerEvent::PointerItem pointerItem; 1861 pointerItem.SetWindowX(10); 1862 pointerItem.SetWindowY(20); 1863 pointerItem.SetTargetWindowId(2); 1864 1865 auto itemPid = WIN_MGR->GetWindowPid(windowId); 1866 EXPECT_FALSE(itemPid >= 0); 1867 EXPECT_FALSE(itemPid != InputHandler->udsServer_->GetClientPid(fd)); 1868 ASSERT_NO_FATAL_FAILURE(dispatch.FilterInvalidPointerItem(pointerEvent, fd)); 1869 } 1870 1871 /** 1872 * @tc.name: EventDispatchTest_FilterInvalidPointerItem_008 1873 * @tc.desc: Test the function FilterInvalidPointerItem 1874 * @tc.type: FUNC 1875 * @tc.require: 1876 */ 1877 HWTEST_F(EventDispatchTest, EventDispatchTest_FilterInvalidPointerItem_008, TestSize.Level1) 1878 { 1879 EventDispatchHandler eventdispatchhandler; 1880 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1881 ASSERT_NE(pointerEvent, nullptr); 1882 int32_t fd = 10; 1883 PointerEvent::PointerItem item1; 1884 item1.pointerId_ = 1; 1885 item1.pressed_ = true; 1886 item1.displayX_ = 10; 1887 item1.displayY_ = 20; 1888 pointerEvent->pointers_.push_back(item1); 1889 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd)); 1890 PointerEvent::PointerItem item2; 1891 item2.pointerId_ = 2; 1892 item2.pressed_ = false; 1893 item2.displayX_ = 20; 1894 item2.displayY_ = 30; 1895 item2.targetWindowId_ = 1; 1896 pointerEvent->pointers_.push_back(item2); 1897 UDSServer udsServer; 1898 udsServer.pid_ = 1; 1899 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd)); 1900 udsServer.pid_ = -1; 1901 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.FilterInvalidPointerItem(pointerEvent, fd)); 1902 } 1903 1904 /** 1905 * @tc.name: EventDispatchTest_HandleMultiWindowPointerEvent_008 1906 * @tc.desc: Test the function HandleMultiWindowPointerEvent 1907 * @tc.type: FUNC 1908 * @tc.require: 1909 */ 1910 HWTEST_F(EventDispatchTest, EventDispatchTest_HandleMultiWindowPointerEvent_008, TestSize.Level1) 1911 { 1912 EventDispatchHandler eventdispatchhandler; 1913 std::shared_ptr<PointerEvent> point = PointerEvent::Create(); 1914 ASSERT_NE(point, nullptr); 1915 PointerEvent::PointerItem pointerItem; 1916 pointerItem.SetWindowX(1); 1917 pointerItem.SetWindowY(2); 1918 pointerItem.SetTargetWindowId(3); 1919 point->pointerAction_ = PointerEvent::POINTER_ACTION_UP; 1920 point->pointerId_ = 3; 1921 std::shared_ptr<WindowInfo> windowInfo = std::make_shared<WindowInfo>(); 1922 windowInfo->id = 3; 1923 eventdispatchhandler.cancelEventList_[1].push_back(windowInfo); 1924 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1925 windowInfo->id = 1; 1926 eventdispatchhandler.cancelEventList_[2].push_back(windowInfo); 1927 point->pointerAction_ = PointerEvent::POINTER_ACTION_MOVE; 1928 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1929 point->pointerAction_ = PointerEvent::POINTER_ACTION_CANCEL; 1930 ASSERT_NO_FATAL_FAILURE(eventdispatchhandler.HandleMultiWindowPointerEvent(point, pointerItem)); 1931 } 1932 1933 /** 1934 * @tc.name: EventDispatchTest_DispatchKeyEvent_002 1935 * @tc.desc: Test the funcation DispatchKeyEvent 1936 * @tc.type: FUNC 1937 * @tc.require: 1938 */ 1939 HWTEST_F(EventDispatchTest, EventDispatchTest_DispatchKeyEvent_002, TestSize.Level1) 1940 { 1941 EventDispatchHandler handler; 1942 int32_t fd = 1; 1943 UDSServer udsServer; 1944 std::shared_ptr<KeyEvent> key = KeyEvent::Create(); 1945 ASSERT_NE(key, nullptr); 1946 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, 1, 1, 100, 100); 1947 session->tokenType_ = 0; 1948 session->isAnrProcess_.insert(std::make_pair(1, true)); 1949 int32_t ret = handler.DispatchKeyEvent(fd, udsServer, key); 1950 EXPECT_EQ(ret, RET_ERR); 1951 fd = 2; 1952 session->isAnrProcess_.insert(std::make_pair(2, false)); 1953 ret = handler.DispatchKeyEvent(fd, udsServer, key); 1954 EXPECT_EQ(ret, RET_ERR); 1955 } 1956 } // namespace MMI 1957 } // namespace OHOS 1958