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
3 // found in the LICENSE file.
5 // Include test fixture.
6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']);
8 GEN_INCLUDE(['../../testing/mock_tts.js']);
11 * Test fixture for Background.
13 * @extends {ChromeVoxNextE2ETest}
15 function BackgroundTest() {
16 ChromeVoxNextE2ETest.call(this);
19 BackgroundTest.prototype = {
20 __proto__: ChromeVoxNextE2ETest.prototype,
24 this.mockTts = new MockTts();
25 cvox.ChromeVox.tts = this.mockTts;
29 * Create a function which perform the command |cmd|.
31 * @return {function() : void}
33 doCmd: function(cmd) {
35 global.backgroundObj.onGotCommand(cmd);
39 linksAndHeadingsDoc: function() {/*!
41 <a href='#a'>alpha</a>
45 <a href='foo'>delta</a>
47 <a href='#bar'>echo</a>
49 <p>end<span>of test</span></p>
52 formsDoc: function() {/*!
53 <select id="fruitSelect">
54 <option>apple</option>
55 <option>grape</option>
56 <option> banana</option>
61 /** Tests that ChromeVox classic is in this context. */
62 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() {
63 assertEquals('object', typeof(cvox));
64 assertEquals('function', typeof(cvox.ChromeVoxBackground));
67 /** Tests that ChromeVox next is in this context. */
68 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() {
69 assertEquals('function', typeof(Background));
72 /** Tests feedback once a page loads. */
73 TEST_F('BackgroundTest', 'MANUAL_InitialFeedback', function() {
74 cvox.ChromeVox.tts.expectSpeech('start', this.newCallback());
76 this.runWithTab(function() {/*!
82 /** Tests consistency of navigating forward and backward. */
83 TEST_F('BackgroundTest', 'MANUAL_ForwardBackwardNavigation', function() {
84 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() {
85 var doCmd = this.doCmd.bind(this);
87 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts);
89 expectAfter('alpha', doCmd('nextLink'));
90 expectAfter('beta', doCmd('nextLink'));
91 expectAfter('delta', doCmd('nextLink'));
92 expectAfter('beta', doCmd('previousLink'));
94 expectAfter('charlie', doCmd('nextHeading'));
95 expectAfter('foxtraut', doCmd('nextHeading'));
96 expectAfter('charlie', doCmd('previousHeading'));
98 expectAfter('delta', doCmd('nextElement'));
99 expectAfter('echo', doCmd('nextElement'));
100 expectAfter('foxtraut', doCmd('nextElement'));
101 expectAfter('end', doCmd('nextElement'));
102 expectAfter('foxtraut', doCmd('previousElement'));
103 expectAfter('end of test', doCmd('nextLine'));
105 expectAfter('start', doCmd('goToBeginning'));
106 expectAfter('of test', doCmd('goToEnd'));
108 cvox.ChromeVox.tts.finishExpectations(this.newCallback());
112 TEST_F('BackgroundTest', 'MANUAL_CaretNavigation', function() {
113 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() {
114 var doCmd = this.doCmd.bind(this);
116 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts);
118 expectAfter('t', doCmd('nextCharacter'), true);
119 expectAfter('a', doCmd('nextCharacter'), true);
120 expectAfter('Link alpha', doCmd('nextWord'), true);
121 expectAfter('Link beta', doCmd('nextWord'), true);
122 expectAfter('Heading charlie', doCmd('nextWord'), true);
123 expectAfter('Link delta', doCmd('nextLine'), true);
124 expectAfter('Link echo', doCmd('nextLine'), true);
125 expectAfter('Heading foxtraut', doCmd('nextLine'), true);
127 'end of test', doCmd('nextLine'), true);
128 expectAfter('n', doCmd('nextCharacter'), true);
129 expectAfter('e', doCmd('previousCharacter'), true);
130 expectAfter('Heading t', doCmd('previousCharacter'), true);
131 expectAfter('foxtraut', doCmd('previousWord'), true);
132 expectAfter('Link echo', doCmd('previousWord'), true);
133 expectAfter('Link a', doCmd('previousCharacter'), true);
134 expectAfter('t', doCmd('previousCharacter'), true);
135 expectAfter('Link echo', doCmd('nextWord'), true);
137 cvox.ChromeVox.tts.finishExpectations(this.newCallback());
141 // Flaky: http://crbug.com/451362
142 TEST_F('BackgroundTest', 'DISABLED_SelectSingleBasic', function() {
143 this.runWithLoadedTree(this.formsDoc, function() {
144 var sendDownToSelect =
145 this.sendKeyToElement.bind(this, undefined, 'Down', '#fruitSelect');
146 var expect = cvox.ChromeVox.tts.expectSpeech.bind(cvox.ChromeVox.tts);
147 expect('apple Menu item 1 of 3 ', sendDownToSelect, true);
148 expect('grape 2 of 3 ', sendDownToSelect, true);
149 expect('banana 3 of 3 ', function() {}, true);
150 cvox.ChromeVox.tts.finishExpectations(this.newCallback());
154 TEST_F('BackgroundTest', 'MANUAL_ContinuousRead', function() {
155 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() {
156 cvox.ChromeVox.tts.expectSpeech('start');
157 cvox.ChromeVox.tts.expectSpeechAfter('start', this.doCmd('continuousRead'));
158 cvox.ChromeVox.tts.expectSpeech('alpha');
159 cvox.ChromeVox.tts.expectSpeech('Link');
160 cvox.ChromeVox.tts.expectSpeech('beta');
161 cvox.ChromeVox.tts.expectSpeech('Link');
162 cvox.ChromeVox.tts.expectSpeech('Heading 1');
163 cvox.ChromeVox.tts.expectSpeech('charlie');
164 cvox.ChromeVox.tts.finishExpectations();
168 TEST_F('BackgroundTest', 'LiveRegionAddElement', function() {
169 this.runWithLoadedTree(
171 <h1>Document with live region</h1>
172 <p id="live" aria-live="polite"></p>
173 <button id="go">Go</button>
175 document.getElementById('go').addEventListener('click', function() {
176 document.getElementById('live').innerHTML = 'Hello, world';
181 var go = rootNode.find({ role: chrome.automation.RoleType.button });
183 cvox.ChromeVox.tts.expectSpeech('Hello, world', testDone);
184 cvox.ChromeVox.tts.finishExpectations();
188 TEST_F('BackgroundTest', 'LiveRegionRemoveElement', function() {
189 this.runWithLoadedTree(
191 <h1>Document with live region</h1>
192 <p id="live" aria-live="polite" aria-relevant="removals">Hello, world</p>
193 <button id="go">Go</button>
195 document.getElementById('go').addEventListener('click', function() {
196 document.getElementById('live').innerHTML = '';
201 var go = rootNode.find({ role: chrome.automation.RoleType.button });
203 cvox.ChromeVox.tts.expectSpeech('removed:');
204 cvox.ChromeVox.tts.expectSpeech('Hello, world', testDone);
205 cvox.ChromeVox.tts.finishExpectations();
209 TEST_F('BackgroundTest', 'ShowContextMenu', function() {
210 this.runWithLoadedTree('<a href="a">a</a>',
212 cvox.ChromeVox.tts.expectSpeech(' menu opened', testDone);
214 var go = rootNode.find({ role: chrome.automation.RoleType.link });
215 go.addEventListener('focus', function(e) {
216 this.doCmd('showContextMenu')();
222 TEST_F('BackgroundTest', 'InitialFocus', function() {
223 this.runWithLoadedTree('<a href="a">a</a>',
225 cvox.ChromeVox.tts.expectSpeech('a link', testDone);
231 TEST_F('BackgroundTest', 'AriaLabel', function() {
232 this.runWithLoadedTree('<a aria-label="foo" href="a">a</a>',
234 cvox.ChromeVox.tts.expectSpeech('foo link', testDone);