cross-origin-element.sub.html (1792B)
1 <!DOCTYPE HTML> 2 <meta charset=utf-8> 3 <title>Element Timing: observe cross-origin images but without renderTime</title> 4 <body> 5 <style> 6 body { 7 margin: 0; 8 } 9 </style> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <script src="resources/element-timing-helpers.js"></script> 13 <script> 14 async_test((t) => { 15 const test_start = performance.now(); 16 assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented"); 17 let img; 18 const pathname = 'http://{{domains[www]}}:{{ports[http][1]}}' 19 + '/element-timing/resources/square100.png'; 20 const observer = new PerformanceObserver( 21 t.step_func_done((entryList) => { 22 assert_equals(entryList.getEntries().length, 1); 23 const entry = entryList.getEntries()[0]; 24 checkElement(entry, pathname, 'my_image', 'the_id', test_start, img); 25 assert_greater_than_equal(entry.renderTime, entry.loadTime, 26 'The renderTime of a cross-origin image should be coarseĀ but at least as high as loadTime'); 27 checkRect(entry, [0, 100, 0, 100]); 28 checkNaturalSize(entry, 100, 100); 29 }) 30 ); 31 observer.observe({entryTypes: ['element']}); 32 // We add the image during onload to be sure that the observer is registered 33 // in time for it to observe the element timing. 34 // TODO(npm): change observer to use buffered flag. 35 window.onload = t.step_func(() => { 36 // Add a cross origin image resource. 37 img = document.createElement('img'); 38 img.src = pathname; 39 img.setAttribute('elementtiming', 'my_image'); 40 img.setAttribute('id', 'the_id'); 41 document.body.appendChild(img); 42 }); 43 }, 'Cross-origin image element is NOT observable.'); 44 </script> 45 46 </body>