| 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 * @fileoverview Dummy implementation of TTS for testing. | 6 * @fileoverview Dummy implementation of TTS for testing. |
| 7 * | 7 * |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 goog.provide('cvox.TestTts'); | 10 goog.provide('cvox.TestTts'); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 * @type {string} | 30 * @type {string} |
| 31 * @private | 31 * @private |
| 32 */ | 32 */ |
| 33 cvox.TestTts.prototype.sentinelText_ = '@@@STOP@@@'; | 33 cvox.TestTts.prototype.sentinelText_ = '@@@STOP@@@'; |
| 34 | 34 |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * @override | 37 * @override |
| 38 */ | 38 */ |
| 39 cvox.TestTts.prototype.speak = function(text, queueMode, opt_properties) { | 39 cvox.TestTts.prototype.speak = function(text, queueMode, opt_properties) { |
| 40 this.utterances_.push({text: text, | 40 this.utterances_.push( |
| 41 queueMode: queueMode, | 41 {text: text, queueMode: queueMode, properties: opt_properties}); |
| 42 properties: opt_properties}); | |
| 43 if (opt_properties && opt_properties['endCallback'] != undefined) { | 42 if (opt_properties && opt_properties['endCallback'] != undefined) { |
| 44 var len = this.utterances_.length; | 43 var len = this.utterances_.length; |
| 45 // 'After' is a sentinel value in the tests that tells TTS to stop and | 44 // 'After' is a sentinel value in the tests that tells TTS to stop and |
| 46 // ends callbacks being called. | 45 // ends callbacks being called. |
| 47 if (this.utterances_[len - 1].text != | 46 if (this.utterances_[len - 1].text != this.sentinelText_) { |
| 48 this.sentinelText_) { | |
| 49 opt_properties['endCallback'](); | 47 opt_properties['endCallback'](); |
| 50 } | 48 } |
| 51 } | 49 } |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 | 52 |
| 55 /** | 53 /** |
| 56 * Creates a sentinel element that indicates when TTS should stop and callbacks | 54 * Creates a sentinel element that indicates when TTS should stop and callbacks |
| 57 * should stop being called. | 55 * should stop being called. |
| 58 * @return {Element} The sentinel element. | 56 * @return {Element} The sentinel element. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 var utterance = this.utterances_[i]; | 96 var utterance = this.utterances_[i]; |
| 99 switch (utterance.queueMode) { | 97 switch (utterance.queueMode) { |
| 100 case cvox.AbstractTts.QUEUE_MODE_FLUSH: | 98 case cvox.AbstractTts.QUEUE_MODE_FLUSH: |
| 101 queue = []; | 99 queue = []; |
| 102 break; | 100 break; |
| 103 case cvox.AbstractTts.QUEUE_MODE_QUEUE: | 101 case cvox.AbstractTts.QUEUE_MODE_QUEUE: |
| 104 break; | 102 break; |
| 105 case cvox.AbstractTts.QUEUE_MODE_CATEGORY_FLUSH: | 103 case cvox.AbstractTts.QUEUE_MODE_CATEGORY_FLUSH: |
| 106 queue = queue.filter(function(u) { | 104 queue = queue.filter(function(u) { |
| 107 return (utterance.properties && utterance.properties.category) && | 105 return (utterance.properties && utterance.properties.category) && |
| 108 (!u.properties || | 106 (!u.properties || |
| 109 u.properties.category != utterance.properties.category); | 107 u.properties.category != utterance.properties.category); |
| 110 }); | 108 }); |
| 111 break; | 109 break; |
| 112 } | 110 } |
| 113 queue.push(utterance); | 111 queue.push(utterance); |
| 114 } | 112 } |
| 115 | 113 |
| 116 return queue.map(function(u) { return u.text; }); | 114 return queue.map(function(u) { |
| 115 return u.text; |
| 116 }); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * Return a list of strings of what was spoken by tts.speak(). | 120 * Return a list of strings of what was spoken by tts.speak(). |
| 121 * @return {Array<string>} A list of all utterances spoken since | 121 * @return {Array<string>} A list of all utterances spoken since |
| 122 * initialization or the last call to clearUtterances. | 122 * initialization or the last call to clearUtterances. |
| 123 */ | 123 */ |
| 124 cvox.TestTts.prototype.getUtteranceList = function() { | 124 cvox.TestTts.prototype.getUtteranceList = function() { |
| 125 var result = []; | 125 var result = []; |
| 126 for (var i = 0; i < this.utterances_.length; i++) { | 126 for (var i = 0; i < this.utterances_.length; i++) { |
| 127 result.push(this.utterances_[i].text); | 127 result.push(this.utterances_[i].text); |
| 128 } | 128 } |
| 129 return result; | 129 return result; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * Return a list of strings of what was spoken by tts.speak(). | 133 * Return a list of strings of what was spoken by tts.speak(). |
| 134 * @return {Array<{text: string, queueMode: cvox.QueueMode}>} | 134 * @return {Array<{text: string, queueMode: cvox.QueueMode}>} |
| 135 * A list of info about all utterances spoken since | 135 * A list of info about all utterances spoken since |
| 136 * initialization or the last call to clearUtterances. | 136 * initialization or the last call to clearUtterances. |
| 137 */ | 137 */ |
| 138 cvox.TestTts.prototype.getUtteranceInfoList = function() { | 138 cvox.TestTts.prototype.getUtteranceInfoList = function() { |
| 139 return this.utterances_; | 139 return this.utterances_; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 /** @override */ | 142 /** @override */ |
| 143 cvox.HostFactory.ttsConstructor = cvox.TestTts; | 143 cvox.HostFactory.ttsConstructor = cvox.TestTts; |
| OLD | NEW |