response-stream-disturbed-4.any.js (1622B)
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 createResponseWithCancelledReadableStream(bodySource, callback) { 6 const response = await responseFromBodySource(bodySource); 7 response.body.cancel(); 8 return callback(response); 9 } 10 11 for (const bodySource of ["fetch", "stream", "string"]) { 12 promise_test(function(test) { 13 return createResponseWithCancelledReadableStream(bodySource, function(response) { 14 return promise_rejects_js(test, TypeError, response.blob()); 15 }); 16 }, `Getting blob after cancelling the Response body (body source: ${bodySource})`); 17 18 promise_test(function(test) { 19 return createResponseWithCancelledReadableStream(bodySource, function(response) { 20 return promise_rejects_js(test, TypeError, response.text()); 21 }); 22 }, `Getting text after cancelling the Response body (body source: ${bodySource})`); 23 24 promise_test(function(test) { 25 return createResponseWithCancelledReadableStream(bodySource, function(response) { 26 return promise_rejects_js(test, TypeError, response.json()); 27 }); 28 }, `Getting json after cancelling the Response body (body source: ${bodySource})`); 29 30 promise_test(function(test) { 31 return createResponseWithCancelledReadableStream(bodySource, function(response) { 32 return promise_rejects_js(test, TypeError, response.arrayBuffer()); 33 }); 34 }, `Getting arrayBuffer after cancelling the Response body (body source: ${bodySource})`); 35 }