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 CvoxLayoutLineWalkerUnitTest() {} 14 15CvoxLayoutLineWalkerUnitTest.prototype = { 16 __proto__: ChromeVoxUnitTestBase.prototype, 17 18 /** @override */ 19 closureModuleDeps: [ 20 'cvox.CursorSelection', 21 'cvox.LayoutLineWalker', 22 'cvox.TestMsgs', 23 ], 24 25 /** @override */ 26 setUp: function() { 27 this.loadHtml( 28 '<div id="1">' + 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.' + 32 '</p>' + 33 '<p id="b">' + 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!' + 39 '</p>' + 40 '</div>' 41 ); 42 cvox.ChromeVox.msgs = new cvox.TestMsgs(); 43 this.walker = new cvox.LayoutLineWalker(); 44 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')); 49 50 this.line1Text = 'Demonstrating that in-line links like google are' + 51 ' considered a single layout line.'; 52 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.'; 56 57 this.line3Text = 58 'Braille also benefits greatly from this type of formatting since ' + 59 'some displays can handle lots of text like 80 cell displays!'; 60 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.AbstractEarcons.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}]; 71 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}, 77 {'context': '', 78 'text': 'Wikipedia', 79 'userValue': '', 80 'annotation': 'Link', 81 'earcons': [cvox.AbstractEarcons.LINK], 82 'personality': null, 83 'hint': '', 'category': null}, 84 {'context': '', 'text': 85 'is a great example of a site that this walker becomes valuable.', 86 'userValue': '', 87 'annotation': '', 'earcons': [], 'personality': null, 88 'hint': '', 'category': null}]; 89 } 90}; 91 92TEST_F('CvoxLayoutLineWalkerUnitTest', 'Sync', function() { 93 var sel = cvox.CursorSelection.fromNode($('1')); 94 sel = this.walker.sync(sel); 95 assertEquals(this.line1Text, sel.getText()); 96 97 sel = this.walker.sync(this.a); 98 assertEquals(this.line1Text, sel.getText()); 99 100 sel = this.walker.sync(this.aa); 101 assertEquals(this.line1Text, sel.getText()); 102 103 sel = this.walker.sync(this.b); 104 assertEquals(this.line2Text, sel.getText()); 105 106 sel = this.walker.sync(this.bb); 107 assertEquals(this.line2Text, sel.getText()); 108 109 // Reversed sync. 110 sel = this.walker.sync(this.a).setReversed(true); 111 assertEquals(this.line1Text, sel.getText()); 112 113 sel = this.walker.sync(this.aa).setReversed(true); 114 assertEquals(this.line1Text, sel.getText()); 115 116 sel = this.walker.sync(this.b).setReversed(true); 117 assertEquals(this.line2Text, sel.getText()); 118 119 sel = this.walker.sync(this.bb).setReversed(true); 120 assertEquals(this.line2Text, sel.getText()); 121}); 122 123/** Tests description of valid selections. */ 124TEST_F('CvoxLayoutLineWalkerUnitTest', 'Description', function() { 125 var sel = this.walker.sync(this.a); 126 assertEqualsJSON(this.line1Description, 127 this.walker.getDescription(sel, sel)); 128 129 var sel = this.walker.sync(this.b); 130 assertEqualsJSON(this.line2Description, this.walker.getDescription(sel, sel)); 131}); 132 133 134/** Tests back/forward movement. */ 135TEST_F('CvoxLayoutLineWalkerUnitTest', 'BackForward', function() { 136 var sel = this.walker.sync(this.a); 137 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); 145 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); 152 153 // Last line. 154 var last = this.walker.next(sel); 155 assertEquals(this.line3Text, last.getText()); 156 157 // Wrap. 158 assertEquals(null, this.walker.next(last)); 159 160 // Reverse. 161 sel = last.setReversed(true); 162 163 // Second line. 164 sel = this.walker.next(sel); 165 assertEquals(this.line2Text, sel.getText()); 166 167 // Next always returns an unreversed selection for line granularity. Reverse 168 // it to move backward. 169 sel.setReversed(true); 170 171 // First line. 172 sel = this.walker.next(sel); 173 assertEquals(this.line1Text, sel.getText()); 174 175 // Wrap. 176 sel.setReversed(true); 177 sel = this.walker.next(sel); 178 assertEquals(null, sel); 179}); 180