Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 811dc18

Browse files
Hexcleschromium-wpt-export-bot
authored andcommitted
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).
1 parent 88a0c99 commit 811dc18

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

imagebitmap-renderingcontext/tranferFromImageBitmap-ToBlob-offscreen.html

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,29 @@
1515
}
1616

1717
promise_test(function() {
18-
function testTransferFromImageBitmapToBlobOffscreen(greenImage) {
18+
function transferFromImageBitmapToBlobOffscreen(greenImage) {
1919
var bitmapCanvas = new OffscreenCanvas(width,height);
2020
var bitmapCtx = bitmapCanvas.getContext('bitmaprenderer');
2121
bitmapCtx.transferFromImageBitmap(greenImage);
2222

23+
return bitmapCanvas.convertToBlob();
24+
}
25+
26+
function drawBlobToCanvas(blob) {
2327
// Make sure the bitmap renderer canvas is filled correctly.
2428
var pngImage = new Image();
25-
bitmapCanvas.convertToBlob().then(function(blob){
26-
pngImage.src = URL.createObjectURL(blob);
27-
var myCanvasToTest = document.createElement('canvas');
28-
myCanvasToTest.width = width;
29-
myCanvasToTest.height = height;
30-
var myCtxToTest = myCanvasToTest.getContext('2d');
31-
myCtxToTest.drawImage(pngImage, 0, 0);
32-
testCanvas(myCtxToTest, 0, 255, 0, 255);
29+
var myCanvasToTest = document.createElement('canvas');
30+
myCanvasToTest.width = width;
31+
myCanvasToTest.height = height;
32+
33+
// Wait for the blob img to load.
34+
return new Promise(function(resolve) {
35+
pngImage.src = URL.createObjectURL(blob);
36+
pngImage.onload = function() {
37+
var myCtxToTest = myCanvasToTest.getContext('2d');
38+
myCtxToTest.drawImage(pngImage, 0, 0);
39+
resolve(myCtxToTest);
40+
};
3341
});
3442
}
3543

@@ -40,11 +48,13 @@
4048
greenCtx.fillStyle = '#0f0';
4149
greenCtx.fillRect(0, 0, width, height);
4250

43-
return Promise.all([
44-
createImageBitmap(greenCanvas),
45-
]).then(([greenImage]) => {
46-
testTransferFromImageBitmapToBlobOffscreen(greenImage);
47-
});
48-
},'Test that transferToBlob works and produce the expected image');
51+
return createImageBitmap(greenCanvas).then(
52+
greenImage => transferFromImageBitmapToBlobOffscreen(greenImage)
53+
).then(
54+
blob => drawBlobToCanvas(blob)
55+
).then(
56+
ctx => testCanvas(ctx, 0, 255, 0, 255)
57+
);
58+
},'Test that convertToBlob works and produce the expected image');
4959

5060
</script>

0 commit comments

Comments
 (0)