| Index: chrome/browser/resources/chromeos/chromevox/host/chrome/braille_integration_test.unitjs
|
| diff --git a/chrome/browser/resources/chromeos/chromevox/host/chrome/braille_integration_test.unitjs b/chrome/browser/resources/chromeos/chromevox/host/chrome/braille_integration_test.unitjs
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4fbe3dbd1f73c1293c896e3b32cba613358b11a1
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/chromeos/chromevox/host/chrome/braille_integration_test.unitjs
|
| @@ -0,0 +1,220 @@
|
| +// Copyright 2014 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(['../../testing/chromevox_unittest_base.js',
|
| + '../../testing/assert_additions.js']);
|
| +
|
| +// Tests the communication between content script and background page for
|
| +// braille.
|
| +
|
| +/**
|
| + * Test fixture.
|
| + * @constructor
|
| + * @extends {ChromeVoxUnitTestBase}
|
| + */
|
| +function CvoxBrailleIntegrationUnitTest() {}
|
| +
|
| +CvoxBrailleIntegrationUnitTest.prototype = {
|
| + __proto__: ChromeVoxUnitTestBase.prototype,
|
| +
|
| + /** @override */
|
| + closureModuleDeps: [
|
| + 'cvox.BrailleBackground',
|
| + 'cvox.BrailleInputHandler',
|
| + 'cvox.BrailleKeyCommand',
|
| + 'cvox.BrailleUtil',
|
| + 'cvox.ChromeBraille',
|
| + 'cvox.ExpandingBrailleTranslator',
|
| + ],
|
| +
|
| + /** @override */
|
| + setUp: function() {
|
| + cvox.BrailleTable.getAll = function() {}
|
| + this.displayManager = new FakeDisplayManager();
|
| + this.inputHandler = new FakeInputHandler();
|
| +
|
| + this.brailleBackground = new cvox.BrailleBackground(
|
| + this.displayManager, this.inputHandler);
|
| +
|
| + cvox.ExtensionBridge = new FakeExtensionBridge(this.brailleBackground);
|
| +
|
| + this.braille = new cvox.ChromeBraille();
|
| + this.braille.setCommandListener(function(command, content) {
|
| + this.lastCommand = command;
|
| + this.lastCommandContent = content;
|
| + }.bind(this));
|
| + this.lastCommand = null;
|
| + this.lastCommandContent = null;
|
| +
|
| + // Create convenience objects used in all tests.
|
| + this.command1 = {command: cvox.BrailleKeyCommand.PAN_LEFT};
|
| + this.content1 = cvox.NavBraille.fromText('text 1');
|
| + this.command2 = {command: cvox.BrailleKeyCommand.ROUTING};
|
| + this.content2 = cvox.NavBraille.fromText('text 2');
|
| + },
|
| +
|
| + /** @Override */
|
| + tearDown: function() {
|
| + cvox.ExtensionBridge = null;
|
| + },
|
| +
|
| + sendCommand: function(command, content) {
|
| + this.displayManager.commandListener(command, content);
|
| + }
|
| +};
|
| +
|
| +function FakeExtensionBridge(brailleBackground) {
|
| + /** @private {Function} */
|
| + this.messageListener_ = null;
|
| + /** @private {cvox.BrailleBackground} */
|
| + this.brailleBackground_ = brailleBackground;
|
| +}
|
| +
|
| +FakeExtensionBridge.prototype = {
|
| + uniqueId: function() { return 1; },
|
| +
|
| + /** @param {Function} listener The listener. */
|
| + addMessageListener: function(listener) {
|
| + assertEquals(null, this.messageListener_);
|
| + this.messageListener_ = listener;
|
| + },
|
| +
|
| + send: function(msg) {
|
| + if (msg['message'] == 'BRAILLE') {
|
| + assertNotEquals(null, this.messageListener_);
|
| + this.messageListener_(msg);
|
| + } else {
|
| + assertEquals('BRAILLE', msg['target']);
|
| + this.brailleBackground_.onBrailleMessage(msg);
|
| + }
|
| + }
|
| +};
|
| +
|
| +/** @extends {cvox.BrailleDisplaymanager} */
|
| +function FakeDisplayManager() {
|
| + /** @type {Function} */
|
| + this.commandListener = null;
|
| + /** @type {cvox.NavBraille} */
|
| + this.content = null;
|
| +}
|
| +
|
| +FakeDisplayManager.prototype = {
|
| + /** @Override */
|
| + setCommandListener: function(listener) {
|
| + this.commandListener = listener;
|
| + },
|
| +
|
| + /** @Override */
|
| + setContent: function(content, expansionType) {
|
| + assertEquals(cvox.ExpandingBrailleTranslator.ExpansionType.SELECTION,
|
| + expansionType);
|
| + this.content = content;
|
| + }
|
| +};
|
| +
|
| +/** @extends {cvox.BrailleInputHandler} */
|
| +function FakeInputHandler() {
|
| +}
|
| +
|
| +FakeInputHandler.prototype = {
|
| + /** @Override */
|
| + init: function() {},
|
| +
|
| + /** @Override */
|
| + onBrailleKeyEvent: function() {
|
| + return false;
|
| + },
|
| +
|
| + /** @Override */
|
| + onDisplayContentChanged: function() {},
|
| +
|
| + /** @Override */
|
| + getExpansionType: function() {
|
| + return cvox.ExpandingBrailleTranslator.ExpansionType.SELECTION;
|
| + }
|
| +};
|
| +
|
| +TEST_F('CvoxBrailleIntegrationUnitTest', 'Write', function() {
|
| + this.braille.write(this.content1);
|
| + assertEqualsJSON(this.content1, this.displayManager.content);
|
| +});
|
| +
|
| +TEST_F('CvoxBrailleIntegrationUnitTest', 'WriteWithSpans', function() {
|
| + var selectionSpan = new cvox.BrailleUtil.ValueSelectionSpan();
|
| + var valueSpan = new cvox.BrailleUtil.ValueSpan(20);
|
| + var toSend = cvox.NavBraille.fromText(
|
| + new cvox.Spannable('Hello', valueSpan));
|
| + toSend.text.setSpan(selectionSpan, 0, 0);
|
| + toSend.text.setSpan(document.body, 0, toSend.text.getLength());
|
| + var expected = cvox.NavBraille.fromText(
|
| + new cvox.Spannable(toSend.text.toString(), valueSpan));
|
| + expected.text.setSpan(selectionSpan, 0, 0);
|
| +
|
| + this.braille.write(toSend);
|
| + assertEqualsJSON(expected, this.displayManager.content);
|
| +});
|
| +
|
| +TEST_F('CvoxBrailleIntegrationUnitTest', 'CommandNoContent', function() {
|
| + // Commands are only delivered to the content script if the window has focus.
|
| + window.focus();
|
| + this.sendCommand(this.command1, null);
|
| + assertEqualsJSON(this.command1, this.lastCommand);
|
| + assertEquals(null, this.lastCommandContent);
|
| +});
|
| +
|
| +TEST_F('CvoxBrailleIntegrationUnitTest', 'InterleavedWritesAndCommands',
|
| + function() {
|
| + window.focus();
|
| + this.braille.write(this.content1);
|
| + this.sendCommand(this.command1, this.displayManager.content);
|
| + assertEqualsJSON(this.command1, this.lastCommand);
|
| + assertEqualsJSON(this.content1, this.lastCommandContent);
|
| +
|
| + var savedContent1 = this.displayManager.content;
|
| + this.braille.write(this.content2);
|
| + // Old content still on display.
|
| + this.sendCommand(this.command1, savedContent1);
|
| + assertEqualsJSON(this.command1, this.lastCommand);
|
| + assertEquals(null, this.lastCommandContent);
|
| + this.sendCommand(this.command2, this.displayManager.content);
|
| + assertEqualsJSON(this.command2, this.lastCommand);
|
| + assertEqualsJSON(this.content2, this.lastCommandContent);
|
| +
|
| +});
|
| +
|
| +TEST_F('CvoxBrailleIntegrationUnitTest', 'CommandAfterBackgroundWrite',
|
| + function() {
|
| + window.focus();
|
| + this.braille.write(this.content1);
|
| + this.sendCommand(this.command1, this.displayManager.content);
|
| + assertEqualsJSON(this.command1, this.lastCommand);
|
| + assertEqualsJSON(this.content1, this.lastCommandContent);
|
| +
|
| + this.brailleBackground.write(this.content2);
|
| + assertEqualsJSON(this.content2, this.displayManager.content);
|
| + this.sendCommand(this.command2, this.displayManager.content);
|
| + assertEqualsJSON(this.command2, this.lastCommand);
|
| + assertEquals(null, this.lastCommandContent);
|
| +});
|
| +
|
| +TEST_F('CvoxBrailleIntegrationUnitTest', 'CommandAfterOtherTabWrite',
|
| + function() {
|
| + window.focus();
|
| + // Ignore the listener of the braille from the second 'tab'.
|
| + cvox.ExtensionBridge.addMessageListener = function() {}
|
| + // Create another content script braille object, presumably from another
|
| + // tab.
|
| + var anotherBraille = new cvox.ChromeBraille();
|
| + this.braille.write(this.content1);
|
| + this.sendCommand(this.command1, this.displayManager.content);
|
| + // Now, this other braille gets a different unique id.
|
| + cvox.ExtensionBridge.uniqueId = function() { return 2; }
|
| + anotherBraille.write(this.content2);
|
| + this.sendCommand(this.command2, this.displayManager.content);
|
| + // The first 'tab' still gets the command, but since the second 'tab's\
|
| + // braille was on the display, it gets null content.
|
| + assertEqualsJSON(this.command2, this.lastCommand);
|
| + assertEquals(null, this.lastCommandContent);
|
| +});
|
|
|