summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/toDataURL-noData.html
blob: 9fd5a85e19e457d3a6aeb6d2c00616d360deff9c (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<head>
    <script>
        if (window.testRunner)
            testRunner.dumpAsText();

        function log(msg)
        {
            document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
        }

        function testToDataURL()
        {
            var canvas1 = document.getElementById("zero-Zero")
            var canvas2 = document.getElementById("zero-oneHundred");
            var canvas3 = document.getElementById("oneHundred-zero");

            testMIMEType(canvas1, "0x0", undefined);
            testMIMEType(canvas2, "0x100", undefined);
            testMIMEType(canvas3, "100x0", undefined);

            testMIMEType(canvas1, "0x0"  , "image/jpeg");
            testMIMEType(canvas2, "0x100", "image/jpeg");
            testMIMEType(canvas3, "100x0", "image/jpeg");

            testMIMEType(canvas1, "0x0"  , "image/webp");
            testMIMEType(canvas2, "0x100", "image/webp");
            testMIMEType(canvas3, "100x0", "image/webp");
        }

        function testMIMEType(canvas, description, mimeType)
        {
            var ctx = canvas.getContext("2d");

            // draw into canvas
            ctx.fillStyle = "rgb(200,0,0)";
            ctx.fillRect(10, 10, 55, 50);
            ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
            ctx.fillRect(30, 30, 55, 50);

            var dataURL;

            if (mimeType == undefined) {
                dataURL = canvas.toDataURL();
                log("mimeType: unspecified");
            } else {
                dataURL = canvas.toDataURL(mimeType);
                log("mimeType: " + mimeType);
            }

            if (dataURL == "data:,")
                log("PASS: Canvas of size " + description + " created data: url with no content - '" + dataURL + "'.");
            else
                log("FAIL: Canvas of size " + description + " did not create a data: url with no content - '" + dataURL + "'.");
        }
    </script>
</head>
<body onload="testToDataURL();">
    <canvas id="zero-Zero" width="0" height="0"></canvas>
    <canvas id="zero-oneHundred" width="0" height="100"></canvas>
    <canvas id="oneHundred-zero" width="100" height="0"></canvas>
    <pre id='console'></pre>
</body>
</html>