tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

performance-timeline.https.html (1863B)


      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 <script>
      6 
      7 service_worker_test(
      8    'resources/performance-timeline-worker.js',
      9    'Test Performance Timeline API in Service Worker');
     10 
     11 // The purpose of this test is to verify that service worker overhead
     12 // is included in the Performance API's timing information.
     13 promise_test(t => {
     14  let script = 'resources/empty-but-slow-worker.js';
     15  let scope = 'resources/sample.txt?slow-sw-timing';
     16  let url = new URL(scope, window.location).href;
     17  let slowURL = url + '&slow';
     18  let frame;
     19  return service_worker_unregister_and_register(t, script, scope)
     20    .then(reg => {
     21        t.add_cleanup(() => service_worker_unregister(t, scope));
     22 
     23        return wait_for_state(t, reg.installing, 'activated');
     24      })
     25    .then(_ => with_iframe(scope))
     26    .then(f => {
     27      frame = f;
     28      return frame.contentWindow.fetch(url).then(r => r && r.text());
     29    })
     30    .then(_ => {
     31      return frame.contentWindow.fetch(slowURL).then(r => r && r.text());
     32    })
     33    .then(_ => {
     34      function elapsed(u) {
     35        let entry = frame.contentWindow.performance.getEntriesByName(u);
     36        return entry[0] ? entry[0].duration : undefined;
     37      }
     38      let urlTime = elapsed(url);
     39      let slowURLTime = elapsed(slowURL);
     40      // Verify the request slowed by the service worker is indeed measured
     41      // to be slower.  Note, we compare to smaller delay instead of the exact
     42      // delay amount to avoid making the test racy under automation.
     43      assert_greater_than(slowURLTime, urlTime + 1000,
     44                  'Slow service worker request should measure increased delay.');
     45      frame.remove();
     46    })
     47 }, 'empty service worker fetch event included in performance timings');
     48 
     49 </script>