Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / chromevox / cvox2 / background / background_test.extjs
blob2932d2a8f73f60881a18b09f6dc733097f7ebadf
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',
7              '../../testing/assert_additions.js']);
9 GEN_INCLUDE(['../../testing/mock_feedback.js']);
11 /**
12  * Test fixture for Background.
13  * @constructor
14  * @extends {ChromeVoxNextE2ETest}
15  */
16 function BackgroundTest() {
17   ChromeVoxNextE2ETest.call(this);
20 BackgroundTest.prototype = {
21   __proto__: ChromeVoxNextE2ETest.prototype,
23   /**
24    * @return {!MockFeedback}
25    */
26   createMockFeedback: function() {
27     var mockFeedback = new MockFeedback(this.newCallback(),
28                                         this.newCallback.bind(this));
29     mockFeedback.install();
30     return mockFeedback;
31   },
33   /**
34    * Create a function which perform the command |cmd|.
35    * @param {string} cmd
36    * @return {function() : void}
37    */
38   doCmd: function(cmd) {
39     return function() {
40       global.backgroundObj.onGotCommand(cmd);
41     };
42   },
44   linksAndHeadingsDoc: function() {/*!
45     <p>start</p>
46     <a href='#a'>alpha</a>
47     <a href='#b'>beta</a>
48     <p>
49       <h1>charlie</h1>
50       <a href='foo'>delta</a>
51     </p>
52     <a href='#bar'>echo</a>
53     <h2>foxtraut</h2>
54     <p>end<span>of test</span></p>
55   */},
57   formsDoc: function() {/*!
58     <select id="fruitSelect">
59       <option>apple</option>
60       <option>grape</option>
61       <option> banana</option>
62     </select>
63   */}
66 /** Tests that ChromeVox classic is in this context. */
67 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() {
68   assertEquals('object', typeof(cvox));
69   assertEquals('function', typeof(cvox.ChromeVoxBackground));
70 });
72 /** Tests that ChromeVox next is in this context. */
73 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() {
74   assertEquals('function', typeof(Background));
75 });
77 /** Tests consistency of navigating forward and backward. */
78 TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() {
79   var mockFeedback = this.createMockFeedback();
80   this.runWithLoadedTree(this.linksAndHeadingsDoc, function() {
81     var doCmd = this.doCmd.bind(this);
83     mockFeedback.expectSpeech('start').expectBraille('start');
85     mockFeedback.call(doCmd('nextLink'))
86         .expectSpeech('alpha', 'Link')
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');
107     mockFeedback.call(doCmd('nextElement'))
108         .expectSpeech('delta', 'Link')
109         .expectBraille('delta lnk');
110     mockFeedback.call(doCmd('nextElement'))
111         .expectSpeech('echo', 'Link')
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');
126     mockFeedback.call(doCmd('goToBeginning'))
127         .expectSpeech('start')
128         .expectBraille('start');
129     mockFeedback.call(doCmd('goToEnd'))
130         .expectSpeech('of test')
131         .expectBraille('of test');
133     mockFeedback.replay();
134   });
137 TEST_F('BackgroundTest', 'CaretNavigation', function() {
138   // TODO(plundblad): Add braille expectaions when crbug.com/523285 is fixed.
139   var mockFeedback = this.createMockFeedback();
140   this.runWithLoadedTree(this.linksAndHeadingsDoc, function() {
141     var doCmd = this.doCmd.bind(this);
143     mockFeedback.expectSpeech('start');
144     mockFeedback.call(doCmd('nextCharacter'))
145         .expectSpeech('t');
146     mockFeedback.call(doCmd('nextCharacter'))
147         .expectSpeech('a');
148     mockFeedback.call(doCmd('nextWord'))
149         .expectSpeech('Link', 'alpha');
150     mockFeedback.call(doCmd('nextWord'))
151         .expectSpeech('Link', 'beta');
152     mockFeedback.call(doCmd('nextWord'))
153         .expectSpeech('Heading 1', 'charlie');
154     mockFeedback.call(doCmd('nextLine'))
155         .expectSpeech('Link', 'delta');
156     mockFeedback.call(doCmd('nextLine'))
157         .expectSpeech('Link', 'echo');
158     mockFeedback.call(doCmd('nextLine'))
159         .expectSpeech('Heading 2', 'foxtraut');
160     mockFeedback.call(doCmd('nextLine'))
161         .expectSpeech('end', 'of test');
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();
179   });
182 TEST_F('BackgroundTest', 'SelectSingleBasic', function() {
183   var mockFeedback = this.createMockFeedback();
184   this.runWithLoadedTree(this.formsDoc, function() {
185     var sendDownToSelect =
186         this.sendKeyToElement.bind(this, undefined, 'Down', '#fruitSelect');
187     mockFeedback.expectSpeech('apple', 'Menu item', /1 of 3/)
188         .expectBraille('apple mnuitm 1/3')
189         .call(sendDownToSelect)
190         .expectSpeech('grape', /2 of 3/)
191         .expectBraille('grape mnuitm 2/3')
192         .call(sendDownToSelect)
193         .expectSpeech('banana', /3 of 3/)
194         .expectBraille('banana mnuitm 3/3');
195     mockFeedback.replay();
196   });
199 TEST_F('BackgroundTest', 'ContinuousRead', function() {
200   var mockFeedback = this.createMockFeedback();
201   this.runWithLoadedTree(this.linksAndHeadingsDoc, function() {
202     mockFeedback.expectSpeech('start')
203         .call(this.doCmd('continuousRead'))
204         .expectSpeech(
205             'start',
206             'alpha', 'Link',
207             'beta', 'Link',
208             'Heading 1', 'charlie');
209     mockFeedback.replay();
210   });
213 TEST_F('BackgroundTest', 'LiveRegionAddElement', function() {
214   var mockFeedback = this.createMockFeedback();
215   this.runWithLoadedTree(
216     function() {/*!
217       <h1>Document with live region</h1>
218       <p id="live" aria-live="polite"></p>
219       <button id="go">Go</button>
220       <script>
221         document.getElementById('go').addEventListener('click', function() {
222           document.getElementById('live').innerHTML = 'Hello, world';
223         }, false);
224       </script>
225     */},
226     function(rootNode) {
227       var go = rootNode.find({ role: chrome.automation.RoleType.button });
228       mockFeedback.call(go.doDefault.bind(go))
229           .expectSpeech('Hello, world');
230       mockFeedback.replay();
231     });
234 TEST_F('BackgroundTest', 'LiveRegionRemoveElement', function() {
235   var mockFeedback = this.createMockFeedback();
236   this.runWithLoadedTree(
237     function() {/*!
238       <h1>Document with live region</h1>
239       <p id="live" aria-live="polite" aria-relevant="removals">Hello, world</p>
240       <button id="go">Go</button>
241       <script>
242         document.getElementById('go').addEventListener('click', function() {
243           document.getElementById('live').innerHTML = '';
244         }, false);
245       </script>
246     */},
247     function(rootNode) {
248       var go = rootNode.find({ role: chrome.automation.RoleType.button });
249       go.doDefault();
250       mockFeedback.expectSpeech('removed:')
251           .expectSpeech('Hello, world');
252       mockFeedback.replay();
253     });
256 TEST_F('BackgroundTest', 'InitialFocus', function() {
257   var mockFeedback = this.createMockFeedback();
258   this.runWithLoadedTree('<a href="a">a</a>',
259     function(rootNode) {
260       mockFeedback.expectSpeech('a')
261           .expectSpeech('Link');
262       mockFeedback.replay();
263     });
266 TEST_F('BackgroundTest', 'AriaLabel', function() {
267   var mockFeedback = this.createMockFeedback();
268   this.runWithLoadedTree('<a aria-label="foo" href="a">a</a>',
269     function(rootNode) {
270       rootNode.find({role: 'link'}).focus();
271       mockFeedback.expectSpeech('foo')
272           .expectSpeech('Link')
273           .expectBraille('foo lnk');
274       mockFeedback.replay();
275     }
276   );
279 TEST_F('BackgroundTest', 'ShowContextMenu', function() {
280   var mockFeedback = this.createMockFeedback();
281   this.runWithLoadedTree('<a href="a">a</a>',
282     function(rootNode) {
283       mockFeedback.expectSpeech(/menu opened/)
284           .call(function() {
285             // When shown, the context menu pushes a new message loop so test
286             // messages sent to the browser do not get processed. Ensure we
287             // exit the context menu here.
288             go.showContextMenu();
289           });
290       mockFeedback.replay();
292       var go = rootNode.find({ role: chrome.automation.RoleType.link });
293       this.listenOnce(go, 'focus', function(e) {
294         this.doCmd('showContextMenu')();
295       }.bind(this), true);
296       go.focus();
297     }.bind(this));
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       });