Commit a3de32ec authored by enne@google.com's avatar enne@google.com

2011-01-05 Adrienne Walker <enne@google.com>

        Reviewed by Kenneth Russell.

        Add tests for WebGL's lost context events.
        https://bugs.webkit.org/show_bug.cgi?id=51492

        * fast/canvas/webgl/context-lost-expected.txt: Added.
        * fast/canvas/webgl/context-lost-restored-expected.txt: Added.
        * fast/canvas/webgl/context-lost-restored.html: Added.
        * fast/canvas/webgl/context-lost.html: Added.
2011-01-05  Adrienne Walker  <enne@google.com>

        Reviewed by Kenneth Russell.

        Add WEBKIT_lose_context WebGL extension.
        https://bugs.webkit.org/show_bug.cgi?id=51492

        Tests: fast/canvas/webgl/context-lost-restored.html
               fast/canvas/webgl/context-lost.html

        * CMakeLists.txt:
        * DerivedSources.make:
        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pri:
        * WebCore.pro:
        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/JSWebGLRenderingContextCustom.cpp:
        (WebCore::toJS):
        (WebCore::JSWebGLRenderingContext::getSupportedExtensions):
        * bindings/v8/custom/V8WebGLRenderingContextCustom.cpp:
        (WebCore::toV8Object):
        (WebCore::V8WebGLRenderingContext::getSupportedExtensionsCallback):
        * html/canvas/WebGLExtension.h:
        * html/canvas/WebGLRenderingContext.cpp:
        (WebCore::WebGLRenderingContext::WebGLRenderingContextRestoreTimer::fired):
        (WebCore::WebGLRenderingContext::getExtension):
        (WebCore::WebGLRenderingContext::getSupportedExtensions):
        (WebCore::WebGLRenderingContext::forceLostContext):
        (WebCore::WebGLRenderingContext::onLostContext):
        (WebCore::WebGLRenderingContext::getNumberOfExtensions):
        (WebCore::WebGLRenderingContext::getExtensionNumber):
        * html/canvas/WebGLRenderingContext.h:
        * html/canvas/WebKitLoseContext.cpp: Copied from WebCore/html/canvas/WebGLExtension.h.
        (WebCore::WebKitLoseContext::WebKitLoseContext):
        (WebCore::WebKitLoseContext::~WebKitLoseContext):
        (WebCore::WebKitLoseContext::getName):
        (WebCore::WebKitLoseContext::create):
        (WebCore::WebKitLoseContext::loseContext):
        * html/canvas/WebKitLoseContext.h: Copied from WebCore/html/canvas/WebGLExtension.h.
        * html/canvas/WebKitLoseContext.idl: Copied from WebCore/html/canvas/WebGLExtension.h.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75271 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 37521711
