Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / toDataURL-alpha-stability.html
blob3b3ea3e717e6068b70d5c218727a086a846187cd
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <style>
5 canvas { padding: 3px; padding-bottom: 0px;}
6 </style>
8 <script>
9 var autoTest = false;
11 if (window.testRunner) {
12 window.testRunner.dumpAsTextWithPixelResults();
13 window.testRunner.waitUntilDone();
14 autoTest = true;
17 function logMessage(message)
19 document.getElementById('log').textContent += '\n' + message;
22 function logPixel(canvasContext, x, y)
24 var p = canvasContext.getImageData(x, y, 1, 1).data;
25 logMessage('rgba(' + [p[0], p[1], p[2], p[3]] + ')');
28 function appendNewCanvasElementTo(parentId, canvasId)
30 var canvas = document.createElement('canvas');
31 canvas.width = canvas.height = 64;
32 document.getElementById(parentId).appendChild(canvas);
33 canvas.id = canvasId;
34 return canvas;
37 function canvasTest(item, mimeType)
39 var previousCanvas = document.getElementById('c' + (item - 1));
41 var img = new Image();
42 img.onload = function() {
43 var canvas = appendNewCanvasElementTo('list', 'c' + item);
44 var context = canvas.getContext('2d');
45 context.drawImage(this, 0, 0);
46 if (!window.testRunner)
47 logPixel(context, 25, 25);
48 if (autoTest)
49 setTimeout(test, 0);
52 img.src = previousCanvas.toDataURL(mimeType);
55 function load()
57 var list = document.getElementById('list');
58 var log = document.getElementById('log');
59 list.innerHTML = log.innerHTML = '';
61 var select = document.getElementById('alpha');
62 var alpha = Number(select.value).toFixed(3);
63 select.onchange = function() { load(); };
65 var canvas = appendNewCanvasElementTo('list', 'c0');
66 var context = canvas.getContext('2d');
67 context.fillStyle = 'rgba(0, 64, 0, ' + alpha + ')';
68 context.fillRect(0, 0, 64, 64);
69 canvas.style.display = 'none';
71 if (window.testRunner) {
72 document.getElementById('instructions').style.display = 'none';
73 } else {
74 logMessage('alpha ' + alpha);
77 nextItem = 1;
78 if (autoTest)
79 test();
82 function test()
84 if (autoTest && nextItem > 70) {
85 if (window.testRunner)
86 window.testRunner.notifyDone();
87 return;
90 canvasTest(nextItem, 'image/png');
91 ++nextItem;
93 </script>
94 </head>
96 <body onload='load()'>
97 <p id='instructions'>
98 Back-to-back canvas alpha image/png encode decode <button onclick='test()'>Test</button> alpha
99 <input id='alpha' type='text' value='0.5'>
100 </p>
101 <ul id='list'></ul>
102 <pre id='log'></pre>
103 </body>
105 </html>