fune/testing/web-platform/tests/imagebitmap-renderingcontext/context-creation-with-alpha.html
Juanmi Huertas 5b4082637f Bug 1556071 [wpt PR 17121] - Reland "Reland "Adding support to bitmaprenderer in OffscreenCanvas"", a=testonly
Automatic update from web-platform-tests
Reland "Reland "Adding support to bitmaprenderer in OffscreenCanvas""

Registering the factory on OffscreenCanvas in modules, adding
ImageBitmapRenderer to the union type for OffscreenCanvas.
Adding new functionality to bitmaprenderer to let it be used
in offscreencanvas.
Changing IDL and some tests to validate new functionality.
Adding a new virtual test to guarantee testing validation
of trasnsfertooffscreencanvas for bitmaprenderer.

Added bug: 969151 for the two missing tests.

TBR=chrishtr

Bug: 907141
Change-Id: I7c611952686aabdf2eb3df8ffe5ca73a69ae97f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1638919
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665260}

--

wp5At-commits: 209c15ce44be1c7a9059167676843e1a711a2734
wpt-pr: 17121
2019-06-19 11:06:34 -07:00

64 lines
2.4 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8">
<title>Canvas's ImageBitmapRenderingContext test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#the-imagebitmap-rendering-context">
<script>
var width = 10;
var height = 10;
function testImageBitmap(image, opts, expectedR, expectedG, expectedB, expectedA)
{
var dstCanvas = document.createElement('canvas');
dstCanvas.width = width;
dstCanvas.height = height;
var dstCtx = dstCanvas.getContext('bitmaprenderer', opts);
dstCtx.transferFromImageBitmap(image);
var myCanvas = document.createElement('canvas');
myCanvas.width = width;
myCanvas.height = height;
var myCtx = myCanvas.getContext('2d');
myCtx.drawImage(dstCanvas, 0, 0);
var color = myCtx.getImageData(5, 5, 1, 1).data;
assert_array_approx_equals(color, [expectedR, expectedG, expectedB, expectedA],1);
}
promise_test(function() {
var srcCanvas = document.createElement('canvas');
srcCanvas.width = width;
srcCanvas.height = height;
var ctx = srcCanvas.getContext('2d');
ctx.fillStyle = 'rgba(0, 255, 0, 0.5)';
ctx.fillRect(0, 0, width, height);
return createImageBitmap(srcCanvas).then(function(image) {
testImageBitmap(image, {alpha: false}, 0, 255, 0, 128);
});
}, "Test that an ImageBitmapRenderingContext with alpha disabled makes the canvas opaque");
promise_test(function() {
var srcCanvas = document.createElement('canvas');
srcCanvas.width = width;
srcCanvas.height = height;
var ctx = srcCanvas.getContext('2d');
ctx.fillStyle = 'rgba(0, 255, 0, 0.5)';
ctx.fillRect(0, 0, width, height);
return createImageBitmap(srcCanvas).then(function(image) {
testImageBitmap(image, {alpha: true}, 0, 255, 0, 128);
});
}, "Test that an ImageBitmapRenderingContext with alpha enabled preserves the alpha");
promise_test(function() {
var srcCanvas = document.createElement('canvas');
srcCanvas.width = width;
srcCanvas.height = height;
var ctx = srcCanvas.getContext('2d');
ctx.fillStyle = 'rgba(0, 255, 0, 0.5)';
ctx.fillRect(0, 0, width, height);
return createImageBitmap(srcCanvas).then(function(image) {
testImageBitmap(image, {}, 0, 255, 0, 128);
});
}, "Test that the 'alpha' context creation attribute is true by default");
</script>