blob: 0cd0d460d110675fadd3584f74df67c74ef7f413 [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 Singh33a10a62023-10-12 13:06:54 +000044const auto TOUCHPAD_PALM_REJECTION_V2 =
45 ACONFIG_FLAG(input_flags, enable_v2_touchpad_typing_palm_rejection);
Arpit Singh3d84add2023-10-10 19:08:29 +000046
47} // namespace
48
Harry Cutts4fb941a2022-12-14 19:14:04 +000049using testing::AllOf;
Harry Cutts39648ab2024-02-15 14:23:50 +000050using testing::Each;
Harry Cutts5f26e952023-11-30 18:20:27 +000051using testing::ElementsAre;
52using testing::VariantWith;
Harry Cutts4fb941a2022-12-14 19:14:04 +000053
Byoungho Jungee6268f2023-10-30 17:27:26 +090054class GestureConverterTestBase : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000055protected:
56 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000057 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000058 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000059 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000060 static constexpr float POINTER_Y = 200;
61
62 void SetUp() {
63 mFakeEventHub = std::make_unique<FakeEventHub>();
64 mFakePolicy = sp<FakeInputReaderPolicy>::make();
65 mFakeListener = std::make_unique<TestInputListener>();
66 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
67 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000068 mDevice = newDevice();
69 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
70 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000071
72 mFakePointerController = std::make_shared<FakePointerController>();
73 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
74 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
75 mFakePolicy->setPointerController(mFakePointerController);
76 }
77
Harry Cuttsc5748d12022-12-02 17:30:18 +000078 std::shared_ptr<InputDevice> newDevice() {
79 InputDeviceIdentifier identifier;
80 identifier.name = "device";
81 identifier.location = "USB1";
82 identifier.bus = 0;
83 std::shared_ptr<InputDevice> device =
84 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
85 identifier);
86 mReader->pushNextDevice(device);
87 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
88 identifier.bus);
89 mReader->loopOnce();
90 return device;
91 }
92
Harry Cutts4fb941a2022-12-14 19:14:04 +000093 std::shared_ptr<FakeEventHub> mFakeEventHub;
94 sp<FakeInputReaderPolicy> mFakePolicy;
95 std::unique_ptr<TestInputListener> mFakeListener;
96 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000097 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000098 std::shared_ptr<FakePointerController> mFakePointerController;
99};
100
Byoungho Jungee6268f2023-10-30 17:27:26 +0900101class GestureConverterTest : public GestureConverterTestBase {
102protected:
103 void SetUp() override {
104 input_flags::enable_pointer_choreographer(false);
105 GestureConverterTestBase::SetUp();
106 }
107};
108
Harry Cutts4fb941a2022-12-14 19:14:04 +0000109TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000110 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
111 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000112 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000113
114 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000115 std::list<NotifyArgs> args =
116 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000117 ASSERT_THAT(args,
118 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000119 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
120 WithCoords(POINTER_X, POINTER_Y),
121 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
122 WithDisplayId(ADISPLAY_ID_DEFAULT))),
123 VariantWith<NotifyMotionArgs>(
124 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
125 WithCoords(POINTER_X - 5, POINTER_Y + 10),
126 WithRelativeMotion(-5, 10),
127 WithToolType(ToolType::FINGER), WithButtonState(0),
128 WithPressure(0.0f),
129 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000130
Harry Cuttsb1e83552022-12-20 11:02:26 +0000131 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts379ea422023-12-21 15:31:47 +0000132
133 // The same gesture again should only repeat the HOVER_MOVE and cursor position change, not the
134 // HOVER_ENTER.
135 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
136 ASSERT_THAT(args,
137 ElementsAre(VariantWith<NotifyMotionArgs>(
138 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
139 WithCoords(POINTER_X - 10, POINTER_Y + 20),
140 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
141 WithButtonState(0), WithPressure(0.0f),
142 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
143
144 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 10, POINTER_Y + 20));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000145}
146
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000147TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000148 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
149 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000150 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000151 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000152
153 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000154 std::list<NotifyArgs> args =
155 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000156 ASSERT_THAT(args,
157 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000158 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
159 WithCoords(POINTER_X, POINTER_Y),
160 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
161 WithDisplayId(ADISPLAY_ID_DEFAULT))),
162 VariantWith<NotifyMotionArgs>(
163 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
164 WithCoords(POINTER_X + 10, POINTER_Y + 5),
165 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER),
166 WithButtonState(0), WithPressure(0.0f),
167 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000168
Harry Cuttsb1e83552022-12-20 11:02:26 +0000169 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000170}
171
Harry Cutts4fb941a2022-12-14 19:14:04 +0000172TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000173 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
174 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000175 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000176
177 // Press left and right buttons at once
178 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
179 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
180 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000181 std::list<NotifyArgs> args =
182 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000183 ASSERT_THAT(args,
184 ElementsAre(VariantWith<NotifyMotionArgs>(
185 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
186 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
187 AMOTION_EVENT_BUTTON_SECONDARY),
188 WithCoords(POINTER_X, POINTER_Y),
189 WithToolType(ToolType::FINGER),
190 WithDisplayId(ADISPLAY_ID_DEFAULT))),
191 VariantWith<NotifyMotionArgs>(
192 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
193 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
194 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
195 WithCoords(POINTER_X, POINTER_Y),
196 WithToolType(ToolType::FINGER),
197 WithDisplayId(ADISPLAY_ID_DEFAULT))),
198 VariantWith<NotifyMotionArgs>(
199 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
200 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
201 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
202 AMOTION_EVENT_BUTTON_SECONDARY),
203 WithCoords(POINTER_X, POINTER_Y),
204 WithToolType(ToolType::FINGER),
205 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000206
207 // Then release the left button
208 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
209 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
210 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000211 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000212 ASSERT_THAT(args,
213 ElementsAre(VariantWith<NotifyMotionArgs>(
214 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
215 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
216 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
217 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
218 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000219
220 // Finally release the right button
221 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
222 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
223 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000224 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000225 ASSERT_THAT(args,
226 ElementsAre(VariantWith<NotifyMotionArgs>(
227 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
228 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
229 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
230 WithToolType(ToolType::FINGER),
231 WithDisplayId(ADISPLAY_ID_DEFAULT))),
232 VariantWith<NotifyMotionArgs>(
233 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
234 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
235 WithToolType(ToolType::FINGER),
236 WithDisplayId(ADISPLAY_ID_DEFAULT))),
237 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000238 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000239 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
240 WithToolType(ToolType::FINGER),
241 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000242}
243
Harry Cutts379ea422023-12-21 15:31:47 +0000244TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) {
245 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
246 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
247 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
248
249 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
250 std::list<NotifyArgs> args =
251 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
252
253 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
254 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
255 /*is_tap=*/false);
256 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
257 ASSERT_THAT(args.front(),
258 VariantWith<NotifyMotionArgs>(
259 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
260 WithCoords(POINTER_X - 5, POINTER_Y + 10),
261 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))));
262}
263
Harry Cutts4fb941a2022-12-14 19:14:04 +0000264TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000265 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
266 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000267 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000268
269 // Press the button
270 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
271 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
272 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000273 std::list<NotifyArgs> args =
274 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000275 ASSERT_THAT(args,
276 ElementsAre(VariantWith<NotifyMotionArgs>(
277 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
278 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
279 WithCoords(POINTER_X, POINTER_Y),
280 WithToolType(ToolType::FINGER),
281 WithDisplayId(ADISPLAY_ID_DEFAULT))),
282 VariantWith<NotifyMotionArgs>(
283 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
284 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
285 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
286 WithCoords(POINTER_X, POINTER_Y),
287 WithToolType(ToolType::FINGER),
288 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000289
290 // Move
291 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000292 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000293 ASSERT_THAT(args,
294 ElementsAre(VariantWith<NotifyMotionArgs>(
295 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
296 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
297 WithToolType(ToolType::FINGER),
298 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
299 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000300
Harry Cuttsb1e83552022-12-20 11:02:26 +0000301 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000302
303 // Release the button
304 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
305 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
306 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000307 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000308 ASSERT_THAT(args,
309 ElementsAre(VariantWith<NotifyMotionArgs>(
310 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
311 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
312 WithButtonState(0),
313 WithCoords(POINTER_X - 5, POINTER_Y + 10),
314 WithToolType(ToolType::FINGER),
315 WithDisplayId(ADISPLAY_ID_DEFAULT))),
316 VariantWith<NotifyMotionArgs>(
317 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
318 WithButtonState(0),
319 WithCoords(POINTER_X - 5, POINTER_Y + 10),
320 WithToolType(ToolType::FINGER),
321 WithDisplayId(ADISPLAY_ID_DEFAULT))),
322 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000323 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000324 WithButtonState(0),
325 WithCoords(POINTER_X - 5, POINTER_Y + 10),
326 WithToolType(ToolType::FINGER),
327 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000328}
329
Harry Cuttsef400b22022-12-16 21:26:24 +0000330TEST_F(GestureConverterTest, Scroll) {
331 const nsecs_t downTime = 12345;
332 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
333 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000334 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000335
Harry Cuttsa546ba82023-01-13 17:21:00 +0000336 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000337 std::list<NotifyArgs> args =
338 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000339 ASSERT_THAT(args,
340 ElementsAre(VariantWith<NotifyMotionArgs>(
341 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
342 WithCoords(POINTER_X, POINTER_Y),
343 WithGestureScrollDistance(0, 0, EPSILON),
344 WithMotionClassification(
345 MotionClassification::TWO_FINGER_SWIPE),
346 WithToolType(ToolType::FINGER), WithDownTime(downTime),
347 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
348 WithDisplayId(ADISPLAY_ID_DEFAULT))),
349 VariantWith<NotifyMotionArgs>(
350 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
351 WithCoords(POINTER_X, POINTER_Y - 10),
352 WithGestureScrollDistance(0, 10, EPSILON),
353 WithMotionClassification(
354 MotionClassification::TWO_FINGER_SWIPE),
355 WithToolType(ToolType::FINGER),
356 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
357 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000358
Harry Cuttsa546ba82023-01-13 17:21:00 +0000359 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000360 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000361 ASSERT_THAT(args,
362 ElementsAre(VariantWith<NotifyMotionArgs>(
363 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
364 WithCoords(POINTER_X, POINTER_Y - 15),
365 WithGestureScrollDistance(0, 5, EPSILON),
366 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
367 WithToolType(ToolType::FINGER),
368 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
369 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000370
371 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
372 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000373 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000374 ASSERT_THAT(args,
375 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000376 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
377 WithCoords(POINTER_X, POINTER_Y - 15),
378 WithGestureScrollDistance(0, 0, EPSILON),
379 WithMotionClassification(
380 MotionClassification::TWO_FINGER_SWIPE),
381 WithToolType(ToolType::FINGER),
382 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
383 WithDisplayId(ADISPLAY_ID_DEFAULT))),
384 VariantWith<NotifyMotionArgs>(
385 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
386 WithCoords(POINTER_X, POINTER_Y),
387 WithMotionClassification(MotionClassification::NONE),
388 WithToolType(ToolType::FINGER),
389 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000390}
391
392TEST_F(GestureConverterTest, Scroll_Rotated) {
393 const nsecs_t downTime = 12345;
394 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
395 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
396 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000397 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000398
Harry Cuttsa546ba82023-01-13 17:21:00 +0000399 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000400 std::list<NotifyArgs> args =
401 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000402 ASSERT_THAT(args,
403 ElementsAre(VariantWith<NotifyMotionArgs>(
404 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
405 WithCoords(POINTER_X, POINTER_Y),
406 WithGestureScrollDistance(0, 0, EPSILON),
407 WithMotionClassification(
408 MotionClassification::TWO_FINGER_SWIPE),
409 WithToolType(ToolType::FINGER), WithDownTime(downTime),
410 WithDisplayId(ADISPLAY_ID_DEFAULT))),
411 VariantWith<NotifyMotionArgs>(
412 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
413 WithCoords(POINTER_X - 10, POINTER_Y),
414 WithGestureScrollDistance(0, 10, EPSILON),
415 WithMotionClassification(
416 MotionClassification::TWO_FINGER_SWIPE),
417 WithToolType(ToolType::FINGER),
418 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000419
Harry Cuttsa546ba82023-01-13 17:21:00 +0000420 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000421 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000422 ASSERT_THAT(args,
423 ElementsAre(VariantWith<NotifyMotionArgs>(
424 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
425 WithCoords(POINTER_X - 15, POINTER_Y),
426 WithGestureScrollDistance(0, 5, EPSILON),
427 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
428 WithToolType(ToolType::FINGER),
429 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000430 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
431 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000432 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000433 ASSERT_THAT(args,
434 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000435 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
436 WithCoords(POINTER_X - 15, POINTER_Y),
437 WithGestureScrollDistance(0, 0, EPSILON),
438 WithMotionClassification(
439 MotionClassification::TWO_FINGER_SWIPE),
440 WithToolType(ToolType::FINGER),
441 WithDisplayId(ADISPLAY_ID_DEFAULT))),
442 VariantWith<NotifyMotionArgs>(
443 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
444 WithCoords(POINTER_X, POINTER_Y),
445 WithMotionClassification(MotionClassification::NONE),
446 WithToolType(ToolType::FINGER),
447 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000448}
449
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000450TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000451 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
452 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000453 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000454
Harry Cuttsa546ba82023-01-13 17:21:00 +0000455 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000456 std::list<NotifyArgs> args =
457 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000458
Harry Cuttsa546ba82023-01-13 17:21:00 +0000459 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000460 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000461
462 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
463 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000464 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000465
466 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000467 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000468 ASSERT_THAT(args,
469 ElementsAre(VariantWith<NotifyMotionArgs>(
470 AllOf(WithMotionClassification(MotionClassification::NONE),
471 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000472}
473
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000474TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000475 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
476 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000477 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000478
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000479 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000480 std::list<NotifyArgs> args =
481 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000482
483 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000484 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000485
486 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
487 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000488 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000489
490 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
491 // need to use another gesture type, like pinch.
492 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
493 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000494 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000495 ASSERT_FALSE(args.empty());
496 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
497}
498
499TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
500 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
501 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000502 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000503
504 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
505 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000506 std::list<NotifyArgs> args =
507 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000508
509 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000510 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000511
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000512 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
513 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000514 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000515 ASSERT_EQ(1u, args.size());
Harry Cutts5f26e952023-11-30 18:20:27 +0000516 ASSERT_THAT(args,
517 ElementsAre(VariantWith<NotifyMotionArgs>(
518 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000519}
520
Harry Cutts8743f182023-05-17 12:03:49 +0000521TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000522 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
523 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000524 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000525
526 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
527 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000528 std::list<NotifyArgs> args =
529 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000530
531 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000532 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000533
534 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
535 // need to use another gesture type, like pinch.
536 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
537 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000538 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000539 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000540 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
541 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000542}
543
544TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
545 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
546 // start swiping up and then start moving left or right, it'll return gesture events with only Y
547 // deltas until you lift your fingers and start swiping again. That's why each of these tests
548 // only checks movement in one dimension.
549 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
550 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000551 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000552
553 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
554 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000555 std::list<NotifyArgs> args =
556 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000557 ASSERT_EQ(4u, args.size());
558
559 // Three fake fingers should be created. We don't actually care where they are, so long as they
560 // move appropriately.
561 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
562 ASSERT_THAT(arg,
563 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000564 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000565 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000566 WithPointerCount(1u), WithToolType(ToolType::FINGER),
567 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000568 PointerCoords finger0Start = arg.pointerCoords[0];
569 args.pop_front();
570 arg = std::get<NotifyMotionArgs>(args.front());
571 ASSERT_THAT(arg,
572 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
573 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000574 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000575 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000576 WithPointerCount(2u), WithToolType(ToolType::FINGER),
577 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000578 PointerCoords finger1Start = arg.pointerCoords[1];
579 args.pop_front();
580 arg = std::get<NotifyMotionArgs>(args.front());
581 ASSERT_THAT(arg,
582 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
583 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000584 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000585 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000586 WithPointerCount(3u), WithToolType(ToolType::FINGER),
587 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000588 PointerCoords finger2Start = arg.pointerCoords[2];
589 args.pop_front();
590
591 arg = std::get<NotifyMotionArgs>(args.front());
592 ASSERT_THAT(arg,
593 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000594 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000595 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000596 WithPointerCount(3u), WithToolType(ToolType::FINGER),
597 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000598 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
599 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
600 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
601 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
602 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
603 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
604
605 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
606 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000607 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000608 ASSERT_EQ(1u, args.size());
609 arg = std::get<NotifyMotionArgs>(args.front());
610 ASSERT_THAT(arg,
611 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000612 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000613 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000614 WithPointerCount(3u), WithToolType(ToolType::FINGER),
615 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000616 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
617 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
618 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
619 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
620 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
621 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
622
623 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000624 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000625 ASSERT_THAT(args,
626 ElementsAre(VariantWith<NotifyMotionArgs>(
627 AllOf(WithMotionAction(
628 AMOTION_EVENT_ACTION_POINTER_UP |
629 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
630 WithGestureOffset(0, 0, EPSILON),
631 WithGestureSwipeFingerCount(3),
632 WithMotionClassification(
633 MotionClassification::MULTI_FINGER_SWIPE),
634 WithPointerCount(3u), WithToolType(ToolType::FINGER),
635 WithDisplayId(ADISPLAY_ID_DEFAULT))),
636 VariantWith<NotifyMotionArgs>(
637 AllOf(WithMotionAction(
638 AMOTION_EVENT_ACTION_POINTER_UP |
639 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
640 WithGestureOffset(0, 0, EPSILON),
641 WithGestureSwipeFingerCount(3),
642 WithMotionClassification(
643 MotionClassification::MULTI_FINGER_SWIPE),
644 WithPointerCount(2u), WithToolType(ToolType::FINGER),
645 WithDisplayId(ADISPLAY_ID_DEFAULT))),
646 VariantWith<NotifyMotionArgs>(
647 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
648 WithGestureOffset(0, 0, EPSILON),
649 WithGestureSwipeFingerCount(3),
650 WithMotionClassification(
651 MotionClassification::MULTI_FINGER_SWIPE),
652 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000653 WithDisplayId(ADISPLAY_ID_DEFAULT))),
654 VariantWith<NotifyMotionArgs>(
655 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
656 WithCoords(POINTER_X, POINTER_Y),
657 WithMotionClassification(MotionClassification::NONE),
658 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000659 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000660}
661
Harry Cutts94f5bd52023-01-06 18:02:18 +0000662TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
663 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
664 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
665 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000666 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000667
668 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
669 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000670 std::list<NotifyArgs> args =
671 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000672 ASSERT_EQ(4u, args.size());
673
674 // Three fake fingers should be created. We don't actually care where they are, so long as they
675 // move appropriately.
676 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
677 ASSERT_THAT(arg,
678 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000679 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000680 PointerCoords finger0Start = arg.pointerCoords[0];
681 args.pop_front();
682 arg = std::get<NotifyMotionArgs>(args.front());
683 ASSERT_THAT(arg,
684 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
685 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000686 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
687 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000688 PointerCoords finger1Start = arg.pointerCoords[1];
689 args.pop_front();
690 arg = std::get<NotifyMotionArgs>(args.front());
691 ASSERT_THAT(arg,
692 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
693 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000694 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
695 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000696 PointerCoords finger2Start = arg.pointerCoords[2];
697 args.pop_front();
698
699 arg = std::get<NotifyMotionArgs>(args.front());
700 ASSERT_THAT(arg,
701 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000702 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
703 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000704 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
705 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
706 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
707 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
708 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
709 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
710
711 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
712 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000713 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000714 ASSERT_EQ(1u, args.size());
715 arg = std::get<NotifyMotionArgs>(args.front());
716 ASSERT_THAT(arg,
717 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000718 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
719 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000720 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
721 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
722 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
723 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
724 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
725 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
726
727 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000728 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000729 ASSERT_THAT(args,
730 ElementsAre(VariantWith<NotifyMotionArgs>(
731 AllOf(WithMotionAction(
732 AMOTION_EVENT_ACTION_POINTER_UP |
733 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
734 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
735 WithDisplayId(ADISPLAY_ID_DEFAULT))),
736 VariantWith<NotifyMotionArgs>(
737 AllOf(WithMotionAction(
738 AMOTION_EVENT_ACTION_POINTER_UP |
739 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
740 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
741 WithDisplayId(ADISPLAY_ID_DEFAULT))),
742 VariantWith<NotifyMotionArgs>(
743 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
744 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
Harry Cutts379ea422023-12-21 15:31:47 +0000745 WithDisplayId(ADISPLAY_ID_DEFAULT))),
746 VariantWith<NotifyMotionArgs>(
747 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000748 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000749}
750
Harry Cuttsc5748d12022-12-02 17:30:18 +0000751TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
752 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
753 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000754 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000755
756 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
757 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000758 std::list<NotifyArgs> args =
759 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000760 ASSERT_EQ(5u, args.size());
761
762 // Four fake fingers should be created. We don't actually care where they are, so long as they
763 // move appropriately.
764 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
765 ASSERT_THAT(arg,
766 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000767 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000768 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000769 WithPointerCount(1u), WithToolType(ToolType::FINGER),
770 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000771 PointerCoords finger0Start = arg.pointerCoords[0];
772 args.pop_front();
773 arg = std::get<NotifyMotionArgs>(args.front());
774 ASSERT_THAT(arg,
775 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
776 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000777 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000778 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000779 WithPointerCount(2u), WithToolType(ToolType::FINGER),
780 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000781 PointerCoords finger1Start = arg.pointerCoords[1];
782 args.pop_front();
783 arg = std::get<NotifyMotionArgs>(args.front());
784 ASSERT_THAT(arg,
785 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
786 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000787 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000788 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000789 WithPointerCount(3u), WithToolType(ToolType::FINGER),
790 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000791 PointerCoords finger2Start = arg.pointerCoords[2];
792 args.pop_front();
793 arg = std::get<NotifyMotionArgs>(args.front());
794 ASSERT_THAT(arg,
795 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
796 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000797 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000798 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000799 WithPointerCount(4u), WithToolType(ToolType::FINGER),
800 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000801 PointerCoords finger3Start = arg.pointerCoords[3];
802 args.pop_front();
803
804 arg = std::get<NotifyMotionArgs>(args.front());
805 ASSERT_THAT(arg,
806 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000807 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000808 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000809 WithPointerCount(4u), WithToolType(ToolType::FINGER),
810 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000811 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
812 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
813 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
814 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
815 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
816 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
817 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
818 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
819
820 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
821 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000822 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000823 ASSERT_EQ(1u, args.size());
824 arg = std::get<NotifyMotionArgs>(args.front());
825 ASSERT_THAT(arg,
826 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000827 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000828 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000829 WithPointerCount(4u), WithToolType(ToolType::FINGER),
830 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000831 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
832 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
833 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
834 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
835 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
836 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
837 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
838 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
839
840 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000841 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000842 ASSERT_THAT(args,
843 ElementsAre(VariantWith<NotifyMotionArgs>(
844 AllOf(WithMotionAction(
845 AMOTION_EVENT_ACTION_POINTER_UP |
846 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
847 WithGestureOffset(0, 0, EPSILON),
848 WithGestureSwipeFingerCount(4),
849 WithMotionClassification(
850 MotionClassification::MULTI_FINGER_SWIPE),
851 WithPointerCount(4u), WithToolType(ToolType::FINGER),
852 WithDisplayId(ADISPLAY_ID_DEFAULT))),
853 VariantWith<NotifyMotionArgs>(
854 AllOf(WithMotionAction(
855 AMOTION_EVENT_ACTION_POINTER_UP |
856 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
857 WithGestureOffset(0, 0, EPSILON),
858 WithGestureSwipeFingerCount(4),
859 WithMotionClassification(
860 MotionClassification::MULTI_FINGER_SWIPE),
861 WithPointerCount(3u), WithToolType(ToolType::FINGER),
862 WithDisplayId(ADISPLAY_ID_DEFAULT))),
863 VariantWith<NotifyMotionArgs>(
864 AllOf(WithMotionAction(
865 AMOTION_EVENT_ACTION_POINTER_UP |
866 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
867 WithGestureOffset(0, 0, EPSILON),
868 WithGestureSwipeFingerCount(4),
869 WithMotionClassification(
870 MotionClassification::MULTI_FINGER_SWIPE),
871 WithPointerCount(2u), WithToolType(ToolType::FINGER),
872 WithDisplayId(ADISPLAY_ID_DEFAULT))),
873 VariantWith<NotifyMotionArgs>(
874 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
875 WithGestureOffset(0, 0, EPSILON),
876 WithGestureSwipeFingerCount(4),
877 WithMotionClassification(
878 MotionClassification::MULTI_FINGER_SWIPE),
879 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000880 WithDisplayId(ADISPLAY_ID_DEFAULT))),
881 VariantWith<NotifyMotionArgs>(
882 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
883 WithCoords(POINTER_X, POINTER_Y),
884 WithMotionClassification(MotionClassification::NONE),
885 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000886 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000887}
888
Harry Cuttsb1e83552022-12-20 11:02:26 +0000889TEST_F(GestureConverterTest, Pinch_Inwards) {
890 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
891 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000892 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000893
894 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
895 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000896 std::list<NotifyArgs> args =
897 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000898 ASSERT_THAT(args,
899 ElementsAre(VariantWith<NotifyMotionArgs>(
900 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
901 WithMotionClassification(MotionClassification::PINCH),
902 WithGesturePinchScaleFactor(1.0f, EPSILON),
903 WithCoords(POINTER_X - 100, POINTER_Y),
904 WithPointerCount(1u), WithToolType(ToolType::FINGER),
905 WithDisplayId(ADISPLAY_ID_DEFAULT))),
906 VariantWith<NotifyMotionArgs>(
907 AllOf(WithMotionAction(
908 AMOTION_EVENT_ACTION_POINTER_DOWN |
909 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
910 WithMotionClassification(MotionClassification::PINCH),
911 WithGesturePinchScaleFactor(1.0f, EPSILON),
912 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
913 WithPointerCount(2u), WithToolType(ToolType::FINGER),
914 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000915
916 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
917 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000918 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000919 ASSERT_THAT(args,
920 ElementsAre(VariantWith<NotifyMotionArgs>(
921 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
922 WithMotionClassification(MotionClassification::PINCH),
923 WithGesturePinchScaleFactor(0.8f, EPSILON),
924 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
925 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
926 WithToolType(ToolType::FINGER),
927 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000928
929 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
930 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000931 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000932 ASSERT_THAT(args,
933 ElementsAre(VariantWith<NotifyMotionArgs>(
934 AllOf(WithMotionAction(
935 AMOTION_EVENT_ACTION_POINTER_UP |
936 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
937 WithMotionClassification(MotionClassification::PINCH),
938 WithGesturePinchScaleFactor(1.0f, EPSILON),
939 WithPointerCount(2u), WithToolType(ToolType::FINGER),
940 WithDisplayId(ADISPLAY_ID_DEFAULT))),
941 VariantWith<NotifyMotionArgs>(
942 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
943 WithMotionClassification(MotionClassification::PINCH),
944 WithGesturePinchScaleFactor(1.0f, EPSILON),
945 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000946 WithDisplayId(ADISPLAY_ID_DEFAULT))),
947 VariantWith<NotifyMotionArgs>(
948 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
949 WithCoords(POINTER_X, POINTER_Y),
950 WithMotionClassification(MotionClassification::NONE),
951 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000952 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000953}
954
955TEST_F(GestureConverterTest, Pinch_Outwards) {
956 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
957 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000958 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000959
960 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
961 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000962 std::list<NotifyArgs> args =
963 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000964 ASSERT_THAT(args,
965 ElementsAre(VariantWith<NotifyMotionArgs>(
966 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
967 WithMotionClassification(MotionClassification::PINCH),
968 WithGesturePinchScaleFactor(1.0f, EPSILON),
969 WithCoords(POINTER_X - 100, POINTER_Y),
970 WithPointerCount(1u), WithToolType(ToolType::FINGER),
971 WithDisplayId(ADISPLAY_ID_DEFAULT))),
972 VariantWith<NotifyMotionArgs>(
973 AllOf(WithMotionAction(
974 AMOTION_EVENT_ACTION_POINTER_DOWN |
975 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
976 WithMotionClassification(MotionClassification::PINCH),
977 WithGesturePinchScaleFactor(1.0f, EPSILON),
978 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
979 WithPointerCount(2u), WithToolType(ToolType::FINGER),
980 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000981
982 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
983 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000984 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000985 ASSERT_THAT(args,
986 ElementsAre(VariantWith<NotifyMotionArgs>(
987 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
988 WithMotionClassification(MotionClassification::PINCH),
989 WithGesturePinchScaleFactor(1.2f, EPSILON),
990 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
991 WithPointerCoords(1, POINTER_X + 120, POINTER_Y),
992 WithPointerCount(2u), WithToolType(ToolType::FINGER),
993 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000994
995 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
996 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000997 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000998 ASSERT_THAT(args,
999 ElementsAre(VariantWith<NotifyMotionArgs>(
1000 AllOf(WithMotionAction(
1001 AMOTION_EVENT_ACTION_POINTER_UP |
1002 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1003 WithMotionClassification(MotionClassification::PINCH),
1004 WithGesturePinchScaleFactor(1.0f, EPSILON),
1005 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1006 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1007 VariantWith<NotifyMotionArgs>(
1008 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1009 WithMotionClassification(MotionClassification::PINCH),
1010 WithGesturePinchScaleFactor(1.0f, EPSILON),
1011 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001012 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1013 VariantWith<NotifyMotionArgs>(
1014 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1015 WithCoords(POINTER_X, POINTER_Y),
1016 WithMotionClassification(MotionClassification::NONE),
1017 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001018 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001019}
1020
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001021TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +00001022 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1023 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001024 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001025
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001026 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001027 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001028 std::list<NotifyArgs> args =
1029 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001030
1031 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001032 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001033 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001034
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001035 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001036 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001037 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001038
1039 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001040 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001041 ASSERT_THAT(args,
1042 ElementsAre(VariantWith<NotifyMotionArgs>(
1043 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001044}
1045
1046TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
1047 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1048 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001049 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001050
1051 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1052 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001053 std::list<NotifyArgs> args =
1054 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001055
1056 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1057 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001058 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001059
1060 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1061 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001062 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001063
1064 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1065 // need to use another gesture type, like scroll.
1066 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1067 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001068 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001069 ASSERT_FALSE(args.empty());
1070 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001071}
1072
Harry Cuttse9b71422023-03-14 16:54:44 +00001073TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1074 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1075 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001076 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001077
1078 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1079 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1080 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001081 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001082
1083 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001084 ASSERT_THAT(args,
1085 ElementsAre(VariantWith<NotifyMotionArgs>(
1086 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1087 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1088 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
1089 WithCoords(POINTER_X, POINTER_Y),
1090 WithToolType(ToolType::FINGER),
1091 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1092 VariantWith<NotifyMotionArgs>(
1093 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1094 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1095 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1096 WithToolType(ToolType::FINGER),
1097 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1098 VariantWith<NotifyMotionArgs>(
1099 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1100 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1101 WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001102 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1103 VariantWith<NotifyMotionArgs>(
1104 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1105 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1106 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001107 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001108}
1109
1110TEST_F(GestureConverterTest, ResetDuringScroll) {
1111 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1112 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001113 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001114
1115 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001116 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001117
1118 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001119 ASSERT_THAT(args,
1120 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001121 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1122 WithCoords(POINTER_X, POINTER_Y - 10),
1123 WithGestureScrollDistance(0, 0, EPSILON),
1124 WithMotionClassification(
1125 MotionClassification::TWO_FINGER_SWIPE),
1126 WithToolType(ToolType::FINGER),
1127 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1128 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1129 VariantWith<NotifyMotionArgs>(
1130 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1131 WithCoords(POINTER_X, POINTER_Y),
1132 WithMotionClassification(MotionClassification::NONE),
1133 WithToolType(ToolType::FINGER),
1134 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001135}
1136
1137TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1138 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1139 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001140 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001141
1142 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1143 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001144 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001145
1146 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001147 ASSERT_THAT(args,
1148 ElementsAre(VariantWith<NotifyMotionArgs>(
1149 AllOf(WithMotionAction(
1150 AMOTION_EVENT_ACTION_POINTER_UP |
1151 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1152 WithGestureOffset(0, 0, EPSILON),
1153 WithMotionClassification(
1154 MotionClassification::MULTI_FINGER_SWIPE),
1155 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1156 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1157 VariantWith<NotifyMotionArgs>(
1158 AllOf(WithMotionAction(
1159 AMOTION_EVENT_ACTION_POINTER_UP |
1160 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1161 WithGestureOffset(0, 0, EPSILON),
1162 WithMotionClassification(
1163 MotionClassification::MULTI_FINGER_SWIPE),
1164 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1165 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1166 VariantWith<NotifyMotionArgs>(
1167 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1168 WithGestureOffset(0, 0, EPSILON),
1169 WithMotionClassification(
1170 MotionClassification::MULTI_FINGER_SWIPE),
1171 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001172 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1173 VariantWith<NotifyMotionArgs>(
1174 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1175 WithMotionClassification(MotionClassification::NONE),
1176 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001177 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001178}
1179
1180TEST_F(GestureConverterTest, ResetDuringPinch) {
1181 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1182 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001183 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001184
1185 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1186 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001187 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001188
1189 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001190 ASSERT_THAT(args,
1191 ElementsAre(VariantWith<NotifyMotionArgs>(
1192 AllOf(WithMotionAction(
1193 AMOTION_EVENT_ACTION_POINTER_UP |
1194 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1195 WithMotionClassification(MotionClassification::PINCH),
1196 WithGesturePinchScaleFactor(1.0f, EPSILON),
1197 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1198 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1199 VariantWith<NotifyMotionArgs>(
1200 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1201 WithMotionClassification(MotionClassification::PINCH),
1202 WithGesturePinchScaleFactor(1.0f, EPSILON),
1203 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001204 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1205 VariantWith<NotifyMotionArgs>(
1206 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1207 WithCoords(POINTER_X, POINTER_Y),
1208 WithMotionClassification(MotionClassification::NONE),
1209 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001210 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001211}
1212
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001213TEST_F(GestureConverterTest, FlingTapDown) {
1214 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1215 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001216 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001217
1218 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1219 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001220 std::list<NotifyArgs> args =
1221 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001222
1223 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001224 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001225 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001226 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1227 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001228
1229 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1230 ASSERT_TRUE(mFakePointerController->isPointerShown());
1231}
1232
Harry Cutts39648ab2024-02-15 14:23:50 +00001233TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1234 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1235 input_flags::enable_touchpad_fling_stop(true);
1236 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1237 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1238
1239 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1240 std::list<NotifyArgs> args =
1241 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1242 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1243 GESTURES_FLING_START);
1244 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1245
1246 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1247 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1248 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1249 ASSERT_THAT(args,
1250 ElementsAre(VariantWith<NotifyMotionArgs>(
1251 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1252 VariantWith<NotifyMotionArgs>(
1253 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1254 VariantWith<NotifyMotionArgs>(
1255 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1256 VariantWith<NotifyMotionArgs>(
1257 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1258 WithMotionClassification(MotionClassification::NONE)))));
1259 ASSERT_THAT(args,
1260 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1261 WithToolType(ToolType::FINGER),
1262 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
1263}
1264
Arpit Singha5ea7c12023-07-05 15:39:25 +00001265TEST_F(GestureConverterTest, Tap) {
1266 // Tap should produce button press/release events
1267 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1268 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001269 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001270
1271 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1272 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001273 std::list<NotifyArgs> args =
1274 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001275 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001276
1277 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1278 /* down= */ GESTURES_BUTTON_LEFT,
1279 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001280 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001281
Harry Cutts5f26e952023-11-30 18:20:27 +00001282 ASSERT_THAT(args,
1283 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001284 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1285 WithCoords(POINTER_X, POINTER_Y),
1286 WithRelativeMotion(0.f, 0.f),
1287 WithToolType(ToolType::FINGER), WithButtonState(0),
1288 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1289 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001290 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1291 WithCoords(POINTER_X, POINTER_Y),
1292 WithRelativeMotion(0.f, 0.f),
1293 WithToolType(ToolType::FINGER),
1294 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1295 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1296 VariantWith<NotifyMotionArgs>(
1297 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1298 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1299 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1300 WithCoords(POINTER_X, POINTER_Y),
1301 WithRelativeMotion(0.f, 0.f),
1302 WithToolType(ToolType::FINGER),
1303 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1304 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1305 VariantWith<NotifyMotionArgs>(
1306 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1307 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1308 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1309 WithRelativeMotion(0.f, 0.f),
1310 WithToolType(ToolType::FINGER), WithButtonState(0),
1311 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1312 VariantWith<NotifyMotionArgs>(
1313 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1314 WithCoords(POINTER_X, POINTER_Y),
1315 WithRelativeMotion(0.f, 0.f),
1316 WithToolType(ToolType::FINGER), WithButtonState(0),
1317 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1318 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001319 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001320 WithCoords(POINTER_X, POINTER_Y),
1321 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1322 WithButtonState(0), WithPressure(0.0f),
1323 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001324}
1325
1326TEST_F(GestureConverterTest, Click) {
1327 // Click should produce button press/release events
1328 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1329 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001330 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001331
1332 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1333 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001334 std::list<NotifyArgs> args =
1335 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001336 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001337
1338 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1339 /* down= */ GESTURES_BUTTON_LEFT,
1340 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001341 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001342
Harry Cutts5f26e952023-11-30 18:20:27 +00001343 ASSERT_THAT(args,
1344 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001345 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1346 WithCoords(POINTER_X, POINTER_Y),
1347 WithRelativeMotion(0.f, 0.f),
1348 WithToolType(ToolType::FINGER), WithButtonState(0),
1349 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1350 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001351 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1352 WithCoords(POINTER_X, POINTER_Y),
1353 WithRelativeMotion(0.f, 0.f),
1354 WithToolType(ToolType::FINGER),
1355 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1356 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1357 VariantWith<NotifyMotionArgs>(
1358 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1359 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1360 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1361 WithCoords(POINTER_X, POINTER_Y),
1362 WithRelativeMotion(0.f, 0.f),
1363 WithToolType(ToolType::FINGER),
1364 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1365 WithPressure(1.0f),
1366 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001367
1368 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1369 /* down= */ GESTURES_BUTTON_NONE,
1370 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001371 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001372 ASSERT_THAT(args,
1373 ElementsAre(VariantWith<NotifyMotionArgs>(
1374 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1375 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1376 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1377 WithRelativeMotion(0.f, 0.f),
1378 WithToolType(ToolType::FINGER), WithButtonState(0),
1379 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1380 VariantWith<NotifyMotionArgs>(
1381 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1382 WithCoords(POINTER_X, POINTER_Y),
1383 WithRelativeMotion(0.f, 0.f),
1384 WithToolType(ToolType::FINGER), WithButtonState(0),
1385 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1386 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001387 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001388 WithCoords(POINTER_X, POINTER_Y),
1389 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1390 WithButtonState(0), WithPressure(0.0f),
1391 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001392}
1393
Arpit Singh3d84add2023-10-10 19:08:29 +00001394TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001395 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1396 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1397 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1398
Arpit Singha5ea7c12023-07-05 15:39:25 +00001399 // Tap should be ignored when disabled
1400 mReader->getContext()->setPreventingTouchpadTaps(true);
1401
1402 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1403 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001404 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001405
Arpit Singh82b27a02023-10-16 11:02:19 +00001406 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001407 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001408 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001409 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001410 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001411
Arpit Singh82b27a02023-10-16 11:02:19 +00001412 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001413 /* down= */ GESTURES_BUTTON_LEFT,
1414 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001415 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001416
1417 // no events should be generated
1418 ASSERT_EQ(0u, args.size());
1419
1420 // Future taps should be re-enabled
1421 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1422}
1423
Arpit Singh82b27a02023-10-16 11:02:19 +00001424TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1425 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1426 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1427
1428 // Tap should be ignored when disabled
1429 mReader->getContext()->setPreventingTouchpadTaps(true);
1430
1431 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1432 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1433 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1434
1435 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1436 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1437 std::list<NotifyArgs> args =
1438 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001439 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001440
1441 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1442 /* down= */ GESTURES_BUTTON_LEFT,
1443 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1444 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1445
1446 // no events should be generated
1447 ASSERT_EQ(0u, args.size());
1448
1449 // Future taps should be re-enabled
1450 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1451
1452 // taps before the threshold should still be ignored
1453 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1454 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1455 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1456 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1457
1458 ASSERT_EQ(1u, args.size());
1459 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1460 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1461
1462 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1463 /* down= */ GESTURES_BUTTON_LEFT,
1464 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1465 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1466
1467 // no events should be generated
1468 ASSERT_EQ(0u, args.size());
1469
1470 // taps after the threshold should be recognised
1471 currentTime += 1;
1472 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1473 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1474 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1475
1476 ASSERT_EQ(1u, args.size());
1477 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1478 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1479
1480 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1481 /* down= */ GESTURES_BUTTON_LEFT,
1482 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1483 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1484
Harry Cutts379ea422023-12-21 15:31:47 +00001485 ASSERT_EQ(6u, args.size());
1486 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1487 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1488 WithRelativeMotion(0.f, 0.f), WithButtonState(0)));
1489 args.pop_front();
Arpit Singh82b27a02023-10-16 11:02:19 +00001490 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1491 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
1492 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
1493 args.pop_front();
1494 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1495 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1496 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
1497 WithRelativeMotion(0.f, 0.f)));
1498 args.pop_front();
1499 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1500 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1501 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1502 WithRelativeMotion(0.f, 0.f)));
1503 args.pop_front();
1504 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1505 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
1506 WithButtonState(0)));
1507 args.pop_front();
1508 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001509 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0),
Arpit Singh82b27a02023-10-16 11:02:19 +00001510 WithButtonState(0)));
1511}
1512
Arpit Singh3d84add2023-10-10 19:08:29 +00001513TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1514 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001515 // Click should still produce button press/release events
1516 mReader->getContext()->setPreventingTouchpadTaps(true);
1517
1518 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1519 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001520 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001521
1522 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1523 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001524 std::list<NotifyArgs> args =
1525 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001526 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001527
1528 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1529 /* down= */ GESTURES_BUTTON_LEFT,
1530 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001531 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001532 ASSERT_THAT(args,
1533 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001534 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1535 WithCoords(POINTER_X, POINTER_Y),
1536 WithRelativeMotion(0.f, 0.f),
1537 WithToolType(ToolType::FINGER), WithButtonState(0),
1538 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1539 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001540 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1541 WithCoords(POINTER_X, POINTER_Y),
1542 WithRelativeMotion(0.f, 0.f),
1543 WithToolType(ToolType::FINGER),
1544 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1545 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1546 VariantWith<NotifyMotionArgs>(
1547 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1548 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1549 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1550 WithCoords(POINTER_X, POINTER_Y),
1551 WithRelativeMotion(0.f, 0.f),
1552 WithToolType(ToolType::FINGER),
1553 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1554 WithPressure(1.0f),
1555 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001556
1557 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1558 /* down= */ GESTURES_BUTTON_NONE,
1559 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001560 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001561
Harry Cutts5f26e952023-11-30 18:20:27 +00001562 ASSERT_THAT(args,
1563 ElementsAre(VariantWith<NotifyMotionArgs>(
1564 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1565 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1566 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1567 WithRelativeMotion(0.f, 0.f),
1568 WithToolType(ToolType::FINGER), WithButtonState(0),
1569 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1570 VariantWith<NotifyMotionArgs>(
1571 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1572 WithCoords(POINTER_X, POINTER_Y),
1573 WithRelativeMotion(0.f, 0.f),
1574 WithToolType(ToolType::FINGER), WithButtonState(0),
1575 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1576 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001577 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001578 WithCoords(POINTER_X, POINTER_Y),
1579 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1580 WithButtonState(0), WithPressure(0.0f),
1581 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001582
1583 // Future taps should be re-enabled
1584 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1585}
1586
Arpit Singh3d84add2023-10-10 19:08:29 +00001587TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1588 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001589 // initially disable tap-to-click
1590 mReader->getContext()->setPreventingTouchpadTaps(true);
1591
1592 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1593 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001594 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001595
1596 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001597 std::list<NotifyArgs> args =
1598 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001599 // We don't need to check args here, since it's covered by the Move test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001600
1601 // Future taps should be re-enabled
1602 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1603}
1604
Arpit Singh33a10a62023-10-12 13:06:54 +00001605TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1606 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1607 const nsecs_t gestureStartTime = 1000;
1608 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1609 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1610 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1611
1612 // Start a move gesture at gestureStartTime
1613 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1614 std::list<NotifyArgs> args =
1615 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001616 ASSERT_THAT(args,
1617 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001618 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1619 VariantWith<NotifyMotionArgs>(
1620 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001621
1622 // Key presses with IME connection should cancel ongoing move gesture
1623 nsecs_t currentTime = gestureStartTime + 100;
1624 mFakePolicy->setIsInputMethodConnectionActive(true);
1625 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1626 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1627 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001628 ASSERT_THAT(args,
1629 ElementsAre(VariantWith<NotifyMotionArgs>(
1630 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001631
1632 // any updates in existing move gesture should be ignored
1633 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1634 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1635 ASSERT_EQ(0u, args.size());
1636
1637 // New gesture should not be affected
1638 currentTime += 100;
1639 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1640 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001641 ASSERT_THAT(args,
1642 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001643 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1644 VariantWith<NotifyMotionArgs>(
1645 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001646}
1647
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001648// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1649// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001650class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1651protected:
1652 void SetUp() override {
1653 input_flags::enable_pointer_choreographer(true);
1654 GestureConverterTestBase::SetUp();
1655 }
1656};
1657
1658TEST_F(GestureConverterTestWithChoreographer, Move) {
1659 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1660 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1661 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1662
1663 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001664 std::list<NotifyArgs> args =
1665 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001666 ASSERT_THAT(args,
1667 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001668 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1669 WithCoords(0, 0), WithRelativeMotion(0, 0),
1670 WithToolType(ToolType::FINGER),
1671 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1672 VariantWith<NotifyMotionArgs>(
1673 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1674 WithCoords(0, 0), WithRelativeMotion(-5, 10),
1675 WithToolType(ToolType::FINGER), WithButtonState(0),
1676 WithPressure(0.0f),
1677 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
1678
1679 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
1680 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1681 ASSERT_THAT(args,
1682 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001683 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1684 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1685 WithButtonState(0), WithPressure(0.0f),
1686 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001687}
1688
1689TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1690 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1691 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1692 converter.setOrientation(ui::ROTATION_90);
1693 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1694
1695 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001696 std::list<NotifyArgs> args =
1697 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001698 ASSERT_THAT(args,
1699 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001700 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1701 WithCoords(0, 0), WithRelativeMotion(0, 0),
1702 WithToolType(ToolType::FINGER),
1703 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1704 VariantWith<NotifyMotionArgs>(
1705 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1706 WithCoords(0, 0), WithRelativeMotion(10, 5),
1707 WithToolType(ToolType::FINGER), WithButtonState(0),
1708 WithPressure(0.0f),
1709 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001710}
1711
1712TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1713 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1714 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1715 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1716
1717 // Press left and right buttons at once
1718 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1719 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1720 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001721 std::list<NotifyArgs> args =
1722 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001723 ASSERT_THAT(args,
1724 ElementsAre(VariantWith<NotifyMotionArgs>(
1725 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1726 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1727 AMOTION_EVENT_BUTTON_SECONDARY),
1728 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1729 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1730 VariantWith<NotifyMotionArgs>(
1731 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1732 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1733 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1734 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1735 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1736 VariantWith<NotifyMotionArgs>(
1737 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1738 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1739 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1740 AMOTION_EVENT_BUTTON_SECONDARY),
1741 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1742 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001743
1744 // Then release the left button
1745 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1746 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1747 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001748 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001749 ASSERT_THAT(args,
1750 ElementsAre(VariantWith<NotifyMotionArgs>(
1751 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1752 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1753 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1754 WithToolType(ToolType::FINGER),
1755 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001756
1757 // Finally release the right button
1758 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1759 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1760 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001761 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001762 ASSERT_THAT(args,
1763 ElementsAre(VariantWith<NotifyMotionArgs>(
1764 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1765 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1766 WithButtonState(0), WithCoords(0, 0),
1767 WithToolType(ToolType::FINGER),
1768 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1769 VariantWith<NotifyMotionArgs>(
1770 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1771 WithButtonState(0), WithCoords(0, 0),
1772 WithToolType(ToolType::FINGER),
1773 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1774 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001775 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001776 WithButtonState(0), WithCoords(0, 0),
1777 WithToolType(ToolType::FINGER),
1778 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001779}
1780
Harry Cutts379ea422023-12-21 15:31:47 +00001781TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) {
1782 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1783 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1784 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1785
1786 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1787 std::list<NotifyArgs> args =
1788 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1789
1790 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1791 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
1792 /*is_tap=*/false);
1793 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
1794 ASSERT_THAT(args.front(),
1795 VariantWith<NotifyMotionArgs>(
1796 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
1797 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1798 WithDisplayId(ADISPLAY_ID_DEFAULT))));
1799}
1800
Byoungho Jungee6268f2023-10-30 17:27:26 +09001801TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1802 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1803 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1804 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1805
1806 // Press the button
1807 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1808 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1809 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001810 std::list<NotifyArgs> args =
1811 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001812 ASSERT_THAT(args,
1813 ElementsAre(VariantWith<NotifyMotionArgs>(
1814 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1815 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1816 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1817 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1818 VariantWith<NotifyMotionArgs>(
1819 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1820 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1821 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1822 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1823 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001824
1825 // Move
1826 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001827 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001828 ASSERT_THAT(args,
1829 ElementsAre(VariantWith<NotifyMotionArgs>(
1830 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1831 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1832 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1833 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001834
1835 // Release the button
1836 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1837 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1838 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001839 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001840 ASSERT_THAT(args,
1841 ElementsAre(VariantWith<NotifyMotionArgs>(
1842 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1843 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1844 WithButtonState(0), WithCoords(0, 0),
1845 WithToolType(ToolType::FINGER),
1846 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1847 VariantWith<NotifyMotionArgs>(
1848 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1849 WithButtonState(0), WithCoords(0, 0),
1850 WithToolType(ToolType::FINGER),
1851 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1852 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001853 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001854 WithButtonState(0), WithCoords(0, 0),
1855 WithToolType(ToolType::FINGER),
1856 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001857}
1858
1859TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1860 const nsecs_t downTime = 12345;
1861 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1862 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1863 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1864
1865 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001866 std::list<NotifyArgs> args =
1867 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001868 ASSERT_THAT(args,
1869 ElementsAre(VariantWith<NotifyMotionArgs>(
1870 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1871 WithCoords(0, 0),
1872 WithGestureScrollDistance(0, 0, EPSILON),
1873 WithMotionClassification(
1874 MotionClassification::TWO_FINGER_SWIPE),
1875 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1876 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1877 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1878 VariantWith<NotifyMotionArgs>(
1879 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1880 WithCoords(0, -10),
1881 WithGestureScrollDistance(0, 10, EPSILON),
1882 WithMotionClassification(
1883 MotionClassification::TWO_FINGER_SWIPE),
1884 WithToolType(ToolType::FINGER),
1885 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1886 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001887
1888 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001889 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001890 ASSERT_THAT(args,
1891 ElementsAre(VariantWith<NotifyMotionArgs>(
1892 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1893 WithGestureScrollDistance(0, 5, EPSILON),
1894 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1895 WithToolType(ToolType::FINGER),
1896 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1897 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001898
1899 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1900 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001901 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001902 ASSERT_THAT(args,
1903 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001904 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1905 WithCoords(0, -15),
1906 WithGestureScrollDistance(0, 0, EPSILON),
1907 WithMotionClassification(
1908 MotionClassification::TWO_FINGER_SWIPE),
1909 WithToolType(ToolType::FINGER),
1910 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1911 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1912 VariantWith<NotifyMotionArgs>(
1913 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1914 WithCoords(0, 0),
1915 WithMotionClassification(MotionClassification::NONE),
1916 WithToolType(ToolType::FINGER),
1917 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001918}
1919
1920TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1921 const nsecs_t downTime = 12345;
1922 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1923 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1924 converter.setOrientation(ui::ROTATION_90);
1925 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1926
1927 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001928 std::list<NotifyArgs> args =
1929 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001930 ASSERT_THAT(args,
1931 ElementsAre(VariantWith<NotifyMotionArgs>(
1932 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1933 WithCoords(0, 0),
1934 WithGestureScrollDistance(0, 0, EPSILON),
1935 WithMotionClassification(
1936 MotionClassification::TWO_FINGER_SWIPE),
1937 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1938 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1939 VariantWith<NotifyMotionArgs>(
1940 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1941 WithCoords(-10, 0),
1942 WithGestureScrollDistance(0, 10, EPSILON),
1943 WithMotionClassification(
1944 MotionClassification::TWO_FINGER_SWIPE),
1945 WithToolType(ToolType::FINGER),
1946 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001947
1948 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001949 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001950 ASSERT_THAT(args,
1951 ElementsAre(VariantWith<NotifyMotionArgs>(
1952 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1953 WithGestureScrollDistance(0, 5, EPSILON),
1954 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1955 WithToolType(ToolType::FINGER),
1956 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001957
1958 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1959 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001960 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001961 ASSERT_THAT(args,
1962 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001963 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1964 WithCoords(-15, 0),
1965 WithGestureScrollDistance(0, 0, EPSILON),
1966 WithMotionClassification(
1967 MotionClassification::TWO_FINGER_SWIPE),
1968 WithToolType(ToolType::FINGER),
1969 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1970 VariantWith<NotifyMotionArgs>(
1971 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1972 WithCoords(0, 0),
1973 WithMotionClassification(MotionClassification::NONE),
1974 WithToolType(ToolType::FINGER),
1975 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001976}
1977
1978TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1979 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1980 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1981 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1982
1983 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001984 std::list<NotifyArgs> args =
1985 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001986
1987 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001988 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001989
1990 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1991 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001992 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001993
1994 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001995 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001996 ASSERT_THAT(args,
1997 ElementsAre(VariantWith<NotifyMotionArgs>(
1998 AllOf(WithMotionClassification(MotionClassification::NONE),
1999 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002000}
2001
2002TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
2003 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2004 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2005 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2006
2007 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002008 std::list<NotifyArgs> args =
2009 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002010
2011 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002012 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002013
2014 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
2015 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002016 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002017
2018 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2019 // need to use another gesture type, like pinch.
2020 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2021 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002022 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002023 ASSERT_FALSE(args.empty());
2024 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
2025}
2026
2027TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
2028 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2029 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2030 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2031
2032 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2033 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002034 std::list<NotifyArgs> args =
2035 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002036
2037 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002038 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002039
2040 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
2041 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002042 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002043 ASSERT_THAT(args,
2044 ElementsAre(VariantWith<NotifyMotionArgs>(
2045 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002046}
2047
2048TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
2049 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2050 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2051 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2052
2053 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
2054 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002055 std::list<NotifyArgs> args =
2056 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002057
2058 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002059 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002060
2061 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2062 // need to use another gesture type, like pinch.
2063 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2064 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002065 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002066 ASSERT_FALSE(args.empty());
2067 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2068 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
2069}
2070
2071TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
2072 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
2073 // start swiping up and then start moving left or right, it'll return gesture events with only Y
2074 // deltas until you lift your fingers and start swiping again. That's why each of these tests
2075 // only checks movement in one dimension.
2076 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2077 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2078 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2079
2080 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2081 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002082 std::list<NotifyArgs> args =
2083 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002084 ASSERT_EQ(4u, args.size());
2085
2086 // Three fake fingers should be created. We don't actually care where they are, so long as they
2087 // move appropriately.
2088 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2089 ASSERT_THAT(arg,
2090 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2091 WithGestureSwipeFingerCount(3),
2092 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2093 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2094 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2095 PointerCoords finger0Start = arg.pointerCoords[0];
2096 args.pop_front();
2097 arg = std::get<NotifyMotionArgs>(args.front());
2098 ASSERT_THAT(arg,
2099 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2100 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2101 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
2102 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2103 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2104 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2105 PointerCoords finger1Start = arg.pointerCoords[1];
2106 args.pop_front();
2107 arg = std::get<NotifyMotionArgs>(args.front());
2108 ASSERT_THAT(arg,
2109 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2110 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2111 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
2112 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2113 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2114 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2115 PointerCoords finger2Start = arg.pointerCoords[2];
2116 args.pop_front();
2117
2118 arg = std::get<NotifyMotionArgs>(args.front());
2119 ASSERT_THAT(arg,
2120 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2121 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
2122 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2123 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2124 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2125 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2126 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2127 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2128 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
2129 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
2130 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
2131
2132 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2133 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002134 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002135 ASSERT_EQ(1u, args.size());
2136 arg = std::get<NotifyMotionArgs>(args.front());
2137 ASSERT_THAT(arg,
2138 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2139 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
2140 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2141 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2142 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2143 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2144 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2145 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2146 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
2147 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
2148 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
2149
2150 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002151 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002152 ASSERT_THAT(args,
2153 ElementsAre(VariantWith<NotifyMotionArgs>(
2154 AllOf(WithMotionAction(
2155 AMOTION_EVENT_ACTION_POINTER_UP |
2156 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2157 WithGestureOffset(0, 0, EPSILON),
2158 WithGestureSwipeFingerCount(3),
2159 WithMotionClassification(
2160 MotionClassification::MULTI_FINGER_SWIPE),
2161 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2162 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2163 VariantWith<NotifyMotionArgs>(
2164 AllOf(WithMotionAction(
2165 AMOTION_EVENT_ACTION_POINTER_UP |
2166 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2167 WithGestureOffset(0, 0, EPSILON),
2168 WithGestureSwipeFingerCount(3),
2169 WithMotionClassification(
2170 MotionClassification::MULTI_FINGER_SWIPE),
2171 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2172 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2173 VariantWith<NotifyMotionArgs>(
2174 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2175 WithGestureOffset(0, 0, EPSILON),
2176 WithGestureSwipeFingerCount(3),
2177 WithMotionClassification(
2178 MotionClassification::MULTI_FINGER_SWIPE),
2179 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002180 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2181 VariantWith<NotifyMotionArgs>(
2182 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2183 WithCoords(0, 0),
2184 WithMotionClassification(MotionClassification::NONE),
2185 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002186 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002187}
2188
2189TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
2190 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2191 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2192 converter.setOrientation(ui::ROTATION_90);
2193 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2194
2195 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2196 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002197 std::list<NotifyArgs> args =
2198 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002199 ASSERT_EQ(4u, args.size());
2200
2201 // Three fake fingers should be created. We don't actually care where they are, so long as they
2202 // move appropriately.
2203 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2204 ASSERT_THAT(arg,
2205 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2206 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2207 PointerCoords finger0Start = arg.pointerCoords[0];
2208 args.pop_front();
2209 arg = std::get<NotifyMotionArgs>(args.front());
2210 ASSERT_THAT(arg,
2211 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2212 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2213 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2214 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2215 PointerCoords finger1Start = arg.pointerCoords[1];
2216 args.pop_front();
2217 arg = std::get<NotifyMotionArgs>(args.front());
2218 ASSERT_THAT(arg,
2219 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2220 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2221 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2222 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2223 PointerCoords finger2Start = arg.pointerCoords[2];
2224 args.pop_front();
2225
2226 arg = std::get<NotifyMotionArgs>(args.front());
2227 ASSERT_THAT(arg,
2228 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2229 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
2230 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2231 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
2232 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
2233 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
2234 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2235 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2236 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2237
2238 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2239 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002240 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002241 ASSERT_EQ(1u, args.size());
2242 arg = std::get<NotifyMotionArgs>(args.front());
2243 ASSERT_THAT(arg,
2244 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2245 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
2246 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2247 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
2248 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
2249 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
2250 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2251 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2252 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2253
2254 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002255 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002256 ASSERT_THAT(args,
2257 ElementsAre(VariantWith<NotifyMotionArgs>(
2258 AllOf(WithMotionAction(
2259 AMOTION_EVENT_ACTION_POINTER_UP |
2260 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2261 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2262 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2263 VariantWith<NotifyMotionArgs>(
2264 AllOf(WithMotionAction(
2265 AMOTION_EVENT_ACTION_POINTER_UP |
2266 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2267 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2268 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2269 VariantWith<NotifyMotionArgs>(
2270 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2271 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
Harry Cutts379ea422023-12-21 15:31:47 +00002272 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2273 VariantWith<NotifyMotionArgs>(
2274 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002275 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002276}
2277
2278TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2279 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2280 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2281 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2282
2283 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2284 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002285 std::list<NotifyArgs> args =
2286 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002287 ASSERT_EQ(5u, args.size());
2288
2289 // Four fake fingers should be created. We don't actually care where they are, so long as they
2290 // move appropriately.
2291 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2292 ASSERT_THAT(arg,
2293 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2294 WithGestureSwipeFingerCount(4),
2295 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2296 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2297 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2298 PointerCoords finger0Start = arg.pointerCoords[0];
2299 args.pop_front();
2300 arg = std::get<NotifyMotionArgs>(args.front());
2301 ASSERT_THAT(arg,
2302 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2303 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2304 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2305 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2306 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2307 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2308 PointerCoords finger1Start = arg.pointerCoords[1];
2309 args.pop_front();
2310 arg = std::get<NotifyMotionArgs>(args.front());
2311 ASSERT_THAT(arg,
2312 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2313 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2314 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2315 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2316 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2317 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2318 PointerCoords finger2Start = arg.pointerCoords[2];
2319 args.pop_front();
2320 arg = std::get<NotifyMotionArgs>(args.front());
2321 ASSERT_THAT(arg,
2322 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2323 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2324 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2325 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2326 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2327 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2328 PointerCoords finger3Start = arg.pointerCoords[3];
2329 args.pop_front();
2330
2331 arg = std::get<NotifyMotionArgs>(args.front());
2332 ASSERT_THAT(arg,
2333 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2334 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
2335 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2336 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2337 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2338 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2339 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2340 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2341 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2342 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2343 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2344 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2345 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2346
2347 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2348 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002349 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002350 ASSERT_EQ(1u, args.size());
2351 arg = std::get<NotifyMotionArgs>(args.front());
2352 ASSERT_THAT(arg,
2353 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2354 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2355 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2356 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2357 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2358 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2359 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2360 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2361 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2362 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2363 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2364 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2365 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2366
2367 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002368 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002369 ASSERT_THAT(args,
2370 ElementsAre(VariantWith<NotifyMotionArgs>(
2371 AllOf(WithMotionAction(
2372 AMOTION_EVENT_ACTION_POINTER_UP |
2373 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2374 WithGestureOffset(0, 0, EPSILON),
2375 WithGestureSwipeFingerCount(4),
2376 WithMotionClassification(
2377 MotionClassification::MULTI_FINGER_SWIPE),
2378 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2379 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2380 VariantWith<NotifyMotionArgs>(
2381 AllOf(WithMotionAction(
2382 AMOTION_EVENT_ACTION_POINTER_UP |
2383 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2384 WithGestureOffset(0, 0, EPSILON),
2385 WithGestureSwipeFingerCount(4),
2386 WithMotionClassification(
2387 MotionClassification::MULTI_FINGER_SWIPE),
2388 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2389 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2390 VariantWith<NotifyMotionArgs>(
2391 AllOf(WithMotionAction(
2392 AMOTION_EVENT_ACTION_POINTER_UP |
2393 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2394 WithGestureOffset(0, 0, EPSILON),
2395 WithGestureSwipeFingerCount(4),
2396 WithMotionClassification(
2397 MotionClassification::MULTI_FINGER_SWIPE),
2398 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2399 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2400 VariantWith<NotifyMotionArgs>(
2401 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2402 WithGestureOffset(0, 0, EPSILON),
2403 WithGestureSwipeFingerCount(4),
2404 WithMotionClassification(
2405 MotionClassification::MULTI_FINGER_SWIPE),
2406 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002407 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2408 VariantWith<NotifyMotionArgs>(
2409 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2410 WithCoords(0, 0),
2411 WithMotionClassification(MotionClassification::NONE),
2412 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002413 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002414}
2415
2416TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2417 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2418 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2419 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2420
2421 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2422 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002423 std::list<NotifyArgs> args =
2424 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002425 ASSERT_THAT(args,
2426 ElementsAre(VariantWith<NotifyMotionArgs>(
2427 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2428 WithMotionClassification(MotionClassification::PINCH),
2429 WithGesturePinchScaleFactor(1.0f, EPSILON),
2430 WithCoords(-100, 0), WithPointerCount(1u),
2431 WithToolType(ToolType::FINGER),
2432 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2433 VariantWith<NotifyMotionArgs>(
2434 AllOf(WithMotionAction(
2435 AMOTION_EVENT_ACTION_POINTER_DOWN |
2436 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2437 WithMotionClassification(MotionClassification::PINCH),
2438 WithGesturePinchScaleFactor(1.0f, EPSILON),
2439 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2440 WithToolType(ToolType::FINGER),
2441 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002442
2443 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2444 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002445 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002446 ASSERT_THAT(args,
2447 ElementsAre(VariantWith<NotifyMotionArgs>(
2448 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2449 WithMotionClassification(MotionClassification::PINCH),
2450 WithGesturePinchScaleFactor(0.8f, EPSILON),
2451 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
2452 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2453 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002454
2455 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2456 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002457 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002458 ASSERT_THAT(args,
2459 ElementsAre(VariantWith<NotifyMotionArgs>(
2460 AllOf(WithMotionAction(
2461 AMOTION_EVENT_ACTION_POINTER_UP |
2462 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2463 WithMotionClassification(MotionClassification::PINCH),
2464 WithGesturePinchScaleFactor(1.0f, EPSILON),
2465 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2466 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2467 VariantWith<NotifyMotionArgs>(
2468 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2469 WithMotionClassification(MotionClassification::PINCH),
2470 WithGesturePinchScaleFactor(1.0f, EPSILON),
2471 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002472 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2473 VariantWith<NotifyMotionArgs>(
2474 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2475 WithCoords(0, 0),
2476 WithMotionClassification(MotionClassification::NONE),
2477 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002478 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002479}
2480
2481TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2482 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2483 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2484 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2485
2486 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2487 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002488 std::list<NotifyArgs> args =
2489 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002490 ASSERT_THAT(args,
2491 ElementsAre(VariantWith<NotifyMotionArgs>(
2492 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2493 WithMotionClassification(MotionClassification::PINCH),
2494 WithGesturePinchScaleFactor(1.0f, EPSILON),
2495 WithCoords(-100, 0), WithPointerCount(1u),
2496 WithToolType(ToolType::FINGER),
2497 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2498 VariantWith<NotifyMotionArgs>(
2499 AllOf(WithMotionAction(
2500 AMOTION_EVENT_ACTION_POINTER_DOWN |
2501 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2502 WithMotionClassification(MotionClassification::PINCH),
2503 WithGesturePinchScaleFactor(1.0f, EPSILON),
2504 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2505 WithToolType(ToolType::FINGER),
2506 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002507
2508 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2509 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002510 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002511 ASSERT_THAT(args,
2512 ElementsAre(VariantWith<NotifyMotionArgs>(
2513 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2514 WithMotionClassification(MotionClassification::PINCH),
2515 WithGesturePinchScaleFactor(1.1f, EPSILON),
2516 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
2517 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2518 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002519
2520 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2521 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002522 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002523 ASSERT_THAT(args,
2524 ElementsAre(VariantWith<NotifyMotionArgs>(
2525 AllOf(WithMotionAction(
2526 AMOTION_EVENT_ACTION_POINTER_UP |
2527 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2528 WithMotionClassification(MotionClassification::PINCH),
2529 WithGesturePinchScaleFactor(1.0f, EPSILON),
2530 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2531 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2532 VariantWith<NotifyMotionArgs>(
2533 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2534 WithMotionClassification(MotionClassification::PINCH),
2535 WithGesturePinchScaleFactor(1.0f, EPSILON),
2536 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002537 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2538 VariantWith<NotifyMotionArgs>(
2539 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2540 WithCoords(0, 0),
2541 WithMotionClassification(MotionClassification::NONE),
2542 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002543 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002544}
2545
2546TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2547 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2548 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2549 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2550
2551 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2552 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002553 std::list<NotifyArgs> args =
2554 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002555
2556 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2557 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002558 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002559
2560 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2561 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002562 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002563
2564 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002565 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002566 ASSERT_THAT(args,
2567 ElementsAre(VariantWith<NotifyMotionArgs>(
2568 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002569}
2570
2571TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2572 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2573 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2574 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2575
2576 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2577 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002578 std::list<NotifyArgs> args =
2579 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002580
2581 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2582 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002583 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002584
2585 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2586 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002587 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002588
2589 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2590 // need to use another gesture type, like scroll.
2591 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2592 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002593 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002594 ASSERT_FALSE(args.empty());
2595 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2596}
2597
2598TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2599 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2600 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2601 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2602
2603 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2604 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2605 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002606 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002607
2608 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002609 ASSERT_THAT(args,
2610 ElementsAre(VariantWith<NotifyMotionArgs>(
2611 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2612 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2613 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
2614 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2615 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2616 VariantWith<NotifyMotionArgs>(
2617 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2618 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
2619 WithButtonState(0), WithCoords(0, 0),
2620 WithToolType(ToolType::FINGER),
2621 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2622 VariantWith<NotifyMotionArgs>(
2623 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2624 WithButtonState(0), WithCoords(0, 0),
2625 WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002626 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2627 VariantWith<NotifyMotionArgs>(
2628 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2629 WithButtonState(0), WithCoords(0, 0),
2630 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002631 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002632}
2633
2634TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2635 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2636 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2637 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2638
2639 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002640 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002641
2642 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002643 ASSERT_THAT(args,
2644 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002645 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2646 WithCoords(0, -10),
2647 WithGestureScrollDistance(0, 0, EPSILON),
2648 WithMotionClassification(
2649 MotionClassification::TWO_FINGER_SWIPE),
2650 WithToolType(ToolType::FINGER),
2651 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2652 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2653 VariantWith<NotifyMotionArgs>(
2654 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2655 WithCoords(0, 0),
2656 WithMotionClassification(MotionClassification::NONE),
2657 WithToolType(ToolType::FINGER),
2658 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002659}
2660
2661TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2662 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2663 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2664 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2665
2666 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2667 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002668 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002669
2670 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002671 ASSERT_THAT(args,
2672 ElementsAre(VariantWith<NotifyMotionArgs>(
2673 AllOf(WithMotionAction(
2674 AMOTION_EVENT_ACTION_POINTER_UP |
2675 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2676 WithGestureOffset(0, 0, EPSILON),
2677 WithMotionClassification(
2678 MotionClassification::MULTI_FINGER_SWIPE),
2679 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2680 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2681 VariantWith<NotifyMotionArgs>(
2682 AllOf(WithMotionAction(
2683 AMOTION_EVENT_ACTION_POINTER_UP |
2684 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2685 WithGestureOffset(0, 0, EPSILON),
2686 WithMotionClassification(
2687 MotionClassification::MULTI_FINGER_SWIPE),
2688 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2689 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2690 VariantWith<NotifyMotionArgs>(
2691 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2692 WithGestureOffset(0, 0, EPSILON),
2693 WithMotionClassification(
2694 MotionClassification::MULTI_FINGER_SWIPE),
2695 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002696 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2697 VariantWith<NotifyMotionArgs>(
2698 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2699 WithMotionClassification(MotionClassification::NONE),
2700 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002701 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002702}
2703
2704TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2705 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2706 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2707 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2708
2709 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2710 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002711 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002712
2713 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002714 ASSERT_THAT(args,
2715 ElementsAre(VariantWith<NotifyMotionArgs>(
2716 AllOf(WithMotionAction(
2717 AMOTION_EVENT_ACTION_POINTER_UP |
2718 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2719 WithMotionClassification(MotionClassification::PINCH),
2720 WithGesturePinchScaleFactor(1.0f, EPSILON),
2721 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2722 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2723 VariantWith<NotifyMotionArgs>(
2724 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2725 WithMotionClassification(MotionClassification::PINCH),
2726 WithGesturePinchScaleFactor(1.0f, EPSILON),
2727 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002728 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2729 VariantWith<NotifyMotionArgs>(
2730 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2731 WithCoords(0, 0),
2732 WithMotionClassification(MotionClassification::NONE),
2733 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002734 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002735}
2736
2737TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2738 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2739 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2740 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2741
2742 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2743 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002744 std::list<NotifyArgs> args =
2745 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002746
2747 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00002748 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
Byoungho Jungee6268f2023-10-30 17:27:26 +09002749 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2750 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2751}
2752
Harry Cutts39648ab2024-02-15 14:23:50 +00002753TEST_F(GestureConverterTestWithChoreographer, FlingTapDownAfterScrollStopsFling) {
2754 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2755 input_flags::enable_touchpad_fling_stop(true);
2756 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2757 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2758
2759 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
2760 std::list<NotifyArgs> args =
2761 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
2762 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
2763 GESTURES_FLING_START);
2764 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
2765
2766 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2767 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
2768 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
2769 ASSERT_THAT(args,
2770 ElementsAre(VariantWith<NotifyMotionArgs>(
2771 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
2772 VariantWith<NotifyMotionArgs>(
2773 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
2774 VariantWith<NotifyMotionArgs>(
2775 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
2776 VariantWith<NotifyMotionArgs>(
2777 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2778 WithMotionClassification(MotionClassification::NONE)))));
2779 ASSERT_THAT(args,
2780 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2781 WithToolType(ToolType::FINGER),
2782 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
2783}
2784
Byoungho Jungee6268f2023-10-30 17:27:26 +09002785TEST_F(GestureConverterTestWithChoreographer, Tap) {
2786 // Tap should produce button press/release events
2787 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2788 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2789 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2790
2791 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2792 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002793 std::list<NotifyArgs> args =
2794 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002795 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002796
2797 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2798 /* down= */ GESTURES_BUTTON_LEFT,
2799 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002800 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002801
Harry Cutts5f26e952023-11-30 18:20:27 +00002802 ASSERT_THAT(args,
2803 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002804 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2805 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2806 WithToolType(ToolType::FINGER), WithButtonState(0),
2807 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2808 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002809 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2810 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2811 WithToolType(ToolType::FINGER),
2812 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2813 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2814 VariantWith<NotifyMotionArgs>(
2815 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2816 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2817 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2818 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2819 WithToolType(ToolType::FINGER),
2820 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2821 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2822 VariantWith<NotifyMotionArgs>(
2823 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2824 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2825 WithButtonState(0), WithCoords(0, 0),
2826 WithRelativeMotion(0.f, 0.f),
2827 WithToolType(ToolType::FINGER), WithButtonState(0),
2828 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2829 VariantWith<NotifyMotionArgs>(
2830 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2831 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2832 WithToolType(ToolType::FINGER), WithButtonState(0),
2833 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2834 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002835 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002836 WithCoords(0, 0), WithRelativeMotion(0, 0),
2837 WithToolType(ToolType::FINGER), WithButtonState(0),
2838 WithPressure(0.0f),
2839 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002840}
2841
2842TEST_F(GestureConverterTestWithChoreographer, Click) {
2843 // Click should produce button press/release events
2844 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2845 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2846 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2847
2848 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2849 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002850 std::list<NotifyArgs> args =
2851 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002852 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002853
2854 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2855 /* down= */ GESTURES_BUTTON_LEFT,
2856 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002857 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002858
Harry Cutts5f26e952023-11-30 18:20:27 +00002859 ASSERT_THAT(args,
2860 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002861 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2862 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2863 WithToolType(ToolType::FINGER), WithButtonState(0),
2864 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2865 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002866 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2867 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2868 WithToolType(ToolType::FINGER),
2869 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2870 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2871 VariantWith<NotifyMotionArgs>(
2872 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2873 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2874 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2875 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2876 WithToolType(ToolType::FINGER),
2877 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2878 WithPressure(1.0f),
2879 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002880
2881 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2882 /* down= */ GESTURES_BUTTON_NONE,
2883 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002884 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002885
Harry Cutts5f26e952023-11-30 18:20:27 +00002886 ASSERT_THAT(args,
2887 ElementsAre(VariantWith<NotifyMotionArgs>(
2888 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2889 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2890 WithButtonState(0), WithCoords(0, 0),
2891 WithRelativeMotion(0.f, 0.f),
2892 WithToolType(ToolType::FINGER), WithButtonState(0),
2893 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2894 VariantWith<NotifyMotionArgs>(
2895 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2896 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2897 WithToolType(ToolType::FINGER), WithButtonState(0),
2898 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2899 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002900 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002901 WithCoords(0, 0), WithRelativeMotion(0, 0),
2902 WithToolType(ToolType::FINGER), WithButtonState(0),
2903 WithPressure(0.0f),
2904 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002905}
2906
2907TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002908 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2909 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2910 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2911
Byoungho Jungee6268f2023-10-30 17:27:26 +09002912 // Tap should be ignored when disabled
2913 mReader->getContext()->setPreventingTouchpadTaps(true);
2914
2915 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2916 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2917 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2918
Arpit Singh82b27a02023-10-16 11:02:19 +00002919 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002920 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002921 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002922 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002923 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002924
Arpit Singh82b27a02023-10-16 11:02:19 +00002925 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002926 /* down= */ GESTURES_BUTTON_LEFT,
2927 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002928 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002929
2930 // no events should be generated
2931 ASSERT_EQ(0u, args.size());
2932
2933 // Future taps should be re-enabled
2934 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2935}
2936
Arpit Singh82b27a02023-10-16 11:02:19 +00002937TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2938 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2939 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2940
2941 // Tap should be ignored when disabled
2942 mReader->getContext()->setPreventingTouchpadTaps(true);
2943
2944 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2945 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2946 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2947
2948 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2949 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2950 std::list<NotifyArgs> args =
2951 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002952 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00002953
2954 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2955 /* down= */ GESTURES_BUTTON_LEFT,
2956 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2957 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2958
2959 // no events should be generated
2960 ASSERT_EQ(0u, args.size());
2961
2962 // Future taps should be re-enabled
2963 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2964
2965 // taps before the threshold should still be ignored
2966 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2967 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2968 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2969 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2970
2971 ASSERT_EQ(1u, args.size());
2972 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2973 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2974
2975 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2976 /* down= */ GESTURES_BUTTON_LEFT,
2977 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2978 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2979
2980 // no events should be generated
2981 ASSERT_EQ(0u, args.size());
2982
2983 // taps after the threshold should be recognised
2984 currentTime += 1;
2985 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2986 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2987 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2988
2989 ASSERT_EQ(1u, args.size());
2990 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2991 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2992
2993 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2994 /* down= */ GESTURES_BUTTON_LEFT,
2995 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2996 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2997
Harry Cutts379ea422023-12-21 15:31:47 +00002998 ASSERT_EQ(6u, args.size());
2999 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3000 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
3001 WithRelativeMotion(0.f, 0.f), WithButtonState(0)));
3002 args.pop_front();
Arpit Singh82b27a02023-10-16 11:02:19 +00003003 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3004 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
3005 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
3006 args.pop_front();
3007 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3008 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
3009 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
3010 WithRelativeMotion(0.f, 0.f)));
3011 args.pop_front();
3012 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3013 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
3014 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
3015 WithRelativeMotion(0.f, 0.f)));
3016 args.pop_front();
3017 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3018 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
3019 WithButtonState(0)));
3020 args.pop_front();
3021 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00003022 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0),
Arpit Singh82b27a02023-10-16 11:02:19 +00003023 WithButtonState(0)));
3024}
3025
Byoungho Jungee6268f2023-10-30 17:27:26 +09003026TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
3027 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
3028 // Click should still produce button press/release events
3029 mReader->getContext()->setPreventingTouchpadTaps(true);
3030
3031 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3032 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3033 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3034
3035 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
3036 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00003037 std::list<NotifyArgs> args =
3038 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00003039 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09003040
3041 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
3042 /* down= */ GESTURES_BUTTON_LEFT,
3043 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00003044 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09003045
Harry Cutts5f26e952023-11-30 18:20:27 +00003046 ASSERT_THAT(args,
3047 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003048 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
3049 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3050 WithToolType(ToolType::FINGER), WithButtonState(0),
3051 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3052 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00003053 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
3054 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3055 WithToolType(ToolType::FINGER),
3056 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
3057 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3058 VariantWith<NotifyMotionArgs>(
3059 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
3060 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
3061 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
3062 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3063 WithToolType(ToolType::FINGER),
3064 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
3065 WithPressure(1.0f),
3066 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09003067
3068 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
3069 /* down= */ GESTURES_BUTTON_NONE,
3070 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00003071 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09003072
Harry Cutts5f26e952023-11-30 18:20:27 +00003073 ASSERT_THAT(args,
3074 ElementsAre(VariantWith<NotifyMotionArgs>(
3075 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
3076 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
3077 WithButtonState(0), WithCoords(0, 0),
3078 WithRelativeMotion(0.f, 0.f),
3079 WithToolType(ToolType::FINGER), WithButtonState(0),
3080 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3081 VariantWith<NotifyMotionArgs>(
3082 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
3083 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3084 WithToolType(ToolType::FINGER), WithButtonState(0),
3085 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3086 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003087 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00003088 WithCoords(0, 0), WithRelativeMotion(0, 0),
3089 WithToolType(ToolType::FINGER), WithButtonState(0),
3090 WithPressure(0.0f),
3091 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09003092
3093 // Future taps should be re-enabled
3094 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
3095}
3096
3097TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
3098 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
3099 // initially disable tap-to-click
3100 mReader->getContext()->setPreventingTouchpadTaps(true);
3101
3102 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3103 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3104 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3105
3106 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00003107 std::list<NotifyArgs> args =
3108 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00003109 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09003110
3111 // Future taps should be re-enabled
3112 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
3113}
3114
Arpit Singh33a10a62023-10-12 13:06:54 +00003115TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
3116 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
3117 const nsecs_t gestureStartTime = 1000;
3118 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3119 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3120 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3121
3122 // Start a move gesture at gestureStartTime
3123 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
3124 std::list<NotifyArgs> args =
3125 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003126 ASSERT_THAT(args,
3127 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003128 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
3129 VariantWith<NotifyMotionArgs>(
3130 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003131
3132 // Key presses with IME connection should cancel ongoing move gesture
3133 nsecs_t currentTime = gestureStartTime + 100;
3134 mFakePolicy->setIsInputMethodConnectionActive(true);
3135 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
3136 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3137 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003138 ASSERT_THAT(args,
3139 ElementsAre(VariantWith<NotifyMotionArgs>(
3140 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003141
3142 // any updates in existing move gesture should be ignored
3143 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3144 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
3145 ASSERT_EQ(0u, args.size());
3146
3147 // New gesture should not be affected
3148 currentTime += 100;
3149 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3150 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003151 ASSERT_THAT(args,
3152 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003153 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
3154 VariantWith<NotifyMotionArgs>(
3155 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003156}
3157
Harry Cutts4fb941a2022-12-14 19:14:04 +00003158} // namespace android