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