AX: Hidden nodes which are not directly referenced should not participate name/descri...
authorjdiggs@igalia.com <jdiggs@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 May 2018 00:06:49 +0000 (00:06 +0000)
committerjdiggs@igalia.com <jdiggs@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 May 2018 00:06:49 +0000 (00:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185478

Reviewed by Chris Fleizach.

Source/WebCore:

Add a check to AccessibilityNodeObject::textUnderElement() and return early
if the node is hidden, not referenced by aria-labelledby or aria-describedby,
not an HTMLLabelElement, and not fallback content for an HTMLCanvasElement.

Test: accessibility/text-alternative-calculation-hidden-nodes.html

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::textUnderElement const):

LayoutTests:

* accessibility/text-alternative-calculation-hidden-nodes-expected.txt: Added.
* accessibility/text-alternative-calculation-hidden-nodes.html: Added.
* platform/gtk/accessibility/text-alternative-calculation-hidden-nodes-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231620 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/accessibility/text-alternative-calculation-hidden-nodes-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/text-alternative-calculation-hidden-nodes.html [new file with mode: 0644]
LayoutTests/platform/gtk/accessibility/text-alternative-calculation-hidden-nodes-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp

index d270cbc..b456dc2 100644 (file)
@@ -1,3 +1,14 @@
+2018-05-09  Joanmarie Diggs  <jdiggs@igalia.com>
+
+        AX: Hidden nodes which are not directly referenced should not participate name/description from content
+        https://bugs.webkit.org/show_bug.cgi?id=185478
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/text-alternative-calculation-hidden-nodes-expected.txt: Added.
+        * accessibility/text-alternative-calculation-hidden-nodes.html: Added.
+        * platform/gtk/accessibility/text-alternative-calculation-hidden-nodes-expected.txt: Added.
+
 2018-05-09  Youenn Fablet  <youenn@apple.com>
 
         LayoutTests/http/tests/appcache/abort-cache-onchecking-manifest-404.html is flaky
diff --git a/LayoutTests/accessibility/text-alternative-calculation-hidden-nodes-expected.txt b/LayoutTests/accessibility/text-alternative-calculation-hidden-nodes-expected.txt
new file mode 100644 (file)
index 0000000..0de0475
--- /dev/null
@@ -0,0 +1,24 @@
+This tests text alternative calculation with hidden nodes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test 1
+       W3C Name: foo
+       W3C Description: 
+Test 2
+       W3C Name: 
+       W3C Description: bar
+Test 3
+       W3C Name: 
+       W3C Description: 
+Test 4
+       W3C Name: cell 1 cell 4
+       W3C Description: 
+Test 5
+       W3C Name: 
+       W3C Description: cell 1 cell 4
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/text-alternative-calculation-hidden-nodes.html b/LayoutTests/accessibility/text-alternative-calculation-hidden-nodes.html
new file mode 100644 (file)
index 0000000..dd96913
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../resources/js-test-pre.js"></script>
+<script src="../resources/accessibility-helper.js"></script>
+</head>
+<body>
+<div id="content">
+  <div id="hidden1" style="visibility:hidden;">foo</div>
+  <div id="hidden2" style="display:none;">bar</div>
+
+  <input id="test1" aria-labelledby="hidden1">
+  <input id="test2" aria-describedby="hidden2">
+
+  <label for="test3" id="hidden3" style="display:none;">baz</label>
+  <input id="test3">
+
+  <table id="table">
+    <tr>
+      <td>cell 1</td>
+      <td style="visibility:hidden;">cell 2</td>
+      <td><div style="display:none;"><div>cell 3</div></td>
+      <td><div>cell 4</div></td>
+    </tr>
+  </table>
+  <input id="test4" aria-labelledby="table">
+  <input id="test5" aria-describedby="table">
+</div>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests text alternative calculation with hidden nodes.");
+
+    if (window.accessibilityController) {
+        for (var i = 1; i <= 5; i++) {
+            var axElement = accessibilityController.accessibleElementById("test" + i);
+            debug("Test " + i);
+            debug("\tW3C Name: " + platformValueForW3CName(axElement));
+            debug("\tW3C Description: " + platformValueForW3CDescription(axElement));
+         }
+       document.getElementById("content").style.visibility = "hidden";
+       document.getElementById("table").style.visibility = "hidden";
+    }
+</script>
+
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/platform/gtk/accessibility/text-alternative-calculation-hidden-nodes-expected.txt b/LayoutTests/platform/gtk/accessibility/text-alternative-calculation-hidden-nodes-expected.txt
new file mode 100644 (file)
index 0000000..fd7a098
--- /dev/null
@@ -0,0 +1,24 @@
+This tests text alternative calculation with hidden nodes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test 1
+       W3C Name: foo
+       W3C Description: 
+Test 2
+       W3C Name: 
+       W3C Description: bar
+Test 3
+       W3C Name: baz
+       W3C Description: 
+Test 4
+       W3C Name: cell 1 cell 4
+       W3C Description: 
+Test 5
+       W3C Name: 
+       W3C Description: cell 1 cell 4
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
index 8d34ea8..d2f9683 100644 (file)
@@ -1,3 +1,19 @@
+2018-05-09  Joanmarie Diggs  <jdiggs@igalia.com>
+
+        AX: Hidden nodes which are not directly referenced should not participate name/description from content
+        https://bugs.webkit.org/show_bug.cgi?id=185478
+
+        Reviewed by Chris Fleizach.
+
+        Add a check to AccessibilityNodeObject::textUnderElement() and return early
+        if the node is hidden, not referenced by aria-labelledby or aria-describedby,
+        not an HTMLLabelElement, and not fallback content for an HTMLCanvasElement.
+
+        Test: accessibility/text-alternative-calculation-hidden-nodes.html
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::textUnderElement const):
+
 2018-05-09  Eric Carlson  <eric.carlson@apple.com>
 
         Update MediaSession to use release logging
index db8575e..709ecc3 100644 (file)
@@ -1733,6 +1733,18 @@ String AccessibilityNodeObject::textUnderElement(AccessibilityTextUnderElementMo
     if (is<Text>(node))
         return downcast<Text>(*node).wholeText();
 
+    // The Accname specification states that if the current node is hidden, and not directly
+    // referenced by aria-labelledby or aria-describedby, and is not a host language text
+    // alternative, the empty string should be returned.
+    if (isHidden() && !is<HTMLLabelElement>(node) && !ancestorsOfType<HTMLCanvasElement>(*node).first()) {
+        AccessibilityObject::AccessibilityChildrenVector labelFor;
+        AccessibilityObject::AccessibilityChildrenVector descriptionFor;
+        ariaLabelledByReferencingElements(labelFor);
+        ariaDescribedByReferencingElements(descriptionFor);
+        if (!labelFor.size() && !descriptionFor.size())
+            return String();
+    }
+
     StringBuilder builder;
     for (AccessibilityObject* child = firstChild(); child; child = child->nextSibling()) {
         if (mode.ignoredChildNode && child->node() == mode.ignoredChildNode)