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 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1170 | TEST_F(GestureConverterTest, Tap) { |
| 1171 | // Tap should produce button press/release events |
| 1172 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1173 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1174 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1175 | |
| 1176 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1177 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1178 | std::list<NotifyArgs> args = |
| 1179 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1180 | // 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] | 1181 | |
| 1182 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1183 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1184 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1185 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1186 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1187 | ASSERT_THAT(args, |
| 1188 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1189 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1190 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1191 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1192 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1193 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1194 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1195 | VariantWith<NotifyMotionArgs>( |
| 1196 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1197 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1198 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1199 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1200 | VariantWith<NotifyMotionArgs>( |
| 1201 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1202 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1203 | WithButtonState(0), WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1204 | VariantWith<NotifyMotionArgs>( |
| 1205 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1206 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1207 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1208 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1209 | WithButtonState(0), WithPressure(0.0f))))); |
| 1210 | ASSERT_THAT(args, |
| 1211 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), |
| 1212 | WithRelativeMotion(0.f, 0.f), |
| 1213 | WithToolType(ToolType::FINGER), |
| 1214 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | TEST_F(GestureConverterTest, Click) { |
| 1218 | // Click should produce button press/release events |
| 1219 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1220 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1221 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1222 | |
| 1223 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1224 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1225 | std::list<NotifyArgs> args = |
| 1226 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1227 | // 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] | 1228 | |
| 1229 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1230 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1231 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1232 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1233 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1234 | ASSERT_THAT(args, |
| 1235 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1236 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1237 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1238 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1239 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1240 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1241 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1242 | VariantWith<NotifyMotionArgs>( |
| 1243 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1244 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1245 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1246 | WithPressure(1.0f))))); |
| 1247 | ASSERT_THAT(args, |
| 1248 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), |
| 1249 | WithRelativeMotion(0.f, 0.f), |
| 1250 | WithToolType(ToolType::FINGER), |
| 1251 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1252 | |
| 1253 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1254 | /* down= */ GESTURES_BUTTON_NONE, |
| 1255 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1256 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1257 | ASSERT_THAT(args, |
| 1258 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1259 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1260 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1261 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1262 | VariantWith<NotifyMotionArgs>( |
| 1263 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1264 | WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1265 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1266 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1267 | WithPressure(0.0f))))); |
| 1268 | ASSERT_THAT(args, |
| 1269 | Each(VariantWith<NotifyMotionArgs>( |
| 1270 | AllOf(WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), |
| 1271 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
| 1272 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1275 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1276 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION), |
| 1277 | REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1278 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1279 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1280 | // Tap should be ignored when disabled |
| 1281 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1282 | |
| 1283 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1284 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1285 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1286 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1287 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1288 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1289 | std::list<NotifyArgs> args = |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1290 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1291 | // 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] | 1292 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1293 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1294 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1295 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1296 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1297 | |
| 1298 | // no events should be generated |
| 1299 | ASSERT_EQ(0u, args.size()); |
| 1300 | |
| 1301 | // Future taps should be re-enabled |
| 1302 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1303 | } |
| 1304 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1305 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay, |
| 1306 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1307 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1308 | |
| 1309 | // Tap should be ignored when disabled |
| 1310 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1311 | |
| 1312 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1313 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1314 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1315 | |
| 1316 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1317 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1318 | std::list<NotifyArgs> args = |
| 1319 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1320 | // 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] | 1321 | |
| 1322 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
| 1323 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1324 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1325 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1326 | |
| 1327 | // no events should be generated |
| 1328 | ASSERT_EQ(0u, args.size()); |
| 1329 | |
| 1330 | // Future taps should be re-enabled |
| 1331 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1332 | |
| 1333 | // taps before the threshold should still be ignored |
| 1334 | currentTime += TAP_ENABLE_DELAY_NANOS.count(); |
| 1335 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1336 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1337 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1338 | |
| 1339 | ASSERT_EQ(1u, args.size()); |
| 1340 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1341 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1342 | |
| 1343 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1344 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1345 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1346 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1347 | |
| 1348 | // no events should be generated |
| 1349 | ASSERT_EQ(0u, args.size()); |
| 1350 | |
| 1351 | // taps after the threshold should be recognised |
| 1352 | currentTime += 1; |
| 1353 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1354 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1355 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1356 | |
| 1357 | ASSERT_EQ(1u, args.size()); |
| 1358 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1359 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1360 | |
| 1361 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1362 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1363 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1364 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1365 | ASSERT_THAT(args, |
| 1366 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1367 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 1368 | WithButtonState(0))), |
| 1369 | VariantWith<NotifyMotionArgs>( |
| 1370 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1371 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 1372 | VariantWith<NotifyMotionArgs>( |
| 1373 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1374 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1375 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 1376 | VariantWith<NotifyMotionArgs>( |
| 1377 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1378 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1379 | WithButtonState(0))), |
| 1380 | VariantWith<NotifyMotionArgs>( |
| 1381 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1382 | WithButtonState(0))), |
| 1383 | VariantWith<NotifyMotionArgs>( |
| 1384 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1385 | WithButtonState(0))))); |
| 1386 | ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f)))); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1389 | TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, |
| 1390 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1391 | // Click should still produce button press/release events |
| 1392 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1393 | |
| 1394 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1395 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1396 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1397 | |
| 1398 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1399 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1400 | std::list<NotifyArgs> args = |
| 1401 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1402 | // 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] | 1403 | |
| 1404 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1405 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1406 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1407 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1408 | ASSERT_THAT(args, |
| 1409 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1410 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1411 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1412 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1413 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1414 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1415 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1416 | VariantWith<NotifyMotionArgs>( |
| 1417 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1418 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1419 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1420 | WithPressure(1.0f))))); |
| 1421 | ASSERT_THAT(args, |
| 1422 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), |
| 1423 | WithRelativeMotion(0.f, 0.f), |
| 1424 | WithToolType(ToolType::FINGER), |
| 1425 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1426 | |
| 1427 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1428 | /* down= */ GESTURES_BUTTON_NONE, |
| 1429 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1430 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1431 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1432 | ASSERT_THAT(args, |
| 1433 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1434 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1435 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1436 | WithButtonState(0), WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1437 | VariantWith<NotifyMotionArgs>( |
| 1438 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1439 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1440 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1441 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1442 | WithButtonState(0), WithPressure(0.0f))))); |
| 1443 | ASSERT_THAT(args, |
| 1444 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), |
| 1445 | WithRelativeMotion(0.f, 0.f), |
| 1446 | WithToolType(ToolType::FINGER), |
| 1447 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1448 | |
| 1449 | // Future taps should be re-enabled |
| 1450 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1451 | } |
| 1452 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1453 | TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick, |
| 1454 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1455 | // initially disable tap-to-click |
| 1456 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1457 | |
| 1458 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1459 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 1460 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1461 | |
| 1462 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1463 | std::list<NotifyArgs> args = |
| 1464 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1465 | // 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] | 1466 | |
| 1467 | // Future taps should be re-enabled |
| 1468 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1469 | } |
| 1470 | |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1471 | TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove, |
| 1472 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1473 | const nsecs_t gestureStartTime = 1000; |
| 1474 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1475 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1476 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1477 | |
| 1478 | // Start a move gesture at gestureStartTime |
| 1479 | Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10); |
| 1480 | std::list<NotifyArgs> args = |
| 1481 | converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1482 | ASSERT_THAT(args, |
| 1483 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1484 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1485 | VariantWith<NotifyMotionArgs>( |
| 1486 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1487 | |
| 1488 | // Key presses with IME connection should cancel ongoing move gesture |
| 1489 | nsecs_t currentTime = gestureStartTime + 100; |
| 1490 | mFakePolicy->setIsInputMethodConnectionActive(true); |
| 1491 | mReader->getContext()->setLastKeyDownTimestamp(currentTime); |
| 1492 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1493 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1494 | ASSERT_THAT(args, |
| 1495 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1496 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1497 | |
| 1498 | // any updates in existing move gesture should be ignored |
| 1499 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1500 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
| 1501 | ASSERT_EQ(0u, args.size()); |
| 1502 | |
| 1503 | // New gesture should not be affected |
| 1504 | currentTime += 100; |
| 1505 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1506 | args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1507 | ASSERT_THAT(args, |
| 1508 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1509 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1510 | VariantWith<NotifyMotionArgs>( |
| 1511 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
Prabir Pradhan | cc7268a | 2023-11-16 18:54:13 +0000 | [diff] [blame] | 1514 | // TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging |
| 1515 | // logic can be removed. |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1516 | class GestureConverterTestWithChoreographer : public GestureConverterTestBase { |
| 1517 | protected: |
| 1518 | void SetUp() override { |
| 1519 | input_flags::enable_pointer_choreographer(true); |
| 1520 | GestureConverterTestBase::SetUp(); |
| 1521 | } |
| 1522 | }; |
| 1523 | |
| 1524 | TEST_F(GestureConverterTestWithChoreographer, Move) { |
| 1525 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1526 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1527 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1528 | |
| 1529 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1530 | std::list<NotifyArgs> args = |
| 1531 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1532 | ASSERT_THAT(args, |
| 1533 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1534 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1535 | WithRelativeMotion(0, 0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1536 | VariantWith<NotifyMotionArgs>( |
| 1537 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1538 | WithRelativeMotion(-5, 10), WithButtonState(0), |
| 1539 | WithPressure(0.0f))))); |
| 1540 | ASSERT_THAT(args, |
| 1541 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 1542 | WithToolType(ToolType::FINGER), |
| 1543 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1544 | |
| 1545 | // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER. |
| 1546 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 1547 | ASSERT_THAT(args, |
| 1548 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1549 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0), |
| 1550 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
| 1551 | WithButtonState(0), WithPressure(0.0f), |
| 1552 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) { |
| 1556 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1557 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1558 | converter.setOrientation(ui::ROTATION_90); |
| 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(10, 5), 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))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) { |
| 1579 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1580 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1581 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1582 | |
| 1583 | // Press left and right buttons at once |
| 1584 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1585 | /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 1586 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1587 | std::list<NotifyArgs> args = |
| 1588 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1589 | ASSERT_THAT(args, |
| 1590 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1591 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1592 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1593 | AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1594 | VariantWith<NotifyMotionArgs>( |
| 1595 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1596 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1597 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1598 | VariantWith<NotifyMotionArgs>( |
| 1599 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1600 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 1601 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1602 | AMOTION_EVENT_BUTTON_SECONDARY))))); |
| 1603 | ASSERT_THAT(args, |
| 1604 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 1605 | WithToolType(ToolType::FINGER), |
| 1606 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1607 | |
| 1608 | // Then release the left button |
| 1609 | Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1610 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 1611 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1612 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1613 | ASSERT_THAT(args, |
| 1614 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1615 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1616 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1617 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0), |
| 1618 | WithToolType(ToolType::FINGER), |
| 1619 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1620 | |
| 1621 | // Finally release the right button |
| 1622 | Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1623 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT, |
| 1624 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1625 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1626 | ASSERT_THAT(args, |
| 1627 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1628 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1629 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1630 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1631 | WithMotionAction(AMOTION_EVENT_ACTION_UP)), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1632 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1633 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
| 1634 | ASSERT_THAT(args, |
| 1635 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), |
| 1636 | WithToolType(ToolType::FINGER), |
| 1637 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1638 | } |
| 1639 | |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1640 | TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) { |
| 1641 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1642 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1643 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1644 | |
| 1645 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 1646 | std::list<NotifyArgs> args = |
| 1647 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 1648 | |
| 1649 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1650 | /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE, |
| 1651 | /*is_tap=*/false); |
| 1652 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
| 1653 | ASSERT_THAT(args.front(), |
| 1654 | VariantWith<NotifyMotionArgs>( |
| 1655 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0), |
| 1656 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1657 | WithDisplayId(ADISPLAY_ID_DEFAULT)))); |
| 1658 | } |
| 1659 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1660 | TEST_F(GestureConverterTestWithChoreographer, DragWithButton) { |
| 1661 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1662 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1663 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1664 | |
| 1665 | // Press the button |
| 1666 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1667 | /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE, |
| 1668 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1669 | std::list<NotifyArgs> args = |
| 1670 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1671 | ASSERT_THAT(args, |
| 1672 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1673 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1674 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1675 | VariantWith<NotifyMotionArgs>( |
| 1676 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1677 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1678 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))))); |
| 1679 | ASSERT_THAT(args, |
| 1680 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 1681 | WithToolType(ToolType::FINGER), |
| 1682 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1683 | |
| 1684 | // Move |
| 1685 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1686 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1687 | ASSERT_THAT(args, |
| 1688 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1689 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0), |
| 1690 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
| 1691 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
| 1692 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1693 | |
| 1694 | // Release the button |
| 1695 | Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1696 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 1697 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1698 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1699 | ASSERT_THAT(args, |
| 1700 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1701 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1702 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1703 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1704 | WithMotionAction(AMOTION_EVENT_ACTION_UP)), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1705 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1706 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
| 1707 | ASSERT_THAT(args, |
| 1708 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), |
| 1709 | WithToolType(ToolType::FINGER), |
| 1710 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | TEST_F(GestureConverterTestWithChoreographer, Scroll) { |
| 1714 | const nsecs_t downTime = 12345; |
| 1715 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1716 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1717 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1718 | |
| 1719 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1720 | std::list<NotifyArgs> args = |
| 1721 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1722 | ASSERT_THAT(args, |
| 1723 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1724 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1725 | WithCoords(0, 0), |
| 1726 | WithGestureScrollDistance(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1727 | WithDownTime(downTime))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1728 | VariantWith<NotifyMotionArgs>( |
| 1729 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 1730 | WithCoords(0, -10), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1731 | WithGestureScrollDistance(0, 10, EPSILON))))); |
| 1732 | ASSERT_THAT(args, |
| 1733 | Each(VariantWith<NotifyMotionArgs>( |
| 1734 | AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 1735 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 1736 | WithToolType(ToolType::FINGER), |
| 1737 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1738 | |
| 1739 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1740 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1741 | ASSERT_THAT(args, |
| 1742 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1743 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15), |
| 1744 | WithGestureScrollDistance(0, 5, EPSILON), |
| 1745 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 1746 | WithToolType(ToolType::FINGER), |
| 1747 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), |
| 1748 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1749 | |
| 1750 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1751 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1752 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1753 | ASSERT_THAT(args, |
| 1754 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1755 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1756 | WithCoords(0, -15), |
| 1757 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1758 | WithMotionClassification( |
| 1759 | MotionClassification::TWO_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1760 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1761 | VariantWith<NotifyMotionArgs>( |
| 1762 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1763 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1764 | WithMotionClassification(MotionClassification::NONE))))); |
| 1765 | ASSERT_THAT(args, |
| 1766 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 1767 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) { |
| 1771 | const nsecs_t downTime = 12345; |
| 1772 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1773 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1774 | converter.setOrientation(ui::ROTATION_90); |
| 1775 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1776 | |
| 1777 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1778 | std::list<NotifyArgs> args = |
| 1779 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1780 | ASSERT_THAT(args, |
| 1781 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1782 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1783 | WithCoords(0, 0), |
| 1784 | WithGestureScrollDistance(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1785 | WithDownTime(downTime))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1786 | VariantWith<NotifyMotionArgs>( |
| 1787 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 1788 | WithCoords(-10, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1789 | WithGestureScrollDistance(0, 10, EPSILON))))); |
| 1790 | ASSERT_THAT(args, |
| 1791 | Each(VariantWith<NotifyMotionArgs>( |
| 1792 | AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 1793 | WithToolType(ToolType::FINGER), |
| 1794 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1795 | |
| 1796 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1797 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1798 | ASSERT_THAT(args, |
| 1799 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1800 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0), |
| 1801 | WithGestureScrollDistance(0, 5, EPSILON), |
| 1802 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 1803 | WithToolType(ToolType::FINGER), |
| 1804 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1805 | |
| 1806 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1807 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1808 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1809 | ASSERT_THAT(args, |
| 1810 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1811 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1812 | WithCoords(-15, 0), |
| 1813 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1814 | WithMotionClassification( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1815 | MotionClassification::TWO_FINGER_SWIPE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1816 | VariantWith<NotifyMotionArgs>( |
| 1817 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1818 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1819 | WithMotionClassification(MotionClassification::NONE))))); |
| 1820 | ASSERT_THAT(args, |
| 1821 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 1822 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) { |
| 1826 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1827 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1828 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1829 | |
| 1830 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1831 | std::list<NotifyArgs> args = |
| 1832 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1833 | |
| 1834 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1835 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1836 | |
| 1837 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1838 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1839 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1840 | |
| 1841 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1842 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1843 | ASSERT_THAT(args, |
| 1844 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1845 | AllOf(WithMotionClassification(MotionClassification::NONE), |
| 1846 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) { |
| 1850 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1851 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1852 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1853 | |
| 1854 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1855 | std::list<NotifyArgs> args = |
| 1856 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1857 | |
| 1858 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1859 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1860 | |
| 1861 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1862 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1863 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1864 | |
| 1865 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 1866 | // need to use another gesture type, like pinch. |
| 1867 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1868 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1869 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1870 | ASSERT_FALSE(args.empty()); |
| 1871 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON)); |
| 1872 | } |
| 1873 | |
| 1874 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) { |
| 1875 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1876 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1877 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1878 | |
| 1879 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 1880 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1881 | std::list<NotifyArgs> args = |
| 1882 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1883 | |
| 1884 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1885 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1886 | |
| 1887 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, |
| 1888 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1889 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1890 | ASSERT_THAT(args, |
| 1891 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1892 | WithMotionClassification(MotionClassification::NONE)))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { |
| 1896 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1897 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1898 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1899 | |
| 1900 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, |
| 1901 | /*dy=*/5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1902 | std::list<NotifyArgs> args = |
| 1903 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1904 | |
| 1905 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1906 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1907 | |
| 1908 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 1909 | // need to use another gesture type, like pinch. |
| 1910 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1911 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1912 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1913 | ASSERT_FALSE(args.empty()); |
| 1914 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1915 | AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0))); |
| 1916 | } |
| 1917 | |
| 1918 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) { |
| 1919 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 1920 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 1921 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 1922 | // only checks movement in one dimension. |
| 1923 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1924 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1925 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 1926 | |
| 1927 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 1928 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1929 | std::list<NotifyArgs> args = |
| 1930 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1931 | ASSERT_EQ(4u, args.size()); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1932 | ASSERT_THAT(args, |
| 1933 | Each(VariantWith<NotifyMotionArgs>( |
| 1934 | AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 1935 | WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER), |
| 1936 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1937 | |
| 1938 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 1939 | // move appropriately. |
| 1940 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 1941 | ASSERT_THAT(arg, |
| 1942 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1943 | WithPointerCount(1u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1944 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 1945 | args.pop_front(); |
| 1946 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 1947 | ASSERT_THAT(arg, |
| 1948 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 1949 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1950 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1951 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 1952 | args.pop_front(); |
| 1953 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 1954 | ASSERT_THAT(arg, |
| 1955 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 1956 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1957 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1958 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 1959 | args.pop_front(); |
| 1960 | |
| 1961 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 1962 | ASSERT_THAT(arg, |
| 1963 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 1964 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1965 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 1966 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 1967 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 1968 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 1969 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 1970 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 1971 | |
| 1972 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1973 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1974 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1975 | ASSERT_EQ(1u, args.size()); |
| 1976 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 1977 | ASSERT_THAT(arg, |
| 1978 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 1979 | WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), |
| 1980 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 1981 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
| 1982 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 1983 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 1984 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 1985 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 1986 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 1987 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 1988 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 1989 | |
| 1990 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1991 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1992 | ASSERT_THAT(args, |
| 1993 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1994 | AllOf(WithMotionAction( |
| 1995 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1996 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1997 | WithGestureOffset(0, 0, EPSILON), |
| 1998 | WithGestureSwipeFingerCount(3), |
| 1999 | WithMotionClassification( |
| 2000 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2001 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2002 | VariantWith<NotifyMotionArgs>( |
| 2003 | AllOf(WithMotionAction( |
| 2004 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2005 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2006 | WithGestureOffset(0, 0, EPSILON), |
| 2007 | WithGestureSwipeFingerCount(3), |
| 2008 | WithMotionClassification( |
| 2009 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2010 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2011 | VariantWith<NotifyMotionArgs>( |
| 2012 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2013 | WithGestureOffset(0, 0, EPSILON), |
| 2014 | WithGestureSwipeFingerCount(3), |
| 2015 | WithMotionClassification( |
| 2016 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2017 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2018 | VariantWith<NotifyMotionArgs>( |
| 2019 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2020 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2021 | WithMotionClassification(MotionClassification::NONE))))); |
| 2022 | ASSERT_THAT(args, |
| 2023 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 2024 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) { |
| 2028 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2029 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2030 | converter.setOrientation(ui::ROTATION_90); |
| 2031 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2032 | |
| 2033 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 2034 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2035 | std::list<NotifyArgs> args = |
| 2036 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2037 | ASSERT_EQ(4u, args.size()); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2038 | ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT)))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2039 | |
| 2040 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 2041 | // move appropriately. |
| 2042 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 2043 | ASSERT_THAT(arg, |
| 2044 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2045 | WithPointerCount(1u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2046 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 2047 | args.pop_front(); |
| 2048 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2049 | ASSERT_THAT(arg, |
| 2050 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2051 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2052 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2053 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 2054 | args.pop_front(); |
| 2055 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2056 | ASSERT_THAT(arg, |
| 2057 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2058 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2059 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2060 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 2061 | args.pop_front(); |
| 2062 | |
| 2063 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2064 | ASSERT_THAT(arg, |
| 2065 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2066 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2067 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 2068 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 2069 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 2070 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2071 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2072 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2073 | |
| 2074 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2075 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2076 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2077 | ASSERT_EQ(1u, args.size()); |
| 2078 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2079 | ASSERT_THAT(arg, |
| 2080 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2081 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), |
| 2082 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2083 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 2084 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 2085 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 2086 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2087 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2088 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2089 | |
| 2090 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2091 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2092 | ASSERT_THAT(args, |
| 2093 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2094 | AllOf(WithMotionAction( |
| 2095 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2096 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2097 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2098 | VariantWith<NotifyMotionArgs>( |
| 2099 | AllOf(WithMotionAction( |
| 2100 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2101 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2102 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2103 | VariantWith<NotifyMotionArgs>( |
| 2104 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2105 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2106 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2107 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))))); |
| 2108 | ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT)))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) { |
| 2112 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2113 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2114 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2115 | |
| 2116 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2117 | /* dx= */ 10, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2118 | std::list<NotifyArgs> args = |
| 2119 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2120 | ASSERT_EQ(5u, args.size()); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2121 | ASSERT_THAT(args, |
| 2122 | Each(VariantWith<NotifyMotionArgs>( |
| 2123 | AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2124 | WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER), |
| 2125 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2126 | |
| 2127 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 2128 | // move appropriately. |
| 2129 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 2130 | ASSERT_THAT(arg, |
| 2131 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2132 | WithPointerCount(1u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2133 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 2134 | args.pop_front(); |
| 2135 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2136 | ASSERT_THAT(arg, |
| 2137 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2138 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2139 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2140 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 2141 | args.pop_front(); |
| 2142 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2143 | ASSERT_THAT(arg, |
| 2144 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2145 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2146 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2147 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 2148 | args.pop_front(); |
| 2149 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2150 | ASSERT_THAT(arg, |
| 2151 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2152 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2153 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2154 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 2155 | args.pop_front(); |
| 2156 | |
| 2157 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2158 | ASSERT_THAT(arg, |
| 2159 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2160 | WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2161 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 2162 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 2163 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 2164 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 2165 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2166 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2167 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2168 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 2169 | |
| 2170 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2171 | /* dx= */ 5, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2172 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2173 | ASSERT_EQ(1u, args.size()); |
| 2174 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 2175 | ASSERT_THAT(arg, |
| 2176 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2177 | WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), |
| 2178 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 2179 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
| 2180 | WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2181 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 2182 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 2183 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 2184 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 2185 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 2186 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 2187 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 2188 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 2189 | |
| 2190 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2191 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2192 | ASSERT_THAT(args, |
| 2193 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2194 | AllOf(WithMotionAction( |
| 2195 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2196 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2197 | WithGestureOffset(0, 0, EPSILON), |
| 2198 | WithGestureSwipeFingerCount(4), |
| 2199 | WithMotionClassification( |
| 2200 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2201 | WithPointerCount(4u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2202 | VariantWith<NotifyMotionArgs>( |
| 2203 | AllOf(WithMotionAction( |
| 2204 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2205 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2206 | WithGestureOffset(0, 0, EPSILON), |
| 2207 | WithGestureSwipeFingerCount(4), |
| 2208 | WithMotionClassification( |
| 2209 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2210 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2211 | VariantWith<NotifyMotionArgs>( |
| 2212 | AllOf(WithMotionAction( |
| 2213 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2214 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2215 | WithGestureOffset(0, 0, EPSILON), |
| 2216 | WithGestureSwipeFingerCount(4), |
| 2217 | WithMotionClassification( |
| 2218 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2219 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2220 | VariantWith<NotifyMotionArgs>( |
| 2221 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2222 | WithGestureOffset(0, 0, EPSILON), |
| 2223 | WithGestureSwipeFingerCount(4), |
| 2224 | WithMotionClassification( |
| 2225 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2226 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2227 | VariantWith<NotifyMotionArgs>( |
| 2228 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2229 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2230 | WithMotionClassification(MotionClassification::NONE))))); |
| 2231 | ASSERT_THAT(args, |
| 2232 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 2233 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) { |
| 2237 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2238 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2239 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2240 | |
| 2241 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2242 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2243 | std::list<NotifyArgs> args = |
| 2244 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2245 | ASSERT_THAT(args, |
| 2246 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2247 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2248 | WithCoords(-100, 0), WithPointerCount(1u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2249 | VariantWith<NotifyMotionArgs>( |
| 2250 | AllOf(WithMotionAction( |
| 2251 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2252 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2253 | WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); |
| 2254 | ASSERT_THAT(args, |
| 2255 | Each(VariantWith<NotifyMotionArgs>( |
| 2256 | AllOf(WithMotionClassification(MotionClassification::PINCH), |
| 2257 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2258 | WithToolType(ToolType::FINGER), |
| 2259 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2260 | |
| 2261 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2262 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2263 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2264 | ASSERT_THAT(args, |
| 2265 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2266 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2267 | WithMotionClassification(MotionClassification::PINCH), |
| 2268 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
| 2269 | WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0), |
| 2270 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2271 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2272 | |
| 2273 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2274 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2275 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2276 | ASSERT_THAT(args, |
| 2277 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2278 | AllOf(WithMotionAction( |
| 2279 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2280 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2281 | WithMotionClassification(MotionClassification::PINCH), |
| 2282 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2283 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2284 | VariantWith<NotifyMotionArgs>( |
| 2285 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2286 | WithMotionClassification(MotionClassification::PINCH), |
| 2287 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2288 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2289 | VariantWith<NotifyMotionArgs>( |
| 2290 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2291 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2292 | WithMotionClassification(MotionClassification::NONE))))); |
| 2293 | ASSERT_THAT(args, |
| 2294 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 2295 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) { |
| 2299 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2300 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2301 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2302 | |
| 2303 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2304 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2305 | std::list<NotifyArgs> args = |
| 2306 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2307 | ASSERT_THAT(args, |
| 2308 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2309 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2310 | WithCoords(-100, 0), WithPointerCount(1u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2311 | VariantWith<NotifyMotionArgs>( |
| 2312 | AllOf(WithMotionAction( |
| 2313 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 2314 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2315 | WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); |
| 2316 | ASSERT_THAT(args, |
| 2317 | Each(VariantWith<NotifyMotionArgs>( |
| 2318 | AllOf(WithMotionClassification(MotionClassification::PINCH), |
| 2319 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 2320 | WithToolType(ToolType::FINGER), |
| 2321 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2322 | |
| 2323 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2324 | /* dz= */ 1.1, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2325 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2326 | ASSERT_THAT(args, |
| 2327 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2328 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 2329 | WithMotionClassification(MotionClassification::PINCH), |
| 2330 | WithGesturePinchScaleFactor(1.1f, EPSILON), |
| 2331 | WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0), |
| 2332 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
| 2333 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2334 | |
| 2335 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 2336 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2337 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2338 | ASSERT_THAT(args, |
| 2339 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2340 | AllOf(WithMotionAction( |
| 2341 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2342 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2343 | WithMotionClassification(MotionClassification::PINCH), |
| 2344 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2345 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2346 | VariantWith<NotifyMotionArgs>( |
| 2347 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2348 | WithMotionClassification(MotionClassification::PINCH), |
| 2349 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2350 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2351 | VariantWith<NotifyMotionArgs>( |
| 2352 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2353 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2354 | WithMotionClassification(MotionClassification::NONE))))); |
| 2355 | ASSERT_THAT(args, |
| 2356 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 2357 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) { |
| 2361 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2362 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2363 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2364 | |
| 2365 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2366 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2367 | std::list<NotifyArgs> args = |
| 2368 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2369 | |
| 2370 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2371 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2372 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2373 | |
| 2374 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2375 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2376 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2377 | |
| 2378 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2379 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2380 | ASSERT_THAT(args, |
| 2381 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2382 | WithMotionClassification(MotionClassification::NONE)))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) { |
| 2386 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2387 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2388 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2389 | |
| 2390 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2391 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2392 | std::list<NotifyArgs> args = |
| 2393 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2394 | |
| 2395 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2396 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2397 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2398 | |
| 2399 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2400 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2401 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2402 | |
| 2403 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 2404 | // need to use another gesture type, like scroll. |
| 2405 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 2406 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2407 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2408 | ASSERT_FALSE(args.empty()); |
| 2409 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
| 2410 | } |
| 2411 | |
| 2412 | TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) { |
| 2413 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2414 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2415 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2416 | |
| 2417 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2418 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 2419 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2420 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2421 | |
| 2422 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2423 | ASSERT_THAT(args, |
| 2424 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2425 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2426 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2427 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2428 | VariantWith<NotifyMotionArgs>( |
| 2429 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2430 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2431 | WithButtonState(0))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2432 | VariantWith<NotifyMotionArgs>( |
| 2433 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2434 | WithButtonState(0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2435 | VariantWith<NotifyMotionArgs>( |
| 2436 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2437 | WithButtonState(0))))); |
| 2438 | ASSERT_THAT(args, |
| 2439 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 2440 | WithToolType(ToolType::FINGER), |
| 2441 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) { |
| 2445 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2446 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2447 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2448 | |
| 2449 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2450 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2451 | |
| 2452 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2453 | ASSERT_THAT(args, |
| 2454 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2455 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2456 | WithCoords(0, -10), |
| 2457 | WithGestureScrollDistance(0, 0, EPSILON), |
| 2458 | WithMotionClassification( |
| 2459 | MotionClassification::TWO_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2460 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2461 | VariantWith<NotifyMotionArgs>( |
| 2462 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2463 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2464 | WithMotionClassification(MotionClassification::NONE))))); |
| 2465 | ASSERT_THAT(args, |
| 2466 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 2467 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) { |
| 2471 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2472 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2473 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2474 | |
| 2475 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 2476 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2477 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2478 | |
| 2479 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2480 | ASSERT_THAT(args, |
| 2481 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2482 | AllOf(WithMotionAction( |
| 2483 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2484 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2485 | WithGestureOffset(0, 0, EPSILON), |
| 2486 | WithMotionClassification( |
| 2487 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2488 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2489 | VariantWith<NotifyMotionArgs>( |
| 2490 | AllOf(WithMotionAction( |
| 2491 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2492 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2493 | WithGestureOffset(0, 0, EPSILON), |
| 2494 | WithMotionClassification( |
| 2495 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2496 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2497 | VariantWith<NotifyMotionArgs>( |
| 2498 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2499 | WithGestureOffset(0, 0, EPSILON), |
| 2500 | WithMotionClassification( |
| 2501 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2502 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2503 | VariantWith<NotifyMotionArgs>( |
| 2504 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2505 | WithMotionClassification(MotionClassification::NONE))))); |
| 2506 | ASSERT_THAT(args, |
| 2507 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), |
| 2508 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) { |
| 2512 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2513 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2514 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2515 | |
| 2516 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 2517 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2518 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2519 | |
| 2520 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2521 | ASSERT_THAT(args, |
| 2522 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2523 | AllOf(WithMotionAction( |
| 2524 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 2525 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 2526 | WithMotionClassification(MotionClassification::PINCH), |
| 2527 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
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 | WithMotionClassification(MotionClassification::PINCH), |
| 2532 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2533 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2534 | VariantWith<NotifyMotionArgs>( |
| 2535 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2536 | WithCoords(0, 0), |
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, FlingTapDown) { |
| 2544 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2545 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2546 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2547 | |
| 2548 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2549 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2550 | std::list<NotifyArgs> args = |
| 2551 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2552 | |
| 2553 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2554 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2555 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
| 2556 | WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))); |
| 2557 | } |
| 2558 | |
| 2559 | TEST_F(GestureConverterTestWithChoreographer, Tap) { |
| 2560 | // Tap should produce button press/release events |
| 2561 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2562 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2563 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2564 | |
| 2565 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 2566 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2567 | std::list<NotifyArgs> args = |
| 2568 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2569 | // 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] | 2570 | |
| 2571 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2572 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2573 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2574 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2575 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2576 | ASSERT_THAT(args, |
| 2577 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2578 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2579 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2580 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2581 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2582 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2583 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2584 | VariantWith<NotifyMotionArgs>( |
| 2585 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 2586 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2587 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2588 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2589 | VariantWith<NotifyMotionArgs>( |
| 2590 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2591 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2592 | WithButtonState(0), WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2593 | VariantWith<NotifyMotionArgs>( |
| 2594 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2595 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2596 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2597 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2598 | WithButtonState(0), WithPressure(0.0f))))); |
| 2599 | ASSERT_THAT(args, |
| 2600 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 2601 | WithRelativeMotion(0.f, 0.f), |
| 2602 | WithToolType(ToolType::FINGER), |
| 2603 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | TEST_F(GestureConverterTestWithChoreographer, Click) { |
| 2607 | // Click should produce button press/release events |
| 2608 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2609 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2610 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2611 | |
| 2612 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 2613 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2614 | std::list<NotifyArgs> args = |
| 2615 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2616 | // 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] | 2617 | |
| 2618 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2619 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2620 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2621 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2622 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2623 | ASSERT_THAT(args, |
| 2624 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2625 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2626 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2627 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2628 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2629 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2630 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2631 | VariantWith<NotifyMotionArgs>( |
| 2632 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 2633 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2634 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2635 | WithPressure(1.0f))))); |
| 2636 | ASSERT_THAT(args, |
| 2637 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 2638 | WithRelativeMotion(0.f, 0.f), |
| 2639 | WithToolType(ToolType::FINGER), |
| 2640 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2641 | |
| 2642 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2643 | /* down= */ GESTURES_BUTTON_NONE, |
| 2644 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2645 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2646 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2647 | ASSERT_THAT(args, |
| 2648 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2649 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2650 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2651 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2652 | VariantWith<NotifyMotionArgs>( |
| 2653 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2654 | WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2655 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2656 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2657 | WithPressure(0.0f))))); |
| 2658 | ASSERT_THAT(args, |
| 2659 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), |
| 2660 | WithRelativeMotion(0.f, 0.f), |
| 2661 | WithToolType(ToolType::FINGER), |
| 2662 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled, |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2666 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION), |
| 2667 | REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 2668 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 2669 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2670 | // Tap should be ignored when disabled |
| 2671 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 2672 | |
| 2673 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2674 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2675 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2676 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2677 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2678 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2679 | std::list<NotifyArgs> args = |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2680 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2681 | // 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] | 2682 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2683 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2684 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2685 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2686 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2687 | |
| 2688 | // no events should be generated |
| 2689 | ASSERT_EQ(0u, args.size()); |
| 2690 | |
| 2691 | // Future taps should be re-enabled |
| 2692 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 2693 | } |
| 2694 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2695 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay, |
| 2696 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 2697 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 2698 | |
| 2699 | // Tap should be ignored when disabled |
| 2700 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 2701 | |
| 2702 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2703 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2704 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2705 | |
| 2706 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 2707 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 2708 | std::list<NotifyArgs> args = |
| 2709 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2710 | // 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] | 2711 | |
| 2712 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
| 2713 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2714 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 2715 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 2716 | |
| 2717 | // no events should be generated |
| 2718 | ASSERT_EQ(0u, args.size()); |
| 2719 | |
| 2720 | // Future taps should be re-enabled |
| 2721 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 2722 | |
| 2723 | // taps before the threshold should still be ignored |
| 2724 | currentTime += TAP_ENABLE_DELAY_NANOS.count(); |
| 2725 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 2726 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 2727 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 2728 | |
| 2729 | ASSERT_EQ(1u, args.size()); |
| 2730 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 2731 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 2732 | |
| 2733 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 2734 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2735 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 2736 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 2737 | |
| 2738 | // no events should be generated |
| 2739 | ASSERT_EQ(0u, args.size()); |
| 2740 | |
| 2741 | // taps after the threshold should be recognised |
| 2742 | currentTime += 1; |
| 2743 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 2744 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 2745 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 2746 | |
| 2747 | ASSERT_EQ(1u, args.size()); |
| 2748 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 2749 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 2750 | |
| 2751 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 2752 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2753 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 2754 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2755 | ASSERT_THAT(args, |
| 2756 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2757 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 2758 | WithButtonState(0))), |
| 2759 | VariantWith<NotifyMotionArgs>( |
| 2760 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 2761 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 2762 | VariantWith<NotifyMotionArgs>( |
| 2763 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 2764 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2765 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 2766 | VariantWith<NotifyMotionArgs>( |
| 2767 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2768 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2769 | WithButtonState(0))), |
| 2770 | VariantWith<NotifyMotionArgs>( |
| 2771 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2772 | WithButtonState(0))), |
| 2773 | VariantWith<NotifyMotionArgs>( |
| 2774 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 2775 | WithButtonState(0))))); |
| 2776 | ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f)))); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2779 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled, |
| 2780 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
| 2781 | // Click should still produce button press/release events |
| 2782 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 2783 | |
| 2784 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2785 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2786 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2787 | |
| 2788 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 2789 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2790 | std::list<NotifyArgs> args = |
| 2791 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2792 | // 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] | 2793 | |
| 2794 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2795 | /* down= */ GESTURES_BUTTON_LEFT, |
| 2796 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2797 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2798 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2799 | ASSERT_THAT(args, |
| 2800 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2801 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2802 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2803 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2804 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2805 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2806 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2807 | VariantWith<NotifyMotionArgs>( |
| 2808 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 2809 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2810 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame^] | 2811 | WithPressure(1.0f))))); |
| 2812 | ASSERT_THAT(args, |
| 2813 | Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), |
| 2814 | WithRelativeMotion(0.f, 0.f), |
| 2815 | WithToolType(ToolType::FINGER), |
| 2816 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2817 | |
| 2818 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 2819 | /* down= */ GESTURES_BUTTON_NONE, |
| 2820 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2821 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2822 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2823 | ASSERT_THAT(args, |
| 2824 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2825 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 2826 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 2827 | WithButtonState(0), WithCoords(0, 0), |
| 2828 | WithRelativeMotion(0.f, 0.f), |
| 2829 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2830 | WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2831 | VariantWith<NotifyMotionArgs>( |
| 2832 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 2833 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 2834 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2835 | WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), |
| 2836 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2837 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2838 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 2839 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 2840 | WithPressure(0.0f), |
| 2841 | WithDisplayId(ADISPLAY_ID_DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 2842 | |
| 2843 | // Future taps should be re-enabled |
| 2844 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 2845 | } |
| 2846 | |
| 2847 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick, |
| 2848 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
| 2849 | // initially disable tap-to-click |
| 2850 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 2851 | |
| 2852 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2853 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2854 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2855 | |
| 2856 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2857 | std::list<NotifyArgs> args = |
| 2858 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2859 | // 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] | 2860 | |
| 2861 | // Future taps should be re-enabled |
| 2862 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 2863 | } |
| 2864 | |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2865 | TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove, |
| 2866 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 2867 | const nsecs_t gestureStartTime = 1000; |
| 2868 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 2869 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 2870 | converter.setDisplayId(ADISPLAY_ID_DEFAULT); |
| 2871 | |
| 2872 | // Start a move gesture at gestureStartTime |
| 2873 | Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10); |
| 2874 | std::list<NotifyArgs> args = |
| 2875 | converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2876 | ASSERT_THAT(args, |
| 2877 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2878 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 2879 | VariantWith<NotifyMotionArgs>( |
| 2880 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2881 | |
| 2882 | // Key presses with IME connection should cancel ongoing move gesture |
| 2883 | nsecs_t currentTime = gestureStartTime + 100; |
| 2884 | mFakePolicy->setIsInputMethodConnectionActive(true); |
| 2885 | mReader->getContext()->setLastKeyDownTimestamp(currentTime); |
| 2886 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 2887 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2888 | ASSERT_THAT(args, |
| 2889 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 2890 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2891 | |
| 2892 | // any updates in existing move gesture should be ignored |
| 2893 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 2894 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
| 2895 | ASSERT_EQ(0u, args.size()); |
| 2896 | |
| 2897 | // New gesture should not be affected |
| 2898 | currentTime += 100; |
| 2899 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 2900 | args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 2901 | ASSERT_THAT(args, |
| 2902 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 2903 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 2904 | VariantWith<NotifyMotionArgs>( |
| 2905 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 2908 | } // namespace android |