tor-browser

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

navigation-timing-extended.https.html (2114B)


      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 navigate_in_frame(frame, url) {
     17    frame.contentWindow.location = url;
     18    return new Promise((resolve) => {
     19        frame.addEventListener('load', () => {
     20            const timing = frame.contentWindow.performance.getEntriesByType('navigation')[0];
     21            const {timeOrigin} = frame.contentWindow.performance;
     22            resolve({
     23                workerStart: timing.workerStart + timeOrigin,
     24                fetchStart: timing.fetchStart + timeOrigin
     25            })
     26        });
     27    });
     28 }
     29 
     30 const worker_url = 'resources/navigation-timing-worker-extended.js';
     31 
     32 promise_test(async (t) => {
     33    const scope = 'resources/timings/dummy.html';
     34    const registration = await service_worker_unregister_and_register(t, worker_url, scope);
     35    t.add_cleanup(() => registration.unregister());
     36    await wait_for_state(t, registration.installing, 'activating');
     37    const frame = await with_iframe('resources/empty.html');
     38    t.add_cleanup(() => frame.remove());
     39 
     40    const [timingFromEntry, timingFromWorker] = await Promise.all([
     41        navigate_in_frame(frame, scope),
     42        new Promise(resolve => {
     43            window.addEventListener('message', m => {
     44                resolve(m.data)
     45            })
     46        })])
     47 
     48    assert_greater_than(timingFromWorker.activateWorkerEnd, timingFromEntry.workerStart,
     49        'workerStart marking should not wait for worker activation to finish');
     50    assert_greater_than(timingFromEntry.fetchStart, timingFromWorker.activateWorkerEnd,
     51        'fetchStart should be marked once the worker is activated');
     52    assert_greater_than(timingFromWorker.handleFetchEvent, timingFromEntry.fetchStart,
     53        'fetchStart should be marked before the Fetch event handler is called');
     54 }, 'Service worker controlled navigation timing');
     55 </script>