resource-timing-bodySize.https.html (2508B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <meta name="timeout" content="long"> 4 <script src="/common/utils.js"></script> 5 <script src="/common/get-host-info.sub.js"></script> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="resources/test-helpers.sub.js"></script> 9 <script> 10 const {REMOTE_ORIGIN} = get_host_info(); 11 12 /* 13 This test does the following: 14 - Loads a service worker 15 - Loads an iframe in the service worker's scope 16 - The service worker tries to fetch a resource which is either: 17 - constructed inside the service worker 18 - fetched from a different URL ny the service worker 19 - Streamed from a differend URL by the service worker 20 - Passes through 21 - By default the RT entry should have encoded/decoded body size. except for 22 the case where the response is an opaque pass-through. 23 */ 24 function test_scenario({tao, mode, name}) { 25 promise_test(async (t) => { 26 const uid = token(); 27 const worker_url = `resources/fetch-response.js?uid=${uid}`; 28 const scope = `resources/fetch-response.html?uid=${uid}`; 29 const iframe = document.createElement('iframe'); 30 const path = name === "passthrough" ? `element-timing/resources/TAOImage.py?origin=*&tao=${ 31 tao === "pass" ? "wildcard" : "none"})}` : name; 32 33 iframe.src = `${scope}&path=${encodeURIComponent( 34 `${mode === "same-origin" ? "" : REMOTE_ORIGIN}/${path}`)}&mode=${mode}`; 35 const registration = await service_worker_unregister_and_register(t, worker_url, scope); 36 t.add_cleanup(() => registration.unregister()); 37 t.add_cleanup(() => iframe.remove()); 38 await wait_for_state(t, registration.installing, 'activated'); 39 const waitForMessage = new Promise(resolve => 40 window.addEventListener('message', ({data}) => resolve(data))); 41 document.body.appendChild(iframe); 42 const {buffer, entry} = await waitForMessage; 43 const expectPass = name !== "passthrough" || mode !== "no-cors"; 44 assert_equals(buffer.byteLength, expectPass ? entry.decodedBodySize : 0); 45 assert_equals(buffer.byteLength, expectPass ? entry.encodedBodySize : 0); 46 }, `Response body size: ${name}, ${mode}, TAO ${tao}`); 47 } 48 for (const mode of ["cors", "no-cors", "same-origin"]) { 49 for (const tao of ["pass", "fail"]) 50 for (const name of ['constructed', 'forward', 'stream', 'passthrough']) { 51 test_scenario({tao, mode, name}); 52 } 53 } 54 55 </script>