2 <title>Canvas test: mozGetAsFile
</title>
3 <script src=
"/MochiKit/MochiKit.js"></script>
4 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
5 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
7 <canvas id=
"c" width=
"100" height=
"50"><p class=
"fallback">FAIL (fallback content)
</p></canvas>
12 function compareAsync(file
, canvas
, type
)
16 var reader
= new FileReader();
19 is(e
.target
.result
, canvas
.toDataURL(type
),
20 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
21 if (--gCompares
== 0) {
25 reader
.readAsDataURL(file
);
28 SimpleTest
.waitForExplicitFinish();
29 addLoadEvent(function () {
31 var canvas
= document
.getElementById('c');
32 var ctx
= canvas
.getContext('2d');
34 ctx
.drawImage(document
.getElementById('yellow75.png'), 0, 0);
36 var pngfile
= canvas
.mozGetAsFile("foo.png");
37 is(pngfile
.type
, "image/png", "Default type for mozGetAsFile should be PNG");
38 compareAsync(pngfile
, canvas
, "image/png");
39 is(pngfile
.name
, "foo.png", "File name should be what we passed in");
41 var jpegfile
= canvas
.mozGetAsFile("bar.jpg", "image/jpeg");
42 is(jpegfile
.type
, "image/jpeg",
43 "When a valid type is specified that should be returned");
44 compareAsync(jpegfile
, canvas
, "image/jpeg");
45 is(jpegfile
.name
, "bar.jpg", "File name should be what we passed in");
49 <img src=
"image_yellow75.png" id=
"yellow75.png" class=
"resource">