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_next_e2e_test_base.js']); | 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js', |
7 '../../testing/assert_additions.js']); | |
7 | 8 |
8 GEN_INCLUDE(['../../testing/mock_tts.js']); | 9 GEN_INCLUDE(['../../testing/mock_feedback.js']); |
9 | 10 |
10 /** | 11 /** |
11 * Test fixture for Background. | 12 * Test fixture for Background. |
12 * @constructor | 13 * @constructor |
13 * @extends {ChromeVoxNextE2ETest} | 14 * @extends {ChromeVoxNextE2ETest} |
14 */ | 15 */ |
15 function BackgroundTest() { | 16 function BackgroundTest() { |
16 ChromeVoxNextE2ETest.call(this); | 17 ChromeVoxNextE2ETest.call(this); |
17 } | 18 } |
18 | 19 |
19 BackgroundTest.prototype = { | 20 BackgroundTest.prototype = { |
20 __proto__: ChromeVoxNextE2ETest.prototype, | 21 __proto__: ChromeVoxNextE2ETest.prototype, |
21 | 22 |
22 /** @override */ | 23 /** |
23 setUp: function() { | 24 * @return {!MockFeedback} |
24 this.mockTts = new MockTts(); | 25 */ |
25 cvox.ChromeVox.tts = this.mockTts; | 26 createMockFeedback: function() { |
27 var mockFeedback = new MockFeedback(this.newCallback(), | |
28 this.newCallback.bind(this)); | |
29 mockFeedback.install(); | |
30 return mockFeedback; | |
26 }, | 31 }, |
27 | 32 |
28 /** | 33 /** |
29 * Create a function which perform the command |cmd|. | 34 * Create a function which perform the command |cmd|. |
30 * @param {string} cmd | 35 * @param {string} cmd |
31 * @return {function() : void} | 36 * @return {function() : void} |
32 */ | 37 */ |
33 doCmd: function(cmd) { | 38 doCmd: function(cmd) { |
34 return function() { | 39 return function() { |
35 global.backgroundObj.onGotCommand(cmd); | 40 global.backgroundObj.onGotCommand(cmd); |
(...skipping 26 matching lines...) Expand all Loading... | |
62 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { | 67 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { |
63 assertEquals('object', typeof(cvox)); | 68 assertEquals('object', typeof(cvox)); |
64 assertEquals('function', typeof(cvox.ChromeVoxBackground)); | 69 assertEquals('function', typeof(cvox.ChromeVoxBackground)); |
65 }); | 70 }); |
66 | 71 |
67 /** Tests that ChromeVox next is in this context. */ | 72 /** Tests that ChromeVox next is in this context. */ |
68 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { | 73 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { |
69 assertEquals('function', typeof(Background)); | 74 assertEquals('function', typeof(Background)); |
70 }); | 75 }); |
71 | 76 |
72 /** Tests feedback once a page loads. */ | |
73 TEST_F('BackgroundTest', 'MANUAL_InitialFeedback', function() { | |
74 cvox.ChromeVox.tts.expectSpeech('start', this.newCallback()); | |
75 | |
76 this.runWithTab(function() {/*! | |
77 <p>start | |
78 <p>end | |
79 */}); | |
80 }); | |
81 | |
82 /** Tests consistency of navigating forward and backward. */ | 77 /** Tests consistency of navigating forward and backward. */ |
83 TEST_F('BackgroundTest', 'MANUAL_ForwardBackwardNavigation', function() { | 78 TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() { |
79 var mockFeedback = this.createMockFeedback(); | |
84 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() { | 80 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() { |
85 var doCmd = this.doCmd.bind(this); | 81 var doCmd = this.doCmd.bind(this); |
86 var expectAfter = | |
87 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts); | |
88 | 82 |
89 expectAfter('alpha', doCmd('nextLink')); | 83 mockFeedback.expectSpeech('start').expectBraille('start'); |
90 expectAfter('beta', doCmd('nextLink')); | |
91 expectAfter('delta', doCmd('nextLink')); | |
92 expectAfter('beta', doCmd('previousLink')); | |
93 | 84 |
94 expectAfter('charlie', doCmd('nextHeading')); | 85 mockFeedback.call(doCmd('nextLink')) |
95 expectAfter('foxtraut', doCmd('nextHeading')); | 86 .expectSpeech('alpha', 'Link') |
96 expectAfter('charlie', doCmd('previousHeading')); | 87 .expectBraille('alpha lnk'); |
88 mockFeedback.call(doCmd('nextLink')) | |
89 .expectSpeech('beta', 'Link') | |
90 .expectBraille('beta lnk'); | |
91 mockFeedback.call(doCmd('nextLink')) | |
92 .expectSpeech('delta', 'Link') | |
93 .expectBraille('delta lnk'); | |
94 mockFeedback.call(doCmd('previousLink')) | |
95 .expectSpeech('beta', 'Link') | |
96 .expectBraille('beta lnk'); | |
97 mockFeedback.call(doCmd('nextHeading')) | |
98 .expectSpeech('Heading 1', 'charlie') | |
99 .expectBraille('h1 charlie'); | |
100 mockFeedback.call(doCmd('nextHeading')) | |
101 .expectSpeech('Heading 2', 'foxtraut') | |
102 .expectBraille('h2 foxtraut'); | |
103 mockFeedback.call(doCmd('previousHeading')) | |
104 .expectSpeech('Heading 1', 'charlie') | |
105 .expectBraille('h1 charlie'); | |
97 | 106 |
98 expectAfter('delta', doCmd('nextElement')); | 107 mockFeedback.call(doCmd('nextElement')) |
99 expectAfter('echo', doCmd('nextElement')); | 108 .expectSpeech('delta', 'Link') |
100 expectAfter('foxtraut', doCmd('nextElement')); | 109 .expectBraille('delta lnk'); |
101 expectAfter('end', doCmd('nextElement')); | 110 mockFeedback.call(doCmd('nextElement')) |
102 expectAfter('foxtraut', doCmd('previousElement')); | 111 .expectSpeech('echo', 'Link') |
103 expectAfter('end of test', doCmd('nextLine')); | 112 .expectBraille('echo lnk'); |
113 mockFeedback.call(doCmd('nextElement')) | |
114 .expectSpeech('Heading 2', 'foxtraut') | |
115 .expectBraille('h2 foxtraut'); | |
116 mockFeedback.call(doCmd('nextElement')) | |
117 .expectSpeech('end') | |
118 .expectBraille('end'); | |
119 mockFeedback.call(doCmd('previousElement')) | |
120 .expectSpeech('Heading 2', 'foxtraut') | |
121 .expectBraille('h2 foxtraut'); | |
122 mockFeedback.call(doCmd('nextLine')) | |
123 .expectSpeech('end', 'of test') | |
124 .expectBraille('end of test'); | |
104 | 125 |
105 expectAfter('start', doCmd('goToBeginning')); | 126 mockFeedback.call(doCmd('goToBeginning')) |
106 expectAfter('of test', doCmd('goToEnd')); | 127 .expectSpeech('start') |
128 .expectBraille('start'); | |
129 mockFeedback.call(doCmd('goToEnd')) | |
130 .expectSpeech('of test') | |
dmazzoni
2015/08/24 19:05:06
Do you think an expectSpeechAndBraille helper woul
| |
131 .expectBraille('of test'); | |
107 | 132 |
108 cvox.ChromeVox.tts.finishExpectations(this.newCallback()); | 133 mockFeedback.replay(); |
109 }); | 134 }); |
110 }); | 135 }); |
111 | 136 |
112 TEST_F('BackgroundTest', 'MANUAL_CaretNavigation', function() { | 137 TEST_F('BackgroundTest', 'CaretNavigation', function() { |
138 // TODO(plundblad): Add braille expectaions when crbug.com/523285 is fixed. | |
139 var mockFeedback = this.createMockFeedback(); | |
113 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() { | 140 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() { |
114 var doCmd = this.doCmd.bind(this); | 141 var doCmd = this.doCmd.bind(this); |
115 var expectAfter = | |
116 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts); | |
117 | 142 |
118 expectAfter('t', doCmd('nextCharacter'), true); | 143 mockFeedback.expectSpeech('start'); |
119 expectAfter('a', doCmd('nextCharacter'), true); | 144 mockFeedback.call(doCmd('nextCharacter')) |
120 expectAfter('Link alpha', doCmd('nextWord'), true); | 145 .expectSpeech('t'); |
121 expectAfter('Link beta', doCmd('nextWord'), true); | 146 mockFeedback.call(doCmd('nextCharacter')) |
122 expectAfter('Heading charlie', doCmd('nextWord'), true); | 147 .expectSpeech('a'); |
123 expectAfter('Link delta', doCmd('nextLine'), true); | 148 mockFeedback.call(doCmd('nextWord')) |
124 expectAfter('Link echo', doCmd('nextLine'), true); | 149 .expectSpeech('Link', 'alpha'); |
125 expectAfter('Heading foxtraut', doCmd('nextLine'), true); | 150 mockFeedback.call(doCmd('nextWord')) |
126 expectAfter( | 151 .expectSpeech('Link', 'beta'); |
127 'end of test', doCmd('nextLine'), true); | 152 mockFeedback.call(doCmd('nextWord')) |
128 expectAfter('n', doCmd('nextCharacter'), true); | 153 .expectSpeech('Heading 1', 'charlie'); |
129 expectAfter('e', doCmd('previousCharacter'), true); | 154 mockFeedback.call(doCmd('nextLine')) |
130 expectAfter('Heading t', doCmd('previousCharacter'), true); | 155 .expectSpeech('Link', 'delta'); |
131 expectAfter('foxtraut', doCmd('previousWord'), true); | 156 mockFeedback.call(doCmd('nextLine')) |
132 expectAfter('Link echo', doCmd('previousWord'), true); | 157 .expectSpeech('Link', 'echo'); |
133 expectAfter('Link a', doCmd('previousCharacter'), true); | 158 mockFeedback.call(doCmd('nextLine')) |
134 expectAfter('t', doCmd('previousCharacter'), true); | 159 .expectSpeech('Heading 2', 'foxtraut'); |
135 expectAfter('Link echo', doCmd('nextWord'), true); | 160 mockFeedback.call(doCmd('nextLine')) |
136 | 161 .expectSpeech('end', 'of test'); |
137 cvox.ChromeVox.tts.finishExpectations(this.newCallback()); | 162 mockFeedback.call(doCmd('nextCharacter')) |
163 .expectSpeech('n'); | |
164 mockFeedback.call(doCmd('previousCharacter')) | |
165 .expectSpeech('e'); | |
166 mockFeedback.call(doCmd('previousCharacter')) | |
167 .expectSpeech('Heading 2', 't'); | |
168 mockFeedback.call(doCmd('previousWord')) | |
169 .expectSpeech('foxtraut'); | |
170 mockFeedback.call(doCmd('previousWord')) | |
171 .expectSpeech('Link', 'echo'); | |
172 mockFeedback.call(doCmd('previousCharacter')) | |
173 .expectSpeech('Link', 'a'); | |
174 mockFeedback.call(doCmd('previousCharacter')) | |
175 .expectSpeech('t'); | |
176 mockFeedback.call(doCmd('nextWord')) | |
177 .expectSpeech('Link', 'echo'); | |
178 mockFeedback.replay(); | |
138 }); | 179 }); |
139 }); | 180 }); |
140 | 181 |
141 // Flaky: http://crbug.com/451362 | 182 TEST_F('BackgroundTest', 'SelectSingleBasic', function() { |
142 TEST_F('BackgroundTest', 'DISABLED_SelectSingleBasic', function() { | 183 var mockFeedback = this.createMockFeedback(); |
143 this.runWithLoadedTree(this.formsDoc, function() { | 184 this.runWithLoadedTree(this.formsDoc, function() { |
144 var sendDownToSelect = | 185 var sendDownToSelect = |
145 this.sendKeyToElement.bind(this, undefined, 'Down', '#fruitSelect'); | 186 this.sendKeyToElement.bind(this, undefined, 'Down', '#fruitSelect'); |
146 var expect = cvox.ChromeVox.tts.expectSpeech.bind(cvox.ChromeVox.tts); | 187 mockFeedback.expectSpeech('apple', 'Menu item', /1 of 3/) |
147 expect('apple Menu item 1 of 3 ', sendDownToSelect, true); | 188 .expectBraille('apple mnuitm 1/3') |
148 expect('grape 2 of 3 ', sendDownToSelect, true); | 189 .call(sendDownToSelect) |
149 expect('banana 3 of 3 ', function() {}, true); | 190 .expectSpeech('grape', /2 of 3/) |
150 cvox.ChromeVox.tts.finishExpectations(this.newCallback()); | 191 .expectBraille('grape mnuitm 2/3') |
192 .call(sendDownToSelect) | |
193 .expectSpeech('banana', /3 of 3/) | |
194 .expectBraille('banana mnuitm 3/3'); | |
195 mockFeedback.replay(); | |
151 }); | 196 }); |
152 }); | 197 }); |
153 | 198 |
154 TEST_F('BackgroundTest', 'MANUAL_ContinuousRead', function() { | 199 TEST_F('BackgroundTest', 'ContinuousRead', function() { |
200 var mockFeedback = this.createMockFeedback(); | |
155 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() { | 201 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() { |
156 cvox.ChromeVox.tts.expectSpeech('start'); | 202 mockFeedback.expectSpeech('start') |
157 cvox.ChromeVox.tts.expectSpeechAfter('start', this.doCmd('continuousRead')); | 203 .call(this.doCmd('continuousRead')) |
158 cvox.ChromeVox.tts.expectSpeech('alpha'); | 204 .expectSpeech( |
159 cvox.ChromeVox.tts.expectSpeech('Link'); | 205 'start', |
160 cvox.ChromeVox.tts.expectSpeech('beta'); | 206 'alpha', 'Link', |
161 cvox.ChromeVox.tts.expectSpeech('Link'); | 207 'beta', 'Link', |
162 cvox.ChromeVox.tts.expectSpeech('Heading 1'); | 208 'Heading 1', 'charlie'); |
163 cvox.ChromeVox.tts.expectSpeech('charlie'); | 209 mockFeedback.replay(); |
164 cvox.ChromeVox.tts.finishExpectations(); | |
165 }); | 210 }); |
166 }); | 211 }); |
167 | 212 |
168 TEST_F('BackgroundTest', 'LiveRegionAddElement', function() { | 213 TEST_F('BackgroundTest', 'LiveRegionAddElement', function() { |
214 var mockFeedback = this.createMockFeedback(); | |
169 this.runWithLoadedTree( | 215 this.runWithLoadedTree( |
170 function() {/*! | 216 function() {/*! |
171 <h1>Document with live region</h1> | 217 <h1>Document with live region</h1> |
172 <p id="live" aria-live="polite"></p> | 218 <p id="live" aria-live="polite"></p> |
173 <button id="go">Go</button> | 219 <button id="go">Go</button> |
174 <script> | 220 <script> |
175 document.getElementById('go').addEventListener('click', function() { | 221 document.getElementById('go').addEventListener('click', function() { |
176 document.getElementById('live').innerHTML = 'Hello, world'; | 222 document.getElementById('live').innerHTML = 'Hello, world'; |
177 }, false); | 223 }, false); |
178 </script> | 224 </script> |
179 */}, | 225 */}, |
180 function(rootNode) { | 226 function(rootNode) { |
181 var go = rootNode.find({ role: chrome.automation.RoleType.button }); | 227 var go = rootNode.find({ role: chrome.automation.RoleType.button }); |
182 go.doDefault(); | 228 mockFeedback.call(go.doDefault.bind(go)) |
183 cvox.ChromeVox.tts.expectSpeech('Hello, world'); | 229 .expectSpeech('Hello, world'); |
184 cvox.ChromeVox.tts.finishExpectations(this.newCallback()); | 230 mockFeedback.replay(); |
185 }); | 231 }); |
186 }); | 232 }); |
187 | 233 |
188 TEST_F('BackgroundTest', 'LiveRegionRemoveElement', function() { | 234 TEST_F('BackgroundTest', 'LiveRegionRemoveElement', function() { |
235 var mockFeedback = this.createMockFeedback(); | |
189 this.runWithLoadedTree( | 236 this.runWithLoadedTree( |
190 function() {/*! | 237 function() {/*! |
191 <h1>Document with live region</h1> | 238 <h1>Document with live region</h1> |
192 <p id="live" aria-live="polite" aria-relevant="removals">Hello, world</p> | 239 <p id="live" aria-live="polite" aria-relevant="removals">Hello, world</p> |
193 <button id="go">Go</button> | 240 <button id="go">Go</button> |
194 <script> | 241 <script> |
195 document.getElementById('go').addEventListener('click', function() { | 242 document.getElementById('go').addEventListener('click', function() { |
196 document.getElementById('live').innerHTML = ''; | 243 document.getElementById('live').innerHTML = ''; |
197 }, false); | 244 }, false); |
198 </script> | 245 </script> |
199 */}, | 246 */}, |
200 function(rootNode) { | 247 function(rootNode) { |
201 var go = rootNode.find({ role: chrome.automation.RoleType.button }); | 248 var go = rootNode.find({ role: chrome.automation.RoleType.button }); |
202 go.doDefault(); | 249 go.doDefault(); |
203 cvox.ChromeVox.tts.expectSpeech('removed:'); | 250 mockFeedback.expectSpeech('removed:') |
204 cvox.ChromeVox.tts.expectSpeech('Hello, world'); | 251 .expectSpeech('Hello, world'); |
205 cvox.ChromeVox.tts.finishExpectations(this.newCallback()); | 252 mockFeedback.replay(); |
206 }); | 253 }); |
207 }); | 254 }); |
208 | 255 |
209 TEST_F('BackgroundTest', 'InitialFocus', function() { | 256 TEST_F('BackgroundTest', 'InitialFocus', function() { |
210 cvox.ChromeVox.tts.expectSpeech('a'); | 257 var mockFeedback = this.createMockFeedback(); |
211 cvox.ChromeVox.tts.expectSpeech('Link', this.newCallback()); | 258 this.runWithLoadedTree('<a href="a">a</a>', |
212 this.runWithLoadedTree('<a href="a">a</a>', function() {}); | 259 function(rootNode) { |
260 mockFeedback.expectSpeech('a') | |
261 .expectSpeech('Link'); | |
262 mockFeedback.replay(); | |
263 }); | |
213 }); | 264 }); |
214 | 265 |
215 TEST_F('BackgroundTest', 'AriaLabel', function() { | 266 TEST_F('BackgroundTest', 'AriaLabel', function() { |
267 var mockFeedback = this.createMockFeedback(); | |
216 this.runWithLoadedTree('<a aria-label="foo" href="a">a</a>', | 268 this.runWithLoadedTree('<a aria-label="foo" href="a">a</a>', |
217 function(rootNode) { | 269 function(rootNode) { |
218 cvox.ChromeVox.tts.expectSpeech('foo'); | |
219 cvox.ChromeVox.tts.expectSpeech('Link', this.newCallback()); | |
220 rootNode.find({role: 'link'}).focus(); | 270 rootNode.find({role: 'link'}).focus(); |
271 mockFeedback.expectSpeech('foo') | |
272 .expectSpeech('Link') | |
273 .expectBraille('foo lnk'); | |
274 mockFeedback.replay(); | |
221 } | 275 } |
222 ); | 276 ); |
223 }); | 277 }); |
224 | 278 |
225 TEST_F('BackgroundTest', 'ShowContextMenu', function() { | 279 TEST_F('BackgroundTest', 'ShowContextMenu', function() { |
280 var mockFeedback = this.createMockFeedback(); | |
226 this.runWithLoadedTree('<a href="a">a</a>', | 281 this.runWithLoadedTree('<a href="a">a</a>', |
227 function(rootNode) { | 282 function(rootNode) { |
228 cvox.ChromeVox.tts.expectSpeech(' menu opened', this.newCallback( | 283 mockFeedback.expectSpeech(/menu opened/) |
229 function() { | 284 .call(function() { |
230 // When shown, the context menu pushes a new message loop so test | 285 // When shown, the context menu pushes a new message loop so test |
231 // messages sent to the browser do not get processed. Ensure we exit | 286 // messages sent to the browser do not get processed. Ensure we |
232 // the context menu here. | 287 // exit the context menu here. |
233 go.showContextMenu(); | 288 go.showContextMenu(); |
234 }) | 289 }); |
235 ); | 290 mockFeedback.replay(); |
236 | 291 |
237 var go = rootNode.find({ role: chrome.automation.RoleType.link }); | 292 var go = rootNode.find({ role: chrome.automation.RoleType.link }); |
238 this.listenOnce(go, 'focus', function(e) { | 293 this.listenOnce(go, 'focus', function(e) { |
239 this.doCmd('showContextMenu')(); | 294 this.doCmd('showContextMenu')(); |
240 }.bind(this), true); | 295 }.bind(this), true); |
241 go.focus(); | 296 go.focus(); |
242 }.bind(this)); | 297 }.bind(this)); |
243 }); | 298 }); |
299 | |
300 TEST_F('BackgroundTest', 'BrailleRouting', function() { | |
301 var mockFeedback = this.createMockFeedback(); | |
302 var route = function(position) { | |
303 assertTrue(global.backgroundObj.onBrailleKeyEvent( | |
304 {command: cvox.BrailleKeyCommand.ROUTING, | |
305 displayPosition: position}, | |
306 mockFeedback.lastMatchedBraille)); | |
307 }; | |
308 this.runWithLoadedTree( | |
309 function() {/*! | |
310 <p>start</p> | |
311 <button id="btn1">Click me</button> | |
312 <p>Some text</p> | |
313 <button id="btn2">Focus me</button> | |
314 <p>Some more text</p> | |
315 <input type="text" id ="text" value="Edit me"> | |
316 <script> | |
317 document.getElementById('btn1').addEventListener('click', function() { | |
318 document.getElementById('btn2').focus(); | |
319 }, false); | |
320 </script> | |
321 */}, | |
322 function(rootNode) { | |
323 var button1 = rootNode.find({role: chrome.automation.RoleType.button, | |
324 name: 'Click me'}); | |
325 var textField = rootNode.find( | |
326 {role: chrome.automation.RoleType.textField}); | |
327 mockFeedback.expectBraille('start') | |
328 .call(button1.focus.bind(button1)) | |
329 .expectBraille(/^Click me btn/) | |
330 .call(route.bind(null, 5)) | |
331 .expectBraille(/Focus me btn/) | |
332 .call(textField.focus.bind(textField)) | |
333 .expectBraille('Edit me ed', {startIndex: 0}) | |
334 .call(route.bind(null, 3)) | |
335 .expectBraille('Edit me ed', {startIndex: 3}) | |
336 .call(function() { | |
337 assertEquals(3, textField.textSelStart); | |
338 }); | |
339 mockFeedback.replay(); | |
340 }); | |
341 }); | |
OLD | NEW |