tor-browser

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

windowclient-navigate-to-same-origin-url-on-iframe.https.html (2068B)


      1 <!DOCTYPE html>
      2 <title>WindowClient.navigate() to same-origin url in a prerendered iframe</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/get-host-info.sub.js"></script>
      7 <script src="/common/utils.js"></script>
      8 <script src="/service-workers/service-worker/resources/test-helpers.sub.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 const PAGE_URL = 'resources/windowclient-navigate-on-iframe.html';
     17 const WORKER_URL = 'resources/windowclient-navigate-worker.js';
     18 const SCOPE = 'resources/';
     19 const SAME_ORIGIN_DESTINATION =
     20    get_host_info()['HTTPS_ORIGIN'] + base_path() + 'resources/empty.html';
     21 
     22 promise_test(async t => {
     23  const uid = token();
     24 
     25  const registration = await service_worker_unregister_and_register(
     26      t, `${WORKER_URL}?uid=${uid}`, SCOPE);
     27  t.add_cleanup(() => registration.unregister());
     28  await wait_for_state(t, registration.installing, 'activated');
     29 
     30  const bc = new PrerenderChannel('test-channel', uid);
     31  t.add_cleanup(_ => bc.close());
     32 
     33  const gotMessage = new Promise(resolve => {
     34    bc.addEventListener('message', e => {
     35      resolve(e.data);
     36    }, {
     37      once: true
     38    });
     39  });
     40 
     41  // PAGE_URL starts a prerender of a page that makes an iframe, then asks the
     42  // service worker to navigate the iframe to `navigationUrl` via
     43  // `WindowClient.navigate(url)`.
     44  window.open(
     45      `${PAGE_URL}?navigationUrl=${SAME_ORIGIN_DESTINATION}&uid=${uid}`,
     46      '_blank',
     47      'noopener');
     48 
     49  const navigationResult = await gotMessage;
     50  assert_equals(navigationResult, 'navigate() succeeded',
     51      'should succeed to finish navigation test');
     52 
     53  // Send a close signal to PrerenderEventCollector on the prerendered page.
     54  new PrerenderChannel('close', uid).postMessage('');
     55 }, 'WindowClient.navigate() to a same-origin URL on a prerendered iframe ' +
     56   'should succeed');
     57 </script>