Bug 1498469 - Part 2: Add test for the feature r=jdescottes,daisuke
authorBelén Albeza <balbeza@mozilla.com>
Tue, 23 Apr 2019 12:09:26 +0000
changeset 470474 512231282d5f08fbf997840fc66c968a9ebaac75
parent 470473 913c397010c2c9ba8ba0f28a1eae5e30e410dbe9
child 470475 401f2be1ced14464292c27ac0a563650ecd3f8c0
push id35906
push useraciure@mozilla.com
push dateTue, 23 Apr 2019 22:14:56 +0000
treeherdermozilla-central@0ce3633f8b80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes, daisuke
bugs1498469
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 1498469 - Part 2: Add test for the feature r=jdescottes,daisuke Differential Revision: https://phabricator.services.mozilla.com/D27927
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_status.js
devtools/client/aboutdebugging-new/test/browser/helper-mocks.js
devtools/client/aboutdebugging-new/test/browser/mocks/helper-adb-mock.js
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -97,17 +97,16 @@ skip-if = debug || asan # Frequent inter
 [browser_aboutdebugging_serviceworker_unregister.js]
 [browser_aboutdebugging_sidebar_connection_state.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_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_unavailable_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]
--- 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
@@ -1,43 +1,44 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-/* import-globals-from helper-adb.js */
-Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-adb.js", this);
-
 const { adbAddon } = require("devtools/shared/adb/adb-addon");
 
 /**
  * This test asserts that the sidebar shows a message describing the status of the USB
  * devices scanning.
  */
 add_task(async function() {
+  const mocks = new Mocks();
+
   await pushPref("devtools.remote.adb.extensionURL",
                  CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi");
-  await checkAdbNotRunning();
-
   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 disabled"),
-    "USB status element has the expected content");
+    "USB status element has 'disabled' content");
 
   info("Install the adb extension and wait for the message to udpate");
   // Use "internal" as the install source to avoid triggering telemetry.
   adbAddon.install("internal");
-  await waitUntil(() => usbStatusElement.textContent.includes("USB enabled"));
-  // Right now we are resuming as soon as "USB 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.
-  await waitForAdbStart();
+  // When using mocks, we manually control the .start() call
+  await mocks.adbProcessMock.adbProcess.start();
 
-  info("Uninstall the adb extension and wait for the message to udpate");
+  info("Wait till the USB status element has 'enabled' content");
+  await waitUntil(() => {
+    const el = document.querySelector(".js-sidebar-usb-status");
+    return el.textContent.includes("USB enabled");
+  });
+
+  info("Uninstall the adb extension and wait for USB status element to update");
   adbAddon.uninstall();
-  await waitUntil(() => usbStatusElement.textContent.includes("USB disabled"));
-  await stopAdbProcess();
+  await waitUntil(() => {
+    const el = document.querySelector(".js-sidebar-usb-status");
+    return el.textContent.includes("USB disabled");
+  });
 
   await removeTab(tab);
 });
--- a/devtools/client/aboutdebugging-new/test/browser/helper-mocks.js
+++ b/devtools/client/aboutdebugging-new/test/browser/helper-mocks.js
@@ -20,16 +20,17 @@ const { RUNTIMES } = require("devtools/c
  * This wrapper around the mocks used in about:debugging tests provides helpers to
  * quickly setup mocks for runtime tests involving USB, network or wifi runtimes that can
  * are difficult to setup in a test environment.
  */
 class Mocks {
   constructor() {
     // Setup the adb mock to rely on internal arrays.
     this.adbMock = createAdbMock();
+    this.adbProcessMock = createAdbProcessMock();
     this._usbRuntimes = [];
     this._usbDevices = [];
     this.adbMock.adb.getRuntimes = () => {
       return this._usbRuntimes;
     };
     this.adbMock.adb.getDevices = () => {
       const runtimeDevices = this._usbRuntimes.map(r => {
         return { id: r.deviceId, name: r.deviceName };
@@ -67,21 +68,23 @@ class Mocks {
   }
 
   get thisFirefoxClient() {
     return this._thisFirefoxClient;
   }
 
   enableMocks() {
     enableAdbMock(this.adbMock);
+    enableAdbProcessMock(this.adbProcessMock);
     enableRuntimeClientFactoryMock(this.runtimeClientFactoryMock);
   }
 
   disableMocks() {
     disableAdbMock();
+    disableAdbProcessMock();
     disableRuntimeClientFactoryMock();
 
     for (const host of Object.keys(this._clients[RUNTIMES.NETWORK])) {
       this.removeNetworkRuntime(host);
     }
   }
 
   createNetworkRuntime(host, runtimeInfo) {
--- a/devtools/client/aboutdebugging-new/test/browser/mocks/helper-adb-mock.js
+++ b/devtools/client/aboutdebugging-new/test/browser/mocks/helper-adb-mock.js
@@ -81,8 +81,38 @@ function addObserverMock(adbMock) {
   // NOTE FOR REVIEW: Instead of emitting "runtime-list-updated" events in the test,
   // this mock could have a emitObservedEvent method, that would just emit the correct
   // event. This way if the event name changes, everything remains contained in this
   // method.
 
   return observerMock;
 }
 /* exported addObserverMock */
+
+function createAdbProcessMock() {
+  const EventEmitter = require("devtools/shared/event-emitter");
+
+  const mock = {};
+  EventEmitter.decorate(mock);
+
+  mock.ready = false;
+
+  mock.start = async () => {
+    console.log("MOCKED METHOD start");
+    mock.ready = true;
+    mock.emit("adb-ready");
+  };
+
+  return { adbProcess: mock };
+}
+/* exported createAdbProcessMock */
+
+function enableAdbProcessMock(mock) {
+  const { setMockedModule } = require("devtools/client/shared/browser-loader-mocks");
+  setMockedModule(mock, "devtools/shared/adb/adb-process");
+}
+/* exported enableAdbProcessMock */
+
+function disableAdbProcessMock() {
+  const { removeMockedModule } = require("devtools/client/shared/browser-loader-mocks");
+  removeMockedModule("devtools/shared/adb/adb-process");
+}
+/* exported disableAdbProcessMock */