Bug 1508307 - Rollback getDeviceDescription change and add test for this-firefox mock;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 23 Nov 2018 08:11:41 +0000
changeset 504230 4afd2f3b8f33bf61287313fdfa609a325386dd06
parent 504229 0f57247530fd990832fd1e3a50d11c25c21b86ac
child 504231 a52096a533cb182c987a3752e6622eadddaab121
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1508307
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 1508307 - Rollback getDeviceDescription change and add test for this-firefox mock;r=daisuke Changed my mind about getDeviceDescription :) I think it is better to remain explicit and to always say which properties we are exporting. I also added a small test for the this-firefox mock to avoid future regressions. Differential Revision: https://phabricator.services.mozilla.com/D12318
devtools/client/aboutdebugging-new/src/actions/runtimes.js
devtools/client/aboutdebugging-new/src/modules/client-wrapper.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_usb_runtime.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_thisfirefox_runtime_info.js
devtools/client/aboutdebugging-new/test/browser/mocks/head-usb-mocks.js
--- a/devtools/client/aboutdebugging-new/src/actions/runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/actions/runtimes.js
@@ -35,17 +35,17 @@ const {
   USB_RUNTIMES_UPDATED,
   WATCH_RUNTIME_FAILURE,
   WATCH_RUNTIME_START,
   WATCH_RUNTIME_SUCCESS,
 } = require("../constants");
 
 async function getRuntimeInfo(runtime, clientWrapper) {
   const { type } = runtime;
-  const { brandName: name, channel, deviceName, version } =
+  const { name, channel, deviceName, version } =
     await clientWrapper.getDeviceDescription();
   const icon =
     (channel === "release" || channel === "beta" || channel === "aurora")
       ? `chrome://devtools/skin/images/aboutdebugging-firefox-${ channel }.svg`
       : "chrome://devtools/skin/images/aboutdebugging-firefox-nightly.svg";
 
   return {
     icon,
--- a/devtools/client/aboutdebugging-new/src/modules/client-wrapper.js
+++ b/devtools/client/aboutdebugging-new/src/modules/client-wrapper.js
@@ -54,17 +54,25 @@ class ClientWrapper {
       this.client.mainRoot.off(evt, listener);
     } else {
       this.client.removeListener(evt, listener);
     }
   }
 
   async getDeviceDescription() {
     const deviceFront = await this.client.mainRoot.getFront("device");
-    return deviceFront.getDescription();
+    const { brandName, channel, deviceName, version } =
+      await deviceFront.getDescription();
+    // Only expose a specific set of properties.
+    return {
+      channel,
+      deviceName,
+      name: brandName,
+      version,
+    };
   }
 
   async setPreference(prefName, value) {
     const prefType = PREF_TO_TYPE[prefName];
     const preferenceFront = await this.client.mainRoot.getFront("preference");
     switch (prefType) {
       case PREF_TYPES.BOOL:
         return preferenceFront.setBoolPref(prefName, value);
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -26,8 +26,9 @@ skip-if = (os == 'linux' && bits == 32) 
 [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]
+[browser_aboutdebugging_thisfirefox_runtime_info.js]
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_usb_runtime.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_usb_runtime.js
@@ -14,18 +14,18 @@ Services.scriptloader.loadSubScript(CHRO
 add_task(async function() {
   const usbMocks = new UsbMocks();
   usbMocks.enableMocks();
   registerCleanupFunction(() => usbMocks.disableMocks());
 
   const { document, tab } = await openAboutDebugging();
 
   const usbClient = usbMocks.createRuntime(RUNTIME_ID, {
-    appName: RUNTIME_APP_NAME,
     deviceName: RUNTIME_DEVICE_NAME,
+    name: RUNTIME_APP_NAME,
   });
   usbMocks.emitUpdate();
 
   await connectToRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
 
   const extensionPane = getDebugTargetPane("Extensions", document);
   info("Check an empty target pane message is displayed");
   ok(extensionPane.querySelector(".js-debug-target-list-empty"),
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
@@ -16,18 +16,18 @@ add_task(async function() {
   usbMocks.enableMocks();
   registerCleanupFunction(() => {
     usbMocks.disableMocks();
   });
 
   const { document, tab } = await openAboutDebugging();
 
   usbMocks.createRuntime(RUNTIME_ID, {
-    appName: RUNTIME_APP_NAME,
     deviceName: RUNTIME_DEVICE_NAME,
+    name: RUNTIME_APP_NAME,
   });
   usbMocks.emitUpdate();
 
   await connectToRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
 
   const SUPPORTED_TARGET_PANES = [
     "Extensions",
     "Tabs",
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
@@ -18,18 +18,18 @@ 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,
+    name: RUNTIME_APP_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,
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_thisfirefox_runtime_info.js
@@ -0,0 +1,49 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from mocks/head-client-wrapper-mock.js */
+Services.scriptloader.loadSubScript(
+  CHROME_URL_ROOT + "mocks/head-client-wrapper-mock.js", this);
+/* import-globals-from mocks/head-runtime-client-factory-mock.js */
+Services.scriptloader.loadSubScript(
+  CHROME_URL_ROOT + "mocks/head-runtime-client-factory-mock.js", this);
+
+/**
+ * Check that the runtime info is correctly displayed for ThisFirefox.
+ * Also acts as basic sanity check for the default mock of the this-firefox client.
+ */
+
+add_task(async function() {
+  // Setup a mock for our runtime client factory to return the default THIS_FIREFOX client
+  // when the client for the this-firefox runtime is requested.
+  const runtimeClientFactoryMock = createRuntimeClientFactoryMock();
+  const thisFirefoxClient = createThisFirefoxClientMock();
+  runtimeClientFactoryMock.createClientForRuntime = runtime => {
+    const { RUNTIMES } = require("devtools/client/aboutdebugging-new/src/constants");
+    if (runtime.id === RUNTIMES.THIS_FIREFOX) {
+      return { clientWrapper: thisFirefoxClient };
+    }
+    throw new Error("Unexpected runtime id " + runtime.id);
+  };
+
+  info("Enable mocks");
+  enableRuntimeClientFactoryMock(runtimeClientFactoryMock);
+  registerCleanupFunction(() => {
+    disableRuntimeClientFactoryMock();
+  });
+
+  const { document, tab } = await openAboutDebugging();
+
+  info("Check that the 'This Firefox' mock is properly displayed");
+  const thisFirefoxRuntimeInfo = document.querySelector(".js-runtime-info");
+  ok(thisFirefoxRuntimeInfo, "Runtime info for this-firefox runtime is displayed");
+  const runtimeInfoText = thisFirefoxRuntimeInfo.textContent;
+  ok(runtimeInfoText.includes("Firefox"),
+    "this-firefox runtime info shows the correct runtime name: " + runtimeInfoText);
+  ok(runtimeInfoText.includes("63.0"),
+    "this-firefox runtime info shows the correct version number: " + runtimeInfoText);
+
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/mocks/head-usb-mocks.js
+++ b/devtools/client/aboutdebugging-new/test/browser/mocks/head-usb-mocks.js
@@ -64,17 +64,17 @@ class UsbMocks {
 
   /**
    * Creates a USB runtime for which a client conenction can be established.
    * @param {String} id
    *        The id of the runtime.
    * @param {Object} optional object used to create the fake runtime & device
    *        - deviceName: {String} Device name
    *        - shortName: {String} Short name for the device
-   *        - appName: {String} Application name, for instance "Firefox"
+   *        - name: {String} Application name, for instance "Firefox"
    *        - channel: {String} Release channel, for instance "release", "nightly"
    *        - version: {String} Version, for instance "63.0a"
    *        - socketPath: {String} (should only be used for connecting, so not here)
    * @return {Object} Returns the mock client created for this runtime so that methods
    * can be overridden on it.
    */
   createRuntime(id, runtimeInfo = {}) {
     // Add a new runtime to the list of scanned runtimes.
@@ -84,17 +84,17 @@ class UsbMocks {
       deviceName: runtimeInfo.deviceName || "test device name",
       shortName: runtimeInfo.shortName || "testshort",
     });
 
     // Add a valid client that can be returned for this particular runtime id.
     const mockUsbClient = createClientMock();
     mockUsbClient.getDeviceDescription = () => {
       return {
-        brandName: runtimeInfo.appName || "TestBrand",
+        name: runtimeInfo.name || "TestBrand",
         channel: runtimeInfo.channel || "release",
         version: runtimeInfo.version || "1.0",
       };
     };
     this._clients[id] = mockUsbClient;
 
     return mockUsbClient;
   }