blob: 163076974ff68e0123c67da427805d4a34aadc45 [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 Cutts5f26e952023-11-30 18:20:27 +000050using testing::ElementsAre;
51using testing::VariantWith;
Harry Cutts4fb941a2022-12-14 19:14:04 +000052
Byoungho Jungee6268f2023-10-30 17:27:26 +090053class GestureConverterTestBase : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000054protected:
55 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000056 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000057 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000058 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000059 static constexpr float POINTER_Y = 200;
60
61 void SetUp() {
62 mFakeEventHub = std::make_unique<FakeEventHub>();
63 mFakePolicy = sp<FakeInputReaderPolicy>::make();
64 mFakeListener = std::make_unique<TestInputListener>();
65 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
66 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000067 mDevice = newDevice();
68 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
69 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000070
71 mFakePointerController = std::make_shared<FakePointerController>();
72 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
73 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
74 mFakePolicy->setPointerController(mFakePointerController);
75 }
76
Harry Cuttsc5748d12022-12-02 17:30:18 +000077 std::shared_ptr<InputDevice> newDevice() {
78 InputDeviceIdentifier identifier;
79 identifier.name = "device";
80 identifier.location = "USB1";
81 identifier.bus = 0;
82 std::shared_ptr<InputDevice> device =
83 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
84 identifier);
85 mReader->pushNextDevice(device);
86 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
87 identifier.bus);
88 mReader->loopOnce();
89 return device;
90 }
91
Harry Cutts4fb941a2022-12-14 19:14:04 +000092 std::shared_ptr<FakeEventHub> mFakeEventHub;
93 sp<FakeInputReaderPolicy> mFakePolicy;
94 std::unique_ptr<TestInputListener> mFakeListener;
95 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000096 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000097 std::shared_ptr<FakePointerController> mFakePointerController;
98};
99
Byoungho Jungee6268f2023-10-30 17:27:26 +0900100class GestureConverterTest : public GestureConverterTestBase {
101protected:
102 void SetUp() override {
103 input_flags::enable_pointer_choreographer(false);
104 GestureConverterTestBase::SetUp();
105 }
106};
107
Harry Cutts4fb941a2022-12-14 19:14:04 +0000108TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000109 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
110 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000111 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000112
113 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000114 std::list<NotifyArgs> args =
115 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000116 ASSERT_THAT(args,
117 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000118 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
119 WithCoords(POINTER_X, POINTER_Y),
120 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
121 WithDisplayId(ADISPLAY_ID_DEFAULT))),
122 VariantWith<NotifyMotionArgs>(
123 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
124 WithCoords(POINTER_X - 5, POINTER_Y + 10),
125 WithRelativeMotion(-5, 10),
126 WithToolType(ToolType::FINGER), WithButtonState(0),
127 WithPressure(0.0f),
128 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000129
Harry Cuttsb1e83552022-12-20 11:02:26 +0000130 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts379ea422023-12-21 15:31:47 +0000131
132 // The same gesture again should only repeat the HOVER_MOVE and cursor position change, not the
133 // HOVER_ENTER.
134 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
135 ASSERT_THAT(args,
136 ElementsAre(VariantWith<NotifyMotionArgs>(
137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
138 WithCoords(POINTER_X - 10, POINTER_Y + 20),
139 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
140 WithButtonState(0), WithPressure(0.0f),
141 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
142
143 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 10, POINTER_Y + 20));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000144}
145
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000146TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000147 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
148 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000149 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000150 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000151
152 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000153 std::list<NotifyArgs> args =
154 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000155 ASSERT_THAT(args,
156 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000157 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
158 WithCoords(POINTER_X, POINTER_Y),
159 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
160 WithDisplayId(ADISPLAY_ID_DEFAULT))),
161 VariantWith<NotifyMotionArgs>(
162 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
163 WithCoords(POINTER_X + 10, POINTER_Y + 5),
164 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER),
165 WithButtonState(0), WithPressure(0.0f),
166 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000167
Harry Cuttsb1e83552022-12-20 11:02:26 +0000168 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000169}
170
Harry Cutts4fb941a2022-12-14 19:14:04 +0000171TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000172 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
173 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000174 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000175
176 // Press left and right buttons at once
177 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
178 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
179 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000180 std::list<NotifyArgs> args =
181 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000182 ASSERT_THAT(args,
183 ElementsAre(VariantWith<NotifyMotionArgs>(
184 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
185 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
186 AMOTION_EVENT_BUTTON_SECONDARY),
187 WithCoords(POINTER_X, POINTER_Y),
188 WithToolType(ToolType::FINGER),
189 WithDisplayId(ADISPLAY_ID_DEFAULT))),
190 VariantWith<NotifyMotionArgs>(
191 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
192 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
193 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
194 WithCoords(POINTER_X, POINTER_Y),
195 WithToolType(ToolType::FINGER),
196 WithDisplayId(ADISPLAY_ID_DEFAULT))),
197 VariantWith<NotifyMotionArgs>(
198 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
199 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
200 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
201 AMOTION_EVENT_BUTTON_SECONDARY),
202 WithCoords(POINTER_X, POINTER_Y),
203 WithToolType(ToolType::FINGER),
204 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000205
206 // Then release the left button
207 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
208 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
209 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000210 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000211 ASSERT_THAT(args,
212 ElementsAre(VariantWith<NotifyMotionArgs>(
213 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
214 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
215 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
216 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
217 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000218
219 // Finally release the right button
220 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
221 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
222 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000223 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000224 ASSERT_THAT(args,
225 ElementsAre(VariantWith<NotifyMotionArgs>(
226 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
227 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
228 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
229 WithToolType(ToolType::FINGER),
230 WithDisplayId(ADISPLAY_ID_DEFAULT))),
231 VariantWith<NotifyMotionArgs>(
232 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
233 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
234 WithToolType(ToolType::FINGER),
235 WithDisplayId(ADISPLAY_ID_DEFAULT))),
236 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000237 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000238 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
239 WithToolType(ToolType::FINGER),
240 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000241}
242
Harry Cutts379ea422023-12-21 15:31:47 +0000243TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) {
244 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
245 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
246 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
247
248 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
249 std::list<NotifyArgs> args =
250 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
251
252 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
253 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
254 /*is_tap=*/false);
255 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
256 ASSERT_THAT(args.front(),
257 VariantWith<NotifyMotionArgs>(
258 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
259 WithCoords(POINTER_X - 5, POINTER_Y + 10),
260 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))));
261}
262
Harry Cutts4fb941a2022-12-14 19:14:04 +0000263TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000264 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
265 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000266 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000267
268 // Press the button
269 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
270 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
271 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000272 std::list<NotifyArgs> args =
273 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000274 ASSERT_THAT(args,
275 ElementsAre(VariantWith<NotifyMotionArgs>(
276 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
277 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
278 WithCoords(POINTER_X, POINTER_Y),
279 WithToolType(ToolType::FINGER),
280 WithDisplayId(ADISPLAY_ID_DEFAULT))),
281 VariantWith<NotifyMotionArgs>(
282 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
283 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
284 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
285 WithCoords(POINTER_X, POINTER_Y),
286 WithToolType(ToolType::FINGER),
287 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000288
289 // Move
290 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000291 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000292 ASSERT_THAT(args,
293 ElementsAre(VariantWith<NotifyMotionArgs>(
294 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
295 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
296 WithToolType(ToolType::FINGER),
297 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
298 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000299
Harry Cuttsb1e83552022-12-20 11:02:26 +0000300 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000301
302 // Release the button
303 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
304 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
305 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000306 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000307 ASSERT_THAT(args,
308 ElementsAre(VariantWith<NotifyMotionArgs>(
309 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
310 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
311 WithButtonState(0),
312 WithCoords(POINTER_X - 5, POINTER_Y + 10),
313 WithToolType(ToolType::FINGER),
314 WithDisplayId(ADISPLAY_ID_DEFAULT))),
315 VariantWith<NotifyMotionArgs>(
316 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
317 WithButtonState(0),
318 WithCoords(POINTER_X - 5, POINTER_Y + 10),
319 WithToolType(ToolType::FINGER),
320 WithDisplayId(ADISPLAY_ID_DEFAULT))),
321 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000322 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000323 WithButtonState(0),
324 WithCoords(POINTER_X - 5, POINTER_Y + 10),
325 WithToolType(ToolType::FINGER),
326 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000327}
328
Harry Cuttsef400b22022-12-16 21:26:24 +0000329TEST_F(GestureConverterTest, Scroll) {
330 const nsecs_t downTime = 12345;
331 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
332 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000333 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000334
Harry Cuttsa546ba82023-01-13 17:21:00 +0000335 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000336 std::list<NotifyArgs> args =
337 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000338 ASSERT_THAT(args,
339 ElementsAre(VariantWith<NotifyMotionArgs>(
340 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
341 WithCoords(POINTER_X, POINTER_Y),
342 WithGestureScrollDistance(0, 0, EPSILON),
343 WithMotionClassification(
344 MotionClassification::TWO_FINGER_SWIPE),
345 WithToolType(ToolType::FINGER), WithDownTime(downTime),
346 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
347 WithDisplayId(ADISPLAY_ID_DEFAULT))),
348 VariantWith<NotifyMotionArgs>(
349 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
350 WithCoords(POINTER_X, POINTER_Y - 10),
351 WithGestureScrollDistance(0, 10, EPSILON),
352 WithMotionClassification(
353 MotionClassification::TWO_FINGER_SWIPE),
354 WithToolType(ToolType::FINGER),
355 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
356 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000357
Harry Cuttsa546ba82023-01-13 17:21:00 +0000358 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000359 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000360 ASSERT_THAT(args,
361 ElementsAre(VariantWith<NotifyMotionArgs>(
362 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
363 WithCoords(POINTER_X, POINTER_Y - 15),
364 WithGestureScrollDistance(0, 5, EPSILON),
365 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
366 WithToolType(ToolType::FINGER),
367 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
368 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000369
370 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
371 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000372 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000373 ASSERT_THAT(args,
374 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000375 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
376 WithCoords(POINTER_X, POINTER_Y - 15),
377 WithGestureScrollDistance(0, 0, EPSILON),
378 WithMotionClassification(
379 MotionClassification::TWO_FINGER_SWIPE),
380 WithToolType(ToolType::FINGER),
381 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
382 WithDisplayId(ADISPLAY_ID_DEFAULT))),
383 VariantWith<NotifyMotionArgs>(
384 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
385 WithCoords(POINTER_X, POINTER_Y),
386 WithMotionClassification(MotionClassification::NONE),
387 WithToolType(ToolType::FINGER),
388 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000389}
390
391TEST_F(GestureConverterTest, Scroll_Rotated) {
392 const nsecs_t downTime = 12345;
393 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
394 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
395 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000396 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000397
Harry Cuttsa546ba82023-01-13 17:21:00 +0000398 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000399 std::list<NotifyArgs> args =
400 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000401 ASSERT_THAT(args,
402 ElementsAre(VariantWith<NotifyMotionArgs>(
403 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
404 WithCoords(POINTER_X, POINTER_Y),
405 WithGestureScrollDistance(0, 0, EPSILON),
406 WithMotionClassification(
407 MotionClassification::TWO_FINGER_SWIPE),
408 WithToolType(ToolType::FINGER), WithDownTime(downTime),
409 WithDisplayId(ADISPLAY_ID_DEFAULT))),
410 VariantWith<NotifyMotionArgs>(
411 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
412 WithCoords(POINTER_X - 10, POINTER_Y),
413 WithGestureScrollDistance(0, 10, EPSILON),
414 WithMotionClassification(
415 MotionClassification::TWO_FINGER_SWIPE),
416 WithToolType(ToolType::FINGER),
417 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000418
Harry Cuttsa546ba82023-01-13 17:21:00 +0000419 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000420 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000421 ASSERT_THAT(args,
422 ElementsAre(VariantWith<NotifyMotionArgs>(
423 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
424 WithCoords(POINTER_X - 15, POINTER_Y),
425 WithGestureScrollDistance(0, 5, EPSILON),
426 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
427 WithToolType(ToolType::FINGER),
428 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000429 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
430 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000431 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000432 ASSERT_THAT(args,
433 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000434 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
435 WithCoords(POINTER_X - 15, POINTER_Y),
436 WithGestureScrollDistance(0, 0, EPSILON),
437 WithMotionClassification(
438 MotionClassification::TWO_FINGER_SWIPE),
439 WithToolType(ToolType::FINGER),
440 WithDisplayId(ADISPLAY_ID_DEFAULT))),
441 VariantWith<NotifyMotionArgs>(
442 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
443 WithCoords(POINTER_X, POINTER_Y),
444 WithMotionClassification(MotionClassification::NONE),
445 WithToolType(ToolType::FINGER),
446 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000447}
448
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000449TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000450 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
451 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000452 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000453
Harry Cuttsa546ba82023-01-13 17:21:00 +0000454 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000455 std::list<NotifyArgs> args =
456 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000457
Harry Cuttsa546ba82023-01-13 17:21:00 +0000458 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000459 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000460
461 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
462 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000463 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000464
465 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000466 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000467 ASSERT_THAT(args,
468 ElementsAre(VariantWith<NotifyMotionArgs>(
469 AllOf(WithMotionClassification(MotionClassification::NONE),
470 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000471}
472
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000473TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000474 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
475 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000476 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000477
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000478 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000479 std::list<NotifyArgs> args =
480 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000481
482 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000483 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000484
485 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
486 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000487 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000488
489 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
490 // need to use another gesture type, like pinch.
491 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
492 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000493 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000494 ASSERT_FALSE(args.empty());
495 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
496}
497
498TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
499 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
500 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000501 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000502
503 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
504 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000505 std::list<NotifyArgs> args =
506 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000507
508 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000509 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000510
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000511 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
512 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000513 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000514 ASSERT_EQ(1u, args.size());
Harry Cutts5f26e952023-11-30 18:20:27 +0000515 ASSERT_THAT(args,
516 ElementsAre(VariantWith<NotifyMotionArgs>(
517 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000518}
519
Harry Cutts8743f182023-05-17 12:03:49 +0000520TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000521 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
522 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000523 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000524
525 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
526 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000527 std::list<NotifyArgs> args =
528 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000529
530 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000531 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000532
533 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
534 // need to use another gesture type, like pinch.
535 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
536 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000537 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000538 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000539 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
540 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000541}
542
543TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
544 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
545 // start swiping up and then start moving left or right, it'll return gesture events with only Y
546 // deltas until you lift your fingers and start swiping again. That's why each of these tests
547 // only checks movement in one dimension.
548 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
549 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000550 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000551
552 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
553 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000554 std::list<NotifyArgs> args =
555 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000556 ASSERT_EQ(4u, args.size());
557
558 // Three fake fingers should be created. We don't actually care where they are, so long as they
559 // move appropriately.
560 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
561 ASSERT_THAT(arg,
562 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000563 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000564 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000565 WithPointerCount(1u), WithToolType(ToolType::FINGER),
566 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000567 PointerCoords finger0Start = arg.pointerCoords[0];
568 args.pop_front();
569 arg = std::get<NotifyMotionArgs>(args.front());
570 ASSERT_THAT(arg,
571 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
572 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000573 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000574 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000575 WithPointerCount(2u), WithToolType(ToolType::FINGER),
576 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000577 PointerCoords finger1Start = arg.pointerCoords[1];
578 args.pop_front();
579 arg = std::get<NotifyMotionArgs>(args.front());
580 ASSERT_THAT(arg,
581 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
582 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000583 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000584 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000585 WithPointerCount(3u), WithToolType(ToolType::FINGER),
586 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000587 PointerCoords finger2Start = arg.pointerCoords[2];
588 args.pop_front();
589
590 arg = std::get<NotifyMotionArgs>(args.front());
591 ASSERT_THAT(arg,
592 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000593 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000594 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000595 WithPointerCount(3u), WithToolType(ToolType::FINGER),
596 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000597 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
598 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
599 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
600 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
601 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
602 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
603
604 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
605 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000606 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000607 ASSERT_EQ(1u, args.size());
608 arg = std::get<NotifyMotionArgs>(args.front());
609 ASSERT_THAT(arg,
610 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000611 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000612 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000613 WithPointerCount(3u), WithToolType(ToolType::FINGER),
614 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000615 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
616 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
617 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
618 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
619 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
620 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
621
622 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000623 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000624 ASSERT_THAT(args,
625 ElementsAre(VariantWith<NotifyMotionArgs>(
626 AllOf(WithMotionAction(
627 AMOTION_EVENT_ACTION_POINTER_UP |
628 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
629 WithGestureOffset(0, 0, EPSILON),
630 WithGestureSwipeFingerCount(3),
631 WithMotionClassification(
632 MotionClassification::MULTI_FINGER_SWIPE),
633 WithPointerCount(3u), WithToolType(ToolType::FINGER),
634 WithDisplayId(ADISPLAY_ID_DEFAULT))),
635 VariantWith<NotifyMotionArgs>(
636 AllOf(WithMotionAction(
637 AMOTION_EVENT_ACTION_POINTER_UP |
638 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
639 WithGestureOffset(0, 0, EPSILON),
640 WithGestureSwipeFingerCount(3),
641 WithMotionClassification(
642 MotionClassification::MULTI_FINGER_SWIPE),
643 WithPointerCount(2u), WithToolType(ToolType::FINGER),
644 WithDisplayId(ADISPLAY_ID_DEFAULT))),
645 VariantWith<NotifyMotionArgs>(
646 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
647 WithGestureOffset(0, 0, EPSILON),
648 WithGestureSwipeFingerCount(3),
649 WithMotionClassification(
650 MotionClassification::MULTI_FINGER_SWIPE),
651 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000652 WithDisplayId(ADISPLAY_ID_DEFAULT))),
653 VariantWith<NotifyMotionArgs>(
654 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
655 WithCoords(POINTER_X, POINTER_Y),
656 WithMotionClassification(MotionClassification::NONE),
657 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000658 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000659}
660
Harry Cutts94f5bd52023-01-06 18:02:18 +0000661TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
662 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
663 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
664 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000665 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000666
667 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
668 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000669 std::list<NotifyArgs> args =
670 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000671 ASSERT_EQ(4u, args.size());
672
673 // Three fake fingers should be created. We don't actually care where they are, so long as they
674 // move appropriately.
675 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
676 ASSERT_THAT(arg,
677 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000678 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000679 PointerCoords finger0Start = arg.pointerCoords[0];
680 args.pop_front();
681 arg = std::get<NotifyMotionArgs>(args.front());
682 ASSERT_THAT(arg,
683 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
684 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000685 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
686 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000687 PointerCoords finger1Start = arg.pointerCoords[1];
688 args.pop_front();
689 arg = std::get<NotifyMotionArgs>(args.front());
690 ASSERT_THAT(arg,
691 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
692 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000693 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
694 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000695 PointerCoords finger2Start = arg.pointerCoords[2];
696 args.pop_front();
697
698 arg = std::get<NotifyMotionArgs>(args.front());
699 ASSERT_THAT(arg,
700 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000701 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
702 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000703 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
704 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
705 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
706 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
707 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
708 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
709
710 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
711 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000712 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000713 ASSERT_EQ(1u, args.size());
714 arg = std::get<NotifyMotionArgs>(args.front());
715 ASSERT_THAT(arg,
716 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000717 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
718 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000719 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
720 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
721 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
722 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
723 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
724 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
725
726 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000727 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000728 ASSERT_THAT(args,
729 ElementsAre(VariantWith<NotifyMotionArgs>(
730 AllOf(WithMotionAction(
731 AMOTION_EVENT_ACTION_POINTER_UP |
732 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
733 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
734 WithDisplayId(ADISPLAY_ID_DEFAULT))),
735 VariantWith<NotifyMotionArgs>(
736 AllOf(WithMotionAction(
737 AMOTION_EVENT_ACTION_POINTER_UP |
738 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
739 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
740 WithDisplayId(ADISPLAY_ID_DEFAULT))),
741 VariantWith<NotifyMotionArgs>(
742 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
743 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
Harry Cutts379ea422023-12-21 15:31:47 +0000744 WithDisplayId(ADISPLAY_ID_DEFAULT))),
745 VariantWith<NotifyMotionArgs>(
746 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000747 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000748}
749
Harry Cuttsc5748d12022-12-02 17:30:18 +0000750TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
751 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
752 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000753 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000754
755 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
756 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000757 std::list<NotifyArgs> args =
758 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000759 ASSERT_EQ(5u, args.size());
760
761 // Four fake fingers should be created. We don't actually care where they are, so long as they
762 // move appropriately.
763 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
764 ASSERT_THAT(arg,
765 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000766 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000767 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000768 WithPointerCount(1u), WithToolType(ToolType::FINGER),
769 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000770 PointerCoords finger0Start = arg.pointerCoords[0];
771 args.pop_front();
772 arg = std::get<NotifyMotionArgs>(args.front());
773 ASSERT_THAT(arg,
774 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
775 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000776 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000777 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000778 WithPointerCount(2u), WithToolType(ToolType::FINGER),
779 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000780 PointerCoords finger1Start = arg.pointerCoords[1];
781 args.pop_front();
782 arg = std::get<NotifyMotionArgs>(args.front());
783 ASSERT_THAT(arg,
784 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
785 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000786 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000787 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000788 WithPointerCount(3u), WithToolType(ToolType::FINGER),
789 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000790 PointerCoords finger2Start = arg.pointerCoords[2];
791 args.pop_front();
792 arg = std::get<NotifyMotionArgs>(args.front());
793 ASSERT_THAT(arg,
794 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
795 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000796 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000797 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000798 WithPointerCount(4u), WithToolType(ToolType::FINGER),
799 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000800 PointerCoords finger3Start = arg.pointerCoords[3];
801 args.pop_front();
802
803 arg = std::get<NotifyMotionArgs>(args.front());
804 ASSERT_THAT(arg,
805 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000806 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000807 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000808 WithPointerCount(4u), WithToolType(ToolType::FINGER),
809 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000810 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
811 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
812 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
813 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
814 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
815 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
816 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
817 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
818
819 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
820 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000821 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000822 ASSERT_EQ(1u, args.size());
823 arg = std::get<NotifyMotionArgs>(args.front());
824 ASSERT_THAT(arg,
825 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000826 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000827 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000828 WithPointerCount(4u), WithToolType(ToolType::FINGER),
829 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000830 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
831 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
832 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
833 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
834 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
835 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
836 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
837 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
838
839 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000840 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000841 ASSERT_THAT(args,
842 ElementsAre(VariantWith<NotifyMotionArgs>(
843 AllOf(WithMotionAction(
844 AMOTION_EVENT_ACTION_POINTER_UP |
845 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
846 WithGestureOffset(0, 0, EPSILON),
847 WithGestureSwipeFingerCount(4),
848 WithMotionClassification(
849 MotionClassification::MULTI_FINGER_SWIPE),
850 WithPointerCount(4u), WithToolType(ToolType::FINGER),
851 WithDisplayId(ADISPLAY_ID_DEFAULT))),
852 VariantWith<NotifyMotionArgs>(
853 AllOf(WithMotionAction(
854 AMOTION_EVENT_ACTION_POINTER_UP |
855 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
856 WithGestureOffset(0, 0, EPSILON),
857 WithGestureSwipeFingerCount(4),
858 WithMotionClassification(
859 MotionClassification::MULTI_FINGER_SWIPE),
860 WithPointerCount(3u), WithToolType(ToolType::FINGER),
861 WithDisplayId(ADISPLAY_ID_DEFAULT))),
862 VariantWith<NotifyMotionArgs>(
863 AllOf(WithMotionAction(
864 AMOTION_EVENT_ACTION_POINTER_UP |
865 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
866 WithGestureOffset(0, 0, EPSILON),
867 WithGestureSwipeFingerCount(4),
868 WithMotionClassification(
869 MotionClassification::MULTI_FINGER_SWIPE),
870 WithPointerCount(2u), WithToolType(ToolType::FINGER),
871 WithDisplayId(ADISPLAY_ID_DEFAULT))),
872 VariantWith<NotifyMotionArgs>(
873 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
874 WithGestureOffset(0, 0, EPSILON),
875 WithGestureSwipeFingerCount(4),
876 WithMotionClassification(
877 MotionClassification::MULTI_FINGER_SWIPE),
878 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000879 WithDisplayId(ADISPLAY_ID_DEFAULT))),
880 VariantWith<NotifyMotionArgs>(
881 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
882 WithCoords(POINTER_X, POINTER_Y),
883 WithMotionClassification(MotionClassification::NONE),
884 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000885 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000886}
887
Harry Cuttsb1e83552022-12-20 11:02:26 +0000888TEST_F(GestureConverterTest, Pinch_Inwards) {
889 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
890 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000891 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000892
893 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
894 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000895 std::list<NotifyArgs> args =
896 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000897 ASSERT_THAT(args,
898 ElementsAre(VariantWith<NotifyMotionArgs>(
899 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
900 WithMotionClassification(MotionClassification::PINCH),
901 WithGesturePinchScaleFactor(1.0f, EPSILON),
902 WithCoords(POINTER_X - 100, POINTER_Y),
903 WithPointerCount(1u), WithToolType(ToolType::FINGER),
904 WithDisplayId(ADISPLAY_ID_DEFAULT))),
905 VariantWith<NotifyMotionArgs>(
906 AllOf(WithMotionAction(
907 AMOTION_EVENT_ACTION_POINTER_DOWN |
908 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
909 WithMotionClassification(MotionClassification::PINCH),
910 WithGesturePinchScaleFactor(1.0f, EPSILON),
911 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
912 WithPointerCount(2u), WithToolType(ToolType::FINGER),
913 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000914
915 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
916 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000917 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000918 ASSERT_THAT(args,
919 ElementsAre(VariantWith<NotifyMotionArgs>(
920 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
921 WithMotionClassification(MotionClassification::PINCH),
922 WithGesturePinchScaleFactor(0.8f, EPSILON),
923 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
924 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
925 WithToolType(ToolType::FINGER),
926 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000927
928 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
929 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000930 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000931 ASSERT_THAT(args,
932 ElementsAre(VariantWith<NotifyMotionArgs>(
933 AllOf(WithMotionAction(
934 AMOTION_EVENT_ACTION_POINTER_UP |
935 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
936 WithMotionClassification(MotionClassification::PINCH),
937 WithGesturePinchScaleFactor(1.0f, EPSILON),
938 WithPointerCount(2u), WithToolType(ToolType::FINGER),
939 WithDisplayId(ADISPLAY_ID_DEFAULT))),
940 VariantWith<NotifyMotionArgs>(
941 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
942 WithMotionClassification(MotionClassification::PINCH),
943 WithGesturePinchScaleFactor(1.0f, EPSILON),
944 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +0000945 WithDisplayId(ADISPLAY_ID_DEFAULT))),
946 VariantWith<NotifyMotionArgs>(
947 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
948 WithCoords(POINTER_X, POINTER_Y),
949 WithMotionClassification(MotionClassification::NONE),
950 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000951 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000952}
953
954TEST_F(GestureConverterTest, Pinch_Outwards) {
955 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
956 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000957 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000958
959 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
960 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000961 std::list<NotifyArgs> args =
962 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000963 ASSERT_THAT(args,
964 ElementsAre(VariantWith<NotifyMotionArgs>(
965 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
966 WithMotionClassification(MotionClassification::PINCH),
967 WithGesturePinchScaleFactor(1.0f, EPSILON),
968 WithCoords(POINTER_X - 100, POINTER_Y),
969 WithPointerCount(1u), WithToolType(ToolType::FINGER),
970 WithDisplayId(ADISPLAY_ID_DEFAULT))),
971 VariantWith<NotifyMotionArgs>(
972 AllOf(WithMotionAction(
973 AMOTION_EVENT_ACTION_POINTER_DOWN |
974 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
975 WithMotionClassification(MotionClassification::PINCH),
976 WithGesturePinchScaleFactor(1.0f, EPSILON),
977 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
978 WithPointerCount(2u), WithToolType(ToolType::FINGER),
979 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000980
981 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
982 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000983 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000984 ASSERT_THAT(args,
985 ElementsAre(VariantWith<NotifyMotionArgs>(
986 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
987 WithMotionClassification(MotionClassification::PINCH),
988 WithGesturePinchScaleFactor(1.2f, EPSILON),
989 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
990 WithPointerCoords(1, POINTER_X + 120, POINTER_Y),
991 WithPointerCount(2u), WithToolType(ToolType::FINGER),
992 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000993
994 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
995 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000996 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000997 ASSERT_THAT(args,
998 ElementsAre(VariantWith<NotifyMotionArgs>(
999 AllOf(WithMotionAction(
1000 AMOTION_EVENT_ACTION_POINTER_UP |
1001 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1002 WithMotionClassification(MotionClassification::PINCH),
1003 WithGesturePinchScaleFactor(1.0f, EPSILON),
1004 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1005 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1006 VariantWith<NotifyMotionArgs>(
1007 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1008 WithMotionClassification(MotionClassification::PINCH),
1009 WithGesturePinchScaleFactor(1.0f, EPSILON),
1010 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001011 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1012 VariantWith<NotifyMotionArgs>(
1013 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1014 WithCoords(POINTER_X, POINTER_Y),
1015 WithMotionClassification(MotionClassification::NONE),
1016 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001017 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001018}
1019
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001020TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +00001021 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1022 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001023 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001024
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001025 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001026 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001027 std::list<NotifyArgs> args =
1028 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001029
1030 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001031 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001032 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001033
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001034 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001035 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001036 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001037
1038 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001039 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001040 ASSERT_THAT(args,
1041 ElementsAre(VariantWith<NotifyMotionArgs>(
1042 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001043}
1044
1045TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
1046 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1047 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001048 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001049
1050 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1051 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001052 std::list<NotifyArgs> args =
1053 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001054
1055 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1056 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001057 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001058
1059 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1060 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001061 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001062
1063 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1064 // need to use another gesture type, like scroll.
1065 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1066 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001067 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001068 ASSERT_FALSE(args.empty());
1069 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001070}
1071
Harry Cuttse9b71422023-03-14 16:54:44 +00001072TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1073 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1074 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001075 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001076
1077 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1078 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1079 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001080 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001081
1082 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001083 ASSERT_THAT(args,
1084 ElementsAre(VariantWith<NotifyMotionArgs>(
1085 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1086 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1087 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
1088 WithCoords(POINTER_X, POINTER_Y),
1089 WithToolType(ToolType::FINGER),
1090 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1091 VariantWith<NotifyMotionArgs>(
1092 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1093 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1094 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1095 WithToolType(ToolType::FINGER),
1096 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1097 VariantWith<NotifyMotionArgs>(
1098 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1099 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1100 WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001101 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1102 VariantWith<NotifyMotionArgs>(
1103 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1104 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1105 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001106 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001107}
1108
1109TEST_F(GestureConverterTest, ResetDuringScroll) {
1110 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1111 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001112 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001113
1114 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001115 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001116
1117 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001118 ASSERT_THAT(args,
1119 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001120 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1121 WithCoords(POINTER_X, POINTER_Y - 10),
1122 WithGestureScrollDistance(0, 0, EPSILON),
1123 WithMotionClassification(
1124 MotionClassification::TWO_FINGER_SWIPE),
1125 WithToolType(ToolType::FINGER),
1126 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1127 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1128 VariantWith<NotifyMotionArgs>(
1129 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1130 WithCoords(POINTER_X, POINTER_Y),
1131 WithMotionClassification(MotionClassification::NONE),
1132 WithToolType(ToolType::FINGER),
1133 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001134}
1135
1136TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1137 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1138 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001139 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001140
1141 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1142 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001143 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001144
1145 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001146 ASSERT_THAT(args,
1147 ElementsAre(VariantWith<NotifyMotionArgs>(
1148 AllOf(WithMotionAction(
1149 AMOTION_EVENT_ACTION_POINTER_UP |
1150 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1151 WithGestureOffset(0, 0, EPSILON),
1152 WithMotionClassification(
1153 MotionClassification::MULTI_FINGER_SWIPE),
1154 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1155 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1156 VariantWith<NotifyMotionArgs>(
1157 AllOf(WithMotionAction(
1158 AMOTION_EVENT_ACTION_POINTER_UP |
1159 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1160 WithGestureOffset(0, 0, EPSILON),
1161 WithMotionClassification(
1162 MotionClassification::MULTI_FINGER_SWIPE),
1163 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1164 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1165 VariantWith<NotifyMotionArgs>(
1166 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1167 WithGestureOffset(0, 0, EPSILON),
1168 WithMotionClassification(
1169 MotionClassification::MULTI_FINGER_SWIPE),
1170 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001171 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1172 VariantWith<NotifyMotionArgs>(
1173 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1174 WithMotionClassification(MotionClassification::NONE),
1175 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001176 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001177}
1178
1179TEST_F(GestureConverterTest, ResetDuringPinch) {
1180 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1181 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001182 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001183
1184 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1185 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001186 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001187
1188 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001189 ASSERT_THAT(args,
1190 ElementsAre(VariantWith<NotifyMotionArgs>(
1191 AllOf(WithMotionAction(
1192 AMOTION_EVENT_ACTION_POINTER_UP |
1193 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1194 WithMotionClassification(MotionClassification::PINCH),
1195 WithGesturePinchScaleFactor(1.0f, EPSILON),
1196 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1197 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1198 VariantWith<NotifyMotionArgs>(
1199 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1200 WithMotionClassification(MotionClassification::PINCH),
1201 WithGesturePinchScaleFactor(1.0f, EPSILON),
1202 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00001203 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1204 VariantWith<NotifyMotionArgs>(
1205 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1206 WithCoords(POINTER_X, POINTER_Y),
1207 WithMotionClassification(MotionClassification::NONE),
1208 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001209 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001210}
1211
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001212TEST_F(GestureConverterTest, FlingTapDown) {
1213 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1214 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001215 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001216
1217 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1218 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001219 std::list<NotifyArgs> args =
1220 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001221
1222 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001223 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001224 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001225 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1226 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001227
1228 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1229 ASSERT_TRUE(mFakePointerController->isPointerShown());
1230}
1231
Arpit Singha5ea7c12023-07-05 15:39:25 +00001232TEST_F(GestureConverterTest, Tap) {
1233 // Tap should produce button press/release events
1234 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1235 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001236 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001237
1238 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1239 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001240 std::list<NotifyArgs> args =
1241 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001242 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001243
1244 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1245 /* down= */ GESTURES_BUTTON_LEFT,
1246 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001247 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001248
Harry Cutts5f26e952023-11-30 18:20:27 +00001249 ASSERT_THAT(args,
1250 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001251 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1252 WithCoords(POINTER_X, POINTER_Y),
1253 WithRelativeMotion(0.f, 0.f),
1254 WithToolType(ToolType::FINGER), WithButtonState(0),
1255 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1256 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001257 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1258 WithCoords(POINTER_X, POINTER_Y),
1259 WithRelativeMotion(0.f, 0.f),
1260 WithToolType(ToolType::FINGER),
1261 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1262 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1263 VariantWith<NotifyMotionArgs>(
1264 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1265 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1266 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1267 WithCoords(POINTER_X, POINTER_Y),
1268 WithRelativeMotion(0.f, 0.f),
1269 WithToolType(ToolType::FINGER),
1270 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1271 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1272 VariantWith<NotifyMotionArgs>(
1273 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1274 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1275 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1276 WithRelativeMotion(0.f, 0.f),
1277 WithToolType(ToolType::FINGER), WithButtonState(0),
1278 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1279 VariantWith<NotifyMotionArgs>(
1280 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1281 WithCoords(POINTER_X, POINTER_Y),
1282 WithRelativeMotion(0.f, 0.f),
1283 WithToolType(ToolType::FINGER), WithButtonState(0),
1284 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1285 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001286 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001287 WithCoords(POINTER_X, POINTER_Y),
1288 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1289 WithButtonState(0), WithPressure(0.0f),
1290 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001291}
1292
1293TEST_F(GestureConverterTest, Click) {
1294 // Click should produce button press/release events
1295 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1296 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001297 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001298
1299 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1300 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001301 std::list<NotifyArgs> args =
1302 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001303 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001304
1305 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1306 /* down= */ GESTURES_BUTTON_LEFT,
1307 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001308 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001309
Harry Cutts5f26e952023-11-30 18:20:27 +00001310 ASSERT_THAT(args,
1311 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001312 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1313 WithCoords(POINTER_X, POINTER_Y),
1314 WithRelativeMotion(0.f, 0.f),
1315 WithToolType(ToolType::FINGER), WithButtonState(0),
1316 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1317 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001318 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1319 WithCoords(POINTER_X, POINTER_Y),
1320 WithRelativeMotion(0.f, 0.f),
1321 WithToolType(ToolType::FINGER),
1322 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1323 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1324 VariantWith<NotifyMotionArgs>(
1325 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1326 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1327 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1328 WithCoords(POINTER_X, POINTER_Y),
1329 WithRelativeMotion(0.f, 0.f),
1330 WithToolType(ToolType::FINGER),
1331 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1332 WithPressure(1.0f),
1333 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001334
1335 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1336 /* down= */ GESTURES_BUTTON_NONE,
1337 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001338 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001339 ASSERT_THAT(args,
1340 ElementsAre(VariantWith<NotifyMotionArgs>(
1341 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1342 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1343 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1344 WithRelativeMotion(0.f, 0.f),
1345 WithToolType(ToolType::FINGER), WithButtonState(0),
1346 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1347 VariantWith<NotifyMotionArgs>(
1348 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1349 WithCoords(POINTER_X, POINTER_Y),
1350 WithRelativeMotion(0.f, 0.f),
1351 WithToolType(ToolType::FINGER), WithButtonState(0),
1352 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1353 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001354 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001355 WithCoords(POINTER_X, POINTER_Y),
1356 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1357 WithButtonState(0), WithPressure(0.0f),
1358 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001359}
1360
Arpit Singh3d84add2023-10-10 19:08:29 +00001361TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001362 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1363 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1364 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1365
Arpit Singha5ea7c12023-07-05 15:39:25 +00001366 // Tap should be ignored when disabled
1367 mReader->getContext()->setPreventingTouchpadTaps(true);
1368
1369 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1370 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001371 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001372
Arpit Singh82b27a02023-10-16 11:02:19 +00001373 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001374 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001375 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001376 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001377 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001378
Arpit Singh82b27a02023-10-16 11:02:19 +00001379 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001380 /* down= */ GESTURES_BUTTON_LEFT,
1381 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001382 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001383
1384 // no events should be generated
1385 ASSERT_EQ(0u, args.size());
1386
1387 // Future taps should be re-enabled
1388 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1389}
1390
Arpit Singh82b27a02023-10-16 11:02:19 +00001391TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1392 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1393 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1394
1395 // Tap should be ignored when disabled
1396 mReader->getContext()->setPreventingTouchpadTaps(true);
1397
1398 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1399 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1400 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1401
1402 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1403 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1404 std::list<NotifyArgs> args =
1405 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001406 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001407
1408 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1409 /* down= */ GESTURES_BUTTON_LEFT,
1410 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1411 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1412
1413 // no events should be generated
1414 ASSERT_EQ(0u, args.size());
1415
1416 // Future taps should be re-enabled
1417 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1418
1419 // taps before the threshold should still be ignored
1420 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1421 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1422 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1423 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1424
1425 ASSERT_EQ(1u, args.size());
1426 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1427 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1428
1429 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1430 /* down= */ GESTURES_BUTTON_LEFT,
1431 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1432 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1433
1434 // no events should be generated
1435 ASSERT_EQ(0u, args.size());
1436
1437 // taps after the threshold should be recognised
1438 currentTime += 1;
1439 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1440 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1441 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1442
1443 ASSERT_EQ(1u, args.size());
1444 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1445 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1446
1447 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1448 /* down= */ GESTURES_BUTTON_LEFT,
1449 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1450 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1451
Harry Cutts379ea422023-12-21 15:31:47 +00001452 ASSERT_EQ(6u, args.size());
1453 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1454 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1455 WithRelativeMotion(0.f, 0.f), WithButtonState(0)));
1456 args.pop_front();
Arpit Singh82b27a02023-10-16 11:02:19 +00001457 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1458 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
1459 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
1460 args.pop_front();
1461 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1462 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1463 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
1464 WithRelativeMotion(0.f, 0.f)));
1465 args.pop_front();
1466 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1467 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1468 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1469 WithRelativeMotion(0.f, 0.f)));
1470 args.pop_front();
1471 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1472 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
1473 WithButtonState(0)));
1474 args.pop_front();
1475 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001476 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0),
Arpit Singh82b27a02023-10-16 11:02:19 +00001477 WithButtonState(0)));
1478}
1479
Arpit Singh3d84add2023-10-10 19:08:29 +00001480TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1481 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001482 // Click should still produce button press/release events
1483 mReader->getContext()->setPreventingTouchpadTaps(true);
1484
1485 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1486 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001487 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001488
1489 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1490 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001491 std::list<NotifyArgs> args =
1492 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001493 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001494
1495 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1496 /* down= */ GESTURES_BUTTON_LEFT,
1497 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001498 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001499 ASSERT_THAT(args,
1500 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001501 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1502 WithCoords(POINTER_X, POINTER_Y),
1503 WithRelativeMotion(0.f, 0.f),
1504 WithToolType(ToolType::FINGER), WithButtonState(0),
1505 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1506 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001507 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1508 WithCoords(POINTER_X, POINTER_Y),
1509 WithRelativeMotion(0.f, 0.f),
1510 WithToolType(ToolType::FINGER),
1511 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1512 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1513 VariantWith<NotifyMotionArgs>(
1514 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1515 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1516 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1517 WithCoords(POINTER_X, POINTER_Y),
1518 WithRelativeMotion(0.f, 0.f),
1519 WithToolType(ToolType::FINGER),
1520 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1521 WithPressure(1.0f),
1522 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001523
1524 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1525 /* down= */ GESTURES_BUTTON_NONE,
1526 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001527 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001528
Harry Cutts5f26e952023-11-30 18:20:27 +00001529 ASSERT_THAT(args,
1530 ElementsAre(VariantWith<NotifyMotionArgs>(
1531 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1532 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1533 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1534 WithRelativeMotion(0.f, 0.f),
1535 WithToolType(ToolType::FINGER), WithButtonState(0),
1536 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1537 VariantWith<NotifyMotionArgs>(
1538 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1539 WithCoords(POINTER_X, POINTER_Y),
1540 WithRelativeMotion(0.f, 0.f),
1541 WithToolType(ToolType::FINGER), WithButtonState(0),
1542 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1543 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001544 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001545 WithCoords(POINTER_X, POINTER_Y),
1546 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1547 WithButtonState(0), WithPressure(0.0f),
1548 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001549
1550 // Future taps should be re-enabled
1551 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1552}
1553
Arpit Singh3d84add2023-10-10 19:08:29 +00001554TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1555 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001556 // initially disable tap-to-click
1557 mReader->getContext()->setPreventingTouchpadTaps(true);
1558
1559 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1560 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001561 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001562
1563 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001564 std::list<NotifyArgs> args =
1565 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001566 // We don't need to check args here, since it's covered by the Move test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001567
1568 // Future taps should be re-enabled
1569 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1570}
1571
Arpit Singh33a10a62023-10-12 13:06:54 +00001572TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1573 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1574 const nsecs_t gestureStartTime = 1000;
1575 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1576 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1577 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1578
1579 // Start a move gesture at gestureStartTime
1580 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1581 std::list<NotifyArgs> args =
1582 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001583 ASSERT_THAT(args,
1584 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001585 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1586 VariantWith<NotifyMotionArgs>(
1587 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001588
1589 // Key presses with IME connection should cancel ongoing move gesture
1590 nsecs_t currentTime = gestureStartTime + 100;
1591 mFakePolicy->setIsInputMethodConnectionActive(true);
1592 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1593 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1594 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001595 ASSERT_THAT(args,
1596 ElementsAre(VariantWith<NotifyMotionArgs>(
1597 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001598
1599 // any updates in existing move gesture should be ignored
1600 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1601 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1602 ASSERT_EQ(0u, args.size());
1603
1604 // New gesture should not be affected
1605 currentTime += 100;
1606 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1607 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001608 ASSERT_THAT(args,
1609 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001610 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1611 VariantWith<NotifyMotionArgs>(
1612 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001613}
1614
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001615// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1616// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001617class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1618protected:
1619 void SetUp() override {
1620 input_flags::enable_pointer_choreographer(true);
1621 GestureConverterTestBase::SetUp();
1622 }
1623};
1624
1625TEST_F(GestureConverterTestWithChoreographer, Move) {
1626 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1627 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1628 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1629
1630 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001631 std::list<NotifyArgs> args =
1632 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001633 ASSERT_THAT(args,
1634 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001635 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1636 WithCoords(0, 0), WithRelativeMotion(0, 0),
1637 WithToolType(ToolType::FINGER),
1638 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1639 VariantWith<NotifyMotionArgs>(
1640 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1641 WithCoords(0, 0), WithRelativeMotion(-5, 10),
1642 WithToolType(ToolType::FINGER), WithButtonState(0),
1643 WithPressure(0.0f),
1644 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
1645
1646 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
1647 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1648 ASSERT_THAT(args,
1649 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001650 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1651 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1652 WithButtonState(0), WithPressure(0.0f),
1653 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001654}
1655
1656TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1657 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1658 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1659 converter.setOrientation(ui::ROTATION_90);
1660 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1661
1662 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001663 std::list<NotifyArgs> args =
1664 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001665 ASSERT_THAT(args,
1666 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001667 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1668 WithCoords(0, 0), WithRelativeMotion(0, 0),
1669 WithToolType(ToolType::FINGER),
1670 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1671 VariantWith<NotifyMotionArgs>(
1672 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1673 WithCoords(0, 0), WithRelativeMotion(10, 5),
1674 WithToolType(ToolType::FINGER), WithButtonState(0),
1675 WithPressure(0.0f),
1676 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001677}
1678
1679TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1680 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1681 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1682 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1683
1684 // Press left and right buttons at once
1685 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1686 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1687 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001688 std::list<NotifyArgs> args =
1689 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001690 ASSERT_THAT(args,
1691 ElementsAre(VariantWith<NotifyMotionArgs>(
1692 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1693 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1694 AMOTION_EVENT_BUTTON_SECONDARY),
1695 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1696 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1697 VariantWith<NotifyMotionArgs>(
1698 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1699 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1700 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1701 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1702 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1703 VariantWith<NotifyMotionArgs>(
1704 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1705 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1706 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1707 AMOTION_EVENT_BUTTON_SECONDARY),
1708 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1709 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001710
1711 // Then release the left button
1712 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1713 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1714 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001715 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001716 ASSERT_THAT(args,
1717 ElementsAre(VariantWith<NotifyMotionArgs>(
1718 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1719 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1720 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1721 WithToolType(ToolType::FINGER),
1722 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001723
1724 // Finally release the right button
1725 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1726 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1727 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001728 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001729 ASSERT_THAT(args,
1730 ElementsAre(VariantWith<NotifyMotionArgs>(
1731 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1732 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1733 WithButtonState(0), WithCoords(0, 0),
1734 WithToolType(ToolType::FINGER),
1735 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1736 VariantWith<NotifyMotionArgs>(
1737 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1738 WithButtonState(0), WithCoords(0, 0),
1739 WithToolType(ToolType::FINGER),
1740 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1741 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001742 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001743 WithButtonState(0), WithCoords(0, 0),
1744 WithToolType(ToolType::FINGER),
1745 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001746}
1747
Harry Cutts379ea422023-12-21 15:31:47 +00001748TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) {
1749 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1750 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1751 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1752
1753 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1754 std::list<NotifyArgs> args =
1755 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1756
1757 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1758 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
1759 /*is_tap=*/false);
1760 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
1761 ASSERT_THAT(args.front(),
1762 VariantWith<NotifyMotionArgs>(
1763 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
1764 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1765 WithDisplayId(ADISPLAY_ID_DEFAULT))));
1766}
1767
Byoungho Jungee6268f2023-10-30 17:27:26 +09001768TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1769 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1770 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1771 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1772
1773 // Press the button
1774 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1775 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1776 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001777 std::list<NotifyArgs> args =
1778 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001779 ASSERT_THAT(args,
1780 ElementsAre(VariantWith<NotifyMotionArgs>(
1781 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1782 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1783 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1784 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1785 VariantWith<NotifyMotionArgs>(
1786 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1787 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1788 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1789 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1790 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001791
1792 // Move
1793 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001794 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001795 ASSERT_THAT(args,
1796 ElementsAre(VariantWith<NotifyMotionArgs>(
1797 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1798 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1799 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1800 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001801
1802 // Release the button
1803 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1804 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1805 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001806 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001807 ASSERT_THAT(args,
1808 ElementsAre(VariantWith<NotifyMotionArgs>(
1809 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1810 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1811 WithButtonState(0), WithCoords(0, 0),
1812 WithToolType(ToolType::FINGER),
1813 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1814 VariantWith<NotifyMotionArgs>(
1815 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1816 WithButtonState(0), WithCoords(0, 0),
1817 WithToolType(ToolType::FINGER),
1818 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1819 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001820 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001821 WithButtonState(0), WithCoords(0, 0),
1822 WithToolType(ToolType::FINGER),
1823 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001824}
1825
1826TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1827 const nsecs_t downTime = 12345;
1828 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1829 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1830 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1831
1832 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001833 std::list<NotifyArgs> args =
1834 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001835 ASSERT_THAT(args,
1836 ElementsAre(VariantWith<NotifyMotionArgs>(
1837 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1838 WithCoords(0, 0),
1839 WithGestureScrollDistance(0, 0, EPSILON),
1840 WithMotionClassification(
1841 MotionClassification::TWO_FINGER_SWIPE),
1842 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1843 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1844 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1845 VariantWith<NotifyMotionArgs>(
1846 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1847 WithCoords(0, -10),
1848 WithGestureScrollDistance(0, 10, EPSILON),
1849 WithMotionClassification(
1850 MotionClassification::TWO_FINGER_SWIPE),
1851 WithToolType(ToolType::FINGER),
1852 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1853 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001854
1855 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001856 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001857 ASSERT_THAT(args,
1858 ElementsAre(VariantWith<NotifyMotionArgs>(
1859 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1860 WithGestureScrollDistance(0, 5, EPSILON),
1861 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1862 WithToolType(ToolType::FINGER),
1863 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1864 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001865
1866 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1867 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001868 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001869 ASSERT_THAT(args,
1870 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001871 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1872 WithCoords(0, -15),
1873 WithGestureScrollDistance(0, 0, EPSILON),
1874 WithMotionClassification(
1875 MotionClassification::TWO_FINGER_SWIPE),
1876 WithToolType(ToolType::FINGER),
1877 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1878 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1879 VariantWith<NotifyMotionArgs>(
1880 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1881 WithCoords(0, 0),
1882 WithMotionClassification(MotionClassification::NONE),
1883 WithToolType(ToolType::FINGER),
1884 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001885}
1886
1887TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1888 const nsecs_t downTime = 12345;
1889 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1890 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1891 converter.setOrientation(ui::ROTATION_90);
1892 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1893
1894 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001895 std::list<NotifyArgs> args =
1896 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001897 ASSERT_THAT(args,
1898 ElementsAre(VariantWith<NotifyMotionArgs>(
1899 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1900 WithCoords(0, 0),
1901 WithGestureScrollDistance(0, 0, EPSILON),
1902 WithMotionClassification(
1903 MotionClassification::TWO_FINGER_SWIPE),
1904 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1905 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1906 VariantWith<NotifyMotionArgs>(
1907 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1908 WithCoords(-10, 0),
1909 WithGestureScrollDistance(0, 10, EPSILON),
1910 WithMotionClassification(
1911 MotionClassification::TWO_FINGER_SWIPE),
1912 WithToolType(ToolType::FINGER),
1913 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001914
1915 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001916 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001917 ASSERT_THAT(args,
1918 ElementsAre(VariantWith<NotifyMotionArgs>(
1919 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1920 WithGestureScrollDistance(0, 5, EPSILON),
1921 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1922 WithToolType(ToolType::FINGER),
1923 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001924
1925 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1926 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001927 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001928 ASSERT_THAT(args,
1929 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001930 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1931 WithCoords(-15, 0),
1932 WithGestureScrollDistance(0, 0, EPSILON),
1933 WithMotionClassification(
1934 MotionClassification::TWO_FINGER_SWIPE),
1935 WithToolType(ToolType::FINGER),
1936 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1937 VariantWith<NotifyMotionArgs>(
1938 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1939 WithCoords(0, 0),
1940 WithMotionClassification(MotionClassification::NONE),
1941 WithToolType(ToolType::FINGER),
1942 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001943}
1944
1945TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1946 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1947 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1948 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1949
1950 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001951 std::list<NotifyArgs> args =
1952 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001953
1954 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001955 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001956
1957 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1958 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001959 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001960
1961 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001962 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001963 ASSERT_THAT(args,
1964 ElementsAre(VariantWith<NotifyMotionArgs>(
1965 AllOf(WithMotionClassification(MotionClassification::NONE),
1966 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001967}
1968
1969TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1970 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1971 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1972 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1973
1974 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001975 std::list<NotifyArgs> args =
1976 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001977
1978 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001979 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001980
1981 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1982 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001983 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001984
1985 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1986 // need to use another gesture type, like pinch.
1987 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1988 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001989 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001990 ASSERT_FALSE(args.empty());
1991 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1992}
1993
1994TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1995 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1996 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1997 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1998
1999 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2000 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002001 std::list<NotifyArgs> args =
2002 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002003
2004 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002005 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002006
2007 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
2008 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002009 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002010 ASSERT_THAT(args,
2011 ElementsAre(VariantWith<NotifyMotionArgs>(
2012 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002013}
2014
2015TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
2016 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2017 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2018 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2019
2020 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
2021 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002022 std::list<NotifyArgs> args =
2023 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002024
2025 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002026 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002027
2028 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2029 // need to use another gesture type, like pinch.
2030 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2031 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002032 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002033 ASSERT_FALSE(args.empty());
2034 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2035 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
2036}
2037
2038TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
2039 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
2040 // start swiping up and then start moving left or right, it'll return gesture events with only Y
2041 // deltas until you lift your fingers and start swiping again. That's why each of these tests
2042 // only checks movement in one dimension.
2043 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2044 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2045 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2046
2047 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2048 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002049 std::list<NotifyArgs> args =
2050 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002051 ASSERT_EQ(4u, args.size());
2052
2053 // Three fake fingers should be created. We don't actually care where they are, so long as they
2054 // move appropriately.
2055 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2056 ASSERT_THAT(arg,
2057 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2058 WithGestureSwipeFingerCount(3),
2059 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2060 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2061 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2062 PointerCoords finger0Start = arg.pointerCoords[0];
2063 args.pop_front();
2064 arg = std::get<NotifyMotionArgs>(args.front());
2065 ASSERT_THAT(arg,
2066 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2067 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2068 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
2069 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2070 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2071 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2072 PointerCoords finger1Start = arg.pointerCoords[1];
2073 args.pop_front();
2074 arg = std::get<NotifyMotionArgs>(args.front());
2075 ASSERT_THAT(arg,
2076 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2077 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2078 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
2079 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2080 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2081 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2082 PointerCoords finger2Start = arg.pointerCoords[2];
2083 args.pop_front();
2084
2085 arg = std::get<NotifyMotionArgs>(args.front());
2086 ASSERT_THAT(arg,
2087 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2088 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
2089 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2090 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2091 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2092 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2093 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2094 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2095 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
2096 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
2097 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
2098
2099 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2100 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002101 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002102 ASSERT_EQ(1u, args.size());
2103 arg = std::get<NotifyMotionArgs>(args.front());
2104 ASSERT_THAT(arg,
2105 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2106 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
2107 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2108 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2109 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2110 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2111 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2112 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2113 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
2114 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
2115 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
2116
2117 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002118 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002119 ASSERT_THAT(args,
2120 ElementsAre(VariantWith<NotifyMotionArgs>(
2121 AllOf(WithMotionAction(
2122 AMOTION_EVENT_ACTION_POINTER_UP |
2123 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2124 WithGestureOffset(0, 0, EPSILON),
2125 WithGestureSwipeFingerCount(3),
2126 WithMotionClassification(
2127 MotionClassification::MULTI_FINGER_SWIPE),
2128 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2129 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2130 VariantWith<NotifyMotionArgs>(
2131 AllOf(WithMotionAction(
2132 AMOTION_EVENT_ACTION_POINTER_UP |
2133 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2134 WithGestureOffset(0, 0, EPSILON),
2135 WithGestureSwipeFingerCount(3),
2136 WithMotionClassification(
2137 MotionClassification::MULTI_FINGER_SWIPE),
2138 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2139 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2140 VariantWith<NotifyMotionArgs>(
2141 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2142 WithGestureOffset(0, 0, EPSILON),
2143 WithGestureSwipeFingerCount(3),
2144 WithMotionClassification(
2145 MotionClassification::MULTI_FINGER_SWIPE),
2146 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002147 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2148 VariantWith<NotifyMotionArgs>(
2149 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2150 WithCoords(0, 0),
2151 WithMotionClassification(MotionClassification::NONE),
2152 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002153 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002154}
2155
2156TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
2157 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2158 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2159 converter.setOrientation(ui::ROTATION_90);
2160 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2161
2162 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2163 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002164 std::list<NotifyArgs> args =
2165 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002166 ASSERT_EQ(4u, args.size());
2167
2168 // Three fake fingers should be created. We don't actually care where they are, so long as they
2169 // move appropriately.
2170 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2171 ASSERT_THAT(arg,
2172 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2173 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2174 PointerCoords finger0Start = arg.pointerCoords[0];
2175 args.pop_front();
2176 arg = std::get<NotifyMotionArgs>(args.front());
2177 ASSERT_THAT(arg,
2178 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2179 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2180 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2181 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2182 PointerCoords finger1Start = arg.pointerCoords[1];
2183 args.pop_front();
2184 arg = std::get<NotifyMotionArgs>(args.front());
2185 ASSERT_THAT(arg,
2186 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2187 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2188 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2189 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2190 PointerCoords finger2Start = arg.pointerCoords[2];
2191 args.pop_front();
2192
2193 arg = std::get<NotifyMotionArgs>(args.front());
2194 ASSERT_THAT(arg,
2195 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2196 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
2197 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2198 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
2199 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
2200 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
2201 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2202 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2203 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2204
2205 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2206 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002207 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002208 ASSERT_EQ(1u, args.size());
2209 arg = std::get<NotifyMotionArgs>(args.front());
2210 ASSERT_THAT(arg,
2211 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2212 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
2213 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2214 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
2215 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
2216 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
2217 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2218 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2219 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2220
2221 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002222 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002223 ASSERT_THAT(args,
2224 ElementsAre(VariantWith<NotifyMotionArgs>(
2225 AllOf(WithMotionAction(
2226 AMOTION_EVENT_ACTION_POINTER_UP |
2227 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2228 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2229 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2230 VariantWith<NotifyMotionArgs>(
2231 AllOf(WithMotionAction(
2232 AMOTION_EVENT_ACTION_POINTER_UP |
2233 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2234 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2235 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2236 VariantWith<NotifyMotionArgs>(
2237 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2238 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
Harry Cutts379ea422023-12-21 15:31:47 +00002239 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2240 VariantWith<NotifyMotionArgs>(
2241 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002242 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002243}
2244
2245TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2246 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2247 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2248 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2249
2250 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2251 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002252 std::list<NotifyArgs> args =
2253 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002254 ASSERT_EQ(5u, args.size());
2255
2256 // Four fake fingers should be created. We don't actually care where they are, so long as they
2257 // move appropriately.
2258 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2259 ASSERT_THAT(arg,
2260 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2261 WithGestureSwipeFingerCount(4),
2262 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2263 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2264 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2265 PointerCoords finger0Start = arg.pointerCoords[0];
2266 args.pop_front();
2267 arg = std::get<NotifyMotionArgs>(args.front());
2268 ASSERT_THAT(arg,
2269 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2270 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2271 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2272 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2273 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2274 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2275 PointerCoords finger1Start = arg.pointerCoords[1];
2276 args.pop_front();
2277 arg = std::get<NotifyMotionArgs>(args.front());
2278 ASSERT_THAT(arg,
2279 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2280 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2281 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2282 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2283 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2284 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2285 PointerCoords finger2Start = arg.pointerCoords[2];
2286 args.pop_front();
2287 arg = std::get<NotifyMotionArgs>(args.front());
2288 ASSERT_THAT(arg,
2289 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2290 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2291 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2292 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2293 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2294 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2295 PointerCoords finger3Start = arg.pointerCoords[3];
2296 args.pop_front();
2297
2298 arg = std::get<NotifyMotionArgs>(args.front());
2299 ASSERT_THAT(arg,
2300 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2301 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
2302 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2303 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2304 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2305 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2306 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2307 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2308 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2309 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2310 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2311 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2312 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2313
2314 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2315 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002316 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002317 ASSERT_EQ(1u, args.size());
2318 arg = std::get<NotifyMotionArgs>(args.front());
2319 ASSERT_THAT(arg,
2320 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2321 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2322 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2323 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2324 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2325 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2326 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2327 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2328 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2329 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2330 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2331 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2332 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2333
2334 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002335 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002336 ASSERT_THAT(args,
2337 ElementsAre(VariantWith<NotifyMotionArgs>(
2338 AllOf(WithMotionAction(
2339 AMOTION_EVENT_ACTION_POINTER_UP |
2340 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2341 WithGestureOffset(0, 0, EPSILON),
2342 WithGestureSwipeFingerCount(4),
2343 WithMotionClassification(
2344 MotionClassification::MULTI_FINGER_SWIPE),
2345 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2346 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2347 VariantWith<NotifyMotionArgs>(
2348 AllOf(WithMotionAction(
2349 AMOTION_EVENT_ACTION_POINTER_UP |
2350 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2351 WithGestureOffset(0, 0, EPSILON),
2352 WithGestureSwipeFingerCount(4),
2353 WithMotionClassification(
2354 MotionClassification::MULTI_FINGER_SWIPE),
2355 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2356 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2357 VariantWith<NotifyMotionArgs>(
2358 AllOf(WithMotionAction(
2359 AMOTION_EVENT_ACTION_POINTER_UP |
2360 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2361 WithGestureOffset(0, 0, EPSILON),
2362 WithGestureSwipeFingerCount(4),
2363 WithMotionClassification(
2364 MotionClassification::MULTI_FINGER_SWIPE),
2365 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2366 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2367 VariantWith<NotifyMotionArgs>(
2368 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2369 WithGestureOffset(0, 0, EPSILON),
2370 WithGestureSwipeFingerCount(4),
2371 WithMotionClassification(
2372 MotionClassification::MULTI_FINGER_SWIPE),
2373 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002374 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2375 VariantWith<NotifyMotionArgs>(
2376 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2377 WithCoords(0, 0),
2378 WithMotionClassification(MotionClassification::NONE),
2379 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002380 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002381}
2382
2383TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2384 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2385 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2386 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2387
2388 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2389 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002390 std::list<NotifyArgs> args =
2391 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002392 ASSERT_THAT(args,
2393 ElementsAre(VariantWith<NotifyMotionArgs>(
2394 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2395 WithMotionClassification(MotionClassification::PINCH),
2396 WithGesturePinchScaleFactor(1.0f, EPSILON),
2397 WithCoords(-100, 0), WithPointerCount(1u),
2398 WithToolType(ToolType::FINGER),
2399 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2400 VariantWith<NotifyMotionArgs>(
2401 AllOf(WithMotionAction(
2402 AMOTION_EVENT_ACTION_POINTER_DOWN |
2403 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2404 WithMotionClassification(MotionClassification::PINCH),
2405 WithGesturePinchScaleFactor(1.0f, EPSILON),
2406 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2407 WithToolType(ToolType::FINGER),
2408 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002409
2410 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2411 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002412 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002413 ASSERT_THAT(args,
2414 ElementsAre(VariantWith<NotifyMotionArgs>(
2415 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2416 WithMotionClassification(MotionClassification::PINCH),
2417 WithGesturePinchScaleFactor(0.8f, EPSILON),
2418 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
2419 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2420 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002421
2422 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2423 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002424 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002425 ASSERT_THAT(args,
2426 ElementsAre(VariantWith<NotifyMotionArgs>(
2427 AllOf(WithMotionAction(
2428 AMOTION_EVENT_ACTION_POINTER_UP |
2429 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2430 WithMotionClassification(MotionClassification::PINCH),
2431 WithGesturePinchScaleFactor(1.0f, EPSILON),
2432 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2433 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2434 VariantWith<NotifyMotionArgs>(
2435 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2436 WithMotionClassification(MotionClassification::PINCH),
2437 WithGesturePinchScaleFactor(1.0f, EPSILON),
2438 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002439 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2440 VariantWith<NotifyMotionArgs>(
2441 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2442 WithCoords(0, 0),
2443 WithMotionClassification(MotionClassification::NONE),
2444 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002445 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002446}
2447
2448TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2449 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2450 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2451 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2452
2453 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2454 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002455 std::list<NotifyArgs> args =
2456 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002457 ASSERT_THAT(args,
2458 ElementsAre(VariantWith<NotifyMotionArgs>(
2459 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2460 WithMotionClassification(MotionClassification::PINCH),
2461 WithGesturePinchScaleFactor(1.0f, EPSILON),
2462 WithCoords(-100, 0), WithPointerCount(1u),
2463 WithToolType(ToolType::FINGER),
2464 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2465 VariantWith<NotifyMotionArgs>(
2466 AllOf(WithMotionAction(
2467 AMOTION_EVENT_ACTION_POINTER_DOWN |
2468 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2469 WithMotionClassification(MotionClassification::PINCH),
2470 WithGesturePinchScaleFactor(1.0f, EPSILON),
2471 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2472 WithToolType(ToolType::FINGER),
2473 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002474
2475 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2476 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002477 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002478 ASSERT_THAT(args,
2479 ElementsAre(VariantWith<NotifyMotionArgs>(
2480 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2481 WithMotionClassification(MotionClassification::PINCH),
2482 WithGesturePinchScaleFactor(1.1f, EPSILON),
2483 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
2484 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2485 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002486
2487 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2488 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002489 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002490 ASSERT_THAT(args,
2491 ElementsAre(VariantWith<NotifyMotionArgs>(
2492 AllOf(WithMotionAction(
2493 AMOTION_EVENT_ACTION_POINTER_UP |
2494 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2495 WithMotionClassification(MotionClassification::PINCH),
2496 WithGesturePinchScaleFactor(1.0f, EPSILON),
2497 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2498 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2499 VariantWith<NotifyMotionArgs>(
2500 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2501 WithMotionClassification(MotionClassification::PINCH),
2502 WithGesturePinchScaleFactor(1.0f, EPSILON),
2503 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002504 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2505 VariantWith<NotifyMotionArgs>(
2506 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2507 WithCoords(0, 0),
2508 WithMotionClassification(MotionClassification::NONE),
2509 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002510 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002511}
2512
2513TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2514 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2515 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2516 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2517
2518 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2519 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002520 std::list<NotifyArgs> args =
2521 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002522
2523 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2524 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002525 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002526
2527 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2528 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002529 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002530
2531 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002532 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002533 ASSERT_THAT(args,
2534 ElementsAre(VariantWith<NotifyMotionArgs>(
2535 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002536}
2537
2538TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2539 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2540 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2541 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2542
2543 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2544 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002545 std::list<NotifyArgs> args =
2546 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002547
2548 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2549 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002550 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002551
2552 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2553 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002554 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002555
2556 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2557 // need to use another gesture type, like scroll.
2558 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2559 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002560 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002561 ASSERT_FALSE(args.empty());
2562 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2563}
2564
2565TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2566 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2567 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2568 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2569
2570 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2571 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2572 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002573 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002574
2575 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002576 ASSERT_THAT(args,
2577 ElementsAre(VariantWith<NotifyMotionArgs>(
2578 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2579 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2580 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
2581 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2582 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2583 VariantWith<NotifyMotionArgs>(
2584 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2585 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
2586 WithButtonState(0), WithCoords(0, 0),
2587 WithToolType(ToolType::FINGER),
2588 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2589 VariantWith<NotifyMotionArgs>(
2590 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2591 WithButtonState(0), WithCoords(0, 0),
2592 WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002593 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2594 VariantWith<NotifyMotionArgs>(
2595 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2596 WithButtonState(0), WithCoords(0, 0),
2597 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002598 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002599}
2600
2601TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2602 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2603 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2604 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2605
2606 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002607 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
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>(
Harry Cutts379ea422023-12-21 15:31:47 +00002612 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2613 WithCoords(0, -10),
2614 WithGestureScrollDistance(0, 0, EPSILON),
2615 WithMotionClassification(
2616 MotionClassification::TWO_FINGER_SWIPE),
2617 WithToolType(ToolType::FINGER),
2618 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2619 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2620 VariantWith<NotifyMotionArgs>(
2621 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2622 WithCoords(0, 0),
2623 WithMotionClassification(MotionClassification::NONE),
2624 WithToolType(ToolType::FINGER),
2625 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002626}
2627
2628TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2629 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2630 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2631 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2632
2633 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2634 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002635 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002636
2637 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002638 ASSERT_THAT(args,
2639 ElementsAre(VariantWith<NotifyMotionArgs>(
2640 AllOf(WithMotionAction(
2641 AMOTION_EVENT_ACTION_POINTER_UP |
2642 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2643 WithGestureOffset(0, 0, EPSILON),
2644 WithMotionClassification(
2645 MotionClassification::MULTI_FINGER_SWIPE),
2646 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2647 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2648 VariantWith<NotifyMotionArgs>(
2649 AllOf(WithMotionAction(
2650 AMOTION_EVENT_ACTION_POINTER_UP |
2651 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2652 WithGestureOffset(0, 0, EPSILON),
2653 WithMotionClassification(
2654 MotionClassification::MULTI_FINGER_SWIPE),
2655 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2656 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2657 VariantWith<NotifyMotionArgs>(
2658 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2659 WithGestureOffset(0, 0, EPSILON),
2660 WithMotionClassification(
2661 MotionClassification::MULTI_FINGER_SWIPE),
2662 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002663 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2664 VariantWith<NotifyMotionArgs>(
2665 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2666 WithMotionClassification(MotionClassification::NONE),
2667 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002668 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002669}
2670
2671TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2672 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2673 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2674 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2675
2676 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2677 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002678 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002679
2680 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002681 ASSERT_THAT(args,
2682 ElementsAre(VariantWith<NotifyMotionArgs>(
2683 AllOf(WithMotionAction(
2684 AMOTION_EVENT_ACTION_POINTER_UP |
2685 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2686 WithMotionClassification(MotionClassification::PINCH),
2687 WithGesturePinchScaleFactor(1.0f, EPSILON),
2688 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2689 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2690 VariantWith<NotifyMotionArgs>(
2691 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2692 WithMotionClassification(MotionClassification::PINCH),
2693 WithGesturePinchScaleFactor(1.0f, EPSILON),
2694 WithPointerCount(1u), WithToolType(ToolType::FINGER),
Harry Cutts379ea422023-12-21 15:31:47 +00002695 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2696 VariantWith<NotifyMotionArgs>(
2697 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2698 WithCoords(0, 0),
2699 WithMotionClassification(MotionClassification::NONE),
2700 WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002701 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002702}
2703
2704TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2705 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2706 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2707 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2708
2709 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2710 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002711 std::list<NotifyArgs> args =
2712 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002713
2714 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00002715 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
Byoungho Jungee6268f2023-10-30 17:27:26 +09002716 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2717 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2718}
2719
2720TEST_F(GestureConverterTestWithChoreographer, Tap) {
2721 // Tap should produce button press/release events
2722 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2723 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2724 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2725
2726 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2727 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002728 std::list<NotifyArgs> args =
2729 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002730 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002731
2732 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2733 /* down= */ GESTURES_BUTTON_LEFT,
2734 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002735 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002736
Harry Cutts5f26e952023-11-30 18:20:27 +00002737 ASSERT_THAT(args,
2738 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002739 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2740 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2741 WithToolType(ToolType::FINGER), WithButtonState(0),
2742 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2743 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002744 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2745 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2746 WithToolType(ToolType::FINGER),
2747 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2748 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2749 VariantWith<NotifyMotionArgs>(
2750 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2751 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2752 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2753 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2754 WithToolType(ToolType::FINGER),
2755 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2756 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2757 VariantWith<NotifyMotionArgs>(
2758 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2759 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2760 WithButtonState(0), WithCoords(0, 0),
2761 WithRelativeMotion(0.f, 0.f),
2762 WithToolType(ToolType::FINGER), WithButtonState(0),
2763 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2764 VariantWith<NotifyMotionArgs>(
2765 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2766 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2767 WithToolType(ToolType::FINGER), WithButtonState(0),
2768 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2769 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002770 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002771 WithCoords(0, 0), WithRelativeMotion(0, 0),
2772 WithToolType(ToolType::FINGER), WithButtonState(0),
2773 WithPressure(0.0f),
2774 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002775}
2776
2777TEST_F(GestureConverterTestWithChoreographer, Click) {
2778 // Click should produce button press/release events
2779 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2780 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2781 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2782
2783 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2784 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002785 std::list<NotifyArgs> args =
2786 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002787 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002788
2789 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2790 /* down= */ GESTURES_BUTTON_LEFT,
2791 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002792 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002793
Harry Cutts5f26e952023-11-30 18:20:27 +00002794 ASSERT_THAT(args,
2795 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002796 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2797 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2798 WithToolType(ToolType::FINGER), WithButtonState(0),
2799 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2800 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002801 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2802 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2803 WithToolType(ToolType::FINGER),
2804 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2805 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2806 VariantWith<NotifyMotionArgs>(
2807 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2808 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2809 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2810 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2811 WithToolType(ToolType::FINGER),
2812 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2813 WithPressure(1.0f),
2814 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002815
2816 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2817 /* down= */ GESTURES_BUTTON_NONE,
2818 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002819 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002820
Harry Cutts5f26e952023-11-30 18:20:27 +00002821 ASSERT_THAT(args,
2822 ElementsAre(VariantWith<NotifyMotionArgs>(
2823 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2824 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2825 WithButtonState(0), WithCoords(0, 0),
2826 WithRelativeMotion(0.f, 0.f),
2827 WithToolType(ToolType::FINGER), WithButtonState(0),
2828 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2829 VariantWith<NotifyMotionArgs>(
2830 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2831 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2832 WithToolType(ToolType::FINGER), WithButtonState(0),
2833 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2834 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002835 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002836 WithCoords(0, 0), WithRelativeMotion(0, 0),
2837 WithToolType(ToolType::FINGER), WithButtonState(0),
2838 WithPressure(0.0f),
2839 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002840}
2841
2842TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002843 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2844 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2845 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2846
Byoungho Jungee6268f2023-10-30 17:27:26 +09002847 // Tap should be ignored when disabled
2848 mReader->getContext()->setPreventingTouchpadTaps(true);
2849
2850 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2851 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2852 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2853
Arpit Singh82b27a02023-10-16 11:02:19 +00002854 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002855 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002856 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002857 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002858 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002859
Arpit Singh82b27a02023-10-16 11:02:19 +00002860 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002861 /* down= */ GESTURES_BUTTON_LEFT,
2862 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002863 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002864
2865 // no events should be generated
2866 ASSERT_EQ(0u, args.size());
2867
2868 // Future taps should be re-enabled
2869 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2870}
2871
Arpit Singh82b27a02023-10-16 11:02:19 +00002872TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2873 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2874 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2875
2876 // Tap should be ignored when disabled
2877 mReader->getContext()->setPreventingTouchpadTaps(true);
2878
2879 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2880 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2881 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2882
2883 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2884 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2885 std::list<NotifyArgs> args =
2886 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002887 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00002888
2889 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2890 /* down= */ GESTURES_BUTTON_LEFT,
2891 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2892 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2893
2894 // no events should be generated
2895 ASSERT_EQ(0u, args.size());
2896
2897 // Future taps should be re-enabled
2898 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2899
2900 // taps before the threshold should still be ignored
2901 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2902 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2903 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2904 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2905
2906 ASSERT_EQ(1u, args.size());
2907 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2908 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2909
2910 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2911 /* down= */ GESTURES_BUTTON_LEFT,
2912 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2913 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2914
2915 // no events should be generated
2916 ASSERT_EQ(0u, args.size());
2917
2918 // taps after the threshold should be recognised
2919 currentTime += 1;
2920 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2921 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2922 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2923
2924 ASSERT_EQ(1u, args.size());
2925 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2926 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2927
2928 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2929 /* down= */ GESTURES_BUTTON_LEFT,
2930 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2931 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2932
Harry Cutts379ea422023-12-21 15:31:47 +00002933 ASSERT_EQ(6u, args.size());
2934 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2935 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2936 WithRelativeMotion(0.f, 0.f), WithButtonState(0)));
2937 args.pop_front();
Arpit Singh82b27a02023-10-16 11:02:19 +00002938 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2939 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
2940 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
2941 args.pop_front();
2942 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2943 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2944 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
2945 WithRelativeMotion(0.f, 0.f)));
2946 args.pop_front();
2947 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2948 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2949 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2950 WithRelativeMotion(0.f, 0.f)));
2951 args.pop_front();
2952 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2953 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
2954 WithButtonState(0)));
2955 args.pop_front();
2956 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00002957 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0),
Arpit Singh82b27a02023-10-16 11:02:19 +00002958 WithButtonState(0)));
2959}
2960
Byoungho Jungee6268f2023-10-30 17:27:26 +09002961TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2962 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2963 // Click should still produce button press/release events
2964 mReader->getContext()->setPreventingTouchpadTaps(true);
2965
2966 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2967 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2968 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2969
2970 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2971 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002972 std::list<NotifyArgs> args =
2973 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002974 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002975
2976 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2977 /* down= */ GESTURES_BUTTON_LEFT,
2978 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002979 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002980
Harry Cutts5f26e952023-11-30 18:20:27 +00002981 ASSERT_THAT(args,
2982 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002983 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2984 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2985 WithToolType(ToolType::FINGER), WithButtonState(0),
2986 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2987 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002988 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2989 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2990 WithToolType(ToolType::FINGER),
2991 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2992 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2993 VariantWith<NotifyMotionArgs>(
2994 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2995 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2996 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2997 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2998 WithToolType(ToolType::FINGER),
2999 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
3000 WithPressure(1.0f),
3001 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09003002
3003 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
3004 /* down= */ GESTURES_BUTTON_NONE,
3005 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00003006 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09003007
Harry Cutts5f26e952023-11-30 18:20:27 +00003008 ASSERT_THAT(args,
3009 ElementsAre(VariantWith<NotifyMotionArgs>(
3010 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
3011 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
3012 WithButtonState(0), WithCoords(0, 0),
3013 WithRelativeMotion(0.f, 0.f),
3014 WithToolType(ToolType::FINGER), WithButtonState(0),
3015 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3016 VariantWith<NotifyMotionArgs>(
3017 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
3018 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
3019 WithToolType(ToolType::FINGER), WithButtonState(0),
3020 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
3021 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003022 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00003023 WithCoords(0, 0), WithRelativeMotion(0, 0),
3024 WithToolType(ToolType::FINGER), WithButtonState(0),
3025 WithPressure(0.0f),
3026 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09003027
3028 // Future taps should be re-enabled
3029 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
3030}
3031
3032TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
3033 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
3034 // initially disable tap-to-click
3035 mReader->getContext()->setPreventingTouchpadTaps(true);
3036
3037 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3038 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3039 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3040
3041 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00003042 std::list<NotifyArgs> args =
3043 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00003044 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09003045
3046 // Future taps should be re-enabled
3047 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
3048}
3049
Arpit Singh33a10a62023-10-12 13:06:54 +00003050TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
3051 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
3052 const nsecs_t gestureStartTime = 1000;
3053 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
3054 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
3055 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
3056
3057 // Start a move gesture at gestureStartTime
3058 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
3059 std::list<NotifyArgs> args =
3060 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003061 ASSERT_THAT(args,
3062 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003063 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
3064 VariantWith<NotifyMotionArgs>(
3065 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003066
3067 // Key presses with IME connection should cancel ongoing move gesture
3068 nsecs_t currentTime = gestureStartTime + 100;
3069 mFakePolicy->setIsInputMethodConnectionActive(true);
3070 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
3071 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3072 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003073 ASSERT_THAT(args,
3074 ElementsAre(VariantWith<NotifyMotionArgs>(
3075 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003076
3077 // any updates in existing move gesture should be ignored
3078 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3079 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
3080 ASSERT_EQ(0u, args.size());
3081
3082 // New gesture should not be affected
3083 currentTime += 100;
3084 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
3085 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00003086 ASSERT_THAT(args,
3087 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00003088 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
3089 VariantWith<NotifyMotionArgs>(
3090 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00003091}
3092
Harry Cutts4fb941a2022-12-14 19:14:04 +00003093} // namespace android