304-response-recorded.html (1842B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>Resource Timing - cached resources generate performance entries</title> 6 <link rel="author" title="Google" href="http://www.google.com/" /> 7 <link rel="help" 8 href="https://www.w3.org/TR/resource-timing-2/#resources-included-in-the-performanceresourcetiming-interface"/> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="resources/entry-invariants.js"></script> 12 <script src="resources/resource-loaders.js"></script> 13 </head> 14 <body> 15 <h1>Description</h1> 16 <p>This test validates that a 304 Not Modified resource appears in the 17 Performance Timeline.</p> 18 <script> 19 // Need to fetch the same resource twice; the first will get a 200 response but 20 // the second request should be cached and get a 304. 21 promise_test(async () => { 22 performance.clearResourceTimings(); 23 24 const unique = Math.random(); 25 const path = `resources/fake_responses.py?tag=${unique}`; 26 27 await load.xhr_sync(path); 28 await load.xhr_sync(path, {"If-None-Match": `${unique}`}); 29 const entries = await new Promise(resolve => { 30 const accumulator = []; 31 new PerformanceObserver(entry_list => { 32 entry_list.getEntries().forEach(entry => { 33 accumulator.push(entry); 34 }); 35 if (accumulator.length >= 2) { 36 resolve(accumulator); 37 } 38 }).observe({'type': 'resource', 'buffered': true}); 39 }); 40 41 42 if (entries.length != 2) { 43 throw new Error(`Expecting 2 but got ${entries.length} entries`); 44 } 45 46 assert_equals(entries[0].name, entries[1].name, 47 "Both entries should have the same name"); 48 invariants.assert_tao_pass_no_redirect_http(entries[0]); 49 invariants.assert_tao_pass_304_not_modified_http(entries[1]); 50 }, "304 responses should still show up in the PerformanceTimeline"); 51 </script> 52 </body> 53 </html>