5 testRunner
.dumpAsText();
9 document
.getElementById('console').appendChild(document
.createTextNode(msg
+ "\n"));
12 function testToDataURL()
14 var canvas1
= document
.getElementById("zero-Zero")
15 var canvas2
= document
.getElementById("zero-oneHundred");
16 var canvas3
= document
.getElementById("oneHundred-zero");
18 testMIMEType(canvas1
, "0x0", undefined);
19 testMIMEType(canvas2
, "0x100", undefined);
20 testMIMEType(canvas3
, "100x0", undefined);
22 testMIMEType(canvas1
, "0x0" , "image/jpeg");
23 testMIMEType(canvas2
, "0x100", "image/jpeg");
24 testMIMEType(canvas3
, "100x0", "image/jpeg");
26 testMIMEType(canvas1
, "0x0" , "image/webp");
27 testMIMEType(canvas2
, "0x100", "image/webp");
28 testMIMEType(canvas3
, "100x0", "image/webp");
31 function testMIMEType(canvas
, description
, mimeType
)
33 var ctx
= canvas
.getContext("2d");
36 ctx
.fillStyle
= "rgb(200,0,0)";
37 ctx
.fillRect(10, 10, 55, 50);
38 ctx
.fillStyle
= "rgba(0, 0, 200, 0.5)";
39 ctx
.fillRect(30, 30, 55, 50);
43 if (mimeType
== undefined) {
44 dataURL
= canvas
.toDataURL();
45 log("mimeType: unspecified");
47 dataURL
= canvas
.toDataURL(mimeType
);
48 log("mimeType: " + mimeType
);
51 if (dataURL
== "data:,")
52 log("PASS: Canvas of size " + description
+ " created data: url with no content - '" + dataURL
+ "'.");
54 log("FAIL: Canvas of size " + description
+ " did not create a data: url with no content - '" + dataURL
+ "'.");
58 <body onload=
"testToDataURL();">
59 <canvas id=
"zero-Zero" width=
"0" height=
"0"></canvas>
60 <canvas id=
"zero-oneHundred" width=
"0" height=
"100"></canvas>
61 <canvas id=
"oneHundred-zero" width=
"100" height=
"0"></canvas>
62 <pre id='console'
></pre>