Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / webgl / canvas-to-data-url.html
blob0199b3aba1ec018d8308ddfb20d297c194e648e6
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <canvas id="preserve-canvas3d" width="10" height="10"></canvas>
5 <canvas id="nonpreserve-canvas3d" width="10" height="10"></canvas>
6 <script src="../../../resources/js-test.js"></script>
7 <script>
8 if (window.testRunner) {
9 testRunner.dumpAsText();
10 testRunner.waitUntilDone();
13 var preserve_canvas3D;
14 var nonpreserve_canvas3D;
16 function renderWebGL(gl) {
17 gl.clearColor(0.5, 1, 0.3, 0.1);
18 gl.clear(gl.COLOR_BUFFER_BIT);
21 function asyncTest() {
22 debug("Check if back buffer (toDataURL) is equal to front buffer (getImageSourceURL) one frame after drawing webgl contents.")
23 debug("1) when drawingBuffer is preserved.")
24 shouldBeTrue("preserve_canvas3D.toDataURL('image/png') == window.internals.getImageSourceURL(preserve_canvas3D)");
25 debug("2) when drawingBuffer is not preserved. They must be different.")
26 shouldBeTrue("nonpreserve_canvas3D.toDataURL('image/png') != window.internals.getImageSourceURL(nonpreserve_canvas3D)");
27 if (window.testRunner)
28 testRunner.notifyDone();
31 function startTestAfterFirstPaint() {
32 preserve_canvas3D = document.getElementById('preserve-canvas3d');
33 var preserve_gl = preserve_canvas3D.getContext('webgl', {preserveDrawingBuffer: true, premultipliedAlpha: false});
34 nonpreserve_canvas3D = document.getElementById('nonpreserve-canvas3d');
35 var nonpreserve_gl = nonpreserve_canvas3D.getContext('webgl', {preserveDrawingBuffer: false, premultipliedAlpha: false});
37 // prepare webgl contents.
38 renderWebGL(preserve_gl);
39 renderWebGL(nonpreserve_gl);
41 debug("Check if back buffer (toDataURL) is equal to front buffer (getImageSourceURL)")
42 debug("1) when drawingBuffer is preserved.")
43 shouldBeTrue("preserve_canvas3D.toDataURL('image/png') == window.internals.getImageSourceURL(preserve_canvas3D)");
44 debug("2) when drawingBuffer is not preserved.")
45 shouldBeTrue("nonpreserve_canvas3D.toDataURL('image/png') == window.internals.getImageSourceURL(nonpreserve_canvas3D)");
47 if (window.testRunner) {
48 testRunner.waitUntilDone();
49 testRunner.layoutAndPaintAsyncThen(asyncTest);
50 } else {
51 window.requestAnimationFrame(asyncTest);
55 window.onload = function () {
56 window.requestAnimationFrame(startTestAfterFirstPaint);
58 </script>
59 </body>
60 </html>