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.AbstractBraille');
8 goog.require('cvox.AbstractEarcons');
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.TestHost');
15 goog.require('cvox.TestMathJax');
16 goog.require('cvox.TestMsgs');
17 goog.require('cvox.TestTts');
21 * @fileoverview Testing framework for ChromeVox.
27 * Initializes cvox.ChromeVoxTester and sets up the mock ChromeVox
29 * @param {!Document} doc The DOM document to add event listeners to.
31 cvox.ChromeVoxTester.setUp = function(doc) {
32 cvox.ChromeVox.mathJax = new cvox.TestMathJax();
34 cvox.ChromeVox.navigationManager = new cvox.NavigationManager();
35 cvox.ChromeVoxTester.testTts_ = new cvox.TestTts();
36 cvox.ChromeVox.tts = cvox.ChromeVoxTester.testTts_;
38 // TODO(deboer): Factor this out as 'TestEarcons'
39 cvox.ChromeVox.earcons = new cvox.AbstractEarcons();
40 cvox.ChromeVox.earcons.playEarcon = function(earcon) { };
42 cvox.ChromeVox.braille = new cvox.AbstractBraille();
43 cvox.ChromeVox.braille.write = function(params) {};
45 cvox.ChromeVox.msgs = new cvox.TestMsgs();
47 cvox.ChromeVox.host = new cvox.TestHost();
49 // Init LiveRegions with a date of 0 so that the initial delay before
50 // things is spoken is skipped.
51 cvox.LiveRegions.init(new Date(0), cvox.AbstractTts.QUEUE_MODE_QUEUE, false);
53 cvox.ChromeVoxEventWatcher.init(doc);
54 window.console.log('done setup');
58 * Tears down cvox.ChromeVoxTester.
59 * @param {!Document} doc The DOM document where event listeners were added.
61 cvox.ChromeVoxTester.tearDown = function(doc) {
62 cvox.ChromeVoxEventWatcher.cleanup(doc);
67 * Returns the cvox.TestTts created by the tester.
68 * @return {cvox.TestTts} The TestTts.
70 cvox.ChromeVoxTester.testTts = function() {
71 return cvox.ChromeVoxTester.testTts_;
76 * All calls to tts.speak are saved in an array of utterances.
77 * Clear any utterances that were saved up to this poing.
79 cvox.ChromeVoxTester.clearUtterances = function() {
80 cvox.ChromeVoxTester.testTts_.clearUtterances();
85 * Return a list of strings of what was spoken by tts.speak().
86 * @return {Array.<string>} A list of all utterances spoken since
87 * initialization or the last call to clearUtterances.
89 cvox.ChromeVoxTester.getUtteranceList = function() {
90 return cvox.ChromeVoxTester.testTts_.getUtteranceList();
94 * @type {Object.<string, number>} Map from a navigation strategy name
95 * to the Navigation Manager strategy enum.
97 cvox.ChromeVoxTester.STRATEGY_MAP = {
98 'lineardom': cvox.NavigationShifter.GRANULARITIES.OBJECT,
99 'smart': cvox.NavigationShifter.GRANULARITIES.GROUP,
100 'selection': cvox.NavigationShifter.GRANULARITIES.SENTENCE
104 * Switches to a different navigation strategy.
105 * @param {string} strategy The desired navigation strategy.
107 cvox.ChromeVoxTester.setStrategy = function(strategy) {
108 cvox.ChromeVox.navigationManager.ensureNotSubnavigating();
109 cvox.ChromeVox.navigationManager.setGranularity(
110 cvox.ChromeVoxTester.STRATEGY_MAP[strategy]);
114 * Starts reading the page from the current node.
116 cvox.ChromeVoxTester.readFromHere = function() {
117 cvox.ChromeVox.navigationManager.startReading(
118 cvox.AbstractTts.QUEUE_MODE_FLUSH);
122 * Syncs to the given node in the test HTML
123 * @param {Node} node The node to sync to.
125 cvox.ChromeVoxTester.syncToNode = function(node) {
126 cvox.ChromeVox.navigationManager
127 .updateSel(cvox.CursorSelection.fromNode(node));
128 cvox.ChromeVox.navigationManager.sync();
132 * Syncs to the first node in the test.
134 cvox.ChromeVoxTester.syncToFirstNode = function() {
135 cvox.ChromeVox.navigationManager.updateSel(cvox.CursorSelection.fromBody());
136 cvox.ChromeVox.navigationManager.sync();