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

Unified Diff: third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source.html

Issue 2493673002: Synchronize OffscreenCanvas content with the placeholder canvas (Closed)
Patch Set: fix obsolete test 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/OffscreenCanvas-placeholder-image-source.html
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source.html b/third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source.html
new file mode 100644
index 0000000000000000000000000000000000000000..fa2b295fb74d1c7558c350df7838137e270c1a59
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source.html
@@ -0,0 +1,48 @@
+<!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>
+var t = async_test("Test that using a placeholder canvas as a source image accesses the image that was committed to the associated OffscreenCanvas.");
+var canvas = document.createElement('canvas');
+canvas.width = 100;
+canvas.height = 100;
+var offscreen = canvas.transferControlToOffscreen();
+
+var ctx = offscreen.getContext('2d');
+ctx.fillStyle = '#0f0';
+ctx.fillRect(0, 0, 100, 100);
+ctx.commit();
+verifyImage(canvas, [0, 0, 0, 0], "Verify that OffscreenCanvas.commit() does not propagate the image synchronously to the placeholder canvas.");
+
+setTimeout(function() {
+ // setTimeout is a synchronization barrier that guarantees
+ // that the offscreen commit has been processed by the event loop,
+ // as long as the timeout event is queued after the call to commit().
+ var green = [0, 255, 0, 255];
+ verifyImage(canvas, green, "verify that drawImage works with placeholder canvas as a source.");
+ var testImage = new Image();
+ testImage.src = canvas.toDataURL();
+ testImage.onload = function() {
+ verifyImage(canvas, green, "verify that toDataURL works on placeholder canvas.");
+ canvas.toBlob(blob => {
+ createImageBitmap(blob).then(image => {
+ verifyImage(image, green, "verify that toBlob works on placeholder canvas.");
+ t.done();
+ })
+ });
+ }
+}, 0);
+
+function verifyImage(image, expectedColor, 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, expectedColor, description);
+ });
+}
+</script>

Powered by Google App Engine
This is Rietveld 408576698