diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index b7a3e60b0a4..8f85d78d49f 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -4727,7 +4727,7 @@ function AddonWrapper(aAddon) { return aAddon.iconURL; if (this.hasResource("icon.png")) - return this.getResourceURL("icon.png"); + return this.getResourceURI("icon.png").spec; return null; }, this); @@ -4776,7 +4776,7 @@ function AddonWrapper(aAddon) { let screenshots = []; if (aAddon.type == "theme" && this.hasResource("preview.png")) - screenshots.push(this.getResourceURL("preview.png")); + screenshots.push(this.getResourceURI("preview.png").spec); return screenshots; }); @@ -4901,7 +4901,7 @@ function AddonWrapper(aAddon) { return result; }, - this.getResourceURL = function(aPath) { + this.getResourceURI = function(aPath) { let bundle = null; if (aAddon instanceof DBAddonInternal) { bundle = aAddon._sourceBundle = aAddon._installLocation @@ -4913,10 +4913,10 @@ function AddonWrapper(aAddon) { if (bundle.isDirectory()) { bundle.append(aPath); - return Services.io.newFileURI(bundle).spec; + return Services.io.newFileURI(bundle); } - return buildJarURI(bundle, aPath).spec; + return buildJarURI(bundle, aPath); } } diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js index 61830a0280d..4d16e9f0765 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js @@ -100,7 +100,7 @@ function check_test_1() { dir.append("bootstrap1@tests.mozilla.org"); dir.append("bootstrap.js"); let uri = Services.io.newFileURI(dir).spec; - do_check_eq(b1.getResourceURL("bootstrap.js"), uri); + do_check_eq(b1.getResourceURI("bootstrap.js").spec, uri); AddonManager.getAddonsWithOperationsByTypes(null, function(list) { do_check_eq(list.length, 0); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug526598.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug526598.js index 8a3ff2762f7..1fe2ed2ecbb 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug526598.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug526598.js @@ -55,7 +55,7 @@ function run_test() { do_check_neq(a1, null); do_check_true(a1.hasResource("install.rdf")); - let uri = Services.io.newURI(a1.getResourceURL("install.rdf"), "UTF-8", null); + let uri = a1.getResourceURI("install.rdf"); do_check_true(uri instanceof AM_Ci.nsIFileURL); let file = uri.file; do_check_true(file.exists()); @@ -64,7 +64,7 @@ function run_test() { do_check_neq(a2, null); do_check_true(a2.hasResource("install.rdf")); - uri = Services.io.newURI(a2.getResourceURL("install.rdf"), "UTF-8", null); + uri = a2.getResourceURI("install.rdf"); do_check_true(uri instanceof AM_Ci.nsIFileURL); file = uri.file; do_check_true(file.exists()); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug541420.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug541420.js index 85320873746..7a421746f1c 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug541420.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug541420.js @@ -51,7 +51,7 @@ function run_test() { do_check_neq(addon, null); do_check_true(addon.hasResource("binary")); - let uri = Services.io.newURI(addon.getResourceURL("binary"), "UTF-8", null); + let uri = addon.getResourceURI("binary"); do_check_true(uri instanceof AM_Ci.nsIFileURL); let file = uri.file; do_check_true(file.exists()); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_getresource.js b/toolkit/mozapps/extensions/test/xpcshell/test_getresource.js new file mode 100644 index 00000000000..e2aabadbcaf --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_getresource.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// This verifies the functionality of getResourceURI +// There are two cases - with a filename it returns an nsIFileURL to the filename +// and with no parameters, it returns an nsIFileURL to the root of the addon + +function run_test() { + do_test_pending(); + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); + + startupManager(); + + installAllFiles([do_get_file("data/unsigned.xpi")], function() { + + restartManager(); + + AddonManager.getAddonByID("unsigned-xpi@tests.mozilla.org", + function(a1) { + + do_check_neq(a1, null); + do_check_true(a1.hasResource("install.rdf")); + let uri = a1.getResourceURI("install.rdf"); + do_check_true(uri instanceof AM_Ci.nsIFileURL); + + let uri2 = a1.getResourceURI(); + do_check_true(uri2 instanceof AM_Ci.nsIFileURL); + + let addonDir = gProfD.clone(); + addonDir.append("extensions"); + addonDir.append("unsigned-xpi@tests.mozilla.org"); + + do_check_eq(uri2.file.path, addonDir.path); + + a1.uninstall(); + + restartManager(); + + AddonManager.getAddonByID("unsigned-xpi@tests.mozilla.org", + function(newa1) { + do_check_eq(newa1, null); + + do_test_finished(); + }); + }); + }); +} diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_install.js b/toolkit/mozapps/extensions/test/xpcshell/test_install.js index 372953a3537..3116e1c7228 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js @@ -60,7 +60,7 @@ function run_test_1() { let file = do_get_addon("test_install1"); let uri = Services.io.newFileURI(file).spec; - do_check_eq(install.addon.getResourceURL("install.rdf"), "jar:" + uri + "!/install.rdf"); + do_check_eq(install.addon.getResourceURI("install.rdf").spec, "jar:" + uri + "!/install.rdf"); do_check_eq(install.addon.iconURL, "jar:" + uri + "!/icon.png"); do_check_eq(install.iconURL, null); @@ -132,7 +132,7 @@ function check_test_1() { dir.append("addon1@tests.mozilla.org"); dir.append("install.rdf"); let uri = Services.io.newFileURI(dir).spec; - do_check_eq(a1.getResourceURL("install.rdf"), uri); + do_check_eq(a1.getResourceURI("install.rdf").spec, uri); a1.uninstall(); restartManager(0);