Chromium Code Reviews| 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 CvoxLayoutLineWalkerUnitTest() {} | |
| 14 | |
| 15 CvoxLayoutLineWalkerUnitTest.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.loadDoc(function() {/*! | |
| 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. Braille | |
| 37 also benefits greatly from<br> | |
| 38 this type of formatting since some displays | |
| 39 can handle lots of text like 80 cell displays! | |
| 40 </p> | |
| 41 </div> | |
| 42 */}); | |
| 43 cvox.ChromeVox.msgs = new cvox.TestMsgs(); | |
| 44 this.walker = new cvox.LayoutLineWalker(); | |
| 45 | |
| 46 this.a = cvox.CursorSelection.fromNode(document.getElementById('a')); | |
|
dmazzoni
2014/09/12 15:53:27
nit: we're using $('a') in the other tests, since
| |
| 47 this.aa = cvox.CursorSelection.fromNode(document.getElementById('aa')); | |
| 48 this.b = cvox.CursorSelection.fromNode(document.getElementById('b')); | |
| 49 this.bb = cvox.CursorSelection.fromNode(document.getElementById('bb')); | |
| 50 | |
| 51 this.line1Text = 'Demonstrating that in-line links like google are' + | |
| 52 ' considered a single layout line.'; | |
| 53 | |
| 54 this.line2Text = 'This includes a paragraph that has a lot of text' + | |
| 55 ' like this one. Wikipedia is a great example of a site that this' + | |
| 56 ' walker becomes valuable. Braille also benefits greatly from'; | |
| 57 | |
| 58 this.line3Text = | |
| 59 'this type of formatting since some displays can handle lots of' + | |
| 60 ' text like 80 cell displays!'; | |
| 61 | |
| 62 this.line1Description = | |
| 63 [{'context': '', 'text': 'Demonstrating that in-line links like', | |
| 64 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null, | |
| 65 'hint': '', 'category': null}, | |
| 66 {'context': '', 'text': 'google', 'userValue': '', 'annotation': 'Link' , | |
| 67 'earcons': [cvox.AbstractEarcons.LINK], 'personality': null, | |
| 68 hint: '', 'category': null}, | |
| 69 {'context': '', 'text': 'are considered a single layout line.', | |
| 70 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null, | |
| 71 'hint': '', 'category': null}]; | |
| 72 | |
| 73 this.line2Description = | |
| 74 [{'context': '', 'text': | |
| 75 'This includes a paragraph that has a lot of text like this one.', | |
| 76 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null, | |
| 77 'hint': '', 'category': null}, | |
| 78 {'context': '', | |
| 79 'text': 'Wikipedia', | |
| 80 'userValue': '', | |
| 81 'annotation': 'Link', | |
| 82 'earcons': [cvox.AbstractEarcons.LINK], | |
| 83 'personality': null, | |
| 84 'hint': '', 'category': null}, | |
| 85 {'context': '', 'text': | |
| 86 'is a great example of a site that this walker becomes valuable.' + | |
| 87 ' Braille also benefits greatly from', 'userValue': '', | |
| 88 'annotation': '', 'earcons': [], 'personality': null, | |
| 89 'hint': '', 'category': null}]; | |
| 90 } | |
| 91 }; | |
| 92 | |
| 93 TEST_F('CvoxLayoutLineWalkerUnitTest', 'Sync', function() { | |
| 94 var sel = cvox.CursorSelection.fromNode($('1')); | |
| 95 sel = this.walker.sync(sel); | |
| 96 assertEquals(this.line1Text, sel.getText()); | |
| 97 | |
| 98 sel = this.walker.sync(this.a); | |
| 99 assertEquals(this.line1Text, sel.getText()); | |
| 100 | |
| 101 sel = this.walker.sync(this.aa); | |
| 102 assertEquals(this.line1Text, sel.getText()); | |
| 103 | |
| 104 sel = this.walker.sync(this.b); | |
| 105 assertEquals(this.line2Text, sel.getText()); | |
| 106 | |
| 107 sel = this.walker.sync(this.bb); | |
| 108 assertEquals(this.line2Text, sel.getText()); | |
| 109 | |
| 110 // Reversed sync. | |
| 111 sel = this.walker.sync(this.a).setReversed(true); | |
| 112 assertEquals(this.line1Text, sel.getText()); | |
| 113 | |
| 114 sel = this.walker.sync(this.aa).setReversed(true); | |
| 115 assertEquals(this.line1Text, sel.getText()); | |
| 116 | |
| 117 sel = this.walker.sync(this.b).setReversed(true); | |
| 118 assertEquals(this.line2Text, sel.getText()); | |
| 119 | |
| 120 sel = this.walker.sync(this.bb).setReversed(true); | |
| 121 assertEquals(this.line2Text, sel.getText()); | |
| 122 }); | |
| 123 | |
| 124 /** Tests description of valid selections. */ | |
| 125 TEST_F('CvoxLayoutLineWalkerUnitTest', 'Description', function() { | |
| 126 var sel = this.walker.sync(this.a); | |
| 127 assertEqualsJSON(this.line1Description, | |
| 128 this.walker.getDescription(sel, sel)); | |
| 129 | |
| 130 var sel = this.walker.sync(this.b); | |
| 131 assertEqualsJSON(this.line2Description, this.walker.getDescription(sel, sel)); | |
| 132 }); | |
| 133 | |
| 134 | |
| 135 /** Tests back/forward movement. */ | |
| 136 TEST_F('CvoxLayoutLineWalkerUnitTest', 'BackForward', function() { | |
| 137 var sel = this.walker.sync(this.a); | |
| 138 | |
| 139 // Beginning of second line. | |
| 140 sel = this.walker.next(sel); | |
| 141 assertEquals(Text, sel.start.node.constructor); | |
| 142 assertEquals(this.b.start.node.id, sel.start.node.parentNode.id); | |
| 143 assertEquals(null, sel.start.node.previousSibling); | |
| 144 assertEquals(this.bb.start.node.id, sel.start.node.nextSibling.id); | |
| 145 | |
| 146 // This offset is expected because the index takes into account whitespace | |
| 147 // which is retained from the actual source. | |
| 148 assertEquals(9, sel.start.index); | |
| 149 | |
| 150 // End of second line. | |
| 151 assertEquals(Text, sel.end.node.constructor); | |
| 152 assertEquals(this.b.end.node.id, sel.end.node.parentNode.id); | |
| 153 assertEquals(HTMLBRElement, sel.end.node.nextSibling.constructor); | |
| 154 assertEquals(this.bb.start.node.id, sel.end.node.previousSibling.id); | |
| 155 assertEquals(115, sel.end.index); | |
| 156 | |
| 157 // Last line. | |
| 158 var last = this.walker.next(sel); | |
| 159 assertEquals(this.line3Text, last.getText()); | |
| 160 | |
| 161 // Wrap. | |
| 162 assertEquals(null, this.walker.next(last)); | |
| 163 | |
| 164 // Reverse. | |
| 165 sel = last.setReversed(true); | |
| 166 | |
| 167 // Second line. | |
| 168 sel = this.walker.next(sel); | |
| 169 assertEquals(this.line2Text, sel.getText()); | |
| 170 | |
| 171 // Next always returns an unreversed selection for line granularity. Reverse | |
| 172 // it to move backward. | |
| 173 sel.setReversed(true); | |
| 174 | |
| 175 // First line. | |
| 176 sel = this.walker.next(sel); | |
| 177 assertEquals(this.line1Text, sel.getText()); | |
| 178 | |
| 179 // Wrap. | |
| 180 sel.setReversed(true); | |
| 181 sel = this.walker.next(sel); | |
| 182 assertEquals(null, sel); | |
| 183 }); | |
| OLD | NEW |