Skip to content

Commit

Permalink
Bug 1452928 [wpt PR 8449] - Add more XMLHttpRequest overrideMimeType(…
Browse files Browse the repository at this point in the history
…) tests, a=testonly

Automatic update from web-platform-testsAdd more XMLHttpRequest overrideMimeType() tests

For whatwg/xhr#157, whatwg/xhr#174, and whatwg/mimesniff#42.
--

wpt-commits: ae41496630ba35cff974877498383f1280ca07c2
wpt-pr: 8449

UltraBlame original commit: a743786f569a9e77f8c86a2882abee702f58f981
  • Loading branch information
marco-c committed Oct 2, 2019
1 parent 31f7248 commit 9888f82
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 52 deletions.
16 changes: 13 additions & 3 deletions testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -374471,6 +374471,12 @@
{}
]
],
"xhr/overridemimetype-edge-cases.window.js": [
[
"/xhr/overridemimetype-edge-cases.window.html",
{}
]
],
"xhr/overridemimetype-headers-received-state-force-shiftjis.htm": [
[
"/xhr/overridemimetype-headers-received-state-force-shiftjis.htm",
Expand Down Expand Up @@ -579033,7 +579039,7 @@
"support"
],
"mimesniff/mime-types/resources/mime-types.json": [
"9271134541b22f4af44b6d179606c7a6cb8f3227",
"b214e6025adc09d310f47eea34f2ea316f6132ec",
"support"
],
"mixed-content/OWNERS": [
Expand Down Expand Up @@ -614741,13 +614747,17 @@
"testharness"
],
"xhr/overridemimetype-blob.html": [
"462d95dec7146c2a7beba5d8b2285fd2b8460002",
"38a7f6e2871ac0def651e5b82bb8a43b061633bb",
"testharness"
],
"xhr/overridemimetype-done-state.htm": [
"167f34f8dfc1312a9124c12ee4f8de808fa41680",
"testharness"
],
"xhr/overridemimetype-edge-cases.window.js": [
"a76e1c81a86823765be280747d2fa6994395cc25",
"testharness"
],
"xhr/overridemimetype-headers-received-state-force-shiftjis.htm": [
"92a00af686310d8b44fb5e4c70cc6fbea28e0a88",
"testharness"
Expand Down Expand Up @@ -615225,7 +615235,7 @@
"testharness"
],
"xhr/responsetext-decoding.htm": [
"538d6d5121157e04c44fd947140f2c913dc3b65e",
"d08dd5c1d0b21b639389dfc1deec65215b3334dc",
"testharness"
],
"xhr/responsetype.html": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
"input": "\t",
"output": null
},
{
"input": "/",
"output": null
},
{
"input": "bogus",
"output": null
Expand All @@ -295,6 +299,10 @@
"input": "(/)",
"output": null
},
{
"input": "ÿ/ÿ",
"output": null
},
{
"input": "text/html(;doesnot=matter",
"output": null
Expand Down
89 changes: 40 additions & 49 deletions testing/web-platform/tests/xhr/overridemimetype-blob.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,51 @@
<div id="log"></div>
<script>
async_test(t => {
const client = new XMLHttpRequest()
const client = new XMLHttpRequest();
client.onload = t.step_func_done(() => {
assert_equals(client.getResponseHeader("Content-Type"), "")
assert_equals(client.response.type, "text/xml")
})
client.open("GET", "resources/status.py")
client.responseType = "blob"
client.send()
}, "Use text/xml as fallback MIME type")
assert_equals(client.getResponseHeader("Content-Type"), "");
assert_equals(client.response.type, "text/xml");
});
client.open("GET", "resources/status.py");
client.responseType = "blob";
client.send();
}, "Use text/xml as fallback MIME type");

async_test(t => {
const client = new XMLHttpRequest()
const client = new XMLHttpRequest();
client.onload = t.step_func_done(() => {
assert_equals(client.getResponseHeader("Content-Type"), "")
assert_equals(client.response.type, "text/xml")
assert_equals(client.getResponseHeader("Content-Type"), "");
assert_equals(client.response.type, "text/xml");
})
client.open("GET", "resources/status.py?content=thisshouldnotmakeadifferencebutdoes")
client.responseType = "blob"
client.send()
}, "Use text/xml as fallback MIME type, 2")
client.open("GET", "resources/status.py?content=thisshouldnotmakeadifferencebutdoes");
client.responseType = "blob";
client.send();
}, "Use text/xml as fallback MIME type, 2");

