OLD | NEW |
| (Empty) |
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(['../../../chromevox/testing/chromevox_e2e_test_base.js']); | |
7 | |
8 /** | |
9 * Test fixture for cvox2.Background. | |
10 * @constructor | |
11 * @extends {ChromeVoxE2ETest} | |
12 */ | |
13 function BackgroundTest() {} | |
14 | |
15 BackgroundTest.prototype = { | |
16 __proto__: ChromeVoxE2ETest.prototype, | |
17 | |
18 /** @override */ | |
19 setUp: function() { | |
20 this.mockTts = new MockTts(); | |
21 cvox.ChromeVox.tts = this.mockTts; | |
22 } | |
23 }; | |
24 | |
25 /** | |
26 * Mock tts class. | |
27 * @constructor | |
28 * @extends {cvox.TtsInterface} | |
29 */ | |
30 var MockTts = function() { | |
31 }; | |
32 | |
33 MockTts.prototype = { | |
34 /** Tracks all spoken text. @type {!Array.<string>} */ | |
35 utterances: [], | |
36 | |
37 /** @override */ | |
38 speak: function(textString, queueMode, properties) { | |
39 this.utterances.push(textString); | |
40 }, | |
41 | |
42 /** | |
43 * Checks to see if a string was spoken. | |
44 * @param {string} textString The string to check. | |
45 * @return {boolean} True if the string was spoken (possibly as part of a | |
46 * larger utterance). | |
47 */ | |
48 checkIfSubstringWasSpoken: function(textString) { | |
49 return this.utterances.some(function(t) { | |
50 return t.indexOf(textString) != -1; | |
51 }); | |
52 } | |
53 }; | |
54 | |
55 /** Tests that ChromeVox classic is in this context. */ | |
56 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { | |
57 assertEquals('object', typeof(cvox)); | |
58 assertEquals('function', typeof(cvox.ChromeVoxBackground)); | |
59 }); | |
60 | |
61 /** Tests that ChromeVox next is in this context. */ | |
62 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { | |
63 assertEquals('object', typeof(cvox2)); | |
64 assertEquals('function', typeof(cvox2.Background)); | |
65 }); | |
66 | |
67 /** Tests that ChromeVox reads the desktop tree. */ | |
68 TEST_F('BackgroundTest', 'DesktopFocus', function() { | |
69 function findStatusTray(root) { | |
70 if (root.role == chrome.automation.RoleType.button && | |
71 root.attributes.name && | |
72 root.attributes.name.indexOf('Status tray') != -1) { | |
73 return root; | |
74 } | |
75 for (var i = 0; i < root.children().length; i++) { | |
76 var found = findStatusTray(root.children()[i]); | |
77 if (found) | |
78 return found; | |
79 } | |
80 return null; | |
81 } | |
82 | |
83 chrome.automation.getDesktop(function(root) { | |
84 var testButton = findStatusTray(root); | |
85 testButton.addEventListener(chrome.automation.EventType.focus, | |
86 function(e) { | |
87 var result = | |
88 cvox.ChromeVox.tts.checkIfSubstringWasSpoken('Status tray'); | |
89 testDone([result, '']); | |
90 }, | |
91 true); | |
92 testButton.focus(); | |
93 }); | |
94 }); | |
OLD | NEW |