|
Lines 19-26
a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html_sec1
|
| 19 |
}); |
19 |
}); |
| 20 |
} |
20 |
} |
| 21 |
|
21 |
|
| 22 |
function checkBodyBlob(response, expectedBody) { |
22 |
function checkBodyBlob(response, expectedBody, checkContentType) { |
| 23 |
return response.blob().then(function(bodyAsBlob) { |
23 |
return response.blob().then(function(bodyAsBlob) { |
|
|
24 |
if (checkContentType) |
| 25 |
assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the response Content-Type"); |
| 26 |
|
| 24 |
var promise = new Promise( function (resolve, reject) { |
27 |
var promise = new Promise( function (resolve, reject) { |
| 25 |
var reader = new FileReader(); |
28 |
var reader = new FileReader(); |
| 26 |
reader.onload = function(evt) { |
29 |
reader.onload = function(evt) { |
|
Lines 62-68
a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html_sec2
|
| 62 |
|
65 |
|
| 63 |
function checkResponseBody(body, bodyType, checkFunction) { |
66 |
function checkResponseBody(body, bodyType, checkFunction) { |
| 64 |
promise_test(function(test) { |
67 |
promise_test(function(test) { |
| 65 |
var response = new Response(body); |
68 |
var response = new Response(body, { "headers": [["Content-Type", "text/PLAIN"]] }); |
| 66 |
assert_false(response.bodyUsed, "bodyUsed is false at init"); |
69 |
assert_false(response.bodyUsed, "bodyUsed is false at init"); |
| 67 |
return checkFunction(response, body); |
70 |
return checkFunction(response, body); |
| 68 |
}, "Consume response's body as " + bodyType); |
71 |
}, "Consume response's body as " + bodyType); |
|
Lines 74-80
a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html_sec3
|
| 74 |
var blob = new Blob([textData], { "type" : "text/plain" }); |
77 |
var blob = new Blob([textData], { "type" : "text/plain" }); |
| 75 |
|
78 |
|
| 76 |
checkResponseBody(textData, "text", checkBodyText); |
79 |
checkResponseBody(textData, "text", checkBodyText); |
| 77 |
checkResponseBody(textData, "blob", checkBodyBlob); |
80 |
checkResponseBody(textData, "blob", function(response, body) { checkBodyBlob(response, body, true); }); |
| 78 |
checkResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer); |
81 |
checkResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer); |
| 79 |
checkResponseBody(textData, "json", checkBodyJSON); |
82 |
checkResponseBody(textData, "json", checkBodyJSON); |
| 80 |
checkResponseBody(formData, "formData", checkBodyFormData); |
83 |
checkResponseBody(formData, "formData", checkBodyFormData); |
|
Lines 111-116
a/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume.html_sec4
|
| 111 |
checkReadableStreamResponseBody(textData, "json", checkBodyJSON); |
114 |
checkReadableStreamResponseBody(textData, "json", checkBodyJSON); |
| 112 |
checkReadableStreamResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer); |
115 |
checkReadableStreamResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer); |
| 113 |
|
116 |
|
|
|
117 |
function checkFetchedResponseBody(bodyType, checkFunction) { |
| 118 |
return promise_test(function(test) { |
| 119 |
return fetch("../resources/top.txt").then(function(response) { |
| 120 |
assert_false(response.bodyUsed, "bodyUsed is false at init"); |
| 121 |
return checkFunction(response, "top"); |
| 122 |
}); |
| 123 |
}, "Consume fetched response's body as " + bodyType); |
| 124 |
} |
| 125 |
checkFetchedResponseBody("blob", checkBodyBlob); |
| 126 |
checkFetchedResponseBody("text", checkBodyText); |
| 127 |
checkFetchedResponseBody("arrayBuffer", checkBodyArrayBuffer); |
| 128 |
|
| 114 |
</script> |
129 |
</script> |
| 115 |
</body> |
130 |
</body> |
| 116 |
</html> |
131 |
</html> |