summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-animated.html
blob: e6acaeb6c6833d9f6086a170a26d1fac96347c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
    window.jsTestIsAsync = true;

    function shouldBeGreen(x, y) {
        d = ctx.getImageData(x, y, 1, 1).data;
        shouldBeTrue("d[0] == 0");
        shouldBeTrue("d[1] == 255");
        shouldBeTrue("d[2] == 0");
        shouldBeTrue("d[3] == 255");
    }

    var canvas = document.createElement("canvas");
    canvas.width = 200;
    canvas.height = 200;
    var ctx = canvas.getContext("2d");

    var img = new Image();
    img.onload = imageLoaded;
    img.src = 'resources/green-red-animated.gif';

    function imageLoaded() {
        // If the ImageBitmap is green, we know that it is a snapshot of the gif's 0th frame.
        window.internals.advanceImageAnimation(img);
        createImageBitmap(img).then(function (imageBitmap) {
            ctx.drawImage(imageBitmap, 0, 0);
            shouldBeGreen(100, 100);
            finishJSTest();
        }, function() {
            testFailed("Promise was rejected.");
            finishJSTest();
        });
    }
</script>
</body>
</html>