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">
11 function testCanvas(bitmapCanvas
, r
, g
, b
, a
)
13 var myCanvas
= document
.createElement('canvas');
14 myCanvas
.width
= width
;
15 myCanvas
.height
= height
;
16 var myCtx
= myCanvas
.getContext('2d');
17 myCtx
.drawImage(bitmapCanvas
, 0, 0);
18 var color
= myCtx
.getImageData(5, 5, 1, 1).data
;
19 assert_array_equals(color
, [r
, g
, b
, a
]);
22 promise_test(function() {
23 function testTransferFromImageBitmapNullability(greenImage
, redImage
) {
24 var bitmapCanvas
= new OffscreenCanvas(width
,height
);
25 var bitmapCtx
= bitmapCanvas
.getContext('bitmaprenderer');
26 bitmapCtx
.transferFromImageBitmap(greenImage
);
28 // Make sure the bitmap renderer canvas is filled correctly.
29 testCanvas(bitmapCanvas
, 0, 255, 0, 255);
31 // Test if passing null resets the bitmap renderer canvas.
32 // Drawing the resetted canvas cannot change the destination canvas.
33 bitmapCtx
.transferFromImageBitmap(null);
34 testCanvas(bitmapCanvas
, 0, 0, 0, 0);
36 // Test if we can redraw the bitmap canvas correctly after reset.
37 bitmapCtx
.transferFromImageBitmap(redImage
);
38 testCanvas(bitmapCanvas
, 255, 0, 0, 255);
41 var greenCanvas
= document
.createElement('canvas');
42 greenCanvas
.width
= width
;
43 greenCanvas
.height
= height
;
44 var greenCtx
= greenCanvas
.getContext('2d');
45 greenCtx
.fillStyle
= '#0f0';
46 greenCtx
.fillRect(0, 0, width
, height
);
48 var redCanvas
= document
.createElement('canvas');
49 redCanvas
.width
= width
;
50 redCanvas
.height
= height
;
51 var redCtx
= redCanvas
.getContext('2d');
52 redCtx
.fillStyle
= '#f00';
53 redCtx
.fillRect(0, 0, width
, height
);
56 createImageBitmap(greenCanvas
),
57 createImageBitmap(redCanvas
),
58 ]).then(([greenImage
, redImage
]) => {
59 testTransferFromImageBitmapNullability(greenImage
, redImage
);
61 },'Test that transferFromImageBitmap(null) discards the previously transferred image');