summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-variables/variable-reference-cssom.html
blob: 00354beaf83f9121660191d6e72c512530bb8612 (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
<!DOCTYPE html>
<html>
<head>
    <title>CSS variable references - via CSSOM</title>

    <meta rel="author" title="Kevin Babbitt">
    <meta rel="author" title="Greg Whitworth">
    <link rel="author" title="Microsoft Corporation" href="http://microsoft.com" />
    <!-- This is not directly specified in the spec but should work -->
    <link rel="help" href="http://www.w3.org/TR/css-variables-1/#defining-variables">

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

<div id="target1"></div>
<div id="target2" style="background-color: red;"></div>

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

    // This test verifies that variable references are usable when set via CSSOM calls.

    function TestCssom() {
        var target = document.getElementById("target1");

        target.style.setProperty("background-color", "var(--prop)");
        assert_equals(target.style.backgroundColor, "var(--prop)", "background-color property value after calling setProperty");
        assert_equals(target.style.getPropertyValue("background-color"), "var(--prop)", "getPropertyValue('background-color') after calling setProperty");

        target.style.removeProperty("background-color");
        assert_equals(target.style.backgroundColor, "", "background-color property value after calling removeProperty");
        assert_equals(target.style.getPropertyValue("background-color"), "", "getPropertyValue('background-color') after calling removeProperty");
    }

    function TestCssomOverridingMarkup() {
        var target = document.getElementById("target1");

        target.style.setProperty("background-color", "var(--prop)");
        assert_equals(target.style.backgroundColor, "var(--prop)", "background-color property value after calling setProperty");
        assert_equals(target.style.getPropertyValue("background-color"), "var(--prop)", "getPropertyValue('background-color') after calling setProperty");

        target.style.removeProperty("background-color");
        assert_equals(target.style.backgroundColor, "", "background-color property value after calling removeProperty");
        assert_equals(target.style.getPropertyValue("background-color"), "", "getPropertyValue('background-color') after calling removeProperty");
    }

    test(TestCssom, "Verify correct results using CSSOM");
    test(TestCssomOverridingMarkup, "Verify correct results with CSSOM overriding markup-set values");
</script>

</body>
</html>