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