diff --git a/service/window_manager/include/input_windows_manager.h b/service/window_manager/include/input_windows_manager.h index 8aaba17ee8db50d67c2a2eebc4cd1a245e8de563..b72d9c4d8d7084b58575ce1c9a78e6a3e125c49c 100644 --- a/service/window_manager/include/input_windows_manager.h +++ b/service/window_manager/include/input_windows_manager.h @@ -283,7 +283,7 @@ private: #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_POINTER std::vector HandleHardwareCursor(std::shared_ptr &physicalDisplayInfo, - int32_t physicalX, int32_t physicalY); + int32_t physicalX, int32_t physicalY); int32_t UpdateMouseTarget(std::shared_ptr pointerEvent); void UpdatePointerEvent(int32_t logicalX, int32_t logicalY, const std::shared_ptr& pointerEvent, const WindowInfo& touchWindow); diff --git a/service/window_manager/test/input_windows_manager_ex_test.cpp b/service/window_manager/test/input_windows_manager_ex_test.cpp index e2d90dbbb3d1d994d929285524f174641d89abc6..b3a7a0efbbf1aa4a285f4fbf4da10abe2c6b7b01 100644 --- a/service/window_manager/test/input_windows_manager_ex_test.cpp +++ b/service/window_manager/test/input_windows_manager_ex_test.cpp @@ -4340,5 +4340,182 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SkipPrivacyProtectionW isSkip = false; EXPECT_FALSE(inputWindowsManager->SkipPrivacyProtectionWindow(pointerEvent, isSkip)); } + +#ifdef OHOS_BUILD_ENABLE_POINTER +/** + * @tc.name: InputWindowsManagerTest_HandleHardWareCursorTest001 + * @tc.desc: Test the funcation HandleHardWareCursor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_HandleHardWareCursorTest001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr physicalDisplayInfo = std::make_shared(); + ASSERT_NE(physicalDisplayInfo, nullptr); + physicalDisplayInfo->direction = Direction::DIRECTION0; + physicalDisplayInfo->displayDirection = Direction::DIRECTION0; + physicalDisplayInfo->validWidth = 1024; + physicalDisplayInfo->validHeight = 768; + + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillOnce(Return(false)); + std::vector result = inputWindowsManager->HandleHardwareCursor(physicalDisplayInfo, 512, 384); + EXPECT_EQ(result[0], 512); + EXPECT_EQ(result[1], 384); +} + +/** + * @tc.name: InputWindowsManagerTest_HandleHardWareCursorTest002 + * @tc.desc: Test the funcation HandleHardWareCursor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_HandleHardWareCursorTest002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr physicalDisplayInfo = std::make_shared(); + ASSERT_NE(physicalDisplayInfo, nullptr); + physicalDisplayInfo->direction = Direction::DIRECTION90; + physicalDisplayInfo->displayDirection = Direction::DIRECTION0; + physicalDisplayInfo->validWidth = 1024; + physicalDisplayInfo->validHeight = 768; + + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + std::vector result = inputWindowsManager->HandleHardwareCursor(physicalDisplayInfo, 512, 384); +} + + +/** + * @tc.name: InputWindowsManagerTest_UpdateMouseTargetTest015 + * @tc.desc: Test the funcation UpdateMouseTarget + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateMouseTargetTest015, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->SetTargetDisplayId(1); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 300; + displayInfo.y = 500; + displayInfo.width = 1024; + displayInfo.height = 768; + displayInfo.displayDirection = Direction::DIRECTION0; + displayInfo.direction = Direction::DIRECTION180; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + it->second.displaysInfo.push_back(displayInfo); + } + PointerEvent::PointerItem item; + item.SetPointerId(1); + item.SetDisplayX(150); + item.SetDisplayY(300); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerId(1); + EXPECT_CALL(*messageParcelMock_, UpdateDisplayId(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, SelectWindowInfo(_, _, _)).WillOnce(Return(std::nullopt)); + EXPECT_CALL(*messageParcelMock_, GetHardCursorEnabled()).WillRepeatedly(Return(true)); + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + EXPECT_EQ(inputWindowsManager->UpdateMouseTarget(pointerEvent), RET_ERR); +} + +/** + * @tc.name: InputWindowsManagerTest_UpdateMouseTargetTest016 + * @tc.desc: Test the funcation UpdateMouseTarget + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateMouseTargetTest016, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->SetTargetDisplayId(1); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 300; + displayInfo.y = 500; + displayInfo.width = 1024; + displayInfo.height = 768; + displayInfo.displayDirection = Direction::DIRECTION0; + displayInfo.direction = Direction::DIRECTION180; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + it->second.displaysInfo.push_back(displayInfo); + } + PointerEvent::PointerItem item; + item.SetPointerId(1); + item.SetDisplayX(150); + item.SetDisplayY(300); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerId(1); + EXPECT_CALL(*messageParcelMock_, UpdateDisplayId(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, SelectWindowInfo(_, _, _)).WillOnce(Return(std::nullopt)); + EXPECT_CALL(*messageParcelMock_, GetHardCursorEnabled()).WillRepeatedly(Return(false)); + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + EXPECT_EQ(inputWindowsManager->UpdateMouseTarget(pointerEvent), RET_ERR); +} + +/** + * @tc.name: InputWindowsManagerTest_UpdateMouseTargetTest017 + * @tc.desc: Test the funcation UpdateMouseTarget + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateMouseTargetTest017, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputWindowsManager = + std::static_pointer_cast(WIN_MGR); + ASSERT_NE(inputWindowsManager, nullptr); + std::shared_ptr pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->SetTargetDisplayId(1); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 300; + displayInfo.y = 500; + displayInfo.width = 1024; + displayInfo.height = 768; + displayInfo.displayDirection = Direction::DIRECTION0; + displayInfo.direction = Direction::DIRECTION180; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + it->second.displaysInfo.push_back(displayInfo); + } + PointerEvent::PointerItem item; + item.SetPointerId(1); + item.SetDisplayX(150); + item.SetDisplayY(300); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerId(1); + EXPECT_CALL(*messageParcelMock_, UpdateDisplayId(_)).WillOnce(Return(true)); + EXPECT_CALL(*messageParcelMock_, SelectWindowInfo(_, _, _)).WillOnce(Return(std::nullopt)); + EXPECT_CALL(*messageParcelMock_, GetHardCursorEnabled()).WillRepeatedly(Return(true)); + EXPECT_CALL(*messageParcelMock_, HandleHardwareCursor(_, _, _)).WillOnce(Return(std::vector({ 1 }))); + EXPECT_CALL(*messageParcelMock_, IsSceneBoardEnabled()).WillRepeatedly(Return(true)); + EXPECT_EQ(inputWindowsManager->UpdateMouseTarget(pointerEvent), RET_ERR); +} + +#endif /* OHOS_BUILD_ENABLE_POINTER */ + } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/window_manager/test/mock.h b/service/window_manager/test/mock.h index a74054a843bc34542ac14d5227ef63e864ad287f..02cc8ea3f368c3c8c91b73498f1fae9f431d4e53 100644 --- a/service/window_manager/test/mock.h +++ b/service/window_manager/test/mock.h @@ -54,6 +54,12 @@ public: virtual bool IsWindowRotation() = 0; virtual int32_t GetDisplayId() = 0; virtual std::string GetBindDisplayNameByInputDevice(int32_t inputDeviceId) = 0; + virtual std::optional SelectWindowInfo(int32_t logicalX, int32_t logicalY, + const std::shared_ptr& pointerEvent) = 0; + virtual bool UpdateDisplayId(int32_t& displayId) = 0; + virtual bool GetHardCursorEnabled() = 0; + virtual std::vector HandleHardwareCursor(std::shared_ptr &physicalDisplayInfo, + int32_t physicalX, int32_t physicalY) = 0; public: static inline std::shared_ptr messageParcel = nullptr; }; @@ -71,6 +77,12 @@ public: MOCK_METHOD0(IsSceneBoardEnabled, bool()); MOCK_METHOD0(IsWindowRotation, bool()); MOCK_METHOD0(GetDisplayId, int32_t()); + MOCK_METHOD3(SelectWindowInfo, std::optional(int32_t logicalX, int32_t logicalY, + const std::shared_ptr& pointerEvent)); + MOCK_METHOD1(UpdateDisplayId, bool(int32_t& displayId)); + MOCK_METHOD0(GetHardCursorEnabled, bool()); + MOCK_METHOD3(HandleHardwareCursor, std::vector(std::shared_ptr &physicalDisplayInfo, + int32_t physicalX, int32_t physicalY)); }; } // namespace MMI } // namespace OHOS