4 img { border: 1px solid black; }
5 pre { display: inline-block; margin: 5px; }
8 if (window.layoutTestController)
9 layoutTestController.dumpAsText();
13 var canvas = document.getElementById("canvas");
14 var ctx = canvas.getContext("2d");
16 ctx.fillStyle = "rgb(200,0,0)";
17 ctx.fillRect(10, 10, 55, 50);
18 ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
19 ctx.fillRect(30, 30, 55, 50);
24 // Default list of supported image formats.
25 var supportedMIMETypes = [
31 function testToDataURL()
33 // Test supported MIME types
34 for (var i in supportedMIMETypes) {
35 testMIMEType(supportedMIMETypes[i]);
41 testMIMEType(undefined);
43 // Test other formats that we don't support
44 testMIMEType("image/x-webkitbitmap");
47 function testMIMEType(mime)
49 var canvas = document.getElementById("canvas");
51 var hadArgument = arguments.length;
54 url = canvas.toDataURL();
56 url = canvas.toDataURL(mime);
58 var image = document.createElement("img");
60 var usedMIMEType = url.substring(5, url.search(/;/));
61 document.body.appendChild(image);
62 var info = document.createElement("pre");
63 info.appendChild(document.createTextNode("Given MIMEType: " + (hadArgument ? mime : "")));
64 info.appendChild(document.createTextNode("\n"));
65 info.appendChild(document.createTextNode("Used MIMEType: " + usedMIMEType));
66 info.appendChild(document.createTextNode("\n"));
67 info.appendChild(document.createTextNode((mime == usedMIMEType) ? "MIME types are the SAME." : "MIME types DIFFER."));
68 info.appendChild(document.createTextNode("\n\n"));
70 document.body.appendChild(info);
71 document.body.appendChild(document.createElement("hr"));
75 <body onload="draw();">
76 <canvas id="canvas" width="150" height="150"></canvas> The Actual Canvas <br><hr>