Commit c773e572 authored by Takayoshi Kochi's avatar Takayoshi Kochi Committed by Commit Bot

Do not switch to V1 cascade order if shadow root is UA shadow

Once V1 shadow root is attached to a document, we switch
cascading order to V1-compliant mode from V0-legacy mode,
but recent migration of UA shadows from V0 to V1 caused
the cascading order switch without explicitly creating
author V1 shadow root.

This happens only in the following scenario:
1. An element with V1 UA shadow is created in another document
2. The element with V1 UA shadow is adopted to the document.

In other cases, internal APIs such as EnsureUserAgentShadowRoot()
or CreateUserAgentShadowRoot() does not share the same code path
for web-facing Element.attachShadow(), the cascading order is not
affected.

Bug: 801938, 787717
Change-Id: I93e41e8f6f0acda4f3804e1ef316da205454b62f
Reviewed-on: https://chromium-review.googlesource.com/875585Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Takayoshi Kochi <kochi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#530738}
parent 18fe7842
......@@ -13,9 +13,25 @@ var root = host.createShadowRoot();
root.innerHTML = '<style>:host(#host) { color: green; }</style>';
test(() => {
assert_equals(window.getComputedStyle(host).color, 'rgb(0, 128, 0)');
assert_equals(window.getComputedStyle(host).color, 'rgb(0, 128, 0)',
'V0 cascade order should be used by default.');
// Adding V1 user-agent shadow should not switch cascading order.
var option = document.createElement('option');
dummy.appendChild(option);
assert_equals(window.getComputedStyle(host).color, 'rgb(0, 128, 0)',
'Adding UA shadow should not change the cascade order.');
// Adopting V1 user-agent shadow should not switch cascading order.
var doc2 = document.implementation.createHTMLDocument();
var option2 = doc2.createElement('option');
dummy.appendChild(option2);
assert_equals(window.getComputedStyle(host).color, 'rgb(0, 128, 0)',
'Adopting UA shadow should not change the cascade order.');
// Trigger "V1" shadow cascading order.
dummy.attachShadow({mode: 'open'});
assert_equals(window.getComputedStyle(host).color, 'rgb(255, 0, 0)');
assert_equals(window.getComputedStyle(host).color, 'rgb(255, 0, 0)',
'Adding author V1 shadow should change the cascade order.');
}, 'Upgrading V0 to V1 should cause style recalculation.');
</script>
......@@ -86,7 +86,7 @@ void TreeScopeAdopter::MoveTreeToNewScope(Node& root) const {
if (shadow->GetType() == ShadowRootType::V0) {
new_document.SetShadowCascadeOrder(
ShadowCascadeOrder::kShadowCascadeV0);
} else if (shadow->IsV1()) {
} else if (shadow->IsV1() && !shadow->IsUserAgent()) {
new_document.SetShadowCascadeOrder(
ShadowCascadeOrder::kShadowCascadeV1);
}
......
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