tor-browser

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

image-decode-with-quick-attach.html (3258B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <meta name="timeout" content="long">
      4 <title>HTMLImageElement.prototype.decode(), attach to DOM before promise resolves.</title>
      5 <link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org">
      6 <link rel=help href="https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 
     10 <body>
     11  <picture id="empty-picture-1"></picture>
     12  <picture id="empty-picture-2"></picture>
     13  <picture id="empty-picture-3"></picture>
     14  <picture id="picture-with-source-1">
     15    <source srcset="/images/blue.png"></source>
     16  </picture>
     17  <picture id="picture-with-source-2">
     18    <source srcset="/images/blue.png"></source>
     19  </picture>
     20  <picture id="picture-with-source-3">
     21    <source srcset="/images/blue.png"></source>
     22  </picture>
     23 </body>
     24 
     25 <script>
     26 "use strict";
     27 
     28 let png = "/images/green.png?image-decode-with-quick-attach-" + Math.random();
     29 
     30 function run_test(t, {
     31  image = png,
     32  prop = "src",
     33  container = document.body,
     34  expectReject = false
     35 } = {}) {
     36  const img = new Image();
     37  img[prop] = image;
     38  const promise = img.decode().then(function (arg) {
     39    assert_equals(arg, undefined);
     40  });
     41  // Intentionally don't wait for the promise to settle before attaching the image.
     42  container.appendChild(img);
     43  return expectReject ?
     44    promise_rejects_dom(t, "EncodingError", promise) :
     45    promise;
     46 }
     47 
     48 promise_test(t => run_test(t), document.title + ": src not cached");
     49 promise_test(t => run_test(t), document.title + ": src cached");
     50 promise_test(t => run_test(t, {prop: "srcset"}), document.title + ": srcset");
     51 promise_test(t => run_test(t, {
     52  image: png + "-picture",
     53  container: document.getElementById("empty-picture-1"),
     54  expectReject: true,
     55 }), document.title + ": src in empty picture not cached");
     56 promise_test(t => run_test(t, {
     57  image: png + "-picture",
     58  container: document.getElementById("empty-picture-2"),
     59  // NOTE(emilio): This is inconsistent between the cached and un-cached case
     60  // below, but actually correct per spec, because in the sync case the current
     61  // request doesn't mutate after the decode() call.
     62  // This is expected to change in https://github.com/whatwg/html/issues/10531
     63  expectReject: false,
     64 }), document.title + ": src in empty picture cached");
     65 promise_test(t => run_test(t, {
     66  image: png + "-picture-srcset",
     67  prop: "srcset",
     68  container: document.getElementById("empty-picture-3"),
     69  expectReject: true,
     70 }), document.title + ": srcset in empty picture");
     71 promise_test(t => run_test(t, {
     72  image: png + "-picture-with-source",
     73  container: document.getElementById("picture-with-source-1"),
     74  expectReject: true,
     75 }), document.title + ": src in picture with source not cached");
     76 promise_test(t => run_test(t, {
     77  image: png + "-picture-with-source",
     78  container: document.getElementById("picture-with-source-2"),
     79  expectReject: true,
     80 }), document.title + ": src in picture with source cached");
     81 promise_test(t => run_test(t, {
     82  image: png + "-picture-with-source-srcset",
     83  prop: "srcset",
     84  container: document.getElementById("picture-with-source-3"),
     85  expectReject: true,
     86 }), document.title + ": srcset in picture with source");
     87 </script>