blob: fb48ac7602a5a95fdd86dcd43c19f9141fab84a2 (
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
|
<!DOCTYPE html>
<html class=reftest-wait>
<link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#invoke-a-layout-callback">
<link rel="match" href="fallback-layout-fallback-ref.html">
<meta name="assert" content="This test checks that a layout() class performing layout on an invalid child will fallback to block layout." />
<style>
.test {
background: red;
border: solid 2px;
width: 100px;
}
.test > div {
height: 100px;
}
@supports (display: layout(bad-child-layout)) {
.test {
display: layout(bad-child-layout);
background: green;
}
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>
<div class="test">
<div></div>
</div>
<script id="code" type="text/worklet">
registerLayout('bad-child-layout', class {
static get inputProperties() { return ['--fail']; }
async intrinsicSizes() {}
async layout(children, _, __, styleMap) {
if (styleMap.get('--fail').toString() !== 'true') {
this.child = children[0];
}
// Try to perform layout on the child. If its invalid (we skipped the if
// statement above) we should fallback to block layout.
const fragment = await this.child.layoutNextFragment({});
return {autoBlockSize: 0, childFragments: [fragment]};
}
});
</script>
<script>
function raf() {
return new Promise((resolve) => {
requestAnimationFrame(() => {
resolve();
});
});
}
(async function() {
if (typeof CSS.layoutWorklet === 'undefined') {
takeScreenshot();
return;
}
await importWorklet(CSS.layoutWorklet, document.getElementById('code').textContent);
// Ensure that all instances have a child to perform an invalid layout upon.
const test = document.getElementsByClassName('test')[0];
for (let i = 0; i < 100; i++) {
test.innerHTML = '<div><div>';
await raf();
}
// The next layout should mean that we will fallback to block.
test.innerHTML = '<div></div>';
test.style.setProperty('--fail', 'true');
// Finish up the test.
await raf();
await raf();
takeScreenshot();
})();
</script>
</html>
|