response-stream-disturbed-1.any.js (1922B)
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 createResponseWithReadableStream(bodySource, callback) { 6 const response = await responseFromBodySource(bodySource); 7 const reader = response.body.getReader(); 8 reader.releaseLock(); 9 return callback(response); 10 } 11 12 for (const bodySource of ["fetch", "stream", "string"]) { 13 promise_test(function() { 14 return createResponseWithReadableStream(bodySource, function(response) { 15 return response.blob().then(function(blob) { 16 assert_true(blob instanceof Blob); 17 }); 18 }); 19 }, `Getting blob after getting the Response body - not disturbed, not locked (body source: ${bodySource})`); 20 21 promise_test(function() { 22 return createResponseWithReadableStream(bodySource, function(response) { 23 return response.text().then(function(text) { 24 assert_true(text.length > 0); 25 }); 26 }); 27 }, `Getting text after getting the Response body - not disturbed, not locked (body source: ${bodySource})`); 28 29 promise_test(function() { 30 return createResponseWithReadableStream(bodySource, function(response) { 31 return response.json().then(function(json) { 32 assert_equals(typeof json, "object"); 33 }); 34 }); 35 }, `Getting json after getting the Response body - not disturbed, not locked (body source: ${bodySource})`); 36 37 promise_test(function() { 38 return createResponseWithReadableStream(bodySource, function(response) { 39 return response.arrayBuffer().then(function(arrayBuffer) { 40 assert_true(arrayBuffer.byteLength > 0); 41 }); 42 }); 43 }, `Getting arrayBuffer after getting the Response body - not disturbed, not locked (body source: ${bodySource})`); 44 }