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