Bug 1383215: Part 5 - Update tests that relied on loading the same JSM from multiple URLs.
authorKris Maglione <maglione.k@gmail.com>
Fri, 21 Jul 2017 18:01:42 -0700
changeset 419497 df302a197bca4990e47bce4b31dd00d051e7f079
parent 419496 03777f604c6ca9dd56de4d8314284f7303fda46b
child 419498 3923ce220df31c0a1fb589158f1d2a3f40a93aef
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1383215
milestone56.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 1383215: Part 5 - Update tests that relied on loading the same JSM from multiple URLs. MozReview-Commit-ID: KEXGiMrauH7
addon-sdk/source/test/fixtures/native-addon-test/index.js
js/xpconnect/loader/XPCOMUtils.jsm
js/xpconnect/tests/components/js/xpctest_attributes.js
js/xpconnect/tests/components/js/xpctest_bug809674.js
js/xpconnect/tests/components/js/xpctest_interfaces.js
js/xpconnect/tests/components/js/xpctest_params.js
js/xpconnect/tests/components/js/xpctest_returncode_child.js
js/xpconnect/tests/components/js/xpctest_utils.js
js/xpconnect/tests/unit/test_import.js
js/xpconnect/tests/unit/test_isModuleLoaded.js
js/xpconnect/tests/unit/test_returncode.js
xpcom/tests/unit/data/main_process_directive_service.js
xpcom/tests/unit/test_process_directives.js
--- a/addon-sdk/source/test/fixtures/native-addon-test/index.js
+++ b/addon-sdk/source/test/fixtures/native-addon-test/index.js
@@ -16,17 +16,22 @@ exports.customMainModule = require('test
 exports.customMainModuleRelative = require('test-custom-main-relative');
 exports.defaultMain = require('test-default-main');
 exports.testJSON = require('./dir/c');
 exports.dummyModule = require('./dir/dummy');
 
 exports.eventCore = require('sdk/event/core');
 exports.promise = require('sdk/core/promise');
 
-exports.localJSM  = require('./dir/test.jsm');
+if (module.uri.startsWith("file:"))
+  // We can't load the same file multiple times with different URLs, so
+  // skip this one.
+  exports.localJSM = { test: "this is a jsm" };
+else
+  exports.localJSM = require('./dir/test.jsm');
 exports.promisejsm = require('modules/Promise.jsm').Promise;
 exports.require = require;
 
 var math = require('test-math');
 exports.areModulesCached = (math === exports.math);
 
 // Added noise to test AST walker
 function square (x) {
--- a/js/xpconnect/loader/XPCOMUtils.jsm
+++ b/js/xpconnect/loader/XPCOMUtils.jsm
@@ -452,19 +452,19 @@ this.XPCOMUtils = {
   /**
    * Allows you to fake a relative import. Expects the global object from the
    * module that's calling us, and the relative filename that we wish to import.
    */
   importRelative: function XPCOMUtils__importRelative(that, path, scope) {
     if (!("__URI__" in that))
       throw Error("importRelative may only be used from a JSM, and its first argument "+
                   "must be that JSM's global object (hint: use this)");
-    let uri = that.__URI__;
-    let i = uri.lastIndexOf("/");
-    Components.utils.import(uri.substring(0, i+1) + path, scope || that);
+
+    Cu.importGlobalProperties(["URL"]);
+    Components.utils.import(new URL(path, that.__URI__).href, scope || that);
   },
 
   /**
    * generates a singleton nsIFactory implementation that can be used as
    * the _xpcom_factory of the component.
    * @param aServiceConstructor
    *        Constructor function of the component.
    */
--- a/js/xpconnect/tests/components/js/xpctest_attributes.js
+++ b/js/xpconnect/tests/components/js/xpctest_attributes.js
@@ -1,12 +1,12 @@
 /* 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/. */
-Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function TestObjectReadWrite() {}
 TestObjectReadWrite.prototype = {
 
   /* Boilerplate */
   QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestObjectReadWrite"]]),
   contractID: "@mozilla.org/js/xpc/test/js/ObjectReadWrite;1",
   classID: Components.ID("{8ff41d9c-66e9-4453-924a-7d8de0a5e966}"),
--- a/js/xpconnect/tests/components/js/xpctest_bug809674.js
+++ b/js/xpconnect/tests/components/js/xpctest_bug809674.js
@@ -1,12 +1,12 @@
 /* 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/. */
-Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function TestBug809674() {}
 TestBug809674.prototype = {
 
   /* Boilerplate */
   QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestBug809674"]]),
   contractID: "@mozilla.org/js/xpc/test/js/Bug809674;1",
   classID: Components.ID("{2df46559-da21-49bf-b863-0d7b7bbcbc73}"),
--- a/js/xpconnect/tests/components/js/xpctest_interfaces.js
+++ b/js/xpconnect/tests/components/js/xpctest_interfaces.js
@@ -1,12 +1,12 @@
 /* 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/. */
-Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function TestInterfaceA() {}
 TestInterfaceA.prototype = {
 
   /* Boilerplate */
   QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestInterfaceA"]]),
   contractID: "@mozilla.org/js/xpc/test/js/TestInterfaceA;1",
   classID: Components.ID("{3c8fd2f5-970c-42c6-b5dd-cda1c16dcfd8}"),
--- a/js/xpconnect/tests/components/js/xpctest_params.js
+++ b/js/xpconnect/tests/components/js/xpctest_params.js
@@ -1,12 +1,12 @@
 /* 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/. */
-Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function TestParams() {
 }
 
 /* For once I'm happy that JS is weakly typed. */
 function f(a, b) {
     var rv = b.value;
     b.value = a;
--- a/js/xpconnect/tests/components/js/xpctest_returncode_child.js
+++ b/js/xpconnect/tests/components/js/xpctest_returncode_child.js
@@ -1,13 +1,13 @@
 /* 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/. */
 const {interfaces: Ci, classes: Cc, utils: Cu, results: Cr} = Components;
-Cu.import("resource:///modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function TestReturnCodeChild() {}
 TestReturnCodeChild.prototype = {
 
   /* Boilerplate */
   QueryInterface: XPCOMUtils.generateQI([Ci["nsIXPCTestReturnCodeChild"]]),
   contractID: "@mozilla.org/js/xpc/test/js/ReturnCodeChild;1",
   classID: Components.ID("{38dd78aa-467f-4fad-8dcf-4383a743e235}"),
--- a/js/xpconnect/tests/components/js/xpctest_utils.js
+++ b/js/xpconnect/tests/components/js/xpctest_utils.js
@@ -1,13 +1,13 @@
 /* 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/. */
 
-Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function TestUtils() {}
 TestUtils.prototype = {
 
   /* Boilerplate */
   QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestUtils"]]),
   contractID: "@mozilla.org/js/xpc/test/js/TestUtils;1",
   classID: Components.ID("{e86573c4-a384-441a-8c92-7b99e8575b28}"),
--- a/js/xpconnect/tests/unit/test_import.js
+++ b/js/xpconnect/tests/unit/test_import.js
@@ -34,21 +34,18 @@ function run_test() {
 
   // try on a new object using the resolved URL
   var res = Components.classes["@mozilla.org/network/protocol;1?name=resource"]
                       .getService(Components.interfaces.nsIResProtocolHandler);
   var resURI = res.newURI("resource://gre/modules/XPCOMUtils.jsm");
   dump("resURI: " + resURI + "\n");
   var filePath = res.resolveURI(resURI);
   var scope3 = {};
-  Components.utils.import(filePath, scope3);
-  do_check_eq(typeof(scope3.XPCOMUtils), "object");
-  do_check_eq(typeof(scope3.XPCOMUtils.generateNSGetFactory), "function");
-  
-  do_check_true(scope3.XPCOMUtils == scope.XPCOMUtils);
+  Assert.throws(() => Components.utils.import(filePath, scope3),
+                /NS_ERROR_UNEXPECTED/);
 
   // make sure we throw when the second arg is bogus
   var didThrow = false;
   try {
       Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", "wrong");
   } catch (ex) {
       print("exception (expected): " + ex);
       didThrow = true;
--- a/js/xpconnect/tests/unit/test_isModuleLoaded.js
+++ b/js/xpconnect/tests/unit/test_isModuleLoaded.js
@@ -16,18 +16,9 @@ function run_test() {
                 "isModuleLoaded returned correct value for non-loaded module");
   try {
     Cu.import("resource://gre/modules/ISO8601DateUtils1.jsm");
     do_check_true(false,
                   "Should have thrown while trying to load a non existing file");
   } catch (ex) {}
   do_check_true(!Cu.isModuleLoaded("resource://gre/modules/ISO8601DateUtils1.jsm"),
                 "isModuleLoaded returned correct value for non-loaded module");
-
-  // incorrect url
-  try {
-    Cu.isModuleLoaded("resource://modules/ISO8601DateUtils1.jsm");
-    do_check_true(false,
-                  "Should have thrown while trying to load a non existing file");
-  } catch (ex) {
-    do_check_true(true, "isModuleLoaded threw an exception while loading incorrect uri");
-  }
 }
--- a/js/xpconnect/tests/unit/test_returncode.js
+++ b/js/xpconnect/tests/unit/test_returncode.js
@@ -1,15 +1,15 @@
 /* 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/. */
 
 const {interfaces: Ci, classes: Cc, utils: Cu, manager: Cm, results: Cr} = Components;
 
-Cu.import("resource:///modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function getConsoleMessages() {
   let consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
   let messages = consoleService.getMessageArray().map((m) => m.toString());
   // reset ready for the next call.
   consoleService.reset();
   return messages;
 }
--- a/xpcom/tests/unit/data/main_process_directive_service.js
+++ b/xpcom/tests/unit/data/main_process_directive_service.js
@@ -1,12 +1,12 @@
 /* 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/. */
-Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function TestProcessDirective() {}
 TestProcessDirective.prototype = {
 
   /* Boilerplate */
   QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupportsString]),
   contractID: "@mozilla.org/xpcom/tests/MainProcessDirectiveTest;1",
   classID: Components.ID("{9b6f4160-45be-11e4-916c-0800200c9a66}"),
--- a/xpcom/tests/unit/test_process_directives.js
+++ b/xpcom/tests/unit/test_process_directives.js
@@ -1,12 +1,12 @@
 var Ci = Components.interfaces;
 var Cc = Components.classes;
 
-Components.utils.import("resource:///modules/Services.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
 function run_test()
 {
   Components.manager.autoRegister(do_get_file("data/process_directive.manifest"));
 
   let isChild = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
 
   if (isChild) {