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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/braille/liblouis_test.extjs

Issue 938623003: Fix ChromeVox next tests to fail instead of timing out where applicable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify async callback handling in the tests. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
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.
11 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js', 11 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js',
12 '../testing/assert_additions.js']); 12 '../testing/assert_additions.js']);
13 13
14 /** 14 /**
15 * @constructor 15 * @constructor
16 * @extends {ChromeVoxE2ETest} 16 * @extends {ChromeVoxE2ETest}
17 */ 17 */
18 function CvoxLibLouisTest() {} 18 function CvoxLibLouisTest() {
19 ChromeVoxE2ETest.call(this);
20 }
19 21
20 CvoxLibLouisTest.prototype = { 22 CvoxLibLouisTest.prototype = {
21 __proto__: ChromeVoxE2ETest.prototype, 23 __proto__: ChromeVoxE2ETest.prototype,
22 24
23 createLiblouis: function() { 25 createLiblouis: function() {
24 return new cvox.LibLouis( 26 return new cvox.LibLouis(
25 chrome.extension.getURL('braille/liblouis_nacl.nmf'), 27 chrome.extension.getURL('braille/liblouis_nacl.nmf'),
26 chrome.extension.getURL('braille/tables')); 28 chrome.extension.getURL('braille/tables'));
27 }, 29 },
28 30
29 createAndAttachLiblouis: function() { 31 createAndAttachLiblouis: function() {
30 var liblouis = this.createLiblouis(); 32 var liblouis = this.createLiblouis();
31 liblouis.attachToElement(document.body); 33 liblouis.attachToElement(document.body);
32 return liblouis; 34 return liblouis;
33 }, 35 },
34 36
35 withTranslator: function(liblouis, tableNames, callback) { 37 withTranslator: function(liblouis, tableNames, callback) {
36 liblouis.getTranslator(tableNames, 38 liblouis.getTranslator(tableNames, this.newCallback(callback));
37 this.continueTest(WhenTestDone.ASSERT, callback));
38 }, 39 },
39 }; 40 };
40 41
41 function assertEqualsUint8Array(expected, actual) { 42 function assertEqualsUint8Array(expected, actual) {
42 var as_array = []; 43 var as_array = [];
43 var uint8array = new Uint8Array(actual); 44 var uint8array = new Uint8Array(actual);
44 for (var i = 0; i < uint8array.length; ++i) { 45 for (var i = 0; i < uint8array.length; ++i) {
45 as_array[i] = uint8array[i]; 46 as_array[i] = uint8array[i];
46 } 47 }
47 assertEqualsJSON(expected, as_array); 48 assertEqualsJSON(expected, as_array);
48 } 49 }
49 50
50 TEST_F('CvoxLibLouisTest', 'checkAllTables', function() { 51 TEST_F('CvoxLibLouisTest', 'checkAllTables', function() {
51 var liblouis = this.createAndAttachLiblouis(); 52 var liblouis = this.createAndAttachLiblouis();
52 var continuation = this.continueTest(WhenTestDone.ASSERT, function(tables) { 53 cvox.BrailleTable.getAll(this.newCallback(function(tables) {
53 var i = 0; 54 var i = 0;
54 var checkNextTable = function() { 55 var checkNextTable = function() {
55 var table = tables[i++]; 56 var table = tables[i++];
56 if (table) { 57 if (table) {
57 this.withTranslator(liblouis, table.fileNames, function(translator) { 58 this.withTranslator(liblouis, table.fileNames, function(translator) {
58 assertNotEquals(null, translator, 59 assertNotEquals(null, translator,
59 'Table ' + table + ' should be valid'); 60 'Table ' + table + ' should be valid');
60 checkNextTable(); 61 checkNextTable();
61 }); 62 });
62 } else {
63 testDone();
64 } 63 }
65 }.bind(this); 64 }.bind(this);
66 checkNextTable(); 65 checkNextTable();
67 }.bind(this)); 66 }.bind(this)));
68 cvox.BrailleTable.getAll(continuation);
69 }); 67 });
70 68
71 TEST_F('CvoxLibLouisTest', 'testTranslateComputerBraille', function() { 69 TEST_F('CvoxLibLouisTest', 'testTranslateComputerBraille', function() {
72 var liblouis = this.createAndAttachLiblouis(); 70 var liblouis = this.createAndAttachLiblouis();
73 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) { 71 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) {
74 var continuation = this.continueTest( 72 translator.translate('Hello!', this.newCallback(
75 WhenTestDone.ALWAYS,
76 function(cells, textToBraille, brailleToText) { 73 function(cells, textToBraille, brailleToText) {
77 assertEqualsUint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e], cells); 74 assertEqualsUint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e], cells);
78 assertEqualsJSON([0, 1, 2, 3, 4, 5], textToBraille); 75 assertEqualsJSON([0, 1, 2, 3, 4, 5], textToBraille);
79 assertEqualsJSON([0, 1, 2, 3, 4, 5], brailleToText); 76 assertEqualsJSON([0, 1, 2, 3, 4, 5], brailleToText);
80 }); 77 }));
81 translator.translate('Hello!', continuation);
82 }); 78 });
83 }); 79 });
84 80
85 TEST_F('CvoxLibLouisTest', 'testBackTranslateComputerBraille', function() { 81 TEST_F('CvoxLibLouisTest', 'testBackTranslateComputerBraille', function() {
86 var liblouis = this.createAndAttachLiblouis(); 82 var liblouis = this.createAndAttachLiblouis();
87 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) { 83 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) {
88 var cells = new Uint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e]); 84 var cells = new Uint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e]);
89 var continuation = this.continueTest(WhenTestDone.ALWAYS, function(text) { 85 translator.backTranslate(cells.buffer, this.newCallback(function(text) {
90 assertEquals('Hello!', text); 86 assertEquals('Hello!', text);
91 }); 87 }));
92 translator.backTranslate(cells.buffer, continuation);
93 }); 88 });
94 }); 89 });
95 90
96 TEST_F('CvoxLibLouisTest', 'testTranslateGermanGrade2Braille', function() { 91 TEST_F('CvoxLibLouisTest', 'testTranslateGermanGrade2Braille', function() {
97 var liblouis = this.createAndAttachLiblouis(); 92 var liblouis = this.createAndAttachLiblouis();
98 // This is one of the moderately large tables. 93 // This is one of the moderately large tables.
99 this.withTranslator(liblouis, 'de-de-g2.ctb', function(translator) { 94 this.withTranslator(liblouis, 'de-de-g2.ctb', function(translator) {
100 var continuation = this.continueTest( 95 translator.translate('München', this.newCallback(
101 WhenTestDone.ALWAYS, function(cells, textToBraille, brailleToText) { 96 function(cells, textToBraille, brailleToText) {
102 assertEqualsUint8Array([0x0d, 0x33, 0x1d, 0x39, 0x09], cells); 97 assertEqualsUint8Array([0x0d, 0x33, 0x1d, 0x39, 0x09], cells);
103 assertEqualsJSON([0, 1, 2, 3, 3, 4, 4], textToBraille); 98 assertEqualsJSON([0, 1, 2, 3, 3, 4, 4], textToBraille);
104 assertEqualsJSON([0, 1, 2, 3, 5], brailleToText); 99 assertEqualsJSON([0, 1, 2, 3, 5], brailleToText);
105 }); 100 }));
106 translator.translate('München', continuation);
107 }); 101 });
108 }); 102 });
109 103
110 TEST_F('CvoxLibLouisTest', 'testBackTranslateGermanComputerBraille', function() { 104 TEST_F('CvoxLibLouisTest', 'testBackTranslateGermanComputerBraille', function() {
111 var liblouis = this.createAndAttachLiblouis(); 105 var liblouis = this.createAndAttachLiblouis();
112 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { 106 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) {
113 var cells = new Uint8Array([0xb3]); 107 var cells = new Uint8Array([0xb3]);
114 var continuation = this.continueTest(WhenTestDone.ALWAYS, function(text) { 108 translator.backTranslate(cells.buffer, this.newCallback(function(text) {
115 assertEquals('ü', text); 109 assertEquals('ü', text);
116 }); 110 }));
117 translator.backTranslate(cells.buffer, continuation);
118 }); 111 });
119 }); 112 });
120 113
121 TEST_F('CvoxLibLouisTest', 'testBackTranslateEmptyCells', function() { 114 TEST_F('CvoxLibLouisTest', 'testBackTranslateEmptyCells', function() {
122 var liblouis = this.createAndAttachLiblouis(); 115 var liblouis = this.createAndAttachLiblouis();
123 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { 116 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) {
124 var continuation = this.continueTest(WhenTestDone.ALWAYS, function(text) { 117 translator.backTranslate(
125 assertNotEquals(null, text); 118 new Uint8Array().buffer,
126 assertEquals(0, text.length); 119 this.newCallback(function(text) {
127 }); 120 assertNotEquals(null, text);
128 translator.backTranslate(new Uint8Array().buffer, continuation); 121 assertEquals(0, text.length);
122 }));
129 }); 123 });
130 }); 124 });
131 125
132 TEST_F('CvoxLibLouisTest', 'testGetTranslatorBeforeAttach', function() { 126 TEST_F('CvoxLibLouisTest', 'testGetTranslatorBeforeAttach', function() {
133 var liblouis = this.createLiblouis(); 127 var liblouis = this.createLiblouis();
134 assertFalse(liblouis.isAttached()); 128 assertFalse(liblouis.isAttached());
135 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) { 129 this.withTranslator(liblouis, 'en-us-comp8.ctb', function(translator) {
136 assertEquals(null, translator); 130 assertEquals(null, translator);
137 testDone();
138 }); 131 });
139 }); 132 });
140 133
141 TEST_F('CvoxLibLouisTest', 'testGetInvalidTranslator', function() { 134 TEST_F('CvoxLibLouisTest', 'testGetInvalidTranslator', function() {
142 var liblouis = this.createAndAttachLiblouis(); 135 var liblouis = this.createAndAttachLiblouis();
143 this.withTranslator(liblouis, 'nonexistant-table', function(translator) { 136 this.withTranslator(liblouis, 'nonexistant-table', function(translator) {
144 assertEquals(null, translator); 137 assertEquals(null, translator);
145 testDone();
146 }); 138 });
147 }); 139 });
148 140
149 TEST_F('CvoxLibLouisTest', 'testTranslateAfterDetach', function() { 141 TEST_F('CvoxLibLouisTest', 'testTranslateAfterDetach', function() {
150 var liblouis = this.createAndAttachLiblouis(); 142 var liblouis = this.createAndAttachLiblouis();
151 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { 143 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) {
152 liblouis.detach(); 144 liblouis.detach();
153 var continuation = this.continueTest( 145 translator.translate('Hamburg', this.newCallback(
154 WhenTestDone.ALWAYS,
155 function(cells, textToBraille, brailleToText) { 146 function(cells, textToBraille, brailleToText) {
156 assertEquals(null, cells); 147 assertEquals(null, cells);
157 assertEquals(null, textToBraille); 148 assertEquals(null, textToBraille);
158 assertEquals(null, brailleToText); 149 assertEquals(null, brailleToText);
159 }); 150 }));
160 translator.translate('Hamburg', continuation);
161 }); 151 });
162 }); 152 });
163 153
164 TEST_F('CvoxLibLouisTest', 'testDetachWithOutstandingCallbacks', function() { 154 TEST_F('CvoxLibLouisTest', 'testDetachWithOutstandingCallbacks', function() {
165 var liblouis = this.createAndAttachLiblouis(); 155 var liblouis = this.createAndAttachLiblouis();
166 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) { 156 this.withTranslator(liblouis, 'de-de-comp8.ctb', function(translator) {
167 var continuation = this.continueTest( 157 var called = false;
168 WhenTestDone.ALWAYS, 158 translator.translate('Berlin', this.newCallback(
169 function(cells, textToBraille, brailleToText) { 159 function(cells, textToBraille, brailleToText) {
170 assertEquals(null, cells); 160 assertEquals(null, cells);
171 assertEquals(null, textToBraille); 161 assertEquals(null, textToBraille);
172 assertEquals(null, brailleToText); 162 assertEquals(null, brailleToText);
173 }); 163 called = true;
174 translator.translate('Berlin', continuation); 164 }));
165 assertFalse(called);
175 liblouis.detach(); 166 liblouis.detach();
176 }); 167 });
177 }); 168 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698