Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <title>Canvas test: mozGetAsFile</title>
3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
5 <body>
6 <canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
7 <script>
9 function compareAsync(file, canvas, type, callback)
10 {
11 var reader = new FileReader();
12 reader.onload =
13 function(e) {
14 is(e.target.result, canvas.toDataURL(type),
15 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
16 callback(canvas);
17 };
18 reader.readAsDataURL(file);
19 }
21 function test1(canvas)
22 {
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");
27 }
29 function test2(canvas)
30 {
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");
36 }
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);
45 test1(canvas);
47 });
48 </script>
49 <img src="image_yellow75.png" id="yellow75.png" class="resource">