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

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: 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 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..d953d986f35ebff123b090805d88192c415b4e04
--- /dev/null
+++ b/chrome/browser/resources/chromeos/chromevox/testing/mock_feedback_test.unitjs
@@ -0,0 +1,135 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
dmazzoni 2015/08/24 19:05:07 2015?
+// 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_endCallback) {
+ cvox.ChromeVox.tts.speak(text, 0, {endCallback: opt_endCallback});
+}
+
+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);
+}
+
+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', function() {
+ assertFalse(spruiousStringEndCallbackCalled);
+ spruiousStringEndCallbackCalled = true;
+ });
+ speak('Fourth string');
+ })
+ .expectSpeech('Fourth string')
+ .replay();
+ assertFalse(finishCalled);
+ speak('Third string');
+ assertTrue(finishCalled);
+});
+
+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', 'expectAfterGoThrows', function() {
dmazzoni 2015/08/24 19:05:07 Should this be expectAfterReplayThrows?
+ 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