diff --git a/docshell/test/unit/test_allowJavascript.js b/docshell/test/unit/test_allowJavascript.js index c09e1108d78e..4b760c3e3b02 100644 --- a/docshell/test/unit/test_allowJavascript.js +++ b/docshell/test/unit/test_allowJavascript.js @@ -31,8 +31,12 @@ server.registerPathHandler("/", (request, response) => { response.write(HTML); }); +function getResourceURI(file) { + return Services.io.newFileURI(do_get_file(file)).spec; +} + const { AllowJavascriptParent } = ChromeUtils.import( - "resource://test/AllowJavascriptParent.jsm" + getResourceURI("AllowJavascriptParent.jsm") ); async function assertScriptsAllowed(bc, expectAllowed, desc) { @@ -65,11 +69,11 @@ add_task(async function() { ChromeUtils.registerWindowActor(ACTOR, { allFrames: true, child: { - moduleURI: "resource://test/AllowJavascriptChild.jsm", + moduleURI: getResourceURI("AllowJavascriptChild.jsm"), events: { load: { capture: true } }, }, parent: { - moduleURI: "resource://test/AllowJavascriptParent.jsm", + moduleURI: getResourceURI("AllowJavascriptParent.jsm"), }, }); diff --git a/dom/indexedDB/test/unit/test_globalObjects_other.js b/dom/indexedDB/test/unit/test_globalObjects_other.js index 3727384ae690..d4d60d8bad90 100644 --- a/dom/indexedDB/test/unit/test_globalObjects_other.js +++ b/dom/indexedDB/test/unit/test_globalObjects_other.js @@ -14,7 +14,7 @@ function* testSteps() { // Test for IDBKeyRange and indexedDB availability in JS modules. const { GlobalObjectsModule } = ChromeUtils.import( - "resource://test/GlobalObjectsModule.jsm" + getSpec("GlobalObjectsModule.jsm") ); let test = new GlobalObjectsModule(); test.ok = ok; diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 104f260f1779..c3470970794d 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -1253,12 +1253,6 @@ nsresult mozJSComponentLoader::Import(JSContext* aCx, // Note: This implies EnsureURI(). MOZ_TRY(info.EnsureResolvedURI()); - // Reject imports from untrusted sources. - if ((!info.URI()->SchemeIs("resource")) && - (!info.URI()->SchemeIs("chrome"))) { - return NS_ERROR_DOM_SECURITY_ERR; - } - // get the JAR if there is one nsCOMPtr jarURI; jarURI = do_QueryInterface(info.ResolvedURI(), &rv); diff --git a/js/xpconnect/tests/unit/test_bug408412.js b/js/xpconnect/tests/unit/test_bug408412.js index 06321a6f876b..e73c15cab8ad 100644 --- a/js/xpconnect/tests/unit/test_bug408412.js +++ b/js/xpconnect/tests/unit/test_bug408412.js @@ -3,8 +3,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ function run_test() { + var file = do_get_file("syntax_error.jsm"); + var ios = Cc["@mozilla.org/network/io-service;1"] + .getService(Ci.nsIIOService); + var uri = ios.newFileURI(file); + try { - ChromeUtils.import("resource://test/syntax_error.jsm"); + ChromeUtils.import(uri.spec); do_throw("Failed to report any error at all"); } catch (e) { Assert.notEqual(/^SyntaxError:/.exec(e + ''), null); diff --git a/js/xpconnect/tests/unit/test_import.js b/js/xpconnect/tests/unit/test_import.js index 4aa72c72c6d3..9be6158fd11b 100644 --- a/js/xpconnect/tests/unit/test_import.js +++ b/js/xpconnect/tests/unit/test_import.js @@ -49,10 +49,8 @@ function run_test() { dump("resURI: " + resURI + "\n"); var filePath = res.resolveURI(resURI); var scope3 = {}; - Assert.throws( - () => ChromeUtils.import(filePath, scope3), - /SecurityError/, "Expecting file URI not to be imported" - ); + Assert.throws(() => ChromeUtils.import(filePath, scope3), + /NS_ERROR_UNEXPECTED/); // make sure we throw when the second arg is bogus var didThrow = false; @@ -90,12 +88,4 @@ function run_test() { .createInstance(Ci.nsIClassInfo); Assert.ok(Boolean(bar)); Assert.ok(bar.contractID == contractID + "2"); - - // make sure we throw when the URL scheme is not known - var scope4 = {}; - const wrongScheme = "data:text/javascript,var a = {a:1}"; - Assert.throws( - () => ChromeUtils.import(wrongScheme, scope4), - /SecurityError/, "Expecting data URI not to be imported" - ); } diff --git a/toolkit/components/backgroundtasks/tests/BackgroundTask_crash.jsm b/toolkit/components/backgroundtasks/tests/BackgroundTask_crash.jsm index fb64983e12f6..b3d7c25705c0 100644 --- a/toolkit/components/backgroundtasks/tests/BackgroundTask_crash.jsm +++ b/toolkit/components/backgroundtasks/tests/BackgroundTask_crash.jsm @@ -12,15 +12,9 @@ async function runBackgroundTask(commandLine) { // sibling `testcrasher` library to be in the current working // directory. Fail right away if we can't find the module or the // native library. - let cwd = Services.dirsvc.get("CurWorkD", Ci.nsIFile); - let protocolHandler = Services.io - .getProtocolHandler("resource") - .QueryInterface(Ci.nsIResProtocolHandler); - var curDirURI = Services.io.newFileURI(cwd); - protocolHandler.setSubstitution("test", curDirURI); - + let testPath = Services.dirsvc.get("CurWorkD", Ci.nsIFile).path; const { CrashTestUtils } = ChromeUtils.import( - "resource://test/CrashTestUtils.jsm" + `file://${testPath}/CrashTestUtils.jsm` ); // Get the temp dir. diff --git a/toolkit/components/extensions/moz.build b/toolkit/components/extensions/moz.build index 8cc1fc1bec37..e2f408da316a 100755 --- a/toolkit/components/extensions/moz.build +++ b/toolkit/components/extensions/moz.build @@ -53,8 +53,6 @@ TESTING_JS_MODULES += [ "ExtensionTestCommon.jsm", "ExtensionXPCShellUtils.jsm", "MessageChannel.jsm", - "test/xpcshell/data/TestWorkerWatcherChild.jsm", - "test/xpcshell/data/TestWorkerWatcherParent.jsm", ] DIRS += [ diff --git a/toolkit/components/extensions/test/xpcshell/head_service_worker.js b/toolkit/components/extensions/test/xpcshell/head_service_worker.js index cefd26f6afda..a2c8cf326039 100644 --- a/toolkit/components/extensions/test/xpcshell/head_service_worker.js +++ b/toolkit/components/extensions/test/xpcshell/head_service_worker.js @@ -111,12 +111,15 @@ class TestWorkerWatcher extends ExtensionCommon.EventEmitter { registerProcessActor() { const { JS_ACTOR_NAME } = this; + const getModuleURI = fileName => + Services.io.newFileURI(do_get_file(`${this.dataRelPath}/${fileName}`)) + .spec; ChromeUtils.registerProcessActor(JS_ACTOR_NAME, { parent: { - moduleURI: `resource://testing-common/${JS_ACTOR_NAME}Parent.jsm`, + moduleURI: getModuleURI(`${JS_ACTOR_NAME}Parent.jsm`), }, child: { - moduleURI: `resource://testing-common/${JS_ACTOR_NAME}Child.jsm`, + moduleURI: getModuleURI(`${JS_ACTOR_NAME}Child.jsm`), }, }); }