From 19e31d5c506f83585812856738e53d33a53d32c5 Mon Sep 17 00:00:00 2001 From: charlesvdv Date: Sat, 7 Jan 2017 17:02:06 +0100 Subject: [PATCH 1/3] Handle properly alternate stylesheet --- components/script/dom/htmllinkelement.rs | 24 +++++++++++++----------- components/script/stylesheet_loader.rs | 3 +++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 24b4e779099..3466fa10dab 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -99,6 +99,17 @@ impl HTMLLinkElement { }) }) } + + pub fn is_alternate(&self) -> bool { + let rel = get_attr(self.upcast(), &local_name!("rel")); + match rel { + Some(ref value) => { + value.split(HTML_SPACE_CHARACTERS) + .any(|s| s.eq_ignore_ascii_case("alternate")) + }, + None => false, + } + } } fn get_attr(element: &Element, local_name: &LocalName) -> Option { @@ -112,17 +123,8 @@ fn get_attr(element: &Element, local_name: &LocalName) -> Option { fn string_is_stylesheet(value: &Option) -> bool { match *value { Some(ref value) => { - let mut found_stylesheet = false; - for s in value.split(HTML_SPACE_CHARACTERS).into_iter() { - if s.eq_ignore_ascii_case("alternate") { - return false; - } - - if s.eq_ignore_ascii_case("stylesheet") { - found_stylesheet = true; - } - } - found_stylesheet + value.split(HTML_SPACE_CHARACTERS) + .any(|s| s.eq_ignore_ascii_case("stylesheet")) }, None => false, } diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs index db70c9e8ebb..637f0619fc5 100644 --- a/components/script/stylesheet_loader.rs +++ b/components/script/stylesheet_loader.rs @@ -138,6 +138,9 @@ impl FetchResponseListener for StylesheetContext { Some(&loader), win.css_error_reporter(), ParserContextExtraData::default())); + if elem.downcast::().unwrap().is_alternate() { + sheet.set_disabled(true); + } elem.downcast::() .unwrap() .set_stylesheet(sheet.clone()); From 2bcefa6470f8c04ef2831e0fa75af8fe6ef01630 Mon Sep 17 00:00:00 2001 From: charlesvdv Date: Sun, 8 Jan 2017 18:28:47 +0100 Subject: [PATCH 2/3] Modify test to check if @import stylesheet get applied in a alternate stylesheet --- .../html/semantics/links/linktypes/alternate-import.css | 3 +++ .../html/semantics/links/linktypes/alternate.css | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate-import.css diff --git a/tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate-import.css b/tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate-import.css new file mode 100644 index 00000000000..7db3df1d782 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate-import.css @@ -0,0 +1,3 @@ +body { + background-color: black; +} diff --git a/tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate.css b/tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate.css index 05920c6130c..b101ab91f01 100644 --- a/tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate.css +++ b/tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate.css @@ -1,3 +1,5 @@ +@import url("alternate-import.css"); + div { background-color: red; } From cb9940faf3785d2867bcbd44363fff8bae928358 Mon Sep 17 00:00:00 2001 From: Charles Vandevoorde Date: Wed, 11 Jan 2017 18:02:46 +0100 Subject: [PATCH 3/3] Update metadata tests --- .../subresource-integrity.sub.html.ini | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/wpt/metadata/subresource-integrity/subresource-integrity.sub.html.ini b/tests/wpt/metadata/subresource-integrity/subresource-integrity.sub.html.ini index 164756ce462..ded3e16badb 100644 --- a/tests/wpt/metadata/subresource-integrity/subresource-integrity.sub.html.ini +++ b/tests/wpt/metadata/subresource-integrity/subresource-integrity.sub.html.ini @@ -1,14 +1,11 @@ [subresource-integrity.sub.html] type: testharness - expected: TIMEOUT + expected: OK [Style: with correct hash, ACAO: *] expected: FAIL [Style: Same-origin with correct sha256 and sha512 hash, rel='alternate stylesheet' enabled] - expected: NOTRUN - - [Style: Same-origin with incorrect sha256 and sha512 hash, rel='alternate stylesheet' enabled] - expected: NOTRUN + expected: FAIL [Style: Same-origin with incorrect hash.] expected: FAIL