mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Update web-platform-tests to revision 66c4613f823c4384c78ada77346eda17bb128947
This commit is contained in:
parent
183772583f
commit
a91433f0c8
234 changed files with 4368 additions and 967 deletions
|
@ -11,8 +11,6 @@ function streamBody(reader, test, count) {
|
|||
} else {
|
||||
test.step(function() {
|
||||
assert_true(count >= 2, "Retrieve body progressively");
|
||||
test.done();
|
||||
return;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -20,16 +18,14 @@ function streamBody(reader, test, count) {
|
|||
|
||||
//simulate streaming:
|
||||
//count is large enough to let the UA deliver the body before it is completely retrieved
|
||||
async_test(function(test) {
|
||||
fetch(RESOURCES_DIR + "trickle.py?ms=30&count=100").then(function(resp) {
|
||||
promise_test(function(test) {
|
||||
return fetch(RESOURCES_DIR + "trickle.py?ms=30&count=100").then(function(resp) {
|
||||
var count = 0;
|
||||
if (resp.body)
|
||||
return streamBody(resp.body.getReader(), test, count);
|
||||
else
|
||||
test.step(function() {
|
||||
assert_unreached( "Body does not exist in response");
|
||||
test.done();
|
||||
return;
|
||||
});
|
||||
});
|
||||
}, "Stream response's body");
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
var parameters = [null, 1];
|
||||
parameters.forEach(function(parameter) {
|
||||
test(function() {
|
||||
assert_throws(new TypeError(), () => new Headers(parameter));
|
||||
assert_throws(new TypeError(), function() { new Headers(parameter) });
|
||||
}, "Create headers with " + parameter + " should throw");
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Request consume empty bodies</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function checkBodyText(request) {
|
||||
return request.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "", "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(request) {
|
||||
return request.blob().then(function(bodyAsBlob) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, "", "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(request) {
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(request) {
|
||||
return request.json().then(
|
||||
function(bodyAsJSON) {
|
||||
assert_unreached("JSON parsing should fail");
|
||||
},
|
||||
function() {
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(request) {
|
||||
return request.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_false(request.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkRequestWithNoBody(bodyType, checkFunction) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST"});
|
||||
assert_false(request.bodyUsed);
|
||||
return checkFunction(request);
|
||||
}, "Consume request's body as " + bodyType);
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
checkRequestWithNoBody("text", checkBodyText);
|
||||
checkRequestWithNoBody("blob", checkBodyBlob);
|
||||
checkRequestWithNoBody("arrayBuffer", checkBodyArrayBuffer);
|
||||
checkRequestWithNoBody("json", checkBodyJSON);
|
||||
checkRequestWithNoBody("formData", checkBodyFormData);
|
||||
|
||||
function checkRequestWithEmptyBody(bodyType, body, asText) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body});
|
||||
assert_false(request.bodyUsed, "bodyUsed is false at init");
|
||||
if (asText) {
|
||||
return request.text().then(function(bodyAsString) {
|
||||
assert_equals(bodyAsString.length, 0, "Resolved value should be empty");
|
||||
assert_true(request.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_true(request.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}, "Consume empty " + bodyType + " request body as " + (asText ? "text" : "arrayBuffer"));
|
||||
}
|
||||
|
||||
// FIXME: Add BufferSource, FormData and URLSearchParams.
|
||||
checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), false);
|
||||
checkRequestWithEmptyBody("text", "", false);
|
||||
checkRequestWithEmptyBody("blob", new Blob([], { "type" : "text/plain" }), true);
|
||||
checkRequestWithEmptyBody("text", "", true);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -8,6 +8,7 @@
|
|||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
@ -37,19 +38,9 @@
|
|||
});
|
||||
}
|
||||
|
||||
<!-- Taken from https://developers.google.com -->
|
||||
function str2ab(str) {
|
||||
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
|
||||
var bufView = new Uint16Array(buf);
|
||||
for (var i=0, strLen=str.length; i < strLen; i++) {
|
||||
bufView[i] = str.charCodeAt(i);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(request, expectedBody) {
|
||||
return request.arrayBuffer().then( function(bodyAsArrayBuffer) {
|
||||
assert_array_equals(bodyAsArrayBuffer, str2ab(expectedBody), "Retrieve and verify request's body");
|
||||
return request.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
validateBufferFromString(bodyAsArrayBuffer, expectedBody, "Retrieve and verify request's body");
|
||||
assert_true(request.bodyUsed, "body as arrayBuffer: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
@ -79,12 +70,28 @@
|
|||
|
||||
var formData = new FormData();
|
||||
formData.append("name", "value")
|
||||
checkRequestBody("This is request's body", "text", checkBodyText);
|
||||
checkRequestBody("This is request's body", "blob", checkBodyBlob);
|
||||
checkRequestBody("This is request's body", "arrayBuffer", checkBodyArrayBuffer);
|
||||
checkRequestBody(JSON.stringify("This is request's body"), "json", checkBodyJSON);
|
||||
var textData = JSON.stringify("This is response's body");
|
||||
var blob = new Blob([textData], { "type" : "text/plain" });
|
||||
|
||||
checkRequestBody(textData, "text", checkBodyText);
|
||||
checkRequestBody(textData, "blob", checkBodyBlob);
|
||||
checkRequestBody(textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
checkRequestBody(textData, "json", checkBodyJSON);
|
||||
checkRequestBody(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);
|
||||
}
|
||||
|
||||
checkBlobResponseBody(blob, textData, "blob", checkBodyBlob);
|
||||
checkBlobResponseBody(blob, textData, "text", checkBodyText);
|
||||
checkBlobResponseBody(blob, textData, "json", checkBodyJSON);
|
||||
checkBlobResponseBody(blob, textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
|
||||
var goodJSONValues = ["null", "1", "true", "\"string\""];
|
||||
goodJSONValues.forEach(function(value) {
|
||||
promise_test(function(test) {
|
||||
|
|
|
@ -23,18 +23,23 @@
|
|||
}
|
||||
}, "Initialize Request with headers values");
|
||||
|
||||
function makeRequestInit(body, method) {
|
||||
return {"method": method, "body": body};
|
||||
}
|
||||
|
||||
function checkRequestInit(body, bodyType, expectedTextBody) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body});
|
||||
assert_throws(new TypeError(),
|
||||
function() { new Request("", {"method": "GET", "body": body}); }
|
||||
);
|
||||
assert_throws(new TypeError(),
|
||||
function() { new Request("", {"method": "HEAD", "body": body}); }
|
||||
);
|
||||
var request = new Request("", makeRequestInit(body, "POST"));
|
||||
if (body) {
|
||||
assert_throws(new TypeError(),
|
||||
function() { new Request("", makeRequestInit(body, "GET")); }
|
||||
);
|
||||
} else {
|
||||
new Request("", makeRequestInit(body, "GET")); // should not throw
|
||||
}
|
||||
var reqHeaders = request.headers;
|
||||
var mime = reqHeaders.get("Content-Type");
|
||||
assert_true(mime && mime.search(bodyType) > -1, "Content-Type header should be \"" + bodyType + "\", not \"" + mime + "\"");
|
||||
assert_true(!body || (mime && mime.search(bodyType) > -1), "Content-Type header should be \"" + bodyType + "\", not \"" + mime + "\"");
|
||||
return request.text().then(function(bodyAsText) {
|
||||
//not equals: cannot guess formData exact value
|
||||
assert_true( bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify request body");
|
||||
|
@ -47,6 +52,8 @@
|
|||
formaData.append("name", "value");
|
||||
var usvString = "This is a USVString"
|
||||
|
||||
checkRequestInit(undefined, undefined, "");
|
||||
checkRequestInit(null, null, "");
|
||||
checkRequestInit(blob, "application/octet-binary", "This is a blob");
|
||||
checkRequestInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
|
||||
checkRequestInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
|
||||
|
|
|
@ -44,25 +44,31 @@ function checkRequest(request, ExpectedValuesDict) {
|
|||
}
|
||||
}
|
||||
|
||||
//check reader's text content in an asyncronous test
|
||||
function readTextStream(reader, asyncTest, expectedValue, retrievedText) {
|
||||
if (!retrievedText)
|
||||
retrievedText = "";
|
||||
reader.read().then(function(data) {
|
||||
function stringToArray(str) {
|
||||
var array = new Uint8Array(str.length);
|
||||
for (var i=0, strLen = str.length; i < strLen; i++)
|
||||
array[i] = str.charCodeAt(i);
|
||||
return array;
|
||||
}
|
||||
|
||||
function validateBufferFromString(buffer, expectedValue, message)
|
||||
{
|
||||
return assert_array_equals(new Uint8Array(buffer), stringToArray(expectedValue), message);
|
||||
}
|
||||
|
||||
function validateStreamFromString(reader, expectedValue, retrievedArrayBuffer) {
|
||||
return reader.read().then(function(data) {
|
||||
if (!data.done) {
|
||||
var decoder = new TextDecoder();
|
||||
retrievedText += decoder.decode(data.value);
|
||||
readTextStream(reader, asyncTest, expectedValue, retrievedText);
|
||||
return;
|
||||
var newBuffer;
|
||||
if (retrievedArrayBuffer) {
|
||||
newBuffer = new ArrayBuffer(data.value.length + retrievedArrayBuffer.length);
|
||||
newBuffer.set(retrievedArrayBuffer, 0);
|
||||
newBuffer.set(data.value, retrievedArrayBuffer.length);
|
||||
} else {
|
||||
newBuffer = data.value;
|
||||
}
|
||||
return validateStreamFromString(reader, expectedValue, newBuffer);
|
||||
}
|
||||
asyncTest.step(function() {
|
||||
assert_equals(retrievedText, expectedValue, "Retrieve and verify stream");
|
||||
asyncTest.done();
|
||||
});
|
||||
}).catch(function(e) {
|
||||
asyncTest.step(function() {
|
||||
assert_unreached("Cannot read stream " + e);
|
||||
asyncTest.done();
|
||||
});
|
||||
validateBufferFromString(retrievedArrayBuffer, expectedValue, "Retrieve and verify stream");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -45,12 +45,12 @@
|
|||
"Expect response.headers has name:value header");
|
||||
}, "Check Response's clone has the expected attribute values");
|
||||
|
||||
async_test(function(test) {
|
||||
readTextStream(response.body.getReader(), test, body);
|
||||
promise_test(function(test) {
|
||||
return validateStreamFromString(response.body.getReader(), body);
|
||||
}, "Check orginal response's body after cloning");
|
||||
|
||||
async_test(function(test) {
|
||||
readTextStream(clonedResponse.body.getReader(), test, body);
|
||||
promise_test(function(test) {
|
||||
return validateStreamFromString(clonedResponse.body.getReader(), body);
|
||||
}, "Check cloned response's body");
|
||||
|
||||
promise_test(function(test) {
|
||||
|
@ -63,4 +63,4 @@
|
|||
}, "Cannot clone a disturbed response");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Response consume empty bodies</title>
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
|
||||
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
||||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function checkBodyText(response) {
|
||||
return response.text().then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "", "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyBlob(response) {
|
||||
return response.blob().then(function(bodyAsBlob) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject("Blob's reader failed");
|
||||
};
|
||||
reader.readAsText(bodyAsBlob);
|
||||
});
|
||||
return promise.then(function(body) {
|
||||
assert_equals(body, "", "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyArrayBuffer(response) {
|
||||
return response.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJSON(response) {
|
||||
return response.json().then(
|
||||
function(bodyAsJSON) {
|
||||
assert_unreached("JSON parsing should fail");
|
||||
},
|
||||
function() {
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyFormData(response) {
|
||||
return response.formData().then(function(bodyAsFormData) {
|
||||
assert_true(bodyAsFormData instanceof FormData, "Should receive a FormData");
|
||||
assert_false(response.bodyUsed);
|
||||
});
|
||||
}
|
||||
|
||||
function checkResponseWithNoBody(bodyType, checkFunction) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response();
|
||||
assert_false(response.bodyUsed);
|
||||
return checkFunction(response);
|
||||
}, "Consume response's body as " + bodyType);
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
checkResponseWithNoBody("text", checkBodyText);
|
||||
checkResponseWithNoBody("blob", checkBodyBlob);
|
||||
checkResponseWithNoBody("arrayBuffer", checkBodyArrayBuffer);
|
||||
checkResponseWithNoBody("json", checkBodyJSON);
|
||||
checkResponseWithNoBody("formData", checkBodyFormData);
|
||||
|
||||
function checkResponseWithEmptyBody(bodyType, body, asText) {
|
||||
promise_test(function(test) {
|
||||
var response = new Response(body);
|
||||
assert_false(response.bodyUsed, "bodyUsed is false at init");
|
||||
if (asText) {
|
||||
return response.text().then(function(bodyAsString) {
|
||||
assert_equals(bodyAsString.length, 0, "Resolved value should be empty");
|
||||
assert_true(response.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}
|
||||
return response.arrayBuffer().then(function(bodyAsArrayBuffer) {
|
||||
assert_equals(bodyAsArrayBuffer.byteLength, 0, "Resolved value should be empty");
|
||||
assert_true(response.bodyUsed, "bodyUsed is true after being consumed");
|
||||
});
|
||||
}, "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);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -8,6 +8,7 @@
|
|||
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
@ -39,16 +40,14 @@
|
|||
|
||||
function checkBodyArrayBuffer(response, expectedBody) {
|
||||
return response.arrayBuffer().then( function(bodyAsArrayBuffer) {
|
||||
var decoder = new TextDecoder("utf-8");
|
||||
var strBody = decoder.decode(bodyAsArrayBuffer);
|
||||
assert_equals(strBody, expectedBody, "Retrieve and verify response's body");
|
||||
validateBufferFromString(bodyAsArrayBuffer, expectedBody, "Retrieve and verify response's body");
|
||||
assert_true(response.bodyUsed, "body as arrayBuffer: bodyUsed turned true");
|
||||
});
|
||||
}
|
||||
|
||||
function checkBodyJson(response, expectedBody) {
|
||||
return response.json().then(function(bodyAsJson) {
|
||||
var strBody = JSON.stringify(bodyAsJson)
|
||||
function checkBodyJSON(response, expectedBody) {
|
||||
return response.json().then(function(bodyAsJSON) {
|
||||
var strBody = JSON.stringify(bodyAsJSON)
|
||||
assert_equals(strBody, expectedBody, "Retrieve and verify response's body");
|
||||
assert_true(response.bodyUsed, "body as json: bodyUsed turned true");
|
||||
});
|
||||
|
@ -70,12 +69,29 @@
|
|||
}
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("name", "value")
|
||||
checkResponseBody("This is response's body", "text", checkBodyText);
|
||||
checkResponseBody("This is response's body", "blob", checkBodyBlob);
|
||||
checkResponseBody("This is response's body", "arrayBuffer", checkBodyArrayBuffer);
|
||||
checkResponseBody(JSON.stringify("This is response's body"), "json", checkBodyJson);
|
||||
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", checkBodyBlob);
|
||||
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);
|
||||
}
|
||||
|
||||
checkBlobResponseBody(blob, textData, "blob", checkBodyBlob);
|
||||
checkBlobResponseBody(blob, textData, "text", checkBodyText);
|
||||
checkBlobResponseBody(blob, textData, "json", checkBodyJSON);
|
||||
checkBlobResponseBody(blob, textData, "arrayBuffer", checkBodyArrayBuffer);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -52,10 +52,10 @@
|
|||
checkResponseInit(urlSearchParams, "application/x-www-form-urlencoded;charset=UTF-8", "name=value");
|
||||
checkResponseInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
|
||||
|
||||
async_test(function(test) {
|
||||
promise_test(function(test) {
|
||||
var body = "This is response body";
|
||||
var response = new Response(body);
|
||||
readTextStream(response.body.getReader(), test, body);
|
||||
return validateStreamFromString(response.body.getReader(), body);
|
||||
}, "Read Response's body as readableStream");
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue