Bug 1595112 - [remote] Cache chrome-remote-interface.js between browser chrome tests. r=remote-protocol-reviewers,ato
authorHenrik Skupin <mail@hskupin.info>
Fri, 15 Nov 2019 14:57:51 +0000
changeset 502178 b80efaa3e184d98e9ca691a4a35c0effc20d4573
parent 502177 f7094144a9f065c8821841f3774ac6734f547c01
child 502179 6d7fa567184ed7fe82d21e0f629c09d7f285f717
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersremote-protocol-reviewers, ato
bugs1595112
milestone72.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 1595112 - [remote] Cache chrome-remote-interface.js between browser chrome tests. r=remote-protocol-reviewers,ato By using loadSubScript() instead of injecting a script node into the hidden window, the content of chrome-remote-interface.js can be cached. Only the first load will take about 150ms, each test afterward will only have to spend about 30ms in getCDP(). Differential Revision: https://phabricator.services.mozilla.com/D53073
remote/test/browser/head.js
--- a/remote/test/browser/head.js
+++ b/remote/test/browser/head.js
@@ -1,19 +1,19 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+const { RemoteAgentError } = ChromeUtils.import(
+  "chrome://remote/content/Error.jsm"
+);
 const { RemoteAgent } = ChromeUtils.import(
   "chrome://remote/content/RemoteAgent.jsm"
 );
-const { RemoteAgentError } = ChromeUtils.import(
-  "chrome://remote/content/Error.jsm"
-);
 
 /**
  * Override `add_task` in order to translate chrome-remote-interface exceptions
  * into something that logs better errors on stdout
  */
 const add_plain_task = add_task.bind(this);
 this.add_task = function(taskFn, opts = {}) {
   const { createTab = true } = opts;
@@ -72,55 +72,49 @@ this.add_task = function(taskFn, opts = 
       // Close any additional tabs, so that only a single tab remains open
       while (gBrowser.tabs.length > 1) {
         gBrowser.removeCurrentTab();
       }
     }
   });
 };
 
-const CRI_URI =
-  "http://example.com/browser/remote/test/browser/chrome-remote-interface.js";
-
 /**
  * Create a test document in an invisible window.
  * This window will be automatically closed on test teardown.
  */
 function createTestDocument() {
   const browser = Services.appShell.createWindowlessBrowser(true);
-  const webNavigation = browser.docShell.QueryInterface(Ci.nsIWebNavigation);
+  registerCleanupFunction(() => browser.close());
+
   // Create a system principal content viewer to ensure there is a valid
   // empty document using system principal and avoid any wrapper issues
   // when using document's JS Objects.
+  const webNavigation = browser.docShell.QueryInterface(Ci.nsIWebNavigation);
   const system = Services.scriptSecurityManager.getSystemPrincipal();
   webNavigation.createAboutBlankContentViewer(system, system);
 
-  registerCleanupFunction(() => browser.close());
   return webNavigation.document;
 }
 
 /**
  * Retrieve an intance of CDP object from chrome-remote-interface library
  */
 async function getCDP() {
   // Instantiate a background test document in order to load the library
   // as in a web page
   const document = createTestDocument();
 
-  // Load chrome-remote-interface.js into this background test document
-  const script = document.createElement("script");
-  script.setAttribute("src", CRI_URI);
-  document.documentElement.appendChild(script);
-  await new Promise(resolve => {
-    script.addEventListener("load", resolve, { once: true });
-  });
+  const window = document.defaultView.wrappedJSObject;
+  Services.scriptloader.loadSubScript(
+    "chrome://mochitests/content/browser/remote/test/browser/chrome-remote-interface.js",
+    window
+  );
 
-  const window = document.defaultView.wrappedJSObject;
-
-  // Implements `criRequest` to be called by chrome-remeote-interface
+  // Implements `criRequest` to be called by chrome-remote-interface
   // library in order to do the cross-domain http request, which,
   // in a regular Web page, is impossible.
   window.criRequest = (options, callback) => {
     const { host, port, path } = options;
     const url = `http://${host}:${port}${path}`;
     const xhr = new XMLHttpRequest();
     xhr.open("GET", url, true);