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
3 // found in the LICENSE file.
6 * @fileoverview Tests for the liblouis Native Client wrapper, as seen from
7 * the JavaScript interface.
10 // Include test fixture.
11 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js',
12 '../testing/assert_additions.js']);
16 * @extends {ChromeVoxE2ETest}
18 function CvoxLibLouisTest() {}
20 CvoxLibLouisTest.prototype = {
21 __proto__: ChromeVoxE2ETest.prototype,
25 // Avoid loading a second liblouis instance and get the one that chromevox
26 // is already creating.
27 this.instance = cvox.ChromeVox.braille.getLibLouisForTest();
31 function assertEqualsUint8Array(expected, actual) {
33 var uint8array = new Uint8Array(actual);
34 for (var i = 0; i < uint8array.length; ++i) {
35 as_array[i] = uint8array[i];
37 assertEqualsJSON(expected, as_array);
40 TEST_F('CvoxLibLouisTest', 'checkAllTables', function() {
41 cvox.BrailleTable.getAll(function(all_tables) {
43 var checkNextTable = function() {
44 var table = all_tables[i++];
46 this.instance.getTranslator(table.fileNames, function(translator) {
47 assertNotEquals(null, translator,
48 'Table ' + table + ' should be valid');
59 TEST_F('CvoxLibLouisTest', 'testTranslateComputerBraille', function () {
60 this.instance.getTranslator('en-us-comp8.ctb', function(translator) {
62 'Hello!', function(cells, textToBraille, brailleToText) {
63 assertEqualsUint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e], cells);
64 assertEqualsJSON([0, 1, 2, 3, 4, 5], textToBraille);
65 assertEqualsJSON([0, 1, 2, 3, 4, 5], brailleToText);
71 TEST_F('CvoxLibLouisTest', 'testBackTranslateComputerBraille', function() {
72 this.instance.getTranslator('en-us-comp8.ctb', function(translator) {
73 var cells = new Uint8Array([0x53, 0x11, 0x07, 0x07, 0x15, 0x2e]);
74 translator.backTranslate(cells.buffer, function(text) {
75 assertEquals('Hello!', text);
81 TEST_F('CvoxLibLouisTest', 'testTranslateGermanGrade2Braille', function() {
82 // This is one of the moderately large tables.
83 this.instance.getTranslator('de-de-g2.ctb', function(translator) {
85 'München', function(cells, textToBraille, brailleToText) {
86 assertEqualsUint8Array([0x0d, 0x33, 0x1d, 0x39, 0x09], cells);
87 assertEqualsJSON([0, 1, 2, 3, 3, 4, 4], textToBraille);
88 assertEqualsJSON([0, 1, 2, 3, 5], brailleToText);
94 TEST_F('CvoxLibLouisTest', 'testBackTranslateGermanComputerBraille', function() {
95 this.instance.getTranslator('de-de-comp8.ctb', function(translator) {
96 var cells = new Uint8Array([0xb3]);
97 translator.backTranslate(cells.buffer, function(text) {
98 assertEquals('ü', text);
104 TEST_F('CvoxLibLouisTest', 'testBackTranslateEmptyCells', function() {
105 this.instance.getTranslator('de-de-comp8.ctb', function(translator) {
106 var cells = new Uint8Array();
107 translator.backTranslate(cells.buffer, function(text) {
108 assertNotEquals(null, text);
109 assertEquals(0, text.length);
115 TEST_F('CvoxLibLouisTest', 'testGetTranslatorBeforeAttach', function() {
116 this.instance.detach();
117 assertFalse(this.instance.isAttached());
118 this.instance.getTranslator('en-us-comp8.ctb', function(translator) {
119 assertNotEquals(null, translator);
122 this.instance.attachToElement(document.body);
125 TEST_F('CvoxLibLouisTest', 'testGetInvalidTranslator', function() {
126 this.instance.getTranslator('nonexistant-table', function(translator) {
127 assertEquals(null, translator);