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

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

Issue 2362673004: Aligns text to braille in chromevox. (Closed)
Patch Set: fixed test Created 4 years, 2 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/fake_objects.js']); 7 '../testing/fake_objects.js']);
8 8
9 /** 9 /**
10 * Test fixture. 10 * Test fixture.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 * Asserts that the last written display content is an empty buffer of 84 * Asserts that the last written display content is an empty buffer of
85 * of cells and clears the list of written cells. 85 * of cells and clears the list of written cells.
86 * There must be only one buffer in the list. 86 * There must be only one buffer in the list.
87 */ 87 */
88 assertEmptyDisplayAndClear: function() { 88 assertEmptyDisplayAndClear: function() {
89 assertEquals(1, this.writtenCells.length); 89 assertEquals(1, this.writtenCells.length);
90 var content = this.writtenCells[0]; 90 var content = this.writtenCells[0];
91 this.writtenCells.length = 0; 91 this.writtenCells.length = 0;
92 assertTrue(content instanceof ArrayBuffer); 92 assertTrue(content instanceof ArrayBuffer);
93 assertTrue(content.byteLength == 0); 93 assertTrue(content.byteLength == 0);
94 },
95
96 /**
97 * Asserts that the groups passed in actually match what we expect.
98 */
99 assertGroupsValid: function(groups, expected) {
100 assertEquals(JSON.stringify(groups), JSON.stringify(expected));
94 } 101 }
95 }; 102 };
96 103
97 /** @extends {cvox.ExpandingBrailleTranslator} */ 104 /** @extends {cvox.ExpandingBrailleTranslator} */
98 function FakeTranslator() { 105 function FakeTranslator() {
99 } 106 }
100 107
101 FakeTranslator.prototype = { 108 FakeTranslator.prototype = {
102 /** 109 /**
103 * Does a translation where every other character becomes two cells. 110 * Does a translation where every other character becomes two cells.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 this.addFakeApi(); 185 this.addFakeApi();
179 this.displayState = {available: false}; 186 this.displayState = {available: false};
180 187
181 var manager = new cvox.BrailleDisplayManager(this.translatorManager); 188 var manager = new cvox.BrailleDisplayManager(this.translatorManager);
182 manager.setContent(this.NAV_BRAILLE); 189 manager.setContent(this.NAV_BRAILLE);
183 this.translatorManager.setTranslator(this.translator); 190 this.translatorManager.setTranslator(this.translator);
184 manager.setContent(this.NAV_BRAILLE); 191 manager.setContent(this.NAV_BRAILLE);
185 assertEquals(0, this.writtenCells.length); 192 assertEquals(0, this.writtenCells.length);
186 }); 193 });
187 194
188
189 /** 195 /**
190 * Tests the typical sequence: setContent, setTranslator, setContent. 196 * Tests the typical sequence: setContent, setTranslator, setContent.
191 */ 197 */
192 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'BasicSetContent', function() { 198 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'BasicSetContent', function() {
193 this.addFakeApi(); 199 this.addFakeApi();
194 this.displayAvailable(); 200 this.displayAvailable();
195 var manager = new cvox.BrailleDisplayManager(this.translatorManager); 201 var manager = new cvox.BrailleDisplayManager(this.translatorManager);
196 this.assertEmptyDisplayAndClear(); 202 this.assertEmptyDisplayAndClear();
197 manager.setContent(this.NAV_BRAILLE); 203 manager.setContent(this.NAV_BRAILLE);
198 this.assertEmptyDisplayAndClear(); 204 this.assertEmptyDisplayAndClear();
199 this.translatorManager.setTranslator(this.translator); 205 this.translatorManager.setTranslator(this.translator);
200 this.assertDisplayPositionAndClear(0); 206 this.assertDisplayPositionAndClear(0);
201 manager.setContent(this.NAV_BRAILLE); 207 manager.setContent(this.NAV_BRAILLE);
202 this.assertDisplayPositionAndClear(0); 208 this.assertDisplayPositionAndClear(0);
203 }); 209 });
204 210
205
206 /** 211 /**
207 * Tests that setting empty content clears the display. 212 * Tests that setting empty content clears the display.
208 */ 213 */
209 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'SetEmptyContentWithTranslator', 214 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'SetEmptyContentWithTranslator',
210 function() { 215 function() {
211 this.addFakeApi(); 216 this.addFakeApi();
212 this.displayAvailable(); 217 this.displayAvailable();
213 218
214 var manager = new cvox.BrailleDisplayManager(this.translatorManager); 219 var manager = new cvox.BrailleDisplayManager(this.translatorManager);
215 this.assertEmptyDisplayAndClear(); 220 this.assertEmptyDisplayAndClear();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 2 * this.DISPLAY_SIZE, 253 2 * this.DISPLAY_SIZE,
249 translatedSize % this.DISPLAY_SIZE); 254 translatedSize % this.DISPLAY_SIZE);
250 // Selection from the end of what fits on the first display to the end of the 255 // Selection from the end of what fits on the first display to the end of the
251 // line. 256 // line.
252 manager.setContent(createNavBrailleWithCursor(7, text.length)); 257 manager.setContent(createNavBrailleWithCursor(7, text.length));
253 this.assertDisplayPositionAndClear(0, 10, this.DISPLAY_SIZE); 258 this.assertDisplayPositionAndClear(0, 10, this.DISPLAY_SIZE);
254 // Selection on all of the line. 259 // Selection on all of the line.
255 manager.setContent(createNavBrailleWithCursor(0, text.length)); 260 manager.setContent(createNavBrailleWithCursor(0, text.length));
256 this.assertDisplayPositionAndClear(0, 0, this.DISPLAY_SIZE); 261 this.assertDisplayPositionAndClear(0, 0, this.DISPLAY_SIZE);
257 }); 262 });
263
264 /**
265 * Tests that the grouping algorithm works with one text character that maps
266 * to one braille cell.
267 */
268 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'BasicGroup', function() {
269 var text = 'a';
270 var translated = '1';
271 var mapping = [0];
272 var expected = [['a','1']];
273
274 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(
275 translated, text, mapping);
276 this.assertGroupsValid(groups, expected);
277 });
278
279 /**
280 * Tests that the grouping algorithm works with one text character that maps
281 * to multiple braille cells.
282 */
283 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneRtoManyB', function() {
284 var text = 'A';
285 var translated = '11';
286 var mapping = [0,0];
287 var expected = [['A', '11']];
288
289 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(
290 translated, text, mapping);
291 this.assertGroupsValid(groups, expected);
292 });
293
294 /**
295 * Tests that the grouping algorithm works with one braille cell that maps
296 * to multiple text characters.
297 */
298 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneBtoManyR', function() {
299 var text = 'knowledge';
300 var translated = '1';
301 var mapping = [0];
302 var expected = [['knowledge', '1']];
303
304 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(
305 translated, text, mapping);
306 this.assertGroupsValid(groups, expected);
307 });
308
309 /**
310 * Tests that the grouping algorithm works with one string that on both ends,
311 * have text characters that map to multiple braille cells.
312 */
313 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneRtoManyB_BothEnds', function() {
314 var text = 'AbbC';
315 var translated = 'X122X3';
316 var mapping = [0,0,1,2,3,3];
317 var expected = [['A', 'X1'], ['b', '2'],['b', '2'], ['C', 'X3']];
318
319 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(
320 translated, text, mapping);
321 this.assertGroupsValid(groups, expected);
322 });
323
324 /**
325 * Tests that the grouping algorithm works with one string that on both ends,
326 * have braille cells that map to multiple text characters.
327 */
328 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneBtoManyR_BothEnds', function() {
329 var text = 'knowledgehappych';
330 var translated = '1234456';
331 var mapping = [0, 9, 10, 11, 12, 13, 14];
332 var expected = [['knowledge', '1'], ['h', '2'], ['a', '3'], ['p', '4'],
333 ['p', '4'], ['y', '5'], ['ch', '6']];
334
335 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(translated,
336 text, mapping);
337 this.assertGroupsValid(groups, expected);
338 });
339
340 /**
341 * Tests that the grouping algorithm works with one string that has both types
342 * of mapping.
343 */
344 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'RandB_Random', function() {
345 var text = 'knowledgeIsPower';
346 var translated = '1X23X45678';
347 var mapping = [0, 9, 9, 10, 11, 11, 12, 13, 14, 15];
348 var expected = [['knowledge', '1'], ['I', 'X2'], ['s', '3'], ['P', 'X4'],
349 ['o', '5'], ['w', '6'], ['e', '7'], ['r', '8']];
350
351 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(
352 translated, text, mapping);
353 this.assertGroupsValid(groups, expected);
354 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698