Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js

Issue 259603002: Add touch and basic longpress typing tests for the IME keyboard. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0326b7670d62173eef6fe78093de401e579ff7d1 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,32 @@ 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;
+}
+
+/**
+ * Retrieves the shift key from the current keyset.
+ * @param {Alignment} align The alignment of the shift key.
+ * @return {Object} The key.
+ */
bshe 2014/04/24 18:36:25 Assume this will be used when add upper case tests
rsadam 2014/04/24 21:23:25 Done.
+function getShiftKey(align) {
+ var id;
+ switch(align) {
+ case Alignment.LEFT:
+ id = 'ShiftLeft';
+ break;
+ case Alignment.RIGHT:
+ id = 'ShiftRight';
+ break;
+ default:
+ break;
+ }
+ assertTrue(!!id, "Invalid shift alignment option: " + align);
+ var shift = document.querySelector('#' + id);
+ assertTrue(!!shift, "Cannot find shift key with alignment: " + align);
+ return shift;
}
/**
@@ -80,10 +115,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 +122,94 @@ 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.
bshe 2014/04/24 18:36:25 nit: document return value
rsadam 2014/04/24 21:23:25 Done.
+ */
+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
rsadam 2014/04/24 17:45:04 The current CRX uses the delta in screen position
+ // chrome/test/data.
+ generateTouchEvent(key, 'touchend', true, true)
bshe 2014/04/24 18:36:25 should the touchend dispatched by candidate?
rsadam 2014/04/24 21:23:25 I believe the W3 spec is for the target to be same
+ container = getActiveAltContainer();
+ assertFalse(!!container, "Alt key container was not hidden.");
+}

Powered by Google App Engine
This is Rietveld 408576698