Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE HTML> | |
| 2 <script src="../resources/testharness.js"></script> | |
| 3 <script src="../resources/testharnessreport.js"></script> | |
| 4 | |
| 5 <!-- | |
| 6 | |
| 7 Accessibility Object Model | |
| 8 Explainer: https://github.com/WICG/aom/blob/master/explainer.md | |
| 9 Spec: https://wicg.github.io/aom/spec/ | |
| 10 | |
| 11 --> | |
| 12 | |
| 13 <button id="button">Click Me</button> | |
| 14 | |
| 15 <script> | |
| 16 if (window.internals) | |
| 17 internals.runtimeFlags.accessibilityObjectModelEnabled = true; | |
| 18 | |
| 19 test(function(t) { | |
| 20 var button = document.getElementById("button"); | |
| 21 assert_equals(button.nodeType, Node.ELEMENT_NODE); | |
| 22 assert_not_equals(button.accessibleNode, null); | |
| 23 }, "DOM Elements have an AccessibleNode"); | |
| 24 | |
| 25 test(function(t) { | |
| 26 var button = document.getElementById("button"); | |
| 27 var staticText = button.firstChild; | |
| 28 assert_equals(staticText.nodeType, Node.TEXT_NODE); | |
| 29 assert_not_equals(staticText.accessibleNode, null); | |
| 30 }, "DOM Text nodes do not have an AccessibleNode."); | |
| 31 | |
| 32 test(function(t) { | |
| 33 var button = document.getElementById("button"); | |
| 34 var aomButton = button.accessibleNode; | |
| 35 | |
| 36 assert_equals(aomButton.role, null); | |
| 37 assert_equals(aomButton.label, null); | |
| 38 assert_equals(aomButton.foo, undefined); | |
| 39 assert_equals(aomButton.bar, undefined); | |
| 40 }, "Supported properties on an AccessibleNode are all null by default"); | |
| 41 | |
| 42 test(function(t) { | |
| 43 var button = document.getElementById("button"); | |
| 44 var aomButton = button.accessibleNode; | |
| 45 var axButton = accessibilityController.accessibleElementById("button"); | |
| 46 | |
| 47 button.setAttribute("role", "checkbox"); | |
| 48 button.setAttribute("aria-label", "Check Me"); | |
| 49 | |
| 50 assert_equals(axButton.role, "AXRole: AXCheckBox"); | |
| 51 assert_equals(axButton.name, "Check Me"); | |
| 52 | |
| 53 assert_equals(aomButton.role, "checkbox"); | |
| 54 assert_equals(aomButton.label, "Check Me"); | |
| 55 }, "ARIA attributes are reflected into AOM properties"); | |
| 56 | |
| 57 test(function(t) { | |
| 58 var button = document.getElementById("button"); | |
| 59 var aomButton = button.accessibleNode; | |
| 60 var axButton = accessibilityController.accessibleElementById("button"); | |
| 61 | |
| 62 button.setAttribute("role", "beyonce"); | |
| 63 | |
| 64 assert_equals(axButton.role, "AXRole: AXButton"); | |
| 65 | |
| 66 assert_equals(aomButton.role, "beyonce"); | |
| 67 }, "Invalid ARIA roles are still reflected into AOM properties"); | |
| 68 | |
| 69 test(function(t) { | |
| 70 var button = document.getElementById("button"); | |
| 71 var aomButton = button.accessibleNode; | |
| 72 var axButton = accessibilityController.accessibleElementById("button"); | |
| 73 | |
| 74 aomButton.role = "slider"; | |
| 75 assert_equals(aomButton.role, "slider"); | |
| 76 assert_equals(axButton.role, "AXRole: AXSlider"); | |
| 77 }, "Test setting AccessibleNode.role"); | |
| 78 | |
| 79 test(function(t) { | |
| 80 var button = document.getElementById("button"); | |
| 81 var aomButton = button.accessibleNode; | |
| 82 var axButton = accessibilityController.accessibleElementById("button"); | |
| 83 | |
| 84 button.removeAttribute("role"); | |
| 85 aomButton.role = null; | |
| 86 assert_equals(aomButton.role, null); | |
| 87 assert_equals(axButton.role, "AXRole: AXButton"); | |
| 88 | |
| 89 aomButton.role = "doctor"; | |
| 90 assert_equals(aomButton.role, "doctor"); | |
| 91 assert_equals(axButton.role, "AXRole: AXButton"); | |
| 92 }, "An invalid role should be ignored if there's no ARIA."); | |
| 93 | |
| 94 test(function(t) { | |
| 95 var button = document.getElementById("button"); | |
| 96 var aomButton = button.accessibleNode; | |
| 97 var axButton = accessibilityController.accessibleElementById("button"); | |
| 98 | |
| 99 aomButton.role = "switch checkbox"; | |
| 100 assert_equals(aomButton.role, "switch checkbox"); | |
| 101 assert_equals(axButton.role, "AXRole: AXSwitch"); | |
| 102 | |
| 103 aomButton.role = "tickbox checkbox"; | |
| 104 assert_equals(aomButton.role, "tickbox checkbox"); | |
| 105 assert_equals(axButton.role, "AXRole: AXCheckBox"); | |
| 106 }, "Fallback roles are supported."); | |
| 107 | |
| 108 test(function(t) { | |
| 109 var button = document.getElementById("button"); | |
| 110 var aomButton = button.accessibleNode; | |
| 111 var axButton = accessibilityController.accessibleElementById("button"); | |
| 112 | |
| 113 button.removeAttribute("aria-label"); | |
| 114 aomButton.label = "New Label"; | |
| 115 assert_equals(aomButton.label, "New Label"); | |
| 116 assert_equals(axButton.name, "New Label"); | |
| 117 }, "Test setting AccessibleNode.label"); | |
| 118 </script> | |
| 119 | |
| 120 <button id="button2">Click Me</button> | |
| 121 | |
| 122 <script> | |
| 123 test(function(t) { | |
| 124 var button = document.getElementById("button2"); | |
| 125 var aomButton = button.accessibleNode; | |
| 126 var axButton = accessibilityController.accessibleElementById("button2"); | |
| 127 | |
| 128 button.setAttribute("role", "textbox"); | |
| 129 button.setAttribute("aria-label", "ARIA"); | |
| 130 assert_equals(axButton.role, "AXRole: AXTextField"); | |
| 131 assert_equals(axButton.name, "ARIA"); | |
| 132 | |
| 133 aomButton.role = "radio"; | |
| 134 aomButton.label = "AOM"; | |
| 135 assert_equals(axButton.role, "AXRole: AXRadioButton"); | |
| 136 assert_equals(axButton.name, "AOM"); | |
| 137 }, "Test that AOM properties override ARIA attributes"); | |
| 138 </script> | |
| 139 | |
| 140 <button id="button3">Click Me</button> | |
| 141 | |
| 142 <script> | |
| 143 test(function(t) { | |
| 144 var button = document.getElementById("button3"); | |
| 145 var aomButton = button.accessibleNode; | |
| 146 var axButton = accessibilityController.accessibleElementById("button3"); | |
| 147 assert_equals(axButton.role, "AXRole: AXButton"); | |
| 148 assert_equals(axButton.name, "Click Me"); | |
| 149 | |
| 150 button.setAttribute("role", "textbox"); | |
| 151 button.setAttribute("aria-label", "ARIA"); | |
| 152 assert_equals(axButton.role, "AXRole: AXTextField"); | |
| 153 assert_equals(axButton.name, "ARIA"); | |
| 154 | |
| 155 aomButton.role = "radio"; | |
| 156 aomButton.label = "AOM"; | |
| 157 assert_equals(axButton.role, "AXRole: AXRadioButton"); | |
| 158 assert_equals(axButton.name, "AOM"); | |
|
aboxhall
2017/03/23 04:34:23
Add a case checking that setting the attribute to
dmazzoni
2017/03/23 17:06:48
Good idea, done.
| |
| 159 | |
| 160 aomButton.role = null; | |
| 161 aomButton.label = null; | |
| 162 assert_equals(axButton.role, "AXRole: AXButton"); | |
| 163 assert_equals(axButton.name, "Click Me"); | |
| 164 }, "Once an AOM property has been set, ARIA no longer has any effect"); | |
| 165 </script> | |
| OLD | NEW |