Bug 1495382 - Add support for Workers in network locations runtimes;r=daisuke,ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 09 Jan 2019 09:44:13 +0000
changeset 453017 17b9f7326ef3a3176837edaa5b722fbf76a28336
parent 453016 5f5e0f6f9b55d05e0186a647c8f7e2bbe9df25e3
child 453018 f829749915aa4360071ffcef1ce5aa503c15788a
push id35340
push usercsabou@mozilla.com
push dateWed, 09 Jan 2019 16:04:56 +0000
treeherdermozilla-central@e28e5537e369 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke, ladybenko
bugs1495382
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 1495382 - Add support for Workers in network locations runtimes;r=daisuke,ladybenko Differential Revision: https://phabricator.services.mozilla.com/D15081
devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_workers_remote_runtime.js
--- a/devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
+++ b/devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
@@ -9,24 +9,21 @@ const { DEBUG_TARGETS, DEBUG_TARGET_PANE
 const ALL_DEBUG_TARGETS = [
   DEBUG_TARGETS.EXTENSION,
   DEBUG_TARGETS.TAB,
   DEBUG_TARGETS.WORKER,
 ];
 
 const SUPPORTED_TARGET_BY_RUNTIME = {
   [RUNTIMES.THIS_FIREFOX]: ALL_DEBUG_TARGETS,
+  [RUNTIMES.NETWORK]: ALL_DEBUG_TARGETS,
   [RUNTIMES.USB]: [
     DEBUG_TARGETS.EXTENSION,
     DEBUG_TARGETS.TAB,
   ],
-  [RUNTIMES.NETWORK]: [
-    DEBUG_TARGETS.EXTENSION,
-    DEBUG_TARGETS.TAB,
-  ],
 };
 
 function isSupportedDebugTarget(runtimeType, debugTargetType) {
   return SUPPORTED_TARGET_BY_RUNTIME[runtimeType].includes(debugTargetType);
 }
 exports.isSupportedDebugTarget = isSupportedDebugTarget;
 
 const ALL_DEBUG_TARGET_PANES = [
@@ -39,20 +36,19 @@ const ALL_DEBUG_TARGET_PANES = [
 ];
 
 const SUPPORTED_TARGET_PANE_BY_RUNTIME = {
   [RUNTIMES.THIS_FIREFOX]: ALL_DEBUG_TARGET_PANES,
   [RUNTIMES.USB]: [
     DEBUG_TARGET_PANE.INSTALLED_EXTENSION,
     DEBUG_TARGET_PANE.TAB,
   ],
-  [RUNTIMES.NETWORK]: [
-    DEBUG_TARGET_PANE.INSTALLED_EXTENSION,
-    DEBUG_TARGET_PANE.TAB,
-  ],
+  // All debug target panes except temporary extensions
+  [RUNTIMES.NETWORK]: ALL_DEBUG_TARGET_PANES.filter(p =>
+    p !== DEBUG_TARGET_PANE.TEMPORARY_EXTENSION),
 };
 
 /**
  * A debug target pane is more specialized than a debug target. For instance EXTENSION is
  * a DEBUG_TARGET but INSTALLED_EXTENSION and TEMPORARY_EXTENSION are DEBUG_TARGET_PANES.
  */
 function isSupportedDebugTargetPane(runtimeType, debugTargetPaneKey) {
   return SUPPORTED_TARGET_PANE_BY_RUNTIME[runtimeType].includes(debugTargetPaneKey);
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -55,8 +55,9 @@ skip-if = (os == 'linux' && bits == 32) 
 [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_temporary_addon_install_error.js]
 [browser_aboutdebugging_thisfirefox.js]
 [browser_aboutdebugging_thisfirefox_runtime_info.js]
 [browser_aboutdebugging_thisfirefox_worker_inspection.js]
+[browser_aboutdebugging_workers_remote_runtime.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_workers_remote_runtime.js
@@ -0,0 +1,111 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-mocks.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-mocks.js", this);
+
+const NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+
+const TESTS = [
+  {
+    category: "Other Workers",
+    propertyName: "otherWorkers",
+    workerName: "other/worker/script.js",
+  }, {
+    category: "Service Workers",
+    propertyName: "serviceWorkers",
+    workerName: "service/worker/script.js",
+  }, {
+    category: "Shared Workers",
+    propertyName: "sharedWorkers",
+    workerName: "shared/worker/script.js",
+  },
+];
+
+const EMPTY_WORKERS_RESPONSE = {
+  otherWorkers: [],
+  serviceWorkers: [],
+  sharedWorkers: [],
+};
+
+// Test that workers are displayed and updated for remote runtimes when expected.
+add_task(async function() {
+  const mocks = new Mocks();
+
+  const { document, tab } = await openAboutDebugging();
+
+  info("Prepare Network client mock");
+  const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+    name: NETWORK_RUNTIME_APP_NAME,
+  });
+
+  info("Test workers in runtime page for Network client");
+  await connectToRuntime(NETWORK_RUNTIME_HOST, document);
+  await selectRuntime(NETWORK_RUNTIME_HOST, NETWORK_RUNTIME_APP_NAME, document);
+
+  for (const testData of TESTS) {
+    await testWorkerOnMockedRemoteClient(testData, networkClient, mocks.thisFirefoxClient,
+     document);
+  }
+
+  await removeTab(tab);
+});
+
+/**
+ * Check that workers are visible in the runtime page for a remote client.
+ */
+async function testWorkerOnMockedRemoteClient(testData, remoteClient, firefoxClient,
+  document) {
+  const { category, propertyName, workerName } = testData;
+  info(`Test workers for category [${category}] in remote runtime`);
+
+  const workersPane = getDebugTargetPane(category, document);
+  info("Check an empty target pane message is displayed");
+  ok(workersPane.querySelector(".js-debug-target-list-empty"),
+    "Workers list is empty");
+
+  info(`Add a worker of type [${propertyName}] to the remote client`);
+  const workers = Object.assign({}, EMPTY_WORKERS_RESPONSE, {
+    [propertyName]: [{
+      name: workerName,
+      workerTargetFront: {
+        actorID: workerName,
+      },
+    }],
+  });
+  remoteClient.listWorkers = () => workers;
+  remoteClient._eventEmitter.emit("workerListChanged");
+
+  info("Wait until the worker appears");
+  await waitUntil(() => !workersPane.querySelector(".js-debug-target-list-empty"));
+
+  const workerTarget = findDebugTargetByText(workerName, document);
+  ok(workerTarget, "Worker target appeared for the remote runtime");
+
+  // Check that the list of REMOTE workers are NOT updated when the local this-firefox
+  // emits a workerListChanged event.
+  info("Remove the worker from the remote client WITHOUT sending an event");
+  remoteClient.listWorkers = () => EMPTY_WORKERS_RESPONSE;
+
+  info("Simulate a worker update on the ThisFirefox client");
+  firefoxClient._eventEmitter.emit("workerListChanged");
+
+  // To avoid wait for a set period of time we trigger another async update, adding a new
+  // tab. We assume that if the worker update mechanism had started, it would also be done
+  // when the new tab was processed.
+  info("Wait until the tab target for 'http://some.random/url.com' appears");
+  const testTab = { outerWindowID: 0, url: "http://some.random/url.com" };
+  remoteClient.listTabs = () => [testTab];
+  remoteClient._eventEmitter.emit("tabListChanged");
+  await waitUntil(() => findDebugTargetByText("http://some.random/url.com", document));
+
+  ok(findDebugTargetByText(workerName, document),
+    "The test worker is still visible");
+
+  info("Emit `workerListChanged` on remoteClient and wait for the target list to update");
+  remoteClient._eventEmitter.emit("workerListChanged");
+  await waitUntil(() => !findDebugTargetByText(workerName, document));
+}