зеркало из https://github.com/mozilla/gecko-dev.git
Bug 553113: Perform automatic updates for the default lightweight theme. r=robstrong
This commit is contained in:
Родитель
55120fdd2f
Коммит
34243a67ea
|
@ -274,6 +274,10 @@ var AddonManagerInternal = {
|
||||||
if (!Services.prefs.getBoolPref(PREF_EM_UPDATE_ENABLED))
|
if (!Services.prefs.getBoolPref(PREF_EM_UPDATE_ENABLED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
let scope = {};
|
||||||
|
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", scope);
|
||||||
|
scope.LightweightThemeManager.updateCurrentTheme();
|
||||||
|
|
||||||
this.getAddonsByTypes(null, function getAddonsCallback(addons) {
|
this.getAddonsByTypes(null, function getAddonsCallback(addons) {
|
||||||
addons.forEach(function BUC_forEachCallback(addon) {
|
addons.forEach(function BUC_forEachCallback(addon) {
|
||||||
if (addon.permissions & AddonManager.PERM_CAN_UPGRADE) {
|
if (addon.permissions & AddonManager.PERM_CAN_UPGRADE) {
|
||||||
|
|
|
@ -516,24 +516,24 @@ function _setCurrentTheme(aData, aLocal) {
|
||||||
|
|
||||||
if (aData) {
|
if (aData) {
|
||||||
let theme = LightweightThemeManager.getUsedTheme(aData.id);
|
let theme = LightweightThemeManager.getUsedTheme(aData.id);
|
||||||
// TODO detect if it is an install and act accordingly
|
let isInstall = !theme || theme.version != aData.version;
|
||||||
if (!theme) {
|
if (isInstall) {
|
||||||
|
var oldWrapper = theme ? new AddonWrapper(theme) : null;
|
||||||
var wrapper = new AddonWrapper(aData);
|
var wrapper = new AddonWrapper(aData);
|
||||||
AddonManagerPrivate.callInstallListeners("onExternalInstall", null,
|
AddonManagerPrivate.callInstallListeners("onExternalInstall", null,
|
||||||
wrapper, null, false);
|
wrapper, oldWrapper, false);
|
||||||
AddonManagerPrivate.callAddonListeners("onInstalling", wrapper, 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);
|
AddonManagerPrivate.callAddonListeners("onInstalled", wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -662,7 +662,7 @@ function run_test_13() {
|
||||||
do_check_eq(install.version, "1.0");
|
do_check_eq(install.version, "1.0");
|
||||||
do_check_eq(install.name, "Test Theme 1");
|
do_check_eq(install.name, "Test Theme 1");
|
||||||
do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
|
do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
|
||||||
|
|
||||||
prepare_test({
|
prepare_test({
|
||||||
"theme1@tests.mozilla.org": [
|
"theme1@tests.mozilla.org": [
|
||||||
"onInstalling",
|
"onInstalling",
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
// The test extension uses an insecure update url.
|
// The test extension uses an insecure update url.
|
||||||
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
|
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
|
||||||
|
|
||||||
|
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
|
||||||
|
|
||||||
do_load_httpd_js();
|
do_load_httpd_js();
|
||||||
var testserver;
|
var testserver;
|
||||||
var profileDir;
|
var profileDir;
|
||||||
|
@ -229,6 +231,76 @@ function check_test_4(install) {
|
||||||
a1.uninstall();
|
a1.uninstall();
|
||||||
restartManager(0);
|
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();
|
end_test();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче