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.
5 // Include test fixture.
6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']);
11 * @extends {ChromeVoxUnitTestBase}
13 function CvoxStructuralLineWalkerUnitTest() {}
15 CvoxStructuralLineWalkerUnitTest.prototype = {
16 __proto__: ChromeVoxUnitTestBase.prototype,
20 'cvox.StructuralLineWalker',
26 this.loadDoc(function() {/*!
27 <a id='1' href='google.com'>Click Here</a>
28 <pre id='2'>This text will break
30 <a href='google.com'>And here!</a>
34 cvox.ChromeVox.msgs = new cvox.TestMsgs();
36 this.walker_ = new cvox.StructuralLineWalker();
40 TEST_F('CvoxStructuralLineWalkerUnitTest', 'BrailleLine', function() {
42 var aLinkSel1 = this.walker_.sync(cvox.CursorSelection.fromNode(aLink));
43 assertEquals('Click Here lnk',
44 this.walker_.getBraille(aLinkSel1, aLinkSel1).text.toString());
46 var aPSel1 = this.walker_.next(aLinkSel1);
47 assertEquals('This text will break',
48 this.walker_.getBraille(aLinkSel1, aPSel1).text.toString());
50 var aPSel2 = this.walker_.next(aPSel1);
51 assertEquals('immediately here!',
52 this.walker_.getBraille(aPSel1, aPSel2).text.toString());
54 aLinkSel2 = this.walker_.next(aPSel2);
55 assertEquals('And here! lnk',
56 this.walker_.getBraille(aPSel2, aLinkSel2).text.toString());
60 /** Tests sync'ing to a line in the middle of a paragraph. */
61 TEST_F('CvoxStructuralLineWalkerUnitTest', 'Sync', function() {
62 var p1Sel = this.walker_.sync(
63 cvox.CursorSelection.fromNode($('2')));
65 // The second structural line of the paragraph.
66 var p2Sel = this.walker_.next(p1Sel);
67 assertEquals(29, p2Sel.start.index);
68 assertEquals(46, p2Sel.end.index);
70 // Sync should never mutate a previously synced selection.
71 assertTrue(p2Sel.equals(this.walker_.sync(p2Sel)));
74 /** Tests syncing into an element treated as a leaf by TraverseUtil. */
75 TEST_F('CvoxStructuralLineWalkerUnitTest', 'SyncTraverseUtil', function() {
76 this.loadDoc(function() {/*!
84 this.walker_.sync(cvox.CursorSelection.fromNode(leaf)).start.node.id);
88 /** Tests specialized name calc with listitems with prefixes. */
89 TEST_F('CvoxStructuralLineWalkerUnitTest', 'ListitemPrefixes', function() {
90 this.loadDoc(function() {/*!
92 <li id='li_orange'>orange
93 <li id='li_apple'>apple
94 <li id='li_long'>hi broken<br>line here
97 var li1 = $('li_orange');
98 var li2 = $('li_apple');
99 var li3 = $('li_long');
100 var li1Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li1));
101 var li2Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li2));
102 var li3Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li3));
103 var li3SelNext = this.walker_.next(li3Sel);
105 assertEquals('1. orange',
106 this.walker_.getDescription(li1Sel, li1Sel)[0].text);
107 assertEquals('2. apple', this.walker_.getDescription(li2Sel, li2Sel)[0].text);
110 this.walker_.getDescription(li3Sel, li3Sel)[0].text);
111 assertEquals('line here', this.walker_.getDescription(
112 li3SelNext, li3SelNext)[0].text.toString());
114 assertEquals('1. orange',
115 this.walker_.getBraille(li1Sel, li1Sel).text.toString());
116 assertEquals('2. apple',
117 this.walker_.getBraille(li2Sel, li2Sel).text.toString());
120 this.walker_.getBraille(li3Sel, li3Sel).text.toString());
121 assertEquals('line here',
122 this.walker_.getBraille(li3SelNext, li3SelNext).text.toString());