blob: a3994f08e03b917b8038365e99ab3ee2acb829a2 [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
Harry Cutts8743f182023-05-17 12:03:49 +0000398TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000399 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());
Harry Cutts8743f182023-05-17 12:03:49 +0000415 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
416 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000417}
418
419TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
420 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
421 // start swiping up and then start moving left or right, it'll return gesture events with only Y
422 // deltas until you lift your fingers and start swiping again. That's why each of these tests
423 // only checks movement in one dimension.
424 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
425 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
426
427 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
428 /* dy= */ 10);
429 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
430 ASSERT_EQ(4u, args.size());
431
432 // Three fake fingers should be created. We don't actually care where they are, so long as they
433 // move appropriately.
434 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
435 ASSERT_THAT(arg,
436 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000437 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000438 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700439 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000440 PointerCoords finger0Start = arg.pointerCoords[0];
441 args.pop_front();
442 arg = std::get<NotifyMotionArgs>(args.front());
443 ASSERT_THAT(arg,
444 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
445 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000446 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000447 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700448 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000449 PointerCoords finger1Start = arg.pointerCoords[1];
450 args.pop_front();
451 arg = std::get<NotifyMotionArgs>(args.front());
452 ASSERT_THAT(arg,
453 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
454 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000455 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000456 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700457 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000458 PointerCoords finger2Start = arg.pointerCoords[2];
459 args.pop_front();
460
461 arg = std::get<NotifyMotionArgs>(args.front());
462 ASSERT_THAT(arg,
463 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000464 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000465 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700466 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000467 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
468 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
469 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
470 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
471 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
472 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
473
474 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
475 /* dx= */ 0, /* dy= */ 5);
476 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
477 ASSERT_EQ(1u, args.size());
478 arg = std::get<NotifyMotionArgs>(args.front());
479 ASSERT_THAT(arg,
480 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000481 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000482 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700483 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000484 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
485 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
486 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
487 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
488 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
489 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
490
491 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
492 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
493 ASSERT_EQ(3u, args.size());
494 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
495 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
496 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000497 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000498 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700499 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000500 args.pop_front();
501 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
502 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
503 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000504 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000505 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700506 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000507 args.pop_front();
508 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
509 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000510 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000511 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700512 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000513}
514
Harry Cutts94f5bd52023-01-06 18:02:18 +0000515TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
516 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
517 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
518 converter.setOrientation(ui::ROTATION_90);
519
520 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
521 /* dy= */ 10);
522 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
523 ASSERT_EQ(4u, args.size());
524
525 // Three fake fingers should be created. We don't actually care where they are, so long as they
526 // move appropriately.
527 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
528 ASSERT_THAT(arg,
529 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
530 WithPointerCount(1u)));
531 PointerCoords finger0Start = arg.pointerCoords[0];
532 args.pop_front();
533 arg = std::get<NotifyMotionArgs>(args.front());
534 ASSERT_THAT(arg,
535 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
536 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
537 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
538 PointerCoords finger1Start = arg.pointerCoords[1];
539 args.pop_front();
540 arg = std::get<NotifyMotionArgs>(args.front());
541 ASSERT_THAT(arg,
542 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
543 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
544 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
545 PointerCoords finger2Start = arg.pointerCoords[2];
546 args.pop_front();
547
548 arg = std::get<NotifyMotionArgs>(args.front());
549 ASSERT_THAT(arg,
550 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
551 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
552 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
553 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
554 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
555 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
556 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
557 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
558
559 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
560 /* dx= */ 0, /* dy= */ 5);
561 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
562 ASSERT_EQ(1u, args.size());
563 arg = std::get<NotifyMotionArgs>(args.front());
564 ASSERT_THAT(arg,
565 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
566 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u)));
567 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
568 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
569 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
570 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
571 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
572 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
573
574 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
575 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
576 ASSERT_EQ(3u, args.size());
577 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
578 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
579 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
580 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
581 args.pop_front();
582 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
583 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
584 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
585 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
586 args.pop_front();
587 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
588 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
589 WithPointerCount(1u)));
590}
591
Harry Cuttsc5748d12022-12-02 17:30:18 +0000592TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
593 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
594 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
595
596 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
597 /* dx= */ 10, /* dy= */ 0);
598 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
599 ASSERT_EQ(5u, args.size());
600
601 // Four fake fingers should be created. We don't actually care where they are, so long as they
602 // move appropriately.
603 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
604 ASSERT_THAT(arg,
605 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000606 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000607 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700608 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000609 PointerCoords finger0Start = arg.pointerCoords[0];
610 args.pop_front();
611 arg = std::get<NotifyMotionArgs>(args.front());
612 ASSERT_THAT(arg,
613 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
614 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000615 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000616 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700617 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000618 PointerCoords finger1Start = arg.pointerCoords[1];
619 args.pop_front();
620 arg = std::get<NotifyMotionArgs>(args.front());
621 ASSERT_THAT(arg,
622 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
623 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000624 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000625 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700626 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000627 PointerCoords finger2Start = arg.pointerCoords[2];
628 args.pop_front();
629 arg = std::get<NotifyMotionArgs>(args.front());
630 ASSERT_THAT(arg,
631 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
632 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000633 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000634 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700635 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000636 PointerCoords finger3Start = arg.pointerCoords[3];
637 args.pop_front();
638
639 arg = std::get<NotifyMotionArgs>(args.front());
640 ASSERT_THAT(arg,
641 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000642 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000643 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700644 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000645 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
646 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
647 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
648 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
649 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
650 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
651 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
652 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
653
654 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
655 /* dx= */ 5, /* dy= */ 0);
656 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
657 ASSERT_EQ(1u, args.size());
658 arg = std::get<NotifyMotionArgs>(args.front());
659 ASSERT_THAT(arg,
660 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000661 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000662 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700663 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000664 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
665 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
666 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
667 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
668 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
669 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
670 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
671 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
672
673 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
674 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
675 ASSERT_EQ(4u, args.size());
676 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
677 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
678 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000679 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000680 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700681 WithPointerCount(4u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000682 args.pop_front();
683 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
684 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
685 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000686 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000687 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700688 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000689 args.pop_front();
690 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
691 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
692 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000693 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000694 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700695 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000696 args.pop_front();
697 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
698 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000699 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000700 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700701 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000702}
703
Harry Cuttsb1e83552022-12-20 11:02:26 +0000704TEST_F(GestureConverterTest, Pinch_Inwards) {
705 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
706 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
707
708 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
709 GESTURES_ZOOM_START);
710 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
711 ASSERT_EQ(2u, args.size());
712 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
713 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
714 WithMotionClassification(MotionClassification::PINCH),
715 WithGesturePinchScaleFactor(1.0f, EPSILON),
716 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700717 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000718 args.pop_front();
719 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
720 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
721 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
722 WithMotionClassification(MotionClassification::PINCH),
723 WithGesturePinchScaleFactor(1.0f, EPSILON),
724 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700725 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000726
727 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
728 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
729 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
730 ASSERT_EQ(1u, args.size());
731 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
732 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
733 WithMotionClassification(MotionClassification::PINCH),
734 WithGesturePinchScaleFactor(0.8f, EPSILON),
735 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
736 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700737 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000738
739 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
740 GESTURES_ZOOM_END);
741 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
742 ASSERT_EQ(2u, args.size());
743 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
744 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
745 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
746 WithMotionClassification(MotionClassification::PINCH),
747 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700748 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000749 args.pop_front();
750 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
751 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
752 WithMotionClassification(MotionClassification::PINCH),
753 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700754 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000755}
756
757TEST_F(GestureConverterTest, Pinch_Outwards) {
758 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
759 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
760
761 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
762 GESTURES_ZOOM_START);
763 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
764 ASSERT_EQ(2u, args.size());
765 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
766 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
767 WithMotionClassification(MotionClassification::PINCH),
768 WithGesturePinchScaleFactor(1.0f, EPSILON),
769 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700770 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000771 args.pop_front();
772 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
773 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
774 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
775 WithMotionClassification(MotionClassification::PINCH),
776 WithGesturePinchScaleFactor(1.0f, EPSILON),
777 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700778 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000779
780 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
781 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
782 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
783 ASSERT_EQ(1u, args.size());
784 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
785 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
786 WithMotionClassification(MotionClassification::PINCH),
787 WithGesturePinchScaleFactor(1.2f, EPSILON),
788 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
789 WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700790 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000791
792 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
793 GESTURES_ZOOM_END);
794 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
795 ASSERT_EQ(2u, args.size());
796 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
797 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
798 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
799 WithMotionClassification(MotionClassification::PINCH),
800 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700801 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000802 args.pop_front();
803 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
804 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
805 WithMotionClassification(MotionClassification::PINCH),
806 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700807 WithToolType(ToolType::FINGER)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000808}
809
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000810TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000811 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
812 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
813
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000814 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000815 GESTURES_ZOOM_START);
816 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
817
818 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000819 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000820 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
821
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000822 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000823 GESTURES_ZOOM_END);
824 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
825
826 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
827 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
828 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000829 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
830 WithMotionClassification(MotionClassification::NONE));
831}
832
833TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
834 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
835 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
836
837 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
838 GESTURES_ZOOM_START);
839 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
840
841 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
842 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
843 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
844
845 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
846 GESTURES_ZOOM_END);
847 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
848
849 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
850 // need to use another gesture type, like scroll.
851 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
852 /*dy=*/0);
853 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture);
854 ASSERT_FALSE(args.empty());
855 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000856}
857
Harry Cuttse9b71422023-03-14 16:54:44 +0000858TEST_F(GestureConverterTest, ResetWithButtonPressed) {
859 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
860 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
861
862 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
863 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
864 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
865 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
866
867 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
868 ASSERT_EQ(3u, args.size());
869
870 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
871 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
872 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
873 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
874 WithCoords(POINTER_X, POINTER_Y),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700875 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000876 args.pop_front();
877 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
878 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
879 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), 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 args.pop_front();
883 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
884 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
885 WithCoords(POINTER_X, POINTER_Y),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700886 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000887}
888
889TEST_F(GestureConverterTest, ResetDuringScroll) {
890 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
891 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
892
893 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
894 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
895
896 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
897 ASSERT_EQ(1u, args.size());
898 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
899 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
900 WithCoords(POINTER_X, POINTER_Y - 10),
901 WithGestureScrollDistance(0, 0, EPSILON),
902 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700903 WithToolType(ToolType::FINGER),
Harry Cuttse9b71422023-03-14 16:54:44 +0000904 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
905}
906
907TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
908 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
909 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
910
911 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
912 /*dy=*/10);
913 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
914
915 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
916 ASSERT_EQ(3u, args.size());
917 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
918 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
919 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
920 WithGestureOffset(0, 0, EPSILON),
921 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700922 WithPointerCount(3u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000923 args.pop_front();
924 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
925 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
926 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
927 WithGestureOffset(0, 0, EPSILON),
928 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700929 WithPointerCount(2u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000930 args.pop_front();
931 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
932 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
933 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700934 WithPointerCount(1u), WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000935}
936
937TEST_F(GestureConverterTest, ResetDuringPinch) {
938 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
939 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
940
941 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
942 GESTURES_ZOOM_START);
943 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
944
945 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
946 ASSERT_EQ(2u, args.size());
947 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
948 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
949 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
950 WithMotionClassification(MotionClassification::PINCH),
951 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700952 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000953 args.pop_front();
954 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
955 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
956 WithMotionClassification(MotionClassification::PINCH),
957 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700958 WithToolType(ToolType::FINGER)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000959}
960
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +0000961TEST_F(GestureConverterTest, FlingTapDown) {
962 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
963 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
964
965 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
966 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
967 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture);
968
969 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
970 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
971 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
972 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f)));
973
974 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
975 ASSERT_TRUE(mFakePointerController->isPointerShown());
976}
977
Harry Cutts4fb941a2022-12-14 19:14:04 +0000978} // namespace android