1 <!-- This is a regression test for crbug.com/351956, in which printing
2 of Google Maps was broken. In order to catch the regression it
3 must be run with the threaded compositor enabled. -->
5 <script src="../resources/js-test.js"></script>
11 if (!window.testRunner) {
12 testFailed("Requires window.testRunner");
14 testRunner.waitUntilDone();
15 testRunner.setPrinting();
16 testRunner.dumpAsText();
17 window.requestAnimationFrame(initTest);
22 var testsAndExpectations = [
23 { 'description': 'green', 'clearColor': [0, 1, 0, 1], 'expected': [ 0, 255, 0] },
24 { 'description': 'red', 'clearColor': [1, 0, 0, 1], 'expected': [255, 0, 0] },
25 { 'description': 'blue', 'clearColor': [0, 0, 1, 1], 'expected': [ 0, 0, 255] },
30 var canvas = document.getElementById("c");
33 testFailed("Test requires WebGL");
34 testRunner.notifyDone();
38 window.requestAnimationFrame(nextTest);
42 if (testIndex >= testsAndExpectations.length) {
43 // Without clearing this bit, the output comes out as a render
44 // tree, which is difficult to read.
45 testRunner.clearPrinting();
46 testRunner.notifyDone();
50 var test = testsAndExpectations[testIndex];
51 var color = test['clearColor'];
53 draw(color[0], color[1], color[2], color[3]);
54 testRunner.capturePixelsAsyncThen(completionCallback);
56 debug('error in nextTest');
58 testRunner.notifyDone();
63 function fetchPixelAt(x, y, width, height, snapshot) {
64 var data = new Uint8Array(snapshot);
66 data[4 * (width * y + x) + 0],
67 data[4 * (width * y + x) + 1],
68 data[4 * (width * y + x) + 2],
69 data[4 * (width * y + x) + 3]
73 function completionCallback(width, height, snapshot) {
74 var test = testsAndExpectations[testIndex];
75 debug('Test ' + testIndex + ': canvas should be ' + test['description']);
77 var expectation = test['expected'];
78 fetchPixelAt(50, 50, width, height, snapshot);
79 shouldBeCloseTo('pixel[0]', expectation[0], tolerance);
80 shouldBeCloseTo('pixel[1]', expectation[1], tolerance);
81 shouldBeCloseTo('pixel[2]', expectation[2], tolerance);
83 debug('error in completionCallback');
85 testRunner.notifyDone();
90 window.requestAnimationFrame(nextTest);
93 function initGL(canvas)
96 gl = canvas.getContext("webgl");
101 function draw(r, g, b, a)
103 gl.clearColor(r, g, b, a);
104 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
111 <canvas id="c" width="200" height="200" class="nomargin"></canvas>
112 <div id="console"></div>