OLD | NEW |
1 <html> | 1 <script src="../../resources/testharness.js"></script> |
2 <head> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <script> | 3 |
4 if (window.testRunner) | 4 <canvas id="zero-Zero" width="0" height="0"></canvas> |
5 testRunner.dumpAsText(); | 5 <canvas id="zero-oneHundred" width="0" height="100"></canvas> |
| 6 <canvas id="oneHundred-zero" width="100" height="0"></canvas> |
6 | 7 |
7 function log(msg) | 8 <script> |
8 { | 9 |
9 document.getElementById('console').appendChild(document.createTextNo
de(msg + "\n")); | 10 function testToDataURL() |
| 11 { |
| 12 var canvas1 = document.getElementById("zero-Zero") |
| 13 var canvas2 = document.getElementById("zero-oneHundred"); |
| 14 var canvas3 = document.getElementById("oneHundred-zero"); |
| 15 |
| 16 testMIMEType(canvas1, "0x0", undefined); |
| 17 testMIMEType(canvas2, "0x100", undefined); |
| 18 testMIMEType(canvas3, "100x0", undefined); |
| 19 |
| 20 testMIMEType(canvas1, "0x0" , "image/jpeg"); |
| 21 testMIMEType(canvas2, "0x100", "image/jpeg"); |
| 22 testMIMEType(canvas3, "100x0", "image/jpeg"); |
| 23 |
| 24 testMIMEType(canvas1, "0x0" , "image/webp"); |
| 25 testMIMEType(canvas2, "0x100", "image/webp"); |
| 26 testMIMEType(canvas3, "100x0", "image/webp"); |
| 27 } |
| 28 |
| 29 function testMIMEType(canvas, description, mimeType) |
| 30 { |
| 31 var ctx = canvas.getContext("2d"); |
| 32 |
| 33 // draw into canvas |
| 34 ctx.fillStyle = "rgb(200,0,0)"; |
| 35 ctx.fillRect(10, 10, 55, 50); |
| 36 ctx.fillStyle = "rgba(0, 0, 200, 0.5)"; |
| 37 ctx.fillRect(30, 30, 55, 50); |
| 38 |
| 39 var dataURL; |
| 40 |
| 41 if (mimeType == undefined) { |
| 42 dataURL = canvas.toDataURL(); |
| 43 } else { |
| 44 dataURL = canvas.toDataURL(mimeType); |
| 45 } |
| 46 |
| 47 assert_equals (dataURL, "data:,"); |
| 48 } |
| 49 |
| 50 async_test(t => { |
| 51 window.onload = function() { |
| 52 t.step(testToDataURL); |
| 53 t.done(); |
10 } | 54 } |
11 | 55 }, 'Verify that the custom properties on a Canvas 2D rendering context object ar
e retained across GCs.'); |
12 function testToDataURL() | 56 </script> |
13 { | |
14 var canvas1 = document.getElementById("zero-Zero") | |
15 var canvas2 = document.getElementById("zero-oneHundred"); | |
16 var canvas3 = document.getElementById("oneHundred-zero"); | |
17 | |
18 testMIMEType(canvas1, "0x0", undefined); | |
19 testMIMEType(canvas2, "0x100", undefined); | |
20 testMIMEType(canvas3, "100x0", undefined); | |
21 | |
22 testMIMEType(canvas1, "0x0" , "image/jpeg"); | |
23 testMIMEType(canvas2, "0x100", "image/jpeg"); | |
24 testMIMEType(canvas3, "100x0", "image/jpeg"); | |
25 | |
26 testMIMEType(canvas1, "0x0" , "image/webp"); | |
27 testMIMEType(canvas2, "0x100", "image/webp"); | |
28 testMIMEType(canvas3, "100x0", "image/webp"); | |
29 } | |
30 | |
31 function testMIMEType(canvas, description, mimeType) | |
32 { | |
33 var ctx = canvas.getContext("2d"); | |
34 | |
35 // draw into canvas | |
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); | |
40 | |
41 var dataURL; | |
42 | |
43 if (mimeType == undefined) { | |
44 dataURL = canvas.toDataURL(); | |
45 log("mimeType: unspecified"); | |
46 } else { | |
47 dataURL = canvas.toDataURL(mimeType); | |
48 log("mimeType: " + mimeType); | |
49 } | |
50 | |
51 if (dataURL == "data:,") | |
52 log("PASS: Canvas of size " + description + " created data: url
with no content - '" + dataURL + "'."); | |
53 else | |
54 log("FAIL: Canvas of size " + description + " did not create a d
ata: url with no content - '" + dataURL + "'."); | |
55 } | |
56 </script> | |
57 </head> | |
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> | |
63 </body> | |
64 </html> | |
OLD | NEW |