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