Chromium Code Reviews| 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 3f32d0ca400195ba699af41f9c70f0463edc5d2d..8bde1059c2d434892b40053510d0e22c52bfabc3 100644 |
| --- a/chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js |
| +++ b/chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js |
| @@ -27,6 +27,13 @@ MockTts.prototype = { |
| */ |
| idleUtterances_: [], |
| + /** |
| + * Whether we should skip non-matching utterances. Initially it's set |
| + * to true, but after the first matching utterance it's set to false |
| + * so that we can assert that no extra unrelated speech is generated. |
|
David Tseng
2015/08/19 17:19:25
I think this is called a strict mock.
|
| + */ |
|
David Tseng
2015/08/19 17:19:25
nit: @private
|
| + skipNonMatchingUtterances_: true, |
|
Peter Lundblad
2015/08/20 08:30:06
I support this in principal, but it has the potent
|
| + |
| /** @override */ |
| speak: function(textString, queueMode, properties) { |
| this.process_(textString, false, properties); |
| @@ -79,6 +86,7 @@ MockTts.prototype = { |
| addExpectation_: function(expectedText, opt_expectation, opt_exact) { |
| var expectation = opt_expectation ? opt_expectation : {}; |
| + expectation.text = expectedText; |
| expectation.predicate = function(actualText) { |
| if (opt_exact) |
| return actualText === expectedText; |
| @@ -110,10 +118,23 @@ MockTts.prototype = { |
| var allUtterances = this.idleUtterances_.concat([utterance]); |
| var targetExpectation = this.expectations_.shift(); |
| - allUtterances = allUtterances.filter(function(u) { |
| - return targetExpectation.predicate(u.text); |
| - }); |
| + |
| + if (this.skipNonMatchingUtterances_) { |
| + allUtterances = allUtterances.filter(function(u) { |
| + return targetExpectation.predicate(u.text); |
| + }); |
| + } else if (allUtterances.length > 0 && |
| + !targetExpectation.predicate(allUtterances[0].text)) { |
| + throw new Error('Mock TTS expected ' + targetExpectation.text + |
| + ' but got ' + allUtterances[0].text); |
| + return; |
| + } |
| + |
| if (allUtterances.length > 0) { |
| + // We got a match. Don't skip any more non-matching utterances |
| + // anymore. |
|
Peter Lundblad
2015/08/20 08:30:06
nit: any more, anymore
|
| + this.skipNonMatchingUtterances_ = false; |
| + |
| var matchingProperties = allUtterances[0].properties; |
| this.idleUtterances_.length = 0; |
| if (targetExpectation.endCallback) |