Index: chrome/browser/resources/chromeos/chromevox/host/testing/tts.js |
diff --git a/chrome/browser/resources/chromeos/chromevox/host/testing/tts.js b/chrome/browser/resources/chromeos/chromevox/host/testing/tts.js |
index bff32f281e56a50eb3068a11c2ff2452ff5fbb5e..3b9f556c89960d279324970899f928df6376ec99 100644 |
--- a/chrome/browser/resources/chromeos/chromevox/host/testing/tts.js |
+++ b/chrome/browser/resources/chromeos/chromevox/host/testing/tts.js |
@@ -37,7 +37,9 @@ cvox.TestTts.prototype.sentinelText_ = '@@@STOP@@@'; |
* @override |
*/ |
cvox.TestTts.prototype.speak = function(text, queueMode, opt_properties) { |
- this.utterances_.push({text: text, queueMode: queueMode}); |
+ this.utterances_.push({text: text, |
+ queueMode: queueMode, |
+ properties: opt_properties}); |
if (opt_properties && opt_properties['endCallback'] != undefined) { |
var len = this.utterances_.length; |
// 'After' is a sentinel value in the tests that tells TTS to stop and |
@@ -82,6 +84,49 @@ cvox.TestTts.prototype.getUtterancesAsString = function() { |
}; |
/** |
+ * Processes the utterances spoken the same way the speech queue does, |
+ * as if they were all generated one after another, with no delay between |
+ * them, and returns a list of strings that would be output. |
+ * |
+ * For example, if two strings were spoken with a queue mode of FLUSH, |
+ * only the second string will be returned. |
+ * @return {Array.<string>} A list of strings representing the speech output. |
+ */ |
+cvox.TestTts.prototype.getSpeechQueueOutput = function() { |
+ var queue = []; |
+ for (var i = 0; i < this.utterances_.length; i++) { |
+ var utterance = this.utterances_[i]; |
+ switch (utterance.queueMode) { |
+ case cvox.AbstractTts.QUEUE_MODE_FLUSH: |
+ queue = []; |
+ break; |
+ case cvox.AbstractTts.QUEUE_MODE_QUEUE: |
+ break; |
+ case cvox.AbstractTts.QUEUE_MODE_CATEGORY_FLUSH: |
+ var oldQueue = queue; |
David Tseng
2014/09/26 22:42:20
You could just
(pseudocode)
if utterance has categ
dmazzoni
2014/09/26 22:51:49
Done.
|
+ queue = []; |
+ if (utterance.properties && utterance.properties.category) { |
+ for (var i = 0; i < oldQueue.length; i++) { |
+ if (!oldQueue[i].properties || |
+ oldQueue[i].properties.category != |
+ utterance.properties.category) { |
+ queue.push(oldQueue[i]); |
+ } |
+ } |
+ } |
+ break; |
+ } |
+ queue.push(utterance); |
David Tseng
2014/09/26 22:42:20
Did you mean to push here?
dmazzoni
2014/09/26 22:51:49
Yes
|
+ } |
+ |
+ var result = []; |
David Tseng
2014/09/26 22:42:20
queue.map() seems like a good pattern here.
dmazzoni
2014/09/26 22:51:49
Done.
|
+ for (var i = 0; i < queue.length; i++) { |
+ result.push(queue[i].text); |
+ } |
+ return result; |
+}; |
+ |
+/** |
* Return a list of strings of what was spoken by tts.speak(). |
* @return {Array.<string>} A list of all utterances spoken since |
* initialization or the last call to clearUtterances. |