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

Unified Diff: third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored-worker.html

Issue 2490443002: Make OffscreenCanvas an EventTarget (Closed)
Patch Set: keep a Member<ExecutionContext> in OffscreenCanvas Created 4 years, 1 month 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
Index: third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored-worker.html
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored-worker.html b/third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored-worker.html
new file mode 100644
index 0000000000000000000000000000000000000000..871a306f870907fb40d49e648e1338f92a040bab
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored-worker.html
@@ -0,0 +1,127 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="./resources/webgl-test-utils-full.js"></script>
+</head>
+
+<script id="myWorker" type="text/worker">
+var canvas;
+var gl;
+var WEBGL_lose_context;
+var allowRestore;
+var contextLostEventFired;
+var contextRestoredEventFired;
+// Make everything in results true for easy testing
+var results = [];
+
+function setupTest()
+{
+ canvas = new OffscreenCanvas(10, 10);
+ gl = canvas.getContext('webgl');
+ WEBGL_lose_context = gl.getExtension("WEBGL_lose_context");
+}
+
+function testOriginalContext()
+{
+ results.push(!gl.isContextLost());
+ results.push(gl.getError() == gl.NO_ERROR);
+}
+
+function testLostContext(e)
+{
+ results.push(!contextLostEventFired);
+ contextLostEventFired = true;
+ results.push(gl.isContextLost());
+ results.push(gl.getError() == gl.NO_ERROR);
+ if (allowRestore)
+ e.preventDefault();
+}
+
+function testShouldNotRestoreContext(e)
+{
+ // Should not restore the context unless preventDefault is called on the context lost event
+ results.push(false);
+}
+
+function compareGLError(glError, evalStr) {
+ var exception;
+ try {
+ eval(evalStr);
+ } catch(e) {
+ exception = e;
+ }
+ if (exception) {
+ return false;
+ } else {
+ if (gl.getError() == glError)
+ return true;
+ return false;
+ }
+}
+
+function testRestoredContext() {
+ results.push(!contextRestoredEventFired);
+ contextRestoredEventFired = true;
+ results.push(!gl.isContextLost());
+ results.push(gl.getError() == gl.NO_ERROR);
+}
+
+self.onmessage = function(e) {
+ setupTest();
+ testOriginalContext();
+
+ canvas.addEventListener("webglcontextrestored", testShouldNotRestoreContext);
+ canvas.addEventListener("webglcontextlost", function(e) {
+ testLostContext(e);
+ // restore the context after this event has exited.
+ setTimeout(function() {
+ // we didn't call prevent default so we should not be able to restore the context
+ results.push(compareGLError(gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext()"));
+ results.push(gl.isContextLost());
+ results.push(gl.getError() == gl.NO_ERROR);
+ // gl methods should still be no-ops
+ results.push(compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)"));
+ results.push(false);
+ setTimeout(function() {
+ testRestoredContext();
+ self.postMessage(results);
+ }, 0);
+ }, 0);
+ });
+ allowRestore = false;
+ contextLostEventFired = false;
+ contextRestoredEventFired = false;
+
+ WEBGL_lose_context.loseContext();
+ // The context should be lost immediately.
+ results.push(gl.isContextLost());
+ results.push(gl.getError() == gl.CONTEXT_LOST_WEBGL);
+ results.push(gl.getError() == gl.NO_ERROR);
+ // gl methods should be no-ops
+ results.push(compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)"));
+ // but the event should not have been fired.
+ results.push(!contextLostEventFired);
+};
+
+</script>
+
+<script>
+function makeWorker(script)
+{
+ var blob = new Blob([script]);
+ return new Worker(URL.createObjectURL(blob));
+}
+
+var t = async_test('Test that WebGL context restore event can be handled with OffscreenCanvas in a worker');
+var worker = makeWorker(document.getElementById("myWorker").textContent);
+worker.addEventListener('message', t.step_func(function(msg) {
+ assert_equals(msg.data.length, 18);
+ for (var i = 0; i < msg.data.length; ++i)
+ assert_true(msg.data[i]);
+ t.done();
+}));
+worker.postMessage('start');
+</script>
+</html>

Powered by Google App Engine
This is Rietveld 408576698