OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Include test fixture. | 5 // Include test fixture. |
6 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js', | 6 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js', |
7 '../testing/assert_additions.js']); | 7 '../testing/assert_additions.js']); |
8 | 8 |
9 /** | 9 /** |
10 * Test fixture for cvox.BrailleTranslatorManager tests. | 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 | 11 * This is an E2E test because there's no easy way to load a data file in |
12 * a webui-style test. | 12 * a webui-style test. |
13 * @constructor | 13 * @constructor |
14 * @extends {ChromeVoxE2ETest} | 14 * @extends {ChromeVoxE2ETest} |
15 */ | 15 */ |
16 function CvoxBrailleTranslatorManagerTest() {} | 16 function CvoxBrailleTranslatorManagerTest() {} |
17 | 17 |
18 CvoxBrailleTranslatorManagerTest.prototype = { | 18 CvoxBrailleTranslatorManagerTest.prototype = { |
19 __proto__: ChromeVoxE2ETest.prototype, | 19 __proto__: ChromeVoxE2ETest.prototype, |
20 | 20 |
21 /** @override */ | 21 /** @override */ |
22 setUp: function() { | 22 setUp: function() { |
23 this.liblouis = new FakeLibLouis(); | 23 this.liblouis = new FakeLibLouis(); |
24 this.manager = new cvox.BrailleTranslatorManager(this.liblouis); | 24 this.manager = new cvox.BrailleTranslatorManager(this.liblouis); |
25 this.liblouis.translator_manager = this.manager; | 25 this.liblouis.translatorManager = this.manager; |
| 26 // This is called by an event handler in production, but we don't rely |
| 27 // on that for this test. |
| 28 this.manager.loadLiblouis_(); |
| 29 }, |
| 30 |
| 31 addChangeListener: function(callback) { |
| 32 return this.manager.addChangeListener(this.continueTest( |
| 33 WhenTestDone.ASSERT, callback)); |
26 }, | 34 }, |
27 }; | 35 }; |
28 | 36 |
29 /** @extends {cvox.LibLouis} */ | 37 /** @extends {cvox.LibLouis} */ |
30 function FakeLibLouis() { | 38 function FakeLibLouis() { |
31 } | 39 } |
32 | 40 |
33 FakeLibLouis.prototype = { | 41 FakeLibLouis.prototype = { |
34 /** @override */ | 42 /** @override */ |
35 attachToElement: function() {}, | 43 attachToElement: function() {}, |
36 | 44 |
37 /** @override */ | 45 /** @override */ |
38 getTranslator: function(fileNames, callback) { | 46 getTranslator: function(fileNames, callback) { |
39 var tables = this.translator_manager.getTablesForTest(); | 47 var tables = this.translatorManager.getTablesForTest(); |
40 var result = null; | 48 var result = null; |
41 if (tables != null) { | 49 if (tables != null) { |
42 var found = tables.filter(function(table) { | 50 var found = tables.filter(function(table) { |
43 return table.fileNames === fileNames; | 51 return table.fileNames === fileNames; |
44 })[0]; | 52 })[0]; |
45 if (found) { | 53 if (found) { |
46 result = new FakeTranslator(found); | 54 result = new FakeTranslator(found); |
47 } | 55 } |
48 } | 56 } |
49 callback(result); | 57 callback(result); |
(...skipping 16 matching lines...) Expand all Loading... |
66 callback.apply(null, arguments); | 74 callback.apply(null, arguments); |
67 called = true; | 75 called = true; |
68 } | 76 } |
69 }; | 77 }; |
70 } | 78 } |
71 | 79 |
72 TEST_F('CvoxBrailleTranslatorManagerTest', 'testInitial', function() { | 80 TEST_F('CvoxBrailleTranslatorManagerTest', 'testInitial', function() { |
73 assertEquals(null, this.manager.getExpandingTranslator()); | 81 assertEquals(null, this.manager.getExpandingTranslator()); |
74 assertEquals(null, this.manager.getDefaultTranslator()); | 82 assertEquals(null, this.manager.getDefaultTranslator()); |
75 assertEquals(null, this.manager.getUncontractedTranslator()); | 83 assertEquals(null, this.manager.getUncontractedTranslator()); |
76 this.manager.addChangeListener(function() { | 84 this.addChangeListener(function() { |
77 assertNotEquals(null, this.manager.getExpandingTranslator()); | 85 assertNotEquals(null, this.manager.getExpandingTranslator()); |
78 assertEquals('en-US-comp8', this.manager.getDefaultTranslator().table.id); | 86 assertEquals('en-US-comp8', this.manager.getDefaultTranslator().table.id); |
79 assertEquals(null, this.manager.getUncontractedTranslator()); | 87 assertEquals(null, this.manager.getUncontractedTranslator()); |
80 testDone(); | 88 testDone(); |
81 }.bind(this)); | 89 }.bind(this)); |
82 }); | 90 }); |
83 | 91 |
84 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithoutChange', | 92 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithoutChange', |
85 function() { | 93 function() { |
86 this.manager.addChangeListener(callOnce(function() { | 94 this.addChangeListener(callOnce(function() { |
87 assertNotEquals(null, this.manager.getExpandingTranslator()); | 95 assertNotEquals(null, this.manager.getExpandingTranslator()); |
88 // This works because the fake liblouis is actually not synchonous. | 96 // This works because the fake liblouis is actually not asynchonous. |
89 this.manager.addChangeListener(function() { | 97 this.addChangeListener(function() { |
90 throw Error('Should not be called.'); | 98 throw Error('Should not be called.'); |
91 }); | 99 }); |
92 this.manager.refresh(); | 100 this.manager.refresh(); |
93 testDone(); | 101 testDone(); |
94 }.bind(this))); | 102 }.bind(this))); |
95 }); | 103 }); |
96 | 104 |
97 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithChange', | 105 TEST_F('CvoxBrailleTranslatorManagerTest', 'testRefreshWithChange', |
98 function() { | 106 function() { |
99 this.manager.addChangeListener(callOnce(function() { | 107 this.addChangeListener(callOnce(function() { |
100 assertNotEquals(null, this.manager.getExpandingTranslator()); | 108 assertNotEquals(null, this.manager.getExpandingTranslator()); |
101 this.manager.addChangeListener(function() { | 109 this.addChangeListener(function() { |
102 assertEquals('en-UEB-g2', this.manager.getDefaultTranslator().table.id); | 110 assertEquals('en-UEB-g2', this.manager.getDefaultTranslator().table.id); |
103 assertEquals('en-US-comp8', | 111 assertEquals('en-US-comp8', |
104 this.manager.getUncontractedTranslator().table.id); | 112 this.manager.getUncontractedTranslator().table.id); |
105 testDone(); | 113 testDone(); |
106 }.bind(this)); | 114 }.bind(this)); |
107 localStorage['brailleTable'] = 'en-UEB-g2'; | 115 localStorage['brailleTable'] = 'en-UEB-g2'; |
108 this.manager.refresh(); | 116 this.manager.refresh(); |
109 }.bind(this))); | 117 }.bind(this))); |
110 }); | 118 }); |
OLD | NEW |