Bug 1489224 - Add mochitest to check runtimes section of aboudebugging sidebar;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 21 Sep 2018 14:38:16 +0000
changeset 438160 573a32cebe76bbfc55ffc307abb907fb8a39d6bd
parent 438159 a581d5bc795d34939e62686011df09385d24e627
child 438161 6e2aaef654b01aa7eca017a24819899ca2468521
push id34711
push useraciure@mozilla.com
push dateTue, 25 Sep 2018 21:49:34 +0000
treeherdermozilla-central@2e3e89c9c68c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1489224
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 1489224 - Add mochitest to check runtimes section of aboudebugging sidebar;r=daisuke Differential Revision: https://phabricator.services.mozilla.com/D6402
devtools/client/aboutdebugging-new/src/components/sidebar/Sidebar.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js
--- a/devtools/client/aboutdebugging-new/src/components/sidebar/Sidebar.js
+++ b/devtools/client/aboutdebugging-new/src/components/sidebar/Sidebar.js
@@ -32,17 +32,17 @@ class Sidebar extends PureComponent {
   renderDevices() {
     const { dispatch, runtimes, selectedPage } = this.props;
     if (!runtimes.networkRuntimes.length && !runtimes.usbRuntimes.length) {
       return Localized(
         {
           id: "about-debugging-sidebar-no-devices"
         }, dom.span(
           {
-            className: "sidebar__devices__no-devices-message"
+            className: "sidebar__devices__no-devices-message js-sidebar-no-devices"
           },
           "No devices discovered"
         )
       );
     }
 
     return [
       ...runtimes.networkRuntimes.map(runtime => {
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -5,9 +5,10 @@ support-files =
   debug-target-pane_collapsibilities_head.js
   head.js
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
 [browser_aboutdebugging_connect_networklocations.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
+[browser_aboutdebugging_sidebar_network_runtimes.js]
 [browser_aboutdebugging_thisfirefox.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js
@@ -0,0 +1,47 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const networkLocationsModule =
+  require("devtools/client/aboutdebugging-new/src/modules/network-locations.js");
+
+/**
+ * Test the sidebar is updated correctly when network runtimes are added/removed.
+ */
+
+add_task(async function() {
+  registerCleanupFunction(() => {
+    Services.prefs.clearUserPref("devtools.aboutdebugging.network-locations");
+  });
+
+  const { document, tab } = await openAboutDebugging();
+
+  const noDevicesElement = document.querySelector(".js-sidebar-no-devices");
+  ok(noDevicesElement, "Sidebar shows the 'no devices' element");
+
+  info("Add a network location");
+  networkLocationsModule.addNetworkLocation("localhost:6080");
+
+  info("Wait for 'no devices' element to disappear");
+  waitUntil(() => !document.querySelector(".js-sidebar-no-devices"));
+  ok(findSidebarItemByText("localhost:6080", document),
+    "Found a sidebar item for localhost:6080");
+
+  info("Remove the network location");
+  networkLocationsModule.removeNetworkLocation("localhost:6080");
+
+  info("Wait for 'no devices' element to reappear");
+  waitUntil(() => document.querySelector(".js-sidebar-no-devices"));
+  ok(!findSidebarItemByText("localhost:6080", document),
+    "Sidebar item for localhost:6080 removed");
+
+  await removeTab(tab);
+});
+
+function findSidebarItemByText(text, document) {
+  const sidebarItems = document.querySelectorAll(".js-sidebar-item");
+  return [...sidebarItems].find(element => {
+    return element.textContent.includes(text);
+  });
+}