diff options
Diffstat (limited to 'testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode')
9 files changed, 730 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-iframe.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-iframe.html new file mode 100644 index 0000000000..ed14a007a6 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-iframe.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>HTMLImageElement.prototype.decode(), iframe 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> + +<iframe id="frame_loaded" srcdoc="iframe"></iframe> +<iframe id="frame_notloaded" srcdoc="iframe"></iframe> +<iframe id="frame_notloaded2" srcdoc="iframe"></iframe> + +<script> +"use strict"; + +promise_test(function() { + return new Promise(function(resolve, reject) { + var frame = document.getElementById("frame_loaded"); + var img = frame.contentDocument.createElement("img"); + img.src = "/images/green.png"; + img.onload = function() { + // At this point the frame which created the img is removed, so decode() should fail. + frame.parentNode.removeChild(frame); + img.decode().then(function() { + assert_unreached("Unexpected success"); + }, function() { + resolve(); + }); + }; + }); +}, document.title + " Decode from removed iframe fails (loaded img)"); + +promise_test(function(t) { + var frame = document.getElementById("frame_notloaded"); + var img = frame.contentDocument.createElement("img"); + img.src = "/images/green.png"; + frame.parentNode.removeChild(frame); + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Decode from removed iframe fails (img not loaded)"); + +promise_test(function(t) { + var frame = document.getElementById("frame_notloaded2"); + var img = frame.contentDocument.createElement("img"); + img.src = "/images/green.png"; + // First request a promise, then remove the iframe. + var promise = img.decode(); + frame.parentNode.removeChild(frame); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Decode from iframe, later removed, fails (img not loaded)"); + +</script> + diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-image-document.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-image-document.html new file mode 100644 index 0000000000..e54ae223a0 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-image-document.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<title>HTMLImageElement.prototype.decode(), image document tests.</title> +<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> +<iframe id="frame_imgdoc" src="about:blank"></iframe> +<script> +"use strict"; + +promise_test(function() { + return new Promise(function(resolve) { + var frame = document.getElementById("frame_imgdoc"); + // Load an image in the iframe and then replace that. + frame.src = "/images/red.png"; + frame.onload = function() { + let img = frame.contentDocument.body.firstElementChild; + img.src = "/images/green.png"; + img.decode().then(function() { + resolve(); + }); + }; + }); +}, document.title + " Decode from iframe with image document, succeeds (img not loaded)"); +</script> + diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-path-changes-svg.tentative.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-path-changes-svg.tentative.html new file mode 100644 index 0000000000..1bc53a1f18 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-path-changes-svg.tentative.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>SVGImageElement.prototype.decode(), href mutation tests.</title> +<link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> +"use strict"; + +// src tests +// ------------------- +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.png"); + var promise = img.decode(); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.svg"); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " xlink:href changes fail decode."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "/images/green.png"); + var promise = img.decode(); + img.setAttribute('href', "/images/green.svg"); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " href changes fail decode."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.png"); + var first_promise = img.decode(); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.svg"); + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + second_promise + ]); +}, document.title + " xlink:href changes fail decode; following good decode succeeds."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "/images/green.png"); + var first_promise = img.decode(); + img.setAttribute('href', "/images/green.svg"); + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + second_promise + ]); +}, document.title + " href changes fail decode; following good decode succeeds."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.png"); + var first_promise = img.decode(); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/non/existent/path.png"); + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + promise_rejects_dom(t, "EncodingError", second_promise) + ]); +}, document.title + " xlink:href changes fail decode; following bad decode fails."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "/images/green.png"); + var first_promise = img.decode(); + img.setAttribute('href', "/non/existent/path.png"); + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + promise_rejects_dom(t, "EncodingError", second_promise) + ]); +}, document.title + " href changes fail decode; following bad decode fails."); + +</script> diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-path-changes.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-path-changes.html new file mode 100644 index 0000000000..4b878c1bae --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-path-changes.html @@ -0,0 +1,121 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>HTMLImageElement.prototype.decode(), src/srcset mutation 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> + +<script> +"use strict"; + +// src tests +// ------------------- +promise_test(function(t) { + var img = new Image(); + img.src = "/images/green.png"; + var promise = img.decode(); + img.src = "/images/green.svg"; + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " src changes fail decode."); + +promise_test(function(t) { + var img = new Image(); + img.src = "/images/green.png"; + var first_promise = img.decode(); + img.src = "/images/blue.png"; + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + second_promise + ]); +}, document.title + " src changes fail decode; following good png decode succeeds."); + +promise_test(function(t) { + var img = new Image(); + img.src = "/images/green.png"; + var first_promise = img.decode(); + img.src = "/images/green.svg"; + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + second_promise + ]); +}, document.title + " src changes fail decode; following good svg decode succeeds."); + +promise_test(function(t) { + var img = new Image(); + img.src = "/images/green.png"; + var first_promise = img.decode(); + img.src = "/non/existent/path.png"; + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + promise_rejects_dom(t, "EncodingError", second_promise) + ]); +}, document.title + " src changes fail decode; following bad decode fails."); + +promise_test(function(t) { + return new Promise(function(resolve, reject) { + var img = new Image(); + // We wait for an onload, since the "Updating the image data" spec states + // that if a new microtask is scheduled, the old one is canceled so + // without the onload, the first decode request would be requested when the + // img.src is empty. With an onload, we ensure that the img.src is set and + // the image exists before issuing the first decode, then we verify that the + // src change to the same value does not prevent that request from + // succeeding. + img.onload = t.step_func(function() { + img.onload = null; + + var first_promise = img.decode(); + img.src = "/images/green.png"; + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + resolve(Promise.all([first_promise, second_promise])); + }); + img.src = "/images/green.png"; + }); +}, document.title + " src changes to the same path succeed."); + +// srcset tests +// ------------------- +promise_test(function(t) { + var img = new Image(); + img.srcset = "/images/green.png 100w"; + var promise = img.decode(); + img.srcset = "/images/green.svg 100w"; + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " srcset changes fail decode."); + +promise_test(function(t) { + var img = new Image(); + img.srcset = "/images/green.png 100w"; + var first_promise = img.decode(); + img.srcset = "/images/green.svg 100w"; + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + second_promise + ]); +}, document.title + " srcset changes fail decode; following good decode succeeds."); + +promise_test(function(t) { + var img = new Image(); + img.srcset = "/images/green.png 100w"; + var first_promise = img.decode(); + img.srcset = "/non/existent/path.png 100w"; + var second_promise = img.decode(); + assert_not_equals(first_promise, second_promise); + return Promise.all([ + promise_rejects_dom(t, "EncodingError", first_promise), + promise_rejects_dom(t, "EncodingError", second_promise) + ]); +}, document.title + " srcset changes fail decode; following bad decode fails."); + +</script> diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-picture.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-picture.html new file mode 100644 index 0000000000..2f4d5e7c41 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-picture.html @@ -0,0 +1,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> diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-svg.tentative.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-svg.tentative.html new file mode 100644 index 0000000000..047470f1e3 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-svg.tentative.html @@ -0,0 +1,128 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>SVGImageElement.prototype.decode(), basic tests.</title> +<link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<script> +"use strict"; + +// src tests +// ------------------- +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.png"); + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with PNG xlink:href decodes with undefined."); + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "/images/green.png"); + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with PNG href decodes with undefined."); + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAA" + + "D91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsyAgyw" + + "AAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAWSURBVA" + + "jXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC"); + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with PNG data URL xlink:href decodes with undefined."); + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAA" + + "D91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsyAgyw" + + "AAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAWSURBVA" + + "jXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC"); + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with PNG data URL href decodes with undefined."); + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.svg"); + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with SVG xlink:href decodes with undefined."); + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "/images/green.svg"); + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with SVG href decodes with undefined."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/non/existent/path.png"); + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Non-existent xlink:href fails decode."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "/non/existent/path.png"); + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Non-existent href fails decode."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "data:image/png;base64,iVBO00PDR0BADBEEF00KGg"); + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Corrupt image in xlink:href fails decode."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "data:image/png;base64,iVBO00PDR0BADBEEF00KGg"); + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Corrupt image in href fails decode."); + +promise_test(function(t) { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Image without xlink:href or href fails decode."); + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/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 with a xlink:href succeed."); + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttribute('href', "/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 with a href succeed."); + +</script> diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-with-quick-attach-svg.tentative.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-with-quick-attach-svg.tentative.html new file mode 100644 index 0000000000..0fc49e6036 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-with-quick-attach-svg.tentative.html @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>SVGImageElement.prototype.decode(), attach to DOM before promise resolves.</title> +<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> +<svg></svg> +<script> +"use strict"; + +promise_test(function() { + var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); + img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.png"); + const promise = img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); + // Don't wait for the promise to resolve before attaching the image. + // The promise should still resolve successfully. + document.querySelector('svg').appendChild(img); + return promise; +}, document.title); +</script> diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-with-quick-attach.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-with-quick-attach.html new file mode 100644 index 0000000000..be680da619 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode-with-quick-attach.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>HTMLImageElement.prototype.decode(), attach to DOM before promise resolves.</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> + +<body></body> + +<script> +"use strict"; + +promise_test(function() { + const img = new Image(); + img.src = "/images/green.png"; + const promise = img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); + // Don't wait for the promise to resolve before attaching the image. + // The promise should still resolve successfully. + document.body.appendChild(img); + return promise; +}, document.title); +</script> diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode.html b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode.html new file mode 100644 index 0000000000..fac61a1446 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/decode/image-decode.html @@ -0,0 +1,138 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<meta name="timeout" content="long"> +<title>HTMLImageElement.prototype.decode(), basic 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> + +<script> +"use strict"; + +// src tests +// ------------------- +promise_test(function() { + var img = new Image(); + img.src = "/images/green.png"; + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with PNG src decodes with undefined."); + +promise_test(function() { + var img = new Image(); + img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAA" + + "D91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsyAgyw" + + "AAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAWSURBVA" + + "jXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC"; + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with PNG data URL src decodes with undefined."); + +promise_test(function() { + var img = new Image(); + img.src = "/images/green.svg"; + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with SVG src decodes with undefined."); + +promise_test(function(t) { + var img = new Image(); + img.src = "/non/existent/path.png"; + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Non-existent src fails decode."); + +promise_test(function(t) { + var inactive_doc = document.implementation.createHTMLDocument(); + var img = inactive_doc.createElement("img"); + img.src = "/images/green.png"; + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Inactive document fails decode."); + +promise_test(function(t) { + var inactive_doc = document.implementation.createHTMLDocument(); + var img = document.createElement("img"); + img.src = "/images/green.png"; + var promise = img.decode(); + inactive_doc.body.appendChild(img); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Adopted active image into inactive document fails decode."); + +promise_test(function() { + var inactive_doc = document.implementation.createHTMLDocument(); + var img = inactive_doc.createElement("img"); + img.src = "/images/green.png"; + document.body.appendChild(img); + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Adopted inactive image into active document succeeds."); + +promise_test(function(t) { + var img = new Image(); + img.src = "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 img = new Image(); + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Image without src/srcset fails decode."); + +promise_test(function() { + var img = new Image(); + img.src = "/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."); + +// srcset tests +// ------------------- +promise_test(function() { + var img = new Image(); + img.srcset = "/images/green.png 100w"; + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with PNG srcset decodes with undefined."); + +promise_test(function() { + var img = new Image(); + img.srcset = "/images/green.svg 100w"; + return img.decode().then(function(arg) { + assert_equals(arg, undefined); + }); +}, document.title + " Image with SVG srcset decodes with undefined."); + +promise_test(function(t) { + var img = new Image(); + img.srcset = "/non/existent/path.png 100w"; + var promise = img.decode(); + return promise_rejects_dom(t, "EncodingError", promise); +}, document.title + " Non-existent srcset fails decode."); + +promise_test(function() { + var img = new Image(); + img.srcset = "/images/green.png 100w"; + 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 srcset succeed."); + +</script> |