image-loading-lazy-in-viewport-dynamic.html (1478B)
1 <!DOCTYPE html> 2 <head> 3 <title>In viewport images with loading='lazy' and changed to loading='eager' 4 do not block the window load event</title> 5 <link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com"> 6 <link rel="help" href="https://github.com/scott-little/lazyload"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 </head> 10 11 <script> 12 const t = async_test("Test that in viewport images with loading='lazy' and " + 13 "changed to loading='eager' do not block the window " + 14 "load event."); 15 16 let has_in_viewport_loaded = false; 17 let has_window_loaded = false; 18 19 const in_viewport_img_onload = t.step_func_done(function() { 20 assert_false(has_in_viewport_loaded, 21 "The in_viewport element should load only once."); 22 assert_true(has_window_loaded, 23 "The window load event should fire before in_viewport image loads."); 24 has_in_viewport_loaded = true; 25 }); 26 27 window.addEventListener("load", t.step_func(function() { 28 assert_false(has_window_loaded, 29 "The window load event should only fire once."); 30 has_window_loaded = true; 31 })); 32 </script> 33 34 <body> 35 <img id="in_viewport" src="resources/image.png?in-viewport-dynamic&pipe=trickle(d2)" 36 loading="lazy" onload="in_viewport_img_onload();"> 37 <script> 38 document.getElementById("in_viewport").loading = 'eager'; 39 </script> 40 </body>