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

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

Issue 247883002: Adds browser test framework for the IME keyboard, and some basic typing tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
new file mode 100644
index 0000000000000000000000000000000000000000..2f4944444a4da7c585d8c160152b5a963f411d36
--- /dev/null
+++ b/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2014 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+var mockController;
+var mockTimer;
+var setComposition;
+
+var DEFAULT_CONTEXT_ID = 0;
+
+/**
+ * Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API
+ * calls must set expectations for call signatures.
+ */
+function setUp() {
+ mockController = new MockController();
+ mockTimer = new MockTimer();
+
+ mockTimer.install();
+ mockController.createFunctionMock(chrome.input.ime, 'setComposition');
+ mockController.createFunctionMock(chrome.input.ime, 'commitText');
+
+ var validateCommit = function(index, expected, observed) {
+ // Only consider the first argument, the details object.
+ var expectedEvent = expected[0];
+ var observedEvent = observed[0];
+ assertEquals(expectedEvent.text,
+ observedEvent.text,
+ 'Mismatched commit text.');
+ };
+ chrome.input.ime.commitText.validateCall = validateCommit;
+ setComposition = chrome.input.ime.setComposition;
+ // Mocks setComposition manually to immediately callback.
+ chrome.input.ime.setComposition = function(obj, callback) {
+ callback();
+ }
+ // TODO(rsadam): Mock additional extension API calls as required.
+}
+
+/**
+ * Verify that API calls match expectations.
+ */
+function tearDown() {
+ mockController.verifyMocks();
+ mockController.reset();
+ mockTimer.uninstall();
+ chrome.input.ime.setComposition = setComposition;
Jeffrey Yasskin 2014/04/28 23:14:50 This looks suspicious: you're mocking setCompositi
rsadam 2014/04/30 17:26:11 Oops. We don't need to mock it using a controller
+}
+
+/**
+ * Retrieves the key from the current keyset.
+ * @param {String} char The character of the key.
+ * @return {Object} The key.
+ */
+function getKey(char) {
+ return document.querySelector('#Key' + char.toUpperCase())
+}
+
+/**
+ * Generates a mouse event and dispatches it on the target.
Jeffrey Yasskin 2014/04/28 23:14:50 Mention that this function takes extra arguments b
rsadam 2014/04/30 17:26:11 Done.
+ * @param target {Object} The target of the event.
+ * @param type {String} The type of the mouse event.
+ */
+function generateMouseEvent(target, type) {
+ var e = document.createEvent('MouseEvents');
Jeffrey Yasskin 2014/04/28 23:14:50 https://developer.mozilla.org/en-US/docs/Web/API/d
rsadam 2014/04/30 17:26:11 Done.
+ e.initEvent.apply(e, Array.prototype.slice.call(arguments, 1));
+ target.dispatchEvent(e);
+}
+
+/**
+ * Mocks a character type using the mouse.
+ * @param {String} char The character to type.
+ */
+function mockMouseType(char) {
+ var send = chrome.input.ime.commitText;
+ send.addExpectation({
+ contextId: DEFAULT_CONTEXT_ID,
+ 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);
+ generateMouseEvent(key, 'click', true, true);
+ generateMouseEvent(key, 'mouseover', true, true);
+ generateMouseEvent(key, 'mouseout', true, true);
+}

Powered by Google App Engine
This is Rietveld 408576698