tor-browser

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

iframe-added-post-activation.html (1982B)


      1 <!doctype html>
      2 
      3 <title>iframe added post activation: initiator and prerendered page</title>
      4 <script src="/common/get-host-info.sub.js"></script>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="utils.js"></script>
      8 <body>
      9 <script>
     10 
     11 // When loaded without the "?prerendering" param, this document is called the
     12 // "intiator page". It starts a prerender to the same URL, but with the
     13 // "?prerendering" param.
     14 //
     15 // When loaded with the "?prerendering" param, this document is the "prerendered
     16 // page". It tells the initiator page when it is ready to activate, and messages
     17 // the main test page when it is finished.
     18 
     19 // main() runs the logic of the prerendered page.
     20 //
     21 // On activation, adds an iframe and tests its document.prerendering state.
     22 async function main() {
     23  const activated = new Promise((resolve, reject) => {
     24    document.addEventListener('prerenderingchange', (e) => {
     25      const iframe = document.createElement('iframe');
     26      document.body.appendChild(iframe);
     27      resolve(iframe.contentDocument.prerendering)
     28    });
     29  });
     30 
     31  // Ask to activate.
     32  const prerenderChannel = new PrerenderChannel('prerender-channel');
     33  prerenderChannel.postMessage('readyToActivate');
     34 
     35  // Check that document.prerendering is false in the iframe.
     36  const iframePrerendering = await activated;
     37  assert_true(iframePrerendering === false,
     38              'document.prerendering in iframe should be false');
     39 }
     40 
     41 // See comment at the top of this file.
     42 const params = new URLSearchParams(location.search);
     43 const isPrerendering = params.has('prerendering');
     44 if (!isPrerendering) {
     45  loadInitiatorPage();
     46 } else {
     47  // For the prerendering page, run main() then message the test page with the
     48  // result.
     49  const testChannel = new PrerenderChannel('test-channel');
     50  main().then(() => {
     51    testChannel.postMessage('PASS');
     52  }).catch((e) => {
     53    testChannel.postMessage('FAIL: ' + e);
     54  });
     55 }
     56 </script>
     57 </body>