diff options
author | rsadam@chromium.org <rsadam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 18:13:39 +0000 |
---|---|---|
committer | rsadam@chromium.org <rsadam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 18:13:39 +0000 |
commit | a253e872336b39ccf8bd50b6cf709664c0a02cc6 (patch) | |
tree | dba09f45baf950b312ac889ca19664ab736b3de9 /chrome | |
parent | 261746fea395fb1587311bad6c185a4cde8335ec (diff) | |
download | chromium_src-a253e872336b39ccf8bd50b6cf709664c0a02cc6.zip chromium_src-a253e872336b39ccf8bd50b6cf709664c0a02cc6.tar.gz chromium_src-a253e872336b39ccf8bd50b6cf709664c0a02cc6.tar.bz2 |
Adds unit tests for swipe flick. We add the following tests:
1) Regular swipe flick (Should type hintText)
2) Long swipe flick (Nothing should display)
3) Composed swipe followed by flick (moveCursor triggered, but no flick)
BUG=324823
Review URL: https://codereview.chromium.org/99923003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/test/data/chromeos/virtual_keyboard/typing_test.js | 102 | ||||
-rw-r--r-- | chrome/test/data/chromeos/virtual_keyboard/virtual_keyboard_test_base.js | 20 |
2 files changed, 122 insertions, 0 deletions
diff --git a/chrome/test/data/chromeos/virtual_keyboard/typing_test.js b/chrome/test/data/chromeos/virtual_keyboard/typing_test.js index d58e479..0f21e9e 100644 --- a/chrome/test/data/chromeos/virtual_keyboard/typing_test.js +++ b/chrome/test/data/chromeos/virtual_keyboard/typing_test.js @@ -311,3 +311,105 @@ function testFingerOutType(testDoneCallback) { }; onKeyboardReady('testFingerOutType', runTest, testDoneCallback); } + +/** + * Tests that flicking upwards on a key with hintText types the hint text. + * @param {Function} testDoneCallback The callback function on completion. + */ +function testSwipeFlick(testDoneCallback) { + var mockEvent = function(xOffset, yOffset, target, relatedTarget) { + var bounds = target.getBoundingClientRect(); + return { + pointerId: 1, + isPrimary: true, + screenX: bounds.left + xOffset, + // Note: Y is negative in the 'up' direction. + screenY: bounds.bottom - yOffset, + target: target, + relatedTarget: relatedTarget + }; + } + var runTest = function() { + var key = findKey('.'); + var send = chrome.virtualKeyboardPrivate.sendKeyEvent; + // Test flick on the '.', expect '?' to appear. + send.addExpectation({ + type: 'keydown', + charValue: '?'.charCodeAt(0), + keyCode: 0xBF, + modifiers: Modifier.SHIFT + }); + send.addExpectation({ + type: 'keyup', + charValue: '?'.charCodeAt(0), + keyCode: 0xBF, + modifiers: Modifier.SHIFT + }); + var height = key.clientHeight; + var width = key.clientWidth; + $('keyboard').down(mockEvent(0, 0, key)); + $('keyboard').move(mockEvent(0, height/2, key)); + $('keyboard').up(mockEvent(0, height/2, key)); + + // Test flick that exits the keyboard area. Expect '1' to appear. + var qKey = findKey('q'); + send.addExpectation({ + type: 'keydown', + charValue: '1'.charCodeAt(0), + keyCode: 0x31, + modifiers: Modifier.NONE + }); + send.addExpectation({ + type: 'keyup', + charValue: '1'.charCodeAt(0), + keyCode: 0x31, + modifiers: Modifier.NONE + }); + $('keyboard').down(mockEvent(width/2, height/2, qKey)); + $('keyboard').move(mockEvent(width/2, height, qKey)); + $('keyboard').out(mockEvent(width/2, 2*height, qKey, $('keyboard'))); + + // Test basic long flick. Should not have any output. + $('keyboard').down(mockEvent(0, 0, key)); + $('keyboard').move(mockEvent(0, height/2, key)); + $('keyboard').move(mockEvent(0, 2*height, key)); + $('keyboard').up(mockEvent(0, 2*height, key)); + + // Test flick that crosses the original key boundary. + send.addExpectation({ + type: 'keydown', + charValue: '?'.charCodeAt(0), + keyCode: 0xBF, + modifiers: Modifier.SHIFT + }); + send.addExpectation({ + type: 'keyup', + charValue: '?'.charCodeAt(0), + keyCode: 0xBF, + modifiers: Modifier.SHIFT + }); + var lKey = findKey('l'); + $('keyboard').down(mockEvent(0, height/2, key)); + $('keyboard').move(mockEvent(0, height, key)); + key.out(mockEvent(0, height, key, lKey)); + $('keyboard').move(mockEvent(0, height/2, lKey)); + $('keyboard').up(mockEvent(0, height/2, lKey)); + + // Test long flick that crosses the original key boundary. + $('keyboard').down(mockEvent(0, 0, key)); + $('keyboard').move(mockEvent(0, height/2, key)); + key.out(mockEvent(0, height, key, lKey)); + $('keyboard').move(mockEvent(0, height, lKey)); + $('keyboard').up(mockEvent(0, height, lKey)); + + // Test composed swipe and flick. Should not have any output. + var move = chrome.virtualKeyboardPrivate.moveCursor; + move.addExpectation(SwipeDirection.RIGHT, + Modifier.CONTROL & Modifier.SHIFT); + $('keyboard').down(mockEvent(0, 0, key)); + $('keyboard').move(mockEvent(0, height, key)); + $('keyboard').move(mockEvent(width, height, key)); + $('keyboard').up(mockEvent(width, height, key)); + }; + onKeyboardReady('testSwipeFlick', runTest, testDoneCallback); +}
\ No newline at end of file diff --git a/chrome/test/data/chromeos/virtual_keyboard/virtual_keyboard_test_base.js b/chrome/test/data/chromeos/virtual_keyboard/virtual_keyboard_test_base.js index 4e1e210..93b4f17 100644 --- a/chrome/test/data/chromeos/virtual_keyboard/virtual_keyboard_test_base.js +++ b/chrome/test/data/chromeos/virtual_keyboard/virtual_keyboard_test_base.js @@ -19,6 +19,18 @@ function Debug(message) { } /** + * The enumeration of swipe directions. + * @const + * @enum {number} + */ +var SwipeDirection = { + RIGHT: 0x1, + LEFT: 0x2, + UP: 0x4, + DOWN: 0x8 +}; + +/** * Layouts used in testing. * @enum {string} */ @@ -335,6 +347,8 @@ function setUp() { mockController.createFunctionMock(chrome.virtualKeyboardPrivate, 'hideKeyboard'); + mockController.createFunctionMock(chrome.virtualKeyboardPrivate, + 'moveCursor'); var validateSendCall = function(index, expected, observed) { // Only consider the first argument (VirtualKeyEvent) for the validation of @@ -361,6 +375,12 @@ function setUp() { // matter for the purpose of validating the call. }; + var validateMoveCursor = function(index, expected, observed) { + assertEquals(expected[0], observed[0], "Mismatched swipe directions."); + assertEquals(expected[1], observed[1], "Mismatched swipe flags."); + } + chrome.virtualKeyboardPrivate.moveCursor.validateCall = validateMoveCursor; + // TODO(kevers): Mock additional extension API calls as required. } |