Skip to content

Commit

Permalink
Remove styles when link node is removed from document
Browse files Browse the repository at this point in the history
  • Loading branch information
zaynetro committed Jan 22, 2017
1 parent 9760ea2 commit b3ce08f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
11 changes: 10 additions & 1 deletion components/script/dom/htmllinkelement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}


Expand Down
24 changes: 24 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/remove_link_styles.css
@@ -0,0 +1,4 @@
body {
background-color: red;
color: white !important;
}
19 changes: 19 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/remove_link_styles.html
@@ -0,0 +1,19 @@
<!doctype html>
<meta charset="utf-8">
<title>Removing link tag should remove associated styles</title>
<link rel="stylesheet" type="text/css" href="remove_link_styles.css">
<link rel="match" href="remove_link_styles_ref.html">
<body>
<style>
body {
color: green;
}
</style>

This text should be green and the background should not be red.

<script>
var l = document.querySelector('link[rel="stylesheet"]');
l.parentNode.removeChild(l);
</script>
</body>
11 changes: 11 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/remove_link_styles_ref.html
@@ -0,0 +1,11 @@
<!doctype html>
<meta charset="utf-8">
<body>
<style>
body {
color: green;
}
</style>

This text should be green and the background should not be red.
</body>

0 comments on commit b3ce08f

Please sign in to comment.