OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 var pass = chrome.test.callbackPass; | 5 var pass = chrome.test.callbackPass; |
6 | 6 |
7 var TABLE_NAME = 'en-us-comp8.ctb'; | 7 var TABLE_NAME = 'en-us-comp8.ctb'; |
8 var TEXT = 'hello'; | 8 var TEXT = 'hello'; |
9 // Translation of the above string as a hexadecimal sequence of cells. | 9 // Translation of the above string as a hexadecimal sequence of cells. |
10 var CELLS = '1311070715'; | 10 var CELLS = '1311070715'; |
(...skipping 24 matching lines...) Expand all Loading... |
35 pendingCallback(reply); | 35 pendingCallback(reply); |
36 }, false /* useCapture */); | 36 }, false /* useCapture */); |
37 document.body.appendChild(embed); | 37 document.body.appendChild(embed); |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 function rpc(command, args, callback) { | 41 function rpc(command, args, callback) { |
42 var messageId = '' + nextMessageId++; | 42 var messageId = '' + nextMessageId++; |
43 args['command'] = command; | 43 args['command'] = command; |
44 args['message_id'] = messageId; | 44 args['message_id'] = messageId; |
45 var json = JSON.stringify(args) | 45 var json = JSON.stringify(args); |
46 console.log('Message to liblouis: ' + json); | 46 console.log('Message to liblouis: ' + json); |
47 naclEmbed.postMessage(json); | 47 naclEmbed.postMessage(json); |
48 pendingCallback = callback; | 48 pendingCallback = callback; |
49 pendingMessageId = messageId; | 49 pendingMessageId = messageId; |
50 } | 50 } |
51 | 51 |
52 | 52 |
53 function expectSuccessReply(callback) { | 53 function expectSuccessReply(callback) { |
54 return function(reply) { | 54 return function(reply) { |
55 chrome.test.assertEq(pendingMessageId, reply['in_reply_to']); | 55 chrome.test.assertEq(pendingMessageId, reply['in_reply_to']); |
(...skipping 13 matching lines...) Expand all Loading... |
69 pass(expectSuccessReply())); | 69 pass(expectSuccessReply())); |
70 }, | 70 }, |
71 | 71 |
72 function testTranslateString() { | 72 function testTranslateString() { |
73 rpc('Translate', { 'table_name': TABLE_NAME, 'text': TEXT}, | 73 rpc('Translate', { 'table_name': TABLE_NAME, 'text': TEXT}, |
74 pass(expectSuccessReply(function(reply) { | 74 pass(expectSuccessReply(function(reply) { |
75 chrome.test.assertEq(CELLS, reply['cells']); | 75 chrome.test.assertEq(CELLS, reply['cells']); |
76 }))); | 76 }))); |
77 }, | 77 }, |
78 | 78 |
| 79 // Regression test for the case where the translated result is more than |
| 80 // the double size of the input. In this particular case, a single capital |
| 81 // letter 'T' should be translated to 3 cells in US English grade 2 |
| 82 // braille (dots 56, 6, 2345). |
| 83 function testTranslateGrade2SingleCapital() { |
| 84 rpc('Translate', { 'table_name': 'en-us-g2.ctb', 'text': 'T'}, |
| 85 pass(expectSuccessReply(function(reply) { |
| 86 chrome.test.assertEq('30201e', reply['cells']); |
| 87 }))); |
| 88 }, |
| 89 |
79 function testBackTranslateString() { | 90 function testBackTranslateString() { |
80 rpc('BackTranslate', { 'table_name': TABLE_NAME, 'cells': CELLS}, | 91 rpc('BackTranslate', { 'table_name': TABLE_NAME, 'cells': CELLS}, |
81 pass(expectSuccessReply(function(reply) { | 92 pass(expectSuccessReply(function(reply) { |
82 chrome.test.assertEq(TEXT, reply['text']); | 93 chrome.test.assertEq(TEXT, reply['text']); |
83 }))); | 94 }))); |
84 }, | 95 }, |
85 ])}); | 96 ])}); |
OLD | NEW |