image-not-fully-visible.html (1929B)
1 <!DOCTYPE HTML> 2 <meta charset=utf-8> 3 <title>Element Timing: intersectionRect when image overflows</title> 4 <body> 5 <style> 6 body { 7 margin: 200px 100px; 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 let beforeRender; 15 let img; 16 async_test(function (t) { 17 assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented"); 18 const observer = new PerformanceObserver( 19 t.step_func_done(function(entryList) { 20 assert_equals(entryList.getEntries().length, 1); 21 const entry = entryList.getEntries()[0]; 22 const pathname = window.location.origin + '/element-timing/resources/square20.png'; 23 checkElement(entry, pathname, 'not_fully_visible', '', beforeRender, img); 24 // Image will not be fully visible. It should start from the top left part 25 // of the document, excluding the margin, and then overflow. 26 checkRect(entry, 27 [100, document.documentElement.clientWidth, 200, document.documentElement.clientHeight]); 28 checkNaturalSize(entry, 20, 20); 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 window.onload = () => { 35 // Add an image setting width and height equal to viewport. 36 img = document.createElement('img'); 37 img.src = 'resources/square20.png'; 38 img.setAttribute('elementtiming', 'not_fully_visible'); 39 img.width = document.documentElement.clientWidth; 40 img.height = document.documentElement.clientHeight; 41 document.body.appendChild(img); 42 beforeRender = performance.now(); 43 }; 44 }, 'The intersectionRect of an img element overflowing is computed correctly'); 45 </script> 46 47 </body>