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