Chromium Code Reviews| Index: LayoutTests/compositing/webgl/webgl-copy-image.html |
| diff --git a/LayoutTests/compositing/webgl/webgl-copy-image.html b/LayoutTests/compositing/webgl/webgl-copy-image.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9232539dbb88a477e69f7c5627675fc72ce500a1 |
| --- /dev/null |
| +++ b/LayoutTests/compositing/webgl/webgl-copy-image.html |
| @@ -0,0 +1,100 @@ |
| +<!-- This is a test for crbug.com/392765, in which Copy image for |
| + WebGL elements were crashing. Must be run with the threaded |
| + compositor enabled. --> |
| +<head> |
| +<script src="../../resources/js-test.js"></script> |
| +<script> |
| +var gl; |
| + |
| +function main() |
| +{ |
| + if (!window.testRunner) { |
| + testFailed("Requires window.testRunner"); |
| + } else { |
| + testRunner.waitUntilDone(); |
| + testRunner.dumpAsText(); |
| + window.requestAnimationFrame(initTest); |
| + } |
| +} |
| + |
| +var tolerance = 1; |
| + |
| +function initTest() { |
| + var canvas = document.getElementById("c"); |
| + gl = canvas.getContext("webgl"); |
| + if (!gl) { |
| + testFailed("Test requires WebGL"); |
| + testRunner.notifyDone(); |
| + return; |
| + } |
| + |
| + gl.clearColor(1, 0, 0, 1); |
| + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| + |
| + window.requestAnimationFrame(runTest); |
| +} |
| + |
| +var testsAndExpectations = [ |
| + { 'point': [50, 50], 'expected': 'exists' }, |
| + { 'point': [400, 400], 'expected': 'does not exist' } |
| +]; |
| + |
| +var testIndex = 0; |
| +function runTest() { |
| + if (testIndex >= testsAndExpectations.length) { |
| + testRunner.notifyDone(); |
| + return; |
| + } |
| + |
| + try { |
| + var test = testsAndExpectations[testIndex]; |
| + var point = test['point']; |
| + testRunner.copyImageAtAndCapturePixelsAsyncThen(point[0], point[1], completionCallback); |
| + } catch (e) { |
| + debug('error in runTest'); |
| + debug(e); |
| + testRunner.notifyDone(); |
| + } |
| +} |
| + |
| +var pixel; |
| +function fetchPixelAt(x, y, width, height, snapshot) { |
| + var data = new Uint8Array(snapshot); |
| + pixel = [ |
| + data[4 * (width * y + x) + 0], |
| + data[4 * (width * y + x) + 1], |
| + data[4 * (width * y + x) + 2], |
| + data[4 * (width * y + x) + 3] |
| + ]; |
| +} |
| + |
| +function completionCallback(width, height, snapshot) { |
| + try { |
| + var test = testsAndExpectations[testIndex]; |
| + var point = test['point']; |
| + debug('Test ' + testIndex + ": WebGL element " + test['expected'] + ' at ' + point); |
| + |
| + if (width > 0 && height > 0) { |
|
Ken Russell (switch to Gerrit)
2014/07/17 21:32:31
This doesn't actually verify that the attempt to f
hj.r.chung
2014/07/18 06:31:39
Done.
|
| + fetchPixelAt(50, 50, width, height, snapshot); |
| + shouldBeCloseTo('pixel[0]', 255, tolerance); |
| + shouldBeCloseTo('pixel[1]', 0, tolerance); |
| + shouldBeCloseTo('pixel[2]', 0, tolerance); |
| + } |
| + } catch (e) { |
| + debug('error in completionCallback'); |
| + debug(e); |
| + testRunner.notifyDone(); |
| + return; |
| + } |
| + |
| + ++testIndex; |
| + window.requestAnimationFrame(runTest); |
| +} |
| + |
| +main(); |
| +</script> |
| +</head> |
| +<body> |
| +<canvas id="c" width="200" height="200" class="nomargin"></canvas> |
| +<div id="console"></div> |
| +</body> |