OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
6 * @fileoverview This file contains the |MockFeedback| class which is | 6 * @fileoverview This file contains the |MockFeedback| class which is |
7 * a combined mock class for speech, braille, and earcon feedback. A | 7 * a combined mock class for speech, braille, and earcon feedback. A |
8 * test that uses this class may add expectations for speech | 8 * test that uses this class may add expectations for speech |
9 * utterances, braille display content to be output, and earcons | 9 * utterances, braille display content to be output, and earcons |
10 * played (by name). The |install| method sets appropriate mock | 10 * played (by name). The |install| method sets appropriate mock |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 return !!MockFeedback.matchAndConsume_( | 153 return !!MockFeedback.matchAndConsume_( |
154 text, {}, this.pendingUtterances_); | 154 text, {}, this.pendingUtterances_); |
155 }.bind(this), | 155 }.bind(this), |
156 toString: function() { return 'Speak \'' + text + '\''; } | 156 toString: function() { return 'Speak \'' + text + '\''; } |
157 }); | 157 }); |
158 }.bind(this)); | 158 }.bind(this)); |
159 return this; | 159 return this; |
160 }, | 160 }, |
161 | 161 |
162 /** | 162 /** |
| 163 * Adds an expectation for one spoken utterance that will be enqueued |
| 164 * with a given queue mode. |
| 165 * @param {string|RegExp} text One utterance expectation. |
| 166 * @param {cvox.QueueMode} queueMode The expected queue mode. |
| 167 * @return {MockFeedback} |this| for chaining |
| 168 */ |
| 169 expectSpeechWithQueueMode: function(text, queueMode) { |
| 170 assertFalse(this.replaying_); |
| 171 this.pendingActions_.push({ |
| 172 perform: function() { |
| 173 return !!MockFeedback.matchAndConsume_( |
| 174 text, {queueMode: queueMode}, this.pendingUtterances_); |
| 175 }.bind(this), |
| 176 toString: function() { |
| 177 return 'Speak \'' + text + '\' with mode ' + queueMode; |
| 178 } |
| 179 }); |
| 180 return this; |
| 181 }, |
| 182 |
| 183 /** |
| 184 * Adds an expectation for one spoken utterance that will be queued. |
| 185 * @param {string|RegExp} text One utterance expectation. |
| 186 * @return {MockFeedback} |this| for chaining |
| 187 */ |
| 188 expectQueuedSpeech: function(text) { |
| 189 return this.expectSpeechWithQueueMode(text, cvox.QueueMode.QUEUE); |
| 190 }, |
| 191 |
| 192 /** |
| 193 * Adds an expectation for one spoken utterance that will be flushed. |
| 194 * @param {string|RegExp} text One utterance expectation. |
| 195 * @return {MockFeedback} |this| for chaining |
| 196 */ |
| 197 expectFlushingSpeech: function(text) { |
| 198 return this.expectSpeechWithQueueMode(text, cvox.QueueMode.FLUSH); |
| 199 }, |
| 200 |
| 201 /** |
| 202 * Adds an expectation for one spoken utterance that will be queued |
| 203 * with the category flush mode. |
| 204 * @param {string|RegExp} text One utterance expectation. |
| 205 * @return {MockFeedback} |this| for chaining |
| 206 */ |
| 207 expectCategoryFlushSpeech: function(text) { |
| 208 return this.expectSpeechWithQueueMode(text, cvox.QueueMode.CATEGORY_FLUSH); |
| 209 }, |
| 210 |
| 211 /** |
163 * Adds an expectation that the next spoken utterances do *not* match | 212 * Adds an expectation that the next spoken utterances do *not* match |
164 * the given arguments. | 213 * the given arguments. |
165 * | 214 * |
166 * This is only guaranteed to work for the immediately following utterance. | 215 * This is only guaranteed to work for the immediately following utterance. |
167 * If you use it to check an utterance other than the immediately following | 216 * If you use it to check an utterance other than the immediately following |
168 * one the results may be flaky. | 217 * one the results may be flaky. |
169 * | 218 * |
170 * @param {...(string|RegExp)} var_args One or more utterance to add as | 219 * @param {...(string|RegExp)} var_args One or more utterance to add as |
171 * negative expectations. | 220 * negative expectations. |
172 * @return {MockFeedback} |this| for chaining | 221 * @return {MockFeedback} |this| for chaining |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (properties && (properties.startCallback || properties.endCallback)) { | 341 if (properties && (properties.startCallback || properties.endCallback)) { |
293 var startCallback = properties.startCallback; | 342 var startCallback = properties.startCallback; |
294 var endCallback = properties.endCallback; | 343 var endCallback = properties.endCallback; |
295 callback = function() { | 344 callback = function() { |
296 startCallback && startCallback(); | 345 startCallback && startCallback(); |
297 endCallback && endCallback(); | 346 endCallback && endCallback(); |
298 }; | 347 }; |
299 } | 348 } |
300 this.pendingUtterances_.push( | 349 this.pendingUtterances_.push( |
301 {text: textString, | 350 {text: textString, |
| 351 queueMode: queueMode, |
302 callback: callback}); | 352 callback: callback}); |
303 this.process_(); | 353 this.process_(); |
304 }, | 354 }, |
305 | 355 |
306 /** @private */ | 356 /** @private */ |
307 addBraille_: function(navBraille) { | 357 addBraille_: function(navBraille) { |
308 this.pendingBraille_.push(navBraille); | 358 this.pendingBraille_.push(navBraille); |
309 this.process_(); | 359 this.process_(); |
310 }, | 360 }, |
311 | 361 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 453 } |
404 if (candidate) { | 454 if (candidate) { |
405 var consumed = pending.splice(0, i + 1); | 455 var consumed = pending.splice(0, i + 1); |
406 consumed.forEach(function(item) { | 456 consumed.forEach(function(item) { |
407 if (item.callback) | 457 if (item.callback) |
408 item.callback(); | 458 item.callback(); |
409 }); | 459 }); |
410 } | 460 } |
411 return candidate; | 461 return candidate; |
412 }; | 462 }; |
OLD | NEW |