OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/js-test.js"></script> |
4 </head> | 4 </head> |
5 <body> | 5 <body> |
6 <script> | 6 <script> |
7 window.jsTestIsAsync = true; | 7 window.jsTestIsAsync = true; |
8 | 8 |
9 function shouldBeGreen(x, y) { | 9 function shouldBeGreen(x, y) { |
10 d = ctx.getImageData(x, y, 1, 1).data; | 10 d = ctx.getImageData(x, y, 1, 1).data; |
11 shouldBeTrue("d[0] == 0"); | 11 shouldBeTrue("d[0] == 0"); |
12 shouldBeTrue("d[1] == 255"); | 12 shouldBeTrue("d[1] == 255"); |
13 shouldBeTrue("d[2] == 0"); | 13 shouldBeTrue("d[2] == 0"); |
14 shouldBeTrue("d[3] == 255"); | 14 shouldBeTrue("d[3] == 255"); |
15 } | 15 } |
16 | 16 |
17 var canvas = document.createElement("canvas"); | 17 var canvas = document.createElement("canvas"); |
18 canvas.width = 200; | 18 canvas.width = 200; |
19 canvas.height = 200; | 19 canvas.height = 200; |
20 var ctx = canvas.getContext("2d"); | 20 var ctx = canvas.getContext("2d"); |
21 | 21 |
22 var img = new Image(); | 22 var img = new Image(); |
| 23 img.onload = imageLoaded; |
23 img.src = 'resources/green-red-animated.gif'; | 24 img.src = 'resources/green-red-animated.gif'; |
24 img.onload = imageLoaded; | |
25 | 25 |
26 function imageLoaded() { | 26 function imageLoaded() { |
27 // The gif switches from green to red in 10ms. We wait 50ms to ensure th
at the gif will have changed colors. | |
28 // If the ImageBitmap is green, we know that it is a snapshot of the gif
's 0th frame. | 27 // If the ImageBitmap is green, we know that it is a snapshot of the gif
's 0th frame. |
29 window.setTimeout(function() { | 28 window.internals.advanceImageAnimation(img); |
30 createImageBitmap(img).then(function (imageBitmap) { | 29 createImageBitmap(img).then(function (imageBitmap) { |
31 ctx.drawImage(imageBitmap, 0, 0); | 30 ctx.drawImage(imageBitmap, 0, 0); |
32 shouldBeGreen(100, 100); | 31 shouldBeGreen(100, 100); |
33 finishJSTest(); | 32 finishJSTest(); |
34 }, function() { | 33 }, function() { |
35 testFailed("Promise was rejected."); | 34 testFailed("Promise was rejected."); |
36 finishJSTest(); | 35 finishJSTest(); |
37 }); | 36 }); |
38 }, 50); | |
39 } | 37 } |
40 </script> | 38 </script> |
41 </body> | 39 </body> |
42 </html> | 40 </html> |
OLD | NEW |