File: font-variation-settings-parsing.html

package info (click to toggle)
firefox-esr 68.10.0esr-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,143,932 kB
  • sloc: cpp: 5,227,879; javascript: 4,315,531; ansic: 2,467,042; python: 794,975; java: 349,993; asm: 232,034; xml: 228,320; sh: 82,008; lisp: 41,202; makefile: 22,347; perl: 15,555; objc: 5,277; cs: 4,725; yacc: 1,778; ada: 1,681; pascal: 1,673; lex: 1,417; exp: 527; php: 436; ruby: 225; awk: 162; sed: 53; csh: 44
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>