Bug 563262: Rename GetResourceURL to GetResourceURI and have it return a URI. r=Mossop

This commit is contained in:
Michael Kaply 2010-06-21 17:13:52 -05:00
Родитель c824d5d4d7
Коммит 3580937625
6 изменённых файлов: 59 добавлений и 11 удалений

Просмотреть файл

@ -4727,7 +4727,7 @@ function AddonWrapper(aAddon) {
return aAddon.iconURL; return aAddon.iconURL;
if (this.hasResource("icon.png")) if (this.hasResource("icon.png"))
return this.getResourceURL("icon.png"); return this.getResourceURI("icon.png").spec;
return null; return null;
}, this); }, this);
@ -4776,7 +4776,7 @@ function AddonWrapper(aAddon) {
let screenshots = []; let screenshots = [];
if (aAddon.type == "theme" && this.hasResource("preview.png")) if (aAddon.type == "theme" && this.hasResource("preview.png"))
screenshots.push(this.getResourceURL("preview.png")); screenshots.push(this.getResourceURI("preview.png").spec);
return screenshots; return screenshots;
}); });
@ -4901,7 +4901,7 @@ function AddonWrapper(aAddon) {
return result; return result;
}, },
this.getResourceURL = function(aPath) { this.getResourceURI = function(aPath) {
let bundle = null; let bundle = null;
if (aAddon instanceof DBAddonInternal) { if (aAddon instanceof DBAddonInternal) {
bundle = aAddon._sourceBundle = aAddon._installLocation bundle = aAddon._sourceBundle = aAddon._installLocation
@ -4913,10 +4913,10 @@ function AddonWrapper(aAddon) {
if (bundle.isDirectory()) { if (bundle.isDirectory()) {
bundle.append(aPath); bundle.append(aPath);
return Services.io.newFileURI(bundle).spec; return Services.io.newFileURI(bundle);
} }
return buildJarURI(bundle, aPath).spec; return buildJarURI(bundle, aPath);
} }
} }

Просмотреть файл

@ -100,7 +100,7 @@ function check_test_1() {
dir.append("bootstrap1@tests.mozilla.org"); dir.append("bootstrap1@tests.mozilla.org");
dir.append("bootstrap.js"); dir.append("bootstrap.js");
let uri = Services.io.newFileURI(dir).spec; 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) { AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
do_check_eq(list.length, 0); do_check_eq(list.length, 0);

Просмотреть файл

@ -55,7 +55,7 @@ function run_test() {
do_check_neq(a1, null); do_check_neq(a1, null);
do_check_true(a1.hasResource("install.rdf")); 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); do_check_true(uri instanceof AM_Ci.nsIFileURL);
let file = uri.file; let file = uri.file;
do_check_true(file.exists()); do_check_true(file.exists());
@ -64,7 +64,7 @@ function run_test() {
do_check_neq(a2, null); do_check_neq(a2, null);
do_check_true(a2.hasResource("install.rdf")); 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); do_check_true(uri instanceof AM_Ci.nsIFileURL);
file = uri.file; file = uri.file;
do_check_true(file.exists()); do_check_true(file.exists());

Просмотреть файл

@ -51,7 +51,7 @@ function run_test() {
do_check_neq(addon, null); do_check_neq(addon, null);
do_check_true(addon.hasResource("binary")); 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); do_check_true(uri instanceof AM_Ci.nsIFileURL);
let file = uri.file; let file = uri.file;
do_check_true(file.exists()); do_check_true(file.exists());

Просмотреть файл

@ -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();
});
});
});
}

Просмотреть файл

@ -60,7 +60,7 @@ function run_test_1() {
let file = do_get_addon("test_install1"); let file = do_get_addon("test_install1");
let uri = Services.io.newFileURI(file).spec; 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.addon.iconURL, "jar:" + uri + "!/icon.png");
do_check_eq(install.iconURL, null); do_check_eq(install.iconURL, null);
@ -132,7 +132,7 @@ function check_test_1() {
dir.append("addon1@tests.mozilla.org"); dir.append("addon1@tests.mozilla.org");
dir.append("install.rdf"); dir.append("install.rdf");
let uri = Services.io.newFileURI(dir).spec; 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(); a1.uninstall();
restartManager(0); restartManager(0);