tor-browser

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

browser_aboutNetError_basicHttpAuth.js (2355B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const AUTH_ROUTE =
      7  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      8  "http://example.com/browser/browser/base/content/test/about/basic_auth_route.sjs";
      9 
     10 // From appstrings.properties
     11 const EXPECTED_SHORT_DESC =
     12  "Someone pretending to be the site could try to steal things like your username, password, or email.";
     13 
     14 add_task(async function test_basicHttpAuth() {
     15  await SpecialPowers.pushPrefEnv({
     16    set: [
     17      // https first is disabled to enforce the scheme as http
     18      ["dom.security.https_first", false],
     19      ["network.http.basic_http_auth.enabled", false],
     20      // blank page with error is priortized
     21      ["browser.http.blank_page_with_error_response.enabled", true],
     22      ["security.certerrors.felt-privacy-v1", false],
     23    ],
     24  });
     25 
     26  let browser;
     27  let pageLoaded;
     28  await BrowserTestUtils.openNewForegroundTab(
     29    gBrowser,
     30    () => {
     31      gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, AUTH_ROUTE);
     32      browser = gBrowser.selectedBrowser;
     33      pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
     34    },
     35    false
     36  );
     37 
     38  info("Loading and waiting for the net error");
     39  await pageLoaded;
     40 
     41  await SpecialPowers.spawn(
     42    browser,
     43    [EXPECTED_SHORT_DESC],
     44    function (expectedShortDesc) {
     45      const doc = content.document;
     46      ok(
     47        doc.documentURI.startsWith("about:neterror"),
     48        "Should be showing error page"
     49      );
     50 
     51      const titleEl = doc.querySelector(".title-text");
     52      const actualDataL10nID = titleEl.getAttribute("data-l10n-id");
     53      is(
     54        actualDataL10nID,
     55        "general-body-title",
     56        "Correct error page title is set"
     57      );
     58 
     59      // We use startsWith to account for the error code portion
     60      const shortDesc = doc.getElementById("errorShortDesc");
     61      ok(
     62        shortDesc.textContent.startsWith(expectedShortDesc),
     63        "Correct error page title is set"
     64      );
     65 
     66      const anchor = doc.querySelector("a");
     67      const actualAnchorl10nID = anchor.getAttribute("data-l10n-id");
     68      is(
     69        actualAnchorl10nID,
     70        "neterror-learn-more-link",
     71        "Correct error link is set"
     72      );
     73    }
     74  );
     75 
     76  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     77  await SpecialPowers.popPrefEnv();
     78 });