tor-browser

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

browser_bug1757005.js (2378B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function () {
      7  // (1) Load one page with bfcache disabled and another one with bfcache enabled.
      8  // (2) Check that BrowsingContext.getCurrentTopByBrowserId(browserId) returns
      9  //     the expected browsing context both in the parent process and in the child process.
     10  // (3) Go back and then forward
     11  // (4) Run the same checks as in step 2 again.
     12 
     13  let url1 = "data:text/html,<body onunload='/* disable bfcache */'>";
     14  let url2 = "data:text/html,page2";
     15  await BrowserTestUtils.withNewTab(
     16    {
     17      gBrowser,
     18      url: url1,
     19    },
     20    async function (browser) {
     21      info("Initial load");
     22 
     23      let loaded = BrowserTestUtils.browserLoaded(browser);
     24      BrowserTestUtils.startLoadingURIString(browser, url2);
     25      await loaded;
     26      info("Second page loaded");
     27 
     28      let browserId = browser.browserId;
     29      ok(!!browser.browsingContext, "Should have a BrowsingContext. (1)");
     30      is(
     31        BrowsingContext.getCurrentTopByBrowserId(browserId),
     32        browser.browsingContext,
     33        "Should get the correct browsingContext(1)"
     34      );
     35 
     36      await ContentTask.spawn(browser, browserId, async function (browserId) {
     37        Assert.equal(
     38          BrowsingContext.getCurrentTopByBrowserId(browserId),
     39          docShell.browsingContext
     40        );
     41        Assert.equal(docShell.browsingContext.browserId, browserId);
     42      });
     43 
     44      let awaitPageShow = BrowserTestUtils.waitForContentEvent(
     45        browser,
     46        "pageshow"
     47      );
     48      browser.goBack();
     49      await awaitPageShow;
     50      info("Back");
     51 
     52      awaitPageShow = BrowserTestUtils.waitForContentEvent(browser, "pageshow");
     53      browser.goForward();
     54      await awaitPageShow;
     55      info("Forward");
     56 
     57      ok(!!browser.browsingContext, "Should have a BrowsingContext. (2)");
     58      is(
     59        BrowsingContext.getCurrentTopByBrowserId(browserId),
     60        browser.browsingContext,
     61        "Should get the correct BrowsingContext. (2)"
     62      );
     63 
     64      await ContentTask.spawn(browser, browserId, async function (browserId) {
     65        Assert.equal(
     66          BrowsingContext.getCurrentTopByBrowserId(browserId),
     67          docShell.browsingContext
     68        );
     69        Assert.equal(docShell.browsingContext.browserId, browserId);
     70      });
     71    }
     72  );
     73 });