content/canvas/test/test_toBlob.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: toBlob</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 BlobListener(type, canvas, callback, file)
michael@0 10 {
michael@0 11 is(file.type, type,
michael@0 12 "When a valid type is specified that should be returned");
michael@0 13 var reader = new FileReader();
michael@0 14 reader.onload =
michael@0 15 function(e) {
michael@0 16 is(e.target.result, canvas.toDataURL(type),
michael@0 17 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
michael@0 18 callback(canvas);
michael@0 19 };
michael@0 20 reader.readAsDataURL(file);
michael@0 21 }
michael@0 22
michael@0 23 function test1(canvas)
michael@0 24 {
michael@0 25 canvas.toBlob(BlobListener.bind(undefined, "image/png", canvas, test2));
michael@0 26 }
michael@0 27
michael@0 28 function test2(canvas)
michael@0 29 {
michael@0 30 canvas.toBlob(
michael@0 31 BlobListener.bind(undefined, "image/jpeg", canvas, SimpleTest.finish),
michael@0 32 "image/jpeg");
michael@0 33 }
michael@0 34
michael@0 35 SimpleTest.waitForExplicitFinish();
michael@0 36 addLoadEvent(function () {
michael@0 37
michael@0 38 var canvas = document.getElementById('c');
michael@0 39 var ctx = canvas.getContext('2d');
michael@0 40 ctx.drawImage(document.getElementById('yellow75.png'), 0, 0);
michael@0 41
michael@0 42 test1(canvas);
michael@0 43
michael@0 44 });
michael@0 45 </script>
michael@0 46 <img src="image_yellow75.png" id="yellow75.png" class="resource">
michael@0 47

mercurial