1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<!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",
},
];
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>
|