blob: 6a009b291853c74b3a817f8fb1113e73325e0730 [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
Harry Cutts3beea7d2024-02-21 15:52:35 +000072 mFakePointerController = std::make_shared<FakePointerController>(
73 /*enabled=*/!input_flags::enable_pointer_choreographer());
Harry Cutts4fb941a2022-12-14 19:14:04 +000074 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
75 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
76 mFakePolicy->setPointerController(mFakePointerController);
77 }
78
Harry Cuttsc5748d12022-12-02 17:30:18 +000079 std::shared_ptr<InputDevice> newDevice() {
80 InputDeviceIdentifier identifier;
81 identifier.name = "device";
82 identifier.location = "USB1";
83 identifier.bus = 0;
84 std::shared_ptr<InputDevice> device =
85 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
86 identifier);
87 mReader->pushNextDevice(device);
88 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
89 identifier.bus);
90 mReader->loopOnce();
91 return device;
92 }
93
Harry Cutts4fb941a2022-12-14 19:14:04 +000094 std::shared_ptr<FakeEventHub> mFakeEventHub;
95 sp<FakeInputReaderPolicy> mFakePolicy;
96 std::unique_ptr<TestInputListener> mFakeListener;
97 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000098 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000099 std::shared_ptr<FakePointerController> mFakePointerController;
100};
101
Byoungho Jungee6268f2023-10-30 17:27:26 +0900102class GestureConverterTest : public GestureConverterTestBase {
103protected:
104 void SetUp() override {
105 input_flags::enable_pointer_choreographer(false);
106 GestureConverterTestBase::SetUp();
107 }
108};
109
Harry Cutts4fb941a2022-12-14 19:14:04 +0000110TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000111 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
112 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000113 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000114
115 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000116 std::list<NotifyArgs> args =
117 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000118 ASSERT_THAT(args,
119 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000120 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
121 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000122 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000123 VariantWith<NotifyMotionArgs>(
124 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
125 WithCoords(POINTER_X - 5, POINTER_Y + 10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000126 WithRelativeMotion(-5, 10), WithButtonState(0),
127 WithPressure(0.0f)))));
128 ASSERT_THAT(args,
129 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
130 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000131
Harry Cuttsb1e83552022-12-20 11:02:26 +0000132 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts379ea422023-12-21 15:31:47 +0000133
134 // The same gesture again should only repeat the HOVER_MOVE and cursor position change, not the
135 // HOVER_ENTER.
136 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
137 ASSERT_THAT(args,
138 ElementsAre(VariantWith<NotifyMotionArgs>(
139 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
140 WithCoords(POINTER_X - 10, POINTER_Y + 20),
141 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
142 WithButtonState(0), WithPressure(0.0f),
143 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
144
145 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 10, POINTER_Y + 20));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000146}
147
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000148TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000149 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
150 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000151 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000152 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000153
154 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000155 std::list<NotifyArgs> args =
156 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000157 ASSERT_THAT(args,
158 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000159 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
160 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000161 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000162 VariantWith<NotifyMotionArgs>(
163 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
164 WithCoords(POINTER_X + 10, POINTER_Y + 5),
Harry Cuttsef95e712024-02-16 18:56:39 +0000165 WithRelativeMotion(10, 5), WithButtonState(0),
166 WithPressure(0.0f)))));
167 ASSERT_THAT(args,
168 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
169 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000170
Harry Cuttsb1e83552022-12-20 11:02:26 +0000171 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000172}
173
Harry Cutts4fb941a2022-12-14 19:14:04 +0000174TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000175 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
176 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000177 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000178
179 // Press left and right buttons at once
180 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
181 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
182 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000183 std::list<NotifyArgs> args =
184 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000185 ASSERT_THAT(args,
186 ElementsAre(VariantWith<NotifyMotionArgs>(
187 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
188 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000189 AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000190 VariantWith<NotifyMotionArgs>(
191 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
192 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000193 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000194 VariantWith<NotifyMotionArgs>(
195 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
196 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
197 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000198 AMOTION_EVENT_BUTTON_SECONDARY)))));
199 ASSERT_THAT(args,
200 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
201 WithToolType(ToolType::FINGER),
202 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000203
204 // Then release the left button
205 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
206 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
207 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000208 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000209 ASSERT_THAT(args,
210 ElementsAre(VariantWith<NotifyMotionArgs>(
211 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
212 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
213 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
214 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
215 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000216
217 // Finally release the right button
218 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
219 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
220 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000221 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000222 ASSERT_THAT(args,
223 ElementsAre(VariantWith<NotifyMotionArgs>(
224 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000225 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000226 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000227 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000228 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000229 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
230 ASSERT_THAT(args,
231 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0),
232 WithCoords(POINTER_X, POINTER_Y),
233 WithToolType(ToolType::FINGER),
234 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000235}
236
Harry Cutts379ea422023-12-21 15:31:47 +0000237TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) {
238 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
239 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
240 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
241
242 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
243 std::list<NotifyArgs> args =
244 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
245
246 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
247 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
248 /*is_tap=*/false);
249 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
250 ASSERT_THAT(args.front(),
251 VariantWith<NotifyMotionArgs>(
252 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
253 WithCoords(POINTER_X - 5, POINTER_Y + 10),
254 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT))));
255}
256
Harry Cutts4fb941a2022-12-14 19:14:04 +0000257TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000258 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
259 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000260 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000261
262 // Press the button
263 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
264 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
265 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000266 std::list<NotifyArgs> args =
267 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000268 ASSERT_THAT(args,
269 ElementsAre(VariantWith<NotifyMotionArgs>(
270 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +0000271 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000272 VariantWith<NotifyMotionArgs>(
273 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
274 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000275 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)))));
276 ASSERT_THAT(args,
277 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
278 WithToolType(ToolType::FINGER),
279 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000280
281 // Move
282 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000283 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000284 ASSERT_THAT(args,
285 ElementsAre(VariantWith<NotifyMotionArgs>(
286 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
287 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
288 WithToolType(ToolType::FINGER),
289 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
290 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000291
Harry Cuttsb1e83552022-12-20 11:02:26 +0000292 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000293
294 // Release the button
295 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
296 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
297 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000298 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000299 ASSERT_THAT(args,
300 ElementsAre(VariantWith<NotifyMotionArgs>(
301 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000302 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000303 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000304 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000305 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000306 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
307 ASSERT_THAT(args,
308 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0),
309 WithCoords(POINTER_X - 5, POINTER_Y + 10),
310 WithToolType(ToolType::FINGER),
311 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000312}
313
Harry Cuttsef400b22022-12-16 21:26:24 +0000314TEST_F(GestureConverterTest, Scroll) {
315 const nsecs_t downTime = 12345;
316 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
317 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000318 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000319
Harry Cuttsa546ba82023-01-13 17:21:00 +0000320 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000321 std::list<NotifyArgs> args =
322 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000323 ASSERT_THAT(args,
324 ElementsAre(VariantWith<NotifyMotionArgs>(
325 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
326 WithCoords(POINTER_X, POINTER_Y),
327 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000328 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000329 VariantWith<NotifyMotionArgs>(
330 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
331 WithCoords(POINTER_X, POINTER_Y - 10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000332 WithGestureScrollDistance(0, 10, EPSILON)))));
333 ASSERT_THAT(args,
334 Each(VariantWith<NotifyMotionArgs>(
335 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
336 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
337 WithToolType(ToolType::FINGER),
338 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000339
Harry Cuttsa546ba82023-01-13 17:21:00 +0000340 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000341 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000342 ASSERT_THAT(args,
343 ElementsAre(VariantWith<NotifyMotionArgs>(
344 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
345 WithCoords(POINTER_X, POINTER_Y - 15),
346 WithGestureScrollDistance(0, 5, EPSILON),
347 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
348 WithToolType(ToolType::FINGER),
349 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
350 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000351
352 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
353 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000354 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000355 ASSERT_THAT(args,
356 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000357 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
358 WithCoords(POINTER_X, POINTER_Y - 15),
359 WithGestureScrollDistance(0, 0, EPSILON),
360 WithMotionClassification(
361 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000362 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000363 VariantWith<NotifyMotionArgs>(
364 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
365 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000366 WithMotionClassification(MotionClassification::NONE)))));
367 ASSERT_THAT(args,
368 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
369 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000370}
371
372TEST_F(GestureConverterTest, Scroll_Rotated) {
373 const nsecs_t downTime = 12345;
374 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
375 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
376 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000377 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000378
Harry Cuttsa546ba82023-01-13 17:21:00 +0000379 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000380 std::list<NotifyArgs> args =
381 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000382 ASSERT_THAT(args,
383 ElementsAre(VariantWith<NotifyMotionArgs>(
384 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
385 WithCoords(POINTER_X, POINTER_Y),
386 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000387 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000388 VariantWith<NotifyMotionArgs>(
389 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
390 WithCoords(POINTER_X - 10, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000391 WithGestureScrollDistance(0, 10, EPSILON)))));
392 ASSERT_THAT(args,
393 Each(VariantWith<NotifyMotionArgs>(
394 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
395 WithToolType(ToolType::FINGER),
396 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000397
Harry Cuttsa546ba82023-01-13 17:21:00 +0000398 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000399 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000400 ASSERT_THAT(args,
401 ElementsAre(VariantWith<NotifyMotionArgs>(
402 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
403 WithCoords(POINTER_X - 15, POINTER_Y),
404 WithGestureScrollDistance(0, 5, EPSILON),
405 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
406 WithToolType(ToolType::FINGER),
407 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000408 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
409 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000410 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000411 ASSERT_THAT(args,
412 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000413 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
414 WithCoords(POINTER_X - 15, POINTER_Y),
415 WithGestureScrollDistance(0, 0, EPSILON),
416 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +0000417 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000418 VariantWith<NotifyMotionArgs>(
419 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
420 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000421 WithMotionClassification(MotionClassification::NONE)))));
422 ASSERT_THAT(args,
423 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
424 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000425}
426
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000427TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000428 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
429 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000430 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000431
Harry Cuttsa546ba82023-01-13 17:21:00 +0000432 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000433 std::list<NotifyArgs> args =
434 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000435
Harry Cuttsa546ba82023-01-13 17:21:00 +0000436 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000437 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000438
439 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
440 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000441 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000442
443 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000444 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000445 ASSERT_THAT(args,
446 ElementsAre(VariantWith<NotifyMotionArgs>(
447 AllOf(WithMotionClassification(MotionClassification::NONE),
448 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000449}
450
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000451TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000452 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
453 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000454 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000455
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000456 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000457 std::list<NotifyArgs> args =
458 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000459
460 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000461 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000462
463 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
464 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000465 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000466
467 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
468 // need to use another gesture type, like pinch.
469 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
470 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000471 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000472 ASSERT_FALSE(args.empty());
473 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
474}
475
476TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
477 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
478 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000479 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000480
481 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
482 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000483 std::list<NotifyArgs> args =
484 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000485
486 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000487 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000488
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000489 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
490 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000491 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000492 ASSERT_THAT(args,
493 ElementsAre(VariantWith<NotifyMotionArgs>(
494 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000495}
496
Harry Cutts8743f182023-05-17 12:03:49 +0000497TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000498 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
499 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000500 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000501
502 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
503 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000504 std::list<NotifyArgs> args =
505 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000506
507 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000508 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000509
510 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
511 // need to use another gesture type, like pinch.
512 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
513 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000514 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000515 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000516 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
517 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000518}
519
520TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
521 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
522 // start swiping up and then start moving left or right, it'll return gesture events with only Y
523 // deltas until you lift your fingers and start swiping again. That's why each of these tests
524 // only checks movement in one dimension.
525 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
526 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000527 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000528
529 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
530 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000531 std::list<NotifyArgs> args =
532 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000533 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000534 ASSERT_THAT(args,
535 Each(VariantWith<NotifyMotionArgs>(
536 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
537 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
538 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000539
540 // Three fake fingers should be created. We don't actually care where they are, so long as they
541 // move appropriately.
542 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
543 ASSERT_THAT(arg,
544 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000545 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000546 PointerCoords finger0Start = arg.pointerCoords[0];
547 args.pop_front();
548 arg = std::get<NotifyMotionArgs>(args.front());
549 ASSERT_THAT(arg,
550 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
551 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000552 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000553 PointerCoords finger1Start = arg.pointerCoords[1];
554 args.pop_front();
555 arg = std::get<NotifyMotionArgs>(args.front());
556 ASSERT_THAT(arg,
557 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
558 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000559 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000560 PointerCoords finger2Start = arg.pointerCoords[2];
561 args.pop_front();
562
563 arg = std::get<NotifyMotionArgs>(args.front());
564 ASSERT_THAT(arg,
565 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000566 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000567 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
568 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
569 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
570 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
571 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
572 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
573
574 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
575 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000576 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000577 ASSERT_EQ(1u, args.size());
578 arg = std::get<NotifyMotionArgs>(args.front());
579 ASSERT_THAT(arg,
580 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000581 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000582 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000583 WithPointerCount(3u), WithToolType(ToolType::FINGER),
584 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000585 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
586 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
587 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
588 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
589 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
590 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
591
592 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000593 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000594 ASSERT_THAT(args,
595 ElementsAre(VariantWith<NotifyMotionArgs>(
596 AllOf(WithMotionAction(
597 AMOTION_EVENT_ACTION_POINTER_UP |
598 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
599 WithGestureOffset(0, 0, EPSILON),
600 WithGestureSwipeFingerCount(3),
601 WithMotionClassification(
602 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000603 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000604 VariantWith<NotifyMotionArgs>(
605 AllOf(WithMotionAction(
606 AMOTION_EVENT_ACTION_POINTER_UP |
607 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
608 WithGestureOffset(0, 0, EPSILON),
609 WithGestureSwipeFingerCount(3),
610 WithMotionClassification(
611 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000612 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000613 VariantWith<NotifyMotionArgs>(
614 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
615 WithGestureOffset(0, 0, EPSILON),
616 WithGestureSwipeFingerCount(3),
617 WithMotionClassification(
618 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000619 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000620 VariantWith<NotifyMotionArgs>(
621 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
622 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000623 WithMotionClassification(MotionClassification::NONE)))));
624 ASSERT_THAT(args,
625 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
626 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000627}
628
Harry Cutts94f5bd52023-01-06 18:02:18 +0000629TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
630 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
631 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
632 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000633 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000634
635 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
636 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000637 std::list<NotifyArgs> args =
638 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000639 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000640 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000641
642 // Three fake fingers should be created. We don't actually care where they are, so long as they
643 // move appropriately.
644 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
645 ASSERT_THAT(arg,
646 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000647 WithPointerCount(1u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000648 PointerCoords finger0Start = arg.pointerCoords[0];
649 args.pop_front();
650 arg = std::get<NotifyMotionArgs>(args.front());
651 ASSERT_THAT(arg,
652 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
653 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000654 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000655 PointerCoords finger1Start = arg.pointerCoords[1];
656 args.pop_front();
657 arg = std::get<NotifyMotionArgs>(args.front());
658 ASSERT_THAT(arg,
659 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
660 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000661 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000662 PointerCoords finger2Start = arg.pointerCoords[2];
663 args.pop_front();
664
665 arg = std::get<NotifyMotionArgs>(args.front());
666 ASSERT_THAT(arg,
667 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000668 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000669 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
670 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
671 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
672 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
673 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
674 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
675
676 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
677 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000678 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000679 ASSERT_EQ(1u, args.size());
680 arg = std::get<NotifyMotionArgs>(args.front());
681 ASSERT_THAT(arg,
682 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000683 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
684 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000685 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
686 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
687 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
688 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
689 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
690 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
691
692 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000693 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000694 ASSERT_THAT(args,
695 ElementsAre(VariantWith<NotifyMotionArgs>(
696 AllOf(WithMotionAction(
697 AMOTION_EVENT_ACTION_POINTER_UP |
698 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000699 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000700 VariantWith<NotifyMotionArgs>(
701 AllOf(WithMotionAction(
702 AMOTION_EVENT_ACTION_POINTER_UP |
703 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000704 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000705 VariantWith<NotifyMotionArgs>(
706 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +0000707 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000708 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000709 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
710 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000711}
712
Harry Cuttsc5748d12022-12-02 17:30:18 +0000713TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
714 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
715 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000716 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000717
718 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
719 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000720 std::list<NotifyArgs> args =
721 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000722 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000723 ASSERT_THAT(args,
724 Each(VariantWith<NotifyMotionArgs>(
725 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
726 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
727 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000728
729 // Four fake fingers should be created. We don't actually care where they are, so long as they
730 // move appropriately.
731 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
732 ASSERT_THAT(arg,
733 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000734 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000735 PointerCoords finger0Start = arg.pointerCoords[0];
736 args.pop_front();
737 arg = std::get<NotifyMotionArgs>(args.front());
738 ASSERT_THAT(arg,
739 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
740 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000741 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000742 PointerCoords finger1Start = arg.pointerCoords[1];
743 args.pop_front();
744 arg = std::get<NotifyMotionArgs>(args.front());
745 ASSERT_THAT(arg,
746 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
747 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000748 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000749 PointerCoords finger2Start = arg.pointerCoords[2];
750 args.pop_front();
751 arg = std::get<NotifyMotionArgs>(args.front());
752 ASSERT_THAT(arg,
753 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
754 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000755 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000756 PointerCoords finger3Start = arg.pointerCoords[3];
757 args.pop_front();
758
759 arg = std::get<NotifyMotionArgs>(args.front());
760 ASSERT_THAT(arg,
761 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000762 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000763 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
764 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
765 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
766 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
767 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
768 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
769 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
770 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
771
772 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
773 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000774 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000775 ASSERT_EQ(1u, args.size());
776 arg = std::get<NotifyMotionArgs>(args.front());
777 ASSERT_THAT(arg,
778 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000779 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000780 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000781 WithPointerCount(4u), WithToolType(ToolType::FINGER),
782 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000783 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
784 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
785 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
786 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
787 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
788 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
789 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
790 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
791
792 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000793 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000794 ASSERT_THAT(args,
795 ElementsAre(VariantWith<NotifyMotionArgs>(
796 AllOf(WithMotionAction(
797 AMOTION_EVENT_ACTION_POINTER_UP |
798 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
799 WithGestureOffset(0, 0, EPSILON),
800 WithGestureSwipeFingerCount(4),
801 WithMotionClassification(
802 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000803 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000804 VariantWith<NotifyMotionArgs>(
805 AllOf(WithMotionAction(
806 AMOTION_EVENT_ACTION_POINTER_UP |
807 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
808 WithGestureOffset(0, 0, EPSILON),
809 WithGestureSwipeFingerCount(4),
810 WithMotionClassification(
811 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000812 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000813 VariantWith<NotifyMotionArgs>(
814 AllOf(WithMotionAction(
815 AMOTION_EVENT_ACTION_POINTER_UP |
816 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
817 WithGestureOffset(0, 0, EPSILON),
818 WithGestureSwipeFingerCount(4),
819 WithMotionClassification(
820 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000821 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000822 VariantWith<NotifyMotionArgs>(
823 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
824 WithGestureOffset(0, 0, EPSILON),
825 WithGestureSwipeFingerCount(4),
826 WithMotionClassification(
827 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000828 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000829 VariantWith<NotifyMotionArgs>(
830 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
831 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000832 WithMotionClassification(MotionClassification::NONE)))));
833 ASSERT_THAT(args,
834 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
835 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000836}
837
Harry Cuttsb1e83552022-12-20 11:02:26 +0000838TEST_F(GestureConverterTest, Pinch_Inwards) {
839 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
840 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000841 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000842
843 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
844 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000845 std::list<NotifyArgs> args =
846 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000847 ASSERT_THAT(args,
848 ElementsAre(VariantWith<NotifyMotionArgs>(
849 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +0000850 WithCoords(POINTER_X - 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000851 WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000852 VariantWith<NotifyMotionArgs>(
853 AllOf(WithMotionAction(
854 AMOTION_EVENT_ACTION_POINTER_DOWN |
855 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts5f26e952023-11-30 18:20:27 +0000856 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000857 WithPointerCount(2u)))));
858 ASSERT_THAT(args,
859 Each(VariantWith<NotifyMotionArgs>(
860 AllOf(WithMotionClassification(MotionClassification::PINCH),
861 WithGesturePinchScaleFactor(1.0f, EPSILON),
862 WithToolType(ToolType::FINGER),
863 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000864
865 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
866 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000867 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000868 ASSERT_THAT(args,
869 ElementsAre(VariantWith<NotifyMotionArgs>(
870 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
871 WithMotionClassification(MotionClassification::PINCH),
872 WithGesturePinchScaleFactor(0.8f, EPSILON),
873 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
874 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
875 WithToolType(ToolType::FINGER),
876 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000877
878 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
879 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000880 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000881 ASSERT_THAT(args,
882 ElementsAre(VariantWith<NotifyMotionArgs>(
883 AllOf(WithMotionAction(
884 AMOTION_EVENT_ACTION_POINTER_UP |
885 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
886 WithMotionClassification(MotionClassification::PINCH),
887 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000888 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000889 VariantWith<NotifyMotionArgs>(
890 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
891 WithMotionClassification(MotionClassification::PINCH),
892 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000893 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000894 VariantWith<NotifyMotionArgs>(
895 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
896 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000897 WithMotionClassification(MotionClassification::NONE)))));
898 ASSERT_THAT(args,
899 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
900 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000901}
902
903TEST_F(GestureConverterTest, Pinch_Outwards) {
904 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
905 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000906 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000907
908 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
909 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000910 std::list<NotifyArgs> args =
911 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000912 ASSERT_THAT(args,
913 ElementsAre(VariantWith<NotifyMotionArgs>(
914 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +0000915 WithCoords(POINTER_X - 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000916 WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000917 VariantWith<NotifyMotionArgs>(
918 AllOf(WithMotionAction(
919 AMOTION_EVENT_ACTION_POINTER_DOWN |
920 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts5f26e952023-11-30 18:20:27 +0000921 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000922 WithPointerCount(2u)))));
923 ASSERT_THAT(args,
924 Each(VariantWith<NotifyMotionArgs>(
925 AllOf(WithMotionClassification(MotionClassification::PINCH),
926 WithGesturePinchScaleFactor(1.0f, EPSILON),
927 WithToolType(ToolType::FINGER),
928 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000929
930 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
931 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000932 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000933 ASSERT_THAT(args,
934 ElementsAre(VariantWith<NotifyMotionArgs>(
935 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
936 WithMotionClassification(MotionClassification::PINCH),
937 WithGesturePinchScaleFactor(1.2f, EPSILON),
938 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
939 WithPointerCoords(1, POINTER_X + 120, POINTER_Y),
940 WithPointerCount(2u), WithToolType(ToolType::FINGER),
941 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000942
943 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
944 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000945 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000946 ASSERT_THAT(args,
947 ElementsAre(VariantWith<NotifyMotionArgs>(
948 AllOf(WithMotionAction(
949 AMOTION_EVENT_ACTION_POINTER_UP |
950 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
951 WithMotionClassification(MotionClassification::PINCH),
952 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000953 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000954 VariantWith<NotifyMotionArgs>(
955 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
956 WithMotionClassification(MotionClassification::PINCH),
957 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000958 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000959 VariantWith<NotifyMotionArgs>(
960 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
961 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +0000962 WithMotionClassification(MotionClassification::NONE)))));
963 ASSERT_THAT(args,
964 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
965 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000966}
967
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000968TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000969 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
970 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000971 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000972
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000973 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000974 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000975 std::list<NotifyArgs> args =
976 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000977
978 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000979 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000980 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000981
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000982 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000983 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000984 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000985
986 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000987 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000988 ASSERT_THAT(args,
989 ElementsAre(VariantWith<NotifyMotionArgs>(
990 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000991}
992
993TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
994 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
995 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000996 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000997
998 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
999 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001000 std::list<NotifyArgs> args =
1001 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001002
1003 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1004 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001005 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001006
1007 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1008 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001009 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001010
1011 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1012 // need to use another gesture type, like scroll.
1013 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1014 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001015 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001016 ASSERT_FALSE(args.empty());
1017 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001018}
1019
Harry Cuttse9b71422023-03-14 16:54:44 +00001020TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1021 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1022 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001023 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001024
1025 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1026 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1027 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001028 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001029
1030 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001031 ASSERT_THAT(args,
1032 ElementsAre(VariantWith<NotifyMotionArgs>(
1033 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1034 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001035 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001036 VariantWith<NotifyMotionArgs>(
1037 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1038 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001039 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001040 VariantWith<NotifyMotionArgs>(
1041 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001042 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001043 VariantWith<NotifyMotionArgs>(
1044 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001045 WithButtonState(0)))));
1046 ASSERT_THAT(args,
1047 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1048 WithToolType(ToolType::FINGER),
1049 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001050}
1051
1052TEST_F(GestureConverterTest, ResetDuringScroll) {
1053 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1054 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001055 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001056
1057 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001058 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001059
1060 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001061 ASSERT_THAT(args,
1062 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001063 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1064 WithCoords(POINTER_X, POINTER_Y - 10),
1065 WithGestureScrollDistance(0, 0, EPSILON),
1066 WithMotionClassification(
1067 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001068 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001069 VariantWith<NotifyMotionArgs>(
1070 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1071 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +00001072 WithMotionClassification(MotionClassification::NONE)))));
1073 ASSERT_THAT(args,
1074 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1075 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001076}
1077
1078TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1079 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1080 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001081 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001082
1083 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1084 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001085 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001086
1087 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001088 ASSERT_THAT(args,
1089 ElementsAre(VariantWith<NotifyMotionArgs>(
1090 AllOf(WithMotionAction(
1091 AMOTION_EVENT_ACTION_POINTER_UP |
1092 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1093 WithGestureOffset(0, 0, EPSILON),
1094 WithMotionClassification(
1095 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001096 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001097 VariantWith<NotifyMotionArgs>(
1098 AllOf(WithMotionAction(
1099 AMOTION_EVENT_ACTION_POINTER_UP |
1100 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1101 WithGestureOffset(0, 0, EPSILON),
1102 WithMotionClassification(
1103 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001104 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001105 VariantWith<NotifyMotionArgs>(
1106 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1107 WithGestureOffset(0, 0, EPSILON),
1108 WithMotionClassification(
1109 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001110 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001111 VariantWith<NotifyMotionArgs>(
1112 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001113 WithMotionClassification(MotionClassification::NONE)))));
1114 ASSERT_THAT(args,
1115 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1116 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001117}
1118
1119TEST_F(GestureConverterTest, ResetDuringPinch) {
1120 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1121 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001122 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001123
1124 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1125 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001126 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001127
1128 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001129 ASSERT_THAT(args,
1130 ElementsAre(VariantWith<NotifyMotionArgs>(
1131 AllOf(WithMotionAction(
1132 AMOTION_EVENT_ACTION_POINTER_UP |
1133 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1134 WithMotionClassification(MotionClassification::PINCH),
1135 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001136 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001137 VariantWith<NotifyMotionArgs>(
1138 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1139 WithMotionClassification(MotionClassification::PINCH),
1140 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001141 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001142 VariantWith<NotifyMotionArgs>(
1143 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1144 WithCoords(POINTER_X, POINTER_Y),
Harry Cuttsef95e712024-02-16 18:56:39 +00001145 WithMotionClassification(MotionClassification::NONE)))));
1146 ASSERT_THAT(args,
1147 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1148 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001149}
1150
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001151TEST_F(GestureConverterTest, FlingTapDown) {
1152 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1153 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001154 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001155
1156 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1157 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001158 std::list<NotifyArgs> args =
1159 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001160
1161 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00001162 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001163 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001164 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1165 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001166
1167 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1168 ASSERT_TRUE(mFakePointerController->isPointerShown());
1169}
1170
Harry Cutts39648ab2024-02-15 14:23:50 +00001171TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1172 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1173 input_flags::enable_touchpad_fling_stop(true);
1174 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1175 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1176
1177 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1178 std::list<NotifyArgs> args =
1179 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1180 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1181 GESTURES_FLING_START);
1182 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1183
1184 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1185 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1186 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1187 ASSERT_THAT(args,
1188 ElementsAre(VariantWith<NotifyMotionArgs>(
1189 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1190 VariantWith<NotifyMotionArgs>(
1191 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1192 VariantWith<NotifyMotionArgs>(
1193 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1194 VariantWith<NotifyMotionArgs>(
Harry Cutts574781a2024-04-23 15:30:45 +00001195 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001196 ASSERT_THAT(args,
Harry Cutts574781a2024-04-23 15:30:45 +00001197 Each(VariantWith<NotifyMotionArgs>(
1198 AllOf(WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
1199 WithDisplayId(ADISPLAY_ID_DEFAULT),
1200 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE)))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001201}
1202
Arpit Singha5ea7c12023-07-05 15:39:25 +00001203TEST_F(GestureConverterTest, Tap) {
1204 // Tap should produce button press/release events
1205 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1206 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001207 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001208
1209 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1210 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001211 std::list<NotifyArgs> args =
1212 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001213 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001214
1215 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1216 /* down= */ GESTURES_BUTTON_LEFT,
1217 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001218 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001219
Harry Cutts5f26e952023-11-30 18:20:27 +00001220 ASSERT_THAT(args,
1221 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001222 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001223 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001224 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001225 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001226 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001227 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001228 VariantWith<NotifyMotionArgs>(
1229 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1230 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1231 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001232 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001233 VariantWith<NotifyMotionArgs>(
1234 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1235 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001236 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001237 VariantWith<NotifyMotionArgs>(
1238 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001239 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001240 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001241 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001242 WithButtonState(0), WithPressure(0.0f)))));
1243 ASSERT_THAT(args,
1244 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1245 WithRelativeMotion(0.f, 0.f),
1246 WithToolType(ToolType::FINGER),
1247 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001248}
1249
1250TEST_F(GestureConverterTest, Click) {
1251 // Click should produce button press/release events
1252 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1253 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001254 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001255
1256 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1257 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001258 std::list<NotifyArgs> args =
1259 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001260 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001261
1262 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1263 /* down= */ GESTURES_BUTTON_LEFT,
1264 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001265 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001266
Harry Cutts5f26e952023-11-30 18:20:27 +00001267 ASSERT_THAT(args,
1268 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001269 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001270 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001271 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001272 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001273 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001274 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001275 VariantWith<NotifyMotionArgs>(
1276 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1277 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1278 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001279 WithPressure(1.0f)))));
1280 ASSERT_THAT(args,
1281 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1282 WithRelativeMotion(0.f, 0.f),
1283 WithToolType(ToolType::FINGER),
1284 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001285
1286 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1287 /* down= */ GESTURES_BUTTON_NONE,
1288 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001289 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001290 ASSERT_THAT(args,
1291 ElementsAre(VariantWith<NotifyMotionArgs>(
1292 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1293 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001294 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001295 VariantWith<NotifyMotionArgs>(
1296 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001297 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001298 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001299 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001300 WithPressure(0.0f)))));
1301 ASSERT_THAT(args,
1302 Each(VariantWith<NotifyMotionArgs>(
1303 AllOf(WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1304 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
1305 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001306}
1307
Arpit Singh3d84add2023-10-10 19:08:29 +00001308TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001309 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1310 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1311 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1312
Arpit Singha5ea7c12023-07-05 15:39:25 +00001313 // Tap should be ignored when disabled
1314 mReader->getContext()->setPreventingTouchpadTaps(true);
1315
1316 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1317 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001318 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001319
Arpit Singh82b27a02023-10-16 11:02:19 +00001320 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001321 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001322 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001323 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001324 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001325
Arpit Singh82b27a02023-10-16 11:02:19 +00001326 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001327 /* down= */ GESTURES_BUTTON_LEFT,
1328 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001329 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001330
1331 // no events should be generated
1332 ASSERT_EQ(0u, args.size());
1333
1334 // Future taps should be re-enabled
1335 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1336}
1337
Arpit Singh82b27a02023-10-16 11:02:19 +00001338TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1339 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1340 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1341
1342 // Tap should be ignored when disabled
1343 mReader->getContext()->setPreventingTouchpadTaps(true);
1344
1345 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1346 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1347 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1348
1349 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1350 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1351 std::list<NotifyArgs> args =
1352 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001353 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001354
1355 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1356 /* down= */ GESTURES_BUTTON_LEFT,
1357 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1358 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1359
1360 // no events should be generated
1361 ASSERT_EQ(0u, args.size());
1362
1363 // Future taps should be re-enabled
1364 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1365
1366 // taps before the threshold should still be ignored
1367 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1368 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1369 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1370 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1371
1372 ASSERT_EQ(1u, args.size());
1373 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1374 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1375
1376 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1377 /* down= */ GESTURES_BUTTON_LEFT,
1378 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1379 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1380
1381 // no events should be generated
1382 ASSERT_EQ(0u, args.size());
1383
1384 // taps after the threshold should be recognised
1385 currentTime += 1;
1386 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1387 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1388 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1389
1390 ASSERT_EQ(1u, args.size());
1391 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1392 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1393
1394 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1395 /* down= */ GESTURES_BUTTON_LEFT,
1396 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1397 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001398 ASSERT_THAT(args,
1399 ElementsAre(VariantWith<NotifyMotionArgs>(
1400 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1401 WithButtonState(0))),
1402 VariantWith<NotifyMotionArgs>(
1403 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1404 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1405 VariantWith<NotifyMotionArgs>(
1406 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1407 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1408 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1409 VariantWith<NotifyMotionArgs>(
1410 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1411 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1412 WithButtonState(0))),
1413 VariantWith<NotifyMotionArgs>(
1414 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1415 WithButtonState(0))),
1416 VariantWith<NotifyMotionArgs>(
1417 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1418 WithButtonState(0)))));
1419 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001420}
1421
Arpit Singh3d84add2023-10-10 19:08:29 +00001422TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1423 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001424 // Click should still produce button press/release events
1425 mReader->getContext()->setPreventingTouchpadTaps(true);
1426
1427 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1428 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001429 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001430
1431 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1432 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001433 std::list<NotifyArgs> args =
1434 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001435 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001436
1437 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1438 /* down= */ GESTURES_BUTTON_LEFT,
1439 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001440 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001441 ASSERT_THAT(args,
1442 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001443 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001444 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001445 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001446 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001447 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001448 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001449 VariantWith<NotifyMotionArgs>(
1450 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1451 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1452 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001453 WithPressure(1.0f)))));
1454 ASSERT_THAT(args,
1455 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1456 WithRelativeMotion(0.f, 0.f),
1457 WithToolType(ToolType::FINGER),
1458 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001459
1460 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1461 /* down= */ GESTURES_BUTTON_NONE,
1462 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001463 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001464
Harry Cutts5f26e952023-11-30 18:20:27 +00001465 ASSERT_THAT(args,
1466 ElementsAre(VariantWith<NotifyMotionArgs>(
1467 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1468 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001469 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001470 VariantWith<NotifyMotionArgs>(
1471 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001472 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001473 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001474 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001475 WithButtonState(0), WithPressure(0.0f)))));
1476 ASSERT_THAT(args,
1477 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y),
1478 WithRelativeMotion(0.f, 0.f),
1479 WithToolType(ToolType::FINGER),
1480 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001481
1482 // Future taps should be re-enabled
1483 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1484}
1485
Arpit Singh3d84add2023-10-10 19:08:29 +00001486TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1487 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001488 // initially disable tap-to-click
1489 mReader->getContext()->setPreventingTouchpadTaps(true);
1490
1491 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1492 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001493 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001494
1495 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001496 std::list<NotifyArgs> args =
1497 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001498 // We don't need to check args here, since it's covered by the Move test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001499
1500 // Future taps should be re-enabled
1501 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1502}
1503
Arpit Singh33a10a62023-10-12 13:06:54 +00001504TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1505 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1506 const nsecs_t gestureStartTime = 1000;
1507 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1508 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1509 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1510
1511 // Start a move gesture at gestureStartTime
1512 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1513 std::list<NotifyArgs> args =
1514 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001515 ASSERT_THAT(args,
1516 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001517 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1518 VariantWith<NotifyMotionArgs>(
1519 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001520
1521 // Key presses with IME connection should cancel ongoing move gesture
1522 nsecs_t currentTime = gestureStartTime + 100;
1523 mFakePolicy->setIsInputMethodConnectionActive(true);
1524 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1525 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1526 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001527 ASSERT_THAT(args,
1528 ElementsAre(VariantWith<NotifyMotionArgs>(
1529 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001530
1531 // any updates in existing move gesture should be ignored
1532 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1533 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1534 ASSERT_EQ(0u, args.size());
1535
1536 // New gesture should not be affected
1537 currentTime += 100;
1538 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1539 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001540 ASSERT_THAT(args,
1541 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001542 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1543 VariantWith<NotifyMotionArgs>(
1544 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001545}
1546
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001547// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1548// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001549class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1550protected:
1551 void SetUp() override {
1552 input_flags::enable_pointer_choreographer(true);
1553 GestureConverterTestBase::SetUp();
1554 }
1555};
1556
1557TEST_F(GestureConverterTestWithChoreographer, Move) {
1558 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1559 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1560 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1561
1562 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001563 std::list<NotifyArgs> args =
1564 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001565 ASSERT_THAT(args,
1566 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001567 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001568 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001569 VariantWith<NotifyMotionArgs>(
1570 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001571 WithRelativeMotion(-5, 10), WithButtonState(0),
1572 WithPressure(0.0f)))));
1573 ASSERT_THAT(args,
1574 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1575 WithToolType(ToolType::FINGER),
1576 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts379ea422023-12-21 15:31:47 +00001577
1578 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
1579 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1580 ASSERT_THAT(args,
1581 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001582 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1583 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1584 WithButtonState(0), WithPressure(0.0f),
1585 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001586}
1587
1588TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1589 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1590 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1591 converter.setOrientation(ui::ROTATION_90);
1592 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1593
1594 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001595 std::list<NotifyArgs> args =
1596 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001597 ASSERT_THAT(args,
1598 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001599 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001600 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001601 VariantWith<NotifyMotionArgs>(
1602 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001603 WithRelativeMotion(10, 5), WithButtonState(0),
1604 WithPressure(0.0f)))));
1605 ASSERT_THAT(args,
1606 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1607 WithToolType(ToolType::FINGER),
1608 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001609}
1610
1611TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1612 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1613 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1614 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1615
1616 // Press left and right buttons at once
1617 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1618 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1619 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001620 std::list<NotifyArgs> args =
1621 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001622 ASSERT_THAT(args,
1623 ElementsAre(VariantWith<NotifyMotionArgs>(
1624 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1625 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +00001626 AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001627 VariantWith<NotifyMotionArgs>(
1628 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1629 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001630 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001631 VariantWith<NotifyMotionArgs>(
1632 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1633 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1634 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +00001635 AMOTION_EVENT_BUTTON_SECONDARY)))));
1636 ASSERT_THAT(args,
1637 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1638 WithToolType(ToolType::FINGER),
1639 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001640
1641 // Then release the left button
1642 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1643 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1644 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001645 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001646 ASSERT_THAT(args,
1647 ElementsAre(VariantWith<NotifyMotionArgs>(
1648 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1649 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1650 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1651 WithToolType(ToolType::FINGER),
1652 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001653
1654 // Finally release the right button
1655 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1656 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1657 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001658 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001659 ASSERT_THAT(args,
1660 ElementsAre(VariantWith<NotifyMotionArgs>(
1661 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001662 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001663 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001664 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +00001665 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001666 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
1667 ASSERT_THAT(args,
1668 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
1669 WithToolType(ToolType::FINGER),
1670 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001671}
1672
Harry Cutts379ea422023-12-21 15:31:47 +00001673TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) {
1674 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1675 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1676 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1677
1678 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
1679 std::list<NotifyArgs> args =
1680 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
1681
1682 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1683 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
1684 /*is_tap=*/false);
1685 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
1686 ASSERT_THAT(args.front(),
1687 VariantWith<NotifyMotionArgs>(
1688 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
1689 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1690 WithDisplayId(ADISPLAY_ID_DEFAULT))));
1691}
1692
Byoungho Jungee6268f2023-10-30 17:27:26 +09001693TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1694 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1695 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1696 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1697
1698 // Press the button
1699 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1700 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1701 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001702 std::list<NotifyArgs> args =
1703 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001704 ASSERT_THAT(args,
1705 ElementsAre(VariantWith<NotifyMotionArgs>(
1706 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00001707 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001708 VariantWith<NotifyMotionArgs>(
1709 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1710 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001711 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)))));
1712 ASSERT_THAT(args,
1713 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1714 WithToolType(ToolType::FINGER),
1715 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001716
1717 // Move
1718 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001719 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001720 ASSERT_THAT(args,
1721 ElementsAre(VariantWith<NotifyMotionArgs>(
1722 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1723 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1724 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1725 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001726
1727 // Release the button
1728 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1729 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1730 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001731 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001732 ASSERT_THAT(args,
1733 ElementsAre(VariantWith<NotifyMotionArgs>(
1734 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001735 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001736 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001737 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +00001738 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00001739 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
1740 ASSERT_THAT(args,
1741 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
1742 WithToolType(ToolType::FINGER),
1743 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001744}
1745
1746TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1747 const nsecs_t downTime = 12345;
1748 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1749 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1750 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1751
1752 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001753 std::list<NotifyArgs> args =
1754 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001755 ASSERT_THAT(args,
1756 ElementsAre(VariantWith<NotifyMotionArgs>(
1757 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1758 WithCoords(0, 0),
1759 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001760 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001761 VariantWith<NotifyMotionArgs>(
1762 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1763 WithCoords(0, -10),
Harry Cuttsef95e712024-02-16 18:56:39 +00001764 WithGestureScrollDistance(0, 10, EPSILON)))));
1765 ASSERT_THAT(args,
1766 Each(VariantWith<NotifyMotionArgs>(
1767 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1768 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1769 WithToolType(ToolType::FINGER),
1770 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001771
1772 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001773 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001774 ASSERT_THAT(args,
1775 ElementsAre(VariantWith<NotifyMotionArgs>(
1776 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1777 WithGestureScrollDistance(0, 5, EPSILON),
1778 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1779 WithToolType(ToolType::FINGER),
1780 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1781 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001782
1783 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1784 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001785 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001786 ASSERT_THAT(args,
1787 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001788 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1789 WithCoords(0, -15),
1790 WithGestureScrollDistance(0, 0, EPSILON),
1791 WithMotionClassification(
1792 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001793 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001794 VariantWith<NotifyMotionArgs>(
1795 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1796 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001797 WithMotionClassification(MotionClassification::NONE)))));
1798 ASSERT_THAT(args,
1799 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1800 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001801}
1802
1803TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1804 const nsecs_t downTime = 12345;
1805 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1806 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1807 converter.setOrientation(ui::ROTATION_90);
1808 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1809
1810 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001811 std::list<NotifyArgs> args =
1812 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001813 ASSERT_THAT(args,
1814 ElementsAre(VariantWith<NotifyMotionArgs>(
1815 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1816 WithCoords(0, 0),
1817 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001818 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001819 VariantWith<NotifyMotionArgs>(
1820 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1821 WithCoords(-10, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001822 WithGestureScrollDistance(0, 10, EPSILON)))));
1823 ASSERT_THAT(args,
1824 Each(VariantWith<NotifyMotionArgs>(
1825 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1826 WithToolType(ToolType::FINGER),
1827 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001828
1829 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001830 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001831 ASSERT_THAT(args,
1832 ElementsAre(VariantWith<NotifyMotionArgs>(
1833 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1834 WithGestureScrollDistance(0, 5, EPSILON),
1835 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1836 WithToolType(ToolType::FINGER),
1837 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001838
1839 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1840 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001841 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001842 ASSERT_THAT(args,
1843 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001844 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1845 WithCoords(-15, 0),
1846 WithGestureScrollDistance(0, 0, EPSILON),
1847 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +00001848 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001849 VariantWith<NotifyMotionArgs>(
1850 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1851 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001852 WithMotionClassification(MotionClassification::NONE)))));
1853 ASSERT_THAT(args,
1854 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1855 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001856}
1857
1858TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1859 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1860 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1861 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1862
1863 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001864 std::list<NotifyArgs> args =
1865 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001866
1867 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001868 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001869
1870 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1871 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001872 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001873
1874 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001875 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001876 ASSERT_THAT(args,
1877 ElementsAre(VariantWith<NotifyMotionArgs>(
1878 AllOf(WithMotionClassification(MotionClassification::NONE),
1879 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001880}
1881
1882TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1883 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1884 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1885 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1886
1887 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001888 std::list<NotifyArgs> args =
1889 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001890
1891 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001892 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001893
1894 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1895 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001896 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001897
1898 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1899 // need to use another gesture type, like pinch.
1900 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1901 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001902 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001903 ASSERT_FALSE(args.empty());
1904 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1905}
1906
1907TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1908 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1909 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1910 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1911
1912 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1913 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001914 std::list<NotifyArgs> args =
1915 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001916
1917 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001918 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001919
1920 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1921 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001922 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001923 ASSERT_THAT(args,
1924 ElementsAre(VariantWith<NotifyMotionArgs>(
1925 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001926}
1927
1928TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1929 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1930 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1931 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1932
1933 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1934 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001935 std::list<NotifyArgs> args =
1936 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001937
1938 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001939 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001940
1941 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1942 // need to use another gesture type, like pinch.
1943 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1944 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001945 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001946 ASSERT_FALSE(args.empty());
1947 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1948 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1949}
1950
1951TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1952 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1953 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1954 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1955 // only checks movement in one dimension.
1956 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1957 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1958 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1959
1960 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1961 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001962 std::list<NotifyArgs> args =
1963 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001964 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00001965 ASSERT_THAT(args,
1966 Each(VariantWith<NotifyMotionArgs>(
1967 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1968 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
1969 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001970
1971 // Three fake fingers should be created. We don't actually care where they are, so long as they
1972 // move appropriately.
1973 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1974 ASSERT_THAT(arg,
1975 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001976 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001977 PointerCoords finger0Start = arg.pointerCoords[0];
1978 args.pop_front();
1979 arg = std::get<NotifyMotionArgs>(args.front());
1980 ASSERT_THAT(arg,
1981 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1982 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001983 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001984 PointerCoords finger1Start = arg.pointerCoords[1];
1985 args.pop_front();
1986 arg = std::get<NotifyMotionArgs>(args.front());
1987 ASSERT_THAT(arg,
1988 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1989 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001990 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001991 PointerCoords finger2Start = arg.pointerCoords[2];
1992 args.pop_front();
1993
1994 arg = std::get<NotifyMotionArgs>(args.front());
1995 ASSERT_THAT(arg,
1996 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001997 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001998 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1999 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2000 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2001 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
2002 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
2003 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
2004
2005 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2006 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002007 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002008 ASSERT_EQ(1u, args.size());
2009 arg = std::get<NotifyMotionArgs>(args.front());
2010 ASSERT_THAT(arg,
2011 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2012 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
2013 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2014 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2015 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2016 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
2017 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
2018 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
2019 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
2020 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
2021 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
2022
2023 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002024 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002025 ASSERT_THAT(args,
2026 ElementsAre(VariantWith<NotifyMotionArgs>(
2027 AllOf(WithMotionAction(
2028 AMOTION_EVENT_ACTION_POINTER_UP |
2029 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2030 WithGestureOffset(0, 0, EPSILON),
2031 WithGestureSwipeFingerCount(3),
2032 WithMotionClassification(
2033 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002034 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002035 VariantWith<NotifyMotionArgs>(
2036 AllOf(WithMotionAction(
2037 AMOTION_EVENT_ACTION_POINTER_UP |
2038 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2039 WithGestureOffset(0, 0, EPSILON),
2040 WithGestureSwipeFingerCount(3),
2041 WithMotionClassification(
2042 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002043 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002044 VariantWith<NotifyMotionArgs>(
2045 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2046 WithGestureOffset(0, 0, EPSILON),
2047 WithGestureSwipeFingerCount(3),
2048 WithMotionClassification(
2049 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002050 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002051 VariantWith<NotifyMotionArgs>(
2052 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2053 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002054 WithMotionClassification(MotionClassification::NONE)))));
2055 ASSERT_THAT(args,
2056 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2057 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002058}
2059
2060TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
2061 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2062 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2063 converter.setOrientation(ui::ROTATION_90);
2064 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2065
2066 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2067 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002068 std::list<NotifyArgs> args =
2069 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002070 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00002071 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002072
2073 // Three fake fingers should be created. We don't actually care where they are, so long as they
2074 // move appropriately.
2075 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2076 ASSERT_THAT(arg,
2077 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002078 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002079 PointerCoords finger0Start = arg.pointerCoords[0];
2080 args.pop_front();
2081 arg = std::get<NotifyMotionArgs>(args.front());
2082 ASSERT_THAT(arg,
2083 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2084 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002085 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002086 PointerCoords finger1Start = arg.pointerCoords[1];
2087 args.pop_front();
2088 arg = std::get<NotifyMotionArgs>(args.front());
2089 ASSERT_THAT(arg,
2090 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2091 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002092 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002093 PointerCoords finger2Start = arg.pointerCoords[2];
2094 args.pop_front();
2095
2096 arg = std::get<NotifyMotionArgs>(args.front());
2097 ASSERT_THAT(arg,
2098 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002099 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002100 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
2101 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
2102 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
2103 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2104 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2105 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2106
2107 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2108 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002109 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002110 ASSERT_EQ(1u, args.size());
2111 arg = std::get<NotifyMotionArgs>(args.front());
2112 ASSERT_THAT(arg,
2113 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2114 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
2115 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2116 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
2117 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
2118 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
2119 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2120 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2121 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2122
2123 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002124 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002125 ASSERT_THAT(args,
2126 ElementsAre(VariantWith<NotifyMotionArgs>(
2127 AllOf(WithMotionAction(
2128 AMOTION_EVENT_ACTION_POINTER_UP |
2129 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002130 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002131 VariantWith<NotifyMotionArgs>(
2132 AllOf(WithMotionAction(
2133 AMOTION_EVENT_ACTION_POINTER_UP |
2134 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002135 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002136 VariantWith<NotifyMotionArgs>(
2137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002138 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002139 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +00002140 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
2141 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002142}
2143
2144TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2145 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2146 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2147 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2148
2149 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2150 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002151 std::list<NotifyArgs> args =
2152 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002153 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +00002154 ASSERT_THAT(args,
2155 Each(VariantWith<NotifyMotionArgs>(
2156 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2157 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
2158 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002159
2160 // Four fake fingers should be created. We don't actually care where they are, so long as they
2161 // move appropriately.
2162 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2163 ASSERT_THAT(arg,
2164 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002165 WithPointerCount(1u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002166 PointerCoords finger0Start = arg.pointerCoords[0];
2167 args.pop_front();
2168 arg = std::get<NotifyMotionArgs>(args.front());
2169 ASSERT_THAT(arg,
2170 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2171 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002172 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002173 PointerCoords finger1Start = arg.pointerCoords[1];
2174 args.pop_front();
2175 arg = std::get<NotifyMotionArgs>(args.front());
2176 ASSERT_THAT(arg,
2177 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2178 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002179 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002180 PointerCoords finger2Start = arg.pointerCoords[2];
2181 args.pop_front();
2182 arg = std::get<NotifyMotionArgs>(args.front());
2183 ASSERT_THAT(arg,
2184 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2185 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002186 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002187 PointerCoords finger3Start = arg.pointerCoords[3];
2188 args.pop_front();
2189
2190 arg = std::get<NotifyMotionArgs>(args.front());
2191 ASSERT_THAT(arg,
2192 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002193 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002194 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2195 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2196 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2197 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2198 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2199 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2200 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2201 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2202
2203 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2204 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002205 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002206 ASSERT_EQ(1u, args.size());
2207 arg = std::get<NotifyMotionArgs>(args.front());
2208 ASSERT_THAT(arg,
2209 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2210 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2211 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2212 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2213 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2214 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2215 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2216 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2217 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2218 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2219 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2220 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2221 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2222
2223 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002224 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002225 ASSERT_THAT(args,
2226 ElementsAre(VariantWith<NotifyMotionArgs>(
2227 AllOf(WithMotionAction(
2228 AMOTION_EVENT_ACTION_POINTER_UP |
2229 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2230 WithGestureOffset(0, 0, EPSILON),
2231 WithGestureSwipeFingerCount(4),
2232 WithMotionClassification(
2233 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002234 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002235 VariantWith<NotifyMotionArgs>(
2236 AllOf(WithMotionAction(
2237 AMOTION_EVENT_ACTION_POINTER_UP |
2238 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2239 WithGestureOffset(0, 0, EPSILON),
2240 WithGestureSwipeFingerCount(4),
2241 WithMotionClassification(
2242 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002243 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002244 VariantWith<NotifyMotionArgs>(
2245 AllOf(WithMotionAction(
2246 AMOTION_EVENT_ACTION_POINTER_UP |
2247 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2248 WithGestureOffset(0, 0, EPSILON),
2249 WithGestureSwipeFingerCount(4),
2250 WithMotionClassification(
2251 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002252 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002253 VariantWith<NotifyMotionArgs>(
2254 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2255 WithGestureOffset(0, 0, EPSILON),
2256 WithGestureSwipeFingerCount(4),
2257 WithMotionClassification(
2258 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002259 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002260 VariantWith<NotifyMotionArgs>(
2261 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2262 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002263 WithMotionClassification(MotionClassification::NONE)))));
2264 ASSERT_THAT(args,
2265 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2266 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002267}
2268
2269TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2270 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2271 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2272 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2273
2274 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2275 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002276 std::list<NotifyArgs> args =
2277 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002278 ASSERT_THAT(args,
2279 ElementsAre(VariantWith<NotifyMotionArgs>(
2280 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00002281 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002282 VariantWith<NotifyMotionArgs>(
2283 AllOf(WithMotionAction(
2284 AMOTION_EVENT_ACTION_POINTER_DOWN |
2285 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002286 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
2287 ASSERT_THAT(args,
2288 Each(VariantWith<NotifyMotionArgs>(
2289 AllOf(WithMotionClassification(MotionClassification::PINCH),
2290 WithGesturePinchScaleFactor(1.0f, EPSILON),
2291 WithToolType(ToolType::FINGER),
2292 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002293
2294 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2295 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002296 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002297 ASSERT_THAT(args,
2298 ElementsAre(VariantWith<NotifyMotionArgs>(
2299 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2300 WithMotionClassification(MotionClassification::PINCH),
2301 WithGesturePinchScaleFactor(0.8f, EPSILON),
2302 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
2303 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2304 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002305
2306 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2307 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002308 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002309 ASSERT_THAT(args,
2310 ElementsAre(VariantWith<NotifyMotionArgs>(
2311 AllOf(WithMotionAction(
2312 AMOTION_EVENT_ACTION_POINTER_UP |
2313 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2314 WithMotionClassification(MotionClassification::PINCH),
2315 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002316 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002317 VariantWith<NotifyMotionArgs>(
2318 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2319 WithMotionClassification(MotionClassification::PINCH),
2320 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002321 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002322 VariantWith<NotifyMotionArgs>(
2323 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2324 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002325 WithMotionClassification(MotionClassification::NONE)))));
2326 ASSERT_THAT(args,
2327 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2328 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002329}
2330
2331TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2332 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2333 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2334 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2335
2336 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2337 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002338 std::list<NotifyArgs> args =
2339 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002340 ASSERT_THAT(args,
2341 ElementsAre(VariantWith<NotifyMotionArgs>(
2342 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +00002343 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002344 VariantWith<NotifyMotionArgs>(
2345 AllOf(WithMotionAction(
2346 AMOTION_EVENT_ACTION_POINTER_DOWN |
2347 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002348 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
2349 ASSERT_THAT(args,
2350 Each(VariantWith<NotifyMotionArgs>(
2351 AllOf(WithMotionClassification(MotionClassification::PINCH),
2352 WithGesturePinchScaleFactor(1.0f, EPSILON),
2353 WithToolType(ToolType::FINGER),
2354 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002355
2356 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2357 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002358 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002359 ASSERT_THAT(args,
2360 ElementsAre(VariantWith<NotifyMotionArgs>(
2361 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2362 WithMotionClassification(MotionClassification::PINCH),
2363 WithGesturePinchScaleFactor(1.1f, EPSILON),
2364 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
2365 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2366 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002367
2368 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2369 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002370 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002371 ASSERT_THAT(args,
2372 ElementsAre(VariantWith<NotifyMotionArgs>(
2373 AllOf(WithMotionAction(
2374 AMOTION_EVENT_ACTION_POINTER_UP |
2375 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2376 WithMotionClassification(MotionClassification::PINCH),
2377 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002378 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002379 VariantWith<NotifyMotionArgs>(
2380 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2381 WithMotionClassification(MotionClassification::PINCH),
2382 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002383 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002384 VariantWith<NotifyMotionArgs>(
2385 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2386 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002387 WithMotionClassification(MotionClassification::NONE)))));
2388 ASSERT_THAT(args,
2389 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2390 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002391}
2392
2393TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2394 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2395 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2396 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2397
2398 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2399 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002400 std::list<NotifyArgs> args =
2401 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002402
2403 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2404 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002405 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002406
2407 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2408 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002409 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002410
2411 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002412 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002413 ASSERT_THAT(args,
2414 ElementsAre(VariantWith<NotifyMotionArgs>(
2415 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002416}
2417
2418TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2419 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2420 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2421 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2422
2423 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2424 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002425 std::list<NotifyArgs> args =
2426 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002427
2428 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2429 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002430 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002431
2432 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2433 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002434 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002435
2436 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2437 // need to use another gesture type, like scroll.
2438 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2439 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002440 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002441 ASSERT_FALSE(args.empty());
2442 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2443}
2444
2445TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2446 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2447 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2448 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2449
2450 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2451 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2452 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002453 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002454
2455 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002456 ASSERT_THAT(args,
2457 ElementsAre(VariantWith<NotifyMotionArgs>(
2458 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2459 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002460 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002461 VariantWith<NotifyMotionArgs>(
2462 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2463 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002464 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002465 VariantWith<NotifyMotionArgs>(
2466 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002467 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00002468 VariantWith<NotifyMotionArgs>(
2469 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002470 WithButtonState(0)))));
2471 ASSERT_THAT(args,
2472 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2473 WithToolType(ToolType::FINGER),
2474 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002475}
2476
2477TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2478 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2479 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2480 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2481
2482 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002483 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002484
2485 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002486 ASSERT_THAT(args,
2487 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002488 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2489 WithCoords(0, -10),
2490 WithGestureScrollDistance(0, 0, EPSILON),
2491 WithMotionClassification(
2492 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002493 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00002494 VariantWith<NotifyMotionArgs>(
2495 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2496 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002497 WithMotionClassification(MotionClassification::NONE)))));
2498 ASSERT_THAT(args,
2499 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2500 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002501}
2502
2503TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2504 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2505 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2506 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2507
2508 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2509 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002510 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002511
2512 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002513 ASSERT_THAT(args,
2514 ElementsAre(VariantWith<NotifyMotionArgs>(
2515 AllOf(WithMotionAction(
2516 AMOTION_EVENT_ACTION_POINTER_UP |
2517 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2518 WithGestureOffset(0, 0, EPSILON),
2519 WithMotionClassification(
2520 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002521 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002522 VariantWith<NotifyMotionArgs>(
2523 AllOf(WithMotionAction(
2524 AMOTION_EVENT_ACTION_POINTER_UP |
2525 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2526 WithGestureOffset(0, 0, EPSILON),
2527 WithMotionClassification(
2528 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002529 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002530 VariantWith<NotifyMotionArgs>(
2531 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2532 WithGestureOffset(0, 0, EPSILON),
2533 WithMotionClassification(
2534 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00002535 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002536 VariantWith<NotifyMotionArgs>(
2537 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002538 WithMotionClassification(MotionClassification::NONE)))));
2539 ASSERT_THAT(args,
2540 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2541 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002542}
2543
2544TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2545 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2546 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2547 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2548
2549 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2550 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002551 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002552
2553 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002554 ASSERT_THAT(args,
2555 ElementsAre(VariantWith<NotifyMotionArgs>(
2556 AllOf(WithMotionAction(
2557 AMOTION_EVENT_ACTION_POINTER_UP |
2558 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2559 WithMotionClassification(MotionClassification::PINCH),
2560 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002561 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002562 VariantWith<NotifyMotionArgs>(
2563 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2564 WithMotionClassification(MotionClassification::PINCH),
2565 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00002566 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00002567 VariantWith<NotifyMotionArgs>(
2568 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2569 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00002570 WithMotionClassification(MotionClassification::NONE)))));
2571 ASSERT_THAT(args,
2572 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
2573 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002574}
2575
2576TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2577 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2578 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2579 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2580
2581 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2582 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002583 std::list<NotifyArgs> args =
2584 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002585
2586 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Harry Cutts379ea422023-12-21 15:31:47 +00002587 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
Byoungho Jungee6268f2023-10-30 17:27:26 +09002588 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2589 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2590}
2591
Harry Cutts39648ab2024-02-15 14:23:50 +00002592TEST_F(GestureConverterTestWithChoreographer, FlingTapDownAfterScrollStopsFling) {
2593 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2594 input_flags::enable_touchpad_fling_stop(true);
2595 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2596 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2597
2598 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
2599 std::list<NotifyArgs> args =
2600 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
2601 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
2602 GESTURES_FLING_START);
2603 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
2604
2605 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2606 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
2607 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
2608 ASSERT_THAT(args,
2609 ElementsAre(VariantWith<NotifyMotionArgs>(
2610 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
2611 VariantWith<NotifyMotionArgs>(
2612 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
2613 VariantWith<NotifyMotionArgs>(
2614 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
2615 VariantWith<NotifyMotionArgs>(
Harry Cutts574781a2024-04-23 15:30:45 +00002616 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
Harry Cutts39648ab2024-02-15 14:23:50 +00002617 ASSERT_THAT(args,
Harry Cutts574781a2024-04-23 15:30:45 +00002618 Each(VariantWith<NotifyMotionArgs>(
2619 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
2620 WithDisplayId(ADISPLAY_ID_DEFAULT),
2621 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE)))));
Harry Cutts39648ab2024-02-15 14:23:50 +00002622}
2623
Byoungho Jungee6268f2023-10-30 17:27:26 +09002624TEST_F(GestureConverterTestWithChoreographer, Tap) {
2625 // Tap should produce button press/release events
2626 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2627 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2628 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2629
2630 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2631 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002632 std::list<NotifyArgs> args =
2633 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002634 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002635
2636 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2637 /* down= */ GESTURES_BUTTON_LEFT,
2638 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002639 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002640
Harry Cutts5f26e952023-11-30 18:20:27 +00002641 ASSERT_THAT(args,
2642 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002643 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002644 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002645 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002646 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002647 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002648 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002649 VariantWith<NotifyMotionArgs>(
2650 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2651 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2652 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002653 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002654 VariantWith<NotifyMotionArgs>(
2655 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2656 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002657 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002658 VariantWith<NotifyMotionArgs>(
2659 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002660 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002661 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002662 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002663 WithButtonState(0), WithPressure(0.0f)))));
2664 ASSERT_THAT(args,
2665 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2666 WithRelativeMotion(0.f, 0.f),
2667 WithToolType(ToolType::FINGER),
2668 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002669}
2670
2671TEST_F(GestureConverterTestWithChoreographer, Click) {
2672 // Click should produce button press/release events
2673 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2674 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2675 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2676
2677 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2678 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002679 std::list<NotifyArgs> args =
2680 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, 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
2683 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2684 /* down= */ GESTURES_BUTTON_LEFT,
2685 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002686 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002687
Harry Cutts5f26e952023-11-30 18:20:27 +00002688 ASSERT_THAT(args,
2689 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002690 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002691 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002692 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002693 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002694 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002695 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002696 VariantWith<NotifyMotionArgs>(
2697 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2698 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2699 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002700 WithPressure(1.0f)))));
2701 ASSERT_THAT(args,
2702 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2703 WithRelativeMotion(0.f, 0.f),
2704 WithToolType(ToolType::FINGER),
2705 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002706
2707 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2708 /* down= */ GESTURES_BUTTON_NONE,
2709 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002710 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002711
Harry Cutts5f26e952023-11-30 18:20:27 +00002712 ASSERT_THAT(args,
2713 ElementsAre(VariantWith<NotifyMotionArgs>(
2714 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2715 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002716 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002717 VariantWith<NotifyMotionArgs>(
2718 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00002719 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002720 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002721 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00002722 WithPressure(0.0f)))));
2723 ASSERT_THAT(args,
2724 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
2725 WithRelativeMotion(0.f, 0.f),
2726 WithToolType(ToolType::FINGER),
2727 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002728}
2729
2730TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002731 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2732 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2733 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2734
Byoungho Jungee6268f2023-10-30 17:27:26 +09002735 // Tap should be ignored when disabled
2736 mReader->getContext()->setPreventingTouchpadTaps(true);
2737
2738 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2739 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2740 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2741
Arpit Singh82b27a02023-10-16 11:02:19 +00002742 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002743 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002744 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002745 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002746 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002747
Arpit Singh82b27a02023-10-16 11:02:19 +00002748 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002749 /* down= */ GESTURES_BUTTON_LEFT,
2750 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002751 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002752
2753 // no events should be generated
2754 ASSERT_EQ(0u, args.size());
2755
2756 // Future taps should be re-enabled
2757 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2758}
2759
Arpit Singh82b27a02023-10-16 11:02:19 +00002760TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2761 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2762 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2763
2764 // Tap should be ignored when disabled
2765 mReader->getContext()->setPreventingTouchpadTaps(true);
2766
2767 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2768 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2769 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2770
2771 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2772 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2773 std::list<NotifyArgs> args =
2774 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002775 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00002776
2777 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2778 /* down= */ GESTURES_BUTTON_LEFT,
2779 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2780 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2781
2782 // no events should be generated
2783 ASSERT_EQ(0u, args.size());
2784
2785 // Future taps should be re-enabled
2786 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2787
2788 // taps before the threshold should still be ignored
2789 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2790 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2791 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2792 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2793
2794 ASSERT_EQ(1u, args.size());
2795 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2796 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2797
2798 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2799 /* down= */ GESTURES_BUTTON_LEFT,
2800 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2801 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2802
2803 // no events should be generated
2804 ASSERT_EQ(0u, args.size());
2805
2806 // taps after the threshold should be recognised
2807 currentTime += 1;
2808 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2809 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2810 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2811
2812 ASSERT_EQ(1u, args.size());
2813 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2814 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2815
2816 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2817 /* down= */ GESTURES_BUTTON_LEFT,
2818 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2819 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00002820 ASSERT_THAT(args,
2821 ElementsAre(VariantWith<NotifyMotionArgs>(
2822 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
2823 WithButtonState(0))),
2824 VariantWith<NotifyMotionArgs>(
2825 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2826 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
2827 VariantWith<NotifyMotionArgs>(
2828 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2829 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2830 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
2831 VariantWith<NotifyMotionArgs>(
2832 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2833 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2834 WithButtonState(0))),
2835 VariantWith<NotifyMotionArgs>(
2836 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2837 WithButtonState(0))),
2838 VariantWith<NotifyMotionArgs>(
2839 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
2840 WithButtonState(0)))));
2841 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00002842}
2843
Byoungho Jungee6268f2023-10-30 17:27:26 +09002844TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2845 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2846 // Click should still produce button press/release events
2847 mReader->getContext()->setPreventingTouchpadTaps(true);
2848
2849 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2850 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2851 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2852
2853 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2854 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002855 std::list<NotifyArgs> args =
2856 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002857 // We don't need to check args here, since it's covered by the FlingTapDown test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002858
2859 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2860 /* down= */ GESTURES_BUTTON_LEFT,
2861 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002862 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002863
Harry Cutts5f26e952023-11-30 18:20:27 +00002864 ASSERT_THAT(args,
2865 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002866 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00002867 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00002868 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00002869 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00002870 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002871 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00002872 VariantWith<NotifyMotionArgs>(
2873 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2874 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2875 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00002876 WithPressure(1.0f)))));
2877 ASSERT_THAT(args,
2878 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
2879 WithRelativeMotion(0.f, 0.f),
2880 WithToolType(ToolType::FINGER),
2881 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002882
2883 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2884 /* down= */ GESTURES_BUTTON_NONE,
2885 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002886 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002887
Harry Cutts5f26e952023-11-30 18:20:27 +00002888 ASSERT_THAT(args,
2889 ElementsAre(VariantWith<NotifyMotionArgs>(
2890 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2891 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2892 WithButtonState(0), WithCoords(0, 0),
2893 WithRelativeMotion(0.f, 0.f),
2894 WithToolType(ToolType::FINGER), WithButtonState(0),
2895 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2896 VariantWith<NotifyMotionArgs>(
2897 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2898 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2899 WithToolType(ToolType::FINGER), WithButtonState(0),
2900 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2901 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002902 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00002903 WithCoords(0, 0), WithRelativeMotion(0, 0),
2904 WithToolType(ToolType::FINGER), WithButtonState(0),
2905 WithPressure(0.0f),
2906 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002907
2908 // Future taps should be re-enabled
2909 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2910}
2911
2912TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2913 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2914 // initially disable tap-to-click
2915 mReader->getContext()->setPreventingTouchpadTaps(true);
2916
2917 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2918 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2919 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2920
2921 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002922 std::list<NotifyArgs> args =
2923 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00002924 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09002925
2926 // Future taps should be re-enabled
2927 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2928}
2929
Arpit Singh33a10a62023-10-12 13:06:54 +00002930TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
2931 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2932 const nsecs_t gestureStartTime = 1000;
2933 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2934 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2935 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2936
2937 // Start a move gesture at gestureStartTime
2938 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
2939 std::list<NotifyArgs> args =
2940 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002941 ASSERT_THAT(args,
2942 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002943 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
2944 VariantWith<NotifyMotionArgs>(
2945 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002946
2947 // Key presses with IME connection should cancel ongoing move gesture
2948 nsecs_t currentTime = gestureStartTime + 100;
2949 mFakePolicy->setIsInputMethodConnectionActive(true);
2950 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
2951 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2952 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002953 ASSERT_THAT(args,
2954 ElementsAre(VariantWith<NotifyMotionArgs>(
2955 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002956
2957 // any updates in existing move gesture should be ignored
2958 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2959 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2960 ASSERT_EQ(0u, args.size());
2961
2962 // New gesture should not be affected
2963 currentTime += 100;
2964 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2965 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002966 ASSERT_THAT(args,
2967 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00002968 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
2969 VariantWith<NotifyMotionArgs>(
2970 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002971}
2972
Harry Cutts4fb941a2022-12-14 19:14:04 +00002973} // namespace android