Bug 1585290 - Preserve theme from other extension upon theme.reset() r=robwu

Differential Revision: https://phabricator.services.mozilla.com/D52148

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Myeongjun Go 2020-03-27 15:37:46 +00:00
Родитель 6227308bfd
Коммит 09a0a25b55
4 изменённых файлов: 73 добавлений и 14 удалений

Просмотреть файл

@ -389,7 +389,7 @@ class Theme {
lwtData.window = getWinUtils(
windowTracker.getWindow(windowId)
).outerWindowID;
windowOverrides.set(windowId, emptyTheme);
windowOverrides.delete(windowId);
} else {
windowOverrides.clear();
defaultTheme = emptyTheme;
@ -473,12 +473,12 @@ this.theme = class extends ExtensionAPI {
if (!browserWindow) {
return Promise.reject(`Invalid window ID: ${windowId}`);
}
} else if (defaultTheme.extension !== extension) {
return;
}
if (!defaultTheme && !windowOverrides.has(windowId)) {
// If no theme has been initialized, nothing to do.
let theme = windowOverrides.get(windowId) || defaultTheme;
if (theme.extension !== extension) {
return;
}
} else if (defaultTheme.extension !== extension) {
return;
}

Просмотреть файл

@ -28,18 +28,18 @@ skip-if = verify
[browser_ext_themes_reset.js]
[browser_ext_themes_sanitization.js]
[browser_ext_themes_separators.js]
[browser_ext_themes_static_onUpdated.js]
[browser_ext_themes_sidebars.js]
[browser_ext_themes_static_onUpdated.js]
[browser_ext_themes_tab_line.js]
[browser_ext_themes_tab_loading.js]
[browser_ext_themes_tab_selected.js]
[browser_ext_themes_tab_separators.js]
[browser_ext_themes_tab_text.js]
[browser_ext_themes_toolbar_fields_focus.js]
[browser_ext_themes_toolbar_fields.js]
[browser_ext_themes_toolbars.js]
[browser_ext_themes_toolbarbutton_icons.js]
[browser_ext_themes_toolbarbutton_colors.js]
[browser_ext_themes_toolbarbutton_icons.js]
[browser_ext_themes_toolbars.js]
[browser_ext_themes_theme_transition.js]
[browser_ext_themes_tab_selected.js]
[browser_ext_themes_warnings.js]
[browser_ext_windows_popup_title.js]

Просмотреть файл

@ -145,7 +145,7 @@ add_task(async function test_get_current() {
browser.test.log("Testing getCurrent() after theme.reset(windowId)");
await browser.theme.reset(firstWin.id);
testTheme2(await browser.theme.getCurrent());
testEmptyTheme(await browser.theme.getCurrent(firstWin.id));
testTheme1(await browser.theme.getCurrent(firstWin.id));
testTheme2(await browser.theme.getCurrent(secondWin.id));
browser.test.log(
@ -154,8 +154,8 @@ add_task(async function test_get_current() {
focusChanged = ensureWindowFocused(firstWin.id);
await browser.windows.update(firstWin.id, { focused: true });
await focusChanged;
testEmptyTheme(await browser.theme.getCurrent());
testEmptyTheme(await browser.theme.getCurrent(firstWin.id));
testTheme1(await browser.theme.getCurrent());
testTheme1(await browser.theme.getCurrent(firstWin.id));
testTheme2(await browser.theme.getCurrent(secondWin.id));
browser.test.log("Testing getCurrent() after theme.update(windowId)");

Просмотреть файл

@ -1,6 +1,6 @@
"use strict";
add_task(async function theme_reset_by_extension() {
add_task(async function theme_reset_global_static_theme() {
let global_theme_extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
@ -51,3 +51,62 @@ add_task(async function theme_reset_by_extension() {
await global_theme_extension.unload();
await extension.unload();
});
add_task(async function theme_reset_by_windowId() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["theme"],
},
async background() {
let theme = {
colors: {
frame: "#CF723F",
},
};
let { id: winId } = await browser.windows.getCurrent();
await browser.theme.update(winId, theme);
let update_theme = await browser.theme.getCurrent(winId);
browser.test.onMessage.addListener(async () => {
let current_theme = await browser.theme.getCurrent(winId);
browser.test.assertEq(
update_theme.colors.frame,
current_theme.colors.frame,
"Should not be reset by a reset(windowId) call from another extension"
);
browser.test.sendMessage("done");
});
browser.test.sendMessage("ready", winId);
},
});
let anotherExtension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["theme"],
},
background() {
browser.test.onMessage.addListener(async winId => {
await browser.theme.reset(winId);
browser.test.sendMessage("done");
});
},
});
await extension.startup();
let winId = await extension.awaitMessage("ready");
await anotherExtension.startup();
// theme.reset should be ignored if the theme was set by another extension.
anotherExtension.sendMessage(winId);
await anotherExtension.awaitMessage("done");
extension.sendMessage();
await extension.awaitMessage("done");
await anotherExtension.unload();
await extension.unload();
});