3 <script type="text/javascript">
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);
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) {
35 setTimeout(function() {
36 extension.restoreContext();
42 function testContextRestored() {
43 gl = canvas.getContext("experimental-webgl");
44 if (!gl || gl.isContextLost()) {
45 // Might just be blocked because of infobar.
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");
59 window.domAutomationController.send("FAILED");
62 function testQuantityLoss() {
65 var garbageCanvases = [];
67 function createAndDiscardContext() {
70 var c = document.createElement("canvas");
73 garbageCanvases.push(c);
75 var ctx = c.getContext("experimental-webgl");
79 ctx.clear(gl.COLOR_BUFFER_BIT);
81 if (count < iterations) {
82 window.requestAnimationFrame(createAndDiscardContext);
84 // Remove the references to the garbage canvases, then attempt to trigger
86 garbageCanvases = null;
88 window.domAutomationController.setAutomationId(1);
89 alreadySetAutomationId = true;
90 window.domAutomationController.send("LOADED");
92 // Trying to provoke garbage collection through excessive allocations.
93 setInterval(function() {
94 var garbageArray = new Uint8Array(1024 * 1024);
95 garbageArray[0] = 255;
100 createAndDiscardContext();
103 function contextLostTest(kind)
106 case "WEBGL_lose_context": {
107 extension = gl.getExtension("WEBKIT_WEBGL_lose_context") ||
108 gl.getExtension("WEBGL_lose_context");
109 extension.loseContext();
113 // nothing -- the browser test navigates to about:gpucrash and kills
116 case "kill_after_notification":
117 // The browser test waits for notification from the page that it
118 // has been loaded before navigating to about:gpucrash.
119 window.domAutomationController.setAutomationId(1);
120 alreadySetAutomationId = true;
121 window.domAutomationController.send("LOADED");
123 case "forced_quantity_loss":
124 // Test creates many new contexts, forcing the original context to be
125 // lost. Then a garbage collect is triggered and the original context is
126 // watched to ensure it restores properly.
133 canvas = document.getElementById("canvas1");
138 canvas.addEventListener("webglcontextlost", testContextLost, false);
139 canvas.addEventListener("webglcontextrestored", testContextRestored, false);
141 gl = canvas.getContext("experimental-webgl");
145 if (!testHorizontalBands())
148 var query = /query=(.*)/.exec(window.location.href);
150 contextLostTest(query[1]);
154 <body onload="onLoad()">
155 <canvas id="canvas1" width="16px" height="32px">