Index: chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js |
diff --git a/chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js b/chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js |
index 04fdb7d39b83dcc9fe45289da30faf2af30d00a1..3308992120cd8b9da4a5ad9930711d707f739dd7 100644 |
--- a/chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js |
+++ b/chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js |
@@ -8,11 +8,6 @@ |
* @extends {cvox.TtsInterface} |
*/ |
var MockTts = function() { |
- /** |
- * The event handler for the most recent call to |speak|. |
- * @private |
- */ |
- this.onEvent_; |
}; |
MockTts.prototype = { |
@@ -34,10 +29,7 @@ MockTts.prototype = { |
/** @override */ |
speak: function(textString, queueMode, properties) { |
- if (properties) |
- this.onEvent_ = properties['onEvent']; |
- |
- this.process_(textString); |
+ this.process_(textString, false, properties); |
}, |
/** |
@@ -77,22 +69,6 @@ MockTts.prototype = { |
}, |
/** |
- * Fakes an event to |onEvent|. |
- */ |
- sendStartEvent: function() { |
- if (this.onEvent_) |
- this.onEvent_({type: 'start'}); |
- }, |
- |
- /** |
- * Fakes an event to |onEvent|. |
- */ |
- sendEndEvent: function() { |
- if (this.onEvent_) |
- this.onEvent_({type: 'end'}); |
- }, |
- |
- /** |
* @private |
* @param {string} expectedText Text expected spoken. |
* @param {{startCallback: function() : void, |
@@ -112,28 +88,38 @@ MockTts.prototype = { |
// Process any idleUtterances. |
this.idleUtterances_.forEach(function(utterance) { |
- this.process_(utterance, true); |
+ this.process_(utterance.text, true, utterance.properties); |
}.bind(this)); |
}, |
/** |
* @param {string} textString Utterance to match against callbacks. |
* @param {boolean=} opt_manual True if called outside of tts.speak. |
+ * @param {!Object=} opt_properties |
* @private |
*/ |
- process_: function(textString, opt_manual) { |
+ process_: function(textString, opt_manual, opt_properties) { |
+ var utterance = {text: textString, properties: opt_properties}; |
if (this.expectations_.length == 0) { |
- if (!opt_manual) |
- this.idleUtterances_.push(textString); |
+ if (!opt_manual) { |
+ this.idleUtterances_.push(utterance); |
+ } |
return; |
} |
- var allUtterances = this.idleUtterances_.concat([textString]); |
+ var allUtterances = this.idleUtterances_.concat([utterance]); |
var targetExpectation = this.expectations_.shift(); |
- if (allUtterances.some(targetExpectation.predicate)) { |
+ allUtterances = allUtterances.filter(function(u) { |
+ return targetExpectation.predicate(u.text); |
+ }); |
+ if (allUtterances.length > 0) { |
+ var matchingProperties = allUtterances[0].properties; |
this.idleUtterances_.length = 0; |
if (targetExpectation.endCallback) |
targetExpectation.endCallback(); |
+ if (matchingProperties && matchingProperties.endCallback) { |
+ matchingProperties.endCallback(); |
+ } |
var nextExpectation = this.expectations_[0]; |
if (nextExpectation && nextExpectation.startCallback) |
nextExpectation.startCallback(); |