tor-browser

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

browser_aboutdebugging_connect_networklocations.js (3303B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Test the network locations form of the Connect page.
      8 * Check that a network location can be added and removed.
      9 */
     10 
     11 const TEST_NETWORK_LOCATION = "localhost:1111";
     12 const TEST_NETWORK_LOCATION_INVALID = "testnetwork";
     13 
     14 add_task(async function () {
     15  const { document, tab } = await openAboutDebugging();
     16 
     17  await selectConnectPage(document);
     18 
     19  let networkLocations = document.querySelectorAll(".qa-network-location");
     20  is(
     21    networkLocations.length,
     22    0,
     23    "By default, no network locations are displayed"
     24  );
     25 
     26  info("Check whether error message should show if the input value is invalid");
     27  addNetworkLocation(TEST_NETWORK_LOCATION_INVALID, document);
     28  await waitUntil(() =>
     29    document.querySelector(".qa-connect-page__network-form__error-message")
     30  );
     31 
     32  info("Wait until the new network location is visible in the list");
     33  addNetworkLocation(TEST_NETWORK_LOCATION, document);
     34  await waitUntil(
     35    () => document.querySelectorAll(".qa-network-location").length === 1
     36  );
     37  await waitUntil(
     38    () =>
     39      !document.querySelector(".qa-connect-page__network-form__error-message")
     40  );
     41 
     42  networkLocations = document.querySelectorAll(".qa-network-location");
     43  const networkLocationValue = networkLocations[0].querySelector(
     44    ".qa-network-location-value"
     45  );
     46  is(
     47    networkLocationValue.textContent,
     48    TEST_NETWORK_LOCATION,
     49    "Added network location has the expected value"
     50  );
     51 
     52  info(
     53    "Check whether error message should show if the input value was duplicate"
     54  );
     55  addNetworkLocation(TEST_NETWORK_LOCATION, document);
     56  await waitUntil(() =>
     57    document.querySelector(".qa-connect-page__network-form__error-message")
     58  );
     59 
     60  info("Wait until the new network location is removed from the list");
     61  removeNetworkLocation(TEST_NETWORK_LOCATION, document);
     62  await waitUntil(
     63    () => document.querySelectorAll(".qa-network-location").length === 0
     64  );
     65 
     66  await removeTab(tab);
     67 });
     68 
     69 function addNetworkLocation(location, document) {
     70  info("Setting a value in the network form input");
     71  const networkLocationInput = document.querySelector(".qa-network-form-input");
     72  networkLocationInput.value = "";
     73  networkLocationInput.focus();
     74  EventUtils.sendString(location, networkLocationInput.ownerGlobal);
     75 
     76  info("Click on network form submit button");
     77  const networkLocationSubmitButton = document.querySelector(
     78    ".qa-network-form-submit-button"
     79  );
     80  networkLocationSubmitButton.click();
     81 }
     82 
     83 function removeNetworkLocation(location, document) {
     84  const networkLocation = getNetworkLocation(location, document);
     85  ok(networkLocation, "Network location container found.");
     86 
     87  info("Click on the remove button for the provided network location");
     88  const removeButton = networkLocation.querySelector(
     89    ".qa-network-location-remove-button"
     90  );
     91  removeButton.click();
     92 }
     93 
     94 function getNetworkLocation(location, document) {
     95  info("Find the container for network location: " + location);
     96  const networkLocations = document.querySelectorAll(".qa-network-location");
     97  return [...networkLocations].find(element => {
     98    return (
     99      element.querySelector(".qa-network-location-value").textContent ===
    100      location
    101    );
    102  });
    103 }