Get foreground tab on Android
[chromium-blink-merge.git] / content / test / data / gpu / webgl.html
blob001c569a0f457b979187f97d3bfab811261d58d1
1 <html>
2 <head>
3 <script type="text/javascript">
4 var canvas;
5 var w, h;
6 var gl;
7 var extension;
9 var alreadySetAutomationId = false;
11 function testHorizontalBands() {
12 gl.enable(gl.SCISSOR_TEST);
14 gl.clearColor(1, 0, 0, 1);
15 gl.scissor(0, 0, w, h/2);
16 gl.clear(gl.COLOR_BUFFER_BIT);
18 gl.clearColor(0, 1, 0, 1);
19 gl.scissor(0, h/2, w, h/2);
20 gl.clear(gl.COLOR_BUFFER_BIT);
22 gl.disable(gl.SCISSOR_TEST);
24 var size = w * h * 4;
25 var array = new Uint8Array(size);
26 gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, array);
28 return array[0] == 255 && array[1] == 0 &&
29 array[size - 4] == 0 && array[size - 3] == 255;
32 function testContextLost(e) {
33 e.preventDefault();
34 if (extension) {
35 setTimeout(function() {
36 extension.restoreContext();
37 extension = null;
38 }, 0);
42 function testContextRestored() {
43 gl = canvas.getContext("experimental-webgl");
44 if (!gl || gl.isContextLost()) {
45 // Might just be blocked because of infobar.
46 return;
48 gl.clearColor(0, 0, 1, 1);
49 gl.clear(gl.COLOR_BUFFER_BIT);
51 var a = new Uint8Array(w * h * 4);
52 gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, a);
54 if (!alreadySetAutomationId)
55 window.domAutomationController.setAutomationId(1);
56 if (a[0] == 0 && a[1] == 0 && a[2] == 255)
57 window.domAutomationController.send("SUCCESS");
58 else
59 window.domAutomationController.send("FAILED");
62 function contextLostTest(kind)
64 switch (kind) {
65 case "WEBGL_lose_context": {
66 extension = gl.getExtension("WEBKIT_WEBGL_lose_context") ||
67 gl.getExtension("WEBGL_lose_context");
68 extension.loseContext();
69 break;
71 case "kill":
72 // nothing -- the browser test navigates to about:gpucrash and kills
73 // the GPU process.
74 break;
75 case "kill_after_notification":
76 // The browser test waits for notification from the page that it
77 // has been loaded before navigating to about:gpucrash.
78 window.domAutomationController.setAutomationId(1);
79 alreadySetAutomationId = true;
80 window.domAutomationController.send("LOADED");
81 break;
85 function onLoad() {
86 canvas = document.getElementById("canvas1");
87 w = canvas.width;
88 h = canvas.height;
89 if (!canvas)
90 return;
91 canvas.addEventListener("webglcontextlost", testContextLost, false);
92 canvas.addEventListener("webglcontextrestored", testContextRestored, false);
94 gl = canvas.getContext("experimental-webgl");
95 if (!gl)
96 return;
98 if (!testHorizontalBands())
99 return;
101 var query = /query=(.*)/.exec(window.location.href);
102 if (query)
103 contextLostTest(query[1]);
105 </script>
106 </head>
107 <body onload="onLoad()">
108 <canvas id="canvas1" width="16px" height="32px">
109 </canvas>
110 </body>
111 </html>