tor-browser

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

change_eventhandler_in_bfcache.https.window.js (1269B)


      1 // META: title=CookieStore queues events when bfcached
      2 // META: script=/common/dispatcher/dispatcher.js
      3 // META: script=/common/utils.js
      4 // META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
      5 
      6 'use strict';
      7 
      8 promise_test(async t => {
      9  const rcHelper = new RemoteContextHelper();
     10 
     11  // Open a window with noopener so that BFCache will work.
     12  const rc = await rcHelper.addWindow(null, { features: "noopener" });
     13 
     14  await rc.executeScript(() => {
     15    window.events = [];
     16    window.addEventListener('pageshow', (event) => {
     17      window.events.push("pageshow:" + event.persisted);
     18    });
     19 
     20    window.cookiePromise = new Promise(resolve => {
     21      cookieStore.addEventListener('change', () => {
     22        window.events.push("cookie");
     23        resolve();
     24      }, {once: true});
     25    });
     26  });
     27 
     28  const rc2 = await rc.navigateToNew();
     29 
     30  await rc2.executeScript(() => {
     31    document.cookie = "BFCACHE=1; path=/";
     32  });
     33 
     34  await rc2.historyBack();
     35 
     36  assert_equals(
     37    await rc.executeScript(async () => window.cookiePromise.then(() => window.events.join("-"))), "pageshow:true-cookie",
     38    'precondition: document was bfcached'
     39  );
     40 
     41  await rc.executeScript(async () => {
     42   await cookieStore.delete("BFCACHE");
     43  });
     44 });