Skip to content

Commit

Permalink
Don't clear adoptedStyleSheets when adopting from a template document…
Browse files Browse the repository at this point in the history
… to its owner or vice versa.

See WICG/construct-stylesheets#133, which is
where this change was discussed (and then made to Chromium apparently).

I filed w3c/csswg-drafts#7229 to put some
actual spec text here. Also, tweak the wpt which is supposed to test so
that it fails without this change.

Differential Revision: https://phabricator.services.mozilla.com/D144564

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1737455
gecko-commit: d23de6842cb7948a7d8a69ba19717e52c2bbb3a9
gecko-reviewers: edgar
  • Loading branch information
emilio authored and moz-wptsync-bot committed Apr 26, 2022
1 parent 055d740 commit 131ccad
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions css/cssom/CSSStyleSheet-template-adoption.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,41 @@
<script>
test(function() {
let sheet = new CSSStyleSheet();
sheet.replaceSync("div { color: red }");
sheet.replaceSync("div { color: blue }");

let host = document.getElementById("host");
let root = host.attachShadow({ mode: "open" });
root.innerHTML = `<div></div>`;
root.adoptedStyleSheets = [sheet];
assert_equals(root.adoptedStyleSheets.length, 1);
assert_equals(root.adoptedStyleSheets[0], sheet);

function assertAdoptedStyleSheet() {
assert_equals(host.ownerDocument, root.firstChild.ownerDocument, "Shadow root was not adopted?");
assert_equals(root.adoptedStyleSheets.length, 1);
assert_equals(root.adoptedStyleSheets[0], sheet);
if (root.ownerDocument == document) {
assert_equals(getComputedStyle(root.firstChild).color, "rgb(0, 0, 255)", "Sheet should apply");
}
}

assertAdoptedStyleSheet();

// adoptedStyleSheets is not cleared when adopted into a <template>.
const template = document.getElementById("template");
template.content.appendChild(host);
assert_equals(root.adoptedStyleSheets.length, 1);
assert_equals(root.adoptedStyleSheets[0], sheet);

assert_not_equals(host.ownerDocument, document, "Should've been adopted");
assertAdoptedStyleSheet();

// adoptedStyleSheets is not cleared when adopted back in the main document.
document.body.appendChild(host);
assert_equals(root.adoptedStyleSheets.length, 1);
assert_equals(root.adoptedStyleSheets[0], sheet);
assert_equals(host.ownerDocument, document, "Should've been re-adopted");
assertAdoptedStyleSheet();

// adoptedStyleSheets is not cleared when adopted into a nested <template>.
const nested_template = template.content.firstElementChild;
nested_template.content.appendChild(host);
assert_equals(root.adoptedStyleSheets.length, 1);
assert_equals(root.adoptedStyleSheets[0], sheet);
assert_not_equals(host.ownerDocument, document, "Should've been adopted");
assertAdoptedStyleSheet();

// adoptedStyleSheets is cleared when adopted into an <iframe>.
const iframe = document.createElement("iframe");
Expand Down

0 comments on commit 131ccad

Please sign in to comment.