Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: chrome/browser/resources/chromeos/chromevox/testing/mock_tts.js

Issue 1295213003: Make cvox2 output feedback more robust when focusing a text field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plundblad_fix
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698