diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index 79317764992..caf25b0d7fb 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -4029,6 +4029,15 @@ var XPIDatabase = { DB_BOOL_METADATA.forEach(function(aProp) { addon[aProp] = aRow[aProp] != 0; }); + try { + addon._sourceBundle = addon._installLocation.getLocationForID(addon.id); + } + catch (e) { + // An exception will be thrown if the add-on appears in the database but + // not on disk. In general this should only happen during startup as + // this change is being detected. + } + this.addonCache[aRow.internal_id] = Components.utils.getWeakReference(addon); return addon; }, @@ -4210,6 +4219,14 @@ var XPIDatabase = { DB_BOOL_METADATA.forEach(function(aProp) { addon[aProp] = aRow.getResultByName(aProp) != 0; }); + try { + addon._sourceBundle = addon._installLocation.getLocationForID(addon.id); + } + catch (e) { + // An exception will be thrown if the add-on appears in the database but + // not on disk. In general this should only happen during startup as + // this change is being detected. + } this.addonCache[internal_id] = Components.utils.getWeakReference(addon); addon._pendingCallbacks = [aCallback]; @@ -5668,6 +5685,7 @@ AddonInstall.prototype = { cleanStagingDir(stagedAddon.parent, []); // Update the metadata in the database + this.addon._sourceBundle = file; this.addon._installLocation = this.installLocation; this.addon.updateDate = recursiveLastModifiedTime(file); this.addon.visible = true; @@ -6560,14 +6578,7 @@ function AddonWrapper(aAddon) { }; this.hasResource = function(aPath) { - let bundle = null; - if (aAddon instanceof DBAddonInternal) { - bundle = aAddon._sourceBundle = aAddon._installLocation - .getLocationForID(aAddon.id); - } - else { - bundle = aAddon._sourceBundle.clone(); - } + let bundle = aAddon._sourceBundle.clone(); if (bundle.isDirectory()) { if (aPath) { @@ -6587,14 +6598,7 @@ function AddonWrapper(aAddon) { }, this.getResourceURI = function(aPath) { - let bundle = null; - if (aAddon instanceof DBAddonInternal) { - bundle = aAddon._sourceBundle = aAddon._installLocation - .getLocationForID(aAddon.id); - } - else { - bundle = aAddon._sourceBundle.clone(); - } + let bundle = aAddon._sourceBundle.clone(); if (bundle.isDirectory()) { if (aPath) { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js index 2e14590c00c..555f2bd4e84 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js @@ -27,6 +27,9 @@ userExtDir.append("extensions2"); userExtDir.append(gAppInfo.ID); registerDirectory("XREUSysExt", userExtDir.parent); +do_load_httpd_js(); +var testserver; + function resetPrefs() { Services.prefs.setIntPref("bootstraptest.active_version", -1); Services.prefs.setIntPref("bootstraptest.installed_version", -1); @@ -65,6 +68,11 @@ function run_test() { resetPrefs(); + // Create and configure the HTTP server. + testserver = new nsHttpServer(); + testserver.registerDirectory("/addons/", do_get_file("addons")); + testserver.start(4444); + startupManager(); run_test_1(); @@ -91,6 +99,7 @@ function run_test_1() { AddonManager.OP_NEEDS_RESTART_INSTALL, 0); do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); + let addon = install.addon; prepare_test({ "bootstrap1@tests.mozilla.org": [ ["onInstalling", false], @@ -99,7 +108,10 @@ function run_test_1() { }, [ "onInstallStarted", "onInstallEnded", - ], check_test_1); + ], function() { + do_check_true(addon.hasResource("install.rdf")); + check_test_1(); + }); install.install(); }); } @@ -1017,7 +1029,87 @@ function run_test_22() { do_check_eq(getInstallReason(), ADDON_UPGRADE); do_check_eq(getStartupReason(), APP_STARTUP); - do_test_finished(); + b1.uninstall(); + + run_test_23(); + }); + }); +} + + +// Tests that installing from a URL doesn't require a restart +function run_test_23() { + prepare_test({ }, [ + "onNewInstall" + ]); + + let url = "http://localhost:4444/addons/test_bootstrap1_1.xpi"; + AddonManager.getInstallForURL(url, function(install) { + ensure_test_completed(); + + do_check_neq(install, null); + + prepare_test({ }, [ + "onDownloadStarted", + "onDownloadEnded" + ], function() { + do_check_eq(install.type, "extension"); + do_check_eq(install.version, "1.0"); + do_check_eq(install.name, "Test Bootstrap 1"); + do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); + do_check_true(install.addon.hasResource("install.rdf")); + do_check_true(install.addon.hasResource("bootstrap.js")); + do_check_false(install.addon.hasResource("foo.bar")); + do_check_eq(install.addon.operationsRequiringRestart & + AddonManager.OP_NEEDS_RESTART_INSTALL, 0); + do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); + + let addon = install.addon; + prepare_test({ + "bootstrap1@tests.mozilla.org": [ + ["onInstalling", false], + "onInstalled" + ] + }, [ + "onInstallStarted", + "onInstallEnded", + ], function() { + do_check_true(addon.hasResource("install.rdf")); + check_test_23(); + }); + }); + install.install(); + }, "application/x-xpinstall"); +} + +function check_test_23() { + AddonManager.getAllInstalls(function(installs) { + // There should be no active installs now since the install completed and + // doesn't require a restart. + do_check_eq(installs.length, 0); + + AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) { + do_check_neq(b1, null); + do_check_eq(b1.version, "1.0"); + do_check_false(b1.appDisabled); + do_check_false(b1.userDisabled); + do_check_true(b1.isActive); + do_check_eq(getInstalledVersion(), 1); + do_check_eq(getActiveVersion(), 1); + do_check_eq(getStartupReason(), ADDON_INSTALL); + do_check_true(b1.hasResource("install.rdf")); + do_check_true(b1.hasResource("bootstrap.js")); + do_check_false(b1.hasResource("foo.bar")); + do_check_in_crash_annotation("bootstrap1@tests.mozilla.org", "1.0"); + + let dir = do_get_addon_root_uri(profileDir, "bootstrap1@tests.mozilla.org"); + do_check_eq(b1.getResourceURI("bootstrap.js").spec, dir + "bootstrap.js"); + + AddonManager.getAddonsWithOperationsByTypes(null, function(list) { + do_check_eq(list.length, 0); + + testserver.stop(do_test_finished); + }); }); }); }