Debian Codegraph @

dijit/tests/robot/Dialog_a11y.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <title>robot Dialog A11Y Test</title>
6
7 <style>
8 <style>
9 @import "../../../util/doh/robot/robot.css";
10 </style>
11
12 <!-- required: dojo.js -->
13 <script type="text/javascript" src="../../../dojo/dojo.js"
14 data-dojo-config="isDebug: true"></script>
15
16 <script type="text/javascript">
17 require([
18 "doh/runner", "dojo/robotx",
19 "dojo/aspect", "dojo/dom", "dojo/dom-class", "dojo/dom-style", "dojo/keys",
20 "dijit/tests/helpers", "dojo/domReady!"
21 ], function(doh, robot, aspect, dom, domClass, domStyle, keys, helpers){
22
23 robot.initRobot('../test_Dialog.html');
24
25 doh.register(function setup(){
26 // get pointer to registry in the iframe
27 registry = robot.window.require("dijit/registry");
28 dfocus = robot.window.require("dijit/focus");
29 DialogUnderlay = robot.window.require("dijit/DialogUnderlay");
30 });
31
32 doh.register("keyboard tests (cancel)", [
33 {
34 name: "open dialog",
35 timeout: 10000,
36 runTest: function(){
37 var d = new doh.Deferred();
38
39 // Click the button. We do this manually rather than calling Dialog.show()
40 // so we can later test that focus is restored (to the previous position)
41 // when the dialog is closed
42 dom.byId("dialog1button").focus();
43 robot.keyPress(keys.SPACE, 1000, {});
44 robot.typeKeys("Bill", 1000, 800);
45
46 robot.sequence(d.getTestCallback(function(){
47 doh.t(helpers.isVisible("dialog1"), "dialog 1 has been made visible");
48 doh.is("name", dfocus.curNode.id, "focus is on the first field");
49 }), 500);
50
51 return d;
52 }
53 },
54
55 {
56 name: "tab to the date field",
57 timeout: 10000,
58 runTest: function(){
59 var d = new doh.Deferred();
60
61 robot.keyPress(keys.TAB, 500, {});
62 robot.typeKeys("Japan", 1000, 1000);
63 robot.keyPress(keys.TAB, 500, {});
64
65 robot.sequence(d.getTestCallback(function(){
66 doh.is("date", dfocus.curNode.id, "focus is on the date field");
67 }), 1000);
68
69 return d;
70 }
71 },
72
73 {
74 name: "open and close date drop down",
75 timeout: 4000,
76 runTest: function(){
77 var d = new doh.Deferred();
78
79 robot.keyPress(keys.DOWN_ARROW, 500, {});
80 robot.keyPress(keys.ESCAPE, 500, {});
81
82 robot.sequence(d.getTestCallback(function(){
83 doh.is("date", dfocus.curNode.id, "focus is still on the date field");
84 doh.t(helpers.isVisible("dialog1"), "dialog 1 wasn't closed");
85 }), 1000);
86
87 return d;
88 }
89 },
90
91 {
92 name: "tabbing loops around",
93 timeout: 4000,
94 runTest: function(){
95 var d = new doh.Deferred();
96
97 robot.keyPress(keys.TAB, 500, {});
98 robot.keyPress(keys.TAB, 500, {});
99 robot.keyPress(keys.TAB, 500, {});
100 robot.keyPress(keys.TAB, 500, {});
101
102 robot.sequence(d.getTestCallback(function(){
103 doh.is("name", dfocus.curNode.id, "focus looped back to name field");
104 }), 1000);
105
106 return d;
107 }
108 },
109
110 {
111 name: "reverse-tabbing loops around",
112 timeout: 4000,
113 runTest: function(){
114 var d = new doh.Deferred();
115
116 robot.keyPress(keys.TAB, 500, {shift: true});
117
118 robot.sequence(d.getTestCallback(function(){
119 doh.is("ok", dfocus.curNode.id, "focus looped back to submit button");
120 }), 1000);
121
122 return d;
123 }
124 },
125
126 {
127 name: "close via ESC",
128 timeout: 4000,
129 runTest: function(){
130 var d = new doh.Deferred();
131
132 robot.keyPress(keys.ESCAPE, 500, {});
133
134 robot.sequence(d.getTestCallback(function(){
135 doh.t(helpers.isHidden("dialog1"), "dialog 1 was closed");
136 doh.is("dialog1button", dfocus.curNode.id, "focus returned to button");
137 }), 1000);
138
139 return d;
140 }
141 }
142 ]);
143
144 doh.register("keyboard tests (submit)", [
145 {
146 name: "submit some data",
147 timeout: 15000,
148 setUp: function(){
149 registry.byId("dialog1").reset();
150 },
151 runTest: function(){
152 var d = new doh.Deferred();
153
154 // Setup handler to catch submitted data
155 var data;
156 aspect.after(registry.byId("dialog1"), "execute", function(vals){
157 data = vals;
158 }, true);
159
160 // Open the dialog
161 dom.byId("dialog1button").focus();
162 robot.keyPress(keys.SPACE, 1000, {});
163
164 // Enter some info
165 robot.typeKeys("Ted", 2000, 600);
166 robot.keyPress(keys.TAB, 500, {});
167 robot.typeKeys("America", 1000, 1400);
168 robot.keyPress(keys.TAB, 500, {});
169 robot.keyPress(keys.TAB, 1000, {});
170 robot.keyPress(keys.TAB, 1000, {});
171 robot.keyPress(keys.TAB, 1000, {});
172
173 // Submit
174 robot.keyPress(keys.SPACE, 1000, {});
175
176 robot.sequence(d.getTestCallback(function(){
177 doh.t(helpers.isHidden("dialog1"), "dialog 1 was closed on submit");
178 doh.t(data, "got submit data");
179 doh.is("Ted", data.name, "Name");
180 doh.is("America", data.loc, "Location");
181 }), 1000);
182
183 return d;
184 }
185 }
186 ]);
187
188 doh.register("keyboard tests (cancel via Cancel button)", [
189 {
190 name: "close Dialog via Cancel button",
191 timeout: 15000,
192 runTest: function(){
193 var d = new doh.Deferred();
194
195 // Test which callbacks are called on cancel
196 var executed = false, canceled = false;
197 aspect.after(registry.byId("ABDlg1"), "execute", function(vals){
198 executed = true;
199 }, true);
200 registry.byId("ABDlg1").on("cancel", function(){
201 canceled = true;
202 });
203
204 // Open the dialog
205 dom.byId("ABDlg1Btn").focus();
206 robot.keyPress(keys.SPACE, 1000, {});
207
208 robot.sequence(d.getTestErrback(function(){
209 doh.t(helpers.isVisible("ABDlg1"), "dialog opened");
210 }), 1000);
211
212 // Cancel
213 robot.keyPress(keys.TAB, 500, {});
214 robot.keyPress(keys.SPACE, 500, {});
215
216 robot.sequence(d.getTestCallback(function(){
217 doh.t(helpers.isHidden("ABDlg1"), "dialog closed on cancel");
218 doh.t(canceled, "cancel callback was called");
219 doh.f(executed, "execute callback wasn't called");
220 }), 1000);
221
222 return d;
223 }
224 }
225 ]);
226
227 // Test aria roles, etc.
228 doh.register("aria", function(){
229 var dlog = registry.byId("dialog1");
230 doh.is("dialog", dlog.domNode.getAttribute("role"), "role");
231 doh.is("dialog1_title", dlog.domNode.getAttribute("aria-labelledby"), "aria-labelledby");
232 doh.isNot(undefined, dom.byId("dialog1_title"), "label node exists");
233 doh.isNot("", helpers.innerText(dom.byId("dialog1_title")), "label node has text");
234 // dijit.Dialog does not implement aria-expanded as of this writing -- should it?
235 });
236
237 // Focus tests for special cases. Focus for normal cases was already tested above.
238 doh.register("special focus", [
239 {
240 name: "no focusable elements",
241 timeout: 10000,
242 runTest: function(){
243 var d = new doh.Deferred();
244
245 // Click the button. We do this manually rather than calling Dialog.show()
246 // so we can later test that focus is restored (to the previous position)
247 // when the dialog is closed
248 dom.byId("unmovablebutton").focus();
249 robot.keyPress(keys.SPACE, 500, {});
250
251 robot.sequence(d.getTestErrback(function(){
252 doh.t(dfocus.curNode, "focus is somewhere #1");
253 doh.t(domClass.contains(dfocus.curNode, "dijitDialogCloseIcon"), "focus is on the close button #1");
254 }), 1000);
255
256 // Tab key shouldn't change the focus
257 robot.keyPress(keys.TAB, 500);
258
259 robot.sequence(d.getTestErrback(function(){
260 doh.t(dfocus.curNode, "focus is somewhere #2");
261 doh.t(domClass.contains(dfocus.curNode, "dijitDialogCloseIcon"), "focus is on the close button #2");
262 }), 500);
263
264 // Space key should close the dialog
265 robot.keyPress(keys.SPACE, 500);
266
267 robot.sequence(d.getTestErrback(function(){
268 doh.t(dfocus.curNode, "focus is somewhere #3");
269 doh.is("unmovablebutton", dfocus.curNode.id, "focus is back on the button that opened the dialog #1");
270 }), 500);
271
272 // Open the dialog again
273 robot.keyPress(keys.SPACE, 500, {});
274
275 robot.sequence(d.getTestErrback(function(){
276 doh.t(dfocus.curNode, "focus is somewhere #4");
277 doh.t(domClass.contains(dfocus.curNode, "dijitDialogCloseIcon"), "focus is on the close button #4");
278 }), 500);
279
280 // Esc key should also close the dialog
281 robot.keyPress(keys.ESCAPE, 500);
282
283 robot.sequence(d.getTestCallback(function(){
284 doh.t(dfocus.curNode, "focus is somewhere #5");
285 doh.is("unmovablebutton", dfocus.curNode.id, "focus is back on the button that opened the dialog #2");
286 }), 500);
287
288 return d;
289 }
290 },
291
292 {
293 name: "input type=file",
294 timeout: 10000,
295 runTest: function(){
296 var d = new doh.Deferred();
297
298 // Click the button. We do this manually rather than calling Dialog.show()
299 // so we can later test that focus is restored (to the previous position)
300 // when the dialog is closed
301 dom.byId("filebutton").focus();
302 robot.keyPress(keys.SPACE, 500, {});
303
304 robot.sequence(d.getTestErrback(function(){
305 doh.t(dfocus.curNode, "focus is somewhere #1");
306 doh.is("afile", dfocus.curNode.id, "focus is on the input type=file");
307 }), 1000);
308
309 // Esc key should close the dialog
310 robot.keyPress(keys.ESCAPE, 500);
311
312 robot.sequence(d.getTestCallback(function(){
313 doh.t(dfocus.curNode, "focus is somewhere #2");
314 doh.is("filebutton", dfocus.curNode.id, "focus is back on the button that opened the dialog");
315 }), 500);
316
317 return d;
318 }
319 },
320
321 {
322 name: "radio button as last element",
323 timeout: 10000,
324 runTest: function(){
325 var d = new doh.Deferred();
326
327 // Click the button. We do this manually rather than calling Dialog.show()
328 // so we can later test that focus is restored (to the previous position)
329 // when the dialog is closed
330 dom.byId("RadioButtonDlgBtn").focus();
331 robot.keyPress(keys.SPACE, 500, {});
332
333 robot.sequence(d.getTestErrback(function(){
334 doh.t(dfocus.curNode, "focus is somewhere #1");
335 doh.is("textarea-radio-test", dfocus.curNode.id, "focus is on the textarea");
336 }), 1000);
337
338 robot.keyPress(keys.TAB, 500, {});
339 robot.keyPress(keys.TAB, 500, {});
340
341 robot.sequence(d.getTestErrback(function(){
342 doh.t(dfocus.curNode, "focus is somewhere #2");
343 doh.is("textarea-radio-test", dfocus.curNode.id, "focus wraps around back to the textarea");
344 }), 500);
345
346 // Esc key should close the dialog
347 robot.keyPress(keys.ESCAPE, 500);
348
349 robot.sequence(d.getTestCallback(function(){
350 doh.t(dfocus.curNode, "focus is somewhere #3");
351 doh.is("RadioButtonDlgBtn", dfocus.curNode.id, "focus is back on the button that opened the dialog");
352 }), 500);
353
354 return d;
355 }
356 }
357 ]);
358
359 doh.register("keyboard tests (multiple dialogs)", [
360 {
361 name: "open first dialog",
362 timeout: 10000,
363 setUp: function(){
364 registry.byId("dialog1").reset();
365 },
366 runTest: function(){
367 var d = new doh.Deferred();
368
369 // Click the button. We do this manually rather than calling Dialog.show()
370 // so we can later test that focus is restored (to the previous position)
371 // when the dialog is closed
372 dom.byId("dialog1button").focus();
373 robot.keyPress(keys.SPACE, 1000, {});
374 robot.typeKeys("lower", 1000, 1000);
375
376 // Move focus to second field
377 robot.keyPress(keys.TAB, 1000);
378
379 robot.sequence(d.getTestCallback(function(){
380 doh.t(helpers.isVisible("dialog1"), "dialog 1 is visible");
381
382 var dialog1Z = domStyle.get(registry.byId("dialog1").domNode, "zIndex"),
383 underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex");
384
385 doh.t(dialog1Z > underlayZ, "dialog1 (zIndex=" + dialog1Z +
386 ") above underlay (zIndex=" + underlayZ + ")");
387
388 doh.is("loc", dfocus.curNode.id, "focus is on the second field");
389 }), 1000);
390
391 return d;
392 }
393 },
394
395 {
396 name: "open second dialog",
397 timeout: 10000,
398 runTest: function(){
399 var d = new doh.Deferred();
400
401 registry.byId("tabDialog").show();
402
403 robot.sequence(d.getTestCallback(function(){
404 doh.t(helpers.isVisible("tabDialog"), "tab dialog has been made visible");
405 doh.t(helpers.isVisible("dialog1"), "dialog 1 is still visible");
406
407 var tabDialogZ = domStyle.get(registry.byId("tabDialog").domNode, "zIndex"),
408 dialog1Z = domStyle.get(registry.byId("dialog1").domNode, "zIndex"),
409 underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex");
410
411 doh.t(tabDialogZ > underlayZ, "tabDialog (zIndex=" + tabDialogZ +
412 ") above underlay (zIndex=" + underlayZ + ")");
413 doh.t(dialog1Z < underlayZ, "dialog1 (zIndex=" + dialog1Z +
414 ") below underlay (zIndex=" + underlayZ + ")");
415 }), 2000);
416
417 return d;
418 }
419 },
420
421 {
422 name: "cancel second dialog",
423 timeout: 10000,
424 runTest: function(){
425 var d = new doh.Deferred();
426
427 robot.keyPress(keys.ESCAPE, 500, {});
428
429 robot.sequence(d.getTestCallback(function(){
430 doh.t(helpers.isHidden("tabDialog"), "tab dialog has been hidden");
431 doh.t(helpers.isVisible("dialog1"), "dialog 1 is still visible");
432
433 var dialog1Z = domStyle.get(registry.byId("dialog1").domNode, "zIndex"),
434 underlayZ = domStyle.get(DialogUnderlay._singleton.domNode, "zIndex");
435
436 doh.t(dialog1Z > underlayZ, "dialog1 (zIndex=" + dialog1Z +
437 ") above underlay (zIndex=" + underlayZ + ")");
438
439 doh.is("loc", dfocus.curNode.id, "focus is on the second field");
440 }), 2000);
441
442 return d;
443 }
444 },
445
446 {
447 name: "cancel first dialog",
448 timeout: 10000,
449 runTest: function(){
450 var d = new doh.Deferred();
451
452 robot.keyPress(keys.ESCAPE, 500, {});
453
454 robot.sequence(d.getTestCallback(function(){
455 doh.t(helpers.isHidden("dialog1"), "dialog 1 was closed");
456 doh.is("dialog1button", dfocus.curNode.id, "focus returned to button");
457 }), 2000);
458
459 return d;
460 }
461 }
462 ]);
463
464 // Testing if focus somehow gets shifted to an element behind the underlay, by (for example)
465 // access keys, or tabbing in from the URL bar, or clicking the underlay, thus focusing <body>.
466 doh.register("focus return", [
467 {
468 name: "open first",
469 timeout: 10000,
470 runTest: function(){
471 return registry.byId('dialog1').show();
472 }
473 },
474 {
475 name: "open second",
476 timeout: 10000,
477 runTest: function(){
478 var fifthDlg = registry.byId('fifthDlg');
479 return fifthDlg.show().then(function(){
480 return fifthDlg.onLoadDeferred;
481 });
482 }
483 },
484 {
485 name: "focus main page",
486 timeout: 10000,
487 runTest: function(){
488 var d = new doh.Deferred();
489
490 dom.byId("plainInput").focus();
491
492 setTimeout(d.getTestCallback(function(){
493 doh.t(helpers.isVisible("fifthDlg"), "dialog 5 still visible");
494 doh.is("timeref", dfocus.curNode && dfocus.curNode.id,
495 "focus remains on / returned to dialog");
496 }), 1000);
497
498 return d;
499 }
500 },
501 {
502 name: "close second",
503 timeout: 10000,
504 runTest: function(){
505 return registry.byId('fifthDlg').hide();
506 }
507 },
508 {
509 name: "focus main page again",
510 timeout: 10000,
511 runTest: function(){
512 var d = new doh.Deferred();
513
514 dom.byId("plainInput").focus();
515
516 setTimeout(d.getTestCallback(function(){
517 doh.t(helpers.isVisible("dialog1"), "dialog 1 still visible");
518 doh.is("name", dfocus.curNode && dfocus.curNode.id,
519 "focus remains on / returned to dialog");
520 }), 1000);
521
522 return d;
523 }
524 },
525 {
526 name: "close first",
527 timeout: 10000,
528 runTest: function(){
529 return registry.byId('dialog1').hide();
530 }
531 }
532 ]);
533
534 // Negative test for "focus return". If the execute() handler shifts focus somewhere,
535 // make sure it isn't automatically shifted back to the Dialog (which is fading out but
536 // not yet hidden).
537 doh.register("focus in execute", [
538 {
539 name: "use dialog",
540 timeout: 15000,
541 runTest: function(){
542 var d = new doh.Deferred();
543
544 // Open the dialog
545 dom.byId("insertTextButton", robot.doc).focus();
546 robot.keyPress(keys.SPACE, 500, {});
547
548 // Enter some info
549 robot.typeKeys("Hello world", 2000, 600);
550
551 // Submit
552 robot.keyPress(keys.TAB, 1000, {});
553 robot.keyPress(keys.SPACE, 1000, {});
554
555 robot.sequence(d.getTestCallback(function(){
556 doh.is("editor", dfocus.curNode.id, "focus returned to editor");
557 doh.is("Hello world", dom.byId("editor", robot.doc).value, "text inserted");
558 }), 1000);
559
560 return d;
561 }
562 }
563 ]);
564
565 doh.register("closable", [
566 {
567 name: "open dialog",
568 timeout: 10000,
569 runTest: function(){
570 var d = new doh.Deferred();
571
572 dom.byId("unclosableButton").focus();
573 robot.keyPress(keys.SPACE, 1000, {});
574
575 robot.sequence(d.getTestCallback(function(){
576 doh.t(helpers.isVisible("unclosable"), "visible");
577 doh.t(helpers.isHidden(registry.byId("unclosable").closeButtonNode), "close icon hidden");
578 }), 500);
579
580 return d;
581 }
582 },
583
584 {
585 name: "close via ESC",
586 timeout: 4000,
587 runTest: function(){
588 var d = new doh.Deferred();
589
590 robot.keyPress(keys.ESCAPE, 500, {});
591
592 robot.sequence(d.getTestCallback(function(){
593 doh.t(helpers.isVisible("unclosable"), "still visible");
594 }), 1000);
595
596 return d;
597 }
598 },
599
600 {
601 name: "close via ENTER on OK button",
602 timeout: 4000,
603 runTest: function(){
604 var d = new doh.Deferred();
605
606 robot.keyPress(keys.ENTER, 500, {});
607
608 robot.sequence(d.getTestCallback(function(){
609 doh.t(helpers.isHidden("unclosable"), "hidden");
610 }), 1000);
611
612 return d;
613 }
614 }
615 ]);
616
617 doh.run();
618 });
619 </script>
620 </head>
621 </html>