Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 1 | /* |
| 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 Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 19 | #include <com_android_input_flags.h> |
| 20 | #include <flag_macros.h> |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 21 | #include <gestures/GestureConverter.h> |
| 22 | #include <gtest/gtest.h> |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 23 | #include <gui/constants.h> |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 24 | |
| 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 Pradhan | e3b28dd | 2023-10-06 04:19:29 +0000 | [diff] [blame] | 31 | #include "TestEventMatchers.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 32 | #include "TestInputListener.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 33 | #include "include/gestures.h" |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 34 | #include "ui/Rotation.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 35 | |
| 36 | namespace android { |
| 37 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 38 | namespace input_flags = com::android::input::flags; |
| 39 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 40 | namespace { |
| 41 | |
| 42 | const auto TOUCHPAD_PALM_REJECTION = |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 43 | ACONFIG_FLAG(input_flags, enable_touchpad_typing_palm_rejection); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 44 | const auto TOUCHPAD_PALM_REJECTION_V2 = |
| 45 | ACONFIG_FLAG(input_flags, enable_v2_touchpad_typing_palm_rejection); |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 46 | |
| 47 | } // namespace |
| 48 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 49 | using testing::AllOf; |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame^] | 50 | using testing::Each; |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 51 | using testing::ElementsAre; |
| 52 | using testing::VariantWith; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 53 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 54 | class GestureConverterTestBase : public testing::Test { |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 55 | protected: |
| 56 | static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 57 | static constexpr int32_t EVENTHUB_ID = 1; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 58 | static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2; |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 59 | static constexpr float POINTER_X = 500; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 60 | static constexpr float POINTER_Y = 200; |
| 61 | |
| 62 | void SetUp() { |
| 63 | mFakeEventHub = std::make_unique<FakeEventHub>(); |
| 64 | mFakePolicy = sp<FakeInputReaderPolicy>::make(); |
| 65 | mFakeListener = std::make_unique<TestInputListener>(); |
| 66 | mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, |
| 67 | *mFakeListener); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 68 | mDevice = newDevice(); |
| 69 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20); |
| 70 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 71 | |
| 72 | mFakePointerController = std::make_shared<FakePointerController>(); |
| 73 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); |
| 74 | mFakePointerController->setPosition(POINTER_X, POINTER_Y); |
| 75 | mFakePolicy->setPointerController(mFakePointerController); |
| 76 | } |
| 77 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 78 | std::shared_ptr<InputDevice> newDevice() { |
| 79 | InputDeviceIdentifier identifier; |
| 80 | identifier.name = "device"; |
| 81 | identifier.location = "USB1"; |
| 82 | identifier.bus = 0; |
| 83 | std::shared_ptr<InputDevice> device = |
| 84 | std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2, |
| 85 | identifier); |
| 86 | mReader->pushNextDevice(device); |
| 87 | mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD, |
| 88 | identifier.bus); |
| 89 | mReader->loopOnce(); |
| 90 | return device; |
| 91 | } |
| 92 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 93 | std::shared_ptr<FakeEventHub> mFakeEventHub; |
| 94 | sp<FakeInputReaderPolicy> mFakePolicy; |
| 95 | std::unique_ptr<TestInputListener> mFakeListener; |
| 96 | std::unique_ptr<InstrumentedInputReader> mReader; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 97 | std::shared_ptr<InputDevice> mDevice; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 98 | std::shared_ptr<FakePointerController> mFakePointerController; |
| 99 | }; |
| 100 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 101 | class GestureConverterTest : public GestureConverterTestBase { |
| 102 | protected: |
| 103 | void SetUp() override { |
| 104 | input_flags::enable_pointer_choreographer(false); |
| 105 | GestureConverterTestBase::SetUp(); |
| 106 | } |
| 107 | }; |
| 108 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 109 | TEST_F(GestureConverterTest, Move) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 110 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 111 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 112 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 113 | |
| 114 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 115 | std::list<NotifyArgs> args = |
| 116 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 117 | ASSERT_THAT(args, |
| 118 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 119 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 120 | WithCoords(POINTER_X, POINTER_Y), |
| 121 | WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), |
| 122 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 123 | VariantWith<NotifyMotionArgs>( |
| 124 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 125 | WithCoords(POINTER_X - 5, POINTER_Y + 10), |
| 126 | WithRelativeMotion(-5, 10), |
| 127 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 128 | WithPressure(0.0f), |
| 129 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 130 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 131 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 132 | |
| 133 | // The same gesture again should only repeat the HOVER_MOVE and cursor position change, not the |
| 134 | // HOVER_ENTER. |
| 135 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 136 | ASSERT_THAT(args, |
| 137 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 138 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 139 | WithCoords(POINTER_X - 10, POINTER_Y + 20), |
| 140 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
| 141 | WithButtonState(0), WithPressure(0.0f), |
| 142 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
| 143 | |
| 144 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 10, POINTER_Y + 20)); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 147 | TEST_F(GestureConverterTest, Move_Rotated) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 148 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 149 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 150 | converter.setOrientation(ui::ROTATION_90); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 151 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 152 | |
| 153 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 154 | std::list<NotifyArgs> args = |
| 155 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 156 | ASSERT_THAT(args, |
| 157 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 158 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 159 | WithCoords(POINTER_X, POINTER_Y), |
| 160 | WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), |
| 161 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 162 | VariantWith<NotifyMotionArgs>( |
| 163 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 164 | WithCoords(POINTER_X + 10, POINTER_Y + 5), |
| 165 | WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER), |
| 166 | WithButtonState(0), WithPressure(0.0f), |
| 167 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 168 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 169 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5)); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 172 | TEST_F(GestureConverterTest, ButtonsChange) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 173 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 174 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 175 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 176 | |
| 177 | // Press left and right buttons at once |
| 178 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 179 | /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 180 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 181 | std::list<NotifyArgs> args = |
| 182 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 183 | ASSERT_THAT(args, |
| 184 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 185 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 186 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 187 | AMOTION_EVENT_BUTTON_SECONDARY), |
| 188 | WithCoords(POINTER_X, POINTER_Y), |
| 189 | WithToolType(ToolType::FINGER), |
| 190 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 191 | VariantWith<NotifyMotionArgs>( |
| 192 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 193 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 194 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 195 | WithCoords(POINTER_X, POINTER_Y), |
| 196 | WithToolType(ToolType::FINGER), |
| 197 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 198 | VariantWith<NotifyMotionArgs>( |
| 199 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 200 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 201 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 202 | AMOTION_EVENT_BUTTON_SECONDARY), |
| 203 | WithCoords(POINTER_X, POINTER_Y), |
| 204 | WithToolType(ToolType::FINGER), |
| 205 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 206 | |
| 207 | // Then release the left button |
| 208 | Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 209 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 210 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 211 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 212 | ASSERT_THAT(args, |
| 213 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 214 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 215 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 216 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
| 217 | WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER), |
| 218 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 219 | |
| 220 | // Finally release the right button |
| 221 | Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 222 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT, |
| 223 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 224 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 225 | ASSERT_THAT(args, |
| 226 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 227 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 228 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 229 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 230 | WithToolType(ToolType::FINGER), |
| 231 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 232 | VariantWith<NotifyMotionArgs>( |
| 233 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 234 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 235 | WithToolType(ToolType::FINGER), |
| 236 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 237 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 238 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 239 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 240 | WithToolType(ToolType::FINGER), |
| 241 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 244 | TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { |
| 245 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 246 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 247 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 248 | |
| 249 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 250 | std::list<NotifyArgs> args = |
| 251 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 252 | |
| 253 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 254 | /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE, |
| 255 | /*is_tap=*/false); |
| 256 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
| 257 | ASSERT_THAT(args.front(), |
| 258 | VariantWith<NotifyMotionArgs>( |
| 259 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0), |
| 260 | WithCoords(POINTER_X - 5, POINTER_Y + 10), |
| 261 | WithToolType(ToolType::FINGER), WithDisplayId(ADISPLAY_ID_DEFAULT)))); |
| 262 | } |
| 263 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 264 | TEST_F(GestureConverterTest, DragWithButton) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 265 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 266 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 267 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 268 | |
| 269 | // Press the button |
| 270 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 271 | /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE, |
| 272 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 273 | std::list<NotifyArgs> args = |
| 274 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 275 | ASSERT_THAT(args, |
| 276 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 277 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 278 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 279 | WithCoords(POINTER_X, POINTER_Y), |
| 280 | WithToolType(ToolType::FINGER), |
| 281 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 282 | VariantWith<NotifyMotionArgs>( |
| 283 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 284 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 285 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 286 | WithCoords(POINTER_X, POINTER_Y), |
| 287 | WithToolType(ToolType::FINGER), |
| 288 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 289 | |
| 290 | // Move |
| 291 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 292 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 293 | ASSERT_THAT(args, |
| 294 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 295 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 296 | WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), |
| 297 | WithToolType(ToolType::FINGER), |
| 298 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
| 299 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 300 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 301 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 302 | |
| 303 | // Release the button |
| 304 | Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 305 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 306 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 307 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 308 | ASSERT_THAT(args, |
| 309 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 310 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 311 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 312 | WithButtonState(0), |
| 313 | WithCoords(POINTER_X - 5, POINTER_Y + 10), |
| 314 | WithToolType(ToolType::FINGER), |
| 315 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 316 | VariantWith<NotifyMotionArgs>( |
| 317 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 318 | WithButtonState(0), |
| 319 | WithCoords(POINTER_X - 5, POINTER_Y + 10), |
| 320 | WithToolType(ToolType::FINGER), |
| 321 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 322 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 323 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 324 | WithButtonState(0), |
| 325 | WithCoords(POINTER_X - 5, POINTER_Y + 10), |
| 326 | WithToolType(ToolType::FINGER), |
| 327 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 330 | TEST_F(GestureConverterTest, Scroll) { |
| 331 | const nsecs_t downTime = 12345; |
| 332 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 333 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 334 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 335 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 336 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 337 | std::list<NotifyArgs> args = |
| 338 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 339 | ASSERT_THAT(args, |
| 340 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 341 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 342 | WithCoords(POINTER_X, POINTER_Y), |
| 343 | WithGestureScrollDistance(0, 0, EPSILON), |
| 344 | WithMotionClassification( |
| 345 | MotionClassification::TWO_FINGER_SWIPE), |
| 346 | WithToolType(ToolType::FINGER), WithDownTime(downTime), |
| 347 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 348 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 349 | VariantWith<NotifyMotionArgs>( |
| 350 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 351 | WithCoords(POINTER_X, POINTER_Y - 10), |
| 352 | WithGestureScrollDistance(0, 10, EPSILON), |
| 353 | WithMotionClassification( |
| 354 | MotionClassification::TWO_FINGER_SWIPE), |
| 355 | WithToolType(ToolType::FINGER), |
| 356 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 357 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 358 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 359 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 360 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 361 | ASSERT_THAT(args, |
| 362 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 363 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 364 | WithCoords(POINTER_X, POINTER_Y - 15), |
| 365 | WithGestureScrollDistance(0, 5, EPSILON), |
| 366 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 367 | WithToolType(ToolType::FINGER), |
| 368 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 369 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 370 | |
| 371 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 372 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 373 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 374 | ASSERT_THAT(args, |
| 375 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 376 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 377 | WithCoords(POINTER_X, POINTER_Y - 15), |
| 378 | WithGestureScrollDistance(0, 0, EPSILON), |
| 379 | WithMotionClassification( |
| 380 | MotionClassification::TWO_FINGER_SWIPE), |
| 381 | WithToolType(ToolType::FINGER), |
| 382 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 383 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 384 | VariantWith<NotifyMotionArgs>( |
| 385 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 386 | WithCoords(POINTER_X, POINTER_Y), |
| 387 | WithMotionClassification(MotionClassification::NONE), |
| 388 | WithToolType(ToolType::FINGER), |
| 389 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | TEST_F(GestureConverterTest, Scroll_Rotated) { |
| 393 | const nsecs_t downTime = 12345; |
| 394 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 395 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 396 | converter.setOrientation(ui::ROTATION_90); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 397 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 398 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 399 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 400 | std::list<NotifyArgs> args = |
| 401 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 402 | ASSERT_THAT(args, |
| 403 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 404 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 405 | WithCoords(POINTER_X, POINTER_Y), |
| 406 | WithGestureScrollDistance(0, 0, EPSILON), |
| 407 | WithMotionClassification( |
| 408 | MotionClassification::TWO_FINGER_SWIPE), |
| 409 | WithToolType(ToolType::FINGER), WithDownTime(downTime), |
| 410 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 411 | VariantWith<NotifyMotionArgs>( |
| 412 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 413 | WithCoords(POINTER_X - 10, POINTER_Y), |
| 414 | WithGestureScrollDistance(0, 10, EPSILON), |
| 415 | WithMotionClassification( |
| 416 | MotionClassification::TWO_FINGER_SWIPE), |
| 417 | WithToolType(ToolType::FINGER), |
| 418 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 419 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 420 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 421 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 422 | ASSERT_THAT(args, |
| 423 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 424 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 425 | WithCoords(POINTER_X - 15, POINTER_Y), |
| 426 | WithGestureScrollDistance(0, 5, EPSILON), |
| 427 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 428 | WithToolType(ToolType::FINGER), |
| 429 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 430 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 431 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 432 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 433 | ASSERT_THAT(args, |
| 434 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 435 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 436 | WithCoords(POINTER_X - 15, POINTER_Y), |
| 437 | WithGestureScrollDistance(0, 0, EPSILON), |
| 438 | WithMotionClassification( |
| 439 | MotionClassification::TWO_FINGER_SWIPE), |
| 440 | WithToolType(ToolType::FINGER), |
| 441 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 442 | VariantWith<NotifyMotionArgs>( |
| 443 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 444 | WithCoords(POINTER_X, POINTER_Y), |
| 445 | WithMotionClassification(MotionClassification::NONE), |
| 446 | WithToolType(ToolType::FINGER), |
| 447 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 450 | TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 451 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 452 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 453 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 454 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 455 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 456 | std::list<NotifyArgs> args = |
| 457 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 458 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 459 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 460 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 461 | |
| 462 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 463 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 464 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 465 | |
| 466 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 467 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 468 | ASSERT_THAT(args, |
| 469 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 470 | AllOf(WithMotionClassification(MotionClassification::NONE), |
| 471 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 474 | TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 475 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 476 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 477 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 478 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 479 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 480 | std::list<NotifyArgs> args = |
| 481 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 482 | |
| 483 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 484 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 485 | |
| 486 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 487 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 488 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 489 | |
| 490 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 491 | // need to use another gesture type, like pinch. |
| 492 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 493 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 494 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 495 | ASSERT_FALSE(args.empty()); |
| 496 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON)); |
| 497 | } |
| 498 | |
| 499 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) { |
| 500 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 501 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 502 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 503 | |
| 504 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 505 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 506 | std::list<NotifyArgs> args = |
| 507 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 508 | |
| 509 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 510 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 511 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 512 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, |
| 513 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 514 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 515 | ASSERT_EQ(1u, args.size()); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 516 | ASSERT_THAT(args, |
| 517 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 518 | WithMotionClassification(MotionClassification::NONE)))); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 521 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 522 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 523 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 524 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 525 | |
| 526 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, |
| 527 | /*dy=*/5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 528 | std::list<NotifyArgs> args = |
| 529 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 530 | |
| 531 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 532 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 533 | |
| 534 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 535 | // need to use another gesture type, like pinch. |
| 536 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 537 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 538 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 539 | ASSERT_FALSE(args.empty()); |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 540 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 541 | AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { |
| 545 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 546 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 547 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 548 | // only checks movement in one dimension. |
| 549 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 550 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 551 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 552 | |
| 553 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 554 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 555 | std::list<NotifyArgs> args = |
| 556 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 557 | ASSERT_EQ(4u, args.size()); |
| 558 | |
| 559 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 560 | // move appropriately. |
| 561 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 562 | ASSERT_THAT(arg, |
| 563 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 564 | WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 565 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 566 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 567 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 568 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 569 | args.pop_front(); |
| 570 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 571 | ASSERT_THAT(arg, |
| 572 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 573 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 574 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 575 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 576 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 577 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 578 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 579 | args.pop_front(); |
| 580 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 581 | ASSERT_THAT(arg, |
| 582 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 583 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 584 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 585 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 586 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 587 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 588 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 589 | args.pop_front(); |
| 590 | |
| 591 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 592 | ASSERT_THAT(arg, |
| 593 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 594 | WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 595 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 596 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 597 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 598 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 599 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 600 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 601 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 602 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 603 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 604 | |
| 605 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 606 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 607 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 608 | ASSERT_EQ(1u, args.size()); |
| 609 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 610 | ASSERT_THAT(arg, |
| 611 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 612 | WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 613 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 614 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 615 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 616 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 617 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 618 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 619 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 620 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 621 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 622 | |
| 623 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 624 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 625 | ASSERT_THAT(args, |
| 626 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 627 | AllOf(WithMotionAction( |
| 628 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 629 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 630 | WithGestureOffset(0, 0, EPSILON), |
| 631 | WithGestureSwipeFingerCount(3), |
| 632 | WithMotionClassification( |
| 633 | MotionClassification::MULTI_FINGER_SWIPE), |
| 634 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 635 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 636 | VariantWith<NotifyMotionArgs>( |
| 637 | AllOf(WithMotionAction( |
| 638 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 639 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 640 | WithGestureOffset(0, 0, EPSILON), |
| 641 | WithGestureSwipeFingerCount(3), |
| 642 | WithMotionClassification( |
| 643 | MotionClassification::MULTI_FINGER_SWIPE), |
| 644 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 645 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 646 | VariantWith<NotifyMotionArgs>( |
| 647 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 648 | WithGestureOffset(0, 0, EPSILON), |
| 649 | WithGestureSwipeFingerCount(3), |
| 650 | WithMotionClassification( |
| 651 | MotionClassification::MULTI_FINGER_SWIPE), |
| 652 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 653 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 654 | VariantWith<NotifyMotionArgs>( |
| 655 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 656 | WithCoords(POINTER_X, POINTER_Y), |
| 657 | WithMotionClassification(MotionClassification::NONE), |
| 658 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 659 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 662 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { |
| 663 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 664 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 665 | converter.setOrientation(ui::ROTATION_90); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 666 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 667 | |
| 668 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 669 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 670 | std::list<NotifyArgs> args = |
| 671 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 672 | ASSERT_EQ(4u, args.size()); |
| 673 | |
| 674 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 675 | // move appropriately. |
| 676 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 677 | ASSERT_THAT(arg, |
| 678 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 679 | WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 680 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 681 | args.pop_front(); |
| 682 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 683 | ASSERT_THAT(arg, |
| 684 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 685 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 686 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), |
| 687 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 688 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 689 | args.pop_front(); |
| 690 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 691 | ASSERT_THAT(arg, |
| 692 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 693 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 694 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), |
| 695 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 696 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 697 | args.pop_front(); |
| 698 | |
| 699 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 700 | ASSERT_THAT(arg, |
| 701 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 702 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u), |
| 703 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 704 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 705 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 706 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 707 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 708 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 709 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 710 | |
| 711 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 712 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 713 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 714 | ASSERT_EQ(1u, args.size()); |
| 715 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 716 | ASSERT_THAT(arg, |
| 717 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 718 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), |
| 719 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 720 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 721 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 722 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 723 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 724 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 725 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 726 | |
| 727 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 728 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 729 | ASSERT_THAT(args, |
| 730 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 731 | AllOf(WithMotionAction( |
| 732 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 733 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 734 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), |
| 735 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 736 | VariantWith<NotifyMotionArgs>( |
| 737 | AllOf(WithMotionAction( |
| 738 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 739 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 740 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), |
| 741 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 742 | VariantWith<NotifyMotionArgs>( |
| 743 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 744 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 745 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 746 | VariantWith<NotifyMotionArgs>( |
| 747 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 748 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 751 | TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { |
| 752 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 753 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 754 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 755 | |
| 756 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 757 | /* dx= */ 10, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 758 | std::list<NotifyArgs> args = |
| 759 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 760 | ASSERT_EQ(5u, args.size()); |
| 761 | |
| 762 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 763 | // move appropriately. |
| 764 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 765 | ASSERT_THAT(arg, |
| 766 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 767 | WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 768 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 769 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 770 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 771 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 772 | args.pop_front(); |
| 773 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 774 | ASSERT_THAT(arg, |
| 775 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 776 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 777 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 778 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 779 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 780 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 781 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 782 | args.pop_front(); |
| 783 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 784 | ASSERT_THAT(arg, |
| 785 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 786 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 787 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 788 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 789 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 790 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 791 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 792 | args.pop_front(); |
| 793 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 794 | ASSERT_THAT(arg, |
| 795 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 796 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 797 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 798 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 799 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 800 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 801 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 802 | args.pop_front(); |
| 803 | |
| 804 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 805 | ASSERT_THAT(arg, |
| 806 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 807 | WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 808 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 809 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 810 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 811 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 812 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 813 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 814 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 815 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 816 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 817 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 818 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 819 | |
| 820 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 821 | /* dx= */ 5, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 822 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 823 | ASSERT_EQ(1u, args.size()); |
| 824 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 825 | ASSERT_THAT(arg, |
| 826 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 827 | WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 828 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 829 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 830 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 831 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 832 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 833 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 834 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 835 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 836 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 837 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 838 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 839 | |
| 840 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 841 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 842 | ASSERT_THAT(args, |
| 843 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 844 | AllOf(WithMotionAction( |
| 845 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 846 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 847 | WithGestureOffset(0, 0, EPSILON), |
| 848 | WithGestureSwipeFingerCount(4), |
| 849 | WithMotionClassification( |
| 850 | MotionClassification::MULTI_FINGER_SWIPE), |
| 851 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 852 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 853 | VariantWith<NotifyMotionArgs>( |
| 854 | AllOf(WithMotionAction( |
| 855 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 856 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 857 | WithGestureOffset(0, 0, EPSILON), |
| 858 | WithGestureSwipeFingerCount(4), |
| 859 | WithMotionClassification( |
| 860 | MotionClassification::MULTI_FINGER_SWIPE), |
| 861 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 862 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 863 | VariantWith<NotifyMotionArgs>( |
| 864 | AllOf(WithMotionAction( |
| 865 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 866 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 867 | WithGestureOffset(0, 0, EPSILON), |
| 868 | WithGestureSwipeFingerCount(4), |
| 869 | WithMotionClassification( |
| 870 | MotionClassification::MULTI_FINGER_SWIPE), |
| 871 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 872 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 873 | VariantWith<NotifyMotionArgs>( |
| 874 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 875 | WithGestureOffset(0, 0, EPSILON), |
| 876 | WithGestureSwipeFingerCount(4), |
| 877 | WithMotionClassification( |
| 878 | MotionClassification::MULTI_FINGER_SWIPE), |
| 879 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 880 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 881 | VariantWith<NotifyMotionArgs>( |
| 882 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 883 | WithCoords(POINTER_X, POINTER_Y), |
| 884 | WithMotionClassification(MotionClassification::NONE), |
| 885 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 886 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 889 | TEST_F(GestureConverterTest, Pinch_Inwards) { |
| 890 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 891 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 892 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 893 | |
| 894 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 895 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 896 | std::list<NotifyArgs> args = |
| 897 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 898 | ASSERT_THAT(args, |
| 899 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 900 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 901 | WithMotionClassification(MotionClassification::PINCH), |
| 902 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 903 | WithCoords(POINTER_X - 100, POINTER_Y), |
| 904 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 905 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 906 | VariantWith<NotifyMotionArgs>( |
| 907 | AllOf(WithMotionAction( |
| 908 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 909 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 910 | WithMotionClassification(MotionClassification::PINCH), |
| 911 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 912 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), |
| 913 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 914 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 915 | |
| 916 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 917 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 918 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 919 | ASSERT_THAT(args, |
| 920 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 921 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 922 | WithMotionClassification(MotionClassification::PINCH), |
| 923 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
| 924 | WithPointerCoords(0, POINTER_X - 80, POINTER_Y), |
| 925 | WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u), |
| 926 | WithToolType(ToolType::FINGER), |
| 927 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 928 | |
| 929 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 930 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 931 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 932 | ASSERT_THAT(args, |
| 933 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 934 | AllOf(WithMotionAction( |
| 935 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 936 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 937 | WithMotionClassification(MotionClassification::PINCH), |
| 938 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 939 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 940 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 941 | VariantWith<NotifyMotionArgs>( |
| 942 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 943 | WithMotionClassification(MotionClassification::PINCH), |
| 944 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 945 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 946 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 947 | VariantWith<NotifyMotionArgs>( |
| 948 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 949 | WithCoords(POINTER_X, POINTER_Y), |
| 950 | WithMotionClassification(MotionClassification::NONE), |
| 951 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 952 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | TEST_F(GestureConverterTest, Pinch_Outwards) { |
| 956 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 957 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 958 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 959 | |
| 960 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 961 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 962 | std::list<NotifyArgs> args = |
| 963 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 964 | ASSERT_THAT(args, |
| 965 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 966 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 967 | WithMotionClassification(MotionClassification::PINCH), |
| 968 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 969 | WithCoords(POINTER_X - 100, POINTER_Y), |
| 970 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 971 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 972 | VariantWith<NotifyMotionArgs>( |
| 973 | AllOf(WithMotionAction( |
| 974 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 975 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 976 | WithMotionClassification(MotionClassification::PINCH), |
| 977 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 978 | WithPointerCoords(1, POINTER_X + 100, POINTER_Y), |
| 979 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 980 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 981 | |
| 982 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 983 | /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 984 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 985 | ASSERT_THAT(args, |
| 986 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 987 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 988 | WithMotionClassification(MotionClassification::PINCH), |
| 989 | WithGesturePinchScaleFactor(1.2f, EPSILON), |
| 990 | WithPointerCoords(0, POINTER_X - 120, POINTER_Y), |
| 991 | WithPointerCoords(1, POINTER_X + 120, POINTER_Y), |
| 992 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 993 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 994 | |
| 995 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 996 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 997 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 998 | ASSERT_THAT(args, |
| 999 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1000 | AllOf(WithMotionAction( |
| 1001 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1002 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1003 | WithMotionClassification(MotionClassification::PINCH), |
| 1004 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 1005 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 1006 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1007 | VariantWith<NotifyMotionArgs>( |
| 1008 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1009 | WithMotionClassification(MotionClassification::PINCH), |
| 1010 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 1011 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1012 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1013 | VariantWith<NotifyMotionArgs>( |
| 1014 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1015 | WithCoords(POINTER_X, POINTER_Y), |
| 1016 | WithMotionClassification(MotionClassification::NONE), |
| 1017 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1018 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1021 | TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1022 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1023 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1024 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1025 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1026 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1027 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1028 | std::list<NotifyArgs> args = |
| 1029 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1030 | |
| 1031 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1032 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1033 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1034 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1035 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1036 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1037 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1038 | |
| 1039 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1040 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1041 | ASSERT_THAT(args, |
| 1042 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1043 | WithMotionClassification(MotionClassification::NONE)))); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { |
| 1047 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1048 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1049 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1050 | |
| 1051 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1052 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1053 | std::list<NotifyArgs> args = |
| 1054 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1055 | |
| 1056 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1057 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1058 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1059 | |
| 1060 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1061 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1062 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1063 | |
| 1064 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 1065 | // need to use another gesture type, like scroll. |
| 1066 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 1067 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1068 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1069 | ASSERT_FALSE(args.empty()); |
| 1070 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1073 | TEST_F(GestureConverterTest, ResetWithButtonPressed) { |
| 1074 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1075 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1076 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1077 | |
| 1078 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1079 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 1080 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1081 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1082 | |
| 1083 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1084 | ASSERT_THAT(args, |
| 1085 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1086 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1087 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1088 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
| 1089 | WithCoords(POINTER_X, POINTER_Y), |
| 1090 | WithToolType(ToolType::FINGER), |
| 1091 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1092 | VariantWith<NotifyMotionArgs>( |
| 1093 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1094 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 1095 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 1096 | WithToolType(ToolType::FINGER), |
| 1097 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1098 | VariantWith<NotifyMotionArgs>( |
| 1099 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1100 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 1101 | WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1102 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1103 | VariantWith<NotifyMotionArgs>( |
| 1104 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1105 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 1106 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1107 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | TEST_F(GestureConverterTest, ResetDuringScroll) { |
| 1111 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1112 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1113 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1114 | |
| 1115 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1116 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1117 | |
| 1118 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1119 | ASSERT_THAT(args, |
| 1120 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1121 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1122 | WithCoords(POINTER_X, POINTER_Y - 10), |
| 1123 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1124 | WithMotionClassification( |
| 1125 | MotionClassification::TWO_FINGER_SWIPE), |
| 1126 | WithToolType(ToolType::FINGER), |
| 1127 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 1128 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1129 | VariantWith<NotifyMotionArgs>( |
| 1130 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1131 | WithCoords(POINTER_X, POINTER_Y), |
| 1132 | WithMotionClassification(MotionClassification::NONE), |
| 1133 | WithToolType(ToolType::FINGER), |
| 1134 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { |
| 1138 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1139 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1140 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1141 | |
| 1142 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 1143 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1144 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1145 | |
| 1146 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1147 | ASSERT_THAT(args, |
| 1148 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1149 | AllOf(WithMotionAction( |
| 1150 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1151 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1152 | WithGestureOffset(0, 0, EPSILON), |
| 1153 | WithMotionClassification( |
| 1154 | MotionClassification::MULTI_FINGER_SWIPE), |
| 1155 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 1156 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1157 | VariantWith<NotifyMotionArgs>( |
| 1158 | AllOf(WithMotionAction( |
| 1159 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1160 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1161 | WithGestureOffset(0, 0, EPSILON), |
| 1162 | WithMotionClassification( |
| 1163 | MotionClassification::MULTI_FINGER_SWIPE), |
| 1164 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 1165 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1166 | VariantWith<NotifyMotionArgs>( |
| 1167 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1168 | WithGestureOffset(0, 0, EPSILON), |
| 1169 | WithMotionClassification( |
| 1170 | MotionClassification::MULTI_FINGER_SWIPE), |
| 1171 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1172 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1173 | VariantWith<NotifyMotionArgs>( |
| 1174 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1175 | WithMotionClassification(MotionClassification::NONE), |
| 1176 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1177 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | TEST_F(GestureConverterTest, ResetDuringPinch) { |
| 1181 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1182 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1183 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1184 | |
| 1185 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1186 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1187 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1188 | |
| 1189 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1190 | ASSERT_THAT(args, |
| 1191 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1192 | AllOf(WithMotionAction( |
| 1193 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1194 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1195 | WithMotionClassification(MotionClassification::PINCH), |
| 1196 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 1197 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 1198 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1199 | VariantWith<NotifyMotionArgs>( |
| 1200 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1201 | WithMotionClassification(MotionClassification::PINCH), |
| 1202 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 1203 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1204 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1205 | VariantWith<NotifyMotionArgs>( |
| 1206 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1207 | WithCoords(POINTER_X, POINTER_Y), |
| 1208 | WithMotionClassification(MotionClassification::NONE), |
| 1209 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1210 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1213 | TEST_F(GestureConverterTest, FlingTapDown) { |
| 1214 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1215 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1216 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1217 | |
| 1218 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1219 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1220 | std::list<NotifyArgs> args = |
| 1221 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1222 | |
| 1223 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1224 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1225 | WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1226 | WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f), |
| 1227 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1228 | |
| 1229 | ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y)); |
| 1230 | ASSERT_TRUE(mFakePointerController->isPointerShown()); |
| 1231 | } |
| 1232 | |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame^] | 1233 | TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) { |
| 1234 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1235 | input_flags::enable_touchpad_fling_stop(true); |
| 1236 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1237 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1238 | |
| 1239 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 1240 | std::list<NotifyArgs> args = |
| 1241 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
| 1242 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1243 | GESTURES_FLING_START); |
| 1244 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
| 1245 | |
| 1246 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1247 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
| 1248 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
| 1249 | ASSERT_THAT(args, |
| 1250 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1251 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)), |
| 1252 | VariantWith<NotifyMotionArgs>( |
| 1253 | WithMotionAction(AMOTION_EVENT_ACTION_DOWN)), |
| 1254 | VariantWith<NotifyMotionArgs>( |
| 1255 | WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)), |
| 1256 | VariantWith<NotifyMotionArgs>( |
| 1257 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1258 | WithMotionClassification(MotionClassification::NONE))))); |
| 1259 | ASSERT_THAT(args, |
| 1260 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), |
| 1261 | WithToolType(ToolType::FINGER), |
| 1262 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
| 1263 | } |
| 1264 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1265 | TEST_F(GestureConverterTest, Tap) { |
| 1266 | // Tap should produce button press/release events |
| 1267 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1268 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1269 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1270 | |
| 1271 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1272 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1273 | std::list<NotifyArgs> args = |
| 1274 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1275 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1276 | |
| 1277 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1278 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1279 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1280 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1281 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1282 | ASSERT_THAT(args, |
| 1283 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1284 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 1285 | WithCoords(POINTER_X, POINTER_Y), |
| 1286 | WithRelativeMotion(0.f, 0.f), |
| 1287 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1288 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1289 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1290 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1291 | WithCoords(POINTER_X, POINTER_Y), |
| 1292 | WithRelativeMotion(0.f, 0.f), |
| 1293 | WithToolType(ToolType::FINGER), |
| 1294 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1295 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1296 | VariantWith<NotifyMotionArgs>( |
| 1297 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1298 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1299 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1300 | WithCoords(POINTER_X, POINTER_Y), |
| 1301 | WithRelativeMotion(0.f, 0.f), |
| 1302 | WithToolType(ToolType::FINGER), |
| 1303 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1304 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1305 | VariantWith<NotifyMotionArgs>( |
| 1306 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1307 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1308 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 1309 | WithRelativeMotion(0.f, 0.f), |
| 1310 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1311 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1312 | VariantWith<NotifyMotionArgs>( |
| 1313 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1314 | WithCoords(POINTER_X, POINTER_Y), |
| 1315 | WithRelativeMotion(0.f, 0.f), |
| 1316 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1317 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1318 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1319 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1320 | WithCoords(POINTER_X, POINTER_Y), |
| 1321 | WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), |
| 1322 | WithButtonState(0), WithPressure(0.0f), |
| 1323 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | TEST_F(GestureConverterTest, Click) { |
| 1327 | // Click should produce button press/release events |
| 1328 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1329 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1330 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1331 | |
| 1332 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1333 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1334 | std::list<NotifyArgs> args = |
| 1335 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1336 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1337 | |
| 1338 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1339 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1340 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1341 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1342 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1343 | ASSERT_THAT(args, |
| 1344 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1345 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 1346 | WithCoords(POINTER_X, POINTER_Y), |
| 1347 | WithRelativeMotion(0.f, 0.f), |
| 1348 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1349 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1350 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1351 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1352 | WithCoords(POINTER_X, POINTER_Y), |
| 1353 | WithRelativeMotion(0.f, 0.f), |
| 1354 | WithToolType(ToolType::FINGER), |
| 1355 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1356 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1357 | VariantWith<NotifyMotionArgs>( |
| 1358 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1359 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1360 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1361 | WithCoords(POINTER_X, POINTER_Y), |
| 1362 | WithRelativeMotion(0.f, 0.f), |
| 1363 | WithToolType(ToolType::FINGER), |
| 1364 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1365 | WithPressure(1.0f), |
| 1366 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1367 | |
| 1368 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1369 | /* down= */ GESTURES_BUTTON_NONE, |
| 1370 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1371 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1372 | ASSERT_THAT(args, |
| 1373 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1374 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1375 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1376 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 1377 | WithRelativeMotion(0.f, 0.f), |
| 1378 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1379 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1380 | VariantWith<NotifyMotionArgs>( |
| 1381 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1382 | WithCoords(POINTER_X, POINTER_Y), |
| 1383 | WithRelativeMotion(0.f, 0.f), |
| 1384 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1385 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1386 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1387 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1388 | WithCoords(POINTER_X, POINTER_Y), |
| 1389 | WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), |
| 1390 | WithButtonState(0), WithPressure(0.0f), |
| 1391 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1392 | } |
| 1393 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1394 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1395 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION), |
| 1396 | REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1397 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1398 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1399 | // Tap should be ignored when disabled |
| 1400 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1401 | |
| 1402 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1403 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1404 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1405 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1406 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1407 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1408 | std::list<NotifyArgs> args = |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1409 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1410 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1411 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1412 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1413 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1414 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1415 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1416 | |
| 1417 | // no events should be generated |
| 1418 | ASSERT_EQ(0u, args.size()); |
| 1419 | |
| 1420 | // Future taps should be re-enabled |
| 1421 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1422 | } |
| 1423 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1424 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay, |
| 1425 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1426 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1427 | |
| 1428 | // Tap should be ignored when disabled |
| 1429 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1430 | |
| 1431 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1432 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1433 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1434 | |
| 1435 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1436 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1437 | std::list<NotifyArgs> args = |
| 1438 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1439 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1440 | |
| 1441 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
| 1442 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1443 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1444 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1445 | |
| 1446 | // no events should be generated |
| 1447 | ASSERT_EQ(0u, args.size()); |
| 1448 | |
| 1449 | // Future taps should be re-enabled |
| 1450 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1451 | |
| 1452 | // taps before the threshold should still be ignored |
| 1453 | currentTime += TAP_ENABLE_DELAY_NANOS.count(); |
| 1454 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1455 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1456 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1457 | |
| 1458 | ASSERT_EQ(1u, args.size()); |
| 1459 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1460 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1461 | |
| 1462 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1463 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1464 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1465 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1466 | |
| 1467 | // no events should be generated |
| 1468 | ASSERT_EQ(0u, args.size()); |
| 1469 | |
| 1470 | // taps after the threshold should be recognised |
| 1471 | currentTime += 1; |
| 1472 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1473 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1474 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1475 | |
| 1476 | ASSERT_EQ(1u, args.size()); |
| 1477 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1478 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1479 | |
| 1480 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1481 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1482 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1483 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1484 | |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1485 | ASSERT_EQ(6u, args.size()); |
| 1486 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1487 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 1488 | WithRelativeMotion(0.f, 0.f), WithButtonState(0))); |
| 1489 | args.pop_front(); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1490 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1491 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f), |
| 1492 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))); |
| 1493 | args.pop_front(); |
| 1494 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1495 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1496 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1), |
| 1497 | WithRelativeMotion(0.f, 0.f))); |
| 1498 | args.pop_front(); |
| 1499 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1500 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1501 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), |
| 1502 | WithRelativeMotion(0.f, 0.f))); |
| 1503 | args.pop_front(); |
| 1504 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1505 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f), |
| 1506 | WithButtonState(0))); |
| 1507 | args.pop_front(); |
| 1508 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1509 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0), |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1510 | WithButtonState(0))); |
| 1511 | } |
| 1512 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1513 | TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, |
| 1514 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1515 | // Click should still produce button press/release events |
| 1516 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1517 | |
| 1518 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1519 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1520 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1521 | |
| 1522 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1523 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1524 | std::list<NotifyArgs> args = |
| 1525 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1526 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1527 | |
| 1528 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1529 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1530 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1531 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1532 | ASSERT_THAT(args, |
| 1533 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1534 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 1535 | WithCoords(POINTER_X, POINTER_Y), |
| 1536 | WithRelativeMotion(0.f, 0.f), |
| 1537 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1538 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1539 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1540 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1541 | WithCoords(POINTER_X, POINTER_Y), |
| 1542 | WithRelativeMotion(0.f, 0.f), |
| 1543 | WithToolType(ToolType::FINGER), |
| 1544 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1545 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1546 | VariantWith<NotifyMotionArgs>( |
| 1547 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1548 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1549 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1550 | WithCoords(POINTER_X, POINTER_Y), |
| 1551 | WithRelativeMotion(0.f, 0.f), |
| 1552 | WithToolType(ToolType::FINGER), |
| 1553 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1554 | WithPressure(1.0f), |
| 1555 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1556 | |
| 1557 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1558 | /* down= */ GESTURES_BUTTON_NONE, |
| 1559 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1560 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1561 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1562 | ASSERT_THAT(args, |
| 1563 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1564 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1565 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1566 | WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 1567 | WithRelativeMotion(0.f, 0.f), |
| 1568 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1569 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1570 | VariantWith<NotifyMotionArgs>( |
| 1571 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1572 | WithCoords(POINTER_X, POINTER_Y), |
| 1573 | WithRelativeMotion(0.f, 0.f), |
| 1574 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1575 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1576 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1577 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1578 | WithCoords(POINTER_X, POINTER_Y), |
| 1579 | WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), |
| 1580 | WithButtonState(0), WithPressure(0.0f), |
| 1581 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1582 | |
| 1583 | // Future taps should be re-enabled |
| 1584 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1585 | } |
| 1586 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1587 | TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick, |
| 1588 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1589 | // initially disable tap-to-click |
| 1590 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1591 | |
| 1592 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1593 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1594 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1595 | |
| 1596 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1597 | std::list<NotifyArgs> args = |
| 1598 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1599 | // We don't need to check args here, since it's covered by the Move test. |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1600 | |
| 1601 | // Future taps should be re-enabled |
| 1602 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1603 | } |
| 1604 | |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1605 | TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove, |
| 1606 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1607 | const nsecs_t gestureStartTime = 1000; |
| 1608 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1609 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1610 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1611 | |
| 1612 | // Start a move gesture at gestureStartTime |
| 1613 | Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10); |
| 1614 | std::list<NotifyArgs> args = |
| 1615 | converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1616 | ASSERT_THAT(args, |
| 1617 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1618 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1619 | VariantWith<NotifyMotionArgs>( |
| 1620 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1621 | |
| 1622 | // Key presses with IME connection should cancel ongoing move gesture |
| 1623 | nsecs_t currentTime = gestureStartTime + 100; |
| 1624 | mFakePolicy->setIsInputMethodConnectionActive(true); |
| 1625 | mReader->getContext()->setLastKeyDownTimestamp(currentTime); |
| 1626 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1627 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1628 | ASSERT_THAT(args, |
| 1629 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1630 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1631 | |
| 1632 | // any updates in existing move gesture should be ignored |
| 1633 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1634 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
| 1635 | ASSERT_EQ(0u, args.size()); |
| 1636 | |
| 1637 | // New gesture should not be affected |
| 1638 | currentTime += 100; |
| 1639 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1640 | args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1641 | ASSERT_THAT(args, |
| 1642 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1643 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1644 | VariantWith<NotifyMotionArgs>( |
| 1645 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
Prabir Pradhan | cc7268a | 2023-11-16 18:54:13 +0000 | [diff] [blame] | 1648 | // TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging |
| 1649 | // logic can be removed. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1650 | class GestureConverterTestWithChoreographer : public GestureConverterTestBase { |
| 1651 | protected: |
| 1652 | void SetUp() override { |
| 1653 | input_flags::enable_pointer_choreographer(true); |
| 1654 | GestureConverterTestBase::SetUp(); |
| 1655 | } |
| 1656 | }; |
| 1657 | |
| 1658 | TEST_F(GestureConverterTestWithChoreographer, Move) { |
| 1659 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1660 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1661 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1662 | |
| 1663 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1664 | std::list<NotifyArgs> args = |
| 1665 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1666 | ASSERT_THAT(args, |
| 1667 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1668 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1669 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 1670 | WithToolType(ToolType::FINGER), |
| 1671 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1672 | VariantWith<NotifyMotionArgs>( |
| 1673 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1674 | WithCoords(0, 0), WithRelativeMotion(-5, 10), |
| 1675 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1676 | WithPressure(0.0f), |
| 1677 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
| 1678 | |
| 1679 | // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER. |
| 1680 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 1681 | ASSERT_THAT(args, |
| 1682 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1683 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0), |
| 1684 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
| 1685 | WithButtonState(0), WithPressure(0.0f), |
| 1686 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) { |
| 1690 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1691 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1692 | converter.setOrientation(ui::ROTATION_90); |
| 1693 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1694 | |
| 1695 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1696 | std::list<NotifyArgs> args = |
| 1697 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1698 | ASSERT_THAT(args, |
| 1699 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1700 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1701 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 1702 | WithToolType(ToolType::FINGER), |
| 1703 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1704 | VariantWith<NotifyMotionArgs>( |
| 1705 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 1706 | WithCoords(0, 0), WithRelativeMotion(10, 5), |
| 1707 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1708 | WithPressure(0.0f), |
| 1709 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) { |
| 1713 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1714 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1715 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1716 | |
| 1717 | // Press left and right buttons at once |
| 1718 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1719 | /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 1720 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1721 | std::list<NotifyArgs> args = |
| 1722 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1723 | ASSERT_THAT(args, |
| 1724 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1725 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1726 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 1727 | AMOTION_EVENT_BUTTON_SECONDARY), |
| 1728 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1729 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1730 | VariantWith<NotifyMotionArgs>( |
| 1731 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1732 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1733 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1734 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1735 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1736 | VariantWith<NotifyMotionArgs>( |
| 1737 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1738 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 1739 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
| 1740 | AMOTION_EVENT_BUTTON_SECONDARY), |
| 1741 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1742 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1743 | |
| 1744 | // Then release the left button |
| 1745 | Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1746 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 1747 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1748 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1749 | ASSERT_THAT(args, |
| 1750 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1751 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1752 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1753 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0), |
| 1754 | WithToolType(ToolType::FINGER), |
| 1755 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1756 | |
| 1757 | // Finally release the right button |
| 1758 | Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1759 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT, |
| 1760 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1761 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1762 | ASSERT_THAT(args, |
| 1763 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1764 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1765 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 1766 | WithButtonState(0), WithCoords(0, 0), |
| 1767 | WithToolType(ToolType::FINGER), |
| 1768 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1769 | VariantWith<NotifyMotionArgs>( |
| 1770 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1771 | WithButtonState(0), WithCoords(0, 0), |
| 1772 | WithToolType(ToolType::FINGER), |
| 1773 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1774 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1775 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1776 | WithButtonState(0), WithCoords(0, 0), |
| 1777 | WithToolType(ToolType::FINGER), |
| 1778 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1779 | } |
| 1780 | |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1781 | TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) { |
| 1782 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1783 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1784 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1785 | |
| 1786 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 1787 | std::list<NotifyArgs> args = |
| 1788 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 1789 | |
| 1790 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1791 | /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE, |
| 1792 | /*is_tap=*/false); |
| 1793 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
| 1794 | ASSERT_THAT(args.front(), |
| 1795 | VariantWith<NotifyMotionArgs>( |
| 1796 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0), |
| 1797 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1798 | WithDisplayId(ADISPLAY_ID_DEFAULT)))); |
| 1799 | } |
| 1800 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1801 | TEST_F(GestureConverterTestWithChoreographer, DragWithButton) { |
| 1802 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1803 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1804 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1805 | |
| 1806 | // Press the button |
| 1807 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1808 | /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE, |
| 1809 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1810 | std::list<NotifyArgs> args = |
| 1811 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1812 | ASSERT_THAT(args, |
| 1813 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1814 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1815 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1816 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1817 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1818 | VariantWith<NotifyMotionArgs>( |
| 1819 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1820 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1821 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1822 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1823 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1824 | |
| 1825 | // Move |
| 1826 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1827 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1828 | ASSERT_THAT(args, |
| 1829 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1830 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0), |
| 1831 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
| 1832 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
| 1833 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1834 | |
| 1835 | // Release the button |
| 1836 | Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1837 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 1838 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1839 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1840 | ASSERT_THAT(args, |
| 1841 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1842 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1843 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1844 | WithButtonState(0), WithCoords(0, 0), |
| 1845 | WithToolType(ToolType::FINGER), |
| 1846 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1847 | VariantWith<NotifyMotionArgs>( |
| 1848 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1849 | WithButtonState(0), WithCoords(0, 0), |
| 1850 | WithToolType(ToolType::FINGER), |
| 1851 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1852 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1853 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1854 | WithButtonState(0), WithCoords(0, 0), |
| 1855 | WithToolType(ToolType::FINGER), |
| 1856 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | TEST_F(GestureConverterTestWithChoreographer, Scroll) { |
| 1860 | const nsecs_t downTime = 12345; |
| 1861 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1862 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1863 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1864 | |
| 1865 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1866 | std::list<NotifyArgs> args = |
| 1867 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1868 | ASSERT_THAT(args, |
| 1869 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1870 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1871 | WithCoords(0, 0), |
| 1872 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1873 | WithMotionClassification( |
| 1874 | MotionClassification::TWO_FINGER_SWIPE), |
| 1875 | WithToolType(ToolType::FINGER), WithDownTime(downTime), |
| 1876 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 1877 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1878 | VariantWith<NotifyMotionArgs>( |
| 1879 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 1880 | WithCoords(0, -10), |
| 1881 | WithGestureScrollDistance(0, 10, EPSILON), |
| 1882 | WithMotionClassification( |
| 1883 | MotionClassification::TWO_FINGER_SWIPE), |
| 1884 | WithToolType(ToolType::FINGER), |
| 1885 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 1886 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1887 | |
| 1888 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1889 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1890 | ASSERT_THAT(args, |
| 1891 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1892 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15), |
| 1893 | WithGestureScrollDistance(0, 5, EPSILON), |
| 1894 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 1895 | WithToolType(ToolType::FINGER), |
| 1896 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 1897 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1898 | |
| 1899 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1900 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1901 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1902 | ASSERT_THAT(args, |
| 1903 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1904 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1905 | WithCoords(0, -15), |
| 1906 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1907 | WithMotionClassification( |
| 1908 | MotionClassification::TWO_FINGER_SWIPE), |
| 1909 | WithToolType(ToolType::FINGER), |
| 1910 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 1911 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1912 | VariantWith<NotifyMotionArgs>( |
| 1913 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1914 | WithCoords(0, 0), |
| 1915 | WithMotionClassification(MotionClassification::NONE), |
| 1916 | WithToolType(ToolType::FINGER), |
| 1917 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) { |
| 1921 | const nsecs_t downTime = 12345; |
| 1922 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1923 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1924 | converter.setOrientation(ui::ROTATION_90); |
| 1925 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1926 | |
| 1927 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1928 | std::list<NotifyArgs> args = |
| 1929 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1930 | ASSERT_THAT(args, |
| 1931 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1932 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1933 | WithCoords(0, 0), |
| 1934 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1935 | WithMotionClassification( |
| 1936 | MotionClassification::TWO_FINGER_SWIPE), |
| 1937 | WithToolType(ToolType::FINGER), WithDownTime(downTime), |
| 1938 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1939 | VariantWith<NotifyMotionArgs>( |
| 1940 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 1941 | WithCoords(-10, 0), |
| 1942 | WithGestureScrollDistance(0, 10, EPSILON), |
| 1943 | WithMotionClassification( |
| 1944 | MotionClassification::TWO_FINGER_SWIPE), |
| 1945 | WithToolType(ToolType::FINGER), |
| 1946 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1947 | |
| 1948 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1949 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1950 | ASSERT_THAT(args, |
| 1951 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1952 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0), |
| 1953 | WithGestureScrollDistance(0, 5, EPSILON), |
| 1954 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 1955 | WithToolType(ToolType::FINGER), |
| 1956 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1957 | |
| 1958 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1959 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1960 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1961 | ASSERT_THAT(args, |
| 1962 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1963 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1964 | WithCoords(-15, 0), |
| 1965 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1966 | WithMotionClassification( |
| 1967 | MotionClassification::TWO_FINGER_SWIPE), |
| 1968 | WithToolType(ToolType::FINGER), |
| 1969 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 1970 | VariantWith<NotifyMotionArgs>( |
| 1971 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1972 | WithCoords(0, 0), |
| 1973 | WithMotionClassification(MotionClassification::NONE), |
| 1974 | WithToolType(ToolType::FINGER), |
| 1975 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) { |
| 1979 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1980 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1981 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1982 | |
| 1983 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1984 | std::list<NotifyArgs> args = |
| 1985 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1986 | |
| 1987 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1988 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1989 | |
| 1990 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1991 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1992 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1993 | |
| 1994 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1995 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1996 | ASSERT_THAT(args, |
| 1997 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1998 | AllOf(WithMotionClassification(MotionClassification::NONE), |
| 1999 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) { |
| 2003 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2004 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2005 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2006 | |
| 2007 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2008 | std::list<NotifyArgs> args = |
| 2009 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2010 | |
| 2011 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2012 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2013 | |
| 2014 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 2015 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2016 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2017 | |
| 2018 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 2019 | // need to use another gesture type, like pinch. |
| 2020 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2021 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2022 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2023 | ASSERT_FALSE(args.empty()); |
| 2024 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON)); |
| 2025 | } |
| 2026 | |
| 2027 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) { |
| 2028 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2029 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2030 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2031 | |
| 2032 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 2033 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2034 | std::list<NotifyArgs> args = |
| 2035 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2036 | |
| 2037 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2038 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2039 | |
| 2040 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, |
| 2041 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2042 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2043 | ASSERT_THAT(args, |
| 2044 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2045 | WithMotionClassification(MotionClassification::NONE)))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { |
| 2049 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2050 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2051 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2052 | |
| 2053 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, |
| 2054 | /*dy=*/5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2055 | std::list<NotifyArgs> args = |
| 2056 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2057 | |
| 2058 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2059 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2060 | |
| 2061 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 2062 | // need to use another gesture type, like pinch. |
| 2063 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2064 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2065 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2066 | ASSERT_FALSE(args.empty()); |
| 2067 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 2068 | AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0))); |
| 2069 | } |
| 2070 | |
| 2071 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) { |
| 2072 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 2073 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 2074 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 2075 | // only checks movement in one dimension. |
| 2076 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2077 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2078 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2079 | |
| 2080 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 2081 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2082 | std::list<NotifyArgs> args = |
| 2083 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2084 | ASSERT_EQ(4u, args.size()); |
| 2085 | |
| 2086 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 2087 | // move appropriately. |
| 2088 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 2089 | ASSERT_THAT(arg, |
| 2090 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
| 2091 | WithGestureSwipeFingerCount(3), |
| 2092 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2093 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 2094 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2095 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 2096 | args.pop_front(); |
| 2097 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2098 | ASSERT_THAT(arg, |
| 2099 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2100 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2101 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
| 2102 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2103 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2104 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2105 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 2106 | args.pop_front(); |
| 2107 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2108 | ASSERT_THAT(arg, |
| 2109 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2110 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2111 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), |
| 2112 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2113 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 2114 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2115 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 2116 | args.pop_front(); |
| 2117 | |
| 2118 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2119 | ASSERT_THAT(arg, |
| 2120 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2121 | WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3), |
| 2122 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2123 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 2124 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2125 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 2126 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 2127 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 2128 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 2129 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 2130 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 2131 | |
| 2132 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2133 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2134 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2135 | ASSERT_EQ(1u, args.size()); |
| 2136 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2137 | ASSERT_THAT(arg, |
| 2138 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2139 | WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), |
| 2140 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2141 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 2142 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2143 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 2144 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 2145 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 2146 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 2147 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 2148 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 2149 | |
| 2150 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2151 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2152 | ASSERT_THAT(args, |
| 2153 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2154 | AllOf(WithMotionAction( |
| 2155 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2156 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2157 | WithGestureOffset(0, 0, EPSILON), |
| 2158 | WithGestureSwipeFingerCount(3), |
| 2159 | WithMotionClassification( |
| 2160 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2161 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 2162 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2163 | VariantWith<NotifyMotionArgs>( |
| 2164 | AllOf(WithMotionAction( |
| 2165 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2166 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2167 | WithGestureOffset(0, 0, EPSILON), |
| 2168 | WithGestureSwipeFingerCount(3), |
| 2169 | WithMotionClassification( |
| 2170 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2171 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2172 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2173 | VariantWith<NotifyMotionArgs>( |
| 2174 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2175 | WithGestureOffset(0, 0, EPSILON), |
| 2176 | WithGestureSwipeFingerCount(3), |
| 2177 | WithMotionClassification( |
| 2178 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2179 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2180 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2181 | VariantWith<NotifyMotionArgs>( |
| 2182 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2183 | WithCoords(0, 0), |
| 2184 | WithMotionClassification(MotionClassification::NONE), |
| 2185 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2186 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) { |
| 2190 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2191 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2192 | converter.setOrientation(ui::ROTATION_90); |
| 2193 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2194 | |
| 2195 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 2196 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2197 | std::list<NotifyArgs> args = |
| 2198 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2199 | ASSERT_EQ(4u, args.size()); |
| 2200 | |
| 2201 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 2202 | // move appropriately. |
| 2203 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 2204 | ASSERT_THAT(arg, |
| 2205 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
| 2206 | WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2207 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 2208 | args.pop_front(); |
| 2209 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2210 | ASSERT_THAT(arg, |
| 2211 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2212 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2213 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), |
| 2214 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2215 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 2216 | args.pop_front(); |
| 2217 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2218 | ASSERT_THAT(arg, |
| 2219 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2220 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2221 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), |
| 2222 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2223 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 2224 | args.pop_front(); |
| 2225 | |
| 2226 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2227 | ASSERT_THAT(arg, |
| 2228 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2229 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u), |
| 2230 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2231 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 2232 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 2233 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 2234 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2235 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2236 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2237 | |
| 2238 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2239 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2240 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2241 | ASSERT_EQ(1u, args.size()); |
| 2242 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2243 | ASSERT_THAT(arg, |
| 2244 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2245 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), |
| 2246 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2247 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 2248 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 2249 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 2250 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2251 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2252 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2253 | |
| 2254 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2255 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2256 | ASSERT_THAT(args, |
| 2257 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2258 | AllOf(WithMotionAction( |
| 2259 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2260 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2261 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), |
| 2262 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2263 | VariantWith<NotifyMotionArgs>( |
| 2264 | AllOf(WithMotionAction( |
| 2265 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2266 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2267 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), |
| 2268 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2269 | VariantWith<NotifyMotionArgs>( |
| 2270 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2271 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2272 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2273 | VariantWith<NotifyMotionArgs>( |
| 2274 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2275 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) { |
| 2279 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2280 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2281 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2282 | |
| 2283 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2284 | /* dx= */ 10, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2285 | std::list<NotifyArgs> args = |
| 2286 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2287 | ASSERT_EQ(5u, args.size()); |
| 2288 | |
| 2289 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 2290 | // move appropriately. |
| 2291 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 2292 | ASSERT_THAT(arg, |
| 2293 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
| 2294 | WithGestureSwipeFingerCount(4), |
| 2295 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2296 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
| 2297 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2298 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 2299 | args.pop_front(); |
| 2300 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2301 | ASSERT_THAT(arg, |
| 2302 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2303 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2304 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
| 2305 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2306 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2307 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2308 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 2309 | args.pop_front(); |
| 2310 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2311 | ASSERT_THAT(arg, |
| 2312 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2313 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2314 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
| 2315 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2316 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 2317 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2318 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 2319 | args.pop_front(); |
| 2320 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2321 | ASSERT_THAT(arg, |
| 2322 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2323 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2324 | WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), |
| 2325 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2326 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 2327 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2328 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 2329 | args.pop_front(); |
| 2330 | |
| 2331 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2332 | ASSERT_THAT(arg, |
| 2333 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2334 | WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4), |
| 2335 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2336 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 2337 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2338 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 2339 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 2340 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 2341 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 2342 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2343 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2344 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2345 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 2346 | |
| 2347 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2348 | /* dx= */ 5, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2349 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2350 | ASSERT_EQ(1u, args.size()); |
| 2351 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2352 | ASSERT_THAT(arg, |
| 2353 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2354 | WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), |
| 2355 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2356 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 2357 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2358 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 2359 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 2360 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 2361 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 2362 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2363 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2364 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2365 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 2366 | |
| 2367 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2368 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2369 | ASSERT_THAT(args, |
| 2370 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2371 | AllOf(WithMotionAction( |
| 2372 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2373 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2374 | WithGestureOffset(0, 0, EPSILON), |
| 2375 | WithGestureSwipeFingerCount(4), |
| 2376 | WithMotionClassification( |
| 2377 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2378 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 2379 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2380 | VariantWith<NotifyMotionArgs>( |
| 2381 | AllOf(WithMotionAction( |
| 2382 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2383 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2384 | WithGestureOffset(0, 0, EPSILON), |
| 2385 | WithGestureSwipeFingerCount(4), |
| 2386 | WithMotionClassification( |
| 2387 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2388 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 2389 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2390 | VariantWith<NotifyMotionArgs>( |
| 2391 | AllOf(WithMotionAction( |
| 2392 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2393 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2394 | WithGestureOffset(0, 0, EPSILON), |
| 2395 | WithGestureSwipeFingerCount(4), |
| 2396 | WithMotionClassification( |
| 2397 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2398 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2399 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2400 | VariantWith<NotifyMotionArgs>( |
| 2401 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2402 | WithGestureOffset(0, 0, EPSILON), |
| 2403 | WithGestureSwipeFingerCount(4), |
| 2404 | WithMotionClassification( |
| 2405 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2406 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2407 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2408 | VariantWith<NotifyMotionArgs>( |
| 2409 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2410 | WithCoords(0, 0), |
| 2411 | WithMotionClassification(MotionClassification::NONE), |
| 2412 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2413 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) { |
| 2417 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2418 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2419 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2420 | |
| 2421 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2422 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2423 | std::list<NotifyArgs> args = |
| 2424 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2425 | ASSERT_THAT(args, |
| 2426 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2427 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 2428 | WithMotionClassification(MotionClassification::PINCH), |
| 2429 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2430 | WithCoords(-100, 0), WithPointerCount(1u), |
| 2431 | WithToolType(ToolType::FINGER), |
| 2432 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2433 | VariantWith<NotifyMotionArgs>( |
| 2434 | AllOf(WithMotionAction( |
| 2435 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2436 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2437 | WithMotionClassification(MotionClassification::PINCH), |
| 2438 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2439 | WithPointerCoords(1, 100, 0), WithPointerCount(2u), |
| 2440 | WithToolType(ToolType::FINGER), |
| 2441 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2442 | |
| 2443 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2444 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2445 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2446 | ASSERT_THAT(args, |
| 2447 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2448 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2449 | WithMotionClassification(MotionClassification::PINCH), |
| 2450 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
| 2451 | WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0), |
| 2452 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2453 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2454 | |
| 2455 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2456 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2457 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2458 | ASSERT_THAT(args, |
| 2459 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2460 | AllOf(WithMotionAction( |
| 2461 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2462 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2463 | WithMotionClassification(MotionClassification::PINCH), |
| 2464 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2465 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2466 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2467 | VariantWith<NotifyMotionArgs>( |
| 2468 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2469 | WithMotionClassification(MotionClassification::PINCH), |
| 2470 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2471 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2472 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2473 | VariantWith<NotifyMotionArgs>( |
| 2474 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2475 | WithCoords(0, 0), |
| 2476 | WithMotionClassification(MotionClassification::NONE), |
| 2477 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2478 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) { |
| 2482 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2483 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2484 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2485 | |
| 2486 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2487 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2488 | std::list<NotifyArgs> args = |
| 2489 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2490 | ASSERT_THAT(args, |
| 2491 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2492 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 2493 | WithMotionClassification(MotionClassification::PINCH), |
| 2494 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2495 | WithCoords(-100, 0), WithPointerCount(1u), |
| 2496 | WithToolType(ToolType::FINGER), |
| 2497 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2498 | VariantWith<NotifyMotionArgs>( |
| 2499 | AllOf(WithMotionAction( |
| 2500 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2501 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2502 | WithMotionClassification(MotionClassification::PINCH), |
| 2503 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2504 | WithPointerCoords(1, 100, 0), WithPointerCount(2u), |
| 2505 | WithToolType(ToolType::FINGER), |
| 2506 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2507 | |
| 2508 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2509 | /* dz= */ 1.1, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2510 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2511 | ASSERT_THAT(args, |
| 2512 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2513 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2514 | WithMotionClassification(MotionClassification::PINCH), |
| 2515 | WithGesturePinchScaleFactor(1.1f, EPSILON), |
| 2516 | WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0), |
| 2517 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2518 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2519 | |
| 2520 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2521 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2522 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2523 | ASSERT_THAT(args, |
| 2524 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2525 | AllOf(WithMotionAction( |
| 2526 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2527 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2528 | WithMotionClassification(MotionClassification::PINCH), |
| 2529 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2530 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2531 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2532 | VariantWith<NotifyMotionArgs>( |
| 2533 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2534 | WithMotionClassification(MotionClassification::PINCH), |
| 2535 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2536 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2537 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2538 | VariantWith<NotifyMotionArgs>( |
| 2539 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2540 | WithCoords(0, 0), |
| 2541 | WithMotionClassification(MotionClassification::NONE), |
| 2542 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2543 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) { |
| 2547 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2548 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2549 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2550 | |
| 2551 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2552 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2553 | std::list<NotifyArgs> args = |
| 2554 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2555 | |
| 2556 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2557 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2558 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2559 | |
| 2560 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2561 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2562 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2563 | |
| 2564 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2565 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2566 | ASSERT_THAT(args, |
| 2567 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2568 | WithMotionClassification(MotionClassification::NONE)))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) { |
| 2572 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2573 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2574 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2575 | |
| 2576 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2577 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2578 | std::list<NotifyArgs> args = |
| 2579 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2580 | |
| 2581 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2582 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2583 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2584 | |
| 2585 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2586 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2587 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2588 | |
| 2589 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 2590 | // need to use another gesture type, like scroll. |
| 2591 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 2592 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2593 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2594 | ASSERT_FALSE(args.empty()); |
| 2595 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
| 2596 | } |
| 2597 | |
| 2598 | TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) { |
| 2599 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2600 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2601 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2602 | |
| 2603 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2604 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 2605 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2606 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2607 | |
| 2608 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2609 | ASSERT_THAT(args, |
| 2610 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2611 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2612 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2613 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), |
| 2614 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 2615 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2616 | VariantWith<NotifyMotionArgs>( |
| 2617 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2618 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 2619 | WithButtonState(0), WithCoords(0, 0), |
| 2620 | WithToolType(ToolType::FINGER), |
| 2621 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2622 | VariantWith<NotifyMotionArgs>( |
| 2623 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2624 | WithButtonState(0), WithCoords(0, 0), |
| 2625 | WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2626 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2627 | VariantWith<NotifyMotionArgs>( |
| 2628 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2629 | WithButtonState(0), WithCoords(0, 0), |
| 2630 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2631 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) { |
| 2635 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2636 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2637 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2638 | |
| 2639 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2640 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2641 | |
| 2642 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2643 | ASSERT_THAT(args, |
| 2644 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2645 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2646 | WithCoords(0, -10), |
| 2647 | WithGestureScrollDistance(0, 0, EPSILON), |
| 2648 | WithMotionClassification( |
| 2649 | MotionClassification::TWO_FINGER_SWIPE), |
| 2650 | WithToolType(ToolType::FINGER), |
| 2651 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 2652 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2653 | VariantWith<NotifyMotionArgs>( |
| 2654 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2655 | WithCoords(0, 0), |
| 2656 | WithMotionClassification(MotionClassification::NONE), |
| 2657 | WithToolType(ToolType::FINGER), |
| 2658 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) { |
| 2662 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2663 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2664 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2665 | |
| 2666 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 2667 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2668 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2669 | |
| 2670 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2671 | ASSERT_THAT(args, |
| 2672 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2673 | AllOf(WithMotionAction( |
| 2674 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2675 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2676 | WithGestureOffset(0, 0, EPSILON), |
| 2677 | WithMotionClassification( |
| 2678 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2679 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 2680 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2681 | VariantWith<NotifyMotionArgs>( |
| 2682 | AllOf(WithMotionAction( |
| 2683 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2684 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2685 | WithGestureOffset(0, 0, EPSILON), |
| 2686 | WithMotionClassification( |
| 2687 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2688 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2689 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2690 | VariantWith<NotifyMotionArgs>( |
| 2691 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2692 | WithGestureOffset(0, 0, EPSILON), |
| 2693 | WithMotionClassification( |
| 2694 | MotionClassification::MULTI_FINGER_SWIPE), |
| 2695 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2696 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2697 | VariantWith<NotifyMotionArgs>( |
| 2698 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2699 | WithMotionClassification(MotionClassification::NONE), |
| 2700 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2701 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) { |
| 2705 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2706 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2707 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2708 | |
| 2709 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2710 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2711 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2712 | |
| 2713 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2714 | ASSERT_THAT(args, |
| 2715 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2716 | AllOf(WithMotionAction( |
| 2717 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2718 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2719 | WithMotionClassification(MotionClassification::PINCH), |
| 2720 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2721 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2722 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2723 | VariantWith<NotifyMotionArgs>( |
| 2724 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2725 | WithMotionClassification(MotionClassification::PINCH), |
| 2726 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2727 | WithPointerCount(1u), WithToolType(ToolType::FINGER), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2728 | WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2729 | VariantWith<NotifyMotionArgs>( |
| 2730 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2731 | WithCoords(0, 0), |
| 2732 | WithMotionClassification(MotionClassification::NONE), |
| 2733 | WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2734 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) { |
| 2738 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2739 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2740 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2741 | |
| 2742 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2743 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2744 | std::list<NotifyArgs> args = |
| 2745 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2746 | |
| 2747 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2748 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2749 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
| 2750 | WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2751 | } |
| 2752 | |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame^] | 2753 | TEST_F(GestureConverterTestWithChoreographer, FlingTapDownAfterScrollStopsFling) { |
| 2754 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2755 | input_flags::enable_touchpad_fling_stop(true); |
| 2756 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2757 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2758 | |
| 2759 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 2760 | std::list<NotifyArgs> args = |
| 2761 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
| 2762 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 2763 | GESTURES_FLING_START); |
| 2764 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
| 2765 | |
| 2766 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2767 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
| 2768 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
| 2769 | ASSERT_THAT(args, |
| 2770 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2771 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)), |
| 2772 | VariantWith<NotifyMotionArgs>( |
| 2773 | WithMotionAction(AMOTION_EVENT_ACTION_DOWN)), |
| 2774 | VariantWith<NotifyMotionArgs>( |
| 2775 | WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)), |
| 2776 | VariantWith<NotifyMotionArgs>( |
| 2777 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2778 | WithMotionClassification(MotionClassification::NONE))))); |
| 2779 | ASSERT_THAT(args, |
| 2780 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 2781 | WithToolType(ToolType::FINGER), |
| 2782 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
| 2783 | } |
| 2784 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2785 | TEST_F(GestureConverterTestWithChoreographer, Tap) { |
| 2786 | // Tap should produce button press/release events |
| 2787 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2788 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2789 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2790 | |
| 2791 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 2792 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2793 | std::list<NotifyArgs> args = |
| 2794 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2795 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2796 | |
| 2797 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2798 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2799 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2800 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2801 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2802 | ASSERT_THAT(args, |
| 2803 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2804 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 2805 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2806 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2807 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2808 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2809 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 2810 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2811 | WithToolType(ToolType::FINGER), |
| 2812 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2813 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2814 | VariantWith<NotifyMotionArgs>( |
| 2815 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 2816 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2817 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2818 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2819 | WithToolType(ToolType::FINGER), |
| 2820 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2821 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2822 | VariantWith<NotifyMotionArgs>( |
| 2823 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2824 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2825 | WithButtonState(0), WithCoords(0, 0), |
| 2826 | WithRelativeMotion(0.f, 0.f), |
| 2827 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2828 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2829 | VariantWith<NotifyMotionArgs>( |
| 2830 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2831 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2832 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2833 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2834 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2835 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2836 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 2837 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2838 | WithPressure(0.0f), |
| 2839 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | TEST_F(GestureConverterTestWithChoreographer, Click) { |
| 2843 | // Click should produce button press/release events |
| 2844 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2845 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2846 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2847 | |
| 2848 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 2849 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2850 | std::list<NotifyArgs> args = |
| 2851 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2852 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2853 | |
| 2854 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2855 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2856 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2857 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2858 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2859 | ASSERT_THAT(args, |
| 2860 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2861 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 2862 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2863 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2864 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2865 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2866 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 2867 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2868 | WithToolType(ToolType::FINGER), |
| 2869 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2870 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2871 | VariantWith<NotifyMotionArgs>( |
| 2872 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 2873 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2874 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2875 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2876 | WithToolType(ToolType::FINGER), |
| 2877 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2878 | WithPressure(1.0f), |
| 2879 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2880 | |
| 2881 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2882 | /* down= */ GESTURES_BUTTON_NONE, |
| 2883 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2884 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2885 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2886 | ASSERT_THAT(args, |
| 2887 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2888 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2889 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2890 | WithButtonState(0), WithCoords(0, 0), |
| 2891 | WithRelativeMotion(0.f, 0.f), |
| 2892 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2893 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2894 | VariantWith<NotifyMotionArgs>( |
| 2895 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2896 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2897 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2898 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2899 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2900 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2901 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 2902 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2903 | WithPressure(0.0f), |
| 2904 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled, |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2908 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION), |
| 2909 | REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 2910 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 2911 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2912 | // Tap should be ignored when disabled |
| 2913 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 2914 | |
| 2915 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2916 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2917 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2918 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2919 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2920 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2921 | std::list<NotifyArgs> args = |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2922 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2923 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2924 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2925 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2926 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2927 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2928 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2929 | |
| 2930 | // no events should be generated |
| 2931 | ASSERT_EQ(0u, args.size()); |
| 2932 | |
| 2933 | // Future taps should be re-enabled |
| 2934 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 2935 | } |
| 2936 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2937 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay, |
| 2938 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 2939 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 2940 | |
| 2941 | // Tap should be ignored when disabled |
| 2942 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 2943 | |
| 2944 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2945 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2946 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2947 | |
| 2948 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 2949 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 2950 | std::list<NotifyArgs> args = |
| 2951 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2952 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2953 | |
| 2954 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
| 2955 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2956 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 2957 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 2958 | |
| 2959 | // no events should be generated |
| 2960 | ASSERT_EQ(0u, args.size()); |
| 2961 | |
| 2962 | // Future taps should be re-enabled |
| 2963 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 2964 | |
| 2965 | // taps before the threshold should still be ignored |
| 2966 | currentTime += TAP_ENABLE_DELAY_NANOS.count(); |
| 2967 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 2968 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 2969 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 2970 | |
| 2971 | ASSERT_EQ(1u, args.size()); |
| 2972 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 2973 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 2974 | |
| 2975 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 2976 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2977 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 2978 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 2979 | |
| 2980 | // no events should be generated |
| 2981 | ASSERT_EQ(0u, args.size()); |
| 2982 | |
| 2983 | // taps after the threshold should be recognised |
| 2984 | currentTime += 1; |
| 2985 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 2986 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 2987 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 2988 | |
| 2989 | ASSERT_EQ(1u, args.size()); |
| 2990 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 2991 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 2992 | |
| 2993 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 2994 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2995 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 2996 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 2997 | |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2998 | ASSERT_EQ(6u, args.size()); |
| 2999 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 3000 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 3001 | WithRelativeMotion(0.f, 0.f), WithButtonState(0))); |
| 3002 | args.pop_front(); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 3003 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 3004 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f), |
| 3005 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))); |
| 3006 | args.pop_front(); |
| 3007 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 3008 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 3009 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1), |
| 3010 | WithRelativeMotion(0.f, 0.f))); |
| 3011 | args.pop_front(); |
| 3012 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 3013 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 3014 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), |
| 3015 | WithRelativeMotion(0.f, 0.f))); |
| 3016 | args.pop_front(); |
| 3017 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 3018 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f), |
| 3019 | WithButtonState(0))); |
| 3020 | args.pop_front(); |
| 3021 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 3022 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0), |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 3023 | WithButtonState(0))); |
| 3024 | } |
| 3025 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 3026 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled, |
| 3027 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
| 3028 | // Click should still produce button press/release events |
| 3029 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 3030 | |
| 3031 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 3032 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 3033 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 3034 | |
| 3035 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 3036 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3037 | std::list<NotifyArgs> args = |
| 3038 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 3039 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 3040 | |
| 3041 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 3042 | /* down= */ GESTURES_BUTTON_LEFT, |
| 3043 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3044 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 3045 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 3046 | ASSERT_THAT(args, |
| 3047 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 3048 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 3049 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 3050 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 3051 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 3052 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 3053 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 3054 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 3055 | WithToolType(ToolType::FINGER), |
| 3056 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 3057 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 3058 | VariantWith<NotifyMotionArgs>( |
| 3059 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 3060 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 3061 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 3062 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 3063 | WithToolType(ToolType::FINGER), |
| 3064 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
| 3065 | WithPressure(1.0f), |
| 3066 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 3067 | |
| 3068 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 3069 | /* down= */ GESTURES_BUTTON_NONE, |
| 3070 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3071 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 3072 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 3073 | ASSERT_THAT(args, |
| 3074 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 3075 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 3076 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 3077 | WithButtonState(0), WithCoords(0, 0), |
| 3078 | WithRelativeMotion(0.f, 0.f), |
| 3079 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 3080 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 3081 | VariantWith<NotifyMotionArgs>( |
| 3082 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 3083 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 3084 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 3085 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 3086 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 3087 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 3088 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 3089 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 3090 | WithPressure(0.0f), |
| 3091 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 3092 | |
| 3093 | // Future taps should be re-enabled |
| 3094 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 3095 | } |
| 3096 | |
| 3097 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick, |
| 3098 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
| 3099 | // initially disable tap-to-click |
| 3100 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 3101 | |
| 3102 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 3103 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 3104 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 3105 | |
| 3106 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3107 | std::list<NotifyArgs> args = |
| 3108 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 3109 | // We don't need to check args here, since it's covered by the Move test. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 3110 | |
| 3111 | // Future taps should be re-enabled |
| 3112 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 3113 | } |
| 3114 | |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3115 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove, |
| 3116 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 3117 | const nsecs_t gestureStartTime = 1000; |
| 3118 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 3119 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 3120 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 3121 | |
| 3122 | // Start a move gesture at gestureStartTime |
| 3123 | Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10); |
| 3124 | std::list<NotifyArgs> args = |
| 3125 | converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 3126 | ASSERT_THAT(args, |
| 3127 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 3128 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 3129 | VariantWith<NotifyMotionArgs>( |
| 3130 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3131 | |
| 3132 | // Key presses with IME connection should cancel ongoing move gesture |
| 3133 | nsecs_t currentTime = gestureStartTime + 100; |
| 3134 | mFakePolicy->setIsInputMethodConnectionActive(true); |
| 3135 | mReader->getContext()->setLastKeyDownTimestamp(currentTime); |
| 3136 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 3137 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 3138 | ASSERT_THAT(args, |
| 3139 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 3140 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3141 | |
| 3142 | // any updates in existing move gesture should be ignored |
| 3143 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 3144 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
| 3145 | ASSERT_EQ(0u, args.size()); |
| 3146 | |
| 3147 | // New gesture should not be affected |
| 3148 | currentTime += 100; |
| 3149 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 3150 | args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 3151 | ASSERT_THAT(args, |
| 3152 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 3153 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 3154 | VariantWith<NotifyMotionArgs>( |
| 3155 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 3158 | } // namespace android |