File: font-variation-settings-parsing.html

package info (click to toggle)
thunderbird 1%3A78.14.0-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,922,628 kB
  • sloc: cpp: 5,990,120; javascript: 4,418,692; ansic: 3,063,889; python: 915,509; asm: 304,197; xml: 206,623; sh: 109,253; java: 108,679; makefile: 22,985; perl: 15,867; yacc: 4,565; objc: 3,026; pascal: 1,787; lex: 1,720; ada: 1,681; cs: 879; exp: 505; awk: 485; sql: 452; php: 436; lisp: 432; ruby: 99; sed: 69; csh: 45
file content (59 lines) | stat: -rw-r--r-- 5,034 bytes parent folder | download | duplicates (6)
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
<!DOCTYPE html>
<html>
<head>
    <title>Testing the parsing of the font-variation-settings property</title>
    <link rel="help" href="https://www.w3.org/TR/css-fonts-4/#propdef-font-variation-settings" />
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
</head>
<body>
    <div id="value-parser-test"></div>
    <script>

        var valueParserTests = [
            { value: "'wght' 1000, '9 ~A' -45",           expectedComputedValue: "\"wght\" 1000, \"9 ~A\" -45",    isValid: true,  message: "Axis tag with valid non-letter ascii characters" },
            { value: "'\u001Fbdc' 123",                   expectedComputedValue: "",                               isValid: false, message: "Invalid character below allowed range (first char)"},
            { value: "'abc\u007F' 123",                   expectedComputedValue: "",                               isValid: false, message: "Invalid character above allowed range (mid char)"},
            { value: "'wght' 1e3, 'slnt' -450.0e-1 ",     expectedComputedValue: "\"wght\" 1000, \"slnt\" -45",    isValid: true,  message: "Axis values in scientific form are valid" },
            { value: "normal",                            expectedComputedValue: "normal",                         isValid: true,  message: "'normal' value is valid" },
            { value: "'a' 1234",                          expectedComputedValue: "",                               isValid: false, message: "Tag with less than 4 characters is invalid"},
            { value: "'abcde' 1234",                      expectedComputedValue: "",                               isValid: false, message: "Tag with more than 4 characters is invalid"},
            { value: "'wght' 200, ",                      expectedComputedValue: "",                               isValid: false, message: "Trailing comma is invalid"},
            { value: "abcd 123",                          expectedComputedValue: "",                               isValid: false, message: "Unquoted tags are invalid"},
            { value: "'abcd\" 123",                       expectedComputedValue: "",                               isValid: false, message: "Unmatched quotes around tag are invalid" },
            { value: "'abcd'",                            expectedComputedValue: "",                               isValid: false, message: "Tag without value isinvalid"},
            { value: "123",                               expectedComputedValue: "",                               isValid: false, message: "Value without tag is invalid"},
            { value: "123 'abcd'",                        expectedComputedValue: "",                               isValid: false, message: "Value before tag is invalid"},
            { value: "'wght' 200 'abcd' 400",             expectedComputedValue: "",                               isValid: false, message: "Missing comma between axes is invalid"},
            { value: "'wght' calc(100 + 200)",            expectedComputedValue: "\"wght\" 300",                   isValid: true,  message: "Calculations should be supported" },
            { value: "'wght' 100px",                      expectedComputedValue: "",                               isValid: false, message: "Units should not be supported" },
            { value: "'wght' calc(100px + 200px)",        expectedComputedValue: "",                               isValid: false, message: "Units should not be supported (in calc)" },
            { value: "'wght' 42%",                        expectedComputedValue: "",                               isValid: false, message: "Percentages should not be supported" },
            { value: "'wght' calc(100%)",                 expectedComputedValue: "",                               isValid: false, message: "Percentages should not be supported (in calc)" },
        ];

        valueParserTests.forEach(function (testCase) {
            test(() => {
                var element = document.getElementById("value-parser-test");
                // Reset to empty in order for testing to continue in case the next test would not parse as valid
                element.style.fontVariationSettings = "";
                element.style.fontVariationSettings = testCase.value;
                var computed = window.getComputedStyle(element).fontVariationSettings;
                if (testCase.isValid) {
                    assert_equals(computed, testCase.expectedComputedValue, testCase.message);
                }
                else {
                    assert_equals(computed, "normal", testCase.message);
                }

                element.style.fontVariationSettings = "";
            },  "Property value: " + testCase.message);
        });

        valueParserTests.forEach(function (testCase) {
            test(() => { assert_equals(window.CSS.supports("font-variation-settings", testCase.value), testCase.isValid, testCase.message); }, "@supports: " + testCase.message);
        });

    </script>
</body>
</html>