Bug 1505289 - Add test for unplugged USB runtimes r=ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 15 Apr 2019 22:26:06 +0000
changeset 469623 5b4e9571635e
parent 469622 c3aea0459e5c
child 469624 630d6ce9c7b0
push id35878
push userapavel@mozilla.com
push dateTue, 16 Apr 2019 15:43:40 +0000
treeherdermozilla-central@258af4e91151 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko
bugs1505289
milestone68.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 1505289 - Add test for unplugged USB runtimes r=ladybenko Depends on D25783 Differential Revision: https://phabricator.services.mozilla.com/D25784
devtools/client/aboutdebugging-new/src/components/sidebar/SidebarRuntimeItem.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_unknown_runtime.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_unplugged_device.js
devtools/client/aboutdebugging-new/test/browser/head.js
--- a/devtools/client/aboutdebugging-new/src/components/sidebar/SidebarRuntimeItem.js
+++ b/devtools/client/aboutdebugging-new/src/components/sidebar/SidebarRuntimeItem.js
@@ -110,23 +110,26 @@ class SidebarRuntimeItem extends PureCom
         dom.p({ className: "word-wrap-anywhere" }, localizationId)
       )
     );
   }
 
   renderName() {
     const { deviceName, getString, isUnknown, isUnplugged, name } = this.props;
 
-    let displayName;
+    let displayName, qaClassName;
     if (isUnplugged) {
       displayName = getString("about-debugging-sidebar-runtime-item-unplugged");
+      qaClassName = "qa-runtime-item-unplugged";
     } else if (isUnknown) {
       displayName = getString("about-debugging-sidebar-runtime-item-waiting-for-browser");
+      qaClassName = "qa-runtime-item-waiting-for-browser";
     } else {
       displayName = name;
+      qaClassName = "qa-runtime-item-standard";
     }
 
     const localizationId = deviceName
       ? "about-debugging-sidebar-runtime-item-name"
       : "about-debugging-sidebar-runtime-item-name-no-device";
 
     const className = "ellipsis-text sidebar-runtime-item__runtime";
 
@@ -135,17 +138,17 @@ class SidebarRuntimeItem extends PureCom
         {
           className,
           title: localizationId,
         },
         deviceName,
         dom.br({}),
         dom.span(
           {
-            className: "sidebar-runtime-item__runtime__details",
+            className: `sidebar-runtime-item__runtime__details ${qaClassName}`,
           },
           displayName,
         ),
       );
     }
 
     function renderNoDevice() {
       return dom.span(
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -96,16 +96,17 @@ skip-if = debug || asan # Frequent inter
 [browser_aboutdebugging_sidebar_network_runtimes.js]
 [browser_aboutdebugging_sidebar_usb_runtime.js]
 [browser_aboutdebugging_sidebar_usb_runtime_connect.js]
 [browser_aboutdebugging_sidebar_usb_runtime_refresh.js]
 [browser_aboutdebugging_sidebar_usb_runtime_select.js]
 [browser_aboutdebugging_sidebar_usb_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_sidebar_usb_unknown_runtime.js]
+[browser_aboutdebugging_sidebar_usb_unplugged_device.js]
 [browser_aboutdebugging_system_addons.js]
 [browser_aboutdebugging_tab_favicons.js]
 [browser_aboutdebugging_telemetry_basic.js]
 [browser_aboutdebugging_telemetry_inspect.js]
 [browser_aboutdebugging_telemetry_navigate.js]
 [browser_aboutdebugging_telemetry_runtime_actions.js]
 [browser_aboutdebugging_telemetry_runtime_connected_details.js]
 [browser_aboutdebugging_telemetry_runtime_updates.js]
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_unknown_runtime.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_unknown_runtime.js
@@ -20,19 +20,18 @@ add_task(async function() {
   mocks.addDevice(DEVICE_ID, DEVICE_NAME);
   mocks.emitUSBUpdate();
 
   info("Wait until the USB sidebar item appears");
   await waitUntil(() => findSidebarItemByText(DEVICE_NAME, document));
 
   const usbRuntimeSidebarItem = findSidebarItemByText(DEVICE_NAME, document);
 
-  const itemText = usbRuntimeSidebarItem.textContent;
-  ok(itemText.includes("Waiting for browser"), "Sidebar item shows Waiting for browser");
-  ok(!itemText.includes(RUNTIME_NAME), "Sidebar item does not show the runtime name");
+  ok(usbRuntimeSidebarItem.querySelector(".qa-runtime-item-waiting-for-browser"),
+    "Sidebar item shows as `Waiting for browser`");
 
   const hasConnectButton = usbRuntimeSidebarItem.querySelector(".js-connect-button");
   ok(!hasConnectButton, "Connect button is not displayed");
 
   const hasLink = usbRuntimeSidebarItem.querySelector(".js-sidebar-link");
   ok(!hasLink, "Unknown runtime is not selectable");
 
   info("Add a valid runtime for the same device id and emit update event");
@@ -46,13 +45,13 @@ add_task(async function() {
 
   info("Wait until connect button appears for the USB runtime");
   let updatedSidebarItem = null;
   await waitUntil(() => {
     updatedSidebarItem = findSidebarItemByText(DEVICE_NAME, document);
     return updatedSidebarItem && updatedSidebarItem.querySelector(".js-connect-button");
   });
 
-  const updatedText = updatedSidebarItem.textContent;
-  ok(updatedText.includes(RUNTIME_NAME), "Sidebar item shows the runtime name");
+  ok(updatedSidebarItem.querySelector(".qa-runtime-item-standard"),
+    "Sidebar item for the USB runtime is now a standard sidebar item");
 
   await removeTab(tab);
 });
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_unplugged_device.js
@@ -0,0 +1,61 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_NAME = "RUNTIME_NAME_1";
+const DEVICE_NAME = "DEVICE_NAME_1";
+const DEVICE_ID = "DEVICE_ID_1";
+const RUNTIME_ID = "RUNTIME_ID_1";
+
+const RUNTIME_NAME_2 = "RUNTIME_NAME_2";
+const DEVICE_NAME_2 = "DEVICE_NAME_2";
+const DEVICE_ID_2 = "DEVICE_ID_2";
+const RUNTIME_ID_2 = "RUNTIME_ID_2";
+
+// Test that removed USB devices are still visible as "Unplugged devices", until
+// about:debugging is reloaded.
+add_task(async function() {
+  const mocks = new Mocks();
+  let { document, tab } = await openAboutDebugging();
+
+  info("Create a mocked USB runtime");
+  mocks.createUSBRuntime(RUNTIME_ID, {
+    deviceId: DEVICE_ID,
+    deviceName: DEVICE_NAME,
+    shortName: RUNTIME_NAME,
+  });
+  mocks.emitUSBUpdate();
+
+  info("Wait until the USB sidebar item appears");
+  await waitUntil(() => findSidebarItemByText(DEVICE_NAME, document));
+  const sidebarItem = findSidebarItemByText(DEVICE_NAME, document);
+  ok(sidebarItem.textContent.includes(RUNTIME_NAME),
+    "Sidebar item shows the runtime name");
+
+  mocks.removeUSBRuntime(RUNTIME_ID);
+  mocks.emitUSBUpdate();
+  await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);
+
+  const unpluggedItem = findSidebarItemByText(DEVICE_NAME, document);
+  ok(unpluggedItem.querySelector(".qa-runtime-item-unplugged"),
+    "Sidebar item is shown as `Unplugged…`");
+
+  info("Reload about:debugging");
+  document = await reloadAboutDebugging(tab);
+
+  info("Add another mocked USB runtime, to make sure the sidebar items are rendered.");
+  mocks.createUSBRuntime(RUNTIME_ID_2, {
+    deviceId: DEVICE_ID_2,
+    deviceName: DEVICE_NAME_2,
+    shortName: RUNTIME_NAME_2,
+  });
+  mocks.emitUSBUpdate();
+
+  info("Wait until the other USB sidebar item appears");
+  await waitUntil(() => findSidebarItemByText(DEVICE_NAME_2, document));
+  ok(!findSidebarItemByText(DEVICE_NAME, document),
+    "Unplugged device is no longer displayed after reloading aboutdebugging");
+
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -312,12 +312,11 @@ function getThisFirefoxString(aboutDebug
   const { l10n } = loader.require("devtools/client/aboutdebugging-new/src/modules/l10n");
   return l10n.getString("about-debugging-this-firefox-runtime-name");
 }
 
 function waitUntilUsbDeviceIsUnplugged(deviceName, aboutDebuggingDocument) {
   info("Wait until the USB sidebar item appears as unplugged");
   return waitUntil(() => {
     const sidebarItem = findSidebarItemByText(deviceName, aboutDebuggingDocument);
-    const isUnplugged = sidebarItem.textContent.includes("Unplugged");
-    return isUnplugged;
+    return !!sidebarItem.querySelector(".qa-runtime-item-unplugged");
   });
 }