diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 7b26fb8bbee5..3386e302422e 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -18,7 +18,7 @@ use dom::element::{AttributeMutation, Element, ElementCreator}; use dom::element::{cors_setting_for_element, reflect_cross_origin_attribute, set_cross_origin_attribute}; use dom::globalscope::GlobalScope; use dom::htmlelement::HTMLElement; -use dom::node::{Node, document_from_node, window_from_node}; +use dom::node::{Node, UnbindContext, document_from_node, window_from_node}; use dom::stylesheet::StyleSheet as DOMStyleSheet; use dom::virtualmethods::VirtualMethods; use html5ever_atoms::LocalName; @@ -213,6 +213,15 @@ impl VirtualMethods for HTMLLinkElement { } } } + + fn unbind_from_tree(&self, context: &UnbindContext) { + if let Some(ref s) = self.super_type() { + s.unbind_from_tree(context); + } + + let document = document_from_node(self); + document.invalidate_stylesheets(); + } } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 0cb9a9d9585e..6a4664e05848 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -6462,6 +6462,18 @@ "url": "/_mozilla/mozilla/iframe/resize_after_load.html" } ], + "mozilla/remove_link_styles.html": [ + { + "path": "mozilla/remove_link_styles.html", + "references": [ + [ + "/_mozilla/mozilla/remove_link_styles_ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/remove_link_styles.html" + } + ], "mozilla/reparse_style_elements.html": [ { "path": "mozilla/reparse_style_elements.html", @@ -21852,6 +21864,18 @@ "url": "/_mozilla/mozilla/iframe/resize_after_load.html" } ], + "mozilla/remove_link_styles.html": [ + { + "path": "mozilla/remove_link_styles.html", + "references": [ + [ + "/_mozilla/mozilla/remove_link_styles_ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/remove_link_styles.html" + } + ], "mozilla/reparse_style_elements.html": [ { "path": "mozilla/reparse_style_elements.html", diff --git a/tests/wpt/mozilla/tests/mozilla/remove_link_styles.css b/tests/wpt/mozilla/tests/mozilla/remove_link_styles.css new file mode 100644 index 000000000000..1984cf7df216 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/remove_link_styles.css @@ -0,0 +1,4 @@ +body { + background-color: red; + color: white !important; +} diff --git a/tests/wpt/mozilla/tests/mozilla/remove_link_styles.html b/tests/wpt/mozilla/tests/mozilla/remove_link_styles.html new file mode 100644 index 000000000000..6a1e592d0961 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/remove_link_styles.html @@ -0,0 +1,19 @@ + + +Removing link tag should remove associated styles + + + + + + This text should be green and the background should not be red. + + + diff --git a/tests/wpt/mozilla/tests/mozilla/remove_link_styles_ref.html b/tests/wpt/mozilla/tests/mozilla/remove_link_styles_ref.html new file mode 100644 index 000000000000..e9fd0816b9b2 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/remove_link_styles_ref.html @@ -0,0 +1,11 @@ + + + + + + This text should be green and the background should not be red. +