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