OLD | NEW |
1 <canvas id="canvas" width="64px" height="64px" style="display: none"></canvas> | 1 <canvas id="canvas" width="64px" height="64px" style="display: none"></canvas> |
| 2 <!-- The <img> background color should be visible behind the html5.png test imag
e (the test |
| 3 image has an alpha channel, which should be preserved by the webp toDataURL en
coder). --> |
| 4 <img id="result" style="background-color: green"> |
2 <pre id="log"></pre> | 5 <pre id="log"></pre> |
3 <img id="result"> | 6 |
4 <script> | 7 <script> |
5 if (window.testRunner) { | 8 if (window.testRunner) { |
6 window.testRunner.dumpAsTextWithPixelResults(); | 9 window.testRunner.dumpAsTextWithPixelResults(); |
7 window.testRunner.waitUntilDone(); | 10 window.testRunner.waitUntilDone(); |
8 } | 11 } |
9 | 12 |
10 function webpDataURLTest() | 13 var image = new Image(); |
11 { | 14 image.onload = function() { |
12 var canvas = document.getElementById('canvas'); | 15 var canvas = document.getElementById('canvas'); |
13 var context = canvas.getContext('2d'); | 16 canvas.getContext('2d').drawImage(this, 0, 0, canvas.width, canvas.height); |
14 context.drawImage(window.image, 0, 0, canvas.width, canvas.height); | |
15 | 17 |
16 var dataURL = canvas.toDataURL('image/webp', 0.8); | 18 var dataURL = canvas.toDataURL('image/webp', 0.8); |
| 19 |
17 if (!dataURL.match(/^data:image\/webp[;,]/)) | 20 if (!dataURL.match(/^data:image\/webp[;,]/)) |
18 document.getElementById('log').textContent += "FAIL: canvas.toDataURL('i
mage/webp') not supported"; | 21 document.getElementById('log').textContent += "FAIL: the dataURL should
have 'image/webp' type."; |
19 else | 22 else |
20 document.getElementById('result').src = dataURL; | 23 document.getElementById('result').src = dataURL; |
21 | 24 |
22 if (window.testRunner) | 25 if (window.testRunner) |
23 window.testRunner.notifyDone(); | 26 window.testRunner.notifyDone(); |
24 } | 27 }; |
25 | 28 |
26 var image = new Image(); | |
27 image.onload = webpDataURLTest; | |
28 image.src = 'resources/html5.png'; | 29 image.src = 'resources/html5.png'; |
29 </script> | 30 </script> |
OLD | NEW |