interim-response-times.html (2732B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <meta name="timeout" content="long"> 6 <title>Resource Timing: PerformanceResourceTiming interim resource times</title> 7 <link rel="author" title="Google" href="http://www.google.com/" /> 8 <script src="/common/utils.js"></script> 9 <script src="/common/get-host-info.sub.js"></script> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <script> 13 const {REMOTE_ORIGIN} = get_host_info(); 14 function interim_response_time_test({origin, with100, with103}) { 15 promise_test(async t => { 16 const delay = 500; 17 const url = new URL('/resource-timing/resources/header-delay.py', 18 origin == "same-origin" ? location.href : REMOTE_ORIGIN); 19 url.searchParams.set("delay", delay); 20 if (origin === "cross-origin-with-TAO") 21 url.searchParams.set("tao", "*"); 22 if (with100) 23 url.searchParams.set("with100", "true"); 24 if (with103) 25 url.searchParams.set("with103", "true"); 26 const response = await fetch(url.toString(), {mode: "cors"}); 27 assert_equals(response.status, 200) 28 await response.text(); 29 const [entry] = performance.getEntriesByName(url.toString()); 30 if (origin === "cross-origin") { 31 assert_equals(entry.firstInterimResponseStart, 0); 32 return; 33 } 34 let total_delay = entry.requestStart; 35 if (with100) { 36 total_delay += delay; 37 assert_greater_than(entry.firstInterimResponseStart, 38 total_delay, 39 "firstInterimResponseStart > 100 response"); 40 } 41 42 if (with103) { 43 total_delay += delay; 44 if (with100) { 45 assert_less_than_equal(entry.firstInterimResponseStart, 46 total_delay, "firstInterimResponseStart > 100 response"); 47 } else { 48 assert_greater_than(entry.firstInterimResponseStart, 49 delay, "firstInterimResponseStart > 100 response"); 50 } 51 } 52 53 total_delay += delay; 54 if (!with100 && !with103) 55 assert_equals(entry.firstInterimResponseStart, 0); 56 57 assert_greater_than(entry.finalResponseHeadersStart, total_delay, 58 "responseStart"); 59 assert_equals(entry.responseStart, entry.firstInterimResponseStart || entry.finalResponseHeadersStart); 60 }, `Fetch from ${origin} ${with103 ? "with" : "without"} early hints, ${ 61 with100 ? "with" : "without"} 100 response`); 62 } 63 64 for (const with103 of [true, false]) { 65 for (const with100 of [true, false]) { 66 for (origin of ['same-origin', 'cross-origin', 'cross-origin-with-TAO']) { 67 interim_response_time_test({with100, with103, origin}); 68 } 69 } 70 } 71 </script> 72 </body> 73 </html>