| <!DOCTYPE html><!-- webkit-test-runner [ ARIAActionsSupportEnabled=true ] --> | |
| <html> | |
| <body id="body"> | |
| <script src="../resources/js-test.js"></script> | |
| <div id="content"> | |
| <div id="test" data="some data"> | |
| <div id="firstChild"></div> | |
| <div id="secondChild"></div> | |
| <div id="thirdChild"></div> | |
| </div> | |
| <p id="description"></p> | |
| <div id="console"></div> | |
| <script> | |
| description("This tests ARIA IDL Attribute Reflection."); | |
| var element = document.getElementById("test"); | |
| var data = element.getAttribute("data"); | |
| var otherData = "other data"; | |
| var currentProperty; | |
| var currentAttribute; | |
| function isNonReflectionMethod(method) { | |
| switch (method) { | |
| case "ariaNotify": | |
| return true; | |
| } | |
| return false; | |
| } | |
| function isElementReflectionProperty(property) { | |
| switch (property) { | |
| case "ariaActiveDescendantElement": | |
| return true; | |
| } | |
| return false; | |
| } | |
| function isElementsArrayReflectionProperty(property) { | |
| switch (property) { | |
| case "ariaActionsElements": | |
| case "ariaControlsElements": | |
| case "ariaDescribedByElements": | |
| case "ariaDetailsElements": | |
| case "ariaErrorMessageElements": | |
| case "ariaFlowToElements": | |
| case "ariaLabelledByElements": | |
| case "ariaOwnsElements": | |
| return true; | |
| } | |
| return false; | |
| } | |
| function convertPropertyToAttribute(property) { | |
| if (isElementReflectionProperty(property)) | |
| property = property.replace("Element", ""); | |
| else if (isElementsArrayReflectionProperty(property)) | |
| property = property.replace("Elements", ""); | |
| return property.replace("aria", "aria-").toLowerCase(); | |
| } | |
| function getDataProperty(property) { | |
| if (isElementReflectionProperty(property)) | |
| return firstChild; | |
| else if (isElementsArrayReflectionProperty(property)) | |
| return [firstChild, secondChild]; | |
| return data; | |
| } | |
| function getDataAttribute(property) { | |
| if (isElementReflectionProperty(property)) | |
| return firstChild.id; | |
| else if (isElementsArrayReflectionProperty(property)) | |
| return firstChild.id + " " + secondChild.id; | |
| return data; | |
| } | |
| function getOtherDataProperty(property) { | |
| if (isElementReflectionProperty(property)) | |
| return secondChild; | |
| else if (isElementsArrayReflectionProperty(property)) | |
| return [thirdChild]; | |
| return otherData; | |
| } | |
| function getOtherDataAttribute(property) { | |
| if (isElementReflectionProperty(property)) | |
| return secondChild.id; | |
| else if (isElementsArrayReflectionProperty(property)) | |
| return thirdChild.id; | |
| return otherData; | |
| } | |
| function testElement() { | |
| currentAttribute = convertPropertyToAttribute(currentProperty); | |
| debug("\nTest " + currentProperty + " < - > " + currentAttribute); | |
| shouldBeNull("element[currentProperty]"); | |
| shouldBeNull("element.getAttribute(currentAttribute)"); | |
| // Set the property value | |
| dataProperty = getDataProperty(currentProperty); | |
| dataAttribute = getDataAttribute(currentProperty); | |
| element[currentProperty] = dataProperty; | |
| if (isElementReflectionProperty(currentProperty) || isElementsArrayReflectionProperty(currentProperty)) | |
| shouldBeEmptyString("element.getAttribute(currentAttribute)"); | |
| else | |
| shouldBe("element.getAttribute(currentAttribute)", "dataAttribute"); | |
| // Set the attribute value | |
| otherDataProperty = getOtherDataProperty(currentProperty); | |
| otherDataAttribute = getOtherDataAttribute(currentProperty); | |
| debug("element.setAttribute(\"" + currentAttribute + "\", otherData);"); | |
| element.setAttribute(currentAttribute, otherDataAttribute); | |
| shouldBe("element[currentProperty]", "otherDataProperty"); | |
| } | |
| function testRole() { | |
| currentProperty = "role"; | |
| testElement(); | |
| } | |
| if (window.accessibilityController) { | |
| testRole(); | |
| var count = 0; | |
| for (var propertyName in element) { | |
| if (propertyName.startsWith("aria") && !isNonReflectionMethod(propertyName)) { | |
| currentProperty = propertyName; | |
| testElement(); | |
| count++; | |
| } | |
| } | |
| debug("\n"); | |
| shouldBe("count", "52"); | |
| } else { | |
| testFailed("Could not load accessibility controller"); | |
| } | |
| </script> | |
| </body> | |
| </html> |