blob: ca9ef8e0ef690ab2c179f0d1cea6ea2d5e653838 [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 Cuttsef95e712024-02-16 18:56:39 +000050using testing::Each;
Harry Cutts5f26e952023-11-30 18:20:27 +000051using testing::ElementsAre;
52using testing::VariantWith;
Harry Cutts4fb941a2022-12-14 19:14:04 +000053
Byoungho Jungee6268f2023-10-30 17:27:26 +090054class GestureConverterTestBase : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000055protected:
56 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000057 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000058 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000059 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000060 static constexpr float POINTER_Y = 200;
61
62 void SetUp() {
63 mFakeEventHub = std::make_unique<FakeEventHub>();
64 mFakePolicy = sp<FakeInputReaderPolicy>::make();
65 mFakeListener = std::make_unique<TestInputListener>();
66 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
67 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000068 mDevice = newDevice();
69 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
70 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000071
72 mFakePointerController = std::make_shared<FakePointerController>();
73 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
74 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
75 mFakePolicy->setPointerController(mFakePointerController);
76 }
77
Harry Cuttsc5748d12022-12-02 17:30:18 +000078 std::shared_ptr<InputDevice> newDevice() {
79 InputDeviceIdentifier identifier;
80 identifier.name = "device";
81 identifier.location = "USB1";
82 identifier.bus = 0;
83 std::shared_ptr<InputDevice> device =
84 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
85 identifier);
86 mReader->pushNextDevice(device);
87 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
88 identifier.bus);
89 mReader->loopOnce();
90 return device;
91 }
92
Harry Cutts4fb941a2022-12-14 19:14:04 +000093 std::shared_ptr<FakeEventHub> mFakeEventHub;
94 sp<FakeInputReaderPolicy> mFakePolicy;
95 std::unique_ptr<TestInputListener> mFakeListener;
96 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000097 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000098 std::shared_ptr<FakePointerController> mFakePointerController;
99};
100
Byoungho Jungee6268f2023-10-30 17:27:26 +0900101class GestureConverterTest : public GestureConverterTestBase {
102protected:
103 void SetUp() override {
104 input_flags::enable_pointer_choreographer(false);
105 GestureConverterTestBase::SetUp();
106 }
107};
108
Harry Cutts4fb941a2022-12-14 19:14:04 +0000109TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000110 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
111 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000112 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000113
114 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000115 std::list<NotifyArgs> args =
116 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000117 ASSERT_THAT(args,
118 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000119 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
120 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000121 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000122 VariantWith<NotifyMotionArgs>(
123 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
124 WithCoords(POINTER_X - 5, POINTER_Y + 10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000125 WithRelativeMotion(-5, 10), WithButtonState(0),
126 WithPressure(0.0f)))));
127 ASSERT_THAT(args,
128 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
129 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000130
Harry Cuttsb1e83552022-12-20 11:02:26 +0000131 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts379ea422023-12-21 15:31:47 +0000132
133 // The same gesture again should only repeat the HOVER_MOVE and cursor position change, not the
134 // HOVER_ENTER.
135 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
136 ASSERT_THAT(args,
137 ElementsAre(VariantWith<NotifyMotionArgs>(
138 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
139 WithCoords(POINTER_X - 10, POINTER_Y + 20),
140 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
141 WithButtonState(0), WithPressure(0.0f),
142 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
143
144 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 10, POINTER_Y + 20));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000145}
146
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000147TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000148 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
149 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000150 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000151 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000152
153 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000154 std::list<NotifyArgs> args =
155 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000156 ASSERT_THAT(args,
157 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000158 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
159 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000160 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000161 VariantWith<NotifyMotionArgs>(
162 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
163 WithCoords(POINTER_X + 10, POINTER_Y + 5),
Harry Cuttsef95e712024-02-16 18:56:39 +0000164 WithRelativeMotion(10, 5), WithButtonState(0),
165 WithPressure(0.0f)))));
166 ASSERT_THAT(args,
167 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
168 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000169
Harry Cuttsb1e83552022-12-20 11:02:26 +0000170 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000171}
172
Harry Cutts4fb941a2022-12-14 19:14:04 +0000173TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000174 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
175 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000176 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000177
178 // Press left and right buttons at once
179 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
180 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
181 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000182 std::list<NotifyArgs> args =
183 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000184 ASSERT_THAT(args,
185 ElementsAre(VariantWith<NotifyMotionArgs>(
186 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
187 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000188 AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000189 VariantWith<NotifyMotionArgs>(
190 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
191 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000192 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000193 VariantWith<NotifyMotionArgs>(
194 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
195 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
196 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000197 AMOTION_EVENT_BUTTON_SECONDARY)))));
198 ASSERT_THAT(args,
199 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
200 WithToolType(ToolType::FINGER),
201 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000202
203 // Then release the left button
204 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
205 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
206 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000207 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000208 ASSERT_THAT(args,
209 ElementsAre(VariantWith<NotifyMotionArgs>(
210 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
211 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
212 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
213 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
214 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000215
216 // Finally release the right button
217 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
218 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
219 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000220 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000221 ASSERT_THAT(args,
222 ElementsAre(VariantWith<NotifyMotionArgs>(
223 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000224 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000225 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000226 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000227 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000228 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
229 ASSERT_THAT(args,
230 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0),
231 WithCoords(POINTER_X, POINTER_Y),
232 WithToolType(ToolType::FINGER),
233 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000234}
235
Harry Cutts379ea422023-12-21 15:31:47 +0000236TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) {
237 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
238 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
239 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
240
241 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
242 std::list<NotifyArgs> args =
243 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
244
245 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
246 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
247 /*is_tap=*/false);
248 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
249 ASSERT_THAT(args.front(),
250 VariantWith<NotifyMotionArgs>(
251 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
252 WithCoords(POINTER_X - 5, POINTER_Y + 10),
253 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))));
254}
255
Harry Cutts4fb941a2022-12-14 19:14:04 +0000256TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000257 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
258 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000259 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000260
261 // Press the button
262 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
263 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
264 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000265 std::list<NotifyArgs> args =
266 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000267 ASSERT_THAT(args,
268 ElementsAre(VariantWith<NotifyMotionArgs>(
269 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +0000270 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000271 VariantWith<NotifyMotionArgs>(
272 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
273 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000274 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)))));
275 ASSERT_THAT(args,
276 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
277 WithToolType(ToolType::FINGER),
278 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000279
280 // Move
281 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000282 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000283 ASSERT_THAT(args,
284 ElementsAre(VariantWith<NotifyMotionArgs>(
285 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
286 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
287 WithToolType(ToolType::FINGER),
288 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
289 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000290
Harry Cuttsb1e83552022-12-20 11:02:26 +0000291 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000292
293 // Release the button
294 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
295 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
296 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000297 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000298 ASSERT_THAT(args,
299 ElementsAre(VariantWith<NotifyMotionArgs>(
300 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000301 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000302 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000303 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000304 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000305 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
306 ASSERT_THAT(args,
307 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0),
308 WithCoords(POINTER_X - 5, POINTER_Y + 10),
309 WithToolType(ToolType::FINGER),
310 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000311}
312
Harry Cuttsef400b22022-12-16 21:26:24 +0000313TEST_F(GestureConverterTest, Scroll) {
314 const nsecs_t downTime = 12345;
315 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
316 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000317 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000318
Harry Cuttsa546ba82023-01-13 17:21:00 +0000319 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000320 std::list<NotifyArgs> args =
321 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000322 ASSERT_THAT(args,
323 ElementsAre(VariantWith<NotifyMotionArgs>(
324 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
325 WithCoords(POINTER_X, POINTER_Y),
326 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000327 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000328 VariantWith<NotifyMotionArgs>(
329 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
330 WithCoords(POINTER_X, POINTER_Y - 10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000331 WithGestureScrollDistance(0, 10, EPSILON)))));
332 ASSERT_THAT(args,
333 Each(VariantWith<NotifyMotionArgs>(
334 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
335 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
336 WithToolType(ToolType::FINGER),
337 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000338
Harry Cuttsa546ba82023-01-13 17:21:00 +0000339 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000340 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000341 ASSERT_THAT(args,
342 ElementsAre(VariantWith<NotifyMotionArgs>(
343 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
344 WithCoords(POINTER_X, POINTER_Y - 15),
345 WithGestureScrollDistance(0, 5, EPSILON),
346 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
347 WithToolType(ToolType::FINGER),
348 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
349 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000350
351 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
352 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000353 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000354 ASSERT_THAT(args,
355 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000356 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
357 WithCoords(POINTER_X, POINTER_Y - 15),
358 WithGestureScrollDistance(0, 0, EPSILON),
359 WithMotionClassification(
360 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000361 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000362 VariantWith<NotifyMotionArgs>(
363 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
364 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000365 WithMotionClassification(MotionClassification::NONE)))));
366 ASSERT_THAT(args,
367 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
368 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000369}
370
371TEST_F(GestureConverterTest, Scroll_Rotated) {
372 const nsecs_t downTime = 12345;
373 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
374 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
375 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000376 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000377
Harry Cuttsa546ba82023-01-13 17:21:00 +0000378 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000379 std::list<NotifyArgs> args =
380 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000381 ASSERT_THAT(args,
382 ElementsAre(VariantWith<NotifyMotionArgs>(
383 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
384 WithCoords(POINTER_X, POINTER_Y),
385 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000386 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000387 VariantWith<NotifyMotionArgs>(
388 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
389 WithCoords(POINTER_X - 10, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000390 WithGestureScrollDistance(0, 10, EPSILON)))));
391 ASSERT_THAT(args,
392 Each(VariantWith<NotifyMotionArgs>(
393 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
394 WithToolType(ToolType::FINGER),
395 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000396
Harry Cuttsa546ba82023-01-13 17:21:00 +0000397 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000398 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000399 ASSERT_THAT(args,
400 ElementsAre(VariantWith<NotifyMotionArgs>(
401 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
402 WithCoords(POINTER_X - 15, POINTER_Y),
403 WithGestureScrollDistance(0, 5, EPSILON),
404 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
405 WithToolType(ToolType::FINGER),
406 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000407 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
408 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000409 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000410 ASSERT_THAT(args,
411 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000412 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
413 WithCoords(POINTER_X - 15, POINTER_Y),
414 WithGestureScrollDistance(0, 0, EPSILON),
415 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +0000416 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000417 VariantWith<NotifyMotionArgs>(
418 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
419 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000420 WithMotionClassification(MotionClassification::NONE)))));
421 ASSERT_THAT(args,
422 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
423 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000424}
425
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000426TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000427 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
428 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000429 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000430
Harry Cuttsa546ba82023-01-13 17:21:00 +0000431 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000432 std::list<NotifyArgs> args =
433 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000434
Harry Cuttsa546ba82023-01-13 17:21:00 +0000435 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000436 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000437
438 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
439 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000440 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000441
442 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000443 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000444 ASSERT_THAT(args,
445 ElementsAre(VariantWith<NotifyMotionArgs>(
446 AllOf(WithMotionClassification(MotionClassification::NONE),
447 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000448}
449
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000450TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000451 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
452 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000453 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000454
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000455 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000456 std::list<NotifyArgs> args =
457 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000458
459 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000460 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000461
462 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
463 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000464 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000465
466 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
467 // need to use another gesture type, like pinch.
468 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
469 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000470 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000471 ASSERT_FALSE(args.empty());
472 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
473}
474
475TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
476 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
477 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000478 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000479
480 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
481 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000482 std::list<NotifyArgs> args =
483 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000484
485 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000486 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000487
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000488 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
489 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000490 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000491 ASSERT_THAT(args,
492 ElementsAre(VariantWith<NotifyMotionArgs>(
493 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000494}
495
Harry Cutts8743f182023-05-17 12:03:49 +0000496TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000497 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
498 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000499 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000500
501 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
502 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000503 std::list<NotifyArgs> args =
504 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000505
506 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000507 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000508
509 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
510 // need to use another gesture type, like pinch.
511 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
512 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000513 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000514 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000515 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
516 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000517}
518
519TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
520 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
521 // start swiping up and then start moving left or right, it'll return gesture events with only Y
522 // deltas until you lift your fingers and start swiping again. That's why each of these tests
523 // only checks movement in one dimension.
524 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
525 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000526 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000527
528 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
529 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000530 std::list<NotifyArgs> args =
531 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000532 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000533 ASSERT_THAT(args,
534 Each(VariantWith<NotifyMotionArgs>(
535 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
536 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
537 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000538
539 // Three fake fingers should be created. We don't actually care where they are, so long as they
540 // move appropriately.
541 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
542 ASSERT_THAT(arg,
543 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000544 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000545 PointerCoords finger0Start = arg.pointerCoords[0];
546 args.pop_front();
547 arg = std::get<NotifyMotionArgs>(args.front());
548 ASSERT_THAT(arg,
549 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
550 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000551 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000552 PointerCoords finger1Start = arg.pointerCoords[1];
553 args.pop_front();
554 arg = std::get<NotifyMotionArgs>(args.front());
555 ASSERT_THAT(arg,
556 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
557 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000558 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000559 PointerCoords finger2Start = arg.pointerCoords[2];
560 args.pop_front();
561
562 arg = std::get<NotifyMotionArgs>(args.front());
563 ASSERT_THAT(arg,
564 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000565 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000566 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
567 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
568 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
569 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
570 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
571 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
572
573 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
574 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000575 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000576 ASSERT_EQ(1u, args.size());
577 arg = std::get<NotifyMotionArgs>(args.front());
578 ASSERT_THAT(arg,
579 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000580 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000581 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000582 WithPointerCount(3u), WithToolType(ToolType::FINGER),
583 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000584 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
585 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
586 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
587 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
588 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
589 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
590
591 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000592 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000593 ASSERT_THAT(args,
594 ElementsAre(VariantWith<NotifyMotionArgs>(
595 AllOf(WithMotionAction(
596 AMOTION_EVENT_ACTION_POINTER_UP |
597 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
598 WithGestureOffset(0, 0, EPSILON),
599 WithGestureSwipeFingerCount(3),
600 WithMotionClassification(
601 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000602 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000603 VariantWith<NotifyMotionArgs>(
604 AllOf(WithMotionAction(
605 AMOTION_EVENT_ACTION_POINTER_UP |
606 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
607 WithGestureOffset(0, 0, EPSILON),
608 WithGestureSwipeFingerCount(3),
609 WithMotionClassification(
610 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000611 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000612 VariantWith<NotifyMotionArgs>(
613 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
614 WithGestureOffset(0, 0, EPSILON),
615 WithGestureSwipeFingerCount(3),
616 WithMotionClassification(
617 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000618 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000619 VariantWith<NotifyMotionArgs>(
620 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
621 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000622 WithMotionClassification(MotionClassification::NONE)))));
623 ASSERT_THAT(args,
624 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
625 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000626}
627
Harry Cutts94f5bd52023-01-06 18:02:18 +0000628TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
629 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
630 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
631 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000632 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000633
634 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
635 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000636 std::list<NotifyArgs> args =
637 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000638 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000639 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000640
641 // Three fake fingers should be created. We don't actually care where they are, so long as they
642 // move appropriately.
643 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
644 ASSERT_THAT(arg,
645 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000646 WithPointerCount(1u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000647 PointerCoords finger0Start = arg.pointerCoords[0];
648 args.pop_front();
649 arg = std::get<NotifyMotionArgs>(args.front());
650 ASSERT_THAT(arg,
651 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
652 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000653 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000654 PointerCoords finger1Start = arg.pointerCoords[1];
655 args.pop_front();
656 arg = std::get<NotifyMotionArgs>(args.front());
657 ASSERT_THAT(arg,
658 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
659 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000660 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000661 PointerCoords finger2Start = arg.pointerCoords[2];
662 args.pop_front();
663
664 arg = std::get<NotifyMotionArgs>(args.front());
665 ASSERT_THAT(arg,
666 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000667 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000668 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
669 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
670 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
671 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
672 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
673 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
674
675 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
676 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000677 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000678 ASSERT_EQ(1u, args.size());
679 arg = std::get<NotifyMotionArgs>(args.front());
680 ASSERT_THAT(arg,
681 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000682 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
683 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000684 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
685 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
686 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
687 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
688 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
689 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
690
691 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000692 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000693 ASSERT_THAT(args,
694 ElementsAre(VariantWith<NotifyMotionArgs>(
695 AllOf(WithMotionAction(
696 AMOTION_EVENT_ACTION_POINTER_UP |
697 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000698 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000699 VariantWith<NotifyMotionArgs>(
700 AllOf(WithMotionAction(
701 AMOTION_EVENT_ACTION_POINTER_UP |
702 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000703 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000704 VariantWith<NotifyMotionArgs>(
705 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +0000706 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000707 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000708 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
709 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000710}
711
Harry Cuttsc5748d12022-12-02 17:30:18 +0000712TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
713 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
714 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000715 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000716
717 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
718 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000719 std::list<NotifyArgs> args =
720 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000721 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000722 ASSERT_THAT(args,
723 Each(VariantWith<NotifyMotionArgs>(
724 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
725 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
726 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000727
728 // Four fake fingers should be created. We don't actually care where they are, so long as they
729 // move appropriately.
730 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
731 ASSERT_THAT(arg,
732 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000733 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000734 PointerCoords finger0Start = arg.pointerCoords[0];
735 args.pop_front();
736 arg = std::get<NotifyMotionArgs>(args.front());
737 ASSERT_THAT(arg,
738 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
739 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000740 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000741 PointerCoords finger1Start = arg.pointerCoords[1];
742 args.pop_front();
743 arg = std::get<NotifyMotionArgs>(args.front());
744 ASSERT_THAT(arg,
745 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
746 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000747 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000748 PointerCoords finger2Start = arg.pointerCoords[2];
749 args.pop_front();
750 arg = std::get<NotifyMotionArgs>(args.front());
751 ASSERT_THAT(arg,
752 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
753 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000754 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000755 PointerCoords finger3Start = arg.pointerCoords[3];
756 args.pop_front();
757
758 arg = std::get<NotifyMotionArgs>(args.front());
759 ASSERT_THAT(arg,
760 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000761 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000762 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
763 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
764 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
765 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
766 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
767 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
768 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
769 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
770
771 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
772 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000773 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000774 ASSERT_EQ(1u, args.size());
775 arg = std::get<NotifyMotionArgs>(args.front());
776 ASSERT_THAT(arg,
777 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000778 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000779 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000780 WithPointerCount(4u), WithToolType(ToolType::FINGER),
781 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000782 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
783 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
784 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
785 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
786 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
787 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
788 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
789 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
790
791 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000792 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000793 ASSERT_THAT(args,
794 ElementsAre(VariantWith<NotifyMotionArgs>(
795 AllOf(WithMotionAction(
796 AMOTION_EVENT_ACTION_POINTER_UP |
797 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
798 WithGestureOffset(0, 0, EPSILON),
799 WithGestureSwipeFingerCount(4),
800 WithMotionClassification(
801 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000802 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000803 VariantWith<NotifyMotionArgs>(
804 AllOf(WithMotionAction(
805 AMOTION_EVENT_ACTION_POINTER_UP |
806 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
807 WithGestureOffset(0, 0, EPSILON),
808 WithGestureSwipeFingerCount(4),
809 WithMotionClassification(
810 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000811 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000812 VariantWith<NotifyMotionArgs>(
813 AllOf(WithMotionAction(
814 AMOTION_EVENT_ACTION_POINTER_UP |
815 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
816 WithGestureOffset(0, 0, EPSILON),
817 WithGestureSwipeFingerCount(4),
818 WithMotionClassification(
819 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000820 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000821 VariantWith<NotifyMotionArgs>(
822 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
823 WithGestureOffset(0, 0, EPSILON),
824 WithGestureSwipeFingerCount(4),
825 WithMotionClassification(
826 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000827 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000828 VariantWith<NotifyMotionArgs>(
829 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
830 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000831 WithMotionClassification(MotionClassification::NONE)))));
832 ASSERT_THAT(args,
833 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
834 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000835}
836
Harry Cuttsb1e83552022-12-20 11:02:26 +0000837TEST_F(GestureConverterTest, Pinch_Inwards) {
838 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
839 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000840 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000841
842 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
843 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000844 std::list<NotifyArgs> args =
845 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000846 ASSERT_THAT(args,
847 ElementsAre(VariantWith<NotifyMotionArgs>(
848 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +0000849 WithCoords(POINTER_X - 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000850 WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000851 VariantWith<NotifyMotionArgs>(
852 AllOf(WithMotionAction(
853 AMOTION_EVENT_ACTION_POINTER_DOWN |
854 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts5f26e952023-11-30 18:20:27 +0000855 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000856 WithPointerCount(2u)))));
857 ASSERT_THAT(args,
858 Each(VariantWith<NotifyMotionArgs>(
859 AllOf(WithMotionClassification(MotionClassification::PINCH),
860 WithGesturePinchScaleFactor(1.0f, EPSILON),
861 WithToolType(ToolType::FINGER),
862 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000863
864 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
865 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000866 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000867 ASSERT_THAT(args,
868 ElementsAre(VariantWith<NotifyMotionArgs>(
869 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
870 WithMotionClassification(MotionClassification::PINCH),
871 WithGesturePinchScaleFactor(0.8f, EPSILON),
872 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
873 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
874 WithToolType(ToolType::FINGER),
875 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000876
877 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
878 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000879 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000880 ASSERT_THAT(args,
881 ElementsAre(VariantWith<NotifyMotionArgs>(
882 AllOf(WithMotionAction(
883 AMOTION_EVENT_ACTION_POINTER_UP |
884 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
885 WithMotionClassification(MotionClassification::PINCH),
886 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000887 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000888 VariantWith<NotifyMotionArgs>(
889 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
890 WithMotionClassification(MotionClassification::PINCH),
891 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000892 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000893 VariantWith<NotifyMotionArgs>(
894 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
895 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000896 WithMotionClassification(MotionClassification::NONE)))));
897 ASSERT_THAT(args,
898 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
899 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000900}
901
902TEST_F(GestureConverterTest, Pinch_Outwards) {
903 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
904 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000905 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000906
907 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
908 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000909 std::list<NotifyArgs> args =
910 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000911 ASSERT_THAT(args,
912 ElementsAre(VariantWith<NotifyMotionArgs>(
913 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +0000914 WithCoords(POINTER_X - 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000915 WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000916 VariantWith<NotifyMotionArgs>(
917 AllOf(WithMotionAction(
918 AMOTION_EVENT_ACTION_POINTER_DOWN |
919 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts5f26e952023-11-30 18:20:27 +0000920 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000921 WithPointerCount(2u)))));
922 ASSERT_THAT(args,
923 Each(VariantWith<NotifyMotionArgs>(
924 AllOf(WithMotionClassification(MotionClassification::PINCH),
925 WithGesturePinchScaleFactor(1.0f, EPSILON),
926 WithToolType(ToolType::FINGER),
927 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000928
929 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
930 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000931 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000932 ASSERT_THAT(args,
933 ElementsAre(VariantWith<NotifyMotionArgs>(
934 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
935 WithMotionClassification(MotionClassification::PINCH),
936 WithGesturePinchScaleFactor(1.2f, EPSILON),
937 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
938 WithPointerCoords(1, POINTER_X + 120, POINTER_Y),
939 WithPointerCount(2u), WithToolType(ToolType::FINGER),
940 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000941
942 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
943 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000944 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000945 ASSERT_THAT(args,
946 ElementsAre(VariantWith<NotifyMotionArgs>(
947 AllOf(WithMotionAction(
948 AMOTION_EVENT_ACTION_POINTER_UP |
949 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
950 WithMotionClassification(MotionClassification::PINCH),
951 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000952 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000953 VariantWith<NotifyMotionArgs>(
954 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
955 WithMotionClassification(MotionClassification::PINCH),
956 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000957 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000958 VariantWith<NotifyMotionArgs>(
959 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
960 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000961 WithMotionClassification(MotionClassification::NONE)))));
962 ASSERT_THAT(args,
963 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
964 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000965}
966
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000967TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000968 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
969 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000970 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000971
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000972 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000973 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000974 std::list<NotifyArgs> args =
975 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000976
977 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000978 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000979 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000980
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000981 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000982 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000983 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000984
985 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000986 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000987 ASSERT_THAT(args,
988 ElementsAre(VariantWith<NotifyMotionArgs>(
989 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000990}
991
992TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
993 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
994 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000995 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000996
997 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
998 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000999 std::list<NotifyArgs> args =
1000 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001001
1002 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1003 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001004 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001005
1006 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1007 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001008 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001009
1010 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1011 // need to use another gesture type, like scroll.
1012 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1013 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001014 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001015 ASSERT_FALSE(args.empty());
1016 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001017}
1018
Harry Cuttse9b71422023-03-14 16:54:44 +00001019TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1020 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1021 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001022 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001023
1024 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1025 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1026 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001027 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001028
1029 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001030 ASSERT_THAT(args,
1031 ElementsAre(VariantWith<NotifyMotionArgs>(
1032 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1033 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001034 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001035 VariantWith<NotifyMotionArgs>(
1036 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1037 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001038 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001039 VariantWith<NotifyMotionArgs>(
1040 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001041 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001042 VariantWith<NotifyMotionArgs>(
1043 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001044 WithButtonState(0)))));
1045 ASSERT_THAT(args,
1046 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1047 WithToolType(ToolType::FINGER),
1048 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001049}
1050
1051TEST_F(GestureConverterTest, ResetDuringScroll) {
1052 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1053 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001054 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001055
1056 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001057 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001058
1059 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001060 ASSERT_THAT(args,
1061 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001062 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1063 WithCoords(POINTER_X, POINTER_Y - 10),
1064 WithGestureScrollDistance(0, 0, EPSILON),
1065 WithMotionClassification(
1066 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001067 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001068 VariantWith<NotifyMotionArgs>(
1069 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1070 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +00001071 WithMotionClassification(MotionClassification::NONE)))));
1072 ASSERT_THAT(args,
1073 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1074 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001075}
1076
1077TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1078 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1079 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001080 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001081
1082 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1083 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001084 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001085
1086 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001087 ASSERT_THAT(args,
1088 ElementsAre(VariantWith<NotifyMotionArgs>(
1089 AllOf(WithMotionAction(
1090 AMOTION_EVENT_ACTION_POINTER_UP |
1091 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1092 WithGestureOffset(0, 0, EPSILON),
1093 WithMotionClassification(
1094 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001095 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001096 VariantWith<NotifyMotionArgs>(
1097 AllOf(WithMotionAction(
1098 AMOTION_EVENT_ACTION_POINTER_UP |
1099 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1100 WithGestureOffset(0, 0, EPSILON),
1101 WithMotionClassification(
1102 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001103 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001104 VariantWith<NotifyMotionArgs>(
1105 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1106 WithGestureOffset(0, 0, EPSILON),
1107 WithMotionClassification(
1108 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001109 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001110 VariantWith<NotifyMotionArgs>(
1111 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001112 WithMotionClassification(MotionClassification::NONE)))));
1113 ASSERT_THAT(args,
1114 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1115 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001116}
1117
1118TEST_F(GestureConverterTest, ResetDuringPinch) {
1119 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1120 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001121 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001122
1123 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1124 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001125 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001126
1127 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001128 ASSERT_THAT(args,
1129 ElementsAre(VariantWith<NotifyMotionArgs>(
1130 AllOf(WithMotionAction(
1131 AMOTION_EVENT_ACTION_POINTER_UP |
1132 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1133 WithMotionClassification(MotionClassification::PINCH),
1134 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001135 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001136 VariantWith<NotifyMotionArgs>(
1137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1138 WithMotionClassification(MotionClassification::PINCH),
1139 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001140 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001141 VariantWith<NotifyMotionArgs>(
1142 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1143 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +00001144 WithMotionClassification(MotionClassification::NONE)))));
1145 ASSERT_THAT(args,
1146 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1147 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001148}
1149
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001150TEST_F(GestureConverterTest, FlingTapDown) {
1151 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1152 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001153 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001154
1155 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1156 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001157 std::list<NotifyArgs> args =
1158 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001159
1160 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001161 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001162 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001163 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1164 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001165
1166 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1167 ASSERT_TRUE(mFakePointerController->isPointerShown());
1168}
1169
Harry Cutts39648ab2024-02-15 14:23:50 +00001170TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1171 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1172 input_flags::enable_touchpad_fling_stop(true);
1173 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1174 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1175
1176 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1177 std::list<NotifyArgs> args =
1178 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1179 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1180 GESTURES_FLING_START);
1181 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1182
1183 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1184 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1185 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1186 ASSERT_THAT(args,
1187 ElementsAre(VariantWith<NotifyMotionArgs>(
1188 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1189 VariantWith<NotifyMotionArgs>(
1190 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1191 VariantWith<NotifyMotionArgs>(
1192 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1193 VariantWith<NotifyMotionArgs>(
1194 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1195 WithMotionClassification(MotionClassification::NONE)))));
1196 ASSERT_THAT(args,
1197 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1198 WithToolType(ToolType::FINGER),
1199 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
1200}
1201
Arpit Singha5ea7c12023-07-05 15:39:25 +00001202TEST_F(GestureConverterTest, Tap) {
1203 // Tap should produce button press/release events
1204 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1205 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001206 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001207
1208 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1209 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001210 std::list<NotifyArgs> args =
1211 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001212 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001213
1214 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1215 /* down= */ GESTURES_BUTTON_LEFT,
1216 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001217 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001218
Harry Cutts5f26e952023-11-30 18:20:27 +00001219 ASSERT_THAT(args,
1220 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001221 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001222 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001223 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001224 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001225 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001226 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001227 VariantWith<NotifyMotionArgs>(
1228 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1229 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1230 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001231 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001232 VariantWith<NotifyMotionArgs>(
1233 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1234 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001235 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001236 VariantWith<NotifyMotionArgs>(
1237 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001238 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001239 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001240 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001241 WithButtonState(0), WithPressure(0.0f)))));
1242 ASSERT_THAT(args,
1243 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1244 WithRelativeMotion(0.f, 0.f),
1245 WithToolType(ToolType::FINGER),
1246 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001247}
1248
1249TEST_F(GestureConverterTest, Click) {
1250 // Click should produce button press/release events
1251 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1252 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001253 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001254
1255 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1256 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001257 std::list<NotifyArgs> args =
1258 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001259 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001260
1261 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1262 /* down= */ GESTURES_BUTTON_LEFT,
1263 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001264 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001265
Harry Cutts5f26e952023-11-30 18:20:27 +00001266 ASSERT_THAT(args,
1267 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001268 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001269 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001270 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001271 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001272 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001273 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001274 VariantWith<NotifyMotionArgs>(
1275 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1276 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1277 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001278 WithPressure(1.0f)))));
1279 ASSERT_THAT(args,
1280 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1281 WithRelativeMotion(0.f, 0.f),
1282 WithToolType(ToolType::FINGER),
1283 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001284
1285 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1286 /* down= */ GESTURES_BUTTON_NONE,
1287 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001288 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001289 ASSERT_THAT(args,
1290 ElementsAre(VariantWith<NotifyMotionArgs>(
1291 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1292 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001293 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001294 VariantWith<NotifyMotionArgs>(
1295 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001296 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001297 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001298 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001299 WithPressure(0.0f)))));
1300 ASSERT_THAT(args,
1301 Each(VariantWith<NotifyMotionArgs>(
1302 AllOf(WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1303 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
1304 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001305}
1306
Arpit Singh3d84add2023-10-10 19:08:29 +00001307TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001308 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1309 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1310 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1311
Arpit Singha5ea7c12023-07-05 15:39:25 +00001312 // Tap should be ignored when disabled
1313 mReader->getContext()->setPreventingTouchpadTaps(true);
1314
1315 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1316 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001317 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001318
Arpit Singh82b27a02023-10-16 11:02:19 +00001319 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001320 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001321 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001322 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001323 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001324
Arpit Singh82b27a02023-10-16 11:02:19 +00001325 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001326 /* down= */ GESTURES_BUTTON_LEFT,
1327 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001328 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001329
1330 // no events should be generated
1331 ASSERT_EQ(0u, args.size());
1332
1333 // Future taps should be re-enabled
1334 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1335}
1336
Arpit Singh82b27a02023-10-16 11:02:19 +00001337TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1338 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1339 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1340
1341 // Tap should be ignored when disabled
1342 mReader->getContext()->setPreventingTouchpadTaps(true);
1343
1344 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1345 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1346 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1347
1348 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1349 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1350 std::list<NotifyArgs> args =
1351 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001352 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001353
1354 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1355 /* down= */ GESTURES_BUTTON_LEFT,
1356 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1357 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1358
1359 // no events should be generated
1360 ASSERT_EQ(0u, args.size());
1361
1362 // Future taps should be re-enabled
1363 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1364
1365 // taps before the threshold should still be ignored
1366 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1367 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1368 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1369 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1370
1371 ASSERT_EQ(1u, args.size());
1372 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1373 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1374
1375 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1376 /* down= */ GESTURES_BUTTON_LEFT,
1377 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1378 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1379
1380 // no events should be generated
1381 ASSERT_EQ(0u, args.size());
1382
1383 // taps after the threshold should be recognised
1384 currentTime += 1;
1385 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1386 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1387 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1388
1389 ASSERT_EQ(1u, args.size());
1390 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1391 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1392
1393 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1394 /* down= */ GESTURES_BUTTON_LEFT,
1395 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1396 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001397 ASSERT_THAT(args,
1398 ElementsAre(VariantWith<NotifyMotionArgs>(
1399 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1400 WithButtonState(0))),
1401 VariantWith<NotifyMotionArgs>(
1402 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1403 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1404 VariantWith<NotifyMotionArgs>(
1405 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1406 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1407 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1408 VariantWith<NotifyMotionArgs>(
1409 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1410 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1411 WithButtonState(0))),
1412 VariantWith<NotifyMotionArgs>(
1413 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1414 WithButtonState(0))),
1415 VariantWith<NotifyMotionArgs>(
1416 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1417 WithButtonState(0)))));
1418 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001419}
1420
Arpit Singh3d84add2023-10-10 19:08:29 +00001421TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1422 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001423 // Click should still produce button press/release events
1424 mReader->getContext()->setPreventingTouchpadTaps(true);
1425
1426 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1427 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001428 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001429
1430 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1431 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001432 std::list<NotifyArgs> args =
1433 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001434 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001435
1436 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1437 /* down= */ GESTURES_BUTTON_LEFT,
1438 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001439 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001440 ASSERT_THAT(args,
1441 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001442 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001443 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001444 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001445 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001446 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001447 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001448 VariantWith<NotifyMotionArgs>(
1449 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1450 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1451 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001452 WithPressure(1.0f)))));
1453 ASSERT_THAT(args,
1454 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1455 WithRelativeMotion(0.f, 0.f),
1456 WithToolType(ToolType::FINGER),
1457 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001458
1459 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1460 /* down= */ GESTURES_BUTTON_NONE,
1461 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001462 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001463
Harry Cutts5f26e952023-11-30 18:20:27 +00001464 ASSERT_THAT(args,
1465 ElementsAre(VariantWith<NotifyMotionArgs>(
1466 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1467 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001468 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001469 VariantWith<NotifyMotionArgs>(
1470 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001471 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001472 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001473 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001474 WithButtonState(0), WithPressure(0.0f)))));
1475 ASSERT_THAT(args,
1476 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1477 WithRelativeMotion(0.f, 0.f),
1478 WithToolType(ToolType::FINGER),
1479 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001480
1481 // Future taps should be re-enabled
1482 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1483}
1484
Arpit Singh3d84add2023-10-10 19:08:29 +00001485TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1486 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001487 // initially disable tap-to-click
1488 mReader->getContext()->setPreventingTouchpadTaps(true);
1489
1490 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1491 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001492 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001493
1494 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001495 std::list<NotifyArgs> args =
1496 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001497 // We don't need to check args here, since it's covered by the Move test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001498
1499 // Future taps should be re-enabled
1500 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1501}
1502
Arpit Singh33a10a62023-10-12 13:06:54 +00001503TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1504 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1505 const nsecs_t gestureStartTime = 1000;
1506 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1507 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1508 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1509
1510 // Start a move gesture at gestureStartTime
1511 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1512 std::list<NotifyArgs> args =
1513 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001514 ASSERT_THAT(args,
1515 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001516 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1517 VariantWith<NotifyMotionArgs>(
1518 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001519
1520 // Key presses with IME connection should cancel ongoing move gesture
1521 nsecs_t currentTime = gestureStartTime + 100;
1522 mFakePolicy->setIsInputMethodConnectionActive(true);
1523 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1524 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1525 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001526 ASSERT_THAT(args,
1527 ElementsAre(VariantWith<NotifyMotionArgs>(
1528 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001529
1530 // any updates in existing move gesture should be ignored
1531 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1532 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1533 ASSERT_EQ(0u, args.size());
1534
1535 // New gesture should not be affected
1536 currentTime += 100;
1537 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1538 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001539 ASSERT_THAT(args,
1540 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001541 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1542 VariantWith<NotifyMotionArgs>(
1543 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001544}
1545
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001546// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1547// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001548class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1549protected:
1550 void SetUp() override {
1551 input_flags::enable_pointer_choreographer(true);
1552 GestureConverterTestBase::SetUp();
1553 }
1554};
1555
1556TEST_F(GestureConverterTestWithChoreographer, Move) {
1557 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1558 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1559 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1560
1561 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001562 std::list<NotifyArgs> args =
1563 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001564 ASSERT_THAT(args,
1565 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001566 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001567 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001568 VariantWith<NotifyMotionArgs>(
1569 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001570 WithRelativeMotion(-5, 10), WithButtonState(0),
1571 WithPressure(0.0f)))));
1572 ASSERT_THAT(args,
1573 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1574 WithToolType(ToolType::FINGER),
1575 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts379ea422023-12-21 15:31:47 +00001576
1577 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
1578 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1579 ASSERT_THAT(args,
1580 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001581 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1582 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1583 WithButtonState(0), WithPressure(0.0f),
1584 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001585}
1586
1587TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1588 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1589 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1590 converter.setOrientation(ui::ROTATION_90);
1591 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1592
1593 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001594 std::list<NotifyArgs> args =
1595 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001596 ASSERT_THAT(args,
1597 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001598 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001599 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001600 VariantWith<NotifyMotionArgs>(
1601 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001602 WithRelativeMotion(10, 5), WithButtonState(0),
1603 WithPressure(0.0f)))));
1604 ASSERT_THAT(args,
1605 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1606 WithToolType(ToolType::FINGER),
1607 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001608}
1609
1610TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1611 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1612 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1613 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1614
1615 // Press left and right buttons at once
1616 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1617 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1618 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001619 std::list<NotifyArgs> args =
1620 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001621 ASSERT_THAT(args,
1622 ElementsAre(VariantWith<NotifyMotionArgs>(
1623 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1624 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +00001625 AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001626 VariantWith<NotifyMotionArgs>(
1627 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1628 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001629 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001630 VariantWith<NotifyMotionArgs>(
1631 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1632 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1633 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +00001634 AMOTION_EVENT_BUTTON_SECONDARY)))));
1635 ASSERT_THAT(args,
1636 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1637 WithToolType(ToolType::FINGER),
1638 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001639
1640 // Then release the left button
1641 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1642 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1643 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001644 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001645 ASSERT_THAT(args,
1646 ElementsAre(VariantWith<NotifyMotionArgs>(
1647 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1648 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1649 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1650 WithToolType(ToolType::FINGER),
1651 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001652
1653 // Finally release the right button
1654 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1655 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1656 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001657 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001658 ASSERT_THAT(args,
1659 ElementsAre(VariantWith<NotifyMotionArgs>(
1660 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001661 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001662 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001663 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +00001664 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001665 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
1666 ASSERT_THAT(args,
1667 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
1668 WithToolType(ToolType::FINGER),
1669 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001670}
1671
Harry Cutts379ea422023-12-21 15:31:47 +00001672TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) {
1673 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1674 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1675 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1676
1677 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1678 std::list<NotifyArgs> args =
1679 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1680
1681 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1682 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
1683 /*is_tap=*/false);
1684 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
1685 ASSERT_THAT(args.front(),
1686 VariantWith<NotifyMotionArgs>(
1687 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
1688 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1689 WithDisplayId(ADISPLAY_ID_DEFAULT))));
1690}
1691
Byoungho Jungee6268f2023-10-30 17:27:26 +09001692TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1693 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1694 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1695 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1696
1697 // Press the button
1698 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1699 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1700 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001701 std::list<NotifyArgs> args =
1702 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001703 ASSERT_THAT(args,
1704 ElementsAre(VariantWith<NotifyMotionArgs>(
1705 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00001706 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001707 VariantWith<NotifyMotionArgs>(
1708 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1709 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001710 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)))));
1711 ASSERT_THAT(args,
1712 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1713 WithToolType(ToolType::FINGER),
1714 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001715
1716 // Move
1717 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001718 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001719 ASSERT_THAT(args,
1720 ElementsAre(VariantWith<NotifyMotionArgs>(
1721 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1722 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1723 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1724 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001725
1726 // Release the button
1727 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1728 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1729 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001730 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001731 ASSERT_THAT(args,
1732 ElementsAre(VariantWith<NotifyMotionArgs>(
1733 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001734 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001735 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001736 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +00001737 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001738 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
1739 ASSERT_THAT(args,
1740 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
1741 WithToolType(ToolType::FINGER),
1742 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001743}
1744
1745TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1746 const nsecs_t downTime = 12345;
1747 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1748 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1749 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1750
1751 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001752 std::list<NotifyArgs> args =
1753 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001754 ASSERT_THAT(args,
1755 ElementsAre(VariantWith<NotifyMotionArgs>(
1756 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1757 WithCoords(0, 0),
1758 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001759 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001760 VariantWith<NotifyMotionArgs>(
1761 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1762 WithCoords(0, -10),
Harry Cuttsef95e712024-02-16 18:56:39 +00001763 WithGestureScrollDistance(0, 10, EPSILON)))));
1764 ASSERT_THAT(args,
1765 Each(VariantWith<NotifyMotionArgs>(
1766 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1767 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1768 WithToolType(ToolType::FINGER),
1769 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001770
1771 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001772 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001773 ASSERT_THAT(args,
1774 ElementsAre(VariantWith<NotifyMotionArgs>(
1775 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1776 WithGestureScrollDistance(0, 5, EPSILON),
1777 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1778 WithToolType(ToolType::FINGER),
1779 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1780 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001781
1782 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1783 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001784 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001785 ASSERT_THAT(args,
1786 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001787 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1788 WithCoords(0, -15),
1789 WithGestureScrollDistance(0, 0, EPSILON),
1790 WithMotionClassification(
1791 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001792 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001793 VariantWith<NotifyMotionArgs>(
1794 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1795 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001796 WithMotionClassification(MotionClassification::NONE)))));
1797 ASSERT_THAT(args,
1798 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1799 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001800}
1801
1802TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1803 const nsecs_t downTime = 12345;
1804 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1805 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1806 converter.setOrientation(ui::ROTATION_90);
1807 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1808
1809 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001810 std::list<NotifyArgs> args =
1811 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001812 ASSERT_THAT(args,
1813 ElementsAre(VariantWith<NotifyMotionArgs>(
1814 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1815 WithCoords(0, 0),
1816 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001817 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001818 VariantWith<NotifyMotionArgs>(
1819 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1820 WithCoords(-10, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001821 WithGestureScrollDistance(0, 10, EPSILON)))));
1822 ASSERT_THAT(args,
1823 Each(VariantWith<NotifyMotionArgs>(
1824 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1825 WithToolType(ToolType::FINGER),
1826 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001827
1828 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001829 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001830 ASSERT_THAT(args,
1831 ElementsAre(VariantWith<NotifyMotionArgs>(
1832 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1833 WithGestureScrollDistance(0, 5, EPSILON),
1834 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1835 WithToolType(ToolType::FINGER),
1836 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001837
1838 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1839 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001840 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001841 ASSERT_THAT(args,
1842 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001843 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1844 WithCoords(-15, 0),
1845 WithGestureScrollDistance(0, 0, EPSILON),
1846 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +00001847 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001848 VariantWith<NotifyMotionArgs>(
1849 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1850 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001851 WithMotionClassification(MotionClassification::NONE)))));
1852 ASSERT_THAT(args,
1853 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1854 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001855}
1856
1857TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1858 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1859 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1860 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1861
1862 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001863 std::list<NotifyArgs> args =
1864 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001865
1866 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001867 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001868
1869 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1870 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001871 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001872
1873 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001874 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001875 ASSERT_THAT(args,
1876 ElementsAre(VariantWith<NotifyMotionArgs>(
1877 AllOf(WithMotionClassification(MotionClassification::NONE),
1878 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001879}
1880
1881TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1882 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1883 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1884 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1885
1886 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001887 std::list<NotifyArgs> args =
1888 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001889
1890 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001891 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001892
1893 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1894 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001895 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001896
1897 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1898 // need to use another gesture type, like pinch.
1899 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1900 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001901 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001902 ASSERT_FALSE(args.empty());
1903 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1904}
1905
1906TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1907 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1908 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1909 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1910
1911 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1912 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001913 std::list<NotifyArgs> args =
1914 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001915
1916 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001917 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001918
1919 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1920 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001921 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001922 ASSERT_THAT(args,
1923 ElementsAre(VariantWith<NotifyMotionArgs>(
1924 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001925}
1926
1927TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1928 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1929 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1930 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1931
1932 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1933 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001934 std::list<NotifyArgs> args =
1935 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001936
1937 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001938 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001939
1940 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1941 // need to use another gesture type, like pinch.
1942 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1943 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001944 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001945 ASSERT_FALSE(args.empty());
1946 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1947 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1948}
1949
1950TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1951 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1952 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1953 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1954 // only checks movement in one dimension.
1955 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1956 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1957 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1958
1959 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1960 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001961 std::list<NotifyArgs> args =
1962 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001963 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00001964 ASSERT_THAT(args,
1965 Each(VariantWith<NotifyMotionArgs>(
1966 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1967 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
1968 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001969
1970 // Three fake fingers should be created. We don't actually care where they are, so long as they
1971 // move appropriately.
1972 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1973 ASSERT_THAT(arg,
1974 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001975 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001976 PointerCoords finger0Start = arg.pointerCoords[0];
1977 args.pop_front();
1978 arg = std::get<NotifyMotionArgs>(args.front());
1979 ASSERT_THAT(arg,
1980 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1981 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001982 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001983 PointerCoords finger1Start = arg.pointerCoords[1];
1984 args.pop_front();
1985 arg = std::get<NotifyMotionArgs>(args.front());
1986 ASSERT_THAT(arg,
1987 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1988 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001989 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001990 PointerCoords finger2Start = arg.pointerCoords[2];
1991 args.pop_front();
1992
1993 arg = std::get<NotifyMotionArgs>(args.front());
1994 ASSERT_THAT(arg,
1995 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001996 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001997 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1998 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1999 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2000 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
2001 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
2002 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
2003
2004 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2005 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002006 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002007 ASSERT_EQ(1u, args.size());
2008 arg = std::get<NotifyMotionArgs>(args.front());
2009 ASSERT_THAT(arg,
2010 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2011 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
2012 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2013 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2014 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2015 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2016 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2017 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2018 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
2019 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
2020 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
2021
2022 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002023 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002024 ASSERT_THAT(args,
2025 ElementsAre(VariantWith<NotifyMotionArgs>(
2026 AllOf(WithMotionAction(
2027 AMOTION_EVENT_ACTION_POINTER_UP |
2028 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2029 WithGestureOffset(0, 0, EPSILON),
2030 WithGestureSwipeFingerCount(3),
2031 WithMotionClassification(
2032 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002033 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002034 VariantWith<NotifyMotionArgs>(
2035 AllOf(WithMotionAction(
2036 AMOTION_EVENT_ACTION_POINTER_UP |
2037 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2038 WithGestureOffset(0, 0, EPSILON),
2039 WithGestureSwipeFingerCount(3),
2040 WithMotionClassification(
2041 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002042 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002043 VariantWith<NotifyMotionArgs>(
2044 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2045 WithGestureOffset(0, 0, EPSILON),
2046 WithGestureSwipeFingerCount(3),
2047 WithMotionClassification(
2048 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002049 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002050 VariantWith<NotifyMotionArgs>(
2051 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2052 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002053 WithMotionClassification(MotionClassification::NONE)))));
2054 ASSERT_THAT(args,
2055 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2056 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002057}
2058
2059TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
2060 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2061 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2062 converter.setOrientation(ui::ROTATION_90);
2063 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2064
2065 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2066 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002067 std::list<NotifyArgs> args =
2068 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002069 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00002070 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002071
2072 // Three fake fingers should be created. We don't actually care where they are, so long as they
2073 // move appropriately.
2074 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2075 ASSERT_THAT(arg,
2076 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002077 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002078 PointerCoords finger0Start = arg.pointerCoords[0];
2079 args.pop_front();
2080 arg = std::get<NotifyMotionArgs>(args.front());
2081 ASSERT_THAT(arg,
2082 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2083 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002084 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002085 PointerCoords finger1Start = arg.pointerCoords[1];
2086 args.pop_front();
2087 arg = std::get<NotifyMotionArgs>(args.front());
2088 ASSERT_THAT(arg,
2089 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2090 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002091 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002092 PointerCoords finger2Start = arg.pointerCoords[2];
2093 args.pop_front();
2094
2095 arg = std::get<NotifyMotionArgs>(args.front());
2096 ASSERT_THAT(arg,
2097 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002098 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002099 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
2100 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
2101 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
2102 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2103 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2104 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2105
2106 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2107 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002108 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002109 ASSERT_EQ(1u, args.size());
2110 arg = std::get<NotifyMotionArgs>(args.front());
2111 ASSERT_THAT(arg,
2112 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2113 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
2114 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2115 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
2116 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
2117 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
2118 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2119 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2120 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2121
2122 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002123 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002124 ASSERT_THAT(args,
2125 ElementsAre(VariantWith<NotifyMotionArgs>(
2126 AllOf(WithMotionAction(
2127 AMOTION_EVENT_ACTION_POINTER_UP |
2128 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002129 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002130 VariantWith<NotifyMotionArgs>(
2131 AllOf(WithMotionAction(
2132 AMOTION_EVENT_ACTION_POINTER_UP |
2133 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002134 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002135 VariantWith<NotifyMotionArgs>(
2136 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002137 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002138 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00002139 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
2140 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002141}
2142
2143TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2144 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2145 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2146 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2147
2148 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2149 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002150 std::list<NotifyArgs> args =
2151 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002152 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00002153 ASSERT_THAT(args,
2154 Each(VariantWith<NotifyMotionArgs>(
2155 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2156 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
2157 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002158
2159 // Four fake fingers should be created. We don't actually care where they are, so long as they
2160 // move appropriately.
2161 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2162 ASSERT_THAT(arg,
2163 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002164 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002165 PointerCoords finger0Start = arg.pointerCoords[0];
2166 args.pop_front();
2167 arg = std::get<NotifyMotionArgs>(args.front());
2168 ASSERT_THAT(arg,
2169 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2170 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002171 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002172 PointerCoords finger1Start = arg.pointerCoords[1];
2173 args.pop_front();
2174 arg = std::get<NotifyMotionArgs>(args.front());
2175 ASSERT_THAT(arg,
2176 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2177 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002178 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002179 PointerCoords finger2Start = arg.pointerCoords[2];
2180 args.pop_front();
2181 arg = std::get<NotifyMotionArgs>(args.front());
2182 ASSERT_THAT(arg,
2183 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2184 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002185 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002186 PointerCoords finger3Start = arg.pointerCoords[3];
2187 args.pop_front();
2188
2189 arg = std::get<NotifyMotionArgs>(args.front());
2190 ASSERT_THAT(arg,
2191 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002192 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002193 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2194 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2195 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2196 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2197 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2198 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2199 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2200 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2201
2202 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2203 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002204 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002205 ASSERT_EQ(1u, args.size());
2206 arg = std::get<NotifyMotionArgs>(args.front());
2207 ASSERT_THAT(arg,
2208 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2209 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2210 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2211 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2212 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2213 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2214 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2215 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2216 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.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 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2221
2222 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002223 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002224 ASSERT_THAT(args,
2225 ElementsAre(VariantWith<NotifyMotionArgs>(
2226 AllOf(WithMotionAction(
2227 AMOTION_EVENT_ACTION_POINTER_UP |
2228 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2229 WithGestureOffset(0, 0, EPSILON),
2230 WithGestureSwipeFingerCount(4),
2231 WithMotionClassification(
2232 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002233 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002234 VariantWith<NotifyMotionArgs>(
2235 AllOf(WithMotionAction(
2236 AMOTION_EVENT_ACTION_POINTER_UP |
2237 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2238 WithGestureOffset(0, 0, EPSILON),
2239 WithGestureSwipeFingerCount(4),
2240 WithMotionClassification(
2241 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002242 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002243 VariantWith<NotifyMotionArgs>(
2244 AllOf(WithMotionAction(
2245 AMOTION_EVENT_ACTION_POINTER_UP |
2246 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2247 WithGestureOffset(0, 0, EPSILON),
2248 WithGestureSwipeFingerCount(4),
2249 WithMotionClassification(
2250 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002251 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002252 VariantWith<NotifyMotionArgs>(
2253 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2254 WithGestureOffset(0, 0, EPSILON),
2255 WithGestureSwipeFingerCount(4),
2256 WithMotionClassification(
2257 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002258 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002259 VariantWith<NotifyMotionArgs>(
2260 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2261 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002262 WithMotionClassification(MotionClassification::NONE)))));
2263 ASSERT_THAT(args,
2264 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2265 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002266}
2267
2268TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2269 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2270 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2271 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2272
2273 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2274 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002275 std::list<NotifyArgs> args =
2276 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002277 ASSERT_THAT(args,
2278 ElementsAre(VariantWith<NotifyMotionArgs>(
2279 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00002280 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002281 VariantWith<NotifyMotionArgs>(
2282 AllOf(WithMotionAction(
2283 AMOTION_EVENT_ACTION_POINTER_DOWN |
2284 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002285 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
2286 ASSERT_THAT(args,
2287 Each(VariantWith<NotifyMotionArgs>(
2288 AllOf(WithMotionClassification(MotionClassification::PINCH),
2289 WithGesturePinchScaleFactor(1.0f, EPSILON),
2290 WithToolType(ToolType::FINGER),
2291 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002292
2293 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2294 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002295 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002296 ASSERT_THAT(args,
2297 ElementsAre(VariantWith<NotifyMotionArgs>(
2298 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2299 WithMotionClassification(MotionClassification::PINCH),
2300 WithGesturePinchScaleFactor(0.8f, EPSILON),
2301 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
2302 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2303 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002304
2305 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2306 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002307 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002308 ASSERT_THAT(args,
2309 ElementsAre(VariantWith<NotifyMotionArgs>(
2310 AllOf(WithMotionAction(
2311 AMOTION_EVENT_ACTION_POINTER_UP |
2312 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2313 WithMotionClassification(MotionClassification::PINCH),
2314 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002315 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002316 VariantWith<NotifyMotionArgs>(
2317 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2318 WithMotionClassification(MotionClassification::PINCH),
2319 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002320 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002321 VariantWith<NotifyMotionArgs>(
2322 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2323 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002324 WithMotionClassification(MotionClassification::NONE)))));
2325 ASSERT_THAT(args,
2326 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2327 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002328}
2329
2330TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2331 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2332 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2333 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2334
2335 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2336 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002337 std::list<NotifyArgs> args =
2338 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002339 ASSERT_THAT(args,
2340 ElementsAre(VariantWith<NotifyMotionArgs>(
2341 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00002342 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002343 VariantWith<NotifyMotionArgs>(
2344 AllOf(WithMotionAction(
2345 AMOTION_EVENT_ACTION_POINTER_DOWN |
2346 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002347 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
2348 ASSERT_THAT(args,
2349 Each(VariantWith<NotifyMotionArgs>(
2350 AllOf(WithMotionClassification(MotionClassification::PINCH),
2351 WithGesturePinchScaleFactor(1.0f, EPSILON),
2352 WithToolType(ToolType::FINGER),
2353 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002354
2355 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2356 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002357 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002358 ASSERT_THAT(args,
2359 ElementsAre(VariantWith<NotifyMotionArgs>(
2360 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2361 WithMotionClassification(MotionClassification::PINCH),
2362 WithGesturePinchScaleFactor(1.1f, EPSILON),
2363 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
2364 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2365 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002366
2367 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2368 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002369 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002370 ASSERT_THAT(args,
2371 ElementsAre(VariantWith<NotifyMotionArgs>(
2372 AllOf(WithMotionAction(
2373 AMOTION_EVENT_ACTION_POINTER_UP |
2374 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2375 WithMotionClassification(MotionClassification::PINCH),
2376 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002377 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002378 VariantWith<NotifyMotionArgs>(
2379 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2380 WithMotionClassification(MotionClassification::PINCH),
2381 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002382 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002383 VariantWith<NotifyMotionArgs>(
2384 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2385 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002386 WithMotionClassification(MotionClassification::NONE)))));
2387 ASSERT_THAT(args,
2388 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2389 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002390}
2391
2392TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2393 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2394 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2395 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2396
2397 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2398 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002399 std::list<NotifyArgs> args =
2400 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002401
2402 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2403 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002404 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002405
2406 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2407 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002408 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002409
2410 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002411 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002412 ASSERT_THAT(args,
2413 ElementsAre(VariantWith<NotifyMotionArgs>(
2414 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002415}
2416
2417TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2418 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2419 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2420 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2421
2422 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2423 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002424 std::list<NotifyArgs> args =
2425 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002426
2427 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2428 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002429 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002430
2431 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2432 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002433 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002434
2435 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2436 // need to use another gesture type, like scroll.
2437 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2438 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002439 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002440 ASSERT_FALSE(args.empty());
2441 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2442}
2443
2444TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2445 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2446 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2447 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2448
2449 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2450 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2451 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002452 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002453
2454 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002455 ASSERT_THAT(args,
2456 ElementsAre(VariantWith<NotifyMotionArgs>(
2457 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2458 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002459 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002460 VariantWith<NotifyMotionArgs>(
2461 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2462 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002463 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002464 VariantWith<NotifyMotionArgs>(
2465 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002466 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00002467 VariantWith<NotifyMotionArgs>(
2468 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002469 WithButtonState(0)))));
2470 ASSERT_THAT(args,
2471 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2472 WithToolType(ToolType::FINGER),
2473 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002474}
2475
2476TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2477 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2478 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2479 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2480
2481 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002482 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002483
2484 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002485 ASSERT_THAT(args,
2486 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002487 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2488 WithCoords(0, -10),
2489 WithGestureScrollDistance(0, 0, EPSILON),
2490 WithMotionClassification(
2491 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002492 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00002493 VariantWith<NotifyMotionArgs>(
2494 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2495 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002496 WithMotionClassification(MotionClassification::NONE)))));
2497 ASSERT_THAT(args,
2498 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2499 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002500}
2501
2502TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2503 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2504 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2505 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2506
2507 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2508 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002509 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002510
2511 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002512 ASSERT_THAT(args,
2513 ElementsAre(VariantWith<NotifyMotionArgs>(
2514 AllOf(WithMotionAction(
2515 AMOTION_EVENT_ACTION_POINTER_UP |
2516 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2517 WithGestureOffset(0, 0, EPSILON),
2518 WithMotionClassification(
2519 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002520 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002521 VariantWith<NotifyMotionArgs>(
2522 AllOf(WithMotionAction(
2523 AMOTION_EVENT_ACTION_POINTER_UP |
2524 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2525 WithGestureOffset(0, 0, EPSILON),
2526 WithMotionClassification(
2527 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002528 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002529 VariantWith<NotifyMotionArgs>(
2530 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2531 WithGestureOffset(0, 0, EPSILON),
2532 WithMotionClassification(
2533 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002534 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002535 VariantWith<NotifyMotionArgs>(
2536 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002537 WithMotionClassification(MotionClassification::NONE)))));
2538 ASSERT_THAT(args,
2539 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2540 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002541}
2542
2543TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2544 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2545 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2546 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2547
2548 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2549 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002550 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002551
2552 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002553 ASSERT_THAT(args,
2554 ElementsAre(VariantWith<NotifyMotionArgs>(
2555 AllOf(WithMotionAction(
2556 AMOTION_EVENT_ACTION_POINTER_UP |
2557 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2558 WithMotionClassification(MotionClassification::PINCH),
2559 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002560 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002561 VariantWith<NotifyMotionArgs>(
2562 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2563 WithMotionClassification(MotionClassification::PINCH),
2564 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002565 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002566 VariantWith<NotifyMotionArgs>(
2567 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2568 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002569 WithMotionClassification(MotionClassification::NONE)))));
2570 ASSERT_THAT(args,
2571 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2572 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002573}
2574
2575TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2576 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2577 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2578 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2579
2580 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2581 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002582 std::list<NotifyArgs> args =
2583 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002584
2585 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00002586 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
Byoungho Jungee6268f2023-10-30 17:27:26 +09002587 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2588 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2589}
2590
Harry Cutts39648ab2024-02-15 14:23:50 +00002591TEST_F(GestureConverterTestWithChoreographer, FlingTapDownAfterScrollStopsFling) {
2592 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2593 input_flags::enable_touchpad_fling_stop(true);
2594 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2595 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2596
2597 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
2598 std::list<NotifyArgs> args =
2599 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
2600 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
2601 GESTURES_FLING_START);
2602 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
2603
2604 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2605 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
2606 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
2607 ASSERT_THAT(args,
2608 ElementsAre(VariantWith<NotifyMotionArgs>(
2609 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
2610 VariantWith<NotifyMotionArgs>(
2611 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
2612 VariantWith<NotifyMotionArgs>(
2613 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
2614 VariantWith<NotifyMotionArgs>(
2615 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2616 WithMotionClassification(MotionClassification::NONE)))));
2617 ASSERT_THAT(args,
2618 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2619 WithToolType(ToolType::FINGER),
2620 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
2621}
2622
Byoungho Jungee6268f2023-10-30 17:27:26 +09002623TEST_F(GestureConverterTestWithChoreographer, Tap) {
2624 // Tap should produce button press/release events
2625 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2626 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2627 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2628
2629 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2630 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002631 std::list<NotifyArgs> args =
2632 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002633 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002634
2635 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2636 /* down= */ GESTURES_BUTTON_LEFT,
2637 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002638 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002639
Harry Cutts5f26e952023-11-30 18:20:27 +00002640 ASSERT_THAT(args,
2641 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002642 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002643 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002644 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002645 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002646 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002647 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002648 VariantWith<NotifyMotionArgs>(
2649 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2650 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2651 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002652 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002653 VariantWith<NotifyMotionArgs>(
2654 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2655 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002656 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002657 VariantWith<NotifyMotionArgs>(
2658 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002659 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002660 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002661 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002662 WithButtonState(0), WithPressure(0.0f)))));
2663 ASSERT_THAT(args,
2664 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2665 WithRelativeMotion(0.f, 0.f),
2666 WithToolType(ToolType::FINGER),
2667 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002668}
2669
2670TEST_F(GestureConverterTestWithChoreographer, Click) {
2671 // Click should produce button press/release events
2672 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2673 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2674 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2675
2676 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2677 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002678 std::list<NotifyArgs> args =
2679 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002680 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002681
2682 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2683 /* down= */ GESTURES_BUTTON_LEFT,
2684 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002685 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002686
Harry Cutts5f26e952023-11-30 18:20:27 +00002687 ASSERT_THAT(args,
2688 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002689 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002690 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002691 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002692 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002693 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002694 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002695 VariantWith<NotifyMotionArgs>(
2696 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2697 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2698 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002699 WithPressure(1.0f)))));
2700 ASSERT_THAT(args,
2701 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2702 WithRelativeMotion(0.f, 0.f),
2703 WithToolType(ToolType::FINGER),
2704 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002705
2706 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2707 /* down= */ GESTURES_BUTTON_NONE,
2708 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002709 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002710
Harry Cutts5f26e952023-11-30 18:20:27 +00002711 ASSERT_THAT(args,
2712 ElementsAre(VariantWith<NotifyMotionArgs>(
2713 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2714 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002715 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002716 VariantWith<NotifyMotionArgs>(
2717 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002718 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002719 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002720 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002721 WithPressure(0.0f)))));
2722 ASSERT_THAT(args,
2723 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
2724 WithRelativeMotion(0.f, 0.f),
2725 WithToolType(ToolType::FINGER),
2726 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002727}
2728
2729TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002730 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2731 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2732 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2733
Byoungho Jungee6268f2023-10-30 17:27:26 +09002734 // Tap should be ignored when disabled
2735 mReader->getContext()->setPreventingTouchpadTaps(true);
2736
2737 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2738 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2739 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2740
Arpit Singh82b27a02023-10-16 11:02:19 +00002741 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002742 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002743 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002744 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002745 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002746
Arpit Singh82b27a02023-10-16 11:02:19 +00002747 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002748 /* down= */ GESTURES_BUTTON_LEFT,
2749 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002750 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002751
2752 // no events should be generated
2753 ASSERT_EQ(0u, args.size());
2754
2755 // Future taps should be re-enabled
2756 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2757}
2758
Arpit Singh82b27a02023-10-16 11:02:19 +00002759TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2760 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2761 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2762
2763 // Tap should be ignored when disabled
2764 mReader->getContext()->setPreventingTouchpadTaps(true);
2765
2766 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2767 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2768 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2769
2770 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2771 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2772 std::list<NotifyArgs> args =
2773 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002774 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00002775
2776 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2777 /* down= */ GESTURES_BUTTON_LEFT,
2778 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2779 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2780
2781 // no events should be generated
2782 ASSERT_EQ(0u, args.size());
2783
2784 // Future taps should be re-enabled
2785 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2786
2787 // taps before the threshold should still be ignored
2788 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2789 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2790 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2791 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2792
2793 ASSERT_EQ(1u, args.size());
2794 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2795 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2796
2797 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2798 /* down= */ GESTURES_BUTTON_LEFT,
2799 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2800 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2801
2802 // no events should be generated
2803 ASSERT_EQ(0u, args.size());
2804
2805 // taps after the threshold should be recognised
2806 currentTime += 1;
2807 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2808 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2809 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2810
2811 ASSERT_EQ(1u, args.size());
2812 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2813 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2814
2815 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2816 /* down= */ GESTURES_BUTTON_LEFT,
2817 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2818 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00002819 ASSERT_THAT(args,
2820 ElementsAre(VariantWith<NotifyMotionArgs>(
2821 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2822 WithButtonState(0))),
2823 VariantWith<NotifyMotionArgs>(
2824 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2825 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
2826 VariantWith<NotifyMotionArgs>(
2827 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2828 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2829 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
2830 VariantWith<NotifyMotionArgs>(
2831 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2832 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2833 WithButtonState(0))),
2834 VariantWith<NotifyMotionArgs>(
2835 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2836 WithButtonState(0))),
2837 VariantWith<NotifyMotionArgs>(
2838 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2839 WithButtonState(0)))));
2840 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00002841}
2842
Byoungho Jungee6268f2023-10-30 17:27:26 +09002843TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2844 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2845 // Click should still produce button press/release events
2846 mReader->getContext()->setPreventingTouchpadTaps(true);
2847
2848 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2849 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2850 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2851
2852 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2853 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002854 std::list<NotifyArgs> args =
2855 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002856 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002857
2858 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2859 /* down= */ GESTURES_BUTTON_LEFT,
2860 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002861 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002862
Harry Cutts5f26e952023-11-30 18:20:27 +00002863 ASSERT_THAT(args,
2864 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002865 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002866 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002867 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002868 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002869 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002870 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002871 VariantWith<NotifyMotionArgs>(
2872 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2873 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2874 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002875 WithPressure(1.0f)))));
2876 ASSERT_THAT(args,
2877 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2878 WithRelativeMotion(0.f, 0.f),
2879 WithToolType(ToolType::FINGER),
2880 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002881
2882 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2883 /* down= */ GESTURES_BUTTON_NONE,
2884 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002885 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002886
Harry Cutts5f26e952023-11-30 18:20:27 +00002887 ASSERT_THAT(args,
2888 ElementsAre(VariantWith<NotifyMotionArgs>(
2889 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2890 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2891 WithButtonState(0), WithCoords(0, 0),
2892 WithRelativeMotion(0.f, 0.f),
2893 WithToolType(ToolType::FINGER), WithButtonState(0),
2894 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2895 VariantWith<NotifyMotionArgs>(
2896 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2897 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2898 WithToolType(ToolType::FINGER), WithButtonState(0),
2899 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2900 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002901 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002902 WithCoords(0, 0), WithRelativeMotion(0, 0),
2903 WithToolType(ToolType::FINGER), WithButtonState(0),
2904 WithPressure(0.0f),
2905 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002906
2907 // Future taps should be re-enabled
2908 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2909}
2910
2911TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2912 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2913 // initially disable tap-to-click
2914 mReader->getContext()->setPreventingTouchpadTaps(true);
2915
2916 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2917 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2918 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2919
2920 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002921 std::list<NotifyArgs> args =
2922 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002923 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002924
2925 // Future taps should be re-enabled
2926 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2927}
2928
Arpit Singh33a10a62023-10-12 13:06:54 +00002929TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
2930 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2931 const nsecs_t gestureStartTime = 1000;
2932 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2933 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2934 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2935
2936 // Start a move gesture at gestureStartTime
2937 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
2938 std::list<NotifyArgs> args =
2939 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002940 ASSERT_THAT(args,
2941 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002942 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
2943 VariantWith<NotifyMotionArgs>(
2944 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002945
2946 // Key presses with IME connection should cancel ongoing move gesture
2947 nsecs_t currentTime = gestureStartTime + 100;
2948 mFakePolicy->setIsInputMethodConnectionActive(true);
2949 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
2950 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2951 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002952 ASSERT_THAT(args,
2953 ElementsAre(VariantWith<NotifyMotionArgs>(
2954 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002955
2956 // any updates in existing move gesture should be ignored
2957 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2958 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2959 ASSERT_EQ(0u, args.size());
2960
2961 // New gesture should not be affected
2962 currentTime += 100;
2963 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2964 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002965 ASSERT_THAT(args,
2966 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002967 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
2968 VariantWith<NotifyMotionArgs>(
2969 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002970}
2971
Harry Cutts4fb941a2022-12-14 19:14:04 +00002972} // namespace android