mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Update web-platform-tests to revision e8bfc205e36ad699601212cd50083870bad9a75d
This commit is contained in:
parent
65dd6d4340
commit
ccdb0a3458
1428 changed files with 118036 additions and 9786 deletions
|
@ -0,0 +1,2 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Current page used as a test helper</title>
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Incumbent page used as a test helper</title>
|
||||
|
||||
<iframe src="../current/current.html" id="c"></iframe>
|
||||
<iframe src="../relevant/relevant.html" id="r"></iframe>
|
||||
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const current = document.querySelector('#c').contentWindow;
|
||||
const relevant = document.querySelector('#r').contentWindow;
|
||||
|
||||
window.createRedirectResponse = (...args) => {
|
||||
return current.Response.redirect.call(relevant.Response, ...args);
|
||||
};
|
||||
|
||||
</script>
|
|
@ -0,0 +1,2 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Relevant page used as a test helper</title>
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Response.redirect URL parsing, with multiple globals in play</title>
|
||||
<link rel="help" href="https://fetch.spec.whatwg.org/#dom-response-redirect">
|
||||
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
|
||||
<!-- This is the entry global -->
|
||||
|
||||
<iframe src="incumbent/incumbent.html"></iframe>
|
||||
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const loadPromise = new Promise(resolve => {
|
||||
window.addEventListener("load", () => resolve());
|
||||
});
|
||||
|
||||
promise_test(() => {
|
||||
return loadPromise.then(() => {
|
||||
const res = frames[0].createRedirectResponse("url");
|
||||
|
||||
assert_equals(res.headers.get("Location"), new URL("current/url", location.href).href);
|
||||
});
|
||||
}, "should parse the redirect Location URL relative to the current settings object");
|
||||
|
||||
</script>
|
|
@ -93,6 +93,44 @@
|
|||
});
|
||||
}, 'Cancelling stream should not affect cloned one');
|
||||
|
||||
function testReadableStreamClone(initialBuffer, bufferType)
|
||||
{
|
||||
promise_test(function(test) {
|
||||
var response = new Response(new ReadableStream({start : function(controller) {
|
||||
controller.enqueue(initialBuffer);
|
||||
controller.close();
|
||||
}}));
|
||||
|
||||
var clone = response.clone();
|
||||
var stream1 = response.body;
|
||||
var stream2 = clone.body;
|
||||
|
||||
var buffer;
|
||||
return stream1.getReader().read().then(function(data) {
|
||||
assert_false(data.done);
|
||||
assert_true(data.value === initialBuffer, "Buffer of being-cloned response stream is the same as the original buffer");
|
||||
return stream2.getReader().read();
|
||||
}).then(function(data) {
|
||||
assert_false(data.done);
|
||||
assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
|
||||
assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
|
||||
assert_true(data.value !== initialBuffer, "Buffer of cloned response stream is a clone of the original buffer");
|
||||
});
|
||||
}, "Check response clone use structureClone for teed ReadableStreams (" + bufferType + "chunk)");
|
||||
}
|
||||
|
||||
var arrayBuffer = new ArrayBuffer(16);
|
||||
testReadableStreamClone(new Int8Array(arrayBuffer, 1), "Int8Array");
|
||||
testReadableStreamClone(new Int16Array(arrayBuffer, 2, 2), "Int16Array");
|
||||
testReadableStreamClone(new Int32Array(arrayBuffer), "Int32Array");
|
||||
testReadableStreamClone(arrayBuffer, "ArrayBuffer");
|
||||
testReadableStreamClone(new Uint8Array(arrayBuffer), "Uint8Array");
|
||||
testReadableStreamClone(new Uint8ClampedArray(arrayBuffer), "Uint8ClampedArray");
|
||||
testReadableStreamClone(new Uint16Array(arrayBuffer, 2), "Uint16Array");
|
||||
testReadableStreamClone(new Uint32Array(arrayBuffer), "Uint32Array");
|
||||
testReadableStreamClone(new Float32Array(arrayBuffer), "Float32Array");
|
||||
testReadableStreamClone(new Float64Array(arrayBuffer), "Float64Array");
|
||||
testReadableStreamClone(new DataView(arrayBuffer, 2, 8), "DataView");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -93,11 +93,13 @@
|
|||
}, "Consume empty " + bodyType + " response body as " + (asText ? "text" : "arrayBuffer"));
|
||||
}
|
||||
|
||||
// FIXME: Add BufferSource, FormData and URLSearchParams.
|
||||
checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
|
||||
checkResponseWithEmptyBody("text", "", false);
|
||||
checkResponseWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
|
||||
checkResponseWithEmptyBody("text", "", true);
|
||||
checkResponseWithEmptyBody("URLSearchParams", new URLSearchParams(""), true);
|
||||
checkResponseWithEmptyBody("FormData", new FormData(), true);
|
||||
checkResponseWithEmptyBody("ArrayBuffer", new ArrayBuffer(), true);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -28,6 +28,8 @@ var formData = new FormData();
|
|||
formData.append("name", "value");
|
||||
var textData = JSON.stringify("This is response's body");
|
||||
var blob = new Blob([textData], { "type" : "text/plain" });
|
||||
var urlSearchParamsData = "name=value";
|
||||
var urlSearchParams = new URLSearchParams(urlSearchParamsData);
|
||||
|
||||
promise_test(function(test) {
|
||||
var response = new Response(blob);
|
||||
|
@ -39,6 +41,11 @@ promise_test(function(test) {
|
|||
return validateStreamFromString(response.body.getReader(), textData);
|
||||
}, "Read text response's body as readableStream");
|
||||
|
||||
promise_test(function(test) {
|
||||
var response = new Response(urlSearchParams);
|
||||
return validateStreamFromString(response.body.getReader(), urlSearchParamsData);
|
||||
}, "Read URLSearchParams response's body as readableStream");
|
||||
|
||||
promise_test(function(test) {
|
||||
var arrayBuffer = new ArrayBuffer(textData.length);
|
||||
var int8Array = new Int8Array(arrayBuffer);
|
||||
|
|
|
@ -12,17 +12,49 @@
|
|||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function checkBodyText(response, expectedBody) {
|
||||
function responsePromise(body, responseInit) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
resolve(new Response(body, responseInit));
|
||||
});
|
||||
}
|
||||
|
||||
function responseStringToMultipartFormTextData(response, name, value) {
|
||||
assert_true(response.headers.has("Content-Type"), "Response contains Content-Type header");
|
||||
var boundaryMatches = response.headers.get("Content-Type").match(/;\s*boundary=("?)([^";\s]*)\1/);
|
||||
assert_true(!!boundaryMatches, "Response contains boundary parameter");
|
||||
return stringToMultipartFormTextData(boundaryMatches[2], name, value);
|
||||
}
|
||||
|
||||
function streamResponsePromise(streamData, responseInit) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var stream = new ReadableStream({
|
||||
start: function(controller) {
|
||||
controller.enqueue(stringToArray(streamData));
|
||||
controller.close();
|
||||
}
|
||||
});
|
||||
resolve(new Response(stream, responseInit));
|
||||
});
|
||||
}
|
||||
|
||||
function stringToMultipartFormTextData(multipartBoundary, name, value) {
|
||||
return ('--' + multipartBoundary + '\r\n' +
|
||||
'Content-Disposition: form-data;name="' + name + '"\r\n' +
|
||||
'\r\n' +
|
||||
value + '\r\n' +
|
||||
'--' + multipartBoundary + '--\r\n');
|
||||
}
|
||||
|
||||
function checkBodyText(test, response, expectedBody) {
|
||||
return response.text().then( function(bodyAsText) {
|
||||
assert_equals(bodyAsText, expectedBody, "Retrieve and verify response's body");
|
||||
assert_true(response.bodyUsed, "body as text: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(response, expectedBody, checkContentType) {
|
||||
function checkBodyBlob(test, response, expectedBody, expectedType) {
|
||||
return response.blob().then(function(bodyAsBlob) {
|
||||
if (checkContentType)
|
||||
assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the response Content-Type");
|
||||
assert_equals(bodyAsBlob.type, expectedType || "text/plain", "Blob body type should be computed from the response Content-Type");
|
||||
|
||||
var promise = new Promise( function (resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
|
@ -41,14 +73,14 @@
|
|||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(response, expectedBody) {
|
||||
function checkBodyArrayBuffer(test, response, expectedBody) {
|
||||
return response.arrayBuffer().then( function(bodyAsArrayBuffer) {
|
||||
validateBufferFromString(bodyAsArrayBuffer, expectedBody, "Retrieve and verify response's body");
|
||||
assert_true(response.bodyUsed, "body as arrayBuffer: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(response, expectedBody) {
|
||||
function checkBodyJSON(test, response, expectedBody) {
|
||||
return response.json().then(function(bodyAsJSON) {
|
||||
var strBody = JSON.stringify(bodyAsJSON)
|
||||
assert_equals(strBody, expectedBody, "Retrieve and verify response's body");
|
||||
|
@ -56,75 +88,122 @@
|
|||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(response, expectedBody) {
|
||||
function checkBodyFormDataMultipart(test, response, expectedBody) {
|
||||
return response.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
var entryName = "name";
|
||||
var strBody = responseStringToMultipartFormTextData(response, entryName, bodyAsFormData.get(entryName));
|
||||
assert_equals(strBody, expectedBody, "Retrieve and verify response's body");
|
||||
assert_true(response.bodyUsed, "body as formData: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkResponseBody(body, bodyType, checkFunction) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(body, { "headers": [["Content-Type", "text/PLAIN"]] });
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
return checkFunction(response, body);
|
||||
}, "Consume response's body as " + bodyType);
|
||||
function checkBodyFormDataUrlencoded(test, response, expectedBody) {
|
||||
return response.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
var entryName = "name";
|
||||
var strBody = entryName + "=" + bodyAsFormData.get(entryName);
|
||||
assert_equals(strBody, expectedBody, "Retrieve and verify response's body");
|
||||
assert_true(response.bodyUsed, "body as formData: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("name", "value");
|
||||
var textData = JSON.stringify("This is response's body");
|
||||
var blob = new Blob([textData], { "type" : "text/plain" });
|
||||
|
||||
checkResponseBody(textData, "text", checkBodyText);
|
||||
checkResponseBody(textData, "blob", function(response, body) { checkBodyBlob(response, body, true); });
|
||||
checkResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
checkResponseBody(textData, "json", checkBodyJSON);
|
||||
checkResponseBody(formData, "formData", checkBodyFormData);
|
||||
|
||||
function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(blobBody);
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
return checkFunction(response, blobData);
|
||||
}, "Consume blob response's body as " + bodyType);
|
||||
function checkBodyFormDataError(test, response, expectedBody) {
|
||||
return promise_rejects(test, new TypeError(), response.formData()).then(function() {
|
||||
assert_true(response.bodyUsed, "body as formData: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
checkBlobResponseBody(blob, textData, "blob", checkBodyBlob);
|
||||
checkBlobResponseBody(blob, textData, "text", checkBodyText);
|
||||
checkBlobResponseBody(blob, textData, "json", checkBodyJSON);
|
||||
checkBlobResponseBody(blob, textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
|
||||
function checkReadableStreamResponseBody(streamData, bodyType, checkFunction) {
|
||||
function checkResponseBody(responsePromise, expectedBody, checkFunction, bodyTypes) {
|
||||
promise_test(function(test) {
|
||||
var stream = new ReadableStream({
|
||||
start: function(controller) {
|
||||
controller.enqueue((stringToArray(streamData)));
|
||||
controller.close();
|
||||
}
|
||||
});
|
||||
var response = new Response(stream);
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
return checkFunction(response, streamData);
|
||||
}, "Consume stream response's body as " + bodyType);
|
||||
}
|
||||
|
||||
checkReadableStreamResponseBody(textData, "blob", checkBodyBlob);
|
||||
checkReadableStreamResponseBody(textData, "text", checkBodyText);
|
||||
checkReadableStreamResponseBody(textData, "json", checkBodyJSON);
|
||||
checkReadableStreamResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
|
||||
function checkFetchedResponseBody(bodyType, checkFunction) {
|
||||
return promise_test(function(test) {
|
||||
return fetch("../resources/top.txt").then(function(response) {
|
||||
return responsePromise.then(function(response) {
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
return checkFunction(response, "top");
|
||||
return checkFunction(test, response, expectedBody);
|
||||
});
|
||||
}, "Consume fetched response's body as " + bodyType);
|
||||
}, "Consume response's body: " + bodyTypes);
|
||||
}
|
||||
checkFetchedResponseBody("blob", checkBodyBlob);
|
||||
checkFetchedResponseBody("text", checkBodyText);
|
||||
checkFetchedResponseBody("arrayBuffer", checkBodyArrayBuffer);
|
||||
|
||||
var textData = JSON.stringify("This is response's body");
|
||||
var textResponseInit = { "headers": [["Content-Type", "text/PLAIN"]] };
|
||||
var blob = new Blob([textData], { "type": "application/octet-stream" });
|
||||
var multipartBoundary = "boundary-" + Math.random();
|
||||
var formData = new FormData();
|
||||
var formTextResponseInit = { "headers": [["Content-Type", 'multipart/FORM-data; boundary="' + multipartBoundary + '"']] };
|
||||
var formTextData = stringToMultipartFormTextData(multipartBoundary, "name", textData);
|
||||
var formBlob = new Blob([formTextData]);
|
||||
var urlSearchParamsData = "name=value";
|
||||
var urlSearchParams = new URLSearchParams(urlSearchParamsData);
|
||||
var urlSearchParamsType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||
var urlSearchParamsResponseInit = { "headers": [["Content-Type", urlSearchParamsType]] };
|
||||
var urlSearchParamsBlob = new Blob([urlSearchParamsData], { "type": urlSearchParamsType });
|
||||
formData.append("name", textData);
|
||||
|
||||
checkResponseBody(responsePromise(textData, textResponseInit), textData, checkBodyText, "from text to text");
|
||||
checkResponseBody(responsePromise(textData, textResponseInit), textData, checkBodyBlob, "from text to blob");
|
||||
checkResponseBody(responsePromise(textData, textResponseInit), textData, checkBodyArrayBuffer, "from text to arrayBuffer");
|
||||
checkResponseBody(responsePromise(textData, textResponseInit), textData, checkBodyJSON, "from text to json");
|
||||
checkResponseBody(responsePromise(formTextData, formTextResponseInit), formTextData, checkBodyFormDataMultipart, "from text with correct multipart type to formData");
|
||||
checkResponseBody(responsePromise(formTextData, textResponseInit), undefined, checkBodyFormDataError, "from text without correct multipart type to formData (error case)");
|
||||
checkResponseBody(responsePromise(urlSearchParamsData, urlSearchParamsResponseInit), urlSearchParamsData, checkBodyFormDataUrlencoded, "from text with correct urlencoded type to formData");
|
||||
checkResponseBody(responsePromise(urlSearchParamsData, textResponseInit), undefined, checkBodyFormDataError, "from text without correct urlencoded type to formData (error case)");
|
||||
|
||||
checkResponseBody(responsePromise(blob, textResponseInit), textData, checkBodyBlob, "from blob to blob");
|
||||
checkResponseBody(responsePromise(blob), textData, checkBodyText, "from blob to text");
|
||||
checkResponseBody(responsePromise(blob), textData, checkBodyArrayBuffer, "from blob to arrayBuffer");
|
||||
checkResponseBody(responsePromise(blob), textData, checkBodyJSON, "from blob to json");
|
||||
checkResponseBody(responsePromise(formBlob, formTextResponseInit), formTextData, checkBodyFormDataMultipart, "from blob with correct multipart type to formData");
|
||||
checkResponseBody(responsePromise(formBlob, textResponseInit), undefined, checkBodyFormDataError, "from blob without correct multipart type to formData (error case)");
|
||||
checkResponseBody(responsePromise(urlSearchParamsBlob, urlSearchParamsResponseInit), urlSearchParamsData, checkBodyFormDataUrlencoded, "from blob with correct urlencoded type to formData");
|
||||
checkResponseBody(responsePromise(urlSearchParamsBlob, textResponseInit), undefined, checkBodyFormDataError, "from blob without correct urlencoded type to formData (error case)");
|
||||
|
||||
function checkFormDataResponseBody(responsePromise, expectedName, expectedValue, checkFunction, bodyTypes) {
|
||||
promise_test(function(test) {
|
||||
return responsePromise.then(function(response) {
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
var expectedBody = responseStringToMultipartFormTextData(response, expectedName, expectedValue);
|
||||
return Promise.resolve().then(function() {
|
||||
if (checkFunction === checkBodyFormDataMultipart)
|
||||
return expectedBody;
|
||||
// Modify expectedBody to use the same spacing for
|
||||
// Content-Disposition parameters as Response and FormData does.
|
||||
var response2 = new Response(formData);
|
||||
return response2.text().then(function(formDataAsText) {
|
||||
var reName = /[ \t]*;[ \t]*name=/;
|
||||
var nameMatches = formDataAsText.match(reName);
|
||||
return expectedBody.replace(reName, nameMatches[0]);
|
||||
});
|
||||
}).then(function(expectedBody) {
|
||||
return checkFunction(test, response, expectedBody);
|
||||
});
|
||||
});
|
||||
}, "Consume response's body: " + bodyTypes);
|
||||
}
|
||||
|
||||
checkFormDataResponseBody(responsePromise(formData), "name", textData, checkBodyFormDataMultipart, "from FormData to formData");
|
||||
checkResponseBody(responsePromise(formData, textResponseInit), undefined, checkBodyFormDataError, "from FormData without correct type to formData (error case)");
|
||||
checkFormDataResponseBody(responsePromise(formData), "name", textData, function(test, response, expectedBody) { return checkBodyBlob(test, response, expectedBody, response.headers.get('Content-Type').toLowerCase()); }, "from FormData to blob");
|
||||
checkFormDataResponseBody(responsePromise(formData), "name", textData, checkBodyText, "from FormData to text");
|
||||
checkFormDataResponseBody(responsePromise(formData), "name", textData, checkBodyArrayBuffer, "from FormData to arrayBuffer");
|
||||
|
||||
checkResponseBody(responsePromise(urlSearchParams), urlSearchParamsData, checkBodyFormDataUrlencoded, "from URLSearchParams to formData");
|
||||
checkResponseBody(responsePromise(urlSearchParams, textResponseInit), urlSearchParamsData, checkBodyFormDataError, "from URLSearchParams without correct type to formData (error case)");
|
||||
checkResponseBody(responsePromise(urlSearchParams), urlSearchParamsData, function(test, response, expectedBody) { return checkBodyBlob(test, response, expectedBody, "application/x-www-form-urlencoded;charset=utf-8"); }, "from URLSearchParams to blob");
|
||||
checkResponseBody(responsePromise(urlSearchParams), urlSearchParamsData, checkBodyText, "from URLSearchParams to text");
|
||||
checkResponseBody(responsePromise(urlSearchParams), urlSearchParamsData, checkBodyArrayBuffer, "from URLSearchParams to arrayBuffer");
|
||||
|
||||
checkResponseBody(streamResponsePromise(textData, textResponseInit), textData, checkBodyBlob, "from stream to blob");
|
||||
checkResponseBody(streamResponsePromise(textData), textData, checkBodyText, "from stream to text");
|
||||
checkResponseBody(streamResponsePromise(textData), textData, checkBodyArrayBuffer, "from stream to arrayBuffer");
|
||||
checkResponseBody(streamResponsePromise(textData), textData, checkBodyJSON, "from stream to json");
|
||||
checkResponseBody(streamResponsePromise(formTextData, formTextResponseInit), formTextData, checkBodyFormDataMultipart, "from stream with correct multipart type to formData");
|
||||
checkResponseBody(streamResponsePromise(formTextData), formTextData, checkBodyFormDataError, "from stream without correct multipart type to formData (error case)");
|
||||
checkResponseBody(streamResponsePromise(urlSearchParamsData, urlSearchParamsResponseInit), urlSearchParamsData, checkBodyFormDataUrlencoded, "from stream with correct urlencoded type to formData");
|
||||
checkResponseBody(streamResponsePromise(urlSearchParamsData), urlSearchParamsData, checkBodyFormDataError, "from stream without correct urlencoded type to formData (error case)");
|
||||
|
||||
checkResponseBody(fetch("../resources/top.txt"), "top", checkBodyBlob, "from fetch to blob");
|
||||
checkResponseBody(fetch("../resources/top.txt"), "top", checkBodyText, "from fetch to text");
|
||||
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)");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue