Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / chromevox / testing / tester.js
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 goog.provide('cvox.ChromeVoxTester');
6
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.QueueMode');
15 goog.require('cvox.TestHost');
16 goog.require('cvox.TestMathJax');
17 goog.require('cvox.TestMsgs');
18 goog.require('cvox.TestTts');
19
20
21 /**
22  * @fileoverview Testing framework for ChromeVox.
23  *
24  */
25
26
27 /**
28  * Initializes cvox.ChromeVoxTester and sets up the mock ChromeVox
29  * environment.
30  * @param {!Document} doc The DOM document to add event listeners to.
31  */
32 cvox.ChromeVoxTester.setUp = function(doc) {
33   cvox.ChromeVox.mathJax = new cvox.TestMathJax();
34
35   cvox.ChromeVox.navigationManager = new cvox.NavigationManager();
36   cvox.ChromeVoxTester.testTts_ = new cvox.TestTts();
37   cvox.ChromeVox.tts = cvox.ChromeVoxTester.testTts_;
38
39   // TODO(deboer): Factor this out as 'TestEarcons'
40   cvox.ChromeVox.earcons = new cvox.AbstractEarcons();
41   cvox.ChromeVox.earcons.playEarcon = function(earcon) { };
42
43   cvox.ChromeVox.braille = new cvox.AbstractBraille();
44   cvox.ChromeVox.braille.write = function(params) {};
45
46   cvox.ChromeVox.msgs = new cvox.TestMsgs();
47
48   cvox.ChromeVox.host = new cvox.TestHost();
49
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);
53
54   cvox.ChromeVoxEventWatcher.init(doc);
55   window.console.log('done setup');
56 };
57
58 /**
59  * Tears down cvox.ChromeVoxTester.
60  * @param {!Document} doc The DOM document where event listeners were added.
61  */
62 cvox.ChromeVoxTester.tearDown = function(doc) {
63   cvox.ChromeVoxEventWatcher.cleanup(doc);
64 };
65
66
67 /**
68  * Returns the cvox.TestTts created by the tester.
69  * @return {cvox.TestTts} The TestTts.
70  */
71 cvox.ChromeVoxTester.testTts = function() {
72   return cvox.ChromeVoxTester.testTts_;
73 };
74
75
76 /**
77  * All calls to tts.speak are saved in an array of utterances.
78  * Clear any utterances that were saved up to this poing.
79  */
80 cvox.ChromeVoxTester.clearUtterances = function() {
81   cvox.ChromeVoxTester.testTts_.clearUtterances();
82 };
83
84
85 /**
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.
89  */
90 cvox.ChromeVoxTester.getUtteranceList = function() {
91   return cvox.ChromeVoxTester.testTts_.getUtteranceList();
92 };
93
94 /**
95  * @type {Object.<string, number>} Map from a navigation strategy name
96  *     to the Navigation Manager strategy enum.
97  */
98 cvox.ChromeVoxTester.STRATEGY_MAP = {
99   'lineardom': cvox.NavigationShifter.GRANULARITIES.OBJECT,
100   'smart': cvox.NavigationShifter.GRANULARITIES.GROUP,
101   'selection': cvox.NavigationShifter.GRANULARITIES.SENTENCE
102 };
103
104 /**
105  * Switches to a different navigation strategy.
106  * @param {string} strategy The desired navigation strategy.
107  */
108 cvox.ChromeVoxTester.setStrategy = function(strategy) {
109   cvox.ChromeVox.navigationManager.ensureNotSubnavigating();
110   cvox.ChromeVox.navigationManager.setGranularity(
111          cvox.ChromeVoxTester.STRATEGY_MAP[strategy]);
112 };
113
114 /**
115  * Starts reading the page from the current node.
116  */
117 cvox.ChromeVoxTester.readFromHere = function() {
118   cvox.ChromeVox.navigationManager.startReading(
119          cvox.QueueMode.FLUSH);
120 };
121
122 /**
123  * Syncs to the given node in the test HTML
124  * @param {Node} node The node to sync to.
125  */
126 cvox.ChromeVoxTester.syncToNode = function(node) {
127   cvox.ChromeVox.navigationManager
128       .updateSel(cvox.CursorSelection.fromNode(node));
129   cvox.ChromeVox.navigationManager.sync();
130 };
131
132 /**
133  * Syncs to the first node in the test.
134  */
135 cvox.ChromeVoxTester.syncToFirstNode = function() {
136   cvox.ChromeVox.navigationManager.updateSel(cvox.CursorSelection.fromBody());
137   cvox.ChromeVox.navigationManager.sync();
138 };