not-rendered-below-viewport-image-loading-lazy.html (2631B)
1 <!DOCTYPE html> 2 <head> 3 <title>Below-viewport loading=lazy not-rendered images should never load, 4 even when scrolled into view</title> 5 <link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com"> 6 <link rel="author" title="Dom Farolino" href="mailto:dom@chromium.org"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="../resources/common.js"></script> 10 </head> 11 12 <body> 13 <!-- These images must not attempt to load when scrolled into the 14 viewport --> 15 <img id="display_none" style="display:none;" src="resources/image.png?not-rendered-2" loading="lazy" 16 onload="display_none_img.resolve();" onerror="display_none_img.reject();"> 17 <img id="attribute_hidden" hidden src="resources/image.png?not-rendered-3" loading="lazy" 18 onload="attribute_hidden_img.resolve();" onerror="attribute_hidden_img.reject();"> 19 <img id="js_display_none" src="resources/image.png?not-rendered-4" loading="lazy" 20 onload="js_display_none_img.resolve();" onerror="js_display_none_img.reject();"> 21 <script> 22 document.getElementById("js_display_none").style = 'display:none;'; 23 </script> 24 25 <!-- Later in the test we'll scroll to this div, instead of the above images, 26 since due to them not being rendered, they cannot be scrolled to --> 27 <div id="rendered_div"></div> 28 </body> 29 30 <script> 31 const display_none_img = new ElementLoadPromise("display_none"); 32 const attribute_hidden_img = new ElementLoadPromise("attribute_hidden"); 33 const js_display_none_img = new ElementLoadPromise("js_display_none"); 34 const rendered_div_element = document.querySelector('#rendered_div'); 35 36 async_test(t => { 37 window.addEventListener("load", t.step_func(() => { 38 rendered_div.scrollIntoView(); 39 })); 40 41 const unreached_not_rendered_img_func = 42 t.unreached_func("The not-rendered below-viewport loading=lazy images " + 43 "should not attempt to load."); 44 45 display_none_img.promise 46 .then(unreached_not_rendered_img_func) 47 .catch(unreached_not_rendered_img_func); 48 49 attribute_hidden_img.promise 50 .then(unreached_not_rendered_img_func) 51 .catch(unreached_not_rendered_img_func); 52 53 js_display_none_img.promise 54 .then(unreached_not_rendered_img_func) 55 .catch(unreached_not_rendered_img_func); 56 57 // If none of the above images load after being scrolled to within the below 58 // timeout, the test passes. 59 t.step_timeout(t.done, 2000); 60 }, "Below-viewport loading=lazy not-rendered images should never load, " + 61 "even when scrolled into view"); 62 </script>