Bug 616542 - Shorten file path length of mochitest; r=ted
[gecko.git] / content / canvas / test / test_mozGetAsFile.html
blob32be4c05c4c0a69dad09bd6505b0af76160fd843
1 <!DOCTYPE HTML>
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">
6 <body>
7 <canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
8 <script>
10 var gCompares = 0;
12 function compareAsync(file, canvas, type)
14 ++gCompares;
16 var reader = new FileReader();
17 reader.onload =
18 function(e) {
19 is(e.target.result, canvas.toDataURL(type),
20 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
21 if (--gCompares == 0) {
22 SimpleTest.finish();
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");
47 });
48 </script>
49 <img src="image_yellow75.png" id="yellow75.png" class="resource">