OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Include test fixture. |
| 6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']); |
| 7 |
| 8 /** |
| 9 * Test fixture. |
| 10 * @constructor |
| 11 * @extends {ChromeVoxUnitTestBase} |
| 12 */ |
| 13 function CvoxStructuralLineWalkerUnitTest() {} |
| 14 |
| 15 CvoxStructuralLineWalkerUnitTest.prototype = { |
| 16 __proto__: ChromeVoxUnitTestBase.prototype, |
| 17 |
| 18 /** @override */ |
| 19 closureModuleDeps: [ |
| 20 'cvox.BrailleUtil', |
| 21 'cvox.StructuralLineWalker', |
| 22 'cvox.TestMsgs', |
| 23 ], |
| 24 |
| 25 /** @override */ |
| 26 setUp: function() { |
| 27 this.loadDoc(function() {/*! |
| 28 <a id='1' href='google.com'>Click Here</a> |
| 29 <p id='2'>This is some text that will wrap within the browser; when using |
| 30 line granularity, moving through this text will speak and braille every |
| 31 visual line. This text will break |
| 32 immediately here! |
| 33 <a href='google.com'>And here!</a> |
| 34 </p> |
| 35 */}); |
| 36 |
| 37 cvox.ChromeVox.msgs = new cvox.TestMsgs(); |
| 38 |
| 39 this.walker_ = new cvox.StructuralLineWalker(); |
| 40 }, |
| 41 }; |
| 42 |
| 43 TEST_F('CvoxStructuralLineWalkerUnitTest', 'BrailleLine', function() { |
| 44 var aLink = $('1'); |
| 45 var aLinkSel1 = this.walker_.sync(cvox.CursorSelection.fromNode(aLink)); |
| 46 assertEquals('Click Here lnk', |
| 47 this.walker_.getBraille(aLinkSel1, aLinkSel1).text.toString()); |
| 48 |
| 49 var aPSel1 = this.walker_.next(aLinkSel1); |
| 50 assertEquals('This is some text that will wrap within the browser; when' + |
| 51 ' using line granularity, moving through this text will speak and' + |
| 52 ' braille every visual line. This text will break', |
| 53 this.walker_.getBraille(aLinkSel1, aPSel1).text.toString()); |
| 54 |
| 55 var aPSel2 = this.walker_.next(aPSel1); |
| 56 assertEquals('immediately here!', |
| 57 this.walker_.getBraille(aPSel1, aPSel2).text.toString()); |
| 58 |
| 59 aLinkSel2 = this.walker_.next(aPSel2); |
| 60 assertEquals('And here! lnk', |
| 61 this.walker_.getBraille(aPSel2, aLinkSel2).text.toString()); |
| 62 }); |
| 63 |
| 64 |
| 65 /** Tests sync'ing to a line in the middle of a paragraph. */ |
| 66 TEST_F('CvoxStructuralLineWalkerUnitTest', 'Sync', function() { |
| 67 var p1Sel = this.walker_.sync( |
| 68 cvox.CursorSelection.fromNode($('2'))); |
| 69 |
| 70 // The second structural line of the paragraph. |
| 71 var p2Sel = this.walker_.next(p1Sel); |
| 72 assertEquals(194, p2Sel.start.index); |
| 73 assertEquals(211, p2Sel.end.index); |
| 74 |
| 75 // Sync should never mutate a previously synced selection. |
| 76 assertTrue(p2Sel.equals(this.walker_.sync(p2Sel))); |
| 77 }); |
| 78 |
| 79 /** Tests syncing into an element treated as a leaf by TraverseUtil. */ |
| 80 TEST_F('CvoxStructuralLineWalkerUnitTest', 'SyncTraverseUtil', function() { |
| 81 this.loadDoc(function() {/*! |
| 82 <select id='leaf'> |
| 83 <option>apple |
| 84 <option>orange |
| 85 </select> |
| 86 */}); |
| 87 var leaf = $('leaf'); |
| 88 assertEquals('leaf', |
| 89 this.walker_.sync(cvox.CursorSelection.fromNode(leaf)).start.node.id); |
| 90 }); |
| 91 |
| 92 |
| 93 /** Tests specialized name calc with listitems with prefixes. */ |
| 94 TEST_F('CvoxStructuralLineWalkerUnitTest', 'ListitemPrefixes', function() { |
| 95 this.loadDoc(function() {/*! |
| 96 <ol> |
| 97 <li id='li_orange'>orange |
| 98 <li id='li_apple'>apple |
| 99 <li id='li_long'>========================================================= |
| 100 ================================================== hi long line here |
| 101 </li> |
| 102 </ol> |
| 103 */}); |
| 104 var li1 = $('li_orange'); |
| 105 var li2 = $('li_apple'); |
| 106 var li3 = $('li_long'); |
| 107 var li1Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li1)); |
| 108 var li2Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li2)); |
| 109 var li3Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li3)); |
| 110 var li3SelNext = this.walker_.next(li3Sel); |
| 111 |
| 112 assertEquals('1. orange', |
| 113 this.walker_.getDescription(li1Sel, li1Sel)[0].text); |
| 114 assertEquals('2. apple', this.walker_.getDescription(li2Sel, li2Sel)[0].text); |
| 115 assertEquals( |
| 116 '3. ========================================================= =====' + |
| 117 '============================================= hi long', |
| 118 this.walker_.getDescription(li3Sel, li3Sel)[0].text); |
| 119 assertEquals('line here', this.walker_.getDescription( |
| 120 li3SelNext, li3SelNext)[0].text.toString()); |
| 121 |
| 122 assertEquals('1. orange', |
| 123 this.walker_.getBraille(li1Sel, li1Sel).text.toString()); |
| 124 assertEquals('2. apple', |
| 125 this.walker_.getBraille(li2Sel, li2Sel).text.toString()); |
| 126 assertEquals( |
| 127 '3. ========================================================= =====' + |
| 128 '============================================= hi long', |
| 129 this.walker_.getBraille(li3Sel, li3Sel).text.toString()); |
| 130 assertEquals('line here', |
| 131 this.walker_.getBraille(li3SelNext, li3SelNext).text.toString()); |
| 132 }); |
OLD | NEW |