Chromium Code Reviews| Index: content/test/data/screenshot_sync.html |
| diff --git a/content/test/data/screenshot_sync.html b/content/test/data/screenshot_sync.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2b1d0074b0500251793e150ac9c49e912b585a53 |
| --- /dev/null |
| +++ b/content/test/data/screenshot_sync.html |
| @@ -0,0 +1,121 @@ |
| +<!DOCTYPE html> |
|
bajones
2013/09/26 22:27:23
This test spins through random color clears on a c
|
| +<html> |
| +<head> |
| +<title>Synchronized screenshot test</title> |
| +<style> |
| + html, body { margin: 0; } |
| + #log { height: 150px; overflow: auto; width: 512px; } |
| + #log.failed { background-color: #FFAAAA; } |
| +</style> |
| +</head> |
| +<body> |
| + <canvas id="src-canvas" width="256" height="256"></canvas> |
| + <canvas id="dest-canvas" width="256" height="256"></canvas><br/> |
| + <div id="log"></div> |
| + |
| + <script> |
| + "use strict"; |
| + |
| + (function () { |
| + var log = document.getElementById("log"); |
| + var canvas1 = document.getElementById("src-canvas"); |
| + var canvas2 = document.getElementById("dest-canvas"); |
| + |
| + if (!window.chrome || !window.chrome.gpuBenchmarking || |
| + !window.chrome.gpuBenchmarking.beginWindowSnapshotPNG) { |
| + canvas1.style.display = "none"; |
| + canvas2.style.display = "none"; |
| + log.innerHTML = "chrome.gpuBenchmarking.beginWindowSnapshotPNG not available.<br/>" + |
| + "Please make sure Chrome was launched with --enable-gpu-benchmarking." |
| + return; |
| + } |
| + |
| + var totalTests = 100; |
| + var testInterval = 75; |
| + var testStartDelay = 1000; |
| + var testCount = 0; |
| + var allPassed = true; |
| + |
| + var ctx1 = canvas1.getContext("2d"); |
| + var ctx2 = canvas2.getContext("2d"); |
| + |
| + var clearColor = [0, 0, 0]; |
| + var screenshotClearColor = [0, 0, 0]; |
| + var validatedColor = [0, 0, 0]; |
| + function draw() { |
| + if (testCount == totalTests || !allPassed) |
| + return; |
| + |
| + clearColor[0] = Math.floor(Math.random() * 256.0); |
| + clearColor[1] = Math.floor(Math.random() * 256.0); |
| + clearColor[2] = Math.floor(Math.random() * 256.0); |
| + |
| + ctx1 |
| + ctx1.fillStyle="RGB(" + |
| + clearColor[0] + "," + |
| + clearColor[1] + "," + |
| + clearColor[2] + ")"; |
| + ctx1.fillRect(0,0,canvas1.width,canvas1.height); |
| + |
| + window.requestAnimationFrame(draw); |
| + }; |
| + draw(); |
| + |
| + var snapshotImg = new Image(); |
| + var snapshotBtn = document.getElementById("snapshot"); |
| + var snapshotColorSpan = document.getElementById("snapshotColorSpan"); |
| + var validatedColorSpan = document.getElementById("validatedColorSpan"); |
| + |
| + |
| + function colorsMatch(a, b) { |
| + return (Math.abs(a[0] - b[0]) < 2 && |
| + Math.abs(a[1] - b[1]) < 2 && |
| + Math.abs(a[2] - b[2]) < 2); |
| + } |
| + |
| + function logTest(id, a, b) { |
| + var entry = document.createElement("div"); |
| + var match = colorsMatch(a, b); |
| + entry.innerHTML = "Test " + id + ": " + |
| + "[" + a[0] +", " + a[1] +", " + a[2] +"] " + |
| + "~= " + |
| + "[" + b[0] +", " + b[1] +", " + b[2] +"] " + |
| + ": " + |
| + (match ? "<b style='color: green'>Pass</b>" : "<b style='color: red'>Fail</b>"); |
| + log.insertBefore(entry, log.firstChild); |
| + return match; |
| + } |
| + |
| + // Take snapshots at an arbitrary interval and ensure that the resulting |
| + // image matches the color we last cleared the webgl canvas with |
| + function testSnapshot() { |
| + ++testCount; |
| + |
| + screenshotClearColor[0] = clearColor[0]; |
| + screenshotClearColor[1] = clearColor[1]; |
| + screenshotClearColor[2] = clearColor[2]; |
| + |
| + window.chrome.gpuBenchmarking.beginWindowSnapshotPNG( |
| + function(s) { |
| + snapshotImg.src = "data:image/png;base64," + s.data; |
| + ctx2.drawImage(snapshotImg,0,0); |
| + |
| + var img_data = ctx2.getImageData(0, 0, 1, 1); |
| + validatedColor[0] = img_data.data[0]; |
| + validatedColor[1] = img_data.data[1]; |
| + validatedColor[2] = img_data.data[2]; |
| + |
| + allPassed = allPassed && logTest(testCount, screenshotClearColor, validatedColor); |
| + if (!allPassed) |
| + log.classList.add("failed"); |
| + |
| + if (testCount < totalTests || !allPassed) |
| + setTimeout(testSnapshot, testInterval); |
| + } |
| + ); |
| + } |
| + setTimeout(testSnapshot, testStartDelay); |
| + })(); |
| + </script> |
| + </body> |
| +</html> |