cross-origin-status-codes.html (2281B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Resource Timing: PerformanceResourceTiming attributes shouldn't change 5 if the HTTP status code changes</title> 6 <link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming"/> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src=/common/get-host-info.sub.js></script> 10 </head> 11 <body> 12 <img id="img_200"> 13 <img id="img_307"> 14 <img id="img_404"> 15 <img id="img_502"> 16 <script id="script_200"></script> 17 <script id="script_307"></script> 18 <script id="script_404"></script> 19 <script id="script_502"></script> 20 <script> 21 22 const listenForPerformanceEntries = num_expected => { 23 return new Promise(resolve => { 24 let results = []; 25 new PerformanceObserver(entryList => { 26 entryList.getEntries().forEach(entry => { 27 if (!entry.name.includes("status-code")) 28 return; 29 30 results.push(entry); 31 if (results.length == num_expected) { 32 resolve(results); 33 } 34 }); 35 }).observe({entryTypes: ['resource']}); 36 }); 37 } 38 39 promise_test(async t => { 40 const destUrl = get_host_info().HTTP_REMOTE_ORIGIN + '/resource-timing/resources/'; 41 const statusCodes = ['200', '307', '404', '502']; 42 43 let expected_entry_count = 0; 44 statusCodes.forEach(status => { 45 document.getElementById(`img_${status}`).src = `${destUrl}status-code.py?status=${status}`; 46 document.getElementById(`script_${status}`).src = `${destUrl}status-code.py?status=${status}&script=1`; 47 expected_entry_count += 2; 48 }); 49 50 const entries = await listenForPerformanceEntries(expected_entry_count); 51 52 // We will check that the non-timestamp values of the entry match for all 53 // entries. 54 const keys = [ 55 'entryType', 56 'nextHopProtocol', 57 'transferSize', 58 'encodedBodySize', 59 'decodedBodySize', 60 ]; 61 62 const first = entries[0]; 63 entries.slice(1).forEach(entry => { 64 keys.forEach(attribute => { 65 assert_equals(entry[attribute], first[attribute], 66 `There must be no discernible difference for the ${attribute} ` + 67 `attribute but found a difference for the ${entry.name} resource.`); 68 })}); 69 }, "Make sure cross origin resource fetch failures with different status codes are indistinguishable"); 70 </script>