1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/test_mozGetAsFile.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<title>Canvas test: mozGetAsFile</title> 1.6 +<script src="/tests/SimpleTest/SimpleTest.js"></script> 1.7 +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> 1.8 +<body> 1.9 +<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 1.10 +<script> 1.11 + 1.12 +function compareAsync(file, canvas, type, callback) 1.13 +{ 1.14 + var reader = new FileReader(); 1.15 + reader.onload = 1.16 + function(e) { 1.17 + is(e.target.result, canvas.toDataURL(type), 1.18 + "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()"); 1.19 + callback(canvas); 1.20 + }; 1.21 + reader.readAsDataURL(file); 1.22 +} 1.23 + 1.24 +function test1(canvas) 1.25 +{ 1.26 + var pngfile = canvas.mozGetAsFile("foo.png"); 1.27 + is(pngfile.type, "image/png", "Default type for mozGetAsFile should be PNG"); 1.28 + compareAsync(pngfile, canvas, "image/png", test2); 1.29 + is(pngfile.name, "foo.png", "File name should be what we passed in"); 1.30 +} 1.31 + 1.32 +function test2(canvas) 1.33 +{ 1.34 + var jpegfile = canvas.mozGetAsFile("bar.jpg", "image/jpeg"); 1.35 + is(jpegfile.type, "image/jpeg", 1.36 + "When a valid type is specified that should be returned"); 1.37 + compareAsync(jpegfile, canvas, "image/jpeg", SimpleTest.finish); 1.38 + is(jpegfile.name, "bar.jpg", "File name should be what we passed in"); 1.39 +} 1.40 + 1.41 +SimpleTest.waitForExplicitFinish(); 1.42 +addLoadEvent(function () { 1.43 + 1.44 +var canvas = document.getElementById('c'); 1.45 +var ctx = canvas.getContext('2d'); 1.46 +ctx.drawImage(document.getElementById('yellow75.png'), 0, 0); 1.47 + 1.48 +test1(canvas); 1.49 + 1.50 +}); 1.51 +</script> 1.52 +<img src="image_yellow75.png" id="yellow75.png" class="resource"> 1.53 +