blob: 4df0f69481cce5fcc656b21907a3e42974a40985 [file] [log] [blame]
Harry Cutts4fb941a2022-12-14 19:14:04 +00001/*
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 Cuttsedf6ce72023-01-04 12:15:53 +000032#include "ui/Rotation.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000033
34namespace android {
35
36using testing::AllOf;
37
38class GestureConverterTest : public testing::Test {
39protected:
40 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000041 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000042 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000043 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000044 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 Cuttsc5748d12022-12-02 17:30:18 +000052 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 Cutts4fb941a2022-12-14 19:14:04 +000055
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 Cuttsc5748d12022-12-02 17:30:18 +000062 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 Cutts4fb941a2022-12-14 19:14:04 +000077 std::shared_ptr<FakeEventHub> mFakeEventHub;
78 sp<FakeInputReaderPolicy> mFakePolicy;
79 std::unique_ptr<TestInputListener> mFakeListener;
80 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000081 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000082 std::shared_ptr<FakePointerController> mFakePointerController;
83};
84
85TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +000086 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
87 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cutts4fb941a2022-12-14 19:14:04 +000088
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 Vishniakou6d73f832022-07-21 17:27:03 -070096 WithToolType(ToolType::FINGER), WithButtonState(0),
Harry Cutts4fb941a2022-12-14 19:14:04 +000097 WithPressure(0.0f)));
98
Harry Cuttsb1e83552022-12-20 11:02:26 +000099 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000100}
101
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000102TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000103 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
104 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000105 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 Vishniakou6d73f832022-07-21 17:27:03 -0700114 WithToolType(ToolType::FINGER), WithButtonState(0),
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000115 WithPressure(0.0f)));
116
Harry Cuttsb1e83552022-12-20 11:02:26 +0000117 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000118}
119
Harry Cutts4fb941a2022-12-14 19:14:04 +0000120TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000121 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
122 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000123
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 Vishniakou6d73f832022-07-21 17:27:03 -0700136 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000137 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 Vishniakou6d73f832022-07-21 17:27:03 -0700143 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000144 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 Vishniakou6d73f832022-07-21 17:27:03 -0700151 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000152
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 Vishniakou6d73f832022-07-21 17:27:03 -0700165 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000166
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 Cutts48e7a402023-07-07 15:22:40 +0000172 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000173
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 Vishniakou6d73f832022-07-21 17:27:03 -0700178 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000179 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 Vishniakou6d73f832022-07-21 17:27:03 -0700183 WithToolType(ToolType::FINGER)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000184 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 Cutts4fb941a2022-12-14 19:14:04 +0000188}
189
190TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000191 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
192 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000193
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 Vishniakou6d73f832022-07-21 17:27:03 -0700205 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000206 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 Vishniakou6d73f832022-07-21 17:27:03 -0700212 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000213
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 Vishniakou6d73f832022-07-21 17:27:03 -0700222 WithToolType(ToolType::FINGER),
Harry Cutts4fb941a2022-12-14 19:14:04 +0000223 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f)));
224
Harry Cuttsb1e83552022-12-20 11:02:26 +0000225 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000226
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 Cutts48e7a402023-07-07 15:22:40 +0000232 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000233
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 Vishniakou6d73f832022-07-21 17:27:03 -0700238 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000239 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 Vishniakou6d73f832022-07-21 17:27:03 -0700243 WithToolType(ToolType::FINGER)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000244 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 Cutts4fb941a2022-12-14 19:14:04 +0000248}
249
Harry Cuttsef400b22022-12-16 21:26:24 +0000250TEST_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 Cuttsa546ba82023-01-13 17:21:00 +0000255 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000256 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 Vishniakou6d73f832022-07-21 17:27:03 -0700263 WithToolType(ToolType::FINGER), WithDownTime(downTime),
Harry Cutts24492e62023-03-10 15:17:43 +0000264 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000265 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 Vishniakou6d73f832022-07-21 17:27:03 -0700271 WithToolType(ToolType::FINGER),
Harry Cutts24492e62023-03-10 15:17:43 +0000272 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000273
Harry Cuttsa546ba82023-01-13 17:21:00 +0000274 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000275 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 Vishniakou6d73f832022-07-21 17:27:03 -0700282 WithToolType(ToolType::FINGER),
Harry Cutts24492e62023-03-10 15:17:43 +0000283 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000284
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 Vishniakou6d73f832022-07-21 17:27:03 -0700294 WithToolType(ToolType::FINGER),
Harry Cutts24492e62023-03-10 15:17:43 +0000295 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000296}
297
298TEST_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 Cuttsa546ba82023-01-13 17:21:00 +0000304 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000305 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 Vishniakou6d73f832022-07-21 17:27:03 -0700312 WithToolType(ToolType::FINGER), WithDownTime(downTime)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000313 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 Vishniakou6d73f832022-07-21 17:27:03 -0700319 WithToolType(ToolType::FINGER)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000320
Harry Cuttsa546ba82023-01-13 17:21:00 +0000321 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000322 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 Vishniakou6d73f832022-07-21 17:27:03 -0700329 WithToolType(ToolType::FINGER)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000330
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 Vishniakou6d73f832022-07-21 17:27:03 -0700340 WithToolType(ToolType::FINGER)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000341}
342
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000343TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000344 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
345 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
346
Harry Cuttsa546ba82023-01-13 17:21:00 +0000347 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000348 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
349
Harry Cuttsa546ba82023-01-13 17:21:00 +0000350 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000351 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 Cuttsa5f98c92023-05-17 15:05:44 +0000360 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
361 WithMotionClassification(MotionClassification::NONE));
Harry Cuttsef400b22022-12-16 21:26:24 +0000362}
363
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000364TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000365 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
366 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
367
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000368 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
387TEST_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 Cuttsc5748d12022-12-02 17:30:18 +0000393 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 Cuttsa5f98c92023-05-17 15:05:44 +0000398 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
399 /*dy=*/10);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000400 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
401 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000402 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
403 WithMotionClassification(MotionClassification::NONE));
404}
405
Harry Cutts8743f182023-05-17 12:03:49 +0000406TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000407 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 Cutts8743f182023-05-17 12:03:49 +0000423 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
424 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000425}
426
427TEST_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 Cutts8743f182023-05-17 12:03:49 +0000445 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000446 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700447 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000448 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 Cutts8743f182023-05-17 12:03:49 +0000454 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000455 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700456 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000457 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 Cutts8743f182023-05-17 12:03:49 +0000463 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000464 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700465 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000466 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 Cutts8743f182023-05-17 12:03:49 +0000472 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000473 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700474 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000475 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 Cutts8743f182023-05-17 12:03:49 +0000489 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000490 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700491 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000492 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 Cutts8743f182023-05-17 12:03:49 +0000505 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000506 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700507 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000508 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 Cutts8743f182023-05-17 12:03:49 +0000512 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000513 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700514 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000515 args.pop_front();
516 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
517 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000518 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000519 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700520 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000521}
522
Harry Cutts94f5bd52023-01-06 18:02:18 +0000523TEST_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 Cuttsc5748d12022-12-02 17:30:18 +0000600TEST_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 Cutts8743f182023-05-17 12:03:49 +0000614 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000615 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700616 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000617 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 Cutts8743f182023-05-17 12:03:49 +0000623 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000624 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700625 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000626 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 Cutts8743f182023-05-17 12:03:49 +0000632 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000633 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700634 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000635 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 Cutts8743f182023-05-17 12:03:49 +0000641 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000642 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700643 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000644 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 Cutts8743f182023-05-17 12:03:49 +0000650 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000651 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700652 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000653 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 Cutts8743f182023-05-17 12:03:49 +0000669 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000670 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700671 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000672 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 Cutts8743f182023-05-17 12:03:49 +0000687 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000688 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700689 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000690 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 Cutts8743f182023-05-17 12:03:49 +0000694 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000695 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700696 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000697 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 Cutts8743f182023-05-17 12:03:49 +0000701 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000702 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700703 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000704 args.pop_front();
705 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
706 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000707 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000708 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700709 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000710}
711
Harry Cuttsb1e83552022-12-20 11:02:26 +0000712TEST_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 Vishniakou6d73f832022-07-21 17:27:03 -0700725 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000726 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 Vishniakou6d73f832022-07-21 17:27:03 -0700733 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000734
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 Vishniakou6d73f832022-07-21 17:27:03 -0700745 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000746
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 Vishniakou6d73f832022-07-21 17:27:03 -0700756 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000757 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 Vishniakou6d73f832022-07-21 17:27:03 -0700762 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000763}
764
765TEST_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 Vishniakou6d73f832022-07-21 17:27:03 -0700778 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000779 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 Vishniakou6d73f832022-07-21 17:27:03 -0700786 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000787
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 Vishniakou6d73f832022-07-21 17:27:03 -0700798 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000799
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 Vishniakou6d73f832022-07-21 17:27:03 -0700809 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000810 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 Vishniakou6d73f832022-07-21 17:27:03 -0700815 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000816}
817
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000818TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000819 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
820 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
821
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000822 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000823 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 Cuttsa5f98c92023-05-17 15:05:44 +0000827 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000828 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
829
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000830 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000831 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 Cuttsa5f98c92023-05-17 15:05:44 +0000837 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
838 WithMotionClassification(MotionClassification::NONE));
839}
840
841TEST_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 Cuttsb1e83552022-12-20 11:02:26 +0000864}
865
Harry Cuttse9b71422023-03-14 16:54:44 +0000866TEST_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 Vishniakou6d73f832022-07-21 17:27:03 -0700883 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000884 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 Vishniakou6d73f832022-07-21 17:27:03 -0700889 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000890 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 Vishniakou6d73f832022-07-21 17:27:03 -0700894 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000895}
896
897TEST_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 Vishniakou6d73f832022-07-21 17:27:03 -0700911 WithToolType(ToolType::FINGER),
Harry Cuttse9b71422023-03-14 16:54:44 +0000912 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
913}
914
915TEST_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 Vishniakou6d73f832022-07-21 17:27:03 -0700930 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000931 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 Vishniakou6d73f832022-07-21 17:27:03 -0700937 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000938 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 Vishniakou6d73f832022-07-21 17:27:03 -0700942 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000943}
944
945TEST_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 Vishniakou6d73f832022-07-21 17:27:03 -0700960 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000961 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 Vishniakou6d73f832022-07-21 17:27:03 -0700966 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000967}
968
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +0000969TEST_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 Singha5ea7c12023-07-05 15:39:25 +0000986TEST_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
1037TEST_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
1094TEST_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
1124TEST_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
1186TEST_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 Cutts4fb941a2022-12-14 19:14:04 +00001208} // namespace android