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