OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 /** |
| 6 * @fileoverview Tests for the liblouis Native Client wrapper, as seen from |
| 7 * the JavaScript interface. |
| 8 */ |
| 9 |
| 10 // Include test fixture. |
| 11 GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js', |
| 12 '../testing/assert_additions.js']); |
| 13 |
| 14 /** |
| 15 * @constructor |
| 16 * @extends {ChromeVoxE2ETest} |
| 17 */ |
| 18 function CvoxLibLouisTest() {} |
| 19 |
| 20 CvoxLibLouisTest.prototype = { |
| 21 __proto__: ChromeVoxE2ETest.prototype, |
| 22 |
| 23 /** @override */ |
| 24 setUp: function() { |
| 25 // Avoid loading a second liblouis instance and get the one that chromevox |
| 26 // is already creating. |
| 27 this.instance = cvox.ChromeVox.braille.getLibLouisForTest(); |
| 28 }, |
| 29 }; |
| 30 |
| 31 function assertEqualsUint8Array(expected, actual) { |
| 32 var as_array = []; |
| 33 var uint8array = new Uint8Array(actual); |
| 34 for (var i = 0; i < uint8array.length; ++i) { |
| 35 as_array[i] = uint8array[i]; |
| 36 } |
| 37 assertEqualsJSON(expected, as_array); |
| 38 } |
| 39 |
| 40 TEST_F('CvoxLibLouisTest', 'checkAllTables', function() { |
| 41 cvox.BrailleTable.getAll(function(all_tables) { |
| 42 var i = 0; |
| 43 var checkNextTable = function() { |
| 44 var table = all_tables[i++]; |
| 45 if (table) { |
| 46 this.instance.getTranslator(table.fileName, function(translator) { |
| 47 assertNotEquals(null, translator, |
| 48 'Table ' + table + ' should be valid'); |
| 49 checkNextTable(); |
| 50 }); |
| 51 } else { |
| 52 testDone(); |
| 53 } |
| 54 }.bind(this); |
| 55 checkNextTable(); |
| 56 }.bind(this)); |
| 57 }); |
| 58 |
| 59 TEST_F('CvoxLibLouisTest', 'testTranslateComputerBraille', function () { |
| 60 this.instance.getTranslator('en-us-comp8.ctb', function(translator) { |
| 61 translator.translate( |
| 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); |
| 66 testDone(); |
| 67 }); |
| 68 }); |
| 69 }); |
| 70 |
| 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); |
| 76 testDone(); |
| 77 }); |
| 78 }); |
| 79 }); |
| 80 |
| 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) { |
| 84 translator.translate( |
| 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); |
| 89 testDone(); |
| 90 }); |
| 91 }); |
| 92 }); |
| 93 |
| 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); |
| 99 testDone(); |
| 100 }); |
| 101 }); |
| 102 }); |
| 103 |
| 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); |
| 110 testDone(); |
| 111 }); |
| 112 }); |
| 113 }); |
| 114 |
| 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); |
| 120 testDone(); |
| 121 }); |
| 122 this.instance.attachToElement(document.body); |
| 123 }); |
| 124 |
| 125 TEST_F('CvoxLibLouisTest', 'testGetInvalidTranslator', function() { |
| 126 this.instance.getTranslator('nonexistant-table', function(translator) { |
| 127 assertEquals(null, translator); |
| 128 testDone(); |
| 129 }); |
| 130 }); |
OLD | NEW |