OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Include test fixture. | 5 // Include test fixture. |
6 GEN_INCLUDE(['../../../chromevox/testing/chromevox_unittest_base.js']); | 6 GEN_INCLUDE(['../../../chromevox/testing/chromevox_e2e_test.js']); |
7 | 7 |
8 /** | 8 /** |
9 * Test fixture for cvox2.Background. | 9 * Test fixture for cvox2.Background. |
10 * @constructor | 10 * @constructor |
11 * @extends {ChromeVoxUnitTestBase} | 11 * @extends {ChromeVoxE2ETest} |
12 */ | 12 */ |
13 function BackgroundTest() {} | 13 function BackgroundTest() {} |
14 | 14 |
15 BackgroundTest.prototype = { | 15 BackgroundTest.prototype = { |
16 __proto__: ChromeVoxUnitTestBase.prototype, | 16 __proto__: ChromeVoxE2ETest.prototype, |
17 | 17 |
18 /** @override */ | 18 /** @override */ |
19 browsePreload: null, | 19 setUp: function() { |
20 | 20 this.mockTts = new MockTts(); |
21 /** @override */ | 21 cvox.ChromeVox.tts = this.mockTts; |
22 testGenCppIncludes: function() { | |
23 GEN_BLOCK(function() {/*! | |
24 #include "ash/accessibility_delegate.h" | |
25 #include "base/bind.h" | |
26 #include "base/callback.h" | |
27 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
28 #include "chrome/common/extensions/extension_constants.h" | |
29 */}); | |
30 }, | |
31 | |
32 /** @override */ | |
33 testGenPreamble: function() { | |
34 GEN_BLOCK(function() {/*! | |
35 if (chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) { | |
36 chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(false, | |
37 ash::A11Y_NOTIFICATION_NONE); | |
38 } | |
39 | |
40 base::Closure load_cb = | |
41 base::Bind(&chromeos::AccessibilityManager::EnableSpokenFeedback, | |
42 base::Unretained(chromeos::AccessibilityManager::Get()), | |
43 true, | |
44 ash::A11Y_NOTIFICATION_NONE); | |
45 WaitForExtension(extension_misc::kChromeVoxExtensionId, load_cb); | |
46 */}); | |
47 } | 22 } |
48 }; | 23 }; |
49 | 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 checkIfTextWasSpoken: function(textString) { | |
49 return this.utterances.some(function(t) { | |
50 return t.indexOf(textString) != -1; | |
51 }); | |
52 } | |
53 }; | |
54 | |
55 function SYNC_TEST_F(testFixture, testName, testFunction) { | |
Peter Lundblad
2014/06/19 20:54:10
nit: jsdoc. Also, move to the base class right aw
David Tseng
2014/06/19 22:30:37
Done.
| |
56 var wrappedTestFunction = function() { | |
57 testFunction(); | |
58 testDone([true, '']); | |
59 }; | |
60 TEST_F(testFixture, testName, wrappedTestFunction); | |
61 } | |
62 | |
50 /** Tests ChromeVox classic is in this context. */ | 63 /** Tests ChromeVox classic is in this context. */ |
51 TEST_F('BackgroundTest', 'ClassicNamespaces', function() { | 64 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { |
52 assertEquals('object', typeof(cvox)); | 65 assertEquals('object', typeof(cvox)); |
53 assertEquals('function', typeof(cvox.ChromeVoxBackground)); | 66 assertEquals('function', typeof(cvox.ChromeVoxBackground)); |
54 }); | 67 }); |
68 | |
69 /** Tests ChromeVox next is in this context. */ | |
Peter Lundblad
2014/06/19 20:54:10
nit: Tests that (I find it easier to read that way
David Tseng
2014/06/19 22:30:37
Done. (and below).
| |
70 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { | |
71 assertEquals('object', typeof(cvox2)); | |
72 assertEquals('function', typeof(cvox2.Background)); | |
73 }); | |
74 | |
75 /** Tests that ChromeVox reads the desktop tree. */ | |
76 TEST_F('BackgroundTest', 'DesktopFocus', function() { | |
77 function findStatusTray(root) { | |
78 if (root.role == chrome.automation.RoleType.button && | |
79 root.attributes.name == 'Status tray') { | |
80 return root; | |
81 } | |
82 for (var i = 0; i < root.children().length; i++) { | |
83 var found = findStatusTray(root.children()[i]); | |
84 if (found) | |
85 return found; | |
86 } | |
87 return null; | |
88 } | |
89 | |
90 chrome.automation.getDesktop(function(root) { | |
91 var testButton = findStatusTray(root); | |
92 testButton.addEventListener(chrome.automation.EventType.focus, | |
93 function(e) { | |
94 var result = | |
95 cvox.ChromeVox.tts.checkIfTextWasSpoken('Status tray button'); | |
96 testDone([result, '']); | |
97 }, | |
98 true); | |
99 testButton.focus(); | |
100 }); | |
101 }); | |
OLD | NEW |