blob: 41c7392cbcdf0cb488df88dfeada6d3a252b03c1 [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
Arpit Singh3d84add2023-10-10 19:08:29 +000019#include <com_android_input_flags.h>
20#include <flag_macros.h>
Harry Cutts4fb941a2022-12-14 19:14:04 +000021#include <gestures/GestureConverter.h>
22#include <gtest/gtest.h>
Josep del Riod0746382023-07-29 13:18:25 +000023#include <gui/constants.h>
Harry Cutts4fb941a2022-12-14 19:14:04 +000024
25#include "FakeEventHub.h"
26#include "FakeInputReaderPolicy.h"
27#include "FakePointerController.h"
28#include "InstrumentedInputReader.h"
29#include "NotifyArgs.h"
30#include "TestConstants.h"
Prabir Pradhane3b28dd2023-10-06 04:19:29 +000031#include "TestEventMatchers.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000032#include "TestInputListener.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000033#include "include/gestures.h"
Harry Cuttsedf6ce72023-01-04 12:15:53 +000034#include "ui/Rotation.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000035
36namespace android {
37
Arpit Singh3d84add2023-10-10 19:08:29 +000038namespace {
39
40const auto TOUCHPAD_PALM_REJECTION =
41 ACONFIG_FLAG(com::android::input::flags, enable_touchpad_typing_palm_rejection);
42
43} // namespace
44
Harry Cutts4fb941a2022-12-14 19:14:04 +000045using testing::AllOf;
46
47class GestureConverterTest : public testing::Test {
48protected:
49 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000050 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000051 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000052 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000053 static constexpr float POINTER_Y = 200;
54
55 void SetUp() {
56 mFakeEventHub = std::make_unique<FakeEventHub>();
57 mFakePolicy = sp<FakeInputReaderPolicy>::make();
58 mFakeListener = std::make_unique<TestInputListener>();
59 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
60 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000061 mDevice = newDevice();
62 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
63 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000064
65 mFakePointerController = std::make_shared<FakePointerController>();
66 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
67 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
68 mFakePolicy->setPointerController(mFakePointerController);
69 }
70
Harry Cuttsc5748d12022-12-02 17:30:18 +000071 std::shared_ptr<InputDevice> newDevice() {
72 InputDeviceIdentifier identifier;
73 identifier.name = "device";
74 identifier.location = "USB1";
75 identifier.bus = 0;
76 std::shared_ptr<InputDevice> device =
77 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
78 identifier);
79 mReader->pushNextDevice(device);
80 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
81 identifier.bus);
82 mReader->loopOnce();
83 return device;
84 }
85
Harry Cutts4fb941a2022-12-14 19:14:04 +000086 std::shared_ptr<FakeEventHub> mFakeEventHub;
87 sp<FakeInputReaderPolicy> mFakePolicy;
88 std::unique_ptr<TestInputListener> mFakeListener;
89 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000090 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000091 std::shared_ptr<FakePointerController> mFakePointerController;
92};
93
94TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +000095 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
96 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +000097 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +000098
99 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
100 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
101 ASSERT_EQ(1u, args.size());
102
103 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
104 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
105 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +0000106 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
107 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000108
Harry Cuttsb1e83552022-12-20 11:02:26 +0000109 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000110}
111
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000112TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000113 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
114 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000115 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000116 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000117
118 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
119 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
120 ASSERT_EQ(1u, args.size());
121
122 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
123 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
124 WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5),
Josep del Riod0746382023-07-29 13:18:25 +0000125 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
126 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000127
Harry Cuttsb1e83552022-12-20 11:02:26 +0000128 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000129}
130
Harry Cutts4fb941a2022-12-14 19:14:04 +0000131TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000132 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
133 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000134 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000135
136 // Press left and right buttons at once
137 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
138 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
139 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
140 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
141 ASSERT_EQ(3u, args.size());
142
143 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
144 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
145 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
146 AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000147 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
148 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000149 args.pop_front();
150 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
151 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
152 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
153 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000154 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
155 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000156 args.pop_front();
157 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
158 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
159 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
160 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
161 AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000162 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
163 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000164
165 // Then release the left button
166 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
167 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
168 /* is_tap= */ false);
169 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, leftUpGesture);
170 ASSERT_EQ(1u, args.size());
171
172 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
173 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
174 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
175 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000176 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
177 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000178
179 // Finally release the right button
180 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
181 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
182 /* is_tap= */ false);
183 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, rightUpGesture);
Harry Cutts48e7a402023-07-07 15:22:40 +0000184 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000185
186 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
187 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
188 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000189 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
190 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000191 args.pop_front();
192 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
193 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000194 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
195 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000196 args.pop_front();
197 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
198 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000199 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
200 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000201}
202
203TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000204 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
205 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000206 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000207
208 // Press the button
209 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
210 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
211 /* is_tap= */ false);
212 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
213 ASSERT_EQ(2u, args.size());
214
215 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
216 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
217 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000218 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
219 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000220 args.pop_front();
221 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
222 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
223 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
224 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000225 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
226 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000227
228 // Move
229 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
230 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
231 ASSERT_EQ(1u, args.size());
232
233 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
234 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
235 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +0000236 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
237 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000238
Harry Cuttsb1e83552022-12-20 11:02:26 +0000239 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000240
241 // Release the button
242 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
243 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
244 /* is_tap= */ false);
245 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, upGesture);
Harry Cutts48e7a402023-07-07 15:22:40 +0000246 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000247
248 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
249 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
250 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000251 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
252 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000253 args.pop_front();
254 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
255 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000256 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
257 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000258 args.pop_front();
259 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
260 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000261 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
262 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000263}
264
Harry Cuttsef400b22022-12-16 21:26:24 +0000265TEST_F(GestureConverterTest, Scroll) {
266 const nsecs_t downTime = 12345;
267 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
268 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000269 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000270
Harry Cuttsa546ba82023-01-13 17:21:00 +0000271 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000272 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
273 ASSERT_EQ(2u, args.size());
274
275 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
276 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
277 WithGestureScrollDistance(0, 0, EPSILON),
278 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700279 WithToolType(ToolType::FINGER), WithDownTime(downTime),
Josep del Riod0746382023-07-29 13:18:25 +0000280 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
281 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000282 args.pop_front();
283 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
284 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
285 WithCoords(POINTER_X, POINTER_Y - 10),
286 WithGestureScrollDistance(0, 10, EPSILON),
287 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700288 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000289 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
290 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000291
Harry Cuttsa546ba82023-01-13 17:21:00 +0000292 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000293 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
294 ASSERT_EQ(1u, args.size());
295 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
296 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
297 WithCoords(POINTER_X, POINTER_Y - 15),
298 WithGestureScrollDistance(0, 5, EPSILON),
299 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700300 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000301 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
302 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000303
304 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
305 GESTURES_FLING_START);
306 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
307 ASSERT_EQ(1u, args.size());
308 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
309 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
310 WithCoords(POINTER_X, POINTER_Y - 15),
311 WithGestureScrollDistance(0, 0, EPSILON),
312 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700313 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000314 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
315 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000316}
317
318TEST_F(GestureConverterTest, Scroll_Rotated) {
319 const nsecs_t downTime = 12345;
320 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
321 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
322 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000323 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000324
Harry Cuttsa546ba82023-01-13 17:21:00 +0000325 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000326 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
327 ASSERT_EQ(2u, args.size());
328
329 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
330 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
331 WithGestureScrollDistance(0, 0, EPSILON),
332 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000333 WithToolType(ToolType::FINGER), WithDownTime(downTime),
334 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000335 args.pop_front();
336 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
337 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
338 WithCoords(POINTER_X - 10, POINTER_Y),
339 WithGestureScrollDistance(0, 10, EPSILON),
340 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000341 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000342
Harry Cuttsa546ba82023-01-13 17:21:00 +0000343 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000344 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
345 ASSERT_EQ(1u, args.size());
346 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
347 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
348 WithCoords(POINTER_X - 15, POINTER_Y),
349 WithGestureScrollDistance(0, 5, EPSILON),
350 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000351 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000352
353 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
354 GESTURES_FLING_START);
355 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
356 ASSERT_EQ(1u, args.size());
357 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
358 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
359 WithCoords(POINTER_X - 15, POINTER_Y),
360 WithGestureScrollDistance(0, 0, EPSILON),
361 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000362 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000363}
364
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000365TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000366 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
367 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000368 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000369
Harry Cuttsa546ba82023-01-13 17:21:00 +0000370 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000371 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
372
Harry Cuttsa546ba82023-01-13 17:21:00 +0000373 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000374 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
375
376 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
377 GESTURES_FLING_START);
378 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
379
380 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
381 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
382 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000383 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
Josep del Riod0746382023-07-29 13:18:25 +0000384 AllOf(WithMotionClassification(MotionClassification::NONE),
385 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000386}
387
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000388TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000389 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
390 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000391 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000392
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000393 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
394 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
395
396 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
397 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
398
399 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
400 GESTURES_FLING_START);
401 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
402
403 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
404 // need to use another gesture type, like pinch.
405 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
406 GESTURES_ZOOM_START);
407 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
408 ASSERT_FALSE(args.empty());
409 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
410}
411
412TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
413 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
414 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000415 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000416
417 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
418 /*dy=*/0);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000419 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
420
421 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
422 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
423
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000424 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
425 /*dy=*/10);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000426 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
427 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000428 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
429 WithMotionClassification(MotionClassification::NONE));
430}
431
Harry Cutts8743f182023-05-17 12:03:49 +0000432TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000433 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
434 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000435 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000436
437 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
438 /*dy=*/5);
439 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
440
441 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
442 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
443
444 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
445 // need to use another gesture type, like pinch.
446 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
447 GESTURES_ZOOM_START);
448 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
449 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000450 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
451 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000452}
453
454TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
455 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
456 // start swiping up and then start moving left or right, it'll return gesture events with only Y
457 // deltas until you lift your fingers and start swiping again. That's why each of these tests
458 // only checks movement in one dimension.
459 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
460 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000461 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000462
463 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
464 /* dy= */ 10);
465 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
466 ASSERT_EQ(4u, args.size());
467
468 // Three fake fingers should be created. We don't actually care where they are, so long as they
469 // move appropriately.
470 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
471 ASSERT_THAT(arg,
472 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000473 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000474 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000475 WithPointerCount(1u), WithToolType(ToolType::FINGER),
476 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000477 PointerCoords finger0Start = arg.pointerCoords[0];
478 args.pop_front();
479 arg = std::get<NotifyMotionArgs>(args.front());
480 ASSERT_THAT(arg,
481 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
482 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000483 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000484 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000485 WithPointerCount(2u), WithToolType(ToolType::FINGER),
486 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000487 PointerCoords finger1Start = arg.pointerCoords[1];
488 args.pop_front();
489 arg = std::get<NotifyMotionArgs>(args.front());
490 ASSERT_THAT(arg,
491 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
492 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000493 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000494 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000495 WithPointerCount(3u), WithToolType(ToolType::FINGER),
496 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000497 PointerCoords finger2Start = arg.pointerCoords[2];
498 args.pop_front();
499
500 arg = std::get<NotifyMotionArgs>(args.front());
501 ASSERT_THAT(arg,
502 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000503 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000504 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000505 WithPointerCount(3u), WithToolType(ToolType::FINGER),
506 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000507 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
508 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
509 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
510 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
511 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
512 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
513
514 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
515 /* dx= */ 0, /* dy= */ 5);
516 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
517 ASSERT_EQ(1u, args.size());
518 arg = std::get<NotifyMotionArgs>(args.front());
519 ASSERT_THAT(arg,
520 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000521 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000522 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000523 WithPointerCount(3u), WithToolType(ToolType::FINGER),
524 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000525 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
526 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
527 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
528 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
529 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
530 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
531
532 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
533 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
534 ASSERT_EQ(3u, args.size());
535 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
536 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
537 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000538 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000539 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000540 WithPointerCount(3u), WithToolType(ToolType::FINGER),
541 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000542 args.pop_front();
543 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
544 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
545 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000546 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000547 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000548 WithPointerCount(2u), WithToolType(ToolType::FINGER),
549 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000550 args.pop_front();
551 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
552 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000553 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000554 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000555 WithPointerCount(1u), WithToolType(ToolType::FINGER),
556 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000557}
558
Harry Cutts94f5bd52023-01-06 18:02:18 +0000559TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
560 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
561 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
562 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000563 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000564
565 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
566 /* dy= */ 10);
567 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
568 ASSERT_EQ(4u, args.size());
569
570 // Three fake fingers should be created. We don't actually care where they are, so long as they
571 // move appropriately.
572 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
573 ASSERT_THAT(arg,
574 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000575 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000576 PointerCoords finger0Start = arg.pointerCoords[0];
577 args.pop_front();
578 arg = std::get<NotifyMotionArgs>(args.front());
579 ASSERT_THAT(arg,
580 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
581 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000582 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
583 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000584 PointerCoords finger1Start = arg.pointerCoords[1];
585 args.pop_front();
586 arg = std::get<NotifyMotionArgs>(args.front());
587 ASSERT_THAT(arg,
588 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
589 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000590 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
591 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000592 PointerCoords finger2Start = arg.pointerCoords[2];
593 args.pop_front();
594
595 arg = std::get<NotifyMotionArgs>(args.front());
596 ASSERT_THAT(arg,
597 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000598 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
599 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000600 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
601 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
602 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
603 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
604 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
605 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
606
607 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
608 /* dx= */ 0, /* dy= */ 5);
609 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
610 ASSERT_EQ(1u, args.size());
611 arg = std::get<NotifyMotionArgs>(args.front());
612 ASSERT_THAT(arg,
613 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000614 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
615 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000616 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
617 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
618 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
619 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
620 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
621 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
622
623 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
624 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
625 ASSERT_EQ(3u, args.size());
626 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
627 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
628 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000629 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
630 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000631 args.pop_front();
632 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
633 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
634 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000635 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
636 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000637 args.pop_front();
638 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
639 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000640 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000641}
642
Harry Cuttsc5748d12022-12-02 17:30:18 +0000643TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
644 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
645 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000646 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000647
648 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
649 /* dx= */ 10, /* dy= */ 0);
650 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
651 ASSERT_EQ(5u, args.size());
652
653 // Four fake fingers should be created. We don't actually care where they are, so long as they
654 // move appropriately.
655 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
656 ASSERT_THAT(arg,
657 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000658 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000659 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000660 WithPointerCount(1u), WithToolType(ToolType::FINGER),
661 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000662 PointerCoords finger0Start = arg.pointerCoords[0];
663 args.pop_front();
664 arg = std::get<NotifyMotionArgs>(args.front());
665 ASSERT_THAT(arg,
666 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
667 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000668 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000669 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000670 WithPointerCount(2u), WithToolType(ToolType::FINGER),
671 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000672 PointerCoords finger1Start = arg.pointerCoords[1];
673 args.pop_front();
674 arg = std::get<NotifyMotionArgs>(args.front());
675 ASSERT_THAT(arg,
676 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
677 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000678 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000679 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000680 WithPointerCount(3u), WithToolType(ToolType::FINGER),
681 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000682 PointerCoords finger2Start = arg.pointerCoords[2];
683 args.pop_front();
684 arg = std::get<NotifyMotionArgs>(args.front());
685 ASSERT_THAT(arg,
686 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
687 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000688 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000689 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000690 WithPointerCount(4u), WithToolType(ToolType::FINGER),
691 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000692 PointerCoords finger3Start = arg.pointerCoords[3];
693 args.pop_front();
694
695 arg = std::get<NotifyMotionArgs>(args.front());
696 ASSERT_THAT(arg,
697 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000698 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000699 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000700 WithPointerCount(4u), WithToolType(ToolType::FINGER),
701 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000702 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
703 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
704 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
705 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
706 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
707 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
708 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
709 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
710
711 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
712 /* dx= */ 5, /* dy= */ 0);
713 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
714 ASSERT_EQ(1u, args.size());
715 arg = std::get<NotifyMotionArgs>(args.front());
716 ASSERT_THAT(arg,
717 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000718 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000719 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000720 WithPointerCount(4u), WithToolType(ToolType::FINGER),
721 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000722 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
723 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
724 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
725 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
726 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
727 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
728 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
729 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
730
731 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
732 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
733 ASSERT_EQ(4u, args.size());
734 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
735 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
736 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000737 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000738 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000739 WithPointerCount(4u), WithToolType(ToolType::FINGER),
740 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000741 args.pop_front();
742 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
743 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
744 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000745 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000746 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000747 WithPointerCount(3u), WithToolType(ToolType::FINGER),
748 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000749 args.pop_front();
750 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
751 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
752 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000753 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000754 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000755 WithPointerCount(2u), WithToolType(ToolType::FINGER),
756 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000757 args.pop_front();
758 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
759 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000760 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000761 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000762 WithPointerCount(1u), WithToolType(ToolType::FINGER),
763 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000764}
765
Harry Cuttsb1e83552022-12-20 11:02:26 +0000766TEST_F(GestureConverterTest, Pinch_Inwards) {
767 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
768 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000769 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000770
771 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
772 GESTURES_ZOOM_START);
773 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
774 ASSERT_EQ(2u, args.size());
775 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
776 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
777 WithMotionClassification(MotionClassification::PINCH),
778 WithGesturePinchScaleFactor(1.0f, EPSILON),
779 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000780 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000781 args.pop_front();
782 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
783 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
784 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
785 WithMotionClassification(MotionClassification::PINCH),
786 WithGesturePinchScaleFactor(1.0f, EPSILON),
787 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000788 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000789
790 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
791 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
792 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
793 ASSERT_EQ(1u, args.size());
794 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
795 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
796 WithMotionClassification(MotionClassification::PINCH),
797 WithGesturePinchScaleFactor(0.8f, EPSILON),
798 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
799 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000800 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000801
802 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
803 GESTURES_ZOOM_END);
804 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
805 ASSERT_EQ(2u, args.size());
806 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
807 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
808 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
809 WithMotionClassification(MotionClassification::PINCH),
810 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000811 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000812 args.pop_front();
813 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
814 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
815 WithMotionClassification(MotionClassification::PINCH),
816 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000817 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000818}
819
820TEST_F(GestureConverterTest, Pinch_Outwards) {
821 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
822 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000823 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000824
825 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
826 GESTURES_ZOOM_START);
827 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
828 ASSERT_EQ(2u, args.size());
829 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
830 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
831 WithMotionClassification(MotionClassification::PINCH),
832 WithGesturePinchScaleFactor(1.0f, EPSILON),
833 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000834 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000835 args.pop_front();
836 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
837 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
838 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
839 WithMotionClassification(MotionClassification::PINCH),
840 WithGesturePinchScaleFactor(1.0f, EPSILON),
841 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000842 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000843
844 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
845 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
846 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
847 ASSERT_EQ(1u, args.size());
848 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
849 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
850 WithMotionClassification(MotionClassification::PINCH),
851 WithGesturePinchScaleFactor(1.2f, EPSILON),
852 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
853 WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000854 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000855
856 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
857 GESTURES_ZOOM_END);
858 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
859 ASSERT_EQ(2u, args.size());
860 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
861 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
862 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
863 WithMotionClassification(MotionClassification::PINCH),
864 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000865 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000866 args.pop_front();
867 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
868 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
869 WithMotionClassification(MotionClassification::PINCH),
870 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000871 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000872}
873
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000874TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000875 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
876 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000877 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000878
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000879 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000880 GESTURES_ZOOM_START);
881 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
882
883 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000884 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000885 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
886
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000887 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000888 GESTURES_ZOOM_END);
889 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
890
891 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
892 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
893 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000894 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
895 WithMotionClassification(MotionClassification::NONE));
896}
897
898TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
899 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
900 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000901 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000902
903 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
904 GESTURES_ZOOM_START);
905 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
906
907 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
908 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
909 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
910
911 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
912 GESTURES_ZOOM_END);
913 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
914
915 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
916 // need to use another gesture type, like scroll.
917 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
918 /*dy=*/0);
919 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture);
920 ASSERT_FALSE(args.empty());
921 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000922}
923
Harry Cuttse9b71422023-03-14 16:54:44 +0000924TEST_F(GestureConverterTest, ResetWithButtonPressed) {
925 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
926 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000927 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000928
929 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
930 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
931 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
932 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
933
934 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
935 ASSERT_EQ(3u, args.size());
936
937 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
938 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
939 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
940 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000941 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
942 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000943 args.pop_front();
944 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
945 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
946 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000947 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
948 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000949 args.pop_front();
950 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
951 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000952 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
953 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000954}
955
956TEST_F(GestureConverterTest, ResetDuringScroll) {
957 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
958 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000959 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000960
961 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
962 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
963
964 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
965 ASSERT_EQ(1u, args.size());
966 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
967 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
968 WithCoords(POINTER_X, POINTER_Y - 10),
969 WithGestureScrollDistance(0, 0, EPSILON),
970 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700971 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000972 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
973 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000974}
975
976TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
977 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
978 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000979 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000980
981 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
982 /*dy=*/10);
983 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
984
985 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
986 ASSERT_EQ(3u, args.size());
987 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
988 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
989 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
990 WithGestureOffset(0, 0, EPSILON),
991 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000992 WithPointerCount(3u), WithToolType(ToolType::FINGER),
993 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000994 args.pop_front();
995 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
996 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
997 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
998 WithGestureOffset(0, 0, EPSILON),
999 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001000 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1001 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001002 args.pop_front();
1003 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1004 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1005 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001006 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1007 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001008}
1009
1010TEST_F(GestureConverterTest, ResetDuringPinch) {
1011 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1012 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001013 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001014
1015 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1016 GESTURES_ZOOM_START);
1017 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1018
1019 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
1020 ASSERT_EQ(2u, args.size());
1021 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1022 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1023 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1024 WithMotionClassification(MotionClassification::PINCH),
1025 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +00001026 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001027 args.pop_front();
1028 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1029 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1030 WithMotionClassification(MotionClassification::PINCH),
1031 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +00001032 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001033}
1034
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001035TEST_F(GestureConverterTest, FlingTapDown) {
1036 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1037 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001038 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001039
1040 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1041 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1042 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture);
1043
1044 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1045 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1046 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001047 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1048 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001049
1050 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1051 ASSERT_TRUE(mFakePointerController->isPointerShown());
1052}
1053
Arpit Singha5ea7c12023-07-05 15:39:25 +00001054TEST_F(GestureConverterTest, Tap) {
1055 // Tap should produce button press/release events
1056 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1057 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001058 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001059
1060 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1061 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1062 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1063
1064 ASSERT_EQ(1u, args.size());
1065 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1066 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1067 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001068 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1069 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001070
1071 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1072 /* down= */ GESTURES_BUTTON_LEFT,
1073 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1074 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
1075
1076 ASSERT_EQ(5u, args.size());
1077 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1078 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1079 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001080 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1081 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001082 args.pop_front();
1083 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1084 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1085 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1086 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1087 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1088 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001089 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001090 args.pop_front();
1091 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1092 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1093 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1094 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001095 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1096 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001097 args.pop_front();
1098 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1099 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1100 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001101 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001102 args.pop_front();
1103 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1104 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1105 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001106 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1107 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001108}
1109
1110TEST_F(GestureConverterTest, Click) {
1111 // Click should produce button press/release events
1112 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1113 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001114 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001115
1116 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1117 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1118 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1119
1120 ASSERT_EQ(1u, args.size());
1121 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1122 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1123 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001124 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1125 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001126
1127 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1128 /* down= */ GESTURES_BUTTON_LEFT,
1129 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
1130 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
1131
1132 ASSERT_EQ(2u, args.size());
1133 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1134 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1135 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001136 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1137 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001138 args.pop_front();
1139 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1140 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1141 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1142 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1143 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1144 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001145 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001146
1147 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1148 /* down= */ GESTURES_BUTTON_NONE,
1149 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
1150 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
1151
1152 ASSERT_EQ(3u, args.size());
1153 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1154 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1155 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1156 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001157 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1158 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001159 args.pop_front();
1160 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1161 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1162 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001163 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001164 args.pop_front();
1165 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1166 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1167 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001168 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1169 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001170}
1171
Arpit Singh3d84add2023-10-10 19:08:29 +00001172TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
1173 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001174 // Tap should be ignored when disabled
1175 mReader->getContext()->setPreventingTouchpadTaps(true);
1176
1177 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1178 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001179 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001180
1181 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1182 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1183 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1184
1185 ASSERT_EQ(1u, args.size());
1186 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1187 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1188 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001189 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1190 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001191 args.pop_front();
1192
1193 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1194 /* down= */ GESTURES_BUTTON_LEFT,
1195 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1196 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
1197
1198 // no events should be generated
1199 ASSERT_EQ(0u, args.size());
1200
1201 // Future taps should be re-enabled
1202 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1203}
1204
Arpit Singh3d84add2023-10-10 19:08:29 +00001205TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1206 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001207 // Click should still produce button press/release events
1208 mReader->getContext()->setPreventingTouchpadTaps(true);
1209
1210 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1211 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001212 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001213
1214 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1215 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1216 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1217
1218 ASSERT_EQ(1u, args.size());
1219 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1220 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1221 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001222 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1223 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001224
1225 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1226 /* down= */ GESTURES_BUTTON_LEFT,
1227 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
1228 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
1229 ASSERT_EQ(2u, args.size());
1230
1231 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1232 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1233 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001234 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1235 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001236 args.pop_front();
1237 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1238 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1239 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1240 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1241 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1242 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001243 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001244
1245 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1246 /* down= */ GESTURES_BUTTON_NONE,
1247 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
1248 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
1249
1250 ASSERT_EQ(3u, args.size());
1251 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1252 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1253 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1254 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001255 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1256 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001257 args.pop_front();
1258 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1259 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1260 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001261 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001262 args.pop_front();
1263 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1264 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1265 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001266 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1267 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001268
1269 // Future taps should be re-enabled
1270 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1271}
1272
Arpit Singh3d84add2023-10-10 19:08:29 +00001273TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1274 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001275 // initially disable tap-to-click
1276 mReader->getContext()->setPreventingTouchpadTaps(true);
1277
1278 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1279 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001280 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001281
1282 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1283 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1284 ASSERT_EQ(1u, args.size());
1285
1286 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1287 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1288 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +00001289 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1290 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001291
1292 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
1293
1294 // Future taps should be re-enabled
1295 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1296}
1297
Harry Cutts4fb941a2022-12-14 19:14:04 +00001298} // namespace android