|
| 1 | +<!DOCTYPE HTML> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | +<script src="../resources/js-test-pre.js"></script> |
| 5 | +<script src="../resources/accessibility-helper.js"></script> |
| 6 | +</head> |
| 7 | +<body> |
| 8 | + |
| 9 | +<button id="button">Click Me</button> |
| 10 | +<div id="container"><button id="button2">Button2</button></div> |
| 11 | +<p id="paragraph"></p> |
| 12 | + |
| 13 | +<p id="description"></p> |
| 14 | +<div id="console"></div> |
| 15 | + |
| 16 | +<script> |
| 17 | + description("This tests getting and setting Accessibility Object Model properties."); |
| 18 | + if (window.accessibilityController) { |
| 19 | + var button = document.getElementById("button"); |
| 20 | + var axButton = accessibilityController.accessibleElementById("button"); |
| 21 | + var aomRemovedButton; |
| 22 | + var paragraph = document.getElementById("paragraph"); |
| 23 | + var axParagraph; |
| 24 | + |
| 25 | + shouldBeFalse("button.accessibleNode == null"); |
| 26 | + |
| 27 | + testPropertiesDefault(); |
| 28 | + testNoReflection(); |
| 29 | + testSettingProperties(); |
| 30 | + testBecomeAccessible(); |
| 31 | + testInvalidRole(); |
| 32 | + testElementAlive(); |
| 33 | + } |
| 34 | + |
| 35 | + function testPropertiesDefault() { |
| 36 | + debug("\nSupported properties on an AccessibleNode are all null by default"); |
| 37 | + shouldBeNull("button.accessibleNode.role"); |
| 38 | + shouldBeNull("button.accessibleNode.label"); |
| 39 | + // Invalid property value should be undefined |
| 40 | + shouldBe("button.accessibleNode.foo", "undefined"); |
| 41 | + } |
| 42 | + |
| 43 | + function testNoReflection() { |
| 44 | + debug("\nARIA attributes should not be reflected into AOM properties."); |
| 45 | + button.setAttribute("role", "checkbox"); |
| 46 | + button.setAttribute("aria-label", "label"); |
| 47 | + shouldBe("axButton.role", "'AXRole: AXCheckBox'"); |
| 48 | + shouldBe("axButton.description", "'AXDescription: label'"); |
| 49 | + |
| 50 | + // AOM properties should be null even if we have set ARIA attributes. |
| 51 | + shouldBeNull("button.accessibleNode.role"); |
| 52 | + shouldBeNull("button.accessibleNode.label"); |
| 53 | + } |
| 54 | + |
| 55 | + function testSettingProperties() { |
| 56 | + debug("\nTest setting AOM properties. And make sure AOM takes precedence."); |
| 57 | + |
| 58 | + // Set the ARIA attributes on the element first. |
| 59 | + button.setAttribute("role", "checkbox"); |
| 60 | + button.setAttribute("aria-label", "label"); |
| 61 | + |
| 62 | + // Then set the corresponding AOM properties to some different values. |
| 63 | + button.accessibleNode.role = "slider"; |
| 64 | + shouldBe("button.accessibleNode.role", "'slider'"); |
| 65 | + button.accessibleNode.label = "AOM Label"; |
| 66 | + shouldBe("button.accessibleNode.label", "'AOM Label'"); |
| 67 | + |
| 68 | + // The AOM property values should override ARIA attributes. |
| 69 | + shouldBe("axButton.role", "'AXRole: AXSlider'"); |
| 70 | + shouldBe("axButton.description", "'AXDescription: AOM Label'"); |
| 71 | + } |
| 72 | + |
| 73 | + function testBecomeAccessible() { |
| 74 | + debug("\nSetting some of the AOM properties should be able to make an element accessible."); |
| 75 | + axParagraph = accessibilityController.accessibleElementById("paragraph"); |
| 76 | + shouldBeTrue("axParagraph == null || axParagraph == undefined"); |
| 77 | + |
| 78 | + // The element should be accessible if it has a label. |
| 79 | + paragraph.accessibleNode.label = "test label"; |
| 80 | + axParagraph = accessibilityController.accessibleElementById("paragraph"); |
| 81 | + shouldBeFalse("axParagraph.isIgnored"); |
| 82 | + } |
| 83 | + |
| 84 | + function testInvalidRole() { |
| 85 | + debug("\nAn invalid role should be ignored."); |
| 86 | + |
| 87 | + // Clear the ARIA attribute and AOM property value. |
| 88 | + button.removeAttribute("role"); |
| 89 | + button.accessibleNode.role = null; |
| 90 | + shouldBe("button.accessibleNode.role", "null"); |
| 91 | + shouldBe("axButton.role", "'AXRole: AXButton'"); |
| 92 | + |
| 93 | + // Accessibility should use the semantic role if an invalid role is provided. |
| 94 | + button.accessibleNode.role = "badrole"; |
| 95 | + shouldBe("button.accessibleNode.role", "'badrole'"); |
| 96 | + shouldBe("axButton.role", "'AXRole: AXButton'"); |
| 97 | + } |
| 98 | + |
| 99 | + function testElementAlive() { |
| 100 | + debug("\nAn AccessibleNode keeps its element alive."); |
| 101 | + // Get the button to be removed and access its accessibleNode. |
| 102 | + (function() { |
| 103 | + var button2 = document.getElementById("button2"); |
| 104 | + aomRemovedButton = button2.accessibleNode; |
| 105 | + aomRemovedButton.role = "checkbox"; |
| 106 | + })(); |
| 107 | + shouldBe("aomRemovedButton.role", "'checkbox'"); |
| 108 | + |
| 109 | + // Remove the button make sure we are still able to access the accessibleNode. |
| 110 | + (function() { |
| 111 | + var button2 = document.getElementById("button2"); |
| 112 | + button2.parentElement.removeChild(button2); |
| 113 | + })(); |
| 114 | + gc(); |
| 115 | + shouldBe("aomRemovedButton.role", "'checkbox'"); |
| 116 | + } |
| 117 | + |
| 118 | +</script> |
| 119 | +<script src="../resources/js-test-post.js"></script> |
| 120 | +</body> |
| 121 | +</html> |
0 commit comments