summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-typed-om/the-stylepropertymap/computed/computed.tentative.html
blob: a059787ca12a62a4a09161a56b20f2bd98ad379e (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
<!doctype html>
<meta charset="utf-8">
<title>Computed StylePropertyMap tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#computed-stylepropertymapreadonly-objects">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<style>#target { height: 10px; --foo: auto; }</style>
<div style="width: 50px">
  <div id="target" style="top: 5px; --bar: 5; width: 50%;"></div>
</div>
<script>
'use strict';

const target = document.getElementById('target');
const styleMap = target.computedStyleMap();

test(() => {
  const computedStyle = [...getComputedStyle(target)].sort();
  const properties = [...styleMap.keys()];

  assert_equals(properties.length, computedStyle.length);
  for (let i = 0; i < computedStyle.length; i++) {
    assert_true(properties.includes(computedStyle[i]));
    assert_not_equals(styleMap.get(computedStyle[i]), null);
    assert_not_equals(styleMap.getAll(computedStyle[i]).length, 0);
    assert_true(styleMap.has(computedStyle[i]));
  }
}, 'Computed StylePropertyMap contains every CSS property');

test(() => {
  const result = styleMap.get('height');
  assert_style_value_equals(result, CSS.px(10));
}, 'Computed StylePropertyMap contains CSS property declarations in style rules');

test(() => {
  const result = styleMap.get('--foo');
  assert_style_value_equals(result, new CSSUnparsedValue(['auto']));
}, 'Computed StylePropertyMap contains custom property declarations in style rules');

test(() => {
  const result = styleMap.get('top');
  assert_style_value_equals(result, CSS.px(5));
}, 'Computed StylePropertyMap contains CSS property declarations in inline styles');

test(() => {
  const result = styleMap.get('--bar');
  assert_style_value_equals(result, new CSSUnparsedValue(['5']));
}, 'Computed StylePropertyMap contains custom property declarations in inline rules');

test(() => {
  const computedStyle = getComputedStyle(target);
  assert_equals(computedStyle.width, '25px');

  const result = styleMap.get('width');
  assert_style_value_equals(result, CSS.percent(50));
}, 'Computed StylePropertyMap contains computed values and not resolved values');

test(t => {
  let target = createDivWithStyle(t, 'width: 10px');
  const styleMap = target.attributeStyleMap;
  assert_style_value_equals(styleMap.get('width'), CSS.px(10));

  target.style.width = '20px';
  assert_style_value_equals(styleMap.get('width'), CSS.px(20));
}, 'Computed StylePropertyMap is live');

</script>