tor-browser

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

image-decode-picture.html (4163B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <meta name="timeout" content="long">
      4 <title>HTMLImageElement.prototype.decode(), picture tests.</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 <picture>
     11 <source srcset="/images/green.png">
     12 <source srcset="/images/blue.png">
     13 <img id="testimg">
     14 </picture>
     15 
     16 <script>
     17 "use strict";
     18 
     19 promise_test(function() {
     20  var picture = document.createElement("picture");
     21  var source = document.createElement("source");
     22  var img = document.createElement("img");
     23 
     24  picture.appendChild(source);
     25  picture.appendChild(img);
     26 
     27  source.srcset = "/images/green.png";
     28 
     29  return img.decode().then(function(arg) {
     30    assert_equals(arg, undefined);
     31  });
     32 }, document.title + " Image with PNG source decodes with undefined.");
     33 
     34 promise_test(function() {
     35  var img = document.getElementById("testimg");
     36  return img.decode().then(function(arg) {
     37    assert_equals(arg, undefined);
     38  });
     39 }, document.title + " Image with multiple sources decodes with undefined.");
     40 
     41 promise_test(function() {
     42  var picture = document.createElement("picture");
     43  var source = document.createElement("source");
     44  var img = document.createElement("img");
     45 
     46  picture.appendChild(source);
     47  picture.appendChild(img);
     48 
     49  source.srcset = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIA" +
     50                  "AAD91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsy" +
     51                  "AgywAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAW" +
     52                  "SURBVAjXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC";
     53 
     54  return img.decode().then(function(arg) {
     55    assert_equals(arg, undefined);
     56  });
     57 }, document.title + " Image with PNG data URL source decodes with undefined.");
     58 
     59 promise_test(function() {
     60  var picture = document.createElement("picture");
     61  var source = document.createElement("source");
     62  var img = document.createElement("img");
     63 
     64  picture.appendChild(source);
     65  picture.appendChild(img);
     66 
     67  source.srcset = "/images/green.svg";
     68 
     69  return img.decode().then(function(arg) {
     70    assert_equals(arg, undefined);
     71  });
     72 }, document.title + " Image with SVG source decodes with undefined.");
     73 
     74 promise_test(function(t) {
     75  var picture = document.createElement("picture");
     76  var source = document.createElement("source");
     77  var img = document.createElement("img");
     78 
     79  picture.appendChild(source);
     80  picture.appendChild(img);
     81 
     82  source.srcset = "/non/existent/path.png";
     83 
     84  var promise = img.decode();
     85  return promise_rejects_dom(t, "EncodingError", promise);
     86 }, document.title + " Non-existent source fails decode.");
     87 
     88 promise_test(function(t) {
     89  var picture = document.createElement("picture");
     90  var source = document.createElement("source");
     91  var img = document.createElement("img");
     92 
     93  picture.appendChild(source);
     94  picture.appendChild(img);
     95 
     96  source.srcset = "data:image/png;base64,iVBO00PDR0BADBEEF00KGg";
     97 
     98  var promise = img.decode();
     99  return promise_rejects_dom(t, "EncodingError", promise);
    100 }, document.title + " Corrupt image in src fails decode.");
    101 
    102 promise_test(function(t) {
    103  var picture = document.createElement("picture");
    104  var source = document.createElement("source");
    105  var img = document.createElement("img");
    106 
    107  picture.appendChild(source);
    108  picture.appendChild(img);
    109 
    110  var promise = img.decode();
    111  return promise_rejects_dom(t, "EncodingError", promise);
    112 }, document.title + " Image without srcset fails decode.");
    113 
    114 promise_test(function() {
    115  var picture = document.createElement("picture");
    116  var source = document.createElement("source");
    117  var img = document.createElement("img");
    118 
    119  picture.appendChild(source);
    120  picture.appendChild(img);
    121 
    122  source.srcset = "/images/green.png";
    123 
    124  var first_promise = img.decode();
    125  var second_promise = img.decode();
    126  assert_not_equals(first_promise, second_promise);
    127  return Promise.all([
    128    first_promise,
    129    second_promise
    130  ]);
    131 }, document.title + " Multiple decodes for images with src succeed.");
    132 
    133 </script>