diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 8d279c15d0d1..a8d5c64d9cf8 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -365,6 +365,17 @@ var AddonManagerInternal = { }); }, + /** + * Notifies all providers they need to update the appDisabled property for + * their add-ons in response to an application change such as a blocklist + * update. + */ + updateAddonAppDisabledStates: function AMI_updateAddonAppDisabledStates() { + this.providers.forEach(function(provider) { + callProvider(provider, "updateAddonAppDisabledStates"); + }); + }, + /** * Asynchronously gets an AddonInstall for a URL. * @@ -771,6 +782,10 @@ var AddonManagerPrivate = { AddonManagerInternal.notifyAddonChanged(aId, aType, aPendingRestart); }, + updateAddonAppDisabledStates: function AMP_updateAddonAppDisabledStates() { + AddonManagerInternal.updateAddonAppDisabledStates(); + }, + callInstallListeners: function AMP_callInstallListeners(aMethod) { return AddonManagerInternal.callInstallListeners.apply(AddonManagerInternal, arguments); diff --git a/toolkit/mozapps/extensions/XPIProvider.jsm b/toolkit/mozapps/extensions/XPIProvider.jsm index 01797bd49268..9903dd03d077 100644 --- a/toolkit/mozapps/extensions/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/XPIProvider.jsm @@ -399,7 +399,7 @@ function loadManifestFromRDF(aUri, aStream) { if (addon.type == "theme") addon.userDisabled = addon.internalName != XPIProvider.selectedSkin; else - addon.userDisabled = false; + addon.userDisabled = addon.blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED; addon.appDisabled = !isUsableAddon(addon); addon.applyBackgroundUpdates = true; @@ -1790,6 +1790,16 @@ var XPIProvider = { this.updateAddonDisabledState(previousTheme, true); }, + /** + * Update the appDisabled property for all add-ons. + */ + updateAddonAppDisabledStates: function XPI_updateAddonAppDisabledStates() { + let addons = XPIDatabase.getAddons(); + addons.forEach(function(aAddon) { + this.updateAddonDisabledState(aAddon); + }, this); + }, + /** * When the previously selected theme is removed this method will be called * to enable the default theme. diff --git a/toolkit/mozapps/extensions/nsBlocklistService.js b/toolkit/mozapps/extensions/nsBlocklistService.js index 92cd5ce561e9..35022ba9eb6c 100644 --- a/toolkit/mozapps/extensions/nsBlocklistService.js +++ b/toolkit/mozapps/extensions/nsBlocklistService.js @@ -46,6 +46,7 @@ const Cr = Components.results; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/FileUtils.jsm"); +Components.utils.import("resource://gre/modules/AddonManager.jsm"); const TOOLKIT_ID = "toolkit@mozilla.org" const KEY_PROFILEDIR = "ProfD"; @@ -779,95 +780,114 @@ Blocklist.prototype = { _blocklistUpdated: function(oldAddonEntries, oldPluginEntries) { var addonList = []; - var em = Cc["@mozilla.org/extensions/manager;1"]. - getService(Ci.nsIExtensionManager); - var addons = em.updateAndGetNewBlocklistedItems(); + var self = this; + AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(addons) { - for (let i = 0; i < addons.length; i++) { - let oldState = -1; - if (oldAddonEntries) - oldState = this._getAddonBlocklistState(addons[i].id, addons[i].version, - oldAddonEntries); - let state = this.getAddonBlocklistState(addons[i].id, addons[i].version); - // We don't want to re-warn about items - if (state == oldState) - continue; + for (let i = 0; i < addons.length; i++) { + let oldState = Ci.nsIBlocklistService.STATE_NOTBLOCKED; + if (oldAddonEntries) + oldState = self._getAddonBlocklistState(addons[i].id, addons[i].version, + oldAddonEntries); + let state = self.getAddonBlocklistState(addons[i].id, addons[i].version); - addonList.push({ - name: addons[i].name, - version: addons[i].version, - icon: addons[i].iconURL, - disable: false, - blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED, - item: addons[i] - }); - } + LOG("Blocklist state for " + addons[i].id + " changed from " + oldState + " to " + state); - var phs = Cc["@mozilla.org/plugin/host;1"]. - getService(Ci.nsIPluginHost); - var plugins = phs.getPluginTags(); + // Don't warn about add-ons becoming unblocked. + if (state == 0) + continue; - for (let i = 0; i < plugins.length; i++) { - let oldState = -1; - if (oldPluginEntries) - oldState = this._getPluginBlocklistState(plugins[i], oldPluginEntries); - let state = this.getPluginBlocklistState(plugins[i]); - // We don't want to re-warn about items - if (state == oldState) - continue; + // We don't want to re-warn about add-ons + if (state == oldState) + continue; - if (plugins[i].blocklisted) { - if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED) - plugins[i].disabled = true; - } - else if (!plugins[i].disabled && state != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) { - if (state == Ci.nsIBlocklistService.STATE_OUTDATED) { - gPref.setBoolPref(PREF_PLUGINS_NOTIFYUSER, true); - } - else { - addonList.push({ - name: plugins[i].name, - version: plugins[i].version, - icon: "chrome://mozapps/skin/plugins/pluginGeneric.png", - disable: false, - blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED, - item: plugins[i] - }); + // If an add-on has dropped from hard to soft blocked just mark it as + // user disabled and don't warn about it. + if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED && + oldState == Ci.nsIBlocklistService.STATE_BLOCKED) { + addons[i].userDisabled = true; + continue; } + + // If the add-on is already disabled for some reason then don't warn + // about it + if (!addons[i].isActive) + continue; + + addonList.push({ + name: addons[i].name, + version: addons[i].version, + icon: addons[i].iconURL, + disable: false, + blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED, + item: addons[i] + }); } - plugins[i].blocklisted = state == Ci.nsIBlocklistService.STATE_BLOCKED; - } - if (addonList.length == 0) - return; + AddonManagerPrivate.updateAddonAppDisabledStates(); - var args = { - restart: false, - list: addonList - }; - // This lets the dialog get the raw js object - args.wrappedJSObject = args; + var phs = Cc["@mozilla.org/plugin/host;1"]. + getService(Ci.nsIPluginHost); + var plugins = phs.getPluginTags(); - var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. - getService(Ci.nsIWindowWatcher); - ww.openWindow(null, URI_BLOCKLIST_DIALOG, "", - "chrome,centerscreen,dialog,modal,titlebar", args); + for (let i = 0; i < plugins.length; i++) { + let oldState = -1; + if (oldPluginEntries) + oldState = self._getPluginBlocklistState(plugins[i], oldPluginEntries); + let state = self.getPluginBlocklistState(plugins[i]); + // We don't want to re-warn about items + if (state == oldState) + continue; - for (let i = 0; i < addonList.length; i++) { - if (!addonList[i].disable) - continue; + if (plugins[i].blocklisted) { + if (state == Ci.nsIBlocklistService.STATE_SOFTBLOCKED) + plugins[i].disabled = true; + } + else if (!plugins[i].disabled && state != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) { + if (state == Ci.nsIBlocklistService.STATE_OUTDATED) { + gPref.setBoolPref(PREF_PLUGINS_NOTIFYUSER, true); + } + else { + addonList.push({ + name: plugins[i].name, + version: plugins[i].version, + icon: "chrome://mozapps/skin/plugins/pluginGeneric.png", + disable: false, + blocked: state == Ci.nsIBlocklistService.STATE_BLOCKED, + item: plugins[i] + }); + } + } + plugins[i].blocklisted = state == Ci.nsIBlocklistService.STATE_BLOCKED; + } - if (addonList[i].item instanceof Ci.nsIUpdateItem) - em.disableItem(addonList[i].item.id); - else if (addonList[i].item instanceof Ci.nsIPluginTag) - addonList[i].item.disabled = true; - else - LOG("Blocklist::_blocklistUpdated: Unknown add-on type: " + - addonList[i].item); - } + if (addonList.length == 0) + return; - if (args.restart) - restartApp(); + var args = { + restart: false, + list: addonList + }; + // This lets the dialog get the raw js object + args.wrappedJSObject = args; + + var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. + getService(Ci.nsIWindowWatcher); + ww.openWindow(null, URI_BLOCKLIST_DIALOG, "", + "chrome,centerscreen,dialog,modal,titlebar", args); + + for (let i = 0; i < addonList.length; i++) { + if (!addonList[i].disable) + continue; + + if (addonList[i].item instanceof Ci.nsIPluginTag) + addonList[i].item.disabled = true; + else + addonList[i].item.userDisabled = true; + } + + if (args.restart) + restartApp(); + }); }, classDescription: "Blocklist Service", diff --git a/toolkit/mozapps/extensions/test/unit/data/bug455906_block.xml b/toolkit/mozapps/extensions/test/xpcshell/data/bug455906_block.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/bug455906_block.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/bug455906_block.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/bug455906_empty.xml b/toolkit/mozapps/extensions/test/xpcshell/data/bug455906_empty.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/bug455906_empty.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/bug455906_empty.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/bug455906_start.xml b/toolkit/mozapps/extensions/test/xpcshell/data/bug455906_start.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/bug455906_start.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/bug455906_start.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/bug455906_warn.xml b/toolkit/mozapps/extensions/test/xpcshell/data/bug455906_warn.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/bug455906_warn.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/bug455906_warn.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/test_bug449027_app.xml b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug449027_app.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/test_bug449027_app.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/test_bug449027_app.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/test_bug449027_toolkit.xml b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug449027_toolkit.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/test_bug449027_toolkit.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/test_bug449027_toolkit.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/test_bug514327_3_empty.xml b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug514327_3_empty.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/test_bug514327_3_empty.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/test_bug514327_3_empty.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/test_bug514327_3_outdated_1.xml b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug514327_3_outdated_1.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/test_bug514327_3_outdated_1.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/test_bug514327_3_outdated_1.xml diff --git a/toolkit/mozapps/extensions/test/unit/data/test_bug514327_3_outdated_2.xml b/toolkit/mozapps/extensions/test/xpcshell/data/test_bug514327_3_outdated_2.xml similarity index 100% rename from toolkit/mozapps/extensions/test/unit/data/test_bug514327_3_outdated_2.xml rename to toolkit/mozapps/extensions/test/xpcshell/data/test_bug514327_3_outdated_2.xml diff --git a/toolkit/mozapps/extensions/test/unit/test_bug449027.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js similarity index 88% rename from toolkit/mozapps/extensions/test/unit/test_bug449027.js rename to toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js index c55719bbe719..d2d1b9edb178 100644 --- a/toolkit/mozapps/extensions/test/unit/test_bug449027.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js @@ -499,40 +499,45 @@ function create_addon(addon) { * If a lastTest is provided checks that the notification dialog got passed * the newly blocked items compared to the previous test. */ -function check_state(test, lastTest) { - for (var i = 0; i < ADDONS.length; i++) { - var blocked = getManifestProperty(ADDONS[i].id, "blocklisted") == "true"; - if (blocked != ADDONS[i][test]) - do_throw("Blocklist state did not match expected for extension " + (i + 1) + ", test " + test); - } - for (i = 0; i < PLUGINS.length; i++) { - if (PLUGINS[i].blocklisted != PLUGINS[i][test]) - do_throw("Blocklist state did not match expected for plugin " + (i + 1) + ", test " + test); - } - - if (lastTest) { - var expected = 0; - for (i = 0; i < ADDONS.length; i++) { - if (ADDONS[i][test] && !ADDONS[i][lastTest]) { - if (gNewBlocks.indexOf(ADDONS[i].name + " " + ADDONS[i].version) < 0) - do_throw("Addon " + (i + 1) + " should have been listed in the blocklist notification for test " + test); - expected++; - } +function check_state(test, lastTest, callback) { + AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) { + for (var i = 0; i < ADDONS.length; i++) { + var blocked = addons[i].blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED; + if (blocked != ADDONS[i][test]) + do_throw("Blocklist state did not match expected for extension " + (i + 1) + ", test " + test); } + for (i = 0; i < PLUGINS.length; i++) { - if (PLUGINS[i][test] && !PLUGINS[i][lastTest]) { - if (gNewBlocks.indexOf(PLUGINS[i].name + " " + PLUGINS[i].version) < 0) - do_throw("Plugin " + (i + 1) + " should have been listed in the blocklist notification for test " + test); - expected++; - } + if (PLUGINS[i].blocklisted != PLUGINS[i][test]) + do_throw("Blocklist state did not match expected for plugin " + (i + 1) + ", test " + test); } - do_check_eq(expected, gNewBlocks.length); - } + if (lastTest) { + var expected = 0; + for (i = 0; i < ADDONS.length; i++) { + if (ADDONS[i][test] && !ADDONS[i][lastTest]) { + if (gNewBlocks.indexOf(ADDONS[i].name + " " + ADDONS[i].version) < 0) + do_throw("Addon " + (i + 1) + " should have been listed in the blocklist notification for test " + test); + expected++; + } + } + + for (i = 0; i < PLUGINS.length; i++) { + if (PLUGINS[i][test] && !PLUGINS[i][lastTest]) { + if (gNewBlocks.indexOf(PLUGINS[i].name + " " + PLUGINS[i].version) < 0) + do_throw("Plugin " + (i + 1) + " should have been listed in the blocklist notification for test " + test); + expected++; + } + } + + do_check_eq(expected, gNewBlocks.length); + } + callback(); + }); } function load_blocklist(file) { - gPrefs.setCharPref("extensions.blocklist.url", "http://localhost:4444/data/" + file); + Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:4444/data/" + file); var blocklist = Components.classes["@mozilla.org/extensions/blocklist;1"] .getService(Components.interfaces.nsITimerCallback); blocklist.notify(null); @@ -547,7 +552,7 @@ function run_test() { create_addon(ADDONS[i]); createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8"); - startupEM(); + startupManager(); gTestserver = new nsHttpServer(); gTestserver.registerDirectory("/data/", do_get_file("data")); @@ -562,12 +567,15 @@ function run_test() { */ function check_test_pt1() { dump("Checking pt 1\n"); - for (var i = 0; i < ADDONS.length; i++) { - if (!gEM.getItemForID(ADDONS[i].id)) - do_throw("Addon " + (i + 1) + " did not get installed correctly"); - } - check_state("start", null); - run_test_pt2(); + + AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) { + for (var i = 0; i < ADDONS.length; i++) { + if (!addons[i]) + do_throw("Addon " + (i + 1) + " did not get installed correctly"); + } + + check_state("start", null, run_test_pt2); + }); } /** @@ -581,8 +589,7 @@ function run_test_pt2() { function check_test_pt2() { dump("Checking pt 2\n"); - check_state("toolkitBlocks", "start"); - run_test_pt3(); + check_state("toolkitBlocks", "start", run_test_pt3); } /** @@ -596,6 +603,9 @@ function run_test_pt3() { function check_test_pt3() { dump("Checking pt 3\n"); - check_state("appBlocks", "toolkitBlocks"); + check_state("appBlocks", "toolkitBlocks", end_test); +} + +function end_test() { gTestserver.stop(do_test_finished); } diff --git a/toolkit/mozapps/extensions/test/unit/test_bug455906.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js similarity index 64% rename from toolkit/mozapps/extensions/test/unit/test_bug455906.js rename to toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js index 8ac219d94f7f..bf9cd46a5089 100644 --- a/toolkit/mozapps/extensions/test/unit/test_bug455906.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js @@ -232,22 +232,14 @@ function create_addon(addon) { } function load_blocklist(file) { - gPrefs.setCharPref("extensions.blocklist.url", "http://localhost:4444/data/" + file); + Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:4444/data/" + file); var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. getService(Ci.nsITimerCallback); blocklist.notify(null); } -function isUserDisabled(id) { - return getManifestProperty(id, "userDisabled") == "true"; -} - -function isAppDisabled(id) { - return getManifestProperty(id, "appDisabled") == "true"; -} - -function check_addon_state(id) { - return isUserDisabled(id) + "," + isAppDisabled(id); +function check_addon_state(addon) { + return addon.userDisabled + "," + addon.appDisabled; } function check_plugin_state(plugin) { @@ -269,7 +261,7 @@ function run_test() { blocklist.copyTo(gProfD, "blocklist.xml"); createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8"); - startupEM(); + startupManager(); gTestserver = new nsHttpServer(); gTestserver.registerDirectory("/data/", do_get_file("data")); @@ -280,55 +272,63 @@ function run_test() { } // Before every main test this is the state the add-ons are meant to be in -function check_initial_state() { - do_check_eq(check_addon_state(ADDONS[0].id), "true,false"); - do_check_eq(check_addon_state(ADDONS[1].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[2].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[3].id), "true,false"); - do_check_eq(check_addon_state(ADDONS[4].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[5].id), "false,true"); - do_check_eq(check_addon_state(ADDONS[6].id), "false,true"); +function check_initial_state(callback) { + AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) { + do_check_eq(check_addon_state(addons[0]), "true,false"); + do_check_eq(check_addon_state(addons[1]), "false,false"); + do_check_eq(check_addon_state(addons[2]), "false,false"); + do_check_eq(check_addon_state(addons[3]), "true,false"); + do_check_eq(check_addon_state(addons[4]), "false,false"); + do_check_eq(check_addon_state(addons[5]), "false,true"); + do_check_eq(check_addon_state(addons[6]), "false,true"); + + do_check_eq(check_plugin_state(PLUGINS[0]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[1]), "false,false"); + do_check_eq(check_plugin_state(PLUGINS[2]), "false,false"); + do_check_eq(check_plugin_state(PLUGINS[3]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[4]), "false,false"); + do_check_eq(check_plugin_state(PLUGINS[5]), "false,true"); - do_check_eq(check_plugin_state(PLUGINS[0]), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[1]), "false,false"); - do_check_eq(check_plugin_state(PLUGINS[2]), "false,false"); - do_check_eq(check_plugin_state(PLUGINS[3]), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[4]), "false,false"); - do_check_eq(check_plugin_state(PLUGINS[5]), "false,true"); + callback(); + }); } // Tests the add-ons were installed and the initial blocklist applied as expected function check_test_pt1() { dump("Checking pt 1\n"); - for (var i = 0; i < ADDONS.length; i++) { - if (!gEM.getItemForID(ADDONS[i].id)) - do_throw("Addon " + (i + 1) + " did not get installed correctly"); - } - do_check_eq(check_addon_state(ADDONS[0].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[1].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[2].id), "false,false"); + AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) { + for (var i = 0; i < ADDONS.length; i++) { + if (!addons[i]) + do_throw("Addon " + (i + 1) + " did not get installed correctly"); + } + + do_check_eq(check_addon_state(addons[0]), "false,false"); + do_check_eq(check_addon_state(addons[1]), "false,false"); + do_check_eq(check_addon_state(addons[2]), "false,false"); + + // Warn add-ons should be user disabled automatically + do_check_eq(check_addon_state(addons[3]), "true,false"); + do_check_eq(check_addon_state(addons[4]), "true,false"); + + // Blocked and incompatible should be app disabled only + do_check_eq(check_addon_state(addons[5]), "false,true"); + do_check_eq(check_addon_state(addons[6]), "false,true"); + + // We've overridden the plugin host so we cannot tell what that would have + // initialised the plugins as + + // Put the add-ons into the base state + addons[0].userDisabled = true; + addons[4].userDisabled = false; - // Warn add-ons should be user disabled automatically - do_check_eq(check_addon_state(ADDONS[3].id), "true,false"); - do_check_eq(check_addon_state(ADDONS[4].id), "true,false"); - - // Blocked and incompatible should be app disabled only - do_check_eq(check_addon_state(ADDONS[5].id), "false,true"); - do_check_eq(check_addon_state(ADDONS[6].id), "false,true"); - - // We've overridden the plugin host so we cannot tell what that would have - // initialised the plugins as - - // Put the add-ons into the base state - gEM.disableItem(ADDONS[0].id); - gEM.enableItem(ADDONS[4].id); - restartEM(); - check_initial_state(); - - gNotificationCheck = check_notification_pt2; - gTestCheck = check_test_pt2; - load_blocklist("bug455906_warn.xml"); + restartManager(); + check_initial_state(function() { + gNotificationCheck = check_notification_pt2; + gTestCheck = check_test_pt2; + load_blocklist("bug455906_warn.xml"); + }); + }); } function check_notification_pt2(args) { @@ -337,20 +337,7 @@ function check_notification_pt2(args) { for (let i = 0; i < args.list.length; i++) { let addon = args.list[i]; - if (addon.item instanceof Ci.nsIUpdateItem) { - switch (addon.item.id) { - case "test_bug455906_2@tests.mozilla.org": - do_check_false(addon.blocked); - break; - case "test_bug455906_3@tests.mozilla.org": - do_check_false(addon.blocked); - addon.disable = true; - break; - default: - do_throw("Unknown addon: " + addon.item.id); - } - } - else if (addon.item instanceof Ci.nsIPluginTag) { + if (addon.item instanceof Ci.nsIPluginTag) { switch (addon.item.name) { case "test_bug455906_2": do_check_false(addon.blocked); @@ -364,52 +351,64 @@ function check_notification_pt2(args) { } } else { - do_throw("Unknown add-on type " + addon.item); + switch (addon.item.id) { + case "test_bug455906_2@tests.mozilla.org": + do_check_false(addon.blocked); + break; + case "test_bug455906_3@tests.mozilla.org": + do_check_false(addon.blocked); + addon.disable = true; + break; + default: + do_throw("Unknown addon: " + addon.item.id); + } } } } function check_test_pt2() { - restartEM(); + restartManager(); dump("Checking results pt 2\n"); - // Should have disabled this add-on as requested - do_check_eq(check_addon_state(ADDONS[2].id), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[2]), "true,false"); + AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) { + // Should have disabled this add-on as requested + do_check_eq(check_addon_state(addons[2]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[2]), "true,false"); - // The blocked add-on should have changed to user disabled - do_check_eq(check_addon_state(ADDONS[5].id), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[5]), "true,false"); + // The blocked add-on should have changed to user disabled + do_check_eq(check_addon_state(addons[5]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[5]), "true,false"); - // These should have been unchanged - do_check_eq(check_addon_state(ADDONS[0].id), "true,false"); - do_check_eq(check_addon_state(ADDONS[1].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[3].id), "true,false"); - do_check_eq(check_addon_state(ADDONS[4].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[6].id), "false,true"); - do_check_eq(check_plugin_state(PLUGINS[0]), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[1]), "false,false"); - do_check_eq(check_plugin_state(PLUGINS[3]), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[4]), "false,false"); + // These should have been unchanged + do_check_eq(check_addon_state(addons[0]), "true,false"); + do_check_eq(check_addon_state(addons[1]), "false,false"); + do_check_eq(check_addon_state(addons[3]), "true,false"); + do_check_eq(check_addon_state(addons[4]), "false,false"); + do_check_eq(check_addon_state(addons[6]), "false,true"); + do_check_eq(check_plugin_state(PLUGINS[0]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[1]), "false,false"); + do_check_eq(check_plugin_state(PLUGINS[3]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[4]), "false,false"); - // Back to starting state - gEM.enableItem(ADDONS[2].id); - gEM.enableItem(ADDONS[5].id); - PLUGINS[2].disabled = false; - PLUGINS[5].disabled = false; - restartEM(); - gNotificationCheck = null; - gTestCheck = run_test_pt3; - load_blocklist("bug455906_start.xml"); + // Back to starting state + addons[2].userDisabled = false; + addons[5].userDisabled = false; + PLUGINS[2].disabled = false; + PLUGINS[5].disabled = false; + restartManager(); + gNotificationCheck = null; + gTestCheck = run_test_pt3; + load_blocklist("bug455906_start.xml"); + }); } function run_test_pt3() { - restartEM(); - check_initial_state(); - - gNotificationCheck = check_notification_pt3; - gTestCheck = check_test_pt3; - load_blocklist("bug455906_block.xml"); + restartManager(); + check_initial_state(function() { + gNotificationCheck = check_notification_pt3; + gTestCheck = check_test_pt3; + load_blocklist("bug455906_block.xml"); + }); } function check_notification_pt3(args) { @@ -418,22 +417,7 @@ function check_notification_pt3(args) { for (let i = 0; i < args.list.length; i++) { let addon = args.list[i]; - if (addon.item instanceof Ci.nsIUpdateItem) { - switch (addon.item.id) { - case "test_bug455906_2@tests.mozilla.org": - do_check_true(addon.blocked); - break; - case "test_bug455906_3@tests.mozilla.org": - do_check_true(addon.blocked); - break; - case "test_bug455906_5@tests.mozilla.org": - do_check_true(addon.blocked); - break; - default: - do_throw("Unknown addon: " + addon.item.id); - } - } - else if (addon.item instanceof Ci.nsIPluginTag) { + if (addon.item instanceof Ci.nsIPluginTag) { switch (addon.item.name) { case "test_bug455906_2": do_check_true(addon.blocked); @@ -449,47 +433,63 @@ function check_notification_pt3(args) { } } else { - do_throw("Unknown add-on type " + addon.item); + switch (addon.item.id) { + case "test_bug455906_2@tests.mozilla.org": + do_check_true(addon.blocked); + break; + case "test_bug455906_3@tests.mozilla.org": + do_check_true(addon.blocked); + break; + case "test_bug455906_5@tests.mozilla.org": + do_check_true(addon.blocked); + break; + default: + do_throw("Unknown addon: " + addon.item.id); + } } } } function check_test_pt3() { - restartEM(); + restartManager(); dump("Checking results pt 3\n"); - // All should have gained the blocklist state, user disabled as previously - do_check_eq(check_addon_state(ADDONS[0].id), "true,true"); - do_check_eq(check_addon_state(ADDONS[1].id), "false,true"); - do_check_eq(check_addon_state(ADDONS[2].id), "false,true"); - do_check_eq(check_addon_state(ADDONS[3].id), "true,true"); - do_check_eq(check_addon_state(ADDONS[4].id), "false,true"); - do_check_eq(check_plugin_state(PLUGINS[0]), "true,true"); - do_check_eq(check_plugin_state(PLUGINS[1]), "false,true"); - do_check_eq(check_plugin_state(PLUGINS[2]), "false,true"); - do_check_eq(check_plugin_state(PLUGINS[3]), "true,true"); - do_check_eq(check_plugin_state(PLUGINS[4]), "false,true"); + AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) { + // All should have gained the blocklist state, user disabled as previously + do_check_eq(check_addon_state(addons[0]), "true,true"); + do_check_eq(check_addon_state(addons[1]), "false,true"); + do_check_eq(check_addon_state(addons[2]), "false,true"); + do_check_eq(check_addon_state(addons[3]), "true,true"); + do_check_eq(check_addon_state(addons[4]), "false,true"); + do_check_eq(check_plugin_state(PLUGINS[0]), "true,true"); + do_check_eq(check_plugin_state(PLUGINS[1]), "false,true"); + do_check_eq(check_plugin_state(PLUGINS[2]), "false,true"); + do_check_eq(check_plugin_state(PLUGINS[3]), "true,true"); + do_check_eq(check_plugin_state(PLUGINS[4]), "false,true"); - // Shouldn't be changed - do_check_eq(check_addon_state(ADDONS[5].id), "false,true"); - do_check_eq(check_addon_state(ADDONS[6].id), "false,true"); - do_check_eq(check_plugin_state(PLUGINS[5]), "false,true"); + // Shouldn't be changed + do_check_eq(check_addon_state(addons[5]), "false,true"); + do_check_eq(check_addon_state(addons[6]), "false,true"); + do_check_eq(check_plugin_state(PLUGINS[5]), "false,true"); - // Back to starting state - gNotificationCheck = null; - gTestCheck = run_test_pt4; - load_blocklist("bug455906_start.xml"); + // Back to starting state + gNotificationCheck = null; + gTestCheck = run_test_pt4; + load_blocklist("bug455906_start.xml"); + }); } function run_test_pt4() { - gEM.enableItem(ADDONS[4].id); - PLUGINS[4].disabled = false; - restartEM(); - check_initial_state(); - - gNotificationCheck = check_notification_pt4; - gTestCheck = check_test_pt4; - load_blocklist("bug455906_empty.xml"); + AddonManager.getAddonByID(ADDONS[4].id, function(addon) { + addon.userDisabled = false; + PLUGINS[4].disabled = false; + restartManager(); + check_initial_state(function() { + gNotificationCheck = check_notification_pt4; + gTestCheck = check_test_pt4; + load_blocklist("bug455906_empty.xml"); + }); + }); } function check_notification_pt4(args) { @@ -497,32 +497,34 @@ function check_notification_pt4(args) { // Should be just the dummy add-on to force this notification do_check_eq(args.list.length, 1); - do_check_true(args.list[0].item instanceof Ci.nsIUpdateItem); + do_check_false(args.list[0].item instanceof Ci.nsIPluginTag); do_check_eq(args.list[0].item.id, "dummy_bug455906_2@tests.mozilla.org"); } function check_test_pt4() { - restartEM(); + restartManager(); dump("Checking results pt 4\n"); - // This should have become unblocked - do_check_eq(check_addon_state(ADDONS[5].id), "false,false"); - do_check_eq(check_plugin_state(PLUGINS[5]), "false,false"); + AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) { + // This should have become unblocked + do_check_eq(check_addon_state(addons[5]), "false,false"); + do_check_eq(check_plugin_state(PLUGINS[5]), "false,false"); - // No change for anything else - do_check_eq(check_addon_state(ADDONS[0].id), "true,false"); - do_check_eq(check_addon_state(ADDONS[1].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[2].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[3].id), "true,false"); - do_check_eq(check_addon_state(ADDONS[4].id), "false,false"); - do_check_eq(check_addon_state(ADDONS[6].id), "false,true"); - do_check_eq(check_plugin_state(PLUGINS[0]), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[1]), "false,false"); - do_check_eq(check_plugin_state(PLUGINS[2]), "false,false"); - do_check_eq(check_plugin_state(PLUGINS[3]), "true,false"); - do_check_eq(check_plugin_state(PLUGINS[4]), "false,false"); + // No change for anything else + do_check_eq(check_addon_state(addons[0]), "true,false"); + do_check_eq(check_addon_state(addons[1]), "false,false"); + do_check_eq(check_addon_state(addons[2]), "false,false"); + do_check_eq(check_addon_state(addons[3]), "true,false"); + do_check_eq(check_addon_state(addons[4]), "false,false"); + do_check_eq(check_addon_state(addons[6]), "false,true"); + do_check_eq(check_plugin_state(PLUGINS[0]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[1]), "false,false"); + do_check_eq(check_plugin_state(PLUGINS[2]), "false,false"); + do_check_eq(check_plugin_state(PLUGINS[3]), "true,false"); + do_check_eq(check_plugin_state(PLUGINS[4]), "false,false"); - finish(); + finish(); + }); } function finish() { diff --git a/toolkit/mozapps/extensions/test/unit/test_bug514327_3.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js similarity index 100% rename from toolkit/mozapps/extensions/test/unit/test_bug514327_3.js rename to toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js