зеркало из https://github.com/mozilla/gecko-dev.git
Bug 985084 - Part 2: Properly report userDisabled in the API; r=Unfocused
The change in 0633949f1000 was buggy. If a new Addon instance were created, it would always return the value stored in the database. This meant that if you set userDisabled = false and called getAddonByID(), userDisabled would likely be reported as true. --HG-- extra : rebase_source : 02be7302b6e168b5d56cbf02de0cca4810ccd700 extra : amend_source : 4cdc73bfbc826abd594d6f8a2374672be834dba8
This commit is contained in:
Родитель
45c6a5178f
Коммит
a091d5118f
|
@ -1586,6 +1586,8 @@ var XPIProvider = {
|
|||
_mostRecentlyModifiedFile: {},
|
||||
// Per-addon telemetry information
|
||||
_telemetryDetails: {},
|
||||
// Experiments are disabled by default. Track ones that are locally enabled.
|
||||
_enabledExperiments: null,
|
||||
|
||||
/*
|
||||
* Set a value in the telemetry hash for a given ID
|
||||
|
@ -1765,6 +1767,8 @@ var XPIProvider = {
|
|||
this._shutdownError = null;
|
||||
// Clear this at startup for xpcshell test restarts
|
||||
this._telemetryDetails = {};
|
||||
// Clear the set of enabled experiments (experiments disabled by default).
|
||||
this._enabledExperiments = new Set();
|
||||
// Register our details structure with AddonManager
|
||||
AddonManagerPrivate.setTelemetryDetails("XPI", this._telemetryDetails);
|
||||
|
||||
|
@ -6582,11 +6586,24 @@ function AddonWrapper(aAddon) {
|
|||
});
|
||||
|
||||
this.__defineGetter__("userDisabled", function AddonWrapper_userDisabledGetter() {
|
||||
if (XPIProvider._enabledExperiments.has(aAddon.id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return aAddon.softDisabled || aAddon.userDisabled;
|
||||
});
|
||||
this.__defineSetter__("userDisabled", function AddonWrapper_userDisabledSetter(val) {
|
||||
if (val == this.userDisabled)
|
||||
if (val == this.userDisabled) {
|
||||
return val;
|
||||
}
|
||||
|
||||
if (aAddon.type == "experiment") {
|
||||
if (val) {
|
||||
XPIProvider._enabledExperiments.delete(aAddon.id);
|
||||
} else {
|
||||
XPIProvider._enabledExperiments.add(aAddon.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (aAddon.inDatabase) {
|
||||
if (aAddon.type == "theme" && val) {
|
||||
|
|
|
@ -54,20 +54,26 @@ add_test(function test_experiment() {
|
|||
// Changes to userDisabled should not be persisted to the database.
|
||||
add_test(function test_userDisabledNotPersisted() {
|
||||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
||||
Assert.ok(addon, "Addon is found.");
|
||||
Assert.ok(addon, "Add-on is found.");
|
||||
Assert.ok(addon.userDisabled, "Add-on is user disabled.");
|
||||
|
||||
let listener = {
|
||||
onEnabled: (addon2) => {
|
||||
AddonManager.removeAddonListener(listener);
|
||||
|
||||
Assert.equal(addon2.id, addon.id, "Changed add-on matches expected.");
|
||||
Assert.ok(addon2.isActive, "Add-on is no longer disabled.");
|
||||
Assert.equal(addon2.userDisabled, false, "Add-on is no longer user disabled.");
|
||||
Assert.ok(addon2.isActive, "Add-on is active.");
|
||||
|
||||
Assert.ok("experiment1@tests.mozilla.org" in XPIProvider.bootstrappedAddons,
|
||||
"Experiment add-on listed in XPIProvider bootstrapped list.");
|
||||
|
||||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
||||
Assert.ok(addon, "Add-on retrieved.");
|
||||
Assert.ok(addon.userDisabled, "Add-on is disabled according to database.");
|
||||
Assert.equal(addon.userDisabled, false, "Add-on is still enabled after API retrieve.");
|
||||
Assert.ok(addon.isActive, "Add-on is still active.");
|
||||
|
||||
// Now when we restart the manager the add-on should revert state.
|
||||
restartManager();
|
||||
let persisted = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
|
||||
Assert.ok(!("experiment1@tests.mozilla.org" in persisted),
|
||||
|
@ -76,6 +82,7 @@ add_test(function test_userDisabledNotPersisted() {
|
|||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
||||
Assert.ok(addon, "Add-on retrieved.");
|
||||
Assert.ok(addon.userDisabled, "Add-on is disabled after restart.");
|
||||
Assert.equal(addon.isActive, false, "Add-on is not active after restart.");
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче