summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/test_offscreencanvas_toimagebitmap.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/canvas/test/test_offscreencanvas_toimagebitmap.html')
-rw-r--r--dom/canvas/test/test_offscreencanvas_toimagebitmap.html69
1 files changed, 69 insertions, 0 deletions
diff --git a/dom/canvas/test/test_offscreencanvas_toimagebitmap.html b/dom/canvas/test/test_offscreencanvas_toimagebitmap.html
new file mode 100644
index 000000000..e07f4f335
--- /dev/null
+++ b/dom/canvas/test/test_offscreencanvas_toimagebitmap.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>WebGL in OffscreenCanvas</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+</head>
+<body>
+<canvas id="c" width="64" height="64"></canvas>
+<canvas id="c2" width="64" height="64"></canvas>
+<canvas id="c-ref" width="64" height="64"></canvas>
+<script>
+
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+
+ var worker = new Worker("offscreencanvas.js");
+
+ ok(worker, "Web worker successfully created");
+
+ worker.onmessage = function(evt) {
+ var msg = evt.data || {};
+ if (msg.type == "test") {
+ ok(msg.result, msg.name);
+ }
+ if (msg.type == "imagebitmap") {
+ // testing toBlob
+ // Fill c-ref with green color.
+ var c = document.getElementById("c-ref");
+ var ctx = c.getContext("2d");
+ ctx.rect(0, 0, 64, 64);
+ ctx.fillStyle = "#00FF00";
+ ctx.fill();
+
+ var htmlCanvas = document.getElementById("c");
+ var bitmapRenderer = htmlCanvas.getContext("bitmaprenderer");
+ bitmapRenderer.transferFromImageBitmap(msg.bitmap);
+
+ ok(c.toDataURL() == htmlCanvas.toDataURL(),
+ "imagebitmap should return a 64x64 green square");
+
+ // The ownership of msg.bitmap should be transferred to canvas "c" when
+ // we called transferFromImageBitmap. So we test if the ownership is actually
+ // transferred here.
+ var htmlCanvas = document.getElementById("c2");
+ var bitmapRenderer = htmlCanvas.getContext("bitmaprenderer");
+ bitmapRenderer.transferFromImageBitmap(msg.bitmap);
+
+ SimpleTest.doesThrow(
+ function() { c2.toDataURL(); },
+ "ImageBitmap has been transferred, toDataURL will throw.");
+
+ worker.terminate();
+ SimpleTest.finish();
+ }
+ }
+
+ worker.postMessage({test: 'webgl_imagebitmap'});
+}
+
+SpecialPowers.pushPrefEnv({'set': [
+ ['gfx.offscreencanvas.enabled', true],
+ ['webgl.force-enabled', true],
+]}, runTest);
+
+</script>
+</body>
+</html>