image-decode-svg.tentative.html (5364B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <meta name="timeout" content="long"> 4 <title>SVGImageElement.prototype.decode(), basic tests.</title> 5 <link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <script> 10 "use strict"; 11 12 // src tests 13 // ------------------- 14 promise_test(function() { 15 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 16 img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.png"); 17 return img.decode().then(function(arg) { 18 assert_equals(arg, undefined); 19 }); 20 }, document.title + " Image with PNG xlink:href decodes with undefined."); 21 22 promise_test(function() { 23 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 24 img.setAttribute('href', "/images/green.png"); 25 return img.decode().then(function(arg) { 26 assert_equals(arg, undefined); 27 }); 28 }, document.title + " Image with PNG href decodes with undefined."); 29 30 promise_test(function() { 31 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 32 img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', 33 "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAA" + 34 "D91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsyAgyw" + 35 "AAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAWSURBVA" + 36 "jXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC"); 37 return img.decode().then(function(arg) { 38 assert_equals(arg, undefined); 39 }); 40 }, document.title + " Image with PNG data URL xlink:href decodes with undefined."); 41 42 promise_test(function() { 43 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 44 img.setAttribute('href', 45 "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAA" + 46 "D91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsyAgyw" + 47 "AAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAWSURBVA" + 48 "jXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC"); 49 return img.decode().then(function(arg) { 50 assert_equals(arg, undefined); 51 }); 52 }, document.title + " Image with PNG data URL href decodes with undefined."); 53 54 promise_test(function() { 55 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 56 img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.svg"); 57 return img.decode().then(function(arg) { 58 assert_equals(arg, undefined); 59 }); 60 }, document.title + " Image with SVG xlink:href decodes with undefined."); 61 62 promise_test(function() { 63 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 64 img.setAttribute('href', "/images/green.svg"); 65 return img.decode().then(function(arg) { 66 assert_equals(arg, undefined); 67 }); 68 }, document.title + " Image with SVG href decodes with undefined."); 69 70 promise_test(function(t) { 71 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 72 img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/non/existent/path.png"); 73 var promise = img.decode(); 74 return promise_rejects_dom(t, "EncodingError", promise); 75 }, document.title + " Non-existent xlink:href fails decode."); 76 77 promise_test(function(t) { 78 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 79 img.setAttribute('href', "/non/existent/path.png"); 80 var promise = img.decode(); 81 return promise_rejects_dom(t, "EncodingError", promise); 82 }, document.title + " Non-existent href fails decode."); 83 84 promise_test(function(t) { 85 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 86 img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "data:image/png;base64,iVBO00PDR0BADBEEF00KGg"); 87 var promise = img.decode(); 88 return promise_rejects_dom(t, "EncodingError", promise); 89 }, document.title + " Corrupt image in xlink:href fails decode."); 90 91 promise_test(function(t) { 92 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 93 img.setAttribute('href', "data:image/png;base64,iVBO00PDR0BADBEEF00KGg"); 94 var promise = img.decode(); 95 return promise_rejects_dom(t, "EncodingError", promise); 96 }, document.title + " Corrupt image in href fails decode."); 97 98 promise_test(function(t) { 99 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 100 var promise = img.decode(); 101 return promise_rejects_dom(t, "EncodingError", promise); 102 }, document.title + " Image without xlink:href or href fails decode."); 103 104 promise_test(function() { 105 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 106 img.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', "/images/green.png"); 107 var first_promise = img.decode(); 108 var second_promise = img.decode(); 109 assert_not_equals(first_promise, second_promise); 110 return Promise.all([ 111 first_promise, 112 second_promise 113 ]); 114 }, document.title + " Multiple decodes with a xlink:href succeed."); 115 116 promise_test(function() { 117 var img = document.createElementNS('http://www.w3.org/2000/svg', 'image'); 118 img.setAttribute('href', "/images/green.png"); 119 var first_promise = img.decode(); 120 var second_promise = img.decode(); 121 assert_not_equals(first_promise, second_promise); 122 return Promise.all([ 123 first_promise, 124 second_promise 125 ]); 126 }, document.title + " Multiple decodes with a href succeed."); 127 128 </script>