diff options
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 21 | ||||
-rw-r--r-- | tests/wpt/metadata/MANIFEST.json | 6 | ||||
-rw-r--r-- | tests/wpt/web-platform-tests/XMLHttpRequest/responsexml-get-twice.htm | 66 |
3 files changed, 89 insertions, 4 deletions
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 140ad159792..355cd989e93 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -778,8 +778,8 @@ impl XMLHttpRequestMethods for XMLHttpRequest { }, // Step 2 XMLHttpRequestResponseType::Document => { - let op_doc = self.GetResponseXML(); - if let Ok(Some(doc)) = op_doc { + let op_doc = self.document_response(); + if let Some(doc) = op_doc { doc.to_jsval(cx, rval.handle_mut()); } else { // Substep 1 @@ -1126,19 +1126,28 @@ impl XMLHttpRequest { // https://xhr.spec.whatwg.org/#document-response fn document_response(&self) -> Option<Root<Document>> { + // Step 1 + let response = self.response_xml.get(); + if response.is_some() { + return self.response_xml.get(); + } + let mime_type = self.final_mime_type(); - //TODO: prescan the response to determine encoding if final charset is null + // TODO: prescan the response to determine encoding if final charset is null let charset = self.final_charset().unwrap_or(UTF_8); let temp_doc: Root<Document>; match mime_type { Some(Mime(mime::TopLevel::Text, mime::SubLevel::Html, _)) => { + // Step 5 if self.response_type.get() == XMLHttpRequestResponseType::_empty { return None; } + // Step 6 else { temp_doc = self.document_text_html(); } }, + // Step 7 Some(Mime(mime::TopLevel::Text, mime::SubLevel::Xml, _)) | Some(Mime(mime::TopLevel::Application, mime::SubLevel::Xml, _)) | None => { @@ -1152,10 +1161,14 @@ impl XMLHttpRequest { return None; } }, + // Step 4 _ => { return None; } } + // Step 9 temp_doc.set_encoding_name(DOMString::from(charset.name())); - Some(temp_doc) + // Step 13 + self.response_xml.set(Some(temp_doc.r())); + return self.response_xml.get(); } #[allow(unsafe_code)] diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 6f6feaca966..5bdb72a6704 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -33814,6 +33814,12 @@ "url": "/WebIDL/ecmascript-binding/has-instance.html" } ], + "XMLHttpRequest/responsexml-get-twice.htm": [ + { + "path": "XMLHttpRequest/responsexml-get-twice.htm", + "url": "/XMLHttpRequest/responsexml-get-twice.htm" + } + ], "html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-percent-encoded.html": [ { "path": "html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-percent-encoded.html", diff --git a/tests/wpt/web-platform-tests/XMLHttpRequest/responsexml-get-twice.htm b/tests/wpt/web-platform-tests/XMLHttpRequest/responsexml-get-twice.htm new file mode 100644 index 00000000000..e86a6d59e51 --- /dev/null +++ b/tests/wpt/web-platform-tests/XMLHttpRequest/responsexml-get-twice.htm @@ -0,0 +1,66 @@ +<!doctype html> +<meta charset="utf-8"> +<title></title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + async_test(function() { + var client = new XMLHttpRequest() + client.open("GET", "resources/well-formed.xml") + client.responseType = "document" + assert_equals(client.responseType, "document") + client.send() + client.onload = this.step_func_done(function() { + var first = client.response + var second = client.response + assert_not_equals(first, null) + assert_not_equals(second, null) + assert_equals(first, second) + }) + }, "Getting response, then response") + + async_test(function() { + var client = new XMLHttpRequest() + client.open("GET", "resources/well-formed.xml") + client.responseType = "document" + assert_equals(client.responseType, "document") + client.send() + client.onload = this.step_func_done(function() { + var first = client.responseXML + var second = client.responseXML + assert_not_equals(first, null) + assert_not_equals(second, null) + assert_equals(first, second) + }) + }, "Getting responseXML, then responseXML") + + async_test(function() { + var client = new XMLHttpRequest() + client.open("GET", "resources/well-formed.xml") + client.responseType = "document" + assert_equals(client.responseType, "document") + client.send() + client.onload = this.step_func_done(function() { + var first = client.responseXML + var second = client.response + assert_not_equals(first, null) + assert_not_equals(second, null) + assert_equals(first, second) + }) + }, "Getting responseXML, then response") + + async_test(function() { + var client = new XMLHttpRequest() + client.open("GET", "resources/well-formed.xml") + client.responseType = "document" + assert_equals(client.responseType, "document") + client.send() + client.onload = this.step_func_done(function() { + var first = client.response + var second = client.responseXML + assert_not_equals(first, null) + assert_not_equals(second, null) + assert_equals(first, second) + }) + }, "Getting response, then responseXML") +</script> |