Skip to content

Commit

Permalink
Make Chrome behavior the expected one.
Browse files Browse the repository at this point in the history
As per the current step 3 of "Clip sourceRectangle to the dimensions of input" the cropping rectangle should be clipped to the input's dimensions.
Added early tests for the returned dimension of the ImageBitmap.

Currently Chrome passes all tests, Firefox fails 3 of them.
  • Loading branch information
Kaiido committed Jan 18, 2021
1 parent 579287f commit 25f2f92
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div id="results"></div>
<script>
const color = 204;
function testClip( name, sx, sy, sw, sh, expected ) {
function testClip( name, sx, sy, sw, sh, expectedColors, expectedWidth, expectedHeight ) {
promise_test(function(t) {
return new Promise(function(resolve, reject) {
const image = new Image();
Expand All @@ -17,6 +17,10 @@
}).then(function(image) {
return createImageBitmap(image, sx, sy, sw, sh);
}).then(function(imageBitmap) {

assert_equals(imageBitmap.width, expectedWidth);
assert_equals(imageBitmap.height, expectedHeight);

const canvas = document.createElement("canvas");
canvas.width = 16;
canvas.height = 16;
Expand All @@ -30,34 +34,34 @@
ctx.fillRect(0, 0, 20, 20);
ctx.drawImage(imageBitmap, 0, 0);

for (let [x, y, r, g, b, a] of expected) {
for (let [x, y, r, g, b, a] of expectedColors) {
_assertPixel(canvas, x,y, r,g,b,a, `${x},${y}`, `${r},${g},${b},${a}`);
}
});
}, name);
}
testClip( "simple clip inside",
8, 8, 16, 16, [
8, 8, 8, 8, [
[ 4, 4, 0,255,0,255], [12, 4, color,color,color,255],
[ 4, 12, color,color,color,255], [12, 12, color,color,color,255]
]
], 8, 8
);
testClip( "clip outside negative",
-8, -8, 16, 16, [
[ 4, 4, color,color,color,255], [12, 4, color,color,color,255],
[ 4, 12, color,color,color,255], [12, 12, 0,255,0,255]
]
[ 4, 4, 0,255,0,255], [12, 4, color,color,color,255],
[ 4, 12, color,color,color,255], [12, 12, color,color,color,255]
], 8, 8
);
testClip( "clip outside positive",
8, 8, 16, 16, [
[ 4, 4, 0,255,0,255], [12, 4, color,color,color,255],
[ 4, 12, color,color,color,255], [12, 12, color,color,color,255]
]
[ 4, 4, 0,255,0,255], [12, 4, color,color,color,255],
[ 4, 12, color,color,color,255], [12, 12, color,color,color,255]
], 8, 8
);
testClip( "clip inside using negative width and height",
24, 24, -16, -16, [
[ 4, 4, 0,255,0,255], [12, 4, color,color,color,255],
[ 4, 12, color,color,color,255], [12, 12, color,color,color,255]
]
24, 24, -16, -16, [
[ 4, 4, 0,255,0,255], [12, 4, color,color,color,255],
[ 4, 12, color,color,color,255], [12, 12, color,color,color,255]
], 8, 8
);
</script>

0 comments on commit 25f2f92

Please sign in to comment.