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 goog
.provide('cvox.ChromeVoxTester');
7 goog
.require('cvox.AbstractEarcons');
8 goog
.require('cvox.BrailleInterface');
9 goog
.require('cvox.ChromeVoxEventWatcher');
10 goog
.require('cvox.ChromeVoxUserCommands');
11 goog
.require('cvox.LiveRegions');
12 goog
.require('cvox.NavigationManager');
13 goog
.require('cvox.NavigationShifter');
14 goog
.require('cvox.QueueMode');
15 goog
.require('cvox.TestHost');
16 goog
.require('cvox.TestMathJax');
17 goog
.require('cvox.TestMsgs');
18 goog
.require('cvox.TestTts');
22 * @fileoverview Testing framework for ChromeVox.
28 * Initializes cvox.ChromeVoxTester and sets up the mock ChromeVox
30 * @param {!Document} doc The DOM document to add event listeners to.
32 cvox
.ChromeVoxTester
.setUp = function(doc
) {
33 cvox
.ChromeVox
.mathJax
= new cvox
.TestMathJax();
35 cvox
.ChromeVox
.navigationManager
= new cvox
.NavigationManager();
36 cvox
.ChromeVoxTester
.testTts_
= new cvox
.TestTts();
37 cvox
.ChromeVox
.tts
= cvox
.ChromeVoxTester
.testTts_
;
39 // TODO(deboer): Factor this out as 'TestEarcons'
40 cvox
.ChromeVox
.earcons
= new cvox
.AbstractEarcons();
41 cvox
.ChromeVox
.earcons
.playEarcon = function(earcon
) { };
43 cvox
.ChromeVox
.braille
= new cvox
.BrailleInterface();
44 cvox
.ChromeVox
.braille
.write = function(params
) {};
46 cvox
.ChromeVox
.msgs
= new cvox
.TestMsgs();
48 cvox
.ChromeVox
.host
= new cvox
.TestHost();
50 // Init LiveRegions with a date of 0 so that the initial delay before
51 // things is spoken is skipped.
52 cvox
.LiveRegions
.init(new Date(0), cvox
.QueueMode
.QUEUE
, false);
54 cvox
.ChromeVoxEventWatcher
.init(doc
);
55 window
.console
.log('done setup');
59 * Tears down cvox.ChromeVoxTester.
60 * @param {!Document} doc The DOM document where event listeners were added.
62 cvox
.ChromeVoxTester
.tearDown = function(doc
) {
63 cvox
.ChromeVoxEventWatcher
.cleanup(doc
);
68 * Returns the cvox.TestTts created by the tester.
69 * @return {cvox.TestTts} The TestTts.
71 cvox
.ChromeVoxTester
.testTts = function() {
72 return cvox
.ChromeVoxTester
.testTts_
;
77 * All calls to tts.speak are saved in an array of utterances.
78 * Clear any utterances that were saved up to this poing.
80 cvox
.ChromeVoxTester
.clearUtterances = function() {
81 cvox
.ChromeVoxTester
.testTts_
.clearUtterances();
86 * Return a list of strings of what was spoken by tts.speak().
87 * @return {Array<string>} A list of all utterances spoken since
88 * initialization or the last call to clearUtterances.
90 cvox
.ChromeVoxTester
.getUtteranceList = function() {
91 return cvox
.ChromeVoxTester
.testTts_
.getUtteranceList();
95 * @type {Object<number>} Map from a navigation strategy name to the Navigation
96 * Manager strategy enum.
98 cvox
.ChromeVoxTester
.STRATEGY_MAP
= {
99 'lineardom': cvox
.NavigationShifter
.GRANULARITIES
.OBJECT
,
100 'smart': cvox
.NavigationShifter
.GRANULARITIES
.GROUP
,
101 'selection': cvox
.NavigationShifter
.GRANULARITIES
.SENTENCE
105 * Switches to a different navigation strategy.
106 * @param {string} strategy The desired navigation strategy.
108 cvox
.ChromeVoxTester
.setStrategy = function(strategy
) {
109 cvox
.ChromeVox
.navigationManager
.ensureNotSubnavigating();
110 cvox
.ChromeVox
.navigationManager
.setGranularity(
111 cvox
.ChromeVoxTester
.STRATEGY_MAP
[strategy
]);
115 * Starts reading the page from the current node.
117 cvox
.ChromeVoxTester
.readFromHere = function() {
118 cvox
.ChromeVox
.navigationManager
.startReading(
119 cvox
.QueueMode
.FLUSH
);
123 * Syncs to the given node in the test HTML
124 * @param {Node} node The node to sync to.
126 cvox
.ChromeVoxTester
.syncToNode = function(node
) {
127 cvox
.ChromeVox
.navigationManager
128 .updateSel(cvox
.CursorSelection
.fromNode(node
));
129 cvox
.ChromeVox
.navigationManager
.sync();
133 * Syncs to the first node in the test.
135 cvox
.ChromeVoxTester
.syncToFirstNode = function() {
136 cvox
.ChromeVox
.navigationManager
.updateSel(cvox
.CursorSelection
.fromBody());
137 cvox
.ChromeVox
.navigationManager
.sync();