blob: d2b68dd93e37e33dd855b8cb68f232c088bf4489 [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
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001308// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1309// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001310class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1311protected:
1312 void SetUp() override {
1313 input_flags::enable_pointer_choreographer(true);
1314 GestureConverterTestBase::SetUp();
1315 }
1316};
1317
1318TEST_F(GestureConverterTestWithChoreographer, Move) {
1319 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1320 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1321 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1322
1323 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1324 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1325 ASSERT_EQ(1u, args.size());
1326
1327 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1328 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1329 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1330 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1331}
1332
1333TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1334 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1335 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1336 converter.setOrientation(ui::ROTATION_90);
1337 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1338
1339 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1340 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1341 ASSERT_EQ(1u, args.size());
1342
1343 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1344 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1345 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER), WithButtonState(0),
1346 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1347}
1348
1349TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1350 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1351 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1352 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1353
1354 // Press left and right buttons at once
1355 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1356 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1357 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
1358 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
1359 ASSERT_EQ(3u, args.size());
1360
1361 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1362 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1363 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1364 AMOTION_EVENT_BUTTON_SECONDARY),
1365 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1366 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1367 args.pop_front();
1368 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1369 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1370 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1371 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1372 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1373 args.pop_front();
1374 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1375 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1376 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1377 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1378 AMOTION_EVENT_BUTTON_SECONDARY),
1379 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1380 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1381
1382 // Then release the left button
1383 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1384 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1385 /* is_tap= */ false);
1386 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, leftUpGesture);
1387 ASSERT_EQ(1u, args.size());
1388
1389 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1390 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1391 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1392 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1393 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1394
1395 // Finally release the right button
1396 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1397 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1398 /* is_tap= */ false);
1399 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, rightUpGesture);
1400 ASSERT_EQ(3u, args.size());
1401
1402 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1403 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1404 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
1405 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1406 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1407 args.pop_front();
1408 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1409 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1410 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1411 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1412 args.pop_front();
1413 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1414 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1415 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1416 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1417}
1418
1419TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1420 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1421 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1422 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1423
1424 // Press the button
1425 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1426 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1427 /* is_tap= */ false);
1428 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
1429 ASSERT_EQ(2u, args.size());
1430
1431 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1432 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1433 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1434 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1435 args.pop_front();
1436 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1437 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1438 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1439 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1440 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1441
1442 // Move
1443 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1444 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1445 ASSERT_EQ(1u, args.size());
1446
1447 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1448 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1449 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1450 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1451 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1452
1453 // Release the button
1454 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1455 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1456 /* is_tap= */ false);
1457 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, upGesture);
1458 ASSERT_EQ(3u, args.size());
1459
1460 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1461 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1462 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1463 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1464 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1465 args.pop_front();
1466 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1467 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1468 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1469 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1470 args.pop_front();
1471 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1472 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1473 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1474 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1475}
1476
1477TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1478 const nsecs_t downTime = 12345;
1479 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1480 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1481 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1482
1483 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1484 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
1485 ASSERT_EQ(2u, args.size());
1486
1487 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1488 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1489 WithGestureScrollDistance(0, 0, EPSILON),
1490 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1491 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1492 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1493 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1494 args.pop_front();
1495 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1496 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -10),
1497 WithGestureScrollDistance(0, 10, EPSILON),
1498 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1499 WithToolType(ToolType::FINGER),
1500 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1501 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1502
1503 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1504 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1505 ASSERT_EQ(1u, args.size());
1506 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1507 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1508 WithGestureScrollDistance(0, 5, EPSILON),
1509 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1510 WithToolType(ToolType::FINGER),
1511 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1512 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1513
1514 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1515 GESTURES_FLING_START);
1516 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1517 ASSERT_EQ(1u, args.size());
1518 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1519 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0 - 15),
1520 WithGestureScrollDistance(0, 0, EPSILON),
1521 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1522 WithToolType(ToolType::FINGER),
1523 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1524 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1525}
1526
1527TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1528 const nsecs_t downTime = 12345;
1529 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1530 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1531 converter.setOrientation(ui::ROTATION_90);
1532 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1533
1534 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1535 std::list<NotifyArgs> args = converter.handleGesture(downTime, READ_TIME, startGesture);
1536 ASSERT_EQ(2u, args.size());
1537
1538 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1539 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1540 WithGestureScrollDistance(0, 0, EPSILON),
1541 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1542 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1543 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1544 args.pop_front();
1545 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1546 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-10, 0),
1547 WithGestureScrollDistance(0, 10, EPSILON),
1548 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1549 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1550
1551 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1552 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1553 ASSERT_EQ(1u, args.size());
1554 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1555 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1556 WithGestureScrollDistance(0, 5, EPSILON),
1557 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1558 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1559
1560 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1561 GESTURES_FLING_START);
1562 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1563 ASSERT_EQ(1u, args.size());
1564 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1565 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(-15, 0),
1566 WithGestureScrollDistance(0, 0, EPSILON),
1567 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1568 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1569}
1570
1571TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1572 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1573 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1574 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1575
1576 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1577 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1578
1579 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1580 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1581
1582 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1583 GESTURES_FLING_START);
1584 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1585
1586 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1587 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1588 ASSERT_EQ(1u, args.size());
1589 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1590 AllOf(WithMotionClassification(MotionClassification::NONE),
1591 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1592}
1593
1594TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1595 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1596 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1597 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1598
1599 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1600 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1601
1602 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
1603 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1604
1605 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1606 GESTURES_FLING_START);
1607 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
1608
1609 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1610 // need to use another gesture type, like pinch.
1611 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1612 GESTURES_ZOOM_START);
1613 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
1614 ASSERT_FALSE(args.empty());
1615 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1616}
1617
1618TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1619 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1620 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1621 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1622
1623 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1624 /*dy=*/0);
1625 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1626
1627 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1628 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1629
1630 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1631 /*dy=*/10);
1632 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
1633 ASSERT_EQ(1u, args.size());
1634 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1635 WithMotionClassification(MotionClassification::NONE));
1636}
1637
1638TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1639 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1640 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1641 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1642
1643 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1644 /*dy=*/5);
1645 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1646
1647 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1648 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1649
1650 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1651 // need to use another gesture type, like pinch.
1652 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1653 GESTURES_ZOOM_START);
1654 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
1655 ASSERT_FALSE(args.empty());
1656 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1657 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1658}
1659
1660TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1661 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1662 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1663 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1664 // only checks movement in one dimension.
1665 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1666 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1667 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1668
1669 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1670 /* dy= */ 10);
1671 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1672 ASSERT_EQ(4u, args.size());
1673
1674 // Three fake fingers should be created. We don't actually care where they are, so long as they
1675 // move appropriately.
1676 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1677 ASSERT_THAT(arg,
1678 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1679 WithGestureSwipeFingerCount(3),
1680 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1681 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1682 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1683 PointerCoords finger0Start = arg.pointerCoords[0];
1684 args.pop_front();
1685 arg = std::get<NotifyMotionArgs>(args.front());
1686 ASSERT_THAT(arg,
1687 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1688 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1689 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1690 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1691 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1692 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1693 PointerCoords finger1Start = arg.pointerCoords[1];
1694 args.pop_front();
1695 arg = std::get<NotifyMotionArgs>(args.front());
1696 ASSERT_THAT(arg,
1697 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1698 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1699 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1700 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1701 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1702 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1703 PointerCoords finger2Start = arg.pointerCoords[2];
1704 args.pop_front();
1705
1706 arg = std::get<NotifyMotionArgs>(args.front());
1707 ASSERT_THAT(arg,
1708 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1709 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
1710 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1711 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1712 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1713 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1714 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1715 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1716 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
1717 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
1718 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
1719
1720 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1721 /* dx= */ 0, /* dy= */ 5);
1722 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1723 ASSERT_EQ(1u, args.size());
1724 arg = std::get<NotifyMotionArgs>(args.front());
1725 ASSERT_THAT(arg,
1726 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1727 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
1728 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1729 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1730 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1731 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1732 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1733 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1734 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
1735 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
1736 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
1737
1738 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1739 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1740 ASSERT_EQ(3u, args.size());
1741 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1742 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1743 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1744 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1745 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1746 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1747 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1748 args.pop_front();
1749 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1750 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1751 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1752 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1753 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1754 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1755 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1756 args.pop_front();
1757 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1758 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1759 WithGestureSwipeFingerCount(3),
1760 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1761 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1762 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1763}
1764
1765TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
1766 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1767 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1768 converter.setOrientation(ui::ROTATION_90);
1769 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1770
1771 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1772 /* dy= */ 10);
1773 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1774 ASSERT_EQ(4u, args.size());
1775
1776 // Three fake fingers should be created. We don't actually care where they are, so long as they
1777 // move appropriately.
1778 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1779 ASSERT_THAT(arg,
1780 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1781 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1782 PointerCoords finger0Start = arg.pointerCoords[0];
1783 args.pop_front();
1784 arg = std::get<NotifyMotionArgs>(args.front());
1785 ASSERT_THAT(arg,
1786 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1787 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1788 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
1789 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1790 PointerCoords finger1Start = arg.pointerCoords[1];
1791 args.pop_front();
1792 arg = std::get<NotifyMotionArgs>(args.front());
1793 ASSERT_THAT(arg,
1794 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1795 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1796 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
1797 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1798 PointerCoords finger2Start = arg.pointerCoords[2];
1799 args.pop_front();
1800
1801 arg = std::get<NotifyMotionArgs>(args.front());
1802 ASSERT_THAT(arg,
1803 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1804 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
1805 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1806 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
1807 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
1808 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
1809 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1810 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1811 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1812
1813 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1814 /* dx= */ 0, /* dy= */ 5);
1815 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1816 ASSERT_EQ(1u, args.size());
1817 arg = std::get<NotifyMotionArgs>(args.front());
1818 ASSERT_THAT(arg,
1819 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1820 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
1821 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1822 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
1823 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
1824 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
1825 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1826 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1827 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1828
1829 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1830 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1831 ASSERT_EQ(3u, args.size());
1832 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1833 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1834 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1835 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
1836 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1837 args.pop_front();
1838 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1839 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1840 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1841 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
1842 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1843 args.pop_front();
1844 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1845 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1846 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1847}
1848
1849TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
1850 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1851 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1852 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1853
1854 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1855 /* dx= */ 10, /* dy= */ 0);
1856 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1857 ASSERT_EQ(5u, args.size());
1858
1859 // Four fake fingers should be created. We don't actually care where they are, so long as they
1860 // move appropriately.
1861 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1862 ASSERT_THAT(arg,
1863 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1864 WithGestureSwipeFingerCount(4),
1865 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1866 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1867 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1868 PointerCoords finger0Start = arg.pointerCoords[0];
1869 args.pop_front();
1870 arg = std::get<NotifyMotionArgs>(args.front());
1871 ASSERT_THAT(arg,
1872 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1873 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1874 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1875 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1876 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1877 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1878 PointerCoords finger1Start = arg.pointerCoords[1];
1879 args.pop_front();
1880 arg = std::get<NotifyMotionArgs>(args.front());
1881 ASSERT_THAT(arg,
1882 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1883 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1884 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1885 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1886 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1887 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1888 PointerCoords finger2Start = arg.pointerCoords[2];
1889 args.pop_front();
1890 arg = std::get<NotifyMotionArgs>(args.front());
1891 ASSERT_THAT(arg,
1892 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1893 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1894 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1895 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1896 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1897 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1898 PointerCoords finger3Start = arg.pointerCoords[3];
1899 args.pop_front();
1900
1901 arg = std::get<NotifyMotionArgs>(args.front());
1902 ASSERT_THAT(arg,
1903 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1904 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
1905 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1906 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1907 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1908 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
1909 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
1910 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
1911 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
1912 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1913 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1914 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1915 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
1916
1917 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1918 /* dx= */ 5, /* dy= */ 0);
1919 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
1920 ASSERT_EQ(1u, args.size());
1921 arg = std::get<NotifyMotionArgs>(args.front());
1922 ASSERT_THAT(arg,
1923 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1924 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
1925 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1926 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1927 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1928 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
1929 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
1930 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
1931 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
1932 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1933 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1934 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1935 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
1936
1937 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
1938 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);
1939 ASSERT_EQ(4u, args.size());
1940 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1941 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1942 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1943 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1944 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1945 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1946 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1947 args.pop_front();
1948 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1949 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1950 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1951 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1952 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1953 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1954 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1955 args.pop_front();
1956 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1957 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1958 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1959 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1960 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1961 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1962 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1963 args.pop_front();
1964 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1965 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1966 WithGestureSwipeFingerCount(4),
1967 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1968 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1969 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1970}
1971
1972TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
1973 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1974 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1975 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1976
1977 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
1978 GESTURES_ZOOM_START);
1979 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
1980 ASSERT_EQ(2u, args.size());
1981 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1982 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1983 WithMotionClassification(MotionClassification::PINCH),
1984 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
1985 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1986 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1987 args.pop_front();
1988 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1989 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1990 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1991 WithMotionClassification(MotionClassification::PINCH),
1992 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
1993 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1994 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1995
1996 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1997 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
1998 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
1999 ASSERT_EQ(1u, args.size());
2000 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2001 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2002 WithMotionClassification(MotionClassification::PINCH),
2003 WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, -80, 0),
2004 WithPointerCoords(1, 80, 0), WithPointerCount(2u),
2005 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2006
2007 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2008 GESTURES_ZOOM_END);
2009 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2010 ASSERT_EQ(2u, args.size());
2011 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2012 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2013 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2014 WithMotionClassification(MotionClassification::PINCH),
2015 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2016 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2017 args.pop_front();
2018 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2019 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2020 WithMotionClassification(MotionClassification::PINCH),
2021 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2022 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2023}
2024
2025TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2026 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2027 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2028 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2029
2030 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2031 GESTURES_ZOOM_START);
2032 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2033 ASSERT_EQ(2u, args.size());
2034 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2035 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2036 WithMotionClassification(MotionClassification::PINCH),
2037 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
2038 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2039 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2040 args.pop_front();
2041 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2042 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2043 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2044 WithMotionClassification(MotionClassification::PINCH),
2045 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
2046 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2047 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2048
2049 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2050 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
2051 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
2052 ASSERT_EQ(1u, args.size());
2053 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2054 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2055 WithMotionClassification(MotionClassification::PINCH),
2056 WithGesturePinchScaleFactor(1.1f, EPSILON), WithPointerCoords(0, -110, 0),
2057 WithPointerCoords(1, 110, 0), WithPointerCount(2u),
2058 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2059
2060 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2061 GESTURES_ZOOM_END);
2062 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2063 ASSERT_EQ(2u, args.size());
2064 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2065 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2066 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2067 WithMotionClassification(MotionClassification::PINCH),
2068 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2069 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2070 args.pop_front();
2071 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2072 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2073 WithMotionClassification(MotionClassification::PINCH),
2074 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2075 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2076}
2077
2078TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2079 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2080 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2081 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2082
2083 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2084 GESTURES_ZOOM_START);
2085 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2086
2087 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2088 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
2089 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
2090
2091 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2092 GESTURES_ZOOM_END);
2093 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2094
2095 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
2096 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
2097 ASSERT_EQ(1u, args.size());
2098 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2099 WithMotionClassification(MotionClassification::NONE));
2100}
2101
2102TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2103 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2104 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2105 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2106
2107 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2108 GESTURES_ZOOM_START);
2109 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2110
2111 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2112 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
2113 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);
2114
2115 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2116 GESTURES_ZOOM_END);
2117 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);
2118
2119 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2120 // need to use another gesture type, like scroll.
2121 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2122 /*dy=*/0);
2123 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture);
2124 ASSERT_FALSE(args.empty());
2125 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2126}
2127
2128TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2129 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2130 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2131 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2132
2133 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2134 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2135 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
2136 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, downGesture);
2137
2138 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2139 ASSERT_EQ(3u, args.size());
2140
2141 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2142 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2143 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2144 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
2145 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2146 args.pop_front();
2147 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2148 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2149 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
2150 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2151 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2152 args.pop_front();
2153 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2154 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
2155 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2156 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2157}
2158
2159TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2160 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2161 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2162 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2163
2164 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
2165 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2166
2167 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2168 ASSERT_EQ(1u, args.size());
2169 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2170 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, -10),
2171 WithGestureScrollDistance(0, 0, EPSILON),
2172 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
2173 WithToolType(ToolType::FINGER),
2174 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2175 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2176}
2177
2178TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2179 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2180 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2181 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2182
2183 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2184 /*dy=*/10);
2185 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2186
2187 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2188 ASSERT_EQ(3u, args.size());
2189 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2190 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2191 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2192 WithGestureOffset(0, 0, EPSILON),
2193 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2194 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2195 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2196 args.pop_front();
2197 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2198 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2199 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2200 WithGestureOffset(0, 0, EPSILON),
2201 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2202 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2203 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2204 args.pop_front();
2205 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2206 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
2207 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2208 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2209 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2210}
2211
2212TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2213 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2214 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2215 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2216
2217 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2218 GESTURES_ZOOM_START);
2219 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);
2220
2221 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2222 ASSERT_EQ(2u, args.size());
2223 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2224 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2225 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2226 WithMotionClassification(MotionClassification::PINCH),
2227 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2228 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2229 args.pop_front();
2230 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2231 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2232 WithMotionClassification(MotionClassification::PINCH),
2233 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2234 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2235}
2236
2237TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2238 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2239 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2240 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2241
2242 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2243 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
2244 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapDownGesture);
2245
2246 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2247 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2248 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2249 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2250}
2251
2252TEST_F(GestureConverterTestWithChoreographer, Tap) {
2253 // Tap should produce button press/release events
2254 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2255 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2256 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2257
2258 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2259 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2260 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2261
2262 ASSERT_EQ(1u, args.size());
2263 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2264 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2265 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2266 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2267
2268 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2269 /* down= */ GESTURES_BUTTON_LEFT,
2270 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2271 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
2272
2273 ASSERT_EQ(5u, args.size());
2274 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2275 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2276 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2277 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2278 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2279 args.pop_front();
2280 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2281 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2282 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2283 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2284 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2285 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2286 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2287 args.pop_front();
2288 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2289 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2290 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2291 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2292 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2293 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2294 args.pop_front();
2295 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2296 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2297 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2298 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2299 args.pop_front();
2300 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2301 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2302 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2303 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2304}
2305
2306TEST_F(GestureConverterTestWithChoreographer, Click) {
2307 // Click should produce button press/release events
2308 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2309 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2310 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2311
2312 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2313 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2314 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2315
2316 ASSERT_EQ(1u, args.size());
2317 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2318 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2319 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2320 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2321
2322 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2323 /* down= */ GESTURES_BUTTON_LEFT,
2324 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
2325 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
2326
2327 ASSERT_EQ(2u, args.size());
2328 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2329 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2330 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2331 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2332 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2333 args.pop_front();
2334 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2335 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2336 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2337 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2338 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2339 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2340 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2341
2342 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2343 /* down= */ GESTURES_BUTTON_NONE,
2344 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
2345 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
2346
2347 ASSERT_EQ(3u, args.size());
2348 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2349 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2350 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2351 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2352 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2353 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2354 args.pop_front();
2355 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2356 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2357 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2358 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2359 args.pop_front();
2360 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2361 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2362 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2363 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2364}
2365
2366TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
2367 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2368 // Tap should be ignored when disabled
2369 mReader->getContext()->setPreventingTouchpadTaps(true);
2370
2371 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2372 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2373 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2374
2375 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2376 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2377 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2378
2379 ASSERT_EQ(1u, args.size());
2380 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2381 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2382 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2383 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2384 args.pop_front();
2385
2386 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2387 /* down= */ GESTURES_BUTTON_LEFT,
2388 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2389 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, tapGesture);
2390
2391 // no events should be generated
2392 ASSERT_EQ(0u, args.size());
2393
2394 // Future taps should be re-enabled
2395 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2396}
2397
2398TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2399 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2400 // Click should still produce button press/release events
2401 mReader->getContext()->setPreventingTouchpadTaps(true);
2402
2403 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2404 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2405 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2406
2407 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2408 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2409 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);
2410
2411 ASSERT_EQ(1u, args.size());
2412 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2413 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2414 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2415 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2416
2417 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2418 /* down= */ GESTURES_BUTTON_LEFT,
2419 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
2420 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonDownGesture);
2421 ASSERT_EQ(2u, args.size());
2422
2423 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2424 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2425 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2426 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2427 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2428 args.pop_front();
2429 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2430 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2431 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2432 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2433 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2434 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2435 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2436
2437 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2438 /* down= */ GESTURES_BUTTON_NONE,
2439 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
2440 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, buttonUpGesture);
2441
2442 ASSERT_EQ(3u, args.size());
2443 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2444 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2445 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2446 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2447 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2448 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2449 args.pop_front();
2450 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2451 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2452 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2453 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2454 args.pop_front();
2455 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2456 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2457 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2458 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2459
2460 // Future taps should be re-enabled
2461 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2462}
2463
2464TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2465 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2466 // initially disable tap-to-click
2467 mReader->getContext()->setPreventingTouchpadTaps(true);
2468
2469 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2470 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2471 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2472
2473 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
2474 std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
2475 ASSERT_EQ(1u, args.size());
2476
2477 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2478 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2479 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
2480 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2481
2482 // Future taps should be re-enabled
2483 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2484}
2485
Harry Cutts4fb941a2022-12-14 19:14:04 +00002486} // namespace android