Bug 1425818 - Stop using CPOW in devtools/server/tests/browser/browser_canvasframe_helper_*.js. r=pbro draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 18 Dec 2017 02:21:41 -0800
changeset 713928 9238513bbcc948aac0f9ba85587a9677e9d8c110
parent 712624 e3048146437d8c9746bdac24dc46c4118fe1fb6d
child 744479 9bc15baed93cbfff9061e9fb5319aa7aec1aa531
push id93802
push userbmo:poirot.alex@gmail.com
push dateThu, 21 Dec 2017 11:55:41 +0000
reviewerspbro
bugs1425818
milestone59.0a1
Bug 1425818 - Stop using CPOW in devtools/server/tests/browser/browser_canvasframe_helper_*.js. r=pbro MozReview-Commit-ID: 70IEX3Q5iGa
devtools/client/framework/test/shared-head.js
devtools/client/responsive.html/test/browser/browser_touch_simulation.js
devtools/server/tests/browser/browser.ini
devtools/server/tests/browser/browser_canvasframe_helper_01.js
devtools/server/tests/browser/browser_canvasframe_helper_02.js
devtools/server/tests/browser/browser_canvasframe_helper_03.js
devtools/server/tests/browser/browser_canvasframe_helper_04.js
devtools/server/tests/browser/browser_canvasframe_helper_05.js
devtools/server/tests/browser/browser_canvasframe_helper_06.js
devtools/server/tests/browser/head.js
--- a/devtools/client/framework/test/shared-head.js
+++ b/devtools/client/framework/test/shared-head.js
@@ -688,8 +688,52 @@ function createTestHTTPServer() {
       destroyed.resolve();
     });
     yield destroyed.promise;
   });
 
   server.start(-1);
   return server;
 }
+
+/**
+ * Inject `EventUtils` helpers into ContentTask scope.
+ *
+ * This helper is automatically exposed to mochitest browser tests,
+ * but is missing from content task scope.
+ * You should call this method only once per <browser> tag
+ *
+ * @param {xul:browser} browser
+ *        Reference to the browser in which we load content task
+ */
+async function injectEventUtilsInContentTask(browser) {
+  await ContentTask.spawn(browser, {}, function* () {
+    if ("EventUtils" in this) {
+      return;
+    }
+
+    let EventUtils = this.EventUtils = {};
+
+    EventUtils.window = {};
+    EventUtils.parent = EventUtils.window;
+    /* eslint-disable camelcase */
+    EventUtils._EU_Ci = Components.interfaces;
+    EventUtils._EU_Cc = Components.classes;
+    /* eslint-enable camelcase */
+    // EventUtils' `sendChar` function relies on the navigator to synthetize events.
+    EventUtils.navigator = content.navigator;
+    EventUtils.KeyboardEvent = content.KeyboardEvent;
+
+    EventUtils.synthesizeClick = element => new Promise(resolve => {
+      element.addEventListener("click", function () {
+        resolve();
+      }, {once: true});
+
+      EventUtils.synthesizeMouseAtCenter(element,
+        { type: "mousedown", isSynthesized: false }, content);
+      EventUtils.synthesizeMouseAtCenter(element,
+        { type: "mouseup", isSynthesized: false }, content);
+    });
+
+    Services.scriptloader.loadSubScript(
+      "chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
+  });
+}
--- a/devtools/client/responsive.html/test/browser/browser_touch_simulation.js
+++ b/devtools/client/responsive.html/test/browser/browser_touch_simulation.js
@@ -4,30 +4,29 @@
 "use strict";
 
 // Test global touch simulation button
 
 const TEST_URL = `${URL_ROOT}touch.html`;
 const PREF_DOM_META_VIEWPORT_ENABLED = "dom.meta-viewport.enabled";
 
 addRDMTask(TEST_URL, function* ({ ui }) {
+  yield injectEventUtilsInContentTask(ui.getViewportBrowser());
+
   yield waitBootstrap(ui);
   yield testWithNoTouch(ui);
   yield toggleTouchSimulation(ui);
   yield testWithTouch(ui);
   yield testWithMetaViewportEnabled(ui);
   yield testWithMetaViewportDisabled(ui);
   testTouchButton(ui);
 });
 
 function* testWithNoTouch(ui) {
-  yield injectEventUtils(ui);
   yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
-    let { EventUtils } = content;
-
     let div = content.document.querySelector("div");
     let x = 0, y = 0;
 
     info("testWithNoTouch: Initial test parameter and mouse mouse outside div");
     x = -1; y = -1;
     yield EventUtils.synthesizeMouse(div, x, y,
           { type: "mousemove", isSynthesized: false }, content);
     div.style.transform = "none";
@@ -57,21 +56,17 @@ function* testWithNoTouch(ui) {
     info("testWithNoTouch: Click the div element");
     yield EventUtils.synthesizeClick(div);
     is(div.dataset.isDelay, "false",
       "300ms delay between touch events and mouse events should not work");
   });
 }
 
 function* testWithTouch(ui) {
-  yield injectEventUtils(ui);
-
   yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
-    let { EventUtils } = content;
-
     let div = content.document.querySelector("div");
     let x = 0, y = 0;
 
     info("testWithTouch: Initial test parameter and mouse mouse outside div");
     x = -1; y = -1;
     yield EventUtils.synthesizeMouse(div, x, y,
           { type: "mousemove", isSynthesized: false }, content);
     div.style.transform = "none";
@@ -100,20 +95,18 @@ function* testWithTouch(ui) {
     isnot(div.style.backgroundColor, "blue",
       "mouseout or mouseleave should not work");
   });
 }
 
 function* testWithMetaViewportEnabled(ui) {
   yield SpecialPowers.pushPrefEnv({set: [[PREF_DOM_META_VIEWPORT_ENABLED, true]]});
 
-  yield injectEventUtils(ui);
-
   yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
-    let { synthesizeClick } = content.EventUtils;
+    let { synthesizeClick } = EventUtils;
 
     let meta = content.document.querySelector("meta[name=viewport]");
     let div = content.document.querySelector("div");
     div.dataset.isDelay = "false";
 
     info("testWithMetaViewportEnabled: " +
          "click the div element with <meta name='viewport'>");
     meta.content = "";
@@ -145,20 +138,18 @@ function* testWithMetaViewportEnabled(ui
     is(div.dataset.isDelay, "false",
       "300ms delay between touch events and mouse events should not work");
   });
 }
 
 function* testWithMetaViewportDisabled(ui) {
   yield SpecialPowers.pushPrefEnv({set: [[PREF_DOM_META_VIEWPORT_ENABLED, false]]});
 
-  yield injectEventUtils(ui);
-
   yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
-    let { synthesizeClick } = content.EventUtils;
+    let { synthesizeClick } = EventUtils;
 
     let meta = content.document.querySelector("meta[name=viewport]");
     let div = content.document.querySelector("div");
     div.dataset.isDelay = "false";
 
     info("testWithMetaViewportDisabled: click the div with <meta name='viewport'>");
     meta.content = "";
     yield synthesizeClick(div);
@@ -186,42 +177,8 @@ function testTouchButton(ui) {
 }
 
 function* waitBootstrap(ui) {
   let { store } = ui.toolWindow;
 
   yield waitUntilState(store, state => state.viewports.length == 1);
   yield waitForFrameLoad(ui, TEST_URL);
 }
-
-function* injectEventUtils(ui) {
-  yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
-    if ("EventUtils" in content) {
-      return;
-    }
-
-    let EventUtils = content.EventUtils = {};
-
-    EventUtils.window = {};
-    EventUtils.parent = EventUtils.window;
-    /* eslint-disable camelcase */
-    EventUtils._EU_Ci = Components.interfaces;
-    EventUtils._EU_Cc = Components.classes;
-    /* eslint-enable camelcase */
-    // EventUtils' `sendChar` function relies on the navigator to synthetize events.
-    EventUtils.navigator = content.navigator;
-    EventUtils.KeyboardEvent = content.KeyboardEvent;
-
-    EventUtils.synthesizeClick = element => new Promise(resolve => {
-      element.addEventListener("click", function () {
-        resolve();
-      }, {once: true});
-
-      EventUtils.synthesizeMouseAtCenter(element,
-        { type: "mousedown", isSynthesized: false }, content);
-      EventUtils.synthesizeMouseAtCenter(element,
-        { type: "mouseup", isSynthesized: false }, content);
-    });
-
-    Services.scriptloader.loadSubScript(
-      "chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
-  });
-}
--- a/devtools/server/tests/browser/browser.ini
+++ b/devtools/server/tests/browser/browser.ini
@@ -20,16 +20,17 @@ support-files =
   storage-unsecured-iframe.html
   storage-updates.html
   storage-secured-iframe.html
   stylesheets-nested-iframes.html
   timeline-iframe-child.html
   timeline-iframe-parent.html
   storage-helpers.js
   !/devtools/server/tests/mochitest/hello-actor.js
