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> |
| 23 | |
| 24 | #include "FakeEventHub.h" |
| 25 | #include "FakeInputReaderPolicy.h" |
| 26 | #include "FakePointerController.h" |
| 27 | #include "InstrumentedInputReader.h" |
| 28 | #include "NotifyArgs.h" |
| 29 | #include "TestConstants.h" |
Prabir Pradhan | e3b28dd | 2023-10-06 04:19:29 +0000 | [diff] [blame] | 30 | #include "TestEventMatchers.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 31 | #include "TestInputListener.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 32 | #include "include/gestures.h" |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 33 | #include "ui/Rotation.h" |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 37 | namespace input_flags = com::android::input::flags; |
| 38 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 39 | namespace { |
| 40 | |
| 41 | const auto TOUCHPAD_PALM_REJECTION = |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 42 | ACONFIG_FLAG(input_flags, enable_touchpad_typing_palm_rejection); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 43 | const auto TOUCHPAD_PALM_REJECTION_V2 = |
| 44 | ACONFIG_FLAG(input_flags, enable_v2_touchpad_typing_palm_rejection); |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 45 | |
| 46 | } // namespace |
| 47 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 48 | using testing::AllOf; |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 49 | using testing::Each; |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 50 | using testing::ElementsAre; |
Harry Cutts | af66cee | 2024-10-28 17:34:19 +0000 | [diff] [blame] | 51 | using testing::IsEmpty; |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 52 | using testing::VariantWith; |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 53 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 54 | class GestureConverterTest : 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 | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 59 | |
| 60 | void SetUp() { |
| 61 | mFakeEventHub = std::make_unique<FakeEventHub>(); |
| 62 | mFakePolicy = sp<FakeInputReaderPolicy>::make(); |
| 63 | mFakeListener = std::make_unique<TestInputListener>(); |
| 64 | mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, |
| 65 | *mFakeListener); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 66 | mDevice = newDevice(); |
| 67 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20); |
| 68 | 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] | 69 | } |
| 70 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 71 | std::shared_ptr<InputDevice> newDevice() { |
| 72 | InputDeviceIdentifier identifier; |
| 73 | identifier.name = "device"; |
| 74 | identifier.location = "USB1"; |
| 75 | identifier.bus = 0; |
| 76 | std::shared_ptr<InputDevice> device = |
| 77 | std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2, |
| 78 | identifier); |
| 79 | mReader->pushNextDevice(device); |
| 80 | mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD, |
| 81 | identifier.bus); |
| 82 | mReader->loopOnce(); |
| 83 | return device; |
| 84 | } |
| 85 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 86 | std::shared_ptr<FakeEventHub> mFakeEventHub; |
| 87 | sp<FakeInputReaderPolicy> mFakePolicy; |
| 88 | std::unique_ptr<TestInputListener> mFakeListener; |
| 89 | std::unique_ptr<InstrumentedInputReader> mReader; |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 90 | std::shared_ptr<InputDevice> mDevice; |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 91 | }; |
| 92 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 93 | TEST_F(GestureConverterTest, Move) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 94 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 95 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 96 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 97 | |
| 98 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 99 | std::list<NotifyArgs> args = |
| 100 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 101 | ASSERT_THAT(args, |
| 102 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 103 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 104 | WithRelativeMotion(0, 0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 105 | VariantWith<NotifyMotionArgs>( |
| 106 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 107 | WithRelativeMotion(-5, 10), WithButtonState(0), |
| 108 | WithPressure(0.0f))))); |
| 109 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 110 | Each(VariantWith<NotifyMotionArgs>( |
| 111 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 112 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 113 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 114 | // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER. |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 115 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 116 | ASSERT_THAT(args, |
| 117 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 118 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 119 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
| 120 | WithButtonState(0), WithPressure(0.0f), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 121 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 124 | TEST_F(GestureConverterTest, Move_Rotated) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 125 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 126 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 127 | converter.setOrientation(ui::ROTATION_90); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 128 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 129 | |
| 130 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 131 | std::list<NotifyArgs> args = |
| 132 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 133 | ASSERT_THAT(args, |
| 134 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 135 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 136 | WithRelativeMotion(0, 0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 137 | VariantWith<NotifyMotionArgs>( |
| 138 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 139 | WithRelativeMotion(10, 5), WithButtonState(0), |
| 140 | WithPressure(0.0f))))); |
| 141 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 142 | Each(VariantWith<NotifyMotionArgs>( |
| 143 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 144 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | edf6ce7 | 2023-01-04 12:15:53 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 147 | TEST_F(GestureConverterTest, ButtonsChange) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 148 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 149 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 150 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 151 | |
| 152 | // Press left and right buttons at once |
| 153 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 154 | /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 155 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 156 | std::list<NotifyArgs> args = |
| 157 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 158 | ASSERT_THAT(args, |
| 159 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 160 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 161 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 162 | AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 163 | VariantWith<NotifyMotionArgs>( |
| 164 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 165 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 166 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 167 | VariantWith<NotifyMotionArgs>( |
| 168 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 169 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
| 170 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 171 | AMOTION_EVENT_BUTTON_SECONDARY))))); |
| 172 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 173 | Each(VariantWith<NotifyMotionArgs>( |
| 174 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 175 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 176 | |
| 177 | // Then release the left button |
| 178 | Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 179 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 180 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 181 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 182 | ASSERT_THAT(args, |
| 183 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 184 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 185 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 186 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0), |
| 187 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 188 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 189 | |
| 190 | // Finally release the right button |
| 191 | Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 192 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT, |
| 193 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 194 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 195 | ASSERT_THAT(args, |
| 196 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 197 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 198 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 199 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 200 | WithMotionAction(AMOTION_EVENT_ACTION_UP)), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 201 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 202 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
| 203 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 204 | Each(VariantWith<NotifyMotionArgs>( |
| 205 | AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 206 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 209 | TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { |
| 210 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 211 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 212 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 213 | |
| 214 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 215 | std::list<NotifyArgs> args = |
| 216 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 217 | |
| 218 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 219 | /*down=*/GESTURES_BUTTON_LEFT, /*up=*/GESTURES_BUTTON_NONE, |
| 220 | /*is_tap=*/false); |
| 221 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
| 222 | ASSERT_THAT(args.front(), |
| 223 | VariantWith<NotifyMotionArgs>( |
| 224 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), WithButtonState(0), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 225 | WithCoords(0, 0), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 226 | WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 229 | TEST_F(GestureConverterTest, DragWithButton) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 230 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 231 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 232 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 233 | |
| 234 | // Press the button |
| 235 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 236 | /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE, |
| 237 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 238 | std::list<NotifyArgs> args = |
| 239 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 240 | ASSERT_THAT(args, |
| 241 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 242 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 243 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 244 | VariantWith<NotifyMotionArgs>( |
| 245 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 246 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 247 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))))); |
| 248 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 249 | Each(VariantWith<NotifyMotionArgs>( |
| 250 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 251 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 252 | |
| 253 | // Move |
| 254 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 255 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 256 | ASSERT_THAT(args, |
| 257 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 258 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0), |
| 259 | WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 260 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 261 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 262 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 263 | // Release the button |
| 264 | Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 265 | /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT, |
| 266 | /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 267 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture); |
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_BUTTON_RELEASE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 271 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 272 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 273 | WithMotionAction(AMOTION_EVENT_ACTION_UP)), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 274 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 275 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
| 276 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 277 | Each(VariantWith<NotifyMotionArgs>( |
| 278 | AllOf(WithButtonState(0), WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 279 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 282 | TEST_F(GestureConverterTest, Scroll) { |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 283 | input_flags::enable_touchpad_no_focus_change(true); |
| 284 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 285 | const nsecs_t downTime = 12345; |
| 286 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 287 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 288 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 289 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 290 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 291 | std::list<NotifyArgs> args = |
| 292 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 293 | ASSERT_THAT(args, |
| 294 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 295 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 296 | WithCoords(0, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 297 | WithGestureScrollDistance(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 298 | WithDownTime(downTime))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 299 | VariantWith<NotifyMotionArgs>( |
| 300 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 301 | WithCoords(0, -10), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 302 | WithGestureScrollDistance(0, 10, EPSILON))))); |
| 303 | ASSERT_THAT(args, |
| 304 | Each(VariantWith<NotifyMotionArgs>( |
| 305 | AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 306 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE | |
| 307 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 308 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 309 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 310 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 311 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 312 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 313 | ASSERT_THAT(args, |
| 314 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 315 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 316 | WithGestureScrollDistance(0, 5, EPSILON), |
| 317 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 318 | WithToolType(ToolType::FINGER), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 319 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE | |
| 320 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 321 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 322 | |
| 323 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 324 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 325 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 326 | ASSERT_THAT(args, |
| 327 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 328 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 329 | WithCoords(0, -15), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 330 | WithGestureScrollDistance(0, 0, EPSILON), |
| 331 | WithMotionClassification( |
| 332 | MotionClassification::TWO_FINGER_SWIPE), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 333 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE | |
| 334 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 335 | VariantWith<NotifyMotionArgs>( |
| 336 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 337 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 338 | WithMotionClassification(MotionClassification::NONE))))); |
| 339 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 340 | Each(VariantWith<NotifyMotionArgs>( |
| 341 | AllOf(WithToolType(ToolType::FINGER), |
| 342 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | TEST_F(GestureConverterTest, Scroll_Rotated) { |
| 346 | const nsecs_t downTime = 12345; |
| 347 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 348 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 349 | converter.setOrientation(ui::ROTATION_90); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 350 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 351 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 352 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 353 | std::list<NotifyArgs> args = |
| 354 | converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 355 | ASSERT_THAT(args, |
| 356 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 357 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 358 | WithCoords(0, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 359 | WithGestureScrollDistance(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 360 | WithDownTime(downTime))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 361 | VariantWith<NotifyMotionArgs>( |
| 362 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 363 | WithCoords(-10, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 364 | WithGestureScrollDistance(0, 10, EPSILON))))); |
| 365 | ASSERT_THAT(args, |
| 366 | Each(VariantWith<NotifyMotionArgs>( |
| 367 | AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 368 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 369 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 370 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 371 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 372 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 373 | ASSERT_THAT(args, |
| 374 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 375 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 376 | WithGestureScrollDistance(0, 5, EPSILON), |
| 377 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), |
| 378 | WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 379 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 380 | |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 381 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 382 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 383 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 384 | ASSERT_THAT(args, |
| 385 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 386 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 387 | WithCoords(-15, 0), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 388 | WithGestureScrollDistance(0, 0, EPSILON), |
| 389 | WithMotionClassification( |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 390 | MotionClassification::TWO_FINGER_SWIPE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 391 | VariantWith<NotifyMotionArgs>( |
| 392 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 393 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 394 | WithMotionClassification(MotionClassification::NONE))))); |
| 395 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 396 | Each(VariantWith<NotifyMotionArgs>( |
| 397 | AllOf(WithToolType(ToolType::FINGER), |
| 398 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 401 | TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 402 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 403 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 404 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 405 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 406 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 407 | std::list<NotifyArgs> args = |
| 408 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 409 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 410 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 411 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 412 | |
| 413 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 414 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 415 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 416 | |
| 417 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 418 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 419 | ASSERT_THAT(args, |
| 420 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 421 | AllOf(WithMotionClassification(MotionClassification::NONE), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 422 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | ef400b2 | 2022-12-16 21:26:24 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 425 | TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 426 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 427 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 428 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 429 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 430 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 431 | std::list<NotifyArgs> args = |
| 432 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 433 | |
| 434 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 435 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 436 | |
| 437 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 438 | GESTURES_FLING_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 439 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 440 | |
| 441 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 442 | // need to use another gesture type, like pinch. |
| 443 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 444 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 445 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 446 | ASSERT_FALSE(args.empty()); |
| 447 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON)); |
| 448 | } |
| 449 | |
Prabir Pradhan | 13acbd2 | 2024-05-14 22:36:40 +0000 | [diff] [blame] | 450 | TEST_F(GestureConverterTest, Scroll_ClearsFakeFingerPositionOnSubsequentScrollGestures) { |
| 451 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 452 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 453 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
| 454 | |
| 455 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 15, -10); |
| 456 | std::list<NotifyArgs> args = |
| 457 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
| 458 | |
| 459 | Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -2, -5); |
| 460 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
| 461 | |
| 462 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 463 | GESTURES_FLING_START); |
| 464 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
| 465 | Gesture flingGestureEnd(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, 0, |
| 466 | GESTURES_FLING_TAP_DOWN); |
| 467 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGestureEnd); |
| 468 | |
| 469 | // Start a second scoll gesture, and ensure the fake finger is reset to (0, 0), instead of |
| 470 | // continuing from the position where the last scroll gesture's fake finger ended. |
| 471 | Gesture secondScrollStart(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 2, |
| 472 | 14); |
| 473 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, secondScrollStart); |
| 474 | ASSERT_THAT(args, |
| 475 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 476 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)), |
| 477 | VariantWith<NotifyMotionArgs>( |
| 478 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 479 | WithCoords(0, 0), |
| 480 | WithGestureScrollDistance(0, 0, EPSILON))), |
| 481 | VariantWith<NotifyMotionArgs>( |
| 482 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 483 | WithCoords(2, 14), |
| 484 | WithGestureScrollDistance(-2, -14, EPSILON))))); |
| 485 | } |
| 486 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 487 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) { |
| 488 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 489 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 490 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 491 | |
| 492 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 493 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 494 | std::list<NotifyArgs> args = |
| 495 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 496 | |
| 497 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 498 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 499 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 500 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, |
| 501 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 502 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 503 | ASSERT_THAT(args, |
| 504 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 505 | WithMotionClassification(MotionClassification::NONE)))); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 508 | TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) { |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 509 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 510 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 511 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 512 | |
| 513 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5, |
| 514 | /*dy=*/5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 515 | std::list<NotifyArgs> args = |
| 516 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 517 | |
| 518 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 519 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 520 | |
| 521 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 522 | // need to use another gesture type, like pinch. |
| 523 | Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 524 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 525 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 526 | ASSERT_FALSE(args.empty()); |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 527 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 528 | AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { |
| 532 | // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you |
| 533 | // start swiping up and then start moving left or right, it'll return gesture events with only Y |
| 534 | // deltas until you lift your fingers and start swiping again. That's why each of these tests |
| 535 | // only checks movement in one dimension. |
| 536 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 537 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 538 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 539 | |
| 540 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 541 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 542 | std::list<NotifyArgs> args = |
| 543 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 544 | ASSERT_EQ(4u, args.size()); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 545 | ASSERT_THAT(args, |
| 546 | Each(VariantWith<NotifyMotionArgs>( |
| 547 | AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 548 | WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 549 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 550 | |
| 551 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 552 | // move appropriately. |
| 553 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 554 | ASSERT_THAT(arg, |
| 555 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 556 | WithPointerCount(1u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 557 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 558 | args.pop_front(); |
| 559 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 560 | ASSERT_THAT(arg, |
| 561 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 562 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 563 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 564 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 565 | args.pop_front(); |
| 566 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 567 | ASSERT_THAT(arg, |
| 568 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 569 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 570 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 571 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 572 | args.pop_front(); |
| 573 | |
| 574 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 575 | ASSERT_THAT(arg, |
| 576 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 577 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 578 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 579 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 580 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 581 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); |
| 582 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); |
| 583 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); |
| 584 | |
| 585 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 586 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 587 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 588 | ASSERT_EQ(1u, args.size()); |
| 589 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 590 | ASSERT_THAT(arg, |
| 591 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 592 | WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 593 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 594 | WithPointerCount(3u), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 595 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 596 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); |
| 597 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); |
| 598 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); |
| 599 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); |
| 600 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); |
| 601 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); |
| 602 | |
| 603 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 604 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 605 | ASSERT_THAT(args, |
| 606 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 607 | AllOf(WithMotionAction( |
| 608 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 609 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 610 | WithGestureOffset(0, 0, EPSILON), |
| 611 | WithGestureSwipeFingerCount(3), |
| 612 | WithMotionClassification( |
| 613 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 614 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 615 | VariantWith<NotifyMotionArgs>( |
| 616 | AllOf(WithMotionAction( |
| 617 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 618 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 619 | WithGestureOffset(0, 0, EPSILON), |
| 620 | WithGestureSwipeFingerCount(3), |
| 621 | WithMotionClassification( |
| 622 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 623 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 624 | VariantWith<NotifyMotionArgs>( |
| 625 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 626 | WithGestureOffset(0, 0, EPSILON), |
| 627 | WithGestureSwipeFingerCount(3), |
| 628 | WithMotionClassification( |
| 629 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 630 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 631 | VariantWith<NotifyMotionArgs>( |
| 632 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 633 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 634 | WithMotionClassification(MotionClassification::NONE))))); |
| 635 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 636 | Each(VariantWith<NotifyMotionArgs>( |
| 637 | AllOf(WithToolType(ToolType::FINGER), |
| 638 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 641 | TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { |
| 642 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 643 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 644 | converter.setOrientation(ui::ROTATION_90); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 645 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 646 | |
| 647 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, |
| 648 | /* dy= */ 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 649 | std::list<NotifyArgs> args = |
| 650 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 651 | ASSERT_EQ(4u, args.size()); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 652 | ASSERT_THAT(args, |
| 653 | Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 654 | |
| 655 | // Three fake fingers should be created. We don't actually care where they are, so long as they |
| 656 | // move appropriately. |
| 657 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 658 | ASSERT_THAT(arg, |
| 659 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 660 | WithPointerCount(1u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 661 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 662 | args.pop_front(); |
| 663 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 664 | ASSERT_THAT(arg, |
| 665 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 666 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 667 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 668 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 669 | args.pop_front(); |
| 670 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 671 | ASSERT_THAT(arg, |
| 672 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 673 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 674 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 675 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 676 | args.pop_front(); |
| 677 | |
| 678 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 679 | ASSERT_THAT(arg, |
| 680 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 681 | WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 682 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); |
| 683 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); |
| 684 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); |
| 685 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 686 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 687 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 688 | |
| 689 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 690 | /* dx= */ 0, /* dy= */ 5); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 691 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 692 | ASSERT_EQ(1u, args.size()); |
| 693 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 694 | ASSERT_THAT(arg, |
| 695 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 696 | WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 697 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 698 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15); |
| 699 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15); |
| 700 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15); |
| 701 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 702 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 703 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 704 | |
| 705 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 706 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 707 | ASSERT_THAT(args, |
| 708 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 709 | AllOf(WithMotionAction( |
| 710 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 711 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 712 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 713 | VariantWith<NotifyMotionArgs>( |
| 714 | AllOf(WithMotionAction( |
| 715 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 716 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 717 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 718 | VariantWith<NotifyMotionArgs>( |
| 719 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 720 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 721 | VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 722 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))))); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 723 | ASSERT_THAT(args, |
| 724 | Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ui::LogicalDisplayId::DEFAULT)))); |
Harry Cutts | 94f5bd5 | 2023-01-06 18:02:18 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 727 | TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { |
| 728 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 729 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 730 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 731 | |
| 732 | Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 733 | /* dx= */ 10, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 734 | std::list<NotifyArgs> args = |
| 735 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 736 | ASSERT_EQ(5u, args.size()); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 737 | ASSERT_THAT(args, |
| 738 | Each(VariantWith<NotifyMotionArgs>( |
| 739 | AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
| 740 | WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 741 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 742 | |
| 743 | // Four fake fingers should be created. We don't actually care where they are, so long as they |
| 744 | // move appropriately. |
| 745 | NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); |
| 746 | ASSERT_THAT(arg, |
| 747 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 748 | WithPointerCount(1u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 749 | PointerCoords finger0Start = arg.pointerCoords[0]; |
| 750 | args.pop_front(); |
| 751 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 752 | ASSERT_THAT(arg, |
| 753 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 754 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 755 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 756 | PointerCoords finger1Start = arg.pointerCoords[1]; |
| 757 | args.pop_front(); |
| 758 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 759 | ASSERT_THAT(arg, |
| 760 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 761 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 762 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 763 | PointerCoords finger2Start = arg.pointerCoords[2]; |
| 764 | args.pop_front(); |
| 765 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 766 | ASSERT_THAT(arg, |
| 767 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 768 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 769 | WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 770 | PointerCoords finger3Start = arg.pointerCoords[3]; |
| 771 | args.pop_front(); |
| 772 | |
| 773 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 774 | ASSERT_THAT(arg, |
| 775 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 776 | WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 777 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); |
| 778 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); |
| 779 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); |
| 780 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); |
| 781 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 782 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 783 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 784 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 785 | |
| 786 | Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 787 | /* dx= */ 5, /* dy= */ 0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 788 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 789 | ASSERT_EQ(1u, args.size()); |
| 790 | arg = std::get<NotifyMotionArgs>(args.front()); |
| 791 | ASSERT_THAT(arg, |
| 792 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
Harry Cutts | 8743f18 | 2023-05-17 12:03:49 +0000 | [diff] [blame] | 793 | WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4), |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 794 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), |
Josep del Rio | d074638 | 2023-07-29 13:18:25 +0000 | [diff] [blame] | 795 | WithPointerCount(4u), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 796 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 797 | EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); |
| 798 | EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); |
| 799 | EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); |
| 800 | EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); |
| 801 | EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); |
| 802 | EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); |
| 803 | EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); |
| 804 | EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); |
| 805 | |
| 806 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 807 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 808 | ASSERT_THAT(args, |
| 809 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 810 | AllOf(WithMotionAction( |
| 811 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 812 | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 813 | WithGestureOffset(0, 0, EPSILON), |
| 814 | WithGestureSwipeFingerCount(4), |
| 815 | WithMotionClassification( |
| 816 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 817 | WithPointerCount(4u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 818 | VariantWith<NotifyMotionArgs>( |
| 819 | AllOf(WithMotionAction( |
| 820 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 821 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 822 | WithGestureOffset(0, 0, EPSILON), |
| 823 | WithGestureSwipeFingerCount(4), |
| 824 | WithMotionClassification( |
| 825 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 826 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 827 | VariantWith<NotifyMotionArgs>( |
| 828 | AllOf(WithMotionAction( |
| 829 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 830 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 831 | WithGestureOffset(0, 0, EPSILON), |
| 832 | WithGestureSwipeFingerCount(4), |
| 833 | WithMotionClassification( |
| 834 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 835 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 836 | VariantWith<NotifyMotionArgs>( |
| 837 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 838 | WithGestureOffset(0, 0, EPSILON), |
| 839 | WithGestureSwipeFingerCount(4), |
| 840 | WithMotionClassification( |
| 841 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 842 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 843 | VariantWith<NotifyMotionArgs>( |
| 844 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 845 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 846 | WithMotionClassification(MotionClassification::NONE))))); |
| 847 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 848 | Each(VariantWith<NotifyMotionArgs>( |
| 849 | AllOf(WithToolType(ToolType::FINGER), |
| 850 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | c5748d1 | 2022-12-02 17:30:18 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Harry Cutts | af66cee | 2024-10-28 17:34:19 +0000 | [diff] [blame] | 853 | TEST_F(GestureConverterTest, DisablingSystemGestures_IgnoresMultiFingerSwipe) { |
| 854 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 855 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 856 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
| 857 | |
| 858 | std::list<NotifyArgs> args = converter.setEnableSystemGestures(ARBITRARY_TIME, false); |
| 859 | ASSERT_THAT(args, IsEmpty()); |
| 860 | |
| 861 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 862 | /*dy=*/10); |
| 863 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 864 | /*dy=*/5); |
| 865 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 866 | |
| 867 | args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
| 868 | args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
| 869 | args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
| 870 | ASSERT_THAT(args, IsEmpty()); |
| 871 | |
| 872 | args = converter.setEnableSystemGestures(ARBITRARY_TIME, true); |
| 873 | ASSERT_THAT(args, IsEmpty()); |
| 874 | |
| 875 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
| 876 | ASSERT_THAT(args, |
| 877 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 878 | WithMotionAction(AMOTION_EVENT_ACTION_DOWN)), |
| 879 | VariantWith<NotifyMotionArgs>(WithMotionAction( |
| 880 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 881 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)), |
| 882 | VariantWith<NotifyMotionArgs>(WithMotionAction( |
| 883 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 884 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)), |
| 885 | VariantWith<NotifyMotionArgs>( |
| 886 | WithMotionAction(AMOTION_EVENT_ACTION_MOVE)))); |
| 887 | ASSERT_THAT(args, |
| 888 | Each(VariantWith<NotifyMotionArgs>( |
| 889 | WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE)))); |
| 890 | } |
| 891 | |
| 892 | TEST_F(GestureConverterTest, DisablingSystemGestures_EndsOngoingMultiFingerSwipe) { |
| 893 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 894 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 895 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
| 896 | |
| 897 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 898 | /*dy=*/10); |
| 899 | std::list<NotifyArgs> args; |
| 900 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
| 901 | ASSERT_FALSE(args.empty()); |
| 902 | |
| 903 | // Disabling system gestures should end the swipe early. |
| 904 | args = converter.setEnableSystemGestures(ARBITRARY_TIME, false); |
| 905 | ASSERT_THAT(args, |
| 906 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 907 | AllOf(WithMotionAction( |
| 908 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 909 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 910 | WithGestureOffset(0, 0, EPSILON), |
| 911 | WithMotionClassification( |
| 912 | MotionClassification::MULTI_FINGER_SWIPE), |
| 913 | WithPointerCount(3u))), |
| 914 | VariantWith<NotifyMotionArgs>( |
| 915 | AllOf(WithMotionAction( |
| 916 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 917 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 918 | WithGestureOffset(0, 0, EPSILON), |
| 919 | WithMotionClassification( |
| 920 | MotionClassification::MULTI_FINGER_SWIPE), |
| 921 | WithPointerCount(2u))), |
| 922 | VariantWith<NotifyMotionArgs>( |
| 923 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 924 | WithGestureOffset(0, 0, EPSILON), |
| 925 | WithMotionClassification( |
| 926 | MotionClassification::MULTI_FINGER_SWIPE), |
| 927 | WithPointerCount(1u))), |
| 928 | VariantWith<NotifyMotionArgs>( |
| 929 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 930 | WithMotionClassification(MotionClassification::NONE))))); |
| 931 | ASSERT_THAT(args, |
| 932 | Each(VariantWith<NotifyMotionArgs>( |
| 933 | AllOf(WithToolType(ToolType::FINGER), |
| 934 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
| 935 | |
| 936 | // Further movement in the same swipe should be ignored. |
| 937 | Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 938 | /*dy=*/5); |
| 939 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); |
| 940 | ASSERT_THAT(args, IsEmpty()); |
| 941 | Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); |
| 942 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture); |
| 943 | ASSERT_THAT(args, IsEmpty()); |
| 944 | |
| 945 | // But single-finger pointer motion should be reported. |
| 946 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
| 947 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
| 948 | ASSERT_THAT(args, |
| 949 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 950 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), |
| 951 | WithRelativeMotion(-5, 10), WithButtonState(0))))); |
| 952 | } |
| 953 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 954 | TEST_F(GestureConverterTest, Pinch_Inwards) { |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 955 | input_flags::enable_touchpad_no_focus_change(true); |
| 956 | |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 957 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 958 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 959 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 960 | |
| 961 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 962 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 963 | std::list<NotifyArgs> args = |
| 964 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 965 | ASSERT_THAT(args, |
| 966 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 967 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 968 | WithCoords(-100, 0), WithPointerCount(1u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 969 | VariantWith<NotifyMotionArgs>( |
| 970 | AllOf(WithMotionAction( |
| 971 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 972 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 973 | WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 974 | ASSERT_THAT(args, |
| 975 | Each(VariantWith<NotifyMotionArgs>( |
| 976 | AllOf(WithMotionClassification(MotionClassification::PINCH), |
| 977 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 978 | WithToolType(ToolType::FINGER), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 979 | WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 980 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 981 | |
| 982 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 983 | /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 984 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 985 | ASSERT_THAT(args, |
| 986 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 987 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 988 | WithMotionClassification(MotionClassification::PINCH), |
| 989 | WithGesturePinchScaleFactor(0.8f, EPSILON), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 990 | WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 991 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 992 | WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 993 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 994 | |
| 995 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 996 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 997 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 998 | ASSERT_THAT(args, |
| 999 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1000 | AllOf(WithMotionAction( |
| 1001 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1002 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1003 | WithMotionClassification(MotionClassification::PINCH), |
| 1004 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1005 | WithPointerCount(2u), |
| 1006 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1007 | VariantWith<NotifyMotionArgs>( |
| 1008 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1009 | WithMotionClassification(MotionClassification::PINCH), |
| 1010 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1011 | WithPointerCount(1u), |
| 1012 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1013 | VariantWith<NotifyMotionArgs>( |
| 1014 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1015 | WithCoords(0, 0), |
| 1016 | WithMotionClassification(MotionClassification::NONE))))); |
| 1017 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1018 | Each(VariantWith<NotifyMotionArgs>( |
| 1019 | AllOf(WithToolType(ToolType::FINGER), |
| 1020 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | TEST_F(GestureConverterTest, Pinch_Outwards) { |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1024 | input_flags::enable_touchpad_no_focus_change(true); |
| 1025 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1026 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1027 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1028 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1029 | |
| 1030 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 1031 | GESTURES_ZOOM_START); |
| 1032 | std::list<NotifyArgs> args = |
| 1033 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
| 1034 | ASSERT_THAT(args, |
| 1035 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1036 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1037 | WithCoords(-100, 0), WithPointerCount(1u))), |
| 1038 | VariantWith<NotifyMotionArgs>( |
| 1039 | AllOf(WithMotionAction( |
| 1040 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 1041 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1042 | WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); |
| 1043 | ASSERT_THAT(args, |
| 1044 | Each(VariantWith<NotifyMotionArgs>( |
| 1045 | AllOf(WithMotionClassification(MotionClassification::PINCH), |
| 1046 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
| 1047 | WithToolType(ToolType::FINGER), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1048 | WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 1049 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1050 | |
| 1051 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1052 | /* dz= */ 1.1, GESTURES_ZOOM_UPDATE); |
| 1053 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
| 1054 | ASSERT_THAT(args, |
| 1055 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1056 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), |
| 1057 | WithMotionClassification(MotionClassification::PINCH), |
| 1058 | WithGesturePinchScaleFactor(1.1f, EPSILON), |
| 1059 | WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0), |
| 1060 | WithPointerCount(2u), WithToolType(ToolType::FINGER), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1061 | WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
| 1062 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))))); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1063 | |
| 1064 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, |
| 1065 | GESTURES_ZOOM_END); |
| 1066 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
| 1067 | ASSERT_THAT(args, |
| 1068 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1069 | AllOf(WithMotionAction( |
| 1070 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1071 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1072 | WithMotionClassification(MotionClassification::PINCH), |
| 1073 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1074 | WithPointerCount(2u), |
| 1075 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1076 | VariantWith<NotifyMotionArgs>( |
| 1077 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1078 | WithMotionClassification(MotionClassification::PINCH), |
| 1079 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1080 | WithPointerCount(1u), |
| 1081 | WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1082 | VariantWith<NotifyMotionArgs>( |
| 1083 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1084 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1085 | WithMotionClassification(MotionClassification::NONE))))); |
| 1086 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1087 | Each(VariantWith<NotifyMotionArgs>( |
| 1088 | AllOf(WithToolType(ToolType::FINGER), |
| 1089 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1092 | TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1093 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1094 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1095 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1096 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1097 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1098 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1099 | std::list<NotifyArgs> args = |
| 1100 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1101 | |
| 1102 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1103 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1104 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1105 | |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1106 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1107 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1108 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1109 | |
| 1110 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1111 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1112 | ASSERT_THAT(args, |
| 1113 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1114 | WithMotionClassification(MotionClassification::NONE)))); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) { |
| 1118 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1119 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1120 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1121 | |
| 1122 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1123 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1124 | std::list<NotifyArgs> args = |
| 1125 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1126 | |
| 1127 | Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1128 | /*dz=*/1.2, GESTURES_ZOOM_UPDATE); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1129 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1130 | |
| 1131 | Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1132 | GESTURES_ZOOM_END); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1133 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1134 | |
| 1135 | // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we |
| 1136 | // need to use another gesture type, like scroll. |
| 1137 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1, |
| 1138 | /*dy=*/0); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1139 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
Harry Cutts | a5f98c9 | 2023-05-17 15:05:44 +0000 | [diff] [blame] | 1140 | ASSERT_FALSE(args.empty()); |
| 1141 | EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON)); |
Harry Cutts | b1e8355 | 2022-12-20 11:02:26 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1144 | TEST_F(GestureConverterTest, ResetWithButtonPressed) { |
| 1145 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1146 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1147 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1148 | |
| 1149 | Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1150 | /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT, |
| 1151 | /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1152 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1153 | |
| 1154 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1155 | ASSERT_THAT(args, |
| 1156 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1157 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1158 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1159 | WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1160 | VariantWith<NotifyMotionArgs>( |
| 1161 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1162 | WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1163 | WithButtonState(0))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1164 | VariantWith<NotifyMotionArgs>( |
| 1165 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1166 | WithButtonState(0))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1167 | VariantWith<NotifyMotionArgs>( |
| 1168 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1169 | WithButtonState(0))))); |
| 1170 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1171 | Each(VariantWith<NotifyMotionArgs>( |
| 1172 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
| 1173 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | TEST_F(GestureConverterTest, ResetDuringScroll) { |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1177 | input_flags::enable_touchpad_no_focus_change(true); |
| 1178 | |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1179 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1180 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1181 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1182 | |
| 1183 | Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1184 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1185 | |
| 1186 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1187 | ASSERT_THAT(args, |
| 1188 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1189 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1190 | WithCoords(0, -10), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1191 | WithGestureScrollDistance(0, 0, EPSILON), |
| 1192 | WithMotionClassification( |
| 1193 | MotionClassification::TWO_FINGER_SWIPE), |
Hiroki Sato | dd62ddc | 2024-09-05 17:38:18 +0900 | [diff] [blame] | 1194 | WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE | |
| 1195 | AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1196 | VariantWith<NotifyMotionArgs>( |
| 1197 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1198 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1199 | WithMotionClassification(MotionClassification::NONE))))); |
| 1200 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1201 | Each(VariantWith<NotifyMotionArgs>( |
| 1202 | AllOf(WithToolType(ToolType::FINGER), |
| 1203 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { |
| 1207 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1208 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1209 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1210 | |
| 1211 | Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0, |
| 1212 | /*dy=*/10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1213 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1214 | |
| 1215 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1216 | ASSERT_THAT(args, |
| 1217 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1218 | AllOf(WithMotionAction( |
| 1219 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1220 | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1221 | WithGestureOffset(0, 0, EPSILON), |
| 1222 | WithMotionClassification( |
| 1223 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1224 | WithPointerCount(3u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1225 | VariantWith<NotifyMotionArgs>( |
| 1226 | AllOf(WithMotionAction( |
| 1227 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1228 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1229 | WithGestureOffset(0, 0, EPSILON), |
| 1230 | WithMotionClassification( |
| 1231 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1232 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1233 | VariantWith<NotifyMotionArgs>( |
| 1234 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1235 | WithGestureOffset(0, 0, EPSILON), |
| 1236 | WithMotionClassification( |
| 1237 | MotionClassification::MULTI_FINGER_SWIPE), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1238 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1239 | VariantWith<NotifyMotionArgs>( |
| 1240 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1241 | WithMotionClassification(MotionClassification::NONE))))); |
| 1242 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1243 | Each(VariantWith<NotifyMotionArgs>( |
| 1244 | AllOf(WithToolType(ToolType::FINGER), |
| 1245 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | TEST_F(GestureConverterTest, ResetDuringPinch) { |
| 1249 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1250 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1251 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1252 | |
| 1253 | Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1, |
| 1254 | GESTURES_ZOOM_START); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1255 | (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1256 | |
| 1257 | std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1258 | ASSERT_THAT(args, |
| 1259 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1260 | AllOf(WithMotionAction( |
| 1261 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 1262 | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 1263 | WithMotionClassification(MotionClassification::PINCH), |
| 1264 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1265 | WithPointerCount(2u))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1266 | VariantWith<NotifyMotionArgs>( |
| 1267 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1268 | WithMotionClassification(MotionClassification::PINCH), |
| 1269 | WithGesturePinchScaleFactor(1.0f, EPSILON), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1270 | WithPointerCount(1u))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1271 | VariantWith<NotifyMotionArgs>( |
| 1272 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1273 | WithCoords(0, 0), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1274 | WithMotionClassification(MotionClassification::NONE))))); |
| 1275 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1276 | Each(VariantWith<NotifyMotionArgs>( |
| 1277 | AllOf(WithToolType(ToolType::FINGER), |
| 1278 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Harry Cutts | e9b7142 | 2023-03-14 16:54:44 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1281 | TEST_F(GestureConverterTest, FlingTapDown) { |
| 1282 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1283 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1284 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1285 | |
| 1286 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1287 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1288 | std::list<NotifyArgs> args = |
| 1289 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1290 | |
| 1291 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1292 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), |
| 1293 | WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1294 | WithButtonState(0), WithPressure(0.0f), |
| 1295 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))); |
Prabir Pradhan | f7c4b0e | 2023-05-10 21:25:16 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1298 | TEST_F(GestureConverterTest, FlingTapDownAfterScrollStopsFling) { |
| 1299 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1300 | input_flags::enable_touchpad_fling_stop(true); |
| 1301 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1302 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1303 | |
| 1304 | Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10); |
| 1305 | std::list<NotifyArgs> args = |
| 1306 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture); |
| 1307 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, |
| 1308 | GESTURES_FLING_START); |
| 1309 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
| 1310 | |
| 1311 | Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1312 | /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN); |
| 1313 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture); |
| 1314 | ASSERT_THAT(args, |
| 1315 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1316 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)), |
| 1317 | VariantWith<NotifyMotionArgs>( |
| 1318 | WithMotionAction(AMOTION_EVENT_ACTION_DOWN)), |
| 1319 | VariantWith<NotifyMotionArgs>( |
| 1320 | WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)), |
| 1321 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 574781a | 2024-04-23 15:30:45 +0000 | [diff] [blame] | 1322 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1323 | ASSERT_THAT(args, |
Harry Cutts | 574781a | 2024-04-23 15:30:45 +0000 | [diff] [blame] | 1324 | Each(VariantWith<NotifyMotionArgs>( |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1325 | AllOf(WithCoords(0, 0), WithToolType(ToolType::FINGER), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1326 | WithDisplayId(ui::LogicalDisplayId::DEFAULT), |
Harry Cutts | 574781a | 2024-04-23 15:30:45 +0000 | [diff] [blame] | 1327 | WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE))))); |
Harry Cutts | 39648ab | 2024-02-15 14:23:50 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1330 | TEST_F(GestureConverterTest, Tap) { |
| 1331 | // Tap should produce button press/release events |
| 1332 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1333 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1334 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1335 | |
| 1336 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1337 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1338 | std::list<NotifyArgs> args = |
| 1339 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1340 | // 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] | 1341 | |
| 1342 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1343 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1344 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1345 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1346 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1347 | ASSERT_THAT(args, |
| 1348 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1349 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1350 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1351 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1352 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1353 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1354 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1355 | VariantWith<NotifyMotionArgs>( |
| 1356 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1357 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1358 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1359 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1360 | VariantWith<NotifyMotionArgs>( |
| 1361 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1362 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1363 | WithButtonState(0), WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1364 | VariantWith<NotifyMotionArgs>( |
| 1365 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1366 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1367 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1368 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1369 | WithButtonState(0), WithPressure(0.0f))))); |
| 1370 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1371 | Each(VariantWith<NotifyMotionArgs>( |
| 1372 | AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1373 | WithToolType(ToolType::FINGER), |
| 1374 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Harry Cutts | 2a0210e | 2024-10-18 19:12:59 +0000 | [diff] [blame] | 1377 | TEST_F(GestureConverterTest, ThreeFingerTap_TriggersShortcut) { |
| 1378 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1379 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
| 1380 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
| 1381 | converter.setThreeFingerTapShortcutEnabled(true); |
| 1382 | |
| 1383 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*vx=*/0, |
| 1384 | /*vy=*/0, GESTURES_FLING_TAP_DOWN); |
| 1385 | std::list<NotifyArgs> args = |
| 1386 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
| 1387 | // We don't need to check args here, since it's covered by the FlingTapDown test. |
| 1388 | |
| 1389 | Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1390 | /*down=*/GESTURES_BUTTON_MIDDLE, /*up=*/GESTURES_BUTTON_MIDDLE, |
| 1391 | /*is_tap=*/true); |
| 1392 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture); |
| 1393 | |
| 1394 | ASSERT_TRUE(args.empty()); |
| 1395 | mFakePolicy->assertTouchpadThreeFingerTapNotified(); |
| 1396 | } |
| 1397 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1398 | TEST_F(GestureConverterTest, Click) { |
| 1399 | // Click should produce button press/release events |
| 1400 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1401 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1402 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1403 | |
| 1404 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1405 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1406 | std::list<NotifyArgs> args = |
| 1407 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1408 | // 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] | 1409 | |
| 1410 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1411 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1412 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1413 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1414 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1415 | ASSERT_THAT(args, |
| 1416 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1417 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1418 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1419 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1420 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1421 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1422 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1423 | VariantWith<NotifyMotionArgs>( |
| 1424 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1425 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1426 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1427 | WithPressure(1.0f))))); |
| 1428 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1429 | Each(VariantWith<NotifyMotionArgs>( |
| 1430 | AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1431 | WithToolType(ToolType::FINGER), |
| 1432 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1433 | |
| 1434 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1435 | /* down= */ GESTURES_BUTTON_NONE, |
| 1436 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1437 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1438 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1439 | ASSERT_THAT(args, |
| 1440 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1441 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1442 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1443 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1444 | VariantWith<NotifyMotionArgs>( |
| 1445 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1446 | WithPressure(0.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1447 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1448 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1449 | WithPressure(0.0f))))); |
| 1450 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1451 | Each(VariantWith<NotifyMotionArgs>( |
| 1452 | AllOf(WithButtonState(0), WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1453 | WithToolType(ToolType::FINGER), |
| 1454 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1457 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1458 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION), |
| 1459 | REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1460 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1461 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1462 | // Tap should be ignored when disabled |
| 1463 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1464 | |
| 1465 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1466 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1467 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1468 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1469 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1470 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1471 | std::list<NotifyArgs> args = |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1472 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1473 | // 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] | 1474 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1475 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1476 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1477 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1478 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1479 | |
| 1480 | // no events should be generated |
| 1481 | ASSERT_EQ(0u, args.size()); |
| 1482 | |
| 1483 | // Future taps should be re-enabled |
| 1484 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1485 | } |
| 1486 | |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1487 | TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay, |
| 1488 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1489 | nsecs_t currentTime = ARBITRARY_GESTURE_TIME; |
| 1490 | |
| 1491 | // Tap should be ignored when disabled |
| 1492 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1493 | |
| 1494 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1495 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1496 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1497 | |
| 1498 | Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1499 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1500 | std::list<NotifyArgs> args = |
| 1501 | converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1502 | // 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] | 1503 | |
| 1504 | Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime, |
| 1505 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1506 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1507 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1508 | |
| 1509 | // no events should be generated |
| 1510 | ASSERT_EQ(0u, args.size()); |
| 1511 | |
| 1512 | // Future taps should be re-enabled |
| 1513 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1514 | |
| 1515 | // taps before the threshold should still be ignored |
| 1516 | currentTime += TAP_ENABLE_DELAY_NANOS.count(); |
| 1517 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1518 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1519 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1520 | |
| 1521 | ASSERT_EQ(1u, args.size()); |
| 1522 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1523 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1524 | |
| 1525 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1526 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1527 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1528 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
| 1529 | |
| 1530 | // no events should be generated |
| 1531 | ASSERT_EQ(0u, args.size()); |
| 1532 | |
| 1533 | // taps after the threshold should be recognised |
| 1534 | currentTime += 1; |
| 1535 | flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0, |
| 1536 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
| 1537 | args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture); |
| 1538 | |
| 1539 | ASSERT_EQ(1u, args.size()); |
| 1540 | ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), |
| 1541 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0))); |
| 1542 | |
| 1543 | tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime, |
| 1544 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1545 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); |
| 1546 | args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1547 | ASSERT_THAT(args, |
| 1548 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1549 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
| 1550 | WithButtonState(0))), |
| 1551 | VariantWith<NotifyMotionArgs>( |
| 1552 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
| 1553 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 1554 | VariantWith<NotifyMotionArgs>( |
| 1555 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1556 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1557 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), |
| 1558 | VariantWith<NotifyMotionArgs>( |
| 1559 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1560 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1561 | WithButtonState(0))), |
| 1562 | VariantWith<NotifyMotionArgs>( |
| 1563 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1564 | WithButtonState(0))), |
| 1565 | VariantWith<NotifyMotionArgs>( |
| 1566 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
| 1567 | WithButtonState(0))))); |
| 1568 | ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f)))); |
Arpit Singh | 82b27a0 | 2023-10-16 11:02:19 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
Arpit Singh | 3d84add | 2023-10-10 19:08:29 +0000 | [diff] [blame] | 1571 | TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, |
| 1572 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1573 | // Click should still produce button press/release events |
| 1574 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1575 | |
| 1576 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1577 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1578 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1579 | |
| 1580 | Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0, |
| 1581 | /* vy= */ 0, GESTURES_FLING_TAP_DOWN); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1582 | std::list<NotifyArgs> args = |
| 1583 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1584 | // 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] | 1585 | |
| 1586 | Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1587 | /* down= */ GESTURES_BUTTON_LEFT, |
| 1588 | /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1589 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1590 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1591 | ASSERT_THAT(args, |
| 1592 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1593 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1594 | WithButtonState(0), WithPressure(0.0f))), |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1595 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1596 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1597 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1598 | WithPressure(1.0f))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1599 | VariantWith<NotifyMotionArgs>( |
| 1600 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), |
| 1601 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1602 | WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), |
Harry Cutts | ef95e71 | 2024-02-16 18:56:39 +0000 | [diff] [blame] | 1603 | WithPressure(1.0f))))); |
| 1604 | ASSERT_THAT(args, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1605 | Each(VariantWith<NotifyMotionArgs>( |
| 1606 | AllOf(WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1607 | WithToolType(ToolType::FINGER), |
| 1608 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1609 | |
| 1610 | Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, |
| 1611 | /* down= */ GESTURES_BUTTON_NONE, |
| 1612 | /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1613 | args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1614 | |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1615 | ASSERT_THAT(args, |
| 1616 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1617 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), |
| 1618 | WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), |
| 1619 | WithButtonState(0), WithCoords(0, 0), |
| 1620 | WithRelativeMotion(0.f, 0.f), |
| 1621 | WithToolType(ToolType::FINGER), WithButtonState(0), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1622 | WithPressure(1.0f), |
| 1623 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1624 | VariantWith<NotifyMotionArgs>( |
| 1625 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), |
| 1626 | WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), |
| 1627 | WithToolType(ToolType::FINGER), WithButtonState(0), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1628 | WithPressure(0.0f), |
| 1629 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1630 | VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1631 | AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1632 | WithCoords(0, 0), WithRelativeMotion(0, 0), |
| 1633 | WithToolType(ToolType::FINGER), WithButtonState(0), |
| 1634 | WithPressure(0.0f), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1635 | WithDisplayId(ui::LogicalDisplayId::DEFAULT))))); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1636 | |
| 1637 | // Future taps should be re-enabled |
| 1638 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1639 | } |
| 1640 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1641 | TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick, |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1642 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) { |
| 1643 | // initially disable tap-to-click |
| 1644 | mReader->getContext()->setPreventingTouchpadTaps(true); |
| 1645 | |
| 1646 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1647 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1648 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Byoungho Jung | ee6268f | 2023-10-30 17:27:26 +0900 | [diff] [blame] | 1649 | |
| 1650 | Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1651 | std::list<NotifyArgs> args = |
| 1652 | converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1653 | // 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] | 1654 | |
| 1655 | // Future taps should be re-enabled |
| 1656 | ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); |
| 1657 | } |
| 1658 | |
Prabir Pradhan | 8b05351 | 2024-05-03 23:15:39 +0000 | [diff] [blame] | 1659 | TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove, |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1660 | REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) { |
| 1661 | const nsecs_t gestureStartTime = 1000; |
| 1662 | InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); |
| 1663 | GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 1664 | converter.setDisplayId(ui::LogicalDisplayId::DEFAULT); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1665 | |
| 1666 | // Start a move gesture at gestureStartTime |
| 1667 | Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10); |
| 1668 | std::list<NotifyArgs> args = |
| 1669 | converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1670 | ASSERT_THAT(args, |
| 1671 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1672 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1673 | VariantWith<NotifyMotionArgs>( |
| 1674 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1675 | |
| 1676 | // Key presses with IME connection should cancel ongoing move gesture |
| 1677 | nsecs_t currentTime = gestureStartTime + 100; |
| 1678 | mFakePolicy->setIsInputMethodConnectionActive(true); |
| 1679 | mReader->getContext()->setLastKeyDownTimestamp(currentTime); |
| 1680 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1681 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1682 | ASSERT_THAT(args, |
| 1683 | ElementsAre(VariantWith<NotifyMotionArgs>( |
| 1684 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1685 | |
| 1686 | // any updates in existing move gesture should be ignored |
| 1687 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1688 | args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture); |
| 1689 | ASSERT_EQ(0u, args.size()); |
| 1690 | |
| 1691 | // New gesture should not be affected |
| 1692 | currentTime += 100; |
| 1693 | moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10); |
| 1694 | args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture); |
Harry Cutts | 5f26e95 | 2023-11-30 18:20:27 +0000 | [diff] [blame] | 1695 | ASSERT_THAT(args, |
| 1696 | ElementsAre(VariantWith<NotifyMotionArgs>( |
Harry Cutts | 379ea42 | 2023-12-21 15:31:47 +0000 | [diff] [blame] | 1697 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)), |
| 1698 | VariantWith<NotifyMotionArgs>( |
| 1699 | WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE)))); |
Arpit Singh | 33a10a6 | 2023-10-12 13:06:54 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Harry Cutts | 4fb941a | 2022-12-14 19:14:04 +0000 | [diff] [blame] | 1702 | } // namespace android |