response-stream-disturbed-3.any.js (1647B)
1 // META: global=window,worker 2 // META: title=Consuming Response body after getting a ReadableStream 3 // META: script=./response-stream-disturbed-util.js 4 5 async function createResponseWithDisturbedReadableStream(bodySource, callback) { 6 const response = await responseFromBodySource(bodySource); 7 const reader = response.body.getReader(); 8 reader.read(); 9 return callback(response); 10 } 11 12 for (const bodySource of ["fetch", "stream", "string"]) { 13 promise_test(function(test) { 14 return createResponseWithDisturbedReadableStream(bodySource, function(response) { 15 return promise_rejects_js(test, TypeError, response.blob()); 16 }); 17 }, `Getting blob after reading the Response body (body source: ${bodySource})`); 18 19 promise_test(function(test) { 20 return createResponseWithDisturbedReadableStream(bodySource, function(response) { 21 return promise_rejects_js(test, TypeError, response.text()); 22 }); 23 }, `Getting text after reading the Response body (body source: ${bodySource})`); 24 25 promise_test(function(test) { 26 return createResponseWithDisturbedReadableStream(bodySource, function(response) { 27 return promise_rejects_js(test, TypeError, response.json()); 28 }); 29 }, `Getting json after reading the Response body (body source: ${bodySource})`); 30 31 promise_test(function(test) { 32 return createResponseWithDisturbedReadableStream(bodySource, function(response) { 33 return promise_rejects_js(test, TypeError, response.arrayBuffer()); 34 }); 35 }, `Getting arrayBuffer after reading the Response body (body source: ${bodySource})`); 36 }