Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1616)

Unified Diff: conformance/context/context-lost-restored.html

Issue 8342021: Add webgl conformance tests r15841. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « conformance/context/context-lost.html ('k') | conformance/context/context-type-test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: conformance/context/context-lost-restored.html
===================================================================
--- conformance/context/context-lost-restored.html (revision 0)
+++ conformance/context/context-lost-restored.html (revision 0)
@@ -0,0 +1,180 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/webgl-test.js"></script>
+<script src="../resources/webgl-test-utils.js"></script>
+<script>
+var wtu = WebGLTestUtils;
+var canvas;
+var gl;
+var shouldGenerateGLError;
+var extension_name = "WEBKIT_lose_context";
+var extension;
+var bufferObjects;
+var program;
+var texture;
+var texColor = [255, 10, 20, 255];
+var allowRestore;
+
+function init()
+{
+ if (window.initNonKhronosFramework) {
+ window.initNonKhronosFramework(true);
+ }
+
+ description("Tests behavior under a restored context.");
+
+ shouldGenerateGLError = wtu.shouldGenerateGLError;
+ runTests();
+}
+
+function runTests()
+{
+ testLosingContext();
+ testLosingAndRestoringContext();
+
+ finish();
+}
+
+function setupTest()
+{
+ canvas = document.createElement("canvas");
+ canvas.width = 1;
+ canvas.height = 1;
+ gl = wtu.create3DContext(canvas);
+ extension = gl.getExtension(extension_name);
+ if (!extension) {
+ debug(extension_name + " extension not found.");
+ return false;
+ }
+ return true;
+}
+
+function testLosingContext()
+{
+ if (!setupTest())
+ return;
+
+ debug("Test losing a context and inability to restore it.");
+
+ canvas.addEventListener("webglcontextlost", testLostContext);
+ canvas.addEventListener("webglcontextrestored", testShouldNotRestoreContext);
+ allowRestore = false;
+
+ testOriginalContext();
+ extension.loseContext();
+ shouldGenerateGLError(gl, gl.INVALID_OPERATION, "extension.restoreContext()");
+ debug("");
+}
+
+function testLosingAndRestoringContext()
+{
+ if (!setupTest())
+ return;
+
+ debug("Test losing and restoring a context.");
+
+ canvas.addEventListener("webglcontextlost", testLostContext);
+ canvas.addEventListener("webglcontextrestored", testRestoredContext);
+ allowRestore = true;
+
+ testOriginalContext();
+ extension.loseContext();
+ shouldGenerateGLError(gl, gl.NO_ERROR, "extension.restoreContext()");
+ debug("");
+}
+
+function testRendering()
+{
+ gl.clearColor(0, 0, 0, 255);
+ gl.colorMask(1, 1, 1, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ program = wtu.setupSimpleTextureProgram(gl);
+ bufferObjects = wtu.setupUnitQuad(gl);
+ texture = wtu.createColoredTexture(gl, canvas.width, canvas.height, texColor);
+
+ gl.uniform1i(gl.getUniformLocation(program, "tex"), 0);
+ wtu.drawQuad(gl, [0, 0, 0, 255]);
+
+ var compare = texColor.slice(0, 3);
+ wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, compare, "shouldBe " + compare);
+
+ shouldBe("gl.getError()", "gl.NO_ERROR");
+}
+
+function testOriginalContext()
+{
+ debug("Test valid context");
+ shouldBeFalse("gl.isContextLost()");
+ shouldBe("gl.getError()", "gl.NO_ERROR");
+ testRendering();
+ debug("");
+}
+
+function testLostContext(e)
+{
+ debug("Test lost context");
+ shouldBeTrue("gl.isContextLost()");
+ shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
+ shouldBe("gl.getError()", "gl.NO_ERROR");
+ debug("");
+ if (allowRestore)
+ e.preventDefault();
+}
+
+function testShouldNotRestoreContext(e)
+{
+ testFailed("Should not restore the context unless preventDefault is called on the context lost event");
+ debug("");
+}
+
+function testResources(expected)
+{
+ var tests = [
+ "gl.bindTexture(gl.TEXTURE_2D, texture)",
+ "gl.useProgram(program)",
+ "gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0])",
+ ];
+
+ for (var i = 0; i < tests.length; ++i)
+ shouldGenerateGLError(gl, expected, tests[i]);
+}
+
+function testRestoredContext()
+{
+ debug("Test restored context");
+ shouldBeFalse("gl.isContextLost()");
+ shouldBe("gl.getError()", "gl.NO_ERROR");
+
+ // Validate that using old resources fails.
+ testResources(gl.INVALID_OPERATION);
+
+ testRendering();
+
+ // Validate new resources created in testRendering().
+ testResources(gl.NO_ERROR);
+ debug("");
+}
+
+function finish() {
+ successfullyParsed = true;
+ var epilogue = document.createElement("script");
+ epilogue.onload = function() {
+ if (window.nonKhronosFrameworkNotifyDone)
+ window.nonKhronosFrameworkNotifyDone();
+ };
+ epilogue.src = "../../resources/js-test-post.js";
+ document.body.appendChild(epilogue);
+}
+
+</script>
+</head>
+<body onload="init()">
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
Property changes on: conformance/context/context-lost-restored.html
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « conformance/context/context-lost.html ('k') | conformance/context/context-type-test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698