tor-browser

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

sxg-prefetch-resource-timing.tentative.html (1537B)


      1 <!DOCTYPE html>
      2 <title>Resource Timing for prefetched SignedHTTPExchange</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/get-host-info.sub.js"></script>
      6 <script src="./resources/sxg-util.js"></script>
      7 <body>
      8 <script>
      9 function addPrefetch(url) {
     10  let link = document.createElement('link');
     11  link.rel = 'prefetch';
     12  link.href = url;
     13  document.body.appendChild(link);
     14 }
     15 
     16 async function waitForPerformanceEntries(url) {
     17  let entries = performance.getEntriesByName(url);
     18  if (entries.length > 0) {
     19    return entries;
     20  }
     21  return new Promise((resolve) => {
     22    new PerformanceObserver((list) => {
     23      const entries = list.getEntriesByName(url);
     24      if (entries.length > 0) {
     25        resolve(entries);
     26      }
     27    }).observe({ entryTypes: ['resource'] });
     28  });
     29 }
     30 
     31 promise_test(async (t) => {
     32  const url = get_host_info().HTTPS_ORIGIN + '/signed-exchange/resources/sxg/sxg-location.sxg';
     33  addPrefetch(url);
     34  return waitForPerformanceEntries(url).then((entries) => {
     35    assert_equals(entries.length, 1, "Should have only one resource timing entry");
     36    const e = entries[0];
     37    assert_greater_than(e.duration, 0, "duration should be greater than 0");
     38    assert_greater_than(e.fetchStart, 0, "fetchStart should be greater than 0");
     39    assert_greater_than(e.responseEnd, e.fetchStart,
     40                        "responseEnd should be greater than fetchStart");
     41  });
     42 }, 'Resource Timing for prefetched SignedHTTPExchange');
     43 </script>
     44 </body>