Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(944)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/braille/expanding_braille_translator_test.unitjs

Issue 889593002: Refactorings to reduce dependencies in ChromeVox 2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Readd missing dep and add a new one that should've been there already. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 '../testing/assert_additions.js']); 7 '../testing/assert_additions.js']);
8 8
9 /** 9 /**
10 * Test fixture. 10 * Test fixture.
11 * @constructor 11 * @constructor
12 * @extends {ChromeVoxUnitTestBase} 12 * @extends {ChromeVoxUnitTestBase}
13 */ 13 */
14 function CvoxExpandingBrailleTranslatorUnitTest() {} 14 function CvoxExpandingBrailleTranslatorUnitTest() {}
15 15
16 CvoxExpandingBrailleTranslatorUnitTest.prototype = { 16 CvoxExpandingBrailleTranslatorUnitTest.prototype = {
17 __proto__: ChromeVoxUnitTestBase.prototype, 17 __proto__: ChromeVoxUnitTestBase.prototype,
18 18
19 /** @override */ 19 /** @override */
20 closureModuleDeps: [ 20 closureModuleDeps: [
21 'cvox.BrailleUtil',
22 'cvox.ExpandingBrailleTranslator', 21 'cvox.ExpandingBrailleTranslator',
23 'cvox.LibLouis', 22 'cvox.LibLouis',
24 'cvox.Spannable', 23 'cvox.Spannable',
24 'cvox.ValueSelectionSpan',
25 'cvox.ValueSpan',
25 ] 26 ]
26 }; 27 };
27 28
28 /** 29 /**
29 * An implementation of {@link cvox.LibLouis.Translator} whose translation 30 * An implementation of {@link cvox.LibLouis.Translator} whose translation
30 * output is an array buffer of the same byte length as the input and where 31 * output is an array buffer of the same byte length as the input and where
31 * each byte is equal to the character code of {@code resultChar}. The 32 * each byte is equal to the character code of {@code resultChar}. The
32 * position mappings are one to one in both directions. 33 * position mappings are one to one in both directions.
33 * @param {string} resultChar A one character string used for each byte of the 34 * @param {string} resultChar A one character string used for each byte of the
34 * result. 35 * result.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 assertTrue(actual instanceof ArrayBuffer); 67 assertTrue(actual instanceof ArrayBuffer);
67 var a = new Uint8Array(actual); 68 var a = new Uint8Array(actual);
68 assertEquals(expected.length, a.length); 69 assertEquals(expected.length, a.length);
69 for (var i = 0; i < a.length; ++i) { 70 for (var i = 0; i < a.length; ++i) {
70 assertEquals(expected.charCodeAt(i), a[i], 'Position ' + i); 71 assertEquals(expected.charCodeAt(i), a[i], 'Position ' + i);
71 } 72 }
72 } 73 }
73 74
74 TEST_F('CvoxExpandingBrailleTranslatorUnitTest', 'TranslationError', 75 TEST_F('CvoxExpandingBrailleTranslatorUnitTest', 'TranslationError',
75 function() { 76 function() {
76 var text = new cvox.Spannable('error ok', new cvox.BrailleUtil.ValueSpan()); 77 var text = new cvox.Spannable('error ok', new cvox.ValueSpan());
77 text.setSpan(new cvox.BrailleUtil.ValueSelectionSpan, 0, 0); 78 text.setSpan(new cvox.ValueSelectionSpan, 0, 0);
78 var contractedTranslator = new FakeTranslator('c'); 79 var contractedTranslator = new FakeTranslator('c');
79 // Translator that always results in an error. 80 // Translator that always results in an error.
80 var uncontractedTranslator = { 81 var uncontractedTranslator = {
81 translate: function(text, callback) { 82 translate: function(text, callback) {
82 callback(null, null, null); 83 callback(null, null, null);
83 } 84 }
84 }; 85 };
85 var translationResult = null; 86 var translationResult = null;
86 87
87 var expandingTranslator = new cvox.ExpandingBrailleTranslator( 88 var expandingTranslator = new cvox.ExpandingBrailleTranslator(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 /** 193 /**
193 * Creates a spannable text with optional selection. 194 * Creates a spannable text with optional selection.
194 * @param {string} text The text. 195 * @param {string} text The text.
195 * @param {=opt_selectionStart} Selection start or caret position. No 196 * @param {=opt_selectionStart} Selection start or caret position. No
196 * selection is added if undefined. 197 * selection is added if undefined.
197 * @param {=opt_selectionEnd} Selection end if selection is not a caret. 198 * @param {=opt_selectionEnd} Selection end if selection is not a caret.
198 */ 199 */
199 function createText(text, opt_selectionStart, opt_selectionEnd) { 200 function createText(text, opt_selectionStart, opt_selectionEnd) {
200 var result = new cvox.Spannable(text); 201 var result = new cvox.Spannable(text);
201 202
202 result.setSpan( 203 result.setSpan(new cvox.ValueSpan, 0, text.length);
203 new cvox.BrailleUtil.ValueSpan, 0, text.length);
204 if (goog.isDef(opt_selectionStart)) { 204 if (goog.isDef(opt_selectionStart)) {
205 result.setSpan( 205 result.setSpan(
206 new cvox.BrailleUtil.ValueSelectionSpan, 206 new cvox.ValueSelectionSpan,
207 opt_selectionStart, 207 opt_selectionStart,
208 goog.isDef(opt_selectionEnd) ? opt_selectionEnd : opt_selectionStart); 208 goog.isDef(opt_selectionEnd) ? opt_selectionEnd : opt_selectionStart);
209 } 209 }
210 return result; 210 return result;
211 } 211 }
212 212
213 213
214 var TEXT = 'Hello, world!'; 214 var TEXT = 'Hello, world!';
215 215
216 TEST_F('CvoxExpandingBrailleTranslatorUnitTest', 'successfulTranslations', 216 TEST_F('CvoxExpandingBrailleTranslatorUnitTest', 'successfulTranslations',
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 for (var i = 0, testCase; testCase = TESTDATA[i]; ++i) { 255 for (var i = 0, testCase; testCase = TESTDATA[i]; ++i) {
256 runTranslationTestVariants(testCase, false, expType.SELECTION); 256 runTranslationTestVariants(testCase, false, expType.SELECTION);
257 runTranslationTestVariants(testCase, true, expType.NONE); 257 runTranslationTestVariants(testCase, true, expType.NONE);
258 runTranslationTestVariants(testCase, true, expType.SELECTION); 258 runTranslationTestVariants(testCase, true, expType.SELECTION);
259 runTranslationTestVariants(testCase, true, expType.ALL); 259 runTranslationTestVariants(testCase, true, expType.ALL);
260 } 260 }
261 // Make sure that the logic above runs the tests, adjust when adding more 261 // Make sure that the logic above runs the tests, adjust when adding more
262 // tests. 262 // tests.
263 assertEquals(64, totalRunTranslationTests); 263 assertEquals(64, totalRunTranslationTests);
264 }); 264 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698