summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-contain/container-queries/container-units-content-box.html
blob: 89a76e868ce5750f9739c4713da65701c9498277 (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
<!doctype html>
<title>Container Relative Units: evaluate against the content box</title>
<link rel="help" href="https://drafts.csswg.org/css-contain-3/#container-lengths">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style>
.size {
  container-type: size;
  width:100px;
  height:50px;
  border: 10px solid green;
  padding: 10px;
}
.border-box {
  box-sizing: border-box;
}
</style>
<div id=ref></div>
<div class="size">
  <div id=child></div>
</div>
<div class="size border-box">
  <div id=child2></div>
</div>
<script>
  setup(() => assert_implements_container_queries());

  function assert_unit_equals(element, actual, expected) {
    try {
      element.style.padding = actual;
      ref.style.padding = expected;
      assert_equals(getComputedStyle(element).paddingLeft,
                    getComputedStyle(ref).paddingLeft);
    } finally {
      element.style = '';
      ref.style = '';
    }
  }

  test(function() {
    assert_unit_equals(child, '10cqi', '10px');
    assert_unit_equals(child, '10cqw', '10px');
    assert_unit_equals(child, '10cqb', '5px');
    assert_unit_equals(child, '10cqh', '5px');
    assert_unit_equals(child, '10cqmin', '5px');
    assert_unit_equals(child, '10cqmax', '10px');
  }, 'Container units are relative to the content box of the container');

  test(function() {
    assert_unit_equals(child2, '10cqi', '6px');
    assert_unit_equals(child2, '10cqw', '6px');
    assert_unit_equals(child2, '10cqb', '1px');
    assert_unit_equals(child2, '10cqh', '1px');
    assert_unit_equals(child2, '10cqmin', '1px');
    assert_unit_equals(child2, '10cqmax', '6px');
  }, 'Container units are relative to the content box of the container (box-sizing: border-box)');
</script>