tor-browser

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

window-open-during-prerendering.html (1106B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="utils.js"></script>
      5 <script>
      6 
      7 // This file is loaded twice. First this is loaded as a page to trigger
      8 // prerendering and then loaded as a prerendering page.
      9 
     10 function runAsTriggerPage() {
     11  assert_false(document.prerendering);
     12  startPrerendering(location.href + '&prerendering=true');
     13 
     14  // Close this window for cleanup after the prerendering page runs the test.
     15  const bc = new PrerenderChannel('result');
     16  bc.onmessage = e => window.close();
     17 }
     18 
     19 function runAsPrerenderingPage() {
     20  assert_true(document.prerendering);
     21 
     22  // Attempt to open a window during prerendering.
     23  const win = window.open('empty.html', '_blank');
     24 
     25  // Send the result to the test runner page.
     26  const bc = new PrerenderChannel('result');
     27  if (win) {
     28    bc.postMessage('opened');
     29    win.close();
     30  } else {
     31    bc.postMessage('failed to open');
     32  }
     33 }
     34 
     35 if (new URLSearchParams(location.search).has('prerendering')) {
     36  runAsPrerenderingPage();
     37 } else {
     38  runAsTriggerPage();
     39 }
     40 
     41 </script>