tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

image-loading-lazy-crossorigin-change.sub.html (1942B)


      1 <!DOCTYPE html>
      2 <head>
      3  <title>Deferred images with loading='lazy' use the latest crossorigin attribute</title>
      4  <link rel="author" title="Raj T" href="mailto:rajendrant@chromium.org">
      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 </head>
     10 
     11 <script>
     12  const img = new ElementLoadPromise("cross-origin");
     13 
     14  async_test(function(t) {
     15    window.addEventListener("load", t.step_func(() => {
     16      // At this point the image's #updating-the-image-data algorithm has been
     17      // invoked, and the image request has been deferred. The deferred
     18      // cross-origin image request was created with the `no-cors` request mode,
     19      // which would succeed to load the cross-origin image.
     20      // While the request is deferred, we'll set the `crossorigin` attribute to a
     21      // value that would cause the image request to fail. Since `crossorigin`
     22      // mutations trigger another #updating-the-image-data invocation (replacing
     23      // the first one), when we scroll the image into view, the image should be
     24      // fetched with the latest `crossorigin` attribute value, and fail to load.
     25      img.element().crossOrigin = 'anonymous';
     26      img.element().scrollIntoView();
     27    }));
     28 
     29    img.promise
     30      .then(t.unreached_func("The image should not load."))
     31      .catch(t.step_func(() => { img.element().onload = t.step_func_done(); img.element().src = 'resources/image.png'; }));
     32  }, "Test that when deferred image is loaded, it uses the latest crossorigin attribute.");
     33 </script>
     34 
     35 <body>
     36  <div style="height:1000vh;"></div>
     37  <img id="cross-origin" loading="lazy"
     38       src='http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/embedded-content/the-img-element/resources/image.png'
     39       onload="img.resolve();" onerror="img.reject();">
     40 </body>