OLD | NEW |
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 // Include test fixture. | 5 // Include test fixture. |
6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']); | 6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']); |
7 | 7 |
8 GEN_INCLUDE(['../testing/fake_objects.js']); | 8 GEN_INCLUDE(['../testing/fake_objects.js']); |
9 | 9 |
10 // Fake out the Chrome API namespace we depend on. | 10 // Fake out the Chrome API namespace we depend on. |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 /** @type {FakeChromeEvent} */ | 259 /** @type {FakeChromeEvent} */ |
260 this.onMessage = new FakeChromeEvent(); | 260 this.onMessage = new FakeChromeEvent(); |
261 /** @type {string} */ | 261 /** @type {string} */ |
262 this.name = cvox.BrailleInputHandler.IME_PORT_NAME_; | 262 this.name = cvox.BrailleInputHandler.IME_PORT_NAME_; |
263 /** @type {{id: string}} */ | 263 /** @type {{id: string}} */ |
264 this.sender = {id: cvox.BrailleInputHandler.IME_EXTENSION_ID_}; | 264 this.sender = {id: cvox.BrailleInputHandler.IME_EXTENSION_ID_}; |
265 } | 265 } |
266 | 266 |
267 /** | 267 /** |
268 * Mapping from braille cells to Unicode characters. | 268 * Mapping from braille cells to Unicode characters. |
269 * @const Array.<Array.<string> > | 269 * @const Array<Array<string> > |
270 */ | 270 */ |
271 var UNCONTRACTED_TABLE = [ | 271 var UNCONTRACTED_TABLE = [ |
272 ['0', ' '], | 272 ['0', ' '], |
273 ['1', 'a'], ['12', 'b'], ['14', 'c'], ['145', 'd'], ['15', 'e'], | 273 ['1', 'a'], ['12', 'b'], ['14', 'c'], ['145', 'd'], ['15', 'e'], |
274 ['124', 'f'], ['1245', 'g'], ['125', 'h'], ['24', 'i'], ['245', 'j'], | 274 ['124', 'f'], ['1245', 'g'], ['125', 'h'], ['24', 'i'], ['245', 'j'], |
275 ['13', 'k'], ['123', 'l'], ['134', 'm'], ['1345', 'n'], ['135', 'o'], | 275 ['13', 'k'], ['123', 'l'], ['134', 'm'], ['1345', 'n'], ['135', 'o'], |
276 ['1234', 'p'], ['12345', 'q'], ['1235', 'r'], ['234', 's'], ['2345', 't'] | 276 ['1234', 'p'], ['12345', 'q'], ['1235', 'r'], ['234', 's'], ['2345', 't'] |
277 ]; | 277 ]; |
278 | 278 |
279 | 279 |
280 /** | 280 /** |
281 * Mapping of braille cells to the corresponding word in Grade 2 US English | 281 * Mapping of braille cells to the corresponding word in Grade 2 US English |
282 * braille. This table also includes the uncontracted table above. | 282 * braille. This table also includes the uncontracted table above. |
283 * If a match 'pattern' starts with '^', it must be at the beginning of | 283 * If a match 'pattern' starts with '^', it must be at the beginning of |
284 * the string or be preceded by a blank cell. Similarly, '$' at the end | 284 * the string or be preceded by a blank cell. Similarly, '$' at the end |
285 * of a 'pattern' means that the match must be at the end of the string | 285 * of a 'pattern' means that the match must be at the end of the string |
286 * or be followed by a blank cell. Note that order is significant in the | 286 * or be followed by a blank cell. Note that order is significant in the |
287 * table. First match wins. | 287 * table. First match wins. |
288 * @const | 288 * @const |
289 */ | 289 */ |
290 var CONTRACTED_TABLE = [ | 290 var CONTRACTED_TABLE = [ |
291 ['12 1235 123', 'braille'], | 291 ['12 1235 123', 'braille'], |
292 ['^12$', 'but'], | 292 ['^12$', 'but'], |
293 ['1456', 'this']].concat(UNCONTRACTED_TABLE); | 293 ['1456', 'this']].concat(UNCONTRACTED_TABLE); |
294 | 294 |
295 /** | 295 /** |
296 * A fake braille translator that can do back translation according | 296 * A fake braille translator that can do back translation according |
297 * to one of the tables above. | 297 * to one of the tables above. |
298 * @param {Array.<Array.<number>>} table Backtranslation mapping. | 298 * @param {Array<Array<number>>} table Backtranslation mapping. |
299 * @param {boolean=} opt_capitalize Whether the result should be capitalized. | 299 * @param {boolean=} opt_capitalize Whether the result should be capitalized. |
300 * @constructor | 300 * @constructor |
301 */ | 301 */ |
302 function FakeTranslator(table, opt_capitalize) { | 302 function FakeTranslator(table, opt_capitalize) { |
303 /** @private */ | 303 /** @private */ |
304 this.table_ = table.map(function(entry) { | 304 this.table_ = table.map(function(entry) { |
305 var cells = entry[0]; | 305 var cells = entry[0]; |
306 var result = []; | 306 var result = []; |
307 if (cells[0] === '^') { | 307 if (cells[0] === '^') { |
308 result.start = true; | 308 result.start = true; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 395 } |
396 } | 396 } |
397 }; | 397 }; |
398 | 398 |
399 /** | 399 /** |
400 * Converts a list of cells, represented as a string, to an array. | 400 * Converts a list of cells, represented as a string, to an array. |
401 * @param {string} cells A string with space separated groups of digits. | 401 * @param {string} cells A string with space separated groups of digits. |
402 * Each group corresponds to one braille cell and each digit in a group | 402 * Each group corresponds to one braille cell and each digit in a group |
403 * corresponds to a particular dot in the cell (1 to 8). As a special | 403 * corresponds to a particular dot in the cell (1 to 8). As a special |
404 * case, the digit 0 by itself represents a blank cell. | 404 * case, the digit 0 by itself represents a blank cell. |
405 * @return {Array.<number>} An array with each cell encoded as a bit | 405 * @return {Array<number>} An array with each cell encoded as a bit |
406 * pattern (dot 1 uses bit 0, etc). | 406 * pattern (dot 1 uses bit 0, etc). |
407 */ | 407 */ |
408 function cellsToArray(cells) { | 408 function cellsToArray(cells) { |
409 if (!cells) | 409 if (!cells) |
410 return []; | 410 return []; |
411 return cells.split(/\s+/).map(function(cellString) { | 411 return cells.split(/\s+/).map(function(cellString) { |
412 var cell = 0; | 412 var cell = 0; |
413 assertTrue(cellString.length > 0); | 413 assertTrue(cellString.length > 0); |
414 if (cellString != '0') { | 414 if (cellString != '0') { |
415 for (var i = 0; i < cellString.length; ++i) { | 415 for (var i = 0; i < cellString.length; ++i) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 | 689 |
690 | 690 |
691 TEST_F('CvoxBrailleInputHandlerUnitTest', 'KeysImeNotActive', function() { | 691 TEST_F('CvoxBrailleInputHandlerUnitTest', 'KeysImeNotActive', function() { |
692 var editor = this.createEditor(); | 692 var editor = this.createEditor(); |
693 this.sendKeyEvent('Enter'); | 693 this.sendKeyEvent('Enter'); |
694 this.sendKeyEvent('ArrowUp'); | 694 this.sendKeyEvent('ArrowUp'); |
695 assertEqualsJSON([{keyCode: 13, keyName: 'Enter', charValue: 0x0A}, | 695 assertEqualsJSON([{keyCode: 13, keyName: 'Enter', charValue: 0x0A}, |
696 {keyCode: 38, keyName: 'ArrowUp', charValue: 0x41}], | 696 {keyCode: 38, keyName: 'ArrowUp', charValue: 0x41}], |
697 this.keyEvents); | 697 this.keyEvents); |
698 }); | 698 }); |
OLD | NEW |