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