OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Test using a placeholder canvas as an image source.</title> | 2 <title>Test using a placeholder canvas as an image source.</title> |
3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
5 | 5 |
6 <script> | 6 <script> |
7 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."); | 7 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."); |
8 var canvas = document.createElement('canvas'); | 8 var canvas = document.createElement('canvas'); |
9 canvas.width = 100; | 9 canvas.width = 100; |
10 canvas.height = 100; | 10 canvas.height = 100; |
11 var offscreen = canvas.transferControlToOffscreen(); | 11 var offscreen = canvas.transferControlToOffscreen(); |
12 | 12 |
13 var ctx = offscreen.getContext('2d'); | 13 var ctx = offscreen.getContext('2d'); |
14 ctx.fillStyle = '#0f0'; | 14 ctx.fillStyle = '#0f0'; |
15 ctx.fillRect(0, 0, 100, 100); | 15 ctx.fillRect(0, 0, 100, 100); |
16 ctx.commit(); | 16 ctx.commit(); |
17 verifyImage(canvas, [0, 0, 0, 0], "Verify that OffscreenCanvas.commit() does not
propagate the image synchronously to the placeholder canvas."); | 17 verifyImage(canvas, [0, 0, 0, 0], "Verify that OffscreenCanvas.commit() does not
propagate the image synchronously to the placeholder canvas."); |
18 | 18 |
| 19 // TODO(junov): Use the Promise returned by commit to schedule after the |
| 20 // commit. (crbug.com/709484) |
19 setTimeout(function() { | 21 setTimeout(function() { |
20 // setTimeout is a synchronization barrier that guarantees | 22 setTimeout(function() { |
21 // that the offscreen commit has been processed by the event loop, | 23 var green = [0, 255, 0, 255]; |
22 // as long as the timeout event is queued after the call to commit(). | 24 verifyImage(canvas, green, "verify that drawImage works with placeholder can
vas as a source."); |
23 var green = [0, 255, 0, 255]; | 25 var testImage = new Image(); |
24 verifyImage(canvas, green, "verify that drawImage works with placeholder canva
s as a source."); | 26 testImage.src = canvas.toDataURL(); |
25 var testImage = new Image(); | 27 testImage.onload = function() { |
26 testImage.src = canvas.toDataURL(); | 28 verifyImage(canvas, green, "verify that toDataURL works on placeholder can
vas."); |
27 testImage.onload = function() { | 29 canvas.toBlob(blob => { |
28 verifyImage(canvas, green, "verify that toDataURL works on placeholder canva
s."); | 30 createImageBitmap(blob).then(image => { |
29 canvas.toBlob(blob => { | 31 verifyImage(image, green, "verify that toBlob works on placeholder can
vas."); |
30 createImageBitmap(blob).then(image => { | 32 t.done(); |
31 » verifyImage(image, green, "verify that toBlob works on placeholder canva
s."); | 33 }) |
32 » t.done(); | 34 }); |
33 }) | 35 } |
34 }); | 36 }, 0); |
35 } | |
36 }, 0); | 37 }, 0); |
37 | 38 |
38 function verifyImage(image, expectedColor, description) { | 39 function verifyImage(image, expectedColor, description) { |
39 var testCanvas = document.createElement('canvas'); | 40 var testCanvas = document.createElement('canvas'); |
40 var testCtx = testCanvas.getContext('2d'); | 41 var testCtx = testCanvas.getContext('2d'); |
41 testCtx.drawImage(image, 0, 0); | 42 testCtx.drawImage(image, 0, 0); |
42 | 43 |
43 t.step(function() { | 44 t.step(function() { |
44 var pixel = testCtx.getImageData(50, 50, 1, 1).data; | 45 var pixel = testCtx.getImageData(50, 50, 1, 1).data; |
45 assert_array_equals(pixel, expectedColor, description); | 46 assert_array_equals(pixel, expectedColor, description); |
46 }); | 47 }); |
47 } | 48 } |
48 </script> | 49 </script> |
OLD | NEW |