| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="/resources/testharness.js"></script> | 2 <script src="/resources/testharness.js"></script> |
| 3 <script src="/resources/testharnessreport.js"></script> | 3 <script src="/resources/testharnessreport.js"></script> |
| 4 <script src="resources/test-helpers.sub.js"></script> | 4 <script src="resources/test-helpers.sub.js"></script> |
| 5 <script> | 5 <script> |
| 6 | 6 |
| 7 service_worker_test( | 7 service_worker_test( |
| 8 'resources/performance-timeline-worker.js', | 8 'resources/performance-timeline-worker.js', |
| 9 'Test Performance Timeline API in Service Worker'); | 9 'Test Performance Timeline API in Service Worker'); |
| 10 | 10 |
| 11 // The purpose of this test is to verify that service worker overhead | 11 // The purpose of this test is to verify that service worker overhead |
| 12 // is included in the Performance API's timing information. | 12 // is included in the Performance API's timing information. |
| 13 promise_test(t => { | 13 promise_test(t => { |
| 14 let script = 'resources/empty-but-slow-worker.js'; | 14 let script = 'resources/empty-but-slow-worker.js'; |
| 15 let scope = 'resources/dummy.txt?slow-sw-timing'; | 15 let scope = 'resources/dummy.txt?slow-sw-timing'; |
| 16 let url = new URL(scope, window.location).href; | 16 let url = new URL(scope, window.location).href; |
| 17 let slowURL = url + '&slow'; | 17 let slowURL = url + '&slow'; |
| 18 let frame; | 18 let frame; |
| 19 return service_worker_unregister_and_register(t, script, scope) | 19 return service_worker_unregister_and_register(t, script, scope) |
| 20 .then(reg => wait_for_state(t, reg.installing, 'activated')) | 20 .then(reg => wait_for_state(t, reg.installing, 'activated')) |
| 21 .then(_ => with_iframe(scope)) | 21 .then(_ => with_iframe(scope)) |
| 22 .then(f => { | 22 .then(f => { |
| 23 frame = f; | 23 frame = f; |
| 24 return Promise.all([ | 24 return frame.contentWindow.fetch(url).then(r => r && r.text()); |
| 25 // This will get effectively an empty service worker FetchEvent | 25 }) |
| 26 // handler. It should have no additional delay. Note that the | 26 .then(_ => { |
| 27 // text() call is necessary to complete the response and have the | 27 return frame.contentWindow.fetch(slowURL).then(r => r && r.text()); |
| 28 // timings show up in the performance entries. | |
| 29 frame.contentWindow.fetch(url).then(r => r && r.text()), | |
| 30 // This will cause the service worker to spin for two seconds | |
| 31 // in its FetchEvent handler. | |
| 32 frame.contentWindow.fetch(slowURL).then(r => r && r.text()) | |
| 33 ]); | |
| 34 }) | 28 }) |
| 35 .then(_ => { | 29 .then(_ => { |
| 36 function elapsed(u) { | 30 function elapsed(u) { |
| 37 let entry = frame.contentWindow.performance.getEntriesByName(u); | 31 let entry = frame.contentWindow.performance.getEntriesByName(u); |
| 38 return entry[0] ? entry[0].duration : undefined; | 32 return entry[0] ? entry[0].duration : undefined; |
| 39 } | 33 } |
| 40 let urlTime = elapsed(url); | 34 let urlTime = elapsed(url); |
| 41 let slowURLTime = elapsed(slowURL); | 35 let slowURLTime = elapsed(slowURL); |
| 42 // Verify the request slowed by the service worker is indeed measured | 36 // Verify the request slowed by the service worker is indeed measured |
| 43 // to be slower. Note, we compare to smaller delay instead of the exact | 37 // to be slower. Note, we compare to smaller delay instead of the exact |
| 44 // delay amount to avoid making the test racy under automation. | 38 // delay amount to avoid making the test racy under automation. |
| 45 assert_true(slowURLTime >= urlTime + 1500, | 39 assert_greater_than(slowURLTime, urlTime + 1000, |
| 46 'Slow service worker request should measure increased delay.')
; | 40 'Slow service worker request should measure increased delay.')
; |
| 47 frame.remove(); | 41 frame.remove(); |
| 48 return service_worker_unregister_and_done(t, scope); | 42 return service_worker_unregister_and_done(t, scope); |
| 49 }) | 43 }) |
| 50 }, 'empty service worker fetch event included in performance timings'); | 44 }, 'empty service worker fetch event included in performance timings'); |
| 51 | 45 |
| 52 </script> | 46 </script> |
| OLD | NEW |