blob: 7be6d46954f6e91207a876704e68ae35ac39e714 [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;
50
Byoungho Jungee6268f2023-10-30 17:27:26 +090051class GestureConverterTestBase : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000052protected:
53 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000054 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000055 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000056 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000057 static constexpr float POINTER_Y = 200;
58
59 void SetUp() {
60 mFakeEventHub = std::make_unique<FakeEventHub>();
61 mFakePolicy = sp<FakeInputReaderPolicy>::make();
62 mFakeListener = std::make_unique<TestInputListener>();
63 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
64 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000065 mDevice = newDevice();
66 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
67 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000068
69 mFakePointerController = std::make_shared<FakePointerController>();
70 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
71 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
72 mFakePolicy->setPointerController(mFakePointerController);
73 }
74
Harry Cuttsc5748d12022-12-02 17:30:18 +000075 std::shared_ptr<InputDevice> newDevice() {
76 InputDeviceIdentifier identifier;
77 identifier.name = "device";
78 identifier.location = "USB1";
79 identifier.bus = 0;
80 std::shared_ptr<InputDevice> device =
81 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
82 identifier);
83 mReader->pushNextDevice(device);
84 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
85 identifier.bus);
86 mReader->loopOnce();
87 return device;
88 }
89
Harry Cutts4fb941a2022-12-14 19:14:04 +000090 std::shared_ptr<FakeEventHub> mFakeEventHub;
91 sp<FakeInputReaderPolicy> mFakePolicy;
92 std::unique_ptr<TestInputListener> mFakeListener;
93 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000094 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000095 std::shared_ptr<FakePointerController> mFakePointerController;
96};
97
Byoungho Jungee6268f2023-10-30 17:27:26 +090098class GestureConverterTest : public GestureConverterTestBase {
99protected:
100 void SetUp() override {
101 input_flags::enable_pointer_choreographer(false);
102 GestureConverterTestBase::SetUp();
103 }
104};
105
Harry Cutts4fb941a2022-12-14 19:14:04 +0000106TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000107 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
108 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000109 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000110
111 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000112 std::list<NotifyArgs> args =
113 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000114 ASSERT_EQ(1u, args.size());
115
116 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
117 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
118 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +0000119 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
120 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000121
Harry Cuttsb1e83552022-12-20 11:02:26 +0000122 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000123}
124
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000125TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000126 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
127 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000128 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000129 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000130
131 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000132 std::list<NotifyArgs> args =
133 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000134 ASSERT_EQ(1u, args.size());
135
136 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
138 WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5),
Josep del Riod0746382023-07-29 13:18:25 +0000139 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
140 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000141
Harry Cuttsb1e83552022-12-20 11:02:26 +0000142 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000143}
144
Harry Cutts4fb941a2022-12-14 19:14:04 +0000145TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000146 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
147 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000148 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000149
150 // Press left and right buttons at once
151 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
152 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
153 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000154 std::list<NotifyArgs> args =
155 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000156 ASSERT_EQ(3u, args.size());
157
158 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
159 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
160 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
161 AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000162 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
163 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000164 args.pop_front();
165 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
166 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
167 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
168 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000169 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
170 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000171 args.pop_front();
172 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
173 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
174 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
175 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
176 AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000177 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
178 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000179
180 // Then release the left button
181 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
182 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
183 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000184 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000185 ASSERT_EQ(1u, args.size());
186
187 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
188 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
189 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
190 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000191 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
192 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000193
194 // Finally release the right button
195 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
196 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
197 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000198 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts48e7a402023-07-07 15:22:40 +0000199 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000200
201 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
202 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
203 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000204 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
205 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000206 args.pop_front();
207 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
208 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000209 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
210 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000211 args.pop_front();
212 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
213 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000214 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
215 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000216}
217
218TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000219 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
220 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000221 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000222
223 // Press the button
224 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
225 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
226 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000227 std::list<NotifyArgs> args =
228 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000229 ASSERT_EQ(2u, args.size());
230
231 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
232 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
233 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000234 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
235 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000236 args.pop_front();
237 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
238 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
239 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
240 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +0000241 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
242 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000243
244 // Move
245 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000246 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000247 ASSERT_EQ(1u, args.size());
248
249 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
250 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
251 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +0000252 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
253 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000254
Harry Cuttsb1e83552022-12-20 11:02:26 +0000255 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000256
257 // Release the button
258 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
259 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
260 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000261 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts48e7a402023-07-07 15:22:40 +0000262 ASSERT_EQ(3u, args.size());
Harry Cutts4fb941a2022-12-14 19:14:04 +0000263
264 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
265 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
266 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000267 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
268 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000269 args.pop_front();
270 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
271 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000272 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
273 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts48e7a402023-07-07 15:22:40 +0000274 args.pop_front();
275 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
276 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000277 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithToolType(ToolType::FINGER),
278 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000279}
280
Harry Cuttsef400b22022-12-16 21:26:24 +0000281TEST_F(GestureConverterTest, Scroll) {
282 const nsecs_t downTime = 12345;
283 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
284 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000285 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000286
Harry Cuttsa546ba82023-01-13 17:21:00 +0000287 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000288 std::list<NotifyArgs> args =
289 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000290 ASSERT_EQ(2u, args.size());
291
292 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
293 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
294 WithGestureScrollDistance(0, 0, EPSILON),
295 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700296 WithToolType(ToolType::FINGER), WithDownTime(downTime),
Josep del Riod0746382023-07-29 13:18:25 +0000297 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
298 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000299 args.pop_front();
300 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
301 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
302 WithCoords(POINTER_X, POINTER_Y - 10),
303 WithGestureScrollDistance(0, 10, EPSILON),
304 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700305 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000306 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
307 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000308
Harry Cuttsa546ba82023-01-13 17:21:00 +0000309 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000310 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000311 ASSERT_EQ(1u, args.size());
312 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
313 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
314 WithCoords(POINTER_X, POINTER_Y - 15),
315 WithGestureScrollDistance(0, 5, EPSILON),
316 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700317 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000318 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
319 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000320
321 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
322 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000323 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000324 ASSERT_EQ(1u, args.size());
325 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
326 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
327 WithCoords(POINTER_X, POINTER_Y - 15),
328 WithGestureScrollDistance(0, 0, EPSILON),
329 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700330 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +0000331 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
332 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000333}
334
335TEST_F(GestureConverterTest, Scroll_Rotated) {
336 const nsecs_t downTime = 12345;
337 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
338 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
339 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000340 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000341
Harry Cuttsa546ba82023-01-13 17:21:00 +0000342 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000343 std::list<NotifyArgs> args =
344 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000345 ASSERT_EQ(2u, args.size());
346
347 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
348 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
349 WithGestureScrollDistance(0, 0, EPSILON),
350 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000351 WithToolType(ToolType::FINGER), WithDownTime(downTime),
352 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000353 args.pop_front();
354 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
355 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
356 WithCoords(POINTER_X - 10, POINTER_Y),
357 WithGestureScrollDistance(0, 10, EPSILON),
358 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000359 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000360
Harry Cuttsa546ba82023-01-13 17:21:00 +0000361 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000362 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000363 ASSERT_EQ(1u, args.size());
364 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
365 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
366 WithCoords(POINTER_X - 15, POINTER_Y),
367 WithGestureScrollDistance(0, 5, EPSILON),
368 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000369 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000370
371 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
372 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000373 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000374 ASSERT_EQ(1u, args.size());
375 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
376 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
377 WithCoords(POINTER_X - 15, POINTER_Y),
378 WithGestureScrollDistance(0, 0, EPSILON),
379 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000380 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000381}
382
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000383TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000384 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
385 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000386 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000387
Harry Cuttsa546ba82023-01-13 17:21:00 +0000388 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000389 std::list<NotifyArgs> args =
390 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000391
Harry Cuttsa546ba82023-01-13 17:21:00 +0000392 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000393 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000394
395 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
396 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000397 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000398
399 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000400 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000401 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000402 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
Josep del Riod0746382023-07-29 13:18:25 +0000403 AllOf(WithMotionClassification(MotionClassification::NONE),
404 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsef400b22022-12-16 21:26:24 +0000405}
406
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000407TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000408 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
409 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000410 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000411
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000412 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000413 std::list<NotifyArgs> args =
414 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000415
416 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000417 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000418
419 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
420 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000421 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000422
423 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
424 // need to use another gesture type, like pinch.
425 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
426 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000427 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000428 ASSERT_FALSE(args.empty());
429 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
430}
431
432TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
433 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
434 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000435 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000436
437 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
438 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000439 std::list<NotifyArgs> args =
440 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000441
442 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000443 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000444
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000445 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
446 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000447 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000448 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000449 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
450 WithMotionClassification(MotionClassification::NONE));
451}
452
Harry Cutts8743f182023-05-17 12:03:49 +0000453TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000454 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
455 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000456 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000457
458 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
459 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000460 std::list<NotifyArgs> args =
461 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000462
463 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000464 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000465
466 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
467 // need to use another gesture type, like pinch.
468 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
469 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000470 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000471 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000472 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
473 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000474}
475
476TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
477 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
478 // start swiping up and then start moving left or right, it'll return gesture events with only Y
479 // deltas until you lift your fingers and start swiping again. That's why each of these tests
480 // only checks movement in one dimension.
481 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
482 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000483 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000484
485 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
486 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000487 std::list<NotifyArgs> args =
488 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000489 ASSERT_EQ(4u, args.size());
490
491 // Three fake fingers should be created. We don't actually care where they are, so long as they
492 // move appropriately.
493 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
494 ASSERT_THAT(arg,
495 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000496 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000497 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000498 WithPointerCount(1u), WithToolType(ToolType::FINGER),
499 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000500 PointerCoords finger0Start = arg.pointerCoords[0];
501 args.pop_front();
502 arg = std::get<NotifyMotionArgs>(args.front());
503 ASSERT_THAT(arg,
504 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
505 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000506 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000507 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000508 WithPointerCount(2u), WithToolType(ToolType::FINGER),
509 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000510 PointerCoords finger1Start = arg.pointerCoords[1];
511 args.pop_front();
512 arg = std::get<NotifyMotionArgs>(args.front());
513 ASSERT_THAT(arg,
514 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
515 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000516 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000517 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000518 WithPointerCount(3u), WithToolType(ToolType::FINGER),
519 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000520 PointerCoords finger2Start = arg.pointerCoords[2];
521 args.pop_front();
522
523 arg = std::get<NotifyMotionArgs>(args.front());
524 ASSERT_THAT(arg,
525 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000526 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000527 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000528 WithPointerCount(3u), WithToolType(ToolType::FINGER),
529 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000530 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
531 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
532 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
533 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
534 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
535 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
536
537 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
538 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000539 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000540 ASSERT_EQ(1u, args.size());
541 arg = std::get<NotifyMotionArgs>(args.front());
542 ASSERT_THAT(arg,
543 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000544 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000545 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000546 WithPointerCount(3u), WithToolType(ToolType::FINGER),
547 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000548 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
549 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
550 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
551 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
552 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
553 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
554
555 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000556 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000557 ASSERT_EQ(3u, args.size());
558 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
559 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
560 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000561 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000562 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000563 WithPointerCount(3u), WithToolType(ToolType::FINGER),
564 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000565 args.pop_front();
566 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
567 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
568 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000569 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000570 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000571 WithPointerCount(2u), WithToolType(ToolType::FINGER),
572 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000573 args.pop_front();
574 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
575 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000576 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000577 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000578 WithPointerCount(1u), WithToolType(ToolType::FINGER),
579 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000580}
581
Harry Cutts94f5bd52023-01-06 18:02:18 +0000582TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
583 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
584 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
585 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000586 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000587
588 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
589 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000590 std::list<NotifyArgs> args =
591 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000592 ASSERT_EQ(4u, args.size());
593
594 // Three fake fingers should be created. We don't actually care where they are, so long as they
595 // move appropriately.
596 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
597 ASSERT_THAT(arg,
598 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000599 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000600 PointerCoords finger0Start = arg.pointerCoords[0];
601 args.pop_front();
602 arg = std::get<NotifyMotionArgs>(args.front());
603 ASSERT_THAT(arg,
604 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
605 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000606 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
607 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000608 PointerCoords finger1Start = arg.pointerCoords[1];
609 args.pop_front();
610 arg = std::get<NotifyMotionArgs>(args.front());
611 ASSERT_THAT(arg,
612 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
613 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000614 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
615 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000616 PointerCoords finger2Start = arg.pointerCoords[2];
617 args.pop_front();
618
619 arg = std::get<NotifyMotionArgs>(args.front());
620 ASSERT_THAT(arg,
621 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000622 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
623 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000624 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
625 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
626 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
627 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
628 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
629 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
630
631 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
632 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000633 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000634 ASSERT_EQ(1u, args.size());
635 arg = std::get<NotifyMotionArgs>(args.front());
636 ASSERT_THAT(arg,
637 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000638 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
639 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000640 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
641 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
642 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
643 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
644 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
645 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
646
647 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000648 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000649 ASSERT_EQ(3u, args.size());
650 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
651 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
652 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000653 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
654 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000655 args.pop_front();
656 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
657 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
658 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000659 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
660 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000661 args.pop_front();
662 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
663 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000664 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000665}
666
Harry Cuttsc5748d12022-12-02 17:30:18 +0000667TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
668 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
669 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000670 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000671
672 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
673 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000674 std::list<NotifyArgs> args =
675 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000676 ASSERT_EQ(5u, args.size());
677
678 // Four fake fingers should be created. We don't actually care where they are, so long as they
679 // move appropriately.
680 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
681 ASSERT_THAT(arg,
682 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000683 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000684 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000685 WithPointerCount(1u), WithToolType(ToolType::FINGER),
686 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000687 PointerCoords finger0Start = arg.pointerCoords[0];
688 args.pop_front();
689 arg = std::get<NotifyMotionArgs>(args.front());
690 ASSERT_THAT(arg,
691 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
692 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000693 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000694 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000695 WithPointerCount(2u), WithToolType(ToolType::FINGER),
696 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000697 PointerCoords finger1Start = arg.pointerCoords[1];
698 args.pop_front();
699 arg = std::get<NotifyMotionArgs>(args.front());
700 ASSERT_THAT(arg,
701 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
702 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000703 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000704 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000705 WithPointerCount(3u), WithToolType(ToolType::FINGER),
706 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000707 PointerCoords finger2Start = arg.pointerCoords[2];
708 args.pop_front();
709 arg = std::get<NotifyMotionArgs>(args.front());
710 ASSERT_THAT(arg,
711 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
712 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000713 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000714 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000715 WithPointerCount(4u), WithToolType(ToolType::FINGER),
716 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000717 PointerCoords finger3Start = arg.pointerCoords[3];
718 args.pop_front();
719
720 arg = std::get<NotifyMotionArgs>(args.front());
721 ASSERT_THAT(arg,
722 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000723 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000724 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000725 WithPointerCount(4u), WithToolType(ToolType::FINGER),
726 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000727 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
728 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
729 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
730 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
731 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
732 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
733 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
734 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
735
736 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
737 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000738 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000739 ASSERT_EQ(1u, args.size());
740 arg = std::get<NotifyMotionArgs>(args.front());
741 ASSERT_THAT(arg,
742 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000743 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000744 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000745 WithPointerCount(4u), WithToolType(ToolType::FINGER),
746 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000747 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
748 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
749 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
750 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
751 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
752 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
753 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
754 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
755
756 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000757 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000758 ASSERT_EQ(4u, args.size());
759 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
760 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
761 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000762 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000763 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000764 WithPointerCount(4u), WithToolType(ToolType::FINGER),
765 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000766 args.pop_front();
767 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
768 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
769 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000770 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000771 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000772 WithPointerCount(3u), WithToolType(ToolType::FINGER),
773 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000774 args.pop_front();
775 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
776 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
777 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000778 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000779 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000780 WithPointerCount(2u), WithToolType(ToolType::FINGER),
781 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000782 args.pop_front();
783 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
784 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000785 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000786 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000787 WithPointerCount(1u), WithToolType(ToolType::FINGER),
788 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000789}
790
Harry Cuttsb1e83552022-12-20 11:02:26 +0000791TEST_F(GestureConverterTest, Pinch_Inwards) {
792 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
793 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000794 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000795
796 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
797 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000798 std::list<NotifyArgs> args =
799 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000800 ASSERT_EQ(2u, args.size());
801 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
802 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
803 WithMotionClassification(MotionClassification::PINCH),
804 WithGesturePinchScaleFactor(1.0f, EPSILON),
805 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000806 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000807 args.pop_front();
808 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
809 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
810 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
811 WithMotionClassification(MotionClassification::PINCH),
812 WithGesturePinchScaleFactor(1.0f, EPSILON),
813 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000814 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000815
816 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
817 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000818 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000819 ASSERT_EQ(1u, args.size());
820 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
821 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
822 WithMotionClassification(MotionClassification::PINCH),
823 WithGesturePinchScaleFactor(0.8f, EPSILON),
824 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
825 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000826 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000827
828 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
829 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000830 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000831 ASSERT_EQ(2u, args.size());
832 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
833 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
834 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
835 WithMotionClassification(MotionClassification::PINCH),
836 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000837 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000838 args.pop_front();
839 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
840 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
841 WithMotionClassification(MotionClassification::PINCH),
842 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000843 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000844}
845
846TEST_F(GestureConverterTest, Pinch_Outwards) {
847 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
848 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000849 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000850
851 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
852 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000853 std::list<NotifyArgs> args =
854 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000855 ASSERT_EQ(2u, args.size());
856 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
857 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
858 WithMotionClassification(MotionClassification::PINCH),
859 WithGesturePinchScaleFactor(1.0f, EPSILON),
860 WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000861 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000862 args.pop_front();
863 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
864 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
865 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
866 WithMotionClassification(MotionClassification::PINCH),
867 WithGesturePinchScaleFactor(1.0f, EPSILON),
868 WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000869 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000870
871 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
872 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000873 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000874 ASSERT_EQ(1u, args.size());
875 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
876 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
877 WithMotionClassification(MotionClassification::PINCH),
878 WithGesturePinchScaleFactor(1.2f, EPSILON),
879 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
880 WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000881 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000882
883 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
884 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000885 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000886 ASSERT_EQ(2u, args.size());
887 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
888 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
889 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
890 WithMotionClassification(MotionClassification::PINCH),
891 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +0000892 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000893 args.pop_front();
894 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
895 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
896 WithMotionClassification(MotionClassification::PINCH),
897 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +0000898 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000899}
900
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000901TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000902 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
903 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000904 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000905
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000906 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000907 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000908 std::list<NotifyArgs> args =
909 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000910
911 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000912 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000913 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000914
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000915 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000916 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000917 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000918
919 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000920 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000921 ASSERT_EQ(1u, args.size());
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000922 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
923 WithMotionClassification(MotionClassification::NONE));
924}
925
926TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
927 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
928 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000929 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000930
931 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
932 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000933 std::list<NotifyArgs> args =
934 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000935
936 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
937 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000938 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000939
940 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
941 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000942 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000943
944 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
945 // need to use another gesture type, like scroll.
946 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
947 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000948 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000949 ASSERT_FALSE(args.empty());
950 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000951}
952
Harry Cuttse9b71422023-03-14 16:54:44 +0000953TEST_F(GestureConverterTest, ResetWithButtonPressed) {
954 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
955 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000956 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000957
958 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
959 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
960 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000961 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +0000962
963 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
964 ASSERT_EQ(3u, args.size());
965
966 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
967 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
968 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
969 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
Josep del Riod0746382023-07-29 13:18:25 +0000970 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
971 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000972 args.pop_front();
973 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
974 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
975 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000976 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
977 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000978 args.pop_front();
979 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
980 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
Josep del Riod0746382023-07-29 13:18:25 +0000981 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
982 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +0000983}
984
985TEST_F(GestureConverterTest, ResetDuringScroll) {
986 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
987 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000988 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000989
990 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000991 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +0000992
993 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
994 ASSERT_EQ(1u, args.size());
995 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
996 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
997 WithCoords(POINTER_X, POINTER_Y - 10),
998 WithGestureScrollDistance(0, 0, EPSILON),
999 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -07001000 WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001001 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1002 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001003}
1004
1005TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1006 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1007 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001008 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001009
1010 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1011 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001012 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001013
1014 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
1015 ASSERT_EQ(3u, args.size());
1016 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1017 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1018 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1019 WithGestureOffset(0, 0, EPSILON),
1020 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001021 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1022 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001023 args.pop_front();
1024 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1025 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1026 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1027 WithGestureOffset(0, 0, EPSILON),
1028 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001029 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1030 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001031 args.pop_front();
1032 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1033 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1034 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +00001035 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1036 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001037}
1038
1039TEST_F(GestureConverterTest, ResetDuringPinch) {
1040 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1041 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001042 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001043
1044 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1045 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001046 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001047
1048 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
1049 ASSERT_EQ(2u, args.size());
1050 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1051 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1052 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1053 WithMotionClassification(MotionClassification::PINCH),
1054 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
Josep del Riod0746382023-07-29 13:18:25 +00001055 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001056 args.pop_front();
1057 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1058 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1059 WithMotionClassification(MotionClassification::PINCH),
1060 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
Josep del Riod0746382023-07-29 13:18:25 +00001061 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttse9b71422023-03-14 16:54:44 +00001062}
1063
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001064TEST_F(GestureConverterTest, FlingTapDown) {
1065 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1066 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001067 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001068
1069 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1070 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001071 std::list<NotifyArgs> args =
1072 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001073
1074 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1075 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1076 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001077 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1078 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001079
1080 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1081 ASSERT_TRUE(mFakePointerController->isPointerShown());
1082}
1083
Arpit Singha5ea7c12023-07-05 15:39:25 +00001084TEST_F(GestureConverterTest, Tap) {
1085 // Tap should produce button press/release events
1086 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1087 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001088 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001089
1090 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1091 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001092 std::list<NotifyArgs> args =
1093 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001094
1095 ASSERT_EQ(1u, args.size());
1096 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1097 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1098 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001099 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1100 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001101
1102 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1103 /* down= */ GESTURES_BUTTON_LEFT,
1104 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001105 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001106
1107 ASSERT_EQ(5u, args.size());
1108 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1109 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1110 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001111 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1112 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001113 args.pop_front();
1114 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1115 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1116 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1117 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1118 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1119 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001120 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001121 args.pop_front();
1122 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1123 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1124 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1125 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001126 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1127 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001128 args.pop_front();
1129 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1130 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1131 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001132 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001133 args.pop_front();
1134 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1135 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1136 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001137 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1138 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001139}
1140
1141TEST_F(GestureConverterTest, Click) {
1142 // Click should produce button press/release events
1143 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1144 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001145 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001146
1147 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1148 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001149 std::list<NotifyArgs> args =
1150 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001151
1152 ASSERT_EQ(1u, args.size());
1153 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1154 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1155 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001156 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1157 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001158
1159 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1160 /* down= */ GESTURES_BUTTON_LEFT,
1161 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001162 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001163
1164 ASSERT_EQ(2u, args.size());
1165 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1166 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1167 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001168 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1169 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001170 args.pop_front();
1171 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1172 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1173 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1174 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1175 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1176 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001177 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001178
1179 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1180 /* down= */ GESTURES_BUTTON_NONE,
1181 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001182 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001183
1184 ASSERT_EQ(3u, args.size());
1185 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1186 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1187 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1188 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001189 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1190 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001191 args.pop_front();
1192 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1193 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1194 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001195 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001196 args.pop_front();
1197 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1198 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1199 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001200 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1201 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001202}
1203
Arpit Singh3d84add2023-10-10 19:08:29 +00001204TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001205 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1206 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1207 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1208
Arpit Singha5ea7c12023-07-05 15:39:25 +00001209 // Tap should be ignored when disabled
1210 mReader->getContext()->setPreventingTouchpadTaps(true);
1211
1212 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1213 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001214 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001215
Arpit Singh82b27a02023-10-16 11:02:19 +00001216 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001217 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001218 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001219 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001220
1221 ASSERT_EQ(1u, args.size());
1222 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1223 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1224 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001225 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1226 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001227
Arpit Singh82b27a02023-10-16 11:02:19 +00001228 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001229 /* down= */ GESTURES_BUTTON_LEFT,
1230 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001231 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001232
1233 // no events should be generated
1234 ASSERT_EQ(0u, args.size());
1235
1236 // Future taps should be re-enabled
1237 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1238}
1239
Arpit Singh82b27a02023-10-16 11:02:19 +00001240TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1241 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1242 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1243
1244 // Tap should be ignored when disabled
1245 mReader->getContext()->setPreventingTouchpadTaps(true);
1246
1247 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1248 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1249 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1250
1251 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1252 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1253 std::list<NotifyArgs> args =
1254 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1255
1256 ASSERT_EQ(1u, args.size());
1257 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1258 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1259 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
1260 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1261 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1262
1263 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1264 /* down= */ GESTURES_BUTTON_LEFT,
1265 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1266 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1267
1268 // no events should be generated
1269 ASSERT_EQ(0u, args.size());
1270
1271 // Future taps should be re-enabled
1272 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1273
1274 // taps before the threshold should still be ignored
1275 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1276 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1277 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1278 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1279
1280 ASSERT_EQ(1u, args.size());
1281 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1282 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1283
1284 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1285 /* down= */ GESTURES_BUTTON_LEFT,
1286 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1287 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1288
1289 // no events should be generated
1290 ASSERT_EQ(0u, args.size());
1291
1292 // taps after the threshold should be recognised
1293 currentTime += 1;
1294 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1295 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1296 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1297
1298 ASSERT_EQ(1u, args.size());
1299 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1300 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1301
1302 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1303 /* down= */ GESTURES_BUTTON_LEFT,
1304 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1305 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1306
1307 ASSERT_EQ(5u, args.size());
1308 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1309 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
1310 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
1311 args.pop_front();
1312 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1313 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1314 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
1315 WithRelativeMotion(0.f, 0.f)));
1316 args.pop_front();
1317 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1318 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1319 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1320 WithRelativeMotion(0.f, 0.f)));
1321 args.pop_front();
1322 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1323 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
1324 WithButtonState(0)));
1325 args.pop_front();
1326 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1327 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0),
1328 WithButtonState(0)));
1329}
1330
Arpit Singh3d84add2023-10-10 19:08:29 +00001331TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1332 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001333 // Click should still produce button press/release events
1334 mReader->getContext()->setPreventingTouchpadTaps(true);
1335
1336 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1337 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001338 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001339
1340 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1341 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001342 std::list<NotifyArgs> args =
1343 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001344
1345 ASSERT_EQ(1u, args.size());
1346 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1347 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1348 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001349 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1350 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001351
1352 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1353 /* down= */ GESTURES_BUTTON_LEFT,
1354 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001355 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001356 ASSERT_EQ(2u, args.size());
1357
1358 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1359 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1360 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001361 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1362 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001363 args.pop_front();
1364 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1365 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1366 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1367 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1368 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1369 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001370 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001371
1372 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1373 /* down= */ GESTURES_BUTTON_NONE,
1374 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001375 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001376
1377 ASSERT_EQ(3u, args.size());
1378 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1379 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1380 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1381 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001382 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1383 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001384 args.pop_front();
1385 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1386 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1387 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001388 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001389 args.pop_front();
1390 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1391 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1392 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001393 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1394 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001395
1396 // Future taps should be re-enabled
1397 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1398}
1399
Arpit Singh3d84add2023-10-10 19:08:29 +00001400TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1401 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001402 // initially disable tap-to-click
1403 mReader->getContext()->setPreventingTouchpadTaps(true);
1404
1405 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1406 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001407 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001408
1409 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001410 std::list<NotifyArgs> args =
1411 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001412 ASSERT_EQ(1u, args.size());
1413
1414 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1415 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1416 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +00001417 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1418 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001419
1420 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
1421
1422 // Future taps should be re-enabled
1423 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1424}
1425
Arpit Singh33a10a62023-10-12 13:06:54 +00001426TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1427 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1428 const nsecs_t gestureStartTime = 1000;
1429 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1430 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1431 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1432
1433 // Start a move gesture at gestureStartTime
1434 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1435 std::list<NotifyArgs> args =
1436 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
1437 ASSERT_EQ(1u, args.size());
1438 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1439 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
1440
1441 // Key presses with IME connection should cancel ongoing move gesture
1442 nsecs_t currentTime = gestureStartTime + 100;
1443 mFakePolicy->setIsInputMethodConnectionActive(true);
1444 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1445 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1446 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1447 ASSERT_EQ(1u, args.size());
1448 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1449 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT));
1450
1451 // any updates in existing move gesture should be ignored
1452 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1453 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1454 ASSERT_EQ(0u, args.size());
1455
1456 // New gesture should not be affected
1457 currentTime += 100;
1458 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1459 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
1460 ASSERT_EQ(1u, args.size());
1461 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1462 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
1463}
1464
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001465// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1466// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001467class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1468protected:
1469 void SetUp() override {
1470 input_flags::enable_pointer_choreographer(true);
1471 GestureConverterTestBase::SetUp();
1472 }
1473};
1474
1475TEST_F(GestureConverterTestWithChoreographer, Move) {
1476 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1477 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1478 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1479
1480 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001481 std::list<NotifyArgs> args =
1482 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001483 ASSERT_EQ(1u, args.size());
1484
1485 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1486 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1487 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1488 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1489}
1490
1491TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1492 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1493 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1494 converter.setOrientation(ui::ROTATION_90);
1495 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1496
1497 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001498 std::list<NotifyArgs> args =
1499 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001500 ASSERT_EQ(1u, args.size());
1501
1502 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1503 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1504 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER), WithButtonState(0),
1505 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1506}
1507
1508TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1509 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1510 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1511 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1512
1513 // Press left and right buttons at once
1514 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1515 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1516 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001517 std::list<NotifyArgs> args =
1518 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001519 ASSERT_EQ(3u, args.size());
1520
1521 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1522 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1523 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1524 AMOTION_EVENT_BUTTON_SECONDARY),
1525 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1526 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1527 args.pop_front();
1528 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1529 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1530 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1531 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1532 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1533 args.pop_front();
1534 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1535 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1536 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1537 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1538 AMOTION_EVENT_BUTTON_SECONDARY),
1539 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1540 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1541
1542 // Then release the left button
1543 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1544 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1545 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001546 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001547 ASSERT_EQ(1u, args.size());
1548
1549 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1550 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1551 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1552 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1553 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1554
1555 // Finally release the right button
1556 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1557 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1558 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001559 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001560 ASSERT_EQ(3u, args.size());
1561
1562 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1563 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1564 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
1565 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1566 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1567 args.pop_front();
1568 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1569 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1570 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1571 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1572 args.pop_front();
1573 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1574 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1575 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1576 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1577}
1578
1579TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1580 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1581 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1582 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1583
1584 // Press the button
1585 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1586 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1587 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001588 std::list<NotifyArgs> args =
1589 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001590 ASSERT_EQ(2u, args.size());
1591
1592 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1593 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1594 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1595 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1596 args.pop_front();
1597 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1598 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1599 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1600 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1601 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1602
1603 // Move
1604 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001605 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001606 ASSERT_EQ(1u, args.size());
1607
1608 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1609 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1610 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1611 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1612 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1613
1614 // Release the button
1615 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1616 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1617 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001618 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001619 ASSERT_EQ(3u, args.size());
1620
1621 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1622 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1623 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1624 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1625 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1626 args.pop_front();
1627 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1628 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1629 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1630 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1631 args.pop_front();
1632 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1633 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1634 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1635 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1636}
1637
1638TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1639 const nsecs_t downTime = 12345;
1640 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1641 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1642 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1643
1644 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001645 std::list<NotifyArgs> args =
1646 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001647 ASSERT_EQ(2u, args.size());
1648
1649 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1650 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1651 WithGestureScrollDistance(0, 0, EPSILON),
1652 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1653 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1654 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1655 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1656 args.pop_front();
1657 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1658 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -10),
1659 WithGestureScrollDistance(0, 10, EPSILON),
1660 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1661 WithToolType(ToolType::FINGER),
1662 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1663 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1664
1665 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001666 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001667 ASSERT_EQ(1u, args.size());
1668 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1669 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1670 WithGestureScrollDistance(0, 5, EPSILON),
1671 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1672 WithToolType(ToolType::FINGER),
1673 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1674 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1675
1676 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1677 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001678 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001679 ASSERT_EQ(1u, args.size());
1680 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1681 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0 - 15),
1682 WithGestureScrollDistance(0, 0, EPSILON),
1683 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1684 WithToolType(ToolType::FINGER),
1685 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1686 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1687}
1688
1689TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1690 const nsecs_t downTime = 12345;
1691 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1692 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1693 converter.setOrientation(ui::ROTATION_90);
1694 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1695
1696 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001697 std::list<NotifyArgs> args =
1698 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001699 ASSERT_EQ(2u, args.size());
1700
1701 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1702 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1703 WithGestureScrollDistance(0, 0, EPSILON),
1704 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1705 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1706 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1707 args.pop_front();
1708 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1709 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-10, 0),
1710 WithGestureScrollDistance(0, 10, EPSILON),
1711 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1712 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1713
1714 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001715 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001716 ASSERT_EQ(1u, args.size());
1717 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1718 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1719 WithGestureScrollDistance(0, 5, EPSILON),
1720 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1721 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1722
1723 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1724 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001725 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001726 ASSERT_EQ(1u, args.size());
1727 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1728 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(-15, 0),
1729 WithGestureScrollDistance(0, 0, EPSILON),
1730 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1731 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1732}
1733
1734TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1735 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1736 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1737 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1738
1739 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001740 std::list<NotifyArgs> args =
1741 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001742
1743 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001744 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001745
1746 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1747 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001748 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001749
1750 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001751 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001752 ASSERT_EQ(1u, args.size());
1753 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1754 AllOf(WithMotionClassification(MotionClassification::NONE),
1755 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1756}
1757
1758TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1759 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1760 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1761 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1762
1763 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001764 std::list<NotifyArgs> args =
1765 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001766
1767 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001768 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001769
1770 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1771 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001772 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001773
1774 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1775 // need to use another gesture type, like pinch.
1776 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1777 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001778 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001779 ASSERT_FALSE(args.empty());
1780 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1781}
1782
1783TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1784 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1785 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1786 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1787
1788 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1789 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001790 std::list<NotifyArgs> args =
1791 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001792
1793 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001794 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001795
1796 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1797 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001798 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001799 ASSERT_EQ(1u, args.size());
1800 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1801 WithMotionClassification(MotionClassification::NONE));
1802}
1803
1804TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1805 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1806 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1807 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1808
1809 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1810 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001811 std::list<NotifyArgs> args =
1812 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001813
1814 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001815 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001816
1817 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1818 // need to use another gesture type, like pinch.
1819 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1820 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001821 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001822 ASSERT_FALSE(args.empty());
1823 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1824 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1825}
1826
1827TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1828 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1829 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1830 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1831 // only checks movement in one dimension.
1832 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1833 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1834 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1835
1836 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1837 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001838 std::list<NotifyArgs> args =
1839 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001840 ASSERT_EQ(4u, args.size());
1841
1842 // Three fake fingers should be created. We don't actually care where they are, so long as they
1843 // move appropriately.
1844 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1845 ASSERT_THAT(arg,
1846 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1847 WithGestureSwipeFingerCount(3),
1848 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1849 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1850 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1851 PointerCoords finger0Start = arg.pointerCoords[0];
1852 args.pop_front();
1853 arg = std::get<NotifyMotionArgs>(args.front());
1854 ASSERT_THAT(arg,
1855 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1856 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1857 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1858 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1859 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1860 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1861 PointerCoords finger1Start = arg.pointerCoords[1];
1862 args.pop_front();
1863 arg = std::get<NotifyMotionArgs>(args.front());
1864 ASSERT_THAT(arg,
1865 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1866 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1867 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1868 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1869 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1870 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1871 PointerCoords finger2Start = arg.pointerCoords[2];
1872 args.pop_front();
1873
1874 arg = std::get<NotifyMotionArgs>(args.front());
1875 ASSERT_THAT(arg,
1876 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1877 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
1878 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1879 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1880 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1881 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1882 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1883 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1884 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
1885 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
1886 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
1887
1888 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1889 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001890 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001891 ASSERT_EQ(1u, args.size());
1892 arg = std::get<NotifyMotionArgs>(args.front());
1893 ASSERT_THAT(arg,
1894 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1895 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
1896 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1897 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1898 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1899 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1900 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1901 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1902 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
1903 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
1904 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
1905
1906 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001907 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001908 ASSERT_EQ(3u, args.size());
1909 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1910 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1911 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1912 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1913 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1914 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1915 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1916 args.pop_front();
1917 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1918 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1919 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1920 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1921 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1922 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1923 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1924 args.pop_front();
1925 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1926 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1927 WithGestureSwipeFingerCount(3),
1928 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1929 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1930 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1931}
1932
1933TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
1934 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1935 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1936 converter.setOrientation(ui::ROTATION_90);
1937 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1938
1939 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1940 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001941 std::list<NotifyArgs> args =
1942 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001943 ASSERT_EQ(4u, args.size());
1944
1945 // Three fake fingers should be created. We don't actually care where they are, so long as they
1946 // move appropriately.
1947 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1948 ASSERT_THAT(arg,
1949 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1950 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1951 PointerCoords finger0Start = arg.pointerCoords[0];
1952 args.pop_front();
1953 arg = std::get<NotifyMotionArgs>(args.front());
1954 ASSERT_THAT(arg,
1955 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1956 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1957 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
1958 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1959 PointerCoords finger1Start = arg.pointerCoords[1];
1960 args.pop_front();
1961 arg = std::get<NotifyMotionArgs>(args.front());
1962 ASSERT_THAT(arg,
1963 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1964 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1965 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
1966 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1967 PointerCoords finger2Start = arg.pointerCoords[2];
1968 args.pop_front();
1969
1970 arg = std::get<NotifyMotionArgs>(args.front());
1971 ASSERT_THAT(arg,
1972 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1973 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
1974 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1975 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
1976 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
1977 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
1978 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1979 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1980 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1981
1982 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1983 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001984 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001985 ASSERT_EQ(1u, args.size());
1986 arg = std::get<NotifyMotionArgs>(args.front());
1987 ASSERT_THAT(arg,
1988 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1989 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
1990 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1991 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
1992 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
1993 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
1994 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1995 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1996 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1997
1998 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001999 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002000 ASSERT_EQ(3u, args.size());
2001 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2002 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2003 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2004 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2005 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2006 args.pop_front();
2007 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2008 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2009 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2010 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2011 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2012 args.pop_front();
2013 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2014 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
2015 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2016}
2017
2018TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2019 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2020 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2021 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2022
2023 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2024 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002025 std::list<NotifyArgs> args =
2026 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002027 ASSERT_EQ(5u, args.size());
2028
2029 // Four fake fingers should be created. We don't actually care where they are, so long as they
2030 // move appropriately.
2031 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2032 ASSERT_THAT(arg,
2033 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2034 WithGestureSwipeFingerCount(4),
2035 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2036 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2037 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2038 PointerCoords finger0Start = arg.pointerCoords[0];
2039 args.pop_front();
2040 arg = std::get<NotifyMotionArgs>(args.front());
2041 ASSERT_THAT(arg,
2042 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2043 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2044 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2045 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2046 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2047 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2048 PointerCoords finger1Start = arg.pointerCoords[1];
2049 args.pop_front();
2050 arg = std::get<NotifyMotionArgs>(args.front());
2051 ASSERT_THAT(arg,
2052 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2053 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2054 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2055 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2056 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2057 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2058 PointerCoords finger2Start = arg.pointerCoords[2];
2059 args.pop_front();
2060 arg = std::get<NotifyMotionArgs>(args.front());
2061 ASSERT_THAT(arg,
2062 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2063 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2064 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2065 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2066 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2067 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2068 PointerCoords finger3Start = arg.pointerCoords[3];
2069 args.pop_front();
2070
2071 arg = std::get<NotifyMotionArgs>(args.front());
2072 ASSERT_THAT(arg,
2073 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2074 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
2075 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2076 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2077 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2078 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2079 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2080 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2081 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2082 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2083 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2084 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2085 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2086
2087 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2088 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002089 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002090 ASSERT_EQ(1u, args.size());
2091 arg = std::get<NotifyMotionArgs>(args.front());
2092 ASSERT_THAT(arg,
2093 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2094 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2095 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2096 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2097 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2098 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2099 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2100 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2101 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2102 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2103 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2104 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2105 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2106
2107 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002108 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002109 ASSERT_EQ(4u, args.size());
2110 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2111 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2112 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2113 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2114 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2115 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2116 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2117 args.pop_front();
2118 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2119 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2120 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2121 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2122 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2123 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2124 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2125 args.pop_front();
2126 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2127 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2128 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2129 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2130 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2131 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2132 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2133 args.pop_front();
2134 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2135 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
2136 WithGestureSwipeFingerCount(4),
2137 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2138 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2139 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2140}
2141
2142TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2143 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2144 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2145 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2146
2147 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2148 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002149 std::list<NotifyArgs> args =
2150 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002151 ASSERT_EQ(2u, args.size());
2152 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2153 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2154 WithMotionClassification(MotionClassification::PINCH),
2155 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
2156 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2157 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2158 args.pop_front();
2159 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2160 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2161 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2162 WithMotionClassification(MotionClassification::PINCH),
2163 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
2164 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2165 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2166
2167 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2168 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002169 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002170 ASSERT_EQ(1u, args.size());
2171 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2172 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2173 WithMotionClassification(MotionClassification::PINCH),
2174 WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, -80, 0),
2175 WithPointerCoords(1, 80, 0), WithPointerCount(2u),
2176 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2177
2178 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2179 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002180 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002181 ASSERT_EQ(2u, args.size());
2182 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2183 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2184 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2185 WithMotionClassification(MotionClassification::PINCH),
2186 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2187 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2188 args.pop_front();
2189 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2190 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2191 WithMotionClassification(MotionClassification::PINCH),
2192 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2193 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2194}
2195
2196TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2197 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2198 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2199 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2200
2201 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2202 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002203 std::list<NotifyArgs> args =
2204 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002205 ASSERT_EQ(2u, args.size());
2206 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2207 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2208 WithMotionClassification(MotionClassification::PINCH),
2209 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
2210 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2211 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2212 args.pop_front();
2213 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2214 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2215 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2216 WithMotionClassification(MotionClassification::PINCH),
2217 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
2218 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2219 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2220
2221 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2222 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002223 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002224 ASSERT_EQ(1u, args.size());
2225 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2226 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2227 WithMotionClassification(MotionClassification::PINCH),
2228 WithGesturePinchScaleFactor(1.1f, EPSILON), WithPointerCoords(0, -110, 0),
2229 WithPointerCoords(1, 110, 0), WithPointerCount(2u),
2230 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2231
2232 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2233 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002234 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002235 ASSERT_EQ(2u, args.size());
2236 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2237 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2238 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2239 WithMotionClassification(MotionClassification::PINCH),
2240 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2241 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2242 args.pop_front();
2243 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2244 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2245 WithMotionClassification(MotionClassification::PINCH),
2246 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2247 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2248}
2249
2250TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2251 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2252 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2253 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2254
2255 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2256 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002257 std::list<NotifyArgs> args =
2258 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002259
2260 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2261 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002262 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002263
2264 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2265 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002266 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002267
2268 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002269 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002270 ASSERT_EQ(1u, args.size());
2271 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2272 WithMotionClassification(MotionClassification::NONE));
2273}
2274
2275TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2276 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2277 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2278 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2279
2280 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2281 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002282 std::list<NotifyArgs> args =
2283 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002284
2285 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2286 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002287 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002288
2289 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2290 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002291 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002292
2293 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2294 // need to use another gesture type, like scroll.
2295 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2296 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002297 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002298 ASSERT_FALSE(args.empty());
2299 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2300}
2301
2302TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2303 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2304 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2305 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2306
2307 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2308 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2309 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002310 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002311
2312 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2313 ASSERT_EQ(3u, args.size());
2314
2315 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2316 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2317 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2318 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
2319 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2320 args.pop_front();
2321 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2322 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2323 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
2324 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2325 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2326 args.pop_front();
2327 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2328 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
2329 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2330 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2331}
2332
2333TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2334 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2335 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2336 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2337
2338 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002339 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002340
2341 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2342 ASSERT_EQ(1u, args.size());
2343 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2344 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, -10),
2345 WithGestureScrollDistance(0, 0, EPSILON),
2346 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
2347 WithToolType(ToolType::FINGER),
2348 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2349 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2350}
2351
2352TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2353 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2354 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2355 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2356
2357 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2358 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002359 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002360
2361 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2362 ASSERT_EQ(3u, args.size());
2363 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2364 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2365 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2366 WithGestureOffset(0, 0, EPSILON),
2367 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2368 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2369 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2370 args.pop_front();
2371 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2372 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2373 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2374 WithGestureOffset(0, 0, EPSILON),
2375 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2376 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2377 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2378 args.pop_front();
2379 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2380 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
2381 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2382 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2383 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2384}
2385
2386TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2387 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2388 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2389 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2390
2391 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2392 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002393 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002394
2395 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2396 ASSERT_EQ(2u, args.size());
2397 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2398 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2399 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2400 WithMotionClassification(MotionClassification::PINCH),
2401 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2402 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2403 args.pop_front();
2404 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2405 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2406 WithMotionClassification(MotionClassification::PINCH),
2407 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2408 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2409}
2410
2411TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2412 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2413 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2414 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2415
2416 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2417 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002418 std::list<NotifyArgs> args =
2419 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002420
2421 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2422 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2423 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2424 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2425}
2426
2427TEST_F(GestureConverterTestWithChoreographer, Tap) {
2428 // Tap should produce button press/release events
2429 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2430 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2431 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2432
2433 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2434 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002435 std::list<NotifyArgs> args =
2436 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002437
2438 ASSERT_EQ(1u, args.size());
2439 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2440 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2441 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2442 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2443
2444 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2445 /* down= */ GESTURES_BUTTON_LEFT,
2446 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002447 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002448
2449 ASSERT_EQ(5u, args.size());
2450 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2451 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2452 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2453 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2454 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2455 args.pop_front();
2456 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2457 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2458 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2459 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2460 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2461 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2462 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2463 args.pop_front();
2464 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2465 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2466 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2467 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2468 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2469 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2470 args.pop_front();
2471 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2472 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2473 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2474 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2475 args.pop_front();
2476 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2477 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2478 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2479 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2480}
2481
2482TEST_F(GestureConverterTestWithChoreographer, Click) {
2483 // Click should produce button press/release events
2484 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2485 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2486 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2487
2488 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2489 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002490 std::list<NotifyArgs> args =
2491 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002492
2493 ASSERT_EQ(1u, args.size());
2494 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2495 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2496 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2497 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2498
2499 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2500 /* down= */ GESTURES_BUTTON_LEFT,
2501 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002502 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002503
2504 ASSERT_EQ(2u, args.size());
2505 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2506 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2507 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2508 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2509 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2510 args.pop_front();
2511 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2512 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2513 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2514 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2515 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2516 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2517 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2518
2519 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2520 /* down= */ GESTURES_BUTTON_NONE,
2521 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002522 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002523
2524 ASSERT_EQ(3u, args.size());
2525 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2526 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2527 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2528 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2529 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2530 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2531 args.pop_front();
2532 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2533 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2534 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2535 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2536 args.pop_front();
2537 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2538 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2539 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2540 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2541}
2542
2543TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002544 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2545 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2546 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2547
Byoungho Jungee6268f2023-10-30 17:27:26 +09002548 // Tap should be ignored when disabled
2549 mReader->getContext()->setPreventingTouchpadTaps(true);
2550
2551 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2552 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2553 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2554
Arpit Singh82b27a02023-10-16 11:02:19 +00002555 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002556 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002557 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002558 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002559
2560 ASSERT_EQ(1u, args.size());
2561 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2562 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2563 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2564 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002565
Arpit Singh82b27a02023-10-16 11:02:19 +00002566 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002567 /* down= */ GESTURES_BUTTON_LEFT,
2568 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002569 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002570
2571 // no events should be generated
2572 ASSERT_EQ(0u, args.size());
2573
2574 // Future taps should be re-enabled
2575 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2576}
2577
Arpit Singh82b27a02023-10-16 11:02:19 +00002578TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2579 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2580 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2581
2582 // Tap should be ignored when disabled
2583 mReader->getContext()->setPreventingTouchpadTaps(true);
2584
2585 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2586 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2587 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2588
2589 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2590 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2591 std::list<NotifyArgs> args =
2592 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2593
2594 ASSERT_EQ(1u, args.size());
2595 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2596 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2597 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2598 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2599
2600 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2601 /* down= */ GESTURES_BUTTON_LEFT,
2602 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2603 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2604
2605 // no events should be generated
2606 ASSERT_EQ(0u, args.size());
2607
2608 // Future taps should be re-enabled
2609 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2610
2611 // taps before the threshold should still be ignored
2612 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2613 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2614 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2615 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2616
2617 ASSERT_EQ(1u, args.size());
2618 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2619 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2620
2621 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2622 /* down= */ GESTURES_BUTTON_LEFT,
2623 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2624 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2625
2626 // no events should be generated
2627 ASSERT_EQ(0u, args.size());
2628
2629 // taps after the threshold should be recognised
2630 currentTime += 1;
2631 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2632 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2633 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2634
2635 ASSERT_EQ(1u, args.size());
2636 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2637 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2638
2639 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2640 /* down= */ GESTURES_BUTTON_LEFT,
2641 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2642 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2643
2644 ASSERT_EQ(5u, args.size());
2645 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2646 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
2647 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
2648 args.pop_front();
2649 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2650 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2651 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
2652 WithRelativeMotion(0.f, 0.f)));
2653 args.pop_front();
2654 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2655 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2656 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2657 WithRelativeMotion(0.f, 0.f)));
2658 args.pop_front();
2659 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2660 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
2661 WithButtonState(0)));
2662 args.pop_front();
2663 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2664 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0),
2665 WithButtonState(0)));
2666}
2667
Byoungho Jungee6268f2023-10-30 17:27:26 +09002668TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2669 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2670 // Click should still produce button press/release events
2671 mReader->getContext()->setPreventingTouchpadTaps(true);
2672
2673 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2674 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2675 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2676
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);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002681
2682 ASSERT_EQ(1u, args.size());
2683 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2684 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2685 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2686 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2687
2688 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2689 /* down= */ GESTURES_BUTTON_LEFT,
2690 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002691 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002692 ASSERT_EQ(2u, args.size());
2693
2694 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2695 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2696 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2697 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2698 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2699 args.pop_front();
2700 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2701 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2702 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2703 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2704 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2705 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2706 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2707
2708 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2709 /* down= */ GESTURES_BUTTON_NONE,
2710 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002711 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002712
2713 ASSERT_EQ(3u, args.size());
2714 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2715 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2716 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2717 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2718 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2719 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2720 args.pop_front();
2721 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2722 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2723 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2724 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2725 args.pop_front();
2726 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2727 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2728 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2729 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2730
2731 // Future taps should be re-enabled
2732 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2733}
2734
2735TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2736 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2737 // initially disable tap-to-click
2738 mReader->getContext()->setPreventingTouchpadTaps(true);
2739
2740 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2741 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2742 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2743
2744 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002745 std::list<NotifyArgs> args =
2746 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002747 ASSERT_EQ(1u, args.size());
2748
2749 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2750 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2751 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
2752 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2753
2754 // Future taps should be re-enabled
2755 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2756}
2757
Arpit Singh33a10a62023-10-12 13:06:54 +00002758TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
2759 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2760 const nsecs_t gestureStartTime = 1000;
2761 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2762 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2763 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2764
2765 // Start a move gesture at gestureStartTime
2766 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
2767 std::list<NotifyArgs> args =
2768 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
2769 ASSERT_EQ(1u, args.size());
2770 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2771 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
2772
2773 // Key presses with IME connection should cancel ongoing move gesture
2774 nsecs_t currentTime = gestureStartTime + 100;
2775 mFakePolicy->setIsInputMethodConnectionActive(true);
2776 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
2777 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2778 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2779 ASSERT_EQ(1u, args.size());
2780 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2781 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT));
2782
2783 // any updates in existing move gesture should be ignored
2784 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2785 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2786 ASSERT_EQ(0u, args.size());
2787
2788 // New gesture should not be affected
2789 currentTime += 100;
2790 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2791 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
2792 ASSERT_EQ(1u, args.size());
2793 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2794 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
2795}
2796
Harry Cutts4fb941a2022-12-14 19:14:04 +00002797} // namespace android