summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-sizing/contain-intrinsic-size/auto-011.html
blob: cb82eedf26cffa2e66df71f6379d7369af71884b (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<meta charset="utf-8">
<title>Last remembered size</title>
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#last-remembered">
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#intrinsic-size-override">
<link rel="help" href="https://drafts.csswg.org/css-contain-2/#content-visibility">
<link rel="help" href="https://drafts.csswg.org/css-contain-3/#containment-inline-size">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7807">
<meta name="assert" content="Tests that the last remembered size can be updated when the element has size containment but doesn't skip its contents." />

<style>
#target {
  width: max-content;
  height: max-content;
  border: 1px solid;
}
#target::before {
  content: "";
  display: block;
}
.content-100-50::before {
  width: 100px;
  height: 50px;
}
.content-skip {
  content-visibility: hidden;
}
.contain-size {
  contain: size;
}
.contain-inline-size {
  contain: inline-size;
}
.ciw-auto-2 {
  contain-intrinsic-width: auto 2px;
}
.ciw-auto-20 {
  contain-intrinsic-width: auto 20px;
}
.cih-auto-1 {
  contain-intrinsic-height: auto 1px;
}
.cih-auto-10 {
  contain-intrinsic-height: auto 10px;
}
</style>

<div id="log"></div>

<div id="target"></div>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const target = document.getElementById("target");

function checkSize(expectedWidth, expectedHeight, msg) {
  assert_equals(target.clientWidth, expectedWidth, msg + " - clientWidth");
  assert_equals(target.clientHeight, expectedHeight, msg + " - clientHeight");
}

function nextRendering() {
  return new Promise(resolve => {
    requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
  });
}

promise_test(async function() {
  target.className = "content-100-50";
  checkSize(100, 50, "Sizing normally");

  await nextRendering();
  target.className = "content-100-50 ciw-auto-20 cih-auto-10 contain-size";
  checkSize(20, 10, "Size containment");

  await nextRendering();
  target.className = "content-skip ciw-auto-2 cih-auto-1";
  checkSize(20, 10, "Using last remembered size");
}, "contain:size does not prevent recording last remembered size");

promise_test(async function() {
  target.className = "content-100-50";
  checkSize(100, 50, "Sizing normally");

  await nextRendering();
  target.className = "content-100-50 ciw-auto-20 cih-auto-10 contain-inline-size";
  checkSize(20, 50, "Size containment for inline axis");

  await nextRendering();
  target.className = "content-skip ciw-auto-2 cih-auto-1";
  checkSize(20, 50, "Using last remembered block size");
}, "contain:inline-size does not prevent recording last remembered inline size");
</script>