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

Side by Side 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: Run tests on full layout. Created 6 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 var mockController;
8 var mockTimer;
9 var setComposition;
10
11 var DEFAULT_CONTEXT_ID = 0;
12
13 /**
14 * Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API
15 * calls must set expectations for call signatures.
16 */
17 function setUp() {
18 mockController = new MockController();
19 mockTimer = new MockTimer();
20
21 mockTimer.install();
22 mockController.createFunctionMock(chrome.input.ime, 'commitText');
23
24 var validateCommit = function(index, expected, observed) {
25 // Only consider the first argument, the details object.
26 var expectedEvent = expected[0];
27 var observedEvent = observed[0];
28 assertEquals(expectedEvent.text,
29 observedEvent.text,
30 'Mismatched commit text.');
31 };
32 chrome.input.ime.commitText.validateCall = validateCommit;
33 setComposition = chrome.input.ime.setComposition;
34 // Mocks setComposition manually to immediately callback. The mock controller
35 // does not support callback functions.
36 chrome.input.ime.setComposition = function(obj, callback) {
37 callback();
38 }
39 // TODO(rsadam): Mock additional extension API calls as required.
40 }
41
42 /**
43 * Verify that API calls match expectations.
44 */
45 function tearDown() {
46 mockController.verifyMocks();
47 mockController.reset();
48 mockTimer.uninstall();
49 chrome.input.ime.setComposition = setComposition;
50 }
51
52 /**
53 * Retrieves the key from the current keyset.
54 * @param {String} char The character of the key.
55 * @return {Object} The key.
56 */
57 function getKey(char) {
58 return document.querySelector('#Key' + char.toUpperCase())
59 }
60
61 /**
62 * Generates a mouse event and dispatches it on the target.
63 * @param target {Object} The target of the event.
64 * @param type {String} The type of the mouse event.
65 */
66 function generateMouseEvent(target, type) {
67 var e = new MouseEvent(type, {bubbles:true, cancelable:true});
68 target.dispatchEvent(e);
69 }
70
71 /**
72 * Mocks a character type using the mouse.
73 * @param {String} char The character to type.
74 */
75 function mockMouseType(char) {
76 var send = chrome.input.ime.commitText;
77 send.addExpectation({
78 contextId: DEFAULT_CONTEXT_ID,
79 text: char,
80 });
81 var key = getKey(char);
82 if (!key) {
83 console.error("Cannot find key: " + char);
84 return;
85 }
86 generateMouseEvent(key, 'mouseover');
87 generateMouseEvent(key, 'mousedown');
88 generateMouseEvent(key, 'mouseup');
89 generateMouseEvent(key, 'click');
90 generateMouseEvent(key, 'mouseover');
91 generateMouseEvent(key, 'mouseout');
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698