| <!doctype html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>Consuming Request body after getting a ReadableStream</title> |
| <meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <script> |
| function createRequestWithReadableStream(callback) { |
| var request = new Request("", {body: "{\"key\": \"value\"}", method: "POST"}); |
| var reader = request.body.getReader(); |
| reader.releaseLock(); |
| return callback(request); |
| } |
| |
| promise_test(function() { |
| return createRequestWithReadableStream(function(request) { |
| return request.blob().then(function(blob) { |
| assert_true(blob instanceof Blob); |
| }); |
| }); |
| }, "Getting blob after getting the Request body - not disturbed, not locked"); |
| |
| promise_test(function() { |
| return createRequestWithReadableStream(function(request) { |
| return request.text().then(function(text) { |
| assert_true(text.length > 0); |
| }); |
| }); |
| }, "Getting text after getting the Request body - not disturbed, not locked"); |
| |
| promise_test(function() { |
| return createRequestWithReadableStream(function(request) { |
| return request.json().then(function(json) { |
| assert_true(typeof json === "object"); |
| }); |
| }); |
| }, "Getting json after getting the Request body - not disturbed, not locked"); |
| |
| promise_test(function() { |
| return createRequestWithReadableStream(function(request) { |
| return request.arrayBuffer().then(function(arrayBuffer) { |
| assert_true(arrayBuffer.byteLength > 0); |
| }); |
| }); |
| }, "Getting arrayBuffer after getting the Request body - not disturbed, not locked"); |
| |
| </script> |
| </body> |
| </html> |