tor-browser

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

browser_aboutNetError_emptyResponse.js (2806B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_setup(async function () {
      7  await SpecialPowers.pushPrefEnv({
      8    set: [["test.wait300msAfterTabSwitch", true]],
      9  });
     10 });
     11 
     12 function startDropServer() {
     13  const server = Cc["@mozilla.org/network/server-socket;1"].createInstance(
     14    Ci.nsIServerSocket
     15  );
     16  info("Using a random port.");
     17  server.init(-1, true, -1);
     18  server.asyncListen({
     19    onSocketAccepted(socket, transport) {
     20      // Close immediately, no response sent.
     21      transport.close(Cr.NS_OK);
     22    },
     23    onStopListening() {},
     24  });
     25  registerCleanupFunction(() => server.close());
     26  return server.port;
     27 }
     28 
     29 add_task(async function test_net_empty_response_copy() {
     30  await setSecurityCertErrorsFeltPrivacyToTrue();
     31 
     32  const port = startDropServer();
     33  const url = `http://127.0.0.1:${port}/`;
     34  let browser, tab;
     35  let pageLoaded;
     36  await BrowserTestUtils.openNewForegroundTab(
     37    gBrowser,
     38    () => {
     39      gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url);
     40      browser = gBrowser.selectedBrowser;
     41      tab = gBrowser.selectedTab;
     42      pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
     43    },
     44    false
     45  );
     46 
     47  info("Loading and waiting for the net error.");
     48  await pageLoaded;
     49 
     50  Assert.ok("Loaded empty server response.");
     51  await ContentTask.spawn(browser, null, async () => {
     52    await ContentTaskUtils.waitForCondition(
     53      () => content?.document?.querySelector("net-error-card"),
     54      "Wait for empty-response copy to render"
     55    );
     56    const doc = content.document;
     57    const netErrorCard = doc.querySelector("net-error-card").wrappedJSObject;
     58    Assert.ok(netErrorCard, "NetErrorCard supports empty server responses.");
     59    Assert.ok(
     60      netErrorCard.netErrorTitleText,
     61      "NetErrorCard has netErrorTitleText."
     62    );
     63    Assert.ok(netErrorCard.netErrorIntro, "NetErrorCard has netErrorIntro.");
     64    Assert.ok(
     65      netErrorCard.whatCanYouDo,
     66      "NetErrorCard has whatCanYouDo section."
     67    );
     68    Assert.ok(netErrorCard.tryAgainButton, "NetErrorCard has tryAgainButton.");
     69    Assert.equal(
     70      netErrorCard.netErrorTitleText.dataset.l10nId,
     71      "problem-with-this-site-title",
     72      "Using the 'problem with this site' title"
     73    );
     74    Assert.equal(
     75      netErrorCard.netErrorIntro.dataset.l10nId,
     76      "neterror-http-empty-response-description",
     77      "Using the 'empty response' intro."
     78    );
     79    Assert.equal(
     80      netErrorCard.whatCanYouDo.dataset.l10nId,
     81      "neterror-http-empty-response",
     82      "Using the 'empty response' variant of the 'What can you do' copy."
     83    );
     84    Assert.ok(
     85      ContentTaskUtils.isVisible(netErrorCard.tryAgainButton),
     86      "The 'Try Again' button is shown."
     87    );
     88  });
     89  BrowserTestUtils.removeTab(tab);
     90 });