OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <script> |
| 5 // This test aims to ensure that OffscreenCanvas.commit() does not |
| 6 // crash for a placeholder canvas under frameless document. |
| 7 // Since the document is invisible, the resultant image should be |
| 8 // not visible too. But users must be able to draw to the OffscreenCanvas |
| 9 // and do canvas-operations on the frameless placeholder canvas. |
| 10 // TODO(crbug.com/683172): Modify this test after handling for |
| 11 // frameless canvas is done. |
| 12 function createFramelessCanvas() { |
| 13 var framelessDoc = document.implementation.createHTMLDocument("frameless"); |
| 14 var canvas = framelessDoc.createElement("canvas"); |
| 15 canvas.width = 50; |
| 16 canvas.height = 50; |
| 17 return canvas; |
| 18 } |
| 19 |
| 20 function transferControlAndCommit(canvas) { |
| 21 var offscreenCanvas = canvas.transferControlToOffscreen(); |
| 22 var ctx = offscreenCanvas.getContext("2d"); |
| 23 ctx.fillStyle = "blue"; |
| 24 ctx.fillRect(0, 0, 50, 50); |
| 25 ctx.commit(); |
| 26 return offscreenCanvas; |
| 27 } |
| 28 |
| 29 test(function() { |
| 30 var offscreenCanvas = transferControlAndCommit(createFramelessCanvas()); |
| 31 var ctx = offscreenCanvas.getContext("2d"); |
| 32 var pixels = ctx.getImageData(0, 0, 1, 1).data; |
| 33 assert_array_equals(pixels, [0, 0, 255, 255]); |
| 34 }, "Verify that the getImageData() works on the OffscreenCanvas context of a fra
meless canvas"); |
| 35 |
| 36 async_test(function(t) { |
| 37 var canvas = createFramelessCanvas(); |
| 38 var offscreenCanvas = transferControlAndCommit(canvas); |
| 39 |
| 40 var c = document.createElement("canvas"); |
| 41 c.width = 50; |
| 42 c.height = 50; |
| 43 var ctx2 = c.getContext("2d"); |
| 44 setTimeout(function() { |
| 45 ctx2.drawImage(canvas, 0, 0); |
| 46 var pixels = ctx2.getImageData(0, 0, 1, 1).data; |
| 47 t.step(function() { |
| 48 assert_array_equals(pixels, [0, 0, 255, 255]); |
| 49 }); |
| 50 t.done(); |
| 51 }, 0); |
| 52 }, "Verify that the placeholder canvas can be used as an image source"); |
| 53 </script> |
OLD | NEW |