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