Bug 1516529 - Test that network runtime connections are also persisted;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 04 Jan 2019 12:44:57 +0000
changeset 509631 e03824ca4e747d46c26cb704f369eef3422ec035
parent 509630 b7593c6b7d1e474761f2947747585a48626e59b4
child 509632 1a25a39e7fb40462d2413acba6a689094d82c03b
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1516529
milestone66.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 1516529 - Test that network runtime connections are also persisted;r=daisuke Depends on D15409 Differential Revision: https://phabricator.services.mozilla.com/D15410
devtools/client/aboutdebugging-new/aboutdebugging.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_persist_connection.js
devtools/client/aboutdebugging-new/test/browser/head-mocks.js
--- a/devtools/client/aboutdebugging-new/aboutdebugging.js
+++ b/devtools/client/aboutdebugging-new/aboutdebugging.js
@@ -77,18 +77,18 @@ const AboutDebugging = {
       ),
       this.mount
     );
 
     this.onNetworkLocationsUpdated();
     addNetworkLocationsObserver(this.onNetworkLocationsUpdated);
 
     // Listen to USB runtime updates and retrieve the initial list of runtimes.
+    this.onUSBRuntimesUpdated();
     addUSBRuntimesObserver(this.onUSBRuntimesUpdated);
-    getUSBRuntimes();
 
     adbAddon.on("update", this.onAdbAddonUpdated);
     this.onAdbAddonUpdated();
 
     // Remove deprecated remote debugging extensions.
     await adbAddon.uninstallUnsupportedExtensions();
 
     addMultiE10sListener(this.onMultiE10sUpdated);
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_persist_connection.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_persist_connection.js
@@ -1,49 +1,72 @@
 /* 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 NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+const USB_RUNTIME_ID = "test-runtime-id";
+const USB_DEVICE_NAME = "test device name";
+const USB_APP_NAME = "TestApp";
 
 /* import-globals-from head-mocks.js */
 Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "head-mocks.js", this);
 
 // Test that remote runtime connections are persisted across about:debugging reloads.
 add_task(async function() {
   const mocks = new Mocks();
 
-  let { document, tab } = await openAboutDebugging();
+  info("Test with a USB runtime");
+  const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, {
+    name: USB_APP_NAME,
+    deviceName: USB_DEVICE_NAME,
+  });
+
+  await testRemoteClientPersistConnection(mocks, {
+    client: usbClient,
+    id: USB_RUNTIME_ID,
+    runtimeName: USB_APP_NAME,
+    sidebarName: USB_DEVICE_NAME,
+  });
 
-  const usbClient = mocks.createUSBRuntime(RUNTIME_ID, {
-    name: RUNTIME_APP_NAME,
-    deviceName: RUNTIME_DEVICE_NAME,
+  info("Test with a network runtime");
+  const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+    name: NETWORK_RUNTIME_APP_NAME,
   });
-  mocks.emitUSBUpdate();
 
-  await connectToRuntime(RUNTIME_DEVICE_NAME, document);
-  await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+  await testRemoteClientPersistConnection(mocks, {
+    client: networkClient,
+    id: NETWORK_RUNTIME_HOST,
+    runtimeName: NETWORK_RUNTIME_APP_NAME,
+    sidebarName: NETWORK_RUNTIME_HOST,
+  });
+});
+
+async function testRemoteClientPersistConnection(mocks,
+  { client, id, runtimeName, sidebarName }) {
+  info("Open about:debugging and connect to the test runtime");
+  let { document, tab } = await openAboutDebugging();
+  await connectToRuntime(sidebarName, document);
+  await selectRuntime(sidebarName, runtimeName, document);
 
   info("Reload about:debugging");
   document = await reloadAboutDebugging(tab);
-  mocks.emitUSBUpdate();
 
   info("Wait until the remote runtime appears as connected");
   await waitUntil(() => {
-    const sidebarItem = findSidebarItemByText(RUNTIME_DEVICE_NAME, document);
+    const sidebarItem = findSidebarItemByText(sidebarName, document);
     return sidebarItem && !sidebarItem.querySelector(".js-connect-button");
   });
 
   // Remove the runtime without emitting an update.
   // This is what happens today when we simply close Firefox for Android.
-  info("Remove the runtime from the list of USB runtimes");
-  mocks.removeUSBRuntime(RUNTIME_ID);
+  info("Remove the runtime from the list of remote runtimes");
+  mocks.removeRuntime(id);
 
   info("Emit 'closed' on the client and wait for the sidebar item to disappear");
-  usbClient._eventEmitter.emit("closed");
-  await waitUntil(() => !findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
+  client._eventEmitter.emit("closed");
+  await waitUntil(() => !findSidebarItemByText(sidebarName, document));
 
   info("Remove the tab");
   await removeTab(tab);
-});
+}
--- a/devtools/client/aboutdebugging-new/test/browser/head-mocks.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head-mocks.js
@@ -146,9 +146,17 @@ class Mocks {
 
     return mockUsbClient;
   }
 
   removeUSBRuntime(id) {
     this._usbRuntimes = this._usbRuntimes.filter(runtime => runtime.id !== id);
     delete this._clients[RUNTIMES.USB][id];
   }
+
+  removeRuntime(id) {
+    if (this._clients[RUNTIMES.USB][id]) {
+      this.removeUSBRuntime(id);
+    } else if (this._clients[RUNTIMES.NETWORK][id]) {
+      this.removeNetworkRuntime(id);
+    }
+  }
 }