1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/test_toBlob.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<title>Canvas test: toBlob</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 BlobListener(type, canvas, callback, file) 1.13 +{ 1.14 + is(file.type, type, 1.15 + "When a valid type is specified that should be returned"); 1.16 + var reader = new FileReader(); 1.17 + reader.onload = 1.18 + function(e) { 1.19 + is(e.target.result, canvas.toDataURL(type), 1.20 + "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()"); 1.21 + callback(canvas); 1.22 + }; 1.23 + reader.readAsDataURL(file); 1.24 +} 1.25 + 1.26 +function test1(canvas) 1.27 +{ 1.28 + canvas.toBlob(BlobListener.bind(undefined, "image/png", canvas, test2)); 1.29 +} 1.30 + 1.31 +function test2(canvas) 1.32 +{ 1.33 + canvas.toBlob( 1.34 + BlobListener.bind(undefined, "image/jpeg", canvas, SimpleTest.finish), 1.35 + "image/jpeg"); 1.36 +} 1.37 + 1.38 +SimpleTest.waitForExplicitFinish(); 1.39 +addLoadEvent(function () { 1.40 + 1.41 +var canvas = document.getElementById('c'); 1.42 +var ctx = canvas.getContext('2d'); 1.43 +ctx.drawImage(document.getElementById('yellow75.png'), 0, 0); 1.44 + 1.45 +test1(canvas); 1.46 + 1.47 +}); 1.48 +</script> 1.49 +<img src="image_yellow75.png" id="yellow75.png" class="resource"> 1.50 +