blob: 2f9036f2b4e9ddc22b6ac00f1fe0b5f73ff2e168 [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
444TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
445 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
446 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700447 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000448
449 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
450 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000451 std::list<NotifyArgs> args =
452 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000453
454 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000455 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000456
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000457 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
458 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000459 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000460 ASSERT_THAT(args,
461 ElementsAre(VariantWith<NotifyMotionArgs>(
462 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000463}
464
Harry Cutts8743f182023-05-17 12:03:49 +0000465TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000466 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
467 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700468 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000469
470 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
471 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000472 std::list<NotifyArgs> args =
473 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000474
475 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000476 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000477
478 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
479 // need to use another gesture type, like pinch.
480 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
481 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000482 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000483 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000484 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
485 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000486}
487
488TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
489 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
490 // start swiping up and then start moving left or right, it'll return gesture events with only Y
491 // deltas until you lift your fingers and start swiping again. That's why each of these tests
492 // only checks movement in one dimension.
493 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
494 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700495 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000496
497 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
498 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000499 std::list<NotifyArgs> args =
500 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000501 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000502 ASSERT_THAT(args,
503 Each(VariantWith<NotifyMotionArgs>(
504 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
505 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700506 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000507
508 // Three fake fingers should be created. We don't actually care where they are, so long as they
509 // move appropriately.
510 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
511 ASSERT_THAT(arg,
512 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000513 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000514 PointerCoords finger0Start = arg.pointerCoords[0];
515 args.pop_front();
516 arg = std::get<NotifyMotionArgs>(args.front());
517 ASSERT_THAT(arg,
518 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
519 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000520 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000521 PointerCoords finger1Start = arg.pointerCoords[1];
522 args.pop_front();
523 arg = std::get<NotifyMotionArgs>(args.front());
524 ASSERT_THAT(arg,
525 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
526 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000527 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000528 PointerCoords finger2Start = arg.pointerCoords[2];
529 args.pop_front();
530
531 arg = std::get<NotifyMotionArgs>(args.front());
532 ASSERT_THAT(arg,
533 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000534 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000535 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
536 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
537 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
538 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
539 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
540 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
541
542 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
543 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000544 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000545 ASSERT_EQ(1u, args.size());
546 arg = std::get<NotifyMotionArgs>(args.front());
547 ASSERT_THAT(arg,
548 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000549 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000550 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000551 WithPointerCount(3u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700552 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000553 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
554 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
555 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
556 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
557 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
558 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
559
560 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000561 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000562 ASSERT_THAT(args,
563 ElementsAre(VariantWith<NotifyMotionArgs>(
564 AllOf(WithMotionAction(
565 AMOTION_EVENT_ACTION_POINTER_UP |
566 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
567 WithGestureOffset(0, 0, EPSILON),
568 WithGestureSwipeFingerCount(3),
569 WithMotionClassification(
570 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000571 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000572 VariantWith<NotifyMotionArgs>(
573 AllOf(WithMotionAction(
574 AMOTION_EVENT_ACTION_POINTER_UP |
575 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
576 WithGestureOffset(0, 0, EPSILON),
577 WithGestureSwipeFingerCount(3),
578 WithMotionClassification(
579 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000580 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000581 VariantWith<NotifyMotionArgs>(
582 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
583 WithGestureOffset(0, 0, EPSILON),
584 WithGestureSwipeFingerCount(3),
585 WithMotionClassification(
586 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000587 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000588 VariantWith<NotifyMotionArgs>(
589 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000590 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000591 WithMotionClassification(MotionClassification::NONE)))));
592 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700593 Each(VariantWith<NotifyMotionArgs>(
594 AllOf(WithToolType(ToolType::FINGER),
595 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000596}
597
Harry Cutts94f5bd52023-01-06 18:02:18 +0000598TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
599 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
600 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
601 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700602 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000603
604 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
605 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000606 std::list<NotifyArgs> args =
607 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000608 ASSERT_EQ(4u, args.size());
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700609 ASSERT_THAT(args,
610 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000611
612 // Three fake fingers should be created. We don't actually care where they are, so long as they
613 // move appropriately.
614 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
615 ASSERT_THAT(arg,
616 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000617 WithPointerCount(1u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000618 PointerCoords finger0Start = arg.pointerCoords[0];
619 args.pop_front();
620 arg = std::get<NotifyMotionArgs>(args.front());
621 ASSERT_THAT(arg,
622 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
623 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000624 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000625 PointerCoords finger1Start = arg.pointerCoords[1];
626 args.pop_front();
627 arg = std::get<NotifyMotionArgs>(args.front());
628 ASSERT_THAT(arg,
629 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
630 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000631 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000632 PointerCoords finger2Start = arg.pointerCoords[2];
633 args.pop_front();
634
635 arg = std::get<NotifyMotionArgs>(args.front());
636 ASSERT_THAT(arg,
637 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000638 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000639 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
640 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
641 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
642 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
643 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
644 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
645
646 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
647 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000648 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000649 ASSERT_EQ(1u, args.size());
650 arg = std::get<NotifyMotionArgs>(args.front());
651 ASSERT_THAT(arg,
652 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000653 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700654 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000655 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
656 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
657 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
658 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
659 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
660 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
661
662 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000663 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000664 ASSERT_THAT(args,
665 ElementsAre(VariantWith<NotifyMotionArgs>(
666 AllOf(WithMotionAction(
667 AMOTION_EVENT_ACTION_POINTER_UP |
668 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000669 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000670 VariantWith<NotifyMotionArgs>(
671 AllOf(WithMotionAction(
672 AMOTION_EVENT_ACTION_POINTER_UP |
673 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000674 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000675 VariantWith<NotifyMotionArgs>(
676 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +0000677 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000678 VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000679 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700680 ASSERT_THAT(args,
681 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000682}
683
Harry Cuttsc5748d12022-12-02 17:30:18 +0000684TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
685 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
686 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700687 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000688
689 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
690 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000691 std::list<NotifyArgs> args =
692 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000693 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000694 ASSERT_THAT(args,
695 Each(VariantWith<NotifyMotionArgs>(
696 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
697 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700698 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000699
700 // Four fake fingers should be created. We don't actually care where they are, so long as they
701 // move appropriately.
702 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
703 ASSERT_THAT(arg,
704 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000705 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000706 PointerCoords finger0Start = arg.pointerCoords[0];
707 args.pop_front();
708 arg = std::get<NotifyMotionArgs>(args.front());
709 ASSERT_THAT(arg,
710 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
711 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000712 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000713 PointerCoords finger1Start = arg.pointerCoords[1];
714 args.pop_front();
715 arg = std::get<NotifyMotionArgs>(args.front());
716 ASSERT_THAT(arg,
717 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
718 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000719 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000720 PointerCoords finger2Start = arg.pointerCoords[2];
721 args.pop_front();
722 arg = std::get<NotifyMotionArgs>(args.front());
723 ASSERT_THAT(arg,
724 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
725 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000726 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000727 PointerCoords finger3Start = arg.pointerCoords[3];
728 args.pop_front();
729
730 arg = std::get<NotifyMotionArgs>(args.front());
731 ASSERT_THAT(arg,
732 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000733 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000734 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
735 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
736 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
737 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
738 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
739 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
740 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
741 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
742
743 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
744 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000745 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000746 ASSERT_EQ(1u, args.size());
747 arg = std::get<NotifyMotionArgs>(args.front());
748 ASSERT_THAT(arg,
749 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000750 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000751 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000752 WithPointerCount(4u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700753 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000754 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
755 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
756 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
757 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
758 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
759 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
760 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
761 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
762
763 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000764 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000765 ASSERT_THAT(args,
766 ElementsAre(VariantWith<NotifyMotionArgs>(
767 AllOf(WithMotionAction(
768 AMOTION_EVENT_ACTION_POINTER_UP |
769 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
770 WithGestureOffset(0, 0, EPSILON),
771 WithGestureSwipeFingerCount(4),
772 WithMotionClassification(
773 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000774 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000775 VariantWith<NotifyMotionArgs>(
776 AllOf(WithMotionAction(
777 AMOTION_EVENT_ACTION_POINTER_UP |
778 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
779 WithGestureOffset(0, 0, EPSILON),
780 WithGestureSwipeFingerCount(4),
781 WithMotionClassification(
782 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000783 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000784 VariantWith<NotifyMotionArgs>(
785 AllOf(WithMotionAction(
786 AMOTION_EVENT_ACTION_POINTER_UP |
787 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
788 WithGestureOffset(0, 0, EPSILON),
789 WithGestureSwipeFingerCount(4),
790 WithMotionClassification(
791 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000792 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000793 VariantWith<NotifyMotionArgs>(
794 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
795 WithGestureOffset(0, 0, EPSILON),
796 WithGestureSwipeFingerCount(4),
797 WithMotionClassification(
798 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000799 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000800 VariantWith<NotifyMotionArgs>(
801 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000802 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000803 WithMotionClassification(MotionClassification::NONE)))));
804 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700805 Each(VariantWith<NotifyMotionArgs>(
806 AllOf(WithToolType(ToolType::FINGER),
807 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000808}
809
Harry Cuttsb1e83552022-12-20 11:02:26 +0000810TEST_F(GestureConverterTest, Pinch_Inwards) {
811 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
812 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700813 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000814
815 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
816 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000817 std::list<NotifyArgs> args =
818 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000819 ASSERT_THAT(args,
820 ElementsAre(VariantWith<NotifyMotionArgs>(
821 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000822 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000823 VariantWith<NotifyMotionArgs>(
824 AllOf(WithMotionAction(
825 AMOTION_EVENT_ACTION_POINTER_DOWN |
826 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000827 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
Harry Cuttsef95e712024-02-16 18:56:39 +0000828 ASSERT_THAT(args,
829 Each(VariantWith<NotifyMotionArgs>(
830 AllOf(WithMotionClassification(MotionClassification::PINCH),
831 WithGesturePinchScaleFactor(1.0f, EPSILON),
832 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700833 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000834
835 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
836 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000837 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000838 ASSERT_THAT(args,
839 ElementsAre(VariantWith<NotifyMotionArgs>(
840 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
841 WithMotionClassification(MotionClassification::PINCH),
842 WithGesturePinchScaleFactor(0.8f, EPSILON),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000843 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000844 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700845 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000846
847 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
848 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000849 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000850 ASSERT_THAT(args,
851 ElementsAre(VariantWith<NotifyMotionArgs>(
852 AllOf(WithMotionAction(
853 AMOTION_EVENT_ACTION_POINTER_UP |
854 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
855 WithMotionClassification(MotionClassification::PINCH),
856 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000857 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000858 VariantWith<NotifyMotionArgs>(
859 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
860 WithMotionClassification(MotionClassification::PINCH),
861 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000862 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000863 VariantWith<NotifyMotionArgs>(
864 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000865 WithCoords(0, 0),
866 WithMotionClassification(MotionClassification::NONE)))));
867 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700868 Each(VariantWith<NotifyMotionArgs>(
869 AllOf(WithToolType(ToolType::FINGER),
870 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000871}
872
873TEST_F(GestureConverterTest, Pinch_Outwards) {
874 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
875 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700876 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhan8b053512024-05-03 23:15:39 +0000877
878 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
879 GESTURES_ZOOM_START);
880 std::list<NotifyArgs> args =
881 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
882 ASSERT_THAT(args,
883 ElementsAre(VariantWith<NotifyMotionArgs>(
884 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
885 WithCoords(-100, 0), WithPointerCount(1u))),
886 VariantWith<NotifyMotionArgs>(
887 AllOf(WithMotionAction(
888 AMOTION_EVENT_ACTION_POINTER_DOWN |
889 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
890 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
891 ASSERT_THAT(args,
892 Each(VariantWith<NotifyMotionArgs>(
893 AllOf(WithMotionClassification(MotionClassification::PINCH),
894 WithGesturePinchScaleFactor(1.0f, EPSILON),
895 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700896 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000897
898 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
899 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
900 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
901 ASSERT_THAT(args,
902 ElementsAre(VariantWith<NotifyMotionArgs>(
903 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
904 WithMotionClassification(MotionClassification::PINCH),
905 WithGesturePinchScaleFactor(1.1f, EPSILON),
906 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
907 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700908 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000909
910 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
911 GESTURES_ZOOM_END);
912 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
913 ASSERT_THAT(args,
914 ElementsAre(VariantWith<NotifyMotionArgs>(
915 AllOf(WithMotionAction(
916 AMOTION_EVENT_ACTION_POINTER_UP |
917 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
918 WithMotionClassification(MotionClassification::PINCH),
919 WithGesturePinchScaleFactor(1.0f, EPSILON),
920 WithPointerCount(2u))),
921 VariantWith<NotifyMotionArgs>(
922 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
923 WithMotionClassification(MotionClassification::PINCH),
924 WithGesturePinchScaleFactor(1.0f, EPSILON),
925 WithPointerCount(1u))),
926 VariantWith<NotifyMotionArgs>(
927 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
928 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000929 WithMotionClassification(MotionClassification::NONE)))));
930 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700931 Each(VariantWith<NotifyMotionArgs>(
932 AllOf(WithToolType(ToolType::FINGER),
933 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000934}
935
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000936TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000937 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
938 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700939 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000940
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000941 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000942 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000943 std::list<NotifyArgs> args =
944 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000945
946 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000947 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000948 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000949
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000950 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000951 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000952 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000953
954 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000955 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000956 ASSERT_THAT(args,
957 ElementsAre(VariantWith<NotifyMotionArgs>(
958 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000959}
960
961TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
962 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
963 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700964 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000965
966 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
967 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000968 std::list<NotifyArgs> args =
969 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000970
971 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
972 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000973 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000974
975 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
976 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000977 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000978
979 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
980 // need to use another gesture type, like scroll.
981 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
982 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000983 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000984 ASSERT_FALSE(args.empty());
985 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000986}
987
Harry Cuttse9b71422023-03-14 16:54:44 +0000988TEST_F(GestureConverterTest, ResetWithButtonPressed) {
989 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
990 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700991 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000992
993 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
994 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
995 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000996 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +0000997
998 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +0000999 ASSERT_THAT(args,
1000 ElementsAre(VariantWith<NotifyMotionArgs>(
1001 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1002 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001003 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001004 VariantWith<NotifyMotionArgs>(
1005 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1006 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001007 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001008 VariantWith<NotifyMotionArgs>(
1009 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001010 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001011 VariantWith<NotifyMotionArgs>(
1012 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001013 WithButtonState(0)))));
1014 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001015 Each(VariantWith<NotifyMotionArgs>(
1016 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
1017 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001018}
1019
1020TEST_F(GestureConverterTest, ResetDuringScroll) {
1021 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1022 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001023 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001024
1025 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001026 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001027
1028 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001029 ASSERT_THAT(args,
1030 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001031 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001032 WithCoords(0, -10),
Harry Cutts379ea422023-12-21 15:31:47 +00001033 WithGestureScrollDistance(0, 0, EPSILON),
1034 WithMotionClassification(
1035 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001036 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001037 VariantWith<NotifyMotionArgs>(
1038 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001039 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001040 WithMotionClassification(MotionClassification::NONE)))));
1041 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001042 Each(VariantWith<NotifyMotionArgs>(
1043 AllOf(WithToolType(ToolType::FINGER),
1044 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001045}
1046
1047TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1048 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1049 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001050 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001051
1052 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1053 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001054 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001055
1056 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001057 ASSERT_THAT(args,
1058 ElementsAre(VariantWith<NotifyMotionArgs>(
1059 AllOf(WithMotionAction(
1060 AMOTION_EVENT_ACTION_POINTER_UP |
1061 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1062 WithGestureOffset(0, 0, EPSILON),
1063 WithMotionClassification(
1064 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001065 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001066 VariantWith<NotifyMotionArgs>(
1067 AllOf(WithMotionAction(
1068 AMOTION_EVENT_ACTION_POINTER_UP |
1069 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1070 WithGestureOffset(0, 0, EPSILON),
1071 WithMotionClassification(
1072 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001073 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001074 VariantWith<NotifyMotionArgs>(
1075 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1076 WithGestureOffset(0, 0, EPSILON),
1077 WithMotionClassification(
1078 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001079 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001080 VariantWith<NotifyMotionArgs>(
1081 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001082 WithMotionClassification(MotionClassification::NONE)))));
1083 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001084 Each(VariantWith<NotifyMotionArgs>(
1085 AllOf(WithToolType(ToolType::FINGER),
1086 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001087}
1088
1089TEST_F(GestureConverterTest, ResetDuringPinch) {
1090 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1091 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001092 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001093
1094 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1095 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001096 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001097
1098 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001099 ASSERT_THAT(args,
1100 ElementsAre(VariantWith<NotifyMotionArgs>(
1101 AllOf(WithMotionAction(
1102 AMOTION_EVENT_ACTION_POINTER_UP |
1103 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1104 WithMotionClassification(MotionClassification::PINCH),
1105 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001106 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001107 VariantWith<NotifyMotionArgs>(
1108 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1109 WithMotionClassification(MotionClassification::PINCH),
1110 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001111 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001112 VariantWith<NotifyMotionArgs>(
1113 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001114 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001115 WithMotionClassification(MotionClassification::NONE)))));
1116 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001117 Each(VariantWith<NotifyMotionArgs>(
1118 AllOf(WithToolType(ToolType::FINGER),
1119 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001120}
1121
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001122TEST_F(GestureConverterTest, FlingTapDown) {
1123 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1124 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001125 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001126
1127 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1128 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001129 std::list<NotifyArgs> args =
1130 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001131
1132 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001133 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
1134 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001135 WithButtonState(0), WithPressure(0.0f),
1136 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001137}
1138
Harry Cutts39648ab2024-02-15 14:23:50 +00001139TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1140 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1141 input_flags::enable_touchpad_fling_stop(true);
1142 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001143 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts39648ab2024-02-15 14:23:50 +00001144
1145 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1146 std::list<NotifyArgs> args =
1147 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1148 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1149 GESTURES_FLING_START);
1150 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1151
1152 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1153 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1154 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1155 ASSERT_THAT(args,
1156 ElementsAre(VariantWith<NotifyMotionArgs>(
1157 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1158 VariantWith<NotifyMotionArgs>(
1159 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1160 VariantWith<NotifyMotionArgs>(
1161 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1162 VariantWith<NotifyMotionArgs>(
Harry Cutts574781a2024-04-23 15:30:45 +00001163 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001164 ASSERT_THAT(args,
Harry Cutts574781a2024-04-23 15:30:45 +00001165 Each(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +00001166 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001167 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
Harry Cutts574781a2024-04-23 15:30:45 +00001168 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE)))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001169}
1170
Arpit Singha5ea7c12023-07-05 15:39:25 +00001171TEST_F(GestureConverterTest, Tap) {
1172 // Tap should produce button press/release events
1173 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1174 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001175 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001176
1177 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1178 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001179 std::list<NotifyArgs> args =
1180 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001181 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001182
1183 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1184 /* down= */ GESTURES_BUTTON_LEFT,
1185 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001186 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001187
Harry Cutts5f26e952023-11-30 18:20:27 +00001188 ASSERT_THAT(args,
1189 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001190 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001191 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001192 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001193 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001194 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001195 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001196 VariantWith<NotifyMotionArgs>(
1197 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1198 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1199 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001200 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001201 VariantWith<NotifyMotionArgs>(
1202 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1203 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001204 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001205 VariantWith<NotifyMotionArgs>(
1206 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001207 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001208 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001209 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001210 WithButtonState(0), WithPressure(0.0f)))));
1211 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001212 Each(VariantWith<NotifyMotionArgs>(
1213 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1214 WithToolType(ToolType::FINGER),
1215 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001216}
1217
1218TEST_F(GestureConverterTest, Click) {
1219 // Click should produce button press/release events
1220 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1221 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001222 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001223
1224 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1225 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001226 std::list<NotifyArgs> args =
1227 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001228 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001229
1230 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1231 /* down= */ GESTURES_BUTTON_LEFT,
1232 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001233 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001234
Harry Cutts5f26e952023-11-30 18:20:27 +00001235 ASSERT_THAT(args,
1236 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001237 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001238 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001239 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001240 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001241 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001242 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001243 VariantWith<NotifyMotionArgs>(
1244 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1245 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1246 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001247 WithPressure(1.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 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1255 /* down= */ GESTURES_BUTTON_NONE,
1256 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001257 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Prabir Pradhan8b053512024-05-03 23:15:39 +00001258
Harry Cutts5f26e952023-11-30 18:20:27 +00001259 ASSERT_THAT(args,
1260 ElementsAre(VariantWith<NotifyMotionArgs>(
1261 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1262 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001263 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001264 VariantWith<NotifyMotionArgs>(
1265 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001266 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001267 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001268 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001269 WithPressure(0.0f)))));
1270 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001271 Each(VariantWith<NotifyMotionArgs>(
1272 AllOf(WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1273 WithToolType(ToolType::FINGER),
1274 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001275}
1276
Arpit Singh3d84add2023-10-10 19:08:29 +00001277TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001278 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1279 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1280 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1281
Arpit Singha5ea7c12023-07-05 15:39:25 +00001282 // Tap should be ignored when disabled
1283 mReader->getContext()->setPreventingTouchpadTaps(true);
1284
1285 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1286 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001287 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001288
Arpit Singh82b27a02023-10-16 11:02:19 +00001289 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001290 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001291 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001292 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001293 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001294
Arpit Singh82b27a02023-10-16 11:02:19 +00001295 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001296 /* down= */ GESTURES_BUTTON_LEFT,
1297 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001298 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001299
1300 // no events should be generated
1301 ASSERT_EQ(0u, args.size());
1302
1303 // Future taps should be re-enabled
1304 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1305}
1306
Arpit Singh82b27a02023-10-16 11:02:19 +00001307TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1308 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1309 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1310
1311 // Tap should be ignored when disabled
1312 mReader->getContext()->setPreventingTouchpadTaps(true);
1313
1314 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1315 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001316 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh82b27a02023-10-16 11:02:19 +00001317
1318 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1319 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1320 std::list<NotifyArgs> args =
1321 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001322 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001323
1324 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1325 /* down= */ GESTURES_BUTTON_LEFT,
1326 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1327 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1328
1329 // no events should be generated
1330 ASSERT_EQ(0u, args.size());
1331
1332 // Future taps should be re-enabled
1333 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1334
1335 // taps before the threshold should still be ignored
1336 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1337 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1338 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1339 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1340
1341 ASSERT_EQ(1u, args.size());
1342 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1343 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1344
1345 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1346 /* down= */ GESTURES_BUTTON_LEFT,
1347 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1348 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1349
1350 // no events should be generated
1351 ASSERT_EQ(0u, args.size());
1352
1353 // taps after the threshold should be recognised
1354 currentTime += 1;
1355 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1356 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1357 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1358
1359 ASSERT_EQ(1u, args.size());
1360 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1361 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1362
1363 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1364 /* down= */ GESTURES_BUTTON_LEFT,
1365 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1366 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001367 ASSERT_THAT(args,
1368 ElementsAre(VariantWith<NotifyMotionArgs>(
1369 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1370 WithButtonState(0))),
1371 VariantWith<NotifyMotionArgs>(
1372 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1373 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1374 VariantWith<NotifyMotionArgs>(
1375 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1376 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1377 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1378 VariantWith<NotifyMotionArgs>(
1379 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1380 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1381 WithButtonState(0))),
1382 VariantWith<NotifyMotionArgs>(
1383 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1384 WithButtonState(0))),
1385 VariantWith<NotifyMotionArgs>(
1386 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1387 WithButtonState(0)))));
1388 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001389}
1390
Arpit Singh3d84add2023-10-10 19:08:29 +00001391TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1392 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001393 // Click should still produce button press/release events
1394 mReader->getContext()->setPreventingTouchpadTaps(true);
1395
1396 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1397 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001398 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001399
1400 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1401 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001402 std::list<NotifyArgs> args =
1403 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001404 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001405
1406 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1407 /* down= */ GESTURES_BUTTON_LEFT,
1408 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001409 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001410
Harry Cutts5f26e952023-11-30 18:20:27 +00001411 ASSERT_THAT(args,
1412 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001413 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001414 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001415 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001416 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001417 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001418 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001419 VariantWith<NotifyMotionArgs>(
1420 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1421 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1422 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001423 WithPressure(1.0f)))));
1424 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001425 Each(VariantWith<NotifyMotionArgs>(
1426 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1427 WithToolType(ToolType::FINGER),
1428 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001429
1430 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1431 /* down= */ GESTURES_BUTTON_NONE,
1432 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001433 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001434
Harry Cutts5f26e952023-11-30 18:20:27 +00001435 ASSERT_THAT(args,
1436 ElementsAre(VariantWith<NotifyMotionArgs>(
1437 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1438 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1439 WithButtonState(0), WithCoords(0, 0),
1440 WithRelativeMotion(0.f, 0.f),
1441 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001442 WithPressure(1.0f),
1443 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001444 VariantWith<NotifyMotionArgs>(
1445 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1446 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1447 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001448 WithPressure(0.0f),
1449 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001450 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001451 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001452 WithCoords(0, 0), WithRelativeMotion(0, 0),
1453 WithToolType(ToolType::FINGER), WithButtonState(0),
1454 WithPressure(0.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001455 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001456
1457 // Future taps should be re-enabled
1458 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1459}
1460
Prabir Pradhan8b053512024-05-03 23:15:39 +00001461TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
Byoungho Jungee6268f2023-10-30 17:27:26 +09001462 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
1463 // initially disable tap-to-click
1464 mReader->getContext()->setPreventingTouchpadTaps(true);
1465
1466 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1467 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001468 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001469
1470 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001471 std::list<NotifyArgs> args =
1472 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001473 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001474
1475 // Future taps should be re-enabled
1476 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1477}
1478
Prabir Pradhan8b053512024-05-03 23:15:39 +00001479TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
Arpit Singh33a10a62023-10-12 13:06:54 +00001480 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1481 const nsecs_t gestureStartTime = 1000;
1482 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1483 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001484 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh33a10a62023-10-12 13:06:54 +00001485
1486 // Start a move gesture at gestureStartTime
1487 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1488 std::list<NotifyArgs> args =
1489 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001490 ASSERT_THAT(args,
1491 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001492 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1493 VariantWith<NotifyMotionArgs>(
1494 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001495
1496 // Key presses with IME connection should cancel ongoing move gesture
1497 nsecs_t currentTime = gestureStartTime + 100;
1498 mFakePolicy->setIsInputMethodConnectionActive(true);
1499 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1500 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1501 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001502 ASSERT_THAT(args,
1503 ElementsAre(VariantWith<NotifyMotionArgs>(
1504 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001505
1506 // any updates in existing move gesture should be ignored
1507 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1508 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1509 ASSERT_EQ(0u, args.size());
1510
1511 // New gesture should not be affected
1512 currentTime += 100;
1513 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1514 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001515 ASSERT_THAT(args,
1516 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001517 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1518 VariantWith<NotifyMotionArgs>(
1519 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001520}
1521
Harry Cutts4fb941a2022-12-14 19:14:04 +00001522} // namespace android