summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom/serialize-custom-props.html
blob: cfe96ff0aacb983e66b5ccee305cc5fe84d10d72 (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
<link rel=author title="Tab Atkins-Bittner" href="https://www.xanthir.com/contact/">
<link rel="help" href="https://drafts.csswg.org/css-values/#calc-range">
<body><!doctype html>
<title>Serializing Integers Never Uses Scinot</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<link rel=author title="Tab Atkins-Bittner" href="https://www.xanthir.com/contact/">
<link rel="help" href="https://drafts.csswg.org/cssom/#serialize-a-css-component-value">
<!--
  Per CSSOM, integers always serialize all their digits out.
  They never serialize to scinot, regardless of size,
  because that makes them stop being an integer.
  This applies to custom properties as well.
-->
<body>

<script>

try {
CSS.registerProperty({
    name: "--two",
    value: "<integer>",
    inherits: true,
    initial: -1
});
}catch(e){}

testIntLength(4);
testIntLength(6);
testIntLength(8);
testIntLength(12);
// JS starts serializing with scinot at 22 digits...
testIntLength(25);

function testIntLength(len) {
    let el = document.body;
    const val = "1".repeat(len);
    test(()=>{
        el.removeAttribute("style");
        const nullVal = getComputedStyle(el).zIndex;
        el.style.zIndex=val;
        assert_not_equals(getComputedStyle(el).zIndex, nullVal)
    }, `z-index can take a ${len}-digit integer`);

    test(()=>{
        el.removeAttribute("style");
        el.style.setProperty("--one", val);
        assert_equals(getComputedStyle(el).getPropertyValue("--one"), val);
    }, `An unregistered custom prop can take a ${len}-digit integer`);

    test(()=>{
        el.removeAttribute("style");
        el.style.setProperty("--two", val);
        assert_equals(getComputedStyle(el).getPropertyValue("--two"), val);
    }, `An <integer> custom prop can take a ${len}-digit integer`);

    test(()=>{
        el.removeAttribute("style");
        el.style.zIndex = val;
        const standardVal = getComputedStyle(el).zIndex;
        el.removeAttribute("style");
        el.style.setProperty("--three", val);
        el.style.zIndex = "var(--three)";
        assert_equals(getComputedStyle(el).zIndex, standardVal);
    }, `z-index can take a custom property set to a ${len}-digit integer`);
}

</script>