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> |
| 22 | |
| 23 | #include "FakeEventHub.h" |
| 24 | #include "FakeInputReaderPolicy.h" |
| 25 | #include "FakePointerController.h" |
| 26 | #include "InstrumentedInputReader.h" |
| 27 | #include "NotifyArgs.h" |
| 28 | #include "TestConstants.h" |
| 29 | #include "TestInputListener.h" |
| 30 | #include "TestInputListenerMatchers.h" |
| 31 | #include "include/gestures.h" |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 32 | #include "ui/Rotation.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | using testing::AllOf; |
| 37 | |
| 38 | class GestureConverterTest : public testing::Test { |
| 39 | protected: |
| 40 | static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 41 | static constexpr int32_t EVENTHUB_ID = 1; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 42 | static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2; |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 43 | static constexpr float POINTER_X = 500; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 44 | static constexpr float POINTER_Y = 200; |
| 45 | |
| 46 | void SetUp() { |
| 47 | mFakeEventHub = std::make_unique<FakeEventHub>(); |
| 48 | mFakePolicy = sp<FakeInputReaderPolicy>::make(); |
| 49 | mFakeListener = std::make_unique<TestInputListener>(); |
| 50 | mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, |
| 51 | *mFakeListener); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 52 | mDevice = newDevice(); |
| 53 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20); |
| 54 | 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] | 55 | |
| 56 | mFakePointerController = std::make_shared<FakePointerController>(); |
| 57 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); |
| 58 | mFakePointerController->setPosition(POINTER_X, POINTER_Y); |
| 59 | mFakePolicy->setPointerController(mFakePointerController); |
| 60 | } |
| 61 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 62 | std::shared_ptr<InputDevice> newDevice() { |
| 63 | InputDeviceIdentifier identifier; |
| 64 | identifier.name = "device"; |
| 65 | identifier.location = "USB1"; |
| 66 | identifier.bus = 0; |
| 67 | std::shared_ptr<InputDevice> device = |
| 68 | std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2, |
| 69 | identifier); |
| 70 | mReader->pushNextDevice(device); |
| 71 | mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD, |
| 72 | identifier.bus); |
| 73 | mReader->loopOnce(); |
| 74 | return device; |
| 75 | } |
| 76 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 77 | std::shared_ptr<FakeEventHub> mFakeEventHub; |
| 78 | sp<FakeInputReaderPolicy> mFakePolicy; |
| 79 | std::unique_ptr<TestInputListener> mFakeListener; |
| 80 | std::unique_ptr<InstrumentedInputReader> mReader; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 81 | std::shared_ptr<InputDevice> mDevice; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 82 | std::shared_ptr<FakePointerController> mFakePointerController; |
| 83 | }; |
| 84 | |
| 85 | TEST_F(GestureConverterTest, Move) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 86 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 87 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 88 | |
| 89 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 90 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 91 | ASSERT_EQ(1u, args.size()); |
| 92 | |
| 93 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 94 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 95 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 96 | WithToolType(ToolType::FINGER), WithButtonState(0), |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 97 | WithPressure(0.0f))); |
| 98 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 99 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 102 | TEST_F(GestureConverterTest, Move_Rotated) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 103 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 104 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 105 | converter.setOrientation(ui::ROTATION_90); |
| 106 | |
| 107 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 108 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 109 | ASSERT_EQ(1u, args.size()); |
| 110 | |
| 111 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 112 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 113 | WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 114 | WithToolType(ToolType::FINGER), WithButtonState(0), |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 115 | WithPressure(0.0f))); |
| 116 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 117 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5)); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 120 | TEST_F(GestureConverterTest, ButtonsChange) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 121 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 122 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 123 | |
| 124 | // Press left and right buttons at once |
| 125 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 126 | /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 127 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
| 128 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture); |
| 129 | ASSERT_EQ(3u, args.size()); |
| 130 | |
| 131 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 132 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 133 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 134 | AMOTION_EVENT_BUTTON_SECONDARY), |
| 135 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 136 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 137 | args.pop_front(); |
| 138 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 139 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 140 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 141 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 142 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 143 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 144 | args.pop_front(); |
| 145 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 146 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 147 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 148 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 149 | AMOTION_EVENT_BUTTON_SECONDARY), |
| 150 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 151 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 152 | |
| 153 | // Then release the left button |
| 154 | Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 155 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 156 | /* is_tap= */ false); |
| 157 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, leftUpGesture); |
| 158 | ASSERT_EQ(1u, args.size()); |
| 159 | |
| 160 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 161 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 162 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 163 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
| 164 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 165 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 166 | |
| 167 | // Finally release the right button |
| 168 | Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 169 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT, |
| 170 | /* is_tap= */ false); |
| 171 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, rightUpGesture); |
| 172 | ASSERT_EQ(2u, args.size()); |
| 173 | |
| 174 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 175 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 176 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), |
| 177 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 178 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 179 | args.pop_front(); |
| 180 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 181 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), |
| 182 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 183 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | TEST_F(GestureConverterTest, DragWithButton) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 187 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 188 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 189 | |
| 190 | // Press the button |
| 191 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 192 | /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE, |
| 193 | /* is_tap= */ false); |
| 194 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture); |
| 195 | ASSERT_EQ(2u, args.size()); |
| 196 | |
| 197 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 198 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 199 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 200 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 201 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 202 | args.pop_front(); |
| 203 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 204 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 205 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 206 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 207 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 208 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 209 | |
| 210 | // Move |
| 211 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 212 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 213 | ASSERT_EQ(1u, args.size()); |
| 214 | |
| 215 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 216 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 217 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 218 | WithToolType(ToolType::FINGER), |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 219 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f))); |
| 220 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 221 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 222 | |
| 223 | // Release the button |
| 224 | Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 225 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 226 | /* is_tap= */ false); |
| 227 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, upGesture); |
| 228 | ASSERT_EQ(2u, args.size()); |
| 229 | |
| 230 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 231 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 232 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), |
| 233 | WithCoords(POINTER_X - 5, POINTER_Y + 10), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 234 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 235 | args.pop_front(); |
| 236 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 237 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), |
| 238 | WithCoords(POINTER_X - 5, POINTER_Y + 10), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 239 | WithToolType(ToolType::FINGER))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 242 | TEST_F(GestureConverterTest, Scroll) { |
| 243 | const nsecs_t downTime = 12345; |
| 244 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 245 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 246 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 247 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 248 | std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture); |
| 249 | ASSERT_EQ(2u, args.size()); |
| 250 | |
| 251 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 252 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), |
| 253 | WithGestureScrollDistance(0, 0, EPSILON), |
| 254 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 255 | WithToolType(ToolType::FINGER), WithDownTime(downTime), |
Harry Cutts | 24492e6 | 2023-03-10 15:17:43 +0000 | [diff] [blame] | 256 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 257 | args.pop_front(); |
| 258 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 259 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 260 | WithCoords(POINTER_X, POINTER_Y - 10), |
| 261 | WithGestureScrollDistance(0, 10, EPSILON), |
| 262 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 263 | WithToolType(ToolType::FINGER), |
Harry Cutts | 24492e6 | 2023-03-10 15:17:43 +0000 | [diff] [blame] | 264 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 265 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 266 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 267 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 268 | ASSERT_EQ(1u, args.size()); |
| 269 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 270 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 271 | WithCoords(POINTER_X, POINTER_Y - 15), |
| 272 | WithGestureScrollDistance(0, 5, EPSILON), |
| 273 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 274 | WithToolType(ToolType::FINGER), |
Harry Cutts | 24492e6 | 2023-03-10 15:17:43 +0000 | [diff] [blame] | 275 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 276 | |
| 277 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 278 | GESTURES_FLING_START); |
| 279 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 280 | ASSERT_EQ(1u, args.size()); |
| 281 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 282 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 283 | WithCoords(POINTER_X, POINTER_Y - 15), |
| 284 | WithGestureScrollDistance(0, 0, EPSILON), |
| 285 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 286 | WithToolType(ToolType::FINGER), |
Harry Cutts | 24492e6 | 2023-03-10 15:17:43 +0000 | [diff] [blame] | 287 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | TEST_F(GestureConverterTest, Scroll_Rotated) { |
| 291 | const nsecs_t downTime = 12345; |
| 292 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 293 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 294 | converter.setOrientation(ui::ROTATION_90); |
| 295 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 296 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 297 | std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture); |
| 298 | ASSERT_EQ(2u, args.size()); |
| 299 | |
| 300 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 301 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), |
| 302 | WithGestureScrollDistance(0, 0, EPSILON), |
| 303 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 304 | WithToolType(ToolType::FINGER), WithDownTime(downTime))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 305 | args.pop_front(); |
| 306 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 307 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 308 | WithCoords(POINTER_X - 10, POINTER_Y), |
| 309 | WithGestureScrollDistance(0, 10, EPSILON), |
| 310 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 311 | WithToolType(ToolType::FINGER))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 312 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 313 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 314 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 315 | ASSERT_EQ(1u, args.size()); |
| 316 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 317 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 318 | WithCoords(POINTER_X - 15, POINTER_Y), |
| 319 | WithGestureScrollDistance(0, 5, EPSILON), |
| 320 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 321 | WithToolType(ToolType::FINGER))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 322 | |
| 323 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 324 | GESTURES_FLING_START); |
| 325 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 326 | ASSERT_EQ(1u, args.size()); |
| 327 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 328 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 329 | WithCoords(POINTER_X - 15, POINTER_Y), |
| 330 | WithGestureScrollDistance(0, 0, EPSILON), |
| 331 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 332 | WithToolType(ToolType::FINGER))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 335 | TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 336 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 337 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 338 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 339 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 340 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 341 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 342 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 343 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 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 | |
| 349 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 350 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 351 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 352 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 353 | WithMotionClassification(MotionClassification::NONE)); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 356 | TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 357 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 358 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 359 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 360 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 361 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 362 | |
| 363 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
| 364 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 365 | |
| 366 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 367 | GESTURES_FLING_START); |
| 368 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture); |
| 369 | |
| 370 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 371 | // need to use another gesture type, like pinch. |
| 372 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 373 | GESTURES_ZOOM_START); |
| 374 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture); |
| 375 | ASSERT_FALSE(args.empty()); |
| 376 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON)); |
| 377 | } |
| 378 | |
| 379 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) { |
| 380 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 381 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 382 | |
| 383 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 384 | /*dy=*/0); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 385 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 386 | |
| 387 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 388 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 389 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 390 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, |
| 391 | /*dy=*/10); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 392 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 393 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 394 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 395 | WithMotionClassification(MotionClassification::NONE)); |
| 396 | } |
| 397 | |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 398 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 399 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 400 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 401 | |
| 402 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, |
| 403 | /*dy=*/5); |
| 404 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 405 | |
| 406 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 407 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 408 | |
| 409 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 410 | // need to use another gesture type, like pinch. |
| 411 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 412 | GESTURES_ZOOM_START); |
| 413 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture); |
| 414 | ASSERT_FALSE(args.empty()); |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 415 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 416 | AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { |
| 420 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 421 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 422 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 423 | // only checks movement in one dimension. |
| 424 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 425 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 426 | |
| 427 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 428 | /* dy= */ 10); |
| 429 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 430 | ASSERT_EQ(4u, args.size()); |
| 431 | |
| 432 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 433 | // move appropriately. |
| 434 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 435 | ASSERT_THAT(arg, |
| 436 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 437 | WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 438 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 439 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 440 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 441 | args.pop_front(); |
| 442 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 443 | ASSERT_THAT(arg, |
| 444 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 445 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 446 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 447 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 448 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 449 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 450 | args.pop_front(); |
| 451 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 452 | ASSERT_THAT(arg, |
| 453 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 454 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 455 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 456 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 457 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 458 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 459 | args.pop_front(); |
| 460 | |
| 461 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 462 | ASSERT_THAT(arg, |
| 463 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 464 | WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 465 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 466 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 467 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 468 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 469 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 470 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 471 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 472 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 473 | |
| 474 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 475 | /* dx= */ 0, /* dy= */ 5); |
| 476 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 477 | ASSERT_EQ(1u, args.size()); |
| 478 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 479 | ASSERT_THAT(arg, |
| 480 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 481 | WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 482 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 483 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 484 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 485 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 486 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 487 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 488 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 489 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 490 | |
| 491 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 492 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 493 | ASSERT_EQ(3u, args.size()); |
| 494 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 495 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 496 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 497 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 498 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 499 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 500 | args.pop_front(); |
| 501 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 502 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 503 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 504 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 505 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 506 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 507 | args.pop_front(); |
| 508 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 509 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 510 | WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 511 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 512 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 515 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { |
| 516 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 517 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 518 | converter.setOrientation(ui::ROTATION_90); |
| 519 | |
| 520 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 521 | /* dy= */ 10); |
| 522 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 523 | ASSERT_EQ(4u, args.size()); |
| 524 | |
| 525 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 526 | // move appropriately. |
| 527 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 528 | ASSERT_THAT(arg, |
| 529 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
| 530 | WithPointerCount(1u))); |
| 531 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 532 | args.pop_front(); |
| 533 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 534 | ASSERT_THAT(arg, |
| 535 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 536 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 537 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
| 538 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 539 | args.pop_front(); |
| 540 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 541 | ASSERT_THAT(arg, |
| 542 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 543 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 544 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
| 545 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 546 | args.pop_front(); |
| 547 | |
| 548 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 549 | ASSERT_THAT(arg, |
| 550 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 551 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
| 552 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 553 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 554 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 555 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 556 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 557 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 558 | |
| 559 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 560 | /* dx= */ 0, /* dy= */ 5); |
| 561 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 562 | ASSERT_EQ(1u, args.size()); |
| 563 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 564 | ASSERT_THAT(arg, |
| 565 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 566 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u))); |
| 567 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 568 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 569 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 570 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 571 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 572 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 573 | |
| 574 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 575 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 576 | ASSERT_EQ(3u, args.size()); |
| 577 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 578 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 579 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 580 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
| 581 | args.pop_front(); |
| 582 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 583 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 584 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 585 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
| 586 | args.pop_front(); |
| 587 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 588 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
| 589 | WithPointerCount(1u))); |
| 590 | } |
| 591 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 592 | TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { |
| 593 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 594 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 595 | |
| 596 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 597 | /* dx= */ 10, /* dy= */ 0); |
| 598 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 599 | ASSERT_EQ(5u, args.size()); |
| 600 | |
| 601 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 602 | // move appropriately. |
| 603 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 604 | ASSERT_THAT(arg, |
| 605 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 606 | WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 607 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 608 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 609 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 610 | args.pop_front(); |
| 611 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 612 | ASSERT_THAT(arg, |
| 613 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 614 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 615 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 616 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 617 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 618 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 619 | args.pop_front(); |
| 620 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 621 | ASSERT_THAT(arg, |
| 622 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 623 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 624 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 625 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 626 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 627 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 628 | args.pop_front(); |
| 629 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 630 | ASSERT_THAT(arg, |
| 631 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 632 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 633 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 634 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 635 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 636 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 637 | args.pop_front(); |
| 638 | |
| 639 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 640 | ASSERT_THAT(arg, |
| 641 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 642 | WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 643 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 644 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 645 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 646 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 647 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 648 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 649 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 650 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 651 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 652 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 653 | |
| 654 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 655 | /* dx= */ 5, /* dy= */ 0); |
| 656 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 657 | ASSERT_EQ(1u, args.size()); |
| 658 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 659 | ASSERT_THAT(arg, |
| 660 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 661 | WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 662 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 663 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 664 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 665 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 666 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 667 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 668 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 669 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 670 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 671 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 672 | |
| 673 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 674 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 675 | ASSERT_EQ(4u, args.size()); |
| 676 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 677 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 678 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 679 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 680 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 681 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 682 | args.pop_front(); |
| 683 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 684 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 685 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 686 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 687 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 688 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 689 | args.pop_front(); |
| 690 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 691 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 692 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 693 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 694 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 695 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 696 | args.pop_front(); |
| 697 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 698 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 699 | WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 700 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 701 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 704 | TEST_F(GestureConverterTest, Pinch_Inwards) { |
| 705 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 706 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 707 | |
| 708 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 709 | GESTURES_ZOOM_START); |
| 710 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 711 | ASSERT_EQ(2u, args.size()); |
| 712 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 713 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 714 | WithMotionClassification(MotionClassification::PINCH), |
| 715 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 716 | WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 717 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 718 | args.pop_front(); |
| 719 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 720 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 721 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 722 | WithMotionClassification(MotionClassification::PINCH), |
| 723 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 724 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 725 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 726 | |
| 727 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 728 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
| 729 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 730 | ASSERT_EQ(1u, args.size()); |
| 731 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 732 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 733 | WithMotionClassification(MotionClassification::PINCH), |
| 734 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
| 735 | WithPointerCoords(0, POINTER_X - 80, POINTER_Y), |
| 736 | WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 737 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 738 | |
| 739 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 740 | GESTURES_ZOOM_END); |
| 741 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 742 | ASSERT_EQ(2u, args.size()); |
| 743 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 744 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 745 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 746 | WithMotionClassification(MotionClassification::PINCH), |
| 747 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 748 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 749 | args.pop_front(); |
| 750 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 751 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 752 | WithMotionClassification(MotionClassification::PINCH), |
| 753 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 754 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | TEST_F(GestureConverterTest, Pinch_Outwards) { |
| 758 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 759 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 760 | |
| 761 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 762 | GESTURES_ZOOM_START); |
| 763 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 764 | ASSERT_EQ(2u, args.size()); |
| 765 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 766 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 767 | WithMotionClassification(MotionClassification::PINCH), |
| 768 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 769 | WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 770 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 771 | args.pop_front(); |
| 772 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 773 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 774 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 775 | WithMotionClassification(MotionClassification::PINCH), |
| 776 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 777 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 778 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 779 | |
| 780 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 781 | /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); |
| 782 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 783 | ASSERT_EQ(1u, args.size()); |
| 784 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 785 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 786 | WithMotionClassification(MotionClassification::PINCH), |
| 787 | WithGesturePinchScaleFactor(1.2f, EPSILON), |
| 788 | WithPointerCoords(0, POINTER_X - 120, POINTER_Y), |
| 789 | WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 790 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 791 | |
| 792 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 793 | GESTURES_ZOOM_END); |
| 794 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 795 | ASSERT_EQ(2u, args.size()); |
| 796 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 797 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 798 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 799 | WithMotionClassification(MotionClassification::PINCH), |
| 800 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 801 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 802 | args.pop_front(); |
| 803 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 804 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 805 | WithMotionClassification(MotionClassification::PINCH), |
| 806 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 807 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 810 | TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 811 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 812 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 813 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 814 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 815 | GESTURES_ZOOM_START); |
| 816 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 817 | |
| 818 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 819 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 820 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 821 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 822 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 823 | GESTURES_ZOOM_END); |
| 824 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 825 | |
| 826 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 827 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 828 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 829 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 830 | WithMotionClassification(MotionClassification::NONE)); |
| 831 | } |
| 832 | |
| 833 | TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { |
| 834 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 835 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 836 | |
| 837 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 838 | GESTURES_ZOOM_START); |
| 839 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 840 | |
| 841 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 842 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
| 843 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 844 | |
| 845 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 846 | GESTURES_ZOOM_END); |
| 847 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 848 | |
| 849 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 850 | // need to use another gesture type, like scroll. |
| 851 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 852 | /*dy=*/0); |
| 853 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture); |
| 854 | ASSERT_FALSE(args.empty()); |
| 855 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 858 | TEST_F(GestureConverterTest, ResetWithButtonPressed) { |
| 859 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 860 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 861 | |
| 862 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 863 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 864 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
| 865 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture); |
| 866 | |
| 867 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 868 | ASSERT_EQ(3u, args.size()); |
| 869 | |
| 870 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 871 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 872 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 873 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
| 874 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 875 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 876 | args.pop_front(); |
| 877 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 878 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 879 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), |
| 880 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 881 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 882 | args.pop_front(); |
| 883 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 884 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), |
| 885 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 886 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | TEST_F(GestureConverterTest, ResetDuringScroll) { |
| 890 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 891 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 892 | |
| 893 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 894 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 895 | |
| 896 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 897 | ASSERT_EQ(1u, args.size()); |
| 898 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 899 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 900 | WithCoords(POINTER_X, POINTER_Y - 10), |
| 901 | WithGestureScrollDistance(0, 0, EPSILON), |
| 902 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 903 | WithToolType(ToolType::FINGER), |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 904 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); |
| 905 | } |
| 906 | |
| 907 | TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { |
| 908 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 909 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 910 | |
| 911 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 912 | /*dy=*/10); |
| 913 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 914 | |
| 915 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 916 | ASSERT_EQ(3u, args.size()); |
| 917 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 918 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 919 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 920 | WithGestureOffset(0, 0, EPSILON), |
| 921 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 922 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 923 | args.pop_front(); |
| 924 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 925 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 926 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 927 | WithGestureOffset(0, 0, EPSILON), |
| 928 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 929 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 930 | args.pop_front(); |
| 931 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 932 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
| 933 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 934 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | TEST_F(GestureConverterTest, ResetDuringPinch) { |
| 938 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 939 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 940 | |
| 941 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 942 | GESTURES_ZOOM_START); |
| 943 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 944 | |
| 945 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 946 | ASSERT_EQ(2u, args.size()); |
| 947 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 948 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 949 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 950 | WithMotionClassification(MotionClassification::PINCH), |
| 951 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 952 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 953 | args.pop_front(); |
| 954 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 955 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 956 | WithMotionClassification(MotionClassification::PINCH), |
| 957 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 958 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 961 | TEST_F(GestureConverterTest, FlingTapDown) { |
| 962 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 963 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 964 | |
| 965 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 966 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
| 967 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture); |
| 968 | |
| 969 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 970 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 971 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
| 972 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f))); |
| 973 | |
| 974 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y)); |
| 975 | ASSERT_TRUE(mFakePointerController->isPointerShown()); |
| 976 | } |
| 977 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 978 | } // namespace android |