Commit 698073f9 authored by Meredith Lane's avatar Meredith Lane Committed by Commit Bot

[AOM] Element Reflection tests for scoping.

Adds in extra test cases relating to moving elements in and out of scope.
This behaviour is still under discussion, so is likely to change in
future as the API is finalized.

Bug=981423

Change-Id: I5863b1f8d7ab1b6287af1d95e859945af38fea60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1816496
Commit-Queue: Meredith Lane <meredithl@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713347}
parent 8e7f4fc5
......@@ -425,6 +425,11 @@ HeapVector<Member<Element>>* GetExplicitlySetElementsForAttr(
bool ElementIsDescendantOfShadowIncludingAncestor(
const Element& attribute_element,
const Element& candidate) {
// TODO(meredithl): Update this to allow setting relationships for elements
// outside of the DOM once the spec is finalized. For consistency and
// simplicity, for now it is disallowed.
if (!attribute_element.IsInTreeScope() || !candidate.IsInTreeScope())
return false;
ShadowRoot* nearest_root = attribute_element.ContainingShadowRoot();
const Element* shadow_host = &attribute_element;
while (nearest_root) {
......@@ -757,20 +762,35 @@ void Element::SetElementArrayAttribute(
SpaceSplitString value;
for (auto element : given_elements) {
// Elements that are not descendants of this element's shadow including
// ancestors are dropped.
if (!ElementIsDescendantOfShadowIncludingAncestor(*this, *element))
continue;
// If |value| is null, this means a previous element must have been invalid,
// and the content attribute should reflect the empty string, so we don't
// continue trying to compute it.
if (value.IsNull() && !elements->IsEmpty()) {
elements->push_back(element);
continue;
}
elements->push_back(element);
const AtomicString given_element_id = element->GetIdAttribute();
// We compute the content attribute string as a space separated string of
// the given |element| ids. Every |element| in |given_elements| must have an
// id, must be in the same tree scope and must be the first id in tree order
// with that id, otherwise the content attribute should reflect the empty
// string.
if (given_element_id.IsNull() ||
GetTreeScope() != element->GetTreeScope() ||
GetTreeScope().getElementById(given_element_id) != element) {
value.Clear();
continue;
}
// Whitespace between elements is added when the string is serialized.
value.Add(given_element_id);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment