5 if (!window.testRunner) {
6 testFailed("Requires window.testRunner");
8 testRunner.waitUntilDone();
9 testRunner.setPrinting();
10 testRunner.dumpAsText();
11 window.requestAnimationFrame(initTest);
16 var testsAndExpectations = [
17 { 'description': 'green', 'clearColor': [0, 1, 0, 1], 'expected': [ 0, 255, 0] },
18 { 'description': 'red', 'clearColor': [1, 0, 0, 1], 'expected': [255, 0, 0] },
19 { 'description': 'blue', 'clearColor': [0, 0, 1, 1], 'expected': [ 0, 0, 255] },
24 var canvas = document.getElementById("c");
27 testFailed("Test requires WebGL");
28 testRunner.notifyDone();
32 window.requestAnimationFrame(nextTest);
36 if (testIndex >= testsAndExpectations.length) {
37 // Without clearing this bit, the output comes out as a render
38 // tree, which is difficult to read.
39 testRunner.clearPrinting();
40 testRunner.notifyDone();
44 var test = testsAndExpectations[testIndex];
45 var color = test['clearColor'];
47 draw(color[0], color[1], color[2], color[3]);
48 testRunner.capturePixelsAsyncThen(completionCallback);
50 debug('error in nextTest');
52 testRunner.notifyDone();
57 function fetchPixelAt(x, y, width, height, snapshot) {
58 var data = new Uint8Array(snapshot);
60 data[4 * (width * y + x) + 0],
61 data[4 * (width * y + x) + 1],
62 data[4 * (width * y + x) + 2],
63 data[4 * (width * y + x) + 3]
67 function completionCallback(width, height, snapshot) {
68 var test = testsAndExpectations[testIndex];
69 debug('Test ' + testIndex + ': canvas should be ' + test['description']);
71 var expectation = test['expected'];
72 fetchPixelAt(50, 50, width, height, snapshot);
73 shouldBeCloseTo('pixel[0]', expectation[0], tolerance);
74 shouldBeCloseTo('pixel[1]', expectation[1], tolerance);
75 shouldBeCloseTo('pixel[2]', expectation[2], tolerance);
77 debug('error in completionCallback');
79 testRunner.notifyDone();
84 window.requestAnimationFrame(nextTest);
87 function draw(r, g, b, a)
89 gl.clearColor(r, g, b, a);
90 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);