summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_dont_use_document_fonts.html
diff options
context:
space:
mode:
Diffstat (limited to 'layout/style/test/test_dont_use_document_fonts.html')
-rw-r--r--layout/style/test/test_dont_use_document_fonts.html116
1 files changed, 116 insertions, 0 deletions
diff --git a/layout/style/test/test_dont_use_document_fonts.html b/layout/style/test/test_dont_use_document_fonts.html
new file mode 100644
index 0000000000..59bc6c6d62
--- /dev/null
+++ b/layout/style/test/test_dont_use_document_fonts.html
@@ -0,0 +1,116 @@
+<!doctype html>
+<title>Test for preference to not use document fonts</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<link rel='stylesheet' href='/resources/testharness.css'>
+<div id="content"></div>
+<script>
+const content = document.getElementById("content");
+
+// This is just a subset of browser.display.use_document_fonts.icon_font_allowlist
+// that we feel are worth double-checking via this test. In particular:
+// * Chromium Bug Tracker and https://developers.google.com use "Material Icons"
+// * Google Translate and Google Timeline use "Material Icons Extended"
+// * https://fonts.google.com/icons uses "Material Symbols Outlined"
+// * Google Calendar and Google Contacts use "Google Material Icons"
+const kKnownLigatureIconFonts = "Material Icons, Material Icons Extended, " +
+ "Material Symbols Outlined, Google Material Icons";
+
+setup({explicit_done: true })
+
+content.style.fontFamily = "initial";
+const kInitialFamily = getComputedStyle(content).fontFamily;
+content.style.fontFamily = "";
+
+const kTests = [
+ {
+ specified: "monospace",
+ computed: "monospace",
+ description: "Single generic family should not be changed",
+ },
+ {
+ specified: "monospace, sans-serif",
+ computed: "monospace, sans-serif",
+ description: "Generic families should not be changed",
+ },
+ {
+ specified: "Courier, monospace",
+ computed: "monospace, Courier",
+ description: "Generics are preferred, but may still fall back to document fonts",
+ },
+ {
+ specified: "system-ui, sans-serif",
+ computed: "sans-serif, system-ui",
+ description: "system-ui is not prioritized",
+ },
+ {
+ specified: "Courier, something-else",
+ computed: `${kInitialFamily}, Courier, something-else`,
+ description: "Generic is prepended to the font-family if none is found",
+ },
+ {
+ specified: kKnownLigatureIconFonts + ", something-else, sans-serif",
+ computed: kKnownLigatureIconFonts + ", sans-serif, something-else",
+ description: "Known ligature-icon fonts remain ahead of the generic",
+ },
+ {
+ specified: "Material Icons, something-else, Material Symbols Outlined, sans-serif",
+ computed: "Material Icons, sans-serif, something-else, Material Symbols Outlined",
+ description: "Generic is moved ahead of the first non-allowlisted font",
+ },
+ {
+ specified: "Material Icons, something-else, Material Symbols Outlined",
+ computed: `Material Icons, ${kInitialFamily}, something-else, Material Symbols Outlined`,
+ description: "Default generic is inserted ahead of the first non-allowlisted font",
+ },
+ {
+ specified: "Material Icons, cursive, Material Symbols Outlined, serif",
+ computed: "Material Icons, serif, cursive, Material Symbols Outlined",
+ description: "cursive is not treated as a generic to be prioritized",
+ },
+ {
+ specified: "Material Icons, fantasy, Material Symbols Outlined",
+ computed: `Material Icons, ${kInitialFamily}, fantasy, Material Symbols Outlined`,
+ description: "fantasy is not treated as a generic to be prioritized",
+ },
+];
+
+let systemFont;
+
+// compute expectations while the pref is not active yet.
+test(function() {
+ for (const test of kTests) {
+ content.style.fontFamily = "";
+ content.style.fontFamily = test.computed;
+ assert_not_equals(content.style.fontFamily, "", `computed font ${test.computed} was invalid`);
+ test.expected = getComputedStyle(content).fontFamily;
+ }
+
+ content.style.font = "menu";
+ systemFont = getComputedStyle(content).fontFamily;
+ assert_not_equals(systemFont, "", `computed menu system font was invalid`);
+
+ content.style.font = "";
+}, "Sanity");
+
+function runTest({ specified, computed, description, expected }) {
+ test(function() {
+ content.style.fontFamily = "";
+ content.style.fontFamily = specified;
+ assert_equals(getComputedStyle(content).fontFamily, expected);
+ }, description);
+}
+
+(async function() {
+ await SpecialPowers.pushPrefEnv({'set': [['browser.display.use_document_fonts', 0]]});
+ for (const test of kTests)
+ runTest(test);
+
+ test(function() {
+ content.style.font = "menu";
+ assert_equals(getComputedStyle(content).fontFamily, systemFont);
+ }, "System font should be honored");
+
+ done();
+})();
+</script>