Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / dom / canvas / test / test_toDataURL_parameters.html
blobb288e4d329ea48a5ba38bb9144a3e398e004b70b
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 and webp 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 let canvas = document.getElementById('c');
13 let 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 let pngData = canvas.toDataURL('image/png');
24 let pngQuality = canvas.toDataURL('image/png', 0.1);
25 is(pngQuality, pngData, "Quality is not supported for PNG images");
27 function checkType(imagetype) {
28 let imageTypeString = 'image/' + imagetype;
29 let imageTypeUpperString = 'IMAGE/' + imagetype.toUpperCase();
30 let data = canvas.toDataURL(imageTypeString);
31 if (data.match(new RegExp('^data:image\/' + imagetype + '[;,]'))) {
32 // Test the JPEG/wepb quality parameter
34 let fullQuality = canvas.toDataURL(imageTypeString, 1.0);
35 let lowQuality = canvas.toDataURL(imageTypeString, 0.1);
36 isnot(lowQuality, fullQuality, "A low quality (0.1) should differ from high quality (1.0) " + imageTypeString);
38 let medQuality = canvas.toDataURL(imageTypeString, 0.5);
39 isnot(medQuality, fullQuality, "A medium quality (0.5) should differ from high (1.0) " + imageTypeString);
40 isnot(medQuality, lowQuality, "A medium quality (0.5) should differ from low (0.5) " + imageTypeString);
42 let tooHigh = canvas.toDataURL(imageTypeString, 2.0);
43 is(tooHigh, data, "Quality above 1.0 is treated as unspecified " + imageTypeString);
45 let tooLow = canvas.toDataURL(imageTypeString, -1.0);
46 is(tooLow, data, "Quality below 0.0 is treated as unspecified " + imageTypeString);
48 let lowQualityExtra = canvas.toDataURL(imageTypeString, 0.1, 'foo', 'bar', null);
49 is(lowQualityExtra, lowQuality, "Quality applies even if extra arguments are present " + imageTypeString);
51 let lowQualityUppercase = canvas.toDataURL(imageTypeUpperString, 0.1);
52 is(lowQualityUppercase, lowQuality, "Quality applies to " + imageTypeString + " regardless of case");
54 let lowQualityString = canvas.toDataURL(imageTypeString, '0.1');
55 isnot(lowQualityString, lowQuality, "Quality must be a number (should not be a string) " + imageTypeString);
56 } else {
57 ok(false, "should get a data url " + imageTypeString);
61 checkType('jpeg');
62 checkType('webp');
63 </script>