Index: third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source-with-worker.html |
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source-with-worker.html b/third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source-with-worker.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..642b0a4d1f42a92c1ca73ff70bb9871e7de48434 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source-with-worker.html |
@@ -0,0 +1,55 @@ |
+<!DOCTYPE html> |
+<title>Test using a placeholder canvas as an image source.</title> |
+<script src="../../resources/testharness.js"></script> |
+<script src="../../resources/testharnessreport.js"></script> |
+ |
+<script id='myWorker' type='text/worker'> |
+var ctx; |
+self.onmessage = function(msg) { |
+ ctx = msg.data.getContext('2d'); |
+ ctx.fillStyle = '#0f0'; |
+ ctx.fillRect(0, 0, 100, 100); |
+ ctx.commit(); |
+ |
+ self.postMessage("done"); |
+}; |
+</script> |
+ |
+<script> |
+var t = async_test("Test that using a placeholder canvas as a source image accesses the image that was committed to the associated OffscreenCanvas in a worker."); |
+var canvas = document.createElement('canvas'); |
+canvas.width = 100; |
+canvas.height = 100; |
+var offscreen = canvas.transferControlToOffscreen(); |
+ |
+var blob = new Blob([document.getElementById('myWorker').textContent]); |
+var worker = new Worker(URL.createObjectURL(blob)); |
+worker.postMessage(offscreen, [offscreen]); |
+worker.addEventListener('message', msg => { |
+ // the message is a synchronization barrier that guarantees |
+ // that the offscreen commit has been processed on the worker thread. |
+ verifyImage(canvas, "verify that drawImage works with placeholder canvas as a source."); |
+ var testImage = new Image(); |
+ testImage.src = canvas.toDataURL(); |
+ testImage.onload = function() { |
+ verifyImage(canvas, "verify that toDataURL works on placeholder canvas."); |
+ canvas.toBlob(blob => { |
+ createImageBitmap(blob).then(image => { |
+ verifyImage(image, "verify that toBlob works on placeholder canvas."); |
+ t.done(); |
+ }) |
+ }); |
+ } |
+}); |
+ |
+function verifyImage(image, description) { |
+ var testCanvas = document.createElement('canvas'); |
+ var testCtx = testCanvas.getContext('2d'); |
+ testCtx.drawImage(image, 0, 0); |
+ |
+ t.step(function() { |
+ var pixel = testCtx.getImageData(50, 50, 1, 1).data; |
+ assert_array_equals(pixel, [0, 255, 0, 255], description); |
+ }); |
+} |
+</script> |