tor-browser

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

browser_aboutdebugging_fenix_runtime_display.js (4485B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const RUNTIME_ID = "1337id";
      7 const DEVICE_NAME = "Fancy Phone";
      8 const SERVER_RUNTIME_NAME = "Mozilla Firefox";
      9 const ADB_RUNTIME_NAME = "Firefox Preview";
     10 const SERVER_VERSION = "v7.3.31";
     11 const ADB_VERSION = "v1.3.37";
     12 
     13 const FENIX_RELEASE_ICON_SRC =
     14  "chrome://devtools/skin/images/aboutdebugging-fenix.svg";
     15 const FENIX_NIGHTLY_ICON_SRC =
     16  "chrome://devtools/skin/images/aboutdebugging-fenix-nightly.svg";
     17 
     18 /**
     19 * Check that Fenix runtime information is correctly displayed in about:debugging.
     20 */
     21 add_task(async function () {
     22  const mocks = new Mocks();
     23  mocks.createUSBRuntime(RUNTIME_ID, {
     24    deviceName: DEVICE_NAME,
     25    isFenix: true,
     26    name: SERVER_RUNTIME_NAME,
     27    shortName: ADB_RUNTIME_NAME,
     28    versionName: ADB_VERSION,
     29    version: SERVER_VERSION,
     30  });
     31 
     32  // open a remote runtime page
     33  const { document, tab, window } = await openAboutDebugging();
     34  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     35 
     36  mocks.emitUSBUpdate();
     37  await connectToRuntime(DEVICE_NAME, document);
     38  await waitForRuntimePage(ADB_RUNTIME_NAME, document);
     39 
     40  info("Check that the runtime information is displayed as expected");
     41  const runtimeInfo = document.querySelector(".qa-runtime-name");
     42  ok(runtimeInfo, "Runtime info for the Fenix runtime is displayed");
     43  const runtimeInfoText = runtimeInfo.textContent;
     44 
     45  ok(runtimeInfoText.includes(ADB_RUNTIME_NAME), "Name is the ADB name");
     46  ok(
     47    !runtimeInfoText.includes(SERVER_RUNTIME_NAME),
     48    "Name does not include the server name"
     49  );
     50 
     51  ok(runtimeInfoText.includes(ADB_VERSION), "Version contains the ADB version");
     52  ok(
     53    !runtimeInfoText.includes(SERVER_VERSION),
     54    "Version does not contain the server version"
     55  );
     56 
     57  const runtimeIcon = document.querySelector(".qa-runtime-icon");
     58  is(
     59    runtimeIcon.src,
     60    FENIX_RELEASE_ICON_SRC,
     61    "The runtime icon is the Fenix icon"
     62  );
     63 
     64  info("Remove USB runtime");
     65  mocks.removeUSBRuntime(RUNTIME_ID);
     66  mocks.emitUSBUpdate();
     67  await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);
     68 
     69  await removeTab(tab);
     70 });
     71 
     72 /**
     73 * Check that Fenix runtime information is correctly displayed in about:devtools-toolbox.
     74 */
     75 add_task(async function () {
     76  // We use a real local client combined with a mocked USB runtime to be able to open
     77  // about:devtools-toolbox on a real target.
     78  const clientWrapper = await createLocalClientWrapper();
     79 
     80  const mocks = new Mocks();
     81  mocks.createUSBRuntime(RUNTIME_ID, {
     82    channel: "nightly",
     83    clientWrapper,
     84    deviceName: DEVICE_NAME,
     85    isFenix: true,
     86    name: SERVER_RUNTIME_NAME,
     87    shortName: ADB_RUNTIME_NAME,
     88    versionName: ADB_VERSION,
     89    version: SERVER_VERSION,
     90  });
     91 
     92  // open a remote runtime page
     93  const { document, tab, window } = await openAboutDebugging();
     94  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     95 
     96  mocks.emitUSBUpdate();
     97  info("Select the runtime page for the USB runtime");
     98  const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store);
     99  await connectToRuntime(DEVICE_NAME, document);
    100  await waitForRuntimePage(ADB_RUNTIME_NAME, document);
    101  info(
    102    "Wait for requests to finish the USB runtime is backed by a real local client"
    103  );
    104  await onRequestSuccess;
    105 
    106  info("Wait for the about:debugging target to be available");
    107  await waitUntil(() => findDebugTargetByText("about:debugging", document));
    108  const { devtoolsDocument, devtoolsTab } = await openAboutDevtoolsToolbox(
    109    document,
    110    tab,
    111    window
    112  );
    113 
    114  const runtimeInfo = devtoolsDocument.querySelector(".qa-runtime-info");
    115  const runtimeInfoText = runtimeInfo.textContent;
    116  ok(
    117    runtimeInfoText.includes(ADB_RUNTIME_NAME),
    118    "Name is the ADB runtime name"
    119  );
    120  ok(runtimeInfoText.includes(ADB_VERSION), "Version is the ADB version");
    121 
    122  const runtimeIcon = devtoolsDocument.querySelector(".qa-runtime-icon");
    123  is(
    124    runtimeIcon.src,
    125    FENIX_NIGHTLY_ICON_SRC,
    126    "The runtime icon is the Fenix icon"
    127  );
    128 
    129  info("Wait for all pending requests to settle on the DevToolsClient");
    130  await clientWrapper.client.waitForRequestsToSettle();
    131 
    132  await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
    133 
    134  info("Remove USB runtime");
    135  mocks.removeUSBRuntime(RUNTIME_ID);
    136  mocks.emitUSBUpdate();
    137  await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);
    138 
    139  await removeTab(tab);
    140  await clientWrapper.close();
    141 });