1 // Copyright 2014 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.
5 // Include test fixture.
6 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js',
7 '../testing/assert_additions.js']);
10 * Test fixture for cvox.BrailleTranslatorManager tests.
11 * This is an E2E test because there's no easy way to load a data file in
14 * @extends {ChromeVoxE2ETest}
16 function CvoxBrailleTranslatorManagerTest() {
17 ChromeVoxE2ETest.call(this);
20 CvoxBrailleTranslatorManagerTest.prototype = {
21 __proto__: ChromeVoxE2ETest.prototype,
25 this.liblouis = new FakeLibLouis();
26 this.manager = new cvox.BrailleTranslatorManager(this.liblouis);
27 this.liblouis.translatorManager = this.manager;
28 // This is called by an event handler in production, but we don't rely
29 // on that for this test.
30 this.manager.loadLiblouis_();
33 addChangeListener: function(callback) {
34 return this.manager.addChangeListener(callOnce(this.newCallback(callback)));
38 /** @extends {cvox.LibLouis} */
39 function FakeLibLouis() {
42 FakeLibLouis.prototype = {
44 attachToElement: function() {},
47 getTranslator: function(fileNames, callback) {
48 var tables = this.translatorManager.getTablesForTest();
51 var found = tables.filter(function(table) {
52 return table.fileNames === fileNames;
55 result = new FakeTranslator(found);
63 * @extends {cvox.LibLouis.Translator}
64 * @param {cvox.BrailleTable.Table} table
67 function FakeTranslator(table) {
71 function callOnce(callback) {
76 callback.apply(null, arguments);
81 TEST_F('CvoxBrailleTranslatorManagerTest', 'testInitial', function() {
82 assertEquals(null, this.manager.getExpandingTranslator());
83 assertEquals(null, this.manager.getDefaultTranslator());
84 assertEquals(null, this.manager.getUncontractedTranslator());
85 this.addChangeListener(function() {
86 assertNotEquals(null, this.manager.getExpandingTranslator());
87 assertEquals('en-US-comp8', this.manager.getDefaultTranslator().table.id);
88 assertEquals(null, this.manager.getUncontractedTranslator());
92 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithoutChange',
94 this.addChangeListener(function() {
95 assertNotEquals(null, this.manager.getExpandingTranslator());
96 // This works because the fake liblouis is actually not asynchonous.
97 this.manager.addChangeListener(function() {
98 assertNotReached('Refresh should not be called without a change.');
100 this.manager.refresh();
104 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithChange',
106 this.addChangeListener(function() {
107 assertNotEquals(null, this.manager.getExpandingTranslator());
108 this.addChangeListener(function() {
109 assertEquals('en-UEB-g2', this.manager.getDefaultTranslator().table.id);
110 assertEquals('en-US-comp8',
111 this.manager.getUncontractedTranslator().table.id);
113 localStorage['brailleTable'] = 'en-UEB-g2';
114 this.manager.refresh();