Bug 610686: Cached copies of Addon objects for lightweight themes don't have the correct permissions and pendingOperations during the onEnabling event. r=robstrong, a=blocks-betaN

This commit is contained in:
Dave Townsend 2010-11-11 11:49:43 -08:00
parent 76466d3ce2
commit 26e457835a
2 changed files with 59 additions and 4 deletions

View File

@ -87,6 +87,11 @@ __defineSetter__("_maxUsedThemes", function(aVal) {
return this._maxUsedThemes = aVal;
});
// Holds the ID of the theme being enabled while sending out the events so
// cached AddonWrapper instances can return correct values for permissions and
// pendingOperations
var _themeIDBeingEnabled = null;
var LightweightThemeManager = {
get usedThemes () {
try {
@ -339,7 +344,8 @@ var LightweightThemeManager = {
if (id) {
let theme = this.getUsedTheme(id);
let wrapper = new AddonWrapper(theme, true);
_themeIDBeingEnabled = id;
let wrapper = new AddonWrapper(theme);
if (aPendingRestart) {
AddonManagerPrivate.callAddonListeners("onEnabling", wrapper, true);
Services.prefs.setCharPref(PREF_LWTHEME_TO_SELECT, id);
@ -352,6 +358,7 @@ var LightweightThemeManager = {
this.themeChanged(theme);
AddonManagerPrivate.callAddonListeners("onEnabled", wrapper);
}
_themeIDBeingEnabled = null;
}
},
@ -401,7 +408,7 @@ var LightweightThemeManager = {
* The AddonWrapper wraps lightweight theme to provide the data visible to
* consumers of the AddonManager API.
*/
function AddonWrapper(aTheme, aBeingEnabled) {
function AddonWrapper(aTheme) {
this.__defineGetter__("id", function() aTheme.id + ID_SUFFIX);
this.__defineGetter__("type", function() ADDON_TYPE);
this.__defineGetter__("isActive", function() {
@ -474,7 +481,7 @@ function AddonWrapper(aTheme, aBeingEnabled) {
});
this.__defineGetter__("userDisabled", function() {
if (aBeingEnabled)
if (_themeIDBeingEnabled == aTheme.id)
return false;
try {

View File

@ -1034,6 +1034,54 @@ function run_test_20() {
catch (e) {
}
end_test();
run_test_21();
});
}
// Tests that cached copies of a lightweight theme have the right permissions
// and pendingOperations during the onEnabling event
function run_test_21() {
AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
// Switch to a custom theme so we can test pendingOperations properly.
prepare_test({
"theme1@tests.mozilla.org": [
"onEnabling"
],
"default@tests.mozilla.org": [
"onDisabling"
]
});
t1.userDisabled = false;
ensure_test_completed();
restartManager();
AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) {
AddonManager.addAddonListener({
onEnabling: function(aAddon) {
do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
do_check_true(hasFlag(aAddon.pendingOperations, AddonManager.PENDING_ENABLE));
do_check_eq(aAddon.permissions, p1.permissions);
do_check_eq(aAddon.pendingOperations, p1.pendingOperations);
}
});
prepare_test({
"1@personas.mozilla.org": [
"onEnabling"
],
"theme1@tests.mozilla.org": [
"onDisabling"
]
});
p1.userDisabled = false;
ensure_test_completed();
end_test();
});
});
}