Backed out changeset c0ebdd0be6ba (bug 1467695) for failing browser chrome at browser/components/customizableui/test/browser_1007336_lwthemes_in_customize_mode.js on a CLOSED TREE

This commit is contained in:
Andreea Pavel 2018-06-28 05:41:36 +03:00
parent 968b352951
commit 7aa70eced0
7 changed files with 22 additions and 81 deletions

View File

@ -16,39 +16,29 @@ registerCleanupFunction(() => {
Services.prefs.clearUserPref(PREF_LWTHEME_USED_THEMES);
});
function tick() {
return new Promise(SimpleTest.executeSoon);
}
add_task(async function startTests() {
info("Setting the current theme to null");
LightweightThemeManager.currentTheme = null;
await tick();
ok(!CompactTheme.isStyleSheetEnabled, "There is no compact style sheet when no lw theme is applied.");
info("Adding a lightweight theme.");
LightweightThemeManager.currentTheme = dummyLightweightTheme("preview0");
await tick();
ok(!CompactTheme.isStyleSheetEnabled, "The compact stylesheet has been removed when a lightweight theme is applied.");
info("Applying the dark compact theme.");
LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme(COMPACT_DARK_ID);
await tick();
ok(CompactTheme.isStyleSheetEnabled, "The compact stylesheet has been added when the compact lightweight theme is applied");
info("Applying the light compact theme.");
LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme(COMPACT_LIGHT_ID);
await tick();
ok(CompactTheme.isStyleSheetEnabled, "The compact stylesheet has been added when the compact lightweight theme is applied");
info("Adding a different lightweight theme.");
LightweightThemeManager.currentTheme = dummyLightweightTheme("preview1");
await tick();
ok(!CompactTheme.isStyleSheetEnabled, "The compact stylesheet has been removed when a lightweight theme is applied.");
info("Unapplying all themes.");
LightweightThemeManager.currentTheme = null;
await tick();
ok(!CompactTheme.isStyleSheetEnabled, "There is no compact style sheet when no lw theme is applied.");
});
@ -65,7 +55,6 @@ function dummyLightweightTheme(id) {
add_task(async function testLightweightThemePreview() {
info("Setting compact to current and previewing others");
LightweightThemeManager.currentTheme = LightweightThemeManager.getUsedTheme(COMPACT_LIGHT_ID);
await tick();
ok(CompactTheme.isStyleSheetEnabled, "The compact stylesheet is enabled.");
LightweightThemeManager.previewTheme(dummyLightweightTheme("preview0"));
ok(!CompactTheme.isStyleSheetEnabled, "The compact stylesheet is not enabled after a lightweight theme preview.");
@ -75,7 +64,6 @@ add_task(async function testLightweightThemePreview() {
LightweightThemeManager.resetPreview();
ok(CompactTheme.isStyleSheetEnabled, "The compact stylesheet is enabled again after resetting the preview.");
LightweightThemeManager.currentTheme = null;
await tick();
ok(!CompactTheme.isStyleSheetEnabled, "The compact stylesheet is gone after removing the current theme.");
info("Previewing the compact theme");

View File

@ -1502,7 +1502,7 @@ var AddonManagerInternal = {
* A boolean indicating if the change will only take place the next
* time the application is restarted
*/
async notifyAddonChanged(aID, aType, aPendingRestart) {
notifyAddonChanged(aID, aType, aPendingRestart) {
if (!gStarted)
throw Components.Exception("AddonManager is not initialized",
Cr.NS_ERROR_NOT_INITIALIZED);
@ -1530,10 +1530,7 @@ var AddonManagerInternal = {
// removed by bug 520124, so this is a temporary quick'n'dirty hack.
let providers = [...this.providers, ...this.pendingProviders];
for (let provider of providers) {
let result = callProvider(provider, "addonChanged", null, aID, aType, aPendingRestart);
if (result) {
await result;
}
callProvider(provider, "addonChanged", null, aID, aType, aPendingRestart);
}
},

View File

@ -1602,7 +1602,7 @@ this.XPIDatabase = {
* @param {string} aType
* The type of the newly enabled add-on
*/
async addonChanged(aId, aType) {
addonChanged(aId, aType) {
// We only care about themes in this provider
if (!isTheme(aType))
return;
@ -1610,7 +1610,7 @@ this.XPIDatabase = {
let addons = this.getAddonsByType("webextension-theme");
for (let theme of addons) {
if (theme.visible && theme.id != aId)
await this.updateAddonDisabledState(theme, true, undefined, true);
this.updateAddonDisabledState(theme, true, undefined, true);
}
if (!aId && (!LightweightThemeManager.currentTheme ||

View File

@ -458,14 +458,9 @@ add_task(async function() {
});
function tick() {
return new Promise(SimpleTest.executeSoon);
}
add_task(async function() {
info("Enabling lightweight theme");
LightweightThemeManager.currentTheme = gLWTheme;
await tick();
gManagerWindow.loadView("addons://list/theme");
await new Promise(resolve => wait_for_view_load(gManagerWindow, resolve));
@ -479,7 +474,6 @@ add_task(async function() {
info("Disabling lightweight theme");
LightweightThemeManager.currentTheme = null;
await tick();
is_element_hidden(get_node(addon, "preferences-btn"), "Preferences button should be hidden");
is_element_visible(get_node(addon, "enable-btn"), "Enable button should be hidden");

View File

@ -18,15 +18,6 @@ function dummy(id) {
};
}
function tick() {
return new Promise(executeSoon);
}
function setTheme(theme) {
LightweightThemeManager.currentTheme = theme;
return tick();
}
function hasPermission(aAddon, aPerm) {
var perm = AddonManager["PERM_CAN_" + aPerm.toUpperCase()];
return !!(aAddon.permissions & perm);
@ -38,8 +29,7 @@ add_task(async function run_test() {
Services.prefs.setIntPref("lightweightThemes.maxUsedThemes", 8);
ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm");
let ltm = LightweightThemeManager;
let {LightweightThemeManager: ltm} = ChromeUtils.import("resource://gre/modules/LightweightThemeManager.jsm", {});
Assert.equal(typeof ltm, "object");
Assert.equal(typeof ltm.usedThemes, "object");
@ -55,7 +45,7 @@ add_task(async function run_test() {
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
ltm.resetPreview();
await setTheme(dummy("x0"));
ltm.currentTheme = dummy("x0");
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.id, "x0");
Assert.equal(ltm.usedThemes[0].id, "x0");
@ -69,12 +59,12 @@ add_task(async function run_test() {
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.id, "x0");
await setTheme(dummy("x1"));
ltm.currentTheme = dummy("x1");
Assert.equal(ltm.usedThemes.length, 3);
Assert.equal(ltm.currentTheme.id, "x1");
Assert.equal(ltm.usedThemes[1].id, "x0");
await setTheme(dummy("x2"));
ltm.currentTheme = dummy("x2");
Assert.equal(ltm.usedThemes.length, 4);
Assert.equal(ltm.currentTheme.id, "x2");
Assert.equal(ltm.usedThemes[1].id, "x1");
@ -85,13 +75,12 @@ add_task(async function run_test() {
ltm.currentTheme = dummy("x5");
ltm.currentTheme = dummy("x6");
ltm.currentTheme = dummy("x7");
await tick();
Assert.equal(ltm.usedThemes.length, 9);
Assert.equal(ltm.currentTheme.id, "x7");
Assert.equal(ltm.usedThemes[1].id, "x6");
Assert.equal(ltm.usedThemes[7].id, "x0");
await setTheme(dummy("x8"));
ltm.currentTheme = dummy("x8");
Assert.equal(ltm.usedThemes.length, 9);
Assert.equal(ltm.currentTheme.id, "x8");
Assert.equal(ltm.usedThemes[1].id, "x7");
@ -103,7 +92,6 @@ add_task(async function run_test() {
Assert.notEqual(ltm.currentTheme.id, DEFAULT_THEME_ID);
ltm.forgetUsedTheme("x8");
await tick();
Assert.equal(ltm.usedThemes.length, 8);
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
Assert.equal(ltm.usedThemes[0].id, "x7");
@ -119,19 +107,19 @@ add_task(async function run_test() {
Assert.equal(ltm.usedThemes[0].id, "x2");
Assert.equal(ltm.usedThemes[1].id, "x1");
await setTheme(dummy("x1"));
ltm.currentTheme = dummy("x1");
Assert.equal(ltm.usedThemes.length, 3);
Assert.equal(ltm.currentTheme.id, "x1");
Assert.equal(ltm.usedThemes[0].id, "x1");
Assert.equal(ltm.usedThemes[1].id, "x2");
await setTheme(dummy("x2"));
ltm.currentTheme = dummy("x2");
Assert.equal(ltm.usedThemes.length, 3);
Assert.equal(ltm.currentTheme.id, "x2");
Assert.equal(ltm.usedThemes[0].id, "x2");
Assert.equal(ltm.usedThemes[1].id, "x1");
await setTheme(ltm.getUsedTheme("x1"));
ltm.currentTheme = ltm.getUsedTheme("x1");
Assert.equal(ltm.usedThemes.length, 3);
Assert.equal(ltm.currentTheme.id, "x1");
Assert.equal(ltm.usedThemes[0].id, "x1");
@ -139,7 +127,6 @@ add_task(async function run_test() {
ltm.forgetUsedTheme("x1");
ltm.forgetUsedTheme("x2");
await tick();
Assert.equal(ltm.usedThemes.length, 1);
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
@ -147,7 +134,7 @@ add_task(async function run_test() {
var chineseTheme = dummy("chinese0");
chineseTheme.name = "笢恅0";
chineseTheme.description = "笢恅1";
await setTheme(chineseTheme);
ltm.currentTheme = chineseTheme;
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.name, "笢恅0");
Assert.equal(ltm.currentTheme.description, "笢恅1");
@ -160,7 +147,7 @@ add_task(async function run_test() {
var chineseTheme1 = dummy("chinese1");
chineseTheme1.name = "眵昜湮桵蔗坌~郔乾";
chineseTheme1.description = "眵昜湮桵蔗坌~郔乾";
await setTheme(chineseTheme1);
ltm.currentTheme = chineseTheme1;
Assert.notEqual(ltm.currentTheme.id, DEFAULT_THEME_ID);
Assert.equal(ltm.usedThemes.length, 3);
Assert.equal(ltm.currentTheme.name, "眵昜湮桵蔗坌~郔乾");
@ -171,12 +158,10 @@ add_task(async function run_test() {
Assert.equal(ltm.usedThemes[0].description, "眵昜湮桵蔗坌~郔乾");
ltm.forgetUsedTheme("chinese0");
await tick();
Assert.equal(ltm.usedThemes.length, 2);
Assert.notEqual(ltm.currentTheme.id, DEFAULT_THEME_ID);
ltm.forgetUsedTheme("chinese1");
await tick();
Assert.equal(ltm.usedThemes.length, 1);
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
@ -332,61 +317,52 @@ add_task(async function run_test() {
// Sanitize themes with a bad headerURL
data = dummy();
data.headerURL = "foo";
await setTheme(data);
ltm.currentTheme = data;
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.headerURL, undefined);
ltm.forgetUsedTheme(ltm.currentTheme.id);
await tick();
Assert.equal(ltm.usedThemes.length, 1);
// Sanitize themes with a non-http(s) headerURL
data = dummy();
data.headerURL = "ftp://lwtest.invalid/test.png";
await setTheme(data);
ltm.currentTheme = data;
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.headerURL, undefined);
ltm.forgetUsedTheme(ltm.currentTheme.id);
await tick();
Assert.equal(ltm.usedThemes.length, 1);
// Sanitize themes with a non-http(s) headerURL
data = dummy();
data.headerURL = "file:///test.png";
await setTheme(data);
ltm.currentTheme = data;
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.headerURL, undefined);
ltm.forgetUsedTheme(ltm.currentTheme.id);
await tick();
Assert.equal(ltm.usedThemes.length, 1);
data = dummy();
data.updateURL = "file:///test.json";
ltm.setLocalTheme(data);
await tick();
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.updateURL, undefined);
ltm.forgetUsedTheme(ltm.currentTheme.id);
await tick();
Assert.equal(ltm.usedThemes.length, 1);
data = dummy();
data.headerURL = "file:///test.png";
ltm.setLocalTheme(data);
await tick();
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.headerURL, "file:///test.png");
ltm.forgetUsedTheme(ltm.currentTheme.id);
await tick();
Assert.equal(ltm.usedThemes.length, 1);
data = dummy();
data.headerURL = "ftp://lwtest.invalid/test.png";
ltm.setLocalTheme(data);
await tick();
Assert.equal(ltm.usedThemes.length, 2);
Assert.equal(ltm.currentTheme.updateURL, undefined);
ltm.forgetUsedTheme(ltm.currentTheme.id);
await tick();
Assert.equal(ltm.usedThemes.length, 1);
data = dummy();
@ -407,10 +383,9 @@ add_task(async function run_test() {
Assert.equal(ltm.usedThemes.length, 2);
// This should silently drop the bad theme.
await setTheme(dummy());
ltm.currentTheme = dummy();
Assert.equal(ltm.usedThemes.length, 2);
ltm.forgetUsedTheme(ltm.currentTheme.id);
await tick();
Assert.equal(ltm.usedThemes.length, 1);
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
@ -420,11 +395,10 @@ add_task(async function run_test() {
Assert.equal(ltm.usedThemes.length, 4);
// Switching to an existing theme should drop the bad theme.
await setTheme(ltm.getUsedTheme("x1"));
ltm.currentTheme = ltm.getUsedTheme("x1");
Assert.equal(ltm.usedThemes.length, 3);
ltm.forgetUsedTheme("x1");
ltm.forgetUsedTheme("x2");
await tick();
Assert.equal(ltm.usedThemes.length, 1);
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
@ -433,17 +407,14 @@ add_task(async function run_test() {
// Forgetting an existing theme should drop the bad theme.
ltm.forgetUsedTheme("x1");
await tick();
Assert.equal(ltm.usedThemes.length, 2);
ltm.forgetUsedTheme("x2");
await tick();
Assert.equal(ltm.usedThemes.length, 1);
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
// Test whether a JSON set with setCharPref can be retrieved with usedThemes
ltm.currentTheme = dummy("x0");
ltm.currentTheme = dummy("x1");
await tick();
Services.prefs.setCharPref("lightweightThemes.usedThemes", JSON.stringify(ltm.usedThemes));
Assert.equal(ltm.usedThemes.length, 4);
Assert.equal(ltm.currentTheme.id, "x1");
@ -451,12 +422,10 @@ add_task(async function run_test() {
Assert.equal(ltm.usedThemes[0].id, "x1");
ltm.forgetUsedTheme("x0");
await tick();
Assert.equal(ltm.usedThemes.length, 2);
Assert.notEqual(ltm.currentTheme.id, DEFAULT_THEME_ID);
ltm.forgetUsedTheme("x1");
await tick();
Assert.equal(ltm.usedThemes.length, 1);
Assert.equal(ltm.currentTheme.id, DEFAULT_THEME_ID);
@ -492,12 +461,10 @@ add_task(async function run_test() {
ltm.currentTheme = dummy("x28");
ltm.currentTheme = dummy("x29");
ltm.currentTheme = dummy("x30");
await tick();
Assert.equal(ltm.usedThemes.length, 31);
ltm.currentTheme = dummy("x31");
await tick();
Assert.equal(ltm.usedThemes.length, 31);
Assert.equal(ltm.getUsedTheme("x1"), null);
@ -526,12 +493,10 @@ add_task(async function run_test() {
ltm.currentTheme = dummy("x16");
ltm.currentTheme = dummy("x32");
await tick();
Assert.equal(ltm.usedThemes.length, 33);
ltm.currentTheme = dummy("x33");
await tick();
Assert.equal(ltm.usedThemes.length, 33);
@ -574,7 +539,7 @@ add_task(async function run_test() {
Assert.equal(hasPermission(builtInThemeAddon, "disable"), false);
Assert.equal(hasPermission(builtInThemeAddon, "enable"), true);
await setTheme(dummy("x0"));
ltm.currentTheme = dummy("x0");
Assert.equal([...ltm._builtInThemes].length, 2);
Assert.equal(ltm.usedThemes.length, 3);
Assert.equal(ltm.usedThemes[0].id, "x0");
@ -595,11 +560,10 @@ add_task(async function run_test() {
Assert.equal(hasPermission(x0Addon, "enable"), false);
ltm.forgetUsedTheme("x0");
await tick();
Assert.equal(ltm.currentTheme, null);
// Removing the currently applied app specific theme should unapply it
await setTheme(ltm.getUsedTheme("builtInTheme0"));
ltm.currentTheme = ltm.getUsedTheme("builtInTheme0");
Assert.equal(ltm.currentTheme.id, "builtInTheme0");
Assert.ok(ltm.forgetBuiltInTheme("builtInTheme0"));
Assert.equal(ltm.currentTheme, null);

View File

@ -24,8 +24,7 @@ const IGNORE_PRIVATE = ["AddonAuthor", "AddonCompatibilityOverride",
"setTelemetryDetails", "getTelemetryDetails",
"callNoUpdateListeners", "backgroundUpdateTimerHandler",
"hasUpgradeListener", "getUpgradeListener",
"isDBLoaded", "recordTiming", "BOOTSTRAP_REASONS",
"notifyAddonChanged"];
"isDBLoaded", "recordTiming", "BOOTSTRAP_REASONS"];
async function test_functions() {
for (let prop in AddonManager) {

View File

@ -63,7 +63,6 @@ add_task(async function setup_to_default_browserish_state() {
await t1.disable();
await t2.disable();
await new Promise(executeSoon);
Assert.ok(!t1.isActive, "Theme should be disabled");
Assert.ok(!t2.isActive, "Theme should be disabled");
Assert.ok(d.isActive, "Default theme should be active");