Files
tubestation/testing/web-platform/tests/imagebitmap-renderingcontext/tranferFromImageBitmap-ToBlob-offscreen.html
Juanmi Huertas 0815fa8c75 Bug 1566179 [wpt PR 17747] - Fixing tranferFromimageBitmap-toBlob-offscreen.html to not be flaky, a=testonly
Automatic update from web-platform-tests
Fixing tranferFromimageBitmap-toBlob-offscreen.html to not be flaky

Replacing the getElementById by the creation of a new element to ensure
that the test will not be flaky.

Changing also the name of the function to be coherent with the test itself.

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

--
Fix promises in tranferFromImageBitmap-ToBlob-offscreen.html

The test previously used promises incorrectly:
testTransferFromImageBitmapToBlobOffscreen did not return the promise
produced by convertToBlob up to promise_test, which caused the assertion
(inside testCanvas) to flakiy escape promise_test. In addition, the test
did not wait for pngImage to load before drawing it to canvas.

This change also fixes the name of the test to be more accurate
(transferToBlob -> convertToBlob).

--

wpt-commits: 88a0c99744a4941af3907dfbb3853e3c23b00f04, 811dc186a0946a67e2b1ae59c0e92ccfeb69371d
wpt-pr: 17747
2019-07-31 02:54:11 +00:00

61 lines
2.0 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 testCanvas(ctx, r, g, b, a)
{
var color = ctx.getImageData(5, 5, 1, 1).data;
assert_array_equals(color, [r, g, b, a]);
}
promise_test(function() {
function transferFromImageBitmapToBlobOffscreen(greenImage) {
var bitmapCanvas = new OffscreenCanvas(width,height);
var bitmapCtx = bitmapCanvas.getContext('bitmaprenderer');
bitmapCtx.transferFromImageBitmap(greenImage);
return bitmapCanvas.convertToBlob();
}
function drawBlobToCanvas(blob) {
// Make sure the bitmap renderer canvas is filled correctly.
var pngImage = new Image();
var myCanvasToTest = document.createElement('canvas');
myCanvasToTest.width = width;
myCanvasToTest.height = height;
// Wait for the blob img to load.
return new Promise(function(resolve) {
pngImage.src = URL.createObjectURL(blob);
pngImage.onload = function() {
var myCtxToTest = myCanvasToTest.getContext('2d');
myCtxToTest.drawImage(pngImage, 0, 0);
resolve(myCtxToTest);
};
});
}
var greenCanvas = document.createElement('canvas');
greenCanvas.width = width;
greenCanvas.height = height;
var greenCtx = greenCanvas.getContext('2d');
greenCtx.fillStyle = '#0f0';
greenCtx.fillRect(0, 0, width, height);
return createImageBitmap(greenCanvas).then(
greenImage => transferFromImageBitmapToBlobOffscreen(greenImage)
).then(
blob => drawBlobToCanvas(blob)
).then(
ctx => testCanvas(ctx, 0, 255, 0, 255)
);
},'Test that convertToBlob works and produce the expected image');
</script>