idlharness.html (1814B)
1 <!doctype html> 2 <title>Layout Instability IDL tests</title> 3 <meta name="timeout" content="long"> 4 <link rel="help" href="https://wicg.github.io/layout-instability/"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/WebIDLParser.js"></script> 8 <script src="/resources/idlharness.js"></script> 9 <script src="resources/util.js"></script> 10 <script> 11 'use strict'; 12 13 idl_test( 14 ['layout-instability'], 15 ['performance-timeline', 'geometry', 'dom', 'hr-time'], 16 async (idl_array, t) => { 17 idl_array.add_objects({ 18 LayoutShift: ['layoutShift'], 19 LayoutShiftAttribution: ['layoutShiftAttribution'], 20 }); 21 22 // If LayoutShift isn't supported, avoid the timeout below and just let the 23 // objects declared above be null. The tests will still fail, but we will 24 // consistently generate the same set of subtests on all platforms. 25 if (!PerformanceObserver || 26 !PerformanceObserver.supportedEntryTypes || 27 !PerformanceObserver.supportedEntryTypes.includes('layout-shift')) { 28 return; 29 } 30 31 // Make sure that the image has initially been laid out, so that the movement 32 // later is counted as a layout shift. 33 await waitForAnimationFrames(2); 34 35 self.layoutShift = await new Promise((resolve, reject) => { 36 const observer = new PerformanceObserver(entryList => { 37 resolve(entryList.getEntries()[0]); 38 }); 39 observer.observe({type: 'layout-shift', buffered: true}); 40 t.step_timeout(() => reject('Timed out waiting for LayoutShift entry'), 3000); 41 42 // Move the image, to cause layout shift. 43 image.style.marginTop = '100px'; 44 }); 45 self.layoutShiftAttribution = layoutShift.sources[0]; 46 } 47 ); 48 </script> 49 50 <img id="image" src="/images/green-100x50.png">