blob: f50f5173b845ac5d093acc4b3918ac56b5238cb3 [file] [log] [blame]
Harry Cutts4fb941a2022-12-14 19:14:04 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <memory>
18
Arpit Singh3d84add2023-10-10 19:08:29 +000019#include <com_android_input_flags.h>
20#include <flag_macros.h>
Harry Cutts4fb941a2022-12-14 19:14:04 +000021#include <gestures/GestureConverter.h>
22#include <gtest/gtest.h>
Josep del Riod0746382023-07-29 13:18:25 +000023#include <gui/constants.h>
Harry Cutts4fb941a2022-12-14 19:14:04 +000024
25#include "FakeEventHub.h"
26#include "FakeInputReaderPolicy.h"
27#include "FakePointerController.h"
28#include "InstrumentedInputReader.h"
29#include "NotifyArgs.h"
30#include "TestConstants.h"
Prabir Pradhane3b28dd2023-10-06 04:19:29 +000031#include "TestEventMatchers.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000032#include "TestInputListener.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000033#include "include/gestures.h"
Harry Cuttsedf6ce72023-01-04 12:15:53 +000034#include "ui/Rotation.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000035
36namespace android {
37
Byoungho Jungee6268f2023-10-30 17:27:26 +090038namespace input_flags = com::android::input::flags;
39
Arpit Singh3d84add2023-10-10 19:08:29 +000040namespace {
41
42const auto TOUCHPAD_PALM_REJECTION =
Byoungho Jungee6268f2023-10-30 17:27:26 +090043 ACONFIG_FLAG(input_flags, enable_touchpad_typing_palm_rejection);
Arpit Singh33a10a62023-10-12 13:06:54 +000044const auto TOUCHPAD_PALM_REJECTION_V2 =
45 ACONFIG_FLAG(input_flags, enable_v2_touchpad_typing_palm_rejection);
Arpit Singh3d84add2023-10-10 19:08:29 +000046
47} // namespace
48
Harry Cutts4fb941a2022-12-14 19:14:04 +000049using testing::AllOf;
Harry Cuttsef95e712024-02-16 18:56:39 +000050using testing::Each;
Harry Cutts5f26e952023-11-30 18:20:27 +000051using testing::ElementsAre;
52using 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);
Josep del Riod0746382023-07-29 13:18:25 +000096 converter.setDisplayId(ADISPLAY_ID_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,
Prabir Pradhan8b053512024-05-03 23:15:39 +0000110 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
111 WithToolType(ToolType::FINGER),
Harry Cuttsef95e712024-02-16 18:56:39 +0000112 WithDisplayId(ADISPLAY_ID_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),
121 WithDisplayId(ADISPLAY_ID_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);
Josep del Riod0746382023-07-29 13:18:25 +0000128 converter.setDisplayId(ADISPLAY_ID_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,
Prabir Pradhan8b053512024-05-03 23:15:39 +0000142 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
143 WithToolType(ToolType::FINGER),
Harry Cuttsef95e712024-02-16 18:56:39 +0000144 WithDisplayId(ADISPLAY_ID_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);
Josep del Riod0746382023-07-29 13:18:25 +0000150 converter.setDisplayId(ADISPLAY_ID_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,
Prabir Pradhan8b053512024-05-03 23:15:39 +0000173 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000174 WithToolType(ToolType::FINGER),
175 WithDisplayId(ADISPLAY_ID_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),
Harry Cutts5f26e952023-11-30 18:20:27 +0000188 WithDisplayId(ADISPLAY_ID_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,
Prabir Pradhan8b053512024-05-03 23:15:39 +0000204 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000205 WithToolType(ToolType::FINGER),
206 WithDisplayId(ADISPLAY_ID_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);
212 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
213
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),
226 WithDisplayId(ADISPLAY_ID_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);
Josep del Riod0746382023-07-29 13:18:25 +0000232 converter.setDisplayId(ADISPLAY_ID_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,
Prabir Pradhan8b053512024-05-03 23:15:39 +0000249 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000250 WithToolType(ToolType::FINGER),
251 WithDisplayId(ADISPLAY_ID_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),
261 WithDisplayId(ADISPLAY_ID_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,
Prabir Pradhan8b053512024-05-03 23:15:39 +0000277 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000278 WithToolType(ToolType::FINGER),
279 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000280}
281
Harry Cuttsef400b22022-12-16 21:26:24 +0000282TEST_F(GestureConverterTest, Scroll) {
283 const nsecs_t downTime = 12345;
284 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
285 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000286 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000287
Harry Cuttsa546ba82023-01-13 17:21:00 +0000288 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000289 std::list<NotifyArgs> args =
290 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000291 ASSERT_THAT(args,
292 ElementsAre(VariantWith<NotifyMotionArgs>(
293 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000294 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000295 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000296 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000297 VariantWith<NotifyMotionArgs>(
298 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000299 WithCoords(0, -10),
Harry Cuttsef95e712024-02-16 18:56:39 +0000300 WithGestureScrollDistance(0, 10, EPSILON)))));
301 ASSERT_THAT(args,
302 Each(VariantWith<NotifyMotionArgs>(
303 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
304 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
305 WithToolType(ToolType::FINGER),
306 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000307
Harry Cuttsa546ba82023-01-13 17:21:00 +0000308 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000309 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000310 ASSERT_THAT(args,
311 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000312 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
Harry Cutts5f26e952023-11-30 18:20:27 +0000313 WithGestureScrollDistance(0, 5, EPSILON),
314 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
315 WithToolType(ToolType::FINGER),
316 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
317 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000318
319 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
320 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000321 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000322 ASSERT_THAT(args,
323 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000324 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000325 WithCoords(0, -15),
Harry Cutts379ea422023-12-21 15:31:47 +0000326 WithGestureScrollDistance(0, 0, EPSILON),
327 WithMotionClassification(
328 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000329 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000330 VariantWith<NotifyMotionArgs>(
331 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000332 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000333 WithMotionClassification(MotionClassification::NONE)))));
334 ASSERT_THAT(args,
335 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
336 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000337}
338
339TEST_F(GestureConverterTest, Scroll_Rotated) {
340 const nsecs_t downTime = 12345;
341 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
342 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
343 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000344 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000345
Harry Cuttsa546ba82023-01-13 17:21:00 +0000346 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000347 std::list<NotifyArgs> args =
348 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000349 ASSERT_THAT(args,
350 ElementsAre(VariantWith<NotifyMotionArgs>(
351 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000352 WithCoords(0, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000353 WithGestureScrollDistance(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000354 WithDownTime(downTime))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000355 VariantWith<NotifyMotionArgs>(
356 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000357 WithCoords(-10, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000358 WithGestureScrollDistance(0, 10, EPSILON)))));
359 ASSERT_THAT(args,
360 Each(VariantWith<NotifyMotionArgs>(
361 AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
362 WithToolType(ToolType::FINGER),
363 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000364
Harry Cuttsa546ba82023-01-13 17:21:00 +0000365 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000366 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000367 ASSERT_THAT(args,
368 ElementsAre(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000369 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000370 WithGestureScrollDistance(0, 5, EPSILON),
371 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
372 WithToolType(ToolType::FINGER),
373 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Prabir Pradhan8b053512024-05-03 23:15:39 +0000374
Harry Cuttsef400b22022-12-16 21:26:24 +0000375 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
376 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000377 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000378 ASSERT_THAT(args,
379 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +0000380 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000381 WithCoords(-15, 0),
Harry Cutts379ea422023-12-21 15:31:47 +0000382 WithGestureScrollDistance(0, 0, EPSILON),
383 WithMotionClassification(
Harry Cuttsef95e712024-02-16 18:56:39 +0000384 MotionClassification::TWO_FINGER_SWIPE))),
Harry Cutts379ea422023-12-21 15:31:47 +0000385 VariantWith<NotifyMotionArgs>(
386 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000387 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000388 WithMotionClassification(MotionClassification::NONE)))));
389 ASSERT_THAT(args,
390 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
391 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000392}
393
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000394TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000395 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
396 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000397 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000398
Harry Cuttsa546ba82023-01-13 17:21:00 +0000399 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000400 std::list<NotifyArgs> args =
401 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000402
Harry Cuttsa546ba82023-01-13 17:21:00 +0000403 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000404 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000405
406 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
407 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000408 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000409
410 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000411 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000412 ASSERT_THAT(args,
413 ElementsAre(VariantWith<NotifyMotionArgs>(
414 AllOf(WithMotionClassification(MotionClassification::NONE),
415 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000416}
417
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000418TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000419 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
420 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000421 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000422
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000423 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000424 std::list<NotifyArgs> args =
425 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000426
427 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000428 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000429
430 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
431 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000432 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000433
434 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
435 // need to use another gesture type, like pinch.
436 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
437 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000438 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000439 ASSERT_FALSE(args.empty());
440 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
441}
442
443TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
444 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
445 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000446 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000447
448 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
449 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000450 std::list<NotifyArgs> args =
451 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000452
453 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000454 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000455
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000456 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
457 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000458 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000459 ASSERT_THAT(args,
460 ElementsAre(VariantWith<NotifyMotionArgs>(
461 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000462}
463
Harry Cutts8743f182023-05-17 12:03:49 +0000464TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000465 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
466 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000467 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000468
469 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
470 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000471 std::list<NotifyArgs> args =
472 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000473
474 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000475 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000476
477 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
478 // need to use another gesture type, like pinch.
479 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
480 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000481 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000482 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000483 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
484 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000485}
486
487TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
488 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
489 // start swiping up and then start moving left or right, it'll return gesture events with only Y
490 // deltas until you lift your fingers and start swiping again. That's why each of these tests
491 // only checks movement in one dimension.
492 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
493 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000494 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000495
496 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
497 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000498 std::list<NotifyArgs> args =
499 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000500 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000501 ASSERT_THAT(args,
502 Each(VariantWith<NotifyMotionArgs>(
503 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
504 WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER),
505 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000506
507 // Three fake fingers should be created. We don't actually care where they are, so long as they
508 // move appropriately.
509 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
510 ASSERT_THAT(arg,
511 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000512 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000513 PointerCoords finger0Start = arg.pointerCoords[0];
514 args.pop_front();
515 arg = std::get<NotifyMotionArgs>(args.front());
516 ASSERT_THAT(arg,
517 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
518 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000519 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000520 PointerCoords finger1Start = arg.pointerCoords[1];
521 args.pop_front();
522 arg = std::get<NotifyMotionArgs>(args.front());
523 ASSERT_THAT(arg,
524 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
525 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000526 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000527 PointerCoords finger2Start = arg.pointerCoords[2];
528 args.pop_front();
529
530 arg = std::get<NotifyMotionArgs>(args.front());
531 ASSERT_THAT(arg,
532 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000533 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000534 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
535 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
536 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
537 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
538 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
539 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
540
541 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
542 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000543 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000544 ASSERT_EQ(1u, args.size());
545 arg = std::get<NotifyMotionArgs>(args.front());
546 ASSERT_THAT(arg,
547 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000548 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000549 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000550 WithPointerCount(3u), WithToolType(ToolType::FINGER),
551 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000552 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
553 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
554 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
555 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
556 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
557 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
558
559 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000560 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000561 ASSERT_THAT(args,
562 ElementsAre(VariantWith<NotifyMotionArgs>(
563 AllOf(WithMotionAction(
564 AMOTION_EVENT_ACTION_POINTER_UP |
565 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
566 WithGestureOffset(0, 0, EPSILON),
567 WithGestureSwipeFingerCount(3),
568 WithMotionClassification(
569 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000570 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000571 VariantWith<NotifyMotionArgs>(
572 AllOf(WithMotionAction(
573 AMOTION_EVENT_ACTION_POINTER_UP |
574 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
575 WithGestureOffset(0, 0, EPSILON),
576 WithGestureSwipeFingerCount(3),
577 WithMotionClassification(
578 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000579 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000580 VariantWith<NotifyMotionArgs>(
581 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
582 WithGestureOffset(0, 0, EPSILON),
583 WithGestureSwipeFingerCount(3),
584 WithMotionClassification(
585 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000586 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000587 VariantWith<NotifyMotionArgs>(
588 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000589 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000590 WithMotionClassification(MotionClassification::NONE)))));
591 ASSERT_THAT(args,
592 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
593 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000594}
595
Harry Cutts94f5bd52023-01-06 18:02:18 +0000596TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
597 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
598 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
599 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000600 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000601
602 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
603 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000604 std::list<NotifyArgs> args =
605 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000606 ASSERT_EQ(4u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000607 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000608
609 // Three fake fingers should be created. We don't actually care where they are, so long as they
610 // move appropriately.
611 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
612 ASSERT_THAT(arg,
613 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000614 WithPointerCount(1u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000615 PointerCoords finger0Start = arg.pointerCoords[0];
616 args.pop_front();
617 arg = std::get<NotifyMotionArgs>(args.front());
618 ASSERT_THAT(arg,
619 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
620 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000621 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000622 PointerCoords finger1Start = arg.pointerCoords[1];
623 args.pop_front();
624 arg = std::get<NotifyMotionArgs>(args.front());
625 ASSERT_THAT(arg,
626 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
627 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000628 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000629 PointerCoords finger2Start = arg.pointerCoords[2];
630 args.pop_front();
631
632 arg = std::get<NotifyMotionArgs>(args.front());
633 ASSERT_THAT(arg,
634 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000635 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000636 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
637 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
638 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
639 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
640 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
641 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
642
643 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
644 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000645 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000646 ASSERT_EQ(1u, args.size());
647 arg = std::get<NotifyMotionArgs>(args.front());
648 ASSERT_THAT(arg,
649 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000650 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
651 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000652 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
653 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
654 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
655 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
656 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
657 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
658
659 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000660 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000661 ASSERT_THAT(args,
662 ElementsAre(VariantWith<NotifyMotionArgs>(
663 AllOf(WithMotionAction(
664 AMOTION_EVENT_ACTION_POINTER_UP |
665 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000666 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000667 VariantWith<NotifyMotionArgs>(
668 AllOf(WithMotionAction(
669 AMOTION_EVENT_ACTION_POINTER_UP |
670 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000671 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000672 VariantWith<NotifyMotionArgs>(
673 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +0000674 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000675 VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +0000676 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))));
Harry Cuttsef95e712024-02-16 18:56:39 +0000677 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000678}
679
Harry Cuttsc5748d12022-12-02 17:30:18 +0000680TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
681 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
682 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000683 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000684
685 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
686 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000687 std::list<NotifyArgs> args =
688 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000689 ASSERT_EQ(5u, args.size());
Harry Cuttsef95e712024-02-16 18:56:39 +0000690 ASSERT_THAT(args,
691 Each(VariantWith<NotifyMotionArgs>(
692 AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
693 WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER),
694 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000695
696 // Four fake fingers should be created. We don't actually care where they are, so long as they
697 // move appropriately.
698 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
699 ASSERT_THAT(arg,
700 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000701 WithPointerCount(1u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000702 PointerCoords finger0Start = arg.pointerCoords[0];
703 args.pop_front();
704 arg = std::get<NotifyMotionArgs>(args.front());
705 ASSERT_THAT(arg,
706 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
707 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000708 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000709 PointerCoords finger1Start = arg.pointerCoords[1];
710 args.pop_front();
711 arg = std::get<NotifyMotionArgs>(args.front());
712 ASSERT_THAT(arg,
713 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
714 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000715 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000716 PointerCoords finger2Start = arg.pointerCoords[2];
717 args.pop_front();
718 arg = std::get<NotifyMotionArgs>(args.front());
719 ASSERT_THAT(arg,
720 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
721 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cuttsef95e712024-02-16 18:56:39 +0000722 WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000723 PointerCoords finger3Start = arg.pointerCoords[3];
724 args.pop_front();
725
726 arg = std::get<NotifyMotionArgs>(args.front());
727 ASSERT_THAT(arg,
728 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000729 WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000730 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
731 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
732 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
733 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
734 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
735 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
736 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
737 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
738
739 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
740 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000741 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000742 ASSERT_EQ(1u, args.size());
743 arg = std::get<NotifyMotionArgs>(args.front());
744 ASSERT_THAT(arg,
745 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000746 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000747 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000748 WithPointerCount(4u), WithToolType(ToolType::FINGER),
749 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000750 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
751 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
752 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
753 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
754 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
755 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
756 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
757 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
758
759 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000760 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000761 ASSERT_THAT(args,
762 ElementsAre(VariantWith<NotifyMotionArgs>(
763 AllOf(WithMotionAction(
764 AMOTION_EVENT_ACTION_POINTER_UP |
765 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
766 WithGestureOffset(0, 0, EPSILON),
767 WithGestureSwipeFingerCount(4),
768 WithMotionClassification(
769 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000770 WithPointerCount(4u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000771 VariantWith<NotifyMotionArgs>(
772 AllOf(WithMotionAction(
773 AMOTION_EVENT_ACTION_POINTER_UP |
774 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
775 WithGestureOffset(0, 0, EPSILON),
776 WithGestureSwipeFingerCount(4),
777 WithMotionClassification(
778 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000779 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000780 VariantWith<NotifyMotionArgs>(
781 AllOf(WithMotionAction(
782 AMOTION_EVENT_ACTION_POINTER_UP |
783 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
784 WithGestureOffset(0, 0, EPSILON),
785 WithGestureSwipeFingerCount(4),
786 WithMotionClassification(
787 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000788 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000789 VariantWith<NotifyMotionArgs>(
790 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
791 WithGestureOffset(0, 0, EPSILON),
792 WithGestureSwipeFingerCount(4),
793 WithMotionClassification(
794 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +0000795 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000796 VariantWith<NotifyMotionArgs>(
797 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000798 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000799 WithMotionClassification(MotionClassification::NONE)))));
800 ASSERT_THAT(args,
801 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
802 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000803}
804
Harry Cuttsb1e83552022-12-20 11:02:26 +0000805TEST_F(GestureConverterTest, Pinch_Inwards) {
806 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
807 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000808 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000809
810 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
811 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000812 std::list<NotifyArgs> args =
813 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000814 ASSERT_THAT(args,
815 ElementsAre(VariantWith<NotifyMotionArgs>(
816 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000817 WithCoords(-100, 0), WithPointerCount(1u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000818 VariantWith<NotifyMotionArgs>(
819 AllOf(WithMotionAction(
820 AMOTION_EVENT_ACTION_POINTER_DOWN |
821 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000822 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
Harry Cuttsef95e712024-02-16 18:56:39 +0000823 ASSERT_THAT(args,
824 Each(VariantWith<NotifyMotionArgs>(
825 AllOf(WithMotionClassification(MotionClassification::PINCH),
826 WithGesturePinchScaleFactor(1.0f, EPSILON),
827 WithToolType(ToolType::FINGER),
828 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000829
830 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
831 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000832 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000833 ASSERT_THAT(args,
834 ElementsAre(VariantWith<NotifyMotionArgs>(
835 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
836 WithMotionClassification(MotionClassification::PINCH),
837 WithGesturePinchScaleFactor(0.8f, EPSILON),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000838 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
Harry Cutts5f26e952023-11-30 18:20:27 +0000839 WithPointerCount(2u), WithToolType(ToolType::FINGER),
840 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000841
842 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
843 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000844 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000845 ASSERT_THAT(args,
846 ElementsAre(VariantWith<NotifyMotionArgs>(
847 AllOf(WithMotionAction(
848 AMOTION_EVENT_ACTION_POINTER_UP |
849 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
850 WithMotionClassification(MotionClassification::PINCH),
851 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000852 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000853 VariantWith<NotifyMotionArgs>(
854 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
855 WithMotionClassification(MotionClassification::PINCH),
856 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +0000857 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +0000858 VariantWith<NotifyMotionArgs>(
859 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +0000860 WithCoords(0, 0),
861 WithMotionClassification(MotionClassification::NONE)))));
862 ASSERT_THAT(args,
863 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
864 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
865}
866
867TEST_F(GestureConverterTest, Pinch_Outwards) {
868 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
869 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
870 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
871
872 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
873 GESTURES_ZOOM_START);
874 std::list<NotifyArgs> args =
875 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
876 ASSERT_THAT(args,
877 ElementsAre(VariantWith<NotifyMotionArgs>(
878 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
879 WithCoords(-100, 0), WithPointerCount(1u))),
880 VariantWith<NotifyMotionArgs>(
881 AllOf(WithMotionAction(
882 AMOTION_EVENT_ACTION_POINTER_DOWN |
883 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
884 WithPointerCoords(1, 100, 0), WithPointerCount(2u)))));
885 ASSERT_THAT(args,
886 Each(VariantWith<NotifyMotionArgs>(
887 AllOf(WithMotionClassification(MotionClassification::PINCH),
888 WithGesturePinchScaleFactor(1.0f, EPSILON),
889 WithToolType(ToolType::FINGER),
890 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
891
892 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
893 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
894 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
895 ASSERT_THAT(args,
896 ElementsAre(VariantWith<NotifyMotionArgs>(
897 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
898 WithMotionClassification(MotionClassification::PINCH),
899 WithGesturePinchScaleFactor(1.1f, EPSILON),
900 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
901 WithPointerCount(2u), WithToolType(ToolType::FINGER),
902 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
903
904 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
905 GESTURES_ZOOM_END);
906 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
907 ASSERT_THAT(args,
908 ElementsAre(VariantWith<NotifyMotionArgs>(
909 AllOf(WithMotionAction(
910 AMOTION_EVENT_ACTION_POINTER_UP |
911 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
912 WithMotionClassification(MotionClassification::PINCH),
913 WithGesturePinchScaleFactor(1.0f, EPSILON),
914 WithPointerCount(2u))),
915 VariantWith<NotifyMotionArgs>(
916 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
917 WithMotionClassification(MotionClassification::PINCH),
918 WithGesturePinchScaleFactor(1.0f, EPSILON),
919 WithPointerCount(1u))),
920 VariantWith<NotifyMotionArgs>(
921 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
922 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +0000923 WithMotionClassification(MotionClassification::NONE)))));
924 ASSERT_THAT(args,
925 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
926 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000927}
928
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000929TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000930 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
931 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000932 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000933
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000934 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000935 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000936 std::list<NotifyArgs> args =
937 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000938
939 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000940 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000941 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000942
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000943 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000944 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000945 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000946
947 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000948 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000949 ASSERT_THAT(args,
950 ElementsAre(VariantWith<NotifyMotionArgs>(
951 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000952}
953
954TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
955 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
956 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000957 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000958
959 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
960 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000961 std::list<NotifyArgs> args =
962 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000963
964 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
965 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000966 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000967
968 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
969 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000970 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000971
972 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
973 // need to use another gesture type, like scroll.
974 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
975 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000976 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000977 ASSERT_FALSE(args.empty());
978 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000979}
980
Harry Cuttse9b71422023-03-14 16:54:44 +0000981TEST_F(GestureConverterTest, ResetWithButtonPressed) {
982 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
983 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000984 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000985
986 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
987 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
988 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000989 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +0000990
991 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +0000992 ASSERT_THAT(args,
993 ElementsAre(VariantWith<NotifyMotionArgs>(
994 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
995 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +0000996 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))),
Harry Cutts5f26e952023-11-30 18:20:27 +0000997 VariantWith<NotifyMotionArgs>(
998 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
999 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001000 WithButtonState(0))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001001 VariantWith<NotifyMotionArgs>(
1002 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001003 WithButtonState(0))),
Harry Cutts379ea422023-12-21 15:31:47 +00001004 VariantWith<NotifyMotionArgs>(
1005 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001006 WithButtonState(0)))));
1007 ASSERT_THAT(args,
Prabir Pradhan8b053512024-05-03 23:15:39 +00001008 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001009 WithToolType(ToolType::FINGER),
1010 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001011}
1012
1013TEST_F(GestureConverterTest, ResetDuringScroll) {
1014 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1015 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001016 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001017
1018 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001019 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001020
1021 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001022 ASSERT_THAT(args,
1023 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001024 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001025 WithCoords(0, -10),
Harry Cutts379ea422023-12-21 15:31:47 +00001026 WithGestureScrollDistance(0, 0, EPSILON),
1027 WithMotionClassification(
1028 MotionClassification::TWO_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001029 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
Harry Cutts379ea422023-12-21 15:31:47 +00001030 VariantWith<NotifyMotionArgs>(
1031 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001032 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001033 WithMotionClassification(MotionClassification::NONE)))));
1034 ASSERT_THAT(args,
1035 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1036 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001037}
1038
1039TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1040 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1041 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001042 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001043
1044 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1045 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001046 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001047
1048 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001049 ASSERT_THAT(args,
1050 ElementsAre(VariantWith<NotifyMotionArgs>(
1051 AllOf(WithMotionAction(
1052 AMOTION_EVENT_ACTION_POINTER_UP |
1053 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1054 WithGestureOffset(0, 0, EPSILON),
1055 WithMotionClassification(
1056 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001057 WithPointerCount(3u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001058 VariantWith<NotifyMotionArgs>(
1059 AllOf(WithMotionAction(
1060 AMOTION_EVENT_ACTION_POINTER_UP |
1061 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1062 WithGestureOffset(0, 0, EPSILON),
1063 WithMotionClassification(
1064 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001065 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001066 VariantWith<NotifyMotionArgs>(
1067 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1068 WithGestureOffset(0, 0, EPSILON),
1069 WithMotionClassification(
1070 MotionClassification::MULTI_FINGER_SWIPE),
Harry Cuttsef95e712024-02-16 18:56:39 +00001071 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001072 VariantWith<NotifyMotionArgs>(
1073 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001074 WithMotionClassification(MotionClassification::NONE)))));
1075 ASSERT_THAT(args,
1076 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1077 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001078}
1079
1080TEST_F(GestureConverterTest, ResetDuringPinch) {
1081 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1082 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001083 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001084
1085 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1086 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001087 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001088
1089 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001090 ASSERT_THAT(args,
1091 ElementsAre(VariantWith<NotifyMotionArgs>(
1092 AllOf(WithMotionAction(
1093 AMOTION_EVENT_ACTION_POINTER_UP |
1094 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1095 WithMotionClassification(MotionClassification::PINCH),
1096 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001097 WithPointerCount(2u))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001098 VariantWith<NotifyMotionArgs>(
1099 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1100 WithMotionClassification(MotionClassification::PINCH),
1101 WithGesturePinchScaleFactor(1.0f, EPSILON),
Harry Cuttsef95e712024-02-16 18:56:39 +00001102 WithPointerCount(1u))),
Harry Cutts379ea422023-12-21 15:31:47 +00001103 VariantWith<NotifyMotionArgs>(
1104 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001105 WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001106 WithMotionClassification(MotionClassification::NONE)))));
1107 ASSERT_THAT(args,
1108 Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER),
1109 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001110}
1111
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001112TEST_F(GestureConverterTest, FlingTapDown) {
1113 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1114 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001115 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001116
1117 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1118 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001119 std::list<NotifyArgs> args =
1120 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001121
1122 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
Prabir Pradhan8b053512024-05-03 23:15:39 +00001123 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0),
1124 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
1125 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001126}
1127
Harry Cutts39648ab2024-02-15 14:23:50 +00001128TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) {
1129 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1130 input_flags::enable_touchpad_fling_stop(true);
1131 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1132 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1133
1134 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
1135 std::list<NotifyArgs> args =
1136 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
1137 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1138 GESTURES_FLING_START);
1139 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
1140
1141 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1142 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
1143 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
1144 ASSERT_THAT(args,
1145 ElementsAre(VariantWith<NotifyMotionArgs>(
1146 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
1147 VariantWith<NotifyMotionArgs>(
1148 WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
1149 VariantWith<NotifyMotionArgs>(
1150 WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)),
1151 VariantWith<NotifyMotionArgs>(
Harry Cutts574781a2024-04-23 15:30:45 +00001152 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001153 ASSERT_THAT(args,
Harry Cutts574781a2024-04-23 15:30:45 +00001154 Each(VariantWith<NotifyMotionArgs>(
Prabir Pradhan8b053512024-05-03 23:15:39 +00001155 AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER),
Harry Cutts574781a2024-04-23 15:30:45 +00001156 WithDisplayId(ADISPLAY_ID_DEFAULT),
1157 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE)))));
Harry Cutts39648ab2024-02-15 14:23:50 +00001158}
1159
Arpit Singha5ea7c12023-07-05 15:39:25 +00001160TEST_F(GestureConverterTest, Tap) {
1161 // Tap should produce button press/release events
1162 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1163 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001164 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001165
1166 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1167 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001168 std::list<NotifyArgs> args =
1169 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001170 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001171
1172 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1173 /* down= */ GESTURES_BUTTON_LEFT,
1174 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001175 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001176
Harry Cutts5f26e952023-11-30 18:20:27 +00001177 ASSERT_THAT(args,
1178 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001179 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001180 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001181 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001182 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001183 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001184 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001185 VariantWith<NotifyMotionArgs>(
1186 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1187 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1188 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001189 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001190 VariantWith<NotifyMotionArgs>(
1191 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1192 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001193 WithButtonState(0), WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001194 VariantWith<NotifyMotionArgs>(
1195 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001196 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001197 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001198 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001199 WithButtonState(0), WithPressure(0.0f)))));
1200 ASSERT_THAT(args,
Prabir Pradhan8b053512024-05-03 23:15:39 +00001201 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001202 WithRelativeMotion(0.f, 0.f),
1203 WithToolType(ToolType::FINGER),
1204 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001205}
1206
1207TEST_F(GestureConverterTest, Click) {
1208 // Click should produce button press/release events
1209 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1210 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001211 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001212
1213 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1214 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001215 std::list<NotifyArgs> args =
1216 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001217 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001218
1219 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1220 /* down= */ GESTURES_BUTTON_LEFT,
1221 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001222 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001223
Harry Cutts5f26e952023-11-30 18:20:27 +00001224 ASSERT_THAT(args,
1225 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001226 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001227 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001228 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001229 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001230 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001231 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001232 VariantWith<NotifyMotionArgs>(
1233 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1234 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1235 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001236 WithPressure(1.0f)))));
1237 ASSERT_THAT(args,
Prabir Pradhan8b053512024-05-03 23:15:39 +00001238 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
Harry Cuttsef95e712024-02-16 18:56:39 +00001239 WithRelativeMotion(0.f, 0.f),
1240 WithToolType(ToolType::FINGER),
1241 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001242
1243 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1244 /* down= */ GESTURES_BUTTON_NONE,
1245 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001246 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Prabir Pradhan8b053512024-05-03 23:15:39 +00001247
Harry Cutts5f26e952023-11-30 18:20:27 +00001248 ASSERT_THAT(args,
1249 ElementsAre(VariantWith<NotifyMotionArgs>(
1250 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1251 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001252 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001253 VariantWith<NotifyMotionArgs>(
1254 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
Harry Cuttsef95e712024-02-16 18:56:39 +00001255 WithPressure(0.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001256 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001257 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cuttsef95e712024-02-16 18:56:39 +00001258 WithPressure(0.0f)))));
1259 ASSERT_THAT(args,
Prabir Pradhan8b053512024-05-03 23:15:39 +00001260 Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0),
1261 WithRelativeMotion(0.f, 0.f),
1262 WithToolType(ToolType::FINGER),
1263 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001264}
1265
Arpit Singh3d84add2023-10-10 19:08:29 +00001266TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001267 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1268 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1269 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1270
Arpit Singha5ea7c12023-07-05 15:39:25 +00001271 // Tap should be ignored when disabled
1272 mReader->getContext()->setPreventingTouchpadTaps(true);
1273
1274 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1275 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001276 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001277
Arpit Singh82b27a02023-10-16 11:02:19 +00001278 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001279 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001280 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001281 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001282 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001283
Arpit Singh82b27a02023-10-16 11:02:19 +00001284 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001285 /* down= */ GESTURES_BUTTON_LEFT,
1286 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001287 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001288
1289 // no events should be generated
1290 ASSERT_EQ(0u, args.size());
1291
1292 // Future taps should be re-enabled
1293 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1294}
1295
Arpit Singh82b27a02023-10-16 11:02:19 +00001296TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1297 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1298 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1299
1300 // Tap should be ignored when disabled
1301 mReader->getContext()->setPreventingTouchpadTaps(true);
1302
1303 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1304 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1305 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1306
1307 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1308 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1309 std::list<NotifyArgs> args =
1310 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001311 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singh82b27a02023-10-16 11:02:19 +00001312
1313 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1314 /* down= */ GESTURES_BUTTON_LEFT,
1315 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1316 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1317
1318 // no events should be generated
1319 ASSERT_EQ(0u, args.size());
1320
1321 // Future taps should be re-enabled
1322 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1323
1324 // taps before the threshold should still be ignored
1325 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1326 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1327 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1328 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1329
1330 ASSERT_EQ(1u, args.size());
1331 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1332 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1333
1334 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1335 /* down= */ GESTURES_BUTTON_LEFT,
1336 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1337 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1338
1339 // no events should be generated
1340 ASSERT_EQ(0u, args.size());
1341
1342 // taps after the threshold should be recognised
1343 currentTime += 1;
1344 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1345 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1346 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1347
1348 ASSERT_EQ(1u, args.size());
1349 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1350 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1351
1352 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1353 /* down= */ GESTURES_BUTTON_LEFT,
1354 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1355 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Harry Cuttsef95e712024-02-16 18:56:39 +00001356 ASSERT_THAT(args,
1357 ElementsAre(VariantWith<NotifyMotionArgs>(
1358 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
1359 WithButtonState(0))),
1360 VariantWith<NotifyMotionArgs>(
1361 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1362 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1363 VariantWith<NotifyMotionArgs>(
1364 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1365 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1366 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))),
1367 VariantWith<NotifyMotionArgs>(
1368 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1369 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1370 WithButtonState(0))),
1371 VariantWith<NotifyMotionArgs>(
1372 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1373 WithButtonState(0))),
1374 VariantWith<NotifyMotionArgs>(
1375 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
1376 WithButtonState(0)))));
1377 ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f))));
Arpit Singh82b27a02023-10-16 11:02:19 +00001378}
1379
Arpit Singh3d84add2023-10-10 19:08:29 +00001380TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1381 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001382 // Click should still produce button press/release events
1383 mReader->getContext()->setPreventingTouchpadTaps(true);
1384
1385 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1386 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001387 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001388
1389 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1390 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001391 std::list<NotifyArgs> args =
1392 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001393 // We don't need to check args here, since it's covered by the FlingTapDown test.
Arpit Singha5ea7c12023-07-05 15:39:25 +00001394
1395 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1396 /* down= */ GESTURES_BUTTON_LEFT,
1397 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001398 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001399
Harry Cutts5f26e952023-11-30 18:20:27 +00001400 ASSERT_THAT(args,
1401 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001402 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
Harry Cuttsef95e712024-02-16 18:56:39 +00001403 WithButtonState(0), WithPressure(0.0f))),
Harry Cutts379ea422023-12-21 15:31:47 +00001404 VariantWith<NotifyMotionArgs>(
Harry Cutts5f26e952023-11-30 18:20:27 +00001405 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
Harry Cutts5f26e952023-11-30 18:20:27 +00001406 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001407 WithPressure(1.0f))),
Harry Cutts5f26e952023-11-30 18:20:27 +00001408 VariantWith<NotifyMotionArgs>(
1409 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1410 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1411 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
Harry Cuttsef95e712024-02-16 18:56:39 +00001412 WithPressure(1.0f)))));
1413 ASSERT_THAT(args,
1414 Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0),
1415 WithRelativeMotion(0.f, 0.f),
1416 WithToolType(ToolType::FINGER),
1417 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001418
1419 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1420 /* down= */ GESTURES_BUTTON_NONE,
1421 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001422 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001423
Harry Cutts5f26e952023-11-30 18:20:27 +00001424 ASSERT_THAT(args,
1425 ElementsAre(VariantWith<NotifyMotionArgs>(
1426 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1427 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1428 WithButtonState(0), WithCoords(0, 0),
1429 WithRelativeMotion(0.f, 0.f),
1430 WithToolType(ToolType::FINGER), WithButtonState(0),
1431 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1432 VariantWith<NotifyMotionArgs>(
1433 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1434 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
1435 WithToolType(ToolType::FINGER), WithButtonState(0),
1436 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1437 VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001438 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
Harry Cutts5f26e952023-11-30 18:20:27 +00001439 WithCoords(0, 0), WithRelativeMotion(0, 0),
1440 WithToolType(ToolType::FINGER), WithButtonState(0),
1441 WithPressure(0.0f),
1442 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001443
1444 // Future taps should be re-enabled
1445 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1446}
1447
Prabir Pradhan8b053512024-05-03 23:15:39 +00001448TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
Byoungho Jungee6268f2023-10-30 17:27:26 +09001449 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
1450 // initially disable tap-to-click
1451 mReader->getContext()->setPreventingTouchpadTaps(true);
1452
1453 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1454 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1455 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1456
1457 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001458 std::list<NotifyArgs> args =
1459 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts379ea422023-12-21 15:31:47 +00001460 // We don't need to check args here, since it's covered by the Move test.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001461
1462 // Future taps should be re-enabled
1463 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1464}
1465
Prabir Pradhan8b053512024-05-03 23:15:39 +00001466TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
Arpit Singh33a10a62023-10-12 13:06:54 +00001467 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1468 const nsecs_t gestureStartTime = 1000;
1469 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1470 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1471 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1472
1473 // Start a move gesture at gestureStartTime
1474 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1475 std::list<NotifyArgs> args =
1476 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001477 ASSERT_THAT(args,
1478 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001479 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1480 VariantWith<NotifyMotionArgs>(
1481 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001482
1483 // Key presses with IME connection should cancel ongoing move gesture
1484 nsecs_t currentTime = gestureStartTime + 100;
1485 mFakePolicy->setIsInputMethodConnectionActive(true);
1486 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1487 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1488 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001489 ASSERT_THAT(args,
1490 ElementsAre(VariantWith<NotifyMotionArgs>(
1491 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001492
1493 // any updates in existing move gesture should be ignored
1494 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1495 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1496 ASSERT_EQ(0u, args.size());
1497
1498 // New gesture should not be affected
1499 currentTime += 100;
1500 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1501 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001502 ASSERT_THAT(args,
1503 ElementsAre(VariantWith<NotifyMotionArgs>(
Harry Cutts379ea422023-12-21 15:31:47 +00001504 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)),
1505 VariantWith<NotifyMotionArgs>(
1506 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001507}
1508
Harry Cutts4fb941a2022-12-14 19:14:04 +00001509} // namespace android