blob: 345b6faa728a40da2f64b8a032ece960e2dbbe31 [file] [log] [blame]
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
// Ensure correct behavior of canvas with path stroke using a strokeStyle color with alpha and a shadow.
var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.setAttribute('width', '600');
canvas.setAttribute('height', '1100');
var ctx = canvas.getContext('2d');
ctx.save();
ctx.strokeStyle = 'rgba(0, 0, 255, 0.5)';
ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
ctx.shadowOffsetX = 250;
ctx.lineWidth = 50;
function strokePath(x, y) {
ctx.beginPath();
ctx.arc(x, y, 75, 0, Math.PI*2, true);
ctx.stroke();
}
// Alpha shadow.
ctx.shadowBlur = 0;
strokePath(150, 150);
// Blurry shadow.
ctx.shadowBlur = 10;
strokePath(150, 400);
ctx.rotate(Math.PI/2);
// Rotated alpha shadow.
ctx.shadowBlur = 0;
strokePath(650, -150);
// Rotated blurry shadow.
ctx.shadowBlur = 10;
strokePath(900, -150);
ctx.restore();
var imageData, data;
ctx.fillStyle = 'black';
function testPixelAlphaShadow(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]);
}
// Plot test point.
ctx.fillRect(x, y, 3, 3);
}
var alphaTolerance = 15;
var testPixelAlphaShadowScenarios = [
['Verify alpha shadow 1', 400, 150, [0, 0, 0, 0]],
['Verify alpha shadow 2', 400, 75, [255, 0, 0, 64, alphaTolerance]],
['Verify alpha shadow 3', 400, 225, [255, 0, 0, 64, alphaTolerance]],
['Verify alpha shadow 4', 325, 150, [255, 0, 0, 64, alphaTolerance]],
['Verify alpha shadow 5', 475, 150, [255, 0, 0, 64, alphaTolerance]],
['Verify blurry shadow 1', 400, 400, [0, 0, 0, 0]],
['Verify blurry shadow 2', 400, 300, [255, 0, 0, 31, alphaTolerance]],
['Verify blurry shadow 3', 400, 500, [255, 0, 0, 31, alphaTolerance]],
['Verify blurry shadow 4', 300, 400, [255, 0, 0, 31, alphaTolerance]],
['Verify blurry shadow 5', 500, 400, [255, 0, 0, 31, alphaTolerance]],
['Verify rotated alpha shadow 1', 400, 650, [0, 0, 0, 0]],
['Verify rotated alpha shadow 2', 400, 575, [255, 0, 0, 64, alphaTolerance]],
['Verify rotated alpha shadow 3', 400, 725, [255, 0, 0, 64, alphaTolerance]],
['Verify rotated alpha shadow 4', 325, 650, [255, 0, 0, 64, alphaTolerance]],
['Verify rotated alpha shadow 5', 475, 650, [255, 0, 0, 64, alphaTolerance]],
['Verify rotated blurry shadow 1', 400, 900, [0, 0, 0, 0]],
['Verify rotated blurry shadow 2', 400, 800, [255, 0, 0, 31, alphaTolerance]],
['Verify rotated blurry shadow 3', 400, 1000, [255, 0, 0, 31, alphaTolerance]],
['Verify rotated blurry shadow 4', 300, 900, [255, 0, 0, 31, alphaTolerance]],
['Verify rotated blurry shadow 5', 500, 900, [255, 0, 0, 31, alphaTolerance]],
];
generate_tests(testPixelAlphaShadow, testPixelAlphaShadowScenarios);
</script>
</body>