image-loading-lazy-base-url.html (2118B)
1 <!DOCTYPE html> 2 <head> 3 <title>Deferred images with loading='lazy' use the original 4 base URL specified at parse-time</title> 5 <link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="../resources/common.js"></script> 9 <base href='/html/semantics/embedded-content/the-img-element/resources/'> 10 </head> 11 12 <script> 13 const below_viewport_img = new ElementLoadPromise("below-viewport"); 14 15 let has_window_loaded = false; 16 17 async_test(t => { 18 // At this point, the below-viewport image's request has been set-up, and 19 // its URL is the URL that was parsed relative to the document's base URL 20 // at this time. Any changes to the document's base URL from this point 21 // forward should not impact the image when we scroll it in-view. This is 22 // because the next step in the #updating-the-img-data algorithm is to to 23 // fetch the request that has already been set up. Now we'll change the 24 // document's base URL, and scroll the image in-view. 25 window.addEventListener("load", t.step_func(() => { 26 const base = document.querySelector('base'); 27 base.href = '/invalid-url-where-no-subresources-exist/'; 28 has_window_loaded = true; 29 below_viewport_img.element().scrollIntoView(); 30 })); 31 32 below_viewport_img.promise.then(t.step_func_done(() => { 33 assert_true(has_window_loaded, 34 "Below-viewport loading=lazy images do not block the " + 35 "window load event"); 36 })); 37 38 below_viewport_img.promise.catch( 39 t.unreached_func("The image request should not load relative to the " + 40 "current (incorrect) base URL.") 41 ); 42 }, "When a loading=lazy image is loaded, it loads relative to the " + 43 "document's base URL computed at parse-time."); 44 </script> 45 46 <body> 47 <div style="height:1000vh"></div> 48 <img id="below-viewport" src="image.png?base-url" loading="lazy" 49 onload="below_viewport_img.resolve()" 50 onerror="below_viewport_img.reject()"> 51 </body>