invalid-child.https.html (2120B)
1 <!DOCTYPE html> 2 <html class=reftest-wait> 3 <link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#invoke-an-intrinsic-sizes-callback"> 4 <link rel="match" href="fallback-ref.html"> 5 <meta name="assert" content="This test checks that a layout() class performing intrinsicSizes on an invalid child will fallback to block layout." /> 6 <style> 7 .test { 8 background: red; 9 border: solid 2px; 10 width: min-content; 11 } 12 13 .test > div { 14 height: 100px; 15 } 16 17 @supports (display: layout(bad-child-layout)) { 18 .test { 19 display: layout(bad-child-layout); 20 background: green; 21 } 22 } 23 </style> 24 <script src="/common/reftest-wait.js"></script> 25 <script src="/common/worklet-reftest.js"></script> 26 27 <div class="test"> 28 <div></div> 29 </div> 30 31 <script id="code" type="text/worklet"> 32 registerLayout('bad-child-layout', class { 33 static get inputProperties() { return ['--fail']; } 34 35 async intrinsicSizes(children, _, styleMap) { 36 if (styleMap.get('--fail').toString() !== 'true') { 37 this.child = children[0]; 38 } 39 40 // Try to perform layout on the child. If its invalid (we skipped the if 41 // statement above) we should fallback to block layout. 42 const childIntrinsicSize = await this.child.intrinsicSizes(); 43 44 return { maxContentSize: 100, minContentSize: 100 }; 45 } 46 async layout() {} 47 }); 48 </script> 49 50 <script> 51 function raf() { 52 return new Promise((resolve) => { 53 requestAnimationFrame(() => { 54 resolve(); 55 }); 56 }); 57 } 58 59 (async function() { 60 if (typeof CSS.layoutWorklet === 'undefined') { 61 takeScreenshot(); 62 return; 63 } 64 65 await importWorklet(CSS.layoutWorklet, document.getElementById('code').textContent); 66 67 // Ensure that all instances have a child to perform an invalid intrinsic size upon. 68 const test = document.getElementsByClassName('test')[0]; 69 for (let i = 0; i < 100; i++) { 70 test.innerHTML = '<div><div>'; 71 await raf(); 72 } 73 74 // The next layout should mean that we will fallback to block. 75 test.innerHTML = '<div></div>'; 76 test.style.setProperty('--fail', 'true'); 77 78 // Finish up the test. 79 await raf(); 80 await raf(); 81 takeScreenshot(); 82 })(); 83 </script> 84 </html>