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