summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/support/shorthand-testcommon.js
blob: ab1f3794c8dac2f1e067209fd766ec18858a5f45 (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
'use strict';

function test_shorthand_value(property, value, longhands) {
    const stringifiedValue = JSON.stringify(value);

    for (let longhand of Object.keys(longhands).sort()) {
        test(function(){
            var div = document.getElementById('target') || document.createElement('div');
            div.style[property] = "";
            try {
                div.style[property] = value;

                const readValue = div.style[longhand];
                assert_equals(readValue, longhands[longhand], longhand + " should be canonical");

                div.style[longhand] = "";
                div.style[longhand] = readValue;
                assert_equals(div.style[longhand], readValue, "serialization should round-trip");
            } finally {
                div.style[property] = "";
            }
        }, "e.style['" + property + "'] = " + stringifiedValue + " should set " + longhand);
    }

    test(function(){
        var div = document.getElementById('target') || document.createElement('div');
        div.style[property] = "";
        try {
            const expectedLength = div.style.length;
            div.style[property] = value;
            assert_true(CSS.supports(property, value));
            for (let longhand of Object.keys(longhands).sort()) {
                div.style[longhand] = "";
            }
            assert_equals(div.style.length, expectedLength);
        } finally {
            div.style[property] = "";
        }
    }, "e.style['" + property + "'] = " + stringifiedValue + " should not set unrelated longhands");
}