tor-browser

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

activation-start.https.html (2395B)


      1 <!DOCTYPE html>
      2 <title>PerformanceNavigationTiming's activationStart in prerendered page</title>
      3 <meta name="timeout" content="long">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/common/utils.js"></script>
      7 <script src="/common/dispatcher/dispatcher.js"></script>
      8 <script src="/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js"></script>
      9 <script src="../resources/utils.js"></script>
     10 <script src="resources/utils.js"></script>
     11 
     12 <body>
     13 <script>
     14 setup(() => assertSpeculationRulesIsSupported());
     15 
     16 promise_test(async t => {
     17  const ACTIVATION_DELAY = 10;
     18 
     19  const rcHelper = new PrerenderingRemoteContextHelper();
     20  const referrerRC = await rcHelper.addWindow(undefined, { features: 'noopener' });
     21  const prerenderedRC = await referrerRC.addPrerender();
     22  const iframeRC = await prerenderedRC.addIframe();
     23 
     24  assert_equals(
     25    await getActivationStart(prerenderedRC),
     26    0,
     27    'activationStart must be 0 while prerendering'
     28  );
     29 
     30  assert_equals(
     31    await getActivationStart(iframeRC),
     32    0,
     33    'activationStart must be 0 while prerendering the iframe'
     34  );
     35 
     36  // Wait ACTIVATION_DELAY ms before activation.
     37  await new Promise(resolve => t.step_timeout(resolve, ACTIVATION_DELAY));
     38 
     39  await referrerRC.navigateExpectingPrerenderingActivation(prerenderedRC);
     40 
     41  assert_greater_than_equal(
     42    await getActivationStart(prerenderedRC),
     43    ACTIVATION_DELAY,
     44    'activationStart after activation must be greater than or equal to ' +
     45    'ACTIVATION_DELAY'
     46  );
     47 
     48  assert_greater_than_equal(
     49    await getActivationStart(iframeRC),
     50    ACTIVATION_DELAY,
     51    'activationStart after activation must be greater than or equal to ' +
     52    'ACTIVATION_DELAY in the iframe'
     53  );
     54 });
     55 
     56 // A utility to both extract activationStart from the prerendered
     57 // RemoteContextWrapper, and also check that it shows up in toJSON().
     58 async function getActivationStart(prerenderedRC) {
     59  const [activationStart, activationStartInToJSON] = await prerenderedRC.executeScript(() => {
     60    const entry = performance.getEntriesByType("navigation")[0];
     61    return [entry.activationStart, entry.toJSON().activationStart];
     62  });
     63 
     64  assert_equals(
     65    activationStart,
     66    activationStartInToJSON,
     67    "activationStart value must be available in the result of toJSON()"
     68  );
     69 
     70  return activationStart;
     71 }
     72 </script>