blob: 22c1eefa15ea43f5b58243d20dc0b0214bc425b4 [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
Byoungho Jungee6268f2023-10-30 17:27:26 +090038namespace input_flags = com::android::input::flags;
39
Arpit Singh3d84add2023-10-10 19:08:29 +000040namespace {
41
42const auto TOUCHPAD_PALM_REJECTION =
Byoungho Jungee6268f2023-10-30 17:27:26 +090043 ACONFIG_FLAG(input_flags, enable_touchpad_typing_palm_rejection);
Arpit Singh3d84add2023-10-10 19:08:29 +000044
45} // namespace
46
Harry Cutts4fb941a2022-12-14 19:14:04 +000047using testing::AllOf;
48
Byoungho Jungee6268f2023-10-30 17:27:26 +090049class GestureConverterTestBase : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000050protected:
51 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000052 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000053 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000054 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000055 static constexpr float POINTER_Y = 200;
56
57 void SetUp() {
58 mFakeEventHub = std::make_unique<FakeEventHub>();
59 mFakePolicy = sp<FakeInputReaderPolicy>::make();
60 mFakeListener = std::make_unique<TestInputListener>();
61 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
62 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000063 mDevice = newDevice();
64 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
65 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000066
67 mFakePointerController = std::make_shared<FakePointerController>();
68 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
69 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
70 mFakePolicy->setPointerController(mFakePointerController);
71 }
72
Harry Cuttsc5748d12022-12-02 17:30:18 +000073 std::shared_ptr<InputDevice> newDevice() {
74 InputDeviceIdentifier identifier;
75 identifier.name = "device";
76 identifier.location = "USB1";
77 identifier.bus = 0;
78 std::shared_ptr<InputDevice> device =
79 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
80 identifier);
81 mReader->pushNextDevice(device);
82 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
83 identifier.bus);
84 mReader->loopOnce();
85 return device;
86 }
87
Harry Cutts4fb941a2022-12-14 19:14:04 +000088 std::shared_ptr<FakeEventHub> mFakeEventHub;
89 sp<FakeInputReaderPolicy> mFakePolicy;
90 std::unique_ptr<TestInputListener> mFakeListener;
91 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000092 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000093 std::shared_ptr<FakePointerController> mFakePointerController;
94};
95
Byoungho Jungee6268f2023-10-30 17:27:26 +090096class GestureConverterTest : public GestureConverterTestBase {
97protected:
98 void SetUp() override {
99 input_flags::enable_pointer_choreographer(false);
100 GestureConverterTestBase::SetUp();
101 }
102};
103
Harry Cutts4fb941a2022-12-14 19:14:04 +0000104TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000105 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
106 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000107 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000108
109 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
110 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
111 ASSERT_EQ(1u, args.size());
112
113 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
114 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
115 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +0000116 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
117 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000118
Harry Cuttsb1e83552022-12-20 11:02:26 +0000119 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000120}
121
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000122TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000123 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
124 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000125 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000126 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000127
128 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
129 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
130 ASSERT_EQ(1u, args.size());
131
132 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
133 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
134 WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5),
Josep del Riod0746382023-07-29 13:18:25 +0000135 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
136 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000137
Harry Cuttsb1e83552022-12-20 11:02:26 +0000138 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000139}
140
Harry Cutts4fb941a2022-12-14 19:14:04 +0000141TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000142 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
143 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000144 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000145
146 // Press left and right buttons at once
147 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
148 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
149 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
150 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
151 ASSERT_EQ(3u, args.size());
152
153 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
154 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
155 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
156 AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000157 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
158 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000159 args.pop_front();
160 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
161 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
162 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
163 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000164 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
165 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000166 args.pop_front();
167 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
168 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
169 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
170 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
171 AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000172 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
173 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000174
175 // Then release the left button
176 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
177 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
178 /* is_tap= */ false);
179 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, leftUpGesture);
180 ASSERT_EQ(1u, args.size());
181
182 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
183 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
184 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
185 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000186 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
187 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000188
189 // Finally release the right button
190 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
191 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
192 /* is_tap= */ false);
193 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, rightUpGesture);
Harry Cutts48e7a402023-07-07 15:22:40 +0000194 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000195
196 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
197 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
198 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), 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 args.pop_front();
202 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
203 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000204 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
205 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000206 args.pop_front();
207 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
208 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000209 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
210 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000211}
212
213TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000214 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
215 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000216 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000217
218 // Press the button
219 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
220 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
221 /* is_tap= */ false);
222 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
223 ASSERT_EQ(2u, args.size());
224
225 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
226 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
227 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000228 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
229 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000230 args.pop_front();
231 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
232 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
233 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
234 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000235 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
236 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000237
238 // Move
239 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
240 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
241 ASSERT_EQ(1u, args.size());
242
243 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
244 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
245 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +0000246 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
247 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000248
Harry Cuttsb1e83552022-12-20 11:02:26 +0000249 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000250
251 // Release the button
252 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
253 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
254 /* is_tap= */ false);
255 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, upGesture);
Harry Cutts48e7a402023-07-07 15:22:40 +0000256 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000257
258 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
259 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
260 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), 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 args.pop_front();
264 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
265 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000266 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
267 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000268 args.pop_front();
269 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
270 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000271 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
272 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000273}
274
Harry Cuttsef400b22022-12-16 21:26:24 +0000275TEST_F(GestureConverterTest, Scroll) {
276 const nsecs_t downTime = 12345;
277 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
278 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000279 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000280
Harry Cuttsa546ba82023-01-13 17:21:00 +0000281 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000282 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
283 ASSERT_EQ(2u, args.size());
284
285 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
286 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
287 WithGestureScrollDistance(0, 0, EPSILON),
288 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700289 WithToolType(ToolType::FINGER), WithDownTime(downTime),
Josep del Riod0746382023-07-29 13:18:25 +0000290 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
291 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000292 args.pop_front();
293 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
294 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
295 WithCoords(POINTER_X, POINTER_Y - 10),
296 WithGestureScrollDistance(0, 10, EPSILON),
297 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700298 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000299 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
300 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000301
Harry Cuttsa546ba82023-01-13 17:21:00 +0000302 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000303 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
304 ASSERT_EQ(1u, args.size());
305 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
306 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
307 WithCoords(POINTER_X, POINTER_Y - 15),
308 WithGestureScrollDistance(0, 5, EPSILON),
309 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700310 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000311 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
312 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000313
314 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
315 GESTURES_FLING_START);
316 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
317 ASSERT_EQ(1u, args.size());
318 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
319 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
320 WithCoords(POINTER_X, POINTER_Y - 15),
321 WithGestureScrollDistance(0, 0, EPSILON),
322 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700323 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000324 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
325 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000326}
327
328TEST_F(GestureConverterTest, Scroll_Rotated) {
329 const nsecs_t downTime = 12345;
330 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
331 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
332 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000333 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000334
Harry Cuttsa546ba82023-01-13 17:21:00 +0000335 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000336 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
337 ASSERT_EQ(2u, args.size());
338
339 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
340 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
341 WithGestureScrollDistance(0, 0, EPSILON),
342 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000343 WithToolType(ToolType::FINGER), WithDownTime(downTime),
344 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000345 args.pop_front();
346 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
347 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
348 WithCoords(POINTER_X - 10, POINTER_Y),
349 WithGestureScrollDistance(0, 10, 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
Harry Cuttsa546ba82023-01-13 17:21:00 +0000353 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000354 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
355 ASSERT_EQ(1u, args.size());
356 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
357 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
358 WithCoords(POINTER_X - 15, POINTER_Y),
359 WithGestureScrollDistance(0, 5, EPSILON),
360 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000361 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000362
363 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
364 GESTURES_FLING_START);
365 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
366 ASSERT_EQ(1u, args.size());
367 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
368 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
369 WithCoords(POINTER_X - 15, POINTER_Y),
370 WithGestureScrollDistance(0, 0, EPSILON),
371 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000372 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000373}
374
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000375TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000376 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
377 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000378 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000379
Harry Cuttsa546ba82023-01-13 17:21:00 +0000380 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Harry Cuttsef400b22022-12-16 21:26:24 +0000381 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
382
Harry Cuttsa546ba82023-01-13 17:21:00 +0000383 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Harry Cuttsef400b22022-12-16 21:26:24 +0000384 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
385
386 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
387 GESTURES_FLING_START);
388 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
389
390 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
391 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
392 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000393 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
Josep del Riod0746382023-07-29 13:18:25 +0000394 AllOf(WithMotionClassification(MotionClassification::NONE),
395 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000396}
397
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000398TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000399 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
400 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000401 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000402
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000403 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
404 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
405
406 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
407 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
408
409 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
410 GESTURES_FLING_START);
411 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
412
413 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
414 // need to use another gesture type, like pinch.
415 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
416 GESTURES_ZOOM_START);
417 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
418 ASSERT_FALSE(args.empty());
419 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
420}
421
422TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
423 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
424 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000425 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000426
427 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
428 /*dy=*/0);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000429 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
430
431 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
432 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
433
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000434 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
435 /*dy=*/10);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000436 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
437 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000438 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
439 WithMotionClassification(MotionClassification::NONE));
440}
441
Harry Cutts8743f182023-05-17 12:03:49 +0000442TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000443 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
444 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000445 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000446
447 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
448 /*dy=*/5);
449 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
450
451 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
452 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
453
454 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
455 // need to use another gesture type, like pinch.
456 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
457 GESTURES_ZOOM_START);
458 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
459 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000460 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
461 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000462}
463
464TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
465 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
466 // start swiping up and then start moving left or right, it'll return gesture events with only Y
467 // deltas until you lift your fingers and start swiping again. That's why each of these tests
468 // only checks movement in one dimension.
469 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
470 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000471 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000472
473 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
474 /* dy= */ 10);
475 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
476 ASSERT_EQ(4u, args.size());
477
478 // Three fake fingers should be created. We don't actually care where they are, so long as they
479 // move appropriately.
480 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
481 ASSERT_THAT(arg,
482 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000483 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(1u), WithToolType(ToolType::FINGER),
486 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000487 PointerCoords finger0Start = arg.pointerCoords[0];
488 args.pop_front();
489 arg = std::get<NotifyMotionArgs>(args.front());
490 ASSERT_THAT(arg,
491 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
492 1 << 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(2u), WithToolType(ToolType::FINGER),
496 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000497 PointerCoords finger1Start = arg.pointerCoords[1];
498 args.pop_front();
499 arg = std::get<NotifyMotionArgs>(args.front());
500 ASSERT_THAT(arg,
501 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
502 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000503 WithGestureOffset(0, 0, 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 PointerCoords finger2Start = arg.pointerCoords[2];
508 args.pop_front();
509
510 arg = std::get<NotifyMotionArgs>(args.front());
511 ASSERT_THAT(arg,
512 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000513 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000514 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000515 WithPointerCount(3u), WithToolType(ToolType::FINGER),
516 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000517 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
518 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
519 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
520 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
521 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
522 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
523
524 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
525 /* dx= */ 0, /* dy= */ 5);
526 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
527 ASSERT_EQ(1u, args.size());
528 arg = std::get<NotifyMotionArgs>(args.front());
529 ASSERT_THAT(arg,
530 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000531 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000532 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000533 WithPointerCount(3u), WithToolType(ToolType::FINGER),
534 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000535 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
536 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
537 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
538 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
539 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
540 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
541
542 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
543 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
544 ASSERT_EQ(3u, args.size());
545 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
546 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
547 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000548 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000549 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000550 WithPointerCount(3u), WithToolType(ToolType::FINGER),
551 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000552 args.pop_front();
553 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
554 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
555 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000556 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000557 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000558 WithPointerCount(2u), WithToolType(ToolType::FINGER),
559 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000560 args.pop_front();
561 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
562 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000563 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000564 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000565 WithPointerCount(1u), WithToolType(ToolType::FINGER),
566 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000567}
568
Harry Cutts94f5bd52023-01-06 18:02:18 +0000569TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
570 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
571 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
572 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000573 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000574
575 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
576 /* dy= */ 10);
577 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
578 ASSERT_EQ(4u, args.size());
579
580 // Three fake fingers should be created. We don't actually care where they are, so long as they
581 // move appropriately.
582 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
583 ASSERT_THAT(arg,
584 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000585 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000586 PointerCoords finger0Start = arg.pointerCoords[0];
587 args.pop_front();
588 arg = std::get<NotifyMotionArgs>(args.front());
589 ASSERT_THAT(arg,
590 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
591 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000592 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
593 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000594 PointerCoords finger1Start = arg.pointerCoords[1];
595 args.pop_front();
596 arg = std::get<NotifyMotionArgs>(args.front());
597 ASSERT_THAT(arg,
598 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
599 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000600 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
601 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000602 PointerCoords finger2Start = arg.pointerCoords[2];
603 args.pop_front();
604
605 arg = std::get<NotifyMotionArgs>(args.front());
606 ASSERT_THAT(arg,
607 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000608 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
609 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000610 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
611 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
612 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
613 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
614 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
615 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
616
617 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
618 /* dx= */ 0, /* dy= */ 5);
619 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
620 ASSERT_EQ(1u, args.size());
621 arg = std::get<NotifyMotionArgs>(args.front());
622 ASSERT_THAT(arg,
623 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000624 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
625 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000626 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
627 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
628 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
629 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
630 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
631 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
632
633 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
634 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
635 ASSERT_EQ(3u, args.size());
636 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
637 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
638 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000639 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
640 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000641 args.pop_front();
642 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
643 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
644 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000645 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
646 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000647 args.pop_front();
648 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
649 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000650 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000651}
652
Harry Cuttsc5748d12022-12-02 17:30:18 +0000653TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
654 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
655 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000656 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000657
658 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
659 /* dx= */ 10, /* dy= */ 0);
660 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
661 ASSERT_EQ(5u, args.size());
662
663 // Four fake fingers should be created. We don't actually care where they are, so long as they
664 // move appropriately.
665 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
666 ASSERT_THAT(arg,
667 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000668 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(1u), WithToolType(ToolType::FINGER),
671 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000672 PointerCoords finger0Start = arg.pointerCoords[0];
673 args.pop_front();
674 arg = std::get<NotifyMotionArgs>(args.front());
675 ASSERT_THAT(arg,
676 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
677 1 << 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(2u), WithToolType(ToolType::FINGER),
681 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000682 PointerCoords finger1Start = arg.pointerCoords[1];
683 args.pop_front();
684 arg = std::get<NotifyMotionArgs>(args.front());
685 ASSERT_THAT(arg,
686 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
687 2 << 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(3u), WithToolType(ToolType::FINGER),
691 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000692 PointerCoords finger2Start = arg.pointerCoords[2];
693 args.pop_front();
694 arg = std::get<NotifyMotionArgs>(args.front());
695 ASSERT_THAT(arg,
696 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
697 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000698 WithGestureOffset(0, 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 PointerCoords finger3Start = arg.pointerCoords[3];
703 args.pop_front();
704
705 arg = std::get<NotifyMotionArgs>(args.front());
706 ASSERT_THAT(arg,
707 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000708 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000709 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000710 WithPointerCount(4u), WithToolType(ToolType::FINGER),
711 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000712 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
713 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
714 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
715 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
716 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
717 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
718 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
719 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
720
721 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
722 /* dx= */ 5, /* dy= */ 0);
723 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
724 ASSERT_EQ(1u, args.size());
725 arg = std::get<NotifyMotionArgs>(args.front());
726 ASSERT_THAT(arg,
727 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000728 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000729 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000730 WithPointerCount(4u), WithToolType(ToolType::FINGER),
731 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000732 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
733 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
734 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
735 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
736 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
737 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
738 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
739 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
740
741 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
742 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
743 ASSERT_EQ(4u, args.size());
744 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
745 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
746 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000747 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000748 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000749 WithPointerCount(4u), WithToolType(ToolType::FINGER),
750 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000751 args.pop_front();
752 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
753 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
754 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000755 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000756 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000757 WithPointerCount(3u), WithToolType(ToolType::FINGER),
758 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000759 args.pop_front();
760 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
761 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
762 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000763 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000764 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000765 WithPointerCount(2u), WithToolType(ToolType::FINGER),
766 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000767 args.pop_front();
768 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
769 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000770 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000771 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000772 WithPointerCount(1u), WithToolType(ToolType::FINGER),
773 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000774}
775
Harry Cuttsb1e83552022-12-20 11:02:26 +0000776TEST_F(GestureConverterTest, Pinch_Inwards) {
777 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
778 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000779 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000780
781 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
782 GESTURES_ZOOM_START);
783 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
784 ASSERT_EQ(2u, args.size());
785 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
786 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
787 WithMotionClassification(MotionClassification::PINCH),
788 WithGesturePinchScaleFactor(1.0f, EPSILON),
789 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000790 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000791 args.pop_front();
792 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
793 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
794 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
795 WithMotionClassification(MotionClassification::PINCH),
796 WithGesturePinchScaleFactor(1.0f, EPSILON),
797 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000798 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000799
800 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
801 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
802 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
803 ASSERT_EQ(1u, args.size());
804 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
805 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
806 WithMotionClassification(MotionClassification::PINCH),
807 WithGesturePinchScaleFactor(0.8f, EPSILON),
808 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
809 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000810 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000811
812 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
813 GESTURES_ZOOM_END);
814 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
815 ASSERT_EQ(2u, args.size());
816 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
817 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
818 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
819 WithMotionClassification(MotionClassification::PINCH),
820 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000821 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000822 args.pop_front();
823 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
824 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
825 WithMotionClassification(MotionClassification::PINCH),
826 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000827 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000828}
829
830TEST_F(GestureConverterTest, Pinch_Outwards) {
831 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
832 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000833 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000834
835 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
836 GESTURES_ZOOM_START);
837 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
838 ASSERT_EQ(2u, args.size());
839 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
840 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
841 WithMotionClassification(MotionClassification::PINCH),
842 WithGesturePinchScaleFactor(1.0f, EPSILON),
843 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000844 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000845 args.pop_front();
846 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
847 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
848 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
849 WithMotionClassification(MotionClassification::PINCH),
850 WithGesturePinchScaleFactor(1.0f, EPSILON),
851 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000852 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000853
854 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
855 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
856 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
857 ASSERT_EQ(1u, args.size());
858 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
859 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
860 WithMotionClassification(MotionClassification::PINCH),
861 WithGesturePinchScaleFactor(1.2f, EPSILON),
862 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
863 WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000864 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000865
866 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
867 GESTURES_ZOOM_END);
868 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
869 ASSERT_EQ(2u, args.size());
870 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
871 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
872 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
873 WithMotionClassification(MotionClassification::PINCH),
874 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000875 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000876 args.pop_front();
877 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
878 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
879 WithMotionClassification(MotionClassification::PINCH),
880 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000881 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000882}
883
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000884TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000885 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
886 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000887 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000888
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000889 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000890 GESTURES_ZOOM_START);
891 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
892
893 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000894 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000895 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
896
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000897 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000898 GESTURES_ZOOM_END);
899 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
900
901 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
902 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
903 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000904 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
905 WithMotionClassification(MotionClassification::NONE));
906}
907
908TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
909 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
910 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000911 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000912
913 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
914 GESTURES_ZOOM_START);
915 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
916
917 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
918 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
919 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
920
921 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
922 GESTURES_ZOOM_END);
923 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
924
925 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
926 // need to use another gesture type, like scroll.
927 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
928 /*dy=*/0);
929 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture);
930 ASSERT_FALSE(args.empty());
931 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000932}
933
Harry Cuttse9b71422023-03-14 16:54:44 +0000934TEST_F(GestureConverterTest, ResetWithButtonPressed) {
935 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
936 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000937 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000938
939 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
940 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
941 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
942 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
943
944 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
945 ASSERT_EQ(3u, args.size());
946
947 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
948 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
949 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
950 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000951 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
952 WithDisplayId(ADISPLAY_ID_DEFAULT)));
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_BUTTON_RELEASE),
956 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000957 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
958 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000959 args.pop_front();
960 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
961 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000962 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
963 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000964}
965
966TEST_F(GestureConverterTest, ResetDuringScroll) {
967 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
968 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000969 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000970
971 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
972 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
973
974 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
975 ASSERT_EQ(1u, args.size());
976 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
977 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
978 WithCoords(POINTER_X, POINTER_Y - 10),
979 WithGestureScrollDistance(0, 0, EPSILON),
980 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700981 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000982 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
983 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000984}
985
986TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
987 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
988 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000989 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000990
991 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
992 /*dy=*/10);
993 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
994
995 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
996 ASSERT_EQ(3u, args.size());
997 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
998 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
999 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1000 WithGestureOffset(0, 0, EPSILON),
1001 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001002 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1003 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001004 args.pop_front();
1005 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1006 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1007 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1008 WithGestureOffset(0, 0, EPSILON),
1009 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001010 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1011 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001012 args.pop_front();
1013 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1014 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1015 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001016 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1017 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001018}
1019
1020TEST_F(GestureConverterTest, ResetDuringPinch) {
1021 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1022 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001023 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001024
1025 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1026 GESTURES_ZOOM_START);
1027 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1028
1029 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
1030 ASSERT_EQ(2u, args.size());
1031 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1032 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1033 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1034 WithMotionClassification(MotionClassification::PINCH),
1035 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +00001036 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001037 args.pop_front();
1038 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1039 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1040 WithMotionClassification(MotionClassification::PINCH),
1041 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +00001042 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001043}
1044
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001045TEST_F(GestureConverterTest, FlingTapDown) {
1046 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1047 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001048 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001049
1050 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1051 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1052 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture);
1053
1054 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1055 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1056 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001057 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1058 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001059
1060 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1061 ASSERT_TRUE(mFakePointerController->isPointerShown());
1062}
1063
Arpit Singha5ea7c12023-07-05 15:39:25 +00001064TEST_F(GestureConverterTest, Tap) {
1065 // Tap should produce button press/release events
1066 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1067 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001068 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001069
1070 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1071 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1072 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1073
1074 ASSERT_EQ(1u, args.size());
1075 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1076 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1077 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001078 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1079 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001080
1081 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1082 /* down= */ GESTURES_BUTTON_LEFT,
1083 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1084 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
1085
1086 ASSERT_EQ(5u, args.size());
1087 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1088 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1089 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001090 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1091 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001092 args.pop_front();
1093 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1094 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1095 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1096 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1097 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1098 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001099 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001100 args.pop_front();
1101 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1102 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1103 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1104 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001105 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1106 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001107 args.pop_front();
1108 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1109 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1110 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001111 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001112 args.pop_front();
1113 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1114 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1115 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001116 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1117 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001118}
1119
1120TEST_F(GestureConverterTest, Click) {
1121 // Click should produce button press/release events
1122 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1123 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001124 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001125
1126 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1127 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1128 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1129
1130 ASSERT_EQ(1u, args.size());
1131 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1132 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1133 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001134 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1135 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001136
1137 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1138 /* down= */ GESTURES_BUTTON_LEFT,
1139 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
1140 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
1141
1142 ASSERT_EQ(2u, args.size());
1143 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1144 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1145 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001146 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1147 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001148 args.pop_front();
1149 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1150 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1151 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1152 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1153 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1154 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001155 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001156
1157 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1158 /* down= */ GESTURES_BUTTON_NONE,
1159 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
1160 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
1161
1162 ASSERT_EQ(3u, args.size());
1163 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1164 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1165 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1166 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001167 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1168 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001169 args.pop_front();
1170 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1171 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1172 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001173 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001174 args.pop_front();
1175 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1176 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1177 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001178 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1179 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001180}
1181
Arpit Singh3d84add2023-10-10 19:08:29 +00001182TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
1183 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001184 // Tap should be ignored when disabled
1185 mReader->getContext()->setPreventingTouchpadTaps(true);
1186
1187 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1188 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001189 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001190
1191 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1192 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1193 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1194
1195 ASSERT_EQ(1u, args.size());
1196 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1197 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1198 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001199 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1200 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001201 args.pop_front();
1202
1203 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1204 /* down= */ GESTURES_BUTTON_LEFT,
1205 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1206 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
1207
1208 // no events should be generated
1209 ASSERT_EQ(0u, args.size());
1210
1211 // Future taps should be re-enabled
1212 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1213}
1214
Arpit Singh3d84add2023-10-10 19:08:29 +00001215TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1216 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001217 // Click should still produce button press/release events
1218 mReader->getContext()->setPreventingTouchpadTaps(true);
1219
1220 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1221 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001222 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001223
1224 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1225 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1226 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1227
1228 ASSERT_EQ(1u, args.size());
1229 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1230 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1231 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001232 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1233 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001234
1235 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1236 /* down= */ GESTURES_BUTTON_LEFT,
1237 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
1238 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
1239 ASSERT_EQ(2u, args.size());
1240
1241 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1242 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1243 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001244 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1245 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001246 args.pop_front();
1247 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1248 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1249 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1250 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1251 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1252 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001253 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001254
1255 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1256 /* down= */ GESTURES_BUTTON_NONE,
1257 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
1258 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
1259
1260 ASSERT_EQ(3u, args.size());
1261 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1262 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1263 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1264 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001265 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1266 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001267 args.pop_front();
1268 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1269 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1270 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001271 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001272 args.pop_front();
1273 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1274 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1275 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001276 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1277 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001278
1279 // Future taps should be re-enabled
1280 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1281}
1282
Arpit Singh3d84add2023-10-10 19:08:29 +00001283TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1284 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001285 // initially disable tap-to-click
1286 mReader->getContext()->setPreventingTouchpadTaps(true);
1287
1288 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1289 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001290 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001291
1292 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1293 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1294 ASSERT_EQ(1u, args.size());
1295
1296 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1297 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1298 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +00001299 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1300 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001301
1302 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
1303
1304 // Future taps should be re-enabled
1305 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1306}
1307
Byoungho Jungee6268f2023-10-30 17:27:26 +09001308class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1309protected:
1310 void SetUp() override {
1311 input_flags::enable_pointer_choreographer(true);
1312 GestureConverterTestBase::SetUp();
1313 }
1314};
1315
1316TEST_F(GestureConverterTestWithChoreographer, Move) {
1317 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1318 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1319 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1320
1321 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1322 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1323 ASSERT_EQ(1u, args.size());
1324
1325 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1326 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1327 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1328 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1329}
1330
1331TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1332 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1333 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1334 converter.setOrientation(ui::ROTATION_90);
1335 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1336
1337 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1338 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1339 ASSERT_EQ(1u, args.size());
1340
1341 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1342 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1343 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER), WithButtonState(0),
1344 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1345}
1346
1347TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1348 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1349 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1350 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1351
1352 // Press left and right buttons at once
1353 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1354 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1355 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
1356 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
1357 ASSERT_EQ(3u, args.size());
1358
1359 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1360 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1361 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1362 AMOTION_EVENT_BUTTON_SECONDARY),
1363 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1364 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1365 args.pop_front();
1366 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1367 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1368 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1369 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1370 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1371 args.pop_front();
1372 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1373 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1374 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1375 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1376 AMOTION_EVENT_BUTTON_SECONDARY),
1377 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1378 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1379
1380 // Then release the left button
1381 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1382 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1383 /* is_tap= */ false);
1384 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, leftUpGesture);
1385 ASSERT_EQ(1u, args.size());
1386
1387 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1388 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1389 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1390 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1391 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1392
1393 // Finally release the right button
1394 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1395 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1396 /* is_tap= */ false);
1397 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, rightUpGesture);
1398 ASSERT_EQ(3u, args.size());
1399
1400 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1401 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1402 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
1403 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1404 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1405 args.pop_front();
1406 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1407 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1408 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1409 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1410 args.pop_front();
1411 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1412 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1413 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1414 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1415}
1416
1417TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1418 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1419 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1420 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1421
1422 // Press the button
1423 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1424 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1425 /* is_tap= */ false);
1426 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
1427 ASSERT_EQ(2u, args.size());
1428
1429 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1430 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1431 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1432 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1433 args.pop_front();
1434 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1435 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1436 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1437 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1438 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1439
1440 // Move
1441 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1442 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1443 ASSERT_EQ(1u, args.size());
1444
1445 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1446 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1447 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1448 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1449 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1450
1451 // Release the button
1452 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1453 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1454 /* is_tap= */ false);
1455 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, upGesture);
1456 ASSERT_EQ(3u, args.size());
1457
1458 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1459 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1460 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1461 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1462 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1463 args.pop_front();
1464 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1465 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1466 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1467 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1468 args.pop_front();
1469 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1470 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1471 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1472 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1473}
1474
1475TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1476 const nsecs_t downTime = 12345;
1477 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1478 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1479 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1480
1481 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1482 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
1483 ASSERT_EQ(2u, args.size());
1484
1485 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1486 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1487 WithGestureScrollDistance(0, 0, EPSILON),
1488 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1489 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1490 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1491 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1492 args.pop_front();
1493 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1494 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -10),
1495 WithGestureScrollDistance(0, 10, EPSILON),
1496 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1497 WithToolType(ToolType::FINGER),
1498 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1499 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1500
1501 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1502 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1503 ASSERT_EQ(1u, args.size());
1504 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1505 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1506 WithGestureScrollDistance(0, 5, EPSILON),
1507 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1508 WithToolType(ToolType::FINGER),
1509 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1510 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1511
1512 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1513 GESTURES_FLING_START);
1514 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1515 ASSERT_EQ(1u, args.size());
1516 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1517 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0 - 15),
1518 WithGestureScrollDistance(0, 0, EPSILON),
1519 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1520 WithToolType(ToolType::FINGER),
1521 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1522 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1523}
1524
1525TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1526 const nsecs_t downTime = 12345;
1527 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1528 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1529 converter.setOrientation(ui::ROTATION_90);
1530 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1531
1532 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1533 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
1534 ASSERT_EQ(2u, args.size());
1535
1536 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1537 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1538 WithGestureScrollDistance(0, 0, EPSILON),
1539 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1540 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1541 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1542 args.pop_front();
1543 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1544 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-10, 0),
1545 WithGestureScrollDistance(0, 10, EPSILON),
1546 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1547 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1548
1549 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1550 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1551 ASSERT_EQ(1u, args.size());
1552 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1553 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1554 WithGestureScrollDistance(0, 5, EPSILON),
1555 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1556 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1557
1558 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1559 GESTURES_FLING_START);
1560 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1561 ASSERT_EQ(1u, args.size());
1562 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1563 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(-15, 0),
1564 WithGestureScrollDistance(0, 0, EPSILON),
1565 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1566 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1567}
1568
1569TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1570 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1571 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1572 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1573
1574 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1575 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1576
1577 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1578 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1579
1580 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1581 GESTURES_FLING_START);
1582 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1583
1584 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1585 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1586 ASSERT_EQ(1u, args.size());
1587 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1588 AllOf(WithMotionClassification(MotionClassification::NONE),
1589 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1590}
1591
1592TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1593 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1594 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1595 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1596
1597 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1598 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1599
1600 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1601 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1602
1603 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1604 GESTURES_FLING_START);
1605 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1606
1607 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1608 // need to use another gesture type, like pinch.
1609 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1610 GESTURES_ZOOM_START);
1611 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
1612 ASSERT_FALSE(args.empty());
1613 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1614}
1615
1616TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1617 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1618 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1619 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1620
1621 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1622 /*dy=*/0);
1623 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1624
1625 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1626 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1627
1628 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1629 /*dy=*/10);
1630 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1631 ASSERT_EQ(1u, args.size());
1632 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1633 WithMotionClassification(MotionClassification::NONE));
1634}
1635
1636TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1637 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1638 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1639 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1640
1641 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1642 /*dy=*/5);
1643 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1644
1645 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1646 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1647
1648 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1649 // need to use another gesture type, like pinch.
1650 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1651 GESTURES_ZOOM_START);
1652 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
1653 ASSERT_FALSE(args.empty());
1654 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1655 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1656}
1657
1658TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1659 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1660 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1661 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1662 // only checks movement in one dimension.
1663 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1664 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1665 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1666
1667 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1668 /* dy= */ 10);
1669 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1670 ASSERT_EQ(4u, args.size());
1671
1672 // Three fake fingers should be created. We don't actually care where they are, so long as they
1673 // move appropriately.
1674 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1675 ASSERT_THAT(arg,
1676 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1677 WithGestureSwipeFingerCount(3),
1678 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1679 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1680 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1681 PointerCoords finger0Start = arg.pointerCoords[0];
1682 args.pop_front();
1683 arg = std::get<NotifyMotionArgs>(args.front());
1684 ASSERT_THAT(arg,
1685 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1686 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1687 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1688 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1689 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1690 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1691 PointerCoords finger1Start = arg.pointerCoords[1];
1692 args.pop_front();
1693 arg = std::get<NotifyMotionArgs>(args.front());
1694 ASSERT_THAT(arg,
1695 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1696 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1697 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1698 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1699 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1700 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1701 PointerCoords finger2Start = arg.pointerCoords[2];
1702 args.pop_front();
1703
1704 arg = std::get<NotifyMotionArgs>(args.front());
1705 ASSERT_THAT(arg,
1706 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1707 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
1708 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1709 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1710 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1711 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1712 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1713 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1714 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
1715 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
1716 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
1717
1718 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1719 /* dx= */ 0, /* dy= */ 5);
1720 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1721 ASSERT_EQ(1u, args.size());
1722 arg = std::get<NotifyMotionArgs>(args.front());
1723 ASSERT_THAT(arg,
1724 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1725 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
1726 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1727 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1728 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1729 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1730 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1731 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1732 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
1733 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
1734 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
1735
1736 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1737 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1738 ASSERT_EQ(3u, args.size());
1739 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1740 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1741 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1742 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1743 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1744 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1745 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1746 args.pop_front();
1747 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1748 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1749 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1750 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1751 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1752 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1753 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1754 args.pop_front();
1755 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1756 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1757 WithGestureSwipeFingerCount(3),
1758 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1759 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1760 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1761}
1762
1763TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
1764 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1765 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1766 converter.setOrientation(ui::ROTATION_90);
1767 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1768
1769 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1770 /* dy= */ 10);
1771 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1772 ASSERT_EQ(4u, args.size());
1773
1774 // Three fake fingers should be created. We don't actually care where they are, so long as they
1775 // move appropriately.
1776 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1777 ASSERT_THAT(arg,
1778 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1779 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1780 PointerCoords finger0Start = arg.pointerCoords[0];
1781 args.pop_front();
1782 arg = std::get<NotifyMotionArgs>(args.front());
1783 ASSERT_THAT(arg,
1784 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1785 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1786 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
1787 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1788 PointerCoords finger1Start = arg.pointerCoords[1];
1789 args.pop_front();
1790 arg = std::get<NotifyMotionArgs>(args.front());
1791 ASSERT_THAT(arg,
1792 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1793 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1794 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
1795 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1796 PointerCoords finger2Start = arg.pointerCoords[2];
1797 args.pop_front();
1798
1799 arg = std::get<NotifyMotionArgs>(args.front());
1800 ASSERT_THAT(arg,
1801 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1802 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
1803 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1804 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
1805 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
1806 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
1807 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1808 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1809 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1810
1811 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1812 /* dx= */ 0, /* dy= */ 5);
1813 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1814 ASSERT_EQ(1u, args.size());
1815 arg = std::get<NotifyMotionArgs>(args.front());
1816 ASSERT_THAT(arg,
1817 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1818 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
1819 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1820 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
1821 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
1822 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
1823 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1824 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1825 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1826
1827 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1828 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1829 ASSERT_EQ(3u, args.size());
1830 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1831 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1832 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1833 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
1834 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1835 args.pop_front();
1836 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1837 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1838 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1839 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
1840 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1841 args.pop_front();
1842 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1843 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1844 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1845}
1846
1847TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
1848 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1849 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1850 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1851
1852 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1853 /* dx= */ 10, /* dy= */ 0);
1854 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1855 ASSERT_EQ(5u, args.size());
1856
1857 // Four fake fingers should be created. We don't actually care where they are, so long as they
1858 // move appropriately.
1859 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1860 ASSERT_THAT(arg,
1861 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1862 WithGestureSwipeFingerCount(4),
1863 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1864 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1865 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1866 PointerCoords finger0Start = arg.pointerCoords[0];
1867 args.pop_front();
1868 arg = std::get<NotifyMotionArgs>(args.front());
1869 ASSERT_THAT(arg,
1870 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1871 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1872 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1873 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1874 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1875 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1876 PointerCoords finger1Start = arg.pointerCoords[1];
1877 args.pop_front();
1878 arg = std::get<NotifyMotionArgs>(args.front());
1879 ASSERT_THAT(arg,
1880 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1881 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1882 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1883 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1884 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1885 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1886 PointerCoords finger2Start = arg.pointerCoords[2];
1887 args.pop_front();
1888 arg = std::get<NotifyMotionArgs>(args.front());
1889 ASSERT_THAT(arg,
1890 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1891 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1892 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1893 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1894 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1895 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1896 PointerCoords finger3Start = arg.pointerCoords[3];
1897 args.pop_front();
1898
1899 arg = std::get<NotifyMotionArgs>(args.front());
1900 ASSERT_THAT(arg,
1901 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1902 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
1903 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1904 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1905 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1906 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
1907 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
1908 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
1909 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
1910 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1911 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1912 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1913 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
1914
1915 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1916 /* dx= */ 5, /* dy= */ 0);
1917 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1918 ASSERT_EQ(1u, args.size());
1919 arg = std::get<NotifyMotionArgs>(args.front());
1920 ASSERT_THAT(arg,
1921 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1922 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
1923 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1924 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1925 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1926 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
1927 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
1928 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
1929 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
1930 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1931 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1932 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1933 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
1934
1935 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1936 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1937 ASSERT_EQ(4u, args.size());
1938 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1939 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1940 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1941 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1942 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1943 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1944 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1945 args.pop_front();
1946 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1947 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1948 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1949 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1950 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1951 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1952 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1953 args.pop_front();
1954 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1955 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1956 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1957 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1958 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1959 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1960 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1961 args.pop_front();
1962 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1963 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1964 WithGestureSwipeFingerCount(4),
1965 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1966 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1967 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1968}
1969
1970TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
1971 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1972 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1973 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1974
1975 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
1976 GESTURES_ZOOM_START);
1977 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1978 ASSERT_EQ(2u, args.size());
1979 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1980 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1981 WithMotionClassification(MotionClassification::PINCH),
1982 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
1983 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1984 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1985 args.pop_front();
1986 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1987 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1988 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1989 WithMotionClassification(MotionClassification::PINCH),
1990 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
1991 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1992 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1993
1994 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1995 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
1996 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
1997 ASSERT_EQ(1u, args.size());
1998 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1999 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2000 WithMotionClassification(MotionClassification::PINCH),
2001 WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, -80, 0),
2002 WithPointerCoords(1, 80, 0), WithPointerCount(2u),
2003 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2004
2005 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2006 GESTURES_ZOOM_END);
2007 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2008 ASSERT_EQ(2u, args.size());
2009 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2010 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2011 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2012 WithMotionClassification(MotionClassification::PINCH),
2013 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2014 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2015 args.pop_front();
2016 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2017 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2018 WithMotionClassification(MotionClassification::PINCH),
2019 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2020 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2021}
2022
2023TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2024 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2025 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2026 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2027
2028 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2029 GESTURES_ZOOM_START);
2030 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2031 ASSERT_EQ(2u, args.size());
2032 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2033 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2034 WithMotionClassification(MotionClassification::PINCH),
2035 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
2036 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2037 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2038 args.pop_front();
2039 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2040 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2041 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2042 WithMotionClassification(MotionClassification::PINCH),
2043 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
2044 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2045 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2046
2047 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2048 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
2049 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
2050 ASSERT_EQ(1u, args.size());
2051 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2052 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2053 WithMotionClassification(MotionClassification::PINCH),
2054 WithGesturePinchScaleFactor(1.1f, EPSILON), WithPointerCoords(0, -110, 0),
2055 WithPointerCoords(1, 110, 0), WithPointerCount(2u),
2056 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2057
2058 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2059 GESTURES_ZOOM_END);
2060 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2061 ASSERT_EQ(2u, args.size());
2062 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2063 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2064 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2065 WithMotionClassification(MotionClassification::PINCH),
2066 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2067 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2068 args.pop_front();
2069 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2070 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2071 WithMotionClassification(MotionClassification::PINCH),
2072 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2073 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2074}
2075
2076TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2077 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2078 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2079 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2080
2081 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2082 GESTURES_ZOOM_START);
2083 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2084
2085 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2086 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
2087 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
2088
2089 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2090 GESTURES_ZOOM_END);
2091 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2092
2093 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
2094 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
2095 ASSERT_EQ(1u, args.size());
2096 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2097 WithMotionClassification(MotionClassification::NONE));
2098}
2099
2100TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2101 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2102 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2103 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2104
2105 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2106 GESTURES_ZOOM_START);
2107 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2108
2109 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2110 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
2111 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
2112
2113 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2114 GESTURES_ZOOM_END);
2115 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2116
2117 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2118 // need to use another gesture type, like scroll.
2119 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2120 /*dy=*/0);
2121 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture);
2122 ASSERT_FALSE(args.empty());
2123 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2124}
2125
2126TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2127 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2128 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2129 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2130
2131 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2132 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2133 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
2134 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
2135
2136 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2137 ASSERT_EQ(3u, args.size());
2138
2139 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2140 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2141 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2142 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
2143 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2144 args.pop_front();
2145 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2146 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2147 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
2148 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2149 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2150 args.pop_front();
2151 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2152 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
2153 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2154 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2155}
2156
2157TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2158 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2159 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2160 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2161
2162 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
2163 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2164
2165 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2166 ASSERT_EQ(1u, args.size());
2167 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2168 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, -10),
2169 WithGestureScrollDistance(0, 0, EPSILON),
2170 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
2171 WithToolType(ToolType::FINGER),
2172 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2173 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2174}
2175
2176TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2177 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2178 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2179 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2180
2181 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2182 /*dy=*/10);
2183 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2184
2185 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2186 ASSERT_EQ(3u, args.size());
2187 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2188 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2189 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2190 WithGestureOffset(0, 0, EPSILON),
2191 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2192 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2193 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2194 args.pop_front();
2195 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2196 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2197 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2198 WithGestureOffset(0, 0, EPSILON),
2199 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2200 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2201 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2202 args.pop_front();
2203 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2204 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
2205 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2206 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2207 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2208}
2209
2210TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2211 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2212 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2213 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2214
2215 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2216 GESTURES_ZOOM_START);
2217 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2218
2219 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2220 ASSERT_EQ(2u, args.size());
2221 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2222 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2223 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2224 WithMotionClassification(MotionClassification::PINCH),
2225 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2226 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2227 args.pop_front();
2228 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2229 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2230 WithMotionClassification(MotionClassification::PINCH),
2231 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2232 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2233}
2234
2235TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2236 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2237 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2238 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2239
2240 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2241 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
2242 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture);
2243
2244 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2245 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2246 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2247 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2248}
2249
2250TEST_F(GestureConverterTestWithChoreographer, Tap) {
2251 // Tap should produce button press/release events
2252 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2253 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2254 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2255
2256 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2257 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2258 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2259
2260 ASSERT_EQ(1u, args.size());
2261 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2262 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2263 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2264 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2265
2266 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2267 /* down= */ GESTURES_BUTTON_LEFT,
2268 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2269 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
2270
2271 ASSERT_EQ(5u, args.size());
2272 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2273 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2274 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2275 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2276 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2277 args.pop_front();
2278 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2279 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2280 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2281 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2282 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2283 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2284 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2285 args.pop_front();
2286 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2287 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2288 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2289 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2290 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2291 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2292 args.pop_front();
2293 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2294 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2295 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2296 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2297 args.pop_front();
2298 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2299 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2300 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2301 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2302}
2303
2304TEST_F(GestureConverterTestWithChoreographer, Click) {
2305 // Click should produce button press/release events
2306 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2307 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2308 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2309
2310 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2311 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2312 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2313
2314 ASSERT_EQ(1u, args.size());
2315 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2316 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2317 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2318 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2319
2320 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2321 /* down= */ GESTURES_BUTTON_LEFT,
2322 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
2323 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
2324
2325 ASSERT_EQ(2u, args.size());
2326 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2327 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2328 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2329 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2330 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2331 args.pop_front();
2332 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2333 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2334 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2335 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2336 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2337 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2338 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2339
2340 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2341 /* down= */ GESTURES_BUTTON_NONE,
2342 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
2343 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
2344
2345 ASSERT_EQ(3u, args.size());
2346 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2347 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2348 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2349 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2350 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2351 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2352 args.pop_front();
2353 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2354 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2355 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2356 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2357 args.pop_front();
2358 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2359 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2360 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2361 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2362}
2363
2364TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
2365 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2366 // Tap should be ignored when disabled
2367 mReader->getContext()->setPreventingTouchpadTaps(true);
2368
2369 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2370 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2371 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2372
2373 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2374 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2375 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2376
2377 ASSERT_EQ(1u, args.size());
2378 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2379 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2380 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2381 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2382 args.pop_front();
2383
2384 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2385 /* down= */ GESTURES_BUTTON_LEFT,
2386 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2387 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
2388
2389 // no events should be generated
2390 ASSERT_EQ(0u, args.size());
2391
2392 // Future taps should be re-enabled
2393 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2394}
2395
2396TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2397 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2398 // Click should still produce button press/release events
2399 mReader->getContext()->setPreventingTouchpadTaps(true);
2400
2401 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2402 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2403 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2404
2405 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2406 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2407 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2408
2409 ASSERT_EQ(1u, args.size());
2410 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2411 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2412 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2413 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2414
2415 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2416 /* down= */ GESTURES_BUTTON_LEFT,
2417 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
2418 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
2419 ASSERT_EQ(2u, args.size());
2420
2421 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2422 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2423 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2424 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2425 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2426 args.pop_front();
2427 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2428 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2429 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2430 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2431 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2432 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2433 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2434
2435 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2436 /* down= */ GESTURES_BUTTON_NONE,
2437 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
2438 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
2439
2440 ASSERT_EQ(3u, args.size());
2441 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2442 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2443 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2444 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2445 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2446 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2447 args.pop_front();
2448 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2449 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2450 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2451 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2452 args.pop_front();
2453 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2454 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2455 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2456 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2457
2458 // Future taps should be re-enabled
2459 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2460}
2461
2462TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2463 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2464 // initially disable tap-to-click
2465 mReader->getContext()->setPreventingTouchpadTaps(true);
2466
2467 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2468 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2469 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2470
2471 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
2472 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
2473 ASSERT_EQ(1u, args.size());
2474
2475 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2476 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2477 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
2478 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2479
2480 // Future taps should be re-enabled
2481 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2482}
2483
Harry Cutts4fb941a2022-12-14 19:14:04 +00002484} // namespace android