Chromium Code Reviews| 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 a | 6 * @fileoverview This file contains the |MockFeedback| class which is a |
| 7 * combined mock class for speech and braille feedback. A test that uses | 7 * combined mock class for speech and braille feedback. A test that uses |
| 8 * this class may add expectations for speech utterances and braille display | 8 * this class may add expectations for speech utterances and braille display |
| 9 * content to be output. The |install| method sets appropriate mock classes | 9 * content to be output. The |install| method sets appropriate mock classes |
| 10 * as the |cvox.ChromeVox.tts| and |cvox.ChromeVox.braille| objects, | 10 * as the |cvox.ChromeVox.tts| and |cvox.ChromeVox.braille| objects, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 return !!MockFeedback.matchAndConsume_( | 134 return !!MockFeedback.matchAndConsume_( |
| 135 text, {}, this.pendingUtterances_); | 135 text, {}, this.pendingUtterances_); |
| 136 }.bind(this), | 136 }.bind(this), |
| 137 toString: function() { return 'Speak \'' + text + '\''; } | 137 toString: function() { return 'Speak \'' + text + '\''; } |
| 138 }); | 138 }); |
| 139 }.bind(this)); | 139 }.bind(this)); |
| 140 return this; | 140 return this; |
| 141 }, | 141 }, |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * Adds an expectation that a given utterance will not be spoken. | |
| 145 * @param {...(string|RegExp)} var_args One or more utterance to add as | |
| 146 * negative expectations. | |
| 147 * @return {MockFeedback} |this| for chaining | |
| 148 */ | |
| 149 expectNoSpeech: function() { | |
|
Peter Lundblad
2015/08/26 16:56:13
I think this only works if the unexpected utteranc
dmazzoni
2015/08/26 18:18:23
Good point. How about expectNextSpeechUtteranceIsN
| |
| 150 assertFalse(this.replaying_); | |
| 151 Array.prototype.forEach.call(arguments, function(text) { | |
| 152 this.pendingActions_.push({ | |
| 153 perform: function() { | |
| 154 if (this.pendingUtterances_.length == 0) | |
| 155 return false; | |
| 156 if (MockFeedback.matchAndConsume_( | |
| 157 text, {}, this.pendingUtterances_)) { | |
| 158 throw new Error('Got disallowed utterance "' + text + '".'); | |
| 159 } | |
| 160 return true; | |
| 161 }.bind(this), | |
| 162 toString: function() { return 'Do not speak \'' + text + '\''; } | |
| 163 }); | |
| 164 }.bind(this)); | |
| 165 return this; | |
| 166 }, | |
| 167 | |
| 168 /** | |
| 144 * Adds an expectation for braille output. | 169 * Adds an expectation for braille output. |
| 145 * @param {string|RegExp} text | 170 * @param {string|RegExp} text |
| 146 * @param {Object=} opt_props Additional properties to match in the | 171 * @param {Object=} opt_props Additional properties to match in the |
| 147 * |NavBraille| | 172 * |NavBraille| |
| 148 * @return {MockFeedback} |this| for chaining | 173 * @return {MockFeedback} |this| for chaining |
| 149 */ | 174 */ |
| 150 expectBraille: function(text, opt_props) { | 175 expectBraille: function(text, opt_props) { |
| 151 assertFalse(this.replaying_); | 176 assertFalse(this.replaying_); |
| 152 var props = opt_props || {}; | 177 var props = opt_props || {}; |
| 153 this.pendingActions_.push({ | 178 this.pendingActions_.push({ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 return this.lastMatchedBraille_; | 236 return this.lastMatchedBraille_; |
| 212 }, | 237 }, |
| 213 | 238 |
| 214 /** | 239 /** |
| 215 * @param {string} textString | 240 * @param {string} textString |
| 216 * @param {cvox.QueueMode} queueMode | 241 * @param {cvox.QueueMode} queueMode |
| 217 * @param {Object=} properties | 242 * @param {Object=} properties |
| 218 * @private | 243 * @private |
| 219 */ | 244 */ |
| 220 addUtterance_: function(textString, queueMode, properties) { | 245 addUtterance_: function(textString, queueMode, properties) { |
| 246 console.log('*** ADDUTTERANCE ' + textString); | |
|
Peter Lundblad
2015/08/26 16:56:13
Intentional?
dmazzoni
2015/08/26 18:18:23
Oops, meant to remove that. Is there a way to add
| |
| 221 var callback; | 247 var callback; |
| 222 if (properties && (properties.startCallback || properties.endCallback)) { | 248 if (properties && (properties.startCallback || properties.endCallback)) { |
| 223 var startCallback = properties.startCallback; | 249 var startCallback = properties.startCallback; |
| 224 var endCallback = properties.endCallback; | 250 var endCallback = properties.endCallback; |
| 225 callback = function() { | 251 callback = function() { |
| 226 startCallback && startCallback(); | 252 startCallback && startCallback(); |
| 227 endCallback && endCallback(); | 253 endCallback && endCallback(); |
| 228 }; | 254 }; |
| 229 } | 255 } |
| 230 this.pendingUtterances_.push( | 256 this.pendingUtterances_.push( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 } | 349 } |
| 324 if (candidate) { | 350 if (candidate) { |
| 325 var consumed = pending.splice(0, i + 1); | 351 var consumed = pending.splice(0, i + 1); |
| 326 consumed.forEach(function(item) { | 352 consumed.forEach(function(item) { |
| 327 if (item.callback) | 353 if (item.callback) |
| 328 item.callback(); | 354 item.callback(); |
| 329 }); | 355 }); |
| 330 } | 356 } |
| 331 return candidate; | 357 return candidate; |
| 332 }; | 358 }; |
| OLD | NEW |