summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-variables/variable-substitution-background-properties.html
blob: 88108866209531d6a0eab00c1b86fd4e78f39254 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
    <title>test background property variable substitution</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/#variables-in-shorthands">

    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <style>
        .testArea {
            width: 16px;
            height: 16px;
            display: inline-block;
            background-image: url("../../../../images/green.png");
        }
    </style>
</head>
<body>
    <div id="log"></div>
    <div class="testArea" id="background-attachment" style="--foo: fixed; background-attachment: var(--foo);"></div>
    <div class="testArea" id="background-clip" style="--foo: padding-box; background-clip: var(--foo);"></div>
    <div class="testArea" id="background-color" style="background-image: none; --foo: rgb(0, 128, 0); background-color: var(--foo);"></div>
    <div class="testArea" id="background-origin" style="--foo: content-box; background-origin: var(--foo);"></div>
    <div class="testArea" id="background-position" style="--foo: 0% 50%; background-position: var(--foo);"></div>
    <div class="testArea" id="background-repeat" style="--foo: repeat-x; background-repeat: var(--foo);"></div>
    <div class="testArea" id="background-size" style="--foo: cover; background-size: var(--foo);"></div>
    <div class="testArea" id="background-image-url" style="--foo: url('../../../../images/green-16x16.png'); background-image: var(--foo);"></div>
    <div class="testArea" id="background-image-linear-gradient" style="--location: bottom; background-image: linear-gradient(to var(--location), rgb(30,87,0) 0%,rgb(125,232,185) 100%);"></div>
    <div class="testArea" id="background-image-radial-gradient" style="--shape: ellipse; --location: farthest-corner; background-image: radial-gradient(var(--shape) var(--location) at 25px 25px, black 10%, green 90%);"></div>
    <script type="text/javascript">
        "use strict";

        let templates = [
            {
                testName:"background-attachment",
                propertyName:"background-attachment",
                expectedValue:"fixed",
            },
            {
                testName:"background-clip",
                propertyName:"background-clip",
                expectedValue:"padding-box",
            },
            {
                testName:"background-color",
                propertyName:"background-color",
                expectedValue:"rgb(0, 128, 0)",
            },
            {
                testName:"background-origin",
                propertyName:"background-origin",
                expectedValue:"content-box",
            },
            {
                testName:"background-position",
                propertyName:"background-position",
                expectedValue:"0% 50%",
            },
            {
                testName:"background-repeat",
                propertyName:"background-repeat",
                expectedValue:"repeat-x",
            },
            {
                testName:"background-size",
                propertyName:"background-size",
                expectedValue:"cover",
            },
            {
                testName:"background-image-url",
                propertyName:"background-image",
                expectedValue:"url(\"../../../../images/green-16x16.png\")",
            },
            {
                testName:"background-image-linear-gradient",
                propertyName:"background-image",
                expectedValue:"linear-gradient(rgb(30, 87, 0) 0%, rgb(125, 232, 185) 100%)",
            },
            {
                testName:"background-image-radial-gradient",
                propertyName:"background-image",
                expectedValue:"radial-gradient(at 25px 25px, rgb(0, 0, 0) 10%, rgb(0, 128, 0) 90%)",
            },
        ];

        templates.forEach(function (template) {
            test( function () {
                let target = document.getElementById(template.testName);
                let computedStyle = window.getComputedStyle(target);
                let value = computedStyle.getPropertyValue(template.propertyName);

                if (template.testName != "background-image-url")
                {
                    assert_equals(value, template.expectedValue, "Expected Value should match actual value");
                }
                else
                {
                    assert_regexp_match(value, /green-16x16/, "Actual value should contain expected substring");
                }
            }, template.testName);
        });
    </script>
</body>
</html>