Bug 1478244 - Enable client/debugger/test/mochitest/browser_dbg_target-scoped-actor-01.js in e10s. r=jdescottes draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 25 Jul 2018 00:35:36 -0700
changeset 822878 f6a2924ee429bde8789367df4fb1c3a5d2295d06
parent 822648 4c4abe35d80851590954b52eabf828c763104696
child 822879 836ddf2dc1af6554610250ae28fc80db4fd514ae
push id117504
push userbmo:poirot.alex@gmail.com
push dateThu, 26 Jul 2018 08:14:16 +0000
reviewersjdescottes
bugs1478244
milestone63.0a1
Bug 1478244 - Enable client/debugger/test/mochitest/browser_dbg_target-scoped-actor-01.js in e10s. r=jdescottes MozReview-Commit-ID: HKT4whszLKX
devtools/client/debugger/test/mochitest/browser2.ini
devtools/client/debugger/test/mochitest/browser_dbg_target-scoped-actor-01.js
devtools/client/shared/test/shared-head.js
--- a/devtools/client/debugger/test/mochitest/browser2.ini
+++ b/devtools/client/debugger/test/mochitest/browser2.ini
@@ -395,17 +395,16 @@ skip-if = e10s && debug
 [browser_dbg_stack-contextmenu-02.js]
 uses-unsafe-cpows = true
 subsuite = clipboard
 skip-if = (e10s && debug) || (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
 [browser_dbg_step-out.js]
 uses-unsafe-cpows = true
 skip-if = e10s && debug
 [browser_dbg_target-scoped-actor-01.js]
-skip-if = e10s # TODO
 [browser_dbg_target-scoped-actor-02.js]
 skip-if = e10s # TODO
 [browser_dbg_terminate-on-tab-close.js]
 uses-unsafe-cpows = true
 skip-if = e10s && debug
 [browser_dbg_variables-view-01.js]
 uses-unsafe-cpows = true
 skip-if = e10s && debug
--- a/devtools/client/debugger/test/mochitest/browser_dbg_target-scoped-actor-01.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg_target-scoped-actor-01.js
@@ -5,63 +5,40 @@
 
 /**
  * Check target-scoped actor lifetimes.
  */
 
 const ACTORS_URL = CHROME_URL + "testactors.js";
 const TAB_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
 
-var gClient;
+add_task(async function test() {
+  await addTab(TAB_URL);
 
-function test() {
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
 
-  DebuggerServer.registerModule(ACTORS_URL, {
+  await registerActorInContentProcess(ACTORS_URL, {
     prefix: "testOne",
     constructor: "TestActor1",
     type: { target: true },
   });
 
-  let transport = DebuggerServer.connectPipe();
-  gClient = new DebuggerClient(transport);
-  gClient.connect().then(([aType, aTraits]) => {
-    is(aType, "browser",
-      "Root actor should identify itself as a browser.");
+  const transport = DebuggerServer.connectPipe();
+  const client = new DebuggerClient(transport);
+  const [ type ] = await client.connect();
+  is(type, "browser", "Root actor should identify itself as a browser.");
 
-    addTab(TAB_URL)
-      .then(() => attachTargetActorForUrl(gClient, TAB_URL))
-      .then(testTargetScopedActor)
-      .then(closeTab)
-      .then(() => gClient.close())
-      .then(finish)
-      .catch(aError => {
-        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
-      });
-  });
-}
+  const [ grip ] = await attachTargetActorForUrl(client, TAB_URL);
+  await testTargetScopedActor(client, grip);
+  await removeTab(gBrowser.selectedTab);
+  await client.close();
+});
 
-function testTargetScopedActor([aGrip, aResponse]) {
-  let deferred = promise.defer();
-
-  ok(aGrip.testOneActor,
+async function testTargetScopedActor(client, grip) {
+  ok(grip.testOneActor,
     "Found the test target-scoped actor.");
-  ok(aGrip.testOneActor.includes("testOne"),
+  ok(grip.testOneActor.includes("testOne"),
     "testOneActor's actorPrefix should be used.");
 
-  gClient.request({ to: aGrip.testOneActor, type: "ping" }, aResponse => {
-    is(aResponse.pong, "pong",
-      "Actor should respond to requests.");
-
-    deferred.resolve();
-  });
-
-  return deferred.promise;
+  const response = await client.request({ to: grip.testOneActor, type: "ping" });
+  is(response.pong, "pong", "Actor should respond to requests.");
 }
-
-function closeTab() {
-  return removeTab(gBrowser.selectedTab);
-}
-
-registerCleanupFunction(function () {
-  gClient = null;
-});
--- a/devtools/client/shared/test/shared-head.js
+++ b/devtools/client/shared/test/shared-head.js
@@ -725,8 +725,37 @@ async function injectEventUtilsInContent
 
 /**
  * Temporarily flip all the preferences needed to enable web components.
  */
 async function enableWebComponents() {
   await pushPref("dom.webcomponents.shadowdom.enabled", true);
   await pushPref("dom.webcomponents.customelements.enabled", true);
 }
+
+/*
+ * Register an actor in the content process of the current tab.
+ *
+ * Calling DebuggerServer.registerModule only registers the actor in the current process.
+ * As all test scripts are ran in the parent process, it is only registered here.
+ * This function helps register them in the content process used for the current tab.
+ *
+ * @param {string} url
+ *        Actor module URL or absolute require path
+ * @param {json} options
+ *        Arguments to be passed to DebuggerServer.registerModule
+ */
+async function registerActorInContentProcess(url, options) {
+  function convertChromeToFile(uri) {
+    return Cc["@mozilla.org/chrome/chrome-registry;1"]
+             .getService(Ci.nsIChromeRegistry)
+             .convertChromeURL(Services.io.newURI(uri)).spec;
+  }
+  // chrome://mochitests URI is registered only in the parent process, so convert these
+  // URLs to file:// one in order to work in the content processes
+  url = url.startsWith("chrome://mochitests") ? convertChromeToFile(url) : url;
+  return ContentTask.spawn(gBrowser.selectedBrowser, { url, options }, args => {
+    // eslint-disable-next-line no-shadow
+    const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
+    const { DebuggerServer } = require("devtools/server/main");
+    DebuggerServer.registerModule(args.url, args.options);
+  });
+}