blob: a2c46bf2077973d0818c6249042d9b20ac809571 [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
Harry Cutts3beea7d2024-02-21 15:52:35 +000072 mFakePointerController = std::make_shared<FakePointerController>(
73 /*enabled=*/!input_flags::enable_pointer_choreographer());
Harry Cutts4fb941a2022-12-14 19:14:04 +000074 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
75 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
76 mFakePolicy->setPointerController(mFakePointerController);
77 }
78
Harry Cuttsc5748d12022-12-02 17:30:18 +000079 std::shared_ptr<InputDevice> newDevice() {
80 InputDeviceIdentifier identifier;
81 identifier.name = "device";
82 identifier.location = "USB1";
83 identifier.bus = 0;
84 std::shared_ptr<InputDevice> device =
85 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
86 identifier);
87 mReader->pushNextDevice(device);
88 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
89 identifier.bus);
90 mReader->loopOnce();
91 return device;
92 }
93
Harry Cutts4fb941a2022-12-14 19:14:04 +000094 std::shared_ptr<FakeEventHub> mFakeEventHub;
95 sp<FakeInputReaderPolicy> mFakePolicy;
96 std::unique_ptr<TestInputListener> mFakeListener;
97 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000098 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000099 std::shared_ptr<FakePointerController> mFakePointerController;
100};
101
Byoungho Jungee6268f2023-10-30 17:27:26 +0900102class GestureConverterTest : public GestureConverterTestBase {
103protected:
104 void SetUp() override {
105 input_flags::enable_pointer_choreographer(false);
106 GestureConverterTestBase::SetUp();
107 }
108};
109
Harry Cutts4fb941a2022-12-14 19:14:04 +0000110TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000111 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
112 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000113 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000114
115 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000116 std::list<NotifyArgs> args =
117 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000118 ASSERT_THAT(args,
119 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000120 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
121 WithCoords(POINTER_X, POINTER_Y),
122 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
123 WithDisplayId(ADISPLAY_ID_DEFAULT))),
124 VariantWith<NotifyMotionArgs>(
125 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
126 WithCoords(POINTER_X - 5, POINTER_Y + 10),
127 WithRelativeMotion(-5, 10),
128 WithToolType(ToolType::FINGER), WithButtonState(0),
129 WithPressure(0.0f),
130 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000131
Harry Cuttsb1e83552022-12-20 11:02:26 +0000132 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts379ea422023-12-21 15:31:47 +0000133
134 // The same gesture again should only repeat the HOVER_MOVE and cursor position change, not the
135 // HOVER_ENTER.
136 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
137 ASSERT_THAT(args,
138 ElementsAre(VariantWith<NotifyMotionArgs>(
139 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
140 WithCoords(POINTER_X - 10, POINTER_Y + 20),
141 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
142 WithButtonState(0), WithPressure(0.0f),
143 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
144
145 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 10, POINTER_Y + 20));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000146}
147
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000148TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000149 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
150 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000151 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000152 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000153
154 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000155 std::list<NotifyArgs> args =
156 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000157 ASSERT_THAT(args,
158 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000159 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
160 WithCoords(POINTER_X, POINTER_Y),
161 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
162 WithDisplayId(ADISPLAY_ID_DEFAULT))),
163 VariantWith<NotifyMotionArgs>(
164 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
165 WithCoords(POINTER_X + 10, POINTER_Y + 5),
166 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER),
167 WithButtonState(0), WithPressure(0.0f),
168 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000169
Harry Cuttsb1e83552022-12-20 11:02:26 +0000170 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000171}
172
Harry Cutts4fb941a2022-12-14 19:14:04 +0000173TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000174 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
175 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000176 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000177
178 // Press left and right buttons at once
179 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
180 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
181 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000182 std::list<NotifyArgs> args =
183 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000184 ASSERT_THAT(args,
185 ElementsAre(VariantWith<NotifyMotionArgs>(
186 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
187 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
188 AMOTION_EVENT_BUTTON_SECONDARY),
189 WithCoords(POINTER_X, POINTER_Y),
190 WithToolType(ToolType::FINGER),
191 WithDisplayId(ADISPLAY_ID_DEFAULT))),
192 VariantWith<NotifyMotionArgs>(
193 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
194 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
195 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
196 WithCoords(POINTER_X, POINTER_Y),
197 WithToolType(ToolType::FINGER),
198 WithDisplayId(ADISPLAY_ID_DEFAULT))),
199 VariantWith<NotifyMotionArgs>(
200 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
201 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
202 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
203 AMOTION_EVENT_BUTTON_SECONDARY),
204 WithCoords(POINTER_X, POINTER_Y),
205 WithToolType(ToolType::FINGER),
206 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000207
208 // Then release the left button
209 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
210 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
211 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000212 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000213 ASSERT_THAT(args,
214 ElementsAre(VariantWith<NotifyMotionArgs>(
215 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
216 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
217 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
218 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
219 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000220
221 // Finally release the right button
222 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
223 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
224 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000225 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000226 ASSERT_THAT(args,
227 ElementsAre(VariantWith<NotifyMotionArgs>(
228 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
229 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
230 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
231 WithToolType(ToolType::FINGER),
232 WithDisplayId(ADISPLAY_ID_DEFAULT))),
233 VariantWith<NotifyMotionArgs>(
234 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
235 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
236 WithToolType(ToolType::FINGER),
237 WithDisplayId(ADISPLAY_ID_DEFAULT))),
238 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000239 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000240 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
241 WithToolType(ToolType::FINGER),
242 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000243}
244
Harry Cutts379ea422023-12-21 15:31:47 +0000245TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) {
246 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
247 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
248 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
249
250 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
251 std::list<NotifyArgs> args =
252 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
253
254 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
255 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
256 /*is_tap=*/false);
257 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
258 ASSERT_THAT(args.front(),
259 VariantWith<NotifyMotionArgs>(
260 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
261 WithCoords(POINTER_X - 5, POINTER_Y + 10),
262 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))));
263}
264
Harry Cutts4fb941a2022-12-14 19:14:04 +0000265TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000266 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
267 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000268 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000269
270 // Press the button
271 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
272 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
273 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000274 std::list<NotifyArgs> args =
275 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000276 ASSERT_THAT(args,
277 ElementsAre(VariantWith<NotifyMotionArgs>(
278 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
279 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
280 WithCoords(POINTER_X, POINTER_Y),
281 WithToolType(ToolType::FINGER),
282 WithDisplayId(ADISPLAY_ID_DEFAULT))),
283 VariantWith<NotifyMotionArgs>(
284 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
285 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
286 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
287 WithCoords(POINTER_X, POINTER_Y),
288 WithToolType(ToolType::FINGER),
289 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000290
291 // Move
292 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000293 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000294 ASSERT_THAT(args,
295 ElementsAre(VariantWith<NotifyMotionArgs>(
296 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
297 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
298 WithToolType(ToolType::FINGER),
299 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
300 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000301
Harry Cuttsb1e83552022-12-20 11:02:26 +0000302 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000303
304 // Release the button
305 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
306 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
307 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000308 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000309 ASSERT_THAT(args,
310 ElementsAre(VariantWith<NotifyMotionArgs>(
311 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
312 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
313 WithButtonState(0),
314 WithCoords(POINTER_X - 5, POINTER_Y + 10),
315 WithToolType(ToolType::FINGER),
316 WithDisplayId(ADISPLAY_ID_DEFAULT))),
317 VariantWith<NotifyMotionArgs>(
318 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
319 WithButtonState(0),
320 WithCoords(POINTER_X - 5, POINTER_Y + 10),
321 WithToolType(ToolType::FINGER),
322 WithDisplayId(ADISPLAY_ID_DEFAULT))),
323 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000324 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000325 WithButtonState(0),
326 WithCoords(POINTER_X - 5, POINTER_Y + 10),
327 WithToolType(ToolType::FINGER),
328 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000329}
330
Harry Cuttsef400b22022-12-16 21:26:24 +0000331TEST_F(GestureConverterTest, Scroll) {
332 const nsecs_t downTime = 12345;
333 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
334 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000335 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000336
Harry Cuttsa546ba82023-01-13 17:21:00 +0000337 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000338 std::list<NotifyArgs> args =
339 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000340 ASSERT_THAT(args,
341 ElementsAre(VariantWith<NotifyMotionArgs>(
342 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
343 WithCoords(POINTER_X, POINTER_Y),
344 WithGestureScrollDistance(0, 0, EPSILON),
345 WithMotionClassification(
346 MotionClassification::TWO_FINGER_SWIPE),
347 WithToolType(ToolType::FINGER), WithDownTime(downTime),
348 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
349 WithDisplayId(ADISPLAY_ID_DEFAULT))),
350 VariantWith<NotifyMotionArgs>(
351 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
352 WithCoords(POINTER_X, POINTER_Y - 10),
353 WithGestureScrollDistance(0, 10, EPSILON),
354 WithMotionClassification(
355 MotionClassification::TWO_FINGER_SWIPE),
356 WithToolType(ToolType::FINGER),
357 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
358 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000359
Harry Cuttsa546ba82023-01-13 17:21:00 +0000360 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000361 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000362 ASSERT_THAT(args,
363 ElementsAre(VariantWith<NotifyMotionArgs>(
364 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
365 WithCoords(POINTER_X, POINTER_Y - 15),
366 WithGestureScrollDistance(0, 5, EPSILON),
367 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
368 WithToolType(ToolType::FINGER),
369 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
370 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000371
372 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
373 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000374 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000375 ASSERT_THAT(args,
376 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000377 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
378 WithCoords(POINTER_X, POINTER_Y - 15),
379 WithGestureScrollDistance(0, 0, EPSILON),
380 WithMotionClassification(
381 MotionClassification::TWO_FINGER_SWIPE),
382 WithToolType(ToolType::FINGER),
383 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
384 WithDisplayId(ADISPLAY_ID_DEFAULT))),
385 VariantWith<NotifyMotionArgs>(
386 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
387 WithCoords(POINTER_X, POINTER_Y),
388 WithMotionClassification(MotionClassification::NONE),
389 WithToolType(ToolType::FINGER),
390 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000391}
392
393TEST_F(GestureConverterTest, Scroll_Rotated) {
394 const nsecs_t downTime = 12345;
395 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
396 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
397 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000398 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000399
Harry Cuttsa546ba82023-01-13 17:21:00 +0000400 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000401 std::list<NotifyArgs> args =
402 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000403 ASSERT_THAT(args,
404 ElementsAre(VariantWith<NotifyMotionArgs>(
405 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
406 WithCoords(POINTER_X, POINTER_Y),
407 WithGestureScrollDistance(0, 0, EPSILON),
408 WithMotionClassification(
409 MotionClassification::TWO_FINGER_SWIPE),
410 WithToolType(ToolType::FINGER), WithDownTime(downTime),
411 WithDisplayId(ADISPLAY_ID_DEFAULT))),
412 VariantWith<NotifyMotionArgs>(
413 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
414 WithCoords(POINTER_X - 10, POINTER_Y),
415 WithGestureScrollDistance(0, 10, EPSILON),
416 WithMotionClassification(
417 MotionClassification::TWO_FINGER_SWIPE),
418 WithToolType(ToolType::FINGER),
419 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000420
Harry Cuttsa546ba82023-01-13 17:21:00 +0000421 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000422 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000423 ASSERT_THAT(args,
424 ElementsAre(VariantWith<NotifyMotionArgs>(
425 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
426 WithCoords(POINTER_X - 15, POINTER_Y),
427 WithGestureScrollDistance(0, 5, EPSILON),
428 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
429 WithToolType(ToolType::FINGER),
430 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000431 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
432 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000433 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000434 ASSERT_THAT(args,
435 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000436 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
437 WithCoords(POINTER_X - 15, POINTER_Y),
438 WithGestureScrollDistance(0, 0, EPSILON),
439 WithMotionClassification(
440 MotionClassification::TWO_FINGER_SWIPE),
441 WithToolType(ToolType::FINGER),
442 WithDisplayId(ADISPLAY_ID_DEFAULT))),
443 VariantWith<NotifyMotionArgs>(
444 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
445 WithCoords(POINTER_X, POINTER_Y),
446 WithMotionClassification(MotionClassification::NONE),
447 WithToolType(ToolType::FINGER),
448 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000449}
450
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000451TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000452 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
453 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000454 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000455
Harry Cuttsa546ba82023-01-13 17:21:00 +0000456 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000457 std::list<NotifyArgs> args =
458 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000459
Harry Cuttsa546ba82023-01-13 17:21:00 +0000460 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000461 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000462
463 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
464 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000465 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000466
467 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000468 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000469 ASSERT_THAT(args,
470 ElementsAre(VariantWith<NotifyMotionArgs>(
471 AllOf(WithMotionClassification(MotionClassification::NONE),
472 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000473}
474
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000475TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000476 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
477 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000478 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000479
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000480 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000481 std::list<NotifyArgs> args =
482 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000483
484 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000485 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000486
487 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
488 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000489 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000490
491 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
492 // need to use another gesture type, like pinch.
493 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
494 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000495 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000496 ASSERT_FALSE(args.empty());
497 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
498}
499
500TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
501 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
502 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000503 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000504
505 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
506 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000507 std::list<NotifyArgs> args =
508 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000509
510 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000511 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000512
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000513 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
514 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000515 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000516 ASSERT_EQ(1u, args.size());
Harry Cutts5f26e952023-11-30 18:20:27 +0000517 ASSERT_THAT(args,
518 ElementsAre(VariantWith<NotifyMotionArgs>(
519 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000520}
521
Harry Cutts8743f182023-05-17 12:03:49 +0000522TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000523 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
524 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000525 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000526
527 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
528 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000529 std::list<NotifyArgs> args =
530 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000531
532 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000533 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000534
535 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
536 // need to use another gesture type, like pinch.
537 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
538 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000539 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000540 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000541 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
542 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000543}
544
545TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
546 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
547 // start swiping up and then start moving left or right, it'll return gesture events with only Y
548 // deltas until you lift your fingers and start swiping again. That's why each of these tests
549 // only checks movement in one dimension.
550 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
551 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000552 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000553
554 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
555 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000556 std::list<NotifyArgs> args =
557 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000558 ASSERT_EQ(4u, args.size());
559
560 // Three fake fingers should be created. We don't actually care where they are, so long as they
561 // move appropriately.
562 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
563 ASSERT_THAT(arg,
564 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000565 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000566 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000567 WithPointerCount(1u), WithToolType(ToolType::FINGER),
568 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000569 PointerCoords finger0Start = arg.pointerCoords[0];
570 args.pop_front();
571 arg = std::get<NotifyMotionArgs>(args.front());
572 ASSERT_THAT(arg,
573 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
574 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000575 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000576 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000577 WithPointerCount(2u), WithToolType(ToolType::FINGER),
578 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000579 PointerCoords finger1Start = arg.pointerCoords[1];
580 args.pop_front();
581 arg = std::get<NotifyMotionArgs>(args.front());
582 ASSERT_THAT(arg,
583 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
584 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000585 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000586 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000587 WithPointerCount(3u), WithToolType(ToolType::FINGER),
588 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000589 PointerCoords finger2Start = arg.pointerCoords[2];
590 args.pop_front();
591
592 arg = std::get<NotifyMotionArgs>(args.front());
593 ASSERT_THAT(arg,
594 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000595 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000596 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000597 WithPointerCount(3u), WithToolType(ToolType::FINGER),
598 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000599 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
600 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
601 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
602 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
603 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
604 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
605
606 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
607 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000608 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000609 ASSERT_EQ(1u, args.size());
610 arg = std::get<NotifyMotionArgs>(args.front());
611 ASSERT_THAT(arg,
612 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000613 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000614 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000615 WithPointerCount(3u), WithToolType(ToolType::FINGER),
616 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000617 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
618 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
619 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
620 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
621 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
622 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
623
624 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000625 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000626 ASSERT_THAT(args,
627 ElementsAre(VariantWith<NotifyMotionArgs>(
628 AllOf(WithMotionAction(
629 AMOTION_EVENT_ACTION_POINTER_UP |
630 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
631 WithGestureOffset(0, 0, EPSILON),
632 WithGestureSwipeFingerCount(3),
633 WithMotionClassification(
634 MotionClassification::MULTI_FINGER_SWIPE),
635 WithPointerCount(3u), WithToolType(ToolType::FINGER),
636 WithDisplayId(ADISPLAY_ID_DEFAULT))),
637 VariantWith<NotifyMotionArgs>(
638 AllOf(WithMotionAction(
639 AMOTION_EVENT_ACTION_POINTER_UP |
640 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
641 WithGestureOffset(0, 0, EPSILON),
642 WithGestureSwipeFingerCount(3),
643 WithMotionClassification(
644 MotionClassification::MULTI_FINGER_SWIPE),
645 WithPointerCount(2u), WithToolType(ToolType::FINGER),
646 WithDisplayId(ADISPLAY_ID_DEFAULT))),
647 VariantWith<NotifyMotionArgs>(
648 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
649 WithGestureOffset(0, 0, EPSILON),
650 WithGestureSwipeFingerCount(3),
651 WithMotionClassification(
652 MotionClassification::MULTI_FINGER_SWIPE),
653 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000654 WithDisplayId(ADISPLAY_ID_DEFAULT))),
655 VariantWith<NotifyMotionArgs>(
656 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
657 WithCoords(POINTER_X, POINTER_Y),
658 WithMotionClassification(MotionClassification::NONE),
659 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000660 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000661}
662
Harry Cutts94f5bd52023-01-06 18:02:18 +0000663TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
664 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
665 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
666 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000667 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000668
669 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
670 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000671 std::list<NotifyArgs> args =
672 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000673 ASSERT_EQ(4u, args.size());
674
675 // Three fake fingers should be created. We don't actually care where they are, so long as they
676 // move appropriately.
677 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
678 ASSERT_THAT(arg,
679 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000680 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000681 PointerCoords finger0Start = arg.pointerCoords[0];
682 args.pop_front();
683 arg = std::get<NotifyMotionArgs>(args.front());
684 ASSERT_THAT(arg,
685 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
686 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000687 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
688 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000689 PointerCoords finger1Start = arg.pointerCoords[1];
690 args.pop_front();
691 arg = std::get<NotifyMotionArgs>(args.front());
692 ASSERT_THAT(arg,
693 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
694 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000695 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
696 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000697 PointerCoords finger2Start = arg.pointerCoords[2];
698 args.pop_front();
699
700 arg = std::get<NotifyMotionArgs>(args.front());
701 ASSERT_THAT(arg,
702 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000703 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
704 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000705 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
706 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
707 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
708 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
709 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
710 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
711
712 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
713 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000714 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000715 ASSERT_EQ(1u, args.size());
716 arg = std::get<NotifyMotionArgs>(args.front());
717 ASSERT_THAT(arg,
718 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000719 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
720 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000721 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
722 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
723 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
724 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
725 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
726 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
727
728 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000729 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000730 ASSERT_THAT(args,
731 ElementsAre(VariantWith<NotifyMotionArgs>(
732 AllOf(WithMotionAction(
733 AMOTION_EVENT_ACTION_POINTER_UP |
734 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
735 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
736 WithDisplayId(ADISPLAY_ID_DEFAULT))),
737 VariantWith<NotifyMotionArgs>(
738 AllOf(WithMotionAction(
739 AMOTION_EVENT_ACTION_POINTER_UP |
740 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
741 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
742 WithDisplayId(ADISPLAY_ID_DEFAULT))),
743 VariantWith<NotifyMotionArgs>(
744 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
745 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
Harry Cutts379ea422023-12-21 15:31:47 +0000746 WithDisplayId(ADISPLAY_ID_DEFAULT))),
747 VariantWith<NotifyMotionArgs>(
748 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000749 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000750}
751
Harry Cuttsc5748d12022-12-02 17:30:18 +0000752TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
753 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
754 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000755 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000756
757 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
758 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000759 std::list<NotifyArgs> args =
760 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000761 ASSERT_EQ(5u, args.size());
762
763 // Four fake fingers should be created. We don't actually care where they are, so long as they
764 // move appropriately.
765 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
766 ASSERT_THAT(arg,
767 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000768 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000769 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000770 WithPointerCount(1u), WithToolType(ToolType::FINGER),
771 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000772 PointerCoords finger0Start = arg.pointerCoords[0];
773 args.pop_front();
774 arg = std::get<NotifyMotionArgs>(args.front());
775 ASSERT_THAT(arg,
776 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
777 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000778 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000779 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000780 WithPointerCount(2u), WithToolType(ToolType::FINGER),
781 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000782 PointerCoords finger1Start = arg.pointerCoords[1];
783 args.pop_front();
784 arg = std::get<NotifyMotionArgs>(args.front());
785 ASSERT_THAT(arg,
786 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
787 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000788 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000789 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000790 WithPointerCount(3u), WithToolType(ToolType::FINGER),
791 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000792 PointerCoords finger2Start = arg.pointerCoords[2];
793 args.pop_front();
794 arg = std::get<NotifyMotionArgs>(args.front());
795 ASSERT_THAT(arg,
796 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
797 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000798 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000799 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000800 WithPointerCount(4u), WithToolType(ToolType::FINGER),
801 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000802 PointerCoords finger3Start = arg.pointerCoords[3];
803 args.pop_front();
804
805 arg = std::get<NotifyMotionArgs>(args.front());
806 ASSERT_THAT(arg,
807 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000808 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000809 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000810 WithPointerCount(4u), WithToolType(ToolType::FINGER),
811 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000812 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
813 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
814 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
815 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
816 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
817 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
818 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
819 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
820
821 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
822 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000823 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000824 ASSERT_EQ(1u, args.size());
825 arg = std::get<NotifyMotionArgs>(args.front());
826 ASSERT_THAT(arg,
827 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000828 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000829 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000830 WithPointerCount(4u), WithToolType(ToolType::FINGER),
831 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000832 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
833 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
834 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
835 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
836 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
837 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
838 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
839 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
840
841 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000842 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000843 ASSERT_THAT(args,
844 ElementsAre(VariantWith<NotifyMotionArgs>(
845 AllOf(WithMotionAction(
846 AMOTION_EVENT_ACTION_POINTER_UP |
847 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
848 WithGestureOffset(0, 0, EPSILON),
849 WithGestureSwipeFingerCount(4),
850 WithMotionClassification(
851 MotionClassification::MULTI_FINGER_SWIPE),
852 WithPointerCount(4u), WithToolType(ToolType::FINGER),
853 WithDisplayId(ADISPLAY_ID_DEFAULT))),
854 VariantWith<NotifyMotionArgs>(
855 AllOf(WithMotionAction(
856 AMOTION_EVENT_ACTION_POINTER_UP |
857 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
858 WithGestureOffset(0, 0, EPSILON),
859 WithGestureSwipeFingerCount(4),
860 WithMotionClassification(
861 MotionClassification::MULTI_FINGER_SWIPE),
862 WithPointerCount(3u), WithToolType(ToolType::FINGER),
863 WithDisplayId(ADISPLAY_ID_DEFAULT))),
864 VariantWith<NotifyMotionArgs>(
865 AllOf(WithMotionAction(
866 AMOTION_EVENT_ACTION_POINTER_UP |
867 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
868 WithGestureOffset(0, 0, EPSILON),
869 WithGestureSwipeFingerCount(4),
870 WithMotionClassification(
871 MotionClassification::MULTI_FINGER_SWIPE),
872 WithPointerCount(2u), WithToolType(ToolType::FINGER),
873 WithDisplayId(ADISPLAY_ID_DEFAULT))),
874 VariantWith<NotifyMotionArgs>(
875 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
876 WithGestureOffset(0, 0, EPSILON),
877 WithGestureSwipeFingerCount(4),
878 WithMotionClassification(
879 MotionClassification::MULTI_FINGER_SWIPE),
880 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000881 WithDisplayId(ADISPLAY_ID_DEFAULT))),
882 VariantWith<NotifyMotionArgs>(
883 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
884 WithCoords(POINTER_X, POINTER_Y),
885 WithMotionClassification(MotionClassification::NONE),
886 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000887 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000888}
889
Harry Cuttsb1e83552022-12-20 11:02:26 +0000890TEST_F(GestureConverterTest, Pinch_Inwards) {
891 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
892 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000893 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000894
895 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
896 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000897 std::list<NotifyArgs> args =
898 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000899 ASSERT_THAT(args,
900 ElementsAre(VariantWith<NotifyMotionArgs>(
901 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
902 WithMotionClassification(MotionClassification::PINCH),
903 WithGesturePinchScaleFactor(1.0f, EPSILON),
904 WithCoords(POINTER_X - 100, POINTER_Y),
905 WithPointerCount(1u), WithToolType(ToolType::FINGER),
906 WithDisplayId(ADISPLAY_ID_DEFAULT))),
907 VariantWith<NotifyMotionArgs>(
908 AllOf(WithMotionAction(
909 AMOTION_EVENT_ACTION_POINTER_DOWN |
910 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
911 WithMotionClassification(MotionClassification::PINCH),
912 WithGesturePinchScaleFactor(1.0f, EPSILON),
913 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
914 WithPointerCount(2u), WithToolType(ToolType::FINGER),
915 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000916
917 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
918 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000919 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000920 ASSERT_THAT(args,
921 ElementsAre(VariantWith<NotifyMotionArgs>(
922 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
923 WithMotionClassification(MotionClassification::PINCH),
924 WithGesturePinchScaleFactor(0.8f, EPSILON),
925 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
926 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
927 WithToolType(ToolType::FINGER),
928 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000929
930 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
931 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000932 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000933 ASSERT_THAT(args,
934 ElementsAre(VariantWith<NotifyMotionArgs>(
935 AllOf(WithMotionAction(
936 AMOTION_EVENT_ACTION_POINTER_UP |
937 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
938 WithMotionClassification(MotionClassification::PINCH),
939 WithGesturePinchScaleFactor(1.0f, EPSILON),
940 WithPointerCount(2u), WithToolType(ToolType::FINGER),
941 WithDisplayId(ADISPLAY_ID_DEFAULT))),
942 VariantWith<NotifyMotionArgs>(
943 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
944 WithMotionClassification(MotionClassification::PINCH),
945 WithGesturePinchScaleFactor(1.0f, EPSILON),
946 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000947 WithDisplayId(ADISPLAY_ID_DEFAULT))),
948 VariantWith<NotifyMotionArgs>(
949 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
950 WithCoords(POINTER_X, POINTER_Y),
951 WithMotionClassification(MotionClassification::NONE),
952 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000953 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000954}
955
956TEST_F(GestureConverterTest, Pinch_Outwards) {
957 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
958 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000959 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000960
961 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
962 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000963 std::list<NotifyArgs> args =
964 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000965 ASSERT_THAT(args,
966 ElementsAre(VariantWith<NotifyMotionArgs>(
967 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
968 WithMotionClassification(MotionClassification::PINCH),
969 WithGesturePinchScaleFactor(1.0f, EPSILON),
970 WithCoords(POINTER_X - 100, POINTER_Y),
971 WithPointerCount(1u), WithToolType(ToolType::FINGER),
972 WithDisplayId(ADISPLAY_ID_DEFAULT))),
973 VariantWith<NotifyMotionArgs>(
974 AllOf(WithMotionAction(
975 AMOTION_EVENT_ACTION_POINTER_DOWN |
976 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
977 WithMotionClassification(MotionClassification::PINCH),
978 WithGesturePinchScaleFactor(1.0f, EPSILON),
979 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
980 WithPointerCount(2u), WithToolType(ToolType::FINGER),
981 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000982
983 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
984 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000985 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000986 ASSERT_THAT(args,
987 ElementsAre(VariantWith<NotifyMotionArgs>(
988 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
989 WithMotionClassification(MotionClassification::PINCH),
990 WithGesturePinchScaleFactor(1.2f, EPSILON),
991 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
992 WithPointerCoords(1, POINTER_X + 120, POINTER_Y),
993 WithPointerCount(2u), WithToolType(ToolType::FINGER),
994 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000995
996 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
997 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000998 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000999 ASSERT_THAT(args,
1000 ElementsAre(VariantWith<NotifyMotionArgs>(
1001 AllOf(WithMotionAction(
1002 AMOTION_EVENT_ACTION_POINTER_UP |
1003 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1004 WithMotionClassification(MotionClassification::PINCH),
1005 WithGesturePinchScaleFactor(1.0f, EPSILON),
1006 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1007 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1008 VariantWith<NotifyMotionArgs>(
1009 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1010 WithMotionClassification(MotionClassification::PINCH),
1011 WithGesturePinchScaleFactor(1.0f, EPSILON),
1012 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001013 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1014 VariantWith<NotifyMotionArgs>(
1015 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1016 WithCoords(POINTER_X, POINTER_Y),
1017 WithMotionClassification(MotionClassification::NONE),
1018 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001019 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001020}
1021
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001022TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +00001023 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1024 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001025 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001026
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001027 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001028 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001029 std::list<NotifyArgs> args =
1030 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001031
1032 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001033 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001034 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001035
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001036 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001037 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001038 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001039
1040 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001041 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001042 ASSERT_THAT(args,
1043 ElementsAre(VariantWith<NotifyMotionArgs>(
1044 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001045}
1046
1047TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
1048 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1049 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001050 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001051
1052 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1053 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001054 std::list<NotifyArgs> args =
1055 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001056
1057 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1058 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001059 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001060
1061 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1062 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001063 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001064
1065 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1066 // need to use another gesture type, like scroll.
1067 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1068 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001069 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001070 ASSERT_FALSE(args.empty());
1071 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001072}
1073
Harry Cuttse9b71422023-03-14 16:54:44 +00001074TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1075 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1076 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001077 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001078
1079 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1080 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1081 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001082 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001083
1084 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001085 ASSERT_THAT(args,
1086 ElementsAre(VariantWith<NotifyMotionArgs>(
1087 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1088 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1089 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
1090 WithCoords(POINTER_X, POINTER_Y),
1091 WithToolType(ToolType::FINGER),
1092 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1093 VariantWith<NotifyMotionArgs>(
1094 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1095 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1096 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1097 WithToolType(ToolType::FINGER),
1098 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1099 VariantWith<NotifyMotionArgs>(
1100 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1101 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1102 WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001103 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1104 VariantWith<NotifyMotionArgs>(
1105 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1106 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1107 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001108 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001109}
1110
1111TEST_F(GestureConverterTest, ResetDuringScroll) {
1112 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1113 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001114 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001115
1116 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001117 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001118
1119 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001120 ASSERT_THAT(args,
1121 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001122 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1123 WithCoords(POINTER_X, POINTER_Y - 10),
1124 WithGestureScrollDistance(0, 0, EPSILON),
1125 WithMotionClassification(
1126 MotionClassification::TWO_FINGER_SWIPE),
1127 WithToolType(ToolType::FINGER),
1128 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1129 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1130 VariantWith<NotifyMotionArgs>(
1131 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1132 WithCoords(POINTER_X, POINTER_Y),
1133 WithMotionClassification(MotionClassification::NONE),
1134 WithToolType(ToolType::FINGER),
1135 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001136}
1137
1138TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1139 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1140 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001141 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001142
1143 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1144 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001145 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001146
1147 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001148 ASSERT_THAT(args,
1149 ElementsAre(VariantWith<NotifyMotionArgs>(
1150 AllOf(WithMotionAction(
1151 AMOTION_EVENT_ACTION_POINTER_UP |
1152 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1153 WithGestureOffset(0, 0, EPSILON),
1154 WithMotionClassification(
1155 MotionClassification::MULTI_FINGER_SWIPE),
1156 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1157 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1158 VariantWith<NotifyMotionArgs>(
1159 AllOf(WithMotionAction(
1160 AMOTION_EVENT_ACTION_POINTER_UP |
1161 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1162 WithGestureOffset(0, 0, EPSILON),
1163 WithMotionClassification(
1164 MotionClassification::MULTI_FINGER_SWIPE),
1165 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1166 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1167 VariantWith<NotifyMotionArgs>(
1168 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1169 WithGestureOffset(0, 0, EPSILON),
1170 WithMotionClassification(
1171 MotionClassification::MULTI_FINGER_SWIPE),
1172 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001173 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1174 VariantWith<NotifyMotionArgs>(
1175 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1176 WithMotionClassification(MotionClassification::NONE),
1177 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001178 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001179}
1180
1181TEST_F(GestureConverterTest, ResetDuringPinch) {
1182 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1183 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001184 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001185
1186 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1187 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001188 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001189
1190 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001191 ASSERT_THAT(args,
1192 ElementsAre(VariantWith<NotifyMotionArgs>(
1193 AllOf(WithMotionAction(
1194 AMOTION_EVENT_ACTION_POINTER_UP |
1195 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1196 WithMotionClassification(MotionClassification::PINCH),
1197 WithGesturePinchScaleFactor(1.0f, EPSILON),
1198 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1199 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1200 VariantWith<NotifyMotionArgs>(
1201 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1202 WithMotionClassification(MotionClassification::PINCH),
1203 WithGesturePinchScaleFactor(1.0f, EPSILON),
1204 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001205 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1206 VariantWith<NotifyMotionArgs>(
1207 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1208 WithCoords(POINTER_X, POINTER_Y),
1209 WithMotionClassification(MotionClassification::NONE),
1210 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001211 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001212}
1213
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001214TEST_F(GestureConverterTest, FlingTapDown) {
1215 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1216 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001217 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001218
1219 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1220 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001221 std::list<NotifyArgs> args =
1222 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001223
1224 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001225 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001226 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001227 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1228 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001229
1230 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1231 ASSERT_TRUE(mFakePointerController->isPointerShown());
1232}
1233
Harry Cutts39648ab2024-02-15 14:23:50 +00001234TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1235 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1236 input_flags::enable_touchpad_fling_stop(true);
1237 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1238 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1239
1240 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1241 std::list<NotifyArgs> args =
1242 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1243 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1244 GESTURES_FLING_START);
1245 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1246
1247 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1248 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1249 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1250 ASSERT_THAT(args,
1251 ElementsAre(VariantWith<NotifyMotionArgs>(
1252 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1253 VariantWith<NotifyMotionArgs>(
1254 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1255 VariantWith<NotifyMotionArgs>(
1256 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1257 VariantWith<NotifyMotionArgs>(
1258 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1259 WithMotionClassification(MotionClassification::NONE)))));
1260 ASSERT_THAT(args,
1261 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1262 WithToolType(ToolType::FINGER),
1263 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
1264}
1265
Arpit Singha5ea7c12023-07-05 15:39:25 +00001266TEST_F(GestureConverterTest, Tap) {
1267 // Tap should produce button press/release events
1268 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1269 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001270 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001271
1272 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1273 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001274 std::list<NotifyArgs> args =
1275 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001276 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001277
1278 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1279 /* down= */ GESTURES_BUTTON_LEFT,
1280 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001281 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001282
Harry Cutts5f26e952023-11-30 18:20:27 +00001283 ASSERT_THAT(args,
1284 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001285 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1286 WithCoords(POINTER_X, POINTER_Y),
1287 WithRelativeMotion(0.f, 0.f),
1288 WithToolType(ToolType::FINGER), WithButtonState(0),
1289 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1290 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001291 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1292 WithCoords(POINTER_X, POINTER_Y),
1293 WithRelativeMotion(0.f, 0.f),
1294 WithToolType(ToolType::FINGER),
1295 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1296 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1297 VariantWith<NotifyMotionArgs>(
1298 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1299 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1300 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1301 WithCoords(POINTER_X, POINTER_Y),
1302 WithRelativeMotion(0.f, 0.f),
1303 WithToolType(ToolType::FINGER),
1304 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1305 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1306 VariantWith<NotifyMotionArgs>(
1307 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1308 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1309 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1310 WithRelativeMotion(0.f, 0.f),
1311 WithToolType(ToolType::FINGER), WithButtonState(0),
1312 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1313 VariantWith<NotifyMotionArgs>(
1314 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1315 WithCoords(POINTER_X, POINTER_Y),
1316 WithRelativeMotion(0.f, 0.f),
1317 WithToolType(ToolType::FINGER), WithButtonState(0),
1318 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1319 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001320 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001321 WithCoords(POINTER_X, POINTER_Y),
1322 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1323 WithButtonState(0), WithPressure(0.0f),
1324 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001325}
1326
1327TEST_F(GestureConverterTest, Click) {
1328 // Click should produce button press/release events
1329 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1330 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001331 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001332
1333 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1334 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001335 std::list<NotifyArgs> args =
1336 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001337 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001338
1339 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1340 /* down= */ GESTURES_BUTTON_LEFT,
1341 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001342 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001343
Harry Cutts5f26e952023-11-30 18:20:27 +00001344 ASSERT_THAT(args,
1345 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001346 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1347 WithCoords(POINTER_X, POINTER_Y),
1348 WithRelativeMotion(0.f, 0.f),
1349 WithToolType(ToolType::FINGER), WithButtonState(0),
1350 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1351 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001352 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1353 WithCoords(POINTER_X, POINTER_Y),
1354 WithRelativeMotion(0.f, 0.f),
1355 WithToolType(ToolType::FINGER),
1356 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1357 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1358 VariantWith<NotifyMotionArgs>(
1359 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1360 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1361 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1362 WithCoords(POINTER_X, POINTER_Y),
1363 WithRelativeMotion(0.f, 0.f),
1364 WithToolType(ToolType::FINGER),
1365 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1366 WithPressure(1.0f),
1367 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001368
1369 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1370 /* down= */ GESTURES_BUTTON_NONE,
1371 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001372 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001373 ASSERT_THAT(args,
1374 ElementsAre(VariantWith<NotifyMotionArgs>(
1375 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1376 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1377 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1378 WithRelativeMotion(0.f, 0.f),
1379 WithToolType(ToolType::FINGER), WithButtonState(0),
1380 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1381 VariantWith<NotifyMotionArgs>(
1382 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1383 WithCoords(POINTER_X, POINTER_Y),
1384 WithRelativeMotion(0.f, 0.f),
1385 WithToolType(ToolType::FINGER), WithButtonState(0),
1386 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1387 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001388 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001389 WithCoords(POINTER_X, POINTER_Y),
1390 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1391 WithButtonState(0), WithPressure(0.0f),
1392 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001393}
1394
Arpit Singh3d84add2023-10-10 19:08:29 +00001395TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001396 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1397 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1398 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1399
Arpit Singha5ea7c12023-07-05 15:39:25 +00001400 // Tap should be ignored when disabled
1401 mReader->getContext()->setPreventingTouchpadTaps(true);
1402
1403 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1404 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001405 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001406
Arpit Singh82b27a02023-10-16 11:02:19 +00001407 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001408 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001409 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001410 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001411 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001412
Arpit Singh82b27a02023-10-16 11:02:19 +00001413 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001414 /* down= */ GESTURES_BUTTON_LEFT,
1415 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001416 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001417
1418 // no events should be generated
1419 ASSERT_EQ(0u, args.size());
1420
1421 // Future taps should be re-enabled
1422 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1423}
1424
Arpit Singh82b27a02023-10-16 11:02:19 +00001425TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1426 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1427 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1428
1429 // Tap should be ignored when disabled
1430 mReader->getContext()->setPreventingTouchpadTaps(true);
1431
1432 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1433 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1434 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1435
1436 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1437 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1438 std::list<NotifyArgs> args =
1439 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001440 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001441
1442 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1443 /* down= */ GESTURES_BUTTON_LEFT,
1444 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1445 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1446
1447 // no events should be generated
1448 ASSERT_EQ(0u, args.size());
1449
1450 // Future taps should be re-enabled
1451 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1452
1453 // taps before the threshold should still be ignored
1454 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1455 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1456 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1457 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1458
1459 ASSERT_EQ(1u, args.size());
1460 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1461 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1462
1463 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1464 /* down= */ GESTURES_BUTTON_LEFT,
1465 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1466 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1467
1468 // no events should be generated
1469 ASSERT_EQ(0u, args.size());
1470
1471 // taps after the threshold should be recognised
1472 currentTime += 1;
1473 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1474 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1475 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1476
1477 ASSERT_EQ(1u, args.size());
1478 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1479 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1480
1481 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1482 /* down= */ GESTURES_BUTTON_LEFT,
1483 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1484 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1485
Harry Cutts379ea422023-12-21 15:31:47 +00001486 ASSERT_EQ(6u, args.size());
1487 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1488 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1489 WithRelativeMotion(0.f, 0.f), WithButtonState(0)));
1490 args.pop_front();
Arpit Singh82b27a02023-10-16 11:02:19 +00001491 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1492 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
1493 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
1494 args.pop_front();
1495 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1496 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1497 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
1498 WithRelativeMotion(0.f, 0.f)));
1499 args.pop_front();
1500 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1501 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1502 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1503 WithRelativeMotion(0.f, 0.f)));
1504 args.pop_front();
1505 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1506 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
1507 WithButtonState(0)));
1508 args.pop_front();
1509 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001510 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0),
Arpit Singh82b27a02023-10-16 11:02:19 +00001511 WithButtonState(0)));
1512}
1513
Arpit Singh3d84add2023-10-10 19:08:29 +00001514TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1515 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001516 // Click should still produce button press/release events
1517 mReader->getContext()->setPreventingTouchpadTaps(true);
1518
1519 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1520 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001521 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001522
1523 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1524 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001525 std::list<NotifyArgs> args =
1526 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001527 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001528
1529 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1530 /* down= */ GESTURES_BUTTON_LEFT,
1531 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001532 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001533 ASSERT_THAT(args,
1534 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001535 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1536 WithCoords(POINTER_X, POINTER_Y),
1537 WithRelativeMotion(0.f, 0.f),
1538 WithToolType(ToolType::FINGER), WithButtonState(0),
1539 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1540 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001541 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1542 WithCoords(POINTER_X, POINTER_Y),
1543 WithRelativeMotion(0.f, 0.f),
1544 WithToolType(ToolType::FINGER),
1545 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1546 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1547 VariantWith<NotifyMotionArgs>(
1548 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1549 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1550 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1551 WithCoords(POINTER_X, POINTER_Y),
1552 WithRelativeMotion(0.f, 0.f),
1553 WithToolType(ToolType::FINGER),
1554 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1555 WithPressure(1.0f),
1556 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001557
1558 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1559 /* down= */ GESTURES_BUTTON_NONE,
1560 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001561 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001562
Harry Cutts5f26e952023-11-30 18:20:27 +00001563 ASSERT_THAT(args,
1564 ElementsAre(VariantWith<NotifyMotionArgs>(
1565 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1566 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1567 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1568 WithRelativeMotion(0.f, 0.f),
1569 WithToolType(ToolType::FINGER), WithButtonState(0),
1570 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1571 VariantWith<NotifyMotionArgs>(
1572 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1573 WithCoords(POINTER_X, POINTER_Y),
1574 WithRelativeMotion(0.f, 0.f),
1575 WithToolType(ToolType::FINGER), WithButtonState(0),
1576 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1577 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001578 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001579 WithCoords(POINTER_X, POINTER_Y),
1580 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1581 WithButtonState(0), WithPressure(0.0f),
1582 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001583
1584 // Future taps should be re-enabled
1585 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1586}
1587
Arpit Singh3d84add2023-10-10 19:08:29 +00001588TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1589 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001590 // initially disable tap-to-click
1591 mReader->getContext()->setPreventingTouchpadTaps(true);
1592
1593 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1594 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001595 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001596
1597 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001598 std::list<NotifyArgs> args =
1599 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001600 // We don't need to check args here, since it's covered by the Move test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001601
1602 // Future taps should be re-enabled
1603 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1604}
1605
Arpit Singh33a10a62023-10-12 13:06:54 +00001606TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1607 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1608 const nsecs_t gestureStartTime = 1000;
1609 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1610 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1611 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1612
1613 // Start a move gesture at gestureStartTime
1614 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1615 std::list<NotifyArgs> args =
1616 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001617 ASSERT_THAT(args,
1618 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001619 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1620 VariantWith<NotifyMotionArgs>(
1621 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001622
1623 // Key presses with IME connection should cancel ongoing move gesture
1624 nsecs_t currentTime = gestureStartTime + 100;
1625 mFakePolicy->setIsInputMethodConnectionActive(true);
1626 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1627 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1628 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001629 ASSERT_THAT(args,
1630 ElementsAre(VariantWith<NotifyMotionArgs>(
1631 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001632
1633 // any updates in existing move gesture should be ignored
1634 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1635 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1636 ASSERT_EQ(0u, args.size());
1637
1638 // New gesture should not be affected
1639 currentTime += 100;
1640 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1641 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001642 ASSERT_THAT(args,
1643 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001644 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1645 VariantWith<NotifyMotionArgs>(
1646 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001647}
1648
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001649// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1650// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001651class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1652protected:
1653 void SetUp() override {
1654 input_flags::enable_pointer_choreographer(true);
1655 GestureConverterTestBase::SetUp();
1656 }
1657};
1658
1659TEST_F(GestureConverterTestWithChoreographer, Move) {
1660 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1661 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1662 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1663
1664 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001665 std::list<NotifyArgs> args =
1666 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001667 ASSERT_THAT(args,
1668 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001669 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1670 WithCoords(0, 0), WithRelativeMotion(0, 0),
1671 WithToolType(ToolType::FINGER),
1672 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1673 VariantWith<NotifyMotionArgs>(
1674 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1675 WithCoords(0, 0), WithRelativeMotion(-5, 10),
1676 WithToolType(ToolType::FINGER), WithButtonState(0),
1677 WithPressure(0.0f),
1678 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
1679
1680 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
1681 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1682 ASSERT_THAT(args,
1683 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001684 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1685 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1686 WithButtonState(0), WithPressure(0.0f),
1687 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001688}
1689
1690TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1691 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1692 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1693 converter.setOrientation(ui::ROTATION_90);
1694 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1695
1696 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001697 std::list<NotifyArgs> args =
1698 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001699 ASSERT_THAT(args,
1700 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001701 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1702 WithCoords(0, 0), WithRelativeMotion(0, 0),
1703 WithToolType(ToolType::FINGER),
1704 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1705 VariantWith<NotifyMotionArgs>(
1706 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1707 WithCoords(0, 0), WithRelativeMotion(10, 5),
1708 WithToolType(ToolType::FINGER), WithButtonState(0),
1709 WithPressure(0.0f),
1710 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001711}
1712
1713TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1714 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1715 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1716 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1717
1718 // Press left and right buttons at once
1719 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1720 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1721 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001722 std::list<NotifyArgs> args =
1723 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001724 ASSERT_THAT(args,
1725 ElementsAre(VariantWith<NotifyMotionArgs>(
1726 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1727 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1728 AMOTION_EVENT_BUTTON_SECONDARY),
1729 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1730 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1731 VariantWith<NotifyMotionArgs>(
1732 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1733 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1734 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1735 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1736 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1737 VariantWith<NotifyMotionArgs>(
1738 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1739 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1740 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1741 AMOTION_EVENT_BUTTON_SECONDARY),
1742 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1743 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001744
1745 // Then release the left button
1746 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1747 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1748 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001749 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001750 ASSERT_THAT(args,
1751 ElementsAre(VariantWith<NotifyMotionArgs>(
1752 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1753 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1754 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1755 WithToolType(ToolType::FINGER),
1756 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001757
1758 // Finally release the right button
1759 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1760 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1761 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001762 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001763 ASSERT_THAT(args,
1764 ElementsAre(VariantWith<NotifyMotionArgs>(
1765 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1766 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1767 WithButtonState(0), WithCoords(0, 0),
1768 WithToolType(ToolType::FINGER),
1769 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1770 VariantWith<NotifyMotionArgs>(
1771 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1772 WithButtonState(0), WithCoords(0, 0),
1773 WithToolType(ToolType::FINGER),
1774 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1775 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001776 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001777 WithButtonState(0), WithCoords(0, 0),
1778 WithToolType(ToolType::FINGER),
1779 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001780}
1781
Harry Cutts379ea422023-12-21 15:31:47 +00001782TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) {
1783 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1784 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1785 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1786
1787 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1788 std::list<NotifyArgs> args =
1789 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1790
1791 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1792 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
1793 /*is_tap=*/false);
1794 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
1795 ASSERT_THAT(args.front(),
1796 VariantWith<NotifyMotionArgs>(
1797 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
1798 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1799 WithDisplayId(ADISPLAY_ID_DEFAULT))));
1800}
1801
Byoungho Jungee6268f2023-10-30 17:27:26 +09001802TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1803 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1804 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1805 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1806
1807 // Press the button
1808 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1809 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1810 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001811 std::list<NotifyArgs> args =
1812 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001813 ASSERT_THAT(args,
1814 ElementsAre(VariantWith<NotifyMotionArgs>(
1815 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1816 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1817 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1818 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1819 VariantWith<NotifyMotionArgs>(
1820 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1821 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1822 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1823 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1824 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001825
1826 // Move
1827 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001828 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001829 ASSERT_THAT(args,
1830 ElementsAre(VariantWith<NotifyMotionArgs>(
1831 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1832 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1833 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1834 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001835
1836 // Release the button
1837 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1838 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1839 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001840 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001841 ASSERT_THAT(args,
1842 ElementsAre(VariantWith<NotifyMotionArgs>(
1843 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1844 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1845 WithButtonState(0), WithCoords(0, 0),
1846 WithToolType(ToolType::FINGER),
1847 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1848 VariantWith<NotifyMotionArgs>(
1849 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1850 WithButtonState(0), WithCoords(0, 0),
1851 WithToolType(ToolType::FINGER),
1852 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1853 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001854 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001855 WithButtonState(0), WithCoords(0, 0),
1856 WithToolType(ToolType::FINGER),
1857 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001858}
1859
1860TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1861 const nsecs_t downTime = 12345;
1862 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1863 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1864 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1865
1866 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001867 std::list<NotifyArgs> args =
1868 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001869 ASSERT_THAT(args,
1870 ElementsAre(VariantWith<NotifyMotionArgs>(
1871 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1872 WithCoords(0, 0),
1873 WithGestureScrollDistance(0, 0, EPSILON),
1874 WithMotionClassification(
1875 MotionClassification::TWO_FINGER_SWIPE),
1876 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1877 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1878 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1879 VariantWith<NotifyMotionArgs>(
1880 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1881 WithCoords(0, -10),
1882 WithGestureScrollDistance(0, 10, EPSILON),
1883 WithMotionClassification(
1884 MotionClassification::TWO_FINGER_SWIPE),
1885 WithToolType(ToolType::FINGER),
1886 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1887 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001888
1889 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001890 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001891 ASSERT_THAT(args,
1892 ElementsAre(VariantWith<NotifyMotionArgs>(
1893 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1894 WithGestureScrollDistance(0, 5, EPSILON),
1895 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1896 WithToolType(ToolType::FINGER),
1897 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1898 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001899
1900 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1901 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001902 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001903 ASSERT_THAT(args,
1904 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001905 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1906 WithCoords(0, -15),
1907 WithGestureScrollDistance(0, 0, EPSILON),
1908 WithMotionClassification(
1909 MotionClassification::TWO_FINGER_SWIPE),
1910 WithToolType(ToolType::FINGER),
1911 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1912 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1913 VariantWith<NotifyMotionArgs>(
1914 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1915 WithCoords(0, 0),
1916 WithMotionClassification(MotionClassification::NONE),
1917 WithToolType(ToolType::FINGER),
1918 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001919}
1920
1921TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1922 const nsecs_t downTime = 12345;
1923 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1924 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1925 converter.setOrientation(ui::ROTATION_90);
1926 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1927
1928 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001929 std::list<NotifyArgs> args =
1930 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001931 ASSERT_THAT(args,
1932 ElementsAre(VariantWith<NotifyMotionArgs>(
1933 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1934 WithCoords(0, 0),
1935 WithGestureScrollDistance(0, 0, EPSILON),
1936 WithMotionClassification(
1937 MotionClassification::TWO_FINGER_SWIPE),
1938 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1939 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1940 VariantWith<NotifyMotionArgs>(
1941 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1942 WithCoords(-10, 0),
1943 WithGestureScrollDistance(0, 10, EPSILON),
1944 WithMotionClassification(
1945 MotionClassification::TWO_FINGER_SWIPE),
1946 WithToolType(ToolType::FINGER),
1947 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001948
1949 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001950 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001951 ASSERT_THAT(args,
1952 ElementsAre(VariantWith<NotifyMotionArgs>(
1953 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1954 WithGestureScrollDistance(0, 5, EPSILON),
1955 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1956 WithToolType(ToolType::FINGER),
1957 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001958
1959 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1960 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001961 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001962 ASSERT_THAT(args,
1963 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001964 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1965 WithCoords(-15, 0),
1966 WithGestureScrollDistance(0, 0, EPSILON),
1967 WithMotionClassification(
1968 MotionClassification::TWO_FINGER_SWIPE),
1969 WithToolType(ToolType::FINGER),
1970 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1971 VariantWith<NotifyMotionArgs>(
1972 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1973 WithCoords(0, 0),
1974 WithMotionClassification(MotionClassification::NONE),
1975 WithToolType(ToolType::FINGER),
1976 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001977}
1978
1979TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1980 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1981 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1982 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1983
1984 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001985 std::list<NotifyArgs> args =
1986 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001987
1988 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001989 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001990
1991 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1992 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001993 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001994
1995 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001996 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001997 ASSERT_THAT(args,
1998 ElementsAre(VariantWith<NotifyMotionArgs>(
1999 AllOf(WithMotionClassification(MotionClassification::NONE),
2000 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002001}
2002
2003TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
2004 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2005 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2006 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2007
2008 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002009 std::list<NotifyArgs> args =
2010 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002011
2012 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002013 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002014
2015 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
2016 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002017 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002018
2019 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2020 // need to use another gesture type, like pinch.
2021 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2022 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002023 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002024 ASSERT_FALSE(args.empty());
2025 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
2026}
2027
2028TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
2029 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2030 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2031 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2032
2033 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2034 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002035 std::list<NotifyArgs> args =
2036 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002037
2038 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002039 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002040
2041 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
2042 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002043 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002044 ASSERT_THAT(args,
2045 ElementsAre(VariantWith<NotifyMotionArgs>(
2046 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002047}
2048
2049TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
2050 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2051 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2052 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2053
2054 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
2055 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002056 std::list<NotifyArgs> args =
2057 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002058
2059 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002060 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002061
2062 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2063 // need to use another gesture type, like pinch.
2064 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2065 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002066 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002067 ASSERT_FALSE(args.empty());
2068 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2069 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
2070}
2071
2072TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
2073 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
2074 // start swiping up and then start moving left or right, it'll return gesture events with only Y
2075 // deltas until you lift your fingers and start swiping again. That's why each of these tests
2076 // only checks movement in one dimension.
2077 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2078 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2079 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2080
2081 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2082 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002083 std::list<NotifyArgs> args =
2084 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002085 ASSERT_EQ(4u, args.size());
2086
2087 // Three fake fingers should be created. We don't actually care where they are, so long as they
2088 // move appropriately.
2089 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2090 ASSERT_THAT(arg,
2091 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2092 WithGestureSwipeFingerCount(3),
2093 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2094 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2095 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2096 PointerCoords finger0Start = arg.pointerCoords[0];
2097 args.pop_front();
2098 arg = std::get<NotifyMotionArgs>(args.front());
2099 ASSERT_THAT(arg,
2100 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2101 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2102 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
2103 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2104 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2105 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2106 PointerCoords finger1Start = arg.pointerCoords[1];
2107 args.pop_front();
2108 arg = std::get<NotifyMotionArgs>(args.front());
2109 ASSERT_THAT(arg,
2110 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2111 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2112 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
2113 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2114 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2115 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2116 PointerCoords finger2Start = arg.pointerCoords[2];
2117 args.pop_front();
2118
2119 arg = std::get<NotifyMotionArgs>(args.front());
2120 ASSERT_THAT(arg,
2121 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2122 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
2123 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2124 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2125 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2126 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2127 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2128 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2129 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
2130 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
2131 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
2132
2133 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2134 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002135 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002136 ASSERT_EQ(1u, args.size());
2137 arg = std::get<NotifyMotionArgs>(args.front());
2138 ASSERT_THAT(arg,
2139 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2140 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
2141 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2142 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2143 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2144 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2145 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2146 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2147 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
2148 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
2149 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
2150
2151 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002152 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002153 ASSERT_THAT(args,
2154 ElementsAre(VariantWith<NotifyMotionArgs>(
2155 AllOf(WithMotionAction(
2156 AMOTION_EVENT_ACTION_POINTER_UP |
2157 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2158 WithGestureOffset(0, 0, EPSILON),
2159 WithGestureSwipeFingerCount(3),
2160 WithMotionClassification(
2161 MotionClassification::MULTI_FINGER_SWIPE),
2162 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2163 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2164 VariantWith<NotifyMotionArgs>(
2165 AllOf(WithMotionAction(
2166 AMOTION_EVENT_ACTION_POINTER_UP |
2167 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2168 WithGestureOffset(0, 0, EPSILON),
2169 WithGestureSwipeFingerCount(3),
2170 WithMotionClassification(
2171 MotionClassification::MULTI_FINGER_SWIPE),
2172 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2173 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2174 VariantWith<NotifyMotionArgs>(
2175 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2176 WithGestureOffset(0, 0, EPSILON),
2177 WithGestureSwipeFingerCount(3),
2178 WithMotionClassification(
2179 MotionClassification::MULTI_FINGER_SWIPE),
2180 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002181 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2182 VariantWith<NotifyMotionArgs>(
2183 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2184 WithCoords(0, 0),
2185 WithMotionClassification(MotionClassification::NONE),
2186 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002187 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002188}
2189
2190TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
2191 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2192 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2193 converter.setOrientation(ui::ROTATION_90);
2194 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2195
2196 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2197 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002198 std::list<NotifyArgs> args =
2199 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002200 ASSERT_EQ(4u, args.size());
2201
2202 // Three fake fingers should be created. We don't actually care where they are, so long as they
2203 // move appropriately.
2204 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2205 ASSERT_THAT(arg,
2206 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2207 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2208 PointerCoords finger0Start = arg.pointerCoords[0];
2209 args.pop_front();
2210 arg = std::get<NotifyMotionArgs>(args.front());
2211 ASSERT_THAT(arg,
2212 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2213 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2214 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2215 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2216 PointerCoords finger1Start = arg.pointerCoords[1];
2217 args.pop_front();
2218 arg = std::get<NotifyMotionArgs>(args.front());
2219 ASSERT_THAT(arg,
2220 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2221 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2222 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2223 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2224 PointerCoords finger2Start = arg.pointerCoords[2];
2225 args.pop_front();
2226
2227 arg = std::get<NotifyMotionArgs>(args.front());
2228 ASSERT_THAT(arg,
2229 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2230 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
2231 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2232 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
2233 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
2234 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
2235 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2236 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2237 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2238
2239 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2240 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002241 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002242 ASSERT_EQ(1u, args.size());
2243 arg = std::get<NotifyMotionArgs>(args.front());
2244 ASSERT_THAT(arg,
2245 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2246 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
2247 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2248 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
2249 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
2250 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
2251 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2252 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2253 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2254
2255 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002256 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002257 ASSERT_THAT(args,
2258 ElementsAre(VariantWith<NotifyMotionArgs>(
2259 AllOf(WithMotionAction(
2260 AMOTION_EVENT_ACTION_POINTER_UP |
2261 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2262 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2263 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2264 VariantWith<NotifyMotionArgs>(
2265 AllOf(WithMotionAction(
2266 AMOTION_EVENT_ACTION_POINTER_UP |
2267 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2268 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2269 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2270 VariantWith<NotifyMotionArgs>(
2271 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2272 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
Harry Cutts379ea422023-12-21 15:31:47 +00002273 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2274 VariantWith<NotifyMotionArgs>(
2275 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002276 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002277}
2278
2279TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2280 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2281 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2282 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2283
2284 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2285 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002286 std::list<NotifyArgs> args =
2287 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002288 ASSERT_EQ(5u, args.size());
2289
2290 // Four fake fingers should be created. We don't actually care where they are, so long as they
2291 // move appropriately.
2292 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2293 ASSERT_THAT(arg,
2294 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2295 WithGestureSwipeFingerCount(4),
2296 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2297 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2298 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2299 PointerCoords finger0Start = arg.pointerCoords[0];
2300 args.pop_front();
2301 arg = std::get<NotifyMotionArgs>(args.front());
2302 ASSERT_THAT(arg,
2303 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2304 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2305 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2306 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2307 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2308 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2309 PointerCoords finger1Start = arg.pointerCoords[1];
2310 args.pop_front();
2311 arg = std::get<NotifyMotionArgs>(args.front());
2312 ASSERT_THAT(arg,
2313 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2314 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2315 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2316 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2317 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2318 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2319 PointerCoords finger2Start = arg.pointerCoords[2];
2320 args.pop_front();
2321 arg = std::get<NotifyMotionArgs>(args.front());
2322 ASSERT_THAT(arg,
2323 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2324 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2325 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2326 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2327 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2328 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2329 PointerCoords finger3Start = arg.pointerCoords[3];
2330 args.pop_front();
2331
2332 arg = std::get<NotifyMotionArgs>(args.front());
2333 ASSERT_THAT(arg,
2334 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2335 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
2336 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2337 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2338 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2339 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2340 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2341 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2342 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2343 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2344 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2345 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2346 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2347
2348 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2349 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002350 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002351 ASSERT_EQ(1u, args.size());
2352 arg = std::get<NotifyMotionArgs>(args.front());
2353 ASSERT_THAT(arg,
2354 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2355 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2356 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2357 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2358 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2359 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2360 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2361 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2362 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2363 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2364 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2365 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2366 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2367
2368 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002369 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002370 ASSERT_THAT(args,
2371 ElementsAre(VariantWith<NotifyMotionArgs>(
2372 AllOf(WithMotionAction(
2373 AMOTION_EVENT_ACTION_POINTER_UP |
2374 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2375 WithGestureOffset(0, 0, EPSILON),
2376 WithGestureSwipeFingerCount(4),
2377 WithMotionClassification(
2378 MotionClassification::MULTI_FINGER_SWIPE),
2379 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2380 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2381 VariantWith<NotifyMotionArgs>(
2382 AllOf(WithMotionAction(
2383 AMOTION_EVENT_ACTION_POINTER_UP |
2384 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2385 WithGestureOffset(0, 0, EPSILON),
2386 WithGestureSwipeFingerCount(4),
2387 WithMotionClassification(
2388 MotionClassification::MULTI_FINGER_SWIPE),
2389 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2390 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2391 VariantWith<NotifyMotionArgs>(
2392 AllOf(WithMotionAction(
2393 AMOTION_EVENT_ACTION_POINTER_UP |
2394 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2395 WithGestureOffset(0, 0, EPSILON),
2396 WithGestureSwipeFingerCount(4),
2397 WithMotionClassification(
2398 MotionClassification::MULTI_FINGER_SWIPE),
2399 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2400 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2401 VariantWith<NotifyMotionArgs>(
2402 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2403 WithGestureOffset(0, 0, EPSILON),
2404 WithGestureSwipeFingerCount(4),
2405 WithMotionClassification(
2406 MotionClassification::MULTI_FINGER_SWIPE),
2407 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002408 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2409 VariantWith<NotifyMotionArgs>(
2410 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2411 WithCoords(0, 0),
2412 WithMotionClassification(MotionClassification::NONE),
2413 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002414 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002415}
2416
2417TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2418 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2419 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2420 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2421
2422 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2423 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002424 std::list<NotifyArgs> args =
2425 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002426 ASSERT_THAT(args,
2427 ElementsAre(VariantWith<NotifyMotionArgs>(
2428 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2429 WithMotionClassification(MotionClassification::PINCH),
2430 WithGesturePinchScaleFactor(1.0f, EPSILON),
2431 WithCoords(-100, 0), WithPointerCount(1u),
2432 WithToolType(ToolType::FINGER),
2433 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2434 VariantWith<NotifyMotionArgs>(
2435 AllOf(WithMotionAction(
2436 AMOTION_EVENT_ACTION_POINTER_DOWN |
2437 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2438 WithMotionClassification(MotionClassification::PINCH),
2439 WithGesturePinchScaleFactor(1.0f, EPSILON),
2440 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2441 WithToolType(ToolType::FINGER),
2442 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002443
2444 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2445 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002446 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002447 ASSERT_THAT(args,
2448 ElementsAre(VariantWith<NotifyMotionArgs>(
2449 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2450 WithMotionClassification(MotionClassification::PINCH),
2451 WithGesturePinchScaleFactor(0.8f, EPSILON),
2452 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
2453 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2454 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002455
2456 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2457 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002458 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002459 ASSERT_THAT(args,
2460 ElementsAre(VariantWith<NotifyMotionArgs>(
2461 AllOf(WithMotionAction(
2462 AMOTION_EVENT_ACTION_POINTER_UP |
2463 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2464 WithMotionClassification(MotionClassification::PINCH),
2465 WithGesturePinchScaleFactor(1.0f, EPSILON),
2466 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2467 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2468 VariantWith<NotifyMotionArgs>(
2469 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2470 WithMotionClassification(MotionClassification::PINCH),
2471 WithGesturePinchScaleFactor(1.0f, EPSILON),
2472 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002473 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2474 VariantWith<NotifyMotionArgs>(
2475 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2476 WithCoords(0, 0),
2477 WithMotionClassification(MotionClassification::NONE),
2478 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002479 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002480}
2481
2482TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2483 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2484 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2485 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2486
2487 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2488 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002489 std::list<NotifyArgs> args =
2490 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002491 ASSERT_THAT(args,
2492 ElementsAre(VariantWith<NotifyMotionArgs>(
2493 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2494 WithMotionClassification(MotionClassification::PINCH),
2495 WithGesturePinchScaleFactor(1.0f, EPSILON),
2496 WithCoords(-100, 0), WithPointerCount(1u),
2497 WithToolType(ToolType::FINGER),
2498 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2499 VariantWith<NotifyMotionArgs>(
2500 AllOf(WithMotionAction(
2501 AMOTION_EVENT_ACTION_POINTER_DOWN |
2502 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2503 WithMotionClassification(MotionClassification::PINCH),
2504 WithGesturePinchScaleFactor(1.0f, EPSILON),
2505 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2506 WithToolType(ToolType::FINGER),
2507 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002508
2509 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2510 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002511 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002512 ASSERT_THAT(args,
2513 ElementsAre(VariantWith<NotifyMotionArgs>(
2514 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2515 WithMotionClassification(MotionClassification::PINCH),
2516 WithGesturePinchScaleFactor(1.1f, EPSILON),
2517 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
2518 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2519 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002520
2521 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2522 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002523 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002524 ASSERT_THAT(args,
2525 ElementsAre(VariantWith<NotifyMotionArgs>(
2526 AllOf(WithMotionAction(
2527 AMOTION_EVENT_ACTION_POINTER_UP |
2528 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2529 WithMotionClassification(MotionClassification::PINCH),
2530 WithGesturePinchScaleFactor(1.0f, EPSILON),
2531 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2532 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2533 VariantWith<NotifyMotionArgs>(
2534 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2535 WithMotionClassification(MotionClassification::PINCH),
2536 WithGesturePinchScaleFactor(1.0f, EPSILON),
2537 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002538 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2539 VariantWith<NotifyMotionArgs>(
2540 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2541 WithCoords(0, 0),
2542 WithMotionClassification(MotionClassification::NONE),
2543 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002544 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002545}
2546
2547TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2548 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2549 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2550 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2551
2552 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2553 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002554 std::list<NotifyArgs> args =
2555 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002556
2557 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2558 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002559 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002560
2561 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2562 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002563 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002564
2565 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002566 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002567 ASSERT_THAT(args,
2568 ElementsAre(VariantWith<NotifyMotionArgs>(
2569 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002570}
2571
2572TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2573 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2574 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2575 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2576
2577 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2578 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002579 std::list<NotifyArgs> args =
2580 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002581
2582 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2583 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002584 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002585
2586 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2587 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002588 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002589
2590 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2591 // need to use another gesture type, like scroll.
2592 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2593 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002594 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002595 ASSERT_FALSE(args.empty());
2596 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2597}
2598
2599TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2600 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2601 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2602 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2603
2604 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2605 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2606 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002607 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002608
2609 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002610 ASSERT_THAT(args,
2611 ElementsAre(VariantWith<NotifyMotionArgs>(
2612 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2613 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2614 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
2615 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2616 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2617 VariantWith<NotifyMotionArgs>(
2618 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2619 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
2620 WithButtonState(0), WithCoords(0, 0),
2621 WithToolType(ToolType::FINGER),
2622 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2623 VariantWith<NotifyMotionArgs>(
2624 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2625 WithButtonState(0), WithCoords(0, 0),
2626 WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002627 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2628 VariantWith<NotifyMotionArgs>(
2629 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2630 WithButtonState(0), WithCoords(0, 0),
2631 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002632 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002633}
2634
2635TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2636 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2637 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2638 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2639
2640 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002641 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002642
2643 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002644 ASSERT_THAT(args,
2645 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002646 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2647 WithCoords(0, -10),
2648 WithGestureScrollDistance(0, 0, EPSILON),
2649 WithMotionClassification(
2650 MotionClassification::TWO_FINGER_SWIPE),
2651 WithToolType(ToolType::FINGER),
2652 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2653 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2654 VariantWith<NotifyMotionArgs>(
2655 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2656 WithCoords(0, 0),
2657 WithMotionClassification(MotionClassification::NONE),
2658 WithToolType(ToolType::FINGER),
2659 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002660}
2661
2662TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2663 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2664 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2665 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2666
2667 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2668 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002669 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002670
2671 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002672 ASSERT_THAT(args,
2673 ElementsAre(VariantWith<NotifyMotionArgs>(
2674 AllOf(WithMotionAction(
2675 AMOTION_EVENT_ACTION_POINTER_UP |
2676 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2677 WithGestureOffset(0, 0, EPSILON),
2678 WithMotionClassification(
2679 MotionClassification::MULTI_FINGER_SWIPE),
2680 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2681 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2682 VariantWith<NotifyMotionArgs>(
2683 AllOf(WithMotionAction(
2684 AMOTION_EVENT_ACTION_POINTER_UP |
2685 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2686 WithGestureOffset(0, 0, EPSILON),
2687 WithMotionClassification(
2688 MotionClassification::MULTI_FINGER_SWIPE),
2689 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2690 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2691 VariantWith<NotifyMotionArgs>(
2692 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2693 WithGestureOffset(0, 0, EPSILON),
2694 WithMotionClassification(
2695 MotionClassification::MULTI_FINGER_SWIPE),
2696 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002697 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2698 VariantWith<NotifyMotionArgs>(
2699 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2700 WithMotionClassification(MotionClassification::NONE),
2701 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002702 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002703}
2704
2705TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2706 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2707 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2708 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2709
2710 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2711 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002712 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002713
2714 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002715 ASSERT_THAT(args,
2716 ElementsAre(VariantWith<NotifyMotionArgs>(
2717 AllOf(WithMotionAction(
2718 AMOTION_EVENT_ACTION_POINTER_UP |
2719 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2720 WithMotionClassification(MotionClassification::PINCH),
2721 WithGesturePinchScaleFactor(1.0f, EPSILON),
2722 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2723 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2724 VariantWith<NotifyMotionArgs>(
2725 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2726 WithMotionClassification(MotionClassification::PINCH),
2727 WithGesturePinchScaleFactor(1.0f, EPSILON),
2728 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002729 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2730 VariantWith<NotifyMotionArgs>(
2731 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2732 WithCoords(0, 0),
2733 WithMotionClassification(MotionClassification::NONE),
2734 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002735 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002736}
2737
2738TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2739 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2740 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2741 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2742
2743 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2744 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002745 std::list<NotifyArgs> args =
2746 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002747
2748 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00002749 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
Byoungho Jungee6268f2023-10-30 17:27:26 +09002750 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2751 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2752}
2753
Harry Cutts39648ab2024-02-15 14:23:50 +00002754TEST_F(GestureConverterTestWithChoreographer, FlingTapDownAfterScrollStopsFling) {
2755 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2756 input_flags::enable_touchpad_fling_stop(true);
2757 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2758 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2759
2760 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
2761 std::list<NotifyArgs> args =
2762 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
2763 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
2764 GESTURES_FLING_START);
2765 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
2766
2767 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2768 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
2769 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
2770 ASSERT_THAT(args,
2771 ElementsAre(VariantWith<NotifyMotionArgs>(
2772 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
2773 VariantWith<NotifyMotionArgs>(
2774 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
2775 VariantWith<NotifyMotionArgs>(
2776 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
2777 VariantWith<NotifyMotionArgs>(
2778 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2779 WithMotionClassification(MotionClassification::NONE)))));
2780 ASSERT_THAT(args,
2781 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2782 WithToolType(ToolType::FINGER),
2783 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
2784}
2785
Byoungho Jungee6268f2023-10-30 17:27:26 +09002786TEST_F(GestureConverterTestWithChoreographer, Tap) {
2787 // Tap should produce button press/release events
2788 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2789 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2790 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2791
2792 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2793 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002794 std::list<NotifyArgs> args =
2795 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002796 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002797
2798 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2799 /* down= */ GESTURES_BUTTON_LEFT,
2800 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002801 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002802
Harry Cutts5f26e952023-11-30 18:20:27 +00002803 ASSERT_THAT(args,
2804 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002805 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2806 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2807 WithToolType(ToolType::FINGER), WithButtonState(0),
2808 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2809 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002810 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2811 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2812 WithToolType(ToolType::FINGER),
2813 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2814 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2815 VariantWith<NotifyMotionArgs>(
2816 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2817 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2818 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2819 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2820 WithToolType(ToolType::FINGER),
2821 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2822 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2823 VariantWith<NotifyMotionArgs>(
2824 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2825 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2826 WithButtonState(0), WithCoords(0, 0),
2827 WithRelativeMotion(0.f, 0.f),
2828 WithToolType(ToolType::FINGER), WithButtonState(0),
2829 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2830 VariantWith<NotifyMotionArgs>(
2831 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2832 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2833 WithToolType(ToolType::FINGER), WithButtonState(0),
2834 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2835 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002836 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002837 WithCoords(0, 0), WithRelativeMotion(0, 0),
2838 WithToolType(ToolType::FINGER), WithButtonState(0),
2839 WithPressure(0.0f),
2840 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002841}
2842
2843TEST_F(GestureConverterTestWithChoreographer, Click) {
2844 // Click should produce button press/release events
2845 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2846 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2847 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2848
2849 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2850 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002851 std::list<NotifyArgs> args =
2852 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002853 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002854
2855 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2856 /* down= */ GESTURES_BUTTON_LEFT,
2857 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002858 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002859
Harry Cutts5f26e952023-11-30 18:20:27 +00002860 ASSERT_THAT(args,
2861 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002862 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2863 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2864 WithToolType(ToolType::FINGER), WithButtonState(0),
2865 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2866 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002867 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2868 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2869 WithToolType(ToolType::FINGER),
2870 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2871 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2872 VariantWith<NotifyMotionArgs>(
2873 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2874 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2875 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2876 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2877 WithToolType(ToolType::FINGER),
2878 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2879 WithPressure(1.0f),
2880 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002881
2882 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2883 /* down= */ GESTURES_BUTTON_NONE,
2884 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002885 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002886
Harry Cutts5f26e952023-11-30 18:20:27 +00002887 ASSERT_THAT(args,
2888 ElementsAre(VariantWith<NotifyMotionArgs>(
2889 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2890 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2891 WithButtonState(0), WithCoords(0, 0),
2892 WithRelativeMotion(0.f, 0.f),
2893 WithToolType(ToolType::FINGER), WithButtonState(0),
2894 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2895 VariantWith<NotifyMotionArgs>(
2896 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2897 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2898 WithToolType(ToolType::FINGER), WithButtonState(0),
2899 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2900 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002901 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002902 WithCoords(0, 0), WithRelativeMotion(0, 0),
2903 WithToolType(ToolType::FINGER), WithButtonState(0),
2904 WithPressure(0.0f),
2905 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002906}
2907
2908TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002909 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2910 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2911 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2912
Byoungho Jungee6268f2023-10-30 17:27:26 +09002913 // Tap should be ignored when disabled
2914 mReader->getContext()->setPreventingTouchpadTaps(true);
2915
2916 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2917 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2918 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2919
Arpit Singh82b27a02023-10-16 11:02:19 +00002920 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002921 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002922 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002923 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002924 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002925
Arpit Singh82b27a02023-10-16 11:02:19 +00002926 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002927 /* down= */ GESTURES_BUTTON_LEFT,
2928 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002929 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002930
2931 // no events should be generated
2932 ASSERT_EQ(0u, args.size());
2933
2934 // Future taps should be re-enabled
2935 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2936}
2937
Arpit Singh82b27a02023-10-16 11:02:19 +00002938TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2939 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2940 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2941
2942 // Tap should be ignored when disabled
2943 mReader->getContext()->setPreventingTouchpadTaps(true);
2944
2945 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2946 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2947 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2948
2949 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2950 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2951 std::list<NotifyArgs> args =
2952 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002953 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00002954
2955 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2956 /* down= */ GESTURES_BUTTON_LEFT,
2957 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2958 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2959
2960 // no events should be generated
2961 ASSERT_EQ(0u, args.size());
2962
2963 // Future taps should be re-enabled
2964 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2965
2966 // taps before the threshold should still be ignored
2967 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2968 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2969 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2970 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2971
2972 ASSERT_EQ(1u, args.size());
2973 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2974 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2975
2976 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2977 /* down= */ GESTURES_BUTTON_LEFT,
2978 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2979 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2980
2981 // no events should be generated
2982 ASSERT_EQ(0u, args.size());
2983
2984 // taps after the threshold should be recognised
2985 currentTime += 1;
2986 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2987 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2988 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2989
2990 ASSERT_EQ(1u, args.size());
2991 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2992 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2993
2994 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2995 /* down= */ GESTURES_BUTTON_LEFT,
2996 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2997 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2998
Harry Cutts379ea422023-12-21 15:31:47 +00002999 ASSERT_EQ(6u, args.size());
3000 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3001 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
3002 WithRelativeMotion(0.f, 0.f), WithButtonState(0)));
3003 args.pop_front();
Arpit Singh82b27a02023-10-16 11:02:19 +00003004 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3005 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
3006 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
3007 args.pop_front();
3008 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3009 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
3010 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
3011 WithRelativeMotion(0.f, 0.f)));
3012 args.pop_front();
3013 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3014 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
3015 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
3016 WithRelativeMotion(0.f, 0.f)));
3017 args.pop_front();
3018 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
3019 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
3020 WithButtonState(0)));
3021 args.pop_front();
3022 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00003023 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0),
Arpit Singh82b27a02023-10-16 11:02:19 +00003024 WithButtonState(0)));
3025}
3026
Byoungho Jungee6268f2023-10-30 17:27:26 +09003027TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
3028 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
3029 // Click should still produce button press/release events
3030 mReader->getContext()->setPreventingTouchpadTaps(true);
3031
3032 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3033 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3034 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3035
3036 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
3037 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00003038 std::list<NotifyArgs> args =
3039 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00003040 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09003041
3042 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
3043 /* down= */ GESTURES_BUTTON_LEFT,
3044 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00003045 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09003046
Harry Cutts5f26e952023-11-30 18:20:27 +00003047 ASSERT_THAT(args,
3048 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003049 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
3050 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3051 WithToolType(ToolType::FINGER), WithButtonState(0),
3052 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3053 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00003054 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
3055 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3056 WithToolType(ToolType::FINGER),
3057 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
3058 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3059 VariantWith<NotifyMotionArgs>(
3060 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
3061 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
3062 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
3063 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3064 WithToolType(ToolType::FINGER),
3065 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
3066 WithPressure(1.0f),
3067 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09003068
3069 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
3070 /* down= */ GESTURES_BUTTON_NONE,
3071 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00003072 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09003073
Harry Cutts5f26e952023-11-30 18:20:27 +00003074 ASSERT_THAT(args,
3075 ElementsAre(VariantWith<NotifyMotionArgs>(
3076 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
3077 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
3078 WithButtonState(0), WithCoords(0, 0),
3079 WithRelativeMotion(0.f, 0.f),
3080 WithToolType(ToolType::FINGER), WithButtonState(0),
3081 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3082 VariantWith<NotifyMotionArgs>(
3083 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
3084 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3085 WithToolType(ToolType::FINGER), WithButtonState(0),
3086 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3087 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003088 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00003089 WithCoords(0, 0), WithRelativeMotion(0, 0),
3090 WithToolType(ToolType::FINGER), WithButtonState(0),
3091 WithPressure(0.0f),
3092 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09003093
3094 // Future taps should be re-enabled
3095 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
3096}
3097
3098TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
3099 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
3100 // initially disable tap-to-click
3101 mReader->getContext()->setPreventingTouchpadTaps(true);
3102
3103 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3104 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3105 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3106
3107 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00003108 std::list<NotifyArgs> args =
3109 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00003110 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09003111
3112 // Future taps should be re-enabled
3113 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
3114}
3115
Arpit Singh33a10a62023-10-12 13:06:54 +00003116TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
3117 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
3118 const nsecs_t gestureStartTime = 1000;
3119 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3120 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3121 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3122
3123 // Start a move gesture at gestureStartTime
3124 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
3125 std::list<NotifyArgs> args =
3126 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003127 ASSERT_THAT(args,
3128 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003129 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
3130 VariantWith<NotifyMotionArgs>(
3131 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003132
3133 // Key presses with IME connection should cancel ongoing move gesture
3134 nsecs_t currentTime = gestureStartTime + 100;
3135 mFakePolicy->setIsInputMethodConnectionActive(true);
3136 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
3137 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3138 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003139 ASSERT_THAT(args,
3140 ElementsAre(VariantWith<NotifyMotionArgs>(
3141 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003142
3143 // any updates in existing move gesture should be ignored
3144 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3145 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
3146 ASSERT_EQ(0u, args.size());
3147
3148 // New gesture should not be affected
3149 currentTime += 100;
3150 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3151 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003152 ASSERT_THAT(args,
3153 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003154 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
3155 VariantWith<NotifyMotionArgs>(
3156 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003157}
3158
Harry Cutts4fb941a2022-12-14 19:14:04 +00003159} // namespace android