Implement Document::cookie correctly for cookie-averse documents.

This commit is contained in:
Ms2ger 2016-03-31 10:08:01 +02:00
parent 436f7316d9
commit 3c6cc642ee
2 changed files with 21 additions and 7 deletions

View file

@ -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<DOMString> {
// 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);

View file

@ -1,5 +0,0 @@
[document-cookie.html]
type: testharness
[getting cookie for a cookie-averse document returns empty string, setting does nothing]
expected: FAIL