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

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: Rebase Created 5 years, 4 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 2014 The Chromium Authors. All rights reserved.
dmazzoni 2015/08/24 19:05:07 2015?
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_endCallback) {
10 cvox.ChromeVox.tts.speak(text, 0, {endCallback: opt_endCallback});
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 }
27
28 MockFeedbackUnitTest.prototype = {
29 __proto__: ChromeVoxUnitTestBase.prototype,
30
31 setUp: function() {
32 cvox.ChromeVox = cvox.ChromeVox || {};
33 },
34
35 closureModuleDeps: [
36 'cvox.BrailleInterface',
37 'cvox.NavBraille',
38 'cvox.TtsInterface'
39 ]
40 };
41
42 TEST_F('MockFeedbackUnitTest', 'speechAndCallbacks', function() {
43 var afterThirdStringCalled = false;
44 var spruiousStringEndCallbackCalled = false;
45 var finishCalled = false;
46 var mock = new MockFeedback(function() {
47 assertFalse(finishCalled);
48 finishCalled = true;
49
50 assertTrue(afterThirdStringCalled);
51 assertTrue(spruiousStringEndCallbackCalled);
52 });
53 mock.install();
54 speak('First string');
55 speak('Second string');
56 mock.expectSpeech('First string', 'Second string')
57 .expectSpeech('Third string')
58 .call(function() {
59 assertFalse(afterThirdStringCalled);
60 afterThirdStringCalled = true;
61 speak('Spurious string', function() {
62 assertFalse(spruiousStringEndCallbackCalled);
63 spruiousStringEndCallbackCalled = true;
64 });
65 speak('Fourth string');
66 })
67 .expectSpeech('Fourth string')
68 .replay();
69 assertFalse(finishCalled);
70 speak('Third string');
71 assertTrue(finishCalled);
72 });
73
74 TEST_F('MockFeedbackUnitTest', 'SpeechAndBraille', function() {
75 var secondCallbackCalled = false;
76 var finishCalled = false;
77 var mock = new MockFeedback(function() { finishCalled = true; });
78 var firstExpectedNavBraille;
79 mock.install();
80 braille('Some braille');
81 speak('Some speech');
82 mock.call(function() {
83 assertEquals(null, mock.lastMatchedBraille);
84 firstExpectedNavBraille = braille('First expected braille');
85 speak('First expected speech');
86 braille('Some other braille');
87 })
88 .expectSpeech('First expected speech')
89 .expectBraille('First expected braille')
90 .call(function() {
91 secondCallbackCalled = true;
92 assertEquals(firstExpectedNavBraille, mock.lastMatchedBraille);
93 })
94 .replay();
95 assertTrue(secondCallbackCalled);
96 assertTrue(finishCalled);
97 });
98
99 TEST_F('MockFeedbackUnitTest', 'expectWithRegex', function() {
100 var done = false;
101 var mock = new MockFeedback();
102 mock.install();
103 mock.call(function() { braille('Item 1 of 14'); })
104 .expectBraille(/Item \d+ of \d+/)
105 .call(function() { done = true;})
106 .replay();
107 assertTrue(done);
108 });
109
110 TEST_F('MockFeedbackUnitTest', 'expectAfterGoThrows', function() {
dmazzoni 2015/08/24 19:05:07 Should this be expectAfterReplayThrows?
111 var mock = new MockFeedback();
112 mock.replay();
113 assertException('', function() {
114 mock.expectSpeech('hello');
115 }, 'Error');
116 });
117
118 TEST_F('MockFeedbackUnitTest', 'NoMatchDoesNotFinish', function() {
119 var firstCallbackCalled = false;
120 var mock = new MockFeedback(function() {
121 throw Error('Should not be called');
122 });
123 mock.install();
124 braille('Some string');
125 mock.call(function() {
126 braille('Some other string');
127 firstCallbackCalled = true;
128 })
129 .expectBraille('Unmatched string')
130 .call(function() {
131 throw Error('Should not be called');
132 })
133 .replay();
134 assertTrue(firstCallbackCalled);
135 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698