tor-browser

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

browser_aboutdebugging_routes.js (3784B)


      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 that the initial route is /setup
      8 */
      9 add_task(async function () {
     10  info("Check root route redirects to setup page");
     11  const { document, tab } = await openAboutDebugging();
     12  is(document.location.hash, "#/setup");
     13 
     14  await removeTab(tab);
     15 });
     16 
     17 /**
     18 * Test that the routes in about:debugging show the proper views and document.title
     19 */
     20 add_task(async function () {
     21  // enable USB devices mocks
     22  const mocks = new Mocks();
     23 
     24  const { document, tab } = await openAboutDebugging();
     25 
     26  info("Check 'This Firefox' route");
     27  document.location.hash = "#/runtime/this-firefox";
     28  await waitUntil(() => document.querySelector(".qa-runtime-page"));
     29  const infoLabel = document.querySelector(".qa-runtime-name").textContent;
     30  // NOTE: when using USB Mocks, we see only "Firefox" as the device name
     31  ok(infoLabel.includes("Firefox"), "Runtime is displayed as Firefox");
     32  ok(!infoLabel.includes(" on "), "Runtime is not associated to any device");
     33  is(
     34    document.title,
     35    "Debugging - Runtime / this-firefox",
     36    "Checking title for 'runtime' page"
     37  );
     38 
     39  info("Check 'Setup' page");
     40  document.location.hash = "#/setup";
     41  await waitUntil(() => document.querySelector(".qa-connect-page"));
     42  ok(true, "Setup page has been shown");
     43  is(document.title, "Debugging - Setup", "Checking title for 'setup' page");
     44 
     45  info("Check 'USB device runtime' page");
     46  // connect to a mocked USB runtime
     47  mocks.createUSBRuntime("1337id", {
     48    deviceName: "Fancy Phone",
     49    name: "Lorem ipsum",
     50  });
     51  mocks.emitUSBUpdate();
     52  await connectToRuntime("Fancy Phone", document);
     53  // navigate to it via URL
     54  document.location.hash = "#/runtime/1337id";
     55  await waitUntil(() => document.querySelector(".qa-runtime-page"));
     56  const runtimeLabel = document.querySelector(".qa-runtime-name").textContent;
     57  is(
     58    document.title,
     59    "Debugging - Runtime / 1337id",
     60    "Checking title for 'runtime' page with USB device"
     61  );
     62  ok(
     63    runtimeLabel.includes("Lorem ipsum"),
     64    "Runtime is displayed with the mocked name"
     65  );
     66 
     67  await removeTab(tab);
     68 });
     69 
     70 /**
     71 * Test that an invalid route redirects to / (currently This Firefox page)
     72 */
     73 add_task(async function () {
     74  info("Check an invalid route redirects to root");
     75  const { document, tab } = await openAboutDebugging();
     76 
     77  info("Waiting for a non setup page to load");
     78  document.location.hash = "#/runtime/this-firefox";
     79  await waitUntil(() => document.querySelector(".qa-runtime-page"));
     80 
     81  info("Update hash & wait for a redirect to root (connect page)");
     82  document.location.hash = "#/lorem-ipsum";
     83  await waitUntil(() => document.querySelector(".qa-connect-page"));
     84  is(document.title, "Debugging - Setup", "Checking title for 'setup' page");
     85  is(document.location.hash, "#/setup", "Redirected to root");
     86 
     87  await removeTab(tab);
     88 });
     89 
     90 /**
     91 * Test that routes from old about:debugging redirect to this Firefox.
     92 */
     93 add_task(async function testOldAboutDebuggingRoutes() {
     94  info("Check that routes from old about:debugging redirect to this Firefox");
     95  const { document, tab } = await openAboutDebugging();
     96 
     97  const routes = ["addons", "tabs", "workers"];
     98  for (const route of routes) {
     99    info("Move to setup page before testing the route");
    100    document.location.hash = "#/setup";
    101    await waitUntil(() => document.querySelector(".qa-connect-page"));
    102 
    103    info(`Check that navigating to ${route} redirects to This Firefox`);
    104    document.location.hash = route;
    105    await waitUntil(() => document.querySelector(".qa-runtime-page"));
    106    is(
    107      document.location.hash,
    108      "#/runtime/this-firefox",
    109      `${route} was redirected to This Firefox`
    110    );
    111  }
    112 
    113  await removeTab(tab);
    114 });