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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/braille/liblouis.js

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 JavaScript shim for the liblouis Native Client wrapper. 6 * @fileoverview JavaScript shim for the liblouis Native Client wrapper.
7 */ 7 */
8 8
9 goog.provide('cvox.LibLouis'); 9 goog.provide('cvox.LibLouis');
10 10
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 * @param {string} text Text to be translated. 228 * @param {string} text Text to be translated.
229 * @param {function(ArrayBuffer, Array<number>, Array<number>)} callback 229 * @param {function(ArrayBuffer, Array<number>, Array<number>)} callback
230 * Callback for result. Takes 3 parameters: the resulting cells, 230 * Callback for result. Takes 3 parameters: the resulting cells,
231 * mapping from text to braille positions and mapping from braille to 231 * mapping from text to braille positions and mapping from braille to
232 * text positions. If translation fails for any reason, all parameters are 232 * text positions. If translation fails for any reason, all parameters are
233 * {@code null}. 233 * {@code null}.
234 */ 234 */
235 cvox.LibLouis.Translator.prototype.translate = function(text, callback) { 235 cvox.LibLouis.Translator.prototype.translate = function(text, callback) {
236 if (!this.instance_.isAttached()) { 236 if (!this.instance_.isAttached()) {
237 callback(null /*cells*/, null /*textToBraille*/, null /*brailleToText*/); 237 callback(null /*cells*/, null /*textToBraille*/, null /*brailleToText*/);
238 return;
238 } 239 }
239 var message = { 'table_names': this.tableNames_, 'text': text }; 240 var message = { 'table_names': this.tableNames_, 'text': text };
240 this.instance_.rpc_('Translate', message, function(reply) { 241 this.instance_.rpc_('Translate', message, function(reply) {
241 var cells = null; 242 var cells = null;
242 var textToBraille = null; 243 var textToBraille = null;
243 var brailleToText = null; 244 var brailleToText = null;
244 if (reply['success'] && goog.isString(reply['cells'])) { 245 if (reply['success'] && goog.isString(reply['cells'])) {
245 cells = cvox.LibLouis.Translator.decodeHexString_(reply['cells']); 246 cells = cvox.LibLouis.Translator.decodeHexString_(reply['cells']);
246 if (goog.isDef(reply['text_to_braille'])) { 247 if (goog.isDef(reply['text_to_braille'])) {
247 textToBraille = reply['text_to_braille']; 248 textToBraille = reply['text_to_braille'];
(...skipping 13 matching lines...) Expand all
261 262
262 /** 263 /**
263 * Translates braille cells into text. 264 * Translates braille cells into text.
264 * @param {!ArrayBuffer} cells Cells to be translated. 265 * @param {!ArrayBuffer} cells Cells to be translated.
265 * @param {function(?string)} callback Callback for result. 266 * @param {function(?string)} callback Callback for result.
266 */ 267 */
267 cvox.LibLouis.Translator.prototype.backTranslate = 268 cvox.LibLouis.Translator.prototype.backTranslate =
268 function(cells, callback) { 269 function(cells, callback) {
269 if (!this.instance_.isAttached()) { 270 if (!this.instance_.isAttached()) {
270 callback(null /*text*/); 271 callback(null /*text*/);
272 return;
271 } 273 }
272 if (cells.byteLength == 0) { 274 if (cells.byteLength == 0) {
273 // liblouis doesn't handle empty input, so handle that trivially 275 // liblouis doesn't handle empty input, so handle that trivially
274 // here. 276 // here.
275 callback(''); 277 callback('');
276 return; 278 return;
277 } 279 }
278 var message = { 280 var message = {
279 'table_names': this.tableNames_, 281 'table_names': this.tableNames_,
280 'cells': cvox.LibLouis.Translator.encodeHexString_(cells) 282 'cells': cvox.LibLouis.Translator.encodeHexString_(cells)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 */ 318 */
317 cvox.LibLouis.Translator.encodeHexString_ = function(arrayBuffer) { 319 cvox.LibLouis.Translator.encodeHexString_ = function(arrayBuffer) {
318 var array = new Uint8Array(arrayBuffer); 320 var array = new Uint8Array(arrayBuffer);
319 var hex = ''; 321 var hex = '';
320 for (var i = 0; i < array.length; i++) { 322 for (var i = 0; i < array.length; i++) {
321 var b = array[i]; 323 var b = array[i];
322 hex += (b < 0x10 ? '0' : '') + b.toString(16); 324 hex += (b < 0x10 ? '0' : '') + b.toString(16);
323 } 325 }
324 return hex; 326 return hex;
325 }; 327 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698