blob: 0ad9cc4f61e864d054569479bf8831d002c4b5a9 [file] [log] [blame]
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
// Ensure correct behavior of canvas with strokePath using a gradient strokeStyle 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');
var gradient = ctx.createLinearGradient(0, 0, 300, 0);
gradient.addColorStop(0, 'rgba(0, 0, 255, 0.5)');
gradient.addColorStop(1, 'rgba(0, 0, 255, 0.5)');
ctx.save();
ctx.strokeStyle = gradient;
ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
ctx.shadowOffsetX = 250;
ctx.lineWidth = 25;
var side = 200;
// Alpha shadow.
ctx.shadowBlur = 0;
ctx.beginPath();
ctx.rect(50, 50, side, side);
ctx.stroke();
// Blurry shadow.
ctx.shadowBlur = 10;
ctx.beginPath();
ctx.rect(50, 300, side, side);
ctx.stroke();
ctx.rotate(Math.PI / 2);
// Rotated alpha shadow.
ctx.shadowBlur = 0;
ctx.beginPath();
ctx.rect(550, -250, side, side);
ctx.stroke();
// Rotated blurry shadow.
ctx.shadowBlur = 10;
ctx.beginPath();
ctx.rect(800, -250, side, side);
ctx.stroke();
ctx.restore();
var imageData, data;
ctx.fillStyle = 'black';
function testPixelShadow(x, y, color, rgbTolerance, alphaTolerance)
{
var data = ctx.getImageData(x, y, 1, 1).data;
for (i = 0; i < 3; i++)
assert_approx_equals(data[i], color[i], rgbTolerance);
assert_approx_equals(data[3], color[3], alphaTolerance);
// Plot test point.
ctx.fillRect(x, y, 3, 3);
}
var rgbTolerance = 4;
var alphaTolerance = 15;
var testScenarios = [
['Verify alpha shadow 1' ,400, 150, [0, 0, 0, 0], 0, 0],
['Verify alpha shadow 2' ,400, 75, [0, 0, 0, 0], 0, 0],
['Verify alpha shadow 3' ,400, 225, [0, 0, 0, 0], 0, 0],
['Verify alpha shadow 4' ,325, 150, [0, 0, 0, 0], 0, 0],
['Verify alpha shadow 5' ,475, 150, [0, 0, 0, 0], 0, 0],
['Verify alpha shadow 6' ,400, 50, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify alpha shadow 7' ,500, 150, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify alpha shadow 8' ,400, 250, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify alpha shadow 9' ,300, 150, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify alpha shadow 10' ,400, 25, [0, 0, 0, 0], 0, 0],
['Verify alpha shadow 11' ,525, 150, [0, 0, 0, 0], 0, 0],
['Verify alpha shadow 12' ,400, 275, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 1' ,275, 150, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 2' ,400, 400, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 3' ,400, 325, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 4' ,475, 400, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 5' ,400, 475, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 6' ,325, 400, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 7' ,400, 300, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify blurry shadow 8' ,400, 500, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify blurry shadow 9' ,300, 400, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify blurry shadow 10' ,500, 400, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify blurry shadow 11' ,525, 400, [0, 0, 0, 0], 0, 0],
['Verify blurry shadow 12' ,275, 400, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 1' ,400, 650, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 2' ,400, 575, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 3' ,400, 725, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 4' ,325, 650, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 5' ,475, 650, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 6' ,400, 550, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated alpha shadow 7' ,500, 650, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated alpha shadow 8' ,400, 750, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated alpha shadow 9' ,300, 650, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated alpha shadow 10' ,400, 525, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 11' ,525, 650, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 12' ,400, 775, [0, 0, 0, 0], 0, 0],
['Verify rotated alpha shadow 13' ,275, 650, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 1' ,400, 900, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 2' ,400, 825, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 3' ,475, 900, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 4' ,400, 975, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 5' ,325, 900, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 6' ,400, 800, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated blurry shadow 7' ,400, 1000, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated blurry shadow 8' ,300, 900, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated blurry shadow 9' ,500, 900, [255, 0, 0, 64], rgbTolerance, alphaTolerance],
['Verify rotated blurry shadow 10' ,525, 900, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 11' ,275, 900, [0, 0, 0, 0], 0, 0],
['Verify rotated blurry shadow 12' ,400, 1025, [0, 0, 0, 0], 0, 0],
];
generate_tests(testPixelShadow, testScenarios);
</script>
</body>