From 98b2209e91ac5a8afdc2f4516a3b9e6430276da2 Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Mon, 8 Jun 2020 15:45:23 +0000 Subject: [PATCH] Bug 1637680 - Make softDisable setter async. r=mixedpuppy Some tests rely on the order of execution of the blocklist code which cannot be guaranteed if we don't wait for the enabled state to settle. In particular, when calling `_onUpdate` in `AddonTestUtils.loadBlocklistRawData` in [0] we implicitely assume that all the actions deriving from updating the blocklist settle before the promise is completed, this is not true for the enabled state. Currently the test succedes because `ExtensionPermissions.get` is not actually async in most cases, this is about to change in the next patch. [0]: https://searchfox.org/mozilla-central/rev/559b25eb41c1cbffcb90a34e008b8288312fcd25/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm#925 Differential Revision: https://phabricator.services.mozilla.com/D77937 --- toolkit/mozapps/extensions/Blocklist.jsm | 8 ++++---- toolkit/mozapps/extensions/internal/XPIDatabase.jsm | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/toolkit/mozapps/extensions/Blocklist.jsm b/toolkit/mozapps/extensions/Blocklist.jsm index a523eb724849..5f32ca15296f 100644 --- a/toolkit/mozapps/extensions/Blocklist.jsm +++ b/toolkit/mozapps/extensions/Blocklist.jsm @@ -1219,7 +1219,7 @@ this.ExtensionBlocklistRS = { // Ensure that softDisabled is false if the add-on is not soft blocked if (state != Ci.nsIBlocklistService.STATE_SOFTBLOCKED) { - addon.softDisabled = false; + await addon.setSoftDisabled(false); } // If an add-on has dropped from hard to soft blocked just mark it as @@ -1228,7 +1228,7 @@ this.ExtensionBlocklistRS = { state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED && oldState == Ci.nsIBlocklistService.STATE_BLOCKED ) { - addon.softDisabled = true; + await addon.setSoftDisabled(true); } if ( @@ -1243,7 +1243,7 @@ this.ExtensionBlocklistRS = { state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED && !addon.userDisabled ) { - addon.softDisabled = true; + await addon.setSoftDisabled(true); } // It's a block. We must reset certain preferences. let entry = this._getEntry(addon, this._entries); @@ -1579,7 +1579,7 @@ this.ExtensionBlocklistMLBF = { // Ensure that softDisabled is false if the add-on is not soft blocked // (by a previous implementation of the blocklist). if (state != Ci.nsIBlocklistService.STATE_SOFTBLOCKED) { - addon.softDisabled = false; + await addon.setSoftDisabled(false); } } diff --git a/toolkit/mozapps/extensions/internal/XPIDatabase.jsm b/toolkit/mozapps/extensions/internal/XPIDatabase.jsm index 4d1c469418c5..867c661c214c 100644 --- a/toolkit/mozapps/extensions/internal/XPIDatabase.jsm +++ b/toolkit/mozapps/extensions/internal/XPIDatabase.jsm @@ -607,7 +607,7 @@ class AddonInternal { } if (this.inDatabase && updateDatabase) { - XPIDatabase.updateAddonDisabledState(this, { + await XPIDatabase.updateAddonDisabledState(this, { userDisabled, softDisabled, }); @@ -1163,7 +1163,7 @@ AddonWrapper = class { return addonFor(this).setUserDisabled(true, allowSystemAddons); } - set softDisabled(val) { + async setSoftDisabled(val) { let addon = addonFor(this); if (val == addon.softDisabled) { return val; @@ -1173,10 +1173,14 @@ AddonWrapper = class { // When softDisabling a theme just enable the active theme if (addon.type === "theme" && val && !addon.userDisabled) { if (addon.isWebExtension) { - XPIDatabase.updateAddonDisabledState(addon, { softDisabled: val }); + await XPIDatabase.updateAddonDisabledState(addon, { + softDisabled: val, + }); } } else { - XPIDatabase.updateAddonDisabledState(addon, { softDisabled: val }); + await XPIDatabase.updateAddonDisabledState(addon, { + softDisabled: val, + }); } } else if (!addon.userDisabled) { // Only set softDisabled if not already disabled