| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 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 "../InputReader.h" | 
|  | 18 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 19 | #include <inttypes.h> | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 20 | #include <utils/List.h> | 
|  | 21 | #include <gtest/gtest.h> | 
|  | 22 | #include <math.h> | 
|  | 23 |  | 
|  | 24 | namespace android { | 
|  | 25 |  | 
|  | 26 | // An arbitrary time value. | 
|  | 27 | static const nsecs_t ARBITRARY_TIME = 1234; | 
|  | 28 |  | 
|  | 29 | // Arbitrary display properties. | 
|  | 30 | static const int32_t DISPLAY_ID = 0; | 
|  | 31 | static const int32_t DISPLAY_WIDTH = 480; | 
|  | 32 | static const int32_t DISPLAY_HEIGHT = 800; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 33 | static const int32_t VIRTUAL_DISPLAY_ID = 1; | 
|  | 34 | static const int32_t VIRTUAL_DISPLAY_WIDTH = 400; | 
|  | 35 | static const int32_t VIRTUAL_DISPLAY_HEIGHT = 500; | 
|  | 36 | static const char* VIRTUAL_DISPLAY_UNIQUE_ID = "Vr-display-unique-ID"; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 37 |  | 
|  | 38 | // Error tolerance for floating point assertions. | 
|  | 39 | static const float EPSILON = 0.001f; | 
|  | 40 |  | 
|  | 41 | template<typename T> | 
|  | 42 | static inline T min(T a, T b) { | 
|  | 43 | return a < b ? a : b; | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | static inline float avg(float x, float y) { | 
|  | 47 | return (x + y) / 2; | 
|  | 48 | } | 
|  | 49 |  | 
|  | 50 |  | 
|  | 51 | // --- FakePointerController --- | 
|  | 52 |  | 
|  | 53 | class FakePointerController : public PointerControllerInterface { | 
|  | 54 | bool mHaveBounds; | 
|  | 55 | float mMinX, mMinY, mMaxX, mMaxY; | 
|  | 56 | float mX, mY; | 
|  | 57 | int32_t mButtonState; | 
|  | 58 |  | 
|  | 59 | protected: | 
|  | 60 | virtual ~FakePointerController() { } | 
|  | 61 |  | 
|  | 62 | public: | 
|  | 63 | FakePointerController() : | 
|  | 64 | mHaveBounds(false), mMinX(0), mMinY(0), mMaxX(0), mMaxY(0), mX(0), mY(0), | 
|  | 65 | mButtonState(0) { | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | void setBounds(float minX, float minY, float maxX, float maxY) { | 
|  | 69 | mHaveBounds = true; | 
|  | 70 | mMinX = minX; | 
|  | 71 | mMinY = minY; | 
|  | 72 | mMaxX = maxX; | 
|  | 73 | mMaxY = maxY; | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | virtual void setPosition(float x, float y) { | 
|  | 77 | mX = x; | 
|  | 78 | mY = y; | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | virtual void setButtonState(int32_t buttonState) { | 
|  | 82 | mButtonState = buttonState; | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | virtual int32_t getButtonState() const { | 
|  | 86 | return mButtonState; | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | virtual void getPosition(float* outX, float* outY) const { | 
|  | 90 | *outX = mX; | 
|  | 91 | *outY = mY; | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | private: | 
|  | 95 | virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const { | 
|  | 96 | *outMinX = mMinX; | 
|  | 97 | *outMinY = mMinY; | 
|  | 98 | *outMaxX = mMaxX; | 
|  | 99 | *outMaxY = mMaxY; | 
|  | 100 | return mHaveBounds; | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | virtual void move(float deltaX, float deltaY) { | 
|  | 104 | mX += deltaX; | 
|  | 105 | if (mX < mMinX) mX = mMinX; | 
|  | 106 | if (mX > mMaxX) mX = mMaxX; | 
|  | 107 | mY += deltaY; | 
|  | 108 | if (mY < mMinY) mY = mMinY; | 
|  | 109 | if (mY > mMaxY) mY = mMaxY; | 
|  | 110 | } | 
|  | 111 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 112 | virtual void fade(Transition) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 113 | } | 
|  | 114 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 115 | virtual void unfade(Transition) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 116 | } | 
|  | 117 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 118 | virtual void setPresentation(Presentation) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 119 | } | 
|  | 120 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 121 | virtual void setSpots(const PointerCoords*, const uint32_t*, BitSet32) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 122 | } | 
|  | 123 |  | 
|  | 124 | virtual void clearSpots() { | 
|  | 125 | } | 
|  | 126 | }; | 
|  | 127 |  | 
|  | 128 |  | 
|  | 129 | // --- FakeInputReaderPolicy --- | 
|  | 130 |  | 
|  | 131 | class FakeInputReaderPolicy : public InputReaderPolicyInterface { | 
|  | 132 | InputReaderConfiguration mConfig; | 
|  | 133 | KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers; | 
|  | 134 | Vector<InputDeviceInfo> mInputDevices; | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 135 | TouchAffineTransformation transform; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 136 |  | 
|  | 137 | protected: | 
|  | 138 | virtual ~FakeInputReaderPolicy() { } | 
|  | 139 |  | 
|  | 140 | public: | 
|  | 141 | FakeInputReaderPolicy() { | 
|  | 142 | } | 
|  | 143 |  | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 144 | void setDisplayViewport(int32_t displayId, int32_t width, int32_t height, int32_t orientation, | 
|  | 145 | const String8& uniqueId) { | 
|  | 146 | DisplayViewport v = createDisplayViewport(displayId, width, height, orientation, uniqueId); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 147 | // Set the size of both the internal and external display at the same time. | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 148 | mConfig.setPhysicalDisplayViewport(ViewportType::VIEWPORT_INTERNAL, v); | 
|  | 149 | mConfig.setPhysicalDisplayViewport(ViewportType::VIEWPORT_EXTERNAL, v); | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | void setVirtualDisplayViewport(int32_t displayId, int32_t width, int32_t height, int32_t orientation, | 
|  | 153 | const String8& uniqueId) { | 
|  | 154 | Vector<DisplayViewport> viewports; | 
|  | 155 | viewports.push_back(createDisplayViewport(displayId, width, height, orientation, uniqueId)); | 
|  | 156 | mConfig.setVirtualDisplayViewports(viewports); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 157 | } | 
|  | 158 |  | 
|  | 159 | void addExcludedDeviceName(const String8& deviceName) { | 
|  | 160 | mConfig.excludedDeviceNames.push(deviceName); | 
|  | 161 | } | 
|  | 162 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 163 | void addDisabledDevice(int32_t deviceId) { | 
|  | 164 | ssize_t index = mConfig.disabledDevices.indexOf(deviceId); | 
|  | 165 | bool currentlyEnabled = index < 0; | 
|  | 166 | if (currentlyEnabled) { | 
|  | 167 | mConfig.disabledDevices.add(deviceId); | 
|  | 168 | } | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | void removeDisabledDevice(int32_t deviceId) { | 
|  | 172 | ssize_t index = mConfig.disabledDevices.indexOf(deviceId); | 
|  | 173 | bool currentlyEnabled = index < 0; | 
|  | 174 | if (!currentlyEnabled) { | 
|  | 175 | mConfig.disabledDevices.remove(deviceId); | 
|  | 176 | } | 
|  | 177 | } | 
|  | 178 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 179 | void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) { | 
|  | 180 | mPointerControllers.add(deviceId, controller); | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | const InputReaderConfiguration* getReaderConfiguration() const { | 
|  | 184 | return &mConfig; | 
|  | 185 | } | 
|  | 186 |  | 
|  | 187 | const Vector<InputDeviceInfo>& getInputDevices() const { | 
|  | 188 | return mInputDevices; | 
|  | 189 | } | 
|  | 190 |  | 
| Jason Gerecke | 71b16e8 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 191 | TouchAffineTransformation getTouchAffineTransformation(const String8& inputDeviceDescriptor, | 
|  | 192 | int32_t surfaceRotation) { | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 193 | return transform; | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | void setTouchAffineTransformation(const TouchAffineTransformation t) { | 
|  | 197 | transform = t; | 
| Jason Gerecke | 12d6baa | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 198 | } | 
|  | 199 |  | 
| Vladislav Kaznacheev | 78f97b3 | 2016-12-15 18:14:58 -0800 | [diff] [blame] | 200 | void setPointerCapture(bool enabled) { | 
|  | 201 | mConfig.pointerCapture = enabled; | 
|  | 202 | } | 
|  | 203 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 204 | private: | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 205 | DisplayViewport createDisplayViewport(int32_t displayId, int32_t width, int32_t height, | 
|  | 206 | int32_t orientation, const String8& uniqueId) { | 
|  | 207 | bool isRotated = (orientation == DISPLAY_ORIENTATION_90 | 
|  | 208 | || orientation == DISPLAY_ORIENTATION_270); | 
|  | 209 | DisplayViewport v; | 
|  | 210 | v.displayId = displayId; | 
|  | 211 | v.orientation = orientation; | 
|  | 212 | v.logicalLeft = 0; | 
|  | 213 | v.logicalTop = 0; | 
|  | 214 | v.logicalRight = isRotated ? height : width; | 
|  | 215 | v.logicalBottom = isRotated ? width : height; | 
|  | 216 | v.physicalLeft = 0; | 
|  | 217 | v.physicalTop = 0; | 
|  | 218 | v.physicalRight = isRotated ? height : width; | 
|  | 219 | v.physicalBottom = isRotated ? width : height; | 
|  | 220 | v.deviceWidth = isRotated ? height : width; | 
|  | 221 | v.deviceHeight = isRotated ? width : height; | 
|  | 222 | v.uniqueId = uniqueId; | 
|  | 223 | return v; | 
|  | 224 | } | 
|  | 225 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 226 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) { | 
|  | 227 | *outConfig = mConfig; | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) { | 
|  | 231 | return mPointerControllers.valueFor(deviceId); | 
|  | 232 | } | 
|  | 233 |  | 
|  | 234 | virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) { | 
|  | 235 | mInputDevices = inputDevices; | 
|  | 236 | } | 
|  | 237 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 238 | virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier&) { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 239 | return nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 240 | } | 
|  | 241 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 242 | virtual String8 getDeviceAlias(const InputDeviceIdentifier&) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 243 | return String8::empty(); | 
|  | 244 | } | 
|  | 245 | }; | 
|  | 246 |  | 
|  | 247 |  | 
|  | 248 | // --- FakeInputListener --- | 
|  | 249 |  | 
|  | 250 | class FakeInputListener : public InputListenerInterface { | 
|  | 251 | private: | 
|  | 252 | List<NotifyConfigurationChangedArgs> mNotifyConfigurationChangedArgsQueue; | 
|  | 253 | List<NotifyDeviceResetArgs> mNotifyDeviceResetArgsQueue; | 
|  | 254 | List<NotifyKeyArgs> mNotifyKeyArgsQueue; | 
|  | 255 | List<NotifyMotionArgs> mNotifyMotionArgsQueue; | 
|  | 256 | List<NotifySwitchArgs> mNotifySwitchArgsQueue; | 
|  | 257 |  | 
|  | 258 | protected: | 
|  | 259 | virtual ~FakeInputListener() { } | 
|  | 260 |  | 
|  | 261 | public: | 
|  | 262 | FakeInputListener() { | 
|  | 263 | } | 
|  | 264 |  | 
|  | 265 | void assertNotifyConfigurationChangedWasCalled( | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 266 | NotifyConfigurationChangedArgs* outEventArgs = nullptr) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 267 | ASSERT_FALSE(mNotifyConfigurationChangedArgsQueue.empty()) | 
|  | 268 | << "Expected notifyConfigurationChanged() to have been called."; | 
|  | 269 | if (outEventArgs) { | 
|  | 270 | *outEventArgs = *mNotifyConfigurationChangedArgsQueue.begin(); | 
|  | 271 | } | 
|  | 272 | mNotifyConfigurationChangedArgsQueue.erase(mNotifyConfigurationChangedArgsQueue.begin()); | 
|  | 273 | } | 
|  | 274 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 275 | void assertNotifyConfigurationChangedWasNotCalled() { | 
|  | 276 | ASSERT_TRUE(mNotifyConfigurationChangedArgsQueue.empty()) | 
|  | 277 | << "Expected notifyConfigurationChanged() to not have been called."; | 
|  | 278 | } | 
|  | 279 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 280 | void assertNotifyDeviceResetWasCalled( | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 281 | NotifyDeviceResetArgs* outEventArgs = nullptr) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 282 | ASSERT_FALSE(mNotifyDeviceResetArgsQueue.empty()) | 
|  | 283 | << "Expected notifyDeviceReset() to have been called."; | 
|  | 284 | if (outEventArgs) { | 
|  | 285 | *outEventArgs = *mNotifyDeviceResetArgsQueue.begin(); | 
|  | 286 | } | 
|  | 287 | mNotifyDeviceResetArgsQueue.erase(mNotifyDeviceResetArgsQueue.begin()); | 
|  | 288 | } | 
|  | 289 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 290 | void assertNotifyDeviceResetWasNotCalled() { | 
|  | 291 | ASSERT_TRUE(mNotifyDeviceResetArgsQueue.empty()) | 
|  | 292 | << "Expected notifyDeviceReset() to not have been called."; | 
|  | 293 | } | 
|  | 294 |  | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 295 | void assertNotifyKeyWasCalled(NotifyKeyArgs* outEventArgs = nullptr) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 296 | ASSERT_FALSE(mNotifyKeyArgsQueue.empty()) | 
|  | 297 | << "Expected notifyKey() to have been called."; | 
|  | 298 | if (outEventArgs) { | 
|  | 299 | *outEventArgs = *mNotifyKeyArgsQueue.begin(); | 
|  | 300 | } | 
|  | 301 | mNotifyKeyArgsQueue.erase(mNotifyKeyArgsQueue.begin()); | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | void assertNotifyKeyWasNotCalled() { | 
|  | 305 | ASSERT_TRUE(mNotifyKeyArgsQueue.empty()) | 
|  | 306 | << "Expected notifyKey() to not have been called."; | 
|  | 307 | } | 
|  | 308 |  | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 309 | void assertNotifyMotionWasCalled(NotifyMotionArgs* outEventArgs = nullptr) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 310 | ASSERT_FALSE(mNotifyMotionArgsQueue.empty()) | 
|  | 311 | << "Expected notifyMotion() to have been called."; | 
|  | 312 | if (outEventArgs) { | 
|  | 313 | *outEventArgs = *mNotifyMotionArgsQueue.begin(); | 
|  | 314 | } | 
|  | 315 | mNotifyMotionArgsQueue.erase(mNotifyMotionArgsQueue.begin()); | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | void assertNotifyMotionWasNotCalled() { | 
|  | 319 | ASSERT_TRUE(mNotifyMotionArgsQueue.empty()) | 
|  | 320 | << "Expected notifyMotion() to not have been called."; | 
|  | 321 | } | 
|  | 322 |  | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 323 | void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = nullptr) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 324 | ASSERT_FALSE(mNotifySwitchArgsQueue.empty()) | 
|  | 325 | << "Expected notifySwitch() to have been called."; | 
|  | 326 | if (outEventArgs) { | 
|  | 327 | *outEventArgs = *mNotifySwitchArgsQueue.begin(); | 
|  | 328 | } | 
|  | 329 | mNotifySwitchArgsQueue.erase(mNotifySwitchArgsQueue.begin()); | 
|  | 330 | } | 
|  | 331 |  | 
|  | 332 | private: | 
|  | 333 | virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { | 
|  | 334 | mNotifyConfigurationChangedArgsQueue.push_back(*args); | 
|  | 335 | } | 
|  | 336 |  | 
|  | 337 | virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) { | 
|  | 338 | mNotifyDeviceResetArgsQueue.push_back(*args); | 
|  | 339 | } | 
|  | 340 |  | 
|  | 341 | virtual void notifyKey(const NotifyKeyArgs* args) { | 
|  | 342 | mNotifyKeyArgsQueue.push_back(*args); | 
|  | 343 | } | 
|  | 344 |  | 
|  | 345 | virtual void notifyMotion(const NotifyMotionArgs* args) { | 
|  | 346 | mNotifyMotionArgsQueue.push_back(*args); | 
|  | 347 | } | 
|  | 348 |  | 
|  | 349 | virtual void notifySwitch(const NotifySwitchArgs* args) { | 
|  | 350 | mNotifySwitchArgsQueue.push_back(*args); | 
|  | 351 | } | 
|  | 352 | }; | 
|  | 353 |  | 
|  | 354 |  | 
|  | 355 | // --- FakeEventHub --- | 
|  | 356 |  | 
|  | 357 | class FakeEventHub : public EventHubInterface { | 
|  | 358 | struct KeyInfo { | 
|  | 359 | int32_t keyCode; | 
|  | 360 | uint32_t flags; | 
|  | 361 | }; | 
|  | 362 |  | 
|  | 363 | struct Device { | 
|  | 364 | InputDeviceIdentifier identifier; | 
|  | 365 | uint32_t classes; | 
|  | 366 | PropertyMap configuration; | 
|  | 367 | KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes; | 
|  | 368 | KeyedVector<int, bool> relativeAxes; | 
|  | 369 | KeyedVector<int32_t, int32_t> keyCodeStates; | 
|  | 370 | KeyedVector<int32_t, int32_t> scanCodeStates; | 
|  | 371 | KeyedVector<int32_t, int32_t> switchStates; | 
|  | 372 | KeyedVector<int32_t, int32_t> absoluteAxisValue; | 
|  | 373 | KeyedVector<int32_t, KeyInfo> keysByScanCode; | 
|  | 374 | KeyedVector<int32_t, KeyInfo> keysByUsageCode; | 
|  | 375 | KeyedVector<int32_t, bool> leds; | 
|  | 376 | Vector<VirtualKeyDefinition> virtualKeys; | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 377 | bool enabled; | 
|  | 378 |  | 
|  | 379 | status_t enable() { | 
|  | 380 | enabled = true; | 
|  | 381 | return OK; | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | status_t disable() { | 
|  | 385 | enabled = false; | 
|  | 386 | return OK; | 
|  | 387 | } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 388 |  | 
| Chih-Hung Hsieh | 6ca70ef | 2016-04-29 16:23:55 -0700 | [diff] [blame] | 389 | explicit Device(uint32_t classes) : | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 390 | classes(classes), enabled(true) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 391 | } | 
|  | 392 | }; | 
|  | 393 |  | 
|  | 394 | KeyedVector<int32_t, Device*> mDevices; | 
|  | 395 | Vector<String8> mExcludedDevices; | 
|  | 396 | List<RawEvent> mEvents; | 
|  | 397 |  | 
|  | 398 | protected: | 
|  | 399 | virtual ~FakeEventHub() { | 
|  | 400 | for (size_t i = 0; i < mDevices.size(); i++) { | 
|  | 401 | delete mDevices.valueAt(i); | 
|  | 402 | } | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | public: | 
|  | 406 | FakeEventHub() { } | 
|  | 407 |  | 
|  | 408 | void addDevice(int32_t deviceId, const String8& name, uint32_t classes) { | 
|  | 409 | Device* device = new Device(classes); | 
|  | 410 | device->identifier.name = name; | 
|  | 411 | mDevices.add(deviceId, device); | 
|  | 412 |  | 
|  | 413 | enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0); | 
|  | 414 | } | 
|  | 415 |  | 
|  | 416 | void removeDevice(int32_t deviceId) { | 
|  | 417 | delete mDevices.valueFor(deviceId); | 
|  | 418 | mDevices.removeItem(deviceId); | 
|  | 419 |  | 
|  | 420 | enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0); | 
|  | 421 | } | 
|  | 422 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 423 | bool isDeviceEnabled(int32_t deviceId) { | 
|  | 424 | Device* device = getDevice(deviceId); | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 425 | if (device == nullptr) { | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 426 | ALOGE("Incorrect device id=%" PRId32 " provided to %s", deviceId, __func__); | 
|  | 427 | return false; | 
|  | 428 | } | 
|  | 429 | return device->enabled; | 
|  | 430 | } | 
|  | 431 |  | 
|  | 432 | status_t enableDevice(int32_t deviceId) { | 
|  | 433 | status_t result; | 
|  | 434 | Device* device = getDevice(deviceId); | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 435 | if (device == nullptr) { | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 436 | ALOGE("Incorrect device id=%" PRId32 " provided to %s", deviceId, __func__); | 
|  | 437 | return BAD_VALUE; | 
|  | 438 | } | 
|  | 439 | if (device->enabled) { | 
|  | 440 | ALOGW("Duplicate call to %s, device %" PRId32 " already enabled", __func__, deviceId); | 
|  | 441 | return OK; | 
|  | 442 | } | 
|  | 443 | result = device->enable(); | 
|  | 444 | return result; | 
|  | 445 | } | 
|  | 446 |  | 
|  | 447 | status_t disableDevice(int32_t deviceId) { | 
|  | 448 | Device* device = getDevice(deviceId); | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 449 | if (device == nullptr) { | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 450 | ALOGE("Incorrect device id=%" PRId32 " provided to %s", deviceId, __func__); | 
|  | 451 | return BAD_VALUE; | 
|  | 452 | } | 
|  | 453 | if (!device->enabled) { | 
|  | 454 | ALOGW("Duplicate call to %s, device %" PRId32 " already disabled", __func__, deviceId); | 
|  | 455 | return OK; | 
|  | 456 | } | 
|  | 457 | return device->disable(); | 
|  | 458 | } | 
|  | 459 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 460 | void finishDeviceScan() { | 
|  | 461 | enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0); | 
|  | 462 | } | 
|  | 463 |  | 
|  | 464 | void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) { | 
|  | 465 | Device* device = getDevice(deviceId); | 
|  | 466 | device->configuration.addProperty(key, value); | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | void addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) { | 
|  | 470 | Device* device = getDevice(deviceId); | 
|  | 471 | device->configuration.addAll(configuration); | 
|  | 472 | } | 
|  | 473 |  | 
|  | 474 | void addAbsoluteAxis(int32_t deviceId, int axis, | 
|  | 475 | int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution = 0) { | 
|  | 476 | Device* device = getDevice(deviceId); | 
|  | 477 |  | 
|  | 478 | RawAbsoluteAxisInfo info; | 
|  | 479 | info.valid = true; | 
|  | 480 | info.minValue = minValue; | 
|  | 481 | info.maxValue = maxValue; | 
|  | 482 | info.flat = flat; | 
|  | 483 | info.fuzz = fuzz; | 
|  | 484 | info.resolution = resolution; | 
|  | 485 | device->absoluteAxes.add(axis, info); | 
|  | 486 | } | 
|  | 487 |  | 
|  | 488 | void addRelativeAxis(int32_t deviceId, int32_t axis) { | 
|  | 489 | Device* device = getDevice(deviceId); | 
|  | 490 | device->relativeAxes.add(axis, true); | 
|  | 491 | } | 
|  | 492 |  | 
|  | 493 | void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) { | 
|  | 494 | Device* device = getDevice(deviceId); | 
|  | 495 | device->keyCodeStates.replaceValueFor(keyCode, state); | 
|  | 496 | } | 
|  | 497 |  | 
|  | 498 | void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) { | 
|  | 499 | Device* device = getDevice(deviceId); | 
|  | 500 | device->scanCodeStates.replaceValueFor(scanCode, state); | 
|  | 501 | } | 
|  | 502 |  | 
|  | 503 | void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) { | 
|  | 504 | Device* device = getDevice(deviceId); | 
|  | 505 | device->switchStates.replaceValueFor(switchCode, state); | 
|  | 506 | } | 
|  | 507 |  | 
|  | 508 | void setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) { | 
|  | 509 | Device* device = getDevice(deviceId); | 
|  | 510 | device->absoluteAxisValue.replaceValueFor(axis, value); | 
|  | 511 | } | 
|  | 512 |  | 
|  | 513 | void addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, | 
|  | 514 | int32_t keyCode, uint32_t flags) { | 
|  | 515 | Device* device = getDevice(deviceId); | 
|  | 516 | KeyInfo info; | 
|  | 517 | info.keyCode = keyCode; | 
|  | 518 | info.flags = flags; | 
|  | 519 | if (scanCode) { | 
|  | 520 | device->keysByScanCode.add(scanCode, info); | 
|  | 521 | } | 
|  | 522 | if (usageCode) { | 
|  | 523 | device->keysByUsageCode.add(usageCode, info); | 
|  | 524 | } | 
|  | 525 | } | 
|  | 526 |  | 
|  | 527 | void addLed(int32_t deviceId, int32_t led, bool initialState) { | 
|  | 528 | Device* device = getDevice(deviceId); | 
|  | 529 | device->leds.add(led, initialState); | 
|  | 530 | } | 
|  | 531 |  | 
|  | 532 | bool getLedState(int32_t deviceId, int32_t led) { | 
|  | 533 | Device* device = getDevice(deviceId); | 
|  | 534 | return device->leds.valueFor(led); | 
|  | 535 | } | 
|  | 536 |  | 
|  | 537 | Vector<String8>& getExcludedDevices() { | 
|  | 538 | return mExcludedDevices; | 
|  | 539 | } | 
|  | 540 |  | 
|  | 541 | void addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) { | 
|  | 542 | Device* device = getDevice(deviceId); | 
|  | 543 | device->virtualKeys.push(definition); | 
|  | 544 | } | 
|  | 545 |  | 
|  | 546 | void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type, | 
|  | 547 | int32_t code, int32_t value) { | 
|  | 548 | RawEvent event; | 
|  | 549 | event.when = when; | 
|  | 550 | event.deviceId = deviceId; | 
|  | 551 | event.type = type; | 
|  | 552 | event.code = code; | 
|  | 553 | event.value = value; | 
|  | 554 | mEvents.push_back(event); | 
|  | 555 |  | 
|  | 556 | if (type == EV_ABS) { | 
|  | 557 | setAbsoluteAxisValue(deviceId, code, value); | 
|  | 558 | } | 
|  | 559 | } | 
|  | 560 |  | 
|  | 561 | void assertQueueIsEmpty() { | 
|  | 562 | ASSERT_EQ(size_t(0), mEvents.size()) | 
|  | 563 | << "Expected the event queue to be empty (fully consumed)."; | 
|  | 564 | } | 
|  | 565 |  | 
|  | 566 | private: | 
|  | 567 | Device* getDevice(int32_t deviceId) const { | 
|  | 568 | ssize_t index = mDevices.indexOfKey(deviceId); | 
|  | 569 | return index >= 0 ? mDevices.valueAt(index) : NULL; | 
|  | 570 | } | 
|  | 571 |  | 
|  | 572 | virtual uint32_t getDeviceClasses(int32_t deviceId) const { | 
|  | 573 | Device* device = getDevice(deviceId); | 
|  | 574 | return device ? device->classes : 0; | 
|  | 575 | } | 
|  | 576 |  | 
|  | 577 | virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const { | 
|  | 578 | Device* device = getDevice(deviceId); | 
|  | 579 | return device ? device->identifier : InputDeviceIdentifier(); | 
|  | 580 | } | 
|  | 581 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 582 | virtual int32_t getDeviceControllerNumber(int32_t) const { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 583 | return 0; | 
|  | 584 | } | 
|  | 585 |  | 
|  | 586 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const { | 
|  | 587 | Device* device = getDevice(deviceId); | 
|  | 588 | if (device) { | 
|  | 589 | *outConfiguration = device->configuration; | 
|  | 590 | } | 
|  | 591 | } | 
|  | 592 |  | 
|  | 593 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, | 
|  | 594 | RawAbsoluteAxisInfo* outAxisInfo) const { | 
|  | 595 | Device* device = getDevice(deviceId); | 
|  | 596 | if (device) { | 
|  | 597 | ssize_t index = device->absoluteAxes.indexOfKey(axis); | 
|  | 598 | if (index >= 0) { | 
|  | 599 | *outAxisInfo = device->absoluteAxes.valueAt(index); | 
|  | 600 | return OK; | 
|  | 601 | } | 
|  | 602 | } | 
|  | 603 | outAxisInfo->clear(); | 
|  | 604 | return -1; | 
|  | 605 | } | 
|  | 606 |  | 
|  | 607 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const { | 
|  | 608 | Device* device = getDevice(deviceId); | 
|  | 609 | if (device) { | 
|  | 610 | return device->relativeAxes.indexOfKey(axis) >= 0; | 
|  | 611 | } | 
|  | 612 | return false; | 
|  | 613 | } | 
|  | 614 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 615 | virtual bool hasInputProperty(int32_t, int) const { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 616 | return false; | 
|  | 617 | } | 
|  | 618 |  | 
| Dmitry Torokhov | 0faaa0b | 2015-09-24 13:13:55 -0700 | [diff] [blame] | 619 | virtual status_t mapKey(int32_t deviceId, | 
|  | 620 | int32_t scanCode, int32_t usageCode, int32_t metaState, | 
|  | 621 | int32_t* outKeycode, int32_t *outMetaState, uint32_t* outFlags) const { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 622 | Device* device = getDevice(deviceId); | 
|  | 623 | if (device) { | 
|  | 624 | const KeyInfo* key = getKey(device, scanCode, usageCode); | 
|  | 625 | if (key) { | 
|  | 626 | if (outKeycode) { | 
|  | 627 | *outKeycode = key->keyCode; | 
|  | 628 | } | 
|  | 629 | if (outFlags) { | 
|  | 630 | *outFlags = key->flags; | 
|  | 631 | } | 
| Dmitry Torokhov | 0faaa0b | 2015-09-24 13:13:55 -0700 | [diff] [blame] | 632 | if (outMetaState) { | 
|  | 633 | *outMetaState = metaState; | 
|  | 634 | } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 635 | return OK; | 
|  | 636 | } | 
|  | 637 | } | 
|  | 638 | return NAME_NOT_FOUND; | 
|  | 639 | } | 
|  | 640 |  | 
|  | 641 | const KeyInfo* getKey(Device* device, int32_t scanCode, int32_t usageCode) const { | 
|  | 642 | if (usageCode) { | 
|  | 643 | ssize_t index = device->keysByUsageCode.indexOfKey(usageCode); | 
|  | 644 | if (index >= 0) { | 
|  | 645 | return &device->keysByUsageCode.valueAt(index); | 
|  | 646 | } | 
|  | 647 | } | 
|  | 648 | if (scanCode) { | 
|  | 649 | ssize_t index = device->keysByScanCode.indexOfKey(scanCode); | 
|  | 650 | if (index >= 0) { | 
|  | 651 | return &device->keysByScanCode.valueAt(index); | 
|  | 652 | } | 
|  | 653 | } | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 654 | return nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 655 | } | 
|  | 656 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 657 | virtual status_t mapAxis(int32_t, int32_t, AxisInfo*) const { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 658 | return NAME_NOT_FOUND; | 
|  | 659 | } | 
|  | 660 |  | 
|  | 661 | virtual void setExcludedDevices(const Vector<String8>& devices) { | 
|  | 662 | mExcludedDevices = devices; | 
|  | 663 | } | 
|  | 664 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 665 | virtual size_t getEvents(int, RawEvent* buffer, size_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 666 | if (mEvents.empty()) { | 
|  | 667 | return 0; | 
|  | 668 | } | 
|  | 669 |  | 
|  | 670 | *buffer = *mEvents.begin(); | 
|  | 671 | mEvents.erase(mEvents.begin()); | 
|  | 672 | return 1; | 
|  | 673 | } | 
|  | 674 |  | 
|  | 675 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const { | 
|  | 676 | Device* device = getDevice(deviceId); | 
|  | 677 | if (device) { | 
|  | 678 | ssize_t index = device->scanCodeStates.indexOfKey(scanCode); | 
|  | 679 | if (index >= 0) { | 
|  | 680 | return device->scanCodeStates.valueAt(index); | 
|  | 681 | } | 
|  | 682 | } | 
|  | 683 | return AKEY_STATE_UNKNOWN; | 
|  | 684 | } | 
|  | 685 |  | 
|  | 686 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const { | 
|  | 687 | Device* device = getDevice(deviceId); | 
|  | 688 | if (device) { | 
|  | 689 | ssize_t index = device->keyCodeStates.indexOfKey(keyCode); | 
|  | 690 | if (index >= 0) { | 
|  | 691 | return device->keyCodeStates.valueAt(index); | 
|  | 692 | } | 
|  | 693 | } | 
|  | 694 | return AKEY_STATE_UNKNOWN; | 
|  | 695 | } | 
|  | 696 |  | 
|  | 697 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const { | 
|  | 698 | Device* device = getDevice(deviceId); | 
|  | 699 | if (device) { | 
|  | 700 | ssize_t index = device->switchStates.indexOfKey(sw); | 
|  | 701 | if (index >= 0) { | 
|  | 702 | return device->switchStates.valueAt(index); | 
|  | 703 | } | 
|  | 704 | } | 
|  | 705 | return AKEY_STATE_UNKNOWN; | 
|  | 706 | } | 
|  | 707 |  | 
|  | 708 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, | 
|  | 709 | int32_t* outValue) const { | 
|  | 710 | Device* device = getDevice(deviceId); | 
|  | 711 | if (device) { | 
|  | 712 | ssize_t index = device->absoluteAxisValue.indexOfKey(axis); | 
|  | 713 | if (index >= 0) { | 
|  | 714 | *outValue = device->absoluteAxisValue.valueAt(index); | 
|  | 715 | return OK; | 
|  | 716 | } | 
|  | 717 | } | 
|  | 718 | *outValue = 0; | 
|  | 719 | return -1; | 
|  | 720 | } | 
|  | 721 |  | 
|  | 722 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, | 
|  | 723 | uint8_t* outFlags) const { | 
|  | 724 | bool result = false; | 
|  | 725 | Device* device = getDevice(deviceId); | 
|  | 726 | if (device) { | 
|  | 727 | for (size_t i = 0; i < numCodes; i++) { | 
|  | 728 | for (size_t j = 0; j < device->keysByScanCode.size(); j++) { | 
|  | 729 | if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) { | 
|  | 730 | outFlags[i] = 1; | 
|  | 731 | result = true; | 
|  | 732 | } | 
|  | 733 | } | 
|  | 734 | for (size_t j = 0; j < device->keysByUsageCode.size(); j++) { | 
|  | 735 | if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) { | 
|  | 736 | outFlags[i] = 1; | 
|  | 737 | result = true; | 
|  | 738 | } | 
|  | 739 | } | 
|  | 740 | } | 
|  | 741 | } | 
|  | 742 | return result; | 
|  | 743 | } | 
|  | 744 |  | 
|  | 745 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const { | 
|  | 746 | Device* device = getDevice(deviceId); | 
|  | 747 | if (device) { | 
|  | 748 | ssize_t index = device->keysByScanCode.indexOfKey(scanCode); | 
|  | 749 | return index >= 0; | 
|  | 750 | } | 
|  | 751 | return false; | 
|  | 752 | } | 
|  | 753 |  | 
|  | 754 | virtual bool hasLed(int32_t deviceId, int32_t led) const { | 
|  | 755 | Device* device = getDevice(deviceId); | 
|  | 756 | return device && device->leds.indexOfKey(led) >= 0; | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | virtual void setLedState(int32_t deviceId, int32_t led, bool on) { | 
|  | 760 | Device* device = getDevice(deviceId); | 
|  | 761 | if (device) { | 
|  | 762 | ssize_t index = device->leds.indexOfKey(led); | 
|  | 763 | if (index >= 0) { | 
|  | 764 | device->leds.replaceValueAt(led, on); | 
|  | 765 | } else { | 
|  | 766 | ADD_FAILURE() | 
|  | 767 | << "Attempted to set the state of an LED that the EventHub declared " | 
|  | 768 | "was not present.  led=" << led; | 
|  | 769 | } | 
|  | 770 | } | 
|  | 771 | } | 
|  | 772 |  | 
|  | 773 | virtual void getVirtualKeyDefinitions(int32_t deviceId, | 
|  | 774 | Vector<VirtualKeyDefinition>& outVirtualKeys) const { | 
|  | 775 | outVirtualKeys.clear(); | 
|  | 776 |  | 
|  | 777 | Device* device = getDevice(deviceId); | 
|  | 778 | if (device) { | 
|  | 779 | outVirtualKeys.appendVector(device->virtualKeys); | 
|  | 780 | } | 
|  | 781 | } | 
|  | 782 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 783 | virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t) const { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 784 | return nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 785 | } | 
|  | 786 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 787 | virtual bool setKeyboardLayoutOverlay(int32_t, const sp<KeyCharacterMap>&) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 788 | return false; | 
|  | 789 | } | 
|  | 790 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 791 | virtual void vibrate(int32_t, nsecs_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 792 | } | 
|  | 793 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 794 | virtual void cancelVibrate(int32_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 795 | } | 
|  | 796 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 797 | virtual bool isExternal(int32_t) const { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 798 | return false; | 
|  | 799 | } | 
|  | 800 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 801 | virtual void dump(std::string&) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 802 | } | 
|  | 803 |  | 
|  | 804 | virtual void monitor() { | 
|  | 805 | } | 
|  | 806 |  | 
|  | 807 | virtual void requestReopenDevices() { | 
|  | 808 | } | 
|  | 809 |  | 
|  | 810 | virtual void wake() { | 
|  | 811 | } | 
|  | 812 | }; | 
|  | 813 |  | 
|  | 814 |  | 
|  | 815 | // --- FakeInputReaderContext --- | 
|  | 816 |  | 
|  | 817 | class FakeInputReaderContext : public InputReaderContext { | 
|  | 818 | sp<EventHubInterface> mEventHub; | 
|  | 819 | sp<InputReaderPolicyInterface> mPolicy; | 
|  | 820 | sp<InputListenerInterface> mListener; | 
|  | 821 | int32_t mGlobalMetaState; | 
|  | 822 | bool mUpdateGlobalMetaStateWasCalled; | 
|  | 823 | int32_t mGeneration; | 
|  | 824 |  | 
|  | 825 | public: | 
|  | 826 | FakeInputReaderContext(const sp<EventHubInterface>& eventHub, | 
|  | 827 | const sp<InputReaderPolicyInterface>& policy, | 
|  | 828 | const sp<InputListenerInterface>& listener) : | 
|  | 829 | mEventHub(eventHub), mPolicy(policy), mListener(listener), | 
|  | 830 | mGlobalMetaState(0) { | 
|  | 831 | } | 
|  | 832 |  | 
|  | 833 | virtual ~FakeInputReaderContext() { } | 
|  | 834 |  | 
|  | 835 | void assertUpdateGlobalMetaStateWasCalled() { | 
|  | 836 | ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled) | 
|  | 837 | << "Expected updateGlobalMetaState() to have been called."; | 
|  | 838 | mUpdateGlobalMetaStateWasCalled = false; | 
|  | 839 | } | 
|  | 840 |  | 
|  | 841 | void setGlobalMetaState(int32_t state) { | 
|  | 842 | mGlobalMetaState = state; | 
|  | 843 | } | 
|  | 844 |  | 
| Vladislav Kaznacheev | 78f97b3 | 2016-12-15 18:14:58 -0800 | [diff] [blame] | 845 | uint32_t getGeneration() { | 
|  | 846 | return mGeneration; | 
|  | 847 | } | 
|  | 848 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 849 | private: | 
|  | 850 | virtual void updateGlobalMetaState() { | 
|  | 851 | mUpdateGlobalMetaStateWasCalled = true; | 
|  | 852 | } | 
|  | 853 |  | 
|  | 854 | virtual int32_t getGlobalMetaState() { | 
|  | 855 | return mGlobalMetaState; | 
|  | 856 | } | 
|  | 857 |  | 
|  | 858 | virtual EventHubInterface* getEventHub() { | 
|  | 859 | return mEventHub.get(); | 
|  | 860 | } | 
|  | 861 |  | 
|  | 862 | virtual InputReaderPolicyInterface* getPolicy() { | 
|  | 863 | return mPolicy.get(); | 
|  | 864 | } | 
|  | 865 |  | 
|  | 866 | virtual InputListenerInterface* getListener() { | 
|  | 867 | return mListener.get(); | 
|  | 868 | } | 
|  | 869 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 870 | virtual void disableVirtualKeysUntil(nsecs_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 871 | } | 
|  | 872 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 873 | virtual bool shouldDropVirtualKey(nsecs_t, InputDevice*, int32_t, int32_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 874 | return false; | 
|  | 875 | } | 
|  | 876 |  | 
|  | 877 | virtual void fadePointer() { | 
|  | 878 | } | 
|  | 879 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 880 | virtual void requestTimeoutAtTime(nsecs_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 881 | } | 
|  | 882 |  | 
|  | 883 | virtual int32_t bumpGeneration() { | 
|  | 884 | return ++mGeneration; | 
|  | 885 | } | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 886 |  | 
|  | 887 | virtual void getExternalStylusDevices(Vector<InputDeviceInfo>& outDevices) { | 
|  | 888 |  | 
|  | 889 | } | 
|  | 890 |  | 
|  | 891 | virtual void dispatchExternalStylusState(const StylusState&) { | 
|  | 892 |  | 
|  | 893 | } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 894 | }; | 
|  | 895 |  | 
|  | 896 |  | 
|  | 897 | // --- FakeInputMapper --- | 
|  | 898 |  | 
|  | 899 | class FakeInputMapper : public InputMapper { | 
|  | 900 | uint32_t mSources; | 
|  | 901 | int32_t mKeyboardType; | 
|  | 902 | int32_t mMetaState; | 
|  | 903 | KeyedVector<int32_t, int32_t> mKeyCodeStates; | 
|  | 904 | KeyedVector<int32_t, int32_t> mScanCodeStates; | 
|  | 905 | KeyedVector<int32_t, int32_t> mSwitchStates; | 
|  | 906 | Vector<int32_t> mSupportedKeyCodes; | 
|  | 907 | RawEvent mLastEvent; | 
|  | 908 |  | 
|  | 909 | bool mConfigureWasCalled; | 
|  | 910 | bool mResetWasCalled; | 
|  | 911 | bool mProcessWasCalled; | 
|  | 912 |  | 
|  | 913 | public: | 
|  | 914 | FakeInputMapper(InputDevice* device, uint32_t sources) : | 
|  | 915 | InputMapper(device), | 
|  | 916 | mSources(sources), mKeyboardType(AINPUT_KEYBOARD_TYPE_NONE), | 
|  | 917 | mMetaState(0), | 
|  | 918 | mConfigureWasCalled(false), mResetWasCalled(false), mProcessWasCalled(false) { | 
|  | 919 | } | 
|  | 920 |  | 
|  | 921 | virtual ~FakeInputMapper() { } | 
|  | 922 |  | 
|  | 923 | void setKeyboardType(int32_t keyboardType) { | 
|  | 924 | mKeyboardType = keyboardType; | 
|  | 925 | } | 
|  | 926 |  | 
|  | 927 | void setMetaState(int32_t metaState) { | 
|  | 928 | mMetaState = metaState; | 
|  | 929 | } | 
|  | 930 |  | 
|  | 931 | void assertConfigureWasCalled() { | 
|  | 932 | ASSERT_TRUE(mConfigureWasCalled) | 
|  | 933 | << "Expected configure() to have been called."; | 
|  | 934 | mConfigureWasCalled = false; | 
|  | 935 | } | 
|  | 936 |  | 
|  | 937 | void assertResetWasCalled() { | 
|  | 938 | ASSERT_TRUE(mResetWasCalled) | 
|  | 939 | << "Expected reset() to have been called."; | 
|  | 940 | mResetWasCalled = false; | 
|  | 941 | } | 
|  | 942 |  | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 943 | void assertProcessWasCalled(RawEvent* outLastEvent = nullptr) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 944 | ASSERT_TRUE(mProcessWasCalled) | 
|  | 945 | << "Expected process() to have been called."; | 
|  | 946 | if (outLastEvent) { | 
|  | 947 | *outLastEvent = mLastEvent; | 
|  | 948 | } | 
|  | 949 | mProcessWasCalled = false; | 
|  | 950 | } | 
|  | 951 |  | 
|  | 952 | void setKeyCodeState(int32_t keyCode, int32_t state) { | 
|  | 953 | mKeyCodeStates.replaceValueFor(keyCode, state); | 
|  | 954 | } | 
|  | 955 |  | 
|  | 956 | void setScanCodeState(int32_t scanCode, int32_t state) { | 
|  | 957 | mScanCodeStates.replaceValueFor(scanCode, state); | 
|  | 958 | } | 
|  | 959 |  | 
|  | 960 | void setSwitchState(int32_t switchCode, int32_t state) { | 
|  | 961 | mSwitchStates.replaceValueFor(switchCode, state); | 
|  | 962 | } | 
|  | 963 |  | 
|  | 964 | void addSupportedKeyCode(int32_t keyCode) { | 
|  | 965 | mSupportedKeyCodes.add(keyCode); | 
|  | 966 | } | 
|  | 967 |  | 
|  | 968 | private: | 
|  | 969 | virtual uint32_t getSources() { | 
|  | 970 | return mSources; | 
|  | 971 | } | 
|  | 972 |  | 
|  | 973 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) { | 
|  | 974 | InputMapper::populateDeviceInfo(deviceInfo); | 
|  | 975 |  | 
|  | 976 | if (mKeyboardType != AINPUT_KEYBOARD_TYPE_NONE) { | 
|  | 977 | deviceInfo->setKeyboardType(mKeyboardType); | 
|  | 978 | } | 
|  | 979 | } | 
|  | 980 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 981 | virtual void configure(nsecs_t, const InputReaderConfiguration*, uint32_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 982 | mConfigureWasCalled = true; | 
|  | 983 | } | 
|  | 984 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 985 | virtual void reset(nsecs_t) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 986 | mResetWasCalled = true; | 
|  | 987 | } | 
|  | 988 |  | 
|  | 989 | virtual void process(const RawEvent* rawEvent) { | 
|  | 990 | mLastEvent = *rawEvent; | 
|  | 991 | mProcessWasCalled = true; | 
|  | 992 | } | 
|  | 993 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 994 | virtual int32_t getKeyCodeState(uint32_t, int32_t keyCode) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 995 | ssize_t index = mKeyCodeStates.indexOfKey(keyCode); | 
|  | 996 | return index >= 0 ? mKeyCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN; | 
|  | 997 | } | 
|  | 998 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 999 | virtual int32_t getScanCodeState(uint32_t, int32_t scanCode) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1000 | ssize_t index = mScanCodeStates.indexOfKey(scanCode); | 
|  | 1001 | return index >= 0 ? mScanCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN; | 
|  | 1002 | } | 
|  | 1003 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 1004 | virtual int32_t getSwitchState(uint32_t, int32_t switchCode) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1005 | ssize_t index = mSwitchStates.indexOfKey(switchCode); | 
|  | 1006 | return index >= 0 ? mSwitchStates.valueAt(index) : AKEY_STATE_UNKNOWN; | 
|  | 1007 | } | 
|  | 1008 |  | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 1009 | virtual bool markSupportedKeyCodes(uint32_t, size_t numCodes, | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1010 | const int32_t* keyCodes, uint8_t* outFlags) { | 
|  | 1011 | bool result = false; | 
|  | 1012 | for (size_t i = 0; i < numCodes; i++) { | 
|  | 1013 | for (size_t j = 0; j < mSupportedKeyCodes.size(); j++) { | 
|  | 1014 | if (keyCodes[i] == mSupportedKeyCodes[j]) { | 
|  | 1015 | outFlags[i] = 1; | 
|  | 1016 | result = true; | 
|  | 1017 | } | 
|  | 1018 | } | 
|  | 1019 | } | 
|  | 1020 | return result; | 
|  | 1021 | } | 
|  | 1022 |  | 
|  | 1023 | virtual int32_t getMetaState() { | 
|  | 1024 | return mMetaState; | 
|  | 1025 | } | 
|  | 1026 |  | 
|  | 1027 | virtual void fadePointer() { | 
|  | 1028 | } | 
|  | 1029 | }; | 
|  | 1030 |  | 
|  | 1031 |  | 
|  | 1032 | // --- InstrumentedInputReader --- | 
|  | 1033 |  | 
|  | 1034 | class InstrumentedInputReader : public InputReader { | 
|  | 1035 | InputDevice* mNextDevice; | 
|  | 1036 |  | 
|  | 1037 | public: | 
|  | 1038 | InstrumentedInputReader(const sp<EventHubInterface>& eventHub, | 
|  | 1039 | const sp<InputReaderPolicyInterface>& policy, | 
|  | 1040 | const sp<InputListenerInterface>& listener) : | 
|  | 1041 | InputReader(eventHub, policy, listener), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1042 | mNextDevice(nullptr) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1043 | } | 
|  | 1044 |  | 
|  | 1045 | virtual ~InstrumentedInputReader() { | 
|  | 1046 | if (mNextDevice) { | 
|  | 1047 | delete mNextDevice; | 
|  | 1048 | } | 
|  | 1049 | } | 
|  | 1050 |  | 
|  | 1051 | void setNextDevice(InputDevice* device) { | 
|  | 1052 | mNextDevice = device; | 
|  | 1053 | } | 
|  | 1054 |  | 
|  | 1055 | InputDevice* newDevice(int32_t deviceId, int32_t controllerNumber, const String8& name, | 
|  | 1056 | uint32_t classes) { | 
|  | 1057 | InputDeviceIdentifier identifier; | 
|  | 1058 | identifier.name = name; | 
|  | 1059 | int32_t generation = deviceId + 1; | 
|  | 1060 | return new InputDevice(&mContext, deviceId, generation, controllerNumber, identifier, | 
|  | 1061 | classes); | 
|  | 1062 | } | 
|  | 1063 |  | 
|  | 1064 | protected: | 
|  | 1065 | virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber, | 
|  | 1066 | const InputDeviceIdentifier& identifier, uint32_t classes) { | 
|  | 1067 | if (mNextDevice) { | 
|  | 1068 | InputDevice* device = mNextDevice; | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1069 | mNextDevice = nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1070 | return device; | 
|  | 1071 | } | 
|  | 1072 | return InputReader::createDeviceLocked(deviceId, controllerNumber, identifier, classes); | 
|  | 1073 | } | 
|  | 1074 |  | 
|  | 1075 | friend class InputReaderTest; | 
|  | 1076 | }; | 
|  | 1077 |  | 
|  | 1078 |  | 
|  | 1079 | // --- InputReaderTest --- | 
|  | 1080 |  | 
|  | 1081 | class InputReaderTest : public testing::Test { | 
|  | 1082 | protected: | 
|  | 1083 | sp<FakeInputListener> mFakeListener; | 
|  | 1084 | sp<FakeInputReaderPolicy> mFakePolicy; | 
|  | 1085 | sp<FakeEventHub> mFakeEventHub; | 
|  | 1086 | sp<InstrumentedInputReader> mReader; | 
|  | 1087 |  | 
|  | 1088 | virtual void SetUp() { | 
|  | 1089 | mFakeEventHub = new FakeEventHub(); | 
|  | 1090 | mFakePolicy = new FakeInputReaderPolicy(); | 
|  | 1091 | mFakeListener = new FakeInputListener(); | 
|  | 1092 |  | 
|  | 1093 | mReader = new InstrumentedInputReader(mFakeEventHub, mFakePolicy, mFakeListener); | 
|  | 1094 | } | 
|  | 1095 |  | 
|  | 1096 | virtual void TearDown() { | 
|  | 1097 | mReader.clear(); | 
|  | 1098 |  | 
|  | 1099 | mFakeListener.clear(); | 
|  | 1100 | mFakePolicy.clear(); | 
|  | 1101 | mFakeEventHub.clear(); | 
|  | 1102 | } | 
|  | 1103 |  | 
|  | 1104 | void addDevice(int32_t deviceId, const String8& name, uint32_t classes, | 
|  | 1105 | const PropertyMap* configuration) { | 
|  | 1106 | mFakeEventHub->addDevice(deviceId, name, classes); | 
|  | 1107 |  | 
|  | 1108 | if (configuration) { | 
|  | 1109 | mFakeEventHub->addConfigurationMap(deviceId, configuration); | 
|  | 1110 | } | 
|  | 1111 | mFakeEventHub->finishDeviceScan(); | 
|  | 1112 | mReader->loopOnce(); | 
|  | 1113 | mReader->loopOnce(); | 
|  | 1114 | mFakeEventHub->assertQueueIsEmpty(); | 
|  | 1115 | } | 
|  | 1116 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 1117 | void disableDevice(int32_t deviceId, InputDevice* device) { | 
|  | 1118 | mFakePolicy->addDisabledDevice(deviceId); | 
|  | 1119 | configureDevice(InputReaderConfiguration::CHANGE_ENABLED_STATE, device); | 
|  | 1120 | } | 
|  | 1121 |  | 
|  | 1122 | void enableDevice(int32_t deviceId, InputDevice* device) { | 
|  | 1123 | mFakePolicy->removeDisabledDevice(deviceId); | 
|  | 1124 | configureDevice(InputReaderConfiguration::CHANGE_ENABLED_STATE, device); | 
|  | 1125 | } | 
|  | 1126 |  | 
|  | 1127 | void configureDevice(uint32_t changes, InputDevice* device) { | 
|  | 1128 | device->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), changes); | 
|  | 1129 | } | 
|  | 1130 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1131 | FakeInputMapper* addDeviceWithFakeInputMapper(int32_t deviceId, int32_t controllerNumber, | 
|  | 1132 | const String8& name, uint32_t classes, uint32_t sources, | 
|  | 1133 | const PropertyMap* configuration) { | 
|  | 1134 | InputDevice* device = mReader->newDevice(deviceId, controllerNumber, name, classes); | 
|  | 1135 | FakeInputMapper* mapper = new FakeInputMapper(device, sources); | 
|  | 1136 | device->addMapper(mapper); | 
|  | 1137 | mReader->setNextDevice(device); | 
|  | 1138 | addDevice(deviceId, name, classes, configuration); | 
|  | 1139 | return mapper; | 
|  | 1140 | } | 
|  | 1141 | }; | 
|  | 1142 |  | 
|  | 1143 | TEST_F(InputReaderTest, GetInputDevices) { | 
|  | 1144 | ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1145 | INPUT_DEVICE_CLASS_KEYBOARD, nullptr)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1146 | ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("ignored"), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1147 | 0, nullptr)); // no classes so device will be ignored | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1148 |  | 
|  | 1149 | Vector<InputDeviceInfo> inputDevices; | 
|  | 1150 | mReader->getInputDevices(inputDevices); | 
|  | 1151 |  | 
|  | 1152 | ASSERT_EQ(1U, inputDevices.size()); | 
|  | 1153 | ASSERT_EQ(1, inputDevices[0].getId()); | 
|  | 1154 | ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string()); | 
|  | 1155 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); | 
|  | 1156 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); | 
|  | 1157 | ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); | 
|  | 1158 |  | 
|  | 1159 | // Should also have received a notification describing the new input devices. | 
|  | 1160 | inputDevices = mFakePolicy->getInputDevices(); | 
|  | 1161 | ASSERT_EQ(1U, inputDevices.size()); | 
|  | 1162 | ASSERT_EQ(1, inputDevices[0].getId()); | 
|  | 1163 | ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string()); | 
|  | 1164 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); | 
|  | 1165 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); | 
|  | 1166 | ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); | 
|  | 1167 | } | 
|  | 1168 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 1169 | TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) { | 
|  | 1170 | constexpr int32_t deviceId = 1; | 
|  | 1171 | constexpr uint32_t deviceClass = INPUT_DEVICE_CLASS_KEYBOARD; | 
|  | 1172 | InputDevice* device = mReader->newDevice(deviceId, 0, String8("fake"), deviceClass); | 
|  | 1173 | // Must add at least one mapper or the device will be ignored! | 
|  | 1174 | FakeInputMapper* mapper = new FakeInputMapper(device, AINPUT_SOURCE_KEYBOARD); | 
|  | 1175 | device->addMapper(mapper); | 
|  | 1176 | mReader->setNextDevice(device); | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1177 | addDevice(deviceId, String8("fake"), deviceClass, nullptr); | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 1178 |  | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1179 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(nullptr)); | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 1180 |  | 
|  | 1181 | NotifyDeviceResetArgs resetArgs; | 
|  | 1182 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs)); | 
|  | 1183 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); | 
|  | 1184 | ASSERT_EQ(deviceId, resetArgs.deviceId); | 
|  | 1185 |  | 
|  | 1186 | ASSERT_EQ(device->isEnabled(), true); | 
|  | 1187 | disableDevice(deviceId, device); | 
|  | 1188 | mReader->loopOnce(); | 
|  | 1189 |  | 
|  | 1190 | mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs); | 
|  | 1191 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); | 
|  | 1192 | ASSERT_EQ(deviceId, resetArgs.deviceId); | 
|  | 1193 | ASSERT_EQ(device->isEnabled(), false); | 
|  | 1194 |  | 
|  | 1195 | disableDevice(deviceId, device); | 
|  | 1196 | mReader->loopOnce(); | 
|  | 1197 | mFakeListener->assertNotifyDeviceResetWasNotCalled(); | 
|  | 1198 | mFakeListener->assertNotifyConfigurationChangedWasNotCalled(); | 
|  | 1199 | ASSERT_EQ(device->isEnabled(), false); | 
|  | 1200 |  | 
|  | 1201 | enableDevice(deviceId, device); | 
|  | 1202 | mReader->loopOnce(); | 
|  | 1203 | mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs); | 
|  | 1204 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); | 
|  | 1205 | ASSERT_EQ(deviceId, resetArgs.deviceId); | 
|  | 1206 | ASSERT_EQ(device->isEnabled(), true); | 
|  | 1207 | } | 
|  | 1208 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1209 | TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1210 | FakeInputMapper* mapper = nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1211 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1212 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1213 | mapper->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN); | 
|  | 1214 |  | 
|  | 1215 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(0, | 
|  | 1216 | AINPUT_SOURCE_ANY, AKEYCODE_A)) | 
|  | 1217 | << "Should return unknown when the device id is >= 0 but unknown."; | 
|  | 1218 |  | 
|  | 1219 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(1, | 
|  | 1220 | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) | 
|  | 1221 | << "Should return unknown when the device id is valid but the sources are not supported by the device."; | 
|  | 1222 |  | 
|  | 1223 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(1, | 
|  | 1224 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) | 
|  | 1225 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; | 
|  | 1226 |  | 
|  | 1227 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(-1, | 
|  | 1228 | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) | 
|  | 1229 | << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; | 
|  | 1230 |  | 
|  | 1231 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(-1, | 
|  | 1232 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) | 
|  | 1233 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; | 
|  | 1234 | } | 
|  | 1235 |  | 
|  | 1236 | TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1237 | FakeInputMapper* mapper = nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1238 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1239 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1240 | mapper->setScanCodeState(KEY_A, AKEY_STATE_DOWN); | 
|  | 1241 |  | 
|  | 1242 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(0, | 
|  | 1243 | AINPUT_SOURCE_ANY, KEY_A)) | 
|  | 1244 | << "Should return unknown when the device id is >= 0 but unknown."; | 
|  | 1245 |  | 
|  | 1246 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(1, | 
|  | 1247 | AINPUT_SOURCE_TRACKBALL, KEY_A)) | 
|  | 1248 | << "Should return unknown when the device id is valid but the sources are not supported by the device."; | 
|  | 1249 |  | 
|  | 1250 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(1, | 
|  | 1251 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A)) | 
|  | 1252 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; | 
|  | 1253 |  | 
|  | 1254 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(-1, | 
|  | 1255 | AINPUT_SOURCE_TRACKBALL, KEY_A)) | 
|  | 1256 | << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; | 
|  | 1257 |  | 
|  | 1258 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(-1, | 
|  | 1259 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A)) | 
|  | 1260 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; | 
|  | 1261 | } | 
|  | 1262 |  | 
|  | 1263 | TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1264 | FakeInputMapper* mapper = nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1265 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1266 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1267 | mapper->setSwitchState(SW_LID, AKEY_STATE_DOWN); | 
|  | 1268 |  | 
|  | 1269 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(0, | 
|  | 1270 | AINPUT_SOURCE_ANY, SW_LID)) | 
|  | 1271 | << "Should return unknown when the device id is >= 0 but unknown."; | 
|  | 1272 |  | 
|  | 1273 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(1, | 
|  | 1274 | AINPUT_SOURCE_TRACKBALL, SW_LID)) | 
|  | 1275 | << "Should return unknown when the device id is valid but the sources are not supported by the device."; | 
|  | 1276 |  | 
|  | 1277 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(1, | 
|  | 1278 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID)) | 
|  | 1279 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; | 
|  | 1280 |  | 
|  | 1281 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(-1, | 
|  | 1282 | AINPUT_SOURCE_TRACKBALL, SW_LID)) | 
|  | 1283 | << "Should return unknown when the device id is < 0 but the sources are not supported by any device."; | 
|  | 1284 |  | 
|  | 1285 | ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(-1, | 
|  | 1286 | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID)) | 
|  | 1287 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; | 
|  | 1288 | } | 
|  | 1289 |  | 
|  | 1290 | TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1291 | FakeInputMapper* mapper = nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1292 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1293 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1294 | mapper->addSupportedKeyCode(AKEYCODE_A); | 
|  | 1295 | mapper->addSupportedKeyCode(AKEYCODE_B); | 
|  | 1296 |  | 
|  | 1297 | const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 }; | 
|  | 1298 | uint8_t flags[4] = { 0, 0, 0, 1 }; | 
|  | 1299 |  | 
|  | 1300 | ASSERT_FALSE(mReader->hasKeys(0, AINPUT_SOURCE_ANY, 4, keyCodes, flags)) | 
|  | 1301 | << "Should return false when device id is >= 0 but unknown."; | 
|  | 1302 | ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); | 
|  | 1303 |  | 
|  | 1304 | flags[3] = 1; | 
|  | 1305 | ASSERT_FALSE(mReader->hasKeys(1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) | 
|  | 1306 | << "Should return false when device id is valid but the sources are not supported by the device."; | 
|  | 1307 | ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); | 
|  | 1308 |  | 
|  | 1309 | flags[3] = 1; | 
|  | 1310 | ASSERT_TRUE(mReader->hasKeys(1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) | 
|  | 1311 | << "Should return value provided by mapper when device id is valid and the device supports some of the sources."; | 
|  | 1312 | ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]); | 
|  | 1313 |  | 
|  | 1314 | flags[3] = 1; | 
|  | 1315 | ASSERT_FALSE(mReader->hasKeys(-1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) | 
|  | 1316 | << "Should return false when the device id is < 0 but the sources are not supported by any device."; | 
|  | 1317 | ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]); | 
|  | 1318 |  | 
|  | 1319 | flags[3] = 1; | 
|  | 1320 | ASSERT_TRUE(mReader->hasKeys(-1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) | 
|  | 1321 | << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources."; | 
|  | 1322 | ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]); | 
|  | 1323 | } | 
|  | 1324 |  | 
|  | 1325 | TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1326 | addDevice(1, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, nullptr); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1327 |  | 
|  | 1328 | NotifyConfigurationChangedArgs args; | 
|  | 1329 |  | 
|  | 1330 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(&args)); | 
|  | 1331 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 1332 | } | 
|  | 1333 |  | 
|  | 1334 | TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) { | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1335 | FakeInputMapper* mapper = nullptr; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1336 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"), | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1337 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, nullptr)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1338 |  | 
|  | 1339 | mFakeEventHub->enqueueEvent(0, 1, EV_KEY, KEY_A, 1); | 
|  | 1340 | mReader->loopOnce(); | 
|  | 1341 | ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty()); | 
|  | 1342 |  | 
|  | 1343 | RawEvent event; | 
|  | 1344 | ASSERT_NO_FATAL_FAILURE(mapper->assertProcessWasCalled(&event)); | 
|  | 1345 | ASSERT_EQ(0, event.when); | 
|  | 1346 | ASSERT_EQ(1, event.deviceId); | 
|  | 1347 | ASSERT_EQ(EV_KEY, event.type); | 
|  | 1348 | ASSERT_EQ(KEY_A, event.code); | 
|  | 1349 | ASSERT_EQ(1, event.value); | 
|  | 1350 | } | 
|  | 1351 |  | 
|  | 1352 |  | 
|  | 1353 | // --- InputDeviceTest --- | 
|  | 1354 |  | 
|  | 1355 | class InputDeviceTest : public testing::Test { | 
|  | 1356 | protected: | 
|  | 1357 | static const char* DEVICE_NAME; | 
|  | 1358 | static const int32_t DEVICE_ID; | 
|  | 1359 | static const int32_t DEVICE_GENERATION; | 
|  | 1360 | static const int32_t DEVICE_CONTROLLER_NUMBER; | 
|  | 1361 | static const uint32_t DEVICE_CLASSES; | 
|  | 1362 |  | 
|  | 1363 | sp<FakeEventHub> mFakeEventHub; | 
|  | 1364 | sp<FakeInputReaderPolicy> mFakePolicy; | 
|  | 1365 | sp<FakeInputListener> mFakeListener; | 
|  | 1366 | FakeInputReaderContext* mFakeContext; | 
|  | 1367 |  | 
|  | 1368 | InputDevice* mDevice; | 
|  | 1369 |  | 
|  | 1370 | virtual void SetUp() { | 
|  | 1371 | mFakeEventHub = new FakeEventHub(); | 
|  | 1372 | mFakePolicy = new FakeInputReaderPolicy(); | 
|  | 1373 | mFakeListener = new FakeInputListener(); | 
|  | 1374 | mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener); | 
|  | 1375 |  | 
|  | 1376 | mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); | 
|  | 1377 | InputDeviceIdentifier identifier; | 
|  | 1378 | identifier.name = DEVICE_NAME; | 
|  | 1379 | mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION, | 
|  | 1380 | DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES); | 
|  | 1381 | } | 
|  | 1382 |  | 
|  | 1383 | virtual void TearDown() { | 
|  | 1384 | delete mDevice; | 
|  | 1385 |  | 
|  | 1386 | delete mFakeContext; | 
|  | 1387 | mFakeListener.clear(); | 
|  | 1388 | mFakePolicy.clear(); | 
|  | 1389 | mFakeEventHub.clear(); | 
|  | 1390 | } | 
|  | 1391 | }; | 
|  | 1392 |  | 
|  | 1393 | const char* InputDeviceTest::DEVICE_NAME = "device"; | 
|  | 1394 | const int32_t InputDeviceTest::DEVICE_ID = 1; | 
|  | 1395 | const int32_t InputDeviceTest::DEVICE_GENERATION = 2; | 
|  | 1396 | const int32_t InputDeviceTest::DEVICE_CONTROLLER_NUMBER = 0; | 
|  | 1397 | const uint32_t InputDeviceTest::DEVICE_CLASSES = INPUT_DEVICE_CLASS_KEYBOARD | 
|  | 1398 | | INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_JOYSTICK; | 
|  | 1399 |  | 
|  | 1400 | TEST_F(InputDeviceTest, ImmutableProperties) { | 
|  | 1401 | ASSERT_EQ(DEVICE_ID, mDevice->getId()); | 
|  | 1402 | ASSERT_STREQ(DEVICE_NAME, mDevice->getName()); | 
|  | 1403 | ASSERT_EQ(DEVICE_CLASSES, mDevice->getClasses()); | 
|  | 1404 | } | 
|  | 1405 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 1406 | TEST_F(InputDeviceTest, WhenDeviceCreated_EnabledIsTrue) { | 
|  | 1407 | ASSERT_EQ(mDevice->isEnabled(), true); | 
|  | 1408 | } | 
|  | 1409 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1410 | TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) { | 
|  | 1411 | // Configuration. | 
|  | 1412 | InputReaderConfiguration config; | 
|  | 1413 | mDevice->configure(ARBITRARY_TIME, &config, 0); | 
|  | 1414 |  | 
|  | 1415 | // Reset. | 
|  | 1416 | mDevice->reset(ARBITRARY_TIME); | 
|  | 1417 |  | 
|  | 1418 | NotifyDeviceResetArgs resetArgs; | 
|  | 1419 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs)); | 
|  | 1420 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); | 
|  | 1421 | ASSERT_EQ(DEVICE_ID, resetArgs.deviceId); | 
|  | 1422 |  | 
|  | 1423 | // Metadata. | 
|  | 1424 | ASSERT_TRUE(mDevice->isIgnored()); | 
|  | 1425 | ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mDevice->getSources()); | 
|  | 1426 |  | 
|  | 1427 | InputDeviceInfo info; | 
|  | 1428 | mDevice->getDeviceInfo(&info); | 
|  | 1429 | ASSERT_EQ(DEVICE_ID, info.getId()); | 
|  | 1430 | ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string()); | 
|  | 1431 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NONE, info.getKeyboardType()); | 
|  | 1432 | ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, info.getSources()); | 
|  | 1433 |  | 
|  | 1434 | // State queries. | 
|  | 1435 | ASSERT_EQ(0, mDevice->getMetaState()); | 
|  | 1436 |  | 
|  | 1437 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, 0)) | 
|  | 1438 | << "Ignored device should return unknown key code state."; | 
|  | 1439 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 0)) | 
|  | 1440 | << "Ignored device should return unknown scan code state."; | 
|  | 1441 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 0)) | 
|  | 1442 | << "Ignored device should return unknown switch state."; | 
|  | 1443 |  | 
|  | 1444 | const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B }; | 
|  | 1445 | uint8_t flags[2] = { 0, 1 }; | 
|  | 1446 | ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 2, keyCodes, flags)) | 
|  | 1447 | << "Ignored device should never mark any key codes."; | 
|  | 1448 | ASSERT_EQ(0, flags[0]) << "Flag for unsupported key should be unchanged."; | 
|  | 1449 | ASSERT_EQ(1, flags[1]) << "Flag for unsupported key should be unchanged."; | 
|  | 1450 | } | 
|  | 1451 |  | 
|  | 1452 | TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRequestsToMappers) { | 
|  | 1453 | // Configuration. | 
|  | 1454 | mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8("key"), String8("value")); | 
|  | 1455 |  | 
|  | 1456 | FakeInputMapper* mapper1 = new FakeInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD); | 
|  | 1457 | mapper1->setKeyboardType(AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 1458 | mapper1->setMetaState(AMETA_ALT_ON); | 
|  | 1459 | mapper1->addSupportedKeyCode(AKEYCODE_A); | 
|  | 1460 | mapper1->addSupportedKeyCode(AKEYCODE_B); | 
|  | 1461 | mapper1->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN); | 
|  | 1462 | mapper1->setKeyCodeState(AKEYCODE_B, AKEY_STATE_UP); | 
|  | 1463 | mapper1->setScanCodeState(2, AKEY_STATE_DOWN); | 
|  | 1464 | mapper1->setScanCodeState(3, AKEY_STATE_UP); | 
|  | 1465 | mapper1->setSwitchState(4, AKEY_STATE_DOWN); | 
|  | 1466 | mDevice->addMapper(mapper1); | 
|  | 1467 |  | 
|  | 1468 | FakeInputMapper* mapper2 = new FakeInputMapper(mDevice, AINPUT_SOURCE_TOUCHSCREEN); | 
|  | 1469 | mapper2->setMetaState(AMETA_SHIFT_ON); | 
|  | 1470 | mDevice->addMapper(mapper2); | 
|  | 1471 |  | 
|  | 1472 | InputReaderConfiguration config; | 
|  | 1473 | mDevice->configure(ARBITRARY_TIME, &config, 0); | 
|  | 1474 |  | 
|  | 1475 | String8 propertyValue; | 
|  | 1476 | ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue)) | 
|  | 1477 | << "Device should have read configuration during configuration phase."; | 
|  | 1478 | ASSERT_STREQ("value", propertyValue.string()); | 
|  | 1479 |  | 
|  | 1480 | ASSERT_NO_FATAL_FAILURE(mapper1->assertConfigureWasCalled()); | 
|  | 1481 | ASSERT_NO_FATAL_FAILURE(mapper2->assertConfigureWasCalled()); | 
|  | 1482 |  | 
|  | 1483 | // Reset | 
|  | 1484 | mDevice->reset(ARBITRARY_TIME); | 
|  | 1485 | ASSERT_NO_FATAL_FAILURE(mapper1->assertResetWasCalled()); | 
|  | 1486 | ASSERT_NO_FATAL_FAILURE(mapper2->assertResetWasCalled()); | 
|  | 1487 |  | 
|  | 1488 | NotifyDeviceResetArgs resetArgs; | 
|  | 1489 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs)); | 
|  | 1490 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); | 
|  | 1491 | ASSERT_EQ(DEVICE_ID, resetArgs.deviceId); | 
|  | 1492 |  | 
|  | 1493 | // Metadata. | 
|  | 1494 | ASSERT_FALSE(mDevice->isIgnored()); | 
|  | 1495 | ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), mDevice->getSources()); | 
|  | 1496 |  | 
|  | 1497 | InputDeviceInfo info; | 
|  | 1498 | mDevice->getDeviceInfo(&info); | 
|  | 1499 | ASSERT_EQ(DEVICE_ID, info.getId()); | 
|  | 1500 | ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string()); | 
|  | 1501 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, info.getKeyboardType()); | 
|  | 1502 | ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), info.getSources()); | 
|  | 1503 |  | 
|  | 1504 | // State queries. | 
|  | 1505 | ASSERT_EQ(AMETA_ALT_ON | AMETA_SHIFT_ON, mDevice->getMetaState()) | 
|  | 1506 | << "Should query mappers and combine meta states."; | 
|  | 1507 |  | 
|  | 1508 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) | 
|  | 1509 | << "Should return unknown key code state when source not supported."; | 
|  | 1510 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) | 
|  | 1511 | << "Should return unknown scan code state when source not supported."; | 
|  | 1512 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A)) | 
|  | 1513 | << "Should return unknown switch state when source not supported."; | 
|  | 1514 |  | 
|  | 1515 | ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, AKEYCODE_A)) | 
|  | 1516 | << "Should query mapper when source is supported."; | 
|  | 1517 | ASSERT_EQ(AKEY_STATE_UP, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 3)) | 
|  | 1518 | << "Should query mapper when source is supported."; | 
|  | 1519 | ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 4)) | 
|  | 1520 | << "Should query mapper when source is supported."; | 
|  | 1521 |  | 
|  | 1522 | const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 }; | 
|  | 1523 | uint8_t flags[4] = { 0, 0, 0, 1 }; | 
|  | 1524 | ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags)) | 
|  | 1525 | << "Should do nothing when source is unsupported."; | 
|  | 1526 | ASSERT_EQ(0, flags[0]) << "Flag should be unchanged when source is unsupported."; | 
|  | 1527 | ASSERT_EQ(0, flags[1]) << "Flag should be unchanged when source is unsupported."; | 
|  | 1528 | ASSERT_EQ(0, flags[2]) << "Flag should be unchanged when source is unsupported."; | 
|  | 1529 | ASSERT_EQ(1, flags[3]) << "Flag should be unchanged when source is unsupported."; | 
|  | 1530 |  | 
|  | 1531 | ASSERT_TRUE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 4, keyCodes, flags)) | 
|  | 1532 | << "Should query mapper when source is supported."; | 
|  | 1533 | ASSERT_EQ(1, flags[0]) << "Flag for supported key should be set."; | 
|  | 1534 | ASSERT_EQ(1, flags[1]) << "Flag for supported key should be set."; | 
|  | 1535 | ASSERT_EQ(0, flags[2]) << "Flag for unsupported key should be unchanged."; | 
|  | 1536 | ASSERT_EQ(1, flags[3]) << "Flag for unsupported key should be unchanged."; | 
|  | 1537 |  | 
|  | 1538 | // Event handling. | 
|  | 1539 | RawEvent event; | 
|  | 1540 | mDevice->process(&event, 1); | 
|  | 1541 |  | 
|  | 1542 | ASSERT_NO_FATAL_FAILURE(mapper1->assertProcessWasCalled()); | 
|  | 1543 | ASSERT_NO_FATAL_FAILURE(mapper2->assertProcessWasCalled()); | 
|  | 1544 | } | 
|  | 1545 |  | 
|  | 1546 |  | 
|  | 1547 | // --- InputMapperTest --- | 
|  | 1548 |  | 
|  | 1549 | class InputMapperTest : public testing::Test { | 
|  | 1550 | protected: | 
|  | 1551 | static const char* DEVICE_NAME; | 
|  | 1552 | static const int32_t DEVICE_ID; | 
|  | 1553 | static const int32_t DEVICE_GENERATION; | 
|  | 1554 | static const int32_t DEVICE_CONTROLLER_NUMBER; | 
|  | 1555 | static const uint32_t DEVICE_CLASSES; | 
|  | 1556 |  | 
|  | 1557 | sp<FakeEventHub> mFakeEventHub; | 
|  | 1558 | sp<FakeInputReaderPolicy> mFakePolicy; | 
|  | 1559 | sp<FakeInputListener> mFakeListener; | 
|  | 1560 | FakeInputReaderContext* mFakeContext; | 
|  | 1561 | InputDevice* mDevice; | 
|  | 1562 |  | 
|  | 1563 | virtual void SetUp() { | 
|  | 1564 | mFakeEventHub = new FakeEventHub(); | 
|  | 1565 | mFakePolicy = new FakeInputReaderPolicy(); | 
|  | 1566 | mFakeListener = new FakeInputListener(); | 
|  | 1567 | mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener); | 
|  | 1568 | InputDeviceIdentifier identifier; | 
|  | 1569 | identifier.name = DEVICE_NAME; | 
|  | 1570 | mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION, | 
|  | 1571 | DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES); | 
|  | 1572 |  | 
|  | 1573 | mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0); | 
|  | 1574 | } | 
|  | 1575 |  | 
|  | 1576 | virtual void TearDown() { | 
|  | 1577 | delete mDevice; | 
|  | 1578 | delete mFakeContext; | 
|  | 1579 | mFakeListener.clear(); | 
|  | 1580 | mFakePolicy.clear(); | 
|  | 1581 | mFakeEventHub.clear(); | 
|  | 1582 | } | 
|  | 1583 |  | 
|  | 1584 | void addConfigurationProperty(const char* key, const char* value) { | 
|  | 1585 | mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8(key), String8(value)); | 
|  | 1586 | } | 
|  | 1587 |  | 
| Vladislav Kaznacheev | 78f97b3 | 2016-12-15 18:14:58 -0800 | [diff] [blame] | 1588 | void configureDevice(uint32_t changes) { | 
|  | 1589 | mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), changes); | 
|  | 1590 | } | 
|  | 1591 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1592 | void addMapperAndConfigure(InputMapper* mapper) { | 
|  | 1593 | mDevice->addMapper(mapper); | 
| Vladislav Kaznacheev | 78f97b3 | 2016-12-15 18:14:58 -0800 | [diff] [blame] | 1594 | configureDevice(0); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1595 | mDevice->reset(ARBITRARY_TIME); | 
|  | 1596 | } | 
|  | 1597 |  | 
|  | 1598 | void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, | 
|  | 1599 | int32_t orientation) { | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 1600 | mFakePolicy->setDisplayViewport(displayId, width, height, orientation, String8::empty()); | 
|  | 1601 | configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); | 
|  | 1602 | } | 
|  | 1603 |  | 
|  | 1604 | void setVirtualDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, | 
|  | 1605 | int32_t orientation, const String8& uniqueId) { | 
|  | 1606 | mFakePolicy->setVirtualDisplayViewport(displayId, width, height, orientation, uniqueId); | 
| Vladislav Kaznacheev | 78f97b3 | 2016-12-15 18:14:58 -0800 | [diff] [blame] | 1607 | configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1608 | } | 
|  | 1609 |  | 
|  | 1610 | static void process(InputMapper* mapper, nsecs_t when, int32_t deviceId, int32_t type, | 
|  | 1611 | int32_t code, int32_t value) { | 
|  | 1612 | RawEvent event; | 
|  | 1613 | event.when = when; | 
|  | 1614 | event.deviceId = deviceId; | 
|  | 1615 | event.type = type; | 
|  | 1616 | event.code = code; | 
|  | 1617 | event.value = value; | 
|  | 1618 | mapper->process(&event); | 
|  | 1619 | } | 
|  | 1620 |  | 
|  | 1621 | static void assertMotionRange(const InputDeviceInfo& info, | 
|  | 1622 | int32_t axis, uint32_t source, float min, float max, float flat, float fuzz) { | 
|  | 1623 | const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source); | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 1624 | ASSERT_TRUE(range != nullptr) << "Axis: " << axis << " Source: " << source; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1625 | ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source; | 
|  | 1626 | ASSERT_EQ(source, range->source) << "Axis: " << axis << " Source: " << source; | 
|  | 1627 | ASSERT_NEAR(min, range->min, EPSILON) << "Axis: " << axis << " Source: " << source; | 
|  | 1628 | ASSERT_NEAR(max, range->max, EPSILON) << "Axis: " << axis << " Source: " << source; | 
|  | 1629 | ASSERT_NEAR(flat, range->flat, EPSILON) << "Axis: " << axis << " Source: " << source; | 
|  | 1630 | ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source; | 
|  | 1631 | } | 
|  | 1632 |  | 
|  | 1633 | static void assertPointerCoords(const PointerCoords& coords, | 
|  | 1634 | float x, float y, float pressure, float size, | 
|  | 1635 | float touchMajor, float touchMinor, float toolMajor, float toolMinor, | 
|  | 1636 | float orientation, float distance) { | 
|  | 1637 | ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), 1); | 
|  | 1638 | ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), 1); | 
|  | 1639 | ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON); | 
|  | 1640 | ASSERT_NEAR(size, coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE), EPSILON); | 
|  | 1641 | ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), 1); | 
|  | 1642 | ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), 1); | 
|  | 1643 | ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), 1); | 
|  | 1644 | ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), 1); | 
|  | 1645 | ASSERT_NEAR(orientation, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), EPSILON); | 
|  | 1646 | ASSERT_NEAR(distance, coords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), EPSILON); | 
|  | 1647 | } | 
|  | 1648 |  | 
|  | 1649 | static void assertPosition(const sp<FakePointerController>& controller, float x, float y) { | 
|  | 1650 | float actualX, actualY; | 
|  | 1651 | controller->getPosition(&actualX, &actualY); | 
|  | 1652 | ASSERT_NEAR(x, actualX, 1); | 
|  | 1653 | ASSERT_NEAR(y, actualY, 1); | 
|  | 1654 | } | 
|  | 1655 | }; | 
|  | 1656 |  | 
|  | 1657 | const char* InputMapperTest::DEVICE_NAME = "device"; | 
|  | 1658 | const int32_t InputMapperTest::DEVICE_ID = 1; | 
|  | 1659 | const int32_t InputMapperTest::DEVICE_GENERATION = 2; | 
|  | 1660 | const int32_t InputMapperTest::DEVICE_CONTROLLER_NUMBER = 0; | 
|  | 1661 | const uint32_t InputMapperTest::DEVICE_CLASSES = 0; // not needed for current tests | 
|  | 1662 |  | 
|  | 1663 |  | 
|  | 1664 | // --- SwitchInputMapperTest --- | 
|  | 1665 |  | 
|  | 1666 | class SwitchInputMapperTest : public InputMapperTest { | 
|  | 1667 | protected: | 
|  | 1668 | }; | 
|  | 1669 |  | 
|  | 1670 | TEST_F(SwitchInputMapperTest, GetSources) { | 
|  | 1671 | SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); | 
|  | 1672 | addMapperAndConfigure(mapper); | 
|  | 1673 |  | 
|  | 1674 | ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper->getSources()); | 
|  | 1675 | } | 
|  | 1676 |  | 
|  | 1677 | TEST_F(SwitchInputMapperTest, GetSwitchState) { | 
|  | 1678 | SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); | 
|  | 1679 | addMapperAndConfigure(mapper); | 
|  | 1680 |  | 
|  | 1681 | mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 1); | 
|  | 1682 | ASSERT_EQ(1, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); | 
|  | 1683 |  | 
|  | 1684 | mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 0); | 
|  | 1685 | ASSERT_EQ(0, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID)); | 
|  | 1686 | } | 
|  | 1687 |  | 
|  | 1688 | TEST_F(SwitchInputMapperTest, Process) { | 
|  | 1689 | SwitchInputMapper* mapper = new SwitchInputMapper(mDevice); | 
|  | 1690 | addMapperAndConfigure(mapper); | 
|  | 1691 |  | 
|  | 1692 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_LID, 1); | 
|  | 1693 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_JACK_PHYSICAL_INSERT, 1); | 
|  | 1694 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_HEADPHONE_INSERT, 0); | 
|  | 1695 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 1696 |  | 
|  | 1697 | NotifySwitchArgs args; | 
|  | 1698 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySwitchWasCalled(&args)); | 
|  | 1699 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
| Dan Albert | 1bd2fc0 | 2016-02-02 15:11:57 -0800 | [diff] [blame] | 1700 | ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT), args.switchValues); | 
|  | 1701 | ASSERT_EQ((1U << SW_LID) | (1U << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT), | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1702 | args.switchMask); | 
|  | 1703 | ASSERT_EQ(uint32_t(0), args.policyFlags); | 
|  | 1704 | } | 
|  | 1705 |  | 
|  | 1706 |  | 
|  | 1707 | // --- KeyboardInputMapperTest --- | 
|  | 1708 |  | 
|  | 1709 | class KeyboardInputMapperTest : public InputMapperTest { | 
|  | 1710 | protected: | 
|  | 1711 | void testDPadKeyRotation(KeyboardInputMapper* mapper, | 
|  | 1712 | int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode); | 
|  | 1713 | }; | 
|  | 1714 |  | 
|  | 1715 | void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper* mapper, | 
| Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 1716 | int32_t originalScanCode, int32_t, int32_t rotatedKeyCode) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1717 | NotifyKeyArgs args; | 
|  | 1718 |  | 
|  | 1719 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 1); | 
|  | 1720 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1721 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); | 
|  | 1722 | ASSERT_EQ(originalScanCode, args.scanCode); | 
|  | 1723 | ASSERT_EQ(rotatedKeyCode, args.keyCode); | 
|  | 1724 |  | 
|  | 1725 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 0); | 
|  | 1726 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1727 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); | 
|  | 1728 | ASSERT_EQ(originalScanCode, args.scanCode); | 
|  | 1729 | ASSERT_EQ(rotatedKeyCode, args.keyCode); | 
|  | 1730 | } | 
|  | 1731 |  | 
|  | 1732 |  | 
|  | 1733 | TEST_F(KeyboardInputMapperTest, GetSources) { | 
|  | 1734 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 1735 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 1736 | addMapperAndConfigure(mapper); | 
|  | 1737 |  | 
|  | 1738 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, mapper->getSources()); | 
|  | 1739 | } | 
|  | 1740 |  | 
|  | 1741 | TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) { | 
|  | 1742 | const int32_t USAGE_A = 0x070004; | 
|  | 1743 | const int32_t USAGE_UNKNOWN = 0x07ffff; | 
|  | 1744 | mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE); | 
|  | 1745 | mFakeEventHub->addKey(DEVICE_ID, 0, USAGE_A, AKEYCODE_A, POLICY_FLAG_WAKE); | 
|  | 1746 |  | 
|  | 1747 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 1748 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 1749 | addMapperAndConfigure(mapper); | 
|  | 1750 |  | 
|  | 1751 | // Key down by scan code. | 
|  | 1752 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1753 | EV_KEY, KEY_HOME, 1); | 
|  | 1754 | NotifyKeyArgs args; | 
|  | 1755 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1756 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 1757 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 1758 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 1759 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); | 
|  | 1760 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); | 
|  | 1761 | ASSERT_EQ(KEY_HOME, args.scanCode); | 
|  | 1762 | ASSERT_EQ(AMETA_NONE, args.metaState); | 
|  | 1763 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); | 
|  | 1764 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); | 
|  | 1765 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 1766 |  | 
|  | 1767 | // Key up by scan code. | 
|  | 1768 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, | 
|  | 1769 | EV_KEY, KEY_HOME, 0); | 
|  | 1770 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1771 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 1772 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 1773 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); | 
|  | 1774 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); | 
|  | 1775 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); | 
|  | 1776 | ASSERT_EQ(KEY_HOME, args.scanCode); | 
|  | 1777 | ASSERT_EQ(AMETA_NONE, args.metaState); | 
|  | 1778 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); | 
|  | 1779 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); | 
|  | 1780 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 1781 |  | 
|  | 1782 | // Key down by usage code. | 
|  | 1783 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1784 | EV_MSC, MSC_SCAN, USAGE_A); | 
|  | 1785 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1786 | EV_KEY, 0, 1); | 
|  | 1787 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1788 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 1789 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 1790 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 1791 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); | 
|  | 1792 | ASSERT_EQ(AKEYCODE_A, args.keyCode); | 
|  | 1793 | ASSERT_EQ(0, args.scanCode); | 
|  | 1794 | ASSERT_EQ(AMETA_NONE, args.metaState); | 
|  | 1795 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); | 
|  | 1796 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); | 
|  | 1797 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 1798 |  | 
|  | 1799 | // Key up by usage code. | 
|  | 1800 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1801 | EV_MSC, MSC_SCAN, USAGE_A); | 
|  | 1802 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, | 
|  | 1803 | EV_KEY, 0, 0); | 
|  | 1804 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1805 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 1806 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 1807 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); | 
|  | 1808 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); | 
|  | 1809 | ASSERT_EQ(AKEYCODE_A, args.keyCode); | 
|  | 1810 | ASSERT_EQ(0, args.scanCode); | 
|  | 1811 | ASSERT_EQ(AMETA_NONE, args.metaState); | 
|  | 1812 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); | 
|  | 1813 | ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); | 
|  | 1814 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 1815 |  | 
|  | 1816 | // Key down with unknown scan code or usage code. | 
|  | 1817 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1818 | EV_MSC, MSC_SCAN, USAGE_UNKNOWN); | 
|  | 1819 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1820 | EV_KEY, KEY_UNKNOWN, 1); | 
|  | 1821 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1822 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 1823 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 1824 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 1825 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); | 
|  | 1826 | ASSERT_EQ(0, args.keyCode); | 
|  | 1827 | ASSERT_EQ(KEY_UNKNOWN, args.scanCode); | 
|  | 1828 | ASSERT_EQ(AMETA_NONE, args.metaState); | 
|  | 1829 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); | 
|  | 1830 | ASSERT_EQ(0U, args.policyFlags); | 
|  | 1831 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 1832 |  | 
|  | 1833 | // Key up with unknown scan code or usage code. | 
|  | 1834 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1835 | EV_MSC, MSC_SCAN, USAGE_UNKNOWN); | 
|  | 1836 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, | 
|  | 1837 | EV_KEY, KEY_UNKNOWN, 0); | 
|  | 1838 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1839 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 1840 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 1841 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); | 
|  | 1842 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); | 
|  | 1843 | ASSERT_EQ(0, args.keyCode); | 
|  | 1844 | ASSERT_EQ(KEY_UNKNOWN, args.scanCode); | 
|  | 1845 | ASSERT_EQ(AMETA_NONE, args.metaState); | 
|  | 1846 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags); | 
|  | 1847 | ASSERT_EQ(0U, args.policyFlags); | 
|  | 1848 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 1849 | } | 
|  | 1850 |  | 
|  | 1851 | TEST_F(KeyboardInputMapperTest, Process_ShouldUpdateMetaState) { | 
|  | 1852 | mFakeEventHub->addKey(DEVICE_ID, KEY_LEFTSHIFT, 0, AKEYCODE_SHIFT_LEFT, 0); | 
|  | 1853 | mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0); | 
|  | 1854 |  | 
|  | 1855 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 1856 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 1857 | addMapperAndConfigure(mapper); | 
|  | 1858 |  | 
|  | 1859 | // Initial metastate. | 
|  | 1860 | ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); | 
|  | 1861 |  | 
|  | 1862 | // Metakey down. | 
|  | 1863 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 1864 | EV_KEY, KEY_LEFTSHIFT, 1); | 
|  | 1865 | NotifyKeyArgs args; | 
|  | 1866 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1867 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 1868 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); | 
|  | 1869 | ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled()); | 
|  | 1870 |  | 
|  | 1871 | // Key down. | 
|  | 1872 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, | 
|  | 1873 | EV_KEY, KEY_A, 1); | 
|  | 1874 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1875 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 1876 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); | 
|  | 1877 |  | 
|  | 1878 | // Key up. | 
|  | 1879 | process(mapper, ARBITRARY_TIME + 2, DEVICE_ID, | 
|  | 1880 | EV_KEY, KEY_A, 0); | 
|  | 1881 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1882 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 1883 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState()); | 
|  | 1884 |  | 
|  | 1885 | // Metakey up. | 
|  | 1886 | process(mapper, ARBITRARY_TIME + 3, DEVICE_ID, | 
|  | 1887 | EV_KEY, KEY_LEFTSHIFT, 0); | 
|  | 1888 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1889 | ASSERT_EQ(AMETA_NONE, args.metaState); | 
|  | 1890 | ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); | 
|  | 1891 | ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled()); | 
|  | 1892 | } | 
|  | 1893 |  | 
|  | 1894 | TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateDPad) { | 
|  | 1895 | mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0); | 
|  | 1896 | mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0); | 
|  | 1897 | mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0); | 
|  | 1898 | mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0); | 
|  | 1899 |  | 
|  | 1900 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 1901 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 1902 | addMapperAndConfigure(mapper); | 
|  | 1903 |  | 
|  | 1904 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 1905 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 1906 | DISPLAY_ORIENTATION_90); | 
|  | 1907 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1908 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP)); | 
|  | 1909 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1910 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT)); | 
|  | 1911 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1912 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN)); | 
|  | 1913 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1914 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT)); | 
|  | 1915 | } | 
|  | 1916 |  | 
|  | 1917 | TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { | 
|  | 1918 | mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0); | 
|  | 1919 | mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0); | 
|  | 1920 | mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0); | 
|  | 1921 | mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0); | 
|  | 1922 |  | 
|  | 1923 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 1924 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 1925 | addConfigurationProperty("keyboard.orientationAware", "1"); | 
|  | 1926 | addMapperAndConfigure(mapper); | 
|  | 1927 |  | 
|  | 1928 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 1929 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 1930 | DISPLAY_ORIENTATION_0); | 
|  | 1931 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1932 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP)); | 
|  | 1933 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1934 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT)); | 
|  | 1935 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1936 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN)); | 
|  | 1937 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1938 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT)); | 
|  | 1939 |  | 
|  | 1940 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 1941 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 1942 | DISPLAY_ORIENTATION_90); | 
|  | 1943 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1944 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT)); | 
|  | 1945 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1946 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP)); | 
|  | 1947 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1948 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT)); | 
|  | 1949 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1950 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN)); | 
|  | 1951 |  | 
|  | 1952 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 1953 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 1954 | DISPLAY_ORIENTATION_180); | 
|  | 1955 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1956 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN)); | 
|  | 1957 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1958 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_LEFT)); | 
|  | 1959 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1960 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_UP)); | 
|  | 1961 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1962 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_RIGHT)); | 
|  | 1963 |  | 
|  | 1964 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 1965 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 1966 | DISPLAY_ORIENTATION_270); | 
|  | 1967 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1968 | KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT)); | 
|  | 1969 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1970 | KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_DOWN)); | 
|  | 1971 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1972 | KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_LEFT)); | 
|  | 1973 | ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, | 
|  | 1974 | KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_UP)); | 
|  | 1975 |  | 
|  | 1976 | // Special case: if orientation changes while key is down, we still emit the same keycode | 
|  | 1977 | // in the key up as we did in the key down. | 
|  | 1978 | NotifyKeyArgs args; | 
|  | 1979 |  | 
|  | 1980 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 1981 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 1982 | DISPLAY_ORIENTATION_270); | 
|  | 1983 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1); | 
|  | 1984 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1985 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); | 
|  | 1986 | ASSERT_EQ(KEY_UP, args.scanCode); | 
|  | 1987 | ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode); | 
|  | 1988 |  | 
|  | 1989 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 1990 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 1991 | DISPLAY_ORIENTATION_180); | 
|  | 1992 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0); | 
|  | 1993 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 1994 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); | 
|  | 1995 | ASSERT_EQ(KEY_UP, args.scanCode); | 
|  | 1996 | ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode); | 
|  | 1997 | } | 
|  | 1998 |  | 
| Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 1999 | TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_NotOrientationAware) { | 
|  | 2000 | // If the keyboard is not orientation aware, | 
|  | 2001 | // key events should not be associated with a specific display id | 
|  | 2002 | mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0); | 
|  | 2003 |  | 
|  | 2004 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 2005 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 2006 | addMapperAndConfigure(mapper); | 
|  | 2007 | NotifyKeyArgs args; | 
|  | 2008 |  | 
|  | 2009 | // Display id should be ADISPLAY_ID_NONE without any display configuration. | 
|  | 2010 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1); | 
|  | 2011 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2012 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0); | 
|  | 2013 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2014 | ASSERT_EQ(ADISPLAY_ID_NONE, args.displayId); | 
|  | 2015 |  | 
|  | 2016 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 2017 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0); | 
|  | 2018 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1); | 
|  | 2019 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2020 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0); | 
|  | 2021 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2022 | ASSERT_EQ(ADISPLAY_ID_NONE, args.displayId); | 
|  | 2023 | } | 
|  | 2024 |  | 
|  | 2025 | TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) { | 
|  | 2026 | // If the keyboard is orientation aware, | 
|  | 2027 | // key events should be associated with the internal viewport | 
|  | 2028 | mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0); | 
|  | 2029 |  | 
|  | 2030 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 2031 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 2032 | addConfigurationProperty("keyboard.orientationAware", "1"); | 
|  | 2033 | addMapperAndConfigure(mapper); | 
|  | 2034 | NotifyKeyArgs args; | 
|  | 2035 |  | 
|  | 2036 | // Display id should be ADISPLAY_ID_NONE without any display configuration. | 
|  | 2037 | // ^--- already checked by the previous test | 
|  | 2038 |  | 
|  | 2039 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 2040 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0); | 
|  | 2041 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1); | 
|  | 2042 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2043 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0); | 
|  | 2044 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2045 | ASSERT_EQ(DISPLAY_ID, args.displayId); | 
|  | 2046 |  | 
|  | 2047 | constexpr int32_t newDisplayId = 2; | 
|  | 2048 | setDisplayInfoAndReconfigure(newDisplayId, | 
|  | 2049 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0); | 
|  | 2050 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1); | 
|  | 2051 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2052 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0); | 
|  | 2053 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 2054 | ASSERT_EQ(newDisplayId, args.displayId); | 
|  | 2055 | } | 
|  | 2056 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2057 | TEST_F(KeyboardInputMapperTest, GetKeyCodeState) { | 
|  | 2058 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 2059 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 2060 | addMapperAndConfigure(mapper); | 
|  | 2061 |  | 
|  | 2062 | mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 1); | 
|  | 2063 | ASSERT_EQ(1, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); | 
|  | 2064 |  | 
|  | 2065 | mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 0); | 
|  | 2066 | ASSERT_EQ(0, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); | 
|  | 2067 | } | 
|  | 2068 |  | 
|  | 2069 | TEST_F(KeyboardInputMapperTest, GetScanCodeState) { | 
|  | 2070 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 2071 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 2072 | addMapperAndConfigure(mapper); | 
|  | 2073 |  | 
|  | 2074 | mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 1); | 
|  | 2075 | ASSERT_EQ(1, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); | 
|  | 2076 |  | 
|  | 2077 | mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 0); | 
|  | 2078 | ASSERT_EQ(0, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); | 
|  | 2079 | } | 
|  | 2080 |  | 
|  | 2081 | TEST_F(KeyboardInputMapperTest, MarkSupportedKeyCodes) { | 
|  | 2082 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 2083 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 2084 | addMapperAndConfigure(mapper); | 
|  | 2085 |  | 
|  | 2086 | mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0); | 
|  | 2087 |  | 
|  | 2088 | const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B }; | 
|  | 2089 | uint8_t flags[2] = { 0, 0 }; | 
|  | 2090 | ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 1, keyCodes, flags)); | 
|  | 2091 | ASSERT_TRUE(flags[0]); | 
|  | 2092 | ASSERT_FALSE(flags[1]); | 
|  | 2093 | } | 
|  | 2094 |  | 
|  | 2095 | TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleMetaStateAndLeds) { | 
|  | 2096 | mFakeEventHub->addLed(DEVICE_ID, LED_CAPSL, true /*initially on*/); | 
|  | 2097 | mFakeEventHub->addLed(DEVICE_ID, LED_NUML, false /*initially off*/); | 
|  | 2098 | mFakeEventHub->addLed(DEVICE_ID, LED_SCROLLL, false /*initially off*/); | 
|  | 2099 | mFakeEventHub->addKey(DEVICE_ID, KEY_CAPSLOCK, 0, AKEYCODE_CAPS_LOCK, 0); | 
|  | 2100 | mFakeEventHub->addKey(DEVICE_ID, KEY_NUMLOCK, 0, AKEYCODE_NUM_LOCK, 0); | 
|  | 2101 | mFakeEventHub->addKey(DEVICE_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0); | 
|  | 2102 |  | 
|  | 2103 | KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, | 
|  | 2104 | AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); | 
|  | 2105 | addMapperAndConfigure(mapper); | 
|  | 2106 |  | 
|  | 2107 | // Initialization should have turned all of the lights off. | 
|  | 2108 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); | 
|  | 2109 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); | 
|  | 2110 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); | 
|  | 2111 |  | 
|  | 2112 | // Toggle caps lock on. | 
|  | 2113 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2114 | EV_KEY, KEY_CAPSLOCK, 1); | 
|  | 2115 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2116 | EV_KEY, KEY_CAPSLOCK, 0); | 
|  | 2117 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); | 
|  | 2118 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); | 
|  | 2119 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); | 
|  | 2120 | ASSERT_EQ(AMETA_CAPS_LOCK_ON, mapper->getMetaState()); | 
|  | 2121 |  | 
|  | 2122 | // Toggle num lock on. | 
|  | 2123 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2124 | EV_KEY, KEY_NUMLOCK, 1); | 
|  | 2125 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2126 | EV_KEY, KEY_NUMLOCK, 0); | 
|  | 2127 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); | 
|  | 2128 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); | 
|  | 2129 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); | 
|  | 2130 | ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON, mapper->getMetaState()); | 
|  | 2131 |  | 
|  | 2132 | // Toggle caps lock off. | 
|  | 2133 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2134 | EV_KEY, KEY_CAPSLOCK, 1); | 
|  | 2135 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2136 | EV_KEY, KEY_CAPSLOCK, 0); | 
|  | 2137 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); | 
|  | 2138 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); | 
|  | 2139 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); | 
|  | 2140 | ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper->getMetaState()); | 
|  | 2141 |  | 
|  | 2142 | // Toggle scroll lock on. | 
|  | 2143 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2144 | EV_KEY, KEY_SCROLLLOCK, 1); | 
|  | 2145 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2146 | EV_KEY, KEY_SCROLLLOCK, 0); | 
|  | 2147 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); | 
|  | 2148 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); | 
|  | 2149 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); | 
|  | 2150 | ASSERT_EQ(AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON, mapper->getMetaState()); | 
|  | 2151 |  | 
|  | 2152 | // Toggle num lock off. | 
|  | 2153 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2154 | EV_KEY, KEY_NUMLOCK, 1); | 
|  | 2155 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2156 | EV_KEY, KEY_NUMLOCK, 0); | 
|  | 2157 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); | 
|  | 2158 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); | 
|  | 2159 | ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); | 
|  | 2160 | ASSERT_EQ(AMETA_SCROLL_LOCK_ON, mapper->getMetaState()); | 
|  | 2161 |  | 
|  | 2162 | // Toggle scroll lock off. | 
|  | 2163 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2164 | EV_KEY, KEY_SCROLLLOCK, 1); | 
|  | 2165 | process(mapper, ARBITRARY_TIME, DEVICE_ID, | 
|  | 2166 | EV_KEY, KEY_SCROLLLOCK, 0); | 
|  | 2167 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL)); | 
|  | 2168 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML)); | 
|  | 2169 | ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL)); | 
|  | 2170 | ASSERT_EQ(AMETA_NONE, mapper->getMetaState()); | 
|  | 2171 | } | 
|  | 2172 |  | 
|  | 2173 |  | 
|  | 2174 | // --- CursorInputMapperTest --- | 
|  | 2175 |  | 
|  | 2176 | class CursorInputMapperTest : public InputMapperTest { | 
|  | 2177 | protected: | 
|  | 2178 | static const int32_t TRACKBALL_MOVEMENT_THRESHOLD; | 
|  | 2179 |  | 
|  | 2180 | sp<FakePointerController> mFakePointerController; | 
|  | 2181 |  | 
|  | 2182 | virtual void SetUp() { | 
|  | 2183 | InputMapperTest::SetUp(); | 
|  | 2184 |  | 
|  | 2185 | mFakePointerController = new FakePointerController(); | 
|  | 2186 | mFakePolicy->setPointerController(DEVICE_ID, mFakePointerController); | 
|  | 2187 | } | 
|  | 2188 |  | 
|  | 2189 | void testMotionRotation(CursorInputMapper* mapper, | 
|  | 2190 | int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY); | 
|  | 2191 | }; | 
|  | 2192 |  | 
|  | 2193 | const int32_t CursorInputMapperTest::TRACKBALL_MOVEMENT_THRESHOLD = 6; | 
|  | 2194 |  | 
|  | 2195 | void CursorInputMapperTest::testMotionRotation(CursorInputMapper* mapper, | 
|  | 2196 | int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY) { | 
|  | 2197 | NotifyMotionArgs args; | 
|  | 2198 |  | 
|  | 2199 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, originalX); | 
|  | 2200 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, originalY); | 
|  | 2201 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2202 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2203 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); | 
|  | 2204 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2205 | float(rotatedX) / TRACKBALL_MOVEMENT_THRESHOLD, | 
|  | 2206 | float(rotatedY) / TRACKBALL_MOVEMENT_THRESHOLD, | 
|  | 2207 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2208 | } | 
|  | 2209 |  | 
|  | 2210 | TEST_F(CursorInputMapperTest, WhenModeIsPointer_GetSources_ReturnsMouse) { | 
|  | 2211 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2212 | addConfigurationProperty("cursor.mode", "pointer"); | 
|  | 2213 | addMapperAndConfigure(mapper); | 
|  | 2214 |  | 
|  | 2215 | ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources()); | 
|  | 2216 | } | 
|  | 2217 |  | 
|  | 2218 | TEST_F(CursorInputMapperTest, WhenModeIsNavigation_GetSources_ReturnsTrackball) { | 
|  | 2219 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2220 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2221 | addMapperAndConfigure(mapper); | 
|  | 2222 |  | 
|  | 2223 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, mapper->getSources()); | 
|  | 2224 | } | 
|  | 2225 |  | 
|  | 2226 | TEST_F(CursorInputMapperTest, WhenModeIsPointer_PopulateDeviceInfo_ReturnsRangeFromPointerController) { | 
|  | 2227 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2228 | addConfigurationProperty("cursor.mode", "pointer"); | 
|  | 2229 | addMapperAndConfigure(mapper); | 
|  | 2230 |  | 
|  | 2231 | InputDeviceInfo info; | 
|  | 2232 | mapper->populateDeviceInfo(&info); | 
|  | 2233 |  | 
|  | 2234 | // Initially there may not be a valid motion range. | 
| Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 2235 | ASSERT_EQ(nullptr, info.getMotionRange(AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE)); | 
|  | 2236 | ASSERT_EQ(nullptr, info.getMotionRange(AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2237 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, | 
|  | 2238 | AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, 0.0f, 1.0f, 0.0f, 0.0f)); | 
|  | 2239 |  | 
|  | 2240 | // When the bounds are set, then there should be a valid motion range. | 
|  | 2241 | mFakePointerController->setBounds(1, 2, 800 - 1, 480 - 1); | 
|  | 2242 |  | 
|  | 2243 | InputDeviceInfo info2; | 
|  | 2244 | mapper->populateDeviceInfo(&info2); | 
|  | 2245 |  | 
|  | 2246 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, | 
|  | 2247 | AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE, | 
|  | 2248 | 1, 800 - 1, 0.0f, 0.0f)); | 
|  | 2249 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, | 
|  | 2250 | AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE, | 
|  | 2251 | 2, 480 - 1, 0.0f, 0.0f)); | 
|  | 2252 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2, | 
|  | 2253 | AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, | 
|  | 2254 | 0.0f, 1.0f, 0.0f, 0.0f)); | 
|  | 2255 | } | 
|  | 2256 |  | 
|  | 2257 | TEST_F(CursorInputMapperTest, WhenModeIsNavigation_PopulateDeviceInfo_ReturnsScaledRange) { | 
|  | 2258 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2259 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2260 | addMapperAndConfigure(mapper); | 
|  | 2261 |  | 
|  | 2262 | InputDeviceInfo info; | 
|  | 2263 | mapper->populateDeviceInfo(&info); | 
|  | 2264 |  | 
|  | 2265 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, | 
|  | 2266 | AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_TRACKBALL, | 
|  | 2267 | -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD)); | 
|  | 2268 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, | 
|  | 2269 | AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_TRACKBALL, | 
|  | 2270 | -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD)); | 
|  | 2271 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, | 
|  | 2272 | AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TRACKBALL, | 
|  | 2273 | 0.0f, 1.0f, 0.0f, 0.0f)); | 
|  | 2274 | } | 
|  | 2275 |  | 
|  | 2276 | TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaState) { | 
|  | 2277 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2278 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2279 | addMapperAndConfigure(mapper); | 
|  | 2280 |  | 
|  | 2281 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 2282 |  | 
|  | 2283 | NotifyMotionArgs args; | 
|  | 2284 |  | 
|  | 2285 | // Button press. | 
|  | 2286 | // Mostly testing non x/y behavior here so we don't need to check again elsewhere. | 
|  | 2287 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1); | 
|  | 2288 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2289 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2290 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 2291 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 2292 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); | 
|  | 2293 | ASSERT_EQ(uint32_t(0), args.policyFlags); | 
|  | 2294 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); | 
|  | 2295 | ASSERT_EQ(0, args.flags); | 
|  | 2296 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 2297 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, args.buttonState); | 
|  | 2298 | ASSERT_EQ(0, args.edgeFlags); | 
|  | 2299 | ASSERT_EQ(uint32_t(1), args.pointerCount); | 
|  | 2300 | ASSERT_EQ(0, args.pointerProperties[0].id); | 
|  | 2301 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); | 
|  | 2302 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2303 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2304 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); | 
|  | 2305 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); | 
|  | 2306 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 2307 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2308 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2309 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 2310 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 2311 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); | 
|  | 2312 | ASSERT_EQ(uint32_t(0), args.policyFlags); | 
|  | 2313 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, args.action); | 
|  | 2314 | ASSERT_EQ(0, args.flags); | 
|  | 2315 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 2316 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, args.buttonState); | 
|  | 2317 | ASSERT_EQ(0, args.edgeFlags); | 
|  | 2318 | ASSERT_EQ(uint32_t(1), args.pointerCount); | 
|  | 2319 | ASSERT_EQ(0, args.pointerProperties[0].id); | 
|  | 2320 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); | 
|  | 2321 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2322 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2323 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); | 
|  | 2324 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); | 
|  | 2325 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 2326 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2327 | // Button release.  Should have same down time. | 
|  | 2328 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_KEY, BTN_MOUSE, 0); | 
|  | 2329 | process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2330 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2331 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); | 
|  | 2332 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 2333 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); | 
|  | 2334 | ASSERT_EQ(uint32_t(0), args.policyFlags); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2335 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action); | 
|  | 2336 | ASSERT_EQ(0, args.flags); | 
|  | 2337 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 2338 | ASSERT_EQ(0, args.buttonState); | 
|  | 2339 | ASSERT_EQ(0, args.edgeFlags); | 
|  | 2340 | ASSERT_EQ(uint32_t(1), args.pointerCount); | 
|  | 2341 | ASSERT_EQ(0, args.pointerProperties[0].id); | 
|  | 2342 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); | 
|  | 2343 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2344 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2345 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); | 
|  | 2346 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); | 
|  | 2347 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 2348 |  | 
|  | 2349 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2350 | ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime); | 
|  | 2351 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 2352 | ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source); | 
|  | 2353 | ASSERT_EQ(uint32_t(0), args.policyFlags); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2354 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); | 
|  | 2355 | ASSERT_EQ(0, args.flags); | 
|  | 2356 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 2357 | ASSERT_EQ(0, args.buttonState); | 
|  | 2358 | ASSERT_EQ(0, args.edgeFlags); | 
|  | 2359 | ASSERT_EQ(uint32_t(1), args.pointerCount); | 
|  | 2360 | ASSERT_EQ(0, args.pointerProperties[0].id); | 
|  | 2361 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); | 
|  | 2362 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2363 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2364 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); | 
|  | 2365 | ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); | 
|  | 2366 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 2367 | } | 
|  | 2368 |  | 
|  | 2369 | TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) { | 
|  | 2370 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2371 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2372 | addMapperAndConfigure(mapper); | 
|  | 2373 |  | 
|  | 2374 | NotifyMotionArgs args; | 
|  | 2375 |  | 
|  | 2376 | // Motion in X but not Y. | 
|  | 2377 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1); | 
|  | 2378 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2379 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2380 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); | 
|  | 2381 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2382 | 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2383 |  | 
|  | 2384 | // Motion in Y but not X. | 
|  | 2385 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2); | 
|  | 2386 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2387 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2388 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); | 
|  | 2389 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2390 | 0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2391 | } | 
|  | 2392 |  | 
|  | 2393 | TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentButtonUpdates) { | 
|  | 2394 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2395 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2396 | addMapperAndConfigure(mapper); | 
|  | 2397 |  | 
|  | 2398 | NotifyMotionArgs args; | 
|  | 2399 |  | 
|  | 2400 | // Button press. | 
|  | 2401 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1); | 
|  | 2402 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2403 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2404 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); | 
|  | 2405 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2406 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2407 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2408 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2409 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, args.action); | 
|  | 2410 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2411 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2412 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2413 | // Button release. | 
|  | 2414 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0); | 
|  | 2415 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2416 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2417 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action); | 
|  | 2418 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2419 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2420 |  | 
|  | 2421 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2422 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); | 
|  | 2423 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2424 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2425 | } | 
|  | 2426 |  | 
|  | 2427 | TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) { | 
|  | 2428 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2429 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2430 | addMapperAndConfigure(mapper); | 
|  | 2431 |  | 
|  | 2432 | NotifyMotionArgs args; | 
|  | 2433 |  | 
|  | 2434 | // Combined X, Y and Button. | 
|  | 2435 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1); | 
|  | 2436 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2); | 
|  | 2437 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1); | 
|  | 2438 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2439 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2440 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); | 
|  | 2441 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2442 | 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, | 
|  | 2443 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2444 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2445 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2446 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, args.action); | 
|  | 2447 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2448 | 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, | 
|  | 2449 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2450 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2451 | // Move X, Y a bit while pressed. | 
|  | 2452 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 2); | 
|  | 2453 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 1); | 
|  | 2454 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2455 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2456 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); | 
|  | 2457 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2458 | 2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD, | 
|  | 2459 | 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2460 |  | 
|  | 2461 | // Release Button. | 
|  | 2462 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0); | 
|  | 2463 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2464 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2465 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action); | 
|  | 2466 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2467 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2468 |  | 
|  | 2469 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2470 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); | 
|  | 2471 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2472 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2473 | } | 
|  | 2474 |  | 
|  | 2475 | TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateMotions) { | 
|  | 2476 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2477 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2478 | addMapperAndConfigure(mapper); | 
|  | 2479 |  | 
|  | 2480 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 2481 | DISPLAY_WIDTH, DISPLAY_HEIGHT, | 
|  | 2482 | DISPLAY_ORIENTATION_90); | 
|  | 2483 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0,  1)); | 
|  | 2484 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1,  1)); | 
|  | 2485 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  1,  0)); | 
|  | 2486 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1, -1)); | 
|  | 2487 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0, -1)); | 
|  | 2488 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1)); | 
|  | 2489 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0, -1,  0)); | 
|  | 2490 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1,  1)); | 
|  | 2491 | } | 
|  | 2492 |  | 
|  | 2493 | TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions) { | 
|  | 2494 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2495 | addConfigurationProperty("cursor.mode", "navigation"); | 
|  | 2496 | addConfigurationProperty("cursor.orientationAware", "1"); | 
|  | 2497 | addMapperAndConfigure(mapper); | 
|  | 2498 |  | 
|  | 2499 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 2500 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0); | 
|  | 2501 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0,  1)); | 
|  | 2502 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1,  1)); | 
|  | 2503 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  1,  0)); | 
|  | 2504 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1, -1)); | 
|  | 2505 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0, -1)); | 
|  | 2506 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1)); | 
|  | 2507 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0, -1,  0)); | 
|  | 2508 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1,  1)); | 
|  | 2509 |  | 
|  | 2510 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 2511 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_90); | 
|  | 2512 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  1,  0)); | 
|  | 2513 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1, -1)); | 
|  | 2514 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  0, -1)); | 
|  | 2515 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1, -1, -1)); | 
|  | 2516 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1, -1,  0)); | 
|  | 2517 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1,  1)); | 
|  | 2518 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  0,  1)); | 
|  | 2519 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1,  1,  1)); | 
|  | 2520 |  | 
|  | 2521 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 2522 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_180); | 
|  | 2523 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0, -1)); | 
|  | 2524 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1, -1, -1)); | 
|  | 2525 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0, -1,  0)); | 
|  | 2526 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1, -1,  1)); | 
|  | 2527 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0,  1)); | 
|  | 2528 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1,  1,  1)); | 
|  | 2529 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  1,  0)); | 
|  | 2530 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1,  1, -1)); | 
|  | 2531 |  | 
|  | 2532 | setDisplayInfoAndReconfigure(DISPLAY_ID, | 
|  | 2533 | DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_270); | 
|  | 2534 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1, -1,  0)); | 
|  | 2535 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1, -1,  1)); | 
|  | 2536 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  0,  1)); | 
|  | 2537 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1,  1)); | 
|  | 2538 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  1,  0)); | 
|  | 2539 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1,  1, -1)); | 
|  | 2540 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  0, -1)); | 
|  | 2541 | ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1, -1)); | 
|  | 2542 | } | 
|  | 2543 |  | 
|  | 2544 | TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) { | 
|  | 2545 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2546 | addConfigurationProperty("cursor.mode", "pointer"); | 
|  | 2547 | addMapperAndConfigure(mapper); | 
|  | 2548 |  | 
|  | 2549 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); | 
|  | 2550 | mFakePointerController->setPosition(100, 200); | 
|  | 2551 | mFakePointerController->setButtonState(0); | 
|  | 2552 |  | 
|  | 2553 | NotifyMotionArgs motionArgs; | 
|  | 2554 | NotifyKeyArgs keyArgs; | 
|  | 2555 |  | 
|  | 2556 | // press BTN_LEFT, release BTN_LEFT | 
|  | 2557 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 1); | 
|  | 2558 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2559 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2560 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 2561 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); | 
|  | 2562 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, mFakePointerController->getButtonState()); | 
|  | 2563 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2564 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2565 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2566 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2567 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 2568 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); | 
|  | 2569 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, mFakePointerController->getButtonState()); | 
|  | 2570 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2571 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2572 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2573 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 0); | 
|  | 2574 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2575 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2576 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2577 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2578 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2579 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2580 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2581 |  | 
|  | 2582 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2583 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2584 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2585 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2586 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2587 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2588 |  | 
|  | 2589 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2590 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2591 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2592 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2593 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2594 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2595 |  | 
|  | 2596 | // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE | 
|  | 2597 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 1); | 
|  | 2598 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 1); | 
|  | 2599 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2600 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2601 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 2602 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 2603 | motionArgs.buttonState); | 
|  | 2604 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 2605 | mFakePointerController->getButtonState()); | 
|  | 2606 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2607 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2608 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2609 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2610 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 2611 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
|  | 2612 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 2613 | mFakePointerController->getButtonState()); | 
|  | 2614 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2615 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2616 |  | 
|  | 2617 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2618 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 2619 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 2620 | motionArgs.buttonState); | 
|  | 2621 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 2622 | mFakePointerController->getButtonState()); | 
|  | 2623 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2624 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2625 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2626 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 0); | 
|  | 2627 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2628 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2629 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2630 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
|  | 2631 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, mFakePointerController->getButtonState()); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2632 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2633 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2634 |  | 
|  | 2635 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2636 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2637 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
|  | 2638 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2639 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2640 | 100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2641 |  | 
|  | 2642 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 0); | 
|  | 2643 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2644 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2645 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
|  | 2646 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2647 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
|  | 2648 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2649 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2650 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 0); | 
|  | 2651 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2652 |  | 
|  | 2653 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2654 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2655 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
|  | 2656 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 2657 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2658 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2659 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2660 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2661 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2662 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
|  | 2663 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 2664 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2665 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2666 |  | 
|  | 2667 | // press BTN_BACK, release BTN_BACK | 
|  | 2668 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 1); | 
|  | 2669 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2670 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2671 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 2672 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2673 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2674 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2675 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2676 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 2677 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState()); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2678 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2679 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2680 |  | 
|  | 2681 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2682 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 2683 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 2684 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2685 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2686 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2687 |  | 
|  | 2688 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 0); | 
|  | 2689 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2690 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2691 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2692 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2693 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2694 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2695 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2696 |  | 
|  | 2697 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2698 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2699 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2700 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
|  | 2701 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2702 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2703 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2704 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2705 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 2706 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
|  | 2707 |  | 
|  | 2708 | // press BTN_SIDE, release BTN_SIDE | 
|  | 2709 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 1); | 
|  | 2710 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2711 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2712 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 2713 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2714 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2715 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2716 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2717 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 2718 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState()); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2719 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2720 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2721 |  | 
|  | 2722 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2723 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 2724 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 2725 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2726 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2727 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2728 |  | 
|  | 2729 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 0); | 
|  | 2730 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2731 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2732 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2733 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2734 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2735 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2736 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2737 |  | 
|  | 2738 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2739 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 2740 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2741 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
|  | 2742 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2743 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2744 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2745 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2746 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 2747 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
|  | 2748 |  | 
|  | 2749 | // press BTN_FORWARD, release BTN_FORWARD | 
|  | 2750 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 1); | 
|  | 2751 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2752 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2753 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 2754 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2755 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2756 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2757 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2758 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 2759 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState()); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2760 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2761 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2762 |  | 
|  | 2763 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2764 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 2765 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 2766 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2767 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2768 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2769 |  | 
|  | 2770 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 0); | 
|  | 2771 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2772 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2773 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2774 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2775 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2776 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2777 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2778 |  | 
|  | 2779 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2780 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 2781 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2782 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
|  | 2783 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2784 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2785 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2786 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2787 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 2788 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
|  | 2789 |  | 
|  | 2790 | // press BTN_EXTRA, release BTN_EXTRA | 
|  | 2791 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 1); | 
|  | 2792 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2793 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2794 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 2795 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2796 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2797 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2798 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2799 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 2800 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState()); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2801 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2802 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2803 |  | 
|  | 2804 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2805 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 2806 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 2807 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2808 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2809 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2810 |  | 
|  | 2811 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 0); | 
|  | 2812 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2813 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2814 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2815 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2816 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2817 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2818 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 2819 |  | 
|  | 2820 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 2821 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 2822 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 2823 | ASSERT_EQ(0, mFakePointerController->getButtonState()); | 
|  | 2824 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 2825 | 100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2826 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2827 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 2828 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 2829 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
|  | 2830 | } | 
|  | 2831 |  | 
|  | 2832 | TEST_F(CursorInputMapperTest, Process_WhenModeIsPointer_ShouldMoveThePointerAround) { | 
|  | 2833 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2834 | addConfigurationProperty("cursor.mode", "pointer"); | 
|  | 2835 | addMapperAndConfigure(mapper); | 
|  | 2836 |  | 
|  | 2837 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); | 
|  | 2838 | mFakePointerController->setPosition(100, 200); | 
|  | 2839 | mFakePointerController->setButtonState(0); | 
|  | 2840 |  | 
|  | 2841 | NotifyMotionArgs args; | 
|  | 2842 |  | 
|  | 2843 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 10); | 
|  | 2844 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 20); | 
|  | 2845 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2846 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
| Vladislav Kaznacheev | 78f97b3 | 2016-12-15 18:14:58 -0800 | [diff] [blame] | 2847 | ASSERT_EQ(AINPUT_SOURCE_MOUSE, args.source); | 
|  | 2848 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action); | 
|  | 2849 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2850 | 110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2851 | ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f)); | 
|  | 2852 | } | 
|  | 2853 |  | 
|  | 2854 | TEST_F(CursorInputMapperTest, Process_PointerCapture) { | 
|  | 2855 | CursorInputMapper* mapper = new CursorInputMapper(mDevice); | 
|  | 2856 | addConfigurationProperty("cursor.mode", "pointer"); | 
|  | 2857 | mFakePolicy->setPointerCapture(true); | 
|  | 2858 | addMapperAndConfigure(mapper); | 
|  | 2859 |  | 
|  | 2860 | NotifyDeviceResetArgs resetArgs; | 
|  | 2861 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs)); | 
|  | 2862 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); | 
|  | 2863 | ASSERT_EQ(DEVICE_ID, resetArgs.deviceId); | 
|  | 2864 |  | 
|  | 2865 | mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); | 
|  | 2866 | mFakePointerController->setPosition(100, 200); | 
|  | 2867 | mFakePointerController->setButtonState(0); | 
|  | 2868 |  | 
|  | 2869 | NotifyMotionArgs args; | 
|  | 2870 |  | 
|  | 2871 | // Move. | 
|  | 2872 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 10); | 
|  | 2873 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 20); | 
|  | 2874 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2875 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2876 | ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source); | 
|  | 2877 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); | 
|  | 2878 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2879 | 10.0f, 20.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2880 | ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 100.0f, 200.0f)); | 
|  | 2881 |  | 
|  | 2882 | // Button press. | 
|  | 2883 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1); | 
|  | 2884 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2885 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2886 | ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source); | 
|  | 2887 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); | 
|  | 2888 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2889 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2890 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2891 | ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source); | 
|  | 2892 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, args.action); | 
|  | 2893 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2894 | 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2895 |  | 
|  | 2896 | // Button release. | 
|  | 2897 | process(mapper, ARBITRARY_TIME + 2, DEVICE_ID, EV_KEY, BTN_MOUSE, 0); | 
|  | 2898 | process(mapper, ARBITRARY_TIME + 2, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2899 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2900 | ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source); | 
|  | 2901 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, args.action); | 
|  | 2902 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2903 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2904 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2905 | ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source); | 
|  | 2906 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action); | 
|  | 2907 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2908 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2909 |  | 
|  | 2910 | // Another move. | 
|  | 2911 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 30); | 
|  | 2912 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 40); | 
|  | 2913 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2914 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2915 | ASSERT_EQ(AINPUT_SOURCE_MOUSE_RELATIVE, args.source); | 
|  | 2916 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); | 
|  | 2917 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2918 | 30.0f, 40.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2919 | ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 100.0f, 200.0f)); | 
|  | 2920 |  | 
|  | 2921 | // Disable pointer capture and check that the device generation got bumped | 
|  | 2922 | // and events are generated the usual way. | 
|  | 2923 | const uint32_t generation = mFakeContext->getGeneration(); | 
|  | 2924 | mFakePolicy->setPointerCapture(false); | 
|  | 2925 | configureDevice(InputReaderConfiguration::CHANGE_POINTER_CAPTURE); | 
|  | 2926 | ASSERT_TRUE(mFakeContext->getGeneration() != generation); | 
|  | 2927 |  | 
|  | 2928 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs)); | 
|  | 2929 | ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime); | 
|  | 2930 | ASSERT_EQ(DEVICE_ID, resetArgs.deviceId); | 
|  | 2931 |  | 
|  | 2932 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 10); | 
|  | 2933 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 20); | 
|  | 2934 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 2935 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 2936 | ASSERT_EQ(AINPUT_SOURCE_MOUSE, args.source); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2937 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action); | 
|  | 2938 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 2939 | 110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); | 
|  | 2940 | ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f)); | 
|  | 2941 | } | 
|  | 2942 |  | 
|  | 2943 |  | 
|  | 2944 | // --- TouchInputMapperTest --- | 
|  | 2945 |  | 
|  | 2946 | class TouchInputMapperTest : public InputMapperTest { | 
|  | 2947 | protected: | 
|  | 2948 | static const int32_t RAW_X_MIN; | 
|  | 2949 | static const int32_t RAW_X_MAX; | 
|  | 2950 | static const int32_t RAW_Y_MIN; | 
|  | 2951 | static const int32_t RAW_Y_MAX; | 
|  | 2952 | static const int32_t RAW_TOUCH_MIN; | 
|  | 2953 | static const int32_t RAW_TOUCH_MAX; | 
|  | 2954 | static const int32_t RAW_TOOL_MIN; | 
|  | 2955 | static const int32_t RAW_TOOL_MAX; | 
|  | 2956 | static const int32_t RAW_PRESSURE_MIN; | 
|  | 2957 | static const int32_t RAW_PRESSURE_MAX; | 
|  | 2958 | static const int32_t RAW_ORIENTATION_MIN; | 
|  | 2959 | static const int32_t RAW_ORIENTATION_MAX; | 
|  | 2960 | static const int32_t RAW_DISTANCE_MIN; | 
|  | 2961 | static const int32_t RAW_DISTANCE_MAX; | 
|  | 2962 | static const int32_t RAW_TILT_MIN; | 
|  | 2963 | static const int32_t RAW_TILT_MAX; | 
|  | 2964 | static const int32_t RAW_ID_MIN; | 
|  | 2965 | static const int32_t RAW_ID_MAX; | 
|  | 2966 | static const int32_t RAW_SLOT_MIN; | 
|  | 2967 | static const int32_t RAW_SLOT_MAX; | 
|  | 2968 | static const float X_PRECISION; | 
|  | 2969 | static const float Y_PRECISION; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 2970 | static const float X_PRECISION_VIRTUAL; | 
|  | 2971 | static const float Y_PRECISION_VIRTUAL; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2972 |  | 
|  | 2973 | static const float GEOMETRIC_SCALE; | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 2974 | static const TouchAffineTransformation AFFINE_TRANSFORM; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2975 |  | 
|  | 2976 | static const VirtualKeyDefinition VIRTUAL_KEYS[2]; | 
|  | 2977 |  | 
|  | 2978 | enum Axes { | 
|  | 2979 | POSITION = 1 << 0, | 
|  | 2980 | TOUCH = 1 << 1, | 
|  | 2981 | TOOL = 1 << 2, | 
|  | 2982 | PRESSURE = 1 << 3, | 
|  | 2983 | ORIENTATION = 1 << 4, | 
|  | 2984 | MINOR = 1 << 5, | 
|  | 2985 | ID = 1 << 6, | 
|  | 2986 | DISTANCE = 1 << 7, | 
|  | 2987 | TILT = 1 << 8, | 
|  | 2988 | SLOT = 1 << 9, | 
|  | 2989 | TOOL_TYPE = 1 << 10, | 
|  | 2990 | }; | 
|  | 2991 |  | 
|  | 2992 | void prepareDisplay(int32_t orientation); | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 2993 | void prepareVirtualDisplay(int32_t orientation); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2994 | void prepareVirtualKeys(); | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 2995 | void prepareLocationCalibration(); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 2996 | int32_t toRawX(float displayX); | 
|  | 2997 | int32_t toRawY(float displayY); | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 2998 | float toCookedX(float rawX, float rawY); | 
|  | 2999 | float toCookedY(float rawX, float rawY); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3000 | float toDisplayX(int32_t rawX); | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 3001 | float toDisplayX(int32_t rawX, int32_t displayWidth); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3002 | float toDisplayY(int32_t rawY); | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 3003 | float toDisplayY(int32_t rawY, int32_t displayHeight); | 
|  | 3004 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3005 | }; | 
|  | 3006 |  | 
|  | 3007 | const int32_t TouchInputMapperTest::RAW_X_MIN = 25; | 
|  | 3008 | const int32_t TouchInputMapperTest::RAW_X_MAX = 1019; | 
|  | 3009 | const int32_t TouchInputMapperTest::RAW_Y_MIN = 30; | 
|  | 3010 | const int32_t TouchInputMapperTest::RAW_Y_MAX = 1009; | 
|  | 3011 | const int32_t TouchInputMapperTest::RAW_TOUCH_MIN = 0; | 
|  | 3012 | const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31; | 
|  | 3013 | const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0; | 
|  | 3014 | const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15; | 
| Michael Wright | aa449c9 | 2017-12-13 21:21:43 +0000 | [diff] [blame] | 3015 | const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = 0; | 
|  | 3016 | const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = 255; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3017 | const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7; | 
|  | 3018 | const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7; | 
|  | 3019 | const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0; | 
|  | 3020 | const int32_t TouchInputMapperTest::RAW_DISTANCE_MAX = 7; | 
|  | 3021 | const int32_t TouchInputMapperTest::RAW_TILT_MIN = 0; | 
|  | 3022 | const int32_t TouchInputMapperTest::RAW_TILT_MAX = 150; | 
|  | 3023 | const int32_t TouchInputMapperTest::RAW_ID_MIN = 0; | 
|  | 3024 | const int32_t TouchInputMapperTest::RAW_ID_MAX = 9; | 
|  | 3025 | const int32_t TouchInputMapperTest::RAW_SLOT_MIN = 0; | 
|  | 3026 | const int32_t TouchInputMapperTest::RAW_SLOT_MAX = 9; | 
|  | 3027 | const float TouchInputMapperTest::X_PRECISION = float(RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH; | 
|  | 3028 | const float TouchInputMapperTest::Y_PRECISION = float(RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 3029 | const float TouchInputMapperTest::X_PRECISION_VIRTUAL = | 
|  | 3030 | float(RAW_X_MAX - RAW_X_MIN + 1) / VIRTUAL_DISPLAY_WIDTH; | 
|  | 3031 | const float TouchInputMapperTest::Y_PRECISION_VIRTUAL = | 
|  | 3032 | float(RAW_Y_MAX - RAW_Y_MIN + 1) / VIRTUAL_DISPLAY_HEIGHT; | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 3033 | const TouchAffineTransformation TouchInputMapperTest::AFFINE_TRANSFORM = | 
|  | 3034 | TouchAffineTransformation(1, -2, 3, -4, 5, -6); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3035 |  | 
|  | 3036 | const float TouchInputMapperTest::GEOMETRIC_SCALE = | 
|  | 3037 | avg(float(DISPLAY_WIDTH) / (RAW_X_MAX - RAW_X_MIN + 1), | 
|  | 3038 | float(DISPLAY_HEIGHT) / (RAW_Y_MAX - RAW_Y_MIN + 1)); | 
|  | 3039 |  | 
|  | 3040 | const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = { | 
|  | 3041 | { KEY_HOME, 60, DISPLAY_HEIGHT + 15, 20, 20 }, | 
|  | 3042 | { KEY_MENU, DISPLAY_HEIGHT - 60, DISPLAY_WIDTH + 15, 20, 20 }, | 
|  | 3043 | }; | 
|  | 3044 |  | 
|  | 3045 | void TouchInputMapperTest::prepareDisplay(int32_t orientation) { | 
|  | 3046 | setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation); | 
|  | 3047 | } | 
|  | 3048 |  | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 3049 | void TouchInputMapperTest::prepareVirtualDisplay(int32_t orientation) { | 
|  | 3050 | setVirtualDisplayInfoAndReconfigure(VIRTUAL_DISPLAY_ID, VIRTUAL_DISPLAY_WIDTH, | 
|  | 3051 | VIRTUAL_DISPLAY_HEIGHT, orientation, String8(VIRTUAL_DISPLAY_UNIQUE_ID)); | 
|  | 3052 | } | 
|  | 3053 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3054 | void TouchInputMapperTest::prepareVirtualKeys() { | 
|  | 3055 | mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[0]); | 
|  | 3056 | mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[1]); | 
|  | 3057 | mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE); | 
|  | 3058 | mFakeEventHub->addKey(DEVICE_ID, KEY_MENU, 0, AKEYCODE_MENU, POLICY_FLAG_WAKE); | 
|  | 3059 | } | 
|  | 3060 |  | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 3061 | void TouchInputMapperTest::prepareLocationCalibration() { | 
|  | 3062 | mFakePolicy->setTouchAffineTransformation(AFFINE_TRANSFORM); | 
|  | 3063 | } | 
|  | 3064 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3065 | int32_t TouchInputMapperTest::toRawX(float displayX) { | 
|  | 3066 | return int32_t(displayX * (RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH + RAW_X_MIN); | 
|  | 3067 | } | 
|  | 3068 |  | 
|  | 3069 | int32_t TouchInputMapperTest::toRawY(float displayY) { | 
|  | 3070 | return int32_t(displayY * (RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT + RAW_Y_MIN); | 
|  | 3071 | } | 
|  | 3072 |  | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 3073 | float TouchInputMapperTest::toCookedX(float rawX, float rawY) { | 
|  | 3074 | AFFINE_TRANSFORM.applyTo(rawX, rawY); | 
|  | 3075 | return rawX; | 
|  | 3076 | } | 
|  | 3077 |  | 
|  | 3078 | float TouchInputMapperTest::toCookedY(float rawX, float rawY) { | 
|  | 3079 | AFFINE_TRANSFORM.applyTo(rawX, rawY); | 
|  | 3080 | return rawY; | 
|  | 3081 | } | 
|  | 3082 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3083 | float TouchInputMapperTest::toDisplayX(int32_t rawX) { | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 3084 | return toDisplayX(rawX, DISPLAY_WIDTH); | 
|  | 3085 | } | 
|  | 3086 |  | 
|  | 3087 | float TouchInputMapperTest::toDisplayX(int32_t rawX, int32_t displayWidth) { | 
|  | 3088 | return float(rawX - RAW_X_MIN) * displayWidth / (RAW_X_MAX - RAW_X_MIN + 1); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3089 | } | 
|  | 3090 |  | 
|  | 3091 | float TouchInputMapperTest::toDisplayY(int32_t rawY) { | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 3092 | return toDisplayY(rawY, DISPLAY_HEIGHT); | 
|  | 3093 | } | 
|  | 3094 |  | 
|  | 3095 | float TouchInputMapperTest::toDisplayY(int32_t rawY, int32_t displayHeight) { | 
|  | 3096 | return float(rawY - RAW_Y_MIN) * displayHeight / (RAW_Y_MAX - RAW_Y_MIN + 1); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3097 | } | 
|  | 3098 |  | 
|  | 3099 |  | 
|  | 3100 | // --- SingleTouchInputMapperTest --- | 
|  | 3101 |  | 
|  | 3102 | class SingleTouchInputMapperTest : public TouchInputMapperTest { | 
|  | 3103 | protected: | 
|  | 3104 | void prepareButtons(); | 
|  | 3105 | void prepareAxes(int axes); | 
|  | 3106 |  | 
|  | 3107 | void processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y); | 
|  | 3108 | void processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y); | 
|  | 3109 | void processUp(SingleTouchInputMapper* mappery); | 
|  | 3110 | void processPressure(SingleTouchInputMapper* mapper, int32_t pressure); | 
|  | 3111 | void processToolMajor(SingleTouchInputMapper* mapper, int32_t toolMajor); | 
|  | 3112 | void processDistance(SingleTouchInputMapper* mapper, int32_t distance); | 
|  | 3113 | void processTilt(SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY); | 
|  | 3114 | void processKey(SingleTouchInputMapper* mapper, int32_t code, int32_t value); | 
|  | 3115 | void processSync(SingleTouchInputMapper* mapper); | 
|  | 3116 | }; | 
|  | 3117 |  | 
|  | 3118 | void SingleTouchInputMapperTest::prepareButtons() { | 
|  | 3119 | mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0); | 
|  | 3120 | } | 
|  | 3121 |  | 
|  | 3122 | void SingleTouchInputMapperTest::prepareAxes(int axes) { | 
|  | 3123 | if (axes & POSITION) { | 
|  | 3124 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_X, | 
|  | 3125 | RAW_X_MIN, RAW_X_MAX, 0, 0); | 
|  | 3126 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_Y, | 
|  | 3127 | RAW_Y_MIN, RAW_Y_MAX, 0, 0); | 
|  | 3128 | } | 
|  | 3129 | if (axes & PRESSURE) { | 
|  | 3130 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_PRESSURE, | 
|  | 3131 | RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0); | 
|  | 3132 | } | 
|  | 3133 | if (axes & TOOL) { | 
|  | 3134 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TOOL_WIDTH, | 
|  | 3135 | RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0); | 
|  | 3136 | } | 
|  | 3137 | if (axes & DISTANCE) { | 
|  | 3138 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_DISTANCE, | 
|  | 3139 | RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0); | 
|  | 3140 | } | 
|  | 3141 | if (axes & TILT) { | 
|  | 3142 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_X, | 
|  | 3143 | RAW_TILT_MIN, RAW_TILT_MAX, 0, 0); | 
|  | 3144 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_Y, | 
|  | 3145 | RAW_TILT_MIN, RAW_TILT_MAX, 0, 0); | 
|  | 3146 | } | 
|  | 3147 | } | 
|  | 3148 |  | 
|  | 3149 | void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y) { | 
|  | 3150 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 1); | 
|  | 3151 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x); | 
|  | 3152 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y); | 
|  | 3153 | } | 
|  | 3154 |  | 
|  | 3155 | void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y) { | 
|  | 3156 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x); | 
|  | 3157 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y); | 
|  | 3158 | } | 
|  | 3159 |  | 
|  | 3160 | void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper* mapper) { | 
|  | 3161 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 0); | 
|  | 3162 | } | 
|  | 3163 |  | 
|  | 3164 | void SingleTouchInputMapperTest::processPressure( | 
|  | 3165 | SingleTouchInputMapper* mapper, int32_t pressure) { | 
|  | 3166 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_PRESSURE, pressure); | 
|  | 3167 | } | 
|  | 3168 |  | 
|  | 3169 | void SingleTouchInputMapperTest::processToolMajor( | 
|  | 3170 | SingleTouchInputMapper* mapper, int32_t toolMajor) { | 
|  | 3171 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TOOL_WIDTH, toolMajor); | 
|  | 3172 | } | 
|  | 3173 |  | 
|  | 3174 | void SingleTouchInputMapperTest::processDistance( | 
|  | 3175 | SingleTouchInputMapper* mapper, int32_t distance) { | 
|  | 3176 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_DISTANCE, distance); | 
|  | 3177 | } | 
|  | 3178 |  | 
|  | 3179 | void SingleTouchInputMapperTest::processTilt( | 
|  | 3180 | SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY) { | 
|  | 3181 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_X, tiltX); | 
|  | 3182 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_Y, tiltY); | 
|  | 3183 | } | 
|  | 3184 |  | 
|  | 3185 | void SingleTouchInputMapperTest::processKey( | 
|  | 3186 | SingleTouchInputMapper* mapper, int32_t code, int32_t value) { | 
|  | 3187 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value); | 
|  | 3188 | } | 
|  | 3189 |  | 
|  | 3190 | void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper* mapper) { | 
|  | 3191 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 3192 | } | 
|  | 3193 |  | 
|  | 3194 |  | 
|  | 3195 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) { | 
|  | 3196 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3197 | prepareButtons(); | 
|  | 3198 | prepareAxes(POSITION); | 
|  | 3199 | addMapperAndConfigure(mapper); | 
|  | 3200 |  | 
|  | 3201 | ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources()); | 
|  | 3202 | } | 
|  | 3203 |  | 
|  | 3204 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndIsACursor_ReturnsTouchPad) { | 
|  | 3205 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3206 | mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_X); | 
|  | 3207 | mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_Y); | 
|  | 3208 | prepareButtons(); | 
|  | 3209 | prepareAxes(POSITION); | 
|  | 3210 | addMapperAndConfigure(mapper); | 
|  | 3211 |  | 
|  | 3212 | ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources()); | 
|  | 3213 | } | 
|  | 3214 |  | 
|  | 3215 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchPad_ReturnsTouchPad) { | 
|  | 3216 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3217 | prepareButtons(); | 
|  | 3218 | prepareAxes(POSITION); | 
|  | 3219 | addConfigurationProperty("touch.deviceType", "touchPad"); | 
|  | 3220 | addMapperAndConfigure(mapper); | 
|  | 3221 |  | 
|  | 3222 | ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources()); | 
|  | 3223 | } | 
|  | 3224 |  | 
|  | 3225 | TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchScreen_ReturnsTouchScreen) { | 
|  | 3226 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3227 | prepareButtons(); | 
|  | 3228 | prepareAxes(POSITION); | 
|  | 3229 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3230 | addMapperAndConfigure(mapper); | 
|  | 3231 |  | 
|  | 3232 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper->getSources()); | 
|  | 3233 | } | 
|  | 3234 |  | 
|  | 3235 | TEST_F(SingleTouchInputMapperTest, GetKeyCodeState) { | 
|  | 3236 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3237 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3238 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3239 | prepareButtons(); | 
|  | 3240 | prepareAxes(POSITION); | 
|  | 3241 | prepareVirtualKeys(); | 
|  | 3242 | addMapperAndConfigure(mapper); | 
|  | 3243 |  | 
|  | 3244 | // Unknown key. | 
|  | 3245 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A)); | 
|  | 3246 |  | 
|  | 3247 | // Virtual key is down. | 
|  | 3248 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); | 
|  | 3249 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); | 
|  | 3250 | processDown(mapper, x, y); | 
|  | 3251 | processSync(mapper); | 
|  | 3252 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); | 
|  | 3253 |  | 
|  | 3254 | ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME)); | 
|  | 3255 |  | 
|  | 3256 | // Virtual key is up. | 
|  | 3257 | processUp(mapper); | 
|  | 3258 | processSync(mapper); | 
|  | 3259 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); | 
|  | 3260 |  | 
|  | 3261 | ASSERT_EQ(AKEY_STATE_UP, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME)); | 
|  | 3262 | } | 
|  | 3263 |  | 
|  | 3264 | TEST_F(SingleTouchInputMapperTest, GetScanCodeState) { | 
|  | 3265 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3266 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3267 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3268 | prepareButtons(); | 
|  | 3269 | prepareAxes(POSITION); | 
|  | 3270 | prepareVirtualKeys(); | 
|  | 3271 | addMapperAndConfigure(mapper); | 
|  | 3272 |  | 
|  | 3273 | // Unknown key. | 
|  | 3274 | ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A)); | 
|  | 3275 |  | 
|  | 3276 | // Virtual key is down. | 
|  | 3277 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); | 
|  | 3278 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); | 
|  | 3279 | processDown(mapper, x, y); | 
|  | 3280 | processSync(mapper); | 
|  | 3281 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); | 
|  | 3282 |  | 
|  | 3283 | ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME)); | 
|  | 3284 |  | 
|  | 3285 | // Virtual key is up. | 
|  | 3286 | processUp(mapper); | 
|  | 3287 | processSync(mapper); | 
|  | 3288 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled()); | 
|  | 3289 |  | 
|  | 3290 | ASSERT_EQ(AKEY_STATE_UP, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME)); | 
|  | 3291 | } | 
|  | 3292 |  | 
|  | 3293 | TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) { | 
|  | 3294 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3295 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3296 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3297 | prepareButtons(); | 
|  | 3298 | prepareAxes(POSITION); | 
|  | 3299 | prepareVirtualKeys(); | 
|  | 3300 | addMapperAndConfigure(mapper); | 
|  | 3301 |  | 
|  | 3302 | const int32_t keys[2] = { AKEYCODE_HOME, AKEYCODE_A }; | 
|  | 3303 | uint8_t flags[2] = { 0, 0 }; | 
|  | 3304 | ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 2, keys, flags)); | 
|  | 3305 | ASSERT_TRUE(flags[0]); | 
|  | 3306 | ASSERT_FALSE(flags[1]); | 
|  | 3307 | } | 
|  | 3308 |  | 
|  | 3309 | TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) { | 
|  | 3310 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3311 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3312 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3313 | prepareButtons(); | 
|  | 3314 | prepareAxes(POSITION); | 
|  | 3315 | prepareVirtualKeys(); | 
|  | 3316 | addMapperAndConfigure(mapper); | 
|  | 3317 |  | 
|  | 3318 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 3319 |  | 
|  | 3320 | NotifyKeyArgs args; | 
|  | 3321 |  | 
|  | 3322 | // Press virtual key. | 
|  | 3323 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); | 
|  | 3324 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); | 
|  | 3325 | processDown(mapper, x, y); | 
|  | 3326 | processSync(mapper); | 
|  | 3327 |  | 
|  | 3328 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 3329 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 3330 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 3331 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 3332 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags); | 
|  | 3333 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); | 
|  | 3334 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags); | 
|  | 3335 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); | 
|  | 3336 | ASSERT_EQ(KEY_HOME, args.scanCode); | 
|  | 3337 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 3338 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 3339 |  | 
|  | 3340 | // Release virtual key. | 
|  | 3341 | processUp(mapper); | 
|  | 3342 | processSync(mapper); | 
|  | 3343 |  | 
|  | 3344 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); | 
|  | 3345 | ASSERT_EQ(ARBITRARY_TIME, args.eventTime); | 
|  | 3346 | ASSERT_EQ(DEVICE_ID, args.deviceId); | 
|  | 3347 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source); | 
|  | 3348 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags); | 
|  | 3349 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); | 
|  | 3350 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags); | 
|  | 3351 | ASSERT_EQ(AKEYCODE_HOME, args.keyCode); | 
|  | 3352 | ASSERT_EQ(KEY_HOME, args.scanCode); | 
|  | 3353 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState); | 
|  | 3354 | ASSERT_EQ(ARBITRARY_TIME, args.downTime); | 
|  | 3355 |  | 
|  | 3356 | // Should not have sent any motions. | 
|  | 3357 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 3358 | } | 
|  | 3359 |  | 
|  | 3360 | TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfBounds_SendsKeyDownAndKeyCancel) { | 
|  | 3361 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3362 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3363 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3364 | prepareButtons(); | 
|  | 3365 | prepareAxes(POSITION); | 
|  | 3366 | prepareVirtualKeys(); | 
|  | 3367 | addMapperAndConfigure(mapper); | 
|  | 3368 |  | 
|  | 3369 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 3370 |  | 
|  | 3371 | NotifyKeyArgs keyArgs; | 
|  | 3372 |  | 
|  | 3373 | // Press virtual key. | 
|  | 3374 | int32_t x = toRawX(VIRTUAL_KEYS[0].centerX); | 
|  | 3375 | int32_t y = toRawY(VIRTUAL_KEYS[0].centerY); | 
|  | 3376 | processDown(mapper, x, y); | 
|  | 3377 | processSync(mapper); | 
|  | 3378 |  | 
|  | 3379 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 3380 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime); | 
|  | 3381 | ASSERT_EQ(DEVICE_ID, keyArgs.deviceId); | 
|  | 3382 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source); | 
|  | 3383 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags); | 
|  | 3384 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 3385 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, keyArgs.flags); | 
|  | 3386 | ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode); | 
|  | 3387 | ASSERT_EQ(KEY_HOME, keyArgs.scanCode); | 
|  | 3388 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState); | 
|  | 3389 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime); | 
|  | 3390 |  | 
|  | 3391 | // Move out of bounds.  This should generate a cancel and a pointer down since we moved | 
|  | 3392 | // into the display area. | 
|  | 3393 | y -= 100; | 
|  | 3394 | processMove(mapper, x, y); | 
|  | 3395 | processSync(mapper); | 
|  | 3396 |  | 
|  | 3397 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 3398 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime); | 
|  | 3399 | ASSERT_EQ(DEVICE_ID, keyArgs.deviceId); | 
|  | 3400 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source); | 
|  | 3401 | ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags); | 
|  | 3402 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 3403 | ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY | 
|  | 3404 | | AKEY_EVENT_FLAG_CANCELED, keyArgs.flags); | 
|  | 3405 | ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode); | 
|  | 3406 | ASSERT_EQ(KEY_HOME, keyArgs.scanCode); | 
|  | 3407 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState); | 
|  | 3408 | ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime); | 
|  | 3409 |  | 
|  | 3410 | NotifyMotionArgs motionArgs; | 
|  | 3411 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3412 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3413 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3414 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3415 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3416 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 3417 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3418 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3419 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3420 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3421 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3422 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3423 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3424 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3425 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3426 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3427 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3428 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3429 |  | 
|  | 3430 | // Keep moving out of bounds.  Should generate a pointer move. | 
|  | 3431 | y -= 50; | 
|  | 3432 | processMove(mapper, x, y); | 
|  | 3433 | processSync(mapper); | 
|  | 3434 |  | 
|  | 3435 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3436 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3437 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3438 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3439 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3440 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 3441 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3442 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3443 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3444 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3445 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3446 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3447 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3448 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3449 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3450 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3451 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3452 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3453 |  | 
|  | 3454 | // Release out of bounds.  Should generate a pointer up. | 
|  | 3455 | processUp(mapper); | 
|  | 3456 | processSync(mapper); | 
|  | 3457 |  | 
|  | 3458 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3459 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3460 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3461 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3462 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3463 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 3464 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3465 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3466 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3467 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3468 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3469 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3470 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3471 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3472 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3473 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3474 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3475 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3476 |  | 
|  | 3477 | // Should not have sent any more keys or motions. | 
|  | 3478 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 3479 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 3480 | } | 
|  | 3481 |  | 
|  | 3482 | TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMovesIn_SendsDownAsTouchEntersDisplay) { | 
|  | 3483 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3484 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3485 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3486 | prepareButtons(); | 
|  | 3487 | prepareAxes(POSITION); | 
|  | 3488 | prepareVirtualKeys(); | 
|  | 3489 | addMapperAndConfigure(mapper); | 
|  | 3490 |  | 
|  | 3491 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 3492 |  | 
|  | 3493 | NotifyMotionArgs motionArgs; | 
|  | 3494 |  | 
|  | 3495 | // Initially go down out of bounds. | 
|  | 3496 | int32_t x = -10; | 
|  | 3497 | int32_t y = -10; | 
|  | 3498 | processDown(mapper, x, y); | 
|  | 3499 | processSync(mapper); | 
|  | 3500 |  | 
|  | 3501 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 3502 |  | 
|  | 3503 | // Move into the display area.  Should generate a pointer down. | 
|  | 3504 | x = 50; | 
|  | 3505 | y = 75; | 
|  | 3506 | processMove(mapper, x, y); | 
|  | 3507 | processSync(mapper); | 
|  | 3508 |  | 
|  | 3509 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3510 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3511 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3512 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3513 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3514 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 3515 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3516 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3517 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3518 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3519 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3520 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3521 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3522 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3523 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3524 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3525 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3526 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3527 |  | 
|  | 3528 | // Release.  Should generate a pointer up. | 
|  | 3529 | processUp(mapper); | 
|  | 3530 | processSync(mapper); | 
|  | 3531 |  | 
|  | 3532 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3533 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3534 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3535 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3536 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3537 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 3538 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3539 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3540 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3541 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3542 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3543 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3544 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3545 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3546 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3547 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3548 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3549 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3550 |  | 
|  | 3551 | // Should not have sent any more keys or motions. | 
|  | 3552 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 3553 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 3554 | } | 
|  | 3555 |  | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 3556 | TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDisplay) { | 
|  | 3557 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3558 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3559 | addConfigurationProperty("touch.displayId", VIRTUAL_DISPLAY_UNIQUE_ID); | 
|  | 3560 |  | 
|  | 3561 | prepareVirtualDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3562 | prepareButtons(); | 
|  | 3563 | prepareAxes(POSITION); | 
|  | 3564 | prepareVirtualKeys(); | 
|  | 3565 | addMapperAndConfigure(mapper); | 
|  | 3566 |  | 
|  | 3567 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 3568 |  | 
|  | 3569 | NotifyMotionArgs motionArgs; | 
|  | 3570 |  | 
|  | 3571 | // Down. | 
|  | 3572 | int32_t x = 100; | 
|  | 3573 | int32_t y = 125; | 
|  | 3574 | processDown(mapper, x, y); | 
|  | 3575 | processSync(mapper); | 
|  | 3576 |  | 
|  | 3577 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3578 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3579 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3580 | ASSERT_EQ(VIRTUAL_DISPLAY_ID, motionArgs.displayId); | 
|  | 3581 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3582 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3583 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 3584 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3585 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3586 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3587 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3588 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3589 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3590 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3591 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3592 | toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), | 
|  | 3593 | 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3594 | ASSERT_NEAR(X_PRECISION_VIRTUAL, motionArgs.xPrecision, EPSILON); | 
|  | 3595 | ASSERT_NEAR(Y_PRECISION_VIRTUAL, motionArgs.yPrecision, EPSILON); | 
|  | 3596 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3597 |  | 
|  | 3598 | // Move. | 
|  | 3599 | x += 50; | 
|  | 3600 | y += 75; | 
|  | 3601 | processMove(mapper, x, y); | 
|  | 3602 | processSync(mapper); | 
|  | 3603 |  | 
|  | 3604 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3605 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3606 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3607 | ASSERT_EQ(VIRTUAL_DISPLAY_ID, motionArgs.displayId); | 
|  | 3608 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3609 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3610 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 3611 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3612 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3613 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3614 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3615 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3616 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3617 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3618 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3619 | toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), | 
|  | 3620 | 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3621 | ASSERT_NEAR(X_PRECISION_VIRTUAL, motionArgs.xPrecision, EPSILON); | 
|  | 3622 | ASSERT_NEAR(Y_PRECISION_VIRTUAL, motionArgs.yPrecision, EPSILON); | 
|  | 3623 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3624 |  | 
|  | 3625 | // Up. | 
|  | 3626 | processUp(mapper); | 
|  | 3627 | processSync(mapper); | 
|  | 3628 |  | 
|  | 3629 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3630 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3631 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3632 | ASSERT_EQ(VIRTUAL_DISPLAY_ID, motionArgs.displayId); | 
|  | 3633 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3634 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3635 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 3636 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3637 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3638 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3639 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3640 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3641 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3642 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3643 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3644 | toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), | 
|  | 3645 | 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3646 | ASSERT_NEAR(X_PRECISION_VIRTUAL, motionArgs.xPrecision, EPSILON); | 
|  | 3647 | ASSERT_NEAR(Y_PRECISION_VIRTUAL, motionArgs.yPrecision, EPSILON); | 
|  | 3648 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3649 |  | 
|  | 3650 | // Should not have sent any more keys or motions. | 
|  | 3651 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 3652 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 3653 | } | 
|  | 3654 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3655 | TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { | 
|  | 3656 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3657 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3658 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3659 | prepareButtons(); | 
|  | 3660 | prepareAxes(POSITION); | 
|  | 3661 | prepareVirtualKeys(); | 
|  | 3662 | addMapperAndConfigure(mapper); | 
|  | 3663 |  | 
|  | 3664 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 3665 |  | 
|  | 3666 | NotifyMotionArgs motionArgs; | 
|  | 3667 |  | 
|  | 3668 | // Down. | 
|  | 3669 | int32_t x = 100; | 
|  | 3670 | int32_t y = 125; | 
|  | 3671 | processDown(mapper, x, y); | 
|  | 3672 | processSync(mapper); | 
|  | 3673 |  | 
|  | 3674 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3675 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3676 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3677 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3678 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3679 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 3680 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3681 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3682 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3683 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3684 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3685 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3686 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3687 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3688 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3689 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3690 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3691 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3692 |  | 
|  | 3693 | // Move. | 
|  | 3694 | x += 50; | 
|  | 3695 | y += 75; | 
|  | 3696 | processMove(mapper, x, y); | 
|  | 3697 | processSync(mapper); | 
|  | 3698 |  | 
|  | 3699 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3700 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3701 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3702 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3703 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3704 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 3705 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3706 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3707 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3708 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3709 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3710 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3711 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3712 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3713 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3714 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3715 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3716 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3717 |  | 
|  | 3718 | // Up. | 
|  | 3719 | processUp(mapper); | 
|  | 3720 | processSync(mapper); | 
|  | 3721 |  | 
|  | 3722 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3723 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 3724 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 3725 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 3726 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 3727 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 3728 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 3729 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 3730 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3731 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 3732 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 3733 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 3734 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 3735 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 3736 | toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3737 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 3738 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 3739 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 3740 |  | 
|  | 3741 | // Should not have sent any more keys or motions. | 
|  | 3742 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 3743 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 3744 | } | 
|  | 3745 |  | 
|  | 3746 | TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_DoesNotRotateMotions) { | 
|  | 3747 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3748 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3749 | prepareButtons(); | 
|  | 3750 | prepareAxes(POSITION); | 
|  | 3751 | addConfigurationProperty("touch.orientationAware", "0"); | 
|  | 3752 | addMapperAndConfigure(mapper); | 
|  | 3753 |  | 
|  | 3754 | NotifyMotionArgs args; | 
|  | 3755 |  | 
|  | 3756 | // Rotation 90. | 
|  | 3757 | prepareDisplay(DISPLAY_ORIENTATION_90); | 
|  | 3758 | processDown(mapper, toRawX(50), toRawY(75)); | 
|  | 3759 | processSync(mapper); | 
|  | 3760 |  | 
|  | 3761 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 3762 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); | 
|  | 3763 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); | 
|  | 3764 |  | 
|  | 3765 | processUp(mapper); | 
|  | 3766 | processSync(mapper); | 
|  | 3767 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); | 
|  | 3768 | } | 
|  | 3769 |  | 
|  | 3770 | TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) { | 
|  | 3771 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3772 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3773 | prepareButtons(); | 
|  | 3774 | prepareAxes(POSITION); | 
|  | 3775 | addMapperAndConfigure(mapper); | 
|  | 3776 |  | 
|  | 3777 | NotifyMotionArgs args; | 
|  | 3778 |  | 
|  | 3779 | // Rotation 0. | 
|  | 3780 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3781 | processDown(mapper, toRawX(50), toRawY(75)); | 
|  | 3782 | processSync(mapper); | 
|  | 3783 |  | 
|  | 3784 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 3785 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); | 
|  | 3786 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); | 
|  | 3787 |  | 
|  | 3788 | processUp(mapper); | 
|  | 3789 | processSync(mapper); | 
|  | 3790 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); | 
|  | 3791 |  | 
|  | 3792 | // Rotation 90. | 
|  | 3793 | prepareDisplay(DISPLAY_ORIENTATION_90); | 
|  | 3794 | processDown(mapper, RAW_X_MAX - toRawX(75) + RAW_X_MIN, toRawY(50)); | 
|  | 3795 | processSync(mapper); | 
|  | 3796 |  | 
|  | 3797 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 3798 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); | 
|  | 3799 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); | 
|  | 3800 |  | 
|  | 3801 | processUp(mapper); | 
|  | 3802 | processSync(mapper); | 
|  | 3803 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); | 
|  | 3804 |  | 
|  | 3805 | // Rotation 180. | 
|  | 3806 | prepareDisplay(DISPLAY_ORIENTATION_180); | 
|  | 3807 | processDown(mapper, RAW_X_MAX - toRawX(50) + RAW_X_MIN, RAW_Y_MAX - toRawY(75) + RAW_Y_MIN); | 
|  | 3808 | processSync(mapper); | 
|  | 3809 |  | 
|  | 3810 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 3811 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); | 
|  | 3812 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); | 
|  | 3813 |  | 
|  | 3814 | processUp(mapper); | 
|  | 3815 | processSync(mapper); | 
|  | 3816 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); | 
|  | 3817 |  | 
|  | 3818 | // Rotation 270. | 
|  | 3819 | prepareDisplay(DISPLAY_ORIENTATION_270); | 
|  | 3820 | processDown(mapper, toRawX(75), RAW_Y_MAX - toRawY(50) + RAW_Y_MIN); | 
|  | 3821 | processSync(mapper); | 
|  | 3822 |  | 
|  | 3823 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 3824 | ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1); | 
|  | 3825 | ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1); | 
|  | 3826 |  | 
|  | 3827 | processUp(mapper); | 
|  | 3828 | processSync(mapper); | 
|  | 3829 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled()); | 
|  | 3830 | } | 
|  | 3831 |  | 
|  | 3832 | TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) { | 
|  | 3833 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3834 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3835 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3836 | prepareButtons(); | 
|  | 3837 | prepareAxes(POSITION | PRESSURE | TOOL | DISTANCE | TILT); | 
|  | 3838 | addMapperAndConfigure(mapper); | 
|  | 3839 |  | 
|  | 3840 | // These calculations are based on the input device calibration documentation. | 
|  | 3841 | int32_t rawX = 100; | 
|  | 3842 | int32_t rawY = 200; | 
|  | 3843 | int32_t rawPressure = 10; | 
|  | 3844 | int32_t rawToolMajor = 12; | 
|  | 3845 | int32_t rawDistance = 2; | 
|  | 3846 | int32_t rawTiltX = 30; | 
|  | 3847 | int32_t rawTiltY = 110; | 
|  | 3848 |  | 
|  | 3849 | float x = toDisplayX(rawX); | 
|  | 3850 | float y = toDisplayY(rawY); | 
|  | 3851 | float pressure = float(rawPressure) / RAW_PRESSURE_MAX; | 
|  | 3852 | float size = float(rawToolMajor) / RAW_TOOL_MAX; | 
|  | 3853 | float tool = float(rawToolMajor) * GEOMETRIC_SCALE; | 
|  | 3854 | float distance = float(rawDistance); | 
|  | 3855 |  | 
|  | 3856 | float tiltCenter = (RAW_TILT_MAX + RAW_TILT_MIN) * 0.5f; | 
|  | 3857 | float tiltScale = M_PI / 180; | 
|  | 3858 | float tiltXAngle = (rawTiltX - tiltCenter) * tiltScale; | 
|  | 3859 | float tiltYAngle = (rawTiltY - tiltCenter) * tiltScale; | 
|  | 3860 | float orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle)); | 
|  | 3861 | float tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle)); | 
|  | 3862 |  | 
|  | 3863 | processDown(mapper, rawX, rawY); | 
|  | 3864 | processPressure(mapper, rawPressure); | 
|  | 3865 | processToolMajor(mapper, rawToolMajor); | 
|  | 3866 | processDistance(mapper, rawDistance); | 
|  | 3867 | processTilt(mapper, rawTiltX, rawTiltY); | 
|  | 3868 | processSync(mapper); | 
|  | 3869 |  | 
|  | 3870 | NotifyMotionArgs args; | 
|  | 3871 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 3872 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 3873 | x, y, pressure, size, tool, tool, tool, tool, orientation, distance)); | 
|  | 3874 | ASSERT_EQ(tilt, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TILT)); | 
|  | 3875 | } | 
|  | 3876 |  | 
| Jason Gerecke | 489fda8 | 2012-09-07 17:19:40 -0700 | [diff] [blame] | 3877 | TEST_F(SingleTouchInputMapperTest, Process_XYAxes_AffineCalibration) { | 
|  | 3878 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3879 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3880 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3881 | prepareLocationCalibration(); | 
|  | 3882 | prepareButtons(); | 
|  | 3883 | prepareAxes(POSITION); | 
|  | 3884 | addMapperAndConfigure(mapper); | 
|  | 3885 |  | 
|  | 3886 | int32_t rawX = 100; | 
|  | 3887 | int32_t rawY = 200; | 
|  | 3888 |  | 
|  | 3889 | float x = toDisplayX(toCookedX(rawX, rawY)); | 
|  | 3890 | float y = toDisplayY(toCookedY(rawX, rawY)); | 
|  | 3891 |  | 
|  | 3892 | processDown(mapper, rawX, rawY); | 
|  | 3893 | processSync(mapper); | 
|  | 3894 |  | 
|  | 3895 | NotifyMotionArgs args; | 
|  | 3896 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 3897 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 3898 | x, y, 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 3899 | } | 
|  | 3900 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3901 | TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllButtons) { | 
|  | 3902 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 3903 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 3904 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 3905 | prepareButtons(); | 
|  | 3906 | prepareAxes(POSITION); | 
|  | 3907 | addMapperAndConfigure(mapper); | 
|  | 3908 |  | 
|  | 3909 | NotifyMotionArgs motionArgs; | 
|  | 3910 | NotifyKeyArgs keyArgs; | 
|  | 3911 |  | 
|  | 3912 | processDown(mapper, 100, 200); | 
|  | 3913 | processSync(mapper); | 
|  | 3914 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3915 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 3916 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 3917 |  | 
|  | 3918 | // press BTN_LEFT, release BTN_LEFT | 
|  | 3919 | processKey(mapper, BTN_LEFT, 1); | 
|  | 3920 | processSync(mapper); | 
|  | 3921 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3922 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 3923 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); | 
|  | 3924 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3925 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3926 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 3927 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); | 
|  | 3928 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3929 | processKey(mapper, BTN_LEFT, 0); | 
|  | 3930 | processSync(mapper); | 
|  | 3931 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3932 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3933 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3934 |  | 
|  | 3935 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3936 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3937 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3938 |  | 
|  | 3939 | // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE | 
|  | 3940 | processKey(mapper, BTN_RIGHT, 1); | 
|  | 3941 | processKey(mapper, BTN_MIDDLE, 1); | 
|  | 3942 | processSync(mapper); | 
|  | 3943 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3944 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 3945 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 3946 | motionArgs.buttonState); | 
|  | 3947 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3948 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3949 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 3950 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
|  | 3951 |  | 
|  | 3952 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3953 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 3954 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 3955 | motionArgs.buttonState); | 
|  | 3956 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3957 | processKey(mapper, BTN_RIGHT, 0); | 
|  | 3958 | processSync(mapper); | 
|  | 3959 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3960 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3961 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3962 |  | 
|  | 3963 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3964 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3965 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3966 |  | 
|  | 3967 | processKey(mapper, BTN_MIDDLE, 0); | 
|  | 3968 | processSync(mapper); | 
|  | 3969 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3970 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3971 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3972 |  | 
|  | 3973 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3974 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3975 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3976 |  | 
|  | 3977 | // press BTN_BACK, release BTN_BACK | 
|  | 3978 | processKey(mapper, BTN_BACK, 1); | 
|  | 3979 | processSync(mapper); | 
|  | 3980 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 3981 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 3982 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3983 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3984 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3985 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3986 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 3987 |  | 
|  | 3988 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 3989 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 3990 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3991 |  | 
|  | 3992 | processKey(mapper, BTN_BACK, 0); | 
|  | 3993 | processSync(mapper); | 
|  | 3994 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3995 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3996 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 3997 |  | 
|  | 3998 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 3999 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4000 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4001 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4002 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 4003 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 4004 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
|  | 4005 |  | 
|  | 4006 | // press BTN_SIDE, release BTN_SIDE | 
|  | 4007 | processKey(mapper, BTN_SIDE, 1); | 
|  | 4008 | processSync(mapper); | 
|  | 4009 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 4010 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 4011 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4012 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4013 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4014 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4015 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 4016 |  | 
|  | 4017 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4018 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 4019 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4020 |  | 
|  | 4021 | processKey(mapper, BTN_SIDE, 0); | 
|  | 4022 | processSync(mapper); | 
|  | 4023 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4024 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4025 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4026 |  | 
|  | 4027 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4028 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4029 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4030 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4031 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 4032 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 4033 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
|  | 4034 |  | 
|  | 4035 | // press BTN_FORWARD, release BTN_FORWARD | 
|  | 4036 | processKey(mapper, BTN_FORWARD, 1); | 
|  | 4037 | processSync(mapper); | 
|  | 4038 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 4039 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 4040 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4041 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4042 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4043 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4044 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 4045 |  | 
|  | 4046 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4047 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 4048 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4049 |  | 
|  | 4050 | processKey(mapper, BTN_FORWARD, 0); | 
|  | 4051 | processSync(mapper); | 
|  | 4052 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4053 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4054 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4055 |  | 
|  | 4056 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4057 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4058 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4059 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4060 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 4061 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 4062 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
|  | 4063 |  | 
|  | 4064 | // press BTN_EXTRA, release BTN_EXTRA | 
|  | 4065 | processKey(mapper, BTN_EXTRA, 1); | 
|  | 4066 | processSync(mapper); | 
|  | 4067 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 4068 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 4069 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4070 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4071 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4072 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4073 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 4074 |  | 
|  | 4075 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4076 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 4077 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4078 |  | 
|  | 4079 | processKey(mapper, BTN_EXTRA, 0); | 
|  | 4080 | processSync(mapper); | 
|  | 4081 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4082 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4083 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4084 |  | 
|  | 4085 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4086 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4087 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4088 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4089 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 4090 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 4091 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
|  | 4092 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4093 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 4094 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4095 | // press BTN_STYLUS, release BTN_STYLUS | 
|  | 4096 | processKey(mapper, BTN_STYLUS, 1); | 
|  | 4097 | processSync(mapper); | 
|  | 4098 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4099 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4100 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY, motionArgs.buttonState); | 
|  | 4101 |  | 
|  | 4102 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4103 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 4104 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4105 |  | 
|  | 4106 | processKey(mapper, BTN_STYLUS, 0); | 
|  | 4107 | processSync(mapper); | 
|  | 4108 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4109 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4110 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4111 |  | 
|  | 4112 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4113 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4114 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4115 |  | 
|  | 4116 | // press BTN_STYLUS2, release BTN_STYLUS2 | 
|  | 4117 | processKey(mapper, BTN_STYLUS2, 1); | 
|  | 4118 | processSync(mapper); | 
|  | 4119 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4120 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4121 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_SECONDARY, motionArgs.buttonState); | 
|  | 4122 |  | 
|  | 4123 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4124 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 4125 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_SECONDARY, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4126 |  | 
|  | 4127 | processKey(mapper, BTN_STYLUS2, 0); | 
|  | 4128 | processSync(mapper); | 
|  | 4129 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4130 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4131 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4132 |  | 
|  | 4133 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4134 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 4135 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4136 |  | 
|  | 4137 | // release touch | 
|  | 4138 | processUp(mapper); | 
|  | 4139 | processSync(mapper); | 
|  | 4140 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4141 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 4142 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4143 | } | 
|  | 4144 |  | 
|  | 4145 | TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { | 
|  | 4146 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 4147 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 4148 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 4149 | prepareButtons(); | 
|  | 4150 | prepareAxes(POSITION); | 
|  | 4151 | addMapperAndConfigure(mapper); | 
|  | 4152 |  | 
|  | 4153 | NotifyMotionArgs motionArgs; | 
|  | 4154 |  | 
|  | 4155 | // default tool type is finger | 
|  | 4156 | processDown(mapper, 100, 200); | 
|  | 4157 | processSync(mapper); | 
|  | 4158 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4159 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 4160 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4161 |  | 
|  | 4162 | // eraser | 
|  | 4163 | processKey(mapper, BTN_TOOL_RUBBER, 1); | 
|  | 4164 | processSync(mapper); | 
|  | 4165 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4166 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4167 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); | 
|  | 4168 |  | 
|  | 4169 | // stylus | 
|  | 4170 | processKey(mapper, BTN_TOOL_RUBBER, 0); | 
|  | 4171 | processKey(mapper, BTN_TOOL_PEN, 1); | 
|  | 4172 | processSync(mapper); | 
|  | 4173 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4174 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4175 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 4176 |  | 
|  | 4177 | // brush | 
|  | 4178 | processKey(mapper, BTN_TOOL_PEN, 0); | 
|  | 4179 | processKey(mapper, BTN_TOOL_BRUSH, 1); | 
|  | 4180 | processSync(mapper); | 
|  | 4181 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4182 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4183 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 4184 |  | 
|  | 4185 | // pencil | 
|  | 4186 | processKey(mapper, BTN_TOOL_BRUSH, 0); | 
|  | 4187 | processKey(mapper, BTN_TOOL_PENCIL, 1); | 
|  | 4188 | processSync(mapper); | 
|  | 4189 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4190 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4191 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 4192 |  | 
|  | 4193 | // airbrush | 
|  | 4194 | processKey(mapper, BTN_TOOL_PENCIL, 0); | 
|  | 4195 | processKey(mapper, BTN_TOOL_AIRBRUSH, 1); | 
|  | 4196 | processSync(mapper); | 
|  | 4197 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4198 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4199 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 4200 |  | 
|  | 4201 | // mouse | 
|  | 4202 | processKey(mapper, BTN_TOOL_AIRBRUSH, 0); | 
|  | 4203 | processKey(mapper, BTN_TOOL_MOUSE, 1); | 
|  | 4204 | processSync(mapper); | 
|  | 4205 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4206 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4207 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); | 
|  | 4208 |  | 
|  | 4209 | // lens | 
|  | 4210 | processKey(mapper, BTN_TOOL_MOUSE, 0); | 
|  | 4211 | processKey(mapper, BTN_TOOL_LENS, 1); | 
|  | 4212 | processSync(mapper); | 
|  | 4213 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4214 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4215 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); | 
|  | 4216 |  | 
|  | 4217 | // double-tap | 
|  | 4218 | processKey(mapper, BTN_TOOL_LENS, 0); | 
|  | 4219 | processKey(mapper, BTN_TOOL_DOUBLETAP, 1); | 
|  | 4220 | processSync(mapper); | 
|  | 4221 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4222 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4223 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4224 |  | 
|  | 4225 | // triple-tap | 
|  | 4226 | processKey(mapper, BTN_TOOL_DOUBLETAP, 0); | 
|  | 4227 | processKey(mapper, BTN_TOOL_TRIPLETAP, 1); | 
|  | 4228 | processSync(mapper); | 
|  | 4229 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4230 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4231 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4232 |  | 
|  | 4233 | // quad-tap | 
|  | 4234 | processKey(mapper, BTN_TOOL_TRIPLETAP, 0); | 
|  | 4235 | processKey(mapper, BTN_TOOL_QUADTAP, 1); | 
|  | 4236 | processSync(mapper); | 
|  | 4237 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4238 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4239 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4240 |  | 
|  | 4241 | // finger | 
|  | 4242 | processKey(mapper, BTN_TOOL_QUADTAP, 0); | 
|  | 4243 | processKey(mapper, BTN_TOOL_FINGER, 1); | 
|  | 4244 | processSync(mapper); | 
|  | 4245 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4246 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4247 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4248 |  | 
|  | 4249 | // stylus trumps finger | 
|  | 4250 | processKey(mapper, BTN_TOOL_PEN, 1); | 
|  | 4251 | processSync(mapper); | 
|  | 4252 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4253 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4254 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 4255 |  | 
|  | 4256 | // eraser trumps stylus | 
|  | 4257 | processKey(mapper, BTN_TOOL_RUBBER, 1); | 
|  | 4258 | processSync(mapper); | 
|  | 4259 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4260 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4261 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); | 
|  | 4262 |  | 
|  | 4263 | // mouse trumps eraser | 
|  | 4264 | processKey(mapper, BTN_TOOL_MOUSE, 1); | 
|  | 4265 | processSync(mapper); | 
|  | 4266 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4267 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4268 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); | 
|  | 4269 |  | 
|  | 4270 | // back to default tool type | 
|  | 4271 | processKey(mapper, BTN_TOOL_MOUSE, 0); | 
|  | 4272 | processKey(mapper, BTN_TOOL_RUBBER, 0); | 
|  | 4273 | processKey(mapper, BTN_TOOL_PEN, 0); | 
|  | 4274 | processKey(mapper, BTN_TOOL_FINGER, 0); | 
|  | 4275 | processSync(mapper); | 
|  | 4276 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4277 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4278 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4279 | } | 
|  | 4280 |  | 
|  | 4281 | TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { | 
|  | 4282 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 4283 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 4284 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 4285 | prepareButtons(); | 
|  | 4286 | prepareAxes(POSITION); | 
|  | 4287 | mFakeEventHub->addKey(DEVICE_ID, BTN_TOOL_FINGER, 0, AKEYCODE_UNKNOWN, 0); | 
|  | 4288 | addMapperAndConfigure(mapper); | 
|  | 4289 |  | 
|  | 4290 | NotifyMotionArgs motionArgs; | 
|  | 4291 |  | 
|  | 4292 | // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0 | 
|  | 4293 | processKey(mapper, BTN_TOOL_FINGER, 1); | 
|  | 4294 | processMove(mapper, 100, 200); | 
|  | 4295 | processSync(mapper); | 
|  | 4296 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4297 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 4298 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4299 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4300 |  | 
|  | 4301 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4302 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 4303 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4304 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4305 |  | 
|  | 4306 | // move a little | 
|  | 4307 | processMove(mapper, 150, 250); | 
|  | 4308 | processSync(mapper); | 
|  | 4309 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4310 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 4311 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4312 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4313 |  | 
|  | 4314 | // down when BTN_TOUCH is pressed, pressure defaults to 1 | 
|  | 4315 | processKey(mapper, BTN_TOUCH, 1); | 
|  | 4316 | processSync(mapper); | 
|  | 4317 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4318 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 4319 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4320 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4321 |  | 
|  | 4322 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4323 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 4324 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4325 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4326 |  | 
|  | 4327 | // up when BTN_TOUCH is released, hover restored | 
|  | 4328 | processKey(mapper, BTN_TOUCH, 0); | 
|  | 4329 | processSync(mapper); | 
|  | 4330 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4331 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 4332 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4333 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4334 |  | 
|  | 4335 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4336 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 4337 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4338 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4339 |  | 
|  | 4340 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4341 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 4342 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4343 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4344 |  | 
|  | 4345 | // exit hover when pointer goes away | 
|  | 4346 | processKey(mapper, BTN_TOOL_FINGER, 0); | 
|  | 4347 | processSync(mapper); | 
|  | 4348 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4349 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 4350 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4351 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4352 | } | 
|  | 4353 |  | 
|  | 4354 | TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsValueIsZero) { | 
|  | 4355 | SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice); | 
|  | 4356 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 4357 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 4358 | prepareButtons(); | 
|  | 4359 | prepareAxes(POSITION | PRESSURE); | 
|  | 4360 | addMapperAndConfigure(mapper); | 
|  | 4361 |  | 
|  | 4362 | NotifyMotionArgs motionArgs; | 
|  | 4363 |  | 
|  | 4364 | // initially hovering because pressure is 0 | 
|  | 4365 | processDown(mapper, 100, 200); | 
|  | 4366 | processPressure(mapper, 0); | 
|  | 4367 | processSync(mapper); | 
|  | 4368 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4369 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 4370 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4371 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4372 |  | 
|  | 4373 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4374 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 4375 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4376 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4377 |  | 
|  | 4378 | // move a little | 
|  | 4379 | processMove(mapper, 150, 250); | 
|  | 4380 | processSync(mapper); | 
|  | 4381 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4382 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 4383 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4384 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4385 |  | 
|  | 4386 | // down when pressure is non-zero | 
|  | 4387 | processPressure(mapper, RAW_PRESSURE_MAX); | 
|  | 4388 | processSync(mapper); | 
|  | 4389 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4390 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 4391 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4392 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4393 |  | 
|  | 4394 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4395 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 4396 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4397 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4398 |  | 
|  | 4399 | // up when pressure becomes 0, hover restored | 
|  | 4400 | processPressure(mapper, 0); | 
|  | 4401 | processSync(mapper); | 
|  | 4402 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4403 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 4404 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4405 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4406 |  | 
|  | 4407 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4408 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 4409 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4410 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4411 |  | 
|  | 4412 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4413 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 4414 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4415 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4416 |  | 
|  | 4417 | // exit hover when pointer goes away | 
|  | 4418 | processUp(mapper); | 
|  | 4419 | processSync(mapper); | 
|  | 4420 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4421 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 4422 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4423 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4424 | } | 
|  | 4425 |  | 
|  | 4426 |  | 
|  | 4427 | // --- MultiTouchInputMapperTest --- | 
|  | 4428 |  | 
|  | 4429 | class MultiTouchInputMapperTest : public TouchInputMapperTest { | 
|  | 4430 | protected: | 
|  | 4431 | void prepareAxes(int axes); | 
|  | 4432 |  | 
|  | 4433 | void processPosition(MultiTouchInputMapper* mapper, int32_t x, int32_t y); | 
|  | 4434 | void processTouchMajor(MultiTouchInputMapper* mapper, int32_t touchMajor); | 
|  | 4435 | void processTouchMinor(MultiTouchInputMapper* mapper, int32_t touchMinor); | 
|  | 4436 | void processToolMajor(MultiTouchInputMapper* mapper, int32_t toolMajor); | 
|  | 4437 | void processToolMinor(MultiTouchInputMapper* mapper, int32_t toolMinor); | 
|  | 4438 | void processOrientation(MultiTouchInputMapper* mapper, int32_t orientation); | 
|  | 4439 | void processPressure(MultiTouchInputMapper* mapper, int32_t pressure); | 
|  | 4440 | void processDistance(MultiTouchInputMapper* mapper, int32_t distance); | 
|  | 4441 | void processId(MultiTouchInputMapper* mapper, int32_t id); | 
|  | 4442 | void processSlot(MultiTouchInputMapper* mapper, int32_t slot); | 
|  | 4443 | void processToolType(MultiTouchInputMapper* mapper, int32_t toolType); | 
|  | 4444 | void processKey(MultiTouchInputMapper* mapper, int32_t code, int32_t value); | 
| Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 4445 | void processTimestamp(MultiTouchInputMapper* mapper, uint32_t value); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4446 | void processMTSync(MultiTouchInputMapper* mapper); | 
|  | 4447 | void processSync(MultiTouchInputMapper* mapper); | 
|  | 4448 | }; | 
|  | 4449 |  | 
|  | 4450 | void MultiTouchInputMapperTest::prepareAxes(int axes) { | 
|  | 4451 | if (axes & POSITION) { | 
|  | 4452 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_X, | 
|  | 4453 | RAW_X_MIN, RAW_X_MAX, 0, 0); | 
|  | 4454 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_Y, | 
|  | 4455 | RAW_Y_MIN, RAW_Y_MAX, 0, 0); | 
|  | 4456 | } | 
|  | 4457 | if (axes & TOUCH) { | 
|  | 4458 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MAJOR, | 
|  | 4459 | RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0); | 
|  | 4460 | if (axes & MINOR) { | 
|  | 4461 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MINOR, | 
|  | 4462 | RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0); | 
|  | 4463 | } | 
|  | 4464 | } | 
|  | 4465 | if (axes & TOOL) { | 
|  | 4466 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MAJOR, | 
|  | 4467 | RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0); | 
|  | 4468 | if (axes & MINOR) { | 
|  | 4469 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MINOR, | 
|  | 4470 | RAW_TOOL_MAX, RAW_TOOL_MAX, 0, 0); | 
|  | 4471 | } | 
|  | 4472 | } | 
|  | 4473 | if (axes & ORIENTATION) { | 
|  | 4474 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_ORIENTATION, | 
|  | 4475 | RAW_ORIENTATION_MIN, RAW_ORIENTATION_MAX, 0, 0); | 
|  | 4476 | } | 
|  | 4477 | if (axes & PRESSURE) { | 
|  | 4478 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_PRESSURE, | 
|  | 4479 | RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0); | 
|  | 4480 | } | 
|  | 4481 | if (axes & DISTANCE) { | 
|  | 4482 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_DISTANCE, | 
|  | 4483 | RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0); | 
|  | 4484 | } | 
|  | 4485 | if (axes & ID) { | 
|  | 4486 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TRACKING_ID, | 
|  | 4487 | RAW_ID_MIN, RAW_ID_MAX, 0, 0); | 
|  | 4488 | } | 
|  | 4489 | if (axes & SLOT) { | 
|  | 4490 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_SLOT, | 
|  | 4491 | RAW_SLOT_MIN, RAW_SLOT_MAX, 0, 0); | 
|  | 4492 | mFakeEventHub->setAbsoluteAxisValue(DEVICE_ID, ABS_MT_SLOT, 0); | 
|  | 4493 | } | 
|  | 4494 | if (axes & TOOL_TYPE) { | 
|  | 4495 | mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOOL_TYPE, | 
|  | 4496 | 0, MT_TOOL_MAX, 0, 0); | 
|  | 4497 | } | 
|  | 4498 | } | 
|  | 4499 |  | 
|  | 4500 | void MultiTouchInputMapperTest::processPosition( | 
|  | 4501 | MultiTouchInputMapper* mapper, int32_t x, int32_t y) { | 
|  | 4502 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_X, x); | 
|  | 4503 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_Y, y); | 
|  | 4504 | } | 
|  | 4505 |  | 
|  | 4506 | void MultiTouchInputMapperTest::processTouchMajor( | 
|  | 4507 | MultiTouchInputMapper* mapper, int32_t touchMajor) { | 
|  | 4508 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MAJOR, touchMajor); | 
|  | 4509 | } | 
|  | 4510 |  | 
|  | 4511 | void MultiTouchInputMapperTest::processTouchMinor( | 
|  | 4512 | MultiTouchInputMapper* mapper, int32_t touchMinor) { | 
|  | 4513 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MINOR, touchMinor); | 
|  | 4514 | } | 
|  | 4515 |  | 
|  | 4516 | void MultiTouchInputMapperTest::processToolMajor( | 
|  | 4517 | MultiTouchInputMapper* mapper, int32_t toolMajor) { | 
|  | 4518 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MAJOR, toolMajor); | 
|  | 4519 | } | 
|  | 4520 |  | 
|  | 4521 | void MultiTouchInputMapperTest::processToolMinor( | 
|  | 4522 | MultiTouchInputMapper* mapper, int32_t toolMinor) { | 
|  | 4523 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MINOR, toolMinor); | 
|  | 4524 | } | 
|  | 4525 |  | 
|  | 4526 | void MultiTouchInputMapperTest::processOrientation( | 
|  | 4527 | MultiTouchInputMapper* mapper, int32_t orientation) { | 
|  | 4528 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_ORIENTATION, orientation); | 
|  | 4529 | } | 
|  | 4530 |  | 
|  | 4531 | void MultiTouchInputMapperTest::processPressure( | 
|  | 4532 | MultiTouchInputMapper* mapper, int32_t pressure) { | 
|  | 4533 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_PRESSURE, pressure); | 
|  | 4534 | } | 
|  | 4535 |  | 
|  | 4536 | void MultiTouchInputMapperTest::processDistance( | 
|  | 4537 | MultiTouchInputMapper* mapper, int32_t distance) { | 
|  | 4538 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_DISTANCE, distance); | 
|  | 4539 | } | 
|  | 4540 |  | 
|  | 4541 | void MultiTouchInputMapperTest::processId( | 
|  | 4542 | MultiTouchInputMapper* mapper, int32_t id) { | 
|  | 4543 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TRACKING_ID, id); | 
|  | 4544 | } | 
|  | 4545 |  | 
|  | 4546 | void MultiTouchInputMapperTest::processSlot( | 
|  | 4547 | MultiTouchInputMapper* mapper, int32_t slot) { | 
|  | 4548 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_SLOT, slot); | 
|  | 4549 | } | 
|  | 4550 |  | 
|  | 4551 | void MultiTouchInputMapperTest::processToolType( | 
|  | 4552 | MultiTouchInputMapper* mapper, int32_t toolType) { | 
|  | 4553 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOOL_TYPE, toolType); | 
|  | 4554 | } | 
|  | 4555 |  | 
|  | 4556 | void MultiTouchInputMapperTest::processKey( | 
|  | 4557 | MultiTouchInputMapper* mapper, int32_t code, int32_t value) { | 
|  | 4558 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value); | 
|  | 4559 | } | 
|  | 4560 |  | 
| Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 4561 | void MultiTouchInputMapperTest::processTimestamp(MultiTouchInputMapper* mapper, uint32_t value) { | 
|  | 4562 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_MSC, MSC_TIMESTAMP, value); | 
|  | 4563 | } | 
|  | 4564 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 4565 | void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper* mapper) { | 
|  | 4566 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_MT_REPORT, 0); | 
|  | 4567 | } | 
|  | 4568 |  | 
|  | 4569 | void MultiTouchInputMapperTest::processSync(MultiTouchInputMapper* mapper) { | 
|  | 4570 | process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); | 
|  | 4571 | } | 
|  | 4572 |  | 
|  | 4573 |  | 
|  | 4574 | TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackingIds) { | 
|  | 4575 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 4576 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 4577 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 4578 | prepareAxes(POSITION); | 
|  | 4579 | prepareVirtualKeys(); | 
|  | 4580 | addMapperAndConfigure(mapper); | 
|  | 4581 |  | 
|  | 4582 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 4583 |  | 
|  | 4584 | NotifyMotionArgs motionArgs; | 
|  | 4585 |  | 
|  | 4586 | // Two fingers down at once. | 
|  | 4587 | int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; | 
|  | 4588 | processPosition(mapper, x1, y1); | 
|  | 4589 | processMTSync(mapper); | 
|  | 4590 | processPosition(mapper, x2, y2); | 
|  | 4591 | processMTSync(mapper); | 
|  | 4592 | processSync(mapper); | 
|  | 4593 |  | 
|  | 4594 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4595 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4596 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4597 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4598 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4599 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 4600 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4601 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4602 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4603 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4604 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4605 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4606 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4607 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4608 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4609 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4610 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4611 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4612 |  | 
|  | 4613 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4614 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4615 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4616 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4617 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4618 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4619 | motionArgs.action); | 
|  | 4620 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4621 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4622 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4623 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4624 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4625 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4626 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4627 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4628 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4629 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4630 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4631 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4632 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4633 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4634 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4635 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4636 |  | 
|  | 4637 | // Move. | 
|  | 4638 | x1 += 10; y1 += 15; x2 += 5; y2 -= 10; | 
|  | 4639 | processPosition(mapper, x1, y1); | 
|  | 4640 | processMTSync(mapper); | 
|  | 4641 | processPosition(mapper, x2, y2); | 
|  | 4642 | processMTSync(mapper); | 
|  | 4643 | processSync(mapper); | 
|  | 4644 |  | 
|  | 4645 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4646 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4647 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4648 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4649 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4650 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4651 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4652 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4653 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4654 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4655 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4656 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4657 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4658 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4659 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4660 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4661 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4662 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4663 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4664 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4665 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4666 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4667 |  | 
|  | 4668 | // First finger up. | 
|  | 4669 | x2 += 15; y2 -= 20; | 
|  | 4670 | processPosition(mapper, x2, y2); | 
|  | 4671 | processMTSync(mapper); | 
|  | 4672 | processSync(mapper); | 
|  | 4673 |  | 
|  | 4674 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4675 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4676 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4677 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4678 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4679 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4680 | motionArgs.action); | 
|  | 4681 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4682 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4683 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4684 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4685 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4686 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4687 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4688 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4689 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4690 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4691 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4692 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4693 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4694 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4695 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4696 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4697 |  | 
|  | 4698 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4699 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4700 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4701 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4702 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4703 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4704 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4705 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4706 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4707 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4708 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4709 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); | 
|  | 4710 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4711 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4712 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4713 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4714 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4715 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4716 |  | 
|  | 4717 | // Move. | 
|  | 4718 | x2 += 20; y2 -= 25; | 
|  | 4719 | processPosition(mapper, x2, y2); | 
|  | 4720 | processMTSync(mapper); | 
|  | 4721 | processSync(mapper); | 
|  | 4722 |  | 
|  | 4723 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4724 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4725 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4726 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4727 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4728 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4729 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4730 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4731 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4732 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4733 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4734 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); | 
|  | 4735 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4736 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4737 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4738 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4739 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4740 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4741 |  | 
|  | 4742 | // New finger down. | 
|  | 4743 | int32_t x3 = 700, y3 = 300; | 
|  | 4744 | processPosition(mapper, x2, y2); | 
|  | 4745 | processMTSync(mapper); | 
|  | 4746 | processPosition(mapper, x3, y3); | 
|  | 4747 | processMTSync(mapper); | 
|  | 4748 | processSync(mapper); | 
|  | 4749 |  | 
|  | 4750 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4751 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4752 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4753 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4754 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4755 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4756 | motionArgs.action); | 
|  | 4757 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4758 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4759 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4760 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4761 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4762 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4763 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4764 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4765 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4766 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4767 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4768 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4769 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4770 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4771 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4772 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4773 |  | 
|  | 4774 | // Second finger up. | 
|  | 4775 | x3 += 30; y3 -= 20; | 
|  | 4776 | processPosition(mapper, x3, y3); | 
|  | 4777 | processMTSync(mapper); | 
|  | 4778 | processSync(mapper); | 
|  | 4779 |  | 
|  | 4780 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4781 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4782 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4783 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4784 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4785 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4786 | motionArgs.action); | 
|  | 4787 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4788 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4789 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4790 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4791 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4792 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4793 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4794 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4795 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4796 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4797 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4798 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4799 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4800 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4801 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4802 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4803 |  | 
|  | 4804 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4805 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4806 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4807 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4808 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4809 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4810 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4811 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4812 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4813 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4814 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4815 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4816 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4817 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4818 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4819 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4820 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4821 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4822 |  | 
|  | 4823 | // Last finger up. | 
|  | 4824 | processMTSync(mapper); | 
|  | 4825 | processSync(mapper); | 
|  | 4826 |  | 
|  | 4827 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4828 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime); | 
|  | 4829 | ASSERT_EQ(DEVICE_ID, motionArgs.deviceId); | 
|  | 4830 | ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source); | 
|  | 4831 | ASSERT_EQ(uint32_t(0), motionArgs.policyFlags); | 
|  | 4832 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 4833 | ASSERT_EQ(0, motionArgs.flags); | 
|  | 4834 | ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState); | 
|  | 4835 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 4836 | ASSERT_EQ(0, motionArgs.edgeFlags); | 
|  | 4837 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4838 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4839 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4840 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4841 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4842 | ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); | 
|  | 4843 | ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON); | 
|  | 4844 | ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime); | 
|  | 4845 |  | 
|  | 4846 | // Should not have sent any more keys or motions. | 
|  | 4847 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 4848 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 4849 | } | 
|  | 4850 |  | 
|  | 4851 | TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingIds) { | 
|  | 4852 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 4853 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 4854 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 4855 | prepareAxes(POSITION | ID); | 
|  | 4856 | prepareVirtualKeys(); | 
|  | 4857 | addMapperAndConfigure(mapper); | 
|  | 4858 |  | 
|  | 4859 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 4860 |  | 
|  | 4861 | NotifyMotionArgs motionArgs; | 
|  | 4862 |  | 
|  | 4863 | // Two fingers down at once. | 
|  | 4864 | int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; | 
|  | 4865 | processPosition(mapper, x1, y1); | 
|  | 4866 | processId(mapper, 1); | 
|  | 4867 | processMTSync(mapper); | 
|  | 4868 | processPosition(mapper, x2, y2); | 
|  | 4869 | processId(mapper, 2); | 
|  | 4870 | processMTSync(mapper); | 
|  | 4871 | processSync(mapper); | 
|  | 4872 |  | 
|  | 4873 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4874 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 4875 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4876 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4877 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4878 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4879 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4880 |  | 
|  | 4881 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4882 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4883 | motionArgs.action); | 
|  | 4884 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4885 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4886 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4887 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4888 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4889 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4890 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4891 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4892 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4893 |  | 
|  | 4894 | // Move. | 
|  | 4895 | x1 += 10; y1 += 15; x2 += 5; y2 -= 10; | 
|  | 4896 | processPosition(mapper, x1, y1); | 
|  | 4897 | processId(mapper, 1); | 
|  | 4898 | processMTSync(mapper); | 
|  | 4899 | processPosition(mapper, x2, y2); | 
|  | 4900 | processId(mapper, 2); | 
|  | 4901 | processMTSync(mapper); | 
|  | 4902 | processSync(mapper); | 
|  | 4903 |  | 
|  | 4904 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4905 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4906 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4907 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4908 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4909 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4910 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4911 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4912 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4913 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4914 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4915 |  | 
|  | 4916 | // First finger up. | 
|  | 4917 | x2 += 15; y2 -= 20; | 
|  | 4918 | processPosition(mapper, x2, y2); | 
|  | 4919 | processId(mapper, 2); | 
|  | 4920 | processMTSync(mapper); | 
|  | 4921 | processSync(mapper); | 
|  | 4922 |  | 
|  | 4923 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4924 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4925 | motionArgs.action); | 
|  | 4926 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4927 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4928 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4929 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4930 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4931 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4932 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4933 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4934 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4935 |  | 
|  | 4936 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4937 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4938 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4939 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); | 
|  | 4940 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4941 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4942 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4943 |  | 
|  | 4944 | // Move. | 
|  | 4945 | x2 += 20; y2 -= 25; | 
|  | 4946 | processPosition(mapper, x2, y2); | 
|  | 4947 | processId(mapper, 2); | 
|  | 4948 | processMTSync(mapper); | 
|  | 4949 | processSync(mapper); | 
|  | 4950 |  | 
|  | 4951 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4952 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 4953 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 4954 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); | 
|  | 4955 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4956 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4957 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4958 |  | 
|  | 4959 | // New finger down. | 
|  | 4960 | int32_t x3 = 700, y3 = 300; | 
|  | 4961 | processPosition(mapper, x2, y2); | 
|  | 4962 | processId(mapper, 2); | 
|  | 4963 | processMTSync(mapper); | 
|  | 4964 | processPosition(mapper, x3, y3); | 
|  | 4965 | processId(mapper, 3); | 
|  | 4966 | processMTSync(mapper); | 
|  | 4967 | processSync(mapper); | 
|  | 4968 |  | 
|  | 4969 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4970 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4971 | motionArgs.action); | 
|  | 4972 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4973 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4974 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4975 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4976 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4977 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4978 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4979 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 4980 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4981 |  | 
|  | 4982 | // Second finger up. | 
|  | 4983 | x3 += 30; y3 -= 20; | 
|  | 4984 | processPosition(mapper, x3, y3); | 
|  | 4985 | processId(mapper, 3); | 
|  | 4986 | processMTSync(mapper); | 
|  | 4987 | processSync(mapper); | 
|  | 4988 |  | 
|  | 4989 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 4990 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 4991 | motionArgs.action); | 
|  | 4992 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 4993 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 4994 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 4995 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 4996 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 4997 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 4998 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 4999 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 5000 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5001 |  | 
|  | 5002 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5003 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5004 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 5005 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5006 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5007 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5008 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5009 |  | 
|  | 5010 | // Last finger up. | 
|  | 5011 | processMTSync(mapper); | 
|  | 5012 | processSync(mapper); | 
|  | 5013 |  | 
|  | 5014 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5015 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 5016 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 5017 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5018 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5019 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5020 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5021 |  | 
|  | 5022 | // Should not have sent any more keys or motions. | 
|  | 5023 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 5024 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 5025 | } | 
|  | 5026 |  | 
|  | 5027 | TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { | 
|  | 5028 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5029 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5030 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5031 | prepareAxes(POSITION | ID | SLOT); | 
|  | 5032 | prepareVirtualKeys(); | 
|  | 5033 | addMapperAndConfigure(mapper); | 
|  | 5034 |  | 
|  | 5035 | mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON); | 
|  | 5036 |  | 
|  | 5037 | NotifyMotionArgs motionArgs; | 
|  | 5038 |  | 
|  | 5039 | // Two fingers down at once. | 
|  | 5040 | int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500; | 
|  | 5041 | processPosition(mapper, x1, y1); | 
|  | 5042 | processId(mapper, 1); | 
|  | 5043 | processSlot(mapper, 1); | 
|  | 5044 | processPosition(mapper, x2, y2); | 
|  | 5045 | processId(mapper, 2); | 
|  | 5046 | processSync(mapper); | 
|  | 5047 |  | 
|  | 5048 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5049 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 5050 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 5051 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5052 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5053 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5054 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5055 |  | 
|  | 5056 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5057 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 5058 | motionArgs.action); | 
|  | 5059 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 5060 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5061 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5062 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 5063 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 5064 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5065 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5066 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 5067 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5068 |  | 
|  | 5069 | // Move. | 
|  | 5070 | x1 += 10; y1 += 15; x2 += 5; y2 -= 10; | 
|  | 5071 | processSlot(mapper, 0); | 
|  | 5072 | processPosition(mapper, x1, y1); | 
|  | 5073 | processSlot(mapper, 1); | 
|  | 5074 | processPosition(mapper, x2, y2); | 
|  | 5075 | processSync(mapper); | 
|  | 5076 |  | 
|  | 5077 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5078 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5079 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 5080 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5081 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5082 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 5083 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 5084 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5085 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5086 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 5087 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5088 |  | 
|  | 5089 | // First finger up. | 
|  | 5090 | x2 += 15; y2 -= 20; | 
|  | 5091 | processSlot(mapper, 0); | 
|  | 5092 | processId(mapper, -1); | 
|  | 5093 | processSlot(mapper, 1); | 
|  | 5094 | processPosition(mapper, x2, y2); | 
|  | 5095 | processSync(mapper); | 
|  | 5096 |  | 
|  | 5097 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5098 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 5099 | motionArgs.action); | 
|  | 5100 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 5101 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5102 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5103 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 5104 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 5105 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5106 | toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5107 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 5108 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5109 |  | 
|  | 5110 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5111 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5112 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 5113 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); | 
|  | 5114 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5115 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5116 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5117 |  | 
|  | 5118 | // Move. | 
|  | 5119 | x2 += 20; y2 -= 25; | 
|  | 5120 | processPosition(mapper, x2, y2); | 
|  | 5121 | processSync(mapper); | 
|  | 5122 |  | 
|  | 5123 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5124 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5125 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 5126 | ASSERT_EQ(1, motionArgs.pointerProperties[0].id); | 
|  | 5127 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5128 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5129 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5130 |  | 
|  | 5131 | // New finger down. | 
|  | 5132 | int32_t x3 = 700, y3 = 300; | 
|  | 5133 | processPosition(mapper, x2, y2); | 
|  | 5134 | processSlot(mapper, 0); | 
|  | 5135 | processId(mapper, 3); | 
|  | 5136 | processPosition(mapper, x3, y3); | 
|  | 5137 | processSync(mapper); | 
|  | 5138 |  | 
|  | 5139 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5140 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 5141 | motionArgs.action); | 
|  | 5142 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 5143 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5144 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5145 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 5146 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 5147 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5148 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5149 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 5150 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5151 |  | 
|  | 5152 | // Second finger up. | 
|  | 5153 | x3 += 30; y3 -= 20; | 
|  | 5154 | processSlot(mapper, 1); | 
|  | 5155 | processId(mapper, -1); | 
|  | 5156 | processSlot(mapper, 0); | 
|  | 5157 | processPosition(mapper, x3, y3); | 
|  | 5158 | processSync(mapper); | 
|  | 5159 |  | 
|  | 5160 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5161 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 5162 | motionArgs.action); | 
|  | 5163 | ASSERT_EQ(size_t(2), motionArgs.pointerCount); | 
|  | 5164 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5165 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5166 | ASSERT_EQ(1, motionArgs.pointerProperties[1].id); | 
|  | 5167 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); | 
|  | 5168 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5169 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5170 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], | 
|  | 5171 | toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5172 |  | 
|  | 5173 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5174 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5175 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 5176 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5177 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5178 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5179 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5180 |  | 
|  | 5181 | // Last finger up. | 
|  | 5182 | processId(mapper, -1); | 
|  | 5183 | processSync(mapper); | 
|  | 5184 |  | 
|  | 5185 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5186 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 5187 | ASSERT_EQ(size_t(1), motionArgs.pointerCount); | 
|  | 5188 | ASSERT_EQ(0, motionArgs.pointerProperties[0].id); | 
|  | 5189 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5190 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5191 | toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5192 |  | 
|  | 5193 | // Should not have sent any more keys or motions. | 
|  | 5194 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 5195 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); | 
|  | 5196 | } | 
|  | 5197 |  | 
|  | 5198 | TEST_F(MultiTouchInputMapperTest, Process_AllAxes_WithDefaultCalibration) { | 
|  | 5199 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5200 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5201 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5202 | prepareAxes(POSITION | TOUCH | TOOL | PRESSURE | ORIENTATION | ID | MINOR | DISTANCE); | 
|  | 5203 | addMapperAndConfigure(mapper); | 
|  | 5204 |  | 
|  | 5205 | // These calculations are based on the input device calibration documentation. | 
|  | 5206 | int32_t rawX = 100; | 
|  | 5207 | int32_t rawY = 200; | 
|  | 5208 | int32_t rawTouchMajor = 7; | 
|  | 5209 | int32_t rawTouchMinor = 6; | 
|  | 5210 | int32_t rawToolMajor = 9; | 
|  | 5211 | int32_t rawToolMinor = 8; | 
|  | 5212 | int32_t rawPressure = 11; | 
|  | 5213 | int32_t rawDistance = 0; | 
|  | 5214 | int32_t rawOrientation = 3; | 
|  | 5215 | int32_t id = 5; | 
|  | 5216 |  | 
|  | 5217 | float x = toDisplayX(rawX); | 
|  | 5218 | float y = toDisplayY(rawY); | 
|  | 5219 | float pressure = float(rawPressure) / RAW_PRESSURE_MAX; | 
|  | 5220 | float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX; | 
|  | 5221 | float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE; | 
|  | 5222 | float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE; | 
|  | 5223 | float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE; | 
|  | 5224 | float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE; | 
|  | 5225 | float orientation = float(rawOrientation) / RAW_ORIENTATION_MAX * M_PI_2; | 
|  | 5226 | float distance = float(rawDistance); | 
|  | 5227 |  | 
|  | 5228 | processPosition(mapper, rawX, rawY); | 
|  | 5229 | processTouchMajor(mapper, rawTouchMajor); | 
|  | 5230 | processTouchMinor(mapper, rawTouchMinor); | 
|  | 5231 | processToolMajor(mapper, rawToolMajor); | 
|  | 5232 | processToolMinor(mapper, rawToolMinor); | 
|  | 5233 | processPressure(mapper, rawPressure); | 
|  | 5234 | processOrientation(mapper, rawOrientation); | 
|  | 5235 | processDistance(mapper, rawDistance); | 
|  | 5236 | processId(mapper, id); | 
|  | 5237 | processMTSync(mapper); | 
|  | 5238 | processSync(mapper); | 
|  | 5239 |  | 
|  | 5240 | NotifyMotionArgs args; | 
|  | 5241 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5242 | ASSERT_EQ(0, args.pointerProperties[0].id); | 
|  | 5243 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 5244 | x, y, pressure, size, touchMajor, touchMinor, toolMajor, toolMinor, | 
|  | 5245 | orientation, distance)); | 
|  | 5246 | } | 
|  | 5247 |  | 
|  | 5248 | TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_GeometricCalibration) { | 
|  | 5249 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5250 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5251 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5252 | prepareAxes(POSITION | TOUCH | TOOL | MINOR); | 
|  | 5253 | addConfigurationProperty("touch.size.calibration", "geometric"); | 
|  | 5254 | addMapperAndConfigure(mapper); | 
|  | 5255 |  | 
|  | 5256 | // These calculations are based on the input device calibration documentation. | 
|  | 5257 | int32_t rawX = 100; | 
|  | 5258 | int32_t rawY = 200; | 
|  | 5259 | int32_t rawTouchMajor = 140; | 
|  | 5260 | int32_t rawTouchMinor = 120; | 
|  | 5261 | int32_t rawToolMajor = 180; | 
|  | 5262 | int32_t rawToolMinor = 160; | 
|  | 5263 |  | 
|  | 5264 | float x = toDisplayX(rawX); | 
|  | 5265 | float y = toDisplayY(rawY); | 
|  | 5266 | float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX; | 
|  | 5267 | float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE; | 
|  | 5268 | float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE; | 
|  | 5269 | float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE; | 
|  | 5270 | float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE; | 
|  | 5271 |  | 
|  | 5272 | processPosition(mapper, rawX, rawY); | 
|  | 5273 | processTouchMajor(mapper, rawTouchMajor); | 
|  | 5274 | processTouchMinor(mapper, rawTouchMinor); | 
|  | 5275 | processToolMajor(mapper, rawToolMajor); | 
|  | 5276 | processToolMinor(mapper, rawToolMinor); | 
|  | 5277 | processMTSync(mapper); | 
|  | 5278 | processSync(mapper); | 
|  | 5279 |  | 
|  | 5280 | NotifyMotionArgs args; | 
|  | 5281 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5282 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 5283 | x, y, 1.0f, size, touchMajor, touchMinor, toolMajor, toolMinor, 0, 0)); | 
|  | 5284 | } | 
|  | 5285 |  | 
|  | 5286 | TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_SummedLinearCalibration) { | 
|  | 5287 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5288 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5289 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5290 | prepareAxes(POSITION | TOUCH | TOOL); | 
|  | 5291 | addConfigurationProperty("touch.size.calibration", "diameter"); | 
|  | 5292 | addConfigurationProperty("touch.size.scale", "10"); | 
|  | 5293 | addConfigurationProperty("touch.size.bias", "160"); | 
|  | 5294 | addConfigurationProperty("touch.size.isSummed", "1"); | 
|  | 5295 | addMapperAndConfigure(mapper); | 
|  | 5296 |  | 
|  | 5297 | // These calculations are based on the input device calibration documentation. | 
|  | 5298 | // Note: We only provide a single common touch/tool value because the device is assumed | 
|  | 5299 | //       not to emit separate values for each pointer (isSummed = 1). | 
|  | 5300 | int32_t rawX = 100; | 
|  | 5301 | int32_t rawY = 200; | 
|  | 5302 | int32_t rawX2 = 150; | 
|  | 5303 | int32_t rawY2 = 250; | 
|  | 5304 | int32_t rawTouchMajor = 5; | 
|  | 5305 | int32_t rawToolMajor = 8; | 
|  | 5306 |  | 
|  | 5307 | float x = toDisplayX(rawX); | 
|  | 5308 | float y = toDisplayY(rawY); | 
|  | 5309 | float x2 = toDisplayX(rawX2); | 
|  | 5310 | float y2 = toDisplayY(rawY2); | 
|  | 5311 | float size = float(rawTouchMajor) / 2 / RAW_TOUCH_MAX; | 
|  | 5312 | float touch = float(rawTouchMajor) / 2 * 10.0f + 160.0f; | 
|  | 5313 | float tool = float(rawToolMajor) / 2 * 10.0f + 160.0f; | 
|  | 5314 |  | 
|  | 5315 | processPosition(mapper, rawX, rawY); | 
|  | 5316 | processTouchMajor(mapper, rawTouchMajor); | 
|  | 5317 | processToolMajor(mapper, rawToolMajor); | 
|  | 5318 | processMTSync(mapper); | 
|  | 5319 | processPosition(mapper, rawX2, rawY2); | 
|  | 5320 | processTouchMajor(mapper, rawTouchMajor); | 
|  | 5321 | processToolMajor(mapper, rawToolMajor); | 
|  | 5322 | processMTSync(mapper); | 
|  | 5323 | processSync(mapper); | 
|  | 5324 |  | 
|  | 5325 | NotifyMotionArgs args; | 
|  | 5326 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5327 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action); | 
|  | 5328 |  | 
|  | 5329 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5330 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), | 
|  | 5331 | args.action); | 
|  | 5332 | ASSERT_EQ(size_t(2), args.pointerCount); | 
|  | 5333 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 5334 | x, y, 1.0f, size, touch, touch, tool, tool, 0, 0)); | 
|  | 5335 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[1], | 
|  | 5336 | x2, y2, 1.0f, size, touch, touch, tool, tool, 0, 0)); | 
|  | 5337 | } | 
|  | 5338 |  | 
|  | 5339 | TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_AreaCalibration) { | 
|  | 5340 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5341 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5342 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5343 | prepareAxes(POSITION | TOUCH | TOOL); | 
|  | 5344 | addConfigurationProperty("touch.size.calibration", "area"); | 
|  | 5345 | addConfigurationProperty("touch.size.scale", "43"); | 
|  | 5346 | addConfigurationProperty("touch.size.bias", "3"); | 
|  | 5347 | addMapperAndConfigure(mapper); | 
|  | 5348 |  | 
|  | 5349 | // These calculations are based on the input device calibration documentation. | 
|  | 5350 | int32_t rawX = 100; | 
|  | 5351 | int32_t rawY = 200; | 
|  | 5352 | int32_t rawTouchMajor = 5; | 
|  | 5353 | int32_t rawToolMajor = 8; | 
|  | 5354 |  | 
|  | 5355 | float x = toDisplayX(rawX); | 
|  | 5356 | float y = toDisplayY(rawY); | 
|  | 5357 | float size = float(rawTouchMajor) / RAW_TOUCH_MAX; | 
|  | 5358 | float touch = sqrtf(rawTouchMajor) * 43.0f + 3.0f; | 
|  | 5359 | float tool = sqrtf(rawToolMajor) * 43.0f + 3.0f; | 
|  | 5360 |  | 
|  | 5361 | processPosition(mapper, rawX, rawY); | 
|  | 5362 | processTouchMajor(mapper, rawTouchMajor); | 
|  | 5363 | processToolMajor(mapper, rawToolMajor); | 
|  | 5364 | processMTSync(mapper); | 
|  | 5365 | processSync(mapper); | 
|  | 5366 |  | 
|  | 5367 | NotifyMotionArgs args; | 
|  | 5368 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5369 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 5370 | x, y, 1.0f, size, touch, touch, tool, tool, 0, 0)); | 
|  | 5371 | } | 
|  | 5372 |  | 
|  | 5373 | TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) { | 
|  | 5374 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5375 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5376 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5377 | prepareAxes(POSITION | PRESSURE); | 
|  | 5378 | addConfigurationProperty("touch.pressure.calibration", "amplitude"); | 
|  | 5379 | addConfigurationProperty("touch.pressure.scale", "0.01"); | 
|  | 5380 | addMapperAndConfigure(mapper); | 
|  | 5381 |  | 
| Michael Wright | aa449c9 | 2017-12-13 21:21:43 +0000 | [diff] [blame] | 5382 | InputDeviceInfo info; | 
|  | 5383 | mapper->populateDeviceInfo(&info); | 
|  | 5384 | ASSERT_NO_FATAL_FAILURE(assertMotionRange(info, | 
|  | 5385 | AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TOUCHSCREEN, | 
|  | 5386 | 0.0f, RAW_PRESSURE_MAX * 0.01, 0.0f, 0.0f)); | 
|  | 5387 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5388 | // These calculations are based on the input device calibration documentation. | 
|  | 5389 | int32_t rawX = 100; | 
|  | 5390 | int32_t rawY = 200; | 
|  | 5391 | int32_t rawPressure = 60; | 
|  | 5392 |  | 
|  | 5393 | float x = toDisplayX(rawX); | 
|  | 5394 | float y = toDisplayY(rawY); | 
|  | 5395 | float pressure = float(rawPressure) * 0.01f; | 
|  | 5396 |  | 
|  | 5397 | processPosition(mapper, rawX, rawY); | 
|  | 5398 | processPressure(mapper, rawPressure); | 
|  | 5399 | processMTSync(mapper); | 
|  | 5400 | processSync(mapper); | 
|  | 5401 |  | 
|  | 5402 | NotifyMotionArgs args; | 
|  | 5403 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5404 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], | 
|  | 5405 | x, y, pressure, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5406 | } | 
|  | 5407 |  | 
|  | 5408 | TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllButtons) { | 
|  | 5409 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5410 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5411 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5412 | prepareAxes(POSITION | ID | SLOT); | 
|  | 5413 | addMapperAndConfigure(mapper); | 
|  | 5414 |  | 
|  | 5415 | NotifyMotionArgs motionArgs; | 
|  | 5416 | NotifyKeyArgs keyArgs; | 
|  | 5417 |  | 
|  | 5418 | processId(mapper, 1); | 
|  | 5419 | processPosition(mapper, 100, 200); | 
|  | 5420 | processSync(mapper); | 
|  | 5421 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5422 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 5423 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 5424 |  | 
|  | 5425 | // press BTN_LEFT, release BTN_LEFT | 
|  | 5426 | processKey(mapper, BTN_LEFT, 1); | 
|  | 5427 | processSync(mapper); | 
|  | 5428 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5429 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5430 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); | 
|  | 5431 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5432 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5433 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5434 | ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState); | 
|  | 5435 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5436 | processKey(mapper, BTN_LEFT, 0); | 
|  | 5437 | processSync(mapper); | 
|  | 5438 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5439 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5440 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5441 |  | 
|  | 5442 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5443 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5444 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5445 |  | 
|  | 5446 | // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE | 
|  | 5447 | processKey(mapper, BTN_RIGHT, 1); | 
|  | 5448 | processKey(mapper, BTN_MIDDLE, 1); | 
|  | 5449 | processSync(mapper); | 
|  | 5450 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5451 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5452 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 5453 | motionArgs.buttonState); | 
|  | 5454 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5455 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5456 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5457 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
|  | 5458 |  | 
|  | 5459 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5460 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5461 | ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY, | 
|  | 5462 | motionArgs.buttonState); | 
|  | 5463 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5464 | processKey(mapper, BTN_RIGHT, 0); | 
|  | 5465 | processSync(mapper); | 
|  | 5466 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5467 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5468 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5469 |  | 
|  | 5470 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5471 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5472 | ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5473 |  | 
|  | 5474 | processKey(mapper, BTN_MIDDLE, 0); | 
|  | 5475 | processSync(mapper); | 
|  | 5476 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5477 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5478 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5479 |  | 
|  | 5480 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5481 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5482 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5483 |  | 
|  | 5484 | // press BTN_BACK, release BTN_BACK | 
|  | 5485 | processKey(mapper, BTN_BACK, 1); | 
|  | 5486 | processSync(mapper); | 
|  | 5487 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5488 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 5489 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5490 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5491 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5492 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5493 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 5494 |  | 
|  | 5495 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5496 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5497 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5498 |  | 
|  | 5499 | processKey(mapper, BTN_BACK, 0); | 
|  | 5500 | processSync(mapper); | 
|  | 5501 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5502 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5503 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5504 |  | 
|  | 5505 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5506 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5507 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 5508 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5509 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5510 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 5511 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
|  | 5512 |  | 
|  | 5513 | // press BTN_SIDE, release BTN_SIDE | 
|  | 5514 | processKey(mapper, BTN_SIDE, 1); | 
|  | 5515 | processSync(mapper); | 
|  | 5516 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5517 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 5518 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5519 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5520 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5521 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5522 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
|  | 5523 |  | 
|  | 5524 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5525 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5526 | ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5527 |  | 
|  | 5528 | processKey(mapper, BTN_SIDE, 0); | 
|  | 5529 | processSync(mapper); | 
|  | 5530 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5531 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5532 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5533 |  | 
|  | 5534 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5535 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5536 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 5537 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5538 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5539 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 5540 | ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode); | 
|  | 5541 |  | 
|  | 5542 | // press BTN_FORWARD, release BTN_FORWARD | 
|  | 5543 | processKey(mapper, BTN_FORWARD, 1); | 
|  | 5544 | processSync(mapper); | 
|  | 5545 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5546 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 5547 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5548 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5549 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5550 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5551 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 5552 |  | 
|  | 5553 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5554 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5555 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5556 |  | 
|  | 5557 | processKey(mapper, BTN_FORWARD, 0); | 
|  | 5558 | processSync(mapper); | 
|  | 5559 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5560 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5561 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5562 |  | 
|  | 5563 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5564 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5565 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 5566 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5567 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5568 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 5569 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
|  | 5570 |  | 
|  | 5571 | // press BTN_EXTRA, release BTN_EXTRA | 
|  | 5572 | processKey(mapper, BTN_EXTRA, 1); | 
|  | 5573 | processSync(mapper); | 
|  | 5574 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5575 | ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action); | 
|  | 5576 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5577 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5578 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5579 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5580 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
|  | 5581 |  | 
|  | 5582 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5583 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5584 | ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5585 |  | 
|  | 5586 | processKey(mapper, BTN_EXTRA, 0); | 
|  | 5587 | processSync(mapper); | 
|  | 5588 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5589 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5590 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5591 |  | 
|  | 5592 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5593 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5594 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 5595 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5596 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs)); | 
|  | 5597 | ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action); | 
|  | 5598 | ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode); | 
|  | 5599 |  | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5600 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled()); | 
|  | 5601 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5602 | // press BTN_STYLUS, release BTN_STYLUS | 
|  | 5603 | processKey(mapper, BTN_STYLUS, 1); | 
|  | 5604 | processSync(mapper); | 
|  | 5605 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5606 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5607 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY, motionArgs.buttonState); | 
|  | 5608 |  | 
|  | 5609 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5610 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5611 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5612 |  | 
|  | 5613 | processKey(mapper, BTN_STYLUS, 0); | 
|  | 5614 | processSync(mapper); | 
|  | 5615 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5616 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5617 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5618 |  | 
|  | 5619 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5620 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5621 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5622 |  | 
|  | 5623 | // press BTN_STYLUS2, release BTN_STYLUS2 | 
|  | 5624 | processKey(mapper, BTN_STYLUS2, 1); | 
|  | 5625 | processSync(mapper); | 
|  | 5626 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5627 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5628 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_SECONDARY, motionArgs.buttonState); | 
|  | 5629 |  | 
|  | 5630 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5631 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_PRESS, motionArgs.action); | 
|  | 5632 | ASSERT_EQ(AMOTION_EVENT_BUTTON_STYLUS_SECONDARY, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5633 |  | 
|  | 5634 | processKey(mapper, BTN_STYLUS2, 0); | 
|  | 5635 | processSync(mapper); | 
|  | 5636 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5637 | ASSERT_EQ(AMOTION_EVENT_ACTION_BUTTON_RELEASE, motionArgs.action); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5638 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5639 |  | 
|  | 5640 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5641 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
| Vladislav Kaznacheev | fb75258 | 2016-12-16 14:17:06 -0800 | [diff] [blame] | 5642 | ASSERT_EQ(0, motionArgs.buttonState); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 5643 |  | 
|  | 5644 | // release touch | 
|  | 5645 | processId(mapper, -1); | 
|  | 5646 | processSync(mapper); | 
|  | 5647 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5648 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 5649 | ASSERT_EQ(0, motionArgs.buttonState); | 
|  | 5650 | } | 
|  | 5651 |  | 
|  | 5652 | TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { | 
|  | 5653 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5654 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5655 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5656 | prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); | 
|  | 5657 | addMapperAndConfigure(mapper); | 
|  | 5658 |  | 
|  | 5659 | NotifyMotionArgs motionArgs; | 
|  | 5660 |  | 
|  | 5661 | // default tool type is finger | 
|  | 5662 | processId(mapper, 1); | 
|  | 5663 | processPosition(mapper, 100, 200); | 
|  | 5664 | processSync(mapper); | 
|  | 5665 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5666 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 5667 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5668 |  | 
|  | 5669 | // eraser | 
|  | 5670 | processKey(mapper, BTN_TOOL_RUBBER, 1); | 
|  | 5671 | processSync(mapper); | 
|  | 5672 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5673 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5674 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); | 
|  | 5675 |  | 
|  | 5676 | // stylus | 
|  | 5677 | processKey(mapper, BTN_TOOL_RUBBER, 0); | 
|  | 5678 | processKey(mapper, BTN_TOOL_PEN, 1); | 
|  | 5679 | processSync(mapper); | 
|  | 5680 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5681 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5682 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 5683 |  | 
|  | 5684 | // brush | 
|  | 5685 | processKey(mapper, BTN_TOOL_PEN, 0); | 
|  | 5686 | processKey(mapper, BTN_TOOL_BRUSH, 1); | 
|  | 5687 | processSync(mapper); | 
|  | 5688 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5689 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5690 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 5691 |  | 
|  | 5692 | // pencil | 
|  | 5693 | processKey(mapper, BTN_TOOL_BRUSH, 0); | 
|  | 5694 | processKey(mapper, BTN_TOOL_PENCIL, 1); | 
|  | 5695 | processSync(mapper); | 
|  | 5696 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5697 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5698 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 5699 |  | 
|  | 5700 | // airbrush | 
|  | 5701 | processKey(mapper, BTN_TOOL_PENCIL, 0); | 
|  | 5702 | processKey(mapper, BTN_TOOL_AIRBRUSH, 1); | 
|  | 5703 | processSync(mapper); | 
|  | 5704 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5705 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5706 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 5707 |  | 
|  | 5708 | // mouse | 
|  | 5709 | processKey(mapper, BTN_TOOL_AIRBRUSH, 0); | 
|  | 5710 | processKey(mapper, BTN_TOOL_MOUSE, 1); | 
|  | 5711 | processSync(mapper); | 
|  | 5712 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5713 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5714 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); | 
|  | 5715 |  | 
|  | 5716 | // lens | 
|  | 5717 | processKey(mapper, BTN_TOOL_MOUSE, 0); | 
|  | 5718 | processKey(mapper, BTN_TOOL_LENS, 1); | 
|  | 5719 | processSync(mapper); | 
|  | 5720 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5721 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5722 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); | 
|  | 5723 |  | 
|  | 5724 | // double-tap | 
|  | 5725 | processKey(mapper, BTN_TOOL_LENS, 0); | 
|  | 5726 | processKey(mapper, BTN_TOOL_DOUBLETAP, 1); | 
|  | 5727 | processSync(mapper); | 
|  | 5728 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5729 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5730 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5731 |  | 
|  | 5732 | // triple-tap | 
|  | 5733 | processKey(mapper, BTN_TOOL_DOUBLETAP, 0); | 
|  | 5734 | processKey(mapper, BTN_TOOL_TRIPLETAP, 1); | 
|  | 5735 | processSync(mapper); | 
|  | 5736 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5737 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5738 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5739 |  | 
|  | 5740 | // quad-tap | 
|  | 5741 | processKey(mapper, BTN_TOOL_TRIPLETAP, 0); | 
|  | 5742 | processKey(mapper, BTN_TOOL_QUADTAP, 1); | 
|  | 5743 | processSync(mapper); | 
|  | 5744 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5745 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5746 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5747 |  | 
|  | 5748 | // finger | 
|  | 5749 | processKey(mapper, BTN_TOOL_QUADTAP, 0); | 
|  | 5750 | processKey(mapper, BTN_TOOL_FINGER, 1); | 
|  | 5751 | processSync(mapper); | 
|  | 5752 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5753 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5754 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5755 |  | 
|  | 5756 | // stylus trumps finger | 
|  | 5757 | processKey(mapper, BTN_TOOL_PEN, 1); | 
|  | 5758 | processSync(mapper); | 
|  | 5759 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5760 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5761 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 5762 |  | 
|  | 5763 | // eraser trumps stylus | 
|  | 5764 | processKey(mapper, BTN_TOOL_RUBBER, 1); | 
|  | 5765 | processSync(mapper); | 
|  | 5766 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5767 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5768 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); | 
|  | 5769 |  | 
|  | 5770 | // mouse trumps eraser | 
|  | 5771 | processKey(mapper, BTN_TOOL_MOUSE, 1); | 
|  | 5772 | processSync(mapper); | 
|  | 5773 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5774 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5775 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); | 
|  | 5776 |  | 
|  | 5777 | // MT tool type trumps BTN tool types: MT_TOOL_FINGER | 
|  | 5778 | processToolType(mapper, MT_TOOL_FINGER); // this is the first time we send MT_TOOL_TYPE | 
|  | 5779 | processSync(mapper); | 
|  | 5780 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5781 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5782 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5783 |  | 
|  | 5784 | // MT tool type trumps BTN tool types: MT_TOOL_PEN | 
|  | 5785 | processToolType(mapper, MT_TOOL_PEN); | 
|  | 5786 | processSync(mapper); | 
|  | 5787 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5788 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5789 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); | 
|  | 5790 |  | 
|  | 5791 | // back to default tool type | 
|  | 5792 | processToolType(mapper, -1); // use a deliberately undefined tool type, for testing | 
|  | 5793 | processKey(mapper, BTN_TOOL_MOUSE, 0); | 
|  | 5794 | processKey(mapper, BTN_TOOL_RUBBER, 0); | 
|  | 5795 | processKey(mapper, BTN_TOOL_PEN, 0); | 
|  | 5796 | processKey(mapper, BTN_TOOL_FINGER, 0); | 
|  | 5797 | processSync(mapper); | 
|  | 5798 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5799 | ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); | 
|  | 5800 | ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); | 
|  | 5801 | } | 
|  | 5802 |  | 
|  | 5803 | TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { | 
|  | 5804 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5805 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5806 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5807 | prepareAxes(POSITION | ID | SLOT); | 
|  | 5808 | mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0); | 
|  | 5809 | addMapperAndConfigure(mapper); | 
|  | 5810 |  | 
|  | 5811 | NotifyMotionArgs motionArgs; | 
|  | 5812 |  | 
|  | 5813 | // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0 | 
|  | 5814 | processId(mapper, 1); | 
|  | 5815 | processPosition(mapper, 100, 200); | 
|  | 5816 | processSync(mapper); | 
|  | 5817 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5818 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 5819 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5820 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5821 |  | 
|  | 5822 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5823 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 5824 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5825 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5826 |  | 
|  | 5827 | // move a little | 
|  | 5828 | processPosition(mapper, 150, 250); | 
|  | 5829 | processSync(mapper); | 
|  | 5830 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5831 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 5832 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5833 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5834 |  | 
|  | 5835 | // down when BTN_TOUCH is pressed, pressure defaults to 1 | 
|  | 5836 | processKey(mapper, BTN_TOUCH, 1); | 
|  | 5837 | processSync(mapper); | 
|  | 5838 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5839 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 5840 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5841 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5842 |  | 
|  | 5843 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5844 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 5845 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5846 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5847 |  | 
|  | 5848 | // up when BTN_TOUCH is released, hover restored | 
|  | 5849 | processKey(mapper, BTN_TOUCH, 0); | 
|  | 5850 | processSync(mapper); | 
|  | 5851 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5852 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 5853 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5854 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5855 |  | 
|  | 5856 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5857 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 5858 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5859 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5860 |  | 
|  | 5861 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5862 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 5863 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5864 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5865 |  | 
|  | 5866 | // exit hover when pointer goes away | 
|  | 5867 | processId(mapper, -1); | 
|  | 5868 | processSync(mapper); | 
|  | 5869 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5870 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 5871 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5872 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5873 | } | 
|  | 5874 |  | 
|  | 5875 | TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfItsValueIsZero) { | 
|  | 5876 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5877 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5878 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5879 | prepareAxes(POSITION | ID | SLOT | PRESSURE); | 
|  | 5880 | addMapperAndConfigure(mapper); | 
|  | 5881 |  | 
|  | 5882 | NotifyMotionArgs motionArgs; | 
|  | 5883 |  | 
|  | 5884 | // initially hovering because pressure is 0 | 
|  | 5885 | processId(mapper, 1); | 
|  | 5886 | processPosition(mapper, 100, 200); | 
|  | 5887 | processPressure(mapper, 0); | 
|  | 5888 | processSync(mapper); | 
|  | 5889 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5890 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 5891 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5892 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5893 |  | 
|  | 5894 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5895 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 5896 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5897 | toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5898 |  | 
|  | 5899 | // move a little | 
|  | 5900 | processPosition(mapper, 150, 250); | 
|  | 5901 | processSync(mapper); | 
|  | 5902 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5903 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 5904 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5905 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5906 |  | 
|  | 5907 | // down when pressure becomes non-zero | 
|  | 5908 | processPressure(mapper, RAW_PRESSURE_MAX); | 
|  | 5909 | processSync(mapper); | 
|  | 5910 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5911 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 5912 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5913 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5914 |  | 
|  | 5915 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5916 | ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); | 
|  | 5917 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5918 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5919 |  | 
|  | 5920 | // up when pressure becomes 0, hover restored | 
|  | 5921 | processPressure(mapper, 0); | 
|  | 5922 | processSync(mapper); | 
|  | 5923 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5924 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); | 
|  | 5925 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5926 | toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5927 |  | 
|  | 5928 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5929 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action); | 
|  | 5930 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5931 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5932 |  | 
|  | 5933 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5934 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action); | 
|  | 5935 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5936 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5937 |  | 
|  | 5938 | // exit hover when pointer goes away | 
|  | 5939 | processId(mapper, -1); | 
|  | 5940 | processSync(mapper); | 
|  | 5941 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); | 
|  | 5942 | ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action); | 
|  | 5943 | ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], | 
|  | 5944 | toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); | 
|  | 5945 | } | 
|  | 5946 |  | 
| Siarhei Vishniakou | 16f9069 | 2017-12-27 14:29:55 -0800 | [diff] [blame] | 5947 | TEST_F(MultiTouchInputMapperTest, Process_HandlesTimestamp) { | 
|  | 5948 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5949 |  | 
|  | 5950 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5951 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5952 | prepareAxes(POSITION); | 
|  | 5953 | addMapperAndConfigure(mapper); | 
|  | 5954 | NotifyMotionArgs args; | 
|  | 5955 |  | 
|  | 5956 | // By default, deviceTimestamp should be zero | 
|  | 5957 | processPosition(mapper, 100, 100); | 
|  | 5958 | processMTSync(mapper); | 
|  | 5959 | processSync(mapper); | 
|  | 5960 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5961 | ASSERT_EQ(0U, args.deviceTimestamp); | 
|  | 5962 |  | 
|  | 5963 | // Now the timestamp of 1000 is reported by evdev and should appear in MotionArgs | 
|  | 5964 | processPosition(mapper, 0, 0); | 
|  | 5965 | processTimestamp(mapper, 1000); | 
|  | 5966 | processMTSync(mapper); | 
|  | 5967 | processSync(mapper); | 
|  | 5968 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5969 | ASSERT_EQ(1000U, args.deviceTimestamp); | 
|  | 5970 | } | 
|  | 5971 |  | 
| Siarhei Vishniakou | eaf7acd | 2018-01-09 12:35:51 -0800 | [diff] [blame] | 5972 | TEST_F(MultiTouchInputMapperTest, WhenMapperIsReset_TimestampIsCleared) { | 
|  | 5973 | MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice); | 
|  | 5974 |  | 
|  | 5975 | addConfigurationProperty("touch.deviceType", "touchScreen"); | 
|  | 5976 | prepareDisplay(DISPLAY_ORIENTATION_0); | 
|  | 5977 | prepareAxes(POSITION); | 
|  | 5978 | addMapperAndConfigure(mapper); | 
|  | 5979 | NotifyMotionArgs args; | 
|  | 5980 |  | 
|  | 5981 | // Send a touch event with a timestamp | 
|  | 5982 | processPosition(mapper, 100, 100); | 
|  | 5983 | processTimestamp(mapper, 1); | 
|  | 5984 | processMTSync(mapper); | 
|  | 5985 | processSync(mapper); | 
|  | 5986 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5987 | ASSERT_EQ(1U, args.deviceTimestamp); | 
|  | 5988 |  | 
|  | 5989 | // Since the data accumulates, and new timestamp has not arrived, deviceTimestamp won't change | 
|  | 5990 | processPosition(mapper, 100, 200); | 
|  | 5991 | processMTSync(mapper); | 
|  | 5992 | processSync(mapper); | 
|  | 5993 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 5994 | ASSERT_EQ(1U, args.deviceTimestamp); | 
|  | 5995 |  | 
|  | 5996 | mapper->reset(/* when */ 0); | 
|  | 5997 | // After the mapper is reset, deviceTimestamp should become zero again | 
|  | 5998 | processPosition(mapper, 100, 300); | 
|  | 5999 | processMTSync(mapper); | 
|  | 6000 | processSync(mapper); | 
|  | 6001 | ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args)); | 
|  | 6002 | ASSERT_EQ(0U, args.deviceTimestamp); | 
|  | 6003 | } | 
|  | 6004 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 6005 |  | 
|  | 6006 | } // namespace android |