Bug 1503914 - Add mochitest to check that USB runtimes are not disconnected on refresh;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 14 Nov 2018 03:57:38 +0000
changeset 446558 85d893b168424ecc49fe597c45fd89dd53b8925f
parent 446557 b97a83e789c28e4d10c67ce92d79a262d225caf5
child 446559 acb7047f9492ce3d9fc299f0fbecf1f9c53a5ff9
push id35043
push userebalazs@mozilla.com
push dateThu, 15 Nov 2018 16:12:36 +0000
treeherdermozilla-central@59026ada59bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1503914
milestone65.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 1503914 - Add mochitest to check that USB runtimes are not disconnected on refresh;r=daisuke Depends on D11798 Differential Revision: https://phabricator.services.mozilla.com/D11799
devtools/client/aboutdebugging-new/src/components/sidebar/RefreshDevicesButton.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
devtools/client/aboutdebugging-new/test/browser/mocks/head-usb-runtimes-mock.js
--- a/devtools/client/aboutdebugging-new/src/components/sidebar/RefreshDevicesButton.js
+++ b/devtools/client/aboutdebugging-new/src/components/sidebar/RefreshDevicesButton.js
@@ -25,17 +25,17 @@ class RefreshDevicesButton extends PureC
     this.props.dispatch(Actions.scanUSBRuntimes());
   }
 
   render() {
     return Localized(
       { id: "about-debugging-refresh-usb-devices-button" },
       dom.button(
         {
-          className: "default-button",
+          className: "default-button js-refresh-devices-button",
           disabled: this.props.isScanning,
           onClick: () => this.refreshDevices(),
         },
         "Refresh devices"
       )
     );
   }
 }
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -21,12 +21,13 @@ skip-if = (os == 'linux' && bits == 32) 
 [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_debug-target-pane_usb_runtime.js]
 [browser_aboutdebugging_navigate.js]
 [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_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_tab_favicons.js]
 [browser_aboutdebugging_thisfirefox.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_DEVICE_NAME = "test device name";
+const RUNTIME_APP_NAME = "TestApp";
+
+const OTHER_RUNTIME_ID = "other-runtime-id";
+const OTHER_RUNTIME_APP_NAME = "OtherApp";
+
+/* import-globals-from mocks/head-usb-mocks.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "mocks/head-usb-mocks.js", this);
+
+// Test that USB runtimes are ot disconnected on refresh.
+add_task(async function() {
+  const usbMocks = new UsbMocks();
+  usbMocks.enableMocks();
+  registerCleanupFunction(() => usbMocks.disableMocks());
+
+  const { document, tab } = await openAboutDebugging();
+
+  info("Create a first runtime and connect to it");
+  usbMocks.createRuntime(RUNTIME_ID, {
+    appName: RUNTIME_APP_NAME,
+    deviceName: RUNTIME_DEVICE_NAME,
+  });
+  usbMocks.emitUpdate();
+
+  await connectToRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+
+  info("Create a second runtime and click on Refresh Devices");
+  usbMocks.createRuntime(OTHER_RUNTIME_ID, {
+    deviceName: OTHER_RUNTIME_APP_NAME,
+  });
+
+  // Mock the refreshUSBRuntimes to emit an update.
+  usbMocks.usbRuntimesMock.refreshUSBRuntimes = () => usbMocks.emitUpdate();
+  document.querySelector(".js-refresh-devices-button").click();
+
+  info(`Wait until the sidebar item for ${OTHER_RUNTIME_APP_NAME} appears`);
+  await waitUntil(() => findSidebarItemByText(OTHER_RUNTIME_APP_NAME, document));
+
+  const sidebarItem = findSidebarItemByText(RUNTIME_DEVICE_NAME, document);
+  ok(!sidebarItem.querySelector(".js-connect-button"),
+    "Original USB runtime is still connected");
+
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/mocks/head-usb-runtimes-mock.js
+++ b/devtools/client/aboutdebugging-new/test/browser/mocks/head-usb-runtimes-mock.js
@@ -46,16 +46,20 @@ function createUsbRuntimesMock() {
   usbRuntimesMock.enableUSBRuntimes = function() {
     console.log("MOCKED METHOD enableUSBRuntimes");
   };
 
   usbRuntimesMock.getUSBRuntimes = function() {
     console.log("MOCKED METHOD getUSBRuntimes");
   };
 
+  usbRuntimesMock.refreshUSBRuntimes = function() {
+    console.log("MOCKED METHOD refreshUSBRuntimes");
+  };
+
   usbRuntimesMock.removeUSBRuntimesObserver = function(listener) {
     console.log("MOCKED METHOD removeUSBRuntimesObserver");
   };
 
   return usbRuntimesMock;
 }
 
 /**