Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/testing/mock_feedback_test.unitjs

Issue 1302763002: Add tests for braille commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@js2gtesterr
Patch Set: Document gn template args, rename extra_gen_files to gen_include_files Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 // Include test fixture.
6 GEN_INCLUDE(['chromevox_unittest_base.js',
7 'mock_feedback.js']);
8
9 function speak(text, opt_properties) {
10 cvox.ChromeVox.tts.speak(text, 0, opt_properties);
11 }
12
13 function braille(text) {
14 var navBraille = cvox.NavBraille.fromText(text);
15 cvox.ChromeVox.braille.write(navBraille);
16 return navBraille;
17 }
18
19 /**
20 * Test fixture.
21 * @constructor
22 * @extends {ChromeVoxUnitTestBase}
23 */
24 function MockFeedbackUnitTest() {
25 ChromeVoxUnitTestBase.call(this);
26 this.expectedCalls = [];
27 }
28
29 MockFeedbackUnitTest.prototype = {
30 __proto__: ChromeVoxUnitTestBase.prototype,
31
32 setUp: function() {
33 cvox.ChromeVox = cvox.ChromeVox || {};
34 },
35
36 closureModuleDeps: [
37 'cvox.BrailleInterface',
38 'cvox.NavBraille',
39 'cvox.TtsInterface'
40 ]
41 };
42
43 TEST_F('MockFeedbackUnitTest', 'speechAndCallbacks', function() {
44 var afterThirdStringCalled = false;
45 var spruiousStringEndCallbackCalled = false;
46 var finishCalled = false;
47 var mock = new MockFeedback(function() {
48 assertFalse(finishCalled);
49 finishCalled = true;
50
51 assertTrue(afterThirdStringCalled);
52 assertTrue(spruiousStringEndCallbackCalled);
53 });
54 mock.install();
55 speak('First string');
56 speak('Second string');
57 mock.expectSpeech('First string', 'Second string')
58 .expectSpeech('Third string')
59 .call(function() {
60 assertFalse(afterThirdStringCalled);
61 afterThirdStringCalled = true;
62 speak('Spurious string', {endCallback: function() {
63 assertFalse(spruiousStringEndCallbackCalled);
64 spruiousStringEndCallbackCalled = true;
65 }});
66 speak('Fourth string');
67 })
68 .expectSpeech('Fourth string')
69 .replay();
70 assertFalse(finishCalled);
71 speak('Third string');
72 assertTrue(finishCalled);
73 });
74
75 TEST_F('MockFeedbackUnitTest', 'startAndEndCallbacks', function() {
76 var onlyStartCallbackCalled = false;
77 var onlyEndCallbackCalled = false;
78 var bothCallbacksStartCalled = false;
79 var bothCallbacksEndCalled = false;
80 var mock = new MockFeedback();
81 mock.install();
82 speak('No callbacks', {});
83 speak('Only start callback', {startCallback: function() {
84 assertFalse(onlyStartCallbackCalled);
85 onlyStartCallbackCalled = true;
86 assertFalse(onlyEndCallbackCalled);
87 }});
88 speak('Only end callback', {endCallback: function() {
89 assertTrue(onlyStartCallbackCalled);
90 assertFalse(onlyEndCallbackCalled);
91 onlyEndCallbackCalled = true;
92 assertFalse(bothCallbacksStartCalled);
93 }});
94 speak('Both callbacks',
95 {startCallback: function() {
96 assertTrue(onlyEndCallbackCalled);
97 assertFalse(bothCallbacksStartCalled);
98 bothCallbacksStartCalled = true;
99 assertFalse(bothCallbacksEndCalled);
100 },
101 endCallback: function() {
102 assertTrue(bothCallbacksStartCalled);
103 assertFalse(bothCallbacksEndCalled);
104 bothCallbacksEndCalled = true;
105 }});
106 mock.expectSpeech('Both callbacks');
107 mock.replay();
108 assertTrue(bothCallbacksEndCalled);
109 });
110
111 TEST_F('MockFeedbackUnitTest', 'SpeechAndBraille', function() {
112 var secondCallbackCalled = false;
113 var finishCalled = false;
114 var mock = new MockFeedback(function() { finishCalled = true; });
115 var firstExpectedNavBraille;
116 mock.install();
117 braille('Some braille');
118 speak('Some speech');
119 mock.call(function() {
120 assertEquals(null, mock.lastMatchedBraille);
121 firstExpectedNavBraille = braille('First expected braille');
122 speak('First expected speech');
123 braille('Some other braille');
124 })
125 .expectSpeech('First expected speech')
126 .expectBraille('First expected braille')
127 .call(function() {
128 secondCallbackCalled = true;
129 assertEquals(firstExpectedNavBraille, mock.lastMatchedBraille);
130 })
131 .replay();
132 assertTrue(secondCallbackCalled);
133 assertTrue(finishCalled);
134 });
135
136 TEST_F('MockFeedbackUnitTest', 'expectWithRegex', function() {
137 var done = false;
138 var mock = new MockFeedback();
139 mock.install();
140 mock.call(function() { braille('Item 1 of 14'); })
141 .expectBraille(/Item \d+ of \d+/)
142 .call(function() { done = true;})
143 .replay();
144 assertTrue(done);
145 });
146
147 TEST_F('MockFeedbackUnitTest', 'expectAfterReplayThrows', function() {
148 var mock = new MockFeedback();
149 mock.replay();
150 assertException('', function() {
151 mock.expectSpeech('hello');
152 }, 'Error');
153 });
154
155 TEST_F('MockFeedbackUnitTest', 'NoMatchDoesNotFinish', function() {
156 var firstCallbackCalled = false;
157 var mock = new MockFeedback(function() {
158 throw Error('Should not be called');
159 });
160 mock.install();
161 braille('Some string');
162 mock.call(function() {
163 braille('Some other string');
164 firstCallbackCalled = true;
165 })
166 .expectBraille('Unmatched string')
167 .call(function() {
168 throw Error('Should not be called');
169 })
170 .replay();
171 assertTrue(firstCallbackCalled);
172 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698