invalid-fragment.https.html (2041B)
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 returning an invalid fragment 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-request)) { 18 .test { 19 display: layout(bad-request); 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-request', 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.fragment = await children[0].layoutNextFragment({}); 39 } 40 41 // Return, if the fragment is invalid (we skipped the if statement above) 42 // we should fallback to block layout. 43 return {autoBlockSize: 0, childFragments: [this.fragment]}; 44 } 45 }); 46 </script> 47 48 <script> 49 function raf() { 50 return new Promise((resolve) => { 51 requestAnimationFrame(() => { 52 resolve(); 53 }); 54 }); 55 } 56 57 (async function() { 58 if (typeof CSS.layoutWorklet === 'undefined') { 59 takeScreenshot(); 60 return; 61 } 62 63 await importWorklet(CSS.layoutWorklet, document.getElementById('code').textContent); 64 65 // Ensure that all instances have a child to perform an invalid layout upon. 66 const test = document.getElementsByClassName('test')[0]; 67 for (let i = 0; i < 100; i++) { 68 test.innerHTML = '<div><div>'; 69 await raf(); 70 } 71 72 // The next layout should mean that we will fallback to block. 73 test.innerHTML = '<div></div>'; 74 test.style.setProperty('--fail', 'true'); 75 76 // Finish up the test. 77 await raf(); 78 await raf(); 79 takeScreenshot(); 80 })(); 81 </script> 82 </html>