buffer-before-onload.html (1656B)
1 <!DOCTYPE html> 2 <html> 3 <meta charset=utf-8 /> 4 <title>Element Timing: buffer elements before onload</title> 5 <script src=/resources/testharness.js></script> 6 <script src=/resources/testharnessreport.js></script> 7 <script src="resources/element-timing-helpers.js"></script> 8 <body> 9 <img src=resources/slow-image.py?name=square20.png&sleep=500> 10 <script> 11 /* 12 In this test, a slow image is added to the frame to delay onload. The entry 13 is available from the observer with the buffered flag set to true. 14 */ 15 async_test(function(t) { 16 assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented"); 17 beforeRender = performance.now(); 18 const img = document.createElement('img'); 19 img.src = 'resources/square20.jpg'; 20 img.setAttribute('elementtiming', 'my_image'); 21 img.setAttribute('id', 'my_id'); 22 document.body.appendChild(img); 23 24 // this PerformanceObserver should be notified about the previously 25 // buffered element entry 26 new PerformanceObserver(t.step_func((entryList, observer) => { 27 assert_equals(entryList.getEntries().length, 1); 28 entryList.getEntries().forEach(entry => { 29 assert_equals(entry.entryType, "element"); 30 const pathname = window.location.origin + '/element-timing/resources/square20.jpg'; 31 checkElement(entry, pathname, 'my_image', 'my_id', beforeRender, img); 32 checkNaturalSize(entry, 20, 20); 33 observer.disconnect(); 34 t.done(); 35 }); 36 })).observe({ 37 type: "element", 38 buffered: true 39 }); 40 }, "Element Timing: image loads before onload available from buffered flag."); 41 42 </script> 43 </body> 44 </html>