Commit 4a20bad5 authored by Austin James Ahlstrom's avatar Austin James Ahlstrom Committed by Commit Bot

Edits to support the overrideMimeType-blob test

These changes are to bring Chrome's XHR implementation
in greater agreement with the XHR specs (see links).
This change makes it so that setting the content type
as defined in the XHR response behavior for blobs
is no longer dependent on a non-blank file path,
which is more consistent with the specs.

https://xhr.spec.whatwg.org/#the-overridemimetype()-method
https://xhr.spec.whatwg.org/#response-body

A change to the overridemimetype-blob test is added
based on communication with a spec editor (see link).
This is due to an inconsistency between two specs:
the MIME-sniffing standard and RFC-2045 (see links).

http://logs.glob.uno/?c=freenode%23whatwg&s=6+Jul+2017&e=6+Jul+2017
(see comments by yhirano, annevk, and GPHemsley)
https://mimesniff.spec.whatwg.org/#parsing-a-mime-type
https://tools.ietf.org/html/rfc2045#page-12

This change fixed four test failures on the WPT test,
but created one test failure (xhr-response-blob.html).
I changed the expectations file related to this test
to accommodate the change.

There are two 'FIXME' comments relevant to this test:
XMLHttpRequest.cpp, lines 1428-1429 and lines 1593-1595.
I don't think that they're necessary, and would consider
removing them, but I don't know best practice for that.

Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=699085
Change-Id: I77919178b725792e914d6984cc3f5ebde654e5af
Reviewed-on: https://chromium-review.googlesource.com/563139Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarTakeshi Yoshino <tyoshino@chromium.org>
Commit-Queue: Austin James Ahlstrom <aahlstrom@google.com>
Cr-Commit-Position: refs/heads/master@{#487412}
parent c482fb32
This is a testharness.js-based test.
FAIL Use text/xml as fallback MIME type assert_equals: expected "text/xml" but got ""
PASS Use text/xml as fallback MIME type, 2
FAIL Bogus MIME type should end up as application/octet-stream assert_equals: expected "application/octet-stream" but got ""
FAIL Bogus MIME type should end up as application/octet-stream, 2 assert_equals: expected "application/octet-stream" but got ""
FAIL Valid MIME types need to be normalized assert_equals: expected "hi/x" but got ""
Harness: the test ran to completion.
...@@ -59,7 +59,7 @@ async_test(t => { ...@@ -59,7 +59,7 @@ async_test(t => {
}) })
client.open("GET", "resources/status.py") client.open("GET", "resources/status.py")
client.responseType = "blob" client.responseType = "blob"
client.overrideMimeType("HI/x;test") client.overrideMimeType("HI/x;test=test")
client.send() client.send()
}, "Valid MIME types need to be normalized") }, "Valid MIME types need to be normalized")
</script> </script>
...@@ -15,6 +15,7 @@ function testBlob(blobURL, blobType, doneFunction) { ...@@ -15,6 +15,7 @@ function testBlob(blobURL, blobType, doneFunction) {
return; return;
} }
shouldBeTrue("xhr.response instanceof Blob"); shouldBeTrue("xhr.response instanceof Blob");
// This is checking a value determined by MIME sniffing
shouldBeEqualToString("xhr.response.type", blobType); shouldBeEqualToString("xhr.response.type", blobType);
doneFunction(); doneFunction();
} }
...@@ -22,7 +23,7 @@ function testBlob(blobURL, blobType, doneFunction) { ...@@ -22,7 +23,7 @@ function testBlob(blobURL, blobType, doneFunction) {
testBlob("resources/UTF8.txt", "text/plain", function() { testBlob("resources/UTF8.txt", "text/plain", function() {
testBlob("resources/does_not_exist.txt", "", function() { testBlob("resources/does_not_exist.txt", "", function() {
testBlob("resources/empty-file", "", function() { testBlob("resources/empty-file", "text/plain", function() {
if (window.testRunner) if (window.testRunner)
testRunner.notifyDone(); testRunner.notifyDone();
}) })
......
...@@ -17,5 +17,5 @@ FAIL xhr.response.type should be . Threw exception TypeError: Cannot read proper ...@@ -17,5 +17,5 @@ FAIL xhr.response.type should be . Threw exception TypeError: Cannot read proper
PASS xhr.responseType is "blob" PASS xhr.responseType is "blob"
PASS xhr.response is null PASS xhr.response is null
PASS xhr.response instanceof Blob is true PASS xhr.response instanceof Blob is true
PASS xhr.response.type is "" PASS xhr.response.type is "text/plain"
...@@ -1491,8 +1491,6 @@ AtomicString XMLHttpRequest::FinalResponseMIMETypeWithFallback() const { ...@@ -1491,8 +1491,6 @@ AtomicString XMLHttpRequest::FinalResponseMIMETypeWithFallback() const {
if (!final_type.IsEmpty()) if (!final_type.IsEmpty())
return final_type; return final_type;
// FIXME: This fallback is not specified in the final MIME type algorithm
// of the XHR spec. Move this to more appropriate place.
return AtomicString("text/xml"); return AtomicString("text/xml");
} }
...@@ -1656,11 +1654,8 @@ PassRefPtr<BlobDataHandle> XMLHttpRequest::CreateBlobDataHandleFromResponse() { ...@@ -1656,11 +1654,8 @@ PassRefPtr<BlobDataHandle> XMLHttpRequest::CreateBlobDataHandleFromResponse() {
if (!file_path.IsEmpty() && length_downloaded_to_file_) { if (!file_path.IsEmpty() && length_downloaded_to_file_) {
blob_data->AppendFile(file_path, 0, length_downloaded_to_file_, blob_data->AppendFile(file_path, 0, length_downloaded_to_file_,
InvalidFileTime()); InvalidFileTime());
// FIXME: finalResponseMIMETypeWithFallback() defaults to
// text/xml which may be incorrect. Replace it with
// finalResponseMIMEType() after compatibility investigation.
blob_data->SetContentType(FinalResponseMIMETypeWithFallback().LowerASCII());
} }
blob_data->SetContentType(FinalResponseMIMETypeWithFallback().LowerASCII());
return BlobDataHandle::Create(std::move(blob_data), return BlobDataHandle::Create(std::move(blob_data),
length_downloaded_to_file_); length_downloaded_to_file_);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment