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