wai.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <html>
  2. <head>
  3. <title>Dijit wai unit test</title>
  4. <script type="text/javascript" src="../../../dojo/dojo.js"
  5. djConfig="isDebug: true"></script>
  6. <script type="text/javascript">
  7. dojo.require("doh.runner");
  8. dojo.require("dijit.dijit");
  9. dojo.addOnLoad(function(){
  10. doh.register("dijit.tests._base.wai",
  11. [
  12. function getWaiRoleOnElementWithNoRole(){
  13. var elem = dojo.byId("no-role-or-states");
  14. doh.assertFalse(dijit.hasWaiRole(elem));
  15. doh.assertEqual("", dijit.getWaiRole(elem));
  16. },
  17. function getEmptyWairoleRole(){
  18. var elem = dojo.byId("empty-wairole");
  19. doh.assertTrue(dijit.hasWaiRole(elem));
  20. doh.assertEqual("", dijit.getWaiRole(elem));
  21. },
  22. function getWairoleRole(){
  23. var elem = dojo.byId("wairole");
  24. doh.assertTrue(dijit.hasWaiRole(elem));
  25. doh.assertEqual("menuitem", dijit.getWaiRole(elem));
  26. },
  27. function getUnprefixedRole(){
  28. var elem = dojo.byId("unprefixed-role");
  29. doh.assertTrue(dijit.hasWaiRole(elem));
  30. doh.assertEqual("menuitem", dijit.getWaiRole(elem));
  31. },
  32. function setWaiRole(){
  33. var div = document.createElement("div");
  34. dijit.setWaiRole(div, "menuitem");
  35. if(dojo.isFF && dojo.isFF < 3){
  36. doh.assertEqual("wairole:menuitem",
  37. div.getAttribute("role"));
  38. }else{
  39. doh.assertEqual("menuitem",
  40. div.getAttribute("role"));
  41. }
  42. },
  43. function removeWaiRole(){
  44. var div = document.createElement("div");
  45. dijit.setWaiRole(div, "menuitem");
  46. dijit.removeWaiRole(div);
  47. if(div.hasAttribute){
  48. doh.assertFalse(div.hasAttribute("role"));
  49. }else{
  50. doh.assertTrue(div.getAttribute("role") == null
  51. || div.getAttribute("role") == "");
  52. }
  53. },
  54. function getWaiStateOnElementWithNoState(){
  55. var elem = dojo.byId("no-role-or-states");
  56. doh.assertFalse(dijit.hasWaiState(elem, "checked"));
  57. doh.assertEqual("", dijit.getWaiState(elem, "checked"));
  58. },
  59. function getWaiState(){
  60. if(dojo.isFF && dojo.isFF < 3){
  61. var div = document.createElement("div");
  62. div.setAttributeNS("http://www.w3.org/2005/07/aaa",
  63. "aaa:checked", "true");
  64. doh.assertTrue(dijit.hasWaiState(div, "checked"));
  65. doh.assertEqual("true",
  66. dijit.getWaiState(div, "checked"));
  67. }else{
  68. var elem = dojo.byId("checked");
  69. doh.assertTrue(dijit.hasWaiState(elem, "checked"));
  70. doh.assertEqual("true",
  71. dijit.getWaiState(elem, "checked"));
  72. }
  73. },
  74. function setWaiState(){
  75. var div = document.createElement("div");
  76. dijit.setWaiState(div, "checked", "true");
  77. if(dojo.isFF && dojo.isFF < 3){
  78. doh.assertEqual("true",
  79. div.getAttributeNS("http://www.w3.org/2005/07/aaa",
  80. "checked"));
  81. }else{
  82. doh.assertEqual("true",
  83. div.getAttribute("aria-checked"));
  84. }
  85. },
  86. function removeWaiState(){
  87. var div = document.createElement("div");
  88. dijit.setWaiState(div, "checked", "true");
  89. dijit.removeWaiState(div, "checked");
  90. doh.assertEqual("", dijit.getWaiState(div, "checked"));
  91. }
  92. ]
  93. );
  94. doh.run();
  95. });
  96. </script>
  97. </head>
  98. <body>
  99. <div id="no-role-or-states"></div>
  100. <div id="empty-wairole" role="wairole:"></div>
  101. <div id="wairole" role="wairole:menuitem"></div>
  102. <div id="unprefixed-role" role="menuitem"></div>
  103. <div id="checked" aria-checked="true"></div>
  104. </body>
  105. </html>