blob: f115fff1285f9f2e289bebcf0dc2326a9213c1ee [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);
172 ASSERT_EQ(2u, args.size());
173
174 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
175 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
176 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
177 WithCoords(POINTER_X, POINTER_Y),
Siarhei 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 Cutts4fb941a2022-12-14 19:14:04 +0000184}
185
186TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000187 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
188 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000189
190 // Press the button
191 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
192 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
193 /* is_tap= */ false);
194 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
195 ASSERT_EQ(2u, args.size());
196
197 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
198 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
199 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
200 WithCoords(POINTER_X, POINTER_Y),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700201 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000202 args.pop_front();
203 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
204 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
205 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
206 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
207 WithCoords(POINTER_X, POINTER_Y),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700208 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000209
210 // Move
211 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
212 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
213 ASSERT_EQ(1u, args.size());
214
215 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
216 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
217 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700218 WithToolType(ToolType::FINGER),
Harry Cutts4fb941a2022-12-14 19:14:04 +0000219 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f)));
220
Harry Cuttsb1e83552022-12-20 11:02:26 +0000221 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000222
223 // Release the button
224 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
225 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
226 /* is_tap= */ false);
227 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, upGesture);
228 ASSERT_EQ(2u, args.size());
229
230 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
231 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
232 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
233 WithCoords(POINTER_X - 5, POINTER_Y + 10),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700234 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000235 args.pop_front();
236 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
237 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
238 WithCoords(POINTER_X - 5, POINTER_Y + 10),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700239 WithToolType(ToolType::FINGER)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000240}
241
Harry Cuttsef400b22022-12-16 21:26:24 +0000242TEST_F(GestureConverterTest, Scroll) {
243 const nsecs_t downTime = 12345;
244 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
245 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
246
Harry Cuttsa546ba82023-01-13 17:21:00 +0000247 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000248 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
249 ASSERT_EQ(2u, args.size());
250
251 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
252 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
253 WithGestureScrollDistance(0, 0, EPSILON),
254 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700255 WithToolType(ToolType::FINGER), WithDownTime(downTime),
Harry Cutts24492e62023-03-10 15:17:43 +0000256 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000257 args.pop_front();
258 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
259 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
260 WithCoords(POINTER_X, POINTER_Y - 10),
261 WithGestureScrollDistance(0, 10, EPSILON),
262 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700263 WithToolType(ToolType::FINGER),
Harry Cutts24492e62023-03-10 15:17:43 +0000264 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000265
Harry Cuttsa546ba82023-01-13 17:21:00 +0000266 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000267 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
268 ASSERT_EQ(1u, args.size());
269 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
270 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
271 WithCoords(POINTER_X, POINTER_Y - 15),
272 WithGestureScrollDistance(0, 5, EPSILON),
273 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700274 WithToolType(ToolType::FINGER),
Harry Cutts24492e62023-03-10 15:17:43 +0000275 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000276
277 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
278 GESTURES_FLING_START);
279 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
280 ASSERT_EQ(1u, args.size());
281 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
282 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
283 WithCoords(POINTER_X, POINTER_Y - 15),
284 WithGestureScrollDistance(0, 0, EPSILON),
285 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700286 WithToolType(ToolType::FINGER),
Harry Cutts24492e62023-03-10 15:17:43 +0000287 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000288}
289
290TEST_F(GestureConverterTest, Scroll_Rotated) {
291 const nsecs_t downTime = 12345;
292 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
293 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
294 converter.setOrientation(ui::ROTATION_90);
295
Harry Cuttsa546ba82023-01-13 17:21:00 +0000296 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000297 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
298 ASSERT_EQ(2u, args.size());
299
300 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
301 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
302 WithGestureScrollDistance(0, 0, EPSILON),
303 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700304 WithToolType(ToolType::FINGER), WithDownTime(downTime)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000305 args.pop_front();
306 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
307 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
308 WithCoords(POINTER_X - 10, POINTER_Y),
309 WithGestureScrollDistance(0, 10, EPSILON),
310 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700311 WithToolType(ToolType::FINGER)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000312
Harry Cuttsa546ba82023-01-13 17:21:00 +0000313 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000314 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
315 ASSERT_EQ(1u, args.size());
316 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
317 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
318 WithCoords(POINTER_X - 15, POINTER_Y),
319 WithGestureScrollDistance(0, 5, EPSILON),
320 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700321 WithToolType(ToolType::FINGER)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000322
323 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
324 GESTURES_FLING_START);
325 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
326 ASSERT_EQ(1u, args.size());
327 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
328 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
329 WithCoords(POINTER_X - 15, POINTER_Y),
330 WithGestureScrollDistance(0, 0, EPSILON),
331 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700332 WithToolType(ToolType::FINGER)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000333}
334
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000335TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000336 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
337 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
338
Harry Cuttsa546ba82023-01-13 17:21:00 +0000339 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000340 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
341
Harry Cuttsa546ba82023-01-13 17:21:00 +0000342 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000343 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
344
345 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
346 GESTURES_FLING_START);
347 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
348
349 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
350 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
351 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000352 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
353 WithMotionClassification(MotionClassification::NONE));
Harry Cuttsef400b22022-12-16 21:26:24 +0000354}
355
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000356TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000357 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
358 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
359
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000360 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
361 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
362
363 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
364 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
365
366 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
367 GESTURES_FLING_START);
368 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
369
370 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
371 // need to use another gesture type, like pinch.
372 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
373 GESTURES_ZOOM_START);
374 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
375 ASSERT_FALSE(args.empty());
376 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
377}
378
379TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
380 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
381 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
382
383 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
384 /*dy=*/0);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000385 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
386
387 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
388 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
389
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000390 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
391 /*dy=*/10);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000392 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
393 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000394 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
395 WithMotionClassification(MotionClassification::NONE));
396}
397
398TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsOffsetsAfterGesture) {
399 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
400 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
401
402 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
403 /*dy=*/5);
404 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
405
406 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
407 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
408
409 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
410 // need to use another gesture type, like pinch.
411 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
412 GESTURES_ZOOM_START);
413 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
414 ASSERT_FALSE(args.empty());
415 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureOffset(0, 0, EPSILON));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000416}
417
418TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
419 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
420 // start swiping up and then start moving left or right, it'll return gesture events with only Y
421 // deltas until you lift your fingers and start swiping again. That's why each of these tests
422 // only checks movement in one dimension.
423 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
424 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
425
426 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
427 /* dy= */ 10);
428 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
429 ASSERT_EQ(4u, args.size());
430
431 // Three fake fingers should be created. We don't actually care where they are, so long as they
432 // move appropriately.
433 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
434 ASSERT_THAT(arg,
435 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
436 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700437 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000438 PointerCoords finger0Start = arg.pointerCoords[0];
439 args.pop_front();
440 arg = std::get<NotifyMotionArgs>(args.front());
441 ASSERT_THAT(arg,
442 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
443 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
444 WithGestureOffset(0, 0, EPSILON),
445 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700446 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000447 PointerCoords finger1Start = arg.pointerCoords[1];
448 args.pop_front();
449 arg = std::get<NotifyMotionArgs>(args.front());
450 ASSERT_THAT(arg,
451 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
452 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
453 WithGestureOffset(0, 0, EPSILON),
454 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700455 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000456 PointerCoords finger2Start = arg.pointerCoords[2];
457 args.pop_front();
458
459 arg = std::get<NotifyMotionArgs>(args.front());
460 ASSERT_THAT(arg,
461 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
462 WithGestureOffset(0, -0.01, EPSILON),
463 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700464 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000465 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
466 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
467 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
468 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
469 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
470 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
471
472 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
473 /* dx= */ 0, /* dy= */ 5);
474 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
475 ASSERT_EQ(1u, args.size());
476 arg = std::get<NotifyMotionArgs>(args.front());
477 ASSERT_THAT(arg,
478 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
479 WithGestureOffset(0, -0.005, EPSILON),
480 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700481 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000482 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
483 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
484 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
485 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
486 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
487 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
488
489 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
490 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
491 ASSERT_EQ(3u, args.size());
492 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
493 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
494 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
495 WithGestureOffset(0, 0, EPSILON),
496 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700497 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000498 args.pop_front();
499 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
500 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
501 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
502 WithGestureOffset(0, 0, EPSILON),
503 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700504 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000505 args.pop_front();
506 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
507 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
508 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700509 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000510}
511
Harry Cutts94f5bd52023-01-06 18:02:18 +0000512TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
513 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
514 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
515 converter.setOrientation(ui::ROTATION_90);
516
517 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
518 /* dy= */ 10);
519 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
520 ASSERT_EQ(4u, args.size());
521
522 // Three fake fingers should be created. We don't actually care where they are, so long as they
523 // move appropriately.
524 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
525 ASSERT_THAT(arg,
526 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
527 WithPointerCount(1u)));
528 PointerCoords finger0Start = arg.pointerCoords[0];
529 args.pop_front();
530 arg = std::get<NotifyMotionArgs>(args.front());
531 ASSERT_THAT(arg,
532 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
533 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
534 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
535 PointerCoords finger1Start = arg.pointerCoords[1];
536 args.pop_front();
537 arg = std::get<NotifyMotionArgs>(args.front());
538 ASSERT_THAT(arg,
539 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
540 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
541 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
542 PointerCoords finger2Start = arg.pointerCoords[2];
543 args.pop_front();
544
545 arg = std::get<NotifyMotionArgs>(args.front());
546 ASSERT_THAT(arg,
547 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
548 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
549 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
550 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
551 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
552 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
553 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
554 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
555
556 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
557 /* dx= */ 0, /* dy= */ 5);
558 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
559 ASSERT_EQ(1u, args.size());
560 arg = std::get<NotifyMotionArgs>(args.front());
561 ASSERT_THAT(arg,
562 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
563 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u)));
564 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
565 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
566 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
567 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
568 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
569 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
570
571 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
572 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
573 ASSERT_EQ(3u, args.size());
574 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
575 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
576 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
577 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
578 args.pop_front();
579 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
580 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
581 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
582 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
583 args.pop_front();
584 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
585 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
586 WithPointerCount(1u)));
587}
588
Harry Cuttsc5748d12022-12-02 17:30:18 +0000589TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
590 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
591 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
592
593 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
594 /* dx= */ 10, /* dy= */ 0);
595 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
596 ASSERT_EQ(5u, args.size());
597
598 // Four fake fingers should be created. We don't actually care where they are, so long as they
599 // move appropriately.
600 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
601 ASSERT_THAT(arg,
602 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
603 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700604 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000605 PointerCoords finger0Start = arg.pointerCoords[0];
606 args.pop_front();
607 arg = std::get<NotifyMotionArgs>(args.front());
608 ASSERT_THAT(arg,
609 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
610 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
611 WithGestureOffset(0, 0, EPSILON),
612 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700613 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000614 PointerCoords finger1Start = arg.pointerCoords[1];
615 args.pop_front();
616 arg = std::get<NotifyMotionArgs>(args.front());
617 ASSERT_THAT(arg,
618 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
619 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
620 WithGestureOffset(0, 0, EPSILON),
621 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700622 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000623 PointerCoords finger2Start = arg.pointerCoords[2];
624 args.pop_front();
625 arg = std::get<NotifyMotionArgs>(args.front());
626 ASSERT_THAT(arg,
627 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
628 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
629 WithGestureOffset(0, 0, EPSILON),
630 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700631 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000632 PointerCoords finger3Start = arg.pointerCoords[3];
633 args.pop_front();
634
635 arg = std::get<NotifyMotionArgs>(args.front());
636 ASSERT_THAT(arg,
637 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
638 WithGestureOffset(0.01, 0, EPSILON),
639 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700640 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000641 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
642 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
643 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
644 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
645 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
646 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
647 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
648 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
649
650 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
651 /* dx= */ 5, /* dy= */ 0);
652 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
653 ASSERT_EQ(1u, args.size());
654 arg = std::get<NotifyMotionArgs>(args.front());
655 ASSERT_THAT(arg,
656 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
657 WithGestureOffset(0.005, 0, EPSILON),
658 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700659 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000660 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
661 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
662 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
663 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
664 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
665 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
666 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
667 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
668
669 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
670 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
671 ASSERT_EQ(4u, args.size());
672 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
673 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
674 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
675 WithGestureOffset(0, 0, EPSILON),
676 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700677 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000678 args.pop_front();
679 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
680 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
681 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
682 WithGestureOffset(0, 0, EPSILON),
683 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700684 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000685 args.pop_front();
686 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
687 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
688 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
689 WithGestureOffset(0, 0, EPSILON),
690 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700691 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000692 args.pop_front();
693 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
694 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
695 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700696 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000697}
698
Harry Cuttsb1e83552022-12-20 11:02:26 +0000699TEST_F(GestureConverterTest, Pinch_Inwards) {
700 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
701 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
702
703 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
704 GESTURES_ZOOM_START);
705 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
706 ASSERT_EQ(2u, args.size());
707 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
708 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
709 WithMotionClassification(MotionClassification::PINCH),
710 WithGesturePinchScaleFactor(1.0f, EPSILON),
711 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700712 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000713 args.pop_front();
714 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
715 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
716 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
717 WithMotionClassification(MotionClassification::PINCH),
718 WithGesturePinchScaleFactor(1.0f, EPSILON),
719 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700720 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000721
722 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
723 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
724 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
725 ASSERT_EQ(1u, args.size());
726 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
727 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
728 WithMotionClassification(MotionClassification::PINCH),
729 WithGesturePinchScaleFactor(0.8f, EPSILON),
730 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
731 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700732 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000733
734 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
735 GESTURES_ZOOM_END);
736 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
737 ASSERT_EQ(2u, args.size());
738 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
739 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
740 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
741 WithMotionClassification(MotionClassification::PINCH),
742 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700743 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000744 args.pop_front();
745 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
746 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
747 WithMotionClassification(MotionClassification::PINCH),
748 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700749 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000750}
751
752TEST_F(GestureConverterTest, Pinch_Outwards) {
753 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
754 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
755
756 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
757 GESTURES_ZOOM_START);
758 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
759 ASSERT_EQ(2u, args.size());
760 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
761 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
762 WithMotionClassification(MotionClassification::PINCH),
763 WithGesturePinchScaleFactor(1.0f, EPSILON),
764 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700765 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000766 args.pop_front();
767 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
768 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
769 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
770 WithMotionClassification(MotionClassification::PINCH),
771 WithGesturePinchScaleFactor(1.0f, EPSILON),
772 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700773 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000774
775 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
776 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
777 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
778 ASSERT_EQ(1u, args.size());
779 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
780 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
781 WithMotionClassification(MotionClassification::PINCH),
782 WithGesturePinchScaleFactor(1.2f, EPSILON),
783 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
784 WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700785 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000786
787 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
788 GESTURES_ZOOM_END);
789 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
790 ASSERT_EQ(2u, args.size());
791 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
792 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
793 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
794 WithMotionClassification(MotionClassification::PINCH),
795 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700796 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000797 args.pop_front();
798 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
799 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
800 WithMotionClassification(MotionClassification::PINCH),
801 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700802 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000803}
804
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000805TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000806 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
807 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
808
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000809 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000810 GESTURES_ZOOM_START);
811 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
812
813 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000814 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000815 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
816
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000817 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000818 GESTURES_ZOOM_END);
819 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
820
821 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
822 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
823 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000824 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
825 WithMotionClassification(MotionClassification::NONE));
826}
827
828TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
829 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
830 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
831
832 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
833 GESTURES_ZOOM_START);
834 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
835
836 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
837 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
838 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
839
840 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
841 GESTURES_ZOOM_END);
842 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
843
844 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
845 // need to use another gesture type, like scroll.
846 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
847 /*dy=*/0);
848 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture);
849 ASSERT_FALSE(args.empty());
850 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000851}
852
Harry Cuttse9b71422023-03-14 16:54:44 +0000853TEST_F(GestureConverterTest, ResetWithButtonPressed) {
854 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
855 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
856
857 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
858 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
859 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
860 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
861
862 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
863 ASSERT_EQ(3u, args.size());
864
865 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
866 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
867 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
868 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
869 WithCoords(POINTER_X, POINTER_Y),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700870 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000871 args.pop_front();
872 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
873 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
874 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
875 WithCoords(POINTER_X, POINTER_Y),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700876 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000877 args.pop_front();
878 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
879 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
880 WithCoords(POINTER_X, POINTER_Y),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700881 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000882}
883
884TEST_F(GestureConverterTest, ResetDuringScroll) {
885 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
886 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
887
888 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
889 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
890
891 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
892 ASSERT_EQ(1u, args.size());
893 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
894 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
895 WithCoords(POINTER_X, POINTER_Y - 10),
896 WithGestureScrollDistance(0, 0, EPSILON),
897 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700898 WithToolType(ToolType::FINGER),
Harry Cuttse9b71422023-03-14 16:54:44 +0000899 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
900}
901
902TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
903 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
904 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
905
906 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
907 /*dy=*/10);
908 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
909
910 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
911 ASSERT_EQ(3u, args.size());
912 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
913 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
914 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
915 WithGestureOffset(0, 0, EPSILON),
916 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700917 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000918 args.pop_front();
919 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
920 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
921 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
922 WithGestureOffset(0, 0, EPSILON),
923 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700924 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000925 args.pop_front();
926 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
927 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
928 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700929 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000930}
931
932TEST_F(GestureConverterTest, ResetDuringPinch) {
933 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
934 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
935
936 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
937 GESTURES_ZOOM_START);
938 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
939
940 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
941 ASSERT_EQ(2u, args.size());
942 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
943 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
944 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
945 WithMotionClassification(MotionClassification::PINCH),
946 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700947 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000948 args.pop_front();
949 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
950 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
951 WithMotionClassification(MotionClassification::PINCH),
952 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700953 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000954}
955
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +0000956TEST_F(GestureConverterTest, FlingTapDown) {
957 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
958 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
959
960 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
961 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
962 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture);
963
964 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
965 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
966 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
967 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f)));
968
969 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
970 ASSERT_TRUE(mFakePointerController->isPointerShown());
971}
972
Harry Cutts4fb941a2022-12-14 19:14:04 +0000973} // namespace android