fune/toolkit/components/extensions/test/browser/browser_ext_themes_sanitization.js
Emilio Cobos Álvarez 9192756e3e Bug 1889463 - Re-land tabs-navbar-separator simplification, suppressing it completely if transparent. r=desktop-theme-reviewers,tabbrowser-reviewers,dao
This relands the simplification that was reverted in bug 1647356, which
made it so that the border takes space, with a key tweak.

The border taking space is generally good and simplified some code, but
it causes uneven spacing around the urlbar if we set the separator color
to transparent (like many even builtin themes do).

This is technically already an issue if a theme sets the
`chrome-content-separator-color` to transparent, but I think that's
really uncommon, and we don't want to encourage themes to suppress that
separator IMO... We might want to forbid that even somehow?

So for now only handle the tabs separator. Clean-up some adjacent code
while at it.

An alternative would be to keep the shadow, and add some comments as for
why it's a shadow and not a border, but that seems to subtly complicate
layout in other places (which were working around it before the
regressing bug).

Differential Revision: https://phabricator.services.mozilla.com/D206547
2024-04-04 10:21:27 +00:00

175 lines
4.1 KiB
JavaScript

"use strict";
// This test checks color sanitization in various situations
add_task(async function test_sanitization_invalid() {
// This test checks that invalid values are sanitized
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
bookmark_text: "ntimsfavoriteblue",
},
},
},
});
await extension.startup();
let navbar = document.querySelector("#nav-bar");
Assert.equal(
window.getComputedStyle(navbar).color,
"rgb(0, 0, 0)",
"All invalid values should always compute to black."
);
await extension.unload();
});
add_task(async function test_sanitization_css_variables() {
// This test checks that CSS variables are sanitized
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
bookmark_text: "var(--arrowpanel-dimmed)",
},
},
},
});
await extension.startup();
let navbar = document.querySelector("#nav-bar");
Assert.equal(
window.getComputedStyle(navbar).color,
"rgb(0, 0, 0)",
"All CSS variables should always compute to black."
);
await extension.unload();
});
add_task(async function test_sanitization_important() {
// This test checks that the sanitizer cannot be fooled with !important
let stylesheetAttr = `href="data:text/css,*{color:red!important}" type="text/css"`;
let stylesheet = document.createProcessingInstruction(
"xml-stylesheet",
stylesheetAttr
);
let load = BrowserTestUtils.waitForEvent(stylesheet, "load");
document.insertBefore(stylesheet, document.documentElement);
await load;
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
bookmark_text: "green",
},
},
},
});
await extension.startup();
let navbar = document.querySelector("#nav-bar");
Assert.equal(
window.getComputedStyle(navbar).color,
"rgb(255, 0, 0)",
"Sheet applies"
);
stylesheet.remove();
Assert.equal(
window.getComputedStyle(navbar).color,
"rgb(0, 128, 0)",
"Shouldn't be able to fool the color sanitizer with !important"
);
await extension.unload();
});
add_task(async function test_sanitization_transparent() {
// This test checks whether transparent values are applied properly
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: TEXT_COLOR,
toolbar_top_separator: "transparent",
},
},
},
});
await extension.startup();
let navbar = document.querySelector("#nav-bar");
Assert.equal(
window.getComputedStyle(navbar).borderTopColor,
"rgba(0, 0, 0, 0)",
"Top separator should be transparent"
);
await extension.unload();
});
add_task(async function test_sanitization_transparent_frame_color() {
// This test checks whether transparent frame color falls back to white.
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: "transparent",
tab_background_text: TEXT_COLOR,
},
},
},
});
await extension.startup();
Assert.equal(
getToolboxBackgroundColor(),
"rgb(255, 255, 255)",
"Accent color should be white"
);
await extension.unload();
});
add_task(
async function test_sanitization_transparent_tab_background_text_color() {
// This test checks whether transparent textcolor falls back to black.
let extension = ExtensionTestUtils.loadExtension({
manifest: {
theme: {
colors: {
frame: ACCENT_COLOR,
tab_background_text: "transparent",
},
},
},
});
await extension.startup();
let docEl = document.documentElement;
Assert.equal(
window.getComputedStyle(docEl).color,
"rgb(0, 0, 0)",
"Text color should be black"
);
await extension.unload();
}
);