content/canvas/test/test_toBlob.html
author Kyle Huey <khuey@kylehuey.com>
Mon, 15 Oct 2012 14:15:25 -0700
changeset 113417 cbfef8616b633b460987030a1b6798b1869e769b
parent 77336 content/canvas/test/test_mozGetAsFile.html@67e54020dce568e2c2ba7590b54f285863ed7371
child 139082 7a3535c6e652108238d83b86090aceff0c3ffa5a
permissions -rw-r--r--
Bug 648610 - Implement <canvas>.toBlob. r=smaug, a=blocking-basecamp

<!DOCTYPE HTML>
<title>Canvas test: mozGetAsFile</title>
<script src="/MochiKit/MochiKit.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<script>

var gCompares = 2;

function BlobListener(type, canvas, file)
{
  is(file.type, type,
     "When a valid type is specified that should be returned");
  var reader = new FileReader();
  reader.onload = 
    function(e) {
      is(e.target.result, canvas.toDataURL(type),
 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
      if (--gCompares == 0) {
        SimpleTest.finish();
      }
    };
  reader.readAsDataURL(file);
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(function () {

var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');

ctx.drawImage(document.getElementById('yellow75.png'), 0, 0);

canvas.toBlob(BlobListener.bind(undefined, "image/png", canvas));
canvas.toBlob(BlobListener.bind(undefined, "image/jpeg", canvas), "image/jpeg");

});
</script>
<img src="image_yellow75.png" id="yellow75.png" class="resource">