Skip to content

Commit

Permalink
Fix HTMLStyleElement::UnbindFromTree to always remove its stylesheet.
Browse files Browse the repository at this point in the history
This matches other browsers and
w3c/csswg-drafts#3096.

It also matches SVGStyleElement and HTMLLinkElement of course.

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

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1687126
gecko-commit: 933b5d98c1bfab4b519998bb91ea16d868b07617
gecko-reviewers: smaug
  • Loading branch information
emilio authored and moz-wptsync-bot committed Jan 18, 2021
1 parent ca0a6c0 commit 9da367d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion shadow-dom/ShadowRoot-interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@

shadowRoot.innerHTML = '<span></span><style> a.rule {} </style><style> b.rule {} </style>';
assert_equals(shadowRoot.styleSheets.length, 0, 'shadowRoot.styleSheets must be empty when the shadow root is not connected');
var styles = shadowRoot.querySelectorAll('style');
assert_equals(styles[0].sheet, null, "Sheet should be null in a disconnected tree");
assert_equals(styles[1].sheet, null, "Sheet should be null in a disconnected tree");

document.body.appendChild(host);
assert_equals(shadowRoot.styleSheets.length, 2, 'shadowRoot.styleSheets must contain two items when the shadow root has two style elements');
var styles = shadowRoot.querySelectorAll('style');
assert_equals(shadowRoot.styleSheets[0], styles[0].sheet, 'shadowRoot.styleSheets[0] must be the first style element in the shadow root');
assert_equals(shadowRoot.styleSheets[1], styles[1].sheet, 'shadowRoot.styleSheets[1] must be the second style element in the shadow root');

host.remove();
assert_equals(shadowRoot.styleSheets.length, 0, 'shadowRoot.styleSheets must be empty when the shadow root is not connected');
assert_equals(styles[0].sheet, null, "Sheet should be null in a disconnected tree");
assert_equals(styles[1].sheet, null, "Sheet should be null in a disconnected tree");
}, 'ShadowRoot.styleSheets must return a StyleSheetList sequence containing the shadow root style sheets when shadow root is ' + mode + '.');
}

Expand Down

0 comments on commit 9da367d

Please sign in to comment.