blob: a870449330e9ef6650c60c50730f0b258cfb9ad8 [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, 160, [0, 0, 0, 0]],
['Verify top left 3', 250, 340, [0, 0, 0, 0]],
['Verify top left 4', 160, 250, [0, 0, 0, 0]],
['Verify top left 5', 340, 250, [0, 0, 0, 0]],
['Verify bottom left 1', 250, 450, [255, 0, 0, 126, 20]],
['Verify bottom left 2', 250, 360, [0, 0, 0, 0]],
['Verify bottom left 3', 250, 540, [0, 0, 0, 0]],
['Verify bottom left 4', 160, 450, [0, 0, 0, 0]],
['Verify bottom left 5', 340, 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, 160, [0, 0, 0, 0]],
['Verify top right 3', 450, 340, [0, 0, 0, 0]],
['Verify top right 4', 360, 250, [0, 0, 0, 0]],
['Verify top right 5', 540, 250, [0, 0, 0, 0]],
['Verify bottom right 1', 450, 450, [255, 0, 0, 126, 20]],
['Verify bottom right 2', 450, 360, [0, 0, 0, 0]],
['Verify bottom right 3', 450, 540, [0, 0, 0, 0]],
['Verify bottom right 4', 360, 450, [0, 0, 0, 0]],
['Verify bottom right 5', 540, 450, [0, 0, 0, 0]],
];
generate_tests(testPixelShadowBlur, testPixelShadowBlurScenarios);
</script>
</body>