blob: fe40a5eb4dc9ccea681e01c4c85028e943ee5c09 [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;
Harry Cuttsaf66cee2024-10-28 17:34:19 +000051using testing::IsEmpty;
Harry Cutts5f26e952023-11-30 18:20:27 +000052using testing::VariantWith;
Harry Cutts4fb941a2022-12-14 19:14:04 +000053
Prabir Pradhan8b053512024-05-03 23:15:39 +000054class GestureConverterTest : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000055protected:
56 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000057 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000058 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cutts4fb941a2022-12-14 19:14:04 +000059
60 void SetUp() {
61 mFakeEventHub = std::make_unique<FakeEventHub>();
62 mFakePolicy = sp<FakeInputReaderPolicy>::make();
63 mFakeListener = std::make_unique<TestInputListener>();
64 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
65 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000066 mDevice = newDevice();
67 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
68 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000069 }
70
Harry Cuttsc5748d12022-12-02 17:30:18 +000071 std::shared_ptr<InputDevice> newDevice() {
72 InputDeviceIdentifier identifier;
73 identifier.name = "device";
74 identifier.location = "USB1";
75 identifier.bus = 0;
76 std::shared_ptr<InputDevice> device =
77 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
78 identifier);
79 mReader->pushNextDevice(device);
80 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
81 identifier.bus);
82 mReader->loopOnce();
83 return device;
84 }
85
Harry Cutts4fb941a2022-12-14 19:14:04 +000086 std::shared_ptr<FakeEventHub> mFakeEventHub;
87 sp<FakeInputReaderPolicy> mFakePolicy;
88 std::unique_ptr<TestInputListener> mFakeListener;
89 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000090 std::shared_ptr<InputDevice> mDevice;
Byoungho Jungee6268f2023-10-30 17:27:26 +090091};
92
Harry Cutts4fb941a2022-12-14 19:14:04 +000093TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +000094 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
95 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -070096 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +000097
98 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +000099 std::list<NotifyArgs> args =
100 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000101 ASSERT_THAT(args,
102 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000103 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +0000104 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000105 VariantWith<NotifyMotionArgs>(
106 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000107 WithRelativeMotion(-5, 10), WithButtonState(0),
108 WithPressure(0.0f)))));
109 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700110 Each(VariantWith<NotifyMotionArgs>(
111 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
112 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000113
Prabir Pradhan8b053512024-05-03 23:15:39 +0000114 // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER.
Harry Cutts379ea422023-12-21 15:31:47 +0000115 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
116 ASSERT_THAT(args,
117 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000118 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
Harry Cutts379ea422023-12-21 15:31:47 +0000119 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
120 WithButtonState(0), WithPressure(0.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700121 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000122}
123
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000124TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000125 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
126 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000127 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700128 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000129
130 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000131 std::list<NotifyArgs> args =
132 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000133 ASSERT_THAT(args,
134 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000135 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +0000136 WithRelativeMotion(0, 0))),
Harry Cutts379ea422023-12-21 15:31:47 +0000137 VariantWith<NotifyMotionArgs>(
138 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000139 WithRelativeMotion(10, 5), WithButtonState(0),
140 WithPressure(0.0f)))));
141 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700142 Each(VariantWith<NotifyMotionArgs>(
143 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
144 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000145}
146
Harry Cutts4fb941a2022-12-14 19:14:04 +0000147TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000148 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
149 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700150 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000151
152 // Press left and right buttons at once
153 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
154 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
155 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000156 std::list<NotifyArgs> args =
157 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000158 ASSERT_THAT(args,
159 ElementsAre(VariantWith<NotifyMotionArgs>(
160 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
161 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000162 AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000163 VariantWith<NotifyMotionArgs>(
164 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
165 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000166 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000167 VariantWith<NotifyMotionArgs>(
168 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
169 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
170 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
Harry Cuttsef95e712024-02-16 18:56:39 +0000171 AMOTION_EVENT_BUTTON_SECONDARY)))));
172 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700173 Each(VariantWith<NotifyMotionArgs>(
174 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
175 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000176
177 // Then release the left button
178 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
179 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
180 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000181 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000182 ASSERT_THAT(args,
183 ElementsAre(VariantWith<NotifyMotionArgs>(
184 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
185 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000186 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
187 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700188 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000189
190 // Finally release the right button
191 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
192 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
193 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000194 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000195 ASSERT_THAT(args,
196 ElementsAre(VariantWith<NotifyMotionArgs>(
197 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000198 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000199 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000200 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000201 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000202 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
203 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700204 Each(VariantWith<NotifyMotionArgs>(
205 AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER),
206 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000207}
208
Harry Cutts379ea422023-12-21 15:31:47 +0000209TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) {
210 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
211 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700212 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts379ea422023-12-21 15:31:47 +0000213
214 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
215 std::list<NotifyArgs> args =
216 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
217
218 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
219 /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE,
220 /*is_tap=*/false);
221 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
222 ASSERT_THAT(args.front(),
223 VariantWith<NotifyMotionArgs>(
224 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000225 WithCoords(0, 0), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700226 WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts379ea422023-12-21 15:31:47 +0000227}
228
Harry Cutts4fb941a2022-12-14 19:14:04 +0000229TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000230 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
231 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700232 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000233
234 // Press the button
235 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
236 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
237 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000238 std::list<NotifyArgs> args =
239 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000240 ASSERT_THAT(args,
241 ElementsAre(VariantWith<NotifyMotionArgs>(
242 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cuttsef95e712024-02-16 18:56:39 +0000243 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000244 VariantWith<NotifyMotionArgs>(
245 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
246 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000247 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)))));
248 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700249 Each(VariantWith<NotifyMotionArgs>(
250 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
251 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000252
253 // Move
254 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000255 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000256 ASSERT_THAT(args,
257 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000258 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
259 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
Harry Cutts5f26e952023-11-30 18:20:27 +0000260 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700261 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000262
Harry Cutts4fb941a2022-12-14 19:14:04 +0000263 // Release the button
264 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
265 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
266 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000267 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000268 ASSERT_THAT(args,
269 ElementsAre(VariantWith<NotifyMotionArgs>(
270 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000271 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000272 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000273 WithMotionAction(AMOTION_EVENT_ACTION_UP)),
Harry Cutts5f26e952023-11-30 18:20:27 +0000274 VariantWith<NotifyMotionArgs>(
Harry Cuttsef95e712024-02-16 18:56:39 +0000275 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
276 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700277 Each(VariantWith<NotifyMotionArgs>(
278 AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER),
279 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000280}
281
Harry Cuttsef400b22022-12-16 21:26:24 +0000282TEST_F(GestureConverterTest, Scroll) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900283 input_flags::enable_touchpad_no_focus_change(true);
284
Harry Cuttsef400b22022-12-16 21:26:24 +0000285 const nsecs_t downTime = 12345;
286 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
287 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700288 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000289
Harry Cuttsa546ba82023-01-13 17:21:00 +0000290 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000291 std::list<NotifyArgs> args =
292 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000293 ASSERT_THAT(args,
294 ElementsAre(VariantWith<NotifyMotionArgs>(
295 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000296 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000297 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000298 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000299 VariantWith<NotifyMotionArgs>(
300 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000301 WithCoords(0, -10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000302 WithGestureScrollDistance(0, 10, EPSILON)))));
303 ASSERT_THAT(args,
304 Each(VariantWith<NotifyMotionArgs>(
305 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900306 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
307 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000308 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700309 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000310
Harry Cuttsa546ba82023-01-13 17:21:00 +0000311 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000312 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000313 ASSERT_THAT(args,
314 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000315 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
Harry Cutts5f26e952023-11-30 18:20:27 +0000316 WithGestureScrollDistance(0, 5, EPSILON),
317 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
318 WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900319 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
320 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700321 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000322
323 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
324 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000325 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000326 ASSERT_THAT(args,
327 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000328 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000329 WithCoords(0, -15),
Harry Cutts379ea422023-12-21 15:31:47 +0000330 WithGestureScrollDistance(0, 0, EPSILON),
331 WithMotionClassification(
332 MotionClassification::TWO_FINGER_SWIPE),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900333 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
334 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000335 VariantWith<NotifyMotionArgs>(
336 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000337 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000338 WithMotionClassification(MotionClassification::NONE)))));
339 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700340 Each(VariantWith<NotifyMotionArgs>(
341 AllOf(WithToolType(ToolType::FINGER),
342 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000343}
344
345TEST_F(GestureConverterTest, Scroll_Rotated) {
346 const nsecs_t downTime = 12345;
347 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
348 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
349 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700350 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000351
Harry Cuttsa546ba82023-01-13 17:21:00 +0000352 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000353 std::list<NotifyArgs> args =
354 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000355 ASSERT_THAT(args,
356 ElementsAre(VariantWith<NotifyMotionArgs>(
357 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000358 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000359 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000360 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000361 VariantWith<NotifyMotionArgs>(
362 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000363 WithCoords(-10, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000364 WithGestureScrollDistance(0, 10, EPSILON)))));
365 ASSERT_THAT(args,
366 Each(VariantWith<NotifyMotionArgs>(
367 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
368 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700369 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000370
Harry Cuttsa546ba82023-01-13 17:21:00 +0000371 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000372 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000373 ASSERT_THAT(args,
374 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000375 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000376 WithGestureScrollDistance(0, 5, EPSILON),
377 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
378 WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700379 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000380
Harry Cuttsef400b22022-12-16 21:26:24 +0000381 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
382 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000383 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000384 ASSERT_THAT(args,
385 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000386 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000387 WithCoords(-15, 0),
Harry Cutts379ea422023-12-21 15:31:47 +0000388 WithGestureScrollDistance(0, 0, EPSILON),
389 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +0000390 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000391 VariantWith<NotifyMotionArgs>(
392 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000393 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000394 WithMotionClassification(MotionClassification::NONE)))));
395 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700396 Each(VariantWith<NotifyMotionArgs>(
397 AllOf(WithToolType(ToolType::FINGER),
398 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000399}
400
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000401TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000402 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
403 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700404 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000405
Harry Cuttsa546ba82023-01-13 17:21:00 +0000406 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000407 std::list<NotifyArgs> args =
408 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000409
Harry Cuttsa546ba82023-01-13 17:21:00 +0000410 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000411 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000412
413 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
414 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000415 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000416
417 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000418 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000419 ASSERT_THAT(args,
420 ElementsAre(VariantWith<NotifyMotionArgs>(
421 AllOf(WithMotionClassification(MotionClassification::NONE),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700422 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000423}
424
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000425TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000426 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
427 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700428 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000429
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000430 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000431 std::list<NotifyArgs> args =
432 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000433
434 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000435 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000436
437 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
438 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000439 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000440
441 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
442 // need to use another gesture type, like pinch.
443 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
444 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000445 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000446 ASSERT_FALSE(args.empty());
447 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
448}
449
Prabir Pradhan13acbd22024-05-14 22:36:40 +0000450TEST_F(GestureConverterTest, Scroll_ClearsFakeFingerPositionOnSubsequentScrollGestures) {
451 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
452 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
453 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
454
455 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 15, -10);
456 std::list<NotifyArgs> args =
457 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
458
459 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -2, -5);
460 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
461
462 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
463 GESTURES_FLING_START);
464 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
465 Gesture flingGestureEnd(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, 0,
466 GESTURES_FLING_TAP_DOWN);
467 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGestureEnd);
468
469 // Start a second scoll gesture, and ensure the fake finger is reset to (0, 0), instead of
470 // continuing from the position where the last scroll gesture's fake finger ended.
471 Gesture secondScrollStart(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 2,
472 14);
473 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, secondScrollStart);
474 ASSERT_THAT(args,
475 ElementsAre(VariantWith<NotifyMotionArgs>(
476 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
477 VariantWith<NotifyMotionArgs>(
478 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
479 WithCoords(0, 0),
480 WithGestureScrollDistance(0, 0, EPSILON))),
481 VariantWith<NotifyMotionArgs>(
482 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
483 WithCoords(2, 14),
484 WithGestureScrollDistance(-2, -14, EPSILON)))));
485}
486
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000487TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
488 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
489 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700490 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000491
492 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
493 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000494 std::list<NotifyArgs> args =
495 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000496
497 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000498 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000499
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000500 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
501 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000502 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000503 ASSERT_THAT(args,
504 ElementsAre(VariantWith<NotifyMotionArgs>(
505 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000506}
507
Harry Cutts8743f182023-05-17 12:03:49 +0000508TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000509 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
510 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700511 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000512
513 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
514 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000515 std::list<NotifyArgs> args =
516 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000517
518 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000519 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000520
521 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
522 // need to use another gesture type, like pinch.
523 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
524 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000525 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000526 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000527 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
528 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000529}
530
531TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
532 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
533 // start swiping up and then start moving left or right, it'll return gesture events with only Y
534 // deltas until you lift your fingers and start swiping again. That's why each of these tests
535 // only checks movement in one dimension.
536 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
537 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700538 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000539
540 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
541 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000542 std::list<NotifyArgs> args =
543 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000544 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000545 ASSERT_THAT(args,
546 Each(VariantWith<NotifyMotionArgs>(
547 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
548 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700549 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000550
551 // Three fake fingers should be created. We don't actually care where they are, so long as they
552 // move appropriately.
553 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
554 ASSERT_THAT(arg,
555 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000556 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000557 PointerCoords finger0Start = arg.pointerCoords[0];
558 args.pop_front();
559 arg = std::get<NotifyMotionArgs>(args.front());
560 ASSERT_THAT(arg,
561 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
562 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000563 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000564 PointerCoords finger1Start = arg.pointerCoords[1];
565 args.pop_front();
566 arg = std::get<NotifyMotionArgs>(args.front());
567 ASSERT_THAT(arg,
568 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
569 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000570 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000571 PointerCoords finger2Start = arg.pointerCoords[2];
572 args.pop_front();
573
574 arg = std::get<NotifyMotionArgs>(args.front());
575 ASSERT_THAT(arg,
576 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000577 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000578 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
579 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
580 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
581 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
582 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
583 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
584
585 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
586 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000587 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000588 ASSERT_EQ(1u, args.size());
589 arg = std::get<NotifyMotionArgs>(args.front());
590 ASSERT_THAT(arg,
591 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000592 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000593 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000594 WithPointerCount(3u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700595 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000596 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
597 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
598 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
599 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
600 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
601 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
602
603 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000604 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000605 ASSERT_THAT(args,
606 ElementsAre(VariantWith<NotifyMotionArgs>(
607 AllOf(WithMotionAction(
608 AMOTION_EVENT_ACTION_POINTER_UP |
609 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
610 WithGestureOffset(0, 0, EPSILON),
611 WithGestureSwipeFingerCount(3),
612 WithMotionClassification(
613 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000614 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000615 VariantWith<NotifyMotionArgs>(
616 AllOf(WithMotionAction(
617 AMOTION_EVENT_ACTION_POINTER_UP |
618 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
619 WithGestureOffset(0, 0, EPSILON),
620 WithGestureSwipeFingerCount(3),
621 WithMotionClassification(
622 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000623 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000624 VariantWith<NotifyMotionArgs>(
625 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
626 WithGestureOffset(0, 0, EPSILON),
627 WithGestureSwipeFingerCount(3),
628 WithMotionClassification(
629 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000630 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000631 VariantWith<NotifyMotionArgs>(
632 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000633 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000634 WithMotionClassification(MotionClassification::NONE)))));
635 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700636 Each(VariantWith<NotifyMotionArgs>(
637 AllOf(WithToolType(ToolType::FINGER),
638 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000639}
640
Harry Cutts94f5bd52023-01-06 18:02:18 +0000641TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
642 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
643 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
644 converter.setOrientation(ui::ROTATION_90);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700645 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000646
647 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
648 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000649 std::list<NotifyArgs> args =
650 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000651 ASSERT_EQ(4u, args.size());
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700652 ASSERT_THAT(args,
653 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000654
655 // Three fake fingers should be created. We don't actually care where they are, so long as they
656 // move appropriately.
657 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
658 ASSERT_THAT(arg,
659 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000660 WithPointerCount(1u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000661 PointerCoords finger0Start = arg.pointerCoords[0];
662 args.pop_front();
663 arg = std::get<NotifyMotionArgs>(args.front());
664 ASSERT_THAT(arg,
665 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
666 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000667 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000668 PointerCoords finger1Start = arg.pointerCoords[1];
669 args.pop_front();
670 arg = std::get<NotifyMotionArgs>(args.front());
671 ASSERT_THAT(arg,
672 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
673 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000674 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000675 PointerCoords finger2Start = arg.pointerCoords[2];
676 args.pop_front();
677
678 arg = std::get<NotifyMotionArgs>(args.front());
679 ASSERT_THAT(arg,
680 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000681 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000682 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
683 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
684 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
685 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
686 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
687 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
688
689 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
690 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000691 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000692 ASSERT_EQ(1u, args.size());
693 arg = std::get<NotifyMotionArgs>(args.front());
694 ASSERT_THAT(arg,
695 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000696 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700697 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000698 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
699 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
700 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
701 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
702 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
703 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
704
705 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000706 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000707 ASSERT_THAT(args,
708 ElementsAre(VariantWith<NotifyMotionArgs>(
709 AllOf(WithMotionAction(
710 AMOTION_EVENT_ACTION_POINTER_UP |
711 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000712 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000713 VariantWith<NotifyMotionArgs>(
714 AllOf(WithMotionAction(
715 AMOTION_EVENT_ACTION_POINTER_UP |
716 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000717 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000718 VariantWith<NotifyMotionArgs>(
719 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +0000720 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000721 VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000722 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700723 ASSERT_THAT(args,
724 Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000725}
726
Harry Cuttsc5748d12022-12-02 17:30:18 +0000727TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
728 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
729 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700730 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000731
732 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
733 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000734 std::list<NotifyArgs> args =
735 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000736 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000737 ASSERT_THAT(args,
738 Each(VariantWith<NotifyMotionArgs>(
739 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
740 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700741 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000742
743 // Four fake fingers should be created. We don't actually care where they are, so long as they
744 // move appropriately.
745 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
746 ASSERT_THAT(arg,
747 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000748 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000749 PointerCoords finger0Start = arg.pointerCoords[0];
750 args.pop_front();
751 arg = std::get<NotifyMotionArgs>(args.front());
752 ASSERT_THAT(arg,
753 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
754 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000755 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000756 PointerCoords finger1Start = arg.pointerCoords[1];
757 args.pop_front();
758 arg = std::get<NotifyMotionArgs>(args.front());
759 ASSERT_THAT(arg,
760 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
761 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000762 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000763 PointerCoords finger2Start = arg.pointerCoords[2];
764 args.pop_front();
765 arg = std::get<NotifyMotionArgs>(args.front());
766 ASSERT_THAT(arg,
767 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
768 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000769 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000770 PointerCoords finger3Start = arg.pointerCoords[3];
771 args.pop_front();
772
773 arg = std::get<NotifyMotionArgs>(args.front());
774 ASSERT_THAT(arg,
775 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000776 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000777 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
778 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
779 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
780 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
781 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
782 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
783 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
784 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
785
786 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
787 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000788 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000789 ASSERT_EQ(1u, args.size());
790 arg = std::get<NotifyMotionArgs>(args.front());
791 ASSERT_THAT(arg,
792 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000793 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000794 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000795 WithPointerCount(4u), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700796 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000797 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
798 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
799 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
800 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
801 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
802 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
803 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
804 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
805
806 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000807 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000808 ASSERT_THAT(args,
809 ElementsAre(VariantWith<NotifyMotionArgs>(
810 AllOf(WithMotionAction(
811 AMOTION_EVENT_ACTION_POINTER_UP |
812 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
813 WithGestureOffset(0, 0, EPSILON),
814 WithGestureSwipeFingerCount(4),
815 WithMotionClassification(
816 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000817 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000818 VariantWith<NotifyMotionArgs>(
819 AllOf(WithMotionAction(
820 AMOTION_EVENT_ACTION_POINTER_UP |
821 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
822 WithGestureOffset(0, 0, EPSILON),
823 WithGestureSwipeFingerCount(4),
824 WithMotionClassification(
825 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000826 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000827 VariantWith<NotifyMotionArgs>(
828 AllOf(WithMotionAction(
829 AMOTION_EVENT_ACTION_POINTER_UP |
830 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
831 WithGestureOffset(0, 0, EPSILON),
832 WithGestureSwipeFingerCount(4),
833 WithMotionClassification(
834 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000835 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000836 VariantWith<NotifyMotionArgs>(
837 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
838 WithGestureOffset(0, 0, EPSILON),
839 WithGestureSwipeFingerCount(4),
840 WithMotionClassification(
841 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000842 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000843 VariantWith<NotifyMotionArgs>(
844 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000845 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000846 WithMotionClassification(MotionClassification::NONE)))));
847 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700848 Each(VariantWith<NotifyMotionArgs>(
849 AllOf(WithToolType(ToolType::FINGER),
850 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000851}
852
Harry Cuttsaf66cee2024-10-28 17:34:19 +0000853TEST_F(GestureConverterTest, DisablingSystemGestures_IgnoresMultiFingerSwipe) {
854 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
855 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
856 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
857
858 std::list<NotifyArgs> args = converter.setEnableSystemGestures(ARBITRARY_TIME, false);
859 ASSERT_THAT(args, IsEmpty());
860
861 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
862 /*dy=*/10);
863 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
864 /*dy=*/5);
865 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
866
867 args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
868 args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
869 args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
870 ASSERT_THAT(args, IsEmpty());
871
872 args = converter.setEnableSystemGestures(ARBITRARY_TIME, true);
873 ASSERT_THAT(args, IsEmpty());
874
875 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
876 ASSERT_THAT(args,
877 ElementsAre(VariantWith<NotifyMotionArgs>(
878 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
879 VariantWith<NotifyMotionArgs>(WithMotionAction(
880 AMOTION_EVENT_ACTION_POINTER_DOWN |
881 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)),
882 VariantWith<NotifyMotionArgs>(WithMotionAction(
883 AMOTION_EVENT_ACTION_POINTER_DOWN |
884 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)),
885 VariantWith<NotifyMotionArgs>(
886 WithMotionAction(AMOTION_EVENT_ACTION_MOVE))));
887 ASSERT_THAT(args,
888 Each(VariantWith<NotifyMotionArgs>(
889 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE))));
890}
891
892TEST_F(GestureConverterTest, DisablingSystemGestures_EndsOngoingMultiFingerSwipe) {
893 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
894 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
895 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
896
897 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
898 /*dy=*/10);
899 std::list<NotifyArgs> args;
900 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
901 ASSERT_FALSE(args.empty());
902
903 // Disabling system gestures should end the swipe early.
904 args = converter.setEnableSystemGestures(ARBITRARY_TIME, false);
905 ASSERT_THAT(args,
906 ElementsAre(VariantWith<NotifyMotionArgs>(
907 AllOf(WithMotionAction(
908 AMOTION_EVENT_ACTION_POINTER_UP |
909 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
910 WithGestureOffset(0, 0, EPSILON),
911 WithMotionClassification(
912 MotionClassification::MULTI_FINGER_SWIPE),
913 WithPointerCount(3u))),
914 VariantWith<NotifyMotionArgs>(
915 AllOf(WithMotionAction(
916 AMOTION_EVENT_ACTION_POINTER_UP |
917 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
918 WithGestureOffset(0, 0, EPSILON),
919 WithMotionClassification(
920 MotionClassification::MULTI_FINGER_SWIPE),
921 WithPointerCount(2u))),
922 VariantWith<NotifyMotionArgs>(
923 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
924 WithGestureOffset(0, 0, EPSILON),
925 WithMotionClassification(
926 MotionClassification::MULTI_FINGER_SWIPE),
927 WithPointerCount(1u))),
928 VariantWith<NotifyMotionArgs>(
929 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
930 WithMotionClassification(MotionClassification::NONE)))));
931 ASSERT_THAT(args,
932 Each(VariantWith<NotifyMotionArgs>(
933 AllOf(WithToolType(ToolType::FINGER),
934 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
935
936 // Further movement in the same swipe should be ignored.
937 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
938 /*dy=*/5);
939 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
940 ASSERT_THAT(args, IsEmpty());
941 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
942 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
943 ASSERT_THAT(args, IsEmpty());
944
945 // But single-finger pointer motion should be reported.
946 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
947 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
948 ASSERT_THAT(args,
949 ElementsAre(VariantWith<NotifyMotionArgs>(
950 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
951 WithRelativeMotion(-5, 10), WithButtonState(0)))));
952}
953
Harry Cuttsb1e83552022-12-20 11:02:26 +0000954TEST_F(GestureConverterTest, Pinch_Inwards) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900955 input_flags::enable_touchpad_no_focus_change(true);
956
Harry Cuttsb1e83552022-12-20 11:02:26 +0000957 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
958 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700959 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000960
961 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
962 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000963 std::list<NotifyArgs> args =
964 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000965 ASSERT_THAT(args,
966 ElementsAre(VariantWith<NotifyMotionArgs>(
967 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000968 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000969 VariantWith<NotifyMotionArgs>(
970 AllOf(WithMotionAction(
971 AMOTION_EVENT_ACTION_POINTER_DOWN |
972 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000973 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
Harry Cuttsef95e712024-02-16 18:56:39 +0000974 ASSERT_THAT(args,
975 Each(VariantWith<NotifyMotionArgs>(
976 AllOf(WithMotionClassification(MotionClassification::PINCH),
977 WithGesturePinchScaleFactor(1.0f, EPSILON),
978 WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900979 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
980 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000981
982 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
983 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000984 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000985 ASSERT_THAT(args,
986 ElementsAre(VariantWith<NotifyMotionArgs>(
987 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
988 WithMotionClassification(MotionClassification::PINCH),
989 WithGesturePinchScaleFactor(0.8f, EPSILON),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000990 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000991 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +0900992 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
993 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000994
995 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
996 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000997 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000998 ASSERT_THAT(args,
999 ElementsAre(VariantWith<NotifyMotionArgs>(
1000 AllOf(WithMotionAction(
1001 AMOTION_EVENT_ACTION_POINTER_UP |
1002 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1003 WithMotionClassification(MotionClassification::PINCH),
1004 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001005 WithPointerCount(2u),
1006 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001007 VariantWith<NotifyMotionArgs>(
1008 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1009 WithMotionClassification(MotionClassification::PINCH),
1010 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001011 WithPointerCount(1u),
1012 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001013 VariantWith<NotifyMotionArgs>(
1014 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001015 WithCoords(0, 0),
1016 WithMotionClassification(MotionClassification::NONE)))));
1017 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001018 Each(VariantWith<NotifyMotionArgs>(
1019 AllOf(WithToolType(ToolType::FINGER),
1020 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +00001021}
1022
1023TEST_F(GestureConverterTest, Pinch_Outwards) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001024 input_flags::enable_touchpad_no_focus_change(true);
1025
Prabir Pradhan8b053512024-05-03 23:15:39 +00001026 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1027 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001028 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhan8b053512024-05-03 23:15:39 +00001029
1030 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
1031 GESTURES_ZOOM_START);
1032 std::list<NotifyArgs> args =
1033 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
1034 ASSERT_THAT(args,
1035 ElementsAre(VariantWith<NotifyMotionArgs>(
1036 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1037 WithCoords(-100, 0), WithPointerCount(1u))),
1038 VariantWith<NotifyMotionArgs>(
1039 AllOf(WithMotionAction(
1040 AMOTION_EVENT_ACTION_POINTER_DOWN |
1041 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1042 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
1043 ASSERT_THAT(args,
1044 Each(VariantWith<NotifyMotionArgs>(
1045 AllOf(WithMotionClassification(MotionClassification::PINCH),
1046 WithGesturePinchScaleFactor(1.0f, EPSILON),
1047 WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001048 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
1049 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +00001050
1051 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1052 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
1053 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
1054 ASSERT_THAT(args,
1055 ElementsAre(VariantWith<NotifyMotionArgs>(
1056 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1057 WithMotionClassification(MotionClassification::PINCH),
1058 WithGesturePinchScaleFactor(1.1f, EPSILON),
1059 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
1060 WithPointerCount(2u), WithToolType(ToolType::FINGER),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001061 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
1062 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +00001063
1064 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
1065 GESTURES_ZOOM_END);
1066 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
1067 ASSERT_THAT(args,
1068 ElementsAre(VariantWith<NotifyMotionArgs>(
1069 AllOf(WithMotionAction(
1070 AMOTION_EVENT_ACTION_POINTER_UP |
1071 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1072 WithMotionClassification(MotionClassification::PINCH),
1073 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001074 WithPointerCount(2u),
1075 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001076 VariantWith<NotifyMotionArgs>(
1077 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1078 WithMotionClassification(MotionClassification::PINCH),
1079 WithGesturePinchScaleFactor(1.0f, EPSILON),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001080 WithPointerCount(1u),
1081 WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001082 VariantWith<NotifyMotionArgs>(
1083 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1084 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001085 WithMotionClassification(MotionClassification::NONE)))));
1086 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001087 Each(VariantWith<NotifyMotionArgs>(
1088 AllOf(WithToolType(ToolType::FINGER),
1089 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001090}
1091
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001092TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +00001093 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1094 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001095 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001096
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001097 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001098 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001099 std::list<NotifyArgs> args =
1100 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001101
1102 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001103 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001104 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001105
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001106 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +00001107 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001108 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +00001109
1110 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001111 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001112 ASSERT_THAT(args,
1113 ElementsAre(VariantWith<NotifyMotionArgs>(
1114 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001115}
1116
1117TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
1118 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1119 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001120 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001121
1122 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1123 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001124 std::list<NotifyArgs> args =
1125 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001126
1127 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1128 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00001129 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001130
1131 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1132 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00001133 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001134
1135 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1136 // need to use another gesture type, like scroll.
1137 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
1138 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001139 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +00001140 ASSERT_FALSE(args.empty());
1141 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +00001142}
1143
Harry Cuttse9b71422023-03-14 16:54:44 +00001144TEST_F(GestureConverterTest, ResetWithButtonPressed) {
1145 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1146 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001147 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001148
1149 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1150 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1151 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001152 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001153
1154 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001155 ASSERT_THAT(args,
1156 ElementsAre(VariantWith<NotifyMotionArgs>(
1157 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1158 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001159 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001160 VariantWith<NotifyMotionArgs>(
1161 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1162 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001163 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001164 VariantWith<NotifyMotionArgs>(
1165 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001166 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001167 VariantWith<NotifyMotionArgs>(
1168 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001169 WithButtonState(0)))));
1170 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001171 Each(VariantWith<NotifyMotionArgs>(
1172 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
1173 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001174}
1175
1176TEST_F(GestureConverterTest, ResetDuringScroll) {
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001177 input_flags::enable_touchpad_no_focus_change(true);
1178
Harry Cuttse9b71422023-03-14 16:54:44 +00001179 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1180 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001181 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001182
1183 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001184 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001185
1186 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001187 ASSERT_THAT(args,
1188 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001189 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001190 WithCoords(0, -10),
Harry Cutts379ea422023-12-21 15:31:47 +00001191 WithGestureScrollDistance(0, 0, EPSILON),
1192 WithMotionClassification(
1193 MotionClassification::TWO_FINGER_SWIPE),
Hiroki Satodd62ddc2024-09-05 17:38:18 +09001194 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
1195 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001196 VariantWith<NotifyMotionArgs>(
1197 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001198 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001199 WithMotionClassification(MotionClassification::NONE)))));
1200 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001201 Each(VariantWith<NotifyMotionArgs>(
1202 AllOf(WithToolType(ToolType::FINGER),
1203 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001204}
1205
1206TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1207 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1208 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001209 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001210
1211 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1212 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001213 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001214
1215 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001216 ASSERT_THAT(args,
1217 ElementsAre(VariantWith<NotifyMotionArgs>(
1218 AllOf(WithMotionAction(
1219 AMOTION_EVENT_ACTION_POINTER_UP |
1220 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1221 WithGestureOffset(0, 0, EPSILON),
1222 WithMotionClassification(
1223 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001224 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001225 VariantWith<NotifyMotionArgs>(
1226 AllOf(WithMotionAction(
1227 AMOTION_EVENT_ACTION_POINTER_UP |
1228 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1229 WithGestureOffset(0, 0, EPSILON),
1230 WithMotionClassification(
1231 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001232 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001233 VariantWith<NotifyMotionArgs>(
1234 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1235 WithGestureOffset(0, 0, EPSILON),
1236 WithMotionClassification(
1237 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001238 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001239 VariantWith<NotifyMotionArgs>(
1240 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001241 WithMotionClassification(MotionClassification::NONE)))));
1242 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001243 Each(VariantWith<NotifyMotionArgs>(
1244 AllOf(WithToolType(ToolType::FINGER),
1245 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001246}
1247
1248TEST_F(GestureConverterTest, ResetDuringPinch) {
1249 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1250 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001251 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001252
1253 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1254 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001255 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001256
1257 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001258 ASSERT_THAT(args,
1259 ElementsAre(VariantWith<NotifyMotionArgs>(
1260 AllOf(WithMotionAction(
1261 AMOTION_EVENT_ACTION_POINTER_UP |
1262 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1263 WithMotionClassification(MotionClassification::PINCH),
1264 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001265 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001266 VariantWith<NotifyMotionArgs>(
1267 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1268 WithMotionClassification(MotionClassification::PINCH),
1269 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001270 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001271 VariantWith<NotifyMotionArgs>(
1272 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001273 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001274 WithMotionClassification(MotionClassification::NONE)))));
1275 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001276 Each(VariantWith<NotifyMotionArgs>(
1277 AllOf(WithToolType(ToolType::FINGER),
1278 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001279}
1280
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001281TEST_F(GestureConverterTest, FlingTapDown) {
1282 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1283 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001284 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001285
1286 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1287 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001288 std::list<NotifyArgs> args =
1289 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001290
1291 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001292 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
1293 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001294 WithButtonState(0), WithPressure(0.0f),
1295 WithDisplayId(ui::LogicalDisplayId::DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001296}
1297
Harry Cutts39648ab2024-02-15 14:23:50 +00001298TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1299 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1300 input_flags::enable_touchpad_fling_stop(true);
1301 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001302 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Harry Cutts39648ab2024-02-15 14:23:50 +00001303
1304 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1305 std::list<NotifyArgs> args =
1306 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1307 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1308 GESTURES_FLING_START);
1309 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1310
1311 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1312 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1313 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1314 ASSERT_THAT(args,
1315 ElementsAre(VariantWith<NotifyMotionArgs>(
1316 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1317 VariantWith<NotifyMotionArgs>(
1318 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1319 VariantWith<NotifyMotionArgs>(
1320 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1321 VariantWith<NotifyMotionArgs>(
Harry Cutts574781a2024-04-23 15:30:45 +00001322 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001323 ASSERT_THAT(args,
Harry Cutts574781a2024-04-23 15:30:45 +00001324 Each(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +00001325 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001326 WithDisplayId(ui::LogicalDisplayId::DEFAULT),
Harry Cutts574781a2024-04-23 15:30:45 +00001327 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE)))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001328}
1329
Arpit Singha5ea7c12023-07-05 15:39:25 +00001330TEST_F(GestureConverterTest, Tap) {
1331 // Tap should produce button press/release events
1332 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1333 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001334 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001335
1336 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1337 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001338 std::list<NotifyArgs> args =
1339 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001340 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001341
1342 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1343 /* down= */ GESTURES_BUTTON_LEFT,
1344 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001345 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001346
Harry Cutts5f26e952023-11-30 18:20:27 +00001347 ASSERT_THAT(args,
1348 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001349 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001350 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001351 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001352 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001353 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001354 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001355 VariantWith<NotifyMotionArgs>(
1356 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1357 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1358 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001359 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001360 VariantWith<NotifyMotionArgs>(
1361 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1362 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001363 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001364 VariantWith<NotifyMotionArgs>(
1365 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001366 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001367 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001368 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001369 WithButtonState(0), WithPressure(0.0f)))));
1370 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001371 Each(VariantWith<NotifyMotionArgs>(
1372 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1373 WithToolType(ToolType::FINGER),
1374 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001375}
1376
Harry Cutts2a0210e2024-10-18 19:12:59 +00001377TEST_F(GestureConverterTest, ThreeFingerTap_TriggersShortcut) {
1378 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1379 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1380 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
1381 converter.setThreeFingerTapShortcutEnabled(true);
1382
1383 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*vx=*/0,
1384 /*vy=*/0, GESTURES_FLING_TAP_DOWN);
1385 std::list<NotifyArgs> args =
1386 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1387 // We don't need to check args here, since it's covered by the FlingTapDown test.
1388
1389 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1390 /*down=*/GESTURES_BUTTON_MIDDLE, /*up=*/GESTURES_BUTTON_MIDDLE,
1391 /*is_tap=*/true);
1392 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
1393
1394 ASSERT_TRUE(args.empty());
1395 mFakePolicy->assertTouchpadThreeFingerTapNotified();
1396}
1397
Arpit Singha5ea7c12023-07-05 15:39:25 +00001398TEST_F(GestureConverterTest, Click) {
1399 // Click should produce button press/release events
1400 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1401 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001402 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001403
1404 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1405 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001406 std::list<NotifyArgs> args =
1407 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001408 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001409
1410 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1411 /* down= */ GESTURES_BUTTON_LEFT,
1412 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001413 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001414
Harry Cutts5f26e952023-11-30 18:20:27 +00001415 ASSERT_THAT(args,
1416 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001417 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001418 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001419 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001420 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001421 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001422 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001423 VariantWith<NotifyMotionArgs>(
1424 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1425 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1426 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001427 WithPressure(1.0f)))));
1428 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001429 Each(VariantWith<NotifyMotionArgs>(
1430 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1431 WithToolType(ToolType::FINGER),
1432 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001433
1434 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1435 /* down= */ GESTURES_BUTTON_NONE,
1436 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001437 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Prabir Pradhan8b053512024-05-03 23:15:39 +00001438
Harry Cutts5f26e952023-11-30 18:20:27 +00001439 ASSERT_THAT(args,
1440 ElementsAre(VariantWith<NotifyMotionArgs>(
1441 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1442 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001443 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001444 VariantWith<NotifyMotionArgs>(
1445 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001446 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001447 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001448 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001449 WithPressure(0.0f)))));
1450 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001451 Each(VariantWith<NotifyMotionArgs>(
1452 AllOf(WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1453 WithToolType(ToolType::FINGER),
1454 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001455}
1456
Arpit Singh3d84add2023-10-10 19:08:29 +00001457TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001458 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1459 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1460 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1461
Arpit Singha5ea7c12023-07-05 15:39:25 +00001462 // Tap should be ignored when disabled
1463 mReader->getContext()->setPreventingTouchpadTaps(true);
1464
1465 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1466 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001467 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001468
Arpit Singh82b27a02023-10-16 11:02:19 +00001469 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001470 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001471 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001472 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001473 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001474
Arpit Singh82b27a02023-10-16 11:02:19 +00001475 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001476 /* down= */ GESTURES_BUTTON_LEFT,
1477 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001478 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001479
1480 // no events should be generated
1481 ASSERT_EQ(0u, args.size());
1482
1483 // Future taps should be re-enabled
1484 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1485}
1486
Arpit Singh82b27a02023-10-16 11:02:19 +00001487TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1488 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1489 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1490
1491 // Tap should be ignored when disabled
1492 mReader->getContext()->setPreventingTouchpadTaps(true);
1493
1494 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1495 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001496 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh82b27a02023-10-16 11:02:19 +00001497
1498 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1499 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1500 std::list<NotifyArgs> args =
1501 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001502 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001503
1504 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1505 /* down= */ GESTURES_BUTTON_LEFT,
1506 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1507 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1508
1509 // no events should be generated
1510 ASSERT_EQ(0u, args.size());
1511
1512 // Future taps should be re-enabled
1513 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1514
1515 // taps before the threshold should still be ignored
1516 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1517 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1518 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1519 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1520
1521 ASSERT_EQ(1u, args.size());
1522 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1523 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1524
1525 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1526 /* down= */ GESTURES_BUTTON_LEFT,
1527 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1528 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1529
1530 // no events should be generated
1531 ASSERT_EQ(0u, args.size());
1532
1533 // taps after the threshold should be recognised
1534 currentTime += 1;
1535 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1536 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1537 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1538
1539 ASSERT_EQ(1u, args.size());
1540 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1541 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1542
1543 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1544 /* down= */ GESTURES_BUTTON_LEFT,
1545 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1546 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001547 ASSERT_THAT(args,
1548 ElementsAre(VariantWith<NotifyMotionArgs>(
1549 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1550 WithButtonState(0))),
1551 VariantWith<NotifyMotionArgs>(
1552 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1553 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1554 VariantWith<NotifyMotionArgs>(
1555 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1556 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1557 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1558 VariantWith<NotifyMotionArgs>(
1559 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1560 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1561 WithButtonState(0))),
1562 VariantWith<NotifyMotionArgs>(
1563 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1564 WithButtonState(0))),
1565 VariantWith<NotifyMotionArgs>(
1566 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1567 WithButtonState(0)))));
1568 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001569}
1570
Arpit Singh3d84add2023-10-10 19:08:29 +00001571TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1572 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001573 // Click should still produce button press/release events
1574 mReader->getContext()->setPreventingTouchpadTaps(true);
1575
1576 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1577 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001578 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001579
1580 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1581 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001582 std::list<NotifyArgs> args =
1583 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001584 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001585
1586 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1587 /* down= */ GESTURES_BUTTON_LEFT,
1588 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001589 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001590
Harry Cutts5f26e952023-11-30 18:20:27 +00001591 ASSERT_THAT(args,
1592 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001593 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001594 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001595 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001596 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001597 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001598 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001599 VariantWith<NotifyMotionArgs>(
1600 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1601 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1602 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001603 WithPressure(1.0f)))));
1604 ASSERT_THAT(args,
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001605 Each(VariantWith<NotifyMotionArgs>(
1606 AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1607 WithToolType(ToolType::FINGER),
1608 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001609
1610 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1611 /* down= */ GESTURES_BUTTON_NONE,
1612 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001613 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001614
Harry Cutts5f26e952023-11-30 18:20:27 +00001615 ASSERT_THAT(args,
1616 ElementsAre(VariantWith<NotifyMotionArgs>(
1617 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1618 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1619 WithButtonState(0), WithCoords(0, 0),
1620 WithRelativeMotion(0.f, 0.f),
1621 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001622 WithPressure(1.0f),
1623 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001624 VariantWith<NotifyMotionArgs>(
1625 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1626 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1627 WithToolType(ToolType::FINGER), WithButtonState(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001628 WithPressure(0.0f),
1629 WithDisplayId(ui::LogicalDisplayId::DEFAULT))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001630 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001631 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001632 WithCoords(0, 0), WithRelativeMotion(0, 0),
1633 WithToolType(ToolType::FINGER), WithButtonState(0),
1634 WithPressure(0.0f),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001635 WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001636
1637 // Future taps should be re-enabled
1638 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1639}
1640
Prabir Pradhan8b053512024-05-03 23:15:39 +00001641TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
Byoungho Jungee6268f2023-10-30 17:27:26 +09001642 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
1643 // initially disable tap-to-click
1644 mReader->getContext()->setPreventingTouchpadTaps(true);
1645
1646 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1647 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001648 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001649
1650 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001651 std::list<NotifyArgs> args =
1652 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001653 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001654
1655 // Future taps should be re-enabled
1656 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1657}
1658
Prabir Pradhan8b053512024-05-03 23:15:39 +00001659TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
Arpit Singh33a10a62023-10-12 13:06:54 +00001660 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1661 const nsecs_t gestureStartTime = 1000;
1662 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1663 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -07001664 converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
Arpit Singh33a10a62023-10-12 13:06:54 +00001665
1666 // Start a move gesture at gestureStartTime
1667 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1668 std::list<NotifyArgs> args =
1669 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001670 ASSERT_THAT(args,
1671 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001672 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1673 VariantWith<NotifyMotionArgs>(
1674 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001675
1676 // Key presses with IME connection should cancel ongoing move gesture
1677 nsecs_t currentTime = gestureStartTime + 100;
1678 mFakePolicy->setIsInputMethodConnectionActive(true);
1679 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1680 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1681 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001682 ASSERT_THAT(args,
1683 ElementsAre(VariantWith<NotifyMotionArgs>(
1684 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001685
1686 // any updates in existing move gesture should be ignored
1687 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1688 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1689 ASSERT_EQ(0u, args.size());
1690
1691 // New gesture should not be affected
1692 currentTime += 100;
1693 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1694 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001695 ASSERT_THAT(args,
1696 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001697 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1698 VariantWith<NotifyMotionArgs>(
1699 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001700}
1701
Harry Cutts4fb941a2022-12-14 19:14:04 +00001702} // namespace android