invalid-child.https.html (2106B)
1 <!DOCTYPE html> 2 <html class=reftest-wait> 3 <link rel="help" href="https://drafts.css-houdini.org/css-layout-api/#invoke-a-layout-callback"> 4 <link rel="match" href="fallback-layout-fallback-ref.html"> 5 <meta name="assert" content="This test checks that a layout() class performing layout on an invalid child will fallback to block layout." /> 6 <style> 7 .test { 8 background: red; 9 border: solid 2px; 10 width: 100px; 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() {} 36 async layout(children, _, __, styleMap) { 37 if (styleMap.get('--fail').toString() !== 'true') { 38 this.child = children[0]; 39 } 40 41 // Try to perform layout on the child. If its invalid (we skipped the if 42 // statement above) we should fallback to block layout. 43 const fragment = await this.child.layoutNextFragment({}); 44 45 return {autoBlockSize: 0, childFragments: [fragment]}; 46 } 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 layout 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>