| <!DOCTYPE html> |
| <canvas id='canvas'></canvas> |
| <script> |
| var canvas = document.getElementById('canvas'); |
| canvas.width = canvas.height = 100; |
| var offscreenContext = canvas.transferControlToOffscreen().getContext( |
| "webgl", {preserveDrawingBuffer: true}); |
| offscreenContext.clearColor(0, 1, 0, 1); |
| offscreenContext.clear(offscreenContext.COLOR_BUFFER_BIT); |
| var pixel = new Uint8Array(4); |
| |
| // Make sure that the canvas has been drawn to before capturing |
| function waitForCanvasToDraw() { |
| return new Promise(resolve => { |
| var testPixel = function() { |
| offscreenContext.readPixels(0, 0, 1, 1, |
| offscreenContext.RGBA, offscreenContext.UNSIGNED_BYTE, pixel); |
| var greenChannel = pixel[1]; |
| if (greenChannel != 255) { // The green channel |
| requestAnimationFrame(testPixel); |
| return; |
| } else { |
| resolve(); |
| } |
| } |
| testPixel(); |
| }); |
| } |
| |
| if (window.testRunner) |
| { |
| testRunner.setPrinting(); |
| testRunner.waitUntilDone(); |
| waitForCanvasToDraw().then(() => { |
| // Wait for all testRunner javascript to complete |
| window.setTimeout(() => { |
| testRunner.notifyDone() |
| }, 0); |
| }); |
| } |
| </script> |