tor-browser

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

browser_bfcache_after_auxiliary.js (2799B)


      1 const TEST_PATH = getRootDirectory(gTestPath).replace(
      2  "chrome://mochitests/content",
      3  "https://example.com"
      4 );
      5 
      6 add_task(async function restore_bfcache_after_auxiliary() {
      7  await BrowserTestUtils.withNewTab(
      8    TEST_PATH + "dummy_page.html",
      9    async browser => {
     10      let initialBC = browser.browsingContext;
     11 
     12      // Mark the initial dummy page as having the dynamic state from the bfcache by replacing the body.
     13      await SpecialPowers.spawn(browser, [], () => {
     14        content.document.body.innerHTML = "bfcached";
     15      });
     16 
     17      BrowserTestUtils.startLoadingURIString(
     18        browser,
     19        TEST_PATH + "file_open_about_blank.html"
     20      );
     21      await BrowserTestUtils.browserLoaded(browser);
     22      let openerBC = browser.browsingContext;
     23      isnot(
     24        initialBC,
     25        openerBC,
     26        "should have put the previous document into the bfcache"
     27      );
     28 
     29      // Check that the document is currently BFCached
     30      info("going back for bfcache smoke test");
     31      browser.goBack();
     32      await BrowserTestUtils.waitForContentEvent(browser, "pageshow");
     33 
     34      let restoredInnerHTML = await SpecialPowers.spawn(
     35        browser,
     36        [],
     37        () => content.document.body.innerHTML
     38      );
     39      is(restoredInnerHTML, "bfcached", "page was restored from bfcache");
     40      is(
     41        initialBC,
     42        browser.browsingContext,
     43        "returned to previous browsingcontext"
     44      );
     45 
     46      // Go back forward, and open a pop-up.
     47      info("restoring after bfcache smoke test");
     48      browser.goForward();
     49      await BrowserTestUtils.waitForContentEvent(browser, "pageshow");
     50      is(
     51        openerBC,
     52        browser.browsingContext,
     53        "returned to opener browsingContext"
     54      );
     55 
     56      info("opening a popup");
     57      let waitForPopup = BrowserTestUtils.waitForNewTab(gBrowser);
     58      await SpecialPowers.spawn(browser, [], () => {
     59        content.eval(`window.open("dummy_page.html", "popup");`);
     60        // content.document.querySelector("#open").click()
     61      });
     62      let popup = await waitForPopup;
     63      info("got the popup");
     64      let popupBC = popup.linkedBrowser.browsingContext;
     65      is(popupBC.opener, openerBC, "opener is openerBC");
     66 
     67      // Now that the pop-up is opened, try to go back again.
     68      info("trying to go back with a popup");
     69      browser.goBack();
     70      await BrowserTestUtils.waitForContentEvent(browser, "pageshow");
     71 
     72      let nonRestoredInnerHTML = await SpecialPowers.spawn(
     73        browser,
     74        [],
     75        () => content.document.body.innerHTML
     76      );
     77      isnot(
     78        nonRestoredInnerHTML,
     79        "bfcached",
     80        "page was not restored from bfcache"
     81      );
     82      is(openerBC, browser.browsingContext, "returned to the new bc");
     83 
     84      await BrowserTestUtils.removeTab(popup);
     85    }
     86  );
     87 });