Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/common/braille_util_test.js

Issue 339923002: ChromeVox braille_util_test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/chromevox_tests.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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 CvoxBrailleUtilUnitTest() {}
14
15 CvoxBrailleUtilUnitTest.prototype = {
16 __proto__: ChromeVoxUnitTestBase.prototype,
17
18 /** @override */
19 closureModuleDeps: [
20 'cvox.BrailleUtil',
21 'cvox.CursorSelection',
22 'cvox.NavigationShifter',
23 ],
24
25 /** @override */
26 setUp: function() {
27 /** Simple mock. */
28 cvox.ChromeVox.msgs = {};
29
30 /**
31 * Simply return the message id.
32 * @param {string} msg Message id.
33 * @return {string} Message id.
34 */
35 cvox.ChromeVox.msgs.getMsg = function(msg) {
36 return msg;
37 };
38 },
39
40 /**
41 * @param {!Node} expectedParent Expected parent node.
42 * @param {!Node} node Node to examine.
43 * @private
44 */
45 assertTextNodeChildOf_: function(expectedParent, node) {
46 this.assertEquals(Node.TEXT_NODE, node.nodeType);
47 this.assertEquals(expectedParent, node.parentNode);
48 },
49
50 /**
51 * Helper to retrieve braille for testing.
52 * @param {!cvox.CursorSelection} prevSel Previous selection.
53 * @param {!cvox.CursorSelection} sel Current selection.
54 * @return {!cvox.NavBraille} Resulting braille.
55 * @private
56 */
57 getBraille_: function(prevSel, sel) {
58 return (new cvox.NavigationShifter).getBraille(prevSel, sel);
59 },
60
61 /**
62 * Asserts that two NavBraille objects are equal, ignoring spans.
63 * @param {Object} expected Expected result, should have no spans.
64 * @param {cvox.NavBraille} actual Actual result.
65 */
66 assertBrailleEquals: function(expected, actual) {
67 actual = new cvox.NavBraille({
68 text: actual.text.toString(),
69 startIndex: actual.startIndex,
70 endIndex: actual.endIndex
71 });
72 assertThat(new cvox.NavBraille(expected), eqJSON(actual));
73 }
74 };
75
76 TEST_F('CvoxBrailleUtilUnitTest', 'BrailleName', function() {
77 this.loadHtml(
78 '<div id="navbar">' +
79 '<a id="1" href="one.com">one</a>' +
80 '<a id="2" href="two.com">two</a>' +
81 '<a id="3" href="three.com">three</a>' +
82 '</div>');
83 var navbar = cvox.CursorSelection.fromNode($('navbar'));
84 var braille = this.getBraille_(navbar, navbar);
85 this.assertBrailleEquals(
86 {text: 'one lnk two lnk three lnk',
87 startIndex: 0,
88 endIndex: 1
89 }, braille);
90
91 var one =
92 cvox.CursorSelection.fromNode($('1').firstChild);
93 braille = this.getBraille_(one, one);
94 this.assertBrailleEquals(
95 {text: 'one lnk two lnk three lnk',
96 startIndex: 0,
97 endIndex: 1
98 }, braille);
99
100 var two =
101 cvox.CursorSelection.fromNode($('2').firstChild);
102 braille = this.getBraille_(one, two);
103 this.assertBrailleEquals(
104 {text: 'one lnk two lnk three lnk',
105 startIndex: 8,
106 endIndex: 9
107 }, braille);
108
109 var three =
110 cvox.CursorSelection.fromNode($('3').firstChild);
111 braille = this.getBraille_(two, three);
112 this.assertBrailleEquals(
113 {text: 'one lnk two lnk three lnk',
114 startIndex: 16,
115 endIndex: 17
116 }, braille);
117 });
118
119
120 /**
121 * @export
122 */
123 TEST_F('CvoxBrailleUtilUnitTest', 'NameTemplate', function() {
124 this.loadHtml(
125 '<button id="1">Submit</button>' +
126 '<input id="2" type="text" aria-label="Search">'
127 );
128
129 var button = cvox.CursorSelection.fromNode($('1'));
130
131 this.assertBrailleEquals(
132 {text: '[Submit]',
133 startIndex: 0,
134 endIndex: 1
135 }, this.getBraille_(button, button));
136
137 var inputElement = $('2');
138 var input = cvox.CursorSelection.fromNode(inputElement);
139
140 // Note: the cursor appears where text would be typed.
141 this.assertBrailleEquals(
142 {text: 'Search: edtxt',
143 startIndex: 0,
144 endIndex: 1
145 }, this.getBraille_(input, input));
146 inputElement.focus();
147 this.assertBrailleEquals(
148 {text: 'Search: edtxt',
149 startIndex: 8,
150 endIndex: 8
151 }, this.getBraille_(input, input));
152 });
153
154
155 /**
156 * @export
157 */
158 TEST_F('CvoxBrailleUtilUnitTest', 'TextField', function() {
159 this.loadHtml(
160 '<input id="1" type="text" aria-label="Search" value="larry">'
161 );
162
163 var inputElement = $('1');
164 var input = cvox.CursorSelection.fromNode(inputElement);
165
166 // Note: the cursor appears where text would be typed.
167 // The cursor is at the beginning by default.
168 this.assertBrailleEquals(
169 {text: 'Search: larry edtxt',
170 startIndex: 0,
171 endIndex: 1
172 }, this.getBraille_(input, input));
173 inputElement.focus();
174 this.assertBrailleEquals(
175 {text: 'Search: larry edtxt',
176 startIndex: 8,
177 endIndex: 13
178 }, this.getBraille_(input, input));
179 });
180
181
182 /**
183 * @export
184 */
185 TEST_F('CvoxBrailleUtilUnitTest', 'TextFieldEmpty', function() {
186 this.loadHtml(
187 '<input id="1" type="text">'
188 );
189
190 var inputElement = $('1');
191 var input = cvox.CursorSelection.fromNode($('1'));
192
193 this.assertBrailleEquals(
194 {text: ': edtxt',
195 startIndex: 0,
196 endIndex: 1
197 }, this.getBraille_(input, input));
198 inputElement.focus();
199 this.assertBrailleEquals(
200 {text: ': edtxt',
201 startIndex: 2,
202 endIndex: 2
203 }, this.getBraille_(input, input));
204 });
205
206
207 /**
208 * @export
209 */
210 TEST_F('CvoxBrailleUtilUnitTest', 'TextFieldSelection', function() {
211 this.loadHtml(
212 '<input id="1" type="text" value="strawberry">'
213 );
214
215 var inputElem = $('1');
216 var input = cvox.CursorSelection.fromNode(inputElem);
217
218 // Selection.
219 inputElem.selectionStart = 2;
220 inputElem.selectionEnd = 5;
221 this.assertBrailleEquals(
222 {text: ': strawberry edtxt',
223 startIndex: 4,
224 endIndex: 7
225 }, this.getBraille_(input, input));
226
227 // Cursor at end.
228 inputElem.selectionStart = 10;
229 inputElem.selectionEnd = 10;
230 this.assertBrailleEquals(
231 {text: ': strawberry edtxt',
232 startIndex: 12,
233 endIndex: 12
234 }, this.getBraille_(input, input));
235 });
236
237
238 /**
239 * @export
240 */
241 TEST_F('CvoxBrailleUtilUnitTest', 'StateTemplate', function() {
242 this.loadHtml(
243 '<input id="1" type="checkbox" aria-label="Save">');
244
245 var checkbox = cvox.CursorSelection.fromNode($('1'));
246
247 this.assertBrailleEquals(
248 {text: 'Save ( )',
249 startIndex: 0,
250 endIndex: 1
251 }, this.getBraille_(checkbox, checkbox));
252
253 $('1').checked = true;
254
255 this.assertBrailleEquals(
256 {text: 'Save (x)',
257 startIndex: 0,
258 endIndex: 1
259 }, this.getBraille_(checkbox, checkbox));
260 });
261
262
263 /**
264 * @export
265 */
266 TEST_F('CvoxBrailleUtilUnitTest', 'AccessKey', function() {
267 this.loadHtml(
268 '<a href="http://www.google.com" id="1" accesskey="g">Google</a>');
269
270 var link = cvox.CursorSelection.fromNode($('1'));
271
272 this.assertBrailleEquals(
273 {text: 'Google lnk access key:g',
274 startIndex: 0,
275 endIndex: 1
276 }, this.getBraille_(link, link));
277 });
278
279
280 /**
281 * @export
282 */
283 TEST_F('CvoxBrailleUtilUnitTest', 'ContainerTemplate', function() {
284 this.loadHtml(
285 '<h1>' +
286 '<a id="1" href="#menu">Skip To Menu</a>' +
287 '</h1>'
288 );
289
290 var link = cvox.CursorSelection.fromNode($('1'));
291
292 var navBraille = this.getBraille_(
293 cvox.CursorSelection.fromBody(), link);
294 this.assertBrailleEquals(
295 {text: 'h1 Skip To Menu int lnk',
296 startIndex: 0,
297 endIndex: 1
298 }, navBraille);
299 });
300
301
302 /**
303 * @export
304 */
305 TEST_F('CvoxBrailleUtilUnitTest', 'LinkSpans', function() {
306 this.loadHtml('<p><a id="1" href="#1">Hello</a> from' +
307 ' <a id="2" href="//www.google.com/">ChromeVox</a>');
308 var link1 = $('1');
309 var link2 = $('2');
310 var navBraille = this.getBraille_(
311 cvox.CursorSelection.fromBody(), cvox.CursorSelection.fromNode(link1));
312 this.assertEquals('Hello int lnk from ChromeVox lnk',
313 navBraille.text.toString());
314 this.assertEquals(link1, navBraille.text.getSpan(0));
315 this.assertEquals(link1, navBraille.text.getSpan(12));
316 this.assertEquals('undefined', typeof navBraille.text.getSpan(13));
317 this.assertEquals('undefined', typeof navBraille.text.getSpan(18));
318 this.assertEquals(link2, navBraille.text.getSpan(19));
319 this.assertEquals(link2, navBraille.text.getSpan(31));
320 });
321
322
323 /**
324 * @export
325 */
326 TEST_F('CvoxBrailleUtilUnitTest', 'NestedElements', function() {
327 this.loadHtml('<h1 id="test-h1">Larry, ' +
328 '<a href="#batman" id="batman-link">Sergey</a> and Eric</h1>');
329 var h1 = $('test-h1');
330 var link = $('batman-link');
331 var navBraille = this.getBraille_(
332 cvox.CursorSelection.fromBody(), cvox.CursorSelection.fromNode(h1));
333 this.assertEquals('h1 Larry, Sergey int lnk and Eric',
334 navBraille.text.toString());
335 this.assertTextNodeChildOf_(h1, navBraille.text.getSpan(0));
336 this.assertTextNodeChildOf_(h1, navBraille.text.getSpan(5));
337 this.assertEquals(link, navBraille.text.getSpan(15));
338 this.assertTextNodeChildOf_(h1, navBraille.text.getSpan(30));
339 });
340
341
342 /**
343 * @export
344 */
345 TEST_F('CvoxBrailleUtilUnitTest', 'GetTemplatedOverride', function() {
346 assertEquals('Menu mnu',
347 cvox.BrailleUtil.getTemplated(null, null,
348 { 'name': 'Menu',
349 'roleMsg': 'aria_role_menu' }));
350 assertEquals('alrt: Watch out!',
351 cvox.BrailleUtil.getTemplated(null, null,
352 { 'name': 'Watch out!',
353 'roleMsg': 'aria_role_alert' }));
354 // Test all properties. role, if present, overrides roleMsg.
355 assertEquals('Name Value Role State',
356 cvox.BrailleUtil.getTemplated(null, null,
357 { 'name': 'Name',
358 'role': 'Role',
359 'roleMsg': 'excluded',
360 'value': 'Value',
361 'state': 'State'
362 }));
363 });
364
365
366 /**
367 * @export
368 */
369 TEST_F('CvoxBrailleUtilUnitTest', 'CreateValue', function() {
370 var s;
371 var valueSpan;
372 var selectiponSpan;
373
374 // Value without a selection.
375 s = cvox.BrailleUtil.createValue('value');
376 assertEquals('value', s.toString());
377 assertUndefined(s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan));
378 valueSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSpan);
379 assertEquals(0, s.getSpanStart(valueSpan));
380 assertEquals(s.getLength(), s.getSpanEnd(valueSpan));
381
382 // Value with a carret at the start of the text.
383 s = cvox.BrailleUtil.createValue('value', 0);
384 selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
385 assertEquals(0, s.getSpanStart(selectionSpan));
386 assertEquals(0, s.getSpanEnd(selectionSpan));
387
388 // Value with a carret inside the text.
389 s = cvox.BrailleUtil.createValue('value', 1);
390 selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
391 assertEquals(1, s.getSpanStart(selectionSpan));
392 assertEquals(1, s.getSpanEnd(selectionSpan));
393
394 // Value with a carret at the end of the text.
395 s = cvox.BrailleUtil.createValue('value', 5);
396 selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
397 assertEquals(5, s.getSpanStart(selectionSpan));
398 assertEquals(5, s.getSpanEnd(selectionSpan));
399
400 // All of the value selected selected with reversed start and end.
401 s = cvox.BrailleUtil.createValue('value', 5, 0);
402 selectionSpan = s.getSpanInstanceOf(cvox.BrailleUtil.ValueSelectionSpan);
403 assertEquals(0, s.getSpanStart(selectionSpan));
404 assertEquals(5, s.getSpanEnd(selectionSpan));
405 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/chromevox_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698