tor-browser

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

unload-main-frame-same-origin.window.js (1118B)


      1 // META: title=Unload runs in main frame when navigating same-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 
     25  // Navigate back.
     26  await rc2.historyBack();
     27 
     28  // Test that the unload handler wrote to storage.
     29  // Running it in the remote context after going back should ensure that the
     30  // navigation (and therefore the unload handler) has completed.
     31  assert_equals(
     32      await rc1.executeScript(() => localStorage.getItem('unload')), 'ran');
     33 });