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() {}
17 BackgroundTest.prototype = {
18 __proto__: ChromeVoxNextE2ETest.prototype,
22 this.mockTts = new MockTts();
23 cvox.ChromeVox.tts = this.mockTts;
27 * Create a function which perform the command |cmd|.
29 * @return {function() : void}
31 doCmd: function(cmd) {
33 global.backgroundObj.onGotCommand(cmd);
37 linksAndHeadingsDoc: function() {/*!
39 <a href='#a'>alpha</a>
43 <a href='foo'>delta</a>
45 <a href='#bar'>echo</a>
47 <p>end<span>of test</span></p>
51 /** Tests that ChromeVox classic is in this context. */
52 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() {
53 assertEquals('object', typeof(cvox));
54 assertEquals('function', typeof(cvox.ChromeVoxBackground));
57 /** Tests that ChromeVox next is in this context. */
58 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() {
59 assertEquals('function', typeof(Background));
62 /** Tests that ChromeVox reads the desktop tree. */
63 TEST_F('BackgroundTest', 'DesktopFocus', function() {
64 function findStatusTray(root) {
65 if (root.role == chrome.automation.RoleType.button &&
66 root.attributes.name &&
67 root.attributes.name.indexOf('Status tray') != -1) {
70 for (var i = 0; i < root.children().length; i++) {
71 var found = findStatusTray(root.children()[i]);
78 chrome.automation.getDesktop(function(root) {
79 var testButton = findStatusTray(root);
80 cvox.ChromeVox.tts.expectSpeech('Status tray', testDone);
85 /** Tests feedback once a page loads. */
86 TEST_F('BackgroundTest', 'InitialFeedback', function() {
87 this.runWithDocument(function() {/*!
92 cvox.ChromeVox.tts.expectSpeech('start', function() {
93 global.backgroundObj.onGotCommand('nextLine');
95 cvox.ChromeVox.tts.expectSpeech('end', testDone);
99 /** Tests consistency of navigating forward and backward. */
100 TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() {
101 this.runWithDocument(this.linksAndHeadingsDoc, function() {
102 var doCmd = this.doCmd.bind(this);
104 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts);
106 cvox.ChromeVox.tts.expectSpeech('start');
107 expectAfter('alpha', doCmd('nextLink'));
108 expectAfter('beta', doCmd('nextLink'));
109 expectAfter('delta', doCmd('nextLink'));
110 expectAfter('beta', doCmd('previousLink'));
112 expectAfter('charlie', doCmd('nextHeading'));
113 expectAfter('foxtraut', doCmd('nextHeading'));
114 expectAfter('charlie', doCmd('previousHeading'));
116 expectAfter('delta', doCmd('nextElement'));
117 expectAfter('echo', doCmd('nextElement'));
118 expectAfter('foxtraut', doCmd('nextElement'));
119 expectAfter('end', doCmd('nextElement'));
120 expectAfter('foxtraut', doCmd('previousElement'));
122 // TODO(dtseng): cleanup these utterances.
123 expectAfter(', end, paragraph, of test, paragraph', doCmd('nextLine'));
125 expectAfter('start', doCmd('goToBeginning'));
126 expectAfter('of test', doCmd('goToEnd'));
128 cvox.ChromeVox.tts.finishExpectations();
133 TEST_F('BackgroundTest', 'CaretNavigation', function() {
134 this.runWithDocument(this.linksAndHeadingsDoc, function() {
135 var doCmd = this.doCmd.bind(this);
137 cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts);
139 cvox.ChromeVox.tts.expectSpeech('start');
140 expectAfter('t', doCmd('nextCharacter'), true);
141 expectAfter('a', doCmd('nextCharacter'), true);
142 expectAfter('alpha', doCmd('nextWord'), true);
143 expectAfter('beta', doCmd('nextWord'), true);
144 expectAfter('charlie', doCmd('nextWord'), true);
145 expectAfter('delta', doCmd('nextLine'), true);
146 expectAfter('echo', doCmd('nextLine'), true);
147 expectAfter('foxtraut', doCmd('nextLine'), true);
149 ', end, paragraph, of test, paragraph', doCmd('nextLine'), true);
150 expectAfter('n', doCmd('nextCharacter'), true);
151 expectAfter('e', doCmd('previousCharacter'), true);
152 expectAfter('t', doCmd('previousCharacter'), true);
153 expectAfter('foxtraut', doCmd('previousWord'), true);
154 expectAfter('echo', doCmd('previousWord'), true);
155 expectAfter('a', doCmd('previousCharacter'), true);
156 expectAfter('t', doCmd('previousCharacter'), true);
157 expectAfter('echo', doCmd('nextWord'), true);
159 cvox.ChromeVox.tts.finishExpectations();