+  !/devtools/client/framework/test/shared-head.js
 
 [browser_accessibility_node_events.js]
 [browser_accessibility_node.js]
 [browser_accessibility_simple.js]
 [browser_accessibility_walker.js]
 [browser_animation_emitMutations.js]
 [browser_animation_getFrames.js]
 [browser_animation_getProperties.js]
--- a/devtools/server/tests/browser/browser_canvasframe_helper_01.js
+++ b/devtools/server/tests/browser/browser_canvasframe_helper_01.js
@@ -1,91 +1,89 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Simple CanvasFrameAnonymousContentHelper tests.
 
-// This makes sure the 'domnode' protocol actor type is known when importing
-// highlighter.
-require("devtools/server/actors/inspector");
-const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
-
-const {
-  CanvasFrameAnonymousContentHelper
-} = require("devtools/server/actors/highlighters/utils/markup");
-
 const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
 
-add_task(function* () {
-  let browser = yield addTab(TEST_URL);
-  // eslint-disable-next-line mozilla/no-cpows-in-tests
-  let doc = browser.contentDocument;
+add_task(async function () {
+  let browser = await addTab(TEST_URL);
+
+  await ContentTask.spawn(browser, null, async function () {
+    const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+    const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
+    const {
+      CanvasFrameAnonymousContentHelper
+    } = require("devtools/server/actors/highlighters/utils/markup");
+    let doc = content.document;
 
-  let nodeBuilder = () => {
-    let root = doc.createElement("div");
-    let child = doc.createElement("div");
-    child.style = "width:200px;height:200px;background:red;";
-    child.id = "child-element";
-    child.className = "child-element";
-    child.textContent = "test element";
-    root.appendChild(child);
-    return root;
-  };
+    let nodeBuilder = () => {
+      let root = doc.createElement("div");
+      let child = doc.createElement("div");
+      child.style = "width:200px;height:200px;background:red;";
+      child.id = "child-element";
+      child.className = "child-element";
+      child.textContent = "test element";
+      root.appendChild(child);
+      return root;
+    };
 
-  info("Building the helper");
-  let env = new HighlighterEnvironment();
-  env.initFromWindow(doc.defaultView);
-  let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+    info("Building the helper");
+    let env = new HighlighterEnvironment();
+    env.initFromWindow(doc.defaultView);
+    let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
 
-  ok(helper.content instanceof AnonymousContent,
-    "The helper owns the AnonymousContent object");
-  ok(helper.getTextContentForElement,
-    "The helper has the getTextContentForElement method");
-  ok(helper.setTextContentForElement,
-    "The helper has the setTextContentForElement method");
-  ok(helper.setAttributeForElement,
-    "The helper has the setAttributeForElement method");
-  ok(helper.getAttributeForElement,
-    "The helper has the getAttributeForElement method");
-  ok(helper.removeAttributeForElement,
-    "The helper has the removeAttributeForElement method");
-  ok(helper.addEventListenerForElement,
-    "The helper has the addEventListenerForElement method");
-  ok(helper.removeEventListenerForElement,
-    "The helper has the removeEventListenerForElement method");
-  ok(helper.getElement,
-    "The helper has the getElement method");
-  ok(helper.scaleRootElement,
-    "The helper has the scaleRootElement method");
+    ok(helper.content instanceof content.AnonymousContent,
+      "The helper owns the AnonymousContent object");
+    ok(helper.getTextContentForElement,
+      "The helper has the getTextContentForElement method");
+    ok(helper.setTextContentForElement,
+      "The helper has the setTextContentForElement method");
+    ok(helper.setAttributeForElement,
+      "The helper has the setAttributeForElement method");
+    ok(helper.getAttributeForElement,
+      "The helper has the getAttributeForElement method");
+    ok(helper.removeAttributeForElement,
+      "The helper has the removeAttributeForElement method");
+    ok(helper.addEventListenerForElement,
+      "The helper has the addEventListenerForElement method");
+    ok(helper.removeEventListenerForElement,
+      "The helper has the removeEventListenerForElement method");
+    ok(helper.getElement,
+      "The helper has the getElement method");
+    ok(helper.scaleRootElement,
+      "The helper has the scaleRootElement method");
 
-  is(helper.getTextContentForElement("child-element"), "test element",
-    "The text content was retrieve correctly");
-  is(helper.getAttributeForElement("child-element", "id"), "child-element",
-    "The ID attribute was retrieve correctly");
-  is(helper.getAttributeForElement("child-element", "class"), "child-element",
-    "The class attribute was retrieve correctly");
+    is(helper.getTextContentForElement("child-element"), "test element",
+      "The text content was retrieve correctly");
+    is(helper.getAttributeForElement("child-element", "id"), "child-element",
+      "The ID attribute was retrieve correctly");
+    is(helper.getAttributeForElement("child-element", "class"), "child-element",
+      "The class attribute was retrieve correctly");
 
-  let el = helper.getElement("child-element");
-  ok(el, "The DOMNode-like element was created");
+    let el = helper.getElement("child-element");
+    ok(el, "The DOMNode-like element was created");
 
-  is(el.getTextContent(), "test element",
-    "The text content was retrieve correctly");
-  is(el.getAttribute("id"), "child-element",
-    "The ID attribute was retrieve correctly");
-  is(el.getAttribute("class"), "child-element",
-    "The class attribute was retrieve correctly");
+    is(el.getTextContent(), "test element",
+      "The text content was retrieve correctly");
+    is(el.getAttribute("id"), "child-element",
+      "The ID attribute was retrieve correctly");
+    is(el.getAttribute("class"), "child-element",
+      "The class attribute was retrieve correctly");
 
-  info("Destroying the helper");
-  helper.destroy();
-  env.destroy();
+    info("Destroying the helper");
+    helper.destroy();
+    env.destroy();
 
-  ok(!helper.getTextContentForElement("child-element"),
-    "No text content was retrieved after the helper was destroyed");
-  ok(!helper.getAttributeForElement("child-element", "id"),
-    "No ID attribute was retrieved after the helper was destroyed");
-  ok(!helper.getAttributeForElement("child-element", "class"),
-    "No class attribute was retrieved after the helper was destroyed");
+    ok(!helper.getTextContentForElement("child-element"),
+      "No text content was retrieved after the helper was destroyed");
+    ok(!helper.getAttributeForElement("child-element", "id"),
+      "No ID attribute was retrieved after the helper was destroyed");
+    ok(!helper.getAttributeForElement("child-element", "class"),
+      "No class attribute was retrieved after the helper was destroyed");
+  });
 
   gBrowser.removeCurrentTab();
 });
--- a/devtools/server/tests/browser/browser_canvasframe_helper_02.js
+++ b/devtools/server/tests/browser/browser_canvasframe_helper_02.js
@@ -2,48 +2,45 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test that the CanvasFrameAnonymousContentHelper does not insert content in
 // XUL windows.
 
-// This makes sure the 'domnode' protocol actor type is known when importing
-// highlighter.
-require("devtools/server/actors/inspector");
-
-const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
+add_task(async function () {
+  let browser = await addTab("about:preferences");
 
-const {
-  CanvasFrameAnonymousContentHelper
-} = require("devtools/server/actors/highlighters/utils/markup");
-
-add_task(function* () {
-  let browser = yield addTab("about:preferences");
-  // eslint-disable-next-line mozilla/no-cpows-in-tests
-  let doc = browser.contentDocument;
+  await ContentTask.spawn(browser, null, async function () {
+    const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+    const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
+    const {
+      CanvasFrameAnonymousContentHelper
+    } = require("devtools/server/actors/highlighters/utils/markup");
+    let doc = content.document;
 
-  let nodeBuilder = () => {
-    let root = doc.createElement("div");
-    let child = doc.createElement("div");
-    child.style = "width:200px;height:200px;background:red;";
-    child.id = "child-element";
-    child.className = "child-element";
-    child.textContent = "test element";
-    root.appendChild(child);
-    return root;
-  };
+    let nodeBuilder = () => {
+      let root = doc.createElement("div");
+      let child = doc.createElement("div");
+      child.style = "width:200px;height:200px;background:red;";
+      child.id = "child-element";
+      child.className = "child-element";
+      child.textContent = "test element";
+      root.appendChild(child);
+      return root;
+    };
 
-  info("Building the helper");
-  let env = new HighlighterEnvironment();
-  env.initFromWindow(doc.defaultView);
-  let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+    info("Building the helper");
+    let env = new HighlighterEnvironment();
+    env.initFromWindow(doc.defaultView);
+    let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
 
-  ok(!helper.content, "The AnonymousContent was not inserted in the window");
-  ok(!helper.getTextContentForElement("child-element"),
-    "No text content is returned");
+    ok(!helper.content, "The AnonymousContent was not inserted in the window");
+    ok(!helper.getTextContentForElement("child-element"),
+      "No text content is returned");
 
-  env.destroy();
-  helper.destroy();
+    env.destroy();
+    helper.destroy();
+  });
 
   gBrowser.removeCurrentTab();
 });
--- a/devtools/server/tests/browser/browser_canvasframe_helper_03.js
+++ b/devtools/server/tests/browser/browser_canvasframe_helper_03.js
@@ -1,103 +1,113 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test the CanvasFrameAnonymousContentHelper event handling mechanism.
 
-// This makes sure the 'domnode' protocol actor type is known when importing
-// highlighter.
-require("devtools/server/actors/inspector");
-
-const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
-
-const {
-  CanvasFrameAnonymousContentHelper
-} = require("devtools/server/actors/highlighters/utils/markup");
-
 const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
 
-add_task(function* () {
-  let browser = yield addTab(TEST_URL);
-  // eslint-disable-next-line mozilla/no-cpows-in-tests
-  let doc = browser.contentDocument;
+add_task(async function () {
+  let browser = await addTab(TEST_URL);
+  await ContentTask.spawn(browser, null, async function () {
+    const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+    const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
+    const {
+      CanvasFrameAnonymousContentHelper
+    } = require("devtools/server/actors/highlighters/utils/markup");
+    let doc = content.document;
 
-  let nodeBuilder = () => {
-    let root = doc.createElement("div");
-    let child = doc.createElement("div");
-    child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
-    child.id = "child-element";
-    child.className = "child-element";
-    root.appendChild(child);
-    return root;
-  };
+    let nodeBuilder = () => {
+      let root = doc.createElement("div");
+      let child = doc.createElement("div");
+      child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
+      child.id = "child-element";
+      child.className = "child-element";
+      root.appendChild(child);
+      return root;
+    };
 
-  info("Building the helper");
-  let env = new HighlighterEnvironment();
-  env.initFromWindow(doc.defaultView);
-  let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+    info("Building the helper");
+    let env = new HighlighterEnvironment();
+    env.initFromWindow(doc.defaultView);
+    let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
 
-  let el = helper.getElement("child-element");
+    let el = helper.getElement("child-element");
 
-  info("Adding an event listener on the inserted element");
-  let mouseDownHandled = 0;
-  function onMouseDown(e, id) {
-    is(id, "child-element", "The mousedown event was triggered on the element");
-    ok(!e.originalTarget, "The originalTarget property isn't available");
-    mouseDownHandled++;
-  }
-  el.addEventListener("mousedown", onMouseDown);
+    info("Adding an event listener on the inserted element");
+    let mouseDownHandled = 0;
+    function onMouseDown(e, id) {
+      is(id, "child-element", "The mousedown event was triggered on the element");
+      ok(!e.originalTarget, "The originalTarget property isn't available");
+      mouseDownHandled++;
+    }
+    el.addEventListener("mousedown", onMouseDown);
 
-  info("Synthesizing an event on the inserted element");
-  let onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
+    function once(target, event) {
+      return new Promise(done => {
+        target.addEventListener(event, done, { once: true });
+      });
+    }
+
+    info("Synthesizing an event on the inserted element");
+    let onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
+
+    is(mouseDownHandled, 1, "The mousedown event was handled once on the element");
 
-  is(mouseDownHandled, 1, "The mousedown event was handled once on the element");
+    info("Synthesizing an event somewhere else");
+    onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(400, 400, doc.defaultView);
+    await onDocMouseDown;
 
-  info("Synthesizing an event somewhere else");
-  onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(400, 400, doc.defaultView);
-  yield onDocMouseDown;
+    is(mouseDownHandled, 1, "The mousedown event was not handled on the element");
 
-  is(mouseDownHandled, 1, "The mousedown event was not handled on the element");
+    info("Removing the event listener");
+    el.removeEventListener("mousedown", onMouseDown);
 
-  info("Removing the event listener");
-  el.removeEventListener("mousedown", onMouseDown);
+    info("Synthesizing another event after the listener has been removed");
+    // Using a document event listener to know when the event has been synthesized.
+    onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
 
-  info("Synthesizing another event after the listener has been removed");
-  // Using a document event listener to know when the event has been synthesized.
-  onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
+    is(mouseDownHandled, 1,
+      "The mousedown event hasn't been handled after the listener was removed");
+
+    info("Adding again the event listener");
+    el.addEventListener("mousedown", onMouseDown);
+
+    info("Destroying the helper");
+    env.destroy();
+    helper.destroy();
 
-  is(mouseDownHandled, 1,
-    "The mousedown event hasn't been handled after the listener was removed");
+    info("Synthesizing another event after the helper has been destroyed");
+    // Using a document event listener to know when the event has been synthesized.
+    onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
 
-  info("Adding again the event listener");
-  el.addEventListener("mousedown", onMouseDown);
+    is(mouseDownHandled, 1,
+      "The mousedown event hasn't been handled after the helper was destroyed");
 
-  info("Destroying the helper");
-  env.destroy();
-  helper.destroy();
-
-  info("Synthesizing another event after the helper has been destroyed");
-  // Using a document event listener to know when the event has been synthesized.
-  onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
-
-  is(mouseDownHandled, 1,
-    "The mousedown event hasn't been handled after the helper was destroyed");
+    function synthesizeMouseDown(x, y, win) {
+      // We need to make sure the inserted anonymous content can be targeted by the
+      // event right after having been inserted, and so we need to force a sync
+      // reflow.
+      win.document.documentElement.offsetWidth;
+      // Minimal environment for EventUtils to work.
+      let EventUtils = {
+        window: content,
+        parent: content,
+        _EU_Ci: Components.interfaces,
+        _EU_Cc: Components.classes,
+      };
+      Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
+      EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
+    }
+  });
 
   gBrowser.removeCurrentTab();
 });
-
-function synthesizeMouseDown(x, y, win) {
-  // We need to make sure the inserted anonymous content can be targeted by the
-  // event right after having been inserted, and so we need to force a sync
-  // reflow.
-  win.document.documentElement.offsetWidth;
-  EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
-}
--- a/devtools/server/tests/browser/browser_canvasframe_helper_04.js
+++ b/devtools/server/tests/browser/browser_canvasframe_helper_04.js
@@ -2,100 +2,104 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test the CanvasFrameAnonymousContentHelper re-inserts the content when the
 // page reloads.
 
-// This makes sure the 'domnode' protocol actor type is known when importing
-// highlighter.
-require("devtools/server/actors/inspector");
-
-const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
-
-const {
-  CanvasFrameAnonymousContentHelper
-} = require("devtools/server/actors/highlighters/utils/markup");
-
 const TEST_URL_1 =
   "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test 1";
 const TEST_URL_2 =
   "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test 2";
 
-add_task(function* () {
-  let browser = yield addTab(TEST_URL_1);
-  // eslint-disable-next-line mozilla/no-cpows-in-tests
-  let doc = browser.contentDocument;
+add_task(async function () {
+  let browser = await addTab(TEST_URL_1);
+  await injectEventUtilsInContentTask(browser);
+  await ContentTask.spawn(browser, TEST_URL_2, async function (url2) {
+    const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+    const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
+    const {
+      CanvasFrameAnonymousContentHelper
+    } = require("devtools/server/actors/highlighters/utils/markup");
+    let doc = content.document;
+
+    let nodeBuilder = () => {
+      let root = doc.createElement("div");
+      let child = doc.createElement("div");
+      child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
+      child.id = "child-element";
+      child.className = "child-element";
+      child.textContent = "test content";
+      root.appendChild(child);
+      return root;
+    };
 
-  let nodeBuilder = () => {
-    let root = doc.createElement("div");
-    let child = doc.createElement("div");
-    child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
-    child.id = "child-element";
-    child.className = "child-element";
-    child.textContent = "test content";
-    root.appendChild(child);
-    return root;
-  };
+    info("Building the helper");
+    let env = new HighlighterEnvironment();
+    env.initFromWindow(doc.defaultView);
+    let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+
+    info("Get an element from the helper");
+    let el = helper.getElement("child-element");
 
-  info("Building the helper");
-  let env = new HighlighterEnvironment();
-  env.initFromWindow(doc.defaultView);
-  let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+    info("Try to access the element");
+    is(el.getAttribute("class"), "child-element",
+      "The attribute is correct before navigation");
+    is(el.getTextContent(), "test content",
+      "The text content is correct before navigation");
 
-  info("Get an element from the helper");
-  let el = helper.getElement("child-element");
-
-  info("Try to access the element");
-  is(el.getAttribute("class"), "child-element",
-    "The attribute is correct before navigation");
-  is(el.getTextContent(), "test content",
-    "The text content is correct before navigation");
+    info("Add an event listener on the element");
+    let mouseDownHandled = 0;
+    let onMouseDown = (e, id) => {
+      is(id, "child-element", "The mousedown event was triggered on the element");
+      mouseDownHandled++;
+    };
+    el.addEventListener("mousedown", onMouseDown);
 
-  info("Add an event listener on the element");
-  let mouseDownHandled = 0;
-  function onMouseDown(e, id) {
-    is(id, "child-element", "The mousedown event was triggered on the element");
-    mouseDownHandled++;
-  }
-  el.addEventListener("mousedown", onMouseDown);
+    let once = function once(target, event) {
+      return new Promise(done => {
+        target.addEventListener(event, done, { once: true });
+      });
+    };
 
-  info("Synthesizing an event on the element");
-  let onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
-  is(mouseDownHandled, 1, "The mousedown event was handled once before navigation");
+    let synthesizeMouseDown = function synthesizeMouseDown(x, y, win) {
+      // We need to make sure the inserted anonymous content can be targeted by the
+      // event right after having been inserted, and so we need to force a sync
+      // reflow.
+      win.document.documentElement.offsetWidth;
+      EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
+    };
+
+    info("Synthesizing an event on the element");
+    let onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
+    is(mouseDownHandled, 1, "The mousedown event was handled once before navigation");
 
-  info("Navigating to a new page");
-  let loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
-  BrowserTestUtils.loadURI(browser, TEST_URL_2);
-  yield loaded;
-  // eslint-disable-next-line mozilla/no-cpows-in-tests
-  doc = gBrowser.selectedBrowser.contentWindow.document;
+    info("Navigating to a new page");
+    let loaded = once(this, "load");
+    content.location = url2;
+    await loaded;
+
+    // Update to the new document we just loaded
+    doc = content.document;
 
-  info("Try to access the element again");
-  is(el.getAttribute("class"), "child-element",
-    "The attribute is correct after navigation");
-  is(el.getTextContent(), "test content",
-    "The text content is correct after navigation");
+    info("Try to access the element again");
+    is(el.getAttribute("class"), "child-element",
+      "The attribute is correct after navigation");
+    is(el.getTextContent(), "test content",
+      "The text content is correct after navigation");
 
-  info("Synthesizing an event on the element again");
-  onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
-  is(mouseDownHandled, 1, "The mousedown event was not handled after navigation");
+    info("Synthesizing an event on the element again");
+    onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
+    is(mouseDownHandled, 1, "The mousedown event was not handled after navigation");
 
-  info("Destroying the helper");
-  env.destroy();
-  helper.destroy();
+    info("Destroying the helper");
+    env.destroy();
+    helper.destroy();
+  });
 
   gBrowser.removeCurrentTab();
 });
-
-function synthesizeMouseDown(x, y, win) {
-  // We need to make sure the inserted anonymous content can be targeted by the
-  // event right after having been inserted, and so we need to force a sync
-  // reflow.
-  win.document.documentElement.offsetWidth;
-  EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
-}
--- a/devtools/server/tests/browser/browser_canvasframe_helper_05.js
+++ b/devtools/server/tests/browser/browser_canvasframe_helper_05.js
@@ -2,112 +2,122 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test some edge cases of the CanvasFrameAnonymousContentHelper event handling
 // mechanism.
 
-// This makes sure the 'domnode' protocol actor type is known when importing
-// highlighter.
-require("devtools/server/actors/inspector");
-
-const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
-
-const {
-  CanvasFrameAnonymousContentHelper
-} = require("devtools/server/actors/highlighters/utils/markup");
-
 const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
 
-add_task(function* () {
-  let browser = yield addTab(TEST_URL);
-  // eslint-disable-next-line mozilla/no-cpows-in-tests
-  let doc = browser.contentDocument;
+add_task(async function () {
+  let browser = await addTab(TEST_URL);
+  await ContentTask.spawn(browser, null, async function () {
+    const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+    const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
+    const {
+      CanvasFrameAnonymousContentHelper
+    } = require("devtools/server/actors/highlighters/utils/markup");
+    let doc = content.document;
 
-  let nodeBuilder = () => {
-    let root = doc.createElement("div");
+    let nodeBuilder = () => {
+      let root = doc.createElement("div");
 
-    let parent = doc.createElement("div");
-    parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
-    parent.id = "parent-element";
-    root.appendChild(parent);
+      let parent = doc.createElement("div");
+      parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
+      parent.id = "parent-element";
+      root.appendChild(parent);
 
-    let child = doc.createElement("div");
-    child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
-    child.id = "child-element";
-    parent.appendChild(child);
+      let child = doc.createElement("div");
+      child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
+      child.id = "child-element";
+      parent.appendChild(child);
+
+      return root;
+    };
 
-    return root;
-  };
+    info("Building the helper");
+    let env = new HighlighterEnvironment();
+    env.initFromWindow(doc.defaultView);
+    let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
 
-  info("Building the helper");
-  let env = new HighlighterEnvironment();
-  env.initFromWindow(doc.defaultView);
-  let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+    info("Getting the parent and child elements");
+    let parentEl = helper.getElement("parent-element");
+    let childEl = helper.getElement("child-element");
 
-  info("Getting the parent and child elements");
-  let parentEl = helper.getElement("parent-element");
-  let childEl = helper.getElement("child-element");
+    info("Adding an event listener on both elements");
+    let mouseDownHandled = [];
+    function onMouseDown(e, id) {
+      mouseDownHandled.push(id);
+    }
+    parentEl.addEventListener("mousedown", onMouseDown);
+    childEl.addEventListener("mousedown", onMouseDown);
 
-  info("Adding an event listener on both elements");
-  let mouseDownHandled = [];
-  function onMouseDown(e, id) {
-    mouseDownHandled.push(id);
-  }
-  parentEl.addEventListener("mousedown", onMouseDown);
-  childEl.addEventListener("mousedown", onMouseDown);
+    function once(target, event) {
+      return new Promise(done => {
+        target.addEventListener(event, done, { once: true });
+      });
+    }
+
+    info("Synthesizing an event on the child element");
+    let onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
 
-  info("Synthesizing an event on the child element");
-  let onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
+    is(mouseDownHandled.length, 2, "The mousedown event was handled twice");
+    is(mouseDownHandled[0], "child-element",
+      "The mousedown event was handled on the child element");
+    is(mouseDownHandled[1], "parent-element",
+      "The mousedown event was handled on the parent element");
+
+    info("Synthesizing an event on the parent, outside of the child element");
+    mouseDownHandled = [];
+    onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(250, 250, doc.defaultView);
+    await onDocMouseDown;
 
-  is(mouseDownHandled.length, 2, "The mousedown event was handled twice");
-  is(mouseDownHandled[0], "child-element",
-    "The mousedown event was handled on the child element");
-  is(mouseDownHandled[1], "parent-element",
-    "The mousedown event was handled on the parent element");
+    is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
+    is(mouseDownHandled[0], "parent-element",
+      "The mousedown event was handled on the parent element");
 
-  info("Synthesizing an event on the parent, outside of the child element");
-  mouseDownHandled = [];
-  onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(250, 250, doc.defaultView);
-  yield onDocMouseDown;
+    info("Removing the event listener");
+    parentEl.removeEventListener("mousedown", onMouseDown);
+    childEl.removeEventListener("mousedown", onMouseDown);
 
-  is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
-  is(mouseDownHandled[0], "parent-element",
-    "The mousedown event was handled on the parent element");
+    info("Adding an event listener on the parent element only");
+    mouseDownHandled = [];
+    parentEl.addEventListener("mousedown", onMouseDown);
 
-  info("Removing the event listener");
-  parentEl.removeEventListener("mousedown", onMouseDown);
-  childEl.removeEventListener("mousedown", onMouseDown);
+    info("Synthesizing an event on the child element");
+    onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
 
-  info("Adding an event listener on the parent element only");
-  mouseDownHandled = [];
-  parentEl.addEventListener("mousedown", onMouseDown);
+    is(mouseDownHandled.length, 1, "The mousedown event was handled once");
+    is(mouseDownHandled[0], "parent-element",
+      "The mousedown event did bubble to the parent element");
+
+    info("Removing the parent listener");
+    parentEl.removeEventListener("mousedown", onMouseDown);
+
+    env.destroy();
+    helper.destroy();
 
-  info("Synthesizing an event on the child element");
-  onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
-
-  is(mouseDownHandled.length, 1, "The mousedown event was handled once");
-  is(mouseDownHandled[0], "parent-element",
-    "The mousedown event did bubble to the parent element");
-
-  info("Removing the parent listener");
-  parentEl.removeEventListener("mousedown", onMouseDown);
-
-  env.destroy();
-  helper.destroy();
+    function synthesizeMouseDown(x, y, win) {
+      // We need to make sure the inserted anonymous content can be targeted by the
+      // event right after having been inserted, and so we need to force a sync
+      // reflow.
+      win.document.documentElement.offsetWidth;
+      // Minimal environment for EventUtils to work.
+      let EventUtils = {
+        window: content,
+        parent: content,
+        _EU_Ci: Components.interfaces,
+        _EU_Cc: Components.classes,
+      };
+      Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
+      EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
+    }
+  });
 
   gBrowser.removeCurrentTab();
 });
-
-function synthesizeMouseDown(x, y, win) {
-  // We need to make sure the inserted anonymous content can be targeted by the
-  // event right after having been inserted, and so we need to force a sync
-  // reflow.
-  win.document.documentElement.offsetWidth;
-  EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
-}
--- a/devtools/server/tests/browser/browser_canvasframe_helper_06.js
+++ b/devtools/server/tests/browser/browser_canvasframe_helper_06.js
@@ -2,100 +2,110 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test support for event propagation stop in the
 // CanvasFrameAnonymousContentHelper event handling mechanism.
 
-// This makes sure the 'domnode' protocol actor type is known when importing
-// highlighter.
-require("devtools/server/actors/inspector");
-
-const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
-
-const {
-  CanvasFrameAnonymousContentHelper
-} = require("devtools/server/actors/highlighters/utils/markup");
-
 const TEST_URL = "data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
 
-add_task(function* () {
-  let browser = yield addTab(TEST_URL);
-  // eslint-disable-next-line mozilla/no-cpows-in-tests
-  let doc = browser.contentDocument;
+add_task(async function () {
+  let browser = await addTab(TEST_URL);
+  await ContentTask.spawn(browser, null, async function () {
+    const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+    const {HighlighterEnvironment} = require("devtools/server/actors/highlighters");
+    const {
+      CanvasFrameAnonymousContentHelper
+    } = require("devtools/server/actors/highlighters/utils/markup");
+    let doc = content.document;
 
-  let nodeBuilder = () => {
-    let root = doc.createElement("div");
+    let nodeBuilder = () => {
+      let root = doc.createElement("div");
 
-    let parent = doc.createElement("div");
-    parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
-    parent.id = "parent-element";
-    root.appendChild(parent);
+      let parent = doc.createElement("div");
+      parent.style = "pointer-events:auto;width:300px;height:300px;background:yellow;";
+      parent.id = "parent-element";
+      root.appendChild(parent);
+
+      let child = doc.createElement("div");
+      child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
+      child.id = "child-element";
+      parent.appendChild(child);
 
-    let child = doc.createElement("div");
-    child.style = "pointer-events:auto;width:200px;height:200px;background:red;";
-    child.id = "child-element";
-    parent.appendChild(child);
+      return root;
+    };
 
-    return root;
-  };
+    info("Building the helper");
+    let env = new HighlighterEnvironment();
+    env.initFromWindow(doc.defaultView);
+    let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+
+    info("Getting the parent and child elements");
+    let parentEl = helper.getElement("parent-element");
+    let childEl = helper.getElement("child-element");
 
-  info("Building the helper");
-  let env = new HighlighterEnvironment();
-  env.initFromWindow(doc.defaultView);
-  let helper = new CanvasFrameAnonymousContentHelper(env, nodeBuilder);
+    info("Adding an event listener on both elements");
+    let mouseDownHandled = [];
 
-  info("Getting the parent and child elements");
-  let parentEl = helper.getElement("parent-element");
-  let childEl = helper.getElement("child-element");
+    function onParentMouseDown(e, id) {
+      mouseDownHandled.push(id);
+    }
+    parentEl.addEventListener("mousedown", onParentMouseDown);
 
-  info("Adding an event listener on both elements");
-  let mouseDownHandled = [];
+    function onChildMouseDown(e, id) {
+      mouseDownHandled.push(id);
+      e.stopPropagation();
+    }
+    childEl.addEventListener("mousedown", onChildMouseDown);
 
-  function onParentMouseDown(e, id) {
-    mouseDownHandled.push(id);
-  }
-  parentEl.addEventListener("mousedown", onParentMouseDown);
+    function once(target, event) {
+      return new Promise(done => {
+        target.addEventListener(event, done, { once: true });
+      });
+    }
 
-  function onChildMouseDown(e, id) {
-    mouseDownHandled.push(id);
-    e.stopPropagation();
-  }
-  childEl.addEventListener("mousedown", onChildMouseDown);
+    info("Synthesizing an event on the child element");
+    let onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(100, 100, doc.defaultView);
+    await onDocMouseDown;
 
-  info("Synthesizing an event on the child element");
-  let onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(100, 100, doc.defaultView);
-  yield onDocMouseDown;
+    is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
+    is(mouseDownHandled[0], "child-element",
+      "The mousedown event was handled on the child element");
+
+    info("Synthesizing an event on the parent, outside of the child element");
+    mouseDownHandled = [];
+    onDocMouseDown = once(doc, "mousedown");
+    synthesizeMouseDown(250, 250, doc.defaultView);
+    await onDocMouseDown;
 
-  is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
-  is(mouseDownHandled[0], "child-element",
-    "The mousedown event was handled on the child element");
+    is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
+    is(mouseDownHandled[0], "parent-element",
+      "The mousedown event was handled on the parent element");
 
-  info("Synthesizing an event on the parent, outside of the child element");
-  mouseDownHandled = [];
-  onDocMouseDown = once(doc, "mousedown");
-  synthesizeMouseDown(250, 250, doc.defaultView);
-  yield onDocMouseDown;
+    info("Removing the event listener");
+    parentEl.removeEventListener("mousedown", onParentMouseDown);
+    childEl.removeEventListener("mousedown", onChildMouseDown);
+
+    env.destroy();
+    helper.destroy();
 
-  is(mouseDownHandled.length, 1, "The mousedown event was handled only once");
-  is(mouseDownHandled[0], "parent-element",
-    "The mousedown event was handled on the parent element");
-
-  info("Removing the event listener");
-  parentEl.removeEventListener("mousedown", onParentMouseDown);
-  childEl.removeEventListener("mousedown", onChildMouseDown);
-
-  env.destroy();
-  helper.destroy();
+    function synthesizeMouseDown(x, y, win) {
+      // We need to make sure the inserted anonymous content can be targeted by the
+      // event right after having been inserted, and so we need to force a sync
+      // reflow.
+      win.document.documentElement.offsetWidth;
+      // Minimal environment for EventUtils to work.
+      let EventUtils = {
+        window: content,
+        parent: content,
+        _EU_Ci: Components.interfaces,
+        _EU_Cc: Components.classes,
+      };
+      Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
+      EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
+    }
+  });
 
   gBrowser.removeCurrentTab();
 });
-
-function synthesizeMouseDown(x, y, win) {
-  // We need to make sure the inserted anonymous content can be targeted by the
-  // event right after having been inserted, and so we need to force a sync
-  // reflow.
-  win.document.documentElement.offsetWidth;
-  EventUtils.synthesizeMouseAtPoint(x, y, {type: "mousedown"}, win);
-}
--- a/devtools/server/tests/browser/head.js
+++ b/devtools/server/tests/browser/head.js
@@ -1,27 +1,23 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 /* eslint no-unused-vars: [2, {"vars": "local"}] */
+/* import-globals-from ../../../client/framework/test/shared-head.js */
 
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cu = Components.utils;
+Services.scriptloader.loadSubScript(
+  "chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js",
+  this);
 
-const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
-const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
 const {DebuggerClient} = require("devtools/shared/client/debugger-client");
 const {DebuggerServer} = require("devtools/server/main");
-const {defer} = require("promise");
-const DevToolsUtils = require("devtools/shared/DevToolsUtils");
-const Services = require("Services");
 
 const PATH = "browser/devtools/server/tests/browser/";
 const MAIN_DOMAIN = "http://test1.example.org/" + PATH;
 const ALT_DOMAIN = "http://sectest1.example.org/" + PATH;
 const ALT_DOMAIN_SECURED = "https://sectest1.example.org:443/" + PATH;
 
 // GUID to be used as a separator in compound keys. This must match the same
 // constant in devtools/server/actors/storage.js,