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 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Canvas test: toDataURL parameters (Bug 564388)</title> |
michael@0 | 5 | <script src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" href="/tests/SimpleTest/test.css"> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <p> |
michael@0 | 10 | For image types that do not support an alpha channel, the image must be |
michael@0 | 11 | composited onto a solid black background using the source-over operator, |
michael@0 | 12 | and the resulting image must be the one used to create the data: URL. |
michael@0 | 13 | </p> |
michael@0 | 14 | <p> See: |
michael@0 | 15 | <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-canvas-todataurl"> |
michael@0 | 16 | http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-canvas-todataurl |
michael@0 | 17 | </a> |
michael@0 | 18 | </p> |
michael@0 | 19 | <p>Mozilla |
michael@0 | 20 | <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=650720">Bug 650720</a> |
michael@0 | 21 | </p> |
michael@0 | 22 | <p class="output">Output:</p> |
michael@0 | 23 | <!-- |
michael@0 | 24 | Author's note: |
michael@0 | 25 | To add more cases to this test: |
michael@0 | 26 | - To add a row (another color value) |
michael@0 | 27 | * Add a row to the table below, using the canvas id format |
michael@0 | 28 | (c<row>-<col>) |
michael@0 | 29 | * Update runTests to include the new row in the loop |
michael@0 | 30 | - To add a column (another image format) |
michael@0 | 31 | * Add a column to the table below, using the canvas id format above |
michael@0 | 32 | * Update runTests to call do_canvas, passing your column number, |
michael@0 | 33 | the image format, and any options to pass to the toDataUrl function |
michael@0 | 34 | |
michael@0 | 35 | Vaguely derived from Philip Taylor's toDataURL.jpeg.alpha test: |
michael@0 | 36 | http://philip.html5.org/tests/canvas/suite/tests/toDataURL.jpeg.alpha.html |
michael@0 | 37 | --> |
michael@0 | 38 | <table> |
michael@0 | 39 | <tr> |
michael@0 | 40 | <th>Type:</th> |
michael@0 | 41 | <th>image/png</th> |
michael@0 | 42 | <th>image/jpeg</th> |
michael@0 | 43 | <th>image/bmp<br />(24 bpp)</th> |
michael@0 | 44 | <th>image/bmp<br />(32 bpp)</th> |
michael@0 | 45 | </tr> |
michael@0 | 46 | <tr> |
michael@0 | 47 | <td id="c1">rgba(128, 255, 128, 0.5)</td> |
michael@0 | 48 | <td><canvas id="c1-1" class="output" width="100" height="50"> |
michael@0 | 49 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 50 | <td><canvas id="c1-2" class="output" width="100" height="50"> |
michael@0 | 51 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 52 | <td><canvas id="c1-3" class="output" width="100" height="50"> |
michael@0 | 53 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 54 | <td><canvas id="c1-4" class="output" width="100" height="50"> |
michael@0 | 55 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 56 | </tr> |
michael@0 | 57 | <tr> |
michael@0 | 58 | <td id="c2">rgba(255, 128, 128, 0.75)</td> |
michael@0 | 59 | <td><canvas id="c2-1" class="output" width="100" height="50"> |
michael@0 | 60 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 61 | <td><canvas id="c2-2" class="output" width="100" height="50"> |
michael@0 | 62 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 63 | <td><canvas id="c2-3" class="output" width="100" height="50"> |
michael@0 | 64 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 65 | <td><canvas id="c2-4" class="output" width="100" height="50"> |
michael@0 | 66 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 67 | </tr> |
michael@0 | 68 | <tr> |
michael@0 | 69 | <td id="c3">rgba(128, 128, 255, 0.25)</td> |
michael@0 | 70 | <td><canvas id="c3-1" class="output" width="100" height="50"> |
michael@0 | 71 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 72 | <td><canvas id="c3-2" class="output" width="100" height="50"> |
michael@0 | 73 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 74 | <td><canvas id="c3-3" class="output" width="100" height="50"> |
michael@0 | 75 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 76 | <td><canvas id="c3-4" class="output" width="100" height="50"> |
michael@0 | 77 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 78 | </tr> |
michael@0 | 79 | <tr> |
michael@0 | 80 | <td id="c4">rgba(255, 255, 255, 1.0)</td> |
michael@0 | 81 | <td><canvas id="c4-1" class="output" width="100" height="50"> |
michael@0 | 82 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 83 | <td><canvas id="c4-2" class="output" width="100" height="50"> |
michael@0 | 84 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 85 | <td><canvas id="c4-3" class="output" width="100" height="50"> |
michael@0 | 86 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 87 | <td><canvas id="c4-4" class="output" width="100" height="50"> |
michael@0 | 88 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 89 | </tr> |
michael@0 | 90 | <tr> |
michael@0 | 91 | <td id="c5">rgba(255, 255, 255, 0)</td> |
michael@0 | 92 | <td><canvas id="c5-1" class="output" width="100" height="50"> |
michael@0 | 93 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 94 | <td><canvas id="c5-2" class="output" width="100" height="50"> |
michael@0 | 95 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 96 | <td><canvas id="c5-3" class="output" width="100" height="50"> |
michael@0 | 97 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 98 | <td><canvas id="c5-4" class="output" width="100" height="50"> |
michael@0 | 99 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 100 | </tr> |
michael@0 | 101 | <tr> |
michael@0 | 102 | <td id="c6">rgba(0, 0, 0, 1.0)</td> |
michael@0 | 103 | <td><canvas id="c6-1" class="output" width="100" height="50"> |
michael@0 | 104 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 105 | <td><canvas id="c6-2" class="output" width="100" height="50"> |
michael@0 | 106 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 107 | <td><canvas id="c6-3" class="output" width="100" height="50"> |
michael@0 | 108 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 109 | <td><canvas id="c6-4" class="output" width="100" height="50"> |
michael@0 | 110 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 111 | </tr> |
michael@0 | 112 | <tr> |
michael@0 | 113 | <td id="c7">rgba(0, 0, 0, 0)</td> |
michael@0 | 114 | <td><canvas id="c7-1" class="output" width="100" height="50"> |
michael@0 | 115 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 116 | <td><canvas id="c7-2" class="output" width="100" height="50"> |
michael@0 | 117 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 118 | <td><canvas id="c7-3" class="output" width="100" height="50"> |
michael@0 | 119 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 120 | <td><canvas id="c7-4" class="output" width="100" height="50"> |
michael@0 | 121 | <p class="fallback">FAIL (fallback content)</p></canvas></td> |
michael@0 | 122 | </tr> |
michael@0 | 123 | </table> |
michael@0 | 124 | |
michael@0 | 125 | <script> |
michael@0 | 126 | var finishedTests = []; |
michael@0 | 127 | |
michael@0 | 128 | function isPixel(ctx, x,y, r,g,b,a, d) |
michael@0 | 129 | { |
michael@0 | 130 | var pos = x + "," + y; |
michael@0 | 131 | var colour = r + "," + g + "," + b + "," + a; |
michael@0 | 132 | var pixel = ctx.getImageData(x, y, 1, 1); |
michael@0 | 133 | var pr = pixel.data[0], |
michael@0 | 134 | pg = pixel.data[1], |
michael@0 | 135 | pb = pixel.data[2], |
michael@0 | 136 | pa = pixel.data[3]; |
michael@0 | 137 | ok(r-d <= pr && pr <= r+d && |
michael@0 | 138 | g-d <= pg && pg <= g+d && |
michael@0 | 139 | b-d <= pb && pb <= b+d && |
michael@0 | 140 | a-d <= pa && pa <= a+d, |
michael@0 | 141 | "pixel "+pos+" of "+ctx.canvas.id+" is "+pr+","+pg+","+pb+","+pa+ |
michael@0 | 142 | "; expected "+colour+" +/- "+d); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | function do_canvas(row, col, type, options) |
michael@0 | 147 | { |
michael@0 | 148 | finishedTests[row + '_' + col] = false; |
michael@0 | 149 | var canvas = document.getElementById('c' + row + '-' + col); |
michael@0 | 150 | var ctx = canvas.getContext('2d'); |
michael@0 | 151 | |
michael@0 | 152 | ctx.fillStyle = document.getElementById('c' + row).textContent; |
michael@0 | 153 | ctx.fillRect(0, 0, 100, 50); |
michael@0 | 154 | var data = canvas.toDataURL(type, options); |
michael@0 | 155 | |
michael@0 | 156 | ctx.fillStyle = '#000'; |
michael@0 | 157 | ctx.fillRect(0, 0, 100, 50); |
michael@0 | 158 | var img = new Image(); |
michael@0 | 159 | |
michael@0 | 160 | var color = document.getElementById('c' + row).textContent; |
michael@0 | 161 | color = color.substr(5, color.length - 6); // strip off the 'argb()' |
michael@0 | 162 | var colors = color.replace(' ', '', 'g').split(','); |
michael@0 | 163 | var r = colors[0]*colors[3], |
michael@0 | 164 | g = colors[1]*colors[3], |
michael@0 | 165 | b = colors[2]*colors[3]; |
michael@0 | 166 | |
michael@0 | 167 | img.onload = function () |
michael@0 | 168 | { |
michael@0 | 169 | ctx.drawImage(img, 0, 0); |
michael@0 | 170 | isPixel(ctx, 50,25, r,g,b,255, 8); |
michael@0 | 171 | finishedTests[row + '_' + col] = true; |
michael@0 | 172 | }; |
michael@0 | 173 | img.src = data; |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | function checkFinished() |
michael@0 | 177 | { |
michael@0 | 178 | for (var t in finishedTests) { |
michael@0 | 179 | if (!finishedTests[t]) { |
michael@0 | 180 | setTimeout(checkFinished, 500); |
michael@0 | 181 | return; |
michael@0 | 182 | } |
michael@0 | 183 | } |
michael@0 | 184 | SimpleTest.finish(); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | function runTests() |
michael@0 | 188 | { |
michael@0 | 189 | for (var row = 1; row <= 7; row++) { |
michael@0 | 190 | do_canvas(row, 1, 'image/png'); |
michael@0 | 191 | do_canvas(row, 2, 'image/jpeg'); |
michael@0 | 192 | do_canvas(row, 3, 'image/bmp'); |
michael@0 | 193 | do_canvas(row, 4, 'image/bmp', '-moz-parse-options:bpp=32'); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | setTimeout(checkFinished, 500); |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 200 | |
michael@0 | 201 | addLoadEvent(runTests); |
michael@0 | 202 | |
michael@0 | 203 | </script> |
michael@0 | 204 | |
michael@0 | 205 | </html> |