Bug 1506513: Add worker mock test. r=jdescottes
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Fri, 07 Dec 2018 16:27:47 +0000
changeset 508831 7b9332b0c24d8f40310d9020693bb2321f32c935
parent 508830 62dd0d1a37b723f368848036c3e650c3ccfb44cf
child 508832 0ade0aa77b2f2e04e15b4618c9ef1a74b8739777
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1506513
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 1506513: Add worker mock test. r=jdescottes Depends on D13970 Differential Revision: https://phabricator.services.mozilla.com/D13971
devtools/client/aboutdebugging-new/src/components/debugtarget/InspectAction.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_thisfirefox_worker_inspection.js
--- a/devtools/client/aboutdebugging-new/src/components/debugtarget/InspectAction.js
+++ b/devtools/client/aboutdebugging-new/src/components/debugtarget/InspectAction.js
@@ -33,17 +33,17 @@ class InspectAction extends PureComponen
   render() {
     return Localized(
       {
         id: "about-debugging-debug-target-inspect-button",
       },
       dom.button(
         {
           onClick: e => this.inspect(),
-          className: "default-button",
+          className: "default-button  js-debug-target-inspect-button",
         },
         "Inspect"
       )
     );
   }
 }
 
 module.exports = InspectAction;
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -40,8 +40,9 @@ skip-if = (os == 'linux' && bits == 32) 
 [browser_aboutdebugging_sidebar_usb_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_stop_adb.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_system_addons.js]
 [browser_aboutdebugging_tab_favicons.js]
 [browser_aboutdebugging_thisfirefox.js]
 [browser_aboutdebugging_thisfirefox_runtime_info.js]
+[browser_aboutdebugging_thisfirefox_worker_inspection.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_thisfirefox_worker_inspection.js
@@ -0,0 +1,75 @@
+/* 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);
+const { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
+
+add_task(async function() {
+  const thisFirefoxClient = createThisFirefoxClientMock();
+  // Prepare a worker mock.
+  const testWorkerTargetFront = {
+    actorID: "test-worker-id",
+  };
+  const testWorker = {
+    name: "Test Worker",
+    workerTargetFront: testWorkerTargetFront,
+  };
+  // Add a worker mock as other worker.
+  thisFirefoxClient.listWorkers = () => ({
+    otherWorkers: [testWorker],
+    serviceWorkers: [],
+    sharedWorkers: [],
+  });
+  // Override getActor function of client which is used in inspect action for worker.
+  thisFirefoxClient.client.getActor = id => {
+    return id === testWorkerTargetFront.actorID ? testWorkerTargetFront : null;
+  };
+
+  const runtimeClientFactoryMock = createRuntimeClientFactoryMock();
+  runtimeClientFactoryMock.createClientForRuntime = runtime => {
+    const { RUNTIMES } = require("devtools/client/aboutdebugging-new/src/constants");
+    if (runtime.id === RUNTIMES.THIS_FIREFOX) {
+      return thisFirefoxClient;
+    }
+    throw new Error("Unexpected runtime id " + runtime.id);
+  };
+
+  info("Enable mocks");
+  enableRuntimeClientFactoryMock(runtimeClientFactoryMock);
+  const originalOpenWorkerForToolbox =  gDevToolsBrowser.openWorkerToolbox;
+  registerCleanupFunction(() => {
+    disableRuntimeClientFactoryMock();
+    gDevToolsBrowser.openWorkerToolbox = originalOpenWorkerForToolbox;
+  });
+
+  const { document, tab } = await openAboutDebugging();
+
+  const workerTarget = findDebugTargetByText(testWorker.name, document);
+  ok(workerTarget, "Worker target appeared for the test worker");
+  const inspectButton = workerTarget.querySelector(".js-debug-target-inspect-button");
+  ok(inspectButton, "Inspect button for the worker appeared");
+
+  info("Check whether the correct actor front will be opened in worker toolbox");
+  const waitForWorkerInspection = new Promise(resolve => {
+    // Override openWorkerToolbox of gDevToolsBrowser to check the parameter.
+    gDevToolsBrowser.openWorkerToolbox = front => {
+      if (front === testWorkerTargetFront) {
+        resolve();
+      }
+    };
+  });
+
+  inspectButton.click();
+
+  await waitForWorkerInspection;
+  ok(true, "Correct actor front will be opened in worker toolbox");
+
+  await removeTab(tab);
+});