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