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