blob: 225ae0f67c5df75560f2d0910089315276feebd0 [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) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900282 input_flags::enable_touchpad_no_focus_change(true);
283
Harry Cuttsef400b22022-12-16 21:26:24 +0000284 const nsecs_t downTime = 12345;
285 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
286 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700287 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000288
Harry Cuttsa546ba82023-01-13 17:21:00 +0000289 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000290 std::list<NotifyArgs> args =
291 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000292 ASSERT_THAT(args,
293 ElementsAre(VariantWith<NotifyMotionArgs>(
294 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000295 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000296 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000297 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000298 VariantWith<NotifyMotionArgs>(
299 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000300 WithCoords(0, -10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000301 WithGestureScrollDistance(0, 10, EPSILON)))));
302 ASSERT_THAT(args,
303 Each(VariantWith<NotifyMotionArgs>(
304 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900305 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
306 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000307 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700308 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000309
Harry Cuttsa546ba82023-01-13 17:21:00 +0000310 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000311 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000312 ASSERT_THAT(args,
313 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000314 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
Harry Cutts5f26e952023-11-30 18:20:27 +0000315 WithGestureScrollDistance(0, 5, EPSILON),
316 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
317 WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900318 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
319 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700320 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000321
322 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
323 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000324 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000325 ASSERT_THAT(args,
326 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000327 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000328 WithCoords(0, -15),
Harry Cutts379ea422023-12-21 15:31:47 +0000329 WithGestureScrollDistance(0, 0, EPSILON),
330 WithMotionClassification(
331 MotionClassification::TWO_FINGER_SWIPE),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900332 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
333 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000334 VariantWith<NotifyMotionArgs>(
335 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000336 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000337 WithMotionClassification(MotionClassification::NONE)))));
338 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700339 Each(VariantWith<NotifyMotionArgs>(
340 AllOf(WithToolType(ToolType::FINGER),
341 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000342}
343
344TEST_F(GestureConverterTest, Scroll_Rotated) {
345 const nsecs_t downTime = 12345;
346 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
347 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
348 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700349 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000350
Harry Cuttsa546ba82023-01-13 17:21:00 +0000351 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000352 std::list<NotifyArgs> args =
353 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000354 ASSERT_THAT(args,
355 ElementsAre(VariantWith<NotifyMotionArgs>(
356 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000357 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000358 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000359 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000360 VariantWith<NotifyMotionArgs>(
361 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000362 WithCoords(-10, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000363 WithGestureScrollDistance(0, 10, EPSILON)))));
364 ASSERT_THAT(args,
365 Each(VariantWith<NotifyMotionArgs>(
366 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
367 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700368 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000369
Harry Cuttsa546ba82023-01-13 17:21:00 +0000370 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000371 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000372 ASSERT_THAT(args,
373 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000374 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000375 WithGestureScrollDistance(0, 5, EPSILON),
376 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
377 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700378 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000379
Harry Cuttsef400b22022-12-16 21:26:24 +0000380 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
381 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000382 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000383 ASSERT_THAT(args,
384 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000385 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000386 WithCoords(-15, 0),
Harry Cutts379ea422023-12-21 15:31:47 +0000387 WithGestureScrollDistance(0, 0, EPSILON),
388 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +0000389 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000390 VariantWith<NotifyMotionArgs>(
391 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000392 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000393 WithMotionClassification(MotionClassification::NONE)))));
394 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700395 Each(VariantWith<NotifyMotionArgs>(
396 AllOf(WithToolType(ToolType::FINGER),
397 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000398}
399
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000400TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000401 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
402 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700403 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000404
Harry Cuttsa546ba82023-01-13 17:21:00 +0000405 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000406 std::list<NotifyArgs> args =
407 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000408
Harry Cuttsa546ba82023-01-13 17:21:00 +0000409 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000410 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000411
412 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
413 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000414 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000415
416 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000417 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000418 ASSERT_THAT(args,
419 ElementsAre(VariantWith<NotifyMotionArgs>(
420 AllOf(WithMotionClassification(MotionClassification::NONE),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700421 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000422}
423
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000424TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000425 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
426 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700427 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000428
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000429 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000430 std::list<NotifyArgs> args =
431 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000432
433 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000434 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000435
436 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
437 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000438 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000439
440 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
441 // need to use another gesture type, like pinch.
442 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
443 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000444 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000445 ASSERT_FALSE(args.empty());
446 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
447}
448
Prabir Pradhan13acbd22024-05-14 22:36:40 +0000449TEST_F(GestureConverterTest, Scroll_ClearsFakeFingerPositionOnSubsequentScrollGestures) {
450 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
451 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
452 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
453
454 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 15, -10);
455 std::list<NotifyArgs> args =
456 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
457
458 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -2, -5);
459 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
460
461 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
462 GESTURES_FLING_START);
463 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
464 Gesture flingGestureEnd(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, 0,
465 GESTURES_FLING_TAP_DOWN);
466 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGestureEnd);
467
468 // Start a second scoll gesture, and ensure the fake finger is reset to (0, 0), instead of
469 // continuing from the position where the last scroll gesture's fake finger ended.
470 Gesture secondScrollStart(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 2,
471 14);
472 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, secondScrollStart);
473 ASSERT_THAT(args,
474 ElementsAre(VariantWith<NotifyMotionArgs>(
475 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
476 VariantWith<NotifyMotionArgs>(
477 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
478 WithCoords(0, 0),
479 WithGestureScrollDistance(0, 0, EPSILON))),
480 VariantWith<NotifyMotionArgs>(
481 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
482 WithCoords(2, 14),
483 WithGestureScrollDistance(-2, -14, EPSILON)))));
484}
485
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000486TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
487 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
488 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700489 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000490
491 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
492 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000493 std::list<NotifyArgs> args =
494 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000495
496 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000497 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000498
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000499 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
500 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000501 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000502 ASSERT_THAT(args,
503 ElementsAre(VariantWith<NotifyMotionArgs>(
504 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000505}
506
Harry Cutts8743f182023-05-17 12:03:49 +0000507TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000508 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
509 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700510 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000511
512 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
513 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000514 std::list<NotifyArgs> args =
515 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000516
517 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000518 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000519
520 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
521 // need to use another gesture type, like pinch.
522 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
523 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000524 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000525 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000526 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
527 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000528}
529
530TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
531 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
532 // start swiping up and then start moving left or right, it'll return gesture events with only Y
533 // deltas until you lift your fingers and start swiping again. That's why each of these tests
534 // only checks movement in one dimension.
535 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
536 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700537 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000538
539 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
540 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000541 std::list<NotifyArgs> args =
542 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000543 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000544 ASSERT_THAT(args,
545 Each(VariantWith<NotifyMotionArgs>(
546 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
547 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700548 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000549
550 // Three fake fingers should be created. We don't actually care where they are, so long as they
551 // move appropriately.
552 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
553 ASSERT_THAT(arg,
554 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000555 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000556 PointerCoords finger0Start = arg.pointerCoords[0];
557 args.pop_front();
558 arg = std::get<NotifyMotionArgs>(args.front());
559 ASSERT_THAT(arg,
560 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
561 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000562 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000563 PointerCoords finger1Start = arg.pointerCoords[1];
564 args.pop_front();
565 arg = std::get<NotifyMotionArgs>(args.front());
566 ASSERT_THAT(arg,
567 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
568 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000569 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000570 PointerCoords finger2Start = arg.pointerCoords[2];
571 args.pop_front();
572
573 arg = std::get<NotifyMotionArgs>(args.front());
574 ASSERT_THAT(arg,
575 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000576 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000577 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
578 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
579 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
580 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
581 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
582 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
583
584 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
585 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000586 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000587 ASSERT_EQ(1u, args.size());
588 arg = std::get<NotifyMotionArgs>(args.front());
589 ASSERT_THAT(arg,
590 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000591 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000592 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000593 WithPointerCount(3u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700594 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000595 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
596 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
597 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
598 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
599 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
600 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
601
602 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000603 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000604 ASSERT_THAT(args,
605 ElementsAre(VariantWith<NotifyMotionArgs>(
606 AllOf(WithMotionAction(
607 AMOTION_EVENT_ACTION_POINTER_UP |
608 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
609 WithGestureOffset(0, 0, EPSILON),
610 WithGestureSwipeFingerCount(3),
611 WithMotionClassification(
612 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000613 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000614 VariantWith<NotifyMotionArgs>(
615 AllOf(WithMotionAction(
616 AMOTION_EVENT_ACTION_POINTER_UP |
617 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
618 WithGestureOffset(0, 0, EPSILON),
619 WithGestureSwipeFingerCount(3),
620 WithMotionClassification(
621 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000622 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000623 VariantWith<NotifyMotionArgs>(
624 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
625 WithGestureOffset(0, 0, EPSILON),
626 WithGestureSwipeFingerCount(3),
627 WithMotionClassification(
628 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000629 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000630 VariantWith<NotifyMotionArgs>(
631 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000632 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000633 WithMotionClassification(MotionClassification::NONE)))));
634 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700635 Each(VariantWith<NotifyMotionArgs>(
636 AllOf(WithToolType(ToolType::FINGER),
637 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000638}
639
Harry Cutts94f5bd52023-01-06 18:02:18 +0000640TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
641 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
642 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
643 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700644 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000645
646 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
647 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000648 std::list<NotifyArgs> args =
649 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000650 ASSERT_EQ(4u, args.size());
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700651 ASSERT_THAT(args,
652 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000653
654 // Three fake fingers should be created. We don't actually care where they are, so long as they
655 // move appropriately.
656 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
657 ASSERT_THAT(arg,
658 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000659 WithPointerCount(1u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000660 PointerCoords finger0Start = arg.pointerCoords[0];
661 args.pop_front();
662 arg = std::get<NotifyMotionArgs>(args.front());
663 ASSERT_THAT(arg,
664 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
665 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000666 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000667 PointerCoords finger1Start = arg.pointerCoords[1];
668 args.pop_front();
669 arg = std::get<NotifyMotionArgs>(args.front());
670 ASSERT_THAT(arg,
671 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
672 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000673 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000674 PointerCoords finger2Start = arg.pointerCoords[2];
675 args.pop_front();
676
677 arg = std::get<NotifyMotionArgs>(args.front());
678 ASSERT_THAT(arg,
679 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000680 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000681 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
682 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
683 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
684 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
685 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
686 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
687
688 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
689 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000690 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000691 ASSERT_EQ(1u, args.size());
692 arg = std::get<NotifyMotionArgs>(args.front());
693 ASSERT_THAT(arg,
694 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000695 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700696 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000697 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
698 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
699 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
700 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
701 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
702 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
703
704 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000705 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000706 ASSERT_THAT(args,
707 ElementsAre(VariantWith<NotifyMotionArgs>(
708 AllOf(WithMotionAction(
709 AMOTION_EVENT_ACTION_POINTER_UP |
710 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000711 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000712 VariantWith<NotifyMotionArgs>(
713 AllOf(WithMotionAction(
714 AMOTION_EVENT_ACTION_POINTER_UP |
715 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000716 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000717 VariantWith<NotifyMotionArgs>(
718 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +0000719 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000720 VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000721 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700722 ASSERT_THAT(args,
723 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000724}
725
Harry Cuttsc5748d12022-12-02 17:30:18 +0000726TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
727 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
728 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700729 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000730
731 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
732 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000733 std::list<NotifyArgs> args =
734 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000735 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000736 ASSERT_THAT(args,
737 Each(VariantWith<NotifyMotionArgs>(
738 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
739 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700740 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000741
742 // Four fake fingers should be created. We don't actually care where they are, so long as they
743 // move appropriately.
744 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
745 ASSERT_THAT(arg,
746 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000747 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000748 PointerCoords finger0Start = arg.pointerCoords[0];
749 args.pop_front();
750 arg = std::get<NotifyMotionArgs>(args.front());
751 ASSERT_THAT(arg,
752 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
753 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000754 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000755 PointerCoords finger1Start = arg.pointerCoords[1];
756 args.pop_front();
757 arg = std::get<NotifyMotionArgs>(args.front());
758 ASSERT_THAT(arg,
759 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
760 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000761 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000762 PointerCoords finger2Start = arg.pointerCoords[2];
763 args.pop_front();
764 arg = std::get<NotifyMotionArgs>(args.front());
765 ASSERT_THAT(arg,
766 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
767 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000768 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000769 PointerCoords finger3Start = arg.pointerCoords[3];
770 args.pop_front();
771
772 arg = std::get<NotifyMotionArgs>(args.front());
773 ASSERT_THAT(arg,
774 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000775 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000776 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
777 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
778 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
779 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
780 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
781 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
782 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
783 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
784
785 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
786 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000787 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000788 ASSERT_EQ(1u, args.size());
789 arg = std::get<NotifyMotionArgs>(args.front());
790 ASSERT_THAT(arg,
791 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000792 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000793 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000794 WithPointerCount(4u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700795 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000796 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
797 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
798 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
799 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
800 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
801 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
802 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
803 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
804
805 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000806 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000807 ASSERT_THAT(args,
808 ElementsAre(VariantWith<NotifyMotionArgs>(
809 AllOf(WithMotionAction(
810 AMOTION_EVENT_ACTION_POINTER_UP |
811 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
812 WithGestureOffset(0, 0, EPSILON),
813 WithGestureSwipeFingerCount(4),
814 WithMotionClassification(
815 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000816 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000817 VariantWith<NotifyMotionArgs>(
818 AllOf(WithMotionAction(
819 AMOTION_EVENT_ACTION_POINTER_UP |
820 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
821 WithGestureOffset(0, 0, EPSILON),
822 WithGestureSwipeFingerCount(4),
823 WithMotionClassification(
824 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000825 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000826 VariantWith<NotifyMotionArgs>(
827 AllOf(WithMotionAction(
828 AMOTION_EVENT_ACTION_POINTER_UP |
829 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
830 WithGestureOffset(0, 0, EPSILON),
831 WithGestureSwipeFingerCount(4),
832 WithMotionClassification(
833 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000834 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000835 VariantWith<NotifyMotionArgs>(
836 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
837 WithGestureOffset(0, 0, EPSILON),
838 WithGestureSwipeFingerCount(4),
839 WithMotionClassification(
840 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000841 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000842 VariantWith<NotifyMotionArgs>(
843 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000844 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000845 WithMotionClassification(MotionClassification::NONE)))));
846 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700847 Each(VariantWith<NotifyMotionArgs>(
848 AllOf(WithToolType(ToolType::FINGER),
849 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000850}
851
Harry Cuttsb1e83552022-12-20 11:02:26 +0000852TEST_F(GestureConverterTest, Pinch_Inwards) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900853 input_flags::enable_touchpad_no_focus_change(true);
854
Harry Cuttsb1e83552022-12-20 11:02:26 +0000855 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
856 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700857 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000858
859 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
860 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000861 std::list<NotifyArgs> args =
862 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000863 ASSERT_THAT(args,
864 ElementsAre(VariantWith<NotifyMotionArgs>(
865 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000866 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000867 VariantWith<NotifyMotionArgs>(
868 AllOf(WithMotionAction(
869 AMOTION_EVENT_ACTION_POINTER_DOWN |
870 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000871 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
Harry Cuttsef95e712024-02-16 18:56:39 +0000872 ASSERT_THAT(args,
873 Each(VariantWith<NotifyMotionArgs>(
874 AllOf(WithMotionClassification(MotionClassification::PINCH),
875 WithGesturePinchScaleFactor(1.0f, EPSILON),
876 WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900877 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
878 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000879
880 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
881 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000882 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000883 ASSERT_THAT(args,
884 ElementsAre(VariantWith<NotifyMotionArgs>(
885 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
886 WithMotionClassification(MotionClassification::PINCH),
887 WithGesturePinchScaleFactor(0.8f, EPSILON),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000888 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000889 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900890 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
891 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000892
893 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
894 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000895 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000896 ASSERT_THAT(args,
897 ElementsAre(VariantWith<NotifyMotionArgs>(
898 AllOf(WithMotionAction(
899 AMOTION_EVENT_ACTION_POINTER_UP |
900 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
901 WithMotionClassification(MotionClassification::PINCH),
902 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900903 WithPointerCount(2u),
904 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000905 VariantWith<NotifyMotionArgs>(
906 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
907 WithMotionClassification(MotionClassification::PINCH),
908 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900909 WithPointerCount(1u),
910 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000911 VariantWith<NotifyMotionArgs>(
912 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000913 WithCoords(0, 0),
914 WithMotionClassification(MotionClassification::NONE)))));
915 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700916 Each(VariantWith<NotifyMotionArgs>(
917 AllOf(WithToolType(ToolType::FINGER),
918 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000919}
920
921TEST_F(GestureConverterTest, Pinch_Outwards) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900922 input_flags::enable_touchpad_no_focus_change(true);
923
Prabir Pradhan8b053512024-05-03 23:15:39 +0000924 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
925 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700926 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhan8b053512024-05-03 23:15:39 +0000927
928 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
929 GESTURES_ZOOM_START);
930 std::list<NotifyArgs> args =
931 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
932 ASSERT_THAT(args,
933 ElementsAre(VariantWith<NotifyMotionArgs>(
934 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
935 WithCoords(-100, 0), WithPointerCount(1u))),
936 VariantWith<NotifyMotionArgs>(
937 AllOf(WithMotionAction(
938 AMOTION_EVENT_ACTION_POINTER_DOWN |
939 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
940 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
941 ASSERT_THAT(args,
942 Each(VariantWith<NotifyMotionArgs>(
943 AllOf(WithMotionClassification(MotionClassification::PINCH),
944 WithGesturePinchScaleFactor(1.0f, EPSILON),
945 WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900946 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
947 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000948
949 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
950 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
951 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
952 ASSERT_THAT(args,
953 ElementsAre(VariantWith<NotifyMotionArgs>(
954 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
955 WithMotionClassification(MotionClassification::PINCH),
956 WithGesturePinchScaleFactor(1.1f, EPSILON),
957 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
958 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900959 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
960 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000961
962 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
963 GESTURES_ZOOM_END);
964 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
965 ASSERT_THAT(args,
966 ElementsAre(VariantWith<NotifyMotionArgs>(
967 AllOf(WithMotionAction(
968 AMOTION_EVENT_ACTION_POINTER_UP |
969 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
970 WithMotionClassification(MotionClassification::PINCH),
971 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900972 WithPointerCount(2u),
973 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000974 VariantWith<NotifyMotionArgs>(
975 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
976 WithMotionClassification(MotionClassification::PINCH),
977 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900978 WithPointerCount(1u),
979 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000980 VariantWith<NotifyMotionArgs>(
981 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
982 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000983 WithMotionClassification(MotionClassification::NONE)))));
984 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700985 Each(VariantWith<NotifyMotionArgs>(
986 AllOf(WithToolType(ToolType::FINGER),
987 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000988}
989
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000990TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000991 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
992 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700993 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000994
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000995 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000996 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000997 std::list<NotifyArgs> args =
998 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000999
1000 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001001 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001002 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001003
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001004 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001005 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001006 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001007
1008 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001009 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001010 ASSERT_THAT(args,
1011 ElementsAre(VariantWith<NotifyMotionArgs>(
1012 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001013}
1014
1015TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
1016 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1017 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001018 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001019
1020 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1021 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001022 std::list<NotifyArgs> args =
1023 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001024
1025 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1026 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001027 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001028
1029 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1030 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001031 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001032
1033 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1034 // need to use another gesture type, like scroll.
1035 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1036 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001037 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001038 ASSERT_FALSE(args.empty());
1039 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001040}
1041
Harry Cuttse9b71422023-03-14 16:54:44 +00001042TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1043 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1044 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001045 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001046
1047 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1048 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1049 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001050 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001051
1052 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001053 ASSERT_THAT(args,
1054 ElementsAre(VariantWith<NotifyMotionArgs>(
1055 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1056 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001057 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001058 VariantWith<NotifyMotionArgs>(
1059 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1060 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001061 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001062 VariantWith<NotifyMotionArgs>(
1063 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001064 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001065 VariantWith<NotifyMotionArgs>(
1066 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001067 WithButtonState(0)))));
1068 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001069 Each(VariantWith<NotifyMotionArgs>(
1070 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
1071 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001072}
1073
1074TEST_F(GestureConverterTest, ResetDuringScroll) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001075 input_flags::enable_touchpad_no_focus_change(true);
1076
Harry Cuttse9b71422023-03-14 16:54:44 +00001077 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1078 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001079 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001080
1081 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001082 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001083
1084 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001085 ASSERT_THAT(args,
1086 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001087 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001088 WithCoords(0, -10),
Harry Cutts379ea422023-12-21 15:31:47 +00001089 WithGestureScrollDistance(0, 0, EPSILON),
1090 WithMotionClassification(
1091 MotionClassification::TWO_FINGER_SWIPE),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001092 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
1093 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001094 VariantWith<NotifyMotionArgs>(
1095 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001096 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001097 WithMotionClassification(MotionClassification::NONE)))));
1098 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001099 Each(VariantWith<NotifyMotionArgs>(
1100 AllOf(WithToolType(ToolType::FINGER),
1101 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001102}
1103
1104TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1105 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1106 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001107 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001108
1109 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1110 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001111 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001112
1113 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001114 ASSERT_THAT(args,
1115 ElementsAre(VariantWith<NotifyMotionArgs>(
1116 AllOf(WithMotionAction(
1117 AMOTION_EVENT_ACTION_POINTER_UP |
1118 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1119 WithGestureOffset(0, 0, EPSILON),
1120 WithMotionClassification(
1121 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001122 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001123 VariantWith<NotifyMotionArgs>(
1124 AllOf(WithMotionAction(
1125 AMOTION_EVENT_ACTION_POINTER_UP |
1126 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1127 WithGestureOffset(0, 0, EPSILON),
1128 WithMotionClassification(
1129 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001130 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001131 VariantWith<NotifyMotionArgs>(
1132 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1133 WithGestureOffset(0, 0, EPSILON),
1134 WithMotionClassification(
1135 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001136 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001137 VariantWith<NotifyMotionArgs>(
1138 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001139 WithMotionClassification(MotionClassification::NONE)))));
1140 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001141 Each(VariantWith<NotifyMotionArgs>(
1142 AllOf(WithToolType(ToolType::FINGER),
1143 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001144}
1145
1146TEST_F(GestureConverterTest, ResetDuringPinch) {
1147 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1148 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001149 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001150
1151 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1152 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001153 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001154
1155 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001156 ASSERT_THAT(args,
1157 ElementsAre(VariantWith<NotifyMotionArgs>(
1158 AllOf(WithMotionAction(
1159 AMOTION_EVENT_ACTION_POINTER_UP |
1160 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1161 WithMotionClassification(MotionClassification::PINCH),
1162 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001163 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001164 VariantWith<NotifyMotionArgs>(
1165 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1166 WithMotionClassification(MotionClassification::PINCH),
1167 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001168 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001169 VariantWith<NotifyMotionArgs>(
1170 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001171 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001172 WithMotionClassification(MotionClassification::NONE)))));
1173 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001174 Each(VariantWith<NotifyMotionArgs>(
1175 AllOf(WithToolType(ToolType::FINGER),
1176 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001177}
1178
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001179TEST_F(GestureConverterTest, FlingTapDown) {
1180 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1181 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001182 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001183
1184 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1185 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001186 std::list<NotifyArgs> args =
1187 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001188
1189 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001190 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
1191 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001192 WithButtonState(0), WithPressure(0.0f),
1193 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001194}
1195
Harry Cutts39648ab2024-02-15 14:23:50 +00001196TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1197 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1198 input_flags::enable_touchpad_fling_stop(true);
1199 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001200 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts39648ab2024-02-15 14:23:50 +00001201
1202 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1203 std::list<NotifyArgs> args =
1204 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1205 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1206 GESTURES_FLING_START);
1207 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1208
1209 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1210 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1211 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1212 ASSERT_THAT(args,
1213 ElementsAre(VariantWith<NotifyMotionArgs>(
1214 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1215 VariantWith<NotifyMotionArgs>(
1216 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1217 VariantWith<NotifyMotionArgs>(
1218 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1219 VariantWith<NotifyMotionArgs>(
Harry Cutts574781a2024-04-23 15:30:45 +00001220 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001221 ASSERT_THAT(args,
Harry Cutts574781a2024-04-23 15:30:45 +00001222 Each(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +00001223 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001224 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
Harry Cutts574781a2024-04-23 15:30:45 +00001225 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE)))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001226}
1227
Arpit Singha5ea7c12023-07-05 15:39:25 +00001228TEST_F(GestureConverterTest, Tap) {
1229 // Tap should produce button press/release events
1230 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1231 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001232 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001233
1234 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1235 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001236 std::list<NotifyArgs> args =
1237 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001238 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001239
1240 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1241 /* down= */ GESTURES_BUTTON_LEFT,
1242 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001243 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001244
Harry Cutts5f26e952023-11-30 18:20:27 +00001245 ASSERT_THAT(args,
1246 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001247 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001248 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001249 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001250 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001251 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001252 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001253 VariantWith<NotifyMotionArgs>(
1254 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1255 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1256 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001257 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001258 VariantWith<NotifyMotionArgs>(
1259 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1260 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001261 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001262 VariantWith<NotifyMotionArgs>(
1263 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001264 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001265 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001266 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001267 WithButtonState(0), WithPressure(0.0f)))));
1268 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001269 Each(VariantWith<NotifyMotionArgs>(
1270 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1271 WithToolType(ToolType::FINGER),
1272 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001273}
1274
1275TEST_F(GestureConverterTest, Click) {
1276 // Click should produce button press/release events
1277 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1278 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001279 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001280
1281 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1282 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001283 std::list<NotifyArgs> args =
1284 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001285 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001286
1287 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1288 /* down= */ GESTURES_BUTTON_LEFT,
1289 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001290 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001291
Harry Cutts5f26e952023-11-30 18:20:27 +00001292 ASSERT_THAT(args,
1293 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001294 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001295 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001296 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001297 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001298 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001299 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001300 VariantWith<NotifyMotionArgs>(
1301 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1302 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1303 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001304 WithPressure(1.0f)))));
1305 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001306 Each(VariantWith<NotifyMotionArgs>(
1307 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1308 WithToolType(ToolType::FINGER),
1309 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001310
1311 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1312 /* down= */ GESTURES_BUTTON_NONE,
1313 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001314 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Prabir Pradhan8b053512024-05-03 23:15:39 +00001315
Harry Cutts5f26e952023-11-30 18:20:27 +00001316 ASSERT_THAT(args,
1317 ElementsAre(VariantWith<NotifyMotionArgs>(
1318 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1319 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001320 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001321 VariantWith<NotifyMotionArgs>(
1322 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001323 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001324 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001325 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001326 WithPressure(0.0f)))));
1327 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001328 Each(VariantWith<NotifyMotionArgs>(
1329 AllOf(WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1330 WithToolType(ToolType::FINGER),
1331 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001332}
1333
Arpit Singh3d84add2023-10-10 19:08:29 +00001334TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001335 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1336 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1337 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1338
Arpit Singha5ea7c12023-07-05 15:39:25 +00001339 // Tap should be ignored when disabled
1340 mReader->getContext()->setPreventingTouchpadTaps(true);
1341
1342 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1343 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001344 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001345
Arpit Singh82b27a02023-10-16 11:02:19 +00001346 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001347 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001348 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001349 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001350 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001351
Arpit Singh82b27a02023-10-16 11:02:19 +00001352 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001353 /* down= */ GESTURES_BUTTON_LEFT,
1354 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001355 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001356
1357 // no events should be generated
1358 ASSERT_EQ(0u, args.size());
1359
1360 // Future taps should be re-enabled
1361 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1362}
1363
Arpit Singh82b27a02023-10-16 11:02:19 +00001364TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1365 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1366 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1367
1368 // Tap should be ignored when disabled
1369 mReader->getContext()->setPreventingTouchpadTaps(true);
1370
1371 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1372 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001373 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh82b27a02023-10-16 11:02:19 +00001374
1375 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1376 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1377 std::list<NotifyArgs> args =
1378 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001379 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001380
1381 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1382 /* down= */ GESTURES_BUTTON_LEFT,
1383 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1384 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1385
1386 // no events should be generated
1387 ASSERT_EQ(0u, args.size());
1388
1389 // Future taps should be re-enabled
1390 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1391
1392 // taps before the threshold should still be ignored
1393 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1394 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1395 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1396 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1397
1398 ASSERT_EQ(1u, args.size());
1399 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1400 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1401
1402 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1403 /* down= */ GESTURES_BUTTON_LEFT,
1404 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1405 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1406
1407 // no events should be generated
1408 ASSERT_EQ(0u, args.size());
1409
1410 // taps after the threshold should be recognised
1411 currentTime += 1;
1412 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1413 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1414 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1415
1416 ASSERT_EQ(1u, args.size());
1417 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1418 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1419
1420 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1421 /* down= */ GESTURES_BUTTON_LEFT,
1422 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1423 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001424 ASSERT_THAT(args,
1425 ElementsAre(VariantWith<NotifyMotionArgs>(
1426 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1427 WithButtonState(0))),
1428 VariantWith<NotifyMotionArgs>(
1429 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1430 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1431 VariantWith<NotifyMotionArgs>(
1432 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1433 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1434 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1435 VariantWith<NotifyMotionArgs>(
1436 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1437 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1438 WithButtonState(0))),
1439 VariantWith<NotifyMotionArgs>(
1440 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1441 WithButtonState(0))),
1442 VariantWith<NotifyMotionArgs>(
1443 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1444 WithButtonState(0)))));
1445 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001446}
1447
Arpit Singh3d84add2023-10-10 19:08:29 +00001448TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1449 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001450 // Click should still produce button press/release events
1451 mReader->getContext()->setPreventingTouchpadTaps(true);
1452
1453 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1454 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001455 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001456
1457 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1458 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001459 std::list<NotifyArgs> args =
1460 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001461 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001462
1463 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1464 /* down= */ GESTURES_BUTTON_LEFT,
1465 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001466 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001467
Harry Cutts5f26e952023-11-30 18:20:27 +00001468 ASSERT_THAT(args,
1469 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001470 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001471 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001472 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001473 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001474 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001475 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001476 VariantWith<NotifyMotionArgs>(
1477 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1478 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1479 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001480 WithPressure(1.0f)))));
1481 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001482 Each(VariantWith<NotifyMotionArgs>(
1483 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1484 WithToolType(ToolType::FINGER),
1485 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001486
1487 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1488 /* down= */ GESTURES_BUTTON_NONE,
1489 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001490 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001491
Harry Cutts5f26e952023-11-30 18:20:27 +00001492 ASSERT_THAT(args,
1493 ElementsAre(VariantWith<NotifyMotionArgs>(
1494 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1495 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1496 WithButtonState(0), WithCoords(0, 0),
1497 WithRelativeMotion(0.f, 0.f),
1498 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001499 WithPressure(1.0f),
1500 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001501 VariantWith<NotifyMotionArgs>(
1502 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1503 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1504 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001505 WithPressure(0.0f),
1506 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001507 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001508 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001509 WithCoords(0, 0), WithRelativeMotion(0, 0),
1510 WithToolType(ToolType::FINGER), WithButtonState(0),
1511 WithPressure(0.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001512 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001513
1514 // Future taps should be re-enabled
1515 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1516}
1517
Prabir Pradhan8b053512024-05-03 23:15:39 +00001518TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
Byoungho Jungee6268f2023-10-30 17:27:26 +09001519 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
1520 // initially disable tap-to-click
1521 mReader->getContext()->setPreventingTouchpadTaps(true);
1522
1523 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1524 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001525 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001526
1527 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001528 std::list<NotifyArgs> args =
1529 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001530 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001531
1532 // Future taps should be re-enabled
1533 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1534}
1535
Prabir Pradhan8b053512024-05-03 23:15:39 +00001536TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
Arpit Singh33a10a62023-10-12 13:06:54 +00001537 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1538 const nsecs_t gestureStartTime = 1000;
1539 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1540 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001541 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh33a10a62023-10-12 13:06:54 +00001542
1543 // Start a move gesture at gestureStartTime
1544 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1545 std::list<NotifyArgs> args =
1546 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001547 ASSERT_THAT(args,
1548 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001549 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1550 VariantWith<NotifyMotionArgs>(
1551 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001552
1553 // Key presses with IME connection should cancel ongoing move gesture
1554 nsecs_t currentTime = gestureStartTime + 100;
1555 mFakePolicy->setIsInputMethodConnectionActive(true);
1556 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1557 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1558 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001559 ASSERT_THAT(args,
1560 ElementsAre(VariantWith<NotifyMotionArgs>(
1561 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001562
1563 // any updates in existing move gesture should be ignored
1564 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1565 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1566 ASSERT_EQ(0u, args.size());
1567
1568 // New gesture should not be affected
1569 currentTime += 100;
1570 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1571 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001572 ASSERT_THAT(args,
1573 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001574 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1575 VariantWith<NotifyMotionArgs>(
1576 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001577}
1578
Harry Cutts4fb941a2022-12-14 19:14:04 +00001579} // namespace android