From 3c6cc642ee43375fecb191004b49bedf1b6c4146 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 31 Mar 2016 10:08:01 +0200 Subject: [PATCH] Implement Document::cookie correctly for cookie-averse documents. --- components/script/dom/document.rs | 23 +++++++++++++++++-- .../document-cookie.html.ini | 5 ---- 2 files changed, 21 insertions(+), 7 deletions(-) delete mode 100644 tests/wpt/metadata/html/dom/documents/resource-metadata-management/document-cookie.html.ini diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index ad0ae92eace..cb61bb393ef 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1466,6 +1466,19 @@ impl Document { let target = node.upcast(); event.fire(target); } + + /// https://html.spec.whatwg.org/multipage/#cookie-averse-document-object + fn is_cookie_averse(&self) -> bool { + /// https://url.spec.whatwg.org/#network-scheme + fn url_has_network_scheme(url: &Url) -> bool { + match &*url.scheme { + "ftp" | "http" | "https" => true, + _ => false, + } + } + + self.browsing_context.is_none() || !url_has_network_scheme(&self.url) + } } #[derive(PartialEq, HeapSizeOf)] @@ -2390,7 +2403,10 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#dom-document-cookie fn GetCookie(&self) -> Fallible { - // TODO: return empty string for cookie-averse Document + if self.is_cookie_averse() { + return Ok(DOMString::new()); + } + let url = self.url(); if !is_scheme_host_port_tuple(&url) { return Err(Error::Security); @@ -2403,7 +2419,10 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#dom-document-cookie fn SetCookie(&self, cookie: DOMString) -> ErrorResult { - // TODO: ignore for cookie-averse Document + if self.is_cookie_averse() { + return Ok(()); + } + let url = self.url(); if !is_scheme_host_port_tuple(url) { return Err(Error::Security); diff --git a/tests/wpt/metadata/html/dom/documents/resource-metadata-management/document-cookie.html.ini b/tests/wpt/metadata/html/dom/documents/resource-metadata-management/document-cookie.html.ini deleted file mode 100644 index 74249d5a63d..00000000000 --- a/tests/wpt/metadata/html/dom/documents/resource-metadata-management/document-cookie.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[document-cookie.html] - type: testharness - [getting cookie for a cookie-averse document returns empty string, setting does nothing] - expected: FAIL -