Bug 635115: Allow opting out of sending add-on information to the discovery pane without disabling automatic add-on updates. r=Unfocused, a=beltzner

This commit is contained in:
Dave Townsend 2011-02-24 10:32:02 -08:00
parent 5a7728f990
commit cc7af37c07
6 changed files with 43 additions and 69 deletions

View File

@ -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);

View File

@ -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();
});
},

View File

@ -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;

View File

@ -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;

View File

@ -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);
});
}

View File

@ -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);