summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/response/response-consume-empty.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/fetch/api/response/response-consume-empty.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/fetch/api/response/response-consume-empty.html')
-rw-r--r--testing/web-platform/tests/fetch/api/response/response-consume-empty.html103
1 files changed, 103 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/api/response/response-consume-empty.html b/testing/web-platform/tests/fetch/api/response/response-consume-empty.html
new file mode 100644
index 000000000..788384699
--- /dev/null
+++ b/testing/web-platform/tests/fetch/api/response/response-consume-empty.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>