OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <meta name="timeout" content="long"> |
| 4 <title>img.decode()</title> |
| 5 <link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org"> |
| 6 <link rel=help href=""> |
| 7 <script src="/resources/testharness.js"></script> |
| 8 <script src="/resources/testharnessreport.js"></script> |
| 9 <div id="log"></div> |
| 10 |
| 11 <script> |
| 12 "use strict"; |
| 13 |
| 14 // src tests |
| 15 // ------------------- |
| 16 promise_test(function() { |
| 17 var img = new Image(); |
| 18 img.src = "/images/green.png"; |
| 19 return img.decode().then(function(arg) { |
| 20 assert_equals(arg, undefined); |
| 21 }); |
| 22 }, "(src) PNG image decodes with undefined."); |
| 23 |
| 24 promise_test(function() { |
| 25 var img = new Image(); |
| 26 img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAA" + |
| 27 "D91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUSEioKsyAgyw" + |
| 28 "AAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAWSURBVA" + |
| 29 "jXY9y3bx8DAwPL58+fGRgYACktBRltLfebAAAAAElFTkSuQmCC"; |
| 30 return img.decode().then(function(arg) { |
| 31 assert_equals(arg, undefined); |
| 32 }); |
| 33 }, "(src) PNG url image decodes with undefined."); |
| 34 |
| 35 promise_test(function() { |
| 36 var img = new Image(); |
| 37 img.src = "/images/green.svg"; |
| 38 return img.decode().then(function(arg) { |
| 39 assert_equals(arg, undefined); |
| 40 }); |
| 41 }, "(src) SVG image decodes with undefined."); |
| 42 |
| 43 promise_test(function(t) { |
| 44 var img = new Image(); |
| 45 img.src = "/non/existent/path.png"; |
| 46 var promise = img.decode(); |
| 47 return promise_rejects(t, "EncodingError", promise); |
| 48 }, "(src) Non-existent path fails decode."); |
| 49 |
| 50 promise_test(function(t) { |
| 51 var img = new Image(); |
| 52 img.src = "data:image/png;base64,iVBO00PDR0BADBEEF00KGg"; |
| 53 var promise = img.decode(); |
| 54 return promise_rejects(t, "EncodingError", promise); |
| 55 }, "(src) Corrupt image fails decode."); |
| 56 |
| 57 promise_test(function(t) { |
| 58 var img = new Image(); |
| 59 var promise = img.decode(); |
| 60 return promise_rejects(t, "EncodingError", promise); |
| 61 }, "(src) Path-less image fails decode."); |
| 62 |
| 63 promise_test(function() { |
| 64 var img = new Image(); |
| 65 img.src = "/images/green.png"; |
| 66 var first_promise = img.decode(); |
| 67 var second_promise = img.decode(); |
| 68 assert_true(first_promise !== second_promise); |
| 69 return Promise.all([ |
| 70 first_promise, |
| 71 second_promise |
| 72 ]); |
| 73 }, "(src) Multiple decodes succeed."); |
| 74 |
| 75 // srcset tests |
| 76 // ------------------- |
| 77 promise_test(function() { |
| 78 var img = new Image(); |
| 79 img.srcset = "/images/green.png 100w"; |
| 80 return img.decode().then(function(arg) { |
| 81 assert_equals(arg, undefined); |
| 82 }); |
| 83 }, "(srcset) PNG image decodes with undefined."); |
| 84 |
| 85 promise_test(function() { |
| 86 var img = new Image(); |
| 87 img.srcset = "/images/green.svg 100w"; |
| 88 return img.decode().then(function(arg) { |
| 89 assert_equals(arg, undefined); |
| 90 }); |
| 91 }, "(srcset) SVG image decodes with undefined."); |
| 92 |
| 93 promise_test(function(t) { |
| 94 var img = new Image(); |
| 95 img.srcset = "/non/existent/path.png 100w"; |
| 96 var promise = img.decode(); |
| 97 return promise_rejects(t, "EncodingError", promise); |
| 98 }, "(srcset) Non-existent path fails decode."); |
| 99 |
| 100 promise_test(function() { |
| 101 var img = new Image(); |
| 102 img.srcset = "/images/green.png 100w"; |
| 103 var first_promise = img.decode(); |
| 104 var second_promise = img.decode(); |
| 105 assert_true(first_promise !== second_promise); |
| 106 return Promise.all([ |
| 107 first_promise, |
| 108 second_promise |
| 109 ]); |
| 110 }, "(srcset) Multiple decodes succeed."); |
| 111 |
| 112 </script> |
OLD | NEW |