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 /** | 5 /** |
6 * Mock tts class. | 6 * Mock tts class. |
7 * @constructor | 7 * @constructor |
8 * @extends {cvox.TtsInterface} | 8 * @extends {cvox.TtsInterface} |
9 */ | 9 */ |
10 var MockTts = function() { | 10 var MockTts = function() { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (opt_exact) | 106 if (opt_exact) |
107 return actualText === expectedText; | 107 return actualText === expectedText; |
108 return actualText.indexOf(expectedText) != -1; | 108 return actualText.indexOf(expectedText) != -1; |
109 }; | 109 }; |
110 | 110 |
111 this.expectations_.push(expectation); | 111 this.expectations_.push(expectation); |
112 | 112 |
113 // Process any idleUtterances. | 113 // Process any idleUtterances. |
114 this.idleUtterances_.forEach(function(utterance) { | 114 this.idleUtterances_.forEach(function(utterance) { |
115 this.process_(utterance, true); | 115 this.process_(utterance, true); |
116 }); | 116 }.bind(this)); |
117 }, | 117 }, |
118 | 118 |
119 /** | 119 /** |
120 * @param {string} textString Utterance to match against callbacks. | 120 * @param {string} textString Utterance to match against callbacks. |
121 * @param {boolean=} opt_manual True if called outside of tts.speak. | 121 * @param {boolean=} opt_manual True if called outside of tts.speak. |
122 * @private | 122 * @private |
123 */ | 123 */ |
124 process_: function(textString, opt_manual) { | 124 process_: function(textString, opt_manual) { |
125 if (this.expectations_.length == 0) { | 125 if (this.expectations_.length == 0) { |
126 if (!opt_manual) | 126 if (!opt_manual) |
127 this.idleUtterances_.push(textString); | 127 this.idleUtterances_.push(textString); |
128 return; | 128 return; |
129 } | 129 } |
130 | 130 |
131 var allUtterances = this.idleUtterances_.concat([textString]); | 131 var allUtterances = this.idleUtterances_.concat([textString]); |
132 var targetExpectation = this.expectations_.shift(); | 132 var targetExpectation = this.expectations_.shift(); |
133 if (allUtterances.some(targetExpectation.predicate)) { | 133 if (allUtterances.some(targetExpectation.predicate)) { |
134 this.idleUtterances_.length = 0; | 134 this.idleUtterances_.length = 0; |
135 if (targetExpectation.endCallback) | 135 if (targetExpectation.endCallback) |
136 targetExpectation.endCallback(); | 136 targetExpectation.endCallback(); |
137 var nextExpectation = this.expectations_[0]; | 137 var nextExpectation = this.expectations_[0]; |
138 if (nextExpectation && nextExpectation.startCallback) | 138 if (nextExpectation && nextExpectation.startCallback) |
139 nextExpectation.startCallback(); | 139 nextExpectation.startCallback(); |
140 } else { | 140 } else { |
141 this.expectations_.unshift(targetExpectation); | 141 this.expectations_.unshift(targetExpectation); |
142 } | 142 } |
143 }, | 143 }, |
144 }; | 144 }; |
OLD | NEW |