blob: 6dba9daa0e25dda757a844665c6c16e0d95d8d26 [file] [log] [blame]
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
// Ensure that canvas shadowBlur is not affected by transformations.
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.setAttribute('width', '600');
canvas.setAttribute('height', '600');
var ctx = canvas.getContext('2d');
ctx.shadowBlur = 25;
ctx.shadowOffsetX = 100;
ctx.shadowOffsetY = 100;
ctx.fillStyle = 'rgba(0, 0, 255, 1)';
// top left
ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.scale(4, 4);
ctx.rotate(Math.PI/2);
ctx.translate(25, -50);
ctx.fillRect(0, 0, 25, 25);
// bottom left
ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.scale(0.5, 0.5);
ctx.fillRect(200, 600, 200, 200);
// top right
ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.scale(2, 2);
ctx.fillRect(300, 100, 100, 100);
// bottom right
ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
ctx.fillRect(300, 300, 100, 100);
function testPixelShadowBlur(x, y, color)
{
if (color.length == 4) {
assert_array_equals(ctx.getImageData(x, y, 1, 1).data, color);
} else { // we expect to have [r, g, b, a, alphaApprox]
var data = ctx.getImageData(x, y, 1, 1).data;
assert_array_equals(data.slice(0,3), color.slice(0,3));
assert_approx_equals(data[3], color[3], color[4]);
}
}
var testPixelShadowBlurScenarios = [
['Verify top left 1', 250, 250, [255, 0, 0, 255]],
['Verify top left 2', 250, 175, [0, 0, 0, 0]],
['Verify top left 3', 250, 325, [0, 0, 0, 0]],
['Verify top left 4', 175, 250, [0, 0, 0, 0]],
['Verify top left 5', 325, 250, [0, 0, 0, 0]],
['Verify bottom left 1', 250, 450, [255, 0, 0, 126, 20]],
['Verify bottom left 2', 250, 375, [0, 0, 0, 0]],
['Verify bottom left 3', 250, 525, [0, 0, 0, 0]],
['Verify bottom left 4', 175, 450, [0, 0, 0, 0]],
['Verify bottom left 5', 325, 450, [0, 0, 0, 0]],
['Verify bottom left 6', 250, 250, [255, 0, 0, 255, 20]],
['Verify top right 1', 450, 250, [255, 0, 0, 255, 20]],
['Verify top right 2', 450, 175, [0, 0, 0, 0]],
['Verify top right 3', 450, 325, [0, 0, 0, 0]],
['Verify top right 4', 375, 250, [0, 0, 0, 0]],
['Verify top right 5', 525, 250, [0, 0, 0, 0]],
['Verify bottom right 1', 450, 450, [255, 0, 0, 126, 20]],
['Verify bottom right 2', 450, 375, [0, 0, 0, 0]],
['Verify bottom right 3', 450, 525, [0, 0, 0, 0]],
['Verify bottom right 2', 375, 450, [0, 0, 0, 0]],
['Verify bottom right 2', 525, 450, [0, 0, 0, 0]],
];
generate_tests(testPixelShadowBlur, testPixelShadowBlurScenarios);
</script>
</body>