OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <title>Response consume</title> |
| 6 <meta name="help" href="https://fetch.spec.whatwg.org/#response"> |
| 7 <meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin"> |
| 8 <meta name="author" title="Canon Research France" href="https://www.crf.cano
n.fr"> |
| 9 <script src="/resources/testharness.js"></script> |
| 10 <script src="/resources/testharnessreport.js"></script> |
| 11 <script src="../resources/utils.js"></script> |
| 12 </head> |
| 13 <body> |
| 14 <script> |
| 15 |
| 16 promise_test(function(test) { |
| 17 var body = ""; |
| 18 var response = new Response(""); |
| 19 return validateStreamFromString(response.body.getReader(), ""); |
| 20 }, "Read empty text response's body as readableStream"); |
| 21 |
| 22 promise_test(function(test) { |
| 23 var response = new Response(new Blob([], { "type" : "text/plain" })); |
| 24 return validateStreamFromString(response.body.getReader(), ""); |
| 25 }, "Read empty blob response's body as readableStream"); |
| 26 |
| 27 var formData = new FormData(); |
| 28 formData.append("name", "value"); |
| 29 var textData = JSON.stringify("This is response's body"); |
| 30 var blob = new Blob([textData], { "type" : "text/plain" }); |
| 31 var urlSearchParamsData = "name=value"; |
| 32 var urlSearchParams = new URLSearchParams(urlSearchParamsData); |
| 33 |
| 34 promise_test(function(test) { |
| 35 var response = new Response(blob); |
| 36 return validateStreamFromString(response.body.getReader(), textData); |
| 37 }, "Read blob response's body as readableStream"); |
| 38 |
| 39 promise_test(function(test) { |
| 40 var response = new Response(textData); |
| 41 return validateStreamFromString(response.body.getReader(), textData); |
| 42 }, "Read text response's body as readableStream"); |
| 43 |
| 44 promise_test(function(test) { |
| 45 var response = new Response(urlSearchParams); |
| 46 return validateStreamFromString(response.body.getReader(), urlSearchParamsDa
ta); |
| 47 }, "Read URLSearchParams response's body as readableStream"); |
| 48 |
| 49 promise_test(function(test) { |
| 50 var arrayBuffer = new ArrayBuffer(textData.length); |
| 51 var int8Array = new Int8Array(arrayBuffer); |
| 52 for (var cptr = 0; cptr < textData.length; cptr++) |
| 53 int8Array[cptr] = textData.charCodeAt(cptr); |
| 54 |
| 55 return validateStreamFromString(new Response(arrayBuffer).body.getReader(),
textData); |
| 56 }, "Read array buffer response's body as readableStream"); |
| 57 |
| 58 promise_test(function(test) { |
| 59 var response = new Response(formData); |
| 60 return validateStreamFromString(response.body.getReader(), "name=value"); |
| 61 }, "Read form data response's body as readableStream"); |
| 62 |
| 63 test(function() { |
| 64 assert_equals(Response.error().body, null); |
| 65 }, "Getting an error Response stream"); |
| 66 |
| 67 promise_test(function(test) { |
| 68 assert_equals(Response.redirect(301).body, null); |
| 69 }, "Getting a redirect Response stream"); |
| 70 |
| 71 </script> |
| 72 </body> |
| 73 </html> |
OLD | NEW |