content/canvas/test/test_mozGetAsFile.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <title>Canvas test: mozGetAsFile</title>
michael@0 3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 4 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
michael@0 5 <body>
michael@0 6 <canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
michael@0 7 <script>
michael@0 8
michael@0 9 function compareAsync(file, canvas, type, callback)
michael@0 10 {
michael@0 11 var reader = new FileReader();
michael@0 12 reader.onload =
michael@0 13 function(e) {
michael@0 14 is(e.target.result, canvas.toDataURL(type),
michael@0 15 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
michael@0 16 callback(canvas);
michael@0 17 };
michael@0 18 reader.readAsDataURL(file);
michael@0 19 }
michael@0 20
michael@0 21 function test1(canvas)
michael@0 22 {
michael@0 23 var pngfile = canvas.mozGetAsFile("foo.png");
michael@0 24 is(pngfile.type, "image/png", "Default type for mozGetAsFile should be PNG");
michael@0 25 compareAsync(pngfile, canvas, "image/png", test2);
michael@0 26 is(pngfile.name, "foo.png", "File name should be what we passed in");
michael@0 27 }
michael@0 28
michael@0 29 function test2(canvas)
michael@0 30 {
michael@0 31 var jpegfile = canvas.mozGetAsFile("bar.jpg", "image/jpeg");
michael@0 32 is(jpegfile.type, "image/jpeg",
michael@0 33 "When a valid type is specified that should be returned");
michael@0 34 compareAsync(jpegfile, canvas, "image/jpeg", SimpleTest.finish);
michael@0 35 is(jpegfile.name, "bar.jpg", "File name should be what we passed in");
michael@0 36 }
michael@0 37
michael@0 38 SimpleTest.waitForExplicitFinish();
michael@0 39 addLoadEvent(function () {
michael@0 40
michael@0 41 var canvas = document.getElementById('c');
michael@0 42 var ctx = canvas.getContext('2d');
michael@0 43 ctx.drawImage(document.getElementById('yellow75.png'), 0, 0);
michael@0 44
michael@0 45 test1(canvas);
michael@0 46
michael@0 47 });
michael@0 48 </script>
michael@0 49 <img src="image_yellow75.png" id="yellow75.png" class="resource">
michael@0 50

mercurial