Diff
Modified: trunk/LayoutTests/ChangeLog (239985 => 239986)
--- trunk/LayoutTests/ChangeLog 2019-01-15 16:24:57 UTC (rev 239985)
+++ trunk/LayoutTests/ChangeLog 2019-01-15 16:28:37 UTC (rev 239986)
@@ -1,3 +1,14 @@
+2019-01-15 Devin Rousso <[email protected]>
+
+ Web Inspector: Audit: provide a way to query for all nodes with a given computed Accessibility role
+ https://bugs.webkit.org/show_bug.cgi?id=193228
+ <rdar://problem/46787787>
+
+ Reviewed by Joseph Pecoraro.
+
+ * inspector/audit/run-accessibility.html: Added.
+ * inspector/audit/run-accessibility-expected.txt: Added.
+
2019-01-15 Zalan Bujtas <[email protected]>
[LFC] Use the containing block's padding box to position out-of-flow elements.
Added: trunk/LayoutTests/inspector/audit/run-accessibility-expected.txt (0 => 239986)
--- trunk/LayoutTests/inspector/audit/run-accessibility-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/audit/run-accessibility-expected.txt 2019-01-15 16:28:37 UTC (rev 239986)
@@ -0,0 +1,49 @@
+Tests for the injected WebInspectorAudit.Accessibility functions.
+
+
+
+== Running test suite: Audit.run.Accessibility
+-- Running test case: Audit.run.Accessibility.getElementsByComputedRole.FakeRole
+Audit setup...
+Audit run `WebInspectorAudit.Accessibility.getElementsByComputedRole("FakeRole")`...
+Result: []
+Audit teardown...
+
+-- Running test case: Audit.run.Accessibility.getElementsByComputedRole.FakeRole.parent
+Audit setup...
+Audit run `WebInspectorAudit.Accessibility.getElementsByComputedRole("FakeRole", document.querySelector("#parent"))`...
+Result: []
+Audit teardown...
+
+-- Running test case: Audit.run.Accessibility.getElementsByComputedRole.tree
+Audit setup...
+Audit run `WebInspectorAudit.Accessibility.getElementsByComputedRole("tree")`...
+Result: ["#parent"]
+Audit teardown...
+
+-- Running test case: Audit.run.Accessibility.getElementsByComputedRole.tree.parent
+Audit setup...
+Audit run `WebInspectorAudit.Accessibility.getElementsByComputedRole("tree", document.querySelector("#parent"))`...
+Result: []
+Audit teardown...
+
+-- Running test case: Audit.run.Accessibility.getElementsByComputedRole.button
+Audit setup...
+Audit run `WebInspectorAudit.Accessibility.getElementsByComputedRole("button")`...
+Result: ["#button","#link"]
+Audit teardown...
+
+-- Running test case: Audit.run.Accessibility.getElementsByComputedRole.button.parent
+Audit setup...
+Audit run `WebInspectorAudit.Accessibility.getElementsByComputedRole("button", document.querySelector("#parent"))`...
+Result: []
+Audit teardown...
+
+-- Running test case: Audit.run.Accessibility.InvalidCopiedFunctionCall
+Audit setup...
+Copying WebInspectorAudit to window...
+Audit teardown...
+Testing copied getElementsByComputedRole...
+PASS: Should produce an exception.
+Error: NotAllowedError: Cannot be called outside of a Web Inspector Audit
+
Added: trunk/LayoutTests/inspector/audit/run-accessibility.html (0 => 239986)
--- trunk/LayoutTests/inspector/audit/run-accessibility.html (rev 0)
+++ trunk/LayoutTests/inspector/audit/run-accessibility.html 2019-01-15 16:28:37 UTC (rev 239986)
@@ -0,0 +1,97 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+function stringify(result) {
+ if (result instanceof Element)
+ return "#" + result.id;
+ if (Array.isArray(result))
+ return JSON.stringify(result.map(stringify));
+ return false;
+}
+
+function test()
+{
+ let suite = InspectorTest.Audit.createSuite("Audit.run.Accessibility");
+
+ function evaluateStringForTest(func, target, role) {
+ if (target) {
+ if (role)
+ return `WebInspectorAudit.Accessibility.${func}("${role}", document.querySelector("#${target}"))`;
+ return `WebInspectorAudit.Accessibility.${func}(document.querySelector("#${target}"))`;
+ }
+
+ if (role)
+ return `WebInspectorAudit.Accessibility.${func}("${role}")`;
+ }
+
+ const tests = [
+ { func: "getElementsByComputedRole", role: "FakeRole" },
+ { func: "getElementsByComputedRole", role: "FakeRole", target: "parent" },
+ { func: "getElementsByComputedRole", role: "tree" },
+ { func: "getElementsByComputedRole", role: "tree", target: "parent" },
+ { func: "getElementsByComputedRole", role: "button" },
+ { func: "getElementsByComputedRole", role: "button", target: "parent" },
+ ];
+
+ for (let {func, target, role} of tests) {
+ suite.addTestCase({
+ name: "Audit.run.Accessibility." + func + (role ? "." + role : "") + (target ? "." + target : ""),
+ async test() {
+ let functionString = evaluateStringForTest(func, target, role);
+
+ await InspectorTest.Audit.setupAudit();
+
+ InspectorTest.log(`Audit run \`${functionString}\`...`);
+ let {result, wasThrown} = await AuditAgent.run(`function() { return stringify(${functionString}); }`);
+ InspectorTest.assert(!wasThrown, "Should not throw an exception.");
+ if (!wasThrown)
+ InspectorTest.log("Result: " + result.value);
+ else
+ InspectorTest.log(result.description);
+
+ await InspectorTest.Audit.teardownAudit();
+ },
+ });
+ }
+
+ suite.addTestCase({
+ name: "Audit.run.Accessibility.InvalidCopiedFunctionCall",
+ description: "Check that WebInspectorAudit.Accessibility functions throw an error when called outside of an audit.",
+ async test() {
+ let functions = new Map;
+ for (let test of tests)
+ functions.set(test.func, test);
+
+ await InspectorTest.Audit.setupAudit();
+ InspectorTest.log(`Copying WebInspectorAudit to window...`);
+ let {wasThrown} = await AuditAgent.run(`function() { window.CopiedWebInspectorAudit = WebInspectorAudit; }`);
+ InspectorTest.assert(!wasThrown, "Should not throw an exception.");
+ await InspectorTest.Audit.teardownAudit();
+
+ for (let {func, target, role} of functions.values()) {
+ InspectorTest.log(`Testing copied ${func}...`);
+ await InspectorTest.expectException(async function() {
+ await InspectorTest.evaluateInPage("window.Copied" + evaluateStringForTest(func, target, role));
+ });
+ }
+ },
+ });
+
+ suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+ <p>Tests for the injected WebInspectorAudit.Accessibility functions.</p>
+ <ul id="parent" role="tree" aria-activedescendant="child" aria-controls="child" aria-flowto="child" aria-owns="child" _onclick_="void(0);">
+ <li id="child" role="treeitem" aria-selected="true"></li>
+ </ul>
+ <button id="button"></button>
+ <a id="link" role="button"></a>
+ <div id="fakeRole" role="fakeRole"></div>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (239985 => 239986)
--- trunk/Source/WebCore/ChangeLog 2019-01-15 16:24:57 UTC (rev 239985)
+++ trunk/Source/WebCore/ChangeLog 2019-01-15 16:28:37 UTC (rev 239986)
@@ -1,3 +1,19 @@
+2019-01-15 Devin Rousso <[email protected]>
+
+ Web Inspector: Audit: provide a way to query for all nodes with a given computed Accessibility role
+ https://bugs.webkit.org/show_bug.cgi?id=193228
+ <rdar://problem/46787787>
+
+ Reviewed by Joseph Pecoraro.
+
+ Test: inspector/audit/run-accessibility.html
+
+ * inspector/InspectorAuditAccessibilityObject.idl:
+ * inspector/InspectorAuditAccessibilityObject.h:
+ * inspector/InspectorAuditAccessibilityObject.cpp:
+ (WebCore::accessiblityObjectForNode): Added.
+ (WebCore::InspectorAuditAccessibilityObject::getElementsByComputedRole): Added.
+
2019-01-15 Simon Fraser <[email protected]>
Simplify isRunningAnimationOnRenderer()
Modified: trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp (239985 => 239986)
--- trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp 2019-01-15 16:24:57 UTC (rev 239985)
+++ trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.cpp 2019-01-15 16:28:37 UTC (rev 239986)
@@ -27,12 +27,52 @@
#include "config.h"
#include "InspectorAuditAccessibilityObject.h"
+#include "AXObjectCache.h"
+#include "AccessibilityObject.h"
+#include "ContainerNode.h"
+#include "Document.h"
+#include "ElementDescendantIterator.h"
+#include "Node.h"
+#include <wtf/Vector.h>
+
namespace WebCore {
using namespace Inspector;
-InspectorAuditAccessibilityObject::InspectorAuditAccessibilityObject()
+#define ERROR_IF_NO_ACTIVE_AUDIT() \
+ if (!m_auditAgent.hasActiveAudit()) \
+ return Exception { NotAllowedError, "Cannot be called outside of a Web Inspector Audit"_s };
+
+InspectorAuditAccessibilityObject::InspectorAuditAccessibilityObject(InspectorAuditAgent& auditAgent)
+ : m_auditAgent(auditAgent)
{
}
+static AccessibilityObject* accessiblityObjectForNode(Node& node)
+{
+ if (!AXObjectCache::accessibilityEnabled())
+ AXObjectCache::enableAccessibility();
+
+ if (AXObjectCache* axObjectCache = node.document().axObjectCache())
+ return axObjectCache->getOrCreate(&node);
+
+ return nullptr;
+}
+
+ExceptionOr<Vector<Ref<Node>>> InspectorAuditAccessibilityObject::getElementsByComputedRole(Document& document, const String& role, Node* container)
+{
+ ERROR_IF_NO_ACTIVE_AUDIT();
+
+ Vector<Ref<Node>> nodes;
+
+ for (Element& element : elementDescendants(is<ContainerNode>(container) ? downcast<ContainerNode>(*container) : document)) {
+ if (AccessibilityObject* axObject = accessiblityObjectForNode(element)) {
+ if (axObject->computedRoleString() == role)
+ nodes.append(element);
+ }
+ }
+
+ return nodes;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.h (239985 => 239986)
--- trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.h 2019-01-15 16:24:57 UTC (rev 239985)
+++ trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.h 2019-01-15 16:28:37 UTC (rev 239986)
@@ -25,21 +25,30 @@
#pragma once
+#include "ExceptionOr.h"
#include <_javascript_Core/InspectorAuditAgent.h>
+#include <wtf/Forward.h>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
namespace WebCore {
+class Document;
+class Node;
+
class InspectorAuditAccessibilityObject : public RefCounted<InspectorAuditAccessibilityObject> {
public:
- static Ref<InspectorAuditAccessibilityObject> create(Inspector::InspectorAuditAgent&)
+ static Ref<InspectorAuditAccessibilityObject> create(Inspector::InspectorAuditAgent& auditAgent)
{
- return adoptRef(*new InspectorAuditAccessibilityObject());
+ return adoptRef(*new InspectorAuditAccessibilityObject(auditAgent));
}
+ ExceptionOr<Vector<Ref<Node>>> getElementsByComputedRole(Document&, const String& role, Node* container);
+
private:
- explicit InspectorAuditAccessibilityObject();
+ explicit InspectorAuditAccessibilityObject(Inspector::InspectorAuditAgent&);
+
+ Inspector::InspectorAuditAgent& m_auditAgent;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.idl (239985 => 239986)
--- trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.idl 2019-01-15 16:24:57 UTC (rev 239985)
+++ trunk/Source/WebCore/inspector/InspectorAuditAccessibilityObject.idl 2019-01-15 16:28:37 UTC (rev 239986)
@@ -28,4 +28,5 @@
JSGenerateToJSObject,
NoInterfaceObject,
] interface InspectorAuditAccessibilityObject {
+ [CallWith=Document, MayThrowException] sequence<Node> getElementsByComputedRole(DOMString role, optional Node? container);
};