Chromium Code Reviews| 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 '../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 Loading... | |
| 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 last written display content is an empty buffer of | |
|
dmazzoni
2016/10/04 22:34:30
Update this comment
ultimatedbz
2016/10/08 01:00:44
Done.
| |
| 98 * of cells and clears the list of written cells. | |
| 99 * There must be only one buffer in the list. | |
| 100 */ | |
| 101 assertGroupValid: function(groups, expected) { | |
|
dmazzoni
2016/10/04 22:34:30
Maybe assertGroupsValid?
ultimatedbz
2016/10/08 01:00:44
Done.
| |
| 102 assertEquals(JSON.stringify(groups), JSON.stringify(expected)); | |
| 94 } | 103 } |
| 95 }; | 104 }; |
| 96 | 105 |
| 97 /** @extends {cvox.ExpandingBrailleTranslator} */ | 106 /** @extends {cvox.ExpandingBrailleTranslator} */ |
| 98 function FakeTranslator() { | 107 function FakeTranslator() { |
| 99 } | 108 } |
| 100 | 109 |
| 101 FakeTranslator.prototype = { | 110 FakeTranslator.prototype = { |
| 102 /** | 111 /** |
| 103 * Does a translation where every other character becomes two cells. | 112 * Does a translation where every other character becomes two cells. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 this.assertEmptyDisplayAndClear(); | 205 this.assertEmptyDisplayAndClear(); |
| 197 manager.setContent(this.NAV_BRAILLE); | 206 manager.setContent(this.NAV_BRAILLE); |
| 198 this.assertEmptyDisplayAndClear(); | 207 this.assertEmptyDisplayAndClear(); |
| 199 this.translatorManager.setTranslator(this.translator); | 208 this.translatorManager.setTranslator(this.translator); |
| 200 this.assertDisplayPositionAndClear(0); | 209 this.assertDisplayPositionAndClear(0); |
| 201 manager.setContent(this.NAV_BRAILLE); | 210 manager.setContent(this.NAV_BRAILLE); |
| 202 this.assertDisplayPositionAndClear(0); | 211 this.assertDisplayPositionAndClear(0); |
| 203 }); | 212 }); |
| 204 | 213 |
| 205 | 214 |
| 215 | |
|
dmazzoni
2016/10/04 22:34:30
Nit: get rid of extra blank line
| |
| 206 /** | 216 /** |
| 207 * Tests that setting empty content clears the display. | 217 * Tests that setting empty content clears the display. |
| 208 */ | 218 */ |
| 209 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'SetEmptyContentWithTranslator', | 219 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'SetEmptyContentWithTranslator', |
| 210 function() { | 220 function() { |
| 211 this.addFakeApi(); | 221 this.addFakeApi(); |
| 212 this.displayAvailable(); | 222 this.displayAvailable(); |
| 213 | 223 |
| 214 var manager = new cvox.BrailleDisplayManager(this.translatorManager); | 224 var manager = new cvox.BrailleDisplayManager(this.translatorManager); |
| 215 this.assertEmptyDisplayAndClear(); | 225 this.assertEmptyDisplayAndClear(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 2 * this.DISPLAY_SIZE, | 258 2 * this.DISPLAY_SIZE, |
| 249 translatedSize % this.DISPLAY_SIZE); | 259 translatedSize % this.DISPLAY_SIZE); |
| 250 // Selection from the end of what fits on the first display to the end of the | 260 // Selection from the end of what fits on the first display to the end of the |
| 251 // line. | 261 // line. |
| 252 manager.setContent(createNavBrailleWithCursor(7, text.length)); | 262 manager.setContent(createNavBrailleWithCursor(7, text.length)); |
| 253 this.assertDisplayPositionAndClear(0, 10, this.DISPLAY_SIZE); | 263 this.assertDisplayPositionAndClear(0, 10, this.DISPLAY_SIZE); |
| 254 // Selection on all of the line. | 264 // Selection on all of the line. |
| 255 manager.setContent(createNavBrailleWithCursor(0, text.length)); | 265 manager.setContent(createNavBrailleWithCursor(0, text.length)); |
| 256 this.assertDisplayPositionAndClear(0, 0, this.DISPLAY_SIZE); | 266 this.assertDisplayPositionAndClear(0, 0, this.DISPLAY_SIZE); |
| 257 }); | 267 }); |
| 268 | |
| 269 /** | |
| 270 * Tests that the grouping algorithm works with one regular letter that maps | |
| 271 * to one braille letter. | |
|
dmazzoni
2016/10/04 22:34:30
Use "braille cell" instead of "braille letter", an
ultimatedbz
2016/10/08 01:00:44
Done.
| |
| 272 */ | |
| 273 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'BasicGroup', function() { | |
| 274 var text = 'a'; | |
| 275 var translated = '1'; | |
| 276 var mapping = [0]; | |
| 277 var expected = [['a','1']]; | |
| 278 | |
| 279 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(translated, te xt, mapping); | |
|
dmazzoni
2016/10/04 22:34:30
Wrap to 80 chars, here and in one or two other pla
| |
| 280 this.assertGroupValid(groups, expected); | |
| 281 }); | |
| 282 | |
| 283 /** | |
| 284 * Tests that the grouping algorithm works with one regular letter that maps | |
| 285 * to multiple braille letters. | |
| 286 */ | |
| 287 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneRtoManyB', function() { | |
| 288 var text = 'A'; | |
| 289 var translated = '11'; | |
| 290 var mapping = [0,0]; | |
| 291 var expected = [['A', '11']]; | |
| 292 | |
| 293 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(translated, te xt, mapping); | |
| 294 this.assertGroupValid(groups, expected); | |
| 295 }); | |
| 296 | |
| 297 /** | |
| 298 * Tests that the grouping algorithm works with one braille letter that maps | |
| 299 * to multiple regular letters. | |
| 300 */ | |
| 301 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneBtoManyR', function() { | |
| 302 var text = 'knowledge'; | |
| 303 var translated = '1'; | |
| 304 var mapping = [0]; | |
| 305 var expected = [['knowledge', '1']]; | |
| 306 | |
| 307 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(translated, te xt, mapping); | |
| 308 this.assertGroupValid(groups, expected); | |
| 309 }); | |
| 310 | |
| 311 /** | |
| 312 * Tests that the grouping algorithm works with one string that on both ends, | |
| 313 * have regular letters that map to multiple braille letters. | |
| 314 */ | |
| 315 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneRtoManyB_BothEnds', function() { | |
| 316 var text = 'AbbC'; | |
| 317 var translated = 'X122X3'; | |
| 318 var mapping = [0,0,1,2,3,3]; | |
| 319 var expected = [['A', 'X1'], ['b', '2'],['b', '2'], ['C', 'X3']]; | |
| 320 | |
| 321 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(translated, te xt, mapping); | |
| 322 this.assertGroupValid(groups, expected); | |
| 323 }); | |
| 324 | |
| 325 /** | |
| 326 * Tests that the grouping algorithm works with one string that on both ends, | |
| 327 * have braille letters that map to multiple regular letters. | |
| 328 */ | |
| 329 TEST_F('CvoxBrailleDisplayManagerUnitTest', 'OneBtoManyR_BothEnds', function() { | |
| 330 var text = 'knowledgehappych'; | |
| 331 var translated = '1234456'; | |
| 332 var mapping = [0, 9, 10, 11, 12, 13, 14]; | |
| 333 var expected = [['knowledge', '1'], ['h', '2'], ['a', '3'], ['p', '4'], | |
| 334 ['p', '4'], ['y', '5'], ['ch', '6']]; | |
| 335 | |
| 336 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(translated, te xt, mapping); | |
| 337 this.assertGroupValid(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'], ['o' , '5'], | |
| 349 ['w', '6'], ['e', '7'], ['r', '8']]; | |
| 350 | |
| 351 var groups = cvox.BrailleCaptionsBackground.groupBrailleAndText(translated, te xt, mapping); | |
| 352 this.assertGroupValid(groups, expected); | |
| 353 }); | |
| OLD | NEW |