| Index: chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js
|
| diff --git a/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js b/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js
|
| index 2f4944444a4da7c585d8c160152b5a963f411d36..b7e13ddbff94adb88aee7e68b285df374994b70e 100644
|
| --- a/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js
|
| +++ b/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js
|
| @@ -9,6 +9,17 @@ var mockTimer;
|
| var setComposition;
|
|
|
| var DEFAULT_CONTEXT_ID = 0;
|
| +var LONGPRESS_DELAY = 1100;
|
| +
|
| +/**
|
| + * Key alignments.
|
| + * @enum {string}
|
| + */
|
| +var Alignment = {
|
| + LEFT: 'left',
|
| + RIGHT: 'right',
|
| + CENTER: 'center'
|
| +};
|
|
|
| /**
|
| * Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API
|
| @@ -19,7 +30,6 @@ function setUp() {
|
| mockTimer = new MockTimer();
|
|
|
| mockTimer.install();
|
| - mockController.createFunctionMock(chrome.input.ime, 'setComposition');
|
| mockController.createFunctionMock(chrome.input.ime, 'commitText');
|
|
|
| var validateCommit = function(index, expected, observed) {
|
| @@ -55,7 +65,9 @@ function tearDown() {
|
| * @return {Object} The key.
|
| */
|
| function getKey(char) {
|
| - return document.querySelector('#Key' + char.toUpperCase())
|
| + var key = document.querySelector('#Key' + char.toUpperCase())
|
| + assertTrue(!!key, "Cannot find key: " + char);
|
| + return key;
|
| }
|
|
|
| /**
|
| @@ -80,10 +92,6 @@ function mockMouseType(char) {
|
| text: char,
|
| });
|
| var key = getKey(char);
|
| - if (!key) {
|
| - console.error("Cannot find key: " + char);
|
| - return;
|
| - }
|
| generateMouseEvent(key, 'mouseover', true, true);
|
| generateMouseEvent(key, 'mousedown', true, true);
|
| generateMouseEvent(key, 'mouseup', true, true);
|
| @@ -91,3 +99,95 @@ function mockMouseType(char) {
|
| generateMouseEvent(key, 'mouseover', true, true);
|
| generateMouseEvent(key, 'mouseout', true, true);
|
| }
|
| +
|
| +/**
|
| + * Generates a touch event and dispatches it on the target.
|
| + * @param target {Object} The target of the event.
|
| + * @param type {String} The type of the touch event.
|
| + */
|
| +function generateTouchEvent(target, type) {
|
| + var e = document.createEvent('UIEvents');
|
| + e.initEvent.apply(e, Array.prototype.slice.call(arguments, 1));
|
| + target.dispatchEvent(e);
|
| +}
|
| +
|
| +/**
|
| + * Mocks a character type using touch.
|
| + * @param {String} char The character to type.
|
| + */
|
| +function mockTouchType(char) {
|
| + var send = chrome.input.ime.commitText;
|
| + send.addExpectation({
|
| + contextId: DEFAULT_CONTEXT_ID,
|
| + text: char,
|
| + });
|
| + var key = getKey(char);
|
| + generateTouchEvent(key, 'touchstart', true, true);
|
| + generateTouchEvent(key, 'touchend', true, true);
|
| +}
|
| +
|
| +/**
|
| + * Checks whether the element is currently being displayed on screen.
|
| + * @param {Object} The object to check.
|
| + * @return {boolean}
|
| + */
|
| +function isActive(element) {
|
| + return getComputedStyle(element).display != "none";
|
| +}
|
| +
|
| +/**
|
| + * Returns, if present, the active alternate key container.
|
| + * @return {?Object}
|
| + */
|
| +function getActiveAltContainer() {
|
| + // TODO(rsadam): Simplify once code refactor to remove unneeded containers is
|
| + // complete.
|
| + var all = document.querySelectorAll('.inputview-altdata-view');
|
| + var hit;
|
| + for (var i = 0; i < all.length; i++) {
|
| + if (isActive(all[i])) {
|
| + assertFalse(!!hit, "More than one alt key container is active.");
|
| + hit = all[i];
|
| + }
|
| + }
|
| + return hit;
|
| +}
|
| +
|
| +/**
|
| + * Mocks a character long press.
|
| + * @param {String} char The character to longpress.
|
| + * @param {Array<String>} altKeys The expected alt keys.
|
| + * @param {String} selection The alt key to select.
|
| + */
|
| +function mockLongpress(char, altKeys, selection) {
|
| + var key = getKey(char);
|
| + generateTouchEvent(key, 'touchstart', true, true);
|
| + mockTimer.tick(LONGPRESS_DELAY);
|
| +
|
| + var container = getActiveAltContainer();
|
| + assertTrue(!!container, "Cannot find active alt container.");
|
| + var options = container.querySelectorAll('.inputview-altdata-key');
|
| + assertEquals(altKeys.length, options.length,
|
| + "Unexpected number of alt keys.");
|
| +
|
| + var candidate;
|
| + // Check all altKeys present and in order specified.
|
| + for (var i = 0; i < altKeys.length; i++) {
|
| + assertEquals(altKeys[i],options[i].innerHTML);
|
| + if (options[i].innerHTML == selection)
|
| + candidate = options[i];
|
| + }
|
| + // Check that selection key found.
|
| + assertTrue(!!candidate, "Could not find alt key to select: " + candidate);
|
| + // Expect selection to be typed
|
| + var send = chrome.input.ime.commitText;
|
| + send.addExpectation({
|
| + contextId: DEFAULT_CONTEXT_ID,
|
| + text: selection,
|
| + });
|
| + // TODO(rsadam:) Add support for touch move here once latest CRX uploaded to
|
| + // chrome/test/data.
|
| + generateTouchEvent(key, 'touchend', true, true)
|
| + container = getActiveAltContainer();
|
| + assertFalse(!!container, "Alt key container was not hidden.");
|
| +}
|
|
|