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

Unified Diff: third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored.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.html
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored.html b/third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored.html
new file mode 100644
index 0000000000000000000000000000000000000000..bfb22a003c1f866af8d5a0ea6054b3a6dff02f36
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/webgl/offscreenCanvas-context-lost-restored.html
@@ -0,0 +1,120 @@
+<!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>
+
+<body>
+<script>
+var wtu = WebGLTestUtils;
+var canvas;
+var gl;
+var WEBGL_lose_context;
+var allowRestore;
+var contextLostEventFired;
+var contextRestoredEventFired;
+
+function setupTest()
+{
+ canvas = new OffscreenCanvas(10, 10);
+ gl = canvas.getContext('webgl');
+ WEBGL_lose_context = getExtensionAndAddProperty(gl, "WEBGL_lose_context");
+ if (!WEBGL_lose_context) {
+ return false;
+ }
+
+ return true;
+}
+
+function getExtensionAndAddProperty(gl, name) {
+ var ext = wtu.getExtensionWithKnownPrefixes(gl, name);
+ if (ext) {
+ ext.webglTestProperty = true;
+ }
+ return ext;
+}
+
+function testOriginalContext()
+{
+ assert_false(gl.isContextLost());
+ assert_equals(gl.getError(), gl.NO_ERROR);
+}
+
+function testLostContext(e)
+{
+ assert_false(contextLostEventFired);
+ contextLostEventFired = true;
+ assert_true(gl.isContextLost());
+ assert_equals(gl.getError(), gl.NO_ERROR);
+ if (allowRestore)
+ e.preventDefault();
+}
+
+function testShouldNotRestoreContext(e)
+{
+ assert_true(false, "Should not restore the context unless preventDefault is called on the context lost event");
+}
+
+function compareGLError(glError, evalStr) {
+ var exception;
+ try {
+ eval(evalStr);
+ } catch(e) {
+ exception = e;
+ }
+ if (exception) {
+ assert_true(false, evalStr + " threw exception " + exception);
+ } else {
+ assert_equals(gl.getError(), glError);
+ }
+}
+
+function testRestoredContext()
+{
+ assert_false(contextRestoredEventFired);
+ contextRestoredEventFired = true;
+// assert_false(gl.isContextLost());
xidachen 2016/11/14 19:56:38 Ken, this test fails here if I un-comment this lin
+ assert_equals(gl.getError(), gl.NO_ERROR);
+}
+
+async_test(function(t) {
+ if (!setupTest())
+ assert_true(false, "Cannot initialize test");
+ testOriginalContext();
+
+ canvas.addEventListener("webglcontextrestored", testShouldNotRestoreContext);
+ canvas.addEventListener("webglcontextlost", function(e) {
+ testLostContext(e);
+ // restore the context after this event has exited.
+ setTimeout(t.step_func(function() {
+ // we didn't call prevent default so we should not be able to restore the context
+ compareGLError(gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext()");
+ assert_true(gl.isContextLost());
+ assert_equals(gl.getError(), gl.NO_ERROR);
+ // gl methods should still be no-ops
+ compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
+ setTimeout(t.step_func_done(function() {
+ testRestoredContext();
+ }, 0));
+ }, 0));
+ });
+ allowRestore = false;
+ contextLostEventFired = false;
+ contextRestoredEventFired = false;
+
+ WEBGL_lose_context.loseContext();
+ // The context should be lost immediately.
+ assert_true(gl.isContextLost());
+ assert_equals(gl.getError(), gl.CONTEXT_LOST_WEBGL);
+ assert_equals(gl.getError(), gl.NO_ERROR);
+ // gl methods should be no-ops
+ compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)");
+ // but the event should not have been fired.
+ assert_false(contextLostEventFired);
+}, 'Test behavior under a restored context with OffscreenCanvas');
+
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698