blob: 04fbc317eee0b155884014c1fa8afda57a04924a [file] [log] [blame]
<!DOCTYPE html>
<!-- Test based on that found at
http://philip.html5.org/tests/canvas/suite/tests/index.2d.composite.globalAlpha.html
-->
<title>Test that canvas2d context fills with the globalAlpha property when applied</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<canvas width="100" height="100"></canvas>
<script>
test(function() {
function assertPixelApprox(ctx, x, y, r, g, b, a, pos, colour, tolerance) {
var imgdata = ctx.getImageData(x, y, 1, 1);
var diff = Math.max(Math.abs(r-imgdata.data[0]), Math.abs(g-imgdata.data[1]), Math.abs(b-imgdata.data[2]), Math.abs(a-imgdata.data[3]));
assert_less_than_equal(diff, tolerance);
}
var ctx = document.querySelector('canvas').getContext('2d');
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 100);
ctx.globalAlpha = 0.01; // avoid any potential alpha = 0 optimisations.
ctx.beginPath();
ctx.fillStyle = '#f00';
ctx.rect(0, 0, 100, 100);
ctx.fill();
assertPixelApprox(ctx, 50, 25, 2, 253, 0, 255, "50,25", "2,253,0,255", 2);
});
</script>