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(['assert_additions.js']); | 5 GEN_INCLUDE(['assert_additions.js']); |
6 GEN_INCLUDE(['common.js', | 6 GEN_INCLUDE(['common.js', 'callback_helper.js']); |
7 'callback_helper.js']); | |
8 | 7 |
9 /** | 8 /** |
10 * Base test fixture for ChromeVox unit tests. | 9 * Base test fixture for ChromeVox unit tests. |
11 * | 10 * |
12 * Note that while conceptually these are unit tests, these tests need | 11 * Note that while conceptually these are unit tests, these tests need |
13 * to run in a full web page, so they're actually run as WebUI browser | 12 * to run in a full web page, so they're actually run as WebUI browser |
14 * tests. | 13 * tests. |
15 * | 14 * |
16 * @constructor | 15 * @constructor |
17 * @extends {testing.Test} | 16 * @extends {testing.Test} |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 * @param {function()} func A function to call when ChromeVox is ready. | 115 * @param {function()} func A function to call when ChromeVox is ready. |
117 * @param {*} var_args Additional arguments to pass through to the function. | 116 * @param {*} var_args Additional arguments to pass through to the function. |
118 * @return {ChromeVoxUnitTestBase} this. | 117 * @return {ChromeVoxUnitTestBase} this. |
119 */ | 118 */ |
120 waitForCalm: function(func, var_args) { | 119 waitForCalm: function(func, var_args) { |
121 var calmArguments = Array.prototype.slice.call(arguments); | 120 var calmArguments = Array.prototype.slice.call(arguments); |
122 calmArguments.shift(); | 121 calmArguments.shift(); |
123 cvox.ChromeVoxEventWatcher.addReadyCallback(this.newCallback(function() { | 122 cvox.ChromeVoxEventWatcher.addReadyCallback(this.newCallback(function() { |
124 func.apply(this, calmArguments); | 123 func.apply(this, calmArguments); |
125 })); | 124 })); |
126 return this; // for chaining. | 125 return this; // for chaining. |
127 }, | 126 }, |
128 | 127 |
129 /** | 128 /** |
130 * Asserts the TTS engine spoke a certain string. Clears the TTS buffer. | 129 * Asserts the TTS engine spoke a certain string. Clears the TTS buffer. |
131 * @param {string} expectedText The expected text. | 130 * @param {string} expectedText The expected text. |
132 * @return {ChromeVoxUnitTestBase} this. | 131 * @return {ChromeVoxUnitTestBase} this. |
133 */ | 132 */ |
134 assertSpoken: function(expectedText) { | 133 assertSpoken: function(expectedText) { |
135 assertEquals(expectedText, | 134 assertEquals( |
136 cvox.ChromeVoxTester.testTts().getUtterancesAsString()); | 135 expectedText, cvox.ChromeVoxTester.testTts().getUtterancesAsString()); |
137 cvox.ChromeVoxTester.clearUtterances(); | 136 cvox.ChromeVoxTester.clearUtterances(); |
138 return this; // for chaining. | 137 return this; // for chaining. |
139 }, | 138 }, |
140 | 139 |
141 /** | 140 /** |
142 * Asserts a list of utterances are in the correct queue mode. | 141 * Asserts a list of utterances are in the correct queue mode. |
143 * @param {cvox.SpokenListBuilder|Array} expectedList A list | 142 * @param {cvox.SpokenListBuilder|Array} expectedList A list |
144 * of [text, queueMode] tuples OR a SpokenListBuilder with the expected | 143 * of [text, queueMode] tuples OR a SpokenListBuilder with the expected |
145 * utterances. | 144 * utterances. |
146 * @return {ChromeVoxUnitTestBase} this. | 145 * @return {ChromeVoxUnitTestBase} this. |
147 */ | 146 */ |
148 assertSpokenList: function(expectedList) { | 147 assertSpokenList: function(expectedList) { |
149 if (expectedList instanceof cvox.SpokenListBuilder) { | 148 if (expectedList instanceof cvox.SpokenListBuilder) { |
150 expectedList = expectedList.build(); | 149 expectedList = expectedList.build(); |
151 } | 150 } |
152 | 151 |
153 var ulist = cvox.ChromeVoxTester.testTts().getUtteranceInfoList(); | 152 var ulist = cvox.ChromeVoxTester.testTts().getUtteranceInfoList(); |
154 for (var i = 0; i < expectedList.length; i++) { | 153 for (var i = 0; i < expectedList.length; i++) { |
155 var text = expectedList[i][0]; | 154 var text = expectedList[i][0]; |
156 var queueMode = expectedList[i][1]; | 155 var queueMode = expectedList[i][1]; |
157 this.assertSingleUtterance_(text, queueMode, | 156 this.assertSingleUtterance_( |
158 ulist[i].text, ulist[i].queueMode); | 157 text, queueMode, ulist[i].text, ulist[i].queueMode); |
159 } | 158 } |
160 cvox.ChromeVoxTester.clearUtterances(); | 159 cvox.ChromeVoxTester.clearUtterances(); |
161 return this; // for chaining. | 160 return this; // for chaining. |
162 }, | 161 }, |
163 | 162 |
164 assertSingleUtterance_: function( | 163 assertSingleUtterance_: function( |
165 expectedText, expectedQueueMode, text, queueMode) { | 164 expectedText, expectedQueueMode, text, queueMode) { |
166 assertEquals(expectedQueueMode, queueMode); | 165 assertEquals(expectedQueueMode, queueMode); |
167 assertEquals(expectedText, text); | 166 assertEquals(expectedText, text); |
168 }, | 167 }, |
169 | 168 |
170 /** | 169 /** |
171 * Focuses an element. | 170 * Focuses an element. |
172 * @param {string} id The id of the element to focus. | 171 * @param {string} id The id of the element to focus. |
173 * @return {ChromeVoxUnitTestBase} this. | 172 * @return {ChromeVoxUnitTestBase} this. |
174 */ | 173 */ |
175 setFocus: function(id) { | 174 setFocus: function(id) { |
176 $(id).focus(); | 175 $(id).focus(); |
177 return this; // for chaining. | 176 return this; // for chaining. |
178 }, | 177 }, |
179 | 178 |
180 /** | 179 /** |
181 * Executes a ChromeVox user command. | 180 * Executes a ChromeVox user command. |
182 * @param {string} command The name of the command to run. | 181 * @param {string} command The name of the command to run. |
183 * @return {ChromeVoxUnitTestBase} this. | 182 * @return {ChromeVoxUnitTestBase} this. |
184 */ | 183 */ |
185 userCommand: function(command) { | 184 userCommand: function(command) { |
186 cvox.ChromeVoxUserCommands.commands[command](); | 185 cvox.ChromeVoxUserCommands.commands[command](); |
187 return this; // for chaining. | 186 return this; // for chaining. |
188 }, | 187 }, |
189 | 188 |
190 /** | 189 /** |
191 * @return {cvox.SpokenListBuilder} A new builder. | 190 * @return {cvox.SpokenListBuilder} A new builder. |
192 */ | 191 */ |
193 spokenList: function() { | 192 spokenList: function() { |
194 return new cvox.SpokenListBuilder(); | 193 return new cvox.SpokenListBuilder(); |
195 }, | 194 }, |
196 | 195 |
197 /** | 196 /** |
198 * @type {CallbackHelper} | 197 * @type {CallbackHelper} |
199 * @private | 198 * @private |
200 */ | 199 */ |
201 callbackHelper_: null, | 200 callbackHelper_: null, |
202 | 201 |
203 /** | 202 /** |
204 * Creates a callback that optionally calls {@code opt_callback} when | 203 * Creates a callback that optionally calls {@code opt_callback} when |
205 * called. If this method is called one or more times, then | 204 * called. If this method is called one or more times, then |
206 * {@code testDone()} will be called when all callbacks have been called. | 205 * {@code testDone()} will be called when all callbacks have been called. |
207 * @param {Function=} opt_callback Wrapped callback that will have its this | 206 * @param {Function=} opt_callback Wrapped callback that will have its this |
208 * reference bound to the test fixture. | 207 * reference bound to the test fixture. |
209 * @return {Function} | 208 * @return {Function} |
210 */ | 209 */ |
211 newCallback: function(opt_callback) { | 210 newCallback: function(opt_callback) { |
212 assertNotEquals(null, this.callbackHelper_); | 211 assertNotEquals(null, this.callbackHelper_); |
213 return this.callbackHelper_.wrap(opt_callback); | 212 return this.callbackHelper_.wrap(opt_callback); |
214 } | 213 } |
215 }; | 214 }; |
OLD | NEW |