Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / chromevox / cvox2 / background / background_test.extjs
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.
4
5 // Include test fixture.
6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']);
7
8 GEN_INCLUDE(['../../testing/mock_tts.js']);
9
10 /**
11  * Test fixture for Background.
12  * @constructor
13  * @extends {ChromeVoxNextE2ETest}
14  */
15 function BackgroundTest() {}
16
17 BackgroundTest.prototype = {
18   __proto__: ChromeVoxNextE2ETest.prototype,
19
20   /** @override */
21   setUp: function() {
22     this.mockTts = new MockTts();
23     cvox.ChromeVox.tts = this.mockTts;
24   },
25
26   /**
27    * Create a function which perform the command |cmd|.
28    * @param {string} cmd
29    * @return {function() : void}
30    */
31   doCmd: function(cmd) {
32     return function() {
33       global.backgroundObj.onGotCommand(cmd);
34     };
35   },
36
37   linksAndHeadingsDoc: function() {/*!
38     <p>start</p>
39     <a href='#a'>alpha</a>
40     <a href='#b'>beta</a>
41     <p>
42       <h1>charlie</h1>
43       <a href='foo'>delta</a>
44     </p>
45     <a href='#bar'>echo</a>
46     <h2>foxtraut</h2>
47     <p>end<span>of test</span></p>
48   */}
49 };
50
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));
55 });
56
57 /** Tests that ChromeVox next is in this context. */
58 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() {
59   assertEquals('function', typeof(Background));
60 });
61
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) {
68       return root;
69     }
70     for (var i = 0; i < root.children().length; i++) {
71       var found = findStatusTray(root.children()[i]);
72       if (found)
73         return found;
74     }
75     return null;
76   }
77
78   chrome.automation.getDesktop(function(root) {
79     var testButton = findStatusTray(root);
80     cvox.ChromeVox.tts.expectSpeech('Status tray', testDone);
81     testButton.focus();
82   });
83 });
84
85 /** Tests feedback once a page loads. */
86 TEST_F('BackgroundTest', 'InitialFeedback', function() {
87   this.runWithDocument(function() {/*!
88     <p>start
89     <p>end
90   */},
91   function() {
92     cvox.ChromeVox.tts.expectSpeech('start', function() {
93       global.backgroundObj.onGotCommand('nextLine');
94     });
95     cvox.ChromeVox.tts.expectSpeech('end', testDone);
96   }.bind(this));
97 });
98
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);
103       var expectAfter =
104           cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts);
105
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'));
111
112       expectAfter('charlie', doCmd('nextHeading'));
113       expectAfter('foxtraut', doCmd('nextHeading'));
114       expectAfter('charlie', doCmd('previousHeading'));
115
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'));
121
122       // TODO(dtseng): cleanup these utterances.
123       expectAfter(', end, paragraph, of test, paragraph', doCmd('nextLine'));
124
125       expectAfter('start', doCmd('goToBeginning'));
126       expectAfter('of test', doCmd('goToEnd'));
127
128       cvox.ChromeVox.tts.finishExpectations();
129     }.bind(this)
130   );
131 });
132
133 TEST_F('BackgroundTest', 'CaretNavigation', function() {
134   this.runWithDocument(this.linksAndHeadingsDoc, function() {
135       var doCmd = this.doCmd.bind(this);
136       var expectAfter =
137           cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts);
138
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);
148       expectAfter(
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);
158
159       cvox.ChromeVox.tts.finishExpectations();
160   }.bind(this));
161 });