Skip to content

Commit

Permalink
[Element Reflection] Null vs Empty-list differentiation.
Browse files Browse the repository at this point in the history
If the content-attribute is not present, then we return null.

If the content attribute is present, and there are no explicitly set
attr-elements, and the content attribute doesn't yield any valid
elements, then we return an empty array.

This makes the interface more consistent, as a caller could already
to the attribute to null to clear.

This brings the implementation in-line with the update here
whatwg/html#3917 (comment)

This also updates/clarifies code comments and adds descriptive strings
to existing tests.

This is a subset of the work Alice did for https://crrev.com/c/2796854

Change-Id: I3dcc8492fdb5467f82468bbc3d4b7e4a87c5d48e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2825017
Reviewed-by: Alice Boxhall <[email protected]>
Reviewed-by: Kent Tamura <[email protected]>
Commit-Queue: Chris Hall <[email protected]>
Cr-Commit-Position: refs/heads/master@{#872329}
  • Loading branch information
Chris Hall authored and chromium-wpt-export-bot committed Apr 14, 2021
1 parent 85d6b55 commit 8266001
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions dom/nodes/aria-element-reflection.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<script>

test(function(t) {
assert_equals(passwordField.ariaDetailsElements, null);
assert_array_equals(passwordField.ariaDetailsElements, []);
passwordField.ariaDetailsElements = [ listItem1 ];
assert_equals(passwordField.getAttribute("aria-details"), "listItem1");

Expand Down Expand Up @@ -341,7 +341,7 @@
test(function(t) {
const billingElement = document.getElementById("billingElement")
assert_array_equals(input1.ariaLabelledByElements, [billingElement, nameElement], "parsed content attribute sets element references.");
assert_equals(input2.ariaLabelledByElements, null, "Testing empty content attribute after parsing.");
assert_equals(input2.ariaLabelledByElements, null, "Testing missing content attribute after parsing.");

input2.ariaLabelledByElements = [billingElement, addressElement];
assert_array_equals(input2.ariaLabelledByElements, [billingElement, addressElement], "Testing IDL setter/getter.");
Expand All @@ -351,12 +351,12 @@
// As it was explicitly set the underlying association will remain intact,
// but it will be hidden until the element is moved back into a valid scope.
billingElement.remove();
assert_array_equals(input2.ariaLabelledByElements, [addressElement]);
assert_array_equals(input2.ariaLabelledByElements, [addressElement], "Computed ariaLabelledByElements shouldn't include billing when out of scope.");

// Insert the billingElement back into the DOM and check that it is visible
// again, as the underlying association should have been kept intact.
billingElementContainer.appendChild(billingElement);
assert_array_equals(input2.ariaLabelledByElements, [billingElement, addressElement]);
assert_array_equals(input2.ariaLabelledByElements, [billingElement, addressElement], "Billing element back in scope.");

input2.ariaLabelledByElements = [];
assert_array_equals(input2.ariaLabelledByElements, [], "Testing IDL setter/getter for empty array.");
Expand All @@ -366,7 +366,8 @@
assert_equals(input1.ariaLabelledByElements, null);

input1.setAttribute("aria-labelledby", "nameElement addressElement");
assert_array_equals(input1.ariaLabelledByElements, [nameElement, addressElement]);
assert_array_equals(input1.ariaLabelledByElements, [nameElement, addressElement],
"computed value after setting attribute directly");

input1.ariaLabelledByElements = null;
assert_false(input1.hasAttribute("aria-labelledby", "Nullifying the IDL attribute should remove the content attribute."));
Expand Down Expand Up @@ -516,7 +517,7 @@ <h2 id="lightDomHeading" aria-flowto="shadowChild1 shadowChild2">Light DOM Headi

// The elements in the content attribute are in a "darker" tree - they
// enter a shadow encapsulation boundary, so not be associated any more.
assert_equals(lightDomHeading.ariaFlowToElements, null);
assert_array_equals(lightDomHeading.ariaFlowToElements, []);

// These elements are in a shadow including ancestor, i.e "lighter" tree.
// Valid for the IDL attribute, but content attribute should be null.
Expand All @@ -526,7 +527,7 @@ <h2 id="lightDomHeading" aria-flowto="shadowChild1 shadowChild2">Light DOM Headi
// These IDs belong to a different scope, so the attr-associated-element
// cannot be computed.
shadowChild2.setAttribute("aria-flowto", "lightDomText1 lightDomText2");
assert_equals(shadowChild2.ariaFlowToElements, null);
assert_array_equals(shadowChild2.ariaFlowToElements, []);

// Elements that cross into shadow DOM are dropped, only reflect the valid
// elements in IDL and in the content attribute.
Expand Down Expand Up @@ -661,8 +662,6 @@ <h2 id="lightDomHeading" aria-flowto="shadowChild1 shadowChild2">Light DOM Headi
input.ariaActiveDescendantElement = first;
first.parentElement.appendChild(first);

// This behaviour is currently under discussion by WHATWG.
// See: https://github.com/whatwg/html/pull/3917#issuecomment-527263562
assert_equals(input.ariaActiveDescendantElement, first);
}, "Reparenting.");
</script>
Expand Down

0 comments on commit 8266001

Please sign in to comment.