chromium/third_party/blink/web_tests/fast/canvas/canvas-scale-strokePath-shadow.html

<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
// Ensure correct behavior of canvas with path stroke + shadow after 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.scale(2, 2);
ctx.shadowOffsetX = 100;
ctx.shadowOffsetY = 100;
ctx.strokeStyle = 'rgba(0, 0, 255, 1)';
ctx.lineWidth = 5;

ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(100, 50);
ctx.lineTo(100, 100);
ctx.lineTo(50, 100);
ctx.lineTo(50, 50);
ctx.stroke();

ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
ctx.beginPath();
ctx.moveTo(50, 150);
ctx.lineTo(100, 150);
ctx.lineTo(100, 200);
ctx.lineTo(50, 200);
ctx.lineTo(50, 150);
ctx.stroke();

ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.shadowBlur = 10;
ctx.beginPath();
ctx.moveTo(150, 50);
ctx.lineTo(200, 50);
ctx.lineTo(200, 100);
ctx.lineTo(150, 100);
ctx.lineTo(150, 50);
ctx.stroke();

ctx.shadowColor = 'rgba(255, 0, 0, 0.6)';
ctx.beginPath();
ctx.moveTo(150, 150);
ctx.lineTo(200, 150);
ctx.lineTo(200, 200);
ctx.lineTo(150, 200);
ctx.lineTo(150, 150);
ctx.stroke();

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 testPixelShadowScenarios = [
    ['Verify solid shadow 1', 250, 200, [255, 0, 0, 255]],
    ['Verify solid shadow 2', 300, 290, [255, 0, 0, 255]],
    ['Verify solid shadow 3', 200, 250, [255, 0, 0, 255]],

    ['Verify solid alpha shadow 1', 201, 405, [255, 0, 0, 76, 20]],
    ['Verify solid alpha shadow 2', 201, 500, [255, 0, 0, 76, 20]],
    ['Verify solid alpha shadow 3', 300, 499, [255, 0, 0, 76, 20]],

    ['Verify blurry shadow 1', 398, 210, [255, 0, 0, 170, 20]],
    ['Verify blurry shadow 2', 508, 250, [255, 0, 0, 49, 20]],
    ['Verify blurry shadow 3', 450, 198, [255, 0, 0, 178, 20]],

    ['Verify blurry alpha shadow 1', 505, 450, [255, 0, 0, 70, 20]],
    ['Verify blurry alpha shadow 2', 450, 405, [255, 0, 0, 70, 20]],
];

generate_tests(testPixelShadowBlur, testPixelShadowScenarios);

</script>
</body>