summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-typed-om/stylevalue-normalization/normalize-tokens.tentative.html
blob: c83e093e62280b0ea4276c2db38273b78e1e5a70 (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
<!doctype html>
<meta charset="utf-8">
<title>Normalization of raw CSS tokens tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#normalize-tokens">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<body>
<script>
'use strict';

function assert_string_normalizes_to(test, property, str, expected) {
  // From string
  assert_style_value_equals(CSSStyleValue.parse(property, str), expected);
  // From CSSOM
  assert_style_value_equals(
    createInlineStyleMap(test, property + ':' + str).get(property),
    expected
  );
}

const gTestCases = [
  {
    value: 'var(--A)',
    expectedResult: [
      new CSSVariableReferenceValue('--A'),
    ]
  },
  {
    value: 'var(--A, 1em)',
    expectedResult: [
      new CSSVariableReferenceValue('--A', new CSSUnparsedValue([' 1em'])),
    ]
  },
  {
    value: 'var(--A, var(--B))',
    expectedResult: [
      new CSSVariableReferenceValue('--A', new CSSUnparsedValue([' ', new CSSVariableReferenceValue('--B')])),
    ]
  },
  {
    value: 'calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))',
    expectedResult: [
      'calc(42px + ',
      new CSSVariableReferenceValue('--foo', new CSSUnparsedValue([' 15em'])),
      ' + ',
      new CSSVariableReferenceValue('--bar', new CSSUnparsedValue([' ', new CSSVariableReferenceValue('--far'), ' + 15px'])),
      ')',
    ]
  },
];

for (const {value, expectedResult} of gTestCases) {
  test(t => {
    assert_string_normalizes_to(t, 'color', value, new CSSUnparsedValue(expectedResult));
  }, 'Normalizing "' + value + '" on a CSS property returns correct CSSUnparsedValue');

  test(t => {
    assert_string_normalizes_to(t, 'margin', value, new CSSUnparsedValue(expectedResult));
  }, 'Normalizing "' + value + '" on a shorthand returns correct CSSUnparsedValue');

  test(t => {
    assert_string_normalizes_to(t, 'transition-duration', value, new CSSUnparsedValue(expectedResult));
  }, 'Normalizing "' + value + '" on a list-valued property returns correct CSSUnparsedValue');

  test(t => {
    assert_string_normalizes_to(t, '--X', value, new CSSUnparsedValue(expectedResult));
  }, 'Normalizing "' + value + '" on a custom property returns correct CSSUnparsedValue');
}

</script>