Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / compositing / webgl / webgl-copy-image.html
blobd934006f5673e3477d17cc1d9b544e937795677a
1 <!-- This is a test for crbug.com/392765, in which Copy image for
2 WebGL elements were crashing. Must be run with the threaded
3 compositor enabled. -->
4 <head>
5 <script src="../../resources/js-test.js"></script>
6 <script>
8 function main()
10 if (!window.testRunner) {
11 testFailed("Requires window.testRunner");
12 } else {
13 testRunner.waitUntilDone();
14 testRunner.dumpAsText();
15 window.requestAnimationFrame(initTest);
19 var tolerance = 1;
21 function initTest() {
22 var canvas = document.getElementById("c");
23 var gl = canvas.getContext("webgl");
24 if (!gl) {
25 testFailed("Test requires WebGL");
26 testRunner.notifyDone();
27 return;
30 gl.clearColor(1, 0, 0, 1);
31 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
33 window.requestAnimationFrame(runTest);
36 function runTest() {
37 try {
38 testRunner.copyImageAtAndCapturePixelsAsyncThen(50, 50, completionCallback);
39 } catch (e) {
40 debug('error in runTest');
41 debug(e);
42 testRunner.notifyDone();
46 var pixel;
47 function fetchPixelAt(x, y, width, height, snapshot) {
48 var data = new Uint8Array(snapshot);
49 pixel = [
50 data[4 * (width * y + x) + 0],
51 data[4 * (width * y + x) + 1],
52 data[4 * (width * y + x) + 2],
53 data[4 * (width * y + x) + 3]
57 function completionCallback(width, height, snapshot) {
58 try {
59 fetchPixelAt(50, 50, width, height, snapshot);
60 shouldBeCloseTo('pixel[0]', 255, tolerance);
61 shouldBeCloseTo('pixel[1]', 0, tolerance);
62 shouldBeCloseTo('pixel[2]', 0, tolerance);
63 } catch (e) {
64 debug('error in completionCallback');
65 debug(e);
66 testRunner.notifyDone();
67 return;
69 testRunner.notifyDone();
72 main();
73 </script>
74 </head>
75 <body>
76 <canvas id="c" width="200" height="200" class="nomargin"></canvas>
77 <div id="console"></div>
78 </body>