Bug 553113: Perform automatic updates for the default lightweight theme. r=robstrong

This commit is contained in:
Dave Townsend 2010-04-28 11:47:22 -07:00
parent 3025ef0ed4
commit dbfe03be1e
4 changed files with 90 additions and 14 deletions

View File

@ -274,6 +274,10 @@ var AddonManagerInternal = {
if (!Services.prefs.getBoolPref(PREF_EM_UPDATE_ENABLED))
return;
let scope = {};
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", scope);
scope.LightweightThemeManager.updateCurrentTheme();
this.getAddonsByTypes(null, function getAddonsCallback(addons) {
addons.forEach(function BUC_forEachCallback(addon) {
if (addon.permissions & AddonManager.PERM_CAN_UPGRADE) {

View File

@ -516,24 +516,24 @@ function _setCurrentTheme(aData, aLocal) {
if (aData) {
let theme = LightweightThemeManager.getUsedTheme(aData.id);
// TODO detect if it is an install and act accordingly
if (!theme) {
let isInstall = !theme || theme.version != aData.version;
if (isInstall) {
var oldWrapper = theme ? new AddonWrapper(theme) : null;
var wrapper = new AddonWrapper(aData);
AddonManagerPrivate.callInstallListeners("onExternalInstall", null,
wrapper, null, false);
wrapper, oldWrapper, false);
AddonManagerPrivate.callAddonListeners("onInstalling", wrapper, false);
}
let current = LightweightThemeManager.currentTheme;
if (!current || current.id != aData.id) {
let usedThemes = _usedThemesExceptId(aData.id);
if (current)
usedThemes.splice(1, 0, aData);
else
usedThemes.unshift(aData);
_updateUsedThemes(usedThemes);
}
if (!theme)
let current = LightweightThemeManager.currentTheme;
let usedThemes = _usedThemesExceptId(aData.id);
if (current && current.id != aData.id)
usedThemes.splice(1, 0, aData);
else
usedThemes.unshift(aData);
_updateUsedThemes(usedThemes);
if (isInstall)
AddonManagerPrivate.callAddonListeners("onInstalled", wrapper);
}

View File

@ -662,7 +662,7 @@ function run_test_13() {
do_check_eq(install.version, "1.0");
do_check_eq(install.name, "Test Theme 1");
do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
prepare_test({
"theme1@tests.mozilla.org": [
"onInstalling",

View File

@ -7,6 +7,8 @@
// The test extension uses an insecure update url.
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
do_load_httpd_js();
var testserver;
var profileDir;
@ -229,6 +231,76 @@ function check_test_4(install) {
a1.uninstall();
restartManager(0);
run_test_5();
});
}
// Test that background update checks work for lightweight themes
function run_test_5() {
LightweightThemeManager.currentTheme = {
id: "1",
version: "1",
name: "Test LW Theme",
description: "A test theme",
author: "Mozilla",
homepageURL: "http://localhost:4444/data/index.html",
headerURL: "http://localhost:4444/data/header.png",
footerURL: "http://localhost:4444/data/footer.png",
previewURL: "http://localhost:4444/data/preview.png",
iconURL: "http://localhost:4444/data/icon.png",
updateURL: "http://localhost:4444/data/lwtheme.js"
};
// XXX The lightweight theme manager strips non-https updateURLs so hack it
// back in.
let themes = JSON.parse(Services.prefs.getCharPref("lightweightThemes.usedThemes"));
do_check_eq(themes.length, 1);
themes[0].updateURL = "http://localhost:4444/data/lwtheme.js";
Services.prefs.setCharPref("lightweightThemes.usedThemes", JSON.stringify(themes));
testserver.registerPathHandler("/data/lwtheme.js", function(request, response) {
response.write(JSON.stringify({
id: "1",
version: "2",
name: "Updated Theme",
description: "A test theme",
author: "Mozilla",
homepageURL: "http://localhost:4444/data/index2.html",
headerURL: "http://localhost:4444/data/header.png",
footerURL: "http://localhost:4444/data/footer.png",
previewURL: "http://localhost:4444/data/preview.png",
iconURL: "http://localhost:4444/data/icon2.png",
updateURL: "http://localhost:4444/data/lwtheme.js"
}));
});
AddonManager.getAddon("1@personas.mozilla.org", function(p1) {
do_check_neq(p1, null);
do_check_eq(p1.version, "1");
do_check_eq(p1.name, "Test LW Theme");
do_check_true(p1.isActive);
prepare_test({
"1@personas.mozilla.org": [
["onInstalling", false],
"onInstalled"
]
}, [
"onExternalInstall"
], check_test_5);
// Fake a timer event to cause a background update and wait for the magic to
// happen
gInternalManager.notify(null);
});
}
function check_test_5() {
AddonManager.getAddon("1@personas.mozilla.org", function(p1) {
do_check_neq(p1, null);
do_check_eq(p1.version, "2");
do_check_eq(p1.name, "Updated Theme");
end_test();
});
}