navigation-timing.https.html (2894B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="resources/test-helpers.sub.js"></script> 5 6 <script> 7 const timingEventOrder = [ 8 'startTime', 9 'workerStart', 10 'fetchStart', 11 'requestStart', 12 'responseStart', 13 'responseEnd', 14 ]; 15 16 function verify(timing) { 17 for (let i = 0; i < timingEventOrder.length - 1; i++) { 18 assert_true(timing[timingEventOrder[i]] <= timing[timingEventOrder[i + 1]], 19 `Expected ${timingEventOrder[i]} <= ${timingEventOrder[i + 1]}`); 20 } 21 } 22 23 function navigate_in_frame(frame, url) { 24 frame.contentWindow.location = url; 25 return new Promise((resolve) => { 26 frame.addEventListener('load', () => { 27 const timing = frame.contentWindow.performance.getEntriesByType('navigation')[0]; 28 resolve(timing); 29 }); 30 }); 31 } 32 33 const worker_url = 'resources/navigation-timing-worker.js'; 34 35 promise_test(async (t) => { 36 const scope = 'resources/empty.html'; 37 const registration = await service_worker_unregister_and_register(t, worker_url, scope); 38 t.add_cleanup(() => registration.unregister()); 39 await wait_for_state(t, registration.installing, 'activated'); 40 const frame = await with_iframe(scope); 41 t.add_cleanup(() => frame.remove()); 42 43 const timing = await navigate_in_frame(frame, scope); 44 assert_greater_than(timing.workerStart, 0); 45 verify(timing); 46 }, 'Service worker controlled navigation timing'); 47 48 promise_test(async (t) => { 49 const scope = 'resources/empty.html?network-fallback'; 50 const registration = await service_worker_unregister_and_register(t, worker_url, scope); 51 t.add_cleanup(() => registration.unregister()); 52 await wait_for_state(t, registration.installing, 'activated'); 53 const frame = await with_iframe(scope); 54 t.add_cleanup(() => frame.remove()); 55 56 const timing = await navigate_in_frame(frame, scope); 57 assert_greater_than(timing.workerStart, 0); 58 verify(timing); 59 }, 'Service worker controlled navigation timing network fallback'); 60 61 promise_test(async (t) => { 62 const scope = 'resources/redirect.py?Redirect=empty.html'; 63 const registration = await service_worker_unregister_and_register(t, worker_url, scope); 64 t.add_cleanup(() => registration.unregister()); 65 await wait_for_state(t, registration.installing, 'activated'); 66 const frame = await with_iframe(scope); 67 t.add_cleanup(() => frame.remove()); 68 69 const timing = await navigate_in_frame(frame, scope); 70 verify(timing); 71 // Additional checks for redirected navigation. 72 assert_true(timing.redirectStart <= timing.redirectEnd, 73 'Expected redirectStart <= redirectEnd'); 74 assert_true(timing.redirectEnd <= timing.fetchStart, 75 'Expected redirectEnd <= fetchStart'); 76 }, 'Service worker controlled navigation timing redirect'); 77 </script>