OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 GEN_INCLUDE([ | 5 GEN_INCLUDE([ |
6 'chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js']); | 6 'chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js']); |
7 GEN_INCLUDE([ | 7 GEN_INCLUDE([ |
8 'chrome/browser/resources/chromeos/chromevox/testing/common.js']); | 8 'chrome/browser/resources/chromeos/chromevox/testing/common.js', |
| 9 'chrome/browser/resources/chromeos/chromevox/testing/callback_helper.js']); |
9 | 10 |
10 /** | 11 /** |
11 * Base test fixture for ChromeVox unit tests. | 12 * Base test fixture for ChromeVox unit tests. |
12 * | 13 * |
13 * Note that while conceptually these are unit tests, these tests need | 14 * Note that while conceptually these are unit tests, these tests need |
14 * to run in a full web page, so they're actually run as WebUI browser | 15 * to run in a full web page, so they're actually run as WebUI browser |
15 * tests. | 16 * tests. |
16 * | 17 * |
17 * @constructor | 18 * @constructor |
18 * @extends {testing.Test} | 19 * @extends {testing.Test} |
19 */ | 20 */ |
20 function ChromeVoxUnitTestBase() {} | 21 function ChromeVoxUnitTestBase() { |
| 22 if (this.isAsync) { |
| 23 this.callbackHelper_ = new CallbackHelper(this); |
| 24 } |
| 25 } |
21 | 26 |
22 ChromeVoxUnitTestBase.prototype = { | 27 ChromeVoxUnitTestBase.prototype = { |
23 __proto__: testing.Test.prototype, | 28 __proto__: testing.Test.prototype, |
24 | 29 |
25 /** @override */ | 30 /** @override */ |
26 closureModuleDeps: [ | 31 closureModuleDeps: [ |
27 'cvox.ChromeVoxTester', | 32 'cvox.ChromeVoxTester', |
28 'cvox.ChromeVoxUserCommands', | 33 'cvox.ChromeVoxUserCommands', |
29 'cvox.SpokenListBuilder', | 34 'cvox.SpokenListBuilder', |
30 ], | 35 ], |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 /** | 113 /** |
109 * Waits for the queued events in ChromeVoxEventWatcher to be | 114 * Waits for the queued events in ChromeVoxEventWatcher to be |
110 * handled, then calls a callback function with provided arguments | 115 * handled, then calls a callback function with provided arguments |
111 * in the test case scope. Very useful for asserting the results of events. | 116 * in the test case scope. Very useful for asserting the results of events. |
112 * | 117 * |
113 * @param {function()} func A function to call when ChromeVox is ready. | 118 * @param {function()} func A function to call when ChromeVox is ready. |
114 * @param {*} var_args Additional arguments to pass through to the function. | 119 * @param {*} var_args Additional arguments to pass through to the function. |
115 * @return {ChromeVoxUnitTestBase} this. | 120 * @return {ChromeVoxUnitTestBase} this. |
116 */ | 121 */ |
117 waitForCalm: function(func, var_args) { | 122 waitForCalm: function(func, var_args) { |
118 var me = this; | |
119 var calmArguments = Array.prototype.slice.call(arguments); | 123 var calmArguments = Array.prototype.slice.call(arguments); |
120 calmArguments.shift(); | 124 calmArguments.shift(); |
121 cvox.ChromeVoxEventWatcher.addReadyCallback(function() { | 125 cvox.ChromeVoxEventWatcher.addReadyCallback(this.newCallback(function() { |
122 func.apply(me, calmArguments); | 126 func.apply(this, calmArguments); |
123 }); | 127 })); |
124 return this; // for chaining. | 128 return this; // for chaining. |
125 }, | 129 }, |
126 | 130 |
127 /** | 131 /** |
128 * Asserts the TTS engine spoke a certain string. Clears the TTS buffer. | 132 * Asserts the TTS engine spoke a certain string. Clears the TTS buffer. |
129 * @param {string} expectedText The expected text. | 133 * @param {string} expectedText The expected text. |
130 * @return {ChromeVoxUnitTestBase} this. | 134 * @return {ChromeVoxUnitTestBase} this. |
131 */ | 135 */ |
132 assertSpoken: function(expectedText) { | 136 assertSpoken: function(expectedText) { |
133 assertEquals(expectedText, | 137 assertEquals(expectedText, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 userCommand: function(command) { | 187 userCommand: function(command) { |
184 cvox.ChromeVoxUserCommands.commands[command](); | 188 cvox.ChromeVoxUserCommands.commands[command](); |
185 return this; // for chaining. | 189 return this; // for chaining. |
186 }, | 190 }, |
187 | 191 |
188 /** | 192 /** |
189 * @return {cvox.SpokenListBuilder} A new builder. | 193 * @return {cvox.SpokenListBuilder} A new builder. |
190 */ | 194 */ |
191 spokenList: function() { | 195 spokenList: function() { |
192 return new cvox.SpokenListBuilder(); | 196 return new cvox.SpokenListBuilder(); |
| 197 }, |
| 198 |
| 199 /** |
| 200 * @type {CallbackHelper} |
| 201 * @private |
| 202 */ |
| 203 callbackHelper_: null, |
| 204 |
| 205 /** |
| 206 * Creates a callback that optionally calls {@code opt_callback} when |
| 207 * called. If this method is called one or more times, then |
| 208 * {@code testDone()} will be called when all callbacks have been called. |
| 209 * @param {Function=} opt_callback Wrapped callback that will have its this |
| 210 * reference bound to the test fixture. |
| 211 * @return {Function} |
| 212 */ |
| 213 newCallback: function(opt_callback) { |
| 214 assertNotEquals(null, this.callbackHelper_); |
| 215 return this.callbackHelper_.wrap(opt_callback); |
193 } | 216 } |
194 }; | 217 }; |
OLD | NEW |