diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index 7401c67aa95..285c8af3087 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -15,7 +15,7 @@ use dom::document::Document; use dom::element::{Element, ElementCreator}; use dom::eventtarget::EventTarget; use dom::htmlelement::HTMLElement; -use dom::node::{ChildrenMutation, Node, document_from_node, window_from_node}; +use dom::node::{ChildrenMutation, Node, UnbindContext, document_from_node, window_from_node}; use dom::stylesheet::StyleSheet as DOMStyleSheet; use dom::virtualmethods::VirtualMethods; use html5ever_atoms::LocalName; @@ -161,6 +161,15 @@ impl VirtualMethods for HTMLStyleElement { self.parse_own_css(); } } + + fn unbind_from_tree(&self, context: &UnbindContext) { + if let Some(ref s) = self.super_type() { + s.unbind_from_tree(context); + } + + let doc = document_from_node(self); + doc.invalidate_stylesheets(); + } } impl StylesheetOwner for HTMLStyleElement { diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 6a4664e0584..d396c4d0130 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -6474,6 +6474,18 @@ "url": "/_mozilla/mozilla/remove_link_styles.html" } ], + "mozilla/remove_style_styles.html": [ + { + "path": "mozilla/remove_style_styles.html", + "references": [ + [ + "/_mozilla/mozilla/remove_style_styles_ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/remove_style_styles.html" + } + ], "mozilla/reparse_style_elements.html": [ { "path": "mozilla/reparse_style_elements.html", @@ -21876,6 +21888,18 @@ "url": "/_mozilla/mozilla/remove_link_styles.html" } ], + "mozilla/remove_style_styles.html": [ + { + "path": "mozilla/remove_style_styles.html", + "references": [ + [ + "/_mozilla/mozilla/remove_style_styles_ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/remove_style_styles.html" + } + ], "mozilla/reparse_style_elements.html": [ { "path": "mozilla/reparse_style_elements.html", diff --git a/tests/wpt/mozilla/tests/mozilla/remove_style_styles.html b/tests/wpt/mozilla/tests/mozilla/remove_style_styles.html new file mode 100644 index 00000000000..f8a94bb7350 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/remove_style_styles.html @@ -0,0 +1,20 @@ + + +Removing style element should remove all associated styles + + + + + This text should be black and the background should not be red. + + + diff --git a/tests/wpt/mozilla/tests/mozilla/remove_style_styles_ref.html b/tests/wpt/mozilla/tests/mozilla/remove_style_styles_ref.html new file mode 100644 index 00000000000..d562e127203 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/remove_style_styles_ref.html @@ -0,0 +1,5 @@ + + + + This text should be black and the background should not be red. +