Debian Codegraph @

dijit/tests/form/robot/Button_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>doh.robot Button Test</title>
6
7 <style>
8 @import "../../../../util/doh/robot/robot.css";
9 </style>
10
11 <!-- required: dojo.js -->
12 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
13
14 <script type="text/javascript">
15 dojo.require("dojo.on");
16 dojo.require("dijit.robotx");
17 dojo.require("dijit.tests.helpers"); // functions to help test
18
19 dojo.ready(function(){
20 doh.robot.initRobot('../test_Button.html');
21
22 var submitCount = 0, resetCount = 0;
23
24 doh.register("setup", function(){
25 doh.robot.sequence(function(){
26 dojo.connect(dijit.byId("testForm"), "onSubmit", function(){
27 submitCount++;
28 });
29 dojo.connect(dijit.byId("testForm"), "onReset", function(){
30 resetCount++;
31 })
32 });
33 });
34
35 doh.register("dijit.form.Button", [
36 {
37 name: "label",
38 timeout: 1000,
39 runTest: function(){
40 var label = dijit.byId("T1465").containerNode.innerHTML;
41 doh.is('Create', dojo.trim(label), "source.innerHTML label " + label);
42 var label2 = dijit.byId("T1466").containerNode.innerHTML;
43 doh.is('View', label2, "subclass label " + label2);
44 }
45 },
46 {
47 name: "enabled",
48 timeout: 5000,
49 runTest: function(){
50 var d = new doh.Deferred();
51
52 dojo.byId("input").focus();
53
54 var clicks = 0;
55 dijit.byId("T1465").set("onClick", function(){ clicks++; });
56
57
58 // tab into button to get focus
59 doh.robot.keyPress(dojo.keys.TAB, 1000, {});
60
61 // and activate with space / enter
62 doh.robot.keyPress(dojo.keys.SPACE, 1000, {});
63 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
64
65 doh.robot.sequence(d.getTestCallback(function(){
66 doh.is(2, clicks, "both space and enter click the button");
67 }), 500);
68 return d;
69 }
70 },
71 {
72 name: "disabled no focus",
73 timeout: 4000,
74 runTest: function(){
75 var d = new doh.Deferred();
76
77 doh.is("T1465", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).id, "focus starting on 1465");
78
79 dijit.byId("T1466").set("disabled", true);
80
81 // tab over disabled "View" button to "Create" combo-button
82 doh.robot.keyPress(dojo.keys.TAB, 500, {});
83
84 doh.robot.sequence(d.getTestCallback(function(){
85 console.log("current focus is ", dojo.global.dijit.focus.curNode);
86 doh.is("comboCreate", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).id, "focus jumped to combo create (left part of button)");
87 }), 1000);
88 return d;
89 }
90 }
91 ]);
92
93 doh.register("dijit.form.DropDownButton", [
94 function initialState(){
95 doh.f(dojo.hasClass(dijit.byId("edit").domNode, "dijitDropDownButtonOpened"),
96 "no dijitDropDownButtonOpened class");
97 },
98 {
99 name: "down arrow opens menu",
100 timeout: 4000,
101 runTest: function(){
102 var d = new doh.Deferred();
103
104 dijit.byId("edit").focus();
105 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
106
107 doh.robot.sequence(d.getTestCallback(function(){
108 doh.t(dojo.hasClass(dijit.byId("edit").domNode, "dijitDropDownButtonOpened"),
109 "dijitDropDownButtonOpened class");
110 doh.t(isVisible("editMenu"), "edit menu is visible: " + dijit.byId("editMenu").domNode.style.cssText);
111 doh.is("cut", dojo.global.dijit.focus.curNode.id, "focus is on menu");
112 }), 500);
113 return d;
114 }
115 },
116
117 {
118 name: "esc closes menu",
119 timeout: 4000,
120 runTest: function(){
121 var d = new doh.Deferred();
122
123 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
124
125 doh.robot.sequence(d.getTestCallback(function(){
126 doh.t(isHidden("editMenu"), "edit menu is hidden: " + dijit.byId("editMenu").domNode.style.cssText);
127 doh.is("edit", dojo.global.dijit.focus.curNode.id, "focus is back on button");
128 doh.f(dojo.hasClass(dijit.byId("edit").domNode, "dijitDropDownButtonOpened"),
129 "no dijitDropDownButtonOpened class");
130 }), 1000);
131 return d;
132 }
133 },
134 {
135 name: "space opens menu",
136 timeout: 4000,
137 runTest: function(){
138 var d = new doh.Deferred();
139
140 dijit.byId("edit").focus();
141 doh.robot.keyPress(dojo.keys.SPACE, 500, {});
142
143 doh.robot.sequence(d.getTestCallback(function(){
144 doh.t(isVisible("editMenu"), "edit menu is visible: " + dijit.byId("editMenu").domNode.style.cssText);
145 }), 1000);
146 return d;
147 }
148 },
149
150 {
151 name: "space executes menu",
152 timeout: 4000,
153 runTest: function(){
154 var d = new doh.Deferred();
155
156 doh.robot.keyPress(dojo.keys.SPACE, 500, {});
157
158 doh.robot.sequence(d.getTestCallback(function(){
159 doh.t(isHidden("editMenu"), "edit menu is hidden: " + dijit.byId("editMenu").domNode.style.cssText);
160 doh.is("edit", dojo.global.dijit.focus.curNode.id, "focus is back on button");
161 }), 1000);
162 return d;
163 }
164 },
165 {
166 name: "enter opens menu",
167 timeout: 4000,
168 runTest: function(){
169 var d = new doh.Deferred();
170
171 dijit.byId("edit").focus();
172 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
173
174 doh.robot.sequence(d.getTestCallback(function(){
175 doh.t(isVisible("editMenu"), "edit menu is visible: " + dijit.byId("editMenu").domNode.style.cssText);
176 }), 1000);
177 return d;
178 }
179 },
180
181 {
182 name: "tab key closes popup, goes back to button",
183 timeout: 4000,
184 runTest: function(){
185 var d = new doh.Deferred();
186
187 doh.robot.keyPress(dojo.keys.TAB, 500, {});
188
189 doh.robot.sequence(d.getTestCallback(function(){
190 doh.t(isHidden("editMenu"), "edit menu is hidden: " + dijit.byId("editMenu").domNode.style.cssText);
191 doh.is("edit", dojo.global.dijit.focus.curNode.id, "focus is back on button");
192 }), 1000);
193 return d;
194 }
195 },
196 {
197 name: "enter opens menu again",
198 timeout: 4000,
199 runTest: function(){
200 var d = new doh.Deferred();
201
202 dijit.byId("edit").focus();
203 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
204
205 doh.robot.sequence(d.getTestCallback(function(){
206 doh.t(isVisible("editMenu"), "edit menu is visible: " + dijit.byId("editMenu").domNode.style.cssText);
207 }), 1000);
208 return d;
209 }
210 },
211
212 {
213 name: "enter closes menu (#4772)",
214 timeout: 4000,
215 runTest: function(){
216 var d = new doh.Deferred();
217
218 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
219
220 doh.robot.sequence(d.getTestCallback(function(){
221 doh.t(isHidden("editMenu"), "edit menu is hidden: " + dijit.byId("editMenu").domNode.style.cssText);
222 doh.is("edit", dojo.global.dijit.focus.curNode.id, "focus is back on button");
223 }), 1000);
224 return d;
225 }
226 },
227 {
228 name: "aria role and attributes",
229 timeout: 2000,
230 runTest: function(){
231 var d = new doh.Deferred(),
232 button = dijit.byId("dropdown_default"); //testing dropDownButton
233
234 doh.is("button", button._popupStateNode.getAttribute("role"), "button._popupStateNode role");
235 doh.t(button._popupStateNode.getAttribute("aria-haspopup"), "button._popupStateNode aria-haspopup");
236 doh.is("dropdown_default_label", button._popupStateNode.getAttribute("aria-labelledby"), "aria-labelledby");
237 doh.f(button._popupStateNode.getAttribute("aria-expanded"), "dont expect initial aria-expanded");
238 doh.f(button._popupStateNode.getAttribute("aria-owns"), "initally missing aria-owns");
239
240 // open the drop down, check that button now has aria-owns to the dropDown
241 button.focus();
242 doh.robot.keyPress(dojo.keys.ENTER, 1000, {});
243
244 doh.robot.sequence(d.getTestCallback(function(){
245 doh.t(button._popupStateNode.getAttribute("aria-expanded"), "now aria-expanded should be true");
246 doh.is("dijit_ColorPalette_0", button._popupStateNode.getAttribute("aria-owns"), "should aria-own the Dlg");
247 // Check roles and attributes on the popped out ColorPalette
248 var popup = dijit.byId("dijit_ColorPalette_0");
249 doh.is("grid", popup.domNode.getAttribute("role"), "popup domNode role");
250 doh.is("dropdown_default", popup.domNode.getAttribute("aria-labelledby"), "aria-labelledby of popup should point to the button");
251 }), 500);
252
253 return d;
254 },
255 tearDown: function(){
256 dijit.byId("combo_default").focus();
257 }
258 }
259 ]);
260
261 doh.register("dijit.form.ComboButton", [
262 {
263 name: "aria role and attributes",
264 timeout: 20000,
265 runTest: function(){
266 var d = new doh.Deferred(),
267 button = dijit.byId("combo_default");
268
269 doh.is("button", button._popupStateNode.getAttribute("role"), "button._popupStateNode role");
270 doh.t(button._popupStateNode.getAttribute("aria-haspopup"), "button._popupStateNode aria-haspopup");
271 doh.f(button._popupStateNode.getAttribute("aria-expanded"), "dont expect initial aria-expanded");
272 doh.f(button._popupStateNode.getAttribute("aria-owns"), "initally missing aria-owns");
273
274 button.focus(); //calling focus() on a ComboButton focuses the dropDownArrow node
275 doh.robot.keyPress(dojo.keys.ENTER, 2000, {});
276
277 doh.robot.sequence(d.getTestCallback(function(){
278 doh.t(button._popupStateNode.getAttribute("aria-expanded"), "post click aria-expanded");
279 doh.is("dijit_Menu_0", button._popupStateNode.getAttribute("aria-owns"), "should aria-own the Menu");
280 var popup = dijit.byId("dijit_Menu_0");
281 doh.is("menu", popup.domNode.getAttribute("role"), "popup domNode role");
282 doh.is("combo_default", popup.domNode.getAttribute("aria-labelledby"), "aria-labelledby of popup should point to the button");
283 }), 500);
284
285 return d;
286 },
287 tearDown: function(){
288 dijit.byId("combo_default").focus();
289 }
290 },
291 {
292 name: "tab to button",
293 timeout: 4000,
294 runTest: function(){
295 var d = new doh.Deferred();
296
297 dijit.byId("color").focus();
298
299 doh.robot.keyPress(dojo.keys.TAB, 1000, {});
300
301 var leftPart = dojo.query(".dijitButtonContents", dojo.byId("save"))[0];
302 doh.t(leftPart, "found left part of button");
303
304 doh.robot.sequence(d.getTestCallback(function(){
305 doh.is(leftPart, dojo.global.dijit.focus.curNode, "focused on left part");
306 doh.f(dojo.hasClass(dijit.byId("save").domNode, "dijitComboButtonOpened"),
307 "no dijitComboButtonOpened class");
308 }), 1000);
309 return d;
310 }
311 },
312
313 {
314 name: "click button",
315 timeout: 4000,
316 runTest: function(){
317 var d = new doh.Deferred();
318
319 var clicked = false;
320 dijit.byId("save").set("onClick", function(){ clicked = true; });
321
322 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
323
324 doh.robot.sequence(d.getTestCallback(function(){
325 doh.t(clicked, "button was clicked");
326 doh.f(dojo.hasClass(dijit.byId("save").domNode, "dijitComboButtonOpened"),
327 "no dijitComboButtonOpened class");
328 }), 1000);
329 return d;
330 }
331 },
332
333 {
334 name: "tab to drop down arrow",
335 timeout: 4000,
336 runTest: function(){
337 var d = new doh.Deferred();
338
339 var rightPart = dojo.query(".dijitDownArrowButton", dojo.byId("save"))[0];
340 doh.t(rightPart, "found right part of button");
341
342 doh.robot.keyPress(dojo.keys.TAB, 500, {});
343
344 doh.robot.sequence(d.getTestCallback(function(){
345 doh.is(rightPart, dojo.global.dijit.focus.curNode, "focused on right part of combo");
346 doh.f(dojo.hasClass(dijit.byId("save").domNode, "dijitComboButtonOpened"),
347 "no dijitComboButtonOpened class");
348 }), 1000);
349 return d;
350 }
351 },
352
353 {
354 name: "down arrow opens menu",
355 timeout: 4000,
356 runTest: function(){
357 var d = new doh.Deferred();
358
359 var rightPart = dojo.query(".dijitDownArrowButton", dojo.byId("save"))[0];
360 doh.t(rightPart, "found right part of button");
361
362 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
363
364 doh.robot.sequence(d.getTestCallback(function(){
365 doh.t(isVisible("saveMenu"), "save menu is visible: " + dijit.byId("saveMenu").domNode.style.cssText);
366 doh.t(dojo.hasClass(dijit.byId("save").domNode, "dijitComboButtonOpened"),
367 "dijitComboButtonOpened class");
368 }), 1000);
369 return d;
370 }
371 },
372
373 {
374 name: "esc closes menu",
375 timeout: 4000,
376 runTest: function(){
377 var d = new doh.Deferred();
378
379 var rightPart = dojo.query(".dijitDownArrowButton", dojo.byId("save"))[0];
380 doh.t(rightPart, "found right part of button");
381
382 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
383
384 doh.robot.sequence(d.getTestCallback(function(){
385 doh.t(isHidden("saveMenu"), "save menu was closed: " + dijit.byId("saveMenu").domNode.style.cssText);
386 doh.is(rightPart, dojo.global.dijit.focus.curNode, "refocused on right part of combo");
387 }), 1000);
388 return d;
389 }
390 },
391
392 {
393 name: "enter key opens menu",
394 timeout: 4000,
395 runTest: function(){
396 var d = new doh.Deferred();
397
398 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
399
400 doh.robot.sequence(d.getTestCallback(function(){
401 doh.t(isVisible("saveMenu"), "save menu is visible: " + dijit.byId("saveMenu").domNode.style.cssText);
402 }), 1000);
403 return d;
404 }
405 },
406
407 {
408 name: "tab closes menu",
409 timeout: 4000,
410 runTest: function(){
411 var d = new doh.Deferred();
412
413 var rightPart = dojo.query(".dijitDownArrowButton", dojo.byId("save"))[0];
414 doh.t(rightPart, "found right part of button");
415
416 doh.robot.keyPress(dojo.keys.TAB, 500, {});
417
418 doh.robot.sequence(d.getTestCallback(function(){
419 doh.t(isHidden("saveMenu"), "save menu was closed: " + dijit.byId("saveMenu").domNode.style.cssText);
420 doh.is(rightPart, dojo.global.dijit.focus.curNode, "refocused on right part of combo");
421 }), 1000);
422 return d;
423 }
424 },
425
426 {
427 name: "tab closes menu",
428 timeout: 4000,
429 runTest: function(){
430 var d = new doh.Deferred();
431
432 // Focus element before "save" ComboButton
433 dijit.byId("color").focus();
434 // And disable the ComboButton
435 dijit.byId("save").set("disabled", true);
436
437 // Tab should skip over the ComboButton entirely
438 doh.robot.keyPress(dojo.keys.TAB, 1000, {});
439
440 doh.robot.sequence(d.getTestCallback(function(){
441 var focusedWidget = dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode);
442 doh.isNot("save", focusedWidget && focusedWidget.id, "didn't focus on combo");
443 }), 1000);
444 return d;
445 }
446 }
447 ]);
448
449 doh.register("dijit.form.ToggleButton", [
450 {
451 name: "uncheck",
452 timeout: 4000,
453 runTest: function(){
454 var toggle1 = dijit.byId("toggle1");
455 var checked = toggle1.get("checked");
456 doh.t(checked, "toggle1 initially checked");
457 doh.is("true", dojo.byId('toggle1').getAttribute("aria-pressed"), "aria-pressed 1");
458
459 var d = new doh.Deferred();
460
461 var watchOld, watchNew;
462 toggle1.set("onChange", function(v){ checked = v; });
463 toggle1.watch("checked", function(name, o, n){
464 watchOld = o;
465 watchNew = n;
466 });
467
468 toggle1.focus();
469 doh.robot.typeKeys(' ', 1000, 250);
470
471 doh.robot.sequence(d.getTestCallback(function(){
472 doh.f(checked, "toggle1 unchecked");
473 doh.is("false", dojo.byId('toggle1').getAttribute("aria-pressed"), "aria-pressed 2");
474 doh.t(watchOld, "watch: previous == checked");
475 doh.f(watchNew, "watch: new == unchecked");
476 }), 1000);
477 return d;
478 }
479 },
480 {
481 name: "check",
482 timeout: 4000,
483 runTest: function(){
484 var toggle1 = dijit.byId("toggle1");
485 var checked = toggle1.get("checked");
486 doh.f(checked, "toggle1 unchecked");
487 doh.is("false", dojo.byId('toggle1').getAttribute("aria-pressed"), "aria-pressed 1");
488
489 var d = new doh.Deferred();
490
491 var watchOld, watchNew;
492 toggle1.set("onChange", function(v){ checked = v; });
493 toggle1.watch("checked", function(name, o, n){
494 watchOld = o;
495 watchNew = n;
496 });
497
498 doh.robot.typeKeys(' ', 500, 250);
499
500 doh.robot.sequence(d.getTestCallback(function(){
501 doh.t(checked, "toggle1 checked");
502 doh.is("true", dojo.byId('toggle1').getAttribute("aria-pressed"), "aria-pressed 2");
503 doh.f(watchOld, "watch: previous == unchecked");
504 doh.t(watchNew, "watch: new == checked");
505 }), 1000);
506 return d;
507 }
508 }
509
510 ]);
511
512 dojo.forEach(["SPACE", "ENTER"], function(key){
513 doh.register("Invoke Submit and Reset Buttons by " + key, [
514 {
515 name: "click Submit",
516 timeout: 5000,
517 runTest: function(){
518 var d = new doh.Deferred();
519 submitCount = 0;
520 dijit.byId("bSubmit").focus();
521 doh.robot.keyPress(dojo.keys[key], 1000, {});
522
523 doh.robot.sequence(d.getTestCallback(function(){
524 doh.is(1, submitCount, (key + ": # of times submit invoked " + submitCount));
525 }), 500);
526
527 return d;
528 }
529 },
530
531 {
532 name: "click Reset",
533 timeout: 7000,
534 runTest: function(){
535 var d = new doh.Deferred();
536 resetCount = 0;
537 dijit.byId("testName").value = "";
538
539 dijit.byId("testName").focus();
540 doh.robot.typeKeys("test", 1000, 2000);
541
542 doh.robot.sequence(function(){
543 dijit.byId("bReset").focus();
544 }, 500);
545 doh.robot.keyPress(dojo.keys[key], 1000, {});
546
547 doh.robot.sequence(d.getTestCallback(function(){
548 doh.is(1, resetCount, (key + ": reset should be invoked 1 time. actual count = " + resetCount));
549 doh.is("",dijit.byId("testName").value, "Name field has been reset");
550 }), 1000);
551 return d;
552 }
553 }
554 ]);
555 });
556
557 doh.register("Submit via ENTER key on input", {
558 name: "enter on input",
559 timeout: 5000,
560 runTest: function(){
561 var d = new doh.Deferred();
562 submitCount = 0;
563 dijit.byId("testName").focus();
564 doh.robot.keyPress(dojo.keys.ENTER, 1000, {});
565
566 doh.robot.sequence(d.getTestCallback(function(){
567 doh.is(1, submitCount, "submitted via enter key on input");
568 }), 500);
569
570 return d;
571 }
572 });
573
574 doh.register("bubbling", [
575 {
576 name: "bubbling",
577 timeout: 5000,
578 runTest: function(){
579
580 var d = new doh.Deferred(),
581 wrapper = dojo.byId("bubbleContainer"),
582 buttonNode = dojo.byId("bubble2");
583
584 // Listen for click events on the outer DOMNode.
585 var clicks = 0;
586 dojo.on(wrapper, "click", function(){
587 clicks++;
588 });
589
590 // Keyboard-click the widget button
591 doh.robot.sequence(function(){
592 buttonNode.focus();
593 }, 500);
594 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
595
596 // Check that one click event bubbled
597 doh.robot.sequence(d.getTestCallback(function(){
598 doh.is(1, clicks, "one click event bubbled");
599 }), 500);
600
601 return d;
602 }
603 }
604 ]);
605
606 doh.run();
607 });
608 </script>
609 </head>
610 </html>