Bug 1500072 - Add browserLoader reference on window when flags.testing is true;r=ochameau
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 13 Feb 2019 15:44:05 +0000
changeset 458914 0fb5dc2c5657
parent 458913 ac92eed544e9
child 458915 785a3ad7dc4f
push id35551
push usershindli@mozilla.com
push dateWed, 13 Feb 2019 21:34:09 +0000
treeherdermozilla-central@08f794a4928e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1500072
milestone67.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 1500072 - Add browserLoader reference on window when flags.testing is true;r=ochameau Depends on D19582 Differential Revision: https://phabricator.services.mozilla.com/D19638
devtools/client/framework/test/metrics/browser_metrics_webconsole.js
devtools/client/shared/browser-loader.js
devtools/client/shared/test/browser_browserloader_mocks.js
devtools/client/shared/test/browser_require_raw.js
devtools/client/webconsole/main.js
--- a/devtools/client/framework/test/metrics/browser_metrics_webconsole.js
+++ b/devtools/client/framework/test/metrics/browser_metrics_webconsole.js
@@ -12,20 +12,20 @@
  * of characters in those modules, when opening the webconsole. These metrics are
  * retrieved by perfherder via logs.
  */
 
 const TEST_URL = "data:text/html;charset=UTF-8,<div>Webconsole modules load test</div>";
 
 add_task(async function() {
   const toolbox = await openNewTabAndToolbox(TEST_URL, "webconsole");
-  const hud = toolbox.getCurrentPanel().hud;
+  const panel = toolbox.getCurrentPanel();
 
   // Retrieve the browser loader dedicated to the WebConsole.
-  const webconsoleLoader = hud.ui.browserLoader;
+  const webconsoleLoader = panel._frameWindow.getBrowserLoaderForWindow();
   const loaders = [loader.provider.loader, webconsoleLoader.loader];
 
   runMetricsTest({
     filterString: "devtools/client/webconsole",
     loaders,
     panelName: "webconsole",
   });
 });
--- a/devtools/client/shared/browser-loader.js
+++ b/devtools/client/shared/browser-loader.js
@@ -183,16 +183,20 @@ function BrowserLoaderBuilder({ baseURI,
         lazyServiceGetter: devtools.lazyServiceGetter,
         lazyRequireGetter: this.lazyRequireGetter.bind(this),
       },
     },
   };
 
   const mainModule = loaders.Module(baseURI, joinURI(baseURI, "main.js"));
   this.loader = loaders.Loader(opts);
+  // When running tests, expose the BrowserLoader instance for metrics tests.
+  if (flags.testing) {
+    window.getBrowserLoaderForWindow = () => this;
+  }
   this.require = loaders.Require(this.loader, mainModule);
 }
 
 BrowserLoaderBuilder.prototype = {
   /**
    * Define a getter property on the given object that requires the given
    * module. This enables delaying importing modules until the module is
    * actually used.
--- a/devtools/client/shared/test/browser_browserloader_mocks.js
+++ b/devtools/client/shared/test/browser_browserloader_mocks.js
@@ -97,10 +97,11 @@ function testWithRegularDevtoolsModule()
   ok(!getMockedModule(DEVTOOLS_MODULE_URI), "Has no mock entry for the full URI");
   const m4 = browserRequire(DEVTOOLS_MODULE_PATH);
   is(m4.joinURI("http://a", "b"), "http://a/b", "Original module can be required again");
 }
 
 function test() {
   testWithChromeScheme();
   testWithRegularDevtoolsModule();
+  delete window.getBrowserLoaderForWindow;
   finish();
 }
--- a/devtools/client/shared/test/browser_require_raw.js
+++ b/devtools/client/shared/test/browser_require_raw.js
@@ -11,10 +11,11 @@ const { require: browserRequire } = Brow
   baseURI: "resource://devtools/client/shared/",
   window,
 });
 
 const variableFileContents = browserRequire("raw!devtools/client/themes/variables.css");
 
 function test() {
   ok(variableFileContents.length > 0, "raw browserRequire worked");
+  delete window.getBrowserLoaderForWindow;
   finish();
 }
--- a/devtools/client/webconsole/main.js
+++ b/devtools/client/webconsole/main.js
@@ -7,19 +7,14 @@
 "use strict";
 
 const { BrowserLoader } = ChromeUtils.import("resource://devtools/client/shared/browser-loader.js");
 
 this.WebConsoleWrapper = function(parentNode, hud, toolbox, owner, document) {
   // Initialize module loader and load all modules of the new inline
   // preview feature. The entire code-base doesn't need any extra
   // privileges and runs entirely in content scope.
-  const browserLoader = BrowserLoader({
+  const WebConsoleWrapper = BrowserLoader({
     baseURI: "resource://devtools/client/webconsole/",
     window,
-  });
-
-  // Expose the browserLoader instance on the webconsole hud for metrics tests.
-  hud.browserLoader = browserLoader;
-
-  const WebConsoleWrapper = browserLoader.require("./webconsole-wrapper");
+  }).require("./webconsole-wrapper");
   return new WebConsoleWrapper(parentNode, hud, toolbox, owner, document);
 };