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 /** | 5 /** |
6 * @fileoverview Tests for the liblouis Native Client wrapper, as seen from | 6 * @fileoverview Tests for the liblouis Native Client wrapper, as seen from |
7 * the JavaScript interface. | 7 * the JavaScript interface. |
8 */ | 8 */ |
9 | 9 |
10 // Include test fixture. | 10 // Include test fixture. |
(...skipping 12 matching lines...) Expand all Loading... |
23 createLiblouis: function() { | 23 createLiblouis: function() { |
24 return new cvox.LibLouis( | 24 return new cvox.LibLouis( |
25 chrome.extension.getURL('braille/liblouis_nacl.nmf'), | 25 chrome.extension.getURL('braille/liblouis_nacl.nmf'), |
26 chrome.extension.getURL('braille/tables')); | 26 chrome.extension.getURL('braille/tables')); |
27 }, | 27 }, |
28 | 28 |
29 createAndAttachLiblouis: function() { | 29 createAndAttachLiblouis: function() { |
30 var liblouis = this.createLiblouis(); | 30 var liblouis = this.createLiblouis(); |
31 liblouis.attachToElement(document.body); | 31 liblouis.attachToElement(document.body); |
32 return liblouis; | 32 return liblouis; |
33 } | 33 }, |
| 34 |
| 35 withTranslator: function(liblouis, tableNames, callback) { |
| 36 liblouis.getTranslator(tableNames, |
| 37 this.continueTest(WhenTestDone.ASSERT, callback)); |
| 38 }, |
34 }; | 39 }; |
35 | 40 |
36 function assertEqualsUint8Array(expected, actual) { | 41 function assertEqualsUint8Array(expected, actual) { |
37 var as_array = []; | 42 var as_array = []; |
38 var uint8array = new Uint8Array(actual); | 43 var uint8array = new Uint8Array(actual); |
39 for (var i = 0; i < uint8array.length; ++i) { | 44 for (var i = 0; i < uint8array.length; ++i) { |
40 as_array[i] = uint8array[i]; | 45 as_array[i] = uint8array[i]; |
41 } | 46 } |
42 assertEqualsJSON(expected, as_array); | 47 assertEqualsJSON(expected, as_array); |
43 } | 48 } |
44 | 49 |
45 // Disable all of tests because they are flaky. crbug.com/458643 | 50 TEST_F('CvoxLibLouisTest', 'checkAllTables', function() { |
46 | |
47 TEST_F('CvoxLibLouisTest', 'DISABLED_checkAllTables', function() { | |
48 var liblouis = this.createAndAttachLiblouis(); | 51 var liblouis = this.createAndAttachLiblouis(); |
49 cvox.BrailleTable.getAll(function(allTables) { | 52 var continuation = this.continueTest(WhenTestDone.ASSERT, function(tables) { |
50 var i = 0; | 53 var i = 0; |
51 var checkNextTable = function() { | 54 var checkNextTable = function() { |
52 var table = allTables[i++]; | 55 var table = tables[i++]; |
53 if (table) { | 56 if (table) { |
54 liblouis.getTranslator(table.fileNames, function(translator) { | 57 this.withTranslator(liblouis, table.fileNames, function(translator) { |
55 assertNotEquals(null, translator, | 58 assertNotEquals(null, translator, |
56 'Table ' + table + ' should be valid'); | 59 'Table ' + table + ' should be valid'); |
57 checkNextTable(); | 60 checkNextTable(); |
58 }); | 61 }); |
59 } else { | 62 } else { |
60 testDone(); | 63 testDone(); |
61 } | 64 } |
62 }; | 65 }.bind(this); |
63 checkNextTable(); | 66 checkNextTable(); |
| 67 }.bind(this)); |
| 68 cvox.BrailleTable.getAll(continuation); |
| 69 }); |
| 70 |
| 71 TEST_F('CvoxLibLouisTest', 'testTranslateComputerBraille', function() { |
| 72 var liblouis = this.createAndAttachLiblouis(); |
| 73 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) { |
| 74 var continuation = this.continueTest( |
| 75 WhenTestDone.ALWAYS, |
| 76 function(cells, textToBraille, brailleToText) { |
| 77 assertEqualsUint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e], cells); |
| 78 assertEqualsJSON([0, 1, 2, 3, 4, 5], textToBraille); |
| 79 assertEqualsJSON([0, 1, 2, 3, 4, 5], brailleToText); |
| 80 }); |
| 81 translator.translate('Hello!', continuation); |
64 }); | 82 }); |
65 }); | 83 }); |
66 | 84 |
67 TEST_F('CvoxLibLouisTest', 'DISABLED_testTranslateComputerBraille', function ()
{ | 85 TEST_F('CvoxLibLouisTest', 'testBackTranslateComputerBraille', function() { |
68 var liblouis = this.createAndAttachLiblouis(); | 86 var liblouis = this.createAndAttachLiblouis(); |
69 liblouis.getTranslator('en-us-comp8.ctb', function(translator) { | 87 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) { |
70 translator.translate( | 88 var cells = new Uint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e]); |
71 'Hello!', function(cells, textToBraille, brailleToText) { | 89 var continuation = this.continueTest(WhenTestDone.ALWAYS, function(text) { |
72 assertEqualsUint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e], cells); | 90 assertEquals('Hello!', text); |
73 assertEqualsJSON([0, 1, 2, 3, 4, 5], textToBraille); | 91 }); |
74 assertEqualsJSON([0, 1, 2, 3, 4, 5], brailleToText); | 92 translator.backTranslate(cells.buffer, continuation); |
75 testDone(); | |
76 }); | |
77 }); | 93 }); |
78 }); | 94 }); |
79 | 95 |
80 TEST_F('CvoxLibLouisTest', 'DISABLED_testBackTranslateComputerBraille', function
() { | 96 TEST_F('CvoxLibLouisTest', 'testTranslateGermanGrade2Braille', function() { |
81 var liblouis = this.createAndAttachLiblouis(); | 97 var liblouis = this.createAndAttachLiblouis(); |
82 liblouis.getTranslator('en-us-comp8.ctb', function(translator) { | 98 // This is one of the moderately large tables. |
83 var cells = new Uint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e]); | 99 this.withTranslator(liblouis, 'de-de-g2.ctb', function(translator) { |
84 translator.backTranslate(cells.buffer, function(text) { | 100 var continuation = this.continueTest( |
85 assertEquals('Hello!', text); | 101 WhenTestDone.ALWAYS, function(cells, textToBraille, brailleToText) { |
86 testDone(); | 102 assertEqualsUint8Array([0x0d, 0x33, 0x1d, 0x39, 0x09], cells); |
87 }); | 103 assertEqualsJSON([0, 1, 2, 3, 3, 4, 4], textToBraille); |
| 104 assertEqualsJSON([0, 1, 2, 3, 5], brailleToText); |
| 105 }); |
| 106 translator.translate('München', continuation); |
88 }); | 107 }); |
89 }); | 108 }); |
90 | 109 |
91 TEST_F('CvoxLibLouisTest', 'DISABLED_testTranslateGermanGrade2Braille', function
() { | 110 TEST_F('CvoxLibLouisTest', 'testBackTranslateGermanComputerBraille', function()
{ |
92 var liblouis = this.createAndAttachLiblouis(); | 111 var liblouis = this.createAndAttachLiblouis(); |
93 // This is one of the moderately large tables. | 112 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { |
94 liblouis.getTranslator('de-de-g2.ctb', function(translator) { | 113 var cells = new Uint8Array([0xb3]); |
95 translator.translate( | 114 var continuation = this.continueTest(WhenTestDone.ALWAYS, function(text) { |
96 'München', function(cells, textToBraille, brailleToText) { | 115 assertEquals('ü', text); |
97 assertEqualsUint8Array([0x0d, 0x33, 0x1d, 0x39, 0x09], cells); | 116 }); |
98 assertEqualsJSON([0, 1, 2, 3, 3, 4, 4], textToBraille); | 117 translator.backTranslate(cells.buffer, continuation); |
99 assertEqualsJSON([0, 1, 2, 3, 5], brailleToText); | |
100 testDone(); | |
101 }); | |
102 }); | 118 }); |
103 }); | 119 }); |
104 | 120 |
105 TEST_F('CvoxLibLouisTest', 'DISABLED_testBackTranslateGermanComputerBraille', fu
nction() { | 121 TEST_F('CvoxLibLouisTest', 'testBackTranslateEmptyCells', function() { |
106 var liblouis = this.createAndAttachLiblouis(); | 122 var liblouis = this.createAndAttachLiblouis(); |
107 liblouis.getTranslator('de-de-comp8.ctb', function(translator) { | 123 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { |
108 var cells = new Uint8Array([0xb3]); | 124 var continuation = this.continueTest(WhenTestDone.ALWAYS, function(text) { |
109 translator.backTranslate(cells.buffer, function(text) { | 125 assertNotEquals(null, text); |
110 assertEquals('ü', text); | 126 assertEquals(0, text.length); |
111 testDone(); | |
112 }); | 127 }); |
| 128 translator.backTranslate(new Uint8Array().buffer, continuation); |
113 }); | 129 }); |
114 }); | 130 }); |
115 | 131 |
116 TEST_F('CvoxLibLouisTest', 'DISABLED_testBackTranslateEmptyCells', function() { | 132 TEST_F('CvoxLibLouisTest', 'testGetTranslatorBeforeAttach', function() { |
117 var liblouis = this.createAndAttachLiblouis(); | |
118 liblouis.getTranslator('de-de-comp8.ctb', function(translator) { | |
119 var cells = new Uint8Array(); | |
120 translator.backTranslate(cells.buffer, function(text) { | |
121 assertNotEquals(null, text); | |
122 assertEquals(0, text.length); | |
123 testDone(); | |
124 }); | |
125 }); | |
126 }); | |
127 | |
128 TEST_F('CvoxLibLouisTest', 'DISABLED_testGetTranslatorBeforeAttach', function()
{ | |
129 var liblouis = this.createLiblouis(); | 133 var liblouis = this.createLiblouis(); |
130 assertFalse(liblouis.isAttached()); | 134 assertFalse(liblouis.isAttached()); |
131 liblouis.getTranslator('en-us-comp8.ctb', function(translator) { | 135 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) { |
132 assertNotEquals(null, translator); | |
133 testDone(); | |
134 }); | |
135 liblouis.attachToElement(document.body); | |
136 }); | |
137 | |
138 TEST_F('CvoxLibLouisTest', 'DISABLED_testGetInvalidTranslator', function() { | |
139 var liblouis = this.createAndAttachLiblouis(); | |
140 liblouis.getTranslator('nonexistant-table', function(translator) { | |
141 assertEquals(null, translator); | 136 assertEquals(null, translator); |
142 testDone(); | 137 testDone(); |
143 }); | 138 }); |
144 }); | 139 }); |
| 140 |
| 141 TEST_F('CvoxLibLouisTest', 'testGetInvalidTranslator', function() { |
| 142 var liblouis = this.createAndAttachLiblouis(); |
| 143 this.withTranslator(liblouis, 'nonexistant-table', function(translator) { |
| 144 assertEquals(null, translator); |
| 145 testDone(); |
| 146 }); |
| 147 }); |
| 148 |
| 149 TEST_F('CvoxLibLouisTest', 'testTranslateAfterDetach', function() { |
| 150 var liblouis = this.createAndAttachLiblouis(); |
| 151 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { |
| 152 liblouis.detach(); |
| 153 var continuation = this.continueTest( |
| 154 WhenTestDone.ALWAYS, |
| 155 function(cells, textToBraille, brailleToText) { |
| 156 assertEquals(null, cells); |
| 157 assertEquals(null, textToBraille); |
| 158 assertEquals(null, brailleToText); |
| 159 }); |
| 160 translator.translate('Hamburg', continuation); |
| 161 }); |
| 162 }); |
| 163 |
| 164 TEST_F('CvoxLibLouisTest', 'testDetachWithOutstandingCallbacks', function() { |
| 165 var liblouis = this.createAndAttachLiblouis(); |
| 166 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { |
| 167 var continuation = this.continueTest( |
| 168 WhenTestDone.ALWAYS, |
| 169 function(cells, textToBraille, brailleToText) { |
| 170 assertEquals(null, cells); |
| 171 assertEquals(null, textToBraille); |
| 172 assertEquals(null, brailleToText); |
| 173 }); |
| 174 translator.translate('Berlin', continuation); |
| 175 liblouis.detach(); |
| 176 }); |
| 177 }); |
OLD | NEW |