blob: d0cd677ade5ece28166cda3946bef246ac75f7b9 [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>
23
24#include "FakeEventHub.h"
25#include "FakeInputReaderPolicy.h"
26#include "FakePointerController.h"
27#include "InstrumentedInputReader.h"
28#include "NotifyArgs.h"
29#include "TestConstants.h"
Prabir Pradhane3b28dd2023-10-06 04:19:29 +000030#include "TestEventMatchers.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000031#include "TestInputListener.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000032#include "include/gestures.h"
Harry Cuttsedf6ce72023-01-04 12:15:53 +000033#include "ui/Rotation.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000034
35namespace android {
36
Byoungho Jungee6268f2023-10-30 17:27:26 +090037namespace input_flags = com::android::input::flags;
38
Arpit Singh3d84add2023-10-10 19:08:29 +000039namespace {
40
41const auto TOUCHPAD_PALM_REJECTION =
Byoungho Jungee6268f2023-10-30 17:27:26 +090042 ACONFIG_FLAG(input_flags, enable_touchpad_typing_palm_rejection);
Arpit Singh33a10a62023-10-12 13:06:54 +000043const auto TOUCHPAD_PALM_REJECTION_V2 =
44 ACONFIG_FLAG(input_flags, enable_v2_touchpad_typing_palm_rejection);
Arpit Singh3d84add2023-10-10 19:08:29 +000045
46} // namespace
47
Harry Cutts4fb941a2022-12-14 19:14:04 +000048using testing::AllOf;
Harry Cuttsef95e712024-02-16 18:56:39 +000049using testing::Each;
Harry Cutts5f26e952023-11-30 18:20:27 +000050using testing::ElementsAre;
51using testing::VariantWith;
Harry Cutts4fb941a2022-12-14 19:14:04 +000052
Prabir Pradhan8b053512024-05-03 23:15:39 +000053class GestureConverterTest : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000054protected:
55 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000056 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000057 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cutts4fb941a2022-12-14 19:14:04 +000058
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
Harry Cuttsc5748d12022-12-02 17:30:18 +000070 std::shared_ptr<InputDevice> newDevice() {
71 InputDeviceIdentifier identifier;
72 identifier.name = "device";
73 identifier.location = "USB1";
74 identifier.bus = 0;
75 std::shared_ptr<InputDevice> device =
76 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
77 identifier);
78 mReader->pushNextDevice(device);
79 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
80 identifier.bus);
81 mReader->loopOnce();
82 return device;
83 }
84
Harry Cutts4fb941a2022-12-14 19:14:04 +000085 std::shared_ptr<FakeEventHub> mFakeEventHub;
86 sp<FakeInputReaderPolicy> mFakePolicy;
87 std::unique_ptr<TestInputListener> mFakeListener;
88 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000089 std::shared_ptr<InputDevice> mDevice;
Byoungho Jungee6268f2023-10-30 17:27:26 +090090};
91
Harry Cutts4fb941a2022-12-14 19:14:04 +000092TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +000093 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
94 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -070095 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +000096
97 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +000098 std::list<NotifyArgs> args =
99 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000100 ASSERT_THAT(args,
101 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000102 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +0000103 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000104 VariantWith<NotifyMotionArgs>(
105 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000106 WithRelativeMotion(-5, 10), WithButtonState(0),
107 WithPressure(0.0f)))));
108 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700109 Each(VariantWith<NotifyMotionArgs>(
110 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
111 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000112
Prabir Pradhan8b053512024-05-03 23:15:39 +0000113 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
Harry Cutts379ea422023-12-21 15:31:47 +0000114 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
115 ASSERT_THAT(args,
116 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000117 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
Harry Cutts379ea422023-12-21 15:31:47 +0000118 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
119 WithButtonState(0), WithPressure(0.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700120 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000121}
122
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000123TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000124 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
125 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000126 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700127 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000128
129 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000130 std::list<NotifyArgs> args =
131 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000132 ASSERT_THAT(args,
133 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000134 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +0000135 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000136 VariantWith<NotifyMotionArgs>(
137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000138 WithRelativeMotion(10, 5), WithButtonState(0),
139 WithPressure(0.0f)))));
140 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700141 Each(VariantWith<NotifyMotionArgs>(
142 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
143 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000144}
145
Harry Cutts4fb941a2022-12-14 19:14:04 +0000146TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000147 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
148 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700149 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000150
151 // Press left and right buttons at once
152 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
153 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
154 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000155 std::list<NotifyArgs> args =
156 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000157 ASSERT_THAT(args,
158 ElementsAre(VariantWith<NotifyMotionArgs>(
159 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
160 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000161 AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000162 VariantWith<NotifyMotionArgs>(
163 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
164 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000165 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000166 VariantWith<NotifyMotionArgs>(
167 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
168 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
169 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000170 AMOTION_EVENT_BUTTON_SECONDARY)))));
171 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700172 Each(VariantWith<NotifyMotionArgs>(
173 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
174 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000175
176 // Then release the left button
177 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
178 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
179 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000180 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000181 ASSERT_THAT(args,
182 ElementsAre(VariantWith<NotifyMotionArgs>(
183 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
184 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000185 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
186 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700187 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000188
189 // Finally release the right button
190 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
191 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
192 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000193 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000194 ASSERT_THAT(args,
195 ElementsAre(VariantWith<NotifyMotionArgs>(
196 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000197 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000198 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000199 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000200 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000201 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
202 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700203 Each(VariantWith<NotifyMotionArgs>(
204 AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER),
205 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000206}
207
Harry Cutts379ea422023-12-21 15:31:47 +0000208TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) {
209 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
210 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700211 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts379ea422023-12-21 15:31:47 +0000212
213 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
214 std::list<NotifyArgs> args =
215 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
216
217 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
218 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
219 /*is_tap=*/false);
220 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
221 ASSERT_THAT(args.front(),
222 VariantWith<NotifyMotionArgs>(
223 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000224 WithCoords(0, 0), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700225 WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts379ea422023-12-21 15:31:47 +0000226}
227
Harry Cutts4fb941a2022-12-14 19:14:04 +0000228TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000229 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
230 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700231 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000232
233 // Press the button
234 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
235 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
236 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000237 std::list<NotifyArgs> args =
238 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000239 ASSERT_THAT(args,
240 ElementsAre(VariantWith<NotifyMotionArgs>(
241 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +0000242 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000243 VariantWith<NotifyMotionArgs>(
244 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
245 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000246 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)))));
247 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700248 Each(VariantWith<NotifyMotionArgs>(
249 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
250 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000251
252 // Move
253 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000254 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000255 ASSERT_THAT(args,
256 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000257 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
258 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000259 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700260 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000261
Harry Cutts4fb941a2022-12-14 19:14:04 +0000262 // Release the button
263 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
264 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
265 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000266 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000267 ASSERT_THAT(args,
268 ElementsAre(VariantWith<NotifyMotionArgs>(
269 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000270 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000271 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000272 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000273 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000274 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
275 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700276 Each(VariantWith<NotifyMotionArgs>(
277 AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER),
278 WithDisplayId(ui::LogicalDisplayId::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);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700285 converter.setDisplayId(ui::LogicalDisplayId::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 Cutts5f26e952023-11-30 18:20:27 +0000290 ASSERT_THAT(args,
291 ElementsAre(VariantWith<NotifyMotionArgs>(
292 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000293 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000294 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000295 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000296 VariantWith<NotifyMotionArgs>(
297 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000298 WithCoords(0, -10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000299 WithGestureScrollDistance(0, 10, EPSILON)))));
300 ASSERT_THAT(args,
301 Each(VariantWith<NotifyMotionArgs>(
302 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
303 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
304 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700305 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000306
Harry Cuttsa546ba82023-01-13 17:21:00 +0000307 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000308 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000309 ASSERT_THAT(args,
310 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000311 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
Harry Cutts5f26e952023-11-30 18:20:27 +0000312 WithGestureScrollDistance(0, 5, EPSILON),
313 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
314 WithToolType(ToolType::FINGER),
315 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700316 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000317
318 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
319 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000320 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000321 ASSERT_THAT(args,
322 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000323 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000324 WithCoords(0, -15),
Harry Cutts379ea422023-12-21 15:31:47 +0000325 WithGestureScrollDistance(0, 0, EPSILON),
326 WithMotionClassification(
327 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000328 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000329 VariantWith<NotifyMotionArgs>(
330 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000331 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000332 WithMotionClassification(MotionClassification::NONE)))));
333 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700334 Each(VariantWith<NotifyMotionArgs>(
335 AllOf(WithToolType(ToolType::FINGER),
336 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000337}
338
339TEST_F(GestureConverterTest, Scroll_Rotated) {
340 const nsecs_t downTime = 12345;
341 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
342 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
343 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700344 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000345
Harry Cuttsa546ba82023-01-13 17:21:00 +0000346 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000347 std::list<NotifyArgs> args =
348 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000349 ASSERT_THAT(args,
350 ElementsAre(VariantWith<NotifyMotionArgs>(
351 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000352 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000353 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000354 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000355 VariantWith<NotifyMotionArgs>(
356 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000357 WithCoords(-10, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000358 WithGestureScrollDistance(0, 10, EPSILON)))));
359 ASSERT_THAT(args,
360 Each(VariantWith<NotifyMotionArgs>(
361 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
362 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700363 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000364
Harry Cuttsa546ba82023-01-13 17:21:00 +0000365 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000366 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000367 ASSERT_THAT(args,
368 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000369 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000370 WithGestureScrollDistance(0, 5, EPSILON),
371 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
372 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700373 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000374
Harry Cuttsef400b22022-12-16 21:26:24 +0000375 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
376 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000377 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000378 ASSERT_THAT(args,
379 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000380 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000381 WithCoords(-15, 0),
Harry Cutts379ea422023-12-21 15:31:47 +0000382 WithGestureScrollDistance(0, 0, EPSILON),
383 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +0000384 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000385 VariantWith<NotifyMotionArgs>(
386 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000387 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000388 WithMotionClassification(MotionClassification::NONE)))));
389 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700390 Each(VariantWith<NotifyMotionArgs>(
391 AllOf(WithToolType(ToolType::FINGER),
392 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000393}
394
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000395TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000396 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
397 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700398 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000399
Harry Cuttsa546ba82023-01-13 17:21:00 +0000400 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000401 std::list<NotifyArgs> args =
402 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000403
Harry Cuttsa546ba82023-01-13 17:21:00 +0000404 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000405 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000406
407 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
408 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000409 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000410
411 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000412 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000413 ASSERT_THAT(args,
414 ElementsAre(VariantWith<NotifyMotionArgs>(
415 AllOf(WithMotionClassification(MotionClassification::NONE),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700416 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000417}
418
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000419TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000420 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
421 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700422 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000423
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000424 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000425 std::list<NotifyArgs> args =
426 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000427
428 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000429 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000430
431 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
432 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000433 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000434
435 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
436 // need to use another gesture type, like pinch.
437 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
438 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000439 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000440 ASSERT_FALSE(args.empty());
441 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
442}
443
Prabir Pradhan13acbd22024-05-14 22:36:40 +0000444TEST_F(GestureConverterTest, Scroll_ClearsFakeFingerPositionOnSubsequentScrollGestures) {
445 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
446 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
447 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
448
449 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 15, -10);
450 std::list<NotifyArgs> args =
451 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
452
453 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -2, -5);
454 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
455
456 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
457 GESTURES_FLING_START);
458 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
459 Gesture flingGestureEnd(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, 0,
460 GESTURES_FLING_TAP_DOWN);
461 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGestureEnd);
462
463 // Start a second scoll gesture, and ensure the fake finger is reset to (0, 0), instead of
464 // continuing from the position where the last scroll gesture's fake finger ended.
465 Gesture secondScrollStart(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 2,
466 14);
467 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, secondScrollStart);
468 ASSERT_THAT(args,
469 ElementsAre(VariantWith<NotifyMotionArgs>(
470 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
471 VariantWith<NotifyMotionArgs>(
472 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
473 WithCoords(0, 0),
474 WithGestureScrollDistance(0, 0, EPSILON))),
475 VariantWith<NotifyMotionArgs>(
476 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
477 WithCoords(2, 14),
478 WithGestureScrollDistance(-2, -14, EPSILON)))));
479}
480
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000481TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
482 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
483 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700484 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000485
486 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
487 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000488 std::list<NotifyArgs> args =
489 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000490
491 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000492 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000493
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000494 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
495 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000496 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000497 ASSERT_THAT(args,
498 ElementsAre(VariantWith<NotifyMotionArgs>(
499 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000500}
501
Harry Cutts8743f182023-05-17 12:03:49 +0000502TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000503 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
504 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700505 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000506
507 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
508 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000509 std::list<NotifyArgs> args =
510 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000511
512 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000513 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000514
515 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
516 // need to use another gesture type, like pinch.
517 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
518 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000519 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000520 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000521 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
522 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000523}
524
525TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
526 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
527 // start swiping up and then start moving left or right, it'll return gesture events with only Y
528 // deltas until you lift your fingers and start swiping again. That's why each of these tests
529 // only checks movement in one dimension.
530 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
531 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700532 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000533
534 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
535 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000536 std::list<NotifyArgs> args =
537 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000538 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000539 ASSERT_THAT(args,
540 Each(VariantWith<NotifyMotionArgs>(
541 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
542 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700543 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000544
545 // Three fake fingers should be created. We don't actually care where they are, so long as they
546 // move appropriately.
547 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
548 ASSERT_THAT(arg,
549 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000550 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000551 PointerCoords finger0Start = arg.pointerCoords[0];
552 args.pop_front();
553 arg = std::get<NotifyMotionArgs>(args.front());
554 ASSERT_THAT(arg,
555 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
556 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000557 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000558 PointerCoords finger1Start = arg.pointerCoords[1];
559 args.pop_front();
560 arg = std::get<NotifyMotionArgs>(args.front());
561 ASSERT_THAT(arg,
562 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
563 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000564 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000565 PointerCoords finger2Start = arg.pointerCoords[2];
566 args.pop_front();
567
568 arg = std::get<NotifyMotionArgs>(args.front());
569 ASSERT_THAT(arg,
570 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000571 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000572 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
573 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
574 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
575 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
576 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
577 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
578
579 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
580 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000581 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000582 ASSERT_EQ(1u, args.size());
583 arg = std::get<NotifyMotionArgs>(args.front());
584 ASSERT_THAT(arg,
585 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000586 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000587 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000588 WithPointerCount(3u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700589 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000590 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
591 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
592 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
593 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
594 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
595 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
596
597 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000598 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000599 ASSERT_THAT(args,
600 ElementsAre(VariantWith<NotifyMotionArgs>(
601 AllOf(WithMotionAction(
602 AMOTION_EVENT_ACTION_POINTER_UP |
603 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
604 WithGestureOffset(0, 0, EPSILON),
605 WithGestureSwipeFingerCount(3),
606 WithMotionClassification(
607 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000608 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000609 VariantWith<NotifyMotionArgs>(
610 AllOf(WithMotionAction(
611 AMOTION_EVENT_ACTION_POINTER_UP |
612 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
613 WithGestureOffset(0, 0, EPSILON),
614 WithGestureSwipeFingerCount(3),
615 WithMotionClassification(
616 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000617 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000618 VariantWith<NotifyMotionArgs>(
619 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
620 WithGestureOffset(0, 0, EPSILON),
621 WithGestureSwipeFingerCount(3),
622 WithMotionClassification(
623 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000624 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000625 VariantWith<NotifyMotionArgs>(
626 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000627 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000628 WithMotionClassification(MotionClassification::NONE)))));
629 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700630 Each(VariantWith<NotifyMotionArgs>(
631 AllOf(WithToolType(ToolType::FINGER),
632 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000633}
634
Harry Cutts94f5bd52023-01-06 18:02:18 +0000635TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
636 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
637 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
638 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700639 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000640
641 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
642 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000643 std::list<NotifyArgs> args =
644 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000645 ASSERT_EQ(4u, args.size());
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700646 ASSERT_THAT(args,
647 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000648
649 // Three fake fingers should be created. We don't actually care where they are, so long as they
650 // move appropriately.
651 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
652 ASSERT_THAT(arg,
653 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000654 WithPointerCount(1u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000655 PointerCoords finger0Start = arg.pointerCoords[0];
656 args.pop_front();
657 arg = std::get<NotifyMotionArgs>(args.front());
658 ASSERT_THAT(arg,
659 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
660 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000661 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000662 PointerCoords finger1Start = arg.pointerCoords[1];
663 args.pop_front();
664 arg = std::get<NotifyMotionArgs>(args.front());
665 ASSERT_THAT(arg,
666 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
667 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000668 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000669 PointerCoords finger2Start = arg.pointerCoords[2];
670 args.pop_front();
671
672 arg = std::get<NotifyMotionArgs>(args.front());
673 ASSERT_THAT(arg,
674 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000675 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000676 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
677 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
678 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
679 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
680 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
681 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
682
683 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
684 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000685 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000686 ASSERT_EQ(1u, args.size());
687 arg = std::get<NotifyMotionArgs>(args.front());
688 ASSERT_THAT(arg,
689 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000690 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700691 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000692 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
693 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
694 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
695 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
696 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
697 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
698
699 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000700 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000701 ASSERT_THAT(args,
702 ElementsAre(VariantWith<NotifyMotionArgs>(
703 AllOf(WithMotionAction(
704 AMOTION_EVENT_ACTION_POINTER_UP |
705 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000706 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000707 VariantWith<NotifyMotionArgs>(
708 AllOf(WithMotionAction(
709 AMOTION_EVENT_ACTION_POINTER_UP |
710 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000711 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000712 VariantWith<NotifyMotionArgs>(
713 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +0000714 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000715 VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000716 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700717 ASSERT_THAT(args,
718 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000719}
720
Harry Cuttsc5748d12022-12-02 17:30:18 +0000721TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
722 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
723 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700724 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000725
726 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
727 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000728 std::list<NotifyArgs> args =
729 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000730 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000731 ASSERT_THAT(args,
732 Each(VariantWith<NotifyMotionArgs>(
733 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
734 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700735 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000736
737 // Four fake fingers should be created. We don't actually care where they are, so long as they
738 // move appropriately.
739 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
740 ASSERT_THAT(arg,
741 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000742 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000743 PointerCoords finger0Start = arg.pointerCoords[0];
744 args.pop_front();
745 arg = std::get<NotifyMotionArgs>(args.front());
746 ASSERT_THAT(arg,
747 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
748 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000749 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000750 PointerCoords finger1Start = arg.pointerCoords[1];
751 args.pop_front();
752 arg = std::get<NotifyMotionArgs>(args.front());
753 ASSERT_THAT(arg,
754 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
755 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000756 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000757 PointerCoords finger2Start = arg.pointerCoords[2];
758 args.pop_front();
759 arg = std::get<NotifyMotionArgs>(args.front());
760 ASSERT_THAT(arg,
761 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
762 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000763 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000764 PointerCoords finger3Start = arg.pointerCoords[3];
765 args.pop_front();
766
767 arg = std::get<NotifyMotionArgs>(args.front());
768 ASSERT_THAT(arg,
769 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000770 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000771 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
772 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
773 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
774 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
775 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
776 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
777 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
778 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
779
780 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
781 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000782 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000783 ASSERT_EQ(1u, args.size());
784 arg = std::get<NotifyMotionArgs>(args.front());
785 ASSERT_THAT(arg,
786 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000787 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000788 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000789 WithPointerCount(4u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700790 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000791 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
792 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
793 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
794 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
795 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
796 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
797 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
798 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
799
800 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000801 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000802 ASSERT_THAT(args,
803 ElementsAre(VariantWith<NotifyMotionArgs>(
804 AllOf(WithMotionAction(
805 AMOTION_EVENT_ACTION_POINTER_UP |
806 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
807 WithGestureOffset(0, 0, EPSILON),
808 WithGestureSwipeFingerCount(4),
809 WithMotionClassification(
810 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000811 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000812 VariantWith<NotifyMotionArgs>(
813 AllOf(WithMotionAction(
814 AMOTION_EVENT_ACTION_POINTER_UP |
815 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
816 WithGestureOffset(0, 0, EPSILON),
817 WithGestureSwipeFingerCount(4),
818 WithMotionClassification(
819 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000820 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000821 VariantWith<NotifyMotionArgs>(
822 AllOf(WithMotionAction(
823 AMOTION_EVENT_ACTION_POINTER_UP |
824 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
825 WithGestureOffset(0, 0, EPSILON),
826 WithGestureSwipeFingerCount(4),
827 WithMotionClassification(
828 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000829 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000830 VariantWith<NotifyMotionArgs>(
831 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
832 WithGestureOffset(0, 0, EPSILON),
833 WithGestureSwipeFingerCount(4),
834 WithMotionClassification(
835 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000836 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000837 VariantWith<NotifyMotionArgs>(
838 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000839 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000840 WithMotionClassification(MotionClassification::NONE)))));
841 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700842 Each(VariantWith<NotifyMotionArgs>(
843 AllOf(WithToolType(ToolType::FINGER),
844 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000845}
846
Harry Cuttsb1e83552022-12-20 11:02:26 +0000847TEST_F(GestureConverterTest, Pinch_Inwards) {
848 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
849 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700850 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000851
852 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
853 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000854 std::list<NotifyArgs> args =
855 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000856 ASSERT_THAT(args,
857 ElementsAre(VariantWith<NotifyMotionArgs>(
858 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000859 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000860 VariantWith<NotifyMotionArgs>(
861 AllOf(WithMotionAction(
862 AMOTION_EVENT_ACTION_POINTER_DOWN |
863 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000864 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
Harry Cuttsef95e712024-02-16 18:56:39 +0000865 ASSERT_THAT(args,
866 Each(VariantWith<NotifyMotionArgs>(
867 AllOf(WithMotionClassification(MotionClassification::PINCH),
868 WithGesturePinchScaleFactor(1.0f, EPSILON),
869 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700870 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000871
872 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
873 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000874 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000875 ASSERT_THAT(args,
876 ElementsAre(VariantWith<NotifyMotionArgs>(
877 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
878 WithMotionClassification(MotionClassification::PINCH),
879 WithGesturePinchScaleFactor(0.8f, EPSILON),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000880 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000881 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700882 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000883
884 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
885 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000886 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000887 ASSERT_THAT(args,
888 ElementsAre(VariantWith<NotifyMotionArgs>(
889 AllOf(WithMotionAction(
890 AMOTION_EVENT_ACTION_POINTER_UP |
891 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
892 WithMotionClassification(MotionClassification::PINCH),
893 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000894 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000895 VariantWith<NotifyMotionArgs>(
896 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
897 WithMotionClassification(MotionClassification::PINCH),
898 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000899 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000900 VariantWith<NotifyMotionArgs>(
901 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000902 WithCoords(0, 0),
903 WithMotionClassification(MotionClassification::NONE)))));
904 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700905 Each(VariantWith<NotifyMotionArgs>(
906 AllOf(WithToolType(ToolType::FINGER),
907 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000908}
909
910TEST_F(GestureConverterTest, Pinch_Outwards) {
911 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
912 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700913 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhan8b053512024-05-03 23:15:39 +0000914
915 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
916 GESTURES_ZOOM_START);
917 std::list<NotifyArgs> args =
918 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
919 ASSERT_THAT(args,
920 ElementsAre(VariantWith<NotifyMotionArgs>(
921 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
922 WithCoords(-100, 0), WithPointerCount(1u))),
923 VariantWith<NotifyMotionArgs>(
924 AllOf(WithMotionAction(
925 AMOTION_EVENT_ACTION_POINTER_DOWN |
926 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
927 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
928 ASSERT_THAT(args,
929 Each(VariantWith<NotifyMotionArgs>(
930 AllOf(WithMotionClassification(MotionClassification::PINCH),
931 WithGesturePinchScaleFactor(1.0f, EPSILON),
932 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700933 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000934
935 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
936 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
937 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
938 ASSERT_THAT(args,
939 ElementsAre(VariantWith<NotifyMotionArgs>(
940 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
941 WithMotionClassification(MotionClassification::PINCH),
942 WithGesturePinchScaleFactor(1.1f, EPSILON),
943 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
944 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700945 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000946
947 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
948 GESTURES_ZOOM_END);
949 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
950 ASSERT_THAT(args,
951 ElementsAre(VariantWith<NotifyMotionArgs>(
952 AllOf(WithMotionAction(
953 AMOTION_EVENT_ACTION_POINTER_UP |
954 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
955 WithMotionClassification(MotionClassification::PINCH),
956 WithGesturePinchScaleFactor(1.0f, EPSILON),
957 WithPointerCount(2u))),
958 VariantWith<NotifyMotionArgs>(
959 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
960 WithMotionClassification(MotionClassification::PINCH),
961 WithGesturePinchScaleFactor(1.0f, EPSILON),
962 WithPointerCount(1u))),
963 VariantWith<NotifyMotionArgs>(
964 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
965 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000966 WithMotionClassification(MotionClassification::NONE)))));
967 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700968 Each(VariantWith<NotifyMotionArgs>(
969 AllOf(WithToolType(ToolType::FINGER),
970 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000971}
972
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000973TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000974 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
975 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700976 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000977
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000978 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000979 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000980 std::list<NotifyArgs> args =
981 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000982
983 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000984 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000985 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000986
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000987 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000988 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000989 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000990
991 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000992 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000993 ASSERT_THAT(args,
994 ElementsAre(VariantWith<NotifyMotionArgs>(
995 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000996}
997
998TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
999 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1000 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001001 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001002
1003 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1004 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001005 std::list<NotifyArgs> args =
1006 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001007
1008 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1009 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001010 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001011
1012 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1013 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001014 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001015
1016 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1017 // need to use another gesture type, like scroll.
1018 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1019 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001020 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001021 ASSERT_FALSE(args.empty());
1022 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001023}
1024
Harry Cuttse9b71422023-03-14 16:54:44 +00001025TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1026 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1027 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001028 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001029
1030 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1031 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1032 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001033 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001034
1035 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001036 ASSERT_THAT(args,
1037 ElementsAre(VariantWith<NotifyMotionArgs>(
1038 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1039 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001040 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001041 VariantWith<NotifyMotionArgs>(
1042 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1043 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001044 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001045 VariantWith<NotifyMotionArgs>(
1046 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001047 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001048 VariantWith<NotifyMotionArgs>(
1049 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001050 WithButtonState(0)))));
1051 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001052 Each(VariantWith<NotifyMotionArgs>(
1053 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
1054 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001055}
1056
1057TEST_F(GestureConverterTest, ResetDuringScroll) {
1058 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1059 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001060 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001061
1062 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001063 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001064
1065 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001066 ASSERT_THAT(args,
1067 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001068 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001069 WithCoords(0, -10),
Harry Cutts379ea422023-12-21 15:31:47 +00001070 WithGestureScrollDistance(0, 0, EPSILON),
1071 WithMotionClassification(
1072 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001073 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001074 VariantWith<NotifyMotionArgs>(
1075 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001076 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001077 WithMotionClassification(MotionClassification::NONE)))));
1078 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001079 Each(VariantWith<NotifyMotionArgs>(
1080 AllOf(WithToolType(ToolType::FINGER),
1081 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001082}
1083
1084TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1085 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1086 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001087 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001088
1089 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1090 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001091 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001092
1093 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001094 ASSERT_THAT(args,
1095 ElementsAre(VariantWith<NotifyMotionArgs>(
1096 AllOf(WithMotionAction(
1097 AMOTION_EVENT_ACTION_POINTER_UP |
1098 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1099 WithGestureOffset(0, 0, EPSILON),
1100 WithMotionClassification(
1101 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001102 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001103 VariantWith<NotifyMotionArgs>(
1104 AllOf(WithMotionAction(
1105 AMOTION_EVENT_ACTION_POINTER_UP |
1106 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1107 WithGestureOffset(0, 0, EPSILON),
1108 WithMotionClassification(
1109 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001110 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001111 VariantWith<NotifyMotionArgs>(
1112 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1113 WithGestureOffset(0, 0, EPSILON),
1114 WithMotionClassification(
1115 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001116 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001117 VariantWith<NotifyMotionArgs>(
1118 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001119 WithMotionClassification(MotionClassification::NONE)))));
1120 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001121 Each(VariantWith<NotifyMotionArgs>(
1122 AllOf(WithToolType(ToolType::FINGER),
1123 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001124}
1125
1126TEST_F(GestureConverterTest, ResetDuringPinch) {
1127 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1128 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001129 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001130
1131 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1132 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001133 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001134
1135 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001136 ASSERT_THAT(args,
1137 ElementsAre(VariantWith<NotifyMotionArgs>(
1138 AllOf(WithMotionAction(
1139 AMOTION_EVENT_ACTION_POINTER_UP |
1140 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1141 WithMotionClassification(MotionClassification::PINCH),
1142 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001143 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001144 VariantWith<NotifyMotionArgs>(
1145 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1146 WithMotionClassification(MotionClassification::PINCH),
1147 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001148 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001149 VariantWith<NotifyMotionArgs>(
1150 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001151 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001152 WithMotionClassification(MotionClassification::NONE)))));
1153 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001154 Each(VariantWith<NotifyMotionArgs>(
1155 AllOf(WithToolType(ToolType::FINGER),
1156 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001157}
1158
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001159TEST_F(GestureConverterTest, FlingTapDown) {
1160 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1161 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001162 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001163
1164 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1165 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001166 std::list<NotifyArgs> args =
1167 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001168
1169 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001170 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
1171 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001172 WithButtonState(0), WithPressure(0.0f),
1173 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001174}
1175
Harry Cutts39648ab2024-02-15 14:23:50 +00001176TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1177 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1178 input_flags::enable_touchpad_fling_stop(true);
1179 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001180 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts39648ab2024-02-15 14:23:50 +00001181
1182 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1183 std::list<NotifyArgs> args =
1184 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1185 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1186 GESTURES_FLING_START);
1187 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1188
1189 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1190 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1191 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1192 ASSERT_THAT(args,
1193 ElementsAre(VariantWith<NotifyMotionArgs>(
1194 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1195 VariantWith<NotifyMotionArgs>(
1196 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1197 VariantWith<NotifyMotionArgs>(
1198 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1199 VariantWith<NotifyMotionArgs>(
Harry Cutts574781a2024-04-23 15:30:45 +00001200 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001201 ASSERT_THAT(args,
Harry Cutts574781a2024-04-23 15:30:45 +00001202 Each(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +00001203 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001204 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
Harry Cutts574781a2024-04-23 15:30:45 +00001205 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE)))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001206}
1207
Arpit Singha5ea7c12023-07-05 15:39:25 +00001208TEST_F(GestureConverterTest, Tap) {
1209 // Tap should produce button press/release events
1210 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1211 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001212 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001213
1214 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1215 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001216 std::list<NotifyArgs> args =
1217 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001218 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001219
1220 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1221 /* down= */ GESTURES_BUTTON_LEFT,
1222 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001223 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001224
Harry Cutts5f26e952023-11-30 18:20:27 +00001225 ASSERT_THAT(args,
1226 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001227 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001228 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001229 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001230 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001231 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001232 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001233 VariantWith<NotifyMotionArgs>(
1234 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1235 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1236 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001237 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001238 VariantWith<NotifyMotionArgs>(
1239 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1240 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001241 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001242 VariantWith<NotifyMotionArgs>(
1243 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001244 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001245 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001246 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001247 WithButtonState(0), WithPressure(0.0f)))));
1248 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001249 Each(VariantWith<NotifyMotionArgs>(
1250 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1251 WithToolType(ToolType::FINGER),
1252 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001253}
1254
1255TEST_F(GestureConverterTest, Click) {
1256 // Click should produce button press/release events
1257 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1258 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001259 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001260
1261 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1262 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001263 std::list<NotifyArgs> args =
1264 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001265 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001266
1267 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1268 /* down= */ GESTURES_BUTTON_LEFT,
1269 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001270 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001271
Harry Cutts5f26e952023-11-30 18:20:27 +00001272 ASSERT_THAT(args,
1273 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001274 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001275 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001276 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001277 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001278 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001279 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001280 VariantWith<NotifyMotionArgs>(
1281 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1282 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1283 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001284 WithPressure(1.0f)))));
1285 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001286 Each(VariantWith<NotifyMotionArgs>(
1287 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1288 WithToolType(ToolType::FINGER),
1289 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001290
1291 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1292 /* down= */ GESTURES_BUTTON_NONE,
1293 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001294 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Prabir Pradhan8b053512024-05-03 23:15:39 +00001295
Harry Cutts5f26e952023-11-30 18:20:27 +00001296 ASSERT_THAT(args,
1297 ElementsAre(VariantWith<NotifyMotionArgs>(
1298 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1299 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001300 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001301 VariantWith<NotifyMotionArgs>(
1302 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001303 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001304 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001305 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001306 WithPressure(0.0f)))));
1307 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001308 Each(VariantWith<NotifyMotionArgs>(
1309 AllOf(WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1310 WithToolType(ToolType::FINGER),
1311 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001312}
1313
Arpit Singh3d84add2023-10-10 19:08:29 +00001314TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001315 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1316 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1317 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1318
Arpit Singha5ea7c12023-07-05 15:39:25 +00001319 // Tap should be ignored when disabled
1320 mReader->getContext()->setPreventingTouchpadTaps(true);
1321
1322 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1323 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001324 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001325
Arpit Singh82b27a02023-10-16 11:02:19 +00001326 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001327 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001328 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001329 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001330 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001331
Arpit Singh82b27a02023-10-16 11:02:19 +00001332 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001333 /* down= */ GESTURES_BUTTON_LEFT,
1334 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001335 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001336
1337 // no events should be generated
1338 ASSERT_EQ(0u, args.size());
1339
1340 // Future taps should be re-enabled
1341 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1342}
1343
Arpit Singh82b27a02023-10-16 11:02:19 +00001344TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1345 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1346 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1347
1348 // Tap should be ignored when disabled
1349 mReader->getContext()->setPreventingTouchpadTaps(true);
1350
1351 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1352 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001353 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh82b27a02023-10-16 11:02:19 +00001354
1355 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1356 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1357 std::list<NotifyArgs> args =
1358 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001359 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001360
1361 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1362 /* down= */ GESTURES_BUTTON_LEFT,
1363 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1364 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1365
1366 // no events should be generated
1367 ASSERT_EQ(0u, args.size());
1368
1369 // Future taps should be re-enabled
1370 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1371
1372 // taps before the threshold should still be ignored
1373 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1374 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1375 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1376 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1377
1378 ASSERT_EQ(1u, args.size());
1379 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1380 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1381
1382 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1383 /* down= */ GESTURES_BUTTON_LEFT,
1384 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1385 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1386
1387 // no events should be generated
1388 ASSERT_EQ(0u, args.size());
1389
1390 // taps after the threshold should be recognised
1391 currentTime += 1;
1392 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1393 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1394 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1395
1396 ASSERT_EQ(1u, args.size());
1397 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1398 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1399
1400 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1401 /* down= */ GESTURES_BUTTON_LEFT,
1402 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1403 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001404 ASSERT_THAT(args,
1405 ElementsAre(VariantWith<NotifyMotionArgs>(
1406 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1407 WithButtonState(0))),
1408 VariantWith<NotifyMotionArgs>(
1409 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1410 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1411 VariantWith<NotifyMotionArgs>(
1412 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1413 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1414 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1415 VariantWith<NotifyMotionArgs>(
1416 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1417 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1418 WithButtonState(0))),
1419 VariantWith<NotifyMotionArgs>(
1420 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1421 WithButtonState(0))),
1422 VariantWith<NotifyMotionArgs>(
1423 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1424 WithButtonState(0)))));
1425 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001426}
1427
Arpit Singh3d84add2023-10-10 19:08:29 +00001428TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1429 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001430 // Click should still produce button press/release events
1431 mReader->getContext()->setPreventingTouchpadTaps(true);
1432
1433 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1434 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001435 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001436
1437 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1438 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001439 std::list<NotifyArgs> args =
1440 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001441 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001442
1443 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1444 /* down= */ GESTURES_BUTTON_LEFT,
1445 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001446 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001447
Harry Cutts5f26e952023-11-30 18:20:27 +00001448 ASSERT_THAT(args,
1449 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001450 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001451 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001452 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001453 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001454 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001455 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001456 VariantWith<NotifyMotionArgs>(
1457 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1458 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1459 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001460 WithPressure(1.0f)))));
1461 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001462 Each(VariantWith<NotifyMotionArgs>(
1463 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1464 WithToolType(ToolType::FINGER),
1465 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001466
1467 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1468 /* down= */ GESTURES_BUTTON_NONE,
1469 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001470 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001471
Harry Cutts5f26e952023-11-30 18:20:27 +00001472 ASSERT_THAT(args,
1473 ElementsAre(VariantWith<NotifyMotionArgs>(
1474 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1475 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1476 WithButtonState(0), WithCoords(0, 0),
1477 WithRelativeMotion(0.f, 0.f),
1478 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001479 WithPressure(1.0f),
1480 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001481 VariantWith<NotifyMotionArgs>(
1482 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1483 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1484 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001485 WithPressure(0.0f),
1486 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001487 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001488 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001489 WithCoords(0, 0), WithRelativeMotion(0, 0),
1490 WithToolType(ToolType::FINGER), WithButtonState(0),
1491 WithPressure(0.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001492 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001493
1494 // Future taps should be re-enabled
1495 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1496}
1497
Prabir Pradhan8b053512024-05-03 23:15:39 +00001498TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
Byoungho Jungee6268f2023-10-30 17:27:26 +09001499 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
1500 // initially disable tap-to-click
1501 mReader->getContext()->setPreventingTouchpadTaps(true);
1502
1503 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1504 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001505 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001506
1507 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001508 std::list<NotifyArgs> args =
1509 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001510 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001511
1512 // Future taps should be re-enabled
1513 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1514}
1515
Prabir Pradhan8b053512024-05-03 23:15:39 +00001516TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
Arpit Singh33a10a62023-10-12 13:06:54 +00001517 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1518 const nsecs_t gestureStartTime = 1000;
1519 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1520 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001521 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh33a10a62023-10-12 13:06:54 +00001522
1523 // Start a move gesture at gestureStartTime
1524 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1525 std::list<NotifyArgs> args =
1526 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001527 ASSERT_THAT(args,
1528 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001529 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1530 VariantWith<NotifyMotionArgs>(
1531 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001532
1533 // Key presses with IME connection should cancel ongoing move gesture
1534 nsecs_t currentTime = gestureStartTime + 100;
1535 mFakePolicy->setIsInputMethodConnectionActive(true);
1536 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1537 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1538 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001539 ASSERT_THAT(args,
1540 ElementsAre(VariantWith<NotifyMotionArgs>(
1541 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001542
1543 // any updates in existing move gesture should be ignored
1544 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1545 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1546 ASSERT_EQ(0u, args.size());
1547
1548 // New gesture should not be affected
1549 currentTime += 100;
1550 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1551 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001552 ASSERT_THAT(args,
1553 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001554 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1555 VariantWith<NotifyMotionArgs>(
1556 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001557}
1558
Harry Cutts4fb941a2022-12-14 19:14:04 +00001559} // namespace android