From cc7af37c07ef06113633a5f995c848e1b0891f44 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Thu, 24 Feb 2011 10:32:02 -0800 Subject: [PATCH] Bug 635115: Allow opting out of sending add-on information to the discovery pane without disabling automatic add-on updates. r=Unfocused, a=beltzner --- .../content/test/browser_disablechrome.js | 17 +++++-- toolkit/mozapps/extensions/AddonManager.jsm | 14 ++---- .../mozapps/extensions/content/extensions.js | 9 ++-- .../test/browser/browser_discovery.js | 17 ++++--- .../mozapps/extensions/test/browser/head.js | 8 +++- .../xpcshell/test_AddonRepository_cache.js | 47 ++----------------- 6 files changed, 43 insertions(+), 69 deletions(-) diff --git a/browser/base/content/test/browser_disablechrome.js b/browser/base/content/test/browser_disablechrome.js index 4e6227bd960..f2979358258 100644 --- a/browser/base/content/test/browser_disablechrome.js +++ b/browser/base/content/test/browser_disablechrome.js @@ -44,16 +44,25 @@ function load_page(aURL, aCanHide, aCallback) { is_chrome_visible(); if (aURL == "about:addons") { - gNewBrowser.contentDocument.addEventListener("Initialized", function() { - gNewBrowser.contentDocument.removeEventListener("Initialized", arguments.callee, false); - + function check_after_init() { if (aCanHide) is_chrome_hidden(); else is_chrome_visible(); aCallback(); - }, false); + } + + if (gNewBrowser.contentWindow.gIsInitializing) { + gNewBrowser.contentDocument.addEventListener("Initialized", function() { + gNewBrowser.contentDocument.removeEventListener("Initialized", arguments.callee, false); + + check_after_init(); + }, false); + } + else { + check_after_init(); + } } else { executeSoon(aCallback); diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 84c90eb32bf..eb63fde7b48 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -348,6 +348,10 @@ var AddonManagerInternal = { scope.LightweightThemeManager.updateCurrentTheme(); this.getAllAddons(function getAddonsCallback(aAddons) { + pendingUpdates++; + var ids = [a.id for each (a in aAddons)]; + scope.AddonRepository.repopulateCache(ids, notifyComplete); + pendingUpdates += aAddons.length; var autoUpdateDefault = AddonManager.autoUpdateDefault; @@ -361,12 +365,7 @@ var AddonManagerInternal = { return autoUpdateDefault; } - var ids = []; - aAddons.forEach(function BUC_forEachCallback(aAddon) { - if (shouldAutoUpdate(aAddon)) - ids.push(aAddon.id); - // Check all add-ons for updates so that any compatibility updates will // be applied aAddon.findUpdates({ @@ -383,11 +382,6 @@ var AddonManagerInternal = { }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE); }); - if (ids.length > 0) { - pendingUpdates++; - scope.AddonRepository.repopulateCache(ids, notifyComplete); - } - notifyComplete(); }); }, diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 5ad805c0af6..c843aa4f643 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -50,11 +50,11 @@ Cu.import("resource://gre/modules/AddonRepository.jsm"); const PREF_DISCOVERURL = "extensions.webservice.discoverURL"; const PREF_MAXRESULTS = "extensions.getAddons.maxResults"; -const PREF_BACKGROUND_UPDATE = "extensions.update.enabled"; const PREF_CHECK_COMPATIBILITY = "extensions.checkCompatibility"; const PREF_CHECK_UPDATE_SECURITY = "extensions.checkUpdateSecurity"; const PREF_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault"; -const PREF_GETADDONS_CACHE_ENABLED = "extensions.%ID%.getAddons.cache.enabled"; +const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; +const PREF_GETADDONS_CACHE_ID_ENABLED = "extensions.%ID%.getAddons.cache.enabled"; const BRANCH_REGEXP = /^([^\.]+\.[0-9]+[a-z]*).*/gi; @@ -1655,7 +1655,7 @@ var gDiscoverView = { notifyInitialized(); } - if (Services.prefs.getBoolPref(PREF_BACKGROUND_UPDATE) == false) { + if (Services.prefs.getBoolPref(PREF_GETADDONS_CACHE_ENABLED) == false) { setURL(url); return; } @@ -1664,7 +1664,8 @@ var gDiscoverView = { AddonManager.getAllAddons(function(aAddons) { var list = {}; aAddons.forEach(function(aAddon) { - var prefName = PREF_GETADDONS_CACHE_ENABLED.replace("%ID%", aAddon.id); + var prefName = PREF_GETADDONS_CACHE_ID_ENABLED.replace("%ID%", + aAddon.id); try { if (!Services.prefs.getBoolPref(prefName)) return; diff --git a/toolkit/mozapps/extensions/test/browser/browser_discovery.js b/toolkit/mozapps/extensions/test/browser/browser_discovery.js index e2c5a6fb790..ef3652572c5 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_discovery.js +++ b/toolkit/mozapps/extensions/test/browser/browser_discovery.js @@ -4,7 +4,7 @@ // Tests that the discovery view loads properly -const PREF_BACKGROUND_UPDATE = "extensions.update.enabled"; +const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; const PREF_DISCOVERURL = "extensions.webservice.discoverURL"; const MAIN_URL = "https://example.com/" + RELATIVE_DIR + "discovery.html"; @@ -36,8 +36,17 @@ var gProgressListener = { }; function test() { + var currentURL = Services.prefs.getCharPref(PREF_DISCOVERURL); + // Switch to a known url Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL); + // Temporarily enable caching + Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); + + registerCleanupFunction(function() { + Services.prefs.setCharPref(PREF_DISCOVERURL, currentURL); + Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false); + }); waitForExplicitFinish(); @@ -259,11 +268,7 @@ add_test(function() { // Tests that switching to the discovery view displays the right url add_test(function() { - Services.prefs.setBoolPref(PREF_BACKGROUND_UPDATE, false); - - registerCleanupFunction(function() { - Services.prefs.clearUserPref(PREF_BACKGROUND_UPDATE); - }); + Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false); open_manager("addons://list/extension", function(aWindow) { gManagerWindow = aWindow; diff --git a/toolkit/mozapps/extensions/test/browser/head.js b/toolkit/mozapps/extensions/test/browser/head.js index c3d84e1c80d..7d22ba026e8 100644 --- a/toolkit/mozapps/extensions/test/browser/head.js +++ b/toolkit/mozapps/extensions/test/browser/head.js @@ -236,7 +236,13 @@ function open_manager(aView, aCallback, aLoadCallback, aLongerTimeout) { is(aManagerWindow.location, MANAGER_URI, "Should be displaying the correct UI"); wait_for_manager_load(aManagerWindow, function() { - wait_for_view_load(aManagerWindow, aCallback, null, aLongerTimeout); + wait_for_view_load(aManagerWindow, function() { + // Some functions like synthesizeMouse don't like to be called during + // the load event so ensure that has completed + executeSoon(function() { + log_exceptions(aCallback, aManagerWindow); + }); + }, null, aLongerTimeout); }); } diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js index 424fde652da..159f6509a5c 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js @@ -15,7 +15,6 @@ const BASE_URL = "http://localhost:" + PORT; const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; const PREF_GETADDONS_CACHE_TYPES = "extensions.getAddons.cache.types"; const PREF_GETADDONS_BYIDS = "extensions.getAddons.get.url"; -const PREF_EM_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault"; const GETADDONS_RESULTS = BASE_URL + "/data/test_AddonRepository_cache.xml"; const GETADDONS_EMPTY = BASE_URL + "/data/test_AddonRepository_empty.xml"; const GETADDONS_FAILED = BASE_URL + "/data/test_AddonRepository_failed.xml"; @@ -651,49 +650,7 @@ function run_test_14() { AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) { check_results(aAddons, WITHOUT_CACHE); - run_test_14_1(); - }); - }); -} - -// Tests that the XPI add-ons have the correct properties if caching is -// enabled but updates are disabled by default -function run_test_14_1() { - Services.prefs.setBoolPref(PREF_EM_AUTOUPDATE_DEFAULT, false); - Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, GETADDONS_RESULTS); - - trigger_background_update(function() { - check_database_exists(true); - - AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) { - check_results(aAddons, WITHOUT_CACHE); - run_test_14_2(); - }); - }); -} - -// Tests that the XPI add-ons have the correct properties if caching is -// enabled but updates are disabled by individually -function run_test_14_2() { - Services.prefs.setBoolPref(PREF_EM_AUTOUPDATE_DEFAULT, true); - - AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) { - aAddons.forEach(function(aAddon) { - aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE; - }); - - trigger_background_update(function() { - check_database_exists(true); - - AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) { - check_results(aAddons, WITHOUT_CACHE); - - aAddons.forEach(function(aAddon) { - aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT; - }); - - run_test_15(); - }); + run_test_15(); }); }); } @@ -701,6 +658,8 @@ function run_test_14_2() { // Tests that the XPI add-ons correctly use the repository properties when // caching is enabled and the repository information is available function run_test_15() { + Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, GETADDONS_RESULTS); + trigger_background_update(function() { AddonManager.getAddonsByIDs(ADDON_IDS, function(aAddons) { check_results(aAddons, WITH_CACHE);