summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/chromeos/chromevox/testing/tester.js
blob: bab5c6a1559b2b1b3d563ff4896a8bb45d13feaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

goog.provide('cvox.ChromeVoxTester');

goog.require('TestMsgs');
goog.require('cvox.AbstractEarcons');
goog.require('cvox.BrailleInterface');
goog.require('cvox.ChromeVoxEventWatcher');
goog.require('cvox.ChromeVoxUserCommands');
goog.require('cvox.LiveRegions');
goog.require('cvox.NavigationManager');
goog.require('cvox.NavigationShifter');
goog.require('cvox.QueueMode');
goog.require('cvox.TestHost');
goog.require('cvox.TestMathJax');
goog.require('cvox.TestTts');


/**
 * @fileoverview Testing framework for ChromeVox.
 *
 */


/**
 * Initializes cvox.ChromeVoxTester and sets up the mock ChromeVox
 * environment.
 * @param {!Document} doc The DOM document to add event listeners to.
 */
cvox.ChromeVoxTester.setUp = function(doc) {
  cvox.ChromeVox.mathJax = new cvox.TestMathJax();

  cvox.ChromeVox.navigationManager = new cvox.NavigationManager();
  cvox.ChromeVoxTester.testTts_ = new cvox.TestTts();
  cvox.ChromeVox.tts = cvox.ChromeVoxTester.testTts_;

  // TODO(deboer): Factor this out as 'TestEarcons'
  cvox.ChromeVox.earcons = new cvox.AbstractEarcons();
  cvox.ChromeVox.earcons.playEarcon = function(earcon) { };

  cvox.ChromeVox.braille = new cvox.BrailleInterface();
  cvox.ChromeVox.braille.write = function(params) {};

  Msgs = TestMsgs;

  cvox.ChromeVox.host = new cvox.TestHost();

  // Init LiveRegions with a date of 0 so that the initial delay before
  // things is spoken is skipped.
  cvox.LiveRegions.init(new Date(0), cvox.QueueMode.QUEUE, false);

  cvox.ChromeVoxEventWatcher.init(doc);
  window.console.log('done setup');
};

/**
 * Tears down cvox.ChromeVoxTester.
 * @param {!Document} doc The DOM document where event listeners were added.
 */
cvox.ChromeVoxTester.tearDown = function(doc) {
  cvox.ChromeVoxEventWatcher.cleanup(doc);
};


/**
 * Returns the cvox.TestTts created by the tester.
 * @return {cvox.TestTts} The TestTts.
 */
cvox.ChromeVoxTester.testTts = function() {
  return cvox.ChromeVoxTester.testTts_;
};


/**
 * All calls to tts.speak are saved in an array of utterances.
 * Clear any utterances that were saved up to this poing.
 */
cvox.ChromeVoxTester.clearUtterances = function() {
  cvox.ChromeVoxTester.testTts_.clearUtterances();
};


/**
 * Return a list of strings of what was spoken by tts.speak().
 * @return {Array<string>} A list of all utterances spoken since
 *     initialization or the last call to clearUtterances.
 */
cvox.ChromeVoxTester.getUtteranceList = function() {
  return cvox.ChromeVoxTester.testTts_.getUtteranceList();
};

/**
 * @type {Object<number>} Map from a navigation strategy name to the Navigation
 *     Manager strategy enum.
 */
cvox.ChromeVoxTester.STRATEGY_MAP = {
  'lineardom': cvox.NavigationShifter.GRANULARITIES.OBJECT,
  'smart': cvox.NavigationShifter.GRANULARITIES.GROUP,
  'selection': cvox.NavigationShifter.GRANULARITIES.SENTENCE
};

/**
 * Switches to a different navigation strategy.
 * @param {string} strategy The desired navigation strategy.
 */
cvox.ChromeVoxTester.setStrategy = function(strategy) {
  cvox.ChromeVox.navigationManager.ensureNotSubnavigating();
  cvox.ChromeVox.navigationManager.setGranularity(
         cvox.ChromeVoxTester.STRATEGY_MAP[strategy]);
};

/**
 * Starts reading the page from the current node.
 */
cvox.ChromeVoxTester.readFromHere = function() {
  cvox.ChromeVox.navigationManager.startReading(
         cvox.QueueMode.FLUSH);
};

/**
 * Syncs to the given node in the test HTML
 * @param {Node} node The node to sync to.
 */
cvox.ChromeVoxTester.syncToNode = function(node) {
  cvox.ChromeVox.navigationManager
      .updateSel(cvox.CursorSelection.fromNode(node));
  cvox.ChromeVox.navigationManager.sync();
};

/**
 * Syncs to the first node in the test.
 */
cvox.ChromeVoxTester.syncToFirstNode = function() {
  cvox.ChromeVox.navigationManager.updateSel(cvox.CursorSelection.fromBody());
  cvox.ChromeVox.navigationManager.sync();
};