blob: 2c8fa08b9d340c9c0f1cb446a7a445fdc08cfff0 [file] [log] [blame]
xidachen9bf98772016-11-10 20:27:011<!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>
8var width = 10;
9var height = 10;
10
Juanmi Huertas209c15c2019-05-31 21:26:2511function testImageBitmap(image, opts, expectedR, expectedG, expectedB, expectedA)
xidachen9bf98772016-11-10 20:27:0112{
13 var dstCanvas = document.createElement('canvas');
14 dstCanvas.width = width;
15 dstCanvas.height = height;
Juanmi Huertas209c15c2019-05-31 21:26:2516 var dstCtx = dstCanvas.getContext('bitmaprenderer', opts);
xidachen9bf98772016-11-10 20:27:0117 dstCtx.transferFromImageBitmap(image);
18
19 var myCanvas = document.createElement('canvas');
20 myCanvas.width = width;
21 myCanvas.height = height;
22 var myCtx = myCanvas.getContext('2d');
23 myCtx.drawImage(dstCanvas, 0, 0);
Juanmi Huertas209c15c2019-05-31 21:26:2524 var color = myCtx.getImageData(5, 5, 1, 1).data;
25 assert_array_approx_equals(color, [expectedR, expectedG, expectedB, expectedA],1);
xidachen9bf98772016-11-10 20:27:0126}
27
28promise_test(function() {
29 var srcCanvas = document.createElement('canvas');
30 srcCanvas.width = width;
31 srcCanvas.height = height;
32 var ctx = srcCanvas.getContext('2d');
33 ctx.fillStyle = 'rgba(0, 255, 0, 0.5)';
34 ctx.fillRect(0, 0, width, height);
xidachen47e0eb92016-11-14 19:43:1135 return createImageBitmap(srcCanvas).then(function(image) {
Juanmi Huertas209c15c2019-05-31 21:26:2536 testImageBitmap(image, {alpha: false}, 0, 255, 0, 128);
xidachen9bf98772016-11-10 20:27:0137 });
38}, "Test that an ImageBitmapRenderingContext with alpha disabled makes the canvas opaque");
39
40promise_test(function() {
41 var srcCanvas = document.createElement('canvas');
42 srcCanvas.width = width;
43 srcCanvas.height = height;
44 var ctx = srcCanvas.getContext('2d');
45 ctx.fillStyle = 'rgba(0, 255, 0, 0.5)';
46 ctx.fillRect(0, 0, width, height);
xidachen47e0eb92016-11-14 19:43:1147 return createImageBitmap(srcCanvas).then(function(image) {
Juanmi Huertas209c15c2019-05-31 21:26:2548 testImageBitmap(image, {alpha: true}, 0, 255, 0, 128);
xidachen9bf98772016-11-10 20:27:0149 });
50}, "Test that an ImageBitmapRenderingContext with alpha enabled preserves the alpha");
51
52promise_test(function() {
53 var srcCanvas = document.createElement('canvas');
54 srcCanvas.width = width;
55 srcCanvas.height = height;
56 var ctx = srcCanvas.getContext('2d');
57 ctx.fillStyle = 'rgba(0, 255, 0, 0.5)';
58 ctx.fillRect(0, 0, width, height);
xidachen47e0eb92016-11-14 19:43:1159 return createImageBitmap(srcCanvas).then(function(image) {
Juanmi Huertas209c15c2019-05-31 21:26:2560 testImageBitmap(image, {}, 0, 255, 0, 128);
xidachen9bf98772016-11-10 20:27:0161 });
62}, "Test that the 'alpha' context creation attribute is true by default");
63
64</script>