Bug 1371065: Part 0 - Fix unit tests that use the SDK loader :/ r=Mossop
authorKris Maglione <maglione.k@gmail.com>
Fri, 08 Sep 2017 18:16:50 -0700
changeset 663371 46b8854f1f8e710947d857af39e7933e08c7f868
parent 663370 68fc77ea1ef10f5ae69dc67899566391be636ee3
child 663372 f725597fa0b41856bd0d46b7bb2c4feaaca101c7
push id79424
push userbmo:tchiovoloni@mozilla.com
push dateTue, 12 Sep 2017 23:17:54 +0000
reviewersMossop
bugs1371065
milestone57.0a1
Bug 1371065: Part 0 - Fix unit tests that use the SDK loader :/ r=Mossop MozReview-Commit-ID: 4ewrbY0FS09
browser/components/syncedtabs/test/xpcshell/head.js
browser/extensions/formautofill/test/unit/head.js
browser/extensions/shield-recipe-client/test/unit/head_xpc.js
services/fxaccounts/tests/xpcshell/head.js
services/sync/tests/unit/head_helpers.js
testing/mochitest/bootstrap.js
--- a/browser/components/syncedtabs/test/xpcshell/head.js
+++ b/browser/components/syncedtabs/test/xpcshell/head.js
@@ -8,23 +8,11 @@ XPCOMUtils.defineLazyGetter(this, "FxAcc
 });
 
 do_get_profile(); // fxa needs a profile directory for storage.
 
 // ================================================
 // Load mocking/stubbing library, sinon
 // docs: http://sinonjs.org/releases/v2.3.2/
 Cu.import("resource://gre/modules/Timer.jsm");
-const {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
-const loader = new Loader.Loader({
-  paths: {
-    "": "resource://testing-common/",
-  },
-  globals: {
-    setTimeout,
-    setInterval,
-    clearTimeout,
-    clearInterval,
-  },
-});
-const require = Loader.Require(loader, {id: ""});
-const sinon = require("sinon-2.3.2");
+Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
+/* globals sinon */
 // ================================================
--- a/browser/extensions/formautofill/test/unit/head.js
+++ b/browser/extensions/formautofill/test/unit/head.js
@@ -24,30 +24,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/FileUtils.jsm");
 
 do_get_profile();
 
 // ================================================
 // Load mocking/stubbing library, sinon
 // docs: http://sinonjs.org/releases/v2.3.2/
 Cu.import("resource://gre/modules/Timer.jsm");
-var {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
-var loader = new Loader.Loader({
-  paths: {
-    "": "resource://testing-common/",
-  },
-  globals: {
-    setTimeout,
-    setInterval,
-    clearTimeout,
-    clearInterval,
-  },
-});
-var require = Loader.Require(loader, {id: ""});
-var sinon = require("sinon-2.3.2");
+Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
+/* globals sinon */
 // ================================================
 
 // Load our bootstrap extension manifest so we can access our chrome/resource URIs.
 const EXTENSION_ID = "formautofill@mozilla.org";
 let extensionDir = Services.dirsvc.get("GreD", Ci.nsIFile);
 extensionDir.append("browser");
 extensionDir.append("features");
 extensionDir.append(EXTENSION_ID);
--- a/browser/extensions/shield-recipe-client/test/unit/head_xpc.js
+++ b/browser/extensions/shield-recipe-client/test/unit/head_xpc.js
@@ -20,23 +20,11 @@ if (!extensionDir.exists()) {
 }
 Components.manager.addBootstrappedManifestLocation(extensionDir);
 
 // ================================================
 // Load mocking/stubbing library, sinon
 // docs: http://sinonjs.org/releases/v2.3.2/
 /* exported sinon */
 Cu.import("resource://gre/modules/Timer.jsm");
-const {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
-const loader = new Loader.Loader({
-  paths: {
-    "": "resource://testing-common/",
-  },
-  globals: {
-    setTimeout,
-    setInterval,
-    clearTimeout,
-    clearInterval,
-  },
-});
-const require = Loader.Require(loader, {id: ""});
-this.sinon = require("sinon-2.3.2");
+Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
+/* globals sinon */
 // ================================================
--- a/services/fxaccounts/tests/xpcshell/head.js
+++ b/services/fxaccounts/tests/xpcshell/head.js
@@ -19,23 +19,11 @@ Cu.import("resource://gre/modules/XPCOMU
 
   ns.initTestLogging("Trace");
 }).call(this);
 
 // ================================================
 // Load mocking/stubbing library, sinon
 // docs: http://sinonjs.org/releases/v2.3.2/
 Cu.import("resource://gre/modules/Timer.jsm");
-var {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
-var loader = new Loader.Loader({
-  paths: {
-    "": "resource://testing-common/",
-  },
-  globals: {
-    setTimeout,
-    setInterval,
-    clearTimeout,
-    clearInterval,
-  },
-});
-var require = Loader.Require(loader, {id: ""});
-var sinon = require("sinon-2.3.2");
+Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
+/* globals sinon */
 // ================================================
--- a/services/sync/tests/unit/head_helpers.js
+++ b/services/sync/tests/unit/head_helpers.js
@@ -25,30 +25,18 @@ add_task(async function head_setup() {
     await this.Service.promiseInitialized;
   }
 });
 
 // ================================================
 // Load mocking/stubbing library, sinon
 // docs: http://sinonjs.org/releases/v2.3.2/
 Cu.import("resource://gre/modules/Timer.jsm");
-var {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
-var loader = new Loader.Loader({
-  paths: {
-    "": "resource://testing-common/",
-  },
-  globals: {
-    setTimeout,
-    setInterval,
-    clearTimeout,
-    clearInterval,
-  },
-});
-var require = Loader.Require(loader, {id: ""});
-var sinon = require("sinon-2.3.2");
+Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js", this);
+/* globals sinon */
 // ================================================
 
 XPCOMUtils.defineLazyGetter(this, "SyncPingSchema", function() {
   let ns = {};
   Cu.import("resource://gre/modules/FileUtils.jsm", ns);
   let stream = Cc["@mozilla.org/network/file-input-stream;1"]
                .createInstance(Ci.nsIFileInputStream);
   let jsonReader = Cc["@mozilla.org/dom/json;1"]
--- a/testing/mochitest/bootstrap.js
+++ b/testing/mochitest/bootstrap.js
@@ -45,25 +45,17 @@ function loadMochitest(e) {
   win.loadURI(url);
   if (flavor == "mochitest") {
     return;
   }
 
   WindowListener.setupWindow(win);
   Services.wm.addListener(WindowListener);
 
-  let overlay;
-  if (flavor == "jetpack-addon") {
-    overlay = "chrome://mochikit/content/jetpack-addon-overlay.xul";
-  } else if (flavor == "jetpack-package") {
-    overlay = "chrome://mochikit/content/jetpack-package-overlay.xul";
-  } else {
-    overlay = "chrome://mochikit/content/browser-test-overlay.xul";
-  }
-
+  let overlay = "chrome://mochikit/content/browser-test-overlay.xul";
   win.document.loadOverlay(overlay, null);
 }
 
 function startup(data, reason) {
   let win = Services.wm.getMostRecentWindow("navigator:browser");
   // wait for event fired from start_desktop.js containing the
   // suite and url to load
   win.addEventListener('mochitest-load', loadMochitest);