summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-contain/container-queries/container-units-basic.html
blob: 166a003a29b2eb1bc0c017815a36cdcb1361c2aa (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
<!doctype html>
<title>Container Relative Units: cqi, cqb, etc</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>
  .inline { container-type: inline-size; }
  .size { container-type: size; }
  .inline.outer { width: 500px; }
  .size.outer { height: 400px; }
  .inline.inner { width: 300px; }
</style>
<div id=ref></div>
<div class="inline outer">
  <div class="size outer">
    <div class="inline inner">
      <div id=child>Test</div>
    </div>
  </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, '0cqi', '0px');
    assert_unit_equals(child, '1cqi', '3px');
    assert_unit_equals(child, '10cqi', '30px');
    assert_unit_equals(child, '10cqw', '30px');
    assert_unit_equals(child, '10cqb', '40px');
    assert_unit_equals(child, '10cqh', '40px');
    assert_unit_equals(child, '10cqmin', '30px');
    assert_unit_equals(child, '10cqmax', '40px');
  }, 'Container relative units');

  test(function() {
    assert_unit_equals(child, '10cqi', '30px');
    assert_unit_equals(child, '10cqb', '40px');
    assert_unit_equals(child, 'calc(10cqi + 10cqb)', '70px');
    assert_unit_equals(child, 'max(10cqi, 10cqb)', '40px');
  }, 'Container relative units in math functions');
</script>