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