OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Chromium Authors. All rights reserved. | 2 * Copyright 2013 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /** | 7 /** |
8 * Queue for running tests asynchronously. | 8 * Queue for running tests asynchronously. |
9 */ | 9 */ |
10 function TestRunner() { | 10 function TestRunner() { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 */ | 113 */ |
114 function findKey(label) { | 114 function findKey(label) { |
115 var keys = keyboard.querySelectorAll('kb-key'); | 115 var keys = keyboard.querySelectorAll('kb-key'); |
116 for (var i = 0; i < keys.length; i++) { | 116 for (var i = 0; i < keys.length; i++) { |
117 if (keys[i].charValue == label) | 117 if (keys[i].charValue == label) |
118 return keys[i]; | 118 return keys[i]; |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
| 123 * Mock typing of basic keys. Each keystroke should trigger a pair of |
| 124 * API calls to send viritual key events. |
| 125 * @param {string} label The character being typed. |
| 126 * @param {number} keyCode The legacy key code for the character. |
| 127 * @param {boolean} shiftModifier Indicates if the shift key is being |
| 128 * virtually pressed. |
| 129 * @param {number=} opt_unicode Optional unicode value for the character. Only |
| 130 * required if it cannot be directly calculated from the label. |
| 131 */ |
| 132 function mockTypeCharacter(label, keyCode, shiftModifier, opt_unicode) { |
| 133 var key = findKey(label); |
| 134 assertTrue(!!key, 'Unable to find key labelled "' + label + '".'); |
| 135 var unicodeValue = opt_unicode | label.charCodeAt(0); |
| 136 var send = chrome.virtualKeyboardPrivate.sendKeyEvent; |
| 137 send.addExpectation({ |
| 138 type: 'keydown', |
| 139 charValue: unicodeValue, |
| 140 keyCode: keyCode, |
| 141 shiftKey: shiftModifier |
| 142 }); |
| 143 send.addExpectation({ |
| 144 type: 'keyup', |
| 145 charValue: unicodeValue, |
| 146 keyCode: keyCode, |
| 147 shiftKey: shiftModifier |
| 148 }); |
| 149 // Fake typing the key. |
| 150 key.down(); |
| 151 key.up(); |
| 152 } |
| 153 |
| 154 /** |
123 * Triggers a callback function to run post initialization of the virtual | 155 * Triggers a callback function to run post initialization of the virtual |
124 * keyboard. | 156 * keyboard. |
125 * @param {string} testName The name of the test. | 157 * @param {string} testName The name of the test. |
126 * @param {Function} runTestCallback Callback function for running an | 158 * @param {Function} runTestCallback Callback function for running an |
127 * asynchronous test. | 159 * asynchronous test. |
128 * @param {Function} testDoneCallback Callback function to indicate completion | 160 * @param {Function} testDoneCallback Callback function to indicate completion |
129 * of a test. | 161 * of a test. |
130 */ | 162 */ |
131 function onKeyboardReady(testName, runTestCallback, testDoneCallback) { | 163 function onKeyboardReady(testName, runTestCallback, testDoneCallback) { |
132 runTestCallback.testName = testName; | 164 runTestCallback.testName = testName; |
133 runTestCallback.onTestComplete = testDoneCallback; | 165 runTestCallback.onTestComplete = testDoneCallback; |
134 if (keyboard.initialized) | 166 if (keyboard.initialized) |
135 testRunner.runTest(runTestCallback); | 167 testRunner.runTest(runTestCallback); |
136 else | 168 else |
137 testRunner.append(runTestCallback); | 169 testRunner.append(runTestCallback); |
138 } | 170 } |
OLD | NEW |