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