blob: a80bbfd0ff0da6e93c3bb7cdb7b52550ea3f218f [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,
1205 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001206 // Tap should be ignored when disabled
1207 mReader->getContext()->setPreventingTouchpadTaps(true);
1208
1209 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1210 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001211 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001212
1213 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1214 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001215 std::list<NotifyArgs> args =
1216 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001217
1218 ASSERT_EQ(1u, args.size());
1219 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1220 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1221 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001222 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1223 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001224 args.pop_front();
1225
1226 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1227 /* down= */ GESTURES_BUTTON_LEFT,
1228 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001229 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001230
1231 // no events should be generated
1232 ASSERT_EQ(0u, args.size());
1233
1234 // Future taps should be re-enabled
1235 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1236}
1237
Arpit Singh3d84add2023-10-10 19:08:29 +00001238TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1239 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001240 // Click should still produce button press/release events
1241 mReader->getContext()->setPreventingTouchpadTaps(true);
1242
1243 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1244 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001245 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001246
1247 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1248 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001249 std::list<NotifyArgs> args =
1250 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001251
1252 ASSERT_EQ(1u, args.size());
1253 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1254 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1255 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001256 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1257 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001258
1259 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1260 /* down= */ GESTURES_BUTTON_LEFT,
1261 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001262 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001263 ASSERT_EQ(2u, args.size());
1264
1265 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1266 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
1267 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001268 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1269 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001270 args.pop_front();
1271 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1272 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1273 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1274 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1275 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
1276 WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Josep del Riod0746382023-07-29 13:18:25 +00001277 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001278
1279 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1280 /* down= */ GESTURES_BUTTON_NONE,
1281 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001282 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001283
1284 ASSERT_EQ(3u, args.size());
1285 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1286 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1287 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1288 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001289 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
1290 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001291 args.pop_front();
1292 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1293 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(POINTER_X, POINTER_Y),
1294 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Josep del Riod0746382023-07-29 13:18:25 +00001295 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001296 args.pop_front();
1297 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1298 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1299 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
Josep del Riod0746382023-07-29 13:18:25 +00001300 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1301 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001302
1303 // Future taps should be re-enabled
1304 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1305}
1306
Arpit Singh3d84add2023-10-10 19:08:29 +00001307TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1308 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001309 // initially disable tap-to-click
1310 mReader->getContext()->setPreventingTouchpadTaps(true);
1311
1312 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1313 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001314 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001315
1316 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001317 std::list<NotifyArgs> args =
1318 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001319 ASSERT_EQ(1u, args.size());
1320
1321 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1322 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1323 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
Josep del Riod0746382023-07-29 13:18:25 +00001324 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1325 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001326
1327 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
1328
1329 // Future taps should be re-enabled
1330 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1331}
1332
Arpit Singh33a10a62023-10-12 13:06:54 +00001333TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1334 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1335 const nsecs_t gestureStartTime = 1000;
1336 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1337 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1338 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1339
1340 // Start a move gesture at gestureStartTime
1341 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1342 std::list<NotifyArgs> args =
1343 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
1344 ASSERT_EQ(1u, args.size());
1345 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1346 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
1347
1348 // Key presses with IME connection should cancel ongoing move gesture
1349 nsecs_t currentTime = gestureStartTime + 100;
1350 mFakePolicy->setIsInputMethodConnectionActive(true);
1351 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1352 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1353 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1354 ASSERT_EQ(1u, args.size());
1355 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1356 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT));
1357
1358 // any updates in existing move gesture should be ignored
1359 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1360 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1361 ASSERT_EQ(0u, args.size());
1362
1363 // New gesture should not be affected
1364 currentTime += 100;
1365 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1366 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
1367 ASSERT_EQ(1u, args.size());
1368 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1369 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
1370}
1371
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001372// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1373// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001374class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1375protected:
1376 void SetUp() override {
1377 input_flags::enable_pointer_choreographer(true);
1378 GestureConverterTestBase::SetUp();
1379 }
1380};
1381
1382TEST_F(GestureConverterTestWithChoreographer, Move) {
1383 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1384 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1385 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1386
1387 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001388 std::list<NotifyArgs> args =
1389 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001390 ASSERT_EQ(1u, args.size());
1391
1392 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1393 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1394 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1395 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1396}
1397
1398TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1399 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1400 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1401 converter.setOrientation(ui::ROTATION_90);
1402 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1403
1404 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001405 std::list<NotifyArgs> args =
1406 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001407 ASSERT_EQ(1u, args.size());
1408
1409 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1410 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1411 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER), WithButtonState(0),
1412 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1413}
1414
1415TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1416 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1417 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1418 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1419
1420 // Press left and right buttons at once
1421 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1422 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1423 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001424 std::list<NotifyArgs> args =
1425 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001426 ASSERT_EQ(3u, args.size());
1427
1428 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1429 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1430 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1431 AMOTION_EVENT_BUTTON_SECONDARY),
1432 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1433 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1434 args.pop_front();
1435 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1436 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1437 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1438 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1439 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1440 args.pop_front();
1441 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1442 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1443 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1444 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1445 AMOTION_EVENT_BUTTON_SECONDARY),
1446 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1447 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1448
1449 // Then release the left button
1450 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1451 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1452 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001453 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001454 ASSERT_EQ(1u, args.size());
1455
1456 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1457 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1458 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1459 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1460 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1461
1462 // Finally release the right button
1463 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1464 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1465 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001466 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001467 ASSERT_EQ(3u, args.size());
1468
1469 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1470 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1471 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
1472 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1473 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1474 args.pop_front();
1475 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1476 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1477 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1478 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1479 args.pop_front();
1480 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1481 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1482 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1483 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1484}
1485
1486TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1487 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1488 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1489 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1490
1491 // Press the button
1492 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1493 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1494 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001495 std::list<NotifyArgs> args =
1496 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001497 ASSERT_EQ(2u, args.size());
1498
1499 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1500 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1501 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1502 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1503 args.pop_front();
1504 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1505 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1506 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1507 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
1508 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1509
1510 // Move
1511 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001512 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001513 ASSERT_EQ(1u, args.size());
1514
1515 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1516 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1517 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1518 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1519 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1520
1521 // Release the button
1522 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1523 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1524 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001525 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001526 ASSERT_EQ(3u, args.size());
1527
1528 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1529 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1530 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1531 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1532 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1533 args.pop_front();
1534 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1535 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
1536 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1537 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1538 args.pop_front();
1539 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1540 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithButtonState(0),
1541 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1542 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1543}
1544
1545TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1546 const nsecs_t downTime = 12345;
1547 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1548 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1549 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1550
1551 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001552 std::list<NotifyArgs> args =
1553 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001554 ASSERT_EQ(2u, args.size());
1555
1556 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1557 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1558 WithGestureScrollDistance(0, 0, EPSILON),
1559 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1560 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1561 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1562 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1563 args.pop_front();
1564 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1565 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -10),
1566 WithGestureScrollDistance(0, 10, EPSILON),
1567 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1568 WithToolType(ToolType::FINGER),
1569 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1570 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1571
1572 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001573 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001574 ASSERT_EQ(1u, args.size());
1575 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1576 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1577 WithGestureScrollDistance(0, 5, EPSILON),
1578 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1579 WithToolType(ToolType::FINGER),
1580 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1581 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1582
1583 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1584 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001585 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001586 ASSERT_EQ(1u, args.size());
1587 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1588 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0 - 15),
1589 WithGestureScrollDistance(0, 0, EPSILON),
1590 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1591 WithToolType(ToolType::FINGER),
1592 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1593 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1594}
1595
1596TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1597 const nsecs_t downTime = 12345;
1598 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1599 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1600 converter.setOrientation(ui::ROTATION_90);
1601 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1602
1603 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001604 std::list<NotifyArgs> args =
1605 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001606 ASSERT_EQ(2u, args.size());
1607
1608 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1609 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
1610 WithGestureScrollDistance(0, 0, EPSILON),
1611 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1612 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1613 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1614 args.pop_front();
1615 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1616 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-10, 0),
1617 WithGestureScrollDistance(0, 10, EPSILON),
1618 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1619 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1620
1621 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001622 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001623 ASSERT_EQ(1u, args.size());
1624 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1625 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1626 WithGestureScrollDistance(0, 5, EPSILON),
1627 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1628 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1629
1630 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1631 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001632 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001633 ASSERT_EQ(1u, args.size());
1634 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1635 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(-15, 0),
1636 WithGestureScrollDistance(0, 0, EPSILON),
1637 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1638 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1639}
1640
1641TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1642 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1643 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1644 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1645
1646 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001647 std::list<NotifyArgs> args =
1648 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001649
1650 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001651 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001652
1653 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1654 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001655 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001656
1657 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001658 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001659 ASSERT_EQ(1u, args.size());
1660 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1661 AllOf(WithMotionClassification(MotionClassification::NONE),
1662 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1663}
1664
1665TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1666 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1667 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1668 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1669
1670 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001671 std::list<NotifyArgs> args =
1672 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001673
1674 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001675 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001676
1677 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1678 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001679 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001680
1681 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1682 // need to use another gesture type, like pinch.
1683 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1684 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001685 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001686 ASSERT_FALSE(args.empty());
1687 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1688}
1689
1690TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1691 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1692 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1693 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1694
1695 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1696 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001697 std::list<NotifyArgs> args =
1698 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001699
1700 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001701 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001702
1703 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1704 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001705 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001706 ASSERT_EQ(1u, args.size());
1707 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1708 WithMotionClassification(MotionClassification::NONE));
1709}
1710
1711TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1712 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1713 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1714 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1715
1716 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1717 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001718 std::list<NotifyArgs> args =
1719 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001720
1721 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001722 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001723
1724 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1725 // need to use another gesture type, like pinch.
1726 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1727 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001728 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001729 ASSERT_FALSE(args.empty());
1730 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1731 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1732}
1733
1734TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1735 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1736 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1737 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1738 // only checks movement in one dimension.
1739 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1740 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1741 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1742
1743 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1744 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001745 std::list<NotifyArgs> args =
1746 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001747 ASSERT_EQ(4u, args.size());
1748
1749 // Three fake fingers should be created. We don't actually care where they are, so long as they
1750 // move appropriately.
1751 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1752 ASSERT_THAT(arg,
1753 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1754 WithGestureSwipeFingerCount(3),
1755 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1756 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1757 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1758 PointerCoords finger0Start = arg.pointerCoords[0];
1759 args.pop_front();
1760 arg = std::get<NotifyMotionArgs>(args.front());
1761 ASSERT_THAT(arg,
1762 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1763 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1764 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1765 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1766 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1767 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1768 PointerCoords finger1Start = arg.pointerCoords[1];
1769 args.pop_front();
1770 arg = std::get<NotifyMotionArgs>(args.front());
1771 ASSERT_THAT(arg,
1772 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1773 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1774 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1775 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1776 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1777 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1778 PointerCoords finger2Start = arg.pointerCoords[2];
1779 args.pop_front();
1780
1781 arg = std::get<NotifyMotionArgs>(args.front());
1782 ASSERT_THAT(arg,
1783 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1784 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
1785 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1786 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1787 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1788 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1789 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1790 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1791 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
1792 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
1793 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
1794
1795 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1796 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001797 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001798 ASSERT_EQ(1u, args.size());
1799 arg = std::get<NotifyMotionArgs>(args.front());
1800 ASSERT_THAT(arg,
1801 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1802 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
1803 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1804 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1805 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1806 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1807 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1808 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1809 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
1810 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
1811 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
1812
1813 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001814 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001815 ASSERT_EQ(3u, args.size());
1816 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1817 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1818 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1819 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1820 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1821 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1822 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1823 args.pop_front();
1824 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1825 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1826 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1827 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1828 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1829 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1830 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1831 args.pop_front();
1832 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1833 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1834 WithGestureSwipeFingerCount(3),
1835 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1836 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1837 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1838}
1839
1840TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
1841 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1842 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1843 converter.setOrientation(ui::ROTATION_90);
1844 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1845
1846 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1847 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001848 std::list<NotifyArgs> args =
1849 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001850 ASSERT_EQ(4u, args.size());
1851
1852 // Three fake fingers should be created. We don't actually care where they are, so long as they
1853 // move appropriately.
1854 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1855 ASSERT_THAT(arg,
1856 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1857 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1858 PointerCoords finger0Start = arg.pointerCoords[0];
1859 args.pop_front();
1860 arg = std::get<NotifyMotionArgs>(args.front());
1861 ASSERT_THAT(arg,
1862 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1863 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1864 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
1865 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1866 PointerCoords finger1Start = arg.pointerCoords[1];
1867 args.pop_front();
1868 arg = std::get<NotifyMotionArgs>(args.front());
1869 ASSERT_THAT(arg,
1870 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1871 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1872 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
1873 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1874 PointerCoords finger2Start = arg.pointerCoords[2];
1875 args.pop_front();
1876
1877 arg = std::get<NotifyMotionArgs>(args.front());
1878 ASSERT_THAT(arg,
1879 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1880 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
1881 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1882 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
1883 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
1884 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
1885 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1886 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1887 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1888
1889 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1890 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001891 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001892 ASSERT_EQ(1u, args.size());
1893 arg = std::get<NotifyMotionArgs>(args.front());
1894 ASSERT_THAT(arg,
1895 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1896 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
1897 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1898 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
1899 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
1900 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
1901 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1902 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1903 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1904
1905 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001906 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001907 ASSERT_EQ(3u, args.size());
1908 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1909 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1910 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1911 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
1912 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1913 args.pop_front();
1914 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1915 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
1916 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1917 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
1918 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1919 args.pop_front();
1920 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1921 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
1922 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
1923}
1924
1925TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
1926 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1927 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1928 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1929
1930 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1931 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001932 std::list<NotifyArgs> args =
1933 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001934 ASSERT_EQ(5u, args.size());
1935
1936 // Four fake fingers should be created. We don't actually care where they are, so long as they
1937 // move appropriately.
1938 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1939 ASSERT_THAT(arg,
1940 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1941 WithGestureSwipeFingerCount(4),
1942 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1943 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1944 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1945 PointerCoords finger0Start = arg.pointerCoords[0];
1946 args.pop_front();
1947 arg = std::get<NotifyMotionArgs>(args.front());
1948 ASSERT_THAT(arg,
1949 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1950 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1951 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1952 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1953 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1954 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1955 PointerCoords finger1Start = arg.pointerCoords[1];
1956 args.pop_front();
1957 arg = std::get<NotifyMotionArgs>(args.front());
1958 ASSERT_THAT(arg,
1959 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1960 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1961 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1962 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1963 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1964 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1965 PointerCoords finger2Start = arg.pointerCoords[2];
1966 args.pop_front();
1967 arg = std::get<NotifyMotionArgs>(args.front());
1968 ASSERT_THAT(arg,
1969 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1970 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1971 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
1972 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1973 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1974 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1975 PointerCoords finger3Start = arg.pointerCoords[3];
1976 args.pop_front();
1977
1978 arg = std::get<NotifyMotionArgs>(args.front());
1979 ASSERT_THAT(arg,
1980 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1981 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
1982 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1983 WithPointerCount(4u), WithToolType(ToolType::FINGER),
1984 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1985 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
1986 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
1987 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
1988 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
1989 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
1990 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
1991 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
1992 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
1993
1994 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1995 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001996 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001997 ASSERT_EQ(1u, args.size());
1998 arg = std::get<NotifyMotionArgs>(args.front());
1999 ASSERT_THAT(arg,
2000 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2001 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2002 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2003 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2004 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2005 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2006 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2007 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2008 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2009 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2010 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2011 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2012 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2013
2014 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002015 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002016 ASSERT_EQ(4u, args.size());
2017 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2018 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2019 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2020 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2021 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2022 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2023 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2024 args.pop_front();
2025 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2026 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2027 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2028 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2029 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2030 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2031 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2032 args.pop_front();
2033 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2034 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2035 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2036 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2037 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2038 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2039 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2040 args.pop_front();
2041 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2042 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
2043 WithGestureSwipeFingerCount(4),
2044 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2045 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2046 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2047}
2048
2049TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2050 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2051 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2052 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2053
2054 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2055 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002056 std::list<NotifyArgs> args =
2057 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002058 ASSERT_EQ(2u, args.size());
2059 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2060 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2061 WithMotionClassification(MotionClassification::PINCH),
2062 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
2063 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2064 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2065 args.pop_front();
2066 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2067 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2068 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2069 WithMotionClassification(MotionClassification::PINCH),
2070 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
2071 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2072 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2073
2074 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2075 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002076 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002077 ASSERT_EQ(1u, args.size());
2078 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2079 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2080 WithMotionClassification(MotionClassification::PINCH),
2081 WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, -80, 0),
2082 WithPointerCoords(1, 80, 0), WithPointerCount(2u),
2083 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2084
2085 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2086 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002087 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002088 ASSERT_EQ(2u, args.size());
2089 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2090 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2091 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2092 WithMotionClassification(MotionClassification::PINCH),
2093 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2094 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2095 args.pop_front();
2096 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2097 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2098 WithMotionClassification(MotionClassification::PINCH),
2099 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2100 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2101}
2102
2103TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2104 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2105 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2106 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2107
2108 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2109 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002110 std::list<NotifyArgs> args =
2111 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002112 ASSERT_EQ(2u, args.size());
2113 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2114 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2115 WithMotionClassification(MotionClassification::PINCH),
2116 WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(-100, 0),
2117 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2118 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2119 args.pop_front();
2120 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2121 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2122 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2123 WithMotionClassification(MotionClassification::PINCH),
2124 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, 100, 0),
2125 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2126 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2127
2128 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2129 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002130 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002131 ASSERT_EQ(1u, args.size());
2132 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2133 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2134 WithMotionClassification(MotionClassification::PINCH),
2135 WithGesturePinchScaleFactor(1.1f, EPSILON), WithPointerCoords(0, -110, 0),
2136 WithPointerCoords(1, 110, 0), WithPointerCount(2u),
2137 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2138
2139 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2140 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002141 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002142 ASSERT_EQ(2u, args.size());
2143 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2144 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2145 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2146 WithMotionClassification(MotionClassification::PINCH),
2147 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2148 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2149 args.pop_front();
2150 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2151 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2152 WithMotionClassification(MotionClassification::PINCH),
2153 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2154 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2155}
2156
2157TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2158 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2159 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2160 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2161
2162 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2163 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002164 std::list<NotifyArgs> args =
2165 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002166
2167 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2168 /*dz=*/1.2, 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
2171 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2172 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002173 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002174
2175 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002176 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002177 ASSERT_EQ(1u, args.size());
2178 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2179 WithMotionClassification(MotionClassification::NONE));
2180}
2181
2182TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2183 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2184 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2185 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2186
2187 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2188 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002189 std::list<NotifyArgs> args =
2190 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002191
2192 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2193 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002194 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002195
2196 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2197 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002198 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002199
2200 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2201 // need to use another gesture type, like scroll.
2202 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2203 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002204 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002205 ASSERT_FALSE(args.empty());
2206 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2207}
2208
2209TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2210 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2211 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2212 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2213
2214 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2215 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2216 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002217 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002218
2219 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2220 ASSERT_EQ(3u, args.size());
2221
2222 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2223 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2224 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2225 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
2226 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2227 args.pop_front();
2228 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2229 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2230 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0),
2231 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2232 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2233 args.pop_front();
2234 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2235 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0),
2236 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2237 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2238}
2239
2240TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2241 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2242 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2243 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2244
2245 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002246 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002247
2248 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2249 ASSERT_EQ(1u, args.size());
2250 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2251 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, -10),
2252 WithGestureScrollDistance(0, 0, EPSILON),
2253 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
2254 WithToolType(ToolType::FINGER),
2255 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2256 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2257}
2258
2259TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2260 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2261 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2262 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2263
2264 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2265 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002266 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002267
2268 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2269 ASSERT_EQ(3u, args.size());
2270 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2271 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2272 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2273 WithGestureOffset(0, 0, EPSILON),
2274 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2275 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2276 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2277 args.pop_front();
2278 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2279 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2280 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2281 WithGestureOffset(0, 0, EPSILON),
2282 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2283 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2284 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2285 args.pop_front();
2286 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2287 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON),
2288 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2289 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2290 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2291}
2292
2293TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2294 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2295 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2296 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2297
2298 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2299 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002300 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002301
2302 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
2303 ASSERT_EQ(2u, args.size());
2304 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2305 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP |
2306 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2307 WithMotionClassification(MotionClassification::PINCH),
2308 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u),
2309 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2310 args.pop_front();
2311 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
2312 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2313 WithMotionClassification(MotionClassification::PINCH),
2314 WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u),
2315 WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2316}
2317
2318TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2319 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2320 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2321 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2322
2323 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2324 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002325 std::list<NotifyArgs> args =
2326 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002327
2328 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2329 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2330 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2331 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2332}
2333
2334TEST_F(GestureConverterTestWithChoreographer, Tap) {
2335 // Tap should produce button press/release events
2336 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2337 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2338 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2339
2340 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2341 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002342 std::list<NotifyArgs> args =
2343 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002344
2345 ASSERT_EQ(1u, args.size());
2346 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2347 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2348 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2349 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2350
2351 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2352 /* down= */ GESTURES_BUTTON_LEFT,
2353 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002354 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002355
2356 ASSERT_EQ(5u, args.size());
2357 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2358 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2359 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2360 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2361 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2362 args.pop_front();
2363 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2364 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2365 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2366 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2367 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2368 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2369 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2370 args.pop_front();
2371 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2372 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2373 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2374 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2375 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2376 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2377 args.pop_front();
2378 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2379 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2380 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2381 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2382 args.pop_front();
2383 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2384 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2385 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2386 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2387}
2388
2389TEST_F(GestureConverterTestWithChoreographer, Click) {
2390 // Click should produce button press/release events
2391 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2392 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2393 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2394
2395 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2396 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002397 std::list<NotifyArgs> args =
2398 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002399
2400 ASSERT_EQ(1u, args.size());
2401 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2402 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2403 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2404 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2405
2406 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2407 /* down= */ GESTURES_BUTTON_LEFT,
2408 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002409 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002410
2411 ASSERT_EQ(2u, args.size());
2412 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2413 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2414 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2415 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2416 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2417 args.pop_front();
2418 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2419 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2420 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2421 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2422 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2423 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2424 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2425
2426 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2427 /* down= */ GESTURES_BUTTON_NONE,
2428 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002429 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002430
2431 ASSERT_EQ(3u, args.size());
2432 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2433 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2434 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2435 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2436 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2437 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2438 args.pop_front();
2439 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2440 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2441 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2442 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2443 args.pop_front();
2444 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2445 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2446 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2447 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2448}
2449
2450TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
2451 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2452 // Tap should be ignored when disabled
2453 mReader->getContext()->setPreventingTouchpadTaps(true);
2454
2455 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2456 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2457 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2458
2459 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2460 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002461 std::list<NotifyArgs> args =
2462 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002463
2464 ASSERT_EQ(1u, args.size());
2465 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2466 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2467 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2468 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2469 args.pop_front();
2470
2471 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2472 /* down= */ GESTURES_BUTTON_LEFT,
2473 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002474 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002475
2476 // no events should be generated
2477 ASSERT_EQ(0u, args.size());
2478
2479 // Future taps should be re-enabled
2480 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2481}
2482
2483TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2484 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2485 // Click should still produce button press/release events
2486 mReader->getContext()->setPreventingTouchpadTaps(true);
2487
2488 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2489 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2490 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2491
2492 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2493 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002494 std::list<NotifyArgs> args =
2495 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002496
2497 ASSERT_EQ(1u, args.size());
2498 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2499 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2500 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2501 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2502
2503 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2504 /* down= */ GESTURES_BUTTON_LEFT,
2505 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002506 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002507 ASSERT_EQ(2u, args.size());
2508
2509 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2510 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0),
2511 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2512 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2513 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2514 args.pop_front();
2515 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2516 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2517 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2518 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(0, 0),
2519 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2520 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
2521 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2522
2523 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2524 /* down= */ GESTURES_BUTTON_NONE,
2525 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002526 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002527
2528 ASSERT_EQ(3u, args.size());
2529 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2530 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2531 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2532 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2533 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(1.0f),
2534 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2535 args.pop_front();
2536 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2537 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0),
2538 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2539 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2540 args.pop_front();
2541 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2542 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2543 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2544 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2545
2546 // Future taps should be re-enabled
2547 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2548}
2549
2550TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2551 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2552 // initially disable tap-to-click
2553 mReader->getContext()->setPreventingTouchpadTaps(true);
2554
2555 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2556 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2557 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2558
2559 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002560 std::list<NotifyArgs> args =
2561 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002562 ASSERT_EQ(1u, args.size());
2563
2564 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2565 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2566 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
2567 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2568
2569 // Future taps should be re-enabled
2570 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2571}
2572
Arpit Singh33a10a62023-10-12 13:06:54 +00002573TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
2574 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2575 const nsecs_t gestureStartTime = 1000;
2576 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2577 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2578 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2579
2580 // Start a move gesture at gestureStartTime
2581 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
2582 std::list<NotifyArgs> args =
2583 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
2584 ASSERT_EQ(1u, args.size());
2585 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2586 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
2587
2588 // Key presses with IME connection should cancel ongoing move gesture
2589 nsecs_t currentTime = gestureStartTime + 100;
2590 mFakePolicy->setIsInputMethodConnectionActive(true);
2591 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
2592 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2593 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2594 ASSERT_EQ(1u, args.size());
2595 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2596 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT));
2597
2598 // any updates in existing move gesture should be ignored
2599 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2600 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2601 ASSERT_EQ(0u, args.size());
2602
2603 // New gesture should not be affected
2604 currentTime += 100;
2605 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2606 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
2607 ASSERT_EQ(1u, args.size());
2608 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2609 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE));
2610}
2611
Harry Cutts4fb941a2022-12-14 19:14:04 +00002612} // namespace android