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 CvoxLayoutLineWalkerUnitTest() {}
15 CvoxLayoutLineWalkerUnitTest.prototype = {
16 __proto__: ChromeVoxUnitTestBase.prototype,
20 'cvox.CursorSelection',
21 'cvox.LayoutLineWalker',
29 '<p id="a">Demonstrating that in-line links like ' +
30 '<a id="aa" href="google.com">google</a> ' +
31 'are considered a single layout line.' +
34 'This includes a paragraph that has a lot of text like this one. ' +
35 '<a id="bb" href="wikipedia.com">Wikipedia</a> ' +
36 'is a great example of a site that this walker becomes valuable.<br>' +
37 'Braille also benefits greatly from this type of formatting since ' +
38 'some displays can handle lots of text like 80 cell displays!' +
42 cvox.ChromeVox.msgs = new cvox.TestMsgs();
43 this.walker = new cvox.LayoutLineWalker();
45 this.a = cvox.CursorSelection.fromNode($('a'));
46 this.aa = cvox.CursorSelection.fromNode($('aa'));
47 this.b = cvox.CursorSelection.fromNode($('b'));
48 this.bb = cvox.CursorSelection.fromNode($('bb'));
50 this.line1Text = 'Demonstrating that in-line links like google are' +
51 ' considered a single layout line.';
53 this.line2Text = 'This includes a paragraph that has a lot of text' +
54 ' like this one. Wikipedia is a great example of a site that this' +
55 ' walker becomes valuable.';
58 'Braille also benefits greatly from this type of formatting since ' +
59 'some displays can handle lots of text like 80 cell displays!';
61 this.line1Description =
62 [{'context': '', 'text': 'Demonstrating that in-line links like',
63 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null,
64 'hint': '', 'category': null},
65 {'context': '', 'text': 'google', 'userValue': '', 'annotation': 'Link',
66 'earcons': [cvox.Earcon.LINK], 'personality': null,
67 hint: '', 'category': null},
68 {'context': '', 'text': 'are considered a single layout line.',
69 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null,
70 'hint': '', 'category': null}];
72 this.line2Description =
73 [{'context': '', 'text':
74 'This includes a paragraph that has a lot of text like this one.',
75 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null,
76 'hint': '', 'category': null},
81 'earcons': [cvox.Earcon.LINK],
83 'hint': '', 'category': null},
84 {'context': '', 'text':
85 'is a great example of a site that this walker becomes valuable.',
87 'annotation': '', 'earcons': [], 'personality': null,
88 'hint': '', 'category': null}];
92 TEST_F('CvoxLayoutLineWalkerUnitTest', 'Sync', function() {
93 var sel = cvox.CursorSelection.fromNode($('1'));
94 sel = this.walker.sync(sel);
95 assertEquals(this.line1Text, sel.getText());
97 sel = this.walker.sync(this.a);
98 assertEquals(this.line1Text, sel.getText());
100 sel = this.walker.sync(this.aa);
101 assertEquals(this.line1Text, sel.getText());
103 sel = this.walker.sync(this.b);
104 assertEquals(this.line2Text, sel.getText());
106 sel = this.walker.sync(this.bb);
107 assertEquals(this.line2Text, sel.getText());
110 sel = this.walker.sync(this.a).setReversed(true);
111 assertEquals(this.line1Text, sel.getText());
113 sel = this.walker.sync(this.aa).setReversed(true);
114 assertEquals(this.line1Text, sel.getText());
116 sel = this.walker.sync(this.b).setReversed(true);
117 assertEquals(this.line2Text, sel.getText());
119 sel = this.walker.sync(this.bb).setReversed(true);
120 assertEquals(this.line2Text, sel.getText());
123 /** Tests description of valid selections. */
124 TEST_F('CvoxLayoutLineWalkerUnitTest', 'Description', function() {
125 var sel = this.walker.sync(this.a);
126 assertEqualsJSON(this.line1Description,
127 this.walker.getDescription(sel, sel));
129 var sel = this.walker.sync(this.b);
130 assertEqualsJSON(this.line2Description, this.walker.getDescription(sel, sel));
134 /** Tests back/forward movement. */
135 TEST_F('CvoxLayoutLineWalkerUnitTest', 'BackForward', function() {
136 var sel = this.walker.sync(this.a);
138 // Beginning of second line.
139 sel = this.walker.next(sel);
140 assertEquals(Text, sel.start.node.constructor);
141 assertEquals(this.b.start.node.id, sel.start.node.parentNode.id);
142 assertEquals(null, sel.start.node.previousSibling);
143 assertEquals(this.bb.start.node.id, sel.start.node.nextSibling.id);
144 assertEquals(0, sel.start.index);
146 // End of second line.
147 assertEquals(Text, sel.end.node.constructor);
148 assertEquals(this.b.end.node.id, sel.end.node.parentNode.id);
149 assertEquals(HTMLBRElement, sel.end.node.nextSibling.constructor);
150 assertEquals(this.bb.start.node.id, sel.end.node.previousSibling.id);
151 assertEquals(64, sel.end.index);
154 var last = this.walker.next(sel);
155 assertEquals(this.line3Text, last.getText());
158 assertEquals(null, this.walker.next(last));
161 sel = last.setReversed(true);
164 sel = this.walker.next(sel);
165 assertEquals(this.line2Text, sel.getText());
167 // Next always returns an unreversed selection for line granularity. Reverse
168 // it to move backward.
169 sel.setReversed(true);
172 sel = this.walker.next(sel);
173 assertEquals(this.line1Text, sel.getText());
176 sel.setReversed(true);
177 sel = this.walker.next(sel);
178 assertEquals(null, sel);