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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/OffscreenCanvas-placeholder-image-source-with-worker.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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>Test using a placeholder canvas as an image source.</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5
6 <script id='myWorker' type='text/worker'>
7 var ctx;
8 self.onmessage = function(msg) {
9 ctx = msg.data.getContext('2d');
10 ctx.fillStyle = '#0f0';
11 ctx.fillRect(0, 0, 100, 100);
12 ctx.commit();
13
14 self.postMessage("done");
15 };
16 </script>
17
18 <script>
19 var t = async_test("Test that using a placeholder canvas as a source image acces ses the image that was committed to the associated OffscreenCanvas in a worker." );
20 var canvas = document.createElement('canvas');
21 canvas.width = 100;
22 canvas.height = 100;
23 var offscreen = canvas.transferControlToOffscreen();
24
25 var blob = new Blob([document.getElementById('myWorker').textContent]);
26 var worker = new Worker(URL.createObjectURL(blob));
27 worker.postMessage(offscreen, [offscreen]);
28 worker.addEventListener('message', msg => {
29 // the message is a synchronization barrier that guarantees
30 // that the offscreen commit has been processed on the worker thread.
31 verifyImage(canvas, "verify that drawImage works with placeholder canvas as a source.");
32 var testImage = new Image();
33 testImage.src = canvas.toDataURL();
34 testImage.onload = function() {
35 verifyImage(canvas, "verify that toDataURL works on placeholder canvas.");
36 canvas.toBlob(blob => {
37 createImageBitmap(blob).then(image => {
38 verifyImage(image, "verify that toBlob works on placeholder canvas.");
39 t.done();
40 })
41 });
42 }
43 });
44
45 function verifyImage(image, description) {
46 var testCanvas = document.createElement('canvas');
47 var testCtx = testCanvas.getContext('2d');
48 testCtx.drawImage(image, 0, 0);
49
50 t.step(function() {
51 var pixel = testCtx.getImageData(50, 50, 1, 1).data;
52 assert_array_equals(pixel, [0, 255, 0, 255], description);
53 });
54 }
55 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698