Bug 1488506 - Add mochitest for enable/disable USB debugging in Connect page;r=ladybenko,daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 18 Oct 2018 14:34:15 +0000
changeset 500397 cac4aff89a39a7df33305397268510e8c7d2d840
parent 500396 97207813052bd7a33c671422198b5d1e43adab49
child 500398 c597d36a2d7ac1b32de3d57054a87176737ae814
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko, daisuke
bugs1488506
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1488506 - Add mochitest for enable/disable USB debugging in Connect page;r=ladybenko,daisuke Depends on D8556 Differential Revision: https://phabricator.services.mozilla.com/D8557
devtools/client/aboutdebugging-new/src/components/connect/ConnectPage.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connect_networklocations.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connect_toggle_usb_devices.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_status.js
devtools/client/aboutdebugging-new/test/browser/head.js
--- a/devtools/client/aboutdebugging-new/src/components/connect/ConnectPage.js
+++ b/devtools/client/aboutdebugging-new/src/components/connect/ConnectPage.js
@@ -98,17 +98,18 @@ class ConnectPage extends PureComponent 
     const disabled = usbStatus === USB_STATES.UPDATING_USB;
 
     return Localized(
       {
         id: localizedState
       },
       dom.button(
         {
-          className: "std-button connect-page__usb__toggle-button",
+          className: "std-button connect-page__usb__toggle-button " +
+                     "js-connect-usb-toggle-button",
           disabled,
           onClick: () => this.onToggleUSBClick(),
         },
         localizedState
       )
     );
   }
 
