summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/00_test_list.txt12
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-attribute-preserve-drawing-buffer.html93
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.html39
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.js13
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation.html37
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.html43
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.js51
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored.html88
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.html43
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.js35
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost.html69
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.html39
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.js13
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods.html36
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-resize.html93
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-timer-query.html84
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-transfer-image-bitmap.html50
17 files changed, 838 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/00_test_list.txt
new file mode 100644
index 0000000000..8c8154a542
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/00_test_list.txt
@@ -0,0 +1,12 @@
+context-attribute-preserve-drawing-buffer.html
+context-creation.html
+context-creation-worker.html
+context-lost.html
+context-lost-worker.html
+context-lost-restored.html
+context-lost-restored-worker.html
+methods.html
+methods-worker.html
+offscreencanvas-resize.html
+--min-version 1.0.4 offscreencanvas-timer-query.html
+--min-version 1.0.4 offscreencanvas-transfer-image-bitmap.html
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-attribute-preserve-drawing-buffer.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-attribute-preserve-drawing-buffer.html
new file mode 100644
index 0000000000..d230b69d9d
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-attribute-preserve-drawing-buffer.html
@@ -0,0 +1,93 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>OffscreenCanavs context attribute preserveDrawingBuffer</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script src="../../js/tests/canvas-tests-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="canvases"></div>
+<div id="console"></div>
+<script>
+"use strict";
+description("This test checks whether OffscreenCanvas webgl context honors the preserveDrawingBuffer flag.");
+const wtu = WebGLTestUtils;
+const pixels = new Uint8Array(4);
+
+function checkPixels(color) {
+ return (color[0] === pixels[0]) &&
+ (color[1] === pixels[1]) &&
+ (color[2] === pixels[2]) &&
+ (color[3] === pixels[3]);
+}
+
+const nextFrame = () => new Promise(r => requestAnimationFrame(r));
+
+async function getPixelsFromOffscreenWebgl(preserveFlag, color, msg) {
+ const canvas = document.createElement("canvas");
+ document.getElementById("canvases").appendChild(canvas);
+ const offscreenCanvas = transferredOffscreenCanvasCreation(canvas, 10, 10);
+ const gl = offscreenCanvas.getContext("webgl", {preserveDrawingBuffer: preserveFlag});
+
+ // Draw some color on gl
+ gl.clearColor(1, 0, 1, 1);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+
+ let t;
+ const t0 = await nextFrame();
+ const timeDuration = preserveFlag ? 500 : 2000;
+ for (;;) {
+ t = await nextFrame();
+
+ gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
+ if (preserveFlag) {
+ if (!checkPixels(color)) {
+ testFailed(msg + '\nexpected: ' + color.toString() + ' was ' + pixels.toString());
+ return;
+ }
+ } else {
+ if (checkPixels(color)) {
+ testPassed(msg);
+ return;
+ }
+ }
+
+ // Keep checking until it takes up to a certain time.
+ // preserveDrawingBuffer:false seems flaky on Chrome's test bots; run that test for longer.
+ if (t > t0 + timeDuration) {
+ break;
+ }
+ }
+
+ if (preserveFlag) {
+ testPassed(msg);
+ } else {
+ testFailed(msg + '\nafter ' + timeDuration + ' ms, expected: ' + color.toString() + ' was ' + pixels.toString());
+ }
+}
+
+(async () => {
+ if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ } else {
+ // Test if OffscreenCanvas.webgl retains contents if preserveDrawingBuffer is true.
+ await getPixelsFromOffscreenWebgl(true, [255,0,255,255], "should be preserved");
+
+ // Test if OffscreenCanvas.webgl loses contents if preserveDrawingBuffer is false.
+ await getPixelsFromOffscreenWebgl(false, [0, 0, 0, 0], "should not be preserved");
+ }
+ finishTest();
+})();
+
+</script>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.html
new file mode 100644
index 0000000000..38b348ae36
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.html
@@ -0,0 +1,39 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>WebGL Context Creation Test for OffscreenCanvas in a worker</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("This test ensures that the WebGL context can be created on an OffscreenCanvas.");
+
+if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+} else {
+ var worker = new Worker('context-creation-worker.js');
+ worker.postMessage("Start worker");
+ worker.onmessage = function(e) {
+ if (e.data == "Test passed") {
+ testPassed("All tests have passed");
+ } else {
+ testFailed("Some tests failed");
+ }
+ finishTest();
+ }
+}
+
+</script>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.js b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.js
new file mode 100644
index 0000000000..b0d867a1d2
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation-worker.js
@@ -0,0 +1,13 @@
+/*
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+*/
+
+importScripts("../../js/tests/canvas-tests-utils.js");
+self.onmessage = function(e) {
+ if (contextCreation('webgl'))
+ self.postMessage("Test passed");
+ else
+ self.postMessage("Test failed");
+};
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation.html
new file mode 100644
index 0000000000..73c911b5d1
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-creation.html
@@ -0,0 +1,37 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>WebGL Context Creation Test for OffscreenCanvas</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script src="../../js/tests/canvas-tests-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+"use strict";
+description("This test ensures that the WebGL context can be created on an OffscreenCanvas.");
+
+if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+} else {
+ if (contextCreation('webgl')) {
+ testPassed("WebGL context created correctly.");
+ } else {
+ testFailed("WebGL context creation failed");
+ }
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../../js/js-test-post.js"></script>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.html
new file mode 100644
index 0000000000..62d6ef60a5
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.html
@@ -0,0 +1,43 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script>
+function init()
+{
+ description("Tests behavior under a restored context for OffscreenCanvas in a worker.");
+
+ if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+ return;
+ }
+
+ var worker = new Worker('context-lost-restored-worker.js');
+ worker.postMessage("Start worker");
+ worker.onmessage = function(e) {
+ if (e.data == "Test passed") {
+ testPassed("All tests have passed");
+ } else {
+ testFailed("Some test failed");
+ }
+ finishTest();
+ return;
+ }
+}
+
+</script>
+</head>
+<body onload="init()">
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.js b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.js
new file mode 100644
index 0000000000..76f59dce7e
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored-worker.js
@@ -0,0 +1,51 @@
+/*
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+*/
+
+importScripts("../../js/tests/canvas-tests-utils.js");
+self.onmessage = function(e) {
+ if (!setupTest())
+ self.postMessage("Test failed");
+
+ canvas.addEventListener("webglcontextlost", function(e) {
+ if (!testLostContext(e))
+ self.postMessage("Test failed");
+ // 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
+ if (!compareGLError(gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext()"))
+ self.postMessage("Test failed");
+ testLosingAndRestoringContext().then(function() {
+ self.postMessage("Test passed");
+ }, function() {
+ self.postMessage("Test failed");
+ });
+ }, 0);
+ });
+ canvas.addEventListener("webglcontextrestored", function() {
+ self.postMessage("Test failed");
+ });
+ allowRestore = false;
+ contextLostEventFired = false;
+ contextRestoredEventFired = false;
+
+ if (!testOriginalContext())
+ self.postMessage("Test failed");
+ WEBGL_lose_context.loseContext();
+ // The context should be lost immediately.
+ if (!gl.isContextLost())
+ self.postMessage("Test failed");
+ if (gl.getError() != gl.CONTEXT_LOST_WEBGL)
+ self.postMessage("Test failed");
+ if (gl.getError() != gl.NO_ERROR)
+ self.postMessage("Test failed");
+ // gl methods should be no-ops
+ if (!compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)"))
+ self.postMessage("Test failed");
+ // but the event should not have been fired.
+ if (contextLostEventFired)
+ self.postMessage("Test failed");
+}
+
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored.html
new file mode 100644
index 0000000000..28e1878179
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-restored.html
@@ -0,0 +1,88 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script src="../../js/tests/canvas-tests-utils.js"></script>
+<script>
+
+function init()
+{
+ description("Tests behavior under a restored context for OffscreenCanvas.");
+
+ if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+ return;
+ }
+
+ if (!setupTest()) {
+ testFailed("Cannot initialize test");
+ finishTest();
+ return;
+ }
+
+ canvas.addEventListener("webglcontextlost", function(e) {
+ if (!testLostContext(e)) {
+ testFailed("Some test failed");
+ finishTest();
+ return;
+ }
+ // 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
+ if (!compareGLError(gl.INVALID_OPERATION, "WEBGL_lose_context.restoreContext()")) {
+ testFailed("Some test failed");
+ finishTest();
+ return;
+ }
+ testLosingAndRestoringContext().then(function() {
+ testPassed("Test passed");
+ finishTest();
+ return;
+ }, function() {
+ testFailed("Some test failed");
+ finishTest();
+ return;
+ });
+ }, 0);
+ });
+ canvas.addEventListener("webglcontextrestored", function() {
+ testFailed("Some test failed");
+ finishTest();
+ return;
+ });
+ allowRestore = false;
+ contextLostEventFired = false;
+ contextRestoredEventFired = false;
+
+ if (!testOriginalContext()) {
+ testFailed("Some test failed");
+ finishTest();
+ return;
+ }
+ WEBGL_lose_context.loseContext();
+ // The context should be lost immediately.
+ shouldBeTrue("gl.isContextLost()");
+ shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL");
+ shouldBe("gl.getError()", "gl.NO_ERROR");
+ // gl methods should be no-ops
+ shouldBeTrue(compareGLError(gl.NO_ERROR, "gl.blendFunc(gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP)"));
+ // but the event should not have been fired.
+ shouldBeFalse("contextLostEventFired");
+}
+
+</script>
+</head>
+<body onload="init()">
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.html
new file mode 100644
index 0000000000..a4846712de
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.html
@@ -0,0 +1,43 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script>
+function init()
+{
+ description("Tests behavior under a lost context for OffscreenCanvas in a worker");
+
+ if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+ return;
+ }
+
+ var worker = new Worker('context-lost-worker.js');
+ worker.postMessage("Start worker");
+ worker.onmessage = function(e) {
+ if (e.data == "Test passed") {
+ testPassed("All tests have passed");
+ } else {
+ testFailed("Some tests failed");
+ }
+ finishTest();
+ return;
+ }
+}
+
+</script>
+</head>
+<body onload="init()">
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.js b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.js
new file mode 100644
index 0000000000..75cd4b0045
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost-worker.js
@@ -0,0 +1,35 @@
+/*
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+*/
+
+importScripts("../../js/tests/canvas-tests-utils.js");
+self.onmessage = function(e) {
+ canvas = new OffscreenCanvas(10, 10);
+ gl = canvas.getContext('webgl');
+
+ // call testValidContext() before checking for the extension, because this is where we check
+ // for the isContextLost() method, which we want to do regardless of the extension's presence.
+ if (!testValidContext())
+ self.postMessage("Test failed");
+
+ extension = gl.getExtension("WEBGL_lose_context");
+ // need an extension that exposes new API methods.
+ OES_vertex_array_object = gl.getExtension("OES_vertex_array_object");
+ if (extension == null || OES_vertex_array_object == null)
+ self.postMessage("Test failed");
+
+ // We need to initialize |uniformLocation| before losing context.
+ // Otherwise gl.getUniform() when context is lost will throw.
+ uniformLocation = gl.getUniformLocation(program, "tex");
+ extension.loseContext();
+
+ canvas.addEventListener("webglcontextlost", function() {
+ if (testLostContextWithoutRestore())
+ self.postMessage("Test passed");
+ else
+ self.postMessage("Test failed");
+ }, false);
+}
+
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost.html
new file mode 100644
index 0000000000..0568ad229e
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/context-lost.html
@@ -0,0 +1,69 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script src="../../js/tests/canvas-tests-utils.js"></script>
+<script>
+function init()
+{
+ description("Tests behavior under a lost context for OffscreenCanvas");
+
+ if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+ return;
+ }
+
+ canvas = new OffscreenCanvas(10, 10);
+ gl = canvas.getContext('webgl');
+
+ // call testValidContext() before checking for the extension, because this is where we check
+ // for the isContextLost() method, which we want to do regardless of the extension's presence.
+ if (!testValidContext()) {
+ testFailed("Some tests failed");
+ finishTest();
+ return;
+ }
+
+ extension = gl.getExtension("WEBGL_lose_context");
+ // need an extension that exposes new API methods.
+ OES_vertex_array_object = gl.getExtension("OES_vertex_array_object");
+ if (extension == null || OES_vertex_array_object == null) {
+ testFailed("Some tests failed");
+ finishTest();
+ return;
+ }
+
+ // We need to initialize |uniformLocation| before losing context.
+ // Otherwise gl.getUniform() when context is lost will throw.
+ uniformLocation = gl.getUniformLocation(program, "tex");
+ extension.loseContext();
+
+ canvas.addEventListener("webglcontextlost", function() {
+ if (testLostContextWithoutRestore()) {
+ testPassed("All tests passed");
+ finishTest();
+ return;
+ } else {
+ testFailed("Some tests failed");
+ finishTest();
+ return;
+ }
+ }, false);
+}
+
+</script>
+</head>
+<body onload="init()">
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.html
new file mode 100644
index 0000000000..929474c9b4
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.html
@@ -0,0 +1,39 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>WebGL Methods Test for OffscreenCanvas in a worker</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("This test ensures that the WebGL context created for an OffscreenCanvas has all the methods in the specification.");
+
+if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+} else {
+ var worker = new Worker("methods-worker.js");
+ worker.postMessage("Start worker");
+ worker.onmessage = function(e) {
+ if (e.data == "Test passed") {
+ testPassed("All tests have passed");
+ } else {
+ testFailed("Some tests failed");
+ }
+ finishTest();
+ }
+}
+
+</script>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.js b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.js
new file mode 100644
index 0000000000..154cac7fc6
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods-worker.js
@@ -0,0 +1,13 @@
+/*
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+*/
+
+importScripts("../../js/tests/canvas-tests-utils.js");
+self.onmessage = function(e) {
+ if (testAPIs('webgl'))
+ self.postMessage("Test passed");
+ else
+ self.postMessage("Test failed");
+}
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods.html
new file mode 100644
index 0000000000..9129e76cfc
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/methods.html
@@ -0,0 +1,36 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>WebGL Methods Test for OffscreenCanvas</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script src="../../js/tests/canvas-tests-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("This test ensures that the WebGL context created for an OffscreenCanvas has all the methods in the specification.");
+
+if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+} else {
+ if (testAPIs('webgl')) {
+ testPassed("All WebGL methods found");
+ } else {
+ testFailed("Some WebGL methods not found");
+ }
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../../js/js-test-post.js"></script>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-resize.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-resize.html
new file mode 100644
index 0000000000..21107bba53
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-resize.html
@@ -0,0 +1,93 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Resizing Test for OffscreenCanvas commit()</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script src="../../js/tests/canvas-tests-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+"use strict";
+description("This test ensures that the OffscreenCanvas context returns the correct image size after resizing and calling commit().");
+
+function testResizeOnNewOffscreenCanvas() {
+ var canvas = new OffscreenCanvas(10, 20);
+ canvas.getContext("webgl");
+ canvas.width = 30;
+ canvas.height = 40;
+ assertWidthAndHeight(canvas, "canvas", 30, 40);
+ var imagebitmap = canvas.transferToImageBitmap();
+ assertWidthAndHeight(imagebitmap, "imagebitmap", 30, 40);
+}
+
+function testResizeOnTransferredOffscreenCanvas() {
+ var placeholder = document.createElement("canvas");
+ var offscreencanvas = transferredOffscreenCanvasCreation(placeholder, 10, 20);
+ var ctx = offscreencanvas.getContext("webgl");
+
+ // Verify that setting the size of an OffscreenCanvas that has a placeholder works.
+ offscreencanvas.width = 30;
+ offscreencanvas.height = 40;
+ assertWidthAndHeight(offscreencanvas, "resized offscreencanvas", 30, 40);
+ var imagebitmap = offscreencanvas.transferToImageBitmap();
+ assertWidthAndHeight(imagebitmap, "imagebitmap transferred from resized offscreencanvas" , 30, 40);
+
+ // Verify that setting the size of an OffscreenCanvas does not directly update the size of its placeholder canvas.
+ assertWidthAndHeight(placeholder, "placeholder canvas", 10, 20);
+
+ var asyncStepsCompleted = 0;
+ ctx.commit();
+ createImageBitmap(placeholder).then(image => {
+ // Verify that the placeholder was not updated synchronously.
+ assertWidthAndHeight(image, "imagebitmap from placeholder canvas", 10, 20);
+ asyncStepsCompleted++;
+ if (asyncStepsCompleted == 2) {
+ finishTest();
+ }
+ });
+
+ // Set timeout acts as a sync barrier to allow commit to propagate
+ setTimeout(function() {
+ // Verify that commit() asynchronously updates the size of its placeholder canvas.
+ assertWidthAndHeight(placeholder, "placeholder canvas", 30, 40);
+
+ // Verify that width/height attributes are not settable
+ shouldThrow("placeholder.width = 50");
+ shouldThrow("placeholder.height = 60");
+
+ assertWidthAndHeight(placeholder, "placeholder canvas after size reset", 30, 40);
+
+ createImageBitmap(placeholder).then(image => {
+ // Verify that an image grabbed from the placeholder has the correct dimensions
+ assertWidthAndHeight(image, "imagebitmap from placeholder canvas", 30, 40);
+ asyncStepsCompleted++;
+ if (asyncStepsCompleted == 2) {
+ finishTest();
+ }
+ });
+ }, 0);
+}
+
+if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+} else if (!new OffscreenCanvas(10, 20).getContext("webgl").commit) {
+ testPassed("commit() not supported");
+ finishTest();
+} else {
+ testResizeOnNewOffscreenCanvas();
+ testResizeOnTransferredOffscreenCanvas();
+}
+</script>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-timer-query.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-timer-query.html
new file mode 100644
index 0000000000..0d32f14c19
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-timer-query.html
@@ -0,0 +1,84 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Test for Timer Query objects with OffscreenCanvas</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+</head>
+<body>
+ <div id="description"></div>
+ <div id="console"></div>
+ <script id='myWorker' type='text/worker'>
+ function tick(callback) {
+ function tickImpl() {
+ const res = callback();
+ if (res) {
+ if (requestAnimationFrame) {
+ requestAnimationFrame(tickImpl);
+ } else {
+ setTimeout(tickImpl, 10);
+ }
+ }
+ }
+
+ tickImpl();
+ }
+
+ self.onmessage = function(e) {
+ let canvas = new OffscreenCanvas(128, 128);
+ let gl = canvas.getContext("webgl");
+ let ext = gl.getExtension("EXT_disjoint_timer_query");
+ if (!ext) {
+ self.postMessage("PASSED - no EXT_disjoint_timer_query extension - this is legal");
+ return false;
+ }
+ let query = ext.createQueryEXT();
+ ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query);
+ ext.endQueryEXT(ext.TIME_ELAPSED_EXT);
+ gl.clearColor(0.0, 1.0, 0.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ tick(function() {
+ const status = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT);
+ if (status) {
+ self.postMessage("PASSED - timer query object completed successfully on worker");
+ return false;
+ } else {
+ const err = gl.getError();
+ if (err != 0) {
+ self.postMessage("FAILED - GL error " + err);
+ return false;
+ }
+ }
+ return true;
+ });
+ };
+ </script>
+ <script>
+ "use strict";
+ description("This test ensures that timer query objects work with the WebGL 1.0 context created via OffscreenCanvas.");
+ if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+ } else {
+ var blob = new Blob([document.getElementById('myWorker').textContent]);
+ var worker = new Worker(URL.createObjectURL(blob));
+ worker.onmessage = function(msg) {
+ if (msg.data.startsWith("PASSED")) {
+ testPassed(msg.data);
+ } else {
+ testFailed(msg.data);
+ }
+ finishTest();
+ }
+ worker.postMessage("Start Worker");
+ }
+ </script>
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-transfer-image-bitmap.html b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-transfer-image-bitmap.html
new file mode 100644
index 0000000000..70b359216b
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/offscreencanvas/offscreencanvas-transfer-image-bitmap.html
@@ -0,0 +1,50 @@
+<!--
+Copyright (c) 2019 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Test for OffscreenCanvas TransferToImageBitmap</title>
+<link rel="stylesheet" href="../../resources/js-test-style.css"/>
+<script src="../../js/js-test-pre.js"></script>
+<script src="../../js/webgl-test-utils.js"></script>
+<script src="../../js/tests/tex-image-and-sub-image-utils.js"></script>
+<script src="../../js/tests/offscreencanvas-transfer-image-bitmap.js"></script>
+</head>
+<body>
+ <div id="description"></div>
+ <div id="console"></div>
+ <script id='myWorker' type='text/worker'>
+ self.onmessage = function(e) {
+ var canvas = new OffscreenCanvas(128, 128);
+ var gl = canvas.getContext("webgl");
+ gl.clearColor(1.0, 1.0, 0.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ var image = canvas.transferToImageBitmap();
+
+ self.postMessage({ bitmap: image },
+ [ image ]);
+ };
+ </script>
+ <script>
+ "use strict";
+ description("This test ensures that the transferToImageBitmap function of OffscreenCanvas webgl context is functional.");
+ if (!window.OffscreenCanvas) {
+ testPassed("No OffscreenCanvas support");
+ finishTest();
+ } else {
+ var blob = new Blob([document.getElementById('myWorker').textContent]);
+ var worker = new Worker(URL.createObjectURL(blob));
+
+ worker.onmessage = function(msg) {
+ testTransferToImageBitmap("webgl", msg.data.bitmap);
+ finishTest();
+ }
+ worker.postMessage("Start Worker");
+ }
+ </script>
+</body>
+</html>