2011-01-05 Adrienne Walker <enne@google.com>
Reviewed by Kenneth Russell.
Add tests for WebGL's lost context events.
https://bugs.webkit.org/show_bug.cgi?id=51492
* fast/canvas/webgl/context-lost-expected.txt: Added.
* fast/canvas/webgl/context-lost-restored-expected.txt: Added.
* fast/canvas/webgl/context-lost-restored.html: Added.
* fast/canvas/webgl/context-lost.html: Added.
2011-01-07 Stephen White <senorblanco@chromium.org>
Unreviewed; new test baselines and updated chromium expectations.
......
Tests behavior under a lost context
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Test valid context
PASS gl.isContextLost() is false
PASS gl.getError() is gl.NO_ERROR
PASS gl.enable(gl.BLEND) was expected value: NO_ERROR.
PASS gl.isBuffer(buffer) is true
PASS gl.isEnabled(gl.BLEND) is true
PASS gl.isFramebuffer(framebuffer) is true
PASS gl.isProgram(program) is true
PASS gl.isRenderbuffer(renderbuffer) is true
PASS gl.isShader(shader) is true
PASS gl.isTexture(texture) is true
Lose context
PASS extension.loseContext() was expected value: NO_ERROR.
Test lost context
PASS gl.isContextLost() is true
PASS gl.getError() is gl.CONTEXT_LOST_WEBGL
PASS gl.getError() is gl.NO_ERROR
PASS gl.checkFramebufferStatus(gl.FRAMEBUFFER) is gl.FRAMEBUFFER_UNSUPPORTED
PASS gl.getAttribLocation(program, 'u_modelViewProjMatrix') is -1
PASS gl.getVertexAttribOffset(0, gl.VERTEX_ATTRIB_ARRAY_POINTER) is 0
PASS extension.loseContext() was expected value: INVALID_OPERATION.
PASS gl.activeTexture(gl.TEXTURE0) was expected value: NO_ERROR.
PASS gl.attachShader(program, shader) was expected value: NO_ERROR.
PASS gl.bindBuffer(gl.ARRAY_BUFFER, buffer) was expected value: NO_ERROR.
PASS gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer) was expected value: NO_ERROR.
PASS gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer) was expected value: NO_ERROR.
PASS gl.bindTexture(gl.TEXTURE_2D, texture) was expected value: NO_ERROR.
PASS gl.blendColor(1.0, 1.0, 1.0, 1.0) was expected value: NO_ERROR.
PASS gl.blendEquation(gl.FUNC_ADD) was expected value: NO_ERROR.
PASS gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD) was expected value: NO_ERROR.
PASS gl.blendFunc(gl.ONE) was expected value: NO_ERROR.
PASS gl.blendFuncSeparate(gl.ONE, gl.ONE) was expected value: NO_ERROR.
PASS gl.bufferData(gl.ARRAY_BUFFER, 0, gl.STATIC_DRAW) was expected value: NO_ERROR.
PASS gl.bufferData(gl.ARRAY_BUFFER, arrayBufferView, gl.STATIC_DRAW) was expected value: NO_ERROR.
PASS gl.bufferData(gl.ARRAY_BUFFER, arrayBuffer, gl.STATIC_DRAW) was expected value: NO_ERROR.
PASS gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBufferView) was expected value: NO_ERROR.
PASS gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBuffer) was expected value: NO_ERROR.
PASS gl.clear(gl.COLOR_BUFFER_BIT) was expected value: NO_ERROR.
PASS gl.clearColor(1, 1, 1, 1) was expected value: NO_ERROR.
PASS gl.clearDepth(1) was expected value: NO_ERROR.
PASS gl.clearStencil(0) was expected value: NO_ERROR.
PASS gl.colorMask(1, 1, 1, 1) was expected value: NO_ERROR.
PASS gl.compileShader(shader) was expected value: NO_ERROR.
PASS gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.cullFace(gl.FRONT) was expected value: NO_ERROR.
PASS gl.deleteBuffer(buffer) was expected value: NO_ERROR.
PASS gl.deleteFramebuffer(framebuffer) was expected value: NO_ERROR.
PASS gl.deleteProgram(program) was expected value: NO_ERROR.
PASS gl.deleteRenderbuffer(renderbuffer) was expected value: NO_ERROR.
PASS gl.deleteShader(shader) was expected value: NO_ERROR.
PASS gl.deleteTexture(texture) was expected value: NO_ERROR.
PASS gl.depthFunc(gl.NEVER) was expected value: NO_ERROR.
PASS gl.depthMask(0) was expected value: NO_ERROR.
PASS gl.depthRange(0, 1) was expected value: NO_ERROR.
PASS gl.detachShader(program, shader) was expected value: NO_ERROR.
PASS gl.disable(gl.BLEND) was expected value: NO_ERROR.
PASS gl.disableVertexAttribArray(0) was expected value: NO_ERROR.
PASS gl.drawArrays(gl.POINTS, 0, 0) was expected value: NO_ERROR.
PASS gl.drawElements(gl.POINTS, 0, gl.UNSIGNED_SHORT, 0) was expected value: NO_ERROR.
PASS gl.enable(gl.BLEND) was expected value: NO_ERROR.
PASS gl.enableVertexAttribArray(0) was expected value: NO_ERROR.
PASS gl.finish() was expected value: NO_ERROR.
PASS gl.flush() was expected value: NO_ERROR.
PASS gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, renderbuffer) was expected value: NO_ERROR.
PASS gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0) was expected value: NO_ERROR.
PASS gl.frontFace(gl.CW) was expected value: NO_ERROR.
PASS gl.generateMipmap(gl.TEXTURE_2D) was expected value: NO_ERROR.
PASS gl.hint(gl.GENERATE_MIPMAP_HINT, gl.FASTEST) was expected value: NO_ERROR.
PASS gl.lineWidth(0) was expected value: NO_ERROR.
PASS gl.linkProgram(program) was expected value: NO_ERROR.
PASS gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0) was expected value: NO_ERROR.
PASS gl.polygonOffset(0, 0) was expected value: NO_ERROR.
PASS gl.readPixels(0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView) was expected value: NO_ERROR.
PASS gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 0, 0) was expected value: NO_ERROR.
PASS gl.sampleCoverage(0, 0) was expected value: NO_ERROR.
PASS gl.scissor(0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.shaderSource(shader, '') was expected value: NO_ERROR.
PASS gl.stencilFunc(gl.NEVER, 0, 0) was expected value: NO_ERROR.
PASS gl.stencilFuncSeparate(gl.FRONT, gl.NEVER, 0, 0) was expected value: NO_ERROR.
PASS gl.stencilMask(0) was expected value: NO_ERROR.
PASS gl.stencilMaskSeparate(gl.FRONT, 0) was expected value: NO_ERROR.
PASS gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP) was expected value: NO_ERROR.
PASS gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP) was expected value: NO_ERROR.
PASS gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView) was expected value: NO_ERROR.
PASS gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imageData) was expected value: NO_ERROR.
PASS gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image) was expected value: NO_ERROR.
PASS gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas) was expected value: NO_ERROR.
PASS gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video) was expected value: NO_ERROR.
PASS gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) was expected value: NO_ERROR.
PASS gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) was expected value: NO_ERROR.
PASS gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView) was expected value: NO_ERROR.
PASS gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData) was expected value: NO_ERROR.
PASS gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image) was expected value: NO_ERROR.
PASS gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, canvas) was expected value: NO_ERROR.
PASS gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, video) was expected value: NO_ERROR.
PASS gl.uniform1f(uniformLocation, 0) was expected value: NO_ERROR.
PASS gl.uniform1fv(uniformLocation, float32array) was expected value: NO_ERROR.
PASS gl.uniform1fv(uniformLocation, [0]) was expected value: NO_ERROR.
PASS gl.uniform1i(uniformLocation, 0) was expected value: NO_ERROR.
PASS gl.uniform1iv(uniformLocation, int32array) was expected value: NO_ERROR.
PASS gl.uniform1iv(uniformLocation, [0]) was expected value: NO_ERROR.
PASS gl.uniform2f(uniformLocation, 0, 0) was expected value: NO_ERROR.
PASS gl.uniform2fv(uniformLocation, float32array) was expected value: NO_ERROR.
PASS gl.uniform2fv(uniformLocation, [0, 0]) was expected value: NO_ERROR.
PASS gl.uniform2i(uniformLocation, 0, 0) was expected value: NO_ERROR.
PASS gl.uniform2iv(uniformLocation, int32array) was expected value: NO_ERROR.
PASS gl.uniform2iv(uniformLocation, [0, 0]) was expected value: NO_ERROR.
PASS gl.uniform3f(uniformLocation, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.uniform3fv(uniformLocation, float32array) was expected value: NO_ERROR.
PASS gl.uniform3fv(uniformLocation, [0, 0, 0]) was expected value: NO_ERROR.
PASS gl.uniform3i(uniformLocation, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.uniform3iv(uniformLocation, int32array) was expected value: NO_ERROR.
PASS gl.uniform3iv(uniformLocation, [0, 0, 0]) was expected value: NO_ERROR.
PASS gl.uniform4f(uniformLocation, 0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.uniform4fv(uniformLocation, float32array) was expected value: NO_ERROR.
PASS gl.uniform4fv(uniformLocation, [0, 0, 0, 0]) was expected value: NO_ERROR.
PASS gl.uniform4i(uniformLocation, 0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.uniform4iv(uniformLocation, int32array) was expected value: NO_ERROR.
PASS gl.uniform4iv(uniformLocation, [0, 0, 0, 0]) was expected value: NO_ERROR.
PASS gl.uniformMatrix2fv(uniformLocation, false, float32array) was expected value: NO_ERROR.
PASS gl.uniformMatrix2fv(uniformLocation, false, [0, 0, 0, 0]) was expected value: NO_ERROR.
PASS gl.uniformMatrix3fv(uniformLocation, false, float32array) was expected value: NO_ERROR.
PASS gl.uniformMatrix3fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0]) was expected value: NO_ERROR.
PASS gl.uniformMatrix4fv(uniformLocation, false, float32array) was expected value: NO_ERROR.
PASS gl.uniformMatrix4fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) was expected value: NO_ERROR.
PASS gl.useProgram(program) was expected value: NO_ERROR.
PASS gl.validateProgram(program) was expected value: NO_ERROR.
PASS gl.vertexAttrib1f(0, 0) was expected value: NO_ERROR.
PASS gl.vertexAttrib1fv(0, float32array) was expected value: NO_ERROR.
PASS gl.vertexAttrib1fv(0, [0]) was expected value: NO_ERROR.
PASS gl.vertexAttrib2f(0, 0, 0) was expected value: NO_ERROR.
PASS gl.vertexAttrib2fv(0, float32array) was expected value: NO_ERROR.
PASS gl.vertexAttrib2fv(0, [0, 0]) was expected value: NO_ERROR.
PASS gl.vertexAttrib3f(0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.vertexAttrib3fv(0, float32array) was expected value: NO_ERROR.
PASS gl.vertexAttrib3fv(0, [0, 0, 0]) was expected value: NO_ERROR.
PASS gl.vertexAttrib4f(0, 0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.vertexAttrib4fv(0, float32array) was expected value: NO_ERROR.
PASS gl.vertexAttrib4fv(0, [0, 0, 0, 0]) was expected value: NO_ERROR.
PASS gl.vertexAttribPointer(0, 0, gl.FLOAT, false, 0, 0) was expected value: NO_ERROR.
PASS gl.viewport(0, 0, 0, 0) was expected value: NO_ERROR.
PASS gl.createBuffer() is null
PASS gl.createFramebuffer() is null
PASS gl.createProgram() is null
PASS gl.createRenderbuffer() is null
PASS gl.createShader(gl.GL_VERTEX_SHADER) is null
PASS gl.createTexture() is null
PASS gl.getActiveAttrib(program, 0) is null
PASS gl.getActiveUniform(program, 0) is null
PASS gl.getAttachedShaders(program) is null
PASS gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE) is null
PASS gl.getContextAttributes() is null
PASS gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) is null
PASS gl.getParameter(gl.CURRENT_PROGRAM) is null
PASS gl.getProgramInfoLog(program) is null
PASS gl.getProgramParameter(program, gl.LINK_STATUS) is null
PASS gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH) is null
PASS gl.getShaderInfoLog(shader) is null
PASS gl.getShaderParameter(shader, gl.SHADER_TYPE) is null
PASS gl.getShaderSource(shader) is null
PASS gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S) is null
PASS gl.getUniform(program, uniformLocation) is null
PASS gl.getUniformLocation(program, 'vPosition') is null
PASS gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) is null
PASS gl.getSupportedExtensions() is null
PASS gl.getExtension('WEBKIT_lose_context') is null
PASS gl.isBuffer(buffer) is false
PASS gl.isEnabled(gl.BLEND) is false
PASS gl.isFramebuffer(framebuffer) is false
PASS gl.isProgram(program) is false
PASS gl.isRenderbuffer(renderbuffer) is false
PASS gl.isShader(shader) is false
PASS gl.isTexture(texture) is false
PASS gl.getError() is gl.NO_ERROR
PASS successfullyParsed is true
TEST COMPLETE
Tests behavior under a restored context
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Test valid context
PASS gl.isContextLost() is false
PASS gl.getError() is gl.NO_ERROR
PASS shouldBe 255,10,20
PASS gl.getError() is gl.NO_ERROR
Test lost context
PASS gl.isContextLost() is true
PASS gl.getError() is gl.CONTEXT_LOST_WEBGL
PASS gl.getError() is gl.NO_ERROR
Test restored context
PASS gl.isContextLost() is false
PASS gl.getError() is gl.NO_ERROR
PASS gl.bindTexture(gl.TEXTURE_2D, texture) was expected value: INVALID_OPERATION.
PASS gl.useProgram(program) was expected value: INVALID_OPERATION.
PASS gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0]) was expected value: INVALID_OPERATION.
PASS shouldBe 255,10,20
PASS gl.getError() is gl.NO_ERROR
PASS gl.bindTexture(gl.TEXTURE_2D, texture) was expected value: NO_ERROR.
PASS gl.useProgram(program) was expected value: NO_ERROR.
PASS gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0]) was expected value: NO_ERROR.
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
<script src="../../js/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];
function init()
{
if (window.initNonKhronosFramework) {
window.initNonKhronosFramework(true);
}
description("Tests behavior under a restored context");
canvas = document.getElementById("canvas");
canvas.addEventListener("webglcontextlost", testLostContext);
canvas.addEventListener("webglcontextrestored", testRestoredContext);
gl = wtu.create3DContext(canvas);
shouldGenerateGLError = wtu.shouldGenerateGLError;
extension = gl.getExtension(extension_name);
if (!extension) {
debug(extension_name + " extension not found.");
finish();
return;
}
testOriginalContext();
extension.loseContext();
}
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()
{
debug("Test lost context");
shouldBeTrue("gl.isContextLost()");
shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
shouldBe("gl.getError()", "gl.NO_ERROR");
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("");
finish();
}
function finish() {
successfullyParsed = true;
var epilogue = document.createElement("script");
epilogue.onload = function() {
if (window.nonKhronosFrameworkNotifyDone)
window.nonKhronosFrameworkNotifyDone();
};
epilogue.src = "../../js/resources/js-test-post.js";
document.body.appendChild(epilogue);
}
</script>
</head>
<body onload="init()">
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="1px" height="1px"></canvas>
</body>
</html>
<html>
<head>
<link rel="stylesheet" href="../../js/resources/js-test-style.css"/>
<script src="../../js/resources/js-test-pre.js"></script>
<script src="resources/webgl-test.js"></script>
<script src="resources/webgl-test-utils.js"></script>
<script>
var wtu;
var canvas;
var gl;
var shouldGenerateGLError;
var extension_name = "WEBKIT_lose_context";
var extension;
var buffer;
var framebuffer;
var program;
var renderbuffer;
var shader;
var texture;
var uniformLocation;
var arrayBuffer;
var arrayBufferView
var image;
var video;
var canvas2d;
var ctx2d;
var imageData;
var float32array;
var int32array;
function init()
{
wtu = WebGLTestUtils;
canvas = document.getElementById("canvas");
gl = wtu.create3DContext(canvas);
shouldGenerateGLError = wtu.shouldGenerateGLError;
description("Tests behavior under a lost context");
if (window.initNonKhronosFramework) {
window.initNonKhronosFramework(true);
}
extension = gl.getExtension(extension_name);
if (!extension) {
debug(extension_name + " extension not found.");
finish();
return;
}
canvas.addEventListener("webglcontextlost", testLostContext);
testValidContext();
loseContext();
}
function loseContext()
{
debug("");
debug("Lose context");
shouldGenerateGLError(gl, gl.NO_ERROR, "extension.loseContext()");
debug("");
}
function testValidContext()
{
debug("Test valid context");
shouldBeFalse("gl.isContextLost()");
arrayBuffer = new ArrayBuffer(4);
arrayBufferView = new Int8Array(arrayBuffer);
// Generate resources for testing.
buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
program = wtu.setupSimpleTextureProgram(gl);
renderbuffer = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
shader = gl.createShader(gl.VERTEX_SHADER);
texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
shouldBe("gl.getError()", "gl.NO_ERROR");
// Test is queries that will later be false
shouldGenerateGLError(gl, gl.NO_ERROR, "gl.enable(gl.BLEND)");
shouldBeTrue("gl.isBuffer(buffer)");
shouldBeTrue("gl.isEnabled(gl.BLEND)");
shouldBeTrue("gl.isFramebuffer(framebuffer)");
shouldBeTrue("gl.isProgram(program)");
shouldBeTrue("gl.isRenderbuffer(renderbuffer)");
shouldBeTrue("gl.isShader(shader)");
shouldBeTrue("gl.isTexture(texture)");
}
function testLostContext()
{
debug("Test lost context");
// Functions with special return values.
shouldBeTrue("gl.isContextLost()");
shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
shouldBe("gl.getError()", "gl.NO_ERROR");
shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_UNSUPPORTED");
shouldBe("gl.getAttribLocation(program, 'u_modelViewProjMatrix')", "-1");
shouldBe("gl.getVertexAttribOffset(0, gl.VERTEX_ATTRIB_ARRAY_POINTER)", "0");
// Test the extension itself.
shouldGenerateGLError(gl, gl.INVALID_OPERATION, "extension.loseContext()");
image = document.createElement("image");
video = document.createElement("video");
canvas2d = document.createElement("canvas");
ctx2d = canvas2d.getContext("2d");
imageData = ctx2d.createImageData(1, 1);
float32array = new Float32Array(1);
int32array = new Int32Array(1);
// Functions returning void should return immediately.
// This is untestable, but we can at least be sure they cause no errors
// and the codepaths are exercised.
var voidTests = [
"gl.activeTexture(gl.TEXTURE0)",
"gl.attachShader(program, shader)",
"gl.bindBuffer(gl.ARRAY_BUFFER, buffer)",
"gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer)",
"gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer)",
"gl.bindTexture(gl.TEXTURE_2D, texture)",
"gl.blendColor(1.0, 1.0, 1.0, 1.0)",
"gl.blendEquation(gl.FUNC_ADD)",
"gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD)",
"gl.blendFunc(gl.ONE)",
"gl.blendFuncSeparate(gl.ONE, gl.ONE)",
"gl.bufferData(gl.ARRAY_BUFFER, 0, gl.STATIC_DRAW)",
"gl.bufferData(gl.ARRAY_BUFFER, arrayBufferView, gl.STATIC_DRAW)",
"gl.bufferData(gl.ARRAY_BUFFER, arrayBuffer, gl.STATIC_DRAW)",
"gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBufferView)",
"gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBuffer)",
"gl.clear(gl.COLOR_BUFFER_BIT)",
"gl.clearColor(1, 1, 1, 1)",
"gl.clearDepth(1)",
"gl.clearStencil(0)",
"gl.colorMask(1, 1, 1, 1)",
"gl.compileShader(shader)",
"gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, 0, 0)",
"gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 0, 0)",
"gl.cullFace(gl.FRONT)",
"gl.deleteBuffer(buffer)",
"gl.deleteFramebuffer(framebuffer)",
"gl.deleteProgram(program)",
"gl.deleteRenderbuffer(renderbuffer)",
"gl.deleteShader(shader)",
"gl.deleteTexture(texture)",
"gl.depthFunc(gl.NEVER)",
"gl.depthMask(0)",
"gl.depthRange(0, 1)",
"gl.detachShader(program, shader)",
"gl.disable(gl.BLEND)",
"gl.disableVertexAttribArray(0)",
"gl.drawArrays(gl.POINTS, 0, 0)",
"gl.drawElements(gl.POINTS, 0, gl.UNSIGNED_SHORT, 0)",
"gl.enable(gl.BLEND)",
"gl.enableVertexAttribArray(0)",
"gl.finish()",
"gl.flush()",
"gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, renderbuffer)",
"gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0)",
"gl.frontFace(gl.CW)",
"gl.generateMipmap(gl.TEXTURE_2D)",
"gl.hint(gl.GENERATE_MIPMAP_HINT, gl.FASTEST)",
"gl.lineWidth(0)",
"gl.linkProgram(program)",
"gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0)",
"gl.polygonOffset(0, 0)",
"gl.readPixels(0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
"gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 0, 0)",
"gl.sampleCoverage(0, 0)",
"gl.scissor(0, 0, 0, 0)",
"gl.shaderSource(shader, '')",
"gl.stencilFunc(gl.NEVER, 0, 0)",
"gl.stencilFuncSeparate(gl.FRONT, gl.NEVER, 0, 0)",
"gl.stencilMask(0)",
"gl.stencilMaskSeparate(gl.FRONT, 0)",
"gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP)",
"gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imageData)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas)",
"gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video)",
"gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)",
"gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, canvas)",
"gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, video)",
"gl.uniform1f(uniformLocation, 0)",
"gl.uniform1fv(uniformLocation, float32array)",
"gl.uniform1fv(uniformLocation, [0])",
"gl.uniform1i(uniformLocation, 0)",
"gl.uniform1iv(uniformLocation, int32array)",
"gl.uniform1iv(uniformLocation, [0])",
"gl.uniform2f(uniformLocation, 0, 0)",
"gl.uniform2fv(uniformLocation, float32array)",
"gl.uniform2fv(uniformLocation, [0, 0])",
"gl.uniform2i(uniformLocation, 0, 0)",
"gl.uniform2iv(uniformLocation, int32array)",
"gl.uniform2iv(uniformLocation, [0, 0])",
"gl.uniform3f(uniformLocation, 0, 0, 0)",
"gl.uniform3fv(uniformLocation, float32array)",
"gl.uniform3fv(uniformLocation, [0, 0, 0])",
"gl.uniform3i(uniformLocation, 0, 0, 0)",
"gl.uniform3iv(uniformLocation, int32array)",
"gl.uniform3iv(uniformLocation, [0, 0, 0])",
"gl.uniform4f(uniformLocation, 0, 0, 0, 0)",
"gl.uniform4fv(uniformLocation, float32array)",
"gl.uniform4fv(uniformLocation, [0, 0, 0, 0])",
"gl.uniform4i(uniformLocation, 0, 0, 0, 0)",
"gl.uniform4iv(uniformLocation, int32array)",
"gl.uniform4iv(uniformLocation, [0, 0, 0, 0])",
"gl.uniformMatrix2fv(uniformLocation, false, float32array)",
"gl.uniformMatrix2fv(uniformLocation, false, [0, 0, 0, 0])",
"gl.uniformMatrix3fv(uniformLocation, false, float32array)",
"gl.uniformMatrix3fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0])",
"gl.uniformMatrix4fv(uniformLocation, false, float32array)",
"gl.uniformMatrix4fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])",
"gl.useProgram(program)",
"gl.validateProgram(program)",
"gl.vertexAttrib1f(0, 0)",
"gl.vertexAttrib1fv(0, float32array)",
"gl.vertexAttrib1fv(0, [0])",
"gl.vertexAttrib2f(0, 0, 0)",
"gl.vertexAttrib2fv(0, float32array)",
"gl.vertexAttrib2fv(0, [0, 0])",
"gl.vertexAttrib3f(0, 0, 0, 0)",
"gl.vertexAttrib3fv(0, float32array)",
"gl.vertexAttrib3fv(0, [0, 0, 0])",
"gl.vertexAttrib4f(0, 0, 0, 0, 0)",
"gl.vertexAttrib4fv(0, float32array)",
"gl.vertexAttrib4fv(0, [0, 0, 0, 0])",
"gl.vertexAttribPointer(0, 0, gl.FLOAT, false, 0, 0)",
"gl.viewport(0, 0, 0, 0)",
];
for (var i = 0; i < voidTests.length; ++i) {
shouldGenerateGLError(gl, gl.NO_ERROR, voidTests[i]);
}