mirror of
https://github.com/servo/servo.git
synced 2025-08-27 16:18:21 +01:00
Update web-platform-tests to revision 3137d1d2d7757366a69f8a449b458b5057e0e81e
This commit is contained in:
parent
81ca858678
commit
d6ba94ca28
2339 changed files with 89274 additions and 9328 deletions
|
@ -6,7 +6,7 @@ if (this.document === undefined) {
|
|||
function checkContentType(contentType, body)
|
||||
{
|
||||
if (self.FormData && body instanceof self.FormData) {
|
||||
assert_true(contentType.startsWith("multipart/form-data;boundary="), "Request should have header content-type starting with multipart/form-data;boundary=, but got " + contentType);
|
||||
assert_true(contentType.startsWith("multipart/form-data; boundary="), "Request should have header content-type starting with multipart/form-data; boundary=, but got " + contentType);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,8 @@ function requestHeaders(desc, url, method, body, expectedOrigin, expectedContent
|
|||
|
||||
var url = RESOURCES_DIR + "inspect-headers.py"
|
||||
|
||||
requestHeaders("Fetch with GET", url, "GET", null, location.origin, null);
|
||||
requestHeaders("Fetch with HEAD", url, "HEAD", null, location.origin, null);
|
||||
requestHeaders("Fetch with GET", url, "GET", null, null, null);
|
||||
requestHeaders("Fetch with HEAD", url, "HEAD", null, null, null);
|
||||
requestHeaders("Fetch with PUT without body", url, "POST", null, location.origin, "0");
|
||||
requestHeaders("Fetch with PUT with body", url, "PUT", "Request's body", location.origin, "14");
|
||||
requestHeaders("Fetch with POST without body", url, "POST", null, location.origin, "0");
|
||||
|
@ -63,4 +63,24 @@ requestHeaders("Fetch with POST with Blob body with mime type", url, "POST", new
|
|||
requestHeaders("Fetch with Chicken", url, "Chicken", null, location.origin, null);
|
||||
requestHeaders("Fetch with Chicken with body", url, "Chicken", "Request's body", location.origin, "14");
|
||||
|
||||
function requestOriginHeader(method, mode, needsOrigin) {
|
||||
promise_test(function(test){
|
||||
return fetch(url + "?headers=origin", {method:method, mode:mode}).then(function(resp) {
|
||||
assert_equals(resp.status, 200, "HTTP status is 200");
|
||||
assert_equals(resp.type , "basic", "Response's type is basic");
|
||||
if(needsOrigin)
|
||||
assert_equals(resp.headers.get("x-request-origin") , location.origin, "Request should have an Origin header with origin: " + location.origin);
|
||||
else
|
||||
assert_equals(resp.headers.get("x-request-origin"), null, "Request should not have an Origin header")
|
||||
});
|
||||
}, "Fetch with " + method + " and mode \"" + mode + "\" " + (needsOrigin ? "needs" : "does not need") + " an Origin header");
|
||||
}
|
||||
|
||||
requestOriginHeader("GET", "cors", false);
|
||||
requestOriginHeader("POST", "same-origin", true);
|
||||
requestOriginHeader("POST", "no-cors", true);
|
||||
requestOriginHeader("PUT", "same-origin", true);
|
||||
requestOriginHeader("TacO", "same-origin", true);
|
||||
requestOriginHeader("TacO", "cors", true);
|
||||
|
||||
done();
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
assert_equals(headers.get(name), String(headerDict[name]),
|
||||
"name: " + name + " has value: " + headerDict[name]);
|
||||
}
|
||||
}, "Create headers with OpenEndedDictionary");
|
||||
}, "Create headers with record");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers(headerDict);
|
||||
|
@ -68,6 +68,14 @@
|
|||
}
|
||||
}, "Create headers with existing headers");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers({test:"test"});
|
||||
var headers2 = new Headers()
|
||||
headers2[Symbol.iterator] = headers[Symbol.iterator]
|
||||
var headers3 = new Headers(headers2)
|
||||
assert_equals(headers3.get("test"), "test")
|
||||
}, "Create headers with existing headers with custom iterator");
|
||||
|
||||
test(function() {
|
||||
var headers = new Headers();
|
||||
for (name in headerDict) {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<script id="headers-idl" type="text/plain">
|
||||
typedef (Headers or sequence<sequence<ByteString>> or OpenEndedDictionary<ByteString>) HeadersInit;
|
||||
typedef (sequence<sequence<ByteString>> or record<ByteString>) HeadersInit;
|
||||
|
||||
[Constructor(optional HeadersInit init),
|
||||
Exposed=(Window,Worker)]
|
||||
|
@ -27,7 +27,7 @@
|
|||
</script>
|
||||
<script>
|
||||
var idlsArray = new IdlArray();
|
||||
var idl = document.getElementById("headers-idl").innerHTML
|
||||
var idl = document.getElementById("headers-idl").textContent
|
||||
idlsArray.add_idls(idl);
|
||||
idlsArray.add_objects({ Headers: ['new Headers()'] });
|
||||
idlsArray.test();
|
||||
|
|
|
@ -105,6 +105,20 @@
|
|||
assert_throws(new TypeError(), function() { new Request("", options); });
|
||||
},"Bad " + parameter +" init parameter value");
|
||||
});
|
||||
|
||||
function testOnlyIfCachedMode(fetchMode, ok) {
|
||||
test(function() {
|
||||
var options = {"cache": "only-if-cached", "mode": fetchMode};
|
||||
if (ok)
|
||||
new Request("test", options);
|
||||
else
|
||||
assert_throws(new TypeError(), function() { new Request("test", options); });
|
||||
}, "Request with cache mode: only-if-cached and fetch mode: " + fetchMode);
|
||||
}
|
||||
testOnlyIfCachedMode("same-origin", true);
|
||||
testOnlyIfCachedMode("cors", false);
|
||||
testOnlyIfCachedMode("no-cors", false);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -74,8 +74,8 @@
|
|||
</script>
|
||||
<script>
|
||||
var idlsArray = new IdlArray();
|
||||
var idl = document.getElementById("body-idl").innerHTML
|
||||
idl += document.getElementById("request-idl").innerHTML
|
||||
var idl = document.getElementById("body-idl").textContent
|
||||
idl += document.getElementById("request-idl").textContent
|
||||
|
||||
idlsArray.add_idls(idl);
|
||||
idlsArray.add_untested_idls("interface Headers {};");
|
||||
|
|
|
@ -12,6 +12,25 @@
|
|||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function blobToFormDataResponse(name, blob) {
|
||||
var formData = new FormData();
|
||||
formData.append(name, blob);
|
||||
return new Response(formData);
|
||||
}
|
||||
|
||||
function readBlobAsArrayBuffer(blob) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result);
|
||||
};
|
||||
reader.onerror = function(evt) {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsArrayBuffer(blob);
|
||||
});
|
||||
}
|
||||
|
||||
function responsePromise(body, responseInit) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
resolve(new Response(body, responseInit));
|
||||
|
@ -205,6 +224,73 @@
|
|||
checkResponseBody(fetch("../resources/top.txt"), "top", checkBodyArrayBuffer, "from fetch to arrayBuffer");
|
||||
checkResponseBody(fetch("../resources/top.txt"), "top", checkBodyFormDataError, "from fetch without correct type to formData (error case)");
|
||||
|
||||
promise_test(function(test) {
|
||||
var response = new Response(new Blob([
|
||||
"--boundary\r\n",
|
||||
"Content-Disposition: form-data; name=string\r\n",
|
||||
"\r\nvalue", new Uint8Array([0xC2, 0xA0]), "1\r\n",
|
||||
"--boundary\r\n",
|
||||
"Content-Disposition: form-data; name=string-with-default-charset\r\n",
|
||||
"Content-Type: text/plain; charset=utf-8\r\n",
|
||||
"\r\nvalue", new Uint8Array([0xC2, 0xA0]), "2\r\n",
|
||||
"--boundary\r\n",
|
||||
"Content-Disposition: form-data; name=string-with-non-default-charset\r\n",
|
||||
"Content-Type: text/plain; charset=iso-8859-1\r\n",
|
||||
"\r\nvalue", new Uint8Array([0xC2, 0xA0]), "3\r\n",
|
||||
"--boundary\r\n",
|
||||
"Content-Disposition: form-data; name=string-with-non-default-type\r\n",
|
||||
"Content-Type: application/octet-stream\r\n",
|
||||
"\r\nvalue", new Uint8Array([0xC2, 0xA0]), "4\r\n",
|
||||
"--boundary\r\n",
|
||||
"Content-Disposition: form-data; name=file; filename=file1\r\n",
|
||||
"Content-Type: application/octet-stream; x-param=x-value\r\n",
|
||||
"\r\n", new Uint8Array([5, 0x0, 0xFF]), "\r\n",
|
||||
"--boundary\r\n",
|
||||
"Content-Disposition: form-data; name=\"file-without-type\"; filename=\"file2\"\r\n",
|
||||
"\r\n", new Uint8Array([6, 0x0, 0x7F, 0xFF]), "\r\n",
|
||||
"--boundary--\r\n"
|
||||
]), { "headers": [["Content-Type", 'multipart/form-data; boundary="boundary"']] });
|
||||
return response.formData().then(function(bodyAsFormData) {
|
||||
// Non-file parts must always be decoded using utf-8 encoding.
|
||||
assert_equals(bodyAsFormData.get("string"), "value\u00A01", "Retrieve and verify response's 1st entry value");
|
||||
assert_equals(bodyAsFormData.get("string-with-default-charset"), "value\u00A02", "Retrieve and verify response's 2nd entry value");
|
||||
assert_equals(bodyAsFormData.get("string-with-non-default-charset"), "value\u00A03", "Retrieve and verify response's 3rd entry value");
|
||||
assert_equals(bodyAsFormData.get("string-with-non-default-type"), "value\u00A04", "Retrieve and verify response's 4th entry value");
|
||||
// The name of a File must be taken from the filename parameter in
|
||||
// the Content-Disposition header field.
|
||||
assert_equals(bodyAsFormData.get("file").name, "file1", "Retrieve and verify response's 5th entry name property");
|
||||
assert_equals(bodyAsFormData.get("file-without-type").name, "file2", "Retrieve and verify response's 6th entry name property");
|
||||
// The type of a File must be taken from the Content-Type header field
|
||||
// which defaults to "text/plain".
|
||||
assert_equals(bodyAsFormData.get("file").type, "application/octet-stream; x-param=x-value", "Retrieve and verify response's 5th entry type property");
|
||||
assert_equals(bodyAsFormData.get("file-without-type").type, "text/plain", "Retrieve and verify response's 6th entry type property");
|
||||
|
||||
return Promise.resolve().then(function() {
|
||||
return blobToFormDataResponse("file", bodyAsFormData.get("file")).text().then(function(bodyAsText) {
|
||||
// Verify that filename, name and type are preserved.
|
||||
assert_regexp_match(bodyAsText, /\r\nContent-Disposition: *form-data;([^\r\n]*;)* *filename=("?)file1\2[;\r]/i, "Retrieve and verify response's 5th entry filename parameter");
|
||||
assert_regexp_match(bodyAsText, /\r\nContent-Disposition: *form-data;([^\r\n]*;)* *name=("?)file\2[;\r]/i, "Retrieve and verify response's 5th entry name parameter");
|
||||
assert_regexp_match(bodyAsText, /\r\nContent-Type: *application\/octet-stream; x-param=x-value\r\n/i, "Retrieve and verify response's 5th entry type field");
|
||||
// Verify that the content is preserved.
|
||||
return readBlobAsArrayBuffer(bodyAsFormData.get("file")).then(function(arrayBuffer) {
|
||||
assert_array_equals(new Uint8Array(arrayBuffer), new Uint8Array([5, 0x0, 0xFF]), "Retrieve and verify response's 5th entry content");
|
||||
});
|
||||
});
|
||||
}).then(function() {
|
||||
return blobToFormDataResponse("file-without-type", bodyAsFormData.get("file-without-type")).text().then(function(bodyAsText) {
|
||||
// Verify that filename, name and type are preserved.
|
||||
assert_regexp_match(bodyAsText, /\r\nContent-Disposition: *form-data;([^\r\n]*;)* *filename=("?)file2\2[;\r]/i, "Retrieve and verify response's 6th entry filename parameter");
|
||||
assert_regexp_match(bodyAsText, /\r\nContent-Disposition: *form-data;([^\r\n]*;)* *name=("?)file-without-type\2[;\r]/i, "Retrieve and verify response's 6th entry name parameter");
|
||||
assert_regexp_match(bodyAsText, /\r\nContent-Type: *text\/plain\r\n/i, "Retrieve and verify response's 6th entry type field");
|
||||
// Verify that the content is preserved.
|
||||
return readBlobAsArrayBuffer(bodyAsFormData.get("file-without-type")).then(function(arrayBuffer) {
|
||||
assert_array_equals(new Uint8Array(arrayBuffer), new Uint8Array([6, 0x0, 0x7F, 0xFF]), "Retrieve and verify response's 6th entry content");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, "Consume response's body: from multipart form data blob to formData");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -56,8 +56,8 @@
|
|||
</script>
|
||||
<script>
|
||||
var idlsArray = new IdlArray();
|
||||
var idl = document.getElementById("body-idl").innerHTML
|
||||
idl += document.getElementById("response-idl").innerHTML
|
||||
var idl = document.getElementById("body-idl").textContent
|
||||
idl += document.getElementById("response-idl").textContent
|
||||
|
||||
idlsArray.add_idls(idl);
|
||||
idlsArray.add_untested_idls("interface Headers {};");
|
||||
|
|
|
@ -2,18 +2,8 @@
|
|||
<script src=/resources/testharnessreport.js></script>
|
||||
<div id=log></div>
|
||||
<script>
|
||||
var fails = ["", "?type=", "?type=x", "?type=x/x"],
|
||||
passes = ["?type=image/gif", "?type=image/png", "?type=image/png;blah"]
|
||||
|
||||
fails.forEach(function(urlpart) {
|
||||
async_test(function(t) {
|
||||
var img = document.createElement("img")
|
||||
img.onerror = t.step_func_done(function(){})
|
||||
img.onload = t.unreached_func("Unexpected load event")
|
||||
img.src = "resources/image.py" + urlpart
|
||||
document.body.appendChild(img)
|
||||
}, "URL query: " + urlpart)
|
||||
})
|
||||
// Note: images get always sniffed, nosniff doesn't do anything
|
||||
var passes = ["", "?type=", "?type=x", "?type=x/x", "?type=image/gif", "?type=image/png", "?type=image/png;blah"]
|
||||
|
||||
passes.forEach(function(urlpart) {
|
||||
async_test(function(t) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue