blob: 6a174963ef9229150bc9139bbe55811c216354b8 [file] [log] [blame]
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
// Ensure correct behavior of canvas with fillRect+shadow after translation+rotation+scaling. A blue and red checkered pattern should be displayed.
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.setAttribute('width', '600');
canvas.setAttribute('height', '600');
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgba(0, 0, 255, 1.0)';
ctx.shadowOffsetX = 100;
ctx.shadowOffsetY = 100;
ctx.translate(-100, -100);
ctx.rotate(Math.PI/2);
ctx.scale(2, 2);
ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.fillRect(100, -150, 50, 50);
ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
ctx.fillRect(200, -150, 50, 50);
ctx.shadowBlur = 5;
ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.fillRect(100, -250, 50, 50);
ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
ctx.fillRect(200, -250, 50, 50);
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, alphaTolerance]
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 alphaTolerance = 20;
var testPixelShadowScenarios = [
['Verify solid shadow 1', 201, 205, [255, 0, 0, 255]],
['Verify solid shadow 2', 298, 298, [255, 0, 0, 255]],
['Verify solid shadow 3', 201, 298, [255, 0, 0, 255]],
['Verify solid alpha shadow 1', 201, 401, [255, 0, 0, 127, alphaTolerance]],
['Verify solid alpha shadow 2', 298, 450, [255, 0, 0, 127, alphaTolerance]],
['Verify solid alpha shadow 3', 205, 498, [255, 0, 0, 127, alphaTolerance]],
['Verify blurry shadow 1', 399, 205, [255, 0, 0, 106, alphaTolerance]],
['Verify blurry shadow 2', 500, 205, [255, 0, 0, 106, alphaTolerance]],
['Verify blurry shadow 3', 499, 299, [255, 0, 0, 85, alphaTolerance]],
['Verify blurry alpha shadow 1', 398, 405, [255, 0, 0, 36, alphaTolerance]],
['Verify blurry alpha shadow 2', 405, 501, [255, 0, 0, 36, alphaTolerance]],
['Verify blurry alpha shadow 3', 405, 501, [255, 0, 0, 36, alphaTolerance]],
];
generate_tests(testPixelShadowBlur, testPixelShadowScenarios);
</script>
</body>