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