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