aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-01-11 10:34:04 -0800
committerGitHub <noreply@github.com>2017-01-11 10:34:04 -0800
commitcfc74e20603e7395a743b3b3c202db6db840da4d (patch)
tree317d85cfac2e0e1e66e6996f2365ebb4a4371a13
parentd1bc1a4f1b66ab9f63fa37f649eaf79035e12f8e (diff)
parentcb9940faf3785d2867bcbd44363fff8bae928358 (diff)
downloadservo-cfc74e20603e7395a743b3b3c202db6db840da4d.tar.gz
servo-cfc74e20603e7395a743b3b3c202db6db840da4d.zip
Auto merge of #14911 - charlesvdv:alternate-stylesheet, r=cbrewster
Handle properly alternate stylesheet <!-- Please describe your changes on the following line: --> Alternate stylesheet are now fetched and then desactivated instead of ignoring them. I don't know if tests are required to check if the stylesheet is correctly loaded and disabled ? <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14881 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14911) <!-- Reviewable:end -->
-rw-r--r--components/script/dom/htmllinkelement.rs24
-rw-r--r--components/script/stylesheet_loader.rs3
-rw-r--r--tests/wpt/metadata/subresource-integrity/subresource-integrity.sub.html.ini7
-rw-r--r--tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate-import.css3
-rw-r--r--tests/wpt/web-platform-tests/html/semantics/links/linktypes/alternate.css2
5 files changed, 23 insertions, 16 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<String> {
@@ -112,17 +123,8 @@ fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
fn string_is_stylesheet(value: &Option<String>) -> 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::<HTMLLinkElement>().unwrap().is_alternate() {
+ sheet.set_disabled(true);
+ }
elem.downcast::<HTMLLinkElement>()
.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: <crossorigin='anonymous'> 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;
}