mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
bug 1373850 add browser.theme.reset which allows unloading changes caused by browser.theme.update and resets to the default theme r=mattw,mikedeboer
MozReview-Commit-ID: 4wZQNsM2bFw --HG-- extra : rebase_source : 55fd4f87c760010f276ac5985f1dc71c5632473e
This commit is contained in:
parent
18dfa02948
commit
d8a34a9438
@ -284,6 +284,19 @@ this.theme = class extends ExtensionAPI {
|
||||
|
||||
this.theme.load(details);
|
||||
},
|
||||
reset: () => {
|
||||
if (!gThemesEnabled) {
|
||||
// Return early if themes are disabled.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.theme) {
|
||||
// If no theme has been initialized, nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
this.theme.unload();
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -458,6 +458,13 @@
|
||||
"description": "The properties of the theme to update."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "reset",
|
||||
"type": "function",
|
||||
"async": true,
|
||||
"description": "Removes the updates made to the theme.",
|
||||
"parameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -12,22 +12,28 @@ const TEXT_COLOR_2 = "#0ef325";
|
||||
|
||||
function hexToRGB(hex) {
|
||||
hex = parseInt((hex.indexOf("#") > -1 ? hex.substring(1) : hex), 16);
|
||||
return [hex >> 16, (hex & 0x00FF00) >> 8, (hex & 0x0000FF)];
|
||||
return "rgb(" + [hex >> 16, (hex & 0x00FF00) >> 8, (hex & 0x0000FF)].join(", ") + ")";
|
||||
}
|
||||
|
||||
function validateTheme(backgroundImage, accentColor, textColor) {
|
||||
function validateTheme(backgroundImage, accentColor, textColor, isLWT) {
|
||||
let docEl = window.document.documentElement;
|
||||
let style = window.getComputedStyle(docEl);
|
||||
|
||||
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
|
||||
Assert.equal(docEl.getAttribute("lwthemetextcolor"), "bright",
|
||||
"LWT text color attribute should be set");
|
||||
if (isLWT) {
|
||||
Assert.ok(docEl.hasAttribute("lwtheme"), "LWT attribute should be set");
|
||||
Assert.equal(docEl.getAttribute("lwthemetextcolor"), "bright",
|
||||
"LWT text color attribute should be set");
|
||||
}
|
||||
|
||||
Assert.ok(style.backgroundImage.includes(backgroundImage), "Expected correct background image");
|
||||
Assert.equal(style.backgroundColor, "rgb(" + hexToRGB(accentColor).join(", ") + ")",
|
||||
"Expected correct accent color");
|
||||
Assert.equal(style.color, "rgb(" + hexToRGB(textColor).join(", ") + ")",
|
||||
"Expected correct text color");
|
||||
if (accentColor.startsWith("#")) {
|
||||
accentColor = hexToRGB(accentColor);
|
||||
}
|
||||
if (textColor.startsWith("#")) {
|
||||
textColor = hexToRGB(textColor);
|
||||
}
|
||||
Assert.equal(style.backgroundColor, accentColor, "Expected correct accent color");
|
||||
Assert.equal(style.color, textColor, "Expected correct text color");
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
@ -47,16 +53,20 @@ add_task(async function test_dynamic_theme_updates() {
|
||||
},
|
||||
background() {
|
||||
browser.test.onMessage.addListener((msg, details) => {
|
||||
if (msg != "update-theme") {
|
||||
browser.test.fail("expected 'update-theme' message");
|
||||
if (msg === "update-theme") {
|
||||
browser.theme.update(details).then(() => {
|
||||
browser.test.sendMessage("theme-updated");
|
||||
});
|
||||
} else {
|
||||
browser.theme.reset().then(() => {
|
||||
browser.test.sendMessage("theme-reset");
|
||||
});
|
||||
}
|
||||
|
||||
browser.theme.update(details);
|
||||
browser.test.sendMessage("theme-updated");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
let defaultStyle = window.getComputedStyle(window.document.documentElement);
|
||||
await extension.startup();
|
||||
|
||||
extension.sendMessage("update-theme", {
|
||||
@ -71,7 +81,7 @@ add_task(async function test_dynamic_theme_updates() {
|
||||
|
||||
await extension.awaitMessage("theme-updated");
|
||||
|
||||
validateTheme("image1.png", ACCENT_COLOR_1, TEXT_COLOR_1);
|
||||
validateTheme("image1.png", ACCENT_COLOR_1, TEXT_COLOR_1, true);
|
||||
|
||||
extension.sendMessage("update-theme", {
|
||||
"images": {
|
||||
@ -85,7 +95,14 @@ add_task(async function test_dynamic_theme_updates() {
|
||||
|
||||
await extension.awaitMessage("theme-updated");
|
||||
|
||||
validateTheme("image2.png", ACCENT_COLOR_2, TEXT_COLOR_2);
|
||||
validateTheme("image2.png", ACCENT_COLOR_2, TEXT_COLOR_2, true);
|
||||
|
||||
extension.sendMessage("reset-theme");
|
||||
|
||||
await extension.awaitMessage("theme-reset");
|
||||
|
||||
let {backgroundImage, backgroundColor, color} = defaultStyle;
|
||||
validateTheme(backgroundImage, backgroundColor, color, false);
|
||||
|
||||
await extension.unload();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user