OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <script> |
| 5 var width = 10; |
| 6 var height = 10; |
| 7 |
| 8 function testCanvas(ctx, x, y, r, g, b, a) |
| 9 { |
| 10 var color = ctx.getImageData(x, y, 1, 1).data; |
| 11 assert_array_equals(color, [r, g, b, a]); |
| 12 } |
| 13 |
| 14 |
| 15 function consumeImageBitmap(image, t) |
| 16 { |
| 17 var myCanvas = document.createElement('canvas'); |
| 18 myCanvas.width = myCanvas.height = 20; |
| 19 var myCtx = myCanvas.getContext('bitmaprenderer'); |
| 20 myCtx.transferFromImageBitmap(image); |
| 21 |
| 22 var dstCanvas = document.createElement('canvas'); |
| 23 dstCanvas.width = dstCanvas.height = 20; |
| 24 var dstCtx = dstCanvas.getContext('2d'); |
| 25 dstCtx.clearRect(0, 0, 20, 20); |
| 26 dstCtx.drawImage(myCanvas, 0, 0); |
| 27 testCanvas(dstCtx, 5, 5, 0, 255, 0, 255); |
| 28 testCanvas(dstCtx, 15, 15, 0, 0, 0, 0); |
| 29 t.done(); |
| 30 } |
| 31 |
| 32 function consumeImageBitmapByCreateImageBitmap(image, t) |
| 33 { |
| 34 var myCanvas = document.createElement('canvas'); |
| 35 myCanvas.width = myCanvas.height = 20; |
| 36 var myCtx = myCanvas.getContext('bitmaprenderer'); |
| 37 myCtx.transferFromImageBitmap(image); |
| 38 |
| 39 createImageBitmap(myCanvas).then(t.step_func_done(function(imageBitmap) { |
| 40 assert_equals(imageBitmap.width, width); |
| 41 assert_equals(imageBitmap.height, height); |
| 42 |
| 43 var dstCanvas = document.createElement('canvas'); |
| 44 dstCanvas.width = dstCanvas.height = 20; |
| 45 var dstCtx = dstCanvas.getContext('2d'); |
| 46 dstCtx.clearRect(0, 0, 20, 20); |
| 47 dstCtx.drawImage(imageBitmap, 0, 0); |
| 48 testCanvas(dstCtx, 5, 5, 0, 255, 0, 255); |
| 49 testCanvas(dstCtx, 15, 15, 0, 0, 0, 0); |
| 50 })); |
| 51 } |
| 52 |
| 53 async_test(function(t) { |
| 54 var canvas = document.createElement("canvas"); |
| 55 canvas.width = width; |
| 56 canvas.height = height; |
| 57 var ctx = canvas.getContext('2d'); |
| 58 ctx.fillStyle = '#0f0'; |
| 59 ctx.fillRect(0, 0, width, height); |
| 60 createImageBitmap(canvas).then(t.step_func(function(image) { |
| 61 consumeImageBitmap(image, t); |
| 62 })); |
| 63 }, 'Test that drawImage from a bitmaprenderer canvas produces correct result'); |
| 64 |
| 65 async_test(function(t) { |
| 66 var canvas = document.createElement("canvas"); |
| 67 canvas.width = width; |
| 68 canvas.height = height; |
| 69 var ctx = canvas.getContext('2d'); |
| 70 ctx.fillStyle = '#0f0'; |
| 71 ctx.fillRect(0, 0, width, height); |
| 72 createImageBitmap(canvas).then(t.step_func(function(image) { |
| 73 consumeImageBitmapByCreateImageBitmap(image, t); |
| 74 })); |
| 75 }, 'Test that createImageBitmap from a bitmaprenderer canvas produces correct re
sult'); |
| 76 |
| 77 async_test(function(t) { |
| 78 var canvas = document.createElement("canvas"); |
| 79 canvas.width = width; |
| 80 canvas.height = height; |
| 81 var ctx = canvas.getContext('bitmaprenderer'); |
| 82 createImageBitmap(canvas).then(t.step_func_done(function(image) { |
| 83 assert_equals(image.width, width); |
| 84 assert_equals(image.height, height); |
| 85 |
| 86 var dstCanvas = document.createElement('canvas'); |
| 87 dstCanvas.width = width; |
| 88 dstCanvas.height = height; |
| 89 var dstCtx = dstCanvas.getContext('2d'); |
| 90 dstCtx.drawImage(canvas, 0, 0); |
| 91 testCanvas(dstCtx, 5, 5, 0, 0, 0, 0); |
| 92 })); |
| 93 }, 'Test that createImageBitmap on a bitmaprenderer canvas that never consumes a
ny source produces correct result'); |
| 94 |
| 95 |
| 96 async_test(function(t) { |
| 97 var canvas = document.createElement("canvas"); |
| 98 canvas.width = width; |
| 99 canvas.height = height; |
| 100 var ctx = canvas.getContext('bitmaprenderer'); |
| 101 ctx.transferFromImageBitmap(null); |
| 102 createImageBitmap(canvas).then(t.step_func_done(function(image) { |
| 103 assert_equals(image.width, width); |
| 104 assert_equals(image.height, height); |
| 105 |
| 106 var dstCanvas = document.createElement('canvas'); |
| 107 dstCanvas.width = width; |
| 108 dstCanvas.height = height; |
| 109 var dstCtx = dstCanvas.getContext('2d'); |
| 110 dstCtx.drawImage(canvas, 0, 0); |
| 111 testCanvas(dstCtx, 5, 5, 0, 0, 0, 0); |
| 112 })); |
| 113 }, 'Test that createImageBitmap on a bitmaprenderer canvas that consumes null pr
oduces correct result'); |
| 114 </script> |
OLD | NEW |