Update web-platform-tests to revision 4a5223502fa660ce03e470af6a61c8bc26c5a8ee

This commit is contained in:
WPT Sync Bot 2018-04-23 21:13:37 -04:00
parent c5f7c9ccf3
commit e891345f26
1328 changed files with 36632 additions and 20588 deletions

View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Test that async requests (both OPTIONS preflight and regular) are sent with the User-Agent header</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script type="text/javascript">
async_test((test) => {
let xhr = new XMLHttpRequest;
xhr.open("GET", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/header-user-agent.py");
xhr.setRequestHeader("x-test", "foobar");
xhr.onerror = test.unreached_func("Unexpected error");
xhr.onload = test.step_func_done(() => {
assert_equals(xhr.responseText, "PASS");
});
xhr.send();
}, "Async request has User-Agent header");
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Test that sync requests (both OPTIONS preflight and regular) are sent with the User-Agent header</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script type="text/javascript">
test(function() {
let xhr = new XMLHttpRequest;
xhr.open("post", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/header-user-agent.py", false);
xhr.setRequestHeader("x-test", "foobar");
xhr.send();
assert_equals(xhr.responseText, "PASS");
}, "Sync request has User-Agent header");
</script>
</body>
</html>

View file

@ -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>

View file

@ -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");

View file

@ -0,0 +1,15 @@
def main(request, response):
response.headers.set("Access-Control-Allow-Origin", "*")
response.headers.set("Access-Control-Max-Age", 0)
response.headers.set('Access-Control-Allow-Headers', "x-test")
if request.method == "OPTIONS":
if not request.headers.get("User-Agent"):
response.content = "FAIL: User-Agent header missing in preflight request."
response.status = 400
else:
if request.headers.get("User-Agent"):
response.content = "PASS"
else:
response.content = "FAIL: User-Agent header missing in request"
response.status = 400

View file

@ -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");

View file

@ -15,7 +15,7 @@
test(function() {
var client = new XMLHttpRequest()
client.open("POST", "resources/content.py", false)
if(input)
if(input !== null)
client.setRequestHeader("Content-Type", input)
client.send("TEST")
assert_equals(client.responseText, "TEST")
@ -28,6 +28,11 @@
"text; charset=ascii",
"header with invalid MIME type is not changed"
)
request(
"",
"",
"header with invalid MIME type (empty string) is not changed"
)
request(
"charset=ascii",
"charset=ascii",
@ -40,7 +45,7 @@
)
request(
"text/plain;charset=utf-8",
"text/plain;charset=utf-8",
"text/plain;charset=UTF-8",
"Correct text/plain MIME with charset"
)
request(
@ -53,6 +58,11 @@
"text/plain",
"If no charset= param is given, implementation should not add one - known MIME"
)
request(
"text/plain; hi=bye",
"text/plain; hi=bye",
"If no charset= param is given, implementation should not add one - known MIME, unknown param, two spaces"
)
request(
"text/x-thepiano;charset= waddup",
"text/x-thepiano;charset=UTF-8",
@ -60,7 +70,7 @@
)
request(
"text/plain;charset=utf-8;charset=waddup",
"text/plain;charset=utf-8;charset=UTF-8",
"text/plain;charset=UTF-8",
"charset given but wrong, fix it (known MIME, bogus charset)"
)
request(
@ -70,14 +80,34 @@
)
request(
"text/x-pink-unicorn; charset=windows-1252; charset=bogus; notrelated; charset=ascii",
"text/x-pink-unicorn; charset=UTF-8; charset=UTF-8; notrelated; charset=UTF-8",
"If multiple charset parameters are given, all should be rewritten"
"text/x-pink-unicorn;charset=UTF-8",
"Multiple charset parameters deduplicate, bogus parameter dropped"
)
request(
null,
"text/plain;charset=UTF-8",
"No content type set, give MIME and charset"
)
request(
"text/plain;charset= utf-8",
"text/plain;charset=UTF-8",
"charset with space")
request(
"text/plain;charset=\"utf-8\"",
"text/plain;charset=UTF-8",
"charset in double quotes")
request(
"text/plain;charset=\" utf-8\"",
"text/plain;charset=UTF-8",
"charset in double quotes with space")
request(
"text/plain;charset=\"u\\t\\f-8\"",
"text/plain;charset=UTF-8",
"charset in double quotes with backslashes")
request(
"YO/yo;charset=x;yo=YO; X=y",
"yo/yo;charset=UTF-8;yo=YO;x=y",
"unknown parameters need to be preserved")
</script>
</body>
</html>

View file

@ -1,32 +0,0 @@
<!--
self.close()
var xhr = new XMLHttpRequest();
xhr.open("GET", "/resources/testharness.js");
xhr.send(42);
postMessage(xhr.readyState)
/*-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>XHR used when worker is closing itself</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var test = async_test();
test.step(function() {
var worker = new Worker('#')
worker.onmessage = function(e) {
test.step(function() {
assert_equals(e.data, XMLHttpRequest.OPENED, 'XHR.readyState')
})
test.done()
}
})
</script>
</body>
</html>
<!--*/ //-->