tor-browser

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

unload-main-frame-cross-origin.window.js (1184B)


      1 // META: title=Unload runs in main frame when navigating cross-origin.
      2 // META: script=/common/dispatcher/dispatcher.js
      3 // META: script=/common/get-host-info.sub.js
      4 // META: script=/common/utils.js
      5 // META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
      6 
      7 promise_test(async t => {
      8  const rcHelper = new RemoteContextHelper();
      9 
     10  const rc1 = await rcHelper.addWindow();
     11 
     12  t.add_cleanup(() => localStorage.removeItem('unload'));
     13 
     14  // Initialize storage and add "unload" event handler.
     15  await rc1.executeScript(() => {
     16    localStorage.setItem('unload', 'not yet');
     17    addEventListener('unload', () => {
     18      localStorage.setItem('unload', 'ran');
     19    });
     20  });
     21 
     22  // Navigate away.
     23  const rc2 = await rc1.navigateToNew(
     24      {extraRemoteContextConfig: {origin: 'HTTP_REMOTE_ORIGIN'}});
     25 
     26  // Navigate back.
     27  await rc2.historyBack();
     28 
     29  // Test that the unload handler wrote to storage.
     30  // Running it in the remote context after going back should ensure that the
     31  // navigation (and therefore the unload handler) has completed.
     32  assert_equals(
     33      await rc1.executeScript(() => localStorage.getItem('unload')), 'ran');
     34 });