async_test(t => {
const client = new XMLHttpRequest()
client.onload = t.step_func_done(() => {
assert_equals(client.getResponseHeader("Content-Type"), "")
assert_equals(client.response.type, "application/octet-stream")
})
client.open("GET", "resources/status.py")
client.responseType = "blob"
client.overrideMimeType("bogus")
client.send()
}, "Bogus MIME type should end up as application/octet-stream")
promise_test(() => {
// Don't load generated-mime-types.json as sending them all over the network would be prohibitive
return fetch("../mimesniff/mime-types/resources/mime-types.json").then(res => res.json()).then(runTests);
}, "Loading data…");

async_test(t => {
const client = new XMLHttpRequest()
client.onload = t.step_func_done(() => {
assert_equals(client.getResponseHeader("Content-Type"), "")
assert_equals(client.response.type, "application/octet-stream")
})
client.open("GET", "resources/status.py")
client.responseType = "blob"
client.overrideMimeType("text/xml;charset=†")
client.send()
}, "Bogus MIME type should end up as application/octet-stream, 2")

async_test(t => {
const client = new XMLHttpRequest()
client.onload = t.step_func_done(() => {
assert_equals(client.getResponseHeader("Content-Type"), "")
assert_equals(client.response.type, "hi/x")
})
client.open("GET", "resources/status.py")
client.responseType = "blob"
client.overrideMimeType("HI/x;test=test")
client.send()
}, "Valid MIME types need to be normalized")
function runTests(tests) {
let index = 0;
tests.forEach((val) => {
if(typeof val === "string") {
return;
}
index++;
async_test(t => {
const client = new XMLHttpRequest(),
expectedOutput = val.output !== null ? val.output : "application/octet-stream";
client.onload = t.step_func_done(() => {
assert_equals(client.getResponseHeader("Content-Type"), "");
assert_equals(client.response.type, expectedOutput);
});
client.open("GET", "resources/status.py");
client.responseType = "blob";
client.overrideMimeType(val.input);
client.send();
}, index + ") MIME types need to be parsed and serialized: " + val.input);
});
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const testURL = "resources/status.py?type=" + encodeURIComponent("text/plain;charset=windows-1252") + "&content=%C2%F0";

async_test(t => {
const client = new XMLHttpRequest();
let secondTime = false;
client.onload = t.step_func(() => {
if(!secondTime) {
assert_equals(client.responseText, "\uFFFD");
secondTime = true;
client.open("GET", testURL);
client.send();
} else {
assert_equals(client.responseText, "Âð");
t.done();
}
});
client.open("GET", testURL);
client.overrideMimeType("text/plain;charset=UTF-8")
client.send();
}, "overrideMimeType() state needs to be reset across requests");

async_test(t => {
const client = new XMLHttpRequest();
client.onload = t.step_func_done(() => {
assert_equals(client.responseText, "Âð")
});
client.open("GET", testURL);
client.overrideMimeType("text/xml");
client.send();
}, "If charset is not overridden by overrideMimeType() the original continues to be used");

async_test(t => {
const client = new XMLHttpRequest();
client.onload = t.step_func_done(() => {
assert_equals(client.responseText, "\uFFFD")
});
client.open("GET", testURL);
client.overrideMimeType("text/plain;charset=342");
client.send();
}, "Charset can be overridden by overrideMimeType() with a bogus charset");
1 change: 1 addition & 0 deletions testing/web-platform/tests/xhr/responsetext-decoding.htm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
request("text/plain", "%EF%BB%BF", "", "text");
request("text/plain", "%EF%BB%BF%EF%BB%BF", "\uFEFF", "text");
request("text/plain", "%C2", "\uFFFD", "text");
request("text/plain;charset=bogus", "%C2", "\uFFFD", "text");
request("text/xml", "%FE%FF", "", "text");
request("text/xml", "%FE%FF%FE%FF", "\uFEFF", "text");
request("text/xml", "%EF%BB%BF", "", "text");
Expand Down

0 comments on commit 9888f82

Please sign in to comment.