1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
content / test / data / gpu / webgl-domain-not-blocked.html [blame]
<html>
<head>
<script type="text/javascript">
var kSize = 16;
var contextLost = false;
function onLoad() {
var canvas = createNewCanvas();
var gl = canvas.getContext('webgl');
if (!gl || !clearAndValidate(gl, 1, 0, 0))
window.domAutomationController.send("FAILED");
canvas.addEventListener('webglcontextlost', (event) => {
event.preventDefault();
contextLost = true;
});
canvas.addEventListener('webglcontextrestored', () => {
// Using the original WebGL context after restoring should succeed.
if (clearAndValidate(gl, 0, 1, 0))
window.domAutomationController.send("SUCCESS");
else
window.domAutomationController.send("FAILED");
});
window.domAutomationController.send("LOADED");
}
function createNewCanvas() {
var canvas = document.createElement('canvas');
canvas.width = kSize;
canvas.height = kSize;
document.body.appendChild(canvas);
return canvas;
}
function clearAndValidate(gl, r, g, b) {
gl.clearColor(r, g, b, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
var pixels = new Uint8Array(kSize * kSize * 4);
gl.readPixels(0, 0, kSize, kSize, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
return pixels[0] == r * 255 && pixels[1] == g * 255 &&
pixels[2] == b * 255 && pixels[3] == 255;
}
function testNewWebGLContext() {
// Reset the success/failure code that onLoad() may have set.
window.domAutomationController.reset();
var canvas = createNewCanvas();
var gl = canvas.getContext('webgl');
if (gl != null && clearAndValidate(gl, 0, 0, 1))
window.domAutomationController.send("SUCCESS");
else
window.domAutomationController.send("FAILED");
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>