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 <fstream> 17 18 #include <gtest/gtest.h> 19 20 #include "event_monitor_handler.h" 21 #include "input_event_data_transformation.h" 22 #include "input_event_handler.h" 23 #include "mmi_log.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 #ifdef OHOS_BUILD_ENABLE_FINGERPRINT 34 int32_t g_no_focus_pid = 1; 35 #endif // OHOS_BUILD_ENABLE_FINGERPRINT 36 int32_t g_writeFd = -1; 37 constexpr size_t MAX_EVENTIDS_SIZE = 1001; 38 constexpr int32_t REMOVE_OBSERVER { -2 }; 39 constexpr int32_t UNOBSERVED { -1 }; 40 constexpr int32_t ACTIVE_EVENT { 2 }; 41 constexpr int32_t THREE_FINGERS { 3 }; 42 constexpr int32_t FOUR_FINGERS { 4 }; 43 } // namespace 44 45 class EventMonitorHandlerTest : public testing::Test { 46 public: SetUpTestCase(void)47 static void SetUpTestCase(void) {} TearDownTestCase(void)48 static void TearDownTestCase(void) {} 49 }; 50 51 class MyInputEventConsumer : public IInputEventHandler::IInputEventConsumer { 52 public: OnInputEvent(InputHandlerType type,std::shared_ptr<KeyEvent> event) const53 void OnInputEvent(InputHandlerType type, std::shared_ptr<KeyEvent> event) const override {} OnInputEvent(InputHandlerType type,std::shared_ptr<PointerEvent> event) const54 void OnInputEvent(InputHandlerType type, std::shared_ptr<PointerEvent> event) const override {} OnInputEvent(InputHandlerType type,std::shared_ptr<AxisEvent> event) const55 void OnInputEvent(InputHandlerType type, std::shared_ptr<AxisEvent> event) const override {} 56 }; 57 58 /** 59 * @tc.name: EventMonitorHandlerTest_AddInputHandler_002 60 * @tc.desc: Verify the invalid and valid event type of AddInputHandler 61 * @tc.type: FUNC 62 * @tc.require: 63 */ 64 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_AddInputHandler_002, TestSize.Level1) 65 { 66 CALL_TEST_DEBUG; 67 EventMonitorHandler eventMonitorHandler; 68 InputHandlerType handlerType = InputHandlerType::NONE; 69 HandleEventType eventType = HANDLE_EVENT_TYPE_KEY; 70 std::shared_ptr<IInputEventHandler::IInputEventConsumer> callback = std::make_shared<MyInputEventConsumer>(); 71 int32_t ret = eventMonitorHandler.AddInputHandler(handlerType, eventType, callback); 72 EXPECT_EQ(ret, RET_OK); 73 eventType = HANDLE_EVENT_TYPE_NONE; 74 ret = eventMonitorHandler.AddInputHandler(handlerType, eventType, callback); 75 EXPECT_NE(ret, RET_OK); 76 } 77 78 /** 79 * @tc.name: EventMonitorHandlerTest_AddInputHandler_003 80 * @tc.desc: Verify the invalid and valid event type of AddInputHandler 81 * @tc.type: FUNC 82 * @tc.require: 83 */ 84 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_AddInputHandler_003, TestSize.Level1) 85 { 86 CALL_TEST_DEBUG; 87 EventMonitorHandler eventMonitorHandler; 88 InputHandlerType handlerType = InputHandlerType::NONE; 89 HandleEventType eventType = HANDLE_EVENT_TYPE_KEY; 90 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 91 int32_t ret = eventMonitorHandler.AddInputHandler(handlerType, eventType, session); 92 EXPECT_EQ(ret, RET_OK); 93 eventType = HANDLE_EVENT_TYPE_FINGERPRINT; 94 ret = eventMonitorHandler.AddInputHandler(handlerType, eventType, session); 95 EXPECT_EQ(ret, RET_OK); 96 } 97 98 /** 99 * @tc.name: EventMonitorHandlerTest_HandleKeyEvent_001 100 * @tc.desc: Test Overrides the if (HandleKeyEvent(keyEvent)) branch of the HandleKeyEvent function 101 * @tc.type: FUNC 102 * @tc.require: 103 */ 104 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleKeyEvent_001, TestSize.Level1) 105 { 106 CALL_TEST_DEBUG; 107 EventMonitorHandler eventMonitorHandler; 108 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 109 ASSERT_NE(keyEvent, nullptr); 110 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.HandleKeyEvent(keyEvent)); 111 } 112 113 /** 114 * @tc.name: EventMonitorHandlerTest_HandlePointerEvent 115 * @tc.desc: Test Overrides the if (OnHandleEvent(pointerEvent)) branch of the HandlePointerEvent function 116 * @tc.type: FUNC 117 * @tc.require: 118 */ 119 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandlePointerEvent, TestSize.Level1) 120 { 121 CALL_TEST_DEBUG; 122 EventMonitorHandler eventMonitorHandler; 123 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 124 ASSERT_NE(pointerEvent, nullptr); 125 int32_t deviceId = 1; 126 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 127 pointerEvent->bitwise_ = PointerEvent::EVENT_FLAG_NONE; 128 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 129 pointerEvent->SetDeviceId(deviceId); 130 consumptionState.isMonitorConsumed_ = true; 131 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 132 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.HandlePointerEvent(pointerEvent)); 133 } 134 135 /** 136 * @tc.name: EventMonitorHandlerTest_HandleTouchEvent 137 * @tc.desc: Test Test Overrides the if (OnHandleEvent(pointerEvent)) branch of the HandleTouchEvent function 138 * @tc.type: FUNC 139 * @tc.require: 140 */ 141 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleTouchEvent, TestSize.Level1) 142 { 143 CALL_TEST_DEBUG; 144 EventMonitorHandler eventMonitorHandler; 145 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 146 ASSERT_NE(pointerEvent, nullptr); 147 int32_t deviceId = 1; 148 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 149 pointerEvent->bitwise_ = PointerEvent::EVENT_FLAG_NONE; 150 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 151 pointerEvent->SetDeviceId(deviceId); 152 consumptionState.isMonitorConsumed_ = true; 153 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 154 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.HandleTouchEvent(pointerEvent)); 155 } 156 157 /** 158 * @tc.name: EventMonitorHandlerTest_HandleTouchEvent_001 159 * @tc.desc: Test Overrides the if (item.GetToolType() == PointerEvent::TOOL_TYPE_KNUCKLE) branch 160 * <br> of the HandleTouchEvent function 161 * @tc.type: FUNC 162 * @tc.require: 163 */ 164 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleTouchEvent_001, TestSize.Level1) 165 { 166 CALL_TEST_DEBUG; 167 EventMonitorHandler eventMonitorHandler; 168 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 169 ASSERT_NE(pointerEvent, nullptr); 170 pointerEvent->bitwise_ = PointerEvent::EVENT_FLAG_NONE; 171 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 172 pointerEvent->SetPointerId(1); 173 PointerEvent::PointerItem item; 174 item.SetPointerId(1); 175 item.SetToolType(PointerEvent::TOOL_TYPE_KNUCKLE); 176 pointerEvent->AddPointerItem(item); 177 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.HandleTouchEvent(pointerEvent)); 178 } 179 180 /** 181 * @tc.name: EventMonitorHandlerTest_OnHandleEvent_Key 182 * @tc.desc: Test Overrides the if (keyEvent->HasFlag(InputEvent::EVENT_FLAG_NO_MONITOR)) branch 183 * @tc.type: FUNC 184 * @tc.require: 185 */ 186 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnHandleEvent_Key, TestSize.Level1) 187 { 188 CALL_TEST_DEBUG; 189 EventMonitorHandler eventMonitorHandler; 190 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 191 ASSERT_NE(keyEvent, nullptr); 192 keyEvent->bitwise_ = InputEvent::EVENT_FLAG_NO_MONITOR; 193 ASSERT_FALSE(eventMonitorHandler.OnHandleEvent(keyEvent)); 194 keyEvent->bitwise_ = InputEvent::EVENT_FLAG_NONE; 195 ASSERT_FALSE(eventMonitorHandler.OnHandleEvent(keyEvent)); 196 } 197 198 /** 199 * @tc.name: EventMonitorHandlerTest_OnHandleEvent_Pointer 200 * @tc.desc: Test Overrides the if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_NO_MONITOR)) branch 201 * @tc.type: FUNC 202 * @tc.require: 203 */ 204 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnHandleEvent_Pointer, TestSize.Level1) 205 { 206 CALL_TEST_DEBUG; 207 EventMonitorHandler eventMonitorHandler; 208 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 209 ASSERT_NE(pointerEvent, nullptr); 210 pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_NO_MONITOR; 211 ASSERT_FALSE(eventMonitorHandler.OnHandleEvent(pointerEvent)); 212 } 213 214 /** 215 * @tc.name: EventMonitorHandlerTest_OnHandleEvent_Pointer_001 216 * @tc.desc: Test Overrides the if (monitors_.HandleEvent(pointerEvent)) branch 217 * @tc.type: FUNC 218 * @tc.require: 219 */ 220 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnHandleEvent_Pointer_001, TestSize.Level1) 221 { 222 CALL_TEST_DEBUG; 223 EventMonitorHandler eventMonitorHandler; 224 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 225 ASSERT_NE(pointerEvent, nullptr); 226 pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_NONE; 227 int32_t deviceId = 1; 228 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 229 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 230 pointerEvent->SetDeviceId(deviceId); 231 consumptionState.isMonitorConsumed_ = true; 232 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 233 ASSERT_TRUE(eventMonitorHandler.OnHandleEvent(pointerEvent)); 234 } 235 236 /** 237 * @tc.name: EventMonitorHandlerTest_MarkConsumed_001 238 * @tc.desc: Test Overrides the if (eventIds.find(eventId) != eventIds.cend()) branch 239 * @tc.type: FUNC 240 * @tc.require: 241 */ 242 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_MarkConsumed_001, TestSize.Level1) 243 { 244 CALL_TEST_DEBUG; 245 EventMonitorHandler eventMonitorHandler; 246 int32_t deviceId = 1; 247 int32_t eventId = 20; 248 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 249 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 250 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 251 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 252 consumptionState.eventIds_.insert(20); 253 consumptionState.isMonitorConsumed_ = false; 254 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 255 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.MarkConsumed(eventId, session)); 256 } 257 258 /** 259 * @tc.name: EventMonitorHandlerTest_MarkConsumed_002 260 * @tc.desc: Test Overrides the if (tIter == states_.end()) branch 261 * @tc.type: FUNC 262 * @tc.require: 263 */ 264 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_MarkConsumed_002, TestSize.Level1) 265 { 266 CALL_TEST_DEBUG; 267 EventMonitorHandler eventMonitorHandler; 268 int32_t deviceId = 1; 269 int32_t eventId = 20; 270 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 271 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 272 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 273 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 274 consumptionState.eventIds_.insert(10); 275 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 276 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.MarkConsumed(eventId, session)); 277 } 278 279 /** 280 * @tc.name: EventMonitorHandlerTest_MarkConsumed_003 281 * @tc.desc: Test Overrides the if (state.isMonitorConsumed_) branch 282 * @tc.type: FUNC 283 * @tc.require: 284 */ 285 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_MarkConsumed_003, TestSize.Level1) 286 { 287 CALL_TEST_DEBUG; 288 EventMonitorHandler eventMonitorHandler; 289 int32_t deviceId = 1; 290 int32_t eventId = 10; 291 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 292 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 293 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 294 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 295 consumptionState.eventIds_.insert(10); 296 consumptionState.isMonitorConsumed_ = true; 297 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 298 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.MarkConsumed(eventId, session)); 299 } 300 301 /** 302 * @tc.name: EventMonitorHandlerTest_HandleEvent 303 * @tc.desc: Test Overrides the if ((mon.eventType_ & HANDLE_EVENT_TYPE_KEY) == HANDLE_EVENT_TYPE_KEY) branch 304 * @tc.type: FUNC 305 * @tc.require: 306 */ 307 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent, TestSize.Level1) 308 { 309 CALL_TEST_DEBUG; 310 EventMonitorHandler eventMonitorHandler; 311 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 312 ASSERT_NE(keyEvent, nullptr); 313 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 314 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_KEY, session }; 315 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 316 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.HandleEvent(keyEvent)); 317 } 318 319 /** 320 * @tc.name: EventMonitorHandlerTest_HandleEvent_001 321 * @tc.desc: Test Overwrites the else branch of if ((mon.eventType_ & HANDLE_EVENT_TYPE_KEY) == HANDLE_EVENT_TYPE_KEY) 322 * @tc.type: FUNC 323 * @tc.require: 324 */ 325 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent_001, TestSize.Level1) 326 { 327 CALL_TEST_DEBUG; 328 EventMonitorHandler eventMonitorHandler; 329 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 330 ASSERT_NE(keyEvent, nullptr); 331 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 332 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_NONE, session }; 333 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 334 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.HandleEvent(keyEvent)); 335 } 336 337 /** 338 * @tc.name: EventMonitorHandlerTest_HandleEvent_002 339 * @tc.desc: Test HandleEvent 340 * @tc.type: FUNC 341 * @tc.require: 342 */ 343 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent_002, TestSize.Level1) 344 { 345 CALL_TEST_DEBUG; 346 EventMonitorHandler eventMonitorHandler; 347 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 348 ASSERT_NE(keyEvent, nullptr); 349 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 350 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_NONE, session }; 351 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 352 353 NapProcess::GetInstance()->napClientPid_ = ACTIVE_EVENT; 354 OHOS::MMI::NapProcess::NapStatusData napData; 355 napData.pid = 2; 356 napData.uid = 3; 357 napData.bundleName = "programName"; 358 EXPECT_FALSE(NapProcess::GetInstance()->IsNeedNotify(napData)); 359 bool ret = eventMonitorHandler.monitors_.HandleEvent(keyEvent); 360 EXPECT_FALSE(ret); 361 } 362 363 /** 364 * @tc.name: EventMonitorHandlerTest_HandleEvent_003 365 * @tc.desc: Test HandleEvent 366 * @tc.type: FUNC 367 * @tc.require: 368 */ 369 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent_003, TestSize.Level1) 370 { 371 CALL_TEST_DEBUG; 372 EventMonitorHandler eventMonitorHandler; 373 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 374 ASSERT_NE(keyEvent, nullptr); 375 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 376 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_NONE, session }; 377 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 378 379 NapProcess::GetInstance()->napClientPid_ = REMOVE_OBSERVER; 380 bool ret = eventMonitorHandler.monitors_.HandleEvent(keyEvent); 381 EXPECT_FALSE(ret); 382 } 383 384 /** 385 * @tc.name: EventMonitorHandlerTest_HandleEvent_004 386 * @tc.desc: Test HandleEvent 387 * @tc.type: FUNC 388 * @tc.require: 389 */ 390 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent_004, TestSize.Level1) 391 { 392 CALL_TEST_DEBUG; 393 EventMonitorHandler eventMonitorHandler; 394 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 395 ASSERT_NE(keyEvent, nullptr); 396 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 397 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_NONE, session }; 398 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 399 400 NapProcess::GetInstance()->napClientPid_ = UNOBSERVED; 401 bool ret = eventMonitorHandler.monitors_.HandleEvent(keyEvent); 402 EXPECT_FALSE(ret); 403 } 404 405 /** 406 * @tc.name: EventMonitorHandlerTest_HandleEvent_005 407 * @tc.desc: Test Overwrites the else branch of if (keyEvent->GetFourceMonitorFlag()) 408 * @tc.type: FUNC 409 * @tc.require: 410 */ 411 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent_005, TestSize.Level1) 412 { 413 CALL_TEST_DEBUG; 414 EventMonitorHandler eventMonitorHandler; 415 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 416 ASSERT_NE(keyEvent, nullptr); 417 keyEvent->SetFourceMonitorFlag(true); 418 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 419 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_KEY, session }; 420 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 421 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.HandleEvent(keyEvent)); 422 } 423 424 /** 425 * @tc.name: EventMonitorHandlerTest_HandleEvent_006 426 * @tc.desc: Test Overwrites the else branch of if ((mon.session_ != nullptr && mon.session_->GetUid() == POWER_UID)) 427 * @tc.type: FUNC 428 * @tc.require: 429 */ 430 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent_006, TestSize.Level1) 431 { 432 CALL_TEST_DEBUG; 433 EventMonitorHandler eventMonitorHandler; 434 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 435 ASSERT_NE(keyEvent, nullptr); 436 int32_t uid = 5528; 437 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, uid, g_pid); 438 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_KEY, session }; 439 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 440 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.HandleEvent(keyEvent)); 441 } 442 443 /** 444 * @tc.name: EventMonitorHandlerTest_HandleEvent_007 445 * @tc.desc: Test Overwrites the else branch of ((SourceType == SOURCE_TYPE_TOUCHSCREEN or SOURCE_TYPE_TOUCHPAD )) 446 * @tc.type: FUNC 447 * @tc.require: 448 */ 449 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HandleEvent_007, TestSize.Level1) 450 { 451 CALL_TEST_DEBUG; 452 EventMonitorHandler eventMonitorHandler; 453 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 454 ASSERT_NE(pointerEvent, nullptr); 455 int32_t deviceId1 = 1; 456 int32_t deviceId2 = 2; 457 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 458 pointerEvent->SetDeviceId(deviceId1); 459 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 460 consumptionState.isMonitorConsumed_ = true; 461 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId2, consumptionState)); 462 ASSERT_FALSE(eventMonitorHandler.monitors_.HandleEvent(pointerEvent)); 463 } 464 465 /** 466 * @tc.name: EventMonitorHandlerTest_Monitor 467 * @tc.desc: Test Monitor 468 * @tc.type: FUNC 469 * @tc.require: 470 */ 471 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_Monitor, TestSize.Level1) 472 { 473 CALL_TEST_DEBUG; 474 EventMonitorHandler eventMonitorHandler; 475 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 476 ASSERT_NE(pointerEvent, nullptr); 477 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); 478 pointerEvent->SetPointerId(1); 479 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 480 pointerEvent->SetButtonId(1); 481 pointerEvent->SetFingerCount(2); 482 pointerEvent->SetZOrder(100); 483 pointerEvent->SetDispatchTimes(1000); 484 PointerEvent::PointerItem item; 485 item.SetPointerId(1); 486 pointerEvent->AddPointerItem(item); 487 pointerEvent->SetHandlerEventType(HANDLE_EVENT_TYPE_POINTER); 488 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 489 EventMonitorHandler::SessionHandler sess { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_POINTER, session }; 490 eventMonitorHandler.monitors_.monitors_.insert(sess); 491 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.Monitor(pointerEvent)); 492 493 pointerEvent->SetHandlerEventType(HANDLE_EVENT_TYPE_FINGERPRINT); 494 EventMonitorHandler::SessionHandler sesshdl { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_NONE, session }; 495 eventMonitorHandler.monitors_.monitors_.insert(sesshdl); 496 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.Monitor(pointerEvent)); 497 } 498 499 /** 500 * @tc.name: EventMonitorHandlerTest_Monitor_001 501 * @tc.desc: Test Monitor 502 * @tc.type: FUNC 503 * @tc.require: 504 */ 505 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_Monitor_001, TestSize.Level1) 506 { 507 CALL_TEST_DEBUG; 508 EventMonitorHandler eventMonitorHandler; 509 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 510 ASSERT_NE(pointerEvent, nullptr); 511 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); 512 pointerEvent->SetPointerId(1); 513 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 514 pointerEvent->SetButtonId(1); 515 pointerEvent->SetFingerCount(2); 516 pointerEvent->SetZOrder(100); 517 pointerEvent->SetDispatchTimes(1000); 518 PointerEvent::PointerItem item; 519 item.SetPointerId(1); 520 pointerEvent->AddPointerItem(item); 521 522 pointerEvent->SetHandlerEventType(HANDLE_EVENT_TYPE_FINGERPRINT); 523 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 524 EventMonitorHandler::SessionHandler sess { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_NONE, session }; 525 eventMonitorHandler.monitors_.monitors_.insert(sess); 526 527 NapProcess::GetInstance()->napClientPid_ = ACTIVE_EVENT; 528 OHOS::MMI::NapProcess::NapStatusData napData; 529 napData.pid = 2; 530 napData.uid = 3; 531 napData.bundleName = "programName"; 532 EXPECT_FALSE(NapProcess::GetInstance()->IsNeedNotify(napData)); 533 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.Monitor(pointerEvent)); 534 535 NapProcess::GetInstance()->napClientPid_ = REMOVE_OBSERVER; 536 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.Monitor(pointerEvent)); 537 538 NapProcess::GetInstance()->napClientPid_ = UNOBSERVED; 539 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.monitors_.Monitor(pointerEvent)); 540 } 541 542 /** 543 * @tc.name: EventMonitorHandlerTest_Monitor_002 544 * @tc.desc: Test Monitor 545 * @tc.type: FUNC 546 * @tc.require: 547 */ 548 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_Monitor_002, TestSize.Level1) 549 { 550 CALL_TEST_DEBUG; 551 EventMonitorHandler::MonitorCollection monitorCollection; 552 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 553 ASSERT_NE(pointerEvent, nullptr); 554 pointerEvent->SetPointerAction(PointerEvent::TOUCH_ACTION_SWIPE_DOWN); 555 pointerEvent->SetPointerId(1); 556 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 557 pointerEvent->SetButtonId(1); 558 pointerEvent->SetFingerCount(2); 559 pointerEvent->SetZOrder(100); 560 pointerEvent->SetDispatchTimes(1000); 561 PointerEvent::PointerItem item; 562 item.SetPointerId(1); 563 item.SetDisplayX(523); 564 item.SetDisplayY(723); 565 item.SetPressure(5); 566 pointerEvent->AddPointerItem(item); 567 568 pointerEvent->SetHandlerEventType(HANDLE_EVENT_TYPE_POINTER); 569 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 570 EventMonitorHandler::SessionHandler sessionHandler{InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_POINTER, session}; 571 std::set<int32_t> info = {1, 2, 3}; 572 sessionHandler.gesture_.touchGestureInfo_.insert(std::make_pair(TOUCH_GESTURE_TYPE_SWIPE, info)); 573 monitorCollection.monitors_.insert(sessionHandler); 574 NapProcess::GetInstance()->napClientPid_ = 2; 575 OHOS::MMI::NapProcess::NapStatusData napData; 576 napData.pid = 2; 577 napData.uid = 3; 578 napData.bundleName = "programName"; 579 EXPECT_FALSE(NapProcess::GetInstance()->IsNeedNotify(napData)); 580 ASSERT_NO_FATAL_FAILURE(monitorCollection.Monitor(pointerEvent)); 581 } 582 583 /** 584 * @tc.name: EventMonitorHandlerTest_OnHandleEvent_001 585 * @tc.desc: Test OnHandleEvent 586 * @tc.type: FUNC 587 * @tc.require: 588 */ 589 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnHandleEvent_001, TestSize.Level1) 590 { 591 CALL_TEST_DEBUG; 592 EventMonitorHandler eventMonitorHandler; 593 auto keyEvent = KeyEvent::Create(); 594 eventMonitorHandler.HandleKeyEvent(keyEvent); 595 ASSERT_EQ(eventMonitorHandler.OnHandleEvent(keyEvent), false); 596 auto pointerEvent = PointerEvent::Create(); 597 eventMonitorHandler.HandlePointerEvent(pointerEvent); 598 ASSERT_EQ(eventMonitorHandler.OnHandleEvent(pointerEvent), false); 599 600 eventMonitorHandler.HandleTouchEvent(pointerEvent); 601 PointerEvent::PointerItem item; 602 item.SetDeviceId(1); 603 item.SetPointerId(0); 604 item.SetDisplayX(523); 605 item.SetDisplayY(723); 606 item.SetPressure(5); 607 pointerEvent->AddPointerItem(item); 608 item.SetDisplayY(610); 609 item.SetPointerId(1); 610 item.SetDeviceId(1); 611 item.SetPressure(7); 612 item.SetDisplayX(600); 613 pointerEvent->AddPointerItem(item); 614 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); 615 pointerEvent->SetPointerId(1); 616 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 617 618 keyEvent->SetKeyCode(KeyEvent::KEYCODE_BACK); 619 keyEvent->SetActionTime(100); 620 keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); 621 keyEvent->ActionToString(KeyEvent::KEY_ACTION_DOWN); 622 keyEvent->KeyCodeToString(KeyEvent::KEYCODE_BACK); 623 KeyEvent::KeyItem part; 624 part.SetKeyCode(KeyEvent::KEYCODE_BACK); 625 part.SetDownTime(100); 626 part.SetPressed(true); 627 part.SetUnicode(0); 628 keyEvent->AddKeyItem(part); 629 630 eventMonitorHandler.HandlePointerEvent(pointerEvent); 631 eventMonitorHandler.HandleTouchEvent(pointerEvent); 632 ASSERT_EQ(eventMonitorHandler.OnHandleEvent(keyEvent), false); 633 ASSERT_EQ(eventMonitorHandler.OnHandleEvent(pointerEvent), false); 634 } 635 636 /** 637 * @tc.name: EventMonitorHandlerTest_InitSessionLostCallback_001 638 * @tc.desc: Verify the invalid and valid event type of InitSessionLostCallback 639 * @tc.type: FUNC 640 * @tc.require: 641 */ 642 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_InitSessionLostCallback_001, TestSize.Level1) 643 { 644 CALL_TEST_DEBUG; 645 EventMonitorHandler eventMonitorHandler; 646 eventMonitorHandler.sessionLostCallbackInitialized_ = true; 647 eventMonitorHandler.InitSessionLostCallback(); 648 eventMonitorHandler.sessionLostCallbackInitialized_ = false; 649 UDSServer udSever; 650 InputHandler->udsServer_ = &udSever; 651 auto udsServerPtr = InputHandler->GetUDSServer(); 652 EXPECT_NE(udsServerPtr, nullptr); 653 eventMonitorHandler.InitSessionLostCallback(); 654 InputHandler->udsServer_ = nullptr; 655 } 656 657 /** 658 * @tc.name: EventMonitorHandlerTest_AddInputHandler_001 659 * @tc.desc: Verify the invalid and valid event type of AddInputHandler 660 * @tc.type: FUNC 661 * @tc.require: 662 */ 663 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_AddInputHandler_001, TestSize.Level1) 664 { 665 CALL_TEST_DEBUG; 666 EventMonitorHandler eventMonitorHandler; 667 InputHandlerType handlerType = InputHandlerType::NONE; 668 HandleEventType eventType = 0; 669 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 670 int32_t ret = eventMonitorHandler.AddInputHandler(handlerType, eventType, session); 671 EXPECT_EQ(ret, RET_ERR); 672 eventType = 1; 673 ret = eventMonitorHandler.AddInputHandler(handlerType, eventType, session); 674 EXPECT_EQ(ret, RET_OK); 675 } 676 677 /** 678 * @tc.name: EventMonitorHandlerTest_RemoveInputHandler_001 679 * @tc.desc: Verify the invalid and valid event type of RemoveInputHandler 680 * @tc.type: FUNC 681 * @tc.require: 682 */ 683 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveInputHandler_001, TestSize.Level1) 684 { 685 CALL_TEST_DEBUG; 686 EventMonitorHandler eventMonitorHandler; 687 InputHandlerType handlerType = InputHandlerType::NONE; 688 HandleEventType eventType = 1; 689 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 690 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.RemoveInputHandler(handlerType, eventType, session)); 691 handlerType = InputHandlerType::MONITOR; 692 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.RemoveInputHandler(handlerType, eventType, session)); 693 } 694 695 /** 696 * @tc.name: EventMonitorHandlerTest_SendToClient_001 697 * @tc.desc: Verify the keyEvent and pointerEvent of SendToClient 698 * @tc.type: FUNC 699 * @tc.require: 700 */ 701 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_SendToClient_001, TestSize.Level1) 702 { 703 CALL_TEST_DEBUG; 704 InputHandlerType handlerType = InputHandlerType::NONE; 705 HandleEventType eventType = 0; 706 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 707 EventMonitorHandler::SessionHandler sessionHandler { handlerType, eventType, session }; 708 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create(); 709 NetPacket keyEventPkt(MmiMessageId::REPORT_KEY_EVENT); 710 keyEventPkt << InputHandlerType::MONITOR << static_cast<uint32_t>(evdev_device_udev_tags::EVDEV_UDEV_TAG_INPUT); 711 ASSERT_NO_FATAL_FAILURE(sessionHandler.SendToClient(keyEvent, keyEventPkt)); 712 713 NetPacket pointerEventPkt(MmiMessageId::REPORT_POINTER_EVENT); 714 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 715 pointerEventPkt << InputHandlerType::MONITOR << static_cast<uint32_t>(evdev_device_udev_tags::EVDEV_UDEV_TAG_INPUT); 716 InputEventDataTransformation::Marshalling(pointerEvent, pointerEventPkt); 717 ASSERT_NO_FATAL_FAILURE(sessionHandler.SendToClient(pointerEvent, pointerEventPkt)); 718 } 719 720 /** 721 * @tc.name: EventMonitorHandlerTest_AddMonitor_001 722 * @tc.desc: Verify the invalid and valid event type of AddMonitor 723 * @tc.type: FUNC 724 * @tc.require: 725 */ 726 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_AddMonitor_001, TestSize.Level1) 727 { 728 CALL_TEST_DEBUG; 729 EventMonitorHandler::MonitorCollection monitorCollection; 730 InputHandlerType handlerType = InputHandlerType::NONE; 731 HandleEventType eventType = 0; 732 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 733 EventMonitorHandler::SessionHandler sessionHandler { handlerType, eventType, session }; 734 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_TOUCH_GESTURE; 735 monitorCollection.monitors_.insert(sessionHandler); 736 for (int i = 0; i < MAX_N_INPUT_MONITORS - 2; i++) { 737 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 738 EventMonitorHandler::SessionHandler sessionHandler = { handlerType, eventType, session }; 739 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_NONE; 740 monitorCollection.monitors_.insert(sessionHandler); 741 } 742 int32_t ret = monitorCollection.AddMonitor(sessionHandler); 743 EXPECT_EQ(ret, RET_OK); 744 745 monitorCollection.monitors_.erase(sessionHandler); 746 SessionPtr session2 = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 747 EventMonitorHandler::SessionHandler sessionHandler2 { handlerType, eventType, session2 }; 748 monitorCollection.monitors_.insert(sessionHandler2); 749 ret = monitorCollection.AddMonitor(sessionHandler2); 750 EXPECT_EQ(ret, RET_OK); 751 752 SessionPtr session3 = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 753 EventMonitorHandler::SessionHandler sessionHandler3 { handlerType, eventType, session3 }; 754 monitorCollection.monitors_.insert(sessionHandler3); 755 ret = monitorCollection.AddMonitor(sessionHandler3); 756 EXPECT_EQ(ret, RET_ERR); 757 } 758 759 /** 760 * @tc.name: EventMonitorHandlerTest_RemoveMonitor_001 761 * @tc.desc: Verify the invalid and valid event type of RemoveMonitor 762 * @tc.type: FUNC 763 * @tc.require: 764 */ 765 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveMonitor_001, TestSize.Level1) 766 { 767 CALL_TEST_DEBUG; 768 EventMonitorHandler::MonitorCollection monitorCollection; 769 InputHandlerType handlerType = InputHandlerType::NONE; 770 HandleEventType eventType = 0; 771 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 772 EventMonitorHandler::SessionHandler sessionHandler { handlerType, eventType, session }; 773 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveMonitor(sessionHandler)); 774 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_TOUCH_GESTURE; 775 monitorCollection.monitors_.insert(sessionHandler); 776 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveMonitor(sessionHandler)); 777 SessionPtr session2 = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 778 eventType = 1; 779 sessionHandler = { handlerType, eventType, session2 }; 780 monitorCollection.monitors_.insert(sessionHandler); 781 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveMonitor(sessionHandler)); 782 } 783 784 /** 785 * @tc.name: EventMonitorHandlerTest_RemoveMonitor_002 786 * @tc.desc: Verify the invalid and valid event type of RemoveMonitor 787 * @tc.type: FUNC 788 * @tc.require: 789 */ 790 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveMonitor_002, TestSize.Level1) 791 { 792 CALL_TEST_DEBUG; 793 EventMonitorHandler::MonitorCollection monitorCollection; 794 InputHandlerType handlerType = InputHandlerType::NONE; 795 HandleEventType eventType = 0; 796 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 797 EventMonitorHandler::SessionHandler sessionHandler { handlerType, eventType, session }; 798 monitorCollection.monitors_.insert(sessionHandler); 799 std::set<EventMonitorHandler::SessionHandler> setIters = { sessionHandler }; 800 monitorCollection.endScreenCaptureMonitors_[g_pid] = setIters; 801 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveMonitor(sessionHandler)); 802 } 803 804 /** 805 * @tc.name: EventMonitorHandlerTest_RemoveMonitor_003 806 * @tc.desc: Verify the invalid and valid event type of RemoveMonitor 807 * @tc.type: FUNC 808 * @tc.require: 809 */ 810 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveMonitor_003, TestSize.Level1) 811 { 812 CALL_TEST_DEBUG; 813 EventMonitorHandler::MonitorCollection monitorCollection; 814 InputHandlerType handlerType = InputHandlerType::NONE; 815 HandleEventType eventType = 0; 816 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 817 EventMonitorHandler::SessionHandler sessionHandler { handlerType, eventType, session }; 818 monitorCollection.monitors_.insert(sessionHandler); 819 std::set<EventMonitorHandler::SessionHandler> setIters = { }; 820 monitorCollection.endScreenCaptureMonitors_[g_pid] = setIters; 821 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveMonitor(sessionHandler)); 822 } 823 824 /** 825 * @tc.name: EventMonitorHandlerTest_MarkConsumed 826 * @tc.desc: Test MarkConsumed 827 * @tc.type: FUNC 828 * @tc.require: 829 */ 830 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_MarkConsumed, TestSize.Level1) 831 { 832 CALL_TEST_DEBUG; 833 EventMonitorHandler eventMonitorHandler; 834 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 835 int32_t eventId = 100; 836 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.MarkConsumed(eventId, session)); 837 } 838 839 /** 840 * @tc.name: EventMonitorHandlerTest_OnSessionLost 841 * @tc.desc: Test OnSessionLost 842 * @tc.type: FUNC 843 * @tc.require: 844 */ 845 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnSessionLost, TestSize.Level1) 846 { 847 CALL_TEST_DEBUG; 848 EventMonitorHandler eventMonitorHandler; 849 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 850 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_KEY, session }; 851 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 852 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.OnSessionLost(session)); 853 854 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 855 session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 856 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.OnSessionLost(session)); 857 } 858 859 /** 860 * @tc.name: EventMonitorHandlerTest_HasMonitor 861 * @tc.desc: Test HasMonitor 862 * @tc.type: FUNC 863 * @tc.require: 864 */ 865 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HasMonitor, TestSize.Level1) 866 { 867 CALL_TEST_DEBUG; 868 EventMonitorHandler::MonitorCollection monitorCollection; 869 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 870 EventMonitorHandler::SessionHandler monitor { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 871 monitorCollection.monitors_.insert(monitor); 872 ASSERT_TRUE(monitorCollection.HasMonitor(session)); 873 } 874 875 /** 876 * @tc.name: EventMonitorHandlerTest_HasScreenCaptureMonitor 877 * @tc.desc: Test HasScreenCaptureMonitor 878 * @tc.type: FUNC 879 * @tc.require: 880 */ 881 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_HasScreenCaptureMonitor_001, TestSize.Level1) 882 { 883 CALL_TEST_DEBUG; 884 EventMonitorHandler::MonitorCollection monitorCollection; 885 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 886 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 887 std::set<EventMonitorHandler::SessionHandler> setIters = { sessionHandler }; 888 ASSERT_FALSE(monitorCollection.HasScreenCaptureMonitor(session)); 889 monitorCollection.endScreenCaptureMonitors_[g_pid] = setIters; 890 ASSERT_TRUE(monitorCollection.HasScreenCaptureMonitor(session)); 891 } 892 893 /** 894 * @tc.name: EventMonitorHandlerTest_UpdateConsumptionState 895 * @tc.desc: Test UpdateConsumptionState 896 * @tc.type: FUNC 897 * @tc.require: 898 */ 899 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_UpdateConsumptionState, TestSize.Level1) 900 { 901 CALL_TEST_DEBUG; 902 int32_t deviceId = 6; 903 EventMonitorHandler::MonitorCollection monitorCollection; 904 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 905 ASSERT_NE(pointerEvent, nullptr); 906 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 907 pointerEvent->SetDeviceId(deviceId); 908 EventMonitorHandler::MonitorCollection::ConsumptionState state; 909 for (int32_t i = 0; i <= MAX_EVENTIDS_SIZE; ++i) { 910 state.eventIds_.insert(i); 911 } 912 monitorCollection.states_.insert(std::make_pair(deviceId, state)); 913 PointerEvent::PointerItem item; 914 item.SetDeviceId(1); 915 pointerEvent->AddPointerItem(item); 916 pointerEvent->SetId(1); 917 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_BEGIN); 918 ASSERT_NO_FATAL_FAILURE(monitorCollection.UpdateConsumptionState(pointerEvent)); 919 920 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_END); 921 ASSERT_NO_FATAL_FAILURE(monitorCollection.UpdateConsumptionState(pointerEvent)); 922 } 923 924 /** 925 * @tc.name: EventMonitorHandlerTest_UpdateConsumptionState_002 926 * @tc.desc: Test UpdateConsumptionState 927 * @tc.type: FUNC 928 * @tc.require: 929 */ 930 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_UpdateConsumptionState_002, TestSize.Level1) 931 { 932 CALL_TEST_DEBUG; 933 int32_t deviceId = 1; 934 EventMonitorHandler::MonitorCollection monitorCollection; 935 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 936 ASSERT_NE(pointerEvent, nullptr); 937 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 938 pointerEvent->SetDeviceId(deviceId); 939 PointerEvent::PointerItem item1; 940 item1.SetDeviceId(2); 941 pointerEvent->AddPointerItem(item1); 942 PointerEvent::PointerItem item2; 943 item2.SetDeviceId(3); 944 pointerEvent->AddPointerItem(item2); 945 ASSERT_NO_FATAL_FAILURE(monitorCollection.UpdateConsumptionState(pointerEvent)); 946 } 947 948 /** 949 * @tc.name: EventMonitorHandlerTest_ProcessScreenCapture_001 950 * @tc.desc: Test ProcessScreenCapture 951 * @tc.type: FUNC 952 * @tc.require: 953 */ 954 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_ProcessScreenCapture_001, TestSize.Level1) 955 { 956 CALL_TEST_DEBUG; 957 EventMonitorHandler eventMonitorHandler; 958 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 959 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.ProcessScreenCapture(g_pid, false)); 960 EventMonitorHandler::MonitorCollection monitorCollection; 961 EventMonitorHandler::SessionHandler monitor { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 962 monitorCollection.monitors_.insert(monitor); 963 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.ProcessScreenCapture(g_pid, false)); 964 } 965 966 /** 967 * @tc.name: EventMonitorHandlerTest_ProcessScreenCapture_002 968 * @tc.desc: Test ProcessScreenCapture 969 * @tc.type: FUNC 970 * @tc.require: 971 */ 972 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_ProcessScreenCapture_002, TestSize.Level1) 973 { 974 CALL_TEST_DEBUG; 975 EventMonitorHandler eventMonitorHandler; 976 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 977 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.ProcessScreenCapture(g_pid, true)); 978 EventMonitorHandler::MonitorCollection monitorCollection; 979 EventMonitorHandler::SessionHandler monitor { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 980 monitorCollection.monitors_.insert(monitor); 981 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.ProcessScreenCapture(g_pid, true)); 982 } 983 984 /** 985 * @tc.name: EventMonitorHandlerTest_ProcessScreenCapture_003 986 * @tc.desc: Test ProcessScreenCapture 987 * @tc.type: FUNC 988 * @tc.require: 989 */ 990 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_ProcessScreenCapture_003, TestSize.Level1) 991 { 992 CALL_TEST_DEBUG; 993 EventMonitorHandler eventMonitorHandler; 994 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 995 EventMonitorHandler::MonitorCollection monitorCollection; 996 EventMonitorHandler::SessionHandler handler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 997 std::set<EventMonitorHandler::SessionHandler> handlerSet; 998 handlerSet.insert(handler); 999 monitorCollection.endScreenCaptureMonitors_[-1] = handlerSet; 1000 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.ProcessScreenCapture(g_pid, true)); 1001 } 1002 1003 /** 1004 * @tc.name: EventMonitorHandlerTest_Dump_001 1005 * @tc.desc: Test Dump 1006 * @tc.type: FUNC 1007 * @tc.require: 1008 */ 1009 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_Dump_001, TestSize.Level1) 1010 { 1011 CALL_TEST_DEBUG; 1012 EventMonitorHandler eventMonitorHandler; 1013 int32_t fd = 1; 1014 std::vector<std::string> args; 1015 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.Dump(fd, args)); 1016 } 1017 1018 /** 1019 * @tc.name: EventMonitorHandlerTest_OnSessionLost_001 1020 * @tc.desc: Test OnSessionLost 1021 * @tc.type: FUNC 1022 * @tc.require: 1023 */ 1024 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnSessionLost_001, TestSize.Level1) 1025 { 1026 CALL_TEST_DEBUG; 1027 EventMonitorHandler eventMonitorHandler; 1028 EventMonitorHandler::MonitorCollection monitorCollection; 1029 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1030 EventMonitorHandler::SessionHandler sessionHandler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_KEY, session }; 1031 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 1032 std::set<EventMonitorHandler::SessionHandler> handlerSet; 1033 handlerSet.insert(sessionHandler); 1034 monitorCollection.endScreenCaptureMonitors_[-1] = handlerSet; 1035 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.OnSessionLost(session)); 1036 eventMonitorHandler.monitors_.monitors_.insert(sessionHandler); 1037 session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1038 handlerSet.insert(sessionHandler); 1039 monitorCollection.endScreenCaptureMonitors_[-1] = handlerSet; 1040 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.OnSessionLost(session)); 1041 } 1042 1043 /** 1044 * @tc.name: EventMonitorHandlerTest_RecoveryScreenCaptureMonitor_001 1045 * @tc.desc: Test RecoveryScreenCaptureMonitor 1046 * @tc.type: FUNC 1047 * @tc.require: 1048 */ 1049 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RecoveryScreenCaptureMonitor_001, TestSize.Level1) 1050 { 1051 CALL_TEST_DEBUG; 1052 EventMonitorHandler::MonitorCollection monitorCollection; 1053 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1054 session->tokenType_ = TokenType::TOKEN_SHELL; 1055 ASSERT_NO_FATAL_FAILURE(monitorCollection.RecoveryScreenCaptureMonitor(session)); 1056 session->tokenType_ = TokenType::TOKEN_HAP; 1057 ASSERT_NO_FATAL_FAILURE(monitorCollection.RecoveryScreenCaptureMonitor(session)); 1058 1059 EventMonitorHandler::SessionHandler handler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 1060 std::set<EventMonitorHandler::SessionHandler> handlerSet; 1061 handlerSet.insert(handler); 1062 monitorCollection.endScreenCaptureMonitors_[-1] = handlerSet; 1063 ASSERT_NO_FATAL_FAILURE(monitorCollection.RecoveryScreenCaptureMonitor(session)); 1064 } 1065 1066 /** 1067 * @tc.name: EventMonitorHandlerTest_RemoveScreenCaptureMonitor_001 1068 * @tc.desc: Test RemoveScreenCaptureMonitor 1069 * @tc.type: FUNC 1070 * @tc.require: 1071 */ 1072 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveScreenCaptureMonitor_001, TestSize.Level1) 1073 { 1074 CALL_TEST_DEBUG; 1075 EventMonitorHandler::MonitorCollection monitorCollection; 1076 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1077 session->tokenType_ = TokenType::TOKEN_SHELL; 1078 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveScreenCaptureMonitor(session)); 1079 session->tokenType_ = TokenType::TOKEN_HAP; 1080 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveScreenCaptureMonitor(session)); 1081 EventMonitorHandler::SessionHandler handler { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_ALL, session }; 1082 std::set<EventMonitorHandler::SessionHandler> handlerSet; 1083 handlerSet.insert(handler); 1084 monitorCollection.endScreenCaptureMonitors_[-1] = handlerSet; 1085 ASSERT_NO_FATAL_FAILURE(monitorCollection.RemoveScreenCaptureMonitor(session)); 1086 } 1087 1088 /** 1089 * @tc.name: EventMonitorHandlerTest_ProcessScreenCapture_004 1090 * @tc.desc: Test ProcessScreenCapture 1091 * @tc.type: FUNC 1092 * @tc.require: 1093 */ 1094 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_ProcessScreenCapture_004, TestSize.Level1) 1095 { 1096 CALL_TEST_DEBUG; 1097 EventMonitorHandler eventMonitorHandler; 1098 int32_t pid = 2; 1099 bool isStart = true; 1100 UDSServer udSever; 1101 InputHandler->udsServer_ = &udSever; 1102 udSever.idxPidMap_.insert(std::make_pair(pid, 2)); 1103 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1104 udSever.sessionsMap_.insert(std::make_pair(pid, session)); 1105 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.ProcessScreenCapture(pid, isStart)); 1106 isStart = false; 1107 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.ProcessScreenCapture(pid, isStart)); 1108 } 1109 1110 /** 1111 * @tc.name: EventMonitorHandlerTest_Dump_002 1112 * @tc.desc: Test Dump 1113 * @tc.type: FUNC 1114 * @tc.require: 1115 */ 1116 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_Dump_002, TestSize.Level1) 1117 { 1118 CALL_TEST_DEBUG; 1119 EventMonitorHandler eventMonitorHandler; 1120 int32_t fd = 1; 1121 std::vector<std::string> args; 1122 SessionPtr session = nullptr; 1123 EventMonitorHandler::MonitorCollection monitorCollection; 1124 EventMonitorHandler::SessionHandler monitor { InputHandlerType::INTERCEPTOR, 2, session }; 1125 monitorCollection.monitors_.insert(monitor); 1126 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.Dump(fd, args)); 1127 } 1128 1129 /** 1130 * @tc.name: EventMonitorHandlerTest_Dump_003 1131 * @tc.desc: Test Dump 1132 * @tc.type: FUNC 1133 * @tc.require: 1134 */ 1135 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_Dump_003, TestSize.Level1) 1136 { 1137 CALL_TEST_DEBUG; 1138 EventMonitorHandler eventMonitorHandler; 1139 int32_t fd = 1; 1140 std::vector<std::string> args; 1141 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1142 EventMonitorHandler::MonitorCollection monitorCollection; 1143 EventMonitorHandler::SessionHandler monitorone { InputHandlerType::INTERCEPTOR, 2, session }; 1144 monitorCollection.monitors_.insert(monitorone); 1145 EventMonitorHandler::SessionHandler monitortwo { InputHandlerType::MONITOR, 3, session }; 1146 monitorCollection.monitors_.insert(monitortwo); 1147 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.Dump(fd, args)); 1148 } 1149 1150 /** 1151 * @tc.name: EventMonitorHandlerTest_Dump_004 1152 * @tc.desc: Test Dump 1153 * @tc.type: FUNC 1154 * @tc.require: 1155 */ 1156 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_Dump_004, TestSize.Level1) 1157 { 1158 CALL_TEST_DEBUG; 1159 EventMonitorHandler eventMonitorHandler; 1160 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1161 EventMonitorHandler::SessionHandler monitorone { InputHandlerType::MONITOR, HANDLE_EVENT_TYPE_KEY, session }; 1162 eventMonitorHandler.monitors_.monitors_.emplace(monitorone); 1163 int32_t fd = 1; 1164 std::vector<std::string> args; 1165 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.Dump(fd, args)); 1166 } 1167 1168 /** 1169 * @tc.name: EventMonitorHandlerTest_CheckHasInputHandler_001 1170 * @tc.desc: Test CheckHasInputHandler 1171 * @tc.type: FUNC 1172 * @tc.require: 1173 */ 1174 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_CheckHasInputHandler_001, TestSize.Level1) 1175 { 1176 CALL_TEST_DEBUG; 1177 EventMonitorHandler eventMonitorHandler; 1178 HandleEventType eventType = 1; 1179 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.CheckHasInputHandler(eventType)); 1180 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1181 EventMonitorHandler::MonitorCollection monitorCollection; 1182 EventMonitorHandler::SessionHandler monitorone { InputHandlerType::INTERCEPTOR, 1, session }; 1183 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.CheckHasInputHandler(eventType)); 1184 monitorCollection.monitors_.insert(monitorone); 1185 EventMonitorHandler::SessionHandler monitortwo { InputHandlerType::MONITOR, 2, session }; 1186 monitorCollection.monitors_.insert(monitortwo); 1187 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.CheckHasInputHandler(eventType)); 1188 EventMonitorHandler::SessionHandler monitorthere { InputHandlerType::MONITOR, 3, session }; 1189 monitorCollection.monitors_.insert(monitorthere); 1190 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.CheckHasInputHandler(eventType)); 1191 } 1192 1193 /** 1194 * @tc.name: EventMonitorHandlerTest_RemoveInputHandler_002 1195 * @tc.desc: Verify the invalid and valid event type of RemoveInputHandler 1196 * @tc.type: FUNC 1197 * @tc.require: 1198 */ 1199 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveInputHandler_002, TestSize.Level1) 1200 { 1201 CALL_TEST_DEBUG; 1202 EventMonitorHandler eventMonitorHandler; 1203 InputHandlerType handlerType = InputHandlerType::MONITOR; 1204 HandleEventType eventType = 2; 1205 std::shared_ptr<IInputEventHandler::IInputEventConsumer> callback = std::make_shared<MyInputEventConsumer>(); 1206 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.RemoveInputHandler(handlerType, eventType, callback)); 1207 handlerType = InputHandlerType::NONE; 1208 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.RemoveInputHandler(handlerType, eventType, callback)); 1209 } 1210 1211 /** 1212 * @tc.name: EventMonitorHandlerTest_RemoveInputHandler_003 1213 * @tc.desc: Verify the invalid and valid event type of RemoveInputHandler 1214 * @tc.type: FUNC 1215 * @tc.require: 1216 */ 1217 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveInputHandler_003, TestSize.Level1) 1218 { 1219 CALL_TEST_DEBUG; 1220 EventMonitorHandler eventMonitorHandler; 1221 InputHandlerType handlerType = InputHandlerType::MONITOR; 1222 HandleEventType eventType = HANDLE_EVENT_TYPE_TOUCH; 1223 std::shared_ptr<IInputEventHandler::IInputEventConsumer> callback = std::make_shared<MyInputEventConsumer>(); 1224 eventMonitorHandler.AddInputHandler(handlerType, eventType, callback); 1225 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.RemoveInputHandler(handlerType, eventType, callback)); 1226 } 1227 1228 /** 1229 * @tc.name: EventMonitorHandlerTest_RemoveInputHandler_004 1230 * @tc.desc: Verify the invalid and valid event type of RemoveInputHandler 1231 * @tc.type: FUNC 1232 * @tc.require: 1233 */ 1234 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_RemoveInputHandler_004, TestSize.Level1) 1235 { 1236 CALL_TEST_DEBUG; 1237 EventMonitorHandler eventMonitorHandler; 1238 InputHandlerType handlerType = InputHandlerType::MONITOR; 1239 HandleEventType eventType = HANDLE_EVENT_TYPE_TOUCH; 1240 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1241 eventMonitorHandler.AddInputHandler(handlerType, eventType, session); 1242 ASSERT_NO_FATAL_FAILURE(eventMonitorHandler.RemoveInputHandler(handlerType, eventType, session)); 1243 } 1244 1245 /** 1246 * @tc.name: EventMonitorHandlerTest_IsPinch 1247 * @tc.desc: Test IsPinch 1248 * @tc.type: FUNC 1249 * @tc.require: 1250 */ 1251 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsPinch, TestSize.Level1) 1252 { 1253 CALL_TEST_DEBUG; 1254 EventMonitorHandler::MonitorCollection monitorCollection; 1255 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1256 ASSERT_NE(pointerEvent, nullptr); 1257 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN); 1258 bool ret = false; 1259 ret = monitorCollection.IsPinch(pointerEvent); 1260 ASSERT_FALSE(ret); 1261 1262 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 1263 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); 1264 ret = monitorCollection.IsPinch(pointerEvent); 1265 ASSERT_FALSE(ret); 1266 1267 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE); 1268 ret = monitorCollection.IsPinch(pointerEvent); 1269 ASSERT_TRUE(ret); 1270 } 1271 1272 /** 1273 * @tc.name: EventMonitorHandlerTest_IsRotate 1274 * @tc.desc: Test IsRotate 1275 * @tc.type: FUNC 1276 * @tc.require: 1277 */ 1278 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsRotate, TestSize.Level1) 1279 { 1280 CALL_TEST_DEBUG; 1281 EventMonitorHandler::MonitorCollection monitorCollection; 1282 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1283 ASSERT_NE(pointerEvent, nullptr); 1284 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN); 1285 bool ret = false; 1286 ret = monitorCollection.IsRotate(pointerEvent); 1287 ASSERT_FALSE(ret); 1288 1289 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 1290 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_ROTATE_UPDATE); 1291 ret = monitorCollection.IsRotate(pointerEvent); 1292 ASSERT_TRUE(ret); 1293 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_ROTATE_BEGIN); 1294 ret = monitorCollection.IsRotate(pointerEvent); 1295 ASSERT_TRUE(ret); 1296 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_ROTATE_END); 1297 ret = monitorCollection.IsRotate(pointerEvent); 1298 ASSERT_TRUE(ret); 1299 1300 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 1301 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP); 1302 ret = monitorCollection.IsRotate(pointerEvent); 1303 ASSERT_FALSE(ret); 1304 } 1305 1306 /** 1307 * @tc.name: EventMonitorHandlerTest_IsThreeFingersSwipe 1308 * @tc.desc: Test IsThreeFingersSwipe 1309 * @tc.type: FUNC 1310 * @tc.require: 1311 */ 1312 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsThreeFingersSwipe, TestSize.Level1) 1313 { 1314 CALL_TEST_DEBUG; 1315 EventMonitorHandler::MonitorCollection monitorCollection; 1316 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1317 ASSERT_NE(pointerEvent, nullptr); 1318 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1319 bool ret = false; 1320 ret = monitorCollection.IsThreeFingersSwipe(pointerEvent); 1321 ASSERT_FALSE(ret); 1322 1323 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1324 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_UPDATE); 1325 pointerEvent->SetFingerCount(THREE_FINGERS); 1326 ret = monitorCollection.IsThreeFingersSwipe(pointerEvent); 1327 ASSERT_TRUE(ret); 1328 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_BEGIN); 1329 ret = monitorCollection.IsThreeFingersSwipe(pointerEvent); 1330 ASSERT_TRUE(ret); 1331 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_END); 1332 ret = monitorCollection.IsThreeFingersSwipe(pointerEvent); 1333 ASSERT_TRUE(ret); 1334 1335 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1336 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW); 1337 pointerEvent->SetFingerCount(THREE_FINGERS); 1338 ret = monitorCollection.IsThreeFingersSwipe(pointerEvent); 1339 ASSERT_FALSE(ret); 1340 } 1341 1342 /** 1343 * @tc.name: EventMonitorHandlerTest_IsFourFingersSwipe 1344 * @tc.desc: Test IsFourFingersSwipe 1345 * @tc.type: FUNC 1346 * @tc.require: 1347 */ 1348 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsFourFingersSwipe, TestSize.Level1) 1349 { 1350 CALL_TEST_DEBUG; 1351 EventMonitorHandler::MonitorCollection monitorCollection; 1352 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1353 ASSERT_NE(pointerEvent, nullptr); 1354 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1355 bool ret = false; 1356 ret = monitorCollection.IsFourFingersSwipe(pointerEvent); 1357 ASSERT_FALSE(ret); 1358 1359 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1360 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_UPDATE); 1361 pointerEvent->SetFingerCount(FOUR_FINGERS); 1362 ret = monitorCollection.IsFourFingersSwipe(pointerEvent); 1363 ASSERT_TRUE(ret); 1364 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1365 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_UPDATE); 1366 pointerEvent->SetFingerCount(FOUR_FINGERS); 1367 ret = monitorCollection.IsFourFingersSwipe(pointerEvent); 1368 ASSERT_TRUE(ret); 1369 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_BEGIN); 1370 ret = monitorCollection.IsFourFingersSwipe(pointerEvent); 1371 ASSERT_TRUE(ret); 1372 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_END); 1373 ret = monitorCollection.IsFourFingersSwipe(pointerEvent); 1374 ASSERT_TRUE(ret); 1375 1376 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1377 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_UPDATE); 1378 pointerEvent->SetFingerCount(THREE_FINGERS); 1379 ret = monitorCollection.IsFourFingersSwipe(pointerEvent); 1380 ASSERT_FALSE(ret); 1381 1382 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1383 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW); 1384 pointerEvent->SetFingerCount(FOUR_FINGERS); 1385 ret = monitorCollection.IsFourFingersSwipe(pointerEvent); 1386 ASSERT_FALSE(ret); 1387 } 1388 1389 /** 1390 * @tc.name: EventMonitorHandlerTest_IsThreeFingersTap 1391 * @tc.desc: Test IsThreeFingersTap 1392 * @tc.type: FUNC 1393 * @tc.require: 1394 */ 1395 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsThreeFingersTap, TestSize.Level1) 1396 { 1397 CALL_TEST_DEBUG; 1398 EventMonitorHandler::MonitorCollection monitorCollection; 1399 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1400 ASSERT_NE(pointerEvent, nullptr); 1401 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1402 bool ret = false; 1403 ret = monitorCollection.IsThreeFingersTap(pointerEvent); 1404 ASSERT_FALSE(ret); 1405 1406 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1407 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP); 1408 pointerEvent->SetFingerCount(THREE_FINGERS); 1409 ret = monitorCollection.IsThreeFingersTap(pointerEvent); 1410 ASSERT_TRUE(ret); 1411 1412 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1413 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP); 1414 pointerEvent->SetFingerCount(FOUR_FINGERS); 1415 ret = monitorCollection.IsThreeFingersTap(pointerEvent); 1416 ASSERT_FALSE(ret); 1417 1418 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1419 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_QUADTAP); 1420 pointerEvent->SetFingerCount(THREE_FINGERS); 1421 ret = monitorCollection.IsThreeFingersTap(pointerEvent); 1422 ASSERT_FALSE(ret); 1423 } 1424 1425 #ifdef OHOS_BUILD_ENABLE_FINGERPRINT 1426 /** 1427 * @tc.name: EventMonitorHandlerTest_IsFingerprint 1428 * @tc.desc: Test IsFingerprint 1429 * @tc.type: FUNC 1430 * @tc.require: 1431 */ 1432 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsFingerprint, TestSize.Level1) 1433 { 1434 CALL_TEST_DEBUG; 1435 EventMonitorHandler::MonitorCollection monitorCollection; 1436 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1437 ASSERT_NE(pointerEvent, nullptr); 1438 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1439 bool ret = false; 1440 ret = monitorCollection.IsFingerprint(pointerEvent); 1441 ASSERT_FALSE(ret); 1442 1443 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_FINGERPRINT); 1444 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE); 1445 ret = monitorCollection.IsFingerprint(pointerEvent); 1446 ASSERT_TRUE(ret); 1447 } 1448 1449 /** 1450 * @tc.name: EventMonitorHandlerTest_IsFingerprint_002 1451 * @tc.desc: Test IsFingerprint_002 1452 * @tc.type: FUNC 1453 * @tc.require: 1454 */ 1455 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsFingerprint_002, TestSize.Level1) 1456 { 1457 CALL_TEST_DEBUG; 1458 EventMonitorHandler::MonitorCollection monitorCollection; 1459 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1460 ASSERT_NE(pointerEvent, nullptr); 1461 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1462 ASSERT_FALSE(monitorCollection.IsFingerprint(pointerEvent)); 1463 1464 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_FINGERPRINT); 1465 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE); 1466 ASSERT_TRUE(monitorCollection.IsFingerprint(pointerEvent)); 1467 1468 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_HOLD); 1469 ASSERT_TRUE(monitorCollection.IsFingerprint(pointerEvent)); 1470 1471 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_CANCEL); 1472 ASSERT_TRUE(monitorCollection.IsFingerprint(pointerEvent)); 1473 1474 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_CANCEL); 1475 ASSERT_FALSE(monitorCollection.IsFingerprint(pointerEvent)); 1476 } 1477 1478 /** 1479 * @tc.name: EventMonitorHandlerTest_CheckIfNeedSendFingerprintEvent_001 1480 * @tc.desc: Test CheckIfNeedSendFingerprintEvent 1481 * @tc.type: FUNC 1482 * @tc.require: 1483 */ 1484 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_CheckIfNeedSendFingerprintEvent_001, TestSize.Level1) 1485 { 1486 CALL_TEST_DEBUG; 1487 EventMonitorHandler::MonitorCollection monitorCollection; 1488 InputHandlerType handlerType = InputHandlerType::MONITOR; 1489 HandleEventType eventType = HANDLE_EVENT_TYPE_KP; 1490 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1491 EventMonitorHandler::SessionHandler monitor { handlerType, eventType, session }; 1492 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1493 ASSERT_NE(pointerEvent, nullptr); 1494 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_FINGERPRINT); 1495 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE); 1496 std::unordered_set<int32_t> fingerFocusPidSet; 1497 ASSERT_FALSE(monitorCollection.CheckIfNeedSendFingerprintEvent(monitor, pointerEvent, fingerFocusPidSet)); 1498 } 1499 1500 /** 1501 * @tc.name: EventMonitorHandlerTest_CheckIfNeedSendFingerprintEvent_002 1502 * @tc.desc: Test CheckIfNeedSendFingerprintEvent 1503 * @tc.type: FUNC 1504 * @tc.require: 1505 */ 1506 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_CheckIfNeedSendFingerprintEvent_002, TestSize.Level1) 1507 { 1508 CALL_TEST_DEBUG; 1509 EventMonitorHandler::MonitorCollection monitorCollection; 1510 InputHandlerType handlerType = InputHandlerType::MONITOR; 1511 HandleEventType eventType = HANDLE_EVENT_TYPE_FINGERPRINT; 1512 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1513 EventMonitorHandler::SessionHandler monitor { handlerType, eventType, session }; 1514 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1515 ASSERT_NE(pointerEvent, nullptr); 1516 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_FINGERPRINT); 1517 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_CLICK); 1518 std::unordered_set<int32_t> fingerFocusPidSet; 1519 ASSERT_TRUE(monitorCollection.CheckIfNeedSendFingerprintEvent(monitor, pointerEvent, fingerFocusPidSet)); 1520 1521 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE); 1522 ASSERT_TRUE(monitorCollection.CheckIfNeedSendFingerprintEvent(monitor, pointerEvent, fingerFocusPidSet)); 1523 1524 fingerFocusPidSet.insert(g_pid); 1525 ASSERT_TRUE(monitorCollection.CheckIfNeedSendFingerprintEvent(monitor, pointerEvent, fingerFocusPidSet)); 1526 1527 fingerFocusPidSet.clear(); 1528 fingerFocusPidSet.insert(g_no_focus_pid); 1529 ASSERT_FALSE(monitorCollection.CheckIfNeedSendFingerprintEvent(monitor, pointerEvent, fingerFocusPidSet)); 1530 } 1531 #endif // OHOS_BUILD_ENABLE_FINGERPRINT 1532 /** 1533 * @tc.name: EventMonitorHandlerTest_CheckIfNeedSendToClient_01 1534 * @tc.desc: Test CheckIfNeedSendToClient 1535 * @tc.type: FUNC 1536 * @tc.require: 1537 */ 1538 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_CheckIfNeedSendToClient_01, TestSize.Level1) 1539 { 1540 CALL_TEST_DEBUG; 1541 EventMonitorHandler::MonitorCollection monitorCollection; 1542 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1543 ASSERT_NE(pointerEvent, nullptr); 1544 InputHandlerType handlerType = InputHandlerType::NONE; 1545 HandleEventType eventType = 0; 1546 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1547 EventMonitorHandler::SessionHandler sessionHandler { handlerType, eventType, session }; 1548 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_FINGERPRINT; 1549 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_FINGERPRINT); 1550 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE); 1551 bool ret = false; 1552 std::unordered_set<int32_t> fingerFocusPidSet; 1553 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1554 ASSERT_FALSE(ret); 1555 1556 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_TOUCH_GESTURE; 1557 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1558 ASSERT_TRUE(ret); 1559 1560 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_SWIPEINWARD; 1561 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1562 ASSERT_TRUE(ret); 1563 1564 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_TOUCH; 1565 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1566 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1567 ASSERT_TRUE(ret); 1568 1569 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_MOUSE; 1570 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 1571 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1572 ASSERT_TRUE(ret); 1573 1574 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_PINCH; 1575 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 1576 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE); 1577 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1578 ASSERT_TRUE(ret); 1579 1580 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_THREEFINGERSSWIP; 1581 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1582 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_UPDATE); 1583 pointerEvent->SetFingerCount(THREE_FINGERS); 1584 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1585 ASSERT_TRUE(ret); 1586 } 1587 1588 /** 1589 * @tc.name: EventMonitorHandlerTest_CheckIfNeedSendToClient_02 1590 * @tc.desc: Test CheckIfNeedSendToClient 1591 * @tc.type: FUNC 1592 * @tc.require: 1593 */ 1594 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_CheckIfNeedSendToClient_02, TestSize.Level1) 1595 { 1596 CALL_TEST_DEBUG; 1597 EventMonitorHandler::MonitorCollection monitorCollection; 1598 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1599 ASSERT_NE(pointerEvent, nullptr); 1600 InputHandlerType handlerType = InputHandlerType::NONE; 1601 HandleEventType eventType = 0; 1602 SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid); 1603 EventMonitorHandler::SessionHandler sessionHandler { handlerType, eventType, session }; 1604 1605 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_FOURFINGERSSWIP; 1606 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1607 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_SWIPE_UPDATE); 1608 pointerEvent->SetFingerCount(FOUR_FINGERS); 1609 bool ret = false; 1610 std::unordered_set<int32_t> fingerFocusPidSet; 1611 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1612 ASSERT_TRUE(ret); 1613 1614 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_ROTATE; 1615 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 1616 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_ROTATE_UPDATE); 1617 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1618 ASSERT_TRUE(ret); 1619 1620 sessionHandler.eventType_ = HANDLE_EVENT_TYPE_THREEFINGERSTAP; 1621 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD); 1622 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_TRIPTAP); 1623 pointerEvent->SetFingerCount(THREE_FINGERS); 1624 ret = monitorCollection.CheckIfNeedSendToClient(sessionHandler, pointerEvent, fingerFocusPidSet); 1625 ASSERT_TRUE(ret); 1626 } 1627 1628 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 1629 /** 1630 * @tc.name: EventMonitorHandlerTest_OnHandleEvent_002 1631 * @tc.desc: Test OnHandleEvent 1632 * @tc.type: FUNC 1633 * @tc.require: 1634 */ 1635 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnHandleEvent_002, TestSize.Level1) 1636 { 1637 CALL_TEST_DEBUG; 1638 EventMonitorHandler eventMonitorHandler; 1639 auto keyEvent = KeyEvent::Create(); 1640 ASSERT_NE(keyEvent, nullptr); 1641 InputEventHandler inputEventHandler ; 1642 inputEventHandler.eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>(); 1643 ASSERT_TRUE(inputEventHandler.eventNormalizeHandler_ != nullptr); 1644 EventNormalizeHandler eventNormalizeHandler; 1645 eventNormalizeHandler.currentHandleKeyCode_ = 1; 1646 keyEvent->SetKeyCode(2); 1647 bool ret = eventMonitorHandler.OnHandleEvent(keyEvent); 1648 ASSERT_FALSE(ret); 1649 keyEvent->SetKeyCode(1); 1650 ret = eventMonitorHandler.OnHandleEvent(keyEvent); 1651 ASSERT_FALSE(ret); 1652 std::shared_ptr<InputEvent> inputEvent = InputEvent::Create(); 1653 EXPECT_NE(inputEvent, nullptr); 1654 inputEvent->bitwise_ = 0x00000002; 1655 ret = eventMonitorHandler.OnHandleEvent(keyEvent); 1656 ASSERT_FALSE(ret); 1657 inputEvent->bitwise_ = 0x00000000; 1658 ret = eventMonitorHandler.OnHandleEvent(keyEvent); 1659 ASSERT_FALSE(ret); 1660 int32_t deviceId = 1; 1661 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 1662 consumptionState.isMonitorConsumed_ = true; 1663 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 1664 ret = eventMonitorHandler.OnHandleEvent(keyEvent); 1665 ASSERT_FALSE(ret); 1666 } 1667 #endif // OHOS_BUILD_ENABLE_KEYBOARD 1668 1669 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 1670 /** 1671 * @tc.name: EventMonitorHandlerTest_OnHandleEvent_003 1672 * @tc.desc: Test OnHandleEvent 1673 * @tc.type: FUNC 1674 * @tc.require: 1675 */ 1676 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_OnHandleEvent_003, TestSize.Level1) 1677 { 1678 CALL_TEST_DEBUG; 1679 EventMonitorHandler eventMonitorHandler; 1680 auto pointerEvent = PointerEvent::Create(); 1681 int32_t deviceId = 1; 1682 pointerEvent->SetDeviceId(deviceId); 1683 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1684 pointerEvent->bitwise_ = 0x00000002; 1685 ASSERT_FALSE(eventMonitorHandler.OnHandleEvent(pointerEvent)); 1686 1687 pointerEvent->bitwise_ = 0x00000000; 1688 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN); 1689 ASSERT_FALSE(eventMonitorHandler.OnHandleEvent(pointerEvent)); 1690 1691 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); 1692 PointerEvent::PointerItem item; 1693 item.SetDeviceId(1); 1694 item.SetPointerId(0); 1695 item.SetDisplayX(523); 1696 item.SetDisplayY(723); 1697 item.SetPressure(5); 1698 pointerEvent->AddPointerItem(item); 1699 pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); 1700 pointerEvent->SetPointerId(1); 1701 ASSERT_FALSE(eventMonitorHandler.OnHandleEvent(pointerEvent)); 1702 eventMonitorHandler.HandlePointerEvent(pointerEvent); 1703 ASSERT_FALSE(eventMonitorHandler.OnHandleEvent(pointerEvent)); 1704 } 1705 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 1706 1707 #ifdef OHOS_BUILD_ENABLE_X_KEY 1708 /** 1709 * @tc.name: EventMonitorHandlerTest_IsXKey_001 1710 * @tc.desc: Test IsXKey 1711 * @tc.type: FUNC 1712 * @tc.require: 1713 */ 1714 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_IsXKey_001, TestSize.Level1) 1715 { 1716 CALL_TEST_DEBUG; 1717 EventMonitorHandler::MonitorCollection eventMonitorHandler; 1718 std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create(); 1719 ASSERT_NE(pointerEvent, nullptr); 1720 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_X_KEY); 1721 bool ret = eventMonitorHandler.IsXKey(pointerEvent); 1722 ASSERT_TRUE(ret); 1723 pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); 1724 ret = eventMonitorHandler.IsXKey(pointerEvent); 1725 ASSERT_FALSE(ret); 1726 } 1727 #endif // OHOS_BUILD_ENABLE_X_KEY 1728 1729 /** 1730 * @tc.name: EventMonitorHandlerTest_CheckHasInputHandler_002 1731 * @tc.desc: Test CheckHasInputHandler 1732 * @tc.type: FUNC 1733 * @tc.require: 1734 */ 1735 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_CheckHasInputHandler_002, TestSize.Level1) 1736 { 1737 CALL_TEST_DEBUG; 1738 EventMonitorHandler eventMonitorHandler; 1739 HandleEventType eventType = 1; 1740 bool ret = eventMonitorHandler.CheckHasInputHandler(eventType); 1741 ASSERT_FALSE(ret); 1742 int32_t deviceId = 1; 1743 EventMonitorHandler::MonitorCollection::ConsumptionState consumptionState; 1744 consumptionState.isMonitorConsumed_ = true; 1745 eventMonitorHandler.monitors_.states_.insert(std::make_pair(deviceId, consumptionState)); 1746 ret = eventMonitorHandler.CheckHasInputHandler(eventType); 1747 ASSERT_FALSE(ret); 1748 } 1749 1750 #ifdef PLAYER_FRAMEWORK_EXISTS 1751 /** 1752 * @tc.name: EventMonitorHandlerTest_ProcessScreenCapture_005 1753 * @tc.desc: Test ProcessScreenCapture 1754 * @tc.type: FUNC 1755 * @tc.require: 1756 */ 1757 HWTEST_F(EventMonitorHandlerTest, EventMonitorHandlerTest_ProcessScreenCapture_005, TestSize.Level1) 1758 { 1759 CALL_TEST_DEBUG; 1760 EventMonitorHandler eventMonitorHandler; 1761 UDSServer udSever; 1762 InputHandler->udsServer_ = &udSever; 1763 auto udsServerPtr = InputHandler->GetUDSServer(); 1764 EXPECT_NE(udsServerPtr, nullptr); 1765 int32_t pid = 2; 1766 bool isStart = true; 1767 udSever.idxPidMap_.insert(std::make_pair(pid, 2)); 1768 eventMonitorHandler.ProcessScreenCapture(pid, isStart); 1769 isStart = false; 1770 eventMonitorHandler.ProcessScreenCapture(pid, isStart); 1771 } 1772 #endif // PLAYER_FRAMEWORK_EXISTS 1773 } // namespace MMI 1774 } // namespace OHOS 1775