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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/testing/mock_feedback_test.unitjs
diff --git a/chrome/browser/resources/chromeos/chromevox/testing/mock_feedback_test.unitjs b/chrome/browser/resources/chromeos/chromevox/testing/mock_feedback_test.unitjs
new file mode 100644
index 0000000000000000000000000000000000000000..77c82201bb02e715d35e028f4b55e43032a56c1f
--- /dev/null
+++ b/chrome/browser/resources/chromeos/chromevox/testing/mock_feedback_test.unitjs
@@ -0,0 +1,172 @@
+// Copyright 2015 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.
+
+// Include test fixture.
+GEN_INCLUDE(['chromevox_unittest_base.js',
+ 'mock_feedback.js']);
+
+function speak(text, opt_properties) {
+ cvox.ChromeVox.tts.speak(text, 0, opt_properties);
+}
+
+function braille(text) {
+ var navBraille = cvox.NavBraille.fromText(text);
+ cvox.ChromeVox.braille.write(navBraille);
+ return navBraille;
+}
+
+/**
+ * Test fixture.
+ * @constructor
+ * @extends {ChromeVoxUnitTestBase}
+ */
+function MockFeedbackUnitTest() {
+ ChromeVoxUnitTestBase.call(this);
+ this.expectedCalls = [];
+}
+
+MockFeedbackUnitTest.prototype = {
+ __proto__: ChromeVoxUnitTestBase.prototype,
+
+ setUp: function() {
+ cvox.ChromeVox = cvox.ChromeVox || {};
+ },
+
+ closureModuleDeps: [
+ 'cvox.BrailleInterface',
+ 'cvox.NavBraille',
+ 'cvox.TtsInterface'
+ ]
+};
+
+TEST_F('MockFeedbackUnitTest', 'speechAndCallbacks', function() {
+ var afterThirdStringCalled = false;
+ var spruiousStringEndCallbackCalled = false;
+ var finishCalled = false;
+ var mock = new MockFeedback(function() {
+ assertFalse(finishCalled);
+ finishCalled = true;
+
+ assertTrue(afterThirdStringCalled);
+ assertTrue(spruiousStringEndCallbackCalled);
+ });
+ mock.install();
+ speak('First string');
+ speak('Second string');
+ mock.expectSpeech('First string', 'Second string')
+ .expectSpeech('Third string')
+ .call(function() {
+ assertFalse(afterThirdStringCalled);
+ afterThirdStringCalled = true;
+ speak('Spurious string', {endCallback: function() {
+ assertFalse(spruiousStringEndCallbackCalled);
+ spruiousStringEndCallbackCalled = true;
+ }});
+ speak('Fourth string');
+ })
+ .expectSpeech('Fourth string')
+ .replay();
+ assertFalse(finishCalled);
+ speak('Third string');
+ assertTrue(finishCalled);
+});
+
+TEST_F('MockFeedbackUnitTest', 'startAndEndCallbacks', function() {
+ var onlyStartCallbackCalled = false;
+ var onlyEndCallbackCalled = false;
+ var bothCallbacksStartCalled = false;
+ var bothCallbacksEndCalled = false;
+ var mock = new MockFeedback();
+ mock.install();
+ speak('No callbacks', {});
+ speak('Only start callback', {startCallback: function() {
+ assertFalse(onlyStartCallbackCalled);
+ onlyStartCallbackCalled = true;
+ assertFalse(onlyEndCallbackCalled);
+ }});
+ speak('Only end callback', {endCallback: function() {
+ assertTrue(onlyStartCallbackCalled);
+ assertFalse(onlyEndCallbackCalled);
+ onlyEndCallbackCalled = true;
+ assertFalse(bothCallbacksStartCalled);
+ }});
+ speak('Both callbacks',
+ {startCallback: function() {
+ assertTrue(onlyEndCallbackCalled);
+ assertFalse(bothCallbacksStartCalled);
+ bothCallbacksStartCalled = true;
+ assertFalse(bothCallbacksEndCalled);
+ },
+ endCallback: function() {
+ assertTrue(bothCallbacksStartCalled);
+ assertFalse(bothCallbacksEndCalled);
+ bothCallbacksEndCalled = true;
+ }});
+ mock.expectSpeech('Both callbacks');
+ mock.replay();
+ assertTrue(bothCallbacksEndCalled);
+});
+
+TEST_F('MockFeedbackUnitTest', 'SpeechAndBraille', function() {
+ var secondCallbackCalled = false;
+ var finishCalled = false;
+ var mock = new MockFeedback(function() { finishCalled = true; });
+ var firstExpectedNavBraille;
+ mock.install();
+ braille('Some braille');
+ speak('Some speech');
+ mock.call(function() {
+ assertEquals(null, mock.lastMatchedBraille);
+ firstExpectedNavBraille = braille('First expected braille');
+ speak('First expected speech');
+ braille('Some other braille');
+ })
+ .expectSpeech('First expected speech')
+ .expectBraille('First expected braille')
+ .call(function() {
+ secondCallbackCalled = true;
+ assertEquals(firstExpectedNavBraille, mock.lastMatchedBraille);
+ })
+ .replay();
+ assertTrue(secondCallbackCalled);
+ assertTrue(finishCalled);
+});
+
+TEST_F('MockFeedbackUnitTest', 'expectWithRegex', function() {
+ var done = false;
+ var mock = new MockFeedback();
+ mock.install();
+ mock.call(function() { braille('Item 1 of 14'); })
+ .expectBraille(/Item \d+ of \d+/)
+ .call(function() { done = true;})
+ .replay();
+ assertTrue(done);
+});
+
+TEST_F('MockFeedbackUnitTest', 'expectAfterReplayThrows', function() {
+ var mock = new MockFeedback();
+ mock.replay();
+ assertException('', function() {
+ mock.expectSpeech('hello');
+ }, 'Error');
+});
+
+TEST_F('MockFeedbackUnitTest', 'NoMatchDoesNotFinish', function() {
+ var firstCallbackCalled = false;
+ var mock = new MockFeedback(function() {
+ throw Error('Should not be called');
+ });
+ mock.install();
+ braille('Some string');
+ mock.call(function() {
+ braille('Some other string');
+ firstCallbackCalled = true;
+ })
+ .expectBraille('Unmatched string')
+ .call(function() {
+ throw Error('Should not be called');
+ })
+ .replay();
+ assertTrue(firstCallbackCalled);
+});

Powered by Google App Engine
This is Rietveld 408576698