tor-browser

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

browser_aboutdebugging_connect_toggle_usb_devices.js (2647B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /* import-globals-from helper-adb.js */
      7 Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-adb.js", this);
      8 
      9 /**
     10 * Check that USB Devices scanning can be enabled and disabled from the connect page.
     11 */
     12 add_task(async function () {
     13  await pushPref(
     14    "devtools.remote.adb.extensionURL",
     15    CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi"
     16  );
     17  await checkAdbNotRunning();
     18 
     19  const { document, tab } = await openAboutDebugging();
     20 
     21  await selectConnectPage(document);
     22 
     23  info("Wait until Connect page is displayed");
     24  await waitUntil(() => document.querySelector(".qa-connect-page"));
     25 
     26  info("Check that by default USB devices are disabled");
     27  const usbDisabledMessage = document.querySelector(
     28    ".qa-connect-usb-disabled-message"
     29  );
     30  ok(usbDisabledMessage, "A message about enabling USB devices is rendered");
     31 
     32  const usbToggleButton = document.querySelector(
     33    ".qa-connect-usb-toggle-button"
     34  );
     35  ok(usbToggleButton, "The button to toggle USB devices debugging is rendered");
     36  ok(
     37    usbToggleButton.textContent.includes("Enable"),
     38    "The text of the toggle USB button is correct"
     39  );
     40 
     41  info("Click on the toggle button");
     42  usbToggleButton.click();
     43 
     44  info("Wait until the toggle button text is updated");
     45  await waitUntil(() => usbToggleButton.textContent.includes("Disable"));
     46  ok(
     47    !document.querySelector(".qa-connect-usb-disabled-message"),
     48    "The message about enabling USB devices is no longer rendered"
     49  );
     50 
     51  info("Check that the addon was installed with the proper source");
     52  const adbExtensionId = Services.prefs.getCharPref(
     53    "devtools.remote.adb.extensionID"
     54  );
     55  const addon = await AddonManager.getAddonByID(adbExtensionId);
     56  Assert.deepEqual(
     57    addon.installTelemetryInfo,
     58    { source: "about:debugging" },
     59    "Got the expected addon.installTelemetryInfo"
     60  );
     61 
     62  // Right now we are resuming as soon as "USB enabled" is displayed, but ADB
     63  // might still be starting up. If we move to uninstall directly, the ADB startup will
     64  // fail and we will have an unhandled promise rejection.
     65  // See Bug 1498469.
     66  await waitForAdbStart();
     67 
     68  info("Click on the toggle button");
     69  usbToggleButton.click();
     70 
     71  info("Wait until the toggle button text is updated");
     72  await waitUntil(() => usbToggleButton.textContent.includes("Enable"));
     73  ok(
     74    document.querySelector(".qa-connect-usb-disabled-message"),
     75    "The message about enabling USB devices is rendered again"
     76  );
     77 
     78  await stopAdbProcess();
     79 
     80  await removeTab(tab);
     81 });