summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-variables/variable-reference.html
blob: fb3ae56ebcb318c0c9de1701da306328f00da155 (plain)
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
<!DOCTYPE html>
<html>
<head>
    <title>Parse, store, and serialize CSS variable references</title>

    <meta rel="author" title="Kevin Babbitt">
    <meta rel="author" title="Greg Whitworth">
    <link rel="author" title="Microsoft Corporation" href="http://microsoft.com" />
    <link rel="help" href="http://www.w3.org/TR/css-variables-1/#using-variables">

    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>

    <!--
        https://drafts.csswg.org/css-syntax/#error-handling
        If the stylesheet ends while any rule, declaration, function, string, etc. are still open, everything is automatically closed.
    -->
    <style id="variable-reference-left-open">
        div
        {
            width: var(--prop</style>
</head>
<body>

<script type="text/javascript">
    "use strict";

    var testcases = [
        { cssText: "width: var(--prop);",                   expectedPropertyValue: "var(--prop)" },
        { cssText: "width: var(--prop) !important;",        expectedPropertyValue: "var(--prop)" },
        { cssText: "width: var(--prop, );",                 expectedPropertyValue: "var(--prop, )" },
        { cssText: "width: var(--prop, 20px);",             expectedPropertyValue: "var(--prop, 20px)" },
        { cssText: "width: var(--prop, blue);",             expectedPropertyValue: "var(--prop, blue)" },
        { cssText: "width: var(--prop1, var(--prop2));",    expectedPropertyValue: "var(--prop1, var(--prop2))" },
        { cssText: "width: var(--prop1, var(--prop2, var(--prop3, auto)));", expectedPropertyValue: "var(--prop1, var(--prop2, var(--prop3, auto)))" },
        { cssText: "width: var(--prop1) var(--prop2)",      expectedPropertyValue: "var(--prop1) var(--prop2)" },
        { cssText: "width: var(--prop,);",                  expectedPropertyValue: "var(--prop,)" },

        { cssText: "width: var();",                         expectedPropertyValue: "" },
        { cssText: "width: var(prop);",                     expectedPropertyValue: "" },
        { cssText: "width: var(-prop);",                    expectedPropertyValue: "" },
        { cssText: "width: var(--prop 20px);",              expectedPropertyValue: "" },
        { cssText: "width: var(--prop, var(prop));",        expectedPropertyValue: "" },
        { cssText: "width: var(--prop, var(-prop));",       expectedPropertyValue: "" },
        { cssText: "width: var(20px);",                     expectedPropertyValue: "" },
        { cssText: "width: var(var(--prop));",              expectedPropertyValue: "" },
    ];

    testcases.forEach(function (testcase) {
        test( function () {
            var div = document.createElement("div");
            document.body.appendChild(div);
            div.style.cssText = testcase.cssText;
            var actualPropertyValue = div.style.getPropertyValue("width").trim();
            assert_equals(actualPropertyValue, testcase.expectedPropertyValue);
            document.body.removeChild(div);
        }, testcase.cssText);
    });

    test( function() {
            var actualPropertyValue = document.getElementById("variable-reference-left-open").sheet.cssRules[0].style.getPropertyValue("width").trim();
            assert_equals(actualPropertyValue, "var(--prop");
        }, "Variable reference left open at end of stylesheet");
</script>

</body>
</html>