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> |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 23 | #include <gui/constants.h> |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 24 | |
| 25 | #include "FakeEventHub.h" |
| 26 | #include "FakeInputReaderPolicy.h" |
| 27 | #include "FakePointerController.h" |
| 28 | #include "InstrumentedInputReader.h" |
| 29 | #include "NotifyArgs.h" |
| 30 | #include "TestConstants.h" |
Prabir Pradhan | e3b28dd | 2023-10-06 04:19:29 +0000 | [diff] [blame] | 31 | #include "TestEventMatchers.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 32 | #include "TestInputListener.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 33 | #include "include/gestures.h" |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 34 | #include "ui/Rotation.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 35 | |
| 36 | namespace android { |
| 37 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 38 | namespace { |
| 39 | |
| 40 | const auto TOUCHPAD_PALM_REJECTION = |
| 41 | ACONFIG_FLAG(com::android::input::flags, enable_touchpad_typing_palm_rejection); |
| 42 | |
| 43 | } // namespace |
| 44 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 45 | using testing::AllOf; |
| 46 | |
| 47 | class GestureConverterTest : public testing::Test { |
| 48 | protected: |
| 49 | static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 50 | static constexpr int32_t EVENTHUB_ID = 1; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 51 | static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2; |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 52 | static constexpr float POINTER_X = 500; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 53 | static constexpr float POINTER_Y = 200; |
| 54 | |
| 55 | void SetUp() { |
| 56 | mFakeEventHub = std::make_unique<FakeEventHub>(); |
| 57 | mFakePolicy = sp<FakeInputReaderPolicy>::make(); |
| 58 | mFakeListener = std::make_unique<TestInputListener>(); |
| 59 | mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, |
| 60 | *mFakeListener); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 61 | mDevice = newDevice(); |
| 62 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20); |
| 63 | 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] | 64 | |
| 65 | mFakePointerController = std::make_shared<FakePointerController>(); |
| 66 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); |
| 67 | mFakePointerController->setPosition(POINTER_X, POINTER_Y); |
| 68 | mFakePolicy->setPointerController(mFakePointerController); |
| 69 | } |
| 70 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 71 | std::shared_ptr<InputDevice> newDevice() { |
| 72 | InputDeviceIdentifier identifier; |
| 73 | identifier.name = "device"; |
| 74 | identifier.location = "USB1"; |
| 75 | identifier.bus = 0; |
| 76 | std::shared_ptr<InputDevice> device = |
| 77 | std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2, |
| 78 | identifier); |
| 79 | mReader->pushNextDevice(device); |
| 80 | mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD, |
| 81 | identifier.bus); |
| 82 | mReader->loopOnce(); |
| 83 | return device; |
| 84 | } |
| 85 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 86 | std::shared_ptr<FakeEventHub> mFakeEventHub; |
| 87 | sp<FakeInputReaderPolicy> mFakePolicy; |
| 88 | std::unique_ptr<TestInputListener> mFakeListener; |
| 89 | std::unique_ptr<InstrumentedInputReader> mReader; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 90 | std::shared_ptr<InputDevice> mDevice; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 91 | std::shared_ptr<FakePointerController> mFakePointerController; |
| 92 | }; |
| 93 | |
| 94 | TEST_F(GestureConverterTest, Move) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 95 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 96 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 97 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 98 | |
| 99 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 100 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 101 | ASSERT_EQ(1u, args.size()); |
| 102 | |
| 103 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 104 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 105 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 106 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 107 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 108 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 109 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 112 | TEST_F(GestureConverterTest, Move_Rotated) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 113 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 114 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 115 | converter.setOrientation(ui::ROTATION_90); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 116 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 117 | |
| 118 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 119 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 120 | ASSERT_EQ(1u, args.size()); |
| 121 | |
| 122 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 123 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 124 | WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 125 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 126 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 127 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 128 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5)); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 131 | TEST_F(GestureConverterTest, ButtonsChange) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 132 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 133 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 134 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 135 | |
| 136 | // Press left and right buttons at once |
| 137 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 138 | /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 139 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
| 140 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture); |
| 141 | ASSERT_EQ(3u, args.size()); |
| 142 | |
| 143 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 144 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 145 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 146 | AMOTION_EVENT_BUTTON_SECONDARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 147 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 148 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 149 | args.pop_front(); |
| 150 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 151 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 152 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 153 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 154 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 155 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 156 | args.pop_front(); |
| 157 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 158 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 159 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 160 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 161 | AMOTION_EVENT_BUTTON_SECONDARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 162 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 163 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 164 | |
| 165 | // Then release the left button |
| 166 | Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 167 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 168 | /* is_tap= */ false); |
| 169 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, leftUpGesture); |
| 170 | ASSERT_EQ(1u, args.size()); |
| 171 | |
| 172 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 173 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 174 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 175 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 176 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 177 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 178 | |
| 179 | // Finally release the right button |
| 180 | Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 181 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT, |
| 182 | /* is_tap= */ false); |
| 183 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, rightUpGesture); |
Harry Cutts | 48e7a40 | 2023-07-07 15:22:40 +0000 | [diff] [blame] | 184 | ASSERT_EQ(3u, args.size()); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 185 | |
| 186 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 187 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 188 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 189 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 190 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 191 | args.pop_front(); |
| 192 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 193 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 194 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 195 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 48e7a40 | 2023-07-07 15:22:40 +0000 | [diff] [blame] | 196 | args.pop_front(); |
| 197 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 198 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 199 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 200 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | TEST_F(GestureConverterTest, DragWithButton) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 204 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 205 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 206 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 207 | |
| 208 | // Press the button |
| 209 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 210 | /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE, |
| 211 | /* is_tap= */ false); |
| 212 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture); |
| 213 | ASSERT_EQ(2u, args.size()); |
| 214 | |
| 215 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 216 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 217 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 218 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 219 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 220 | args.pop_front(); |
| 221 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 222 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 223 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 224 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 225 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 226 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 227 | |
| 228 | // Move |
| 229 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 230 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 231 | ASSERT_EQ(1u, args.size()); |
| 232 | |
| 233 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 234 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 235 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 236 | WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 237 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 238 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 239 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 240 | |
| 241 | // Release the button |
| 242 | Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 243 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 244 | /* is_tap= */ false); |
| 245 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, upGesture); |
Harry Cutts | 48e7a40 | 2023-07-07 15:22:40 +0000 | [diff] [blame] | 246 | ASSERT_EQ(3u, args.size()); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 247 | |
| 248 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 249 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 250 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 251 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER), |
| 252 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 253 | args.pop_front(); |
| 254 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 255 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 256 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER), |
| 257 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 48e7a40 | 2023-07-07 15:22:40 +0000 | [diff] [blame] | 258 | args.pop_front(); |
| 259 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 260 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 261 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER), |
| 262 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 265 | TEST_F(GestureConverterTest, Scroll) { |
| 266 | const nsecs_t downTime = 12345; |
| 267 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 268 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 269 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 270 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 271 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 272 | std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture); |
| 273 | ASSERT_EQ(2u, args.size()); |
| 274 | |
| 275 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 276 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), |
| 277 | WithGestureScrollDistance(0, 0, EPSILON), |
| 278 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 279 | WithToolType(ToolType::FINGER), WithDownTime(downTime), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 280 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 281 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 282 | args.pop_front(); |
| 283 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 284 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 285 | WithCoords(POINTER_X, POINTER_Y - 10), |
| 286 | WithGestureScrollDistance(0, 10, EPSILON), |
| 287 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 288 | WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 289 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 290 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 291 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 292 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 293 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 294 | ASSERT_EQ(1u, args.size()); |
| 295 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 296 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 297 | WithCoords(POINTER_X, POINTER_Y - 15), |
| 298 | WithGestureScrollDistance(0, 5, EPSILON), |
| 299 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 300 | WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 301 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 302 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 303 | |
| 304 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 305 | GESTURES_FLING_START); |
| 306 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 307 | ASSERT_EQ(1u, args.size()); |
| 308 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 309 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 310 | WithCoords(POINTER_X, POINTER_Y - 15), |
| 311 | WithGestureScrollDistance(0, 0, EPSILON), |
| 312 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 313 | WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 314 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 315 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | TEST_F(GestureConverterTest, Scroll_Rotated) { |
| 319 | const nsecs_t downTime = 12345; |
| 320 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 321 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 322 | converter.setOrientation(ui::ROTATION_90); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 323 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 324 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 325 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 326 | std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture); |
| 327 | ASSERT_EQ(2u, args.size()); |
| 328 | |
| 329 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 330 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), |
| 331 | WithGestureScrollDistance(0, 0, EPSILON), |
| 332 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 333 | WithToolType(ToolType::FINGER), WithDownTime(downTime), |
| 334 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 335 | args.pop_front(); |
| 336 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 337 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 338 | WithCoords(POINTER_X - 10, POINTER_Y), |
| 339 | WithGestureScrollDistance(0, 10, EPSILON), |
| 340 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 341 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 342 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 343 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 344 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 345 | ASSERT_EQ(1u, args.size()); |
| 346 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 347 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 348 | WithCoords(POINTER_X - 15, POINTER_Y), |
| 349 | WithGestureScrollDistance(0, 5, EPSILON), |
| 350 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 351 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 352 | |
| 353 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 354 | GESTURES_FLING_START); |
| 355 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 356 | ASSERT_EQ(1u, args.size()); |
| 357 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 358 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 359 | WithCoords(POINTER_X - 15, POINTER_Y), |
| 360 | WithGestureScrollDistance(0, 0, EPSILON), |
| 361 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 362 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 365 | TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 366 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 367 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 368 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 369 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 370 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 371 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 372 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 373 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 374 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 375 | |
| 376 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 377 | GESTURES_FLING_START); |
| 378 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 379 | |
| 380 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 381 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 382 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 383 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 384 | AllOf(WithMotionClassification(MotionClassification::NONE), |
| 385 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 388 | TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 389 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 390 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 391 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 392 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 393 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 394 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 395 | |
| 396 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
| 397 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 398 | |
| 399 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 400 | GESTURES_FLING_START); |
| 401 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 402 | |
| 403 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 404 | // need to use another gesture type, like pinch. |
| 405 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 406 | GESTURES_ZOOM_START); |
| 407 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture); |
| 408 | ASSERT_FALSE(args.empty()); |
| 409 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON)); |
| 410 | } |
| 411 | |
| 412 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) { |
| 413 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 414 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 415 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 416 | |
| 417 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 418 | /*dy=*/0); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 419 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 420 | |
| 421 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 422 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 423 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 424 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, |
| 425 | /*dy=*/10); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 426 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 427 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 428 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 429 | WithMotionClassification(MotionClassification::NONE)); |
| 430 | } |
| 431 | |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 432 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 433 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 434 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 435 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 436 | |
| 437 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, |
| 438 | /*dy=*/5); |
| 439 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 440 | |
| 441 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 442 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 443 | |
| 444 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 445 | // need to use another gesture type, like pinch. |
| 446 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 447 | GESTURES_ZOOM_START); |
| 448 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture); |
| 449 | ASSERT_FALSE(args.empty()); |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 450 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 451 | AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { |
| 455 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 456 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 457 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 458 | // only checks movement in one dimension. |
| 459 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 460 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 461 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 462 | |
| 463 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 464 | /* dy= */ 10); |
| 465 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 466 | ASSERT_EQ(4u, args.size()); |
| 467 | |
| 468 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 469 | // move appropriately. |
| 470 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 471 | ASSERT_THAT(arg, |
| 472 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 473 | WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 474 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 475 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 476 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 477 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 478 | args.pop_front(); |
| 479 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 480 | ASSERT_THAT(arg, |
| 481 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 482 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 483 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 484 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 485 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 486 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 487 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 488 | args.pop_front(); |
| 489 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 490 | ASSERT_THAT(arg, |
| 491 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 492 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 493 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 494 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 495 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 496 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 497 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 498 | args.pop_front(); |
| 499 | |
| 500 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 501 | ASSERT_THAT(arg, |
| 502 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 503 | WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 504 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 505 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 506 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 507 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 508 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 509 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 510 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 511 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 512 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 513 | |
| 514 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 515 | /* dx= */ 0, /* dy= */ 5); |
| 516 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 517 | ASSERT_EQ(1u, args.size()); |
| 518 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 519 | ASSERT_THAT(arg, |
| 520 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 521 | WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 522 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 523 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 524 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 525 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 526 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 527 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 528 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 529 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 530 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 531 | |
| 532 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 533 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 534 | ASSERT_EQ(3u, args.size()); |
| 535 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 536 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 537 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 538 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 539 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 540 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 541 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 542 | args.pop_front(); |
| 543 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 544 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 545 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 546 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 547 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 548 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 549 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 550 | args.pop_front(); |
| 551 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 552 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 553 | WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 554 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 555 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 556 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 559 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { |
| 560 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 561 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 562 | converter.setOrientation(ui::ROTATION_90); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 563 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 564 | |
| 565 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 566 | /* dy= */ 10); |
| 567 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 568 | ASSERT_EQ(4u, args.size()); |
| 569 | |
| 570 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 571 | // move appropriately. |
| 572 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 573 | ASSERT_THAT(arg, |
| 574 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 575 | WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 576 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 577 | args.pop_front(); |
| 578 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 579 | ASSERT_THAT(arg, |
| 580 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 581 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 582 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), |
| 583 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 584 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 585 | args.pop_front(); |
| 586 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 587 | ASSERT_THAT(arg, |
| 588 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 589 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 590 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), |
| 591 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 592 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 593 | args.pop_front(); |
| 594 | |
| 595 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 596 | ASSERT_THAT(arg, |
| 597 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 598 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u), |
| 599 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 600 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 601 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 602 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 603 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 604 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 605 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 606 | |
| 607 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 608 | /* dx= */ 0, /* dy= */ 5); |
| 609 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 610 | ASSERT_EQ(1u, args.size()); |
| 611 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 612 | ASSERT_THAT(arg, |
| 613 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 614 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), |
| 615 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 616 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 617 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 618 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 619 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 620 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 621 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 622 | |
| 623 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 624 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 625 | ASSERT_EQ(3u, args.size()); |
| 626 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 627 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 628 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 629 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), |
| 630 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 631 | args.pop_front(); |
| 632 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 633 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 634 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 635 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), |
| 636 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 637 | args.pop_front(); |
| 638 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 639 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 640 | WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 643 | TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { |
| 644 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 645 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 646 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 647 | |
| 648 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 649 | /* dx= */ 10, /* dy= */ 0); |
| 650 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 651 | ASSERT_EQ(5u, args.size()); |
| 652 | |
| 653 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 654 | // move appropriately. |
| 655 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 656 | ASSERT_THAT(arg, |
| 657 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 658 | WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 659 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 660 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 661 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 662 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 663 | args.pop_front(); |
| 664 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 665 | ASSERT_THAT(arg, |
| 666 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 667 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 668 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 669 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 670 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 671 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 672 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 673 | args.pop_front(); |
| 674 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 675 | ASSERT_THAT(arg, |
| 676 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 677 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 678 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 679 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 680 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 681 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 682 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 683 | args.pop_front(); |
| 684 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 685 | ASSERT_THAT(arg, |
| 686 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 687 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 688 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 689 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 690 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 691 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 692 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 693 | args.pop_front(); |
| 694 | |
| 695 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 696 | ASSERT_THAT(arg, |
| 697 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 698 | WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 699 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 700 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 701 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 702 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 703 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 704 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 705 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 706 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 707 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 708 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 709 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 710 | |
| 711 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 712 | /* dx= */ 5, /* dy= */ 0); |
| 713 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 714 | ASSERT_EQ(1u, args.size()); |
| 715 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 716 | ASSERT_THAT(arg, |
| 717 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 718 | WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 719 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 720 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 721 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 722 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 723 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 724 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 725 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 726 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 727 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 728 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 729 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 730 | |
| 731 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 732 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 733 | ASSERT_EQ(4u, args.size()); |
| 734 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 735 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 736 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 737 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 738 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 739 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 740 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 741 | args.pop_front(); |
| 742 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 743 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 744 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 745 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 746 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 747 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 748 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 749 | args.pop_front(); |
| 750 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 751 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 752 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 753 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 754 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 755 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 756 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 757 | args.pop_front(); |
| 758 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 759 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 760 | WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 761 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 762 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 763 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 766 | TEST_F(GestureConverterTest, Pinch_Inwards) { |
| 767 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 768 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 769 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 770 | |
| 771 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 772 | GESTURES_ZOOM_START); |
| 773 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 774 | ASSERT_EQ(2u, args.size()); |
| 775 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 776 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 777 | WithMotionClassification(MotionClassification::PINCH), |
| 778 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 779 | WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 780 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 781 | args.pop_front(); |
| 782 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 783 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 784 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 785 | WithMotionClassification(MotionClassification::PINCH), |
| 786 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 787 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 788 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 789 | |
| 790 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 791 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
| 792 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 793 | ASSERT_EQ(1u, args.size()); |
| 794 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 795 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 796 | WithMotionClassification(MotionClassification::PINCH), |
| 797 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
| 798 | WithPointerCoords(0, POINTER_X - 80, POINTER_Y), |
| 799 | WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 800 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 801 | |
| 802 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 803 | GESTURES_ZOOM_END); |
| 804 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 805 | ASSERT_EQ(2u, args.size()); |
| 806 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 807 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 808 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 809 | WithMotionClassification(MotionClassification::PINCH), |
| 810 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 811 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 812 | args.pop_front(); |
| 813 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 814 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 815 | WithMotionClassification(MotionClassification::PINCH), |
| 816 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 817 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | TEST_F(GestureConverterTest, Pinch_Outwards) { |
| 821 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 822 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 823 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 824 | |
| 825 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 826 | GESTURES_ZOOM_START); |
| 827 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 828 | ASSERT_EQ(2u, args.size()); |
| 829 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 830 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 831 | WithMotionClassification(MotionClassification::PINCH), |
| 832 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 833 | WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 834 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 835 | args.pop_front(); |
| 836 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 837 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 838 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 839 | WithMotionClassification(MotionClassification::PINCH), |
| 840 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 841 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 842 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 843 | |
| 844 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 845 | /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); |
| 846 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 847 | ASSERT_EQ(1u, args.size()); |
| 848 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 849 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 850 | WithMotionClassification(MotionClassification::PINCH), |
| 851 | WithGesturePinchScaleFactor(1.2f, EPSILON), |
| 852 | WithPointerCoords(0, POINTER_X - 120, POINTER_Y), |
| 853 | WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 854 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 855 | |
| 856 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 857 | GESTURES_ZOOM_END); |
| 858 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 859 | ASSERT_EQ(2u, args.size()); |
| 860 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 861 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 862 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 863 | WithMotionClassification(MotionClassification::PINCH), |
| 864 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 865 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 866 | args.pop_front(); |
| 867 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 868 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 869 | WithMotionClassification(MotionClassification::PINCH), |
| 870 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 871 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 874 | TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 875 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 876 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 877 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 878 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 879 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 880 | GESTURES_ZOOM_START); |
| 881 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 882 | |
| 883 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 884 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 885 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 886 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 887 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 888 | GESTURES_ZOOM_END); |
| 889 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 890 | |
| 891 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 892 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 893 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 894 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 895 | WithMotionClassification(MotionClassification::NONE)); |
| 896 | } |
| 897 | |
| 898 | TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { |
| 899 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 900 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 901 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 902 | |
| 903 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 904 | GESTURES_ZOOM_START); |
| 905 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 906 | |
| 907 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 908 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
| 909 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 910 | |
| 911 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 912 | GESTURES_ZOOM_END); |
| 913 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 914 | |
| 915 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 916 | // need to use another gesture type, like scroll. |
| 917 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 918 | /*dy=*/0); |
| 919 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture); |
| 920 | ASSERT_FALSE(args.empty()); |
| 921 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 924 | TEST_F(GestureConverterTest, ResetWithButtonPressed) { |
| 925 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 926 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 927 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 928 | |
| 929 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 930 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 931 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
| 932 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture); |
| 933 | |
| 934 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 935 | ASSERT_EQ(3u, args.size()); |
| 936 | |
| 937 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 938 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 939 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 940 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 941 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 942 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 943 | args.pop_front(); |
| 944 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 945 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 946 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 947 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 948 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 949 | args.pop_front(); |
| 950 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 951 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 952 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 953 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | TEST_F(GestureConverterTest, ResetDuringScroll) { |
| 957 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 958 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 959 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 960 | |
| 961 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 962 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 963 | |
| 964 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 965 | ASSERT_EQ(1u, args.size()); |
| 966 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 967 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 968 | WithCoords(POINTER_X, POINTER_Y - 10), |
| 969 | WithGestureScrollDistance(0, 0, EPSILON), |
| 970 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 971 | WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 972 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 973 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { |
| 977 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 978 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 979 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 980 | |
| 981 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 982 | /*dy=*/10); |
| 983 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 984 | |
| 985 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 986 | ASSERT_EQ(3u, args.size()); |
| 987 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 988 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 989 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 990 | WithGestureOffset(0, 0, EPSILON), |
| 991 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 992 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 993 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 994 | args.pop_front(); |
| 995 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 996 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 997 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 998 | WithGestureOffset(0, 0, EPSILON), |
| 999 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1000 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 1001 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1002 | args.pop_front(); |
| 1003 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1004 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
| 1005 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1006 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 1007 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | TEST_F(GestureConverterTest, ResetDuringPinch) { |
| 1011 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1012 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1013 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1014 | |
| 1015 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1016 | GESTURES_ZOOM_START); |
| 1017 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 1018 | |
| 1019 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 1020 | ASSERT_EQ(2u, args.size()); |
| 1021 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1022 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 1023 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1024 | WithMotionClassification(MotionClassification::PINCH), |
| 1025 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1026 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1027 | args.pop_front(); |
| 1028 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1029 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1030 | WithMotionClassification(MotionClassification::PINCH), |
| 1031 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1032 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1035 | TEST_F(GestureConverterTest, FlingTapDown) { |
| 1036 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1037 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1038 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1039 | |
| 1040 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1041 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
| 1042 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture); |
| 1043 | |
| 1044 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1045 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1046 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1047 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1048 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1049 | |
| 1050 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y)); |
| 1051 | ASSERT_TRUE(mFakePointerController->isPointerShown()); |
| 1052 | } |
| 1053 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1054 | TEST_F(GestureConverterTest, Tap) { |
| 1055 | // Tap should produce button press/release events |
| 1056 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1057 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1058 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1059 | |
| 1060 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1061 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1062 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 1063 | |
| 1064 | ASSERT_EQ(1u, args.size()); |
| 1065 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1066 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1067 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1068 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1069 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1070 | |
| 1071 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1072 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1073 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1074 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture); |
| 1075 | |
| 1076 | ASSERT_EQ(5u, args.size()); |
| 1077 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1078 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), |
| 1079 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1080 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
| 1081 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1082 | args.pop_front(); |
| 1083 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1084 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1085 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1086 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1087 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
| 1088 | WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1089 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1090 | args.pop_front(); |
| 1091 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1092 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1093 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), |
| 1094 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1095 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f), |
| 1096 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1097 | args.pop_front(); |
| 1098 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1099 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y), |
| 1100 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1101 | WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1102 | args.pop_front(); |
| 1103 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1104 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1105 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1106 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1107 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | TEST_F(GestureConverterTest, Click) { |
| 1111 | // Click should produce button press/release events |
| 1112 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1113 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1114 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1115 | |
| 1116 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1117 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1118 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 1119 | |
| 1120 | ASSERT_EQ(1u, args.size()); |
| 1121 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1122 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1123 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1124 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1125 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1126 | |
| 1127 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1128 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1129 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
| 1130 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture); |
| 1131 | |
| 1132 | ASSERT_EQ(2u, args.size()); |
| 1133 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1134 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), |
| 1135 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1136 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
| 1137 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1138 | args.pop_front(); |
| 1139 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1140 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1141 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1142 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1143 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
| 1144 | WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1145 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1146 | |
| 1147 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1148 | /* down= */ GESTURES_BUTTON_NONE, |
| 1149 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
| 1150 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture); |
| 1151 | |
| 1152 | ASSERT_EQ(3u, args.size()); |
| 1153 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1154 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1155 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), |
| 1156 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1157 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f), |
| 1158 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1159 | args.pop_front(); |
| 1160 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1161 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y), |
| 1162 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1163 | WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1164 | args.pop_front(); |
| 1165 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1166 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1167 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1168 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1169 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1172 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, |
| 1173 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1174 | // Tap should be ignored when disabled |
| 1175 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1176 | |
| 1177 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1178 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1179 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1180 | |
| 1181 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1182 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1183 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 1184 | |
| 1185 | ASSERT_EQ(1u, args.size()); |
| 1186 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1187 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1188 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1189 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1190 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1191 | args.pop_front(); |
| 1192 | |
| 1193 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1194 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1195 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1196 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture); |
| 1197 | |
| 1198 | // no events should be generated |
| 1199 | ASSERT_EQ(0u, args.size()); |
| 1200 | |
| 1201 | // Future taps should be re-enabled |
| 1202 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1203 | } |
| 1204 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1205 | TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, |
| 1206 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1207 | // Click should still produce button press/release events |
| 1208 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1209 | |
| 1210 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1211 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1212 | converter.setDisplayId(ADISPLAY_ID_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); |
| 1216 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 1217 | |
| 1218 | ASSERT_EQ(1u, args.size()); |
| 1219 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1220 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1221 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1222 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1223 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1224 | |
| 1225 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1226 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1227 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
| 1228 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture); |
| 1229 | ASSERT_EQ(2u, args.size()); |
| 1230 | |
| 1231 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1232 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), |
| 1233 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1234 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
| 1235 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1236 | args.pop_front(); |
| 1237 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1238 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1239 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1240 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1241 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
| 1242 | WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1243 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1244 | |
| 1245 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1246 | /* down= */ GESTURES_BUTTON_NONE, |
| 1247 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
| 1248 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture); |
| 1249 | |
| 1250 | ASSERT_EQ(3u, args.size()); |
| 1251 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1252 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1253 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), |
| 1254 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1255 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f), |
| 1256 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1257 | args.pop_front(); |
| 1258 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1259 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y), |
| 1260 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1261 | WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1262 | args.pop_front(); |
| 1263 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1264 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1265 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1266 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1267 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1268 | |
| 1269 | // Future taps should be re-enabled |
| 1270 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1271 | } |
| 1272 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1273 | TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick, |
| 1274 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1275 | // initially disable tap-to-click |
| 1276 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1277 | |
| 1278 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1279 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1280 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1281 | |
| 1282 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 1283 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 1284 | ASSERT_EQ(1u, args.size()); |
| 1285 | |
| 1286 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1287 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1288 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1289 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1290 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1291 | |
| 1292 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); |
| 1293 | |
| 1294 | // Future taps should be re-enabled |
| 1295 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1296 | } |
| 1297 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 1298 | } // namespace android |