layout/style/test/test_dont_use_document_fonts.html
author Jan de Mooij <jdemooij@mozilla.com>
Mon, 27 Sep 2021 11:15:49 +0000
changeset 593265 5144ad09cfb7011b98c5422b78b82936b1343541
parent 591615 5bd6a0d3b42ed4a87308c401b7ce088e308cd808
permissions -rw-r--r--
Bug 1732281 part 2 - Transpile ValueToIteratorResult in Warp. r=iain Depends on D126514 Differential Revision: https://phabricator.services.mozilla.com/D126515

<!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");

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",
  },
];

// 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 = "";
}, "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);
  done();
})();
</script>