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()); 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 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; }