From 9da367dd42a64fb6e6ab1063354c361476a793a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 18 Jan 2021 11:14:20 +0000 Subject: [PATCH] Fix HTMLStyleElement::UnbindFromTree to always remove its stylesheet. This matches other browsers and https://github.com/w3c/csswg-drafts/issues/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 --- shadow-dom/ShadowRoot-interface.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shadow-dom/ShadowRoot-interface.html b/shadow-dom/ShadowRoot-interface.html index 8efa50e4ea18cc..e95b1d9542e2e3 100644 --- a/shadow-dom/ShadowRoot-interface.html +++ b/shadow-dom/ShadowRoot-interface.html @@ -96,12 +96,19 @@ shadowRoot.innerHTML = ''; 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 + '.'); }