tor-browser

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

browser_bug435325.js (2367B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /* Ensure that clicking the button in the Offline mode neterror page makes the browser go online. See bug 435325. */
      5 
      6 async function checkSwitchPageToOnlineMode(useFelt) {
      7  // Go offline and disable the proxy and cache, then try to load the test URL.
      8  Services.io.offline = true;
      9 
     10  // Tests always connect to localhost, and per bug 87717, localhost is now
     11  // reachable in offline mode.  To avoid this, disable any proxy.
     12  let proxyPrefValue = SpecialPowers.getIntPref("network.proxy.type");
     13  await SpecialPowers.pushPrefEnv({
     14    set: [
     15      ["network.proxy.type", 0],
     16      ["browser.cache.disk.enable", false],
     17      ["browser.cache.memory.enable", false],
     18      ["security.certerrors.felt-privacy-v1", useFelt],
     19    ],
     20  });
     21 
     22  await BrowserTestUtils.withNewTab("about:blank", async function (browser) {
     23    let netErrorLoaded = BrowserTestUtils.waitForErrorPage(browser);
     24 
     25    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     26    BrowserTestUtils.startLoadingURIString(browser, "http://example.com/");
     27    await netErrorLoaded;
     28 
     29    // Re-enable the proxy so example.com is resolved to localhost, rather than
     30    // the actual example.com.
     31    await SpecialPowers.pushPrefEnv({
     32      set: [["network.proxy.type", proxyPrefValue]],
     33    });
     34    let changeObserved = TestUtils.topicObserved(
     35      "network:offline-status-changed"
     36    );
     37 
     38    // Click on the 'Try again' button.
     39    await SpecialPowers.spawn(browser, [useFelt], async function (use_felt) {
     40      ok(
     41        content.document.documentURI.startsWith("about:neterror?e=netOffline"),
     42        "Should be showing error page"
     43      );
     44      const button = use_felt
     45        ? content.document.querySelector("net-error-card").wrappedJSObject
     46            .tryAgainButton
     47        : content.document.querySelector(
     48            "#netErrorButtonContainer > .try-again"
     49          );
     50      button.click();
     51    });
     52 
     53    await changeObserved;
     54    ok(
     55      !Services.io.offline,
     56      "After clicking the 'Try Again' button, we're back online."
     57    );
     58  });
     59 }
     60 add_task(async function runCheckSwitchPageToOnlineMode() {
     61  for (const useFelt of [true, false]) {
     62    await checkSwitchPageToOnlineMode(useFelt);
     63  }
     64 });
     65 
     66 registerCleanupFunction(function () {
     67  Services.io.offline = false;
     68 });