blob: dd8816556196c52a16fafbecbb3bc05326930947 [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
Arpit Singha5ea7c12023-07-05 15:39:25 +00001170TEST_F(GestureConverterTest, Tap) {
1171 // Tap should produce button press/release events
1172 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1173 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001174 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001175
1176 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1177 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001178 std::list<NotifyArgs> args =
1179 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001180 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001181
1182 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1183 /* down= */ GESTURES_BUTTON_LEFT,
1184 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001185 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001186
Harry Cutts5f26e952023-11-30 18:20:27 +00001187 ASSERT_THAT(args,
1188 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001189 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001190 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001191 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001192 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001193 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001194 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001195 VariantWith<NotifyMotionArgs>(
1196 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1197 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1198 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001199 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001200 VariantWith<NotifyMotionArgs>(
1201 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1202 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001203 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001204 VariantWith<NotifyMotionArgs>(
1205 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001206 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001207 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001208 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001209 WithButtonState(0), WithPressure(0.0f)))));
1210 ASSERT_THAT(args,
1211 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1212 WithRelativeMotion(0.f, 0.f),
1213 WithToolType(ToolType::FINGER),
1214 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001215}
1216
1217TEST_F(GestureConverterTest, Click) {
1218 // Click should produce button press/release events
1219 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1220 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001221 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001222
1223 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1224 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001225 std::list<NotifyArgs> args =
1226 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001227 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001228
1229 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1230 /* down= */ GESTURES_BUTTON_LEFT,
1231 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001232 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001233
Harry Cutts5f26e952023-11-30 18:20:27 +00001234 ASSERT_THAT(args,
1235 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001236 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001237 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001238 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001239 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001240 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001241 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001242 VariantWith<NotifyMotionArgs>(
1243 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1244 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1245 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001246 WithPressure(1.0f)))));
1247 ASSERT_THAT(args,
1248 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1249 WithRelativeMotion(0.f, 0.f),
1250 WithToolType(ToolType::FINGER),
1251 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001252
1253 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1254 /* down= */ GESTURES_BUTTON_NONE,
1255 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001256 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001257 ASSERT_THAT(args,
1258 ElementsAre(VariantWith<NotifyMotionArgs>(
1259 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1260 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001261 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001262 VariantWith<NotifyMotionArgs>(
1263 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001264 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001265 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001266 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001267 WithPressure(0.0f)))));
1268 ASSERT_THAT(args,
1269 Each(VariantWith<NotifyMotionArgs>(
1270 AllOf(WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1271 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
1272 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001273}
1274
Arpit Singh3d84add2023-10-10 19:08:29 +00001275TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001276 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1277 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1278 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1279
Arpit Singha5ea7c12023-07-05 15:39:25 +00001280 // Tap should be ignored when disabled
1281 mReader->getContext()->setPreventingTouchpadTaps(true);
1282
1283 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1284 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001285 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001286
Arpit Singh82b27a02023-10-16 11:02:19 +00001287 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001288 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001289 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001290 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001291 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001292
Arpit Singh82b27a02023-10-16 11:02:19 +00001293 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001294 /* down= */ GESTURES_BUTTON_LEFT,
1295 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001296 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001297
1298 // no events should be generated
1299 ASSERT_EQ(0u, args.size());
1300
1301 // Future taps should be re-enabled
1302 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1303}
1304
Arpit Singh82b27a02023-10-16 11:02:19 +00001305TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1306 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1307 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1308
1309 // Tap should be ignored when disabled
1310 mReader->getContext()->setPreventingTouchpadTaps(true);
1311
1312 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1313 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1314 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1315
1316 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1317 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1318 std::list<NotifyArgs> args =
1319 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001320 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001321
1322 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1323 /* down= */ GESTURES_BUTTON_LEFT,
1324 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1325 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1326
1327 // no events should be generated
1328 ASSERT_EQ(0u, args.size());
1329
1330 // Future taps should be re-enabled
1331 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1332
1333 // taps before the threshold should still be ignored
1334 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1335 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1336 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1337 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1338
1339 ASSERT_EQ(1u, args.size());
1340 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1341 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1342
1343 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1344 /* down= */ GESTURES_BUTTON_LEFT,
1345 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1346 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1347
1348 // no events should be generated
1349 ASSERT_EQ(0u, args.size());
1350
1351 // taps after the threshold should be recognised
1352 currentTime += 1;
1353 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1354 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1355 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1356
1357 ASSERT_EQ(1u, args.size());
1358 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1359 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1360
1361 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1362 /* down= */ GESTURES_BUTTON_LEFT,
1363 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1364 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001365 ASSERT_THAT(args,
1366 ElementsAre(VariantWith<NotifyMotionArgs>(
1367 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1368 WithButtonState(0))),
1369 VariantWith<NotifyMotionArgs>(
1370 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1371 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1372 VariantWith<NotifyMotionArgs>(
1373 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1374 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1375 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1376 VariantWith<NotifyMotionArgs>(
1377 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1378 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1379 WithButtonState(0))),
1380 VariantWith<NotifyMotionArgs>(
1381 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1382 WithButtonState(0))),
1383 VariantWith<NotifyMotionArgs>(
1384 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1385 WithButtonState(0)))));
1386 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001387}
1388
Arpit Singh3d84add2023-10-10 19:08:29 +00001389TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1390 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001391 // Click should still produce button press/release events
1392 mReader->getContext()->setPreventingTouchpadTaps(true);
1393
1394 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1395 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001396 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001397
1398 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1399 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001400 std::list<NotifyArgs> args =
1401 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001402 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001403
1404 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1405 /* down= */ GESTURES_BUTTON_LEFT,
1406 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001407 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001408 ASSERT_THAT(args,
1409 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001410 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001411 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001412 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001413 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001414 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001415 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001416 VariantWith<NotifyMotionArgs>(
1417 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1418 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1419 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001420 WithPressure(1.0f)))));
1421 ASSERT_THAT(args,
1422 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1423 WithRelativeMotion(0.f, 0.f),
1424 WithToolType(ToolType::FINGER),
1425 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001426
1427 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1428 /* down= */ GESTURES_BUTTON_NONE,
1429 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001430 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001431
Harry Cutts5f26e952023-11-30 18:20:27 +00001432 ASSERT_THAT(args,
1433 ElementsAre(VariantWith<NotifyMotionArgs>(
1434 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1435 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001436 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001437 VariantWith<NotifyMotionArgs>(
1438 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001439 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001440 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001441 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001442 WithButtonState(0), WithPressure(0.0f)))));
1443 ASSERT_THAT(args,
1444 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1445 WithRelativeMotion(0.f, 0.f),
1446 WithToolType(ToolType::FINGER),
1447 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001448
1449 // Future taps should be re-enabled
1450 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1451}
1452
Arpit Singh3d84add2023-10-10 19:08:29 +00001453TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1454 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001455 // initially disable tap-to-click
1456 mReader->getContext()->setPreventingTouchpadTaps(true);
1457
1458 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1459 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001460 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001461
1462 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001463 std::list<NotifyArgs> args =
1464 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001465 // We don't need to check args here, since it's covered by the Move test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001466
1467 // Future taps should be re-enabled
1468 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1469}
1470
Arpit Singh33a10a62023-10-12 13:06:54 +00001471TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1472 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1473 const nsecs_t gestureStartTime = 1000;
1474 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1475 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1476 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1477
1478 // Start a move gesture at gestureStartTime
1479 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1480 std::list<NotifyArgs> args =
1481 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001482 ASSERT_THAT(args,
1483 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001484 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1485 VariantWith<NotifyMotionArgs>(
1486 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001487
1488 // Key presses with IME connection should cancel ongoing move gesture
1489 nsecs_t currentTime = gestureStartTime + 100;
1490 mFakePolicy->setIsInputMethodConnectionActive(true);
1491 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1492 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1493 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001494 ASSERT_THAT(args,
1495 ElementsAre(VariantWith<NotifyMotionArgs>(
1496 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001497
1498 // any updates in existing move gesture should be ignored
1499 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1500 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1501 ASSERT_EQ(0u, args.size());
1502
1503 // New gesture should not be affected
1504 currentTime += 100;
1505 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1506 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001507 ASSERT_THAT(args,
1508 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001509 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1510 VariantWith<NotifyMotionArgs>(
1511 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001512}
1513
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001514// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1515// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001516class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1517protected:
1518 void SetUp() override {
1519 input_flags::enable_pointer_choreographer(true);
1520 GestureConverterTestBase::SetUp();
1521 }
1522};
1523
1524TEST_F(GestureConverterTestWithChoreographer, Move) {
1525 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1526 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1527 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1528
1529 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001530 std::list<NotifyArgs> args =
1531 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001532 ASSERT_THAT(args,
1533 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001534 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001535 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001536 VariantWith<NotifyMotionArgs>(
1537 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001538 WithRelativeMotion(-5, 10), WithButtonState(0),
1539 WithPressure(0.0f)))));
1540 ASSERT_THAT(args,
1541 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1542 WithToolType(ToolType::FINGER),
1543 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts379ea422023-12-21 15:31:47 +00001544
1545 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
1546 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1547 ASSERT_THAT(args,
1548 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001549 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1550 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1551 WithButtonState(0), WithPressure(0.0f),
1552 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001553}
1554
1555TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1556 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1557 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1558 converter.setOrientation(ui::ROTATION_90);
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(10, 5), 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)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001576}
1577
1578TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1579 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1580 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1581 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1582
1583 // Press left and right buttons at once
1584 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1585 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1586 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001587 std::list<NotifyArgs> args =
1588 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001589 ASSERT_THAT(args,
1590 ElementsAre(VariantWith<NotifyMotionArgs>(
1591 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1592 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +00001593 AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001594 VariantWith<NotifyMotionArgs>(
1595 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1596 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001597 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001598 VariantWith<NotifyMotionArgs>(
1599 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1600 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1601 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +00001602 AMOTION_EVENT_BUTTON_SECONDARY)))));
1603 ASSERT_THAT(args,
1604 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1605 WithToolType(ToolType::FINGER),
1606 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001607
1608 // Then release the left button
1609 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1610 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1611 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001612 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001613 ASSERT_THAT(args,
1614 ElementsAre(VariantWith<NotifyMotionArgs>(
1615 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1616 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1617 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1618 WithToolType(ToolType::FINGER),
1619 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001620
1621 // Finally release the right button
1622 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1623 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1624 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001625 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001626 ASSERT_THAT(args,
1627 ElementsAre(VariantWith<NotifyMotionArgs>(
1628 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001629 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001630 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001631 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +00001632 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001633 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
1634 ASSERT_THAT(args,
1635 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
1636 WithToolType(ToolType::FINGER),
1637 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001638}
1639
Harry Cutts379ea422023-12-21 15:31:47 +00001640TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) {
1641 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1642 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1643 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1644
1645 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1646 std::list<NotifyArgs> args =
1647 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1648
1649 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1650 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
1651 /*is_tap=*/false);
1652 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
1653 ASSERT_THAT(args.front(),
1654 VariantWith<NotifyMotionArgs>(
1655 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
1656 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1657 WithDisplayId(ADISPLAY_ID_DEFAULT))));
1658}
1659
Byoungho Jungee6268f2023-10-30 17:27:26 +09001660TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1661 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1662 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1663 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1664
1665 // Press the button
1666 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1667 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1668 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001669 std::list<NotifyArgs> args =
1670 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001671 ASSERT_THAT(args,
1672 ElementsAre(VariantWith<NotifyMotionArgs>(
1673 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00001674 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001675 VariantWith<NotifyMotionArgs>(
1676 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1677 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001678 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)))));
1679 ASSERT_THAT(args,
1680 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1681 WithToolType(ToolType::FINGER),
1682 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001683
1684 // Move
1685 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001686 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001687 ASSERT_THAT(args,
1688 ElementsAre(VariantWith<NotifyMotionArgs>(
1689 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1690 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1691 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1692 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001693
1694 // Release the button
1695 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1696 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1697 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001698 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001699 ASSERT_THAT(args,
1700 ElementsAre(VariantWith<NotifyMotionArgs>(
1701 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001702 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001703 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001704 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +00001705 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001706 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
1707 ASSERT_THAT(args,
1708 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
1709 WithToolType(ToolType::FINGER),
1710 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001711}
1712
1713TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1714 const nsecs_t downTime = 12345;
1715 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1716 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1717 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1718
1719 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001720 std::list<NotifyArgs> args =
1721 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001722 ASSERT_THAT(args,
1723 ElementsAre(VariantWith<NotifyMotionArgs>(
1724 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1725 WithCoords(0, 0),
1726 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001727 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001728 VariantWith<NotifyMotionArgs>(
1729 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1730 WithCoords(0, -10),
Harry Cuttsef95e712024-02-16 18:56:39 +00001731 WithGestureScrollDistance(0, 10, EPSILON)))));
1732 ASSERT_THAT(args,
1733 Each(VariantWith<NotifyMotionArgs>(
1734 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1735 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1736 WithToolType(ToolType::FINGER),
1737 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001738
1739 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001740 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001741 ASSERT_THAT(args,
1742 ElementsAre(VariantWith<NotifyMotionArgs>(
1743 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1744 WithGestureScrollDistance(0, 5, EPSILON),
1745 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1746 WithToolType(ToolType::FINGER),
1747 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1748 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001749
1750 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1751 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001752 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001753 ASSERT_THAT(args,
1754 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001755 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1756 WithCoords(0, -15),
1757 WithGestureScrollDistance(0, 0, EPSILON),
1758 WithMotionClassification(
1759 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001760 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001761 VariantWith<NotifyMotionArgs>(
1762 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1763 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001764 WithMotionClassification(MotionClassification::NONE)))));
1765 ASSERT_THAT(args,
1766 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1767 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001768}
1769
1770TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1771 const nsecs_t downTime = 12345;
1772 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1773 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1774 converter.setOrientation(ui::ROTATION_90);
1775 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1776
1777 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001778 std::list<NotifyArgs> args =
1779 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001780 ASSERT_THAT(args,
1781 ElementsAre(VariantWith<NotifyMotionArgs>(
1782 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1783 WithCoords(0, 0),
1784 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001785 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001786 VariantWith<NotifyMotionArgs>(
1787 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1788 WithCoords(-10, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001789 WithGestureScrollDistance(0, 10, EPSILON)))));
1790 ASSERT_THAT(args,
1791 Each(VariantWith<NotifyMotionArgs>(
1792 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1793 WithToolType(ToolType::FINGER),
1794 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001795
1796 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001797 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001798 ASSERT_THAT(args,
1799 ElementsAre(VariantWith<NotifyMotionArgs>(
1800 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1801 WithGestureScrollDistance(0, 5, EPSILON),
1802 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1803 WithToolType(ToolType::FINGER),
1804 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001805
1806 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1807 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001808 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001809 ASSERT_THAT(args,
1810 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001811 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1812 WithCoords(-15, 0),
1813 WithGestureScrollDistance(0, 0, EPSILON),
1814 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +00001815 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001816 VariantWith<NotifyMotionArgs>(
1817 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1818 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001819 WithMotionClassification(MotionClassification::NONE)))));
1820 ASSERT_THAT(args,
1821 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1822 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001823}
1824
1825TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1826 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1827 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1828 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1829
1830 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001831 std::list<NotifyArgs> args =
1832 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001833
1834 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001835 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001836
1837 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1838 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001839 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001840
1841 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001842 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001843 ASSERT_THAT(args,
1844 ElementsAre(VariantWith<NotifyMotionArgs>(
1845 AllOf(WithMotionClassification(MotionClassification::NONE),
1846 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001847}
1848
1849TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1850 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1851 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1852 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1853
1854 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001855 std::list<NotifyArgs> args =
1856 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001857
1858 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001859 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001860
1861 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1862 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001863 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001864
1865 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1866 // need to use another gesture type, like pinch.
1867 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1868 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001869 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001870 ASSERT_FALSE(args.empty());
1871 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1872}
1873
1874TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1875 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1876 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1877 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1878
1879 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1880 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001881 std::list<NotifyArgs> args =
1882 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001883
1884 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001885 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001886
1887 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1888 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001889 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001890 ASSERT_THAT(args,
1891 ElementsAre(VariantWith<NotifyMotionArgs>(
1892 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001893}
1894
1895TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1896 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1897 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1898 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1899
1900 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1901 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001902 std::list<NotifyArgs> args =
1903 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001904
1905 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001906 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001907
1908 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1909 // need to use another gesture type, like pinch.
1910 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1911 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001912 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001913 ASSERT_FALSE(args.empty());
1914 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1915 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1916}
1917
1918TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1919 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1920 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1921 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1922 // only checks movement in one dimension.
1923 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1924 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1925 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1926
1927 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1928 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001929 std::list<NotifyArgs> args =
1930 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001931 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00001932 ASSERT_THAT(args,
1933 Each(VariantWith<NotifyMotionArgs>(
1934 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1935 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
1936 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001937
1938 // Three fake fingers should be created. We don't actually care where they are, so long as they
1939 // move appropriately.
1940 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1941 ASSERT_THAT(arg,
1942 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001943 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001944 PointerCoords finger0Start = arg.pointerCoords[0];
1945 args.pop_front();
1946 arg = std::get<NotifyMotionArgs>(args.front());
1947 ASSERT_THAT(arg,
1948 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1949 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001950 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001951 PointerCoords finger1Start = arg.pointerCoords[1];
1952 args.pop_front();
1953 arg = std::get<NotifyMotionArgs>(args.front());
1954 ASSERT_THAT(arg,
1955 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1956 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001957 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001958 PointerCoords finger2Start = arg.pointerCoords[2];
1959 args.pop_front();
1960
1961 arg = std::get<NotifyMotionArgs>(args.front());
1962 ASSERT_THAT(arg,
1963 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001964 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001965 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1966 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1967 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1968 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
1969 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
1970 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
1971
1972 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1973 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001974 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001975 ASSERT_EQ(1u, args.size());
1976 arg = std::get<NotifyMotionArgs>(args.front());
1977 ASSERT_THAT(arg,
1978 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1979 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
1980 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1981 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1982 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1983 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1984 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1985 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1986 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
1987 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
1988 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
1989
1990 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001991 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001992 ASSERT_THAT(args,
1993 ElementsAre(VariantWith<NotifyMotionArgs>(
1994 AllOf(WithMotionAction(
1995 AMOTION_EVENT_ACTION_POINTER_UP |
1996 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1997 WithGestureOffset(0, 0, EPSILON),
1998 WithGestureSwipeFingerCount(3),
1999 WithMotionClassification(
2000 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002001 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002002 VariantWith<NotifyMotionArgs>(
2003 AllOf(WithMotionAction(
2004 AMOTION_EVENT_ACTION_POINTER_UP |
2005 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2006 WithGestureOffset(0, 0, EPSILON),
2007 WithGestureSwipeFingerCount(3),
2008 WithMotionClassification(
2009 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002010 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002011 VariantWith<NotifyMotionArgs>(
2012 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2013 WithGestureOffset(0, 0, EPSILON),
2014 WithGestureSwipeFingerCount(3),
2015 WithMotionClassification(
2016 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002017 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002018 VariantWith<NotifyMotionArgs>(
2019 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2020 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002021 WithMotionClassification(MotionClassification::NONE)))));
2022 ASSERT_THAT(args,
2023 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2024 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002025}
2026
2027TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
2028 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2029 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2030 converter.setOrientation(ui::ROTATION_90);
2031 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2032
2033 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2034 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002035 std::list<NotifyArgs> args =
2036 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002037 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00002038 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002039
2040 // Three fake fingers should be created. We don't actually care where they are, so long as they
2041 // move appropriately.
2042 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2043 ASSERT_THAT(arg,
2044 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002045 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002046 PointerCoords finger0Start = arg.pointerCoords[0];
2047 args.pop_front();
2048 arg = std::get<NotifyMotionArgs>(args.front());
2049 ASSERT_THAT(arg,
2050 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2051 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002052 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002053 PointerCoords finger1Start = arg.pointerCoords[1];
2054 args.pop_front();
2055 arg = std::get<NotifyMotionArgs>(args.front());
2056 ASSERT_THAT(arg,
2057 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2058 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002059 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002060 PointerCoords finger2Start = arg.pointerCoords[2];
2061 args.pop_front();
2062
2063 arg = std::get<NotifyMotionArgs>(args.front());
2064 ASSERT_THAT(arg,
2065 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002066 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002067 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
2068 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
2069 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
2070 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2071 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2072 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2073
2074 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2075 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002076 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002077 ASSERT_EQ(1u, args.size());
2078 arg = std::get<NotifyMotionArgs>(args.front());
2079 ASSERT_THAT(arg,
2080 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2081 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
2082 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2083 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
2084 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
2085 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
2086 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2087 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2088 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2089
2090 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002091 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002092 ASSERT_THAT(args,
2093 ElementsAre(VariantWith<NotifyMotionArgs>(
2094 AllOf(WithMotionAction(
2095 AMOTION_EVENT_ACTION_POINTER_UP |
2096 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002097 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002098 VariantWith<NotifyMotionArgs>(
2099 AllOf(WithMotionAction(
2100 AMOTION_EVENT_ACTION_POINTER_UP |
2101 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002102 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002103 VariantWith<NotifyMotionArgs>(
2104 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002105 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002106 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00002107 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
2108 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002109}
2110
2111TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2112 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2113 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2114 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2115
2116 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2117 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002118 std::list<NotifyArgs> args =
2119 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002120 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00002121 ASSERT_THAT(args,
2122 Each(VariantWith<NotifyMotionArgs>(
2123 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2124 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
2125 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002126
2127 // Four fake fingers should be created. We don't actually care where they are, so long as they
2128 // move appropriately.
2129 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2130 ASSERT_THAT(arg,
2131 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002132 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002133 PointerCoords finger0Start = arg.pointerCoords[0];
2134 args.pop_front();
2135 arg = std::get<NotifyMotionArgs>(args.front());
2136 ASSERT_THAT(arg,
2137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2138 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002139 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002140 PointerCoords finger1Start = arg.pointerCoords[1];
2141 args.pop_front();
2142 arg = std::get<NotifyMotionArgs>(args.front());
2143 ASSERT_THAT(arg,
2144 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2145 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002146 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002147 PointerCoords finger2Start = arg.pointerCoords[2];
2148 args.pop_front();
2149 arg = std::get<NotifyMotionArgs>(args.front());
2150 ASSERT_THAT(arg,
2151 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2152 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002153 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002154 PointerCoords finger3Start = arg.pointerCoords[3];
2155 args.pop_front();
2156
2157 arg = std::get<NotifyMotionArgs>(args.front());
2158 ASSERT_THAT(arg,
2159 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002160 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002161 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2162 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2163 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2164 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2165 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2166 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2167 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2168 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2169
2170 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2171 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002172 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002173 ASSERT_EQ(1u, args.size());
2174 arg = std::get<NotifyMotionArgs>(args.front());
2175 ASSERT_THAT(arg,
2176 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2177 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2178 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2179 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2180 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2181 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2182 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2183 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2184 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2185 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2186 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2187 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2188 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2189
2190 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002191 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002192 ASSERT_THAT(args,
2193 ElementsAre(VariantWith<NotifyMotionArgs>(
2194 AllOf(WithMotionAction(
2195 AMOTION_EVENT_ACTION_POINTER_UP |
2196 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2197 WithGestureOffset(0, 0, EPSILON),
2198 WithGestureSwipeFingerCount(4),
2199 WithMotionClassification(
2200 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002201 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002202 VariantWith<NotifyMotionArgs>(
2203 AllOf(WithMotionAction(
2204 AMOTION_EVENT_ACTION_POINTER_UP |
2205 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2206 WithGestureOffset(0, 0, EPSILON),
2207 WithGestureSwipeFingerCount(4),
2208 WithMotionClassification(
2209 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002210 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002211 VariantWith<NotifyMotionArgs>(
2212 AllOf(WithMotionAction(
2213 AMOTION_EVENT_ACTION_POINTER_UP |
2214 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2215 WithGestureOffset(0, 0, EPSILON),
2216 WithGestureSwipeFingerCount(4),
2217 WithMotionClassification(
2218 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002219 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002220 VariantWith<NotifyMotionArgs>(
2221 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2222 WithGestureOffset(0, 0, EPSILON),
2223 WithGestureSwipeFingerCount(4),
2224 WithMotionClassification(
2225 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002226 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002227 VariantWith<NotifyMotionArgs>(
2228 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2229 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002230 WithMotionClassification(MotionClassification::NONE)))));
2231 ASSERT_THAT(args,
2232 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2233 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002234}
2235
2236TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2237 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2238 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2239 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2240
2241 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2242 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002243 std::list<NotifyArgs> args =
2244 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002245 ASSERT_THAT(args,
2246 ElementsAre(VariantWith<NotifyMotionArgs>(
2247 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00002248 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002249 VariantWith<NotifyMotionArgs>(
2250 AllOf(WithMotionAction(
2251 AMOTION_EVENT_ACTION_POINTER_DOWN |
2252 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002253 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
2254 ASSERT_THAT(args,
2255 Each(VariantWith<NotifyMotionArgs>(
2256 AllOf(WithMotionClassification(MotionClassification::PINCH),
2257 WithGesturePinchScaleFactor(1.0f, EPSILON),
2258 WithToolType(ToolType::FINGER),
2259 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002260
2261 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2262 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002263 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002264 ASSERT_THAT(args,
2265 ElementsAre(VariantWith<NotifyMotionArgs>(
2266 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2267 WithMotionClassification(MotionClassification::PINCH),
2268 WithGesturePinchScaleFactor(0.8f, EPSILON),
2269 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
2270 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2271 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002272
2273 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2274 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002275 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002276 ASSERT_THAT(args,
2277 ElementsAre(VariantWith<NotifyMotionArgs>(
2278 AllOf(WithMotionAction(
2279 AMOTION_EVENT_ACTION_POINTER_UP |
2280 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2281 WithMotionClassification(MotionClassification::PINCH),
2282 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002283 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002284 VariantWith<NotifyMotionArgs>(
2285 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2286 WithMotionClassification(MotionClassification::PINCH),
2287 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002288 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002289 VariantWith<NotifyMotionArgs>(
2290 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2291 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002292 WithMotionClassification(MotionClassification::NONE)))));
2293 ASSERT_THAT(args,
2294 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2295 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002296}
2297
2298TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2299 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2300 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2301 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2302
2303 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2304 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002305 std::list<NotifyArgs> args =
2306 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002307 ASSERT_THAT(args,
2308 ElementsAre(VariantWith<NotifyMotionArgs>(
2309 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00002310 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002311 VariantWith<NotifyMotionArgs>(
2312 AllOf(WithMotionAction(
2313 AMOTION_EVENT_ACTION_POINTER_DOWN |
2314 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002315 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
2316 ASSERT_THAT(args,
2317 Each(VariantWith<NotifyMotionArgs>(
2318 AllOf(WithMotionClassification(MotionClassification::PINCH),
2319 WithGesturePinchScaleFactor(1.0f, EPSILON),
2320 WithToolType(ToolType::FINGER),
2321 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002322
2323 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2324 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002325 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002326 ASSERT_THAT(args,
2327 ElementsAre(VariantWith<NotifyMotionArgs>(
2328 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2329 WithMotionClassification(MotionClassification::PINCH),
2330 WithGesturePinchScaleFactor(1.1f, EPSILON),
2331 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
2332 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2333 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002334
2335 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2336 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002337 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002338 ASSERT_THAT(args,
2339 ElementsAre(VariantWith<NotifyMotionArgs>(
2340 AllOf(WithMotionAction(
2341 AMOTION_EVENT_ACTION_POINTER_UP |
2342 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2343 WithMotionClassification(MotionClassification::PINCH),
2344 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002345 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002346 VariantWith<NotifyMotionArgs>(
2347 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2348 WithMotionClassification(MotionClassification::PINCH),
2349 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002350 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002351 VariantWith<NotifyMotionArgs>(
2352 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2353 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002354 WithMotionClassification(MotionClassification::NONE)))));
2355 ASSERT_THAT(args,
2356 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2357 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002358}
2359
2360TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2361 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2362 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2363 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2364
2365 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2366 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002367 std::list<NotifyArgs> args =
2368 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002369
2370 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2371 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002372 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002373
2374 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2375 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002376 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002377
2378 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002379 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002380 ASSERT_THAT(args,
2381 ElementsAre(VariantWith<NotifyMotionArgs>(
2382 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002383}
2384
2385TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2386 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2387 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2388 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2389
2390 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2391 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002392 std::list<NotifyArgs> args =
2393 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002394
2395 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2396 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002397 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002398
2399 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2400 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002401 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002402
2403 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2404 // need to use another gesture type, like scroll.
2405 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2406 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002407 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002408 ASSERT_FALSE(args.empty());
2409 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2410}
2411
2412TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2413 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2414 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2415 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2416
2417 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2418 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2419 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002420 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002421
2422 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002423 ASSERT_THAT(args,
2424 ElementsAre(VariantWith<NotifyMotionArgs>(
2425 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2426 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002427 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002428 VariantWith<NotifyMotionArgs>(
2429 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2430 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002431 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002432 VariantWith<NotifyMotionArgs>(
2433 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002434 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00002435 VariantWith<NotifyMotionArgs>(
2436 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002437 WithButtonState(0)))));
2438 ASSERT_THAT(args,
2439 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2440 WithToolType(ToolType::FINGER),
2441 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002442}
2443
2444TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2445 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2446 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2447 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2448
2449 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002450 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002451
2452 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002453 ASSERT_THAT(args,
2454 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002455 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2456 WithCoords(0, -10),
2457 WithGestureScrollDistance(0, 0, EPSILON),
2458 WithMotionClassification(
2459 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002460 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00002461 VariantWith<NotifyMotionArgs>(
2462 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2463 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002464 WithMotionClassification(MotionClassification::NONE)))));
2465 ASSERT_THAT(args,
2466 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2467 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002468}
2469
2470TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2471 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2472 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2473 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2474
2475 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2476 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002477 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002478
2479 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002480 ASSERT_THAT(args,
2481 ElementsAre(VariantWith<NotifyMotionArgs>(
2482 AllOf(WithMotionAction(
2483 AMOTION_EVENT_ACTION_POINTER_UP |
2484 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2485 WithGestureOffset(0, 0, EPSILON),
2486 WithMotionClassification(
2487 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002488 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002489 VariantWith<NotifyMotionArgs>(
2490 AllOf(WithMotionAction(
2491 AMOTION_EVENT_ACTION_POINTER_UP |
2492 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2493 WithGestureOffset(0, 0, EPSILON),
2494 WithMotionClassification(
2495 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002496 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002497 VariantWith<NotifyMotionArgs>(
2498 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2499 WithGestureOffset(0, 0, EPSILON),
2500 WithMotionClassification(
2501 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002502 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002503 VariantWith<NotifyMotionArgs>(
2504 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002505 WithMotionClassification(MotionClassification::NONE)))));
2506 ASSERT_THAT(args,
2507 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2508 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002509}
2510
2511TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2512 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2513 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2514 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2515
2516 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2517 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002518 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002519
2520 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002521 ASSERT_THAT(args,
2522 ElementsAre(VariantWith<NotifyMotionArgs>(
2523 AllOf(WithMotionAction(
2524 AMOTION_EVENT_ACTION_POINTER_UP |
2525 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2526 WithMotionClassification(MotionClassification::PINCH),
2527 WithGesturePinchScaleFactor(1.0f, EPSILON),
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 WithMotionClassification(MotionClassification::PINCH),
2532 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002533 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002534 VariantWith<NotifyMotionArgs>(
2535 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2536 WithCoords(0, 0),
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, FlingTapDown) {
2544 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2545 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2546 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2547
2548 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2549 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002550 std::list<NotifyArgs> args =
2551 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002552
2553 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00002554 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
Byoungho Jungee6268f2023-10-30 17:27:26 +09002555 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2556 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2557}
2558
2559TEST_F(GestureConverterTestWithChoreographer, Tap) {
2560 // Tap should produce button press/release events
2561 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2562 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2563 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2564
2565 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2566 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002567 std::list<NotifyArgs> args =
2568 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002569 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002570
2571 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2572 /* down= */ GESTURES_BUTTON_LEFT,
2573 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002574 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002575
Harry Cutts5f26e952023-11-30 18:20:27 +00002576 ASSERT_THAT(args,
2577 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002578 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002579 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002580 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002581 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002582 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002583 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002584 VariantWith<NotifyMotionArgs>(
2585 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2586 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2587 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002588 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002589 VariantWith<NotifyMotionArgs>(
2590 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2591 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002592 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002593 VariantWith<NotifyMotionArgs>(
2594 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002595 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002596 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002597 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002598 WithButtonState(0), WithPressure(0.0f)))));
2599 ASSERT_THAT(args,
2600 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2601 WithRelativeMotion(0.f, 0.f),
2602 WithToolType(ToolType::FINGER),
2603 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002604}
2605
2606TEST_F(GestureConverterTestWithChoreographer, Click) {
2607 // Click should produce button press/release events
2608 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2609 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2610 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2611
2612 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2613 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002614 std::list<NotifyArgs> args =
2615 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002616 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002617
2618 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2619 /* down= */ GESTURES_BUTTON_LEFT,
2620 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002621 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002622
Harry Cutts5f26e952023-11-30 18:20:27 +00002623 ASSERT_THAT(args,
2624 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002625 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002626 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002627 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002628 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002629 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002630 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002631 VariantWith<NotifyMotionArgs>(
2632 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2633 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2634 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002635 WithPressure(1.0f)))));
2636 ASSERT_THAT(args,
2637 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2638 WithRelativeMotion(0.f, 0.f),
2639 WithToolType(ToolType::FINGER),
2640 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002641
2642 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2643 /* down= */ GESTURES_BUTTON_NONE,
2644 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002645 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002646
Harry Cutts5f26e952023-11-30 18:20:27 +00002647 ASSERT_THAT(args,
2648 ElementsAre(VariantWith<NotifyMotionArgs>(
2649 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2650 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002651 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002652 VariantWith<NotifyMotionArgs>(
2653 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002654 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002655 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002656 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002657 WithPressure(0.0f)))));
2658 ASSERT_THAT(args,
2659 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
2660 WithRelativeMotion(0.f, 0.f),
2661 WithToolType(ToolType::FINGER),
2662 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002663}
2664
2665TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002666 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2667 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2668 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2669
Byoungho Jungee6268f2023-10-30 17:27:26 +09002670 // Tap should be ignored when disabled
2671 mReader->getContext()->setPreventingTouchpadTaps(true);
2672
2673 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2674 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2675 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2676
Arpit Singh82b27a02023-10-16 11:02:19 +00002677 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002678 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002679 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002680 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002681 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002682
Arpit Singh82b27a02023-10-16 11:02:19 +00002683 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002684 /* down= */ GESTURES_BUTTON_LEFT,
2685 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002686 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002687
2688 // no events should be generated
2689 ASSERT_EQ(0u, args.size());
2690
2691 // Future taps should be re-enabled
2692 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2693}
2694
Arpit Singh82b27a02023-10-16 11:02:19 +00002695TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2696 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2697 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2698
2699 // Tap should be ignored when disabled
2700 mReader->getContext()->setPreventingTouchpadTaps(true);
2701
2702 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2703 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2704 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2705
2706 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2707 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2708 std::list<NotifyArgs> args =
2709 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002710 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00002711
2712 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2713 /* down= */ GESTURES_BUTTON_LEFT,
2714 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2715 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2716
2717 // no events should be generated
2718 ASSERT_EQ(0u, args.size());
2719
2720 // Future taps should be re-enabled
2721 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2722
2723 // taps before the threshold should still be ignored
2724 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2725 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2726 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2727 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2728
2729 ASSERT_EQ(1u, args.size());
2730 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2731 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2732
2733 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2734 /* down= */ GESTURES_BUTTON_LEFT,
2735 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2736 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2737
2738 // no events should be generated
2739 ASSERT_EQ(0u, args.size());
2740
2741 // taps after the threshold should be recognised
2742 currentTime += 1;
2743 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2744 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2745 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2746
2747 ASSERT_EQ(1u, args.size());
2748 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2749 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2750
2751 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2752 /* down= */ GESTURES_BUTTON_LEFT,
2753 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2754 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00002755 ASSERT_THAT(args,
2756 ElementsAre(VariantWith<NotifyMotionArgs>(
2757 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2758 WithButtonState(0))),
2759 VariantWith<NotifyMotionArgs>(
2760 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2761 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
2762 VariantWith<NotifyMotionArgs>(
2763 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2764 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2765 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
2766 VariantWith<NotifyMotionArgs>(
2767 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2768 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2769 WithButtonState(0))),
2770 VariantWith<NotifyMotionArgs>(
2771 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2772 WithButtonState(0))),
2773 VariantWith<NotifyMotionArgs>(
2774 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2775 WithButtonState(0)))));
2776 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00002777}
2778
Byoungho Jungee6268f2023-10-30 17:27:26 +09002779TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2780 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2781 // Click should still produce button press/release events
2782 mReader->getContext()->setPreventingTouchpadTaps(true);
2783
2784 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2785 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2786 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2787
2788 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2789 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002790 std::list<NotifyArgs> args =
2791 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002792 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002793
2794 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2795 /* down= */ GESTURES_BUTTON_LEFT,
2796 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002797 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002798
Harry Cutts5f26e952023-11-30 18:20:27 +00002799 ASSERT_THAT(args,
2800 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002801 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002802 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002803 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002804 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002805 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002806 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002807 VariantWith<NotifyMotionArgs>(
2808 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2809 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2810 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002811 WithPressure(1.0f)))));
2812 ASSERT_THAT(args,
2813 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2814 WithRelativeMotion(0.f, 0.f),
2815 WithToolType(ToolType::FINGER),
2816 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002817
2818 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2819 /* down= */ GESTURES_BUTTON_NONE,
2820 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002821 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002822
Harry Cutts5f26e952023-11-30 18:20:27 +00002823 ASSERT_THAT(args,
2824 ElementsAre(VariantWith<NotifyMotionArgs>(
2825 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2826 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2827 WithButtonState(0), WithCoords(0, 0),
2828 WithRelativeMotion(0.f, 0.f),
2829 WithToolType(ToolType::FINGER), WithButtonState(0),
2830 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2831 VariantWith<NotifyMotionArgs>(
2832 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2833 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2834 WithToolType(ToolType::FINGER), WithButtonState(0),
2835 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2836 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002837 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002838 WithCoords(0, 0), WithRelativeMotion(0, 0),
2839 WithToolType(ToolType::FINGER), WithButtonState(0),
2840 WithPressure(0.0f),
2841 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002842
2843 // Future taps should be re-enabled
2844 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2845}
2846
2847TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2848 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2849 // initially disable tap-to-click
2850 mReader->getContext()->setPreventingTouchpadTaps(true);
2851
2852 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2853 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2854 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2855
2856 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002857 std::list<NotifyArgs> args =
2858 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002859 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002860
2861 // Future taps should be re-enabled
2862 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2863}
2864
Arpit Singh33a10a62023-10-12 13:06:54 +00002865TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
2866 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2867 const nsecs_t gestureStartTime = 1000;
2868 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2869 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2870 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2871
2872 // Start a move gesture at gestureStartTime
2873 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
2874 std::list<NotifyArgs> args =
2875 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002876 ASSERT_THAT(args,
2877 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002878 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
2879 VariantWith<NotifyMotionArgs>(
2880 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002881
2882 // Key presses with IME connection should cancel ongoing move gesture
2883 nsecs_t currentTime = gestureStartTime + 100;
2884 mFakePolicy->setIsInputMethodConnectionActive(true);
2885 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
2886 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2887 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002888 ASSERT_THAT(args,
2889 ElementsAre(VariantWith<NotifyMotionArgs>(
2890 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002891
2892 // any updates in existing move gesture should be ignored
2893 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2894 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2895 ASSERT_EQ(0u, args.size());
2896
2897 // New gesture should not be affected
2898 currentTime += 100;
2899 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2900 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002901 ASSERT_THAT(args,
2902 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002903 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
2904 VariantWith<NotifyMotionArgs>(
2905 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002906}
2907
Harry Cutts4fb941a2022-12-14 19:14:04 +00002908} // namespace android