PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/public/javascripts/dojo/dijit.1/tests/robot/Dialog_a11y.html

https://github.com/ryangroth5/claims
HTML | 352 lines | 299 code | 51 blank | 2 comment | 0 complexity | d83efef0ea836e7720bbe0de1e66d1bc MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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 Dialog A11Y Test</title>
  6. <style>
  7. @import "../../../util/doh/robot/robot.css";
  8. </style>
  9. <!-- required: dojo.js -->
  10. <script type="text/javascript" src="../../../dojo/dojo.js"
  11. djConfig="isDebug: true"></script>
  12. <!-- functions to help test -->
  13. <script type="text/javascript" src="../helpers.js"></script>
  14. <script type="text/javascript">
  15. dojo.require("dijit.dijit"); // optimize: load dijit layer
  16. dojo.require("dijit.robotx");
  17. var dialogIds = [
  18. { dlg: "dialog1", firstFocus: "name" },
  19. { dlg: "tabDialog",
  20. firstFocus: "dijit_layout__TabButton_0" }, // Warning: if id changes in the test file, this needs updating
  21. { dlg: "fifthDlg", firstFocus: "fifthDlg" },
  22. { dlg: "dialog6", firstFocus: "dialog6", fileInput: "afile" },
  23. { dlg: "cantmove", firstFocus: "cantmove" },
  24. { dlg: "preventer", firstFocus: "preventerOK" }
  25. ];
  26. // testing utilities
  27. function dialogTests(){
  28. var that = {};
  29. var xtraPara = null;
  30. var firstTabStop = null;
  31. var gotFocus = false;
  32. var lostFocus = false;
  33. var focusConnect = null;
  34. var blurConnect = null;
  35. // Define a known location to place keyboard focus, and put it there. Allows for a
  36. // place for focus to return to when dialog is dismissed.
  37. function addTabNavFocus(){
  38. removeTabNavFocus();
  39. xtraPara = dojo.doc.createElement("p");
  40. dojo.attr(xtraPara, 'tabindex', 0);
  41. xtraPara.innerHTML = "Tab-focussable paragraph";
  42. dojo.place(xtraPara, dojo.body(), "first");
  43. xtraPara.focus();
  44. };
  45. function removeTabNavFocus(){
  46. if(xtraPara && xtraPara.parentNode){
  47. xtraPara.parentNode.removeChild(xtraPara);
  48. }
  49. };
  50. that.ariaFocusSetup = function(/*dialog's and first focusable ids*/ ids){
  51. addTabNavFocus();
  52. gotFocus = lostFocus = false;
  53. var dlog = dijit.byId(ids.dlg);
  54. // need to show dialog in order to find the first tab stop.
  55. if( !dojo.isFF && ids.fileInput){
  56. that.firstTabStop = dojo.byId(ids.fileInput);
  57. }else{
  58. that.firstTabStop = dojo.byId(ids.firstFocus);
  59. }
  60. focusConnect = dojo.connect(that.firstTabStop, "onfocus", function(){
  61. gotFocus = true;
  62. });
  63. blurConnect = dojo.connect(that.firstTabStop, "onblur", function(){
  64. lostFocus = true;
  65. });
  66. };
  67. that.ariaFocusTeardown = function(){
  68. removeTabNavFocus();
  69. dojo.disconnect(focusConnect);
  70. dojo.disconnect(blurConnect);
  71. };
  72. that.ariaFocus = function(dlogId){
  73. var d = new doh.Deferred();
  74. var dlog = dijit.byId(dlogId.dlg);
  75. var doShow = function(){
  76. dlog.show();
  77. };
  78. var doHide = function(){
  79. dlog.hide();
  80. };
  81. // <firstTabStop> set in that.ariaFocusSetup(), above.
  82. doh.isNot(null, that.firstTabStop, + "no first-focusable item for dialog: " + dlog.id);
  83. doh.robot.sequence(doShow, 200); // wait a bit for the connects to connect.
  84. doh.robot.sequence(doHide, 800);
  85. var testShowHide = function(){
  86. doh.t(gotFocus, "first focusable didn't get focus on open, for: " + dlog.id);
  87. doh.t(lostFocus, "first focusable didn't lose focus on close, for: " + dlog.id);
  88. };
  89. doh.robot.sequence(d.getTestCallback(testShowHide), 1200);
  90. return d;
  91. };
  92. return that;
  93. } // end dialogTests().
  94. var dialogTest;
  95. dojo.addOnLoad(function(){
  96. doh.robot.initRobot('../test_Dialog.html');
  97. doh.register("dijit.Dialog keyboard tests (cancel)",[
  98. {
  99. name: "open dialog",
  100. timeout: 4000,
  101. runTest: function(){
  102. var d = new doh.Deferred();
  103. // Click the button. We do this manually rather than calling Dialog.show()
  104. // so we can later test that focus is restored (to the previous position)
  105. // when the dialog is closed
  106. doh.robot.sequence(function(){
  107. dojo.byId("dialog1button").focus();
  108. }, 500);
  109. doh.robot.keyPress(dojo.keys.SPACE, 500, {});
  110. doh.robot.typeKeys("Bill", 1000);
  111. doh.robot.sequence(d.getTestCallback(function(){
  112. doh.t(isVisible("dialog1", "dialog 1 has been made visible"));
  113. doh.is("name", dojo.global.dijit._curFocus.id, "focus is on the first field");
  114. }), 500);
  115. return d;
  116. }
  117. },
  118. {
  119. name: "tab to the date field",
  120. timeout: 10000,
  121. runTest: function(){
  122. var d = new doh.Deferred();
  123. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  124. doh.robot.typeKeys("Japan", 500);
  125. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  126. doh.robot.sequence(d.getTestCallback(function(){
  127. doh.is("date", dojo.global.dijit._curFocus.id, "focus is on the date field");
  128. }), 1000);
  129. return d;
  130. }
  131. },
  132. {
  133. name: "close date drop down",
  134. timeout: 4000,
  135. runTest: function(){
  136. var d = new doh.Deferred();
  137. doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
  138. doh.robot.sequence(d.getTestCallback(function(){
  139. doh.is("date", dojo.global.dijit._curFocus.id, "focus is still on the date field");
  140. doh.t(isVisible("dialog1", "dialog 1 wasn't closed"));
  141. }), 500);
  142. return d;
  143. }
  144. },
  145. {
  146. name: "tabbing loops around",
  147. timeout: 4000,
  148. runTest: function(){
  149. var d = new doh.Deferred();
  150. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  151. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  152. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  153. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  154. doh.robot.sequence(d.getTestCallback(function(){
  155. doh.is("name", dojo.global.dijit._curFocus.id, "focus looped back to name field");
  156. }), 500);
  157. return d;
  158. }
  159. },
  160. {
  161. name: "reverse-tabbing loops around",
  162. timeout: 4000,
  163. runTest: function(){
  164. var d = new doh.Deferred();
  165. doh.robot.keyPress(dojo.keys.TAB, 500, {shift: true});
  166. doh.robot.sequence(d.getTestCallback(function(){
  167. doh.is("ok", dojo.global.dijit._curFocus.id, "focus looped back to submit button");
  168. }), 500);
  169. return d;
  170. }
  171. },
  172. {
  173. name: "cancel dialog",
  174. timeout: 4000,
  175. runTest: function(){
  176. var d = new doh.Deferred();
  177. doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
  178. doh.robot.sequence(d.getTestCallback(function(){
  179. doh.t(isHidden("dialog1", "dialog 1 was closed"));
  180. doh.is("dialog1button", dojo.global.dijit._curFocus.id, "focus returned to button");
  181. }), 500);
  182. return d;
  183. }
  184. }
  185. ]);
  186. doh.register("dijit.Dialog keyboard tests (submit)",[
  187. {
  188. name: "submit some data",
  189. timeout: 15000,
  190. setUp: function(){
  191. dijit.byId("dialog1").reset();
  192. },
  193. runTest: function(){
  194. var d = new doh.Deferred();
  195. // Setup handler to catch submitted data
  196. var data;
  197. dojo.connect(dijit.byId("dialog1"), "execute", function(vals){
  198. data = vals;
  199. });
  200. // Open the dialog
  201. doh.robot.sequence(function(){
  202. dojo.byId("dialog1button").focus();
  203. }, 500);
  204. doh.robot.keyPress(dojo.keys.SPACE, 500, {});
  205. // Enter some info
  206. doh.robot.typeKeys("Ted", 2000);
  207. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  208. doh.robot.typeKeys("America", 500);
  209. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  210. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  211. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  212. doh.robot.keyPress(dojo.keys.TAB, 500, {});
  213. // Submit
  214. doh.robot.keyPress(dojo.keys.SPACE, 500, {});
  215. doh.robot.sequence(d.getTestCallback(function(){
  216. doh.t(isHidden("dialog1", "dialog 1 was closed on submit"));
  217. doh.t(data, "got submit data");
  218. doh.is("Ted", data.name, "Name");
  219. doh.is("America", data.loc, "Location");
  220. }), 500);
  221. return d;
  222. }
  223. }
  224. ]);
  225. var dialogTest = dialogTests();
  226. // Loop to register tests for each dialog in the <dialogIds> array
  227. // TODO:
  228. // The a11yAriaRole, a11yLabel, and a11yAriaExpanded tests probably only need
  229. // to be done for one dialog.
  230. // TODO:
  231. // Even the focus tests, the only things we need to test that haven't been tested
  232. // already are:
  233. // 1. focus for a dialog with no focusable elements
  234. // 2. the file focus thing
  235. for(i=0; i<dialogIds.length; i++){
  236. // aria role and properties (aria-labelledby) tests.
  237. doh.register("a11yAriaRole", {
  238. name:dialogIds[i].dlg+"_role",
  239. dialogId:dialogIds[i].dlg,
  240. runTest:function(){
  241. var dlog = dijit.byId(this.dialogId);
  242. doh.is("dialog", dijit.getWaiRole(dlog.domNode), dlog.id + ": aria role (dialog)");
  243. }
  244. });
  245. doh.register("a11yLabel", {
  246. name:dialogIds[i].dlg+"_label",
  247. dialogId:dialogIds[i].dlg,
  248. runTest:function(){
  249. var dlog = dijit.byId(this.dialogId);
  250. var label = dijit.getWaiState(dlog.domNode, 'label');
  251. if(!label){
  252. var labelNodeId = dijit.getWaiState(dlog.domNode, 'labelledby');
  253. if(labelNodeId){
  254. var labelNode = dojo.byId(labelNodeId);
  255. }
  256. if(labelNode){
  257. label = labelNode.innerHTML;
  258. }
  259. }
  260. var hint = "aria-label or aria-labelledby (" + dlog.id + ")";
  261. doh.isNot(null, label, "null " + hint);
  262. doh.isNot("", label, "empty " + hint);
  263. }
  264. });
  265. /* // dijit.Dialog does not implment aria-expanded as of this writing -- should it?
  266. doh.register("a11yAriaExpanded",{
  267. name:dialogIds[i].dlg+"_aria-expanded",
  268. dialogId:dialogIds[i].dlg,
  269. runTest:function(){
  270. var dlog = dijit.byId(this.dialogId);
  271. var expanded = dijit.getWaiState(dlog.domNode, 'expanded');
  272. if(expanded=="") expanded = "false";
  273. doh.is("false", expanded, dlog.id + ": not shown");
  274. dlog.show();
  275. expanded = dijit.getWaiState(dlog.domNode, 'expanded');
  276. dlog.hide();
  277. doh.is("true", expanded, dlog.id + ": shown");
  278. }
  279. });
  280. */
  281. // First focusable tests
  282. doh.register("a11yFirstFocusable",{
  283. name:"a11yFirstFocusable_"+dialogIds[i].dlg,
  284. dialog:dialogIds[i],
  285. timeout:4000,
  286. setUp:function(){
  287. dialogTest.ariaFocusSetup(this.dialog);
  288. },
  289. runTest:function(){
  290. return dialogTest.ariaFocus(this.dialog);
  291. },
  292. tearDown:function(){
  293. dialogTest.ariaFocusTeardown();
  294. }
  295. });
  296. } // end for() loop thru dialogIds array.
  297. doh.run();
  298. });
  299. </script>
  300. </head>
  301. </html>