Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <memory> |
| 18 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 19 | #include <com_android_input_flags.h> |
| 20 | #include <flag_macros.h> |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 21 | #include <gestures/GestureConverter.h> |
| 22 | #include <gtest/gtest.h> |
| 23 | |
| 24 | #include "FakeEventHub.h" |
| 25 | #include "FakeInputReaderPolicy.h" |
| 26 | #include "FakePointerController.h" |
| 27 | #include "InstrumentedInputReader.h" |
| 28 | #include "NotifyArgs.h" |
| 29 | #include "TestConstants.h" |
Prabir Pradhan | e3b28dd | 2023-10-06 04:19:29 +0000 | [diff] [blame] | 30 | #include "TestEventMatchers.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 31 | #include "TestInputListener.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 32 | #include "include/gestures.h" |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 33 | #include "ui/Rotation.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 37 | namespace input_flags = com::android::input::flags; |
| 38 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 39 | namespace { |
| 40 | |
| 41 | const auto TOUCHPAD_PALM_REJECTION = |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 42 | ACONFIG_FLAG(input_flags, enable_touchpad_typing_palm_rejection); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 43 | const auto TOUCHPAD_PALM_REJECTION_V2 = |
| 44 | ACONFIG_FLAG(input_flags, enable_v2_touchpad_typing_palm_rejection); |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 45 | |
| 46 | } // namespace |
| 47 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 48 | using testing::AllOf; |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 49 | using testing::Each; |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 50 | using testing::ElementsAre; |
| 51 | using testing::VariantWith; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 52 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 53 | class GestureConverterTest : public testing::Test { |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 54 | protected: |
| 55 | static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 56 | static constexpr int32_t EVENTHUB_ID = 1; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 57 | static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 58 | |
| 59 | void SetUp() { |
| 60 | mFakeEventHub = std::make_unique<FakeEventHub>(); |
| 61 | mFakePolicy = sp<FakeInputReaderPolicy>::make(); |
| 62 | mFakeListener = std::make_unique<TestInputListener>(); |
| 63 | mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, |
| 64 | *mFakeListener); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 65 | mDevice = newDevice(); |
| 66 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20); |
| 67 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 70 | std::shared_ptr<InputDevice> newDevice() { |
| 71 | InputDeviceIdentifier identifier; |
| 72 | identifier.name = "device"; |
| 73 | identifier.location = "USB1"; |
| 74 | identifier.bus = 0; |
| 75 | std::shared_ptr<InputDevice> device = |
| 76 | std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2, |
| 77 | identifier); |
| 78 | mReader->pushNextDevice(device); |
| 79 | mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD, |
| 80 | identifier.bus); |
| 81 | mReader->loopOnce(); |
| 82 | return device; |
| 83 | } |
| 84 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 85 | std::shared_ptr<FakeEventHub> mFakeEventHub; |
| 86 | sp<FakeInputReaderPolicy> mFakePolicy; |
| 87 | std::unique_ptr<TestInputListener> mFakeListener; |
| 88 | std::unique_ptr<InstrumentedInputReader> mReader; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 89 | std::shared_ptr<InputDevice> mDevice; |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 90 | }; |
| 91 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 92 | TEST_F(GestureConverterTest, Move) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 93 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 94 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 95 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 96 | |
| 97 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 98 | std::list<NotifyArgs> args = |
| 99 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 100 | ASSERT_THAT(args, |
| 101 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 102 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 103 | WithRelativeMotion(0, 0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 104 | VariantWith<NotifyMotionArgs>( |
| 105 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 106 | WithRelativeMotion(-5, 10), WithButtonState(0), |
| 107 | WithPressure(0.0f))))); |
| 108 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 109 | Each(VariantWith<NotifyMotionArgs>( |
| 110 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 111 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 112 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 113 | // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER. |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 114 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 115 | ASSERT_THAT(args, |
| 116 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 117 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 118 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
| 119 | WithButtonState(0), WithPressure(0.0f), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 120 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 123 | TEST_F(GestureConverterTest, Move_Rotated) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 124 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 125 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 126 | converter.setOrientation(ui::ROTATION_90); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 127 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 128 | |
| 129 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 130 | std::list<NotifyArgs> args = |
| 131 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 132 | ASSERT_THAT(args, |
| 133 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 134 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 135 | WithRelativeMotion(0, 0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 136 | VariantWith<NotifyMotionArgs>( |
| 137 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 138 | WithRelativeMotion(10, 5), WithButtonState(0), |
| 139 | WithPressure(0.0f))))); |
| 140 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 141 | Each(VariantWith<NotifyMotionArgs>( |
| 142 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 143 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 146 | TEST_F(GestureConverterTest, ButtonsChange) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 147 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 148 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 149 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 150 | |
| 151 | // Press left and right buttons at once |
| 152 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 153 | /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 154 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 155 | std::list<NotifyArgs> args = |
| 156 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 157 | ASSERT_THAT(args, |
| 158 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 159 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 160 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 161 | AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 162 | VariantWith<NotifyMotionArgs>( |
| 163 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 164 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 165 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 166 | VariantWith<NotifyMotionArgs>( |
| 167 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 168 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 169 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 170 | AMOTION_EVENT_BUTTON_SECONDARY))))); |
| 171 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 172 | Each(VariantWith<NotifyMotionArgs>( |
| 173 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 174 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 175 | |
| 176 | // Then release the left button |
| 177 | Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 178 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 179 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 180 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 181 | ASSERT_THAT(args, |
| 182 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 183 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 184 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 185 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0), |
| 186 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 187 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 188 | |
| 189 | // Finally release the right button |
| 190 | Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 191 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT, |
| 192 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 193 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 194 | ASSERT_THAT(args, |
| 195 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 196 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 197 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 198 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 199 | WithMotionAction(AMOTION_EVENT_ACTION_UP)), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 200 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 201 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
| 202 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 203 | Each(VariantWith<NotifyMotionArgs>( |
| 204 | AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 205 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 208 | TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { |
| 209 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 210 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 211 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 212 | |
| 213 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 214 | std::list<NotifyArgs> args = |
| 215 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 216 | |
| 217 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 218 | /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE, |
| 219 | /*is_tap=*/false); |
| 220 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
| 221 | ASSERT_THAT(args.front(), |
| 222 | VariantWith<NotifyMotionArgs>( |
| 223 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 224 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 225 | WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 228 | TEST_F(GestureConverterTest, DragWithButton) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 229 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 230 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 231 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 232 | |
| 233 | // Press the button |
| 234 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 235 | /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE, |
| 236 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 237 | std::list<NotifyArgs> args = |
| 238 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 239 | ASSERT_THAT(args, |
| 240 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 241 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 242 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 243 | VariantWith<NotifyMotionArgs>( |
| 244 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 245 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 246 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))))); |
| 247 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 248 | Each(VariantWith<NotifyMotionArgs>( |
| 249 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 250 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 251 | |
| 252 | // Move |
| 253 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 254 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 255 | ASSERT_THAT(args, |
| 256 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 257 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0), |
| 258 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 259 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 260 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 261 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 262 | // Release the button |
| 263 | Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 264 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 265 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 266 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 267 | ASSERT_THAT(args, |
| 268 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 269 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 270 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 271 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 272 | WithMotionAction(AMOTION_EVENT_ACTION_UP)), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 273 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 274 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
| 275 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 276 | Each(VariantWith<NotifyMotionArgs>( |
| 277 | AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 278 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 281 | TEST_F(GestureConverterTest, Scroll) { |
| 282 | const nsecs_t downTime = 12345; |
| 283 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 284 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 285 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 286 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 287 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 288 | std::list<NotifyArgs> args = |
| 289 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 290 | ASSERT_THAT(args, |
| 291 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 292 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 293 | WithCoords(0, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 294 | WithGestureScrollDistance(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 295 | WithDownTime(downTime))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 296 | VariantWith<NotifyMotionArgs>( |
| 297 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 298 | WithCoords(0, -10), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 299 | WithGestureScrollDistance(0, 10, EPSILON))))); |
| 300 | ASSERT_THAT(args, |
| 301 | Each(VariantWith<NotifyMotionArgs>( |
| 302 | AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 303 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 304 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 305 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 306 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 307 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 308 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 309 | ASSERT_THAT(args, |
| 310 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 311 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 312 | WithGestureScrollDistance(0, 5, EPSILON), |
| 313 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 314 | WithToolType(ToolType::FINGER), |
| 315 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 316 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 317 | |
| 318 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 319 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 320 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 321 | ASSERT_THAT(args, |
| 322 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 323 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 324 | WithCoords(0, -15), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 325 | WithGestureScrollDistance(0, 0, EPSILON), |
| 326 | WithMotionClassification( |
| 327 | MotionClassification::TWO_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 328 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 329 | VariantWith<NotifyMotionArgs>( |
| 330 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 331 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 332 | WithMotionClassification(MotionClassification::NONE))))); |
| 333 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 334 | Each(VariantWith<NotifyMotionArgs>( |
| 335 | AllOf(WithToolType(ToolType::FINGER), |
| 336 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | TEST_F(GestureConverterTest, Scroll_Rotated) { |
| 340 | const nsecs_t downTime = 12345; |
| 341 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 342 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 343 | converter.setOrientation(ui::ROTATION_90); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 344 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 345 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 346 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 347 | std::list<NotifyArgs> args = |
| 348 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 349 | ASSERT_THAT(args, |
| 350 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 351 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 352 | WithCoords(0, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 353 | WithGestureScrollDistance(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 354 | WithDownTime(downTime))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 355 | VariantWith<NotifyMotionArgs>( |
| 356 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 357 | WithCoords(-10, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 358 | WithGestureScrollDistance(0, 10, EPSILON))))); |
| 359 | ASSERT_THAT(args, |
| 360 | Each(VariantWith<NotifyMotionArgs>( |
| 361 | AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 362 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 363 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 364 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 365 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 366 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 367 | ASSERT_THAT(args, |
| 368 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 369 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 370 | WithGestureScrollDistance(0, 5, EPSILON), |
| 371 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 372 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 373 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 374 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 375 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 376 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 377 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 378 | ASSERT_THAT(args, |
| 379 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 380 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 381 | WithCoords(-15, 0), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 382 | WithGestureScrollDistance(0, 0, EPSILON), |
| 383 | WithMotionClassification( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 384 | MotionClassification::TWO_FINGER_SWIPE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 385 | VariantWith<NotifyMotionArgs>( |
| 386 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 387 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 388 | WithMotionClassification(MotionClassification::NONE))))); |
| 389 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 390 | Each(VariantWith<NotifyMotionArgs>( |
| 391 | AllOf(WithToolType(ToolType::FINGER), |
| 392 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 395 | TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 396 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 397 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 398 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 399 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 400 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 401 | std::list<NotifyArgs> args = |
| 402 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 403 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 404 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 405 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 406 | |
| 407 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 408 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 409 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 410 | |
| 411 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 412 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 413 | ASSERT_THAT(args, |
| 414 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 415 | AllOf(WithMotionClassification(MotionClassification::NONE), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 416 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 419 | TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 420 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 421 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 422 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 423 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 424 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 425 | std::list<NotifyArgs> args = |
| 426 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 427 | |
| 428 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 429 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 430 | |
| 431 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 432 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 433 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 434 | |
| 435 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 436 | // need to use another gesture type, like pinch. |
| 437 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 438 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 439 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 440 | ASSERT_FALSE(args.empty()); |
| 441 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON)); |
| 442 | } |
| 443 | |
Prabir Pradhan | 13acbd2 | 2024-05-14 22:36:40 +0000 | [diff] [blame] | 444 | TEST_F(GestureConverterTest, Scroll_ClearsFakeFingerPositionOnSubsequentScrollGestures) { |
| 445 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 446 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 447 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
| 448 | |
| 449 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 15, -10); |
| 450 | std::list<NotifyArgs> args = |
| 451 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
| 452 | |
| 453 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -2, -5); |
| 454 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
| 455 | |
| 456 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 457 | GESTURES_FLING_START); |
| 458 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
| 459 | Gesture flingGestureEnd(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, 0, |
| 460 | GESTURES_FLING_TAP_DOWN); |
| 461 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGestureEnd); |
| 462 | |
| 463 | // Start a second scoll gesture, and ensure the fake finger is reset to (0, 0), instead of |
| 464 | // continuing from the position where the last scroll gesture's fake finger ended. |
| 465 | Gesture secondScrollStart(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 2, |
| 466 | 14); |
| 467 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, secondScrollStart); |
| 468 | ASSERT_THAT(args, |
| 469 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 470 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)), |
| 471 | VariantWith<NotifyMotionArgs>( |
| 472 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 473 | WithCoords(0, 0), |
| 474 | WithGestureScrollDistance(0, 0, EPSILON))), |
| 475 | VariantWith<NotifyMotionArgs>( |
| 476 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 477 | WithCoords(2, 14), |
| 478 | WithGestureScrollDistance(-2, -14, EPSILON))))); |
| 479 | } |
| 480 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 481 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) { |
| 482 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 483 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 484 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 485 | |
| 486 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 487 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 488 | std::list<NotifyArgs> args = |
| 489 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 490 | |
| 491 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 492 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 493 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 494 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, |
| 495 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 496 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 497 | ASSERT_THAT(args, |
| 498 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 499 | WithMotionClassification(MotionClassification::NONE)))); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 502 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 503 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 504 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 505 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 506 | |
| 507 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, |
| 508 | /*dy=*/5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 509 | std::list<NotifyArgs> args = |
| 510 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 511 | |
| 512 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 513 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 514 | |
| 515 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 516 | // need to use another gesture type, like pinch. |
| 517 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 518 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 519 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 520 | ASSERT_FALSE(args.empty()); |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 521 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 522 | AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { |
| 526 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 527 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 528 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 529 | // only checks movement in one dimension. |
| 530 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 531 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 532 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 533 | |
| 534 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 535 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 536 | std::list<NotifyArgs> args = |
| 537 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 538 | ASSERT_EQ(4u, args.size()); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 539 | ASSERT_THAT(args, |
| 540 | Each(VariantWith<NotifyMotionArgs>( |
| 541 | AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 542 | WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 543 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 544 | |
| 545 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 546 | // move appropriately. |
| 547 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 548 | ASSERT_THAT(arg, |
| 549 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 550 | WithPointerCount(1u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 551 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 552 | args.pop_front(); |
| 553 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 554 | ASSERT_THAT(arg, |
| 555 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 556 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 557 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 558 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 559 | args.pop_front(); |
| 560 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 561 | ASSERT_THAT(arg, |
| 562 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 563 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 564 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 565 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 566 | args.pop_front(); |
| 567 | |
| 568 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 569 | ASSERT_THAT(arg, |
| 570 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 571 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 572 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 573 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 574 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 575 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 576 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 577 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 578 | |
| 579 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 580 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 581 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 582 | ASSERT_EQ(1u, args.size()); |
| 583 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 584 | ASSERT_THAT(arg, |
| 585 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 586 | WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 587 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 588 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 589 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 590 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 591 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 592 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 593 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 594 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 595 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 596 | |
| 597 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 598 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 599 | ASSERT_THAT(args, |
| 600 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 601 | AllOf(WithMotionAction( |
| 602 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 603 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 604 | WithGestureOffset(0, 0, EPSILON), |
| 605 | WithGestureSwipeFingerCount(3), |
| 606 | WithMotionClassification( |
| 607 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 608 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 609 | VariantWith<NotifyMotionArgs>( |
| 610 | AllOf(WithMotionAction( |
| 611 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 612 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 613 | WithGestureOffset(0, 0, EPSILON), |
| 614 | WithGestureSwipeFingerCount(3), |
| 615 | WithMotionClassification( |
| 616 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 617 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 618 | VariantWith<NotifyMotionArgs>( |
| 619 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 620 | WithGestureOffset(0, 0, EPSILON), |
| 621 | WithGestureSwipeFingerCount(3), |
| 622 | WithMotionClassification( |
| 623 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 624 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 625 | VariantWith<NotifyMotionArgs>( |
| 626 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 627 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 628 | WithMotionClassification(MotionClassification::NONE))))); |
| 629 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 630 | Each(VariantWith<NotifyMotionArgs>( |
| 631 | AllOf(WithToolType(ToolType::FINGER), |
| 632 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 635 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { |
| 636 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 637 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 638 | converter.setOrientation(ui::ROTATION_90); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 639 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 640 | |
| 641 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 642 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 643 | std::list<NotifyArgs> args = |
| 644 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 645 | ASSERT_EQ(4u, args.size()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 646 | ASSERT_THAT(args, |
| 647 | Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 648 | |
| 649 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 650 | // move appropriately. |
| 651 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 652 | ASSERT_THAT(arg, |
| 653 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 654 | WithPointerCount(1u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 655 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 656 | args.pop_front(); |
| 657 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 658 | ASSERT_THAT(arg, |
| 659 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 660 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 661 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 662 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 663 | args.pop_front(); |
| 664 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 665 | ASSERT_THAT(arg, |
| 666 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 667 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 668 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 669 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 670 | args.pop_front(); |
| 671 | |
| 672 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 673 | ASSERT_THAT(arg, |
| 674 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 675 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 676 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 677 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 678 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 679 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 680 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 681 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 682 | |
| 683 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 684 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 685 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 686 | ASSERT_EQ(1u, args.size()); |
| 687 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 688 | ASSERT_THAT(arg, |
| 689 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 690 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 691 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 692 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 693 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 694 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 695 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 696 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 697 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 698 | |
| 699 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 700 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 701 | ASSERT_THAT(args, |
| 702 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 703 | AllOf(WithMotionAction( |
| 704 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 705 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 706 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 707 | VariantWith<NotifyMotionArgs>( |
| 708 | AllOf(WithMotionAction( |
| 709 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 710 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 711 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 712 | VariantWith<NotifyMotionArgs>( |
| 713 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 714 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 715 | VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 716 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))))); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 717 | ASSERT_THAT(args, |
| 718 | Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 721 | TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { |
| 722 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 723 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 724 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 725 | |
| 726 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 727 | /* dx= */ 10, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 728 | std::list<NotifyArgs> args = |
| 729 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 730 | ASSERT_EQ(5u, args.size()); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 731 | ASSERT_THAT(args, |
| 732 | Each(VariantWith<NotifyMotionArgs>( |
| 733 | AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 734 | WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 735 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 736 | |
| 737 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 738 | // move appropriately. |
| 739 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 740 | ASSERT_THAT(arg, |
| 741 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 742 | WithPointerCount(1u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 743 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 744 | args.pop_front(); |
| 745 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 746 | ASSERT_THAT(arg, |
| 747 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 748 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 749 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 750 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 751 | args.pop_front(); |
| 752 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 753 | ASSERT_THAT(arg, |
| 754 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 755 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 756 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 757 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 758 | args.pop_front(); |
| 759 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 760 | ASSERT_THAT(arg, |
| 761 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 762 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 763 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 764 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 765 | args.pop_front(); |
| 766 | |
| 767 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 768 | ASSERT_THAT(arg, |
| 769 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 770 | WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 771 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 772 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 773 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 774 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 775 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 776 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 777 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 778 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 779 | |
| 780 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 781 | /* dx= */ 5, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 782 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 783 | ASSERT_EQ(1u, args.size()); |
| 784 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 785 | ASSERT_THAT(arg, |
| 786 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 787 | WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 788 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 789 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 790 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 791 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 792 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 793 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 794 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 795 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 796 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 797 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 798 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 799 | |
| 800 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 801 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 802 | ASSERT_THAT(args, |
| 803 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 804 | AllOf(WithMotionAction( |
| 805 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 806 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 807 | WithGestureOffset(0, 0, EPSILON), |
| 808 | WithGestureSwipeFingerCount(4), |
| 809 | WithMotionClassification( |
| 810 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 811 | WithPointerCount(4u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 812 | VariantWith<NotifyMotionArgs>( |
| 813 | AllOf(WithMotionAction( |
| 814 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 815 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 816 | WithGestureOffset(0, 0, EPSILON), |
| 817 | WithGestureSwipeFingerCount(4), |
| 818 | WithMotionClassification( |
| 819 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 820 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 821 | VariantWith<NotifyMotionArgs>( |
| 822 | AllOf(WithMotionAction( |
| 823 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 824 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 825 | WithGestureOffset(0, 0, EPSILON), |
| 826 | WithGestureSwipeFingerCount(4), |
| 827 | WithMotionClassification( |
| 828 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 829 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 830 | VariantWith<NotifyMotionArgs>( |
| 831 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 832 | WithGestureOffset(0, 0, EPSILON), |
| 833 | WithGestureSwipeFingerCount(4), |
| 834 | WithMotionClassification( |
| 835 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 836 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 837 | VariantWith<NotifyMotionArgs>( |
| 838 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 839 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 840 | WithMotionClassification(MotionClassification::NONE))))); |
| 841 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 842 | Each(VariantWith<NotifyMotionArgs>( |
| 843 | AllOf(WithToolType(ToolType::FINGER), |
| 844 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 847 | TEST_F(GestureConverterTest, Pinch_Inwards) { |
| 848 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 849 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 850 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 851 | |
| 852 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 853 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 854 | std::list<NotifyArgs> args = |
| 855 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 856 | ASSERT_THAT(args, |
| 857 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 858 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 859 | WithCoords(-100, 0), WithPointerCount(1u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 860 | VariantWith<NotifyMotionArgs>( |
| 861 | AllOf(WithMotionAction( |
| 862 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 863 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 864 | WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 865 | ASSERT_THAT(args, |
| 866 | Each(VariantWith<NotifyMotionArgs>( |
| 867 | AllOf(WithMotionClassification(MotionClassification::PINCH), |
| 868 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 869 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 870 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 871 | |
| 872 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 873 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 874 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 875 | ASSERT_THAT(args, |
| 876 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 877 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 878 | WithMotionClassification(MotionClassification::PINCH), |
| 879 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 880 | WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 881 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 882 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 883 | |
| 884 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 885 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 886 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 887 | ASSERT_THAT(args, |
| 888 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 889 | AllOf(WithMotionAction( |
| 890 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 891 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 892 | WithMotionClassification(MotionClassification::PINCH), |
| 893 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 894 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 895 | VariantWith<NotifyMotionArgs>( |
| 896 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 897 | WithMotionClassification(MotionClassification::PINCH), |
| 898 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 899 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 900 | VariantWith<NotifyMotionArgs>( |
| 901 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 902 | WithCoords(0, 0), |
| 903 | WithMotionClassification(MotionClassification::NONE))))); |
| 904 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 905 | Each(VariantWith<NotifyMotionArgs>( |
| 906 | AllOf(WithToolType(ToolType::FINGER), |
| 907 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | TEST_F(GestureConverterTest, Pinch_Outwards) { |
| 911 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 912 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 913 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 914 | |
| 915 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 916 | GESTURES_ZOOM_START); |
| 917 | std::list<NotifyArgs> args = |
| 918 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
| 919 | ASSERT_THAT(args, |
| 920 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 921 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 922 | WithCoords(-100, 0), WithPointerCount(1u))), |
| 923 | VariantWith<NotifyMotionArgs>( |
| 924 | AllOf(WithMotionAction( |
| 925 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 926 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 927 | WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); |
| 928 | ASSERT_THAT(args, |
| 929 | Each(VariantWith<NotifyMotionArgs>( |
| 930 | AllOf(WithMotionClassification(MotionClassification::PINCH), |
| 931 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 932 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 933 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 934 | |
| 935 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 936 | /* dz= */ 1.1, GESTURES_ZOOM_UPDATE); |
| 937 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
| 938 | ASSERT_THAT(args, |
| 939 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 940 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 941 | WithMotionClassification(MotionClassification::PINCH), |
| 942 | WithGesturePinchScaleFactor(1.1f, EPSILON), |
| 943 | WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0), |
| 944 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 945 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 946 | |
| 947 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 948 | GESTURES_ZOOM_END); |
| 949 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
| 950 | ASSERT_THAT(args, |
| 951 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 952 | AllOf(WithMotionAction( |
| 953 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 954 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 955 | WithMotionClassification(MotionClassification::PINCH), |
| 956 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 957 | WithPointerCount(2u))), |
| 958 | VariantWith<NotifyMotionArgs>( |
| 959 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 960 | WithMotionClassification(MotionClassification::PINCH), |
| 961 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 962 | WithPointerCount(1u))), |
| 963 | VariantWith<NotifyMotionArgs>( |
| 964 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 965 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 966 | WithMotionClassification(MotionClassification::NONE))))); |
| 967 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 968 | Each(VariantWith<NotifyMotionArgs>( |
| 969 | AllOf(WithToolType(ToolType::FINGER), |
| 970 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 973 | TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 974 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 975 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 976 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 977 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 978 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 979 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 980 | std::list<NotifyArgs> args = |
| 981 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 982 | |
| 983 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 984 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 985 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 986 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 987 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 988 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 989 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 990 | |
| 991 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 992 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 993 | ASSERT_THAT(args, |
| 994 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 995 | WithMotionClassification(MotionClassification::NONE)))); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { |
| 999 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1000 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1001 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1002 | |
| 1003 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1004 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1005 | std::list<NotifyArgs> args = |
| 1006 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1007 | |
| 1008 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1009 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1010 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1011 | |
| 1012 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1013 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1014 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1015 | |
| 1016 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 1017 | // need to use another gesture type, like scroll. |
| 1018 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 1019 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1020 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1021 | ASSERT_FALSE(args.empty()); |
| 1022 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1025 | TEST_F(GestureConverterTest, ResetWithButtonPressed) { |
| 1026 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1027 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1028 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1029 | |
| 1030 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1031 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 1032 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1033 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1034 | |
| 1035 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1036 | ASSERT_THAT(args, |
| 1037 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1038 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1039 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1040 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1041 | VariantWith<NotifyMotionArgs>( |
| 1042 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1043 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1044 | WithButtonState(0))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1045 | VariantWith<NotifyMotionArgs>( |
| 1046 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1047 | WithButtonState(0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1048 | VariantWith<NotifyMotionArgs>( |
| 1049 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1050 | WithButtonState(0))))); |
| 1051 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1052 | Each(VariantWith<NotifyMotionArgs>( |
| 1053 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1054 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | TEST_F(GestureConverterTest, ResetDuringScroll) { |
| 1058 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1059 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1060 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1061 | |
| 1062 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1063 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1064 | |
| 1065 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1066 | ASSERT_THAT(args, |
| 1067 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1068 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1069 | WithCoords(0, -10), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1070 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1071 | WithMotionClassification( |
| 1072 | MotionClassification::TWO_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1073 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1074 | VariantWith<NotifyMotionArgs>( |
| 1075 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1076 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1077 | WithMotionClassification(MotionClassification::NONE))))); |
| 1078 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1079 | Each(VariantWith<NotifyMotionArgs>( |
| 1080 | AllOf(WithToolType(ToolType::FINGER), |
| 1081 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { |
| 1085 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1086 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1087 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1088 | |
| 1089 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 1090 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1091 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1092 | |
| 1093 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1094 | ASSERT_THAT(args, |
| 1095 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1096 | AllOf(WithMotionAction( |
| 1097 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1098 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1099 | WithGestureOffset(0, 0, EPSILON), |
| 1100 | WithMotionClassification( |
| 1101 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1102 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1103 | VariantWith<NotifyMotionArgs>( |
| 1104 | AllOf(WithMotionAction( |
| 1105 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1106 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1107 | WithGestureOffset(0, 0, EPSILON), |
| 1108 | WithMotionClassification( |
| 1109 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1110 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1111 | VariantWith<NotifyMotionArgs>( |
| 1112 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1113 | WithGestureOffset(0, 0, EPSILON), |
| 1114 | WithMotionClassification( |
| 1115 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1116 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1117 | VariantWith<NotifyMotionArgs>( |
| 1118 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1119 | WithMotionClassification(MotionClassification::NONE))))); |
| 1120 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1121 | Each(VariantWith<NotifyMotionArgs>( |
| 1122 | AllOf(WithToolType(ToolType::FINGER), |
| 1123 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | TEST_F(GestureConverterTest, ResetDuringPinch) { |
| 1127 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1128 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1129 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1130 | |
| 1131 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1132 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1133 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1134 | |
| 1135 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1136 | ASSERT_THAT(args, |
| 1137 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1138 | AllOf(WithMotionAction( |
| 1139 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1140 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1141 | WithMotionClassification(MotionClassification::PINCH), |
| 1142 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1143 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1144 | VariantWith<NotifyMotionArgs>( |
| 1145 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1146 | WithMotionClassification(MotionClassification::PINCH), |
| 1147 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1148 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1149 | VariantWith<NotifyMotionArgs>( |
| 1150 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1151 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1152 | WithMotionClassification(MotionClassification::NONE))))); |
| 1153 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1154 | Each(VariantWith<NotifyMotionArgs>( |
| 1155 | AllOf(WithToolType(ToolType::FINGER), |
| 1156 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1159 | TEST_F(GestureConverterTest, FlingTapDown) { |
| 1160 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1161 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1162 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1163 | |
| 1164 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1165 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1166 | std::list<NotifyArgs> args = |
| 1167 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1168 | |
| 1169 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1170 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), |
| 1171 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1172 | WithButtonState(0), WithPressure(0.0f), |
| 1173 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1176 | TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) { |
| 1177 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1178 | input_flags::enable_touchpad_fling_stop(true); |
| 1179 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1180 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1181 | |
| 1182 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 1183 | std::list<NotifyArgs> args = |
| 1184 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
| 1185 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1186 | GESTURES_FLING_START); |
| 1187 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
| 1188 | |
| 1189 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1190 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
| 1191 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
| 1192 | ASSERT_THAT(args, |
| 1193 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1194 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)), |
| 1195 | VariantWith<NotifyMotionArgs>( |
| 1196 | WithMotionAction(AMOTION_EVENT_ACTION_DOWN)), |
| 1197 | VariantWith<NotifyMotionArgs>( |
| 1198 | WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)), |
| 1199 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 574781a | 2024-04-23 15:30:45 +0000 | [diff] [blame] | 1200 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1201 | ASSERT_THAT(args, |
Harry Cutts | 574781a | 2024-04-23 15:30:45 +0000 | [diff] [blame] | 1202 | Each(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1203 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1204 | WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
Harry Cutts | 574781a | 2024-04-23 15:30:45 +0000 | [diff] [blame] | 1205 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE))))); |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1208 | TEST_F(GestureConverterTest, Tap) { |
| 1209 | // Tap should produce button press/release events |
| 1210 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1211 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1212 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1213 | |
| 1214 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1215 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1216 | std::list<NotifyArgs> args = |
| 1217 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1218 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1219 | |
| 1220 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1221 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1222 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1223 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1224 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1225 | ASSERT_THAT(args, |
| 1226 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1227 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1228 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1229 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1230 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1231 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1232 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1233 | VariantWith<NotifyMotionArgs>( |
| 1234 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1235 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1236 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1237 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1238 | VariantWith<NotifyMotionArgs>( |
| 1239 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1240 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1241 | WithButtonState(0), WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1242 | VariantWith<NotifyMotionArgs>( |
| 1243 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1244 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1245 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1246 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1247 | WithButtonState(0), WithPressure(0.0f))))); |
| 1248 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1249 | Each(VariantWith<NotifyMotionArgs>( |
| 1250 | AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1251 | WithToolType(ToolType::FINGER), |
| 1252 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | TEST_F(GestureConverterTest, Click) { |
| 1256 | // Click should produce button press/release events |
| 1257 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1258 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1259 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1260 | |
| 1261 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1262 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1263 | std::list<NotifyArgs> args = |
| 1264 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1265 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1266 | |
| 1267 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1268 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1269 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1270 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1271 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1272 | ASSERT_THAT(args, |
| 1273 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1274 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1275 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1276 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1277 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1278 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1279 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1280 | VariantWith<NotifyMotionArgs>( |
| 1281 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1282 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1283 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1284 | WithPressure(1.0f))))); |
| 1285 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1286 | Each(VariantWith<NotifyMotionArgs>( |
| 1287 | AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1288 | WithToolType(ToolType::FINGER), |
| 1289 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1290 | |
| 1291 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1292 | /* down= */ GESTURES_BUTTON_NONE, |
| 1293 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1294 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1295 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1296 | ASSERT_THAT(args, |
| 1297 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1298 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1299 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1300 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1301 | VariantWith<NotifyMotionArgs>( |
| 1302 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1303 | WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1304 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1305 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1306 | WithPressure(0.0f))))); |
| 1307 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1308 | Each(VariantWith<NotifyMotionArgs>( |
| 1309 | AllOf(WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1310 | WithToolType(ToolType::FINGER), |
| 1311 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1314 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1315 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION), |
| 1316 | REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1317 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1318 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1319 | // Tap should be ignored when disabled |
| 1320 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1321 | |
| 1322 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1323 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1324 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1325 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1326 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1327 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1328 | std::list<NotifyArgs> args = |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1329 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1330 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1331 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1332 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1333 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1334 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1335 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1336 | |
| 1337 | // no events should be generated |
| 1338 | ASSERT_EQ(0u, args.size()); |
| 1339 | |
| 1340 | // Future taps should be re-enabled |
| 1341 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1342 | } |
| 1343 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1344 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay, |
| 1345 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1346 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1347 | |
| 1348 | // Tap should be ignored when disabled |
| 1349 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1350 | |
| 1351 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1352 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1353 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1354 | |
| 1355 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1356 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1357 | std::list<NotifyArgs> args = |
| 1358 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1359 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1360 | |
| 1361 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
| 1362 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1363 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1364 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1365 | |
| 1366 | // no events should be generated |
| 1367 | ASSERT_EQ(0u, args.size()); |
| 1368 | |
| 1369 | // Future taps should be re-enabled |
| 1370 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1371 | |
| 1372 | // taps before the threshold should still be ignored |
| 1373 | currentTime += TAP_ENABLE_DELAY_NANOS.count(); |
| 1374 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1375 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1376 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1377 | |
| 1378 | ASSERT_EQ(1u, args.size()); |
| 1379 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1380 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1381 | |
| 1382 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1383 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1384 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1385 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1386 | |
| 1387 | // no events should be generated |
| 1388 | ASSERT_EQ(0u, args.size()); |
| 1389 | |
| 1390 | // taps after the threshold should be recognised |
| 1391 | currentTime += 1; |
| 1392 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1393 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1394 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1395 | |
| 1396 | ASSERT_EQ(1u, args.size()); |
| 1397 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1398 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1399 | |
| 1400 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1401 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1402 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1403 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1404 | ASSERT_THAT(args, |
| 1405 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1406 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 1407 | WithButtonState(0))), |
| 1408 | VariantWith<NotifyMotionArgs>( |
| 1409 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1410 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 1411 | VariantWith<NotifyMotionArgs>( |
| 1412 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1413 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1414 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 1415 | VariantWith<NotifyMotionArgs>( |
| 1416 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1417 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1418 | WithButtonState(0))), |
| 1419 | VariantWith<NotifyMotionArgs>( |
| 1420 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1421 | WithButtonState(0))), |
| 1422 | VariantWith<NotifyMotionArgs>( |
| 1423 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1424 | WithButtonState(0))))); |
| 1425 | ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f)))); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1428 | TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, |
| 1429 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1430 | // Click should still produce button press/release events |
| 1431 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1432 | |
| 1433 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1434 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1435 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1436 | |
| 1437 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1438 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1439 | std::list<NotifyArgs> args = |
| 1440 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1441 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1442 | |
| 1443 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1444 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1445 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1446 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1447 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1448 | ASSERT_THAT(args, |
| 1449 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1450 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1451 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1452 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1453 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1454 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1455 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1456 | VariantWith<NotifyMotionArgs>( |
| 1457 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1458 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1459 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1460 | WithPressure(1.0f))))); |
| 1461 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1462 | Each(VariantWith<NotifyMotionArgs>( |
| 1463 | AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1464 | WithToolType(ToolType::FINGER), |
| 1465 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1466 | |
| 1467 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1468 | /* down= */ GESTURES_BUTTON_NONE, |
| 1469 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1470 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1471 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1472 | ASSERT_THAT(args, |
| 1473 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1474 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1475 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1476 | WithButtonState(0), WithCoords(0, 0), |
| 1477 | WithRelativeMotion(0.f, 0.f), |
| 1478 | WithToolType(ToolType::FINGER), WithButtonState(0), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1479 | WithPressure(1.0f), |
| 1480 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1481 | VariantWith<NotifyMotionArgs>( |
| 1482 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1483 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1484 | WithToolType(ToolType::FINGER), WithButtonState(0), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1485 | WithPressure(0.0f), |
| 1486 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1487 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1488 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1489 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 1490 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1491 | WithPressure(0.0f), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1492 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1493 | |
| 1494 | // Future taps should be re-enabled |
| 1495 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1496 | } |
| 1497 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1498 | TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick, |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1499 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
| 1500 | // initially disable tap-to-click |
| 1501 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1502 | |
| 1503 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1504 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1505 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1506 | |
| 1507 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1508 | std::list<NotifyArgs> args = |
| 1509 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1510 | // We don't need to check args here, since it's covered by the Move test. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1511 | |
| 1512 | // Future taps should be re-enabled |
| 1513 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1514 | } |
| 1515 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1516 | TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove, |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1517 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1518 | const nsecs_t gestureStartTime = 1000; |
| 1519 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1520 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1521 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1522 | |
| 1523 | // Start a move gesture at gestureStartTime |
| 1524 | Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10); |
| 1525 | std::list<NotifyArgs> args = |
| 1526 | converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1527 | ASSERT_THAT(args, |
| 1528 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1529 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1530 | VariantWith<NotifyMotionArgs>( |
| 1531 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1532 | |
| 1533 | // Key presses with IME connection should cancel ongoing move gesture |
| 1534 | nsecs_t currentTime = gestureStartTime + 100; |
| 1535 | mFakePolicy->setIsInputMethodConnectionActive(true); |
| 1536 | mReader->getContext()->setLastKeyDownTimestamp(currentTime); |
| 1537 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1538 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1539 | ASSERT_THAT(args, |
| 1540 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1541 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1542 | |
| 1543 | // any updates in existing move gesture should be ignored |
| 1544 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1545 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
| 1546 | ASSERT_EQ(0u, args.size()); |
| 1547 | |
| 1548 | // New gesture should not be affected |
| 1549 | currentTime += 100; |
| 1550 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1551 | args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1552 | ASSERT_THAT(args, |
| 1553 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1554 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1555 | VariantWith<NotifyMotionArgs>( |
| 1556 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 1559 | } // namespace android |