| OLD | NEW |
| 1 <script src = "../../resources/js-test.js"></script> | 1 <script src="../../resources/testharness.js"></script> |
| 2 <script type = 'text/javascript'> | 2 <script src="../../resources/testharnessreport.js"></script> |
| 3 jsTestIsAsync = true; | |
| 4 description("Test that verifies whether the image data survives the toBlob proce
ss after async image encoding"); | |
| 5 | 3 |
| 6 if (window.testRunner) { | 4 <script> |
| 7 testRunner.dumpAsText(); | 5 async_test(t => { |
| 8 testRunner.waitUntilDone(); | 6 |
| 9 } | 7 var canvas = document.createElement("canvas"); |
| 8 var ctx = canvas.getContext("2d"); |
| 9 ctx.fillStyle = "#FF0000"; |
| 10 ctx.fillRect(0, 0, 150, 75); |
| 11 var canvas2 = document.createElement("canvas"); |
| 12 var ctx2 = canvas2.getContext("2d"); |
| 13 |
| 14 var newImg = new Image(); |
| 15 newImg.onload = function() { |
| 16 // 300x150 is the default size of the canvas, which is the source of the
newImg. |
| 17 ctx2.drawImage(newImg, 0, 0, 300, 150); |
| 10 | 18 |
| 11 var canvas = document.createElement("canvas"); | 19 var imageData1 = ctx.getImageData(0, 0, 150, 75).data; |
| 12 var ctx = canvas.getContext("2d"); | 20 var imageData2 = ctx2.getImageData(0, 0, 150, 75).data; |
| 13 ctx.fillStyle = "#FF0000"; | 21 var imageMatched = true; |
| 14 ctx.fillRect(0, 0, 150, 75); | 22 for (var i = 1; i < imageData1.length; i++) |
| 15 var canvas2 = document.createElement("canvas"); | 23 if (imageData1[i]!=imageData2[i]) |
| 16 var ctx2 = canvas2.getContext("2d"); | 24 { |
| 17 | 25 imageMatched = false; |
| 18 var newImg = new Image(); | 26 break; |
| 19 newImg.onload = function() { | 27 } |
| 20 // 300x150 is the default size of the canvas, which is the source of the new
Img. | 28 assert_true(imageMatched); |
| 21 ctx2.drawImage(newImg, 0, 0, 300, 150); | 29 t.done(); |
| 22 | |
| 23 var imageData1 = ctx.getImageData(0, 0, 150, 75).data; | |
| 24 var imageData2 = ctx2.getImageData(0, 0, 150, 75).data; | |
| 25 var imageMatched = true; | |
| 26 for (var i = 1; i < imageData1.length; i++) | |
| 27 { | |
| 28 if (imageData1[i]!=imageData2[i]) | |
| 29 { | |
| 30 imageMatched = false; | |
| 31 break; | |
| 32 } | |
| 33 } | 30 } |
| 34 if (imageMatched) | 31 |
| 35 testPassed("image data survives through the toBlob and PNG Image encoder
"); | 32 canvas.toBlob(function(blob) { |
| 36 else | 33 url = URL.createObjectURL(blob); |
| 37 testFailed("image data does not survive through the toBlob and PNG Image
encoder"); | 34 newImg.src = url; |
| 38 | 35 }); |
| 39 finishJSTest(); | 36 |
| 40 } | 37 }, "Verify whether the image data survives the toBlob process after async image
encoding."); |
| 41 | |
| 42 canvas.toBlob(function(blob) { | |
| 43 url = URL.createObjectURL(blob); | |
| 44 newImg.src = url; | |
| 45 }); | |
| 46 | |
| 47 </script> | 38 </script> |
| OLD | NEW |