Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / webgl / context-lost-restored.html
blob906ea435f0c828265833c7d69c48d7bb8e094dc9
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 <script src="resources/webgl-test.js"></script>
6 <script src="resources/webgl-test-utils.js"></script>
7 <script>
8 if (window.internals)
9 window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
11 var wtu = WebGLTestUtils;
12 var canvas;
13 var gl;
14 var shouldGenerateGLError;
15 var extension;
16 var bufferObjects;
17 var program;
18 var texture;
19 var texColor = [255, 10, 20, 255];
20 var allowRestore;
21 var contextLostEventFired;
22 var contextRestoredEventFired;
24 function init()
26 if (window.initNonKhronosFramework) {
27 window.initNonKhronosFramework(true);
30 description("Tests behavior under a restored context.");
32 shouldGenerateGLError = wtu.shouldGenerateGLError;
33 testLosingContext();
36 function setupTest()
38 canvas = document.createElement("canvas");
39 canvas.width = 1;
40 canvas.height = 1;
41 gl = wtu.create3DContext(canvas);
42 extension = gl.getExtension("WEBGL_lose_context");
43 if (!extension) {
44 debug("Could not find lose_context extension under the following names: WEBGL_lose_context");
45 return false;
47 return true;
50 function testLosingContext()
52 if (!setupTest())
53 finishTest();
55 debug("Test losing a context and inability to restore it.");
57 canvas.addEventListener("webglcontextlost", function(e) {
58 testLostContext(e);
59 // restore the context after this event has exited.
60 setTimeout(function() {
61 // we didn't call prevent default so we should not be able to restore the context
62 shouldGenerateGLError(gl, gl.INVALID_OPERATION, "extension.restoreContext()");
63 testLosingAndRestoringContext();
64 }, 0);
65 });
66 canvas.addEventListener("webglcontextrestored", testShouldNotRestoreContext);
67 allowRestore = false;
68 contextLostEventFired = false;
69 contextRestoredEventFired = false;
71 testOriginalContext();
72 extension.loseContext();
73 // The context should be lost immediately.
74 shouldBeTrue("gl.isContextLost()");
75 shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
76 shouldBe("gl.getError()", "gl.NO_ERROR");
77 // gl methods should be no-ops
78 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
79 // but the event should not have been fired.
80 shouldBeFalse("contextLostEventFired");
83 function testLosingAndRestoringContext()
85 if (!setupTest())
86 finishTest();
88 debug("");
89 debug("Test losing and restoring a context.");
91 canvas.addEventListener("webglcontextlost", function(e) {
92 testLostContext(e);
93 // restore the context after this event has exited.
94 setTimeout(function() {
95 shouldGenerateGLError(gl, gl.NO_ERROR, "extension.restoreContext()");
96 // The context should still be lost. It will not get restored until the
97 // webglrestorecontext event is fired.
98 shouldBeTrue("gl.isContextLost()");
99 shouldBe("gl.getError()", "gl.NO_ERROR");
100 // gl methods should still be no-ops
101 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
102 }, 0);
104 canvas.addEventListener("webglcontextrestored", function() {
105 testRestoredContext();
106 finishTest();
108 allowRestore = true;
109 contextLostEventFired = false;
110 contextRestoredEventFired = false;
112 testOriginalContext();
113 extension.loseContext();
114 // The context should be lost immediately.
115 shouldBeTrue("gl.isContextLost()");
116 shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
117 shouldBe("gl.getError()", "gl.NO_ERROR");
118 // gl methods should be no-ops
119 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
120 // but the event should not have been fired.
121 shouldBeFalse("contextLostEventFired");
124 function testRendering()
126 gl.clearColor(0, 0, 0, 255);
127 gl.colorMask(1, 1, 1, 0);
128 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
130 program = wtu.setupSimpleTextureProgram(gl);
131 bufferObjects = wtu.setupUnitQuad(gl);
132 texture = wtu.createColoredTexture(gl, canvas.width, canvas.height, texColor);
134 gl.uniform1i(gl.getUniformLocation(program, "tex"), 0);
135 wtu.drawQuad(gl, [0, 0, 0, 255]);
137 var compare = texColor.slice(0, 3);
138 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, compare, "shouldBe " + compare);
140 shouldBe("gl.getError()", "gl.NO_ERROR");
143 function testOriginalContext()
145 debug("Test valid context");
146 shouldBeFalse("gl.isContextLost()");
147 shouldBe("gl.getError()", "gl.NO_ERROR");
148 testRendering();
149 debug("");
152 function testLostContext(e)
154 debug("Test lost context");
155 shouldBeFalse("contextLostEventFired");
156 contextLostEventFired = true;
157 shouldBeTrue("gl.isContextLost()");
158 shouldBe("gl.getError()", "gl.NO_ERROR");
159 debug("");
160 if (allowRestore)
161 e.preventDefault();
164 function testShouldNotRestoreContext(e)
166 testFailed("Should not restore the context unless preventDefault is called on the context lost event");
167 debug("");
170 function testResources(expected)
172 var tests = [
173 "gl.bindTexture(gl.TEXTURE_2D, texture)",
174 "gl.useProgram(program)",
175 "gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0])",
178 for (var i = 0; i < tests.length; ++i)
179 shouldGenerateGLError(gl, expected, tests[i]);
182 function testRestoredContext()
184 debug("Test restored context");
185 shouldBeFalse("contextRestoredEventFired");
186 contextRestoredEventFired = true;
187 shouldBeFalse("gl.isContextLost()");
188 shouldBe("gl.getError()", "gl.NO_ERROR");
190 // Validate that using old resources fails.
191 testResources(gl.INVALID_OPERATION);
193 testRendering();
195 // Validate new resources created in testRendering().
196 testResources(gl.NO_ERROR);
197 debug("");
201 </script>
202 </head>
203 <body onload="init()">
204 <div id="description"></div>
205 <div id="console"></div>
206 </body>
207 </html>