fetch-event-respond-with-response-body-with-invalid-chunk.https.html (1837B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>respondWith with response body having invalid chunks</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <script> 8 'use strict'; 9 10 const WORKER = 11 'resources/fetch-event-respond-with-response-body-with-invalid-chunk-worker.js'; 12 const SCOPE = 13 'resources/fetch-event-respond-with-response-body-with-invalid-chunk-iframe.html'; 14 15 // Called by the iframe when it has the reader promise we should watch. 16 var set_reader_promise; 17 let reader_promise = new Promise(resolve => set_reader_promise = resolve); 18 19 var set_fetch_promise; 20 let fetch_promise = new Promise(resolve => set_fetch_promise = resolve); 21 22 // This test creates an controlled iframe that makes a fetch request. The 23 // service worker returns a response with a body stream containing an invalid 24 // chunk. 25 promise_test(async t => { 26 // Start off the process. 27 let errorConstructor; 28 await service_worker_unregister_and_register(t, WORKER, SCOPE) 29 .then(reg => { 30 add_completion_callback(() => reg.unregister()); 31 return wait_for_state(t, reg.installing, 'activated'); 32 }) 33 .then(() => with_iframe(SCOPE)) 34 .then(frame => { 35 t.add_cleanup(() => frame.remove()) 36 errorConstructor = frame.contentWindow.TypeError; 37 }); 38 39 await promise_rejects_js(t, errorConstructor, reader_promise, 40 "read() should be rejected"); 41 // Fetch should complete properly, because the reader error is caught in 42 // the subframe. That is, there should be no errors _other_ than the 43 // reader! 44 return fetch_promise; 45 }, 'Response with a ReadableStream having non-Uint8Array chunks should be transferred as errored'); 46 </script>