OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset="utf-8"> |
| 3 <title>Canvas's ImageBitmapRenderingContext test</title> |
| 4 <script src="/resources/testharness.js"></script> |
| 5 <script src="/resources/testharnessreport.js"></script> |
| 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#the
-imagebitmap-rendering-context"> |
| 7 <script> |
| 8 var width = 10; |
| 9 var height = 10; |
| 10 |
| 11 function testCanvas(ctx, r, g, b, a) |
| 12 { |
| 13 var color = ctx.getImageData(5, 5, 1, 1).data; |
| 14 assert_array_equals(color, [r, g, b, a]); |
| 15 } |
| 16 |
| 17 function consumeImageBitmap(image, alphaVal, expectedR, expectedG, expectedB, ex
pectedA) |
| 18 { |
| 19 var dstCanvas = document.createElement('canvas'); |
| 20 dstCanvas.width = width; |
| 21 dstCanvas.height = height; |
| 22 var dstCtx; |
| 23 if (alphaVal == 'true') |
| 24 dstCtx = dstCanvas.getContext('bitmaprenderer', { alpha: true }); |
| 25 else if (alphaVal == 'false') |
| 26 dstCtx = dstCanvas.getContext('bitmaprenderer', { alpha: false }); |
| 27 else |
| 28 dstCtx = dstCanvas.getContext('bitmaprenderer'); |
| 29 dstCtx.transferFromImageBitmap(image); |
| 30 |
| 31 var myCanvas = document.createElement('canvas'); |
| 32 myCanvas.width = width; |
| 33 myCanvas.height = height; |
| 34 var myCtx = myCanvas.getContext('2d'); |
| 35 myCtx.drawImage(dstCanvas, 0, 0); |
| 36 testCanvas(myCtx, expectedR, expectedG, expectedB, expectedA); |
| 37 } |
| 38 |
| 39 promise_test(function() { |
| 40 var srcCanvas = document.createElement('canvas'); |
| 41 srcCanvas.width = width; |
| 42 srcCanvas.height = height; |
| 43 var ctx = srcCanvas.getContext('2d'); |
| 44 ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; |
| 45 ctx.fillRect(0, 0, width, height); |
| 46 createImageBitmap(srcCanvas).then(function(image) { |
| 47 consumeImageBitmap(image, 'false', 0, 127, 0, 255); |
| 48 }); |
| 49 }, "Test that an ImageBitmapRenderingContext with alpha disabled makes the canva
s opaque"); |
| 50 |
| 51 promise_test(function() { |
| 52 var srcCanvas = document.createElement('canvas'); |
| 53 srcCanvas.width = width; |
| 54 srcCanvas.height = height; |
| 55 var ctx = srcCanvas.getContext('2d'); |
| 56 ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; |
| 57 ctx.fillRect(0, 0, width, height); |
| 58 createImageBitmap(srcCanvas).then(function(image) { |
| 59 consumeImageBitmap(image, 'true', 0, 255, 0, 127); |
| 60 }); |
| 61 }, "Test that an ImageBitmapRenderingContext with alpha enabled preserves the al
pha"); |
| 62 |
| 63 promise_test(function() { |
| 64 var srcCanvas = document.createElement('canvas'); |
| 65 srcCanvas.width = width; |
| 66 srcCanvas.height = height; |
| 67 var ctx = srcCanvas.getContext('2d'); |
| 68 ctx.fillStyle = 'rgba(0, 255, 0, 0.5)'; |
| 69 ctx.fillRect(0, 0, width, height); |
| 70 createImageBitmap(srcCanvas).then(function(image) { |
| 71 consumeImageBitmap(image, '', 0, 255, 0, 127); |
| 72 }); |
| 73 }, "Test that the 'alpha' context creation attribute is true by default"); |
| 74 |
| 75 </script> |
OLD | NEW |