@@ -133,17 +134,19 @@ class ConnectPage extends PureComponent 
               getString("about-debugging-connect-usb-step-plug-device"),
             ]
           }) :
           Localized(
             {
               id: "about-debugging-connect-usb-disabled",
             },
             dom.aside(
-              {},
+              {
+                className: "js-connect-usb-disabled-message"
+              },
               "Enabling this will download and add the required Android USB debugging " +
               "components to Firefox."
             )
           )
         ),
         this.renderUsbToggleButton()
       )
     );
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -6,16 +6,18 @@ support-files =
   head-addons-script.js
   head.js
   resources/test-adb-extension/*
   resources/test-temporary-extension/*
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
 [browser_aboutdebugging_connect_networklocations.js]
+[browser_aboutdebugging_connect_toggle_usb_devices.js]
+skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
 [browser_aboutdebugging_debug-target-pane_empty.js]
 [browser_aboutdebugging_navigate.js]
 [browser_aboutdebugging_sidebar_network_runtimes.js]
 [browser_aboutdebugging_sidebar_usb_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_thisfirefox.js]
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connect_networklocations.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connect_networklocations.js
@@ -8,27 +8,17 @@
  * Check that a network location can be added and removed.
  */
 
 const TEST_NETWORK_LOCATION = "localhost:1111";
 
 add_task(async function() {
   const { document, tab } = await openAboutDebugging();
 
-  const sidebarItems = document.querySelectorAll(".js-sidebar-item");
-  const connectSidebarItem = [...sidebarItems].find(element => {
-    return element.textContent === "Connect";
-  });
-  ok(connectSidebarItem, "Sidebar contains a Connect item");
-
-  info("Click on the Connect item in the sidebar");
-  connectSidebarItem.click();
-
-  info("Wait until Connect page is displayed");
-  await waitUntil(() => document.querySelector(".js-connect-page"));
+  await selectConnectPage(document);
 
   let networkLocations = document.querySelectorAll(".js-network-location");
   is(networkLocations.length, 0, "By default, no network locations are displayed");
 
   addNetworkLocation(TEST_NETWORK_LOCATION, document);
 
   info("Wait until the new network location is visible in the list");
   await waitUntil(() => document.querySelectorAll(".js-network-location").length === 1);
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connect_toggle_usb_devices.js
@@ -0,0 +1,55 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { ADB } = require("devtools/shared/adb/adb");
+
+/**
+ * Check that USB Devices scanning can be enabled and disabled from the connect page.
+ */
+add_task(async function() {
+  await pushPref("devtools.remote.adb.extensionURL",
+                 CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi");
+
+  const { document, tab } = await openAboutDebugging();
+
+  await selectConnectPage(document);
+
+  info("Wait until Connect page is displayed");
+  await waitUntil(() => document.querySelector(".js-connect-page"));
+
+  info("Check that by default USB devices are disabled");
+  const usbDisabledMessage = document.querySelector(".js-connect-usb-disabled-message");
+  ok(usbDisabledMessage, "A message about enabling USB devices is rendered");
+
+  const usbToggleButton = document.querySelector(".js-connect-usb-toggle-button");
+  ok(usbToggleButton, "The button to toggle USB devices debugging is rendered");
+  ok(usbToggleButton.textContent.includes("Enable"),
+    "The text of the toggle USB button is correct");
+
+  info("Click on the toggle button");
+  usbToggleButton.click();
+
+  info("Wait until the toggle button text is updated");
+  await waitUntil(() => usbToggleButton.textContent.includes("Disable"));
+  ok(!document.querySelector(".js-connect-usb-disabled-message"),
+    "The message about enabling USB devices is no longer rendered");
+
+  // Right now we are resuming as soon as "USB devices enabled" is displayed, but ADB
+  // might still be starting up. If we move to uninstall directly, the ADB startup will
+  // fail and we will have an unhandled promise rejection.
+  // See Bug 1498469.
+  info("Wait until ADB has started.");
+  await waitUntil(() => ADB.ready);
+
+  info("Click on the toggle button");
+  usbToggleButton.click();
+
+  info("Wait until the toggle button text is updated");
+  await waitUntil(() => usbToggleButton.textContent.includes("Enable"));
+  ok(document.querySelector(".js-connect-usb-disabled-message"),
+    "The message about enabling USB devices is rendered again");
+
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_status.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_status.js
@@ -6,27 +6,16 @@
 const { adbAddon } = require("devtools/shared/adb/adb-addon");
 const { ADB } = require("devtools/shared/adb/adb");
 
 /**
  * This test asserts that the sidebar shows a message describing the status of the USB
  * devices scanning.
  */
 add_task(async function() {
-  // Make sure the ADB addon is removed and ADB is stopped when the test ends.
-  registerCleanupFunction(async function() {
-    try {
-      await adbAddon.uninstall();
-    } catch (e) {
-      // Will throw if the addon is already uninstalled, ignore exceptions here.
-    }
-
-    await ADB.kill();
-  });
-
   await pushPref("devtools.remote.adb.extensionURL",
                  CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi");
 
   const { document, tab } = await openAboutDebugging();
 
   const usbStatusElement = document.querySelector(".js-sidebar-usb-status");
   ok(usbStatusElement, "Sidebar shows the USB status element");
   ok(usbStatusElement.textContent.includes("USB devices disabled"),
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -12,16 +12,28 @@
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
   this);
 
 // Load collapsibilities helpers
 Services.scriptloader.loadSubScript(
   CHROME_URL_ROOT + "debug-target-pane_collapsibilities_head.js", this);
 
+// Make sure the ADB addon is removed and ADB is stopped when the test ends.
+registerCleanupFunction(async function() {
+  try {
+    const { adbAddon } = require("devtools/shared/adb/adb-addon");
+    await adbAddon.uninstall();
+  } catch (e) {
+    // Will throw if the addon is already uninstalled, ignore exceptions here.
+  }
+  const { ADB } = require("devtools/shared/adb/adb");
+  await ADB.kill();
+});
+
 /**
  * Enable the new about:debugging panel.
  */
 async function enableNewAboutDebugging() {
   await pushPref("devtools.aboutdebugging.new-enabled", true);
 }
 
 async function openAboutDebugging(page, win) {
@@ -37,14 +49,31 @@ async function openAboutDebugging(page, 
   await waitUntil(() => document.querySelector(".app"));
 
   info("Wait until the client connection was established");
   await waitUntil(() => document.querySelector(".js-runtime-page"));
 
   return { tab, document, window };
 }
 
+/**
+ * Navigate to the Connect page. Resolves when the Connect page is rendered.
+ */
+async function selectConnectPage(doc) {
+  const sidebarItems = doc.querySelectorAll(".js-sidebar-item");
+  const connectSidebarItem = [...sidebarItems].find(element => {
+    return element.textContent === "Connect";
+  });
+  ok(connectSidebarItem, "Sidebar contains a Connect item");
+
+  info("Click on the Connect item in the sidebar");
+  connectSidebarItem.click();
+
+  info("Wait until Connect page is displayed");
+  await waitUntil(() => doc.querySelector(".js-connect-page"));
+}
+
 function findSidebarItemByText(text, document) {
   const sidebarItems = document.querySelectorAll(".js-sidebar-item");
   return [...sidebarItems].find(element => {
     return element.textContent.includes(text);
   });
 }