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 // Include test fixture. | 5 // Include test fixture. |
6 GEN_INCLUDE(['../../testing/chromevox_e2e_test_base.js']); | 6 GEN_INCLUDE(['../../testing/chromevox_e2e_test_base.js']); |
7 | 7 |
8 /** | 8 /** |
9 * Test fixture for cvox2.Background. | 9 * Test fixture for cvox2.Background. |
10 * @constructor | 10 * @constructor |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 /** | 43 /** |
44 * Mock tts class. | 44 * Mock tts class. |
45 * @constructor | 45 * @constructor |
46 * @extends {cvox.TtsInterface} | 46 * @extends {cvox.TtsInterface} |
47 */ | 47 */ |
48 var MockTts = function() { | 48 var MockTts = function() { |
49 }; | 49 }; |
50 | 50 |
51 MockTts.prototype = { | 51 MockTts.prototype = { |
52 /** Tracks all spoken text. @type {!Array.<string>} */ | 52 /** |
53 utterances: [], | 53 * A list of predicate callbacks. |
54 * @type {!Array.<function(string) : boolean>} | |
55 * @private | |
56 */ | |
57 callbacks_: [], | |
58 | |
59 /** | |
60 * A list of strings stored whenever there are no expectations. | |
61 * @type {!Array.<string} | |
62 * @private | |
63 */ | |
64 idleUtterances_: [], | |
dmazzoni
2014/09/29 06:06:17
nit: indent 2
David Tseng
2014/09/29 17:05:23
Done.
| |
54 | 65 |
55 /** @override */ | 66 /** @override */ |
56 speak: function(textString, queueMode, properties) { | 67 speak: function(textString, queueMode, properties) { |
57 this.utterances.push(textString); | 68 this.process_(textString); |
58 }, | 69 }, |
59 | 70 |
60 /** | 71 /** |
61 * Checks to see if a string was spoken. | 72 * Adds an expectation for the given string to be spoken. If satisfied, |
62 * @param {string} textString The string to check. | 73 * |opt_callback| is * called. |
dmazzoni
2014/09/29 06:06:18
Nit: delete extra '*'
David Tseng
2014/09/29 17:05:23
Done.
| |
63 * @return {boolean} True if the string was spoken (possibly as part of a | 74 * @param {string} expected |
64 * larger utterance). | 75 * @param {function() : void=} opt_callback |
65 */ | 76 */ |
66 checkIfSubstringWasSpoken: function(textString) { | 77 expectSpeech: function(expected, opt_callback) { |
67 return this.utterances.some(function(t) { | 78 this.callbacks_.push(function(actual) { |
68 return t.indexOf(textString) != -1; | 79 var match = actual.indexOf(expected) != -1; |
80 if (opt_callback && match) | |
81 opt_callback(); | |
82 return match; | |
69 }); | 83 }); |
70 } | 84 |
85 // Process any idleUtterances. | |
86 this.idleUtterances_.forEach(this.process_, true); | |
87 }, | |
88 | |
89 /** | |
90 * @param {string} textString Utterance to match against callbacks. | |
91 * @param {boolean=} opt_manual True if called outside of tts.speak. | |
92 * @private | |
93 */ | |
94 process_: function(textString, opt_manual) { | |
95 if (this.callbacks_.length == 0) { | |
96 if (!opt_manual) | |
97 this.idleUtterances_.push(textString); | |
98 return; | |
99 } | |
100 | |
101 var allUtterances = this.idleUtterances_.concat([textString]); | |
102 var targetCallback = this.callbacks_.shift(); | |
103 if (allUtterances.some(targetCallback)) | |
104 this.idleUtterances_.length = 0; | |
105 else | |
106 this.callbacks_.unshift(targetCallback); | |
107 }, | |
71 }; | 108 }; |
72 | 109 |
73 /** Tests that ChromeVox classic is in this context. */ | 110 /** Tests that ChromeVox classic is in this context. */ |
74 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { | 111 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { |
75 assertEquals('object', typeof(cvox)); | 112 assertEquals('object', typeof(cvox)); |
76 assertEquals('function', typeof(cvox.ChromeVoxBackground)); | 113 assertEquals('function', typeof(cvox.ChromeVoxBackground)); |
77 }); | 114 }); |
78 | 115 |
79 /** Tests that ChromeVox next is in this context. */ | 116 /** Tests that ChromeVox next is in this context. */ |
80 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { | 117 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { |
(...skipping 12 matching lines...) Expand all Loading... | |
93 for (var i = 0; i < root.children().length; i++) { | 130 for (var i = 0; i < root.children().length; i++) { |
94 var found = findStatusTray(root.children()[i]); | 131 var found = findStatusTray(root.children()[i]); |
95 if (found) | 132 if (found) |
96 return found; | 133 return found; |
97 } | 134 } |
98 return null; | 135 return null; |
99 } | 136 } |
100 | 137 |
101 chrome.automation.getDesktop(function(root) { | 138 chrome.automation.getDesktop(function(root) { |
102 var testButton = findStatusTray(root); | 139 var testButton = findStatusTray(root); |
103 testButton.addEventListener(chrome.automation.EventType.focus, | 140 cvox.ChromeVox.tts.expectSpeech('Status tray', testDone); |
dmazzoni
2014/09/29 06:06:18
This looks much cleaner. I don't mind that the ord
| |
104 function(e) { | |
105 var result = | |
106 cvox.ChromeVox.tts.checkIfSubstringWasSpoken('Status tray'); | |
107 testDone([result, '']); | |
108 }, | |
109 true); | |
110 testButton.focus(); | 141 testButton.focus(); |
111 }); | 142 }); |
112 }); | 143 }); |
144 | |
145 /** Tests feedback once a page loads. */ | |
146 TEST_F('BackgroundTest', 'InitialFeedback', function() { | |
147 this.runWithDocument(function() {/*! | |
148 <p>start | |
149 <p>end | |
150 */}, | |
151 function() { | |
152 cvox.ChromeVox.tts.expectSpeech('start', function() { | |
153 cvox2.global.backgroundObj.onGotCommand('nextLine'); | |
154 }); | |
155 cvox.ChromeVox.tts.expectSpeech('end', testDone); | |
156 }.bind(this)); | |
157 }); | |
OLD | NEW |