1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Tests for the liblouis wasm wrapper, as seen from
* the JavaScript interface.
*/
// Include test fixture.
GEN_INCLUDE(['../../testing/chromevox_e2e_test_base.js']);
ChromeVoxMV2LibLouisTest = class extends ChromeVoxE2ETest {
/** @override */
async setUpDeferred() {
await super.setUpDeferred();
const path = chrome.extension.getURL(
'chromevox/third_party/liblouis/liblouis_wrapper.js');
this.liblouis = await LibLouis.create(path, '');
}
async backTranslate(tableNames, buffer) {
const translator = await this.liblouis.getTranslator(tableNames);
return new Promise(resolve => translator.backTranslate(buffer, resolve));
}
async translate(tableNames, text) {
const translator = await this.liblouis.getTranslator(tableNames);
return new Promise(
resolve => translator.translate(text, [], (...args) => resolve(args)));
}
};
function assertEqualsUint8Array(expected, actual) {
const asArray = Array.from(new Uint8Array(actual));
assertEqualsJSON(expected, asArray);
}
AX_TEST_F(
'ChromeVoxMV2LibLouisTest', 'TranslateComputerBraille', async function() {
const [cells, textToBraille, brailleToText] =
await this.translate('en-us-comp8.ctb', 'Hello!');
assertEqualsUint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e], cells);
assertEqualsJSON([0, 1, 2, 3, 4, 5], textToBraille);
assertEqualsJSON([0, 1, 2, 3, 4, 5], brailleToText);
});
AX_TEST_F('ChromeVoxMV2LibLouisTest', 'MAYBE_CheckAllTables', async function() {
const tables = await new Promise(resolve => BrailleTable.getAll(resolve));
for (const table of tables) {
const translator = await this.liblouis.getTranslator(table.fileNames);
assertNotEquals(
null, translator,
'Table ' + JSON.stringify(table) + ' should be valid');
}
}, `
#if defined(MEMORY_SANITIZER)
#define MAYBE_CheckAllTables DISABLED_CheckAllTables
#else
#define MAYBE_CheckAllTables CheckAllTables
#endif
`);
AX_TEST_F(
'ChromeVoxMV2LibLouisTest', 'BackTranslateComputerBraille',
async function() {
const cells = new Uint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e]);
const text = await this.backTranslate('en-us-comp8.ctb', cells.buffer);
assertEquals('Hello!', text);
});
AX_TEST_F(
'ChromeVoxMV2LibLouisTest', 'TranslateGermanGrade2Braille',
async function() {
// This is one of the moderately large tables.
const [cells, textToBraille, brailleToText] =
await this.translate('de-g2.ctb', 'München');
assertEqualsUint8Array([0x0d, 0x33, 0x1d, 0x39, 0x09], cells);
assertEqualsJSON([0, 1, 2, 3, 3, 4, 4], textToBraille);
assertEqualsJSON([0, 1, 2, 3, 5], brailleToText);
});
AX_TEST_F(
'ChromeVoxMV2LibLouisTest', 'TranslateSpaceIsNotDropped', async function() {
const [cells, textToBraille, brailleToText] =
await this.translate('en-ueb-g2.ctb', ' ');
assertEqualsUint8Array([0x0], cells);
});
AX_TEST_F(
'ChromeVoxMV2LibLouisTest', 'BackTranslateGermanComputerBraille',
async function() {
const cells = new Uint8Array([0xb3]);
const text = await this.backTranslate('de-de-comp8.ctb', cells.buffer);
assertEquals('ü', text);
});
AX_TEST_F(
'ChromeVoxMV2LibLouisTest',
'BackTranslateUSEnglishGrade2PreservesTrailingSpace', async function() {
// A full braille cell (dots 1-6) is 'for' when backtranslated.
const cells = new Uint8Array([0b111111, 0]);
const text = await this.backTranslate('en-ueb-g2.ctb', cells.buffer);
assertNotEquals(null, text);
assertEquals('for ', text);
});
AX_TEST_F(
'ChromeVoxMV2LibLouisTest', 'BackTranslateEmptyCells', async function() {
const text =
await this.backTranslate('de-de-comp8.ctb', new Uint8Array().buffer);
assertNotEquals(null, text);
assertEquals(0, text.length);
});
AX_TEST_F('ChromeVoxMV2LibLouisTest', 'GetInvalidTranslator', async function() {
console.log('Expecting an error from liblouis');
const translator = await this.liblouis.getTranslator('nonexistant-table');
assertEquals(null, translator);
});
AX_TEST_F('ChromeVoxMV2LibLouisTest', 'KeyEventStaticData', async function() {
const [cells, textToBraille, brailleToText] = await this.translate(
'en-us-comp8.ctb', 'abcdefghijklmnopqrstuvwxyz 0123456789');
// A-Z.
const view = new Uint8Array(cells);
for (let i = 0; i < 26; i++) {
assertEquals(
String.fromCharCode(i + 65),
BrailleKeyEvent.brailleDotsToStandardKeyCode[view[i]]);
}
// 0-9.
for (let i = 27; i < 37; i++) {
assertEquals(
String.fromCharCode(i + 21),
BrailleKeyEvent.brailleDotsToStandardKeyCode[view[i]]);
}
});
|