Commit a253e872 authored by rsadam@chromium.org's avatar rsadam@chromium.org

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
parent 261746fe
...@@ -311,3 +311,105 @@ function testFingerOutType(testDoneCallback) { ...@@ -311,3 +311,105 @@ function testFingerOutType(testDoneCallback) {
}; };
onKeyboardReady('testFingerOutType', runTest, 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
...@@ -18,6 +18,18 @@ function Debug(message) { ...@@ -18,6 +18,18 @@ function Debug(message) {
console.log(message); console.log(message);
} }
/**
* The enumeration of swipe directions.
* @const
* @enum {number}
*/
var SwipeDirection = {
RIGHT: 0x1,
LEFT: 0x2,
UP: 0x4,
DOWN: 0x8
};
/** /**
* Layouts used in testing. * Layouts used in testing.
* @enum {string} * @enum {string}
...@@ -335,6 +347,8 @@ function setUp() { ...@@ -335,6 +347,8 @@ function setUp() {
mockController.createFunctionMock(chrome.virtualKeyboardPrivate, mockController.createFunctionMock(chrome.virtualKeyboardPrivate,
'hideKeyboard'); 'hideKeyboard');
mockController.createFunctionMock(chrome.virtualKeyboardPrivate,
'moveCursor');
var validateSendCall = function(index, expected, observed) { var validateSendCall = function(index, expected, observed) {
// Only consider the first argument (VirtualKeyEvent) for the validation of // Only consider the first argument (VirtualKeyEvent) for the validation of
...@@ -361,6 +375,12 @@ function setUp() { ...@@ -361,6 +375,12 @@ function setUp() {
// matter for the purpose of validating the call. // 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. // TODO(kevers): Mock additional extension API calls as required.
} }
......
...@@ -351,7 +351,7 @@ ...@@ -351,7 +351,7 @@
ready: function() { ready: function() {
this.voiceInput_ = new VoiceInput(this); this.voiceInput_ = new VoiceInput(this);
this.swipeHandler = this.updateSwipeTracker.bind(this); this.swipeHandler = this.move.bind(this);
}, },
/** /**
...@@ -472,7 +472,7 @@ ...@@ -472,7 +472,7 @@
* status so that PointerEvents can be converted to Swipe events. * status so that PointerEvents can be converted to Swipe events.
* @param {PointerEvent} event. * @param {PointerEvent} event.
*/ */
updateSwipeTracker: function(event) { move: function(event) {
if (!swipeTracker.update(event)) if (!swipeTracker.update(event))
return; return;
// Conversion was successful, swipe is now in progress. // Conversion was successful, swipe is now in progress.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment