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