content/canvas/test/test_toDataURL_parameters.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.

     1 <!DOCTYPE HTML>
     2 <title>Canvas test: toDataURL parameters (Bug 564388)</title>
     3 <script src="/tests/SimpleTest/SimpleTest.js"></script>
     4 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
     5 <body>
     6 <p>
     7 This test covers the JPEG quality parameter. If (when) the HTML5 spec changes the
     8 allowed parameters for ToDataURL, new tests should go here.
     9 </p>
    10 <canvas id="c" width="100" height="100"><p class="fallback">FAIL (fallback content)</p></canvas>
    11 <script>
    12 var canvas = document.getElementById('c');
    13 var ctx = canvas.getContext("2d");
    15 ctx.strokeStyle = '#FF0000';
    16 ctx.fillStyle = '#00FF00';
    17 ctx.fillRect(0, 0, 100, 100);
    18 ctx.beginPath();
    19 ctx.moveTo(10, 10);
    20 ctx.lineTo(90, 90);
    21 ctx.stroke();
    23 var pngData = canvas.toDataURL('image/png');
    24 var pngQuality = canvas.toDataURL('image/png', 0.1);
    25 is(pngQuality, pngData, "Quality is not supported for PNG images");
    27 var data = canvas.toDataURL('image/jpeg');
    28 if (data.match(/^data:image\/jpeg[;,]/)) {
    29     // Test the JPEG quality parameter
    31     var fullQuality = canvas.toDataURL('image/jpeg', 1.0);
    32     var lowQuality = canvas.toDataURL('image/jpeg', 0.1);
    33     isnot(lowQuality, fullQuality, "A low quality (0.1) should differ from high quality (1.0)");
    35     var medQuality = canvas.toDataURL('image/jpeg', 0.5);
    36     isnot(medQuality, fullQuality, "A medium quality (0.5) should differ from high (1.0)");
    37     isnot(medQuality, lowQuality, "A medium quality (0.5) should differ from low (0.5)");
    39     var tooHigh = canvas.toDataURL('image/jpeg', 2.0);
    40     is(tooHigh, data, "Quality above 1.0 is treated as unspecified");
    42     var tooLow = canvas.toDataURL('image/jpeg', -1.0);
    43     is(tooLow, data, "Quality below 0.0 is treated as unspecified");
    45     var lowQualityExtra = canvas.toDataURL('image/jpeg', 0.1, 'foo', 'bar', null);
    46     is(lowQualityExtra, lowQuality, "Quality applies even if extra arguments are present");
    48     var lowQualityUppercase = canvas.toDataURL('IMAGE/JPEG', 0.1);
    49     is(lowQualityUppercase, lowQuality, "Quality applies to image/jpeg regardless of case");
    51     var lowQualityString = canvas.toDataURL('image/jpeg', '0.1');
    52     isnot(lowQualityString, lowQuality, "Quality must be a number (should not be a string)");
    53 }
    54 </script>

mercurial