tor-browser

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

browser_aboutNetError_internet_connection_offline.js (2819B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 async function checkErrorForInvalidUriLoad(l10nId) {
      7  let browser;
      8  let pageLoaded;
      9  await setSecurityCertErrorsFeltPrivacyToFalse();
     10  await BrowserTestUtils.openNewForegroundTab(
     11    gBrowser,
     12    () => {
     13      gBrowser.selectedTab = BrowserTestUtils.addTab(
     14        gBrowser,
     15        "https://does-not-exist.test"
     16      );
     17      browser = gBrowser.selectedBrowser;
     18      pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
     19    },
     20    false
     21  );
     22  await pageLoaded;
     23 
     24  await SpecialPowers.spawn(browser, [l10nId], expectedl10nId => {
     25    const doc = content.document;
     26    ok(
     27      doc.documentURI.startsWith("about:neterror"),
     28      "Should be showing error page"
     29    );
     30    const titleEl = doc.querySelector(".title-text");
     31    const actualDataL10nID = titleEl.getAttribute("data-l10n-id");
     32    is(actualDataL10nID, expectedl10nId, "Correct error page title is set");
     33  });
     34  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     35 }
     36 
     37 async function checkErrorForInvalidUriLoad_feltPrivacyToTrue(l10nId) {
     38  let browser;
     39  let pageLoaded;
     40  await setSecurityCertErrorsFeltPrivacyToTrue(true);
     41  await BrowserTestUtils.openNewForegroundTab(
     42    gBrowser,
     43    () => {
     44      gBrowser.selectedTab = BrowserTestUtils.addTab(
     45        gBrowser,
     46        "https://does-not-exist.test"
     47      );
     48      browser = gBrowser.selectedBrowser;
     49      pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
     50    },
     51    false
     52  );
     53  await pageLoaded;
     54 
     55  await SpecialPowers.spawn(browser, [l10nId], async expectedl10nId => {
     56    const doc = content.document;
     57    const netErrorCard = doc.querySelector("net-error-card").wrappedJSObject;
     58    await netErrorCard.getUpdateComplete();
     59 
     60    Assert.ok(
     61      doc.documentURI.startsWith("about:neterror"),
     62      "Should be showing error page"
     63    );
     64 
     65    Assert.strictEqual(
     66      netErrorCard.netErrorTitleText.dataset.l10nId,
     67      expectedl10nId,
     68      "Correct error page title is set"
     69    );
     70  });
     71  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     72  await SpecialPowers.popPrefEnv();
     73 }
     74 
     75 registerCleanupFunction(function () {
     76  Services.io.offline = false;
     77  Services.io.setConnectivityForTesting(true);
     78 });
     79 
     80 add_task(async function test_offline_mode() {
     81  Services.io.offline = true;
     82  await checkErrorForInvalidUriLoad("netOffline-title");
     83  await checkErrorForInvalidUriLoad_feltPrivacyToTrue(
     84    "fp-neterror-offline-body-title"
     85  );
     86 });
     87 
     88 add_task(async function test_internet_connection_offline() {
     89  Services.io.offline = false;
     90  Services.io.setConnectivityForTesting(false);
     91  await checkErrorForInvalidUriLoad("internet-connection-offline-title");
     92  await checkErrorForInvalidUriLoad_feltPrivacyToTrue(
     93    "fp-neterror-offline-body-title"
     94  );
     95 });