summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-picture.html
blob: 2f4d5e7c41270455529cf9c0a959e47ecff1aeb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>HTMLImageElement.prototype.decode(), picture tests.</title>
<link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<picture>
<source srcset="/images/green.png">
<source srcset="/images/blue.png">
<img id="testimg">
</picture>

<script>
"use strict";

promise_test(function() {
  var picture = document.createElement("picture");
  var source = document.createElement("source");
  var img = document.createElement("img");

  picture.appendChild(source);
  picture.appendChild(img);

  source.srcset = "/images/green.png";

  return img.decode().then(function(arg) {
    assert_equals(arg, undefined);
  });
}, document.title + " Image with PNG source decodes with undefined.");

promise_test(function() {
  var img = document.getElementById("testimg");
  return img.decode().then(function(arg) {
    assert_equals(arg, undefined);
  });
}, document.title + " Image with multiple sources decodes with undefined.");

promise_test(function() {
  var picture = document.createElement("picture");
  var source = document.createElement("source");
  var img = document.createElement("img");

  picture.appendChild(source);
  picture.appendChild(img);

  source.srcset = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIA" +
                  "AAD91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsy" +
                  "AgywAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAW" +
                  "SURBVAjXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC";

  return img.decode().then(function(arg) {
    assert_equals(arg, undefined);
  });
}, document.title + " Image with PNG data URL source decodes with undefined.");

promise_test(function() {
  var picture = document.createElement("picture");
  var source = document.createElement("source");
  var img = document.createElement("img");

  picture.appendChild(source);
  picture.appendChild(img);

  source.srcset = "/images/green.svg";

  return img.decode().then(function(arg) {
    assert_equals(arg, undefined);
  });
}, document.title + " Image with SVG source decodes with undefined.");

promise_test(function(t) {
  var picture = document.createElement("picture");
  var source = document.createElement("source");
  var img = document.createElement("img");

  picture.appendChild(source);
  picture.appendChild(img);

  source.srcset = "/non/existent/path.png";

  var promise = img.decode();
  return promise_rejects_dom(t, "EncodingError", promise);
}, document.title + " Non-existent source fails decode.");

promise_test(function(t) {
  var picture = document.createElement("picture");
  var source = document.createElement("source");
  var img = document.createElement("img");

  picture.appendChild(source);
  picture.appendChild(img);

  source.srcset = "data:image/png;base64,iVBO00PDR0BADBEEF00KGg";

  var promise = img.decode();
  return promise_rejects_dom(t, "EncodingError", promise);
}, document.title + " Corrupt image in src fails decode.");

promise_test(function(t) {
  var picture = document.createElement("picture");
  var source = document.createElement("source");
  var img = document.createElement("img");

  picture.appendChild(source);
  picture.appendChild(img);

  var promise = img.decode();
  return promise_rejects_dom(t, "EncodingError", promise);
}, document.title + " Image without srcset fails decode.");

promise_test(function() {
  var picture = document.createElement("picture");
  var source = document.createElement("source");
  var img = document.createElement("img");

  picture.appendChild(source);
  picture.appendChild(img);

  source.srcset = "/images/green.png";

  var first_promise = img.decode();
  var second_promise = img.decode();
  assert_not_equals(first_promise, second_promise);
  return Promise.all([
    first_promise,
    second_promise
  ]);
}, document.title + " Multiple decodes for images with src succeed.");

</script>