2 <title>Canvas test: mozGetAsFile
</title>
3 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
6 <canvas id=
"c" width=
"100" height=
"50"><p class=
"fallback">FAIL (fallback content)
</p></canvas>
9 function compareAsync(file
, canvas
, type
, callback
)
11 var reader
= new FileReader();
14 is(e
.target
.result
, canvas
.toDataURL(type
),
15 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
18 reader
.readAsDataURL(file
);
21 function test1(canvas
)
23 var pngfile
= canvas
.mozGetAsFile("foo.png");
24 is(pngfile
.type
, "image/png", "Default type for mozGetAsFile should be PNG");
25 compareAsync(pngfile
, canvas
, "image/png", test2
);
26 is(pngfile
.name
, "foo.png", "File name should be what we passed in");
29 function test2(canvas
)
31 var jpegfile
= canvas
.mozGetAsFile("bar.jpg", "image/jpeg");
32 is(jpegfile
.type
, "image/jpeg",
33 "When a valid type is specified that should be returned");
34 compareAsync(jpegfile
, canvas
, "image/jpeg", SimpleTest
.finish
);
35 is(jpegfile
.name
, "bar.jpg", "File name should be what we passed in");
38 SimpleTest
.waitForExplicitFinish();
39 addLoadEvent(function () {
41 var canvas
= document
.getElementById('c');
42 var ctx
= canvas
.getContext('2d');
43 ctx
.drawImage(document
.getElementById('yellow75.png'), 0, 0);
49 <img src=
"image_yellow75.png" id=
"yellow75.png" class=
"resource">