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 | |
| 398 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsOffsetsAfterGesture) { |
| 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()); |
| 415 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureOffset(0, 0, EPSILON)); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { |
| 419 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 420 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 421 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 422 | // only checks movement in one dimension. |
| 423 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 424 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 425 | |
| 426 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 427 | /* dy= */ 10); |
| 428 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 429 | ASSERT_EQ(4u, args.size()); |
| 430 | |
| 431 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 432 | // move appropriately. |
| 433 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 434 | ASSERT_THAT(arg, |
| 435 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
| 436 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 437 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 438 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 439 | args.pop_front(); |
| 440 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 441 | ASSERT_THAT(arg, |
| 442 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 443 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 444 | WithGestureOffset(0, 0, EPSILON), |
| 445 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 446 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 447 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 448 | args.pop_front(); |
| 449 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 450 | ASSERT_THAT(arg, |
| 451 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 452 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 453 | WithGestureOffset(0, 0, EPSILON), |
| 454 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 455 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 456 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 457 | args.pop_front(); |
| 458 | |
| 459 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 460 | ASSERT_THAT(arg, |
| 461 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 462 | WithGestureOffset(0, -0.01, EPSILON), |
| 463 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 464 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 465 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 466 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 467 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 468 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 469 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 470 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 471 | |
| 472 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 473 | /* dx= */ 0, /* dy= */ 5); |
| 474 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 475 | ASSERT_EQ(1u, args.size()); |
| 476 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 477 | ASSERT_THAT(arg, |
| 478 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 479 | WithGestureOffset(0, -0.005, EPSILON), |
| 480 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 481 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 482 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 483 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 484 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 485 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 486 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 487 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 488 | |
| 489 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 490 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 491 | ASSERT_EQ(3u, args.size()); |
| 492 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 493 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 494 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 495 | WithGestureOffset(0, 0, EPSILON), |
| 496 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 497 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 498 | args.pop_front(); |
| 499 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 500 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 501 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 502 | WithGestureOffset(0, 0, EPSILON), |
| 503 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 504 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 505 | args.pop_front(); |
| 506 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 507 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
| 508 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 509 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 512 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { |
| 513 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 514 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 515 | converter.setOrientation(ui::ROTATION_90); |
| 516 | |
| 517 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 518 | /* dy= */ 10); |
| 519 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 520 | ASSERT_EQ(4u, args.size()); |
| 521 | |
| 522 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 523 | // move appropriately. |
| 524 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 525 | ASSERT_THAT(arg, |
| 526 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
| 527 | WithPointerCount(1u))); |
| 528 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 529 | args.pop_front(); |
| 530 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 531 | ASSERT_THAT(arg, |
| 532 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 533 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 534 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
| 535 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 536 | args.pop_front(); |
| 537 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 538 | ASSERT_THAT(arg, |
| 539 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 540 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 541 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
| 542 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 543 | args.pop_front(); |
| 544 | |
| 545 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 546 | ASSERT_THAT(arg, |
| 547 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 548 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
| 549 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 550 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 551 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 552 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 553 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 554 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 555 | |
| 556 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 557 | /* dx= */ 0, /* dy= */ 5); |
| 558 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 559 | ASSERT_EQ(1u, args.size()); |
| 560 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 561 | ASSERT_THAT(arg, |
| 562 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 563 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u))); |
| 564 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 565 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 566 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 567 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 568 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 569 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 570 | |
| 571 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 572 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 573 | ASSERT_EQ(3u, args.size()); |
| 574 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 575 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 576 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 577 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
| 578 | args.pop_front(); |
| 579 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 580 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 581 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 582 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
| 583 | args.pop_front(); |
| 584 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 585 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
| 586 | WithPointerCount(1u))); |
| 587 | } |
| 588 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 589 | TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { |
| 590 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 591 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 592 | |
| 593 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 594 | /* dx= */ 10, /* dy= */ 0); |
| 595 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 596 | ASSERT_EQ(5u, args.size()); |
| 597 | |
| 598 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 599 | // move appropriately. |
| 600 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 601 | ASSERT_THAT(arg, |
| 602 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
| 603 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 604 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 605 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 606 | args.pop_front(); |
| 607 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 608 | ASSERT_THAT(arg, |
| 609 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 610 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 611 | WithGestureOffset(0, 0, EPSILON), |
| 612 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 613 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 614 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 615 | args.pop_front(); |
| 616 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 617 | ASSERT_THAT(arg, |
| 618 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 619 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 620 | WithGestureOffset(0, 0, EPSILON), |
| 621 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 622 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 623 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 624 | args.pop_front(); |
| 625 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 626 | ASSERT_THAT(arg, |
| 627 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 628 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 629 | WithGestureOffset(0, 0, EPSILON), |
| 630 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 631 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 632 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 633 | args.pop_front(); |
| 634 | |
| 635 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 636 | ASSERT_THAT(arg, |
| 637 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 638 | WithGestureOffset(0.01, 0, EPSILON), |
| 639 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 640 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 641 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 642 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 643 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 644 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 645 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 646 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 647 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 648 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 649 | |
| 650 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 651 | /* dx= */ 5, /* dy= */ 0); |
| 652 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); |
| 653 | ASSERT_EQ(1u, args.size()); |
| 654 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 655 | ASSERT_THAT(arg, |
| 656 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 657 | WithGestureOffset(0.005, 0, EPSILON), |
| 658 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 659 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 660 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 661 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 662 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 663 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 664 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 665 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 666 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 667 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 668 | |
| 669 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 670 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); |
| 671 | ASSERT_EQ(4u, args.size()); |
| 672 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 673 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 674 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 675 | WithGestureOffset(0, 0, EPSILON), |
| 676 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 677 | WithPointerCount(4u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 678 | args.pop_front(); |
| 679 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 680 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 681 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 682 | WithGestureOffset(0, 0, EPSILON), |
| 683 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 684 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 685 | args.pop_front(); |
| 686 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 687 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 688 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 689 | WithGestureOffset(0, 0, EPSILON), |
| 690 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 691 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 692 | args.pop_front(); |
| 693 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 694 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
| 695 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 696 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 699 | TEST_F(GestureConverterTest, Pinch_Inwards) { |
| 700 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 701 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 702 | |
| 703 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 704 | GESTURES_ZOOM_START); |
| 705 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 706 | ASSERT_EQ(2u, args.size()); |
| 707 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 708 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 709 | WithMotionClassification(MotionClassification::PINCH), |
| 710 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 711 | WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 712 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 713 | args.pop_front(); |
| 714 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 715 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 716 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 717 | WithMotionClassification(MotionClassification::PINCH), |
| 718 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 719 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 720 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 721 | |
| 722 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 723 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
| 724 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 725 | ASSERT_EQ(1u, args.size()); |
| 726 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 727 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 728 | WithMotionClassification(MotionClassification::PINCH), |
| 729 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
| 730 | WithPointerCoords(0, POINTER_X - 80, POINTER_Y), |
| 731 | WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 732 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 733 | |
| 734 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 735 | GESTURES_ZOOM_END); |
| 736 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 737 | ASSERT_EQ(2u, args.size()); |
| 738 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 739 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 740 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 741 | WithMotionClassification(MotionClassification::PINCH), |
| 742 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 743 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 744 | args.pop_front(); |
| 745 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 746 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 747 | WithMotionClassification(MotionClassification::PINCH), |
| 748 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 749 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | TEST_F(GestureConverterTest, Pinch_Outwards) { |
| 753 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 754 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 755 | |
| 756 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 757 | GESTURES_ZOOM_START); |
| 758 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 759 | ASSERT_EQ(2u, args.size()); |
| 760 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 761 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 762 | WithMotionClassification(MotionClassification::PINCH), |
| 763 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 764 | WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 765 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 766 | args.pop_front(); |
| 767 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 768 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 769 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 770 | WithMotionClassification(MotionClassification::PINCH), |
| 771 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 772 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 773 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 774 | |
| 775 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 776 | /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); |
| 777 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 778 | ASSERT_EQ(1u, args.size()); |
| 779 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 780 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 781 | WithMotionClassification(MotionClassification::PINCH), |
| 782 | WithGesturePinchScaleFactor(1.2f, EPSILON), |
| 783 | WithPointerCoords(0, POINTER_X - 120, POINTER_Y), |
| 784 | WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 785 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 786 | |
| 787 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 788 | GESTURES_ZOOM_END); |
| 789 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 790 | ASSERT_EQ(2u, args.size()); |
| 791 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 792 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 793 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 794 | WithMotionClassification(MotionClassification::PINCH), |
| 795 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 796 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 797 | args.pop_front(); |
| 798 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 799 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 800 | WithMotionClassification(MotionClassification::PINCH), |
| 801 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 802 | WithToolType(ToolType::FINGER))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 805 | TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 806 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 807 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 808 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 809 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 810 | GESTURES_ZOOM_START); |
| 811 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 812 | |
| 813 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 814 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 815 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); |
| 816 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 817 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 818 | GESTURES_ZOOM_END); |
| 819 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 820 | |
| 821 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 822 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); |
| 823 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 824 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 825 | WithMotionClassification(MotionClassification::NONE)); |
| 826 | } |
| 827 | |
| 828 | TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { |
| 829 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 830 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 831 | |
| 832 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 833 | GESTURES_ZOOM_START); |
| 834 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 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 | |
| 840 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 841 | GESTURES_ZOOM_END); |
| 842 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); |
| 843 | |
| 844 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 845 | // need to use another gesture type, like scroll. |
| 846 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 847 | /*dy=*/0); |
| 848 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture); |
| 849 | ASSERT_FALSE(args.empty()); |
| 850 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 853 | TEST_F(GestureConverterTest, ResetWithButtonPressed) { |
| 854 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 855 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 856 | |
| 857 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 858 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 859 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
| 860 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture); |
| 861 | |
| 862 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 863 | ASSERT_EQ(3u, args.size()); |
| 864 | |
| 865 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 866 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 867 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 868 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
| 869 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 870 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 871 | args.pop_front(); |
| 872 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 873 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 874 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), |
| 875 | WithCoords(POINTER_X, POINTER_Y), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 876 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 877 | args.pop_front(); |
| 878 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 879 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), 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 | } |
| 883 | |
| 884 | TEST_F(GestureConverterTest, ResetDuringScroll) { |
| 885 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 886 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 887 | |
| 888 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 889 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 890 | |
| 891 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 892 | ASSERT_EQ(1u, args.size()); |
| 893 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 894 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 895 | WithCoords(POINTER_X, POINTER_Y - 10), |
| 896 | WithGestureScrollDistance(0, 0, EPSILON), |
| 897 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 898 | WithToolType(ToolType::FINGER), |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 899 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); |
| 900 | } |
| 901 | |
| 902 | TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { |
| 903 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 904 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 905 | |
| 906 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 907 | /*dy=*/10); |
| 908 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 909 | |
| 910 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 911 | ASSERT_EQ(3u, args.size()); |
| 912 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 913 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 914 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 915 | WithGestureOffset(0, 0, EPSILON), |
| 916 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 917 | WithPointerCount(3u), WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 918 | args.pop_front(); |
| 919 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 920 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 921 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 922 | WithGestureOffset(0, 0, EPSILON), |
| 923 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 924 | WithPointerCount(2u), WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 925 | args.pop_front(); |
| 926 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 927 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), |
| 928 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 929 | WithPointerCount(1u), WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | TEST_F(GestureConverterTest, ResetDuringPinch) { |
| 933 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 934 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 935 | |
| 936 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 937 | GESTURES_ZOOM_START); |
| 938 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); |
| 939 | |
| 940 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
| 941 | ASSERT_EQ(2u, args.size()); |
| 942 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 943 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | |
| 944 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 945 | WithMotionClassification(MotionClassification::PINCH), |
| 946 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 947 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 948 | args.pop_front(); |
| 949 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 950 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 951 | WithMotionClassification(MotionClassification::PINCH), |
| 952 | WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), |
Siarhei Vishniakou | 6d73f83 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 953 | WithToolType(ToolType::FINGER))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 956 | TEST_F(GestureConverterTest, FlingTapDown) { |
| 957 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 958 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 959 | |
| 960 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 961 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
| 962 | std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture); |
| 963 | |
| 964 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 965 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 966 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
| 967 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f))); |
| 968 | |
| 969 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y)); |
| 970 | ASSERT_TRUE(mFakePointerController->isPointerShown()); |
| 971 | } |
| 972 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 973 | } // namespace android |