<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function(t) {
var canvas = document.createElement("canvas");
canvas.width = 10;
canvas.height = 10;
var ctx = canvas.getContext('2d');
ctx.globalCompositeOperation = 'copy';
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 10, 10);
ctx.drawImage(canvas, 0, 0, 10, 10, 0, 0, 5, 5);
var imageData = ctx.getImageData(0, 0, 1, 1);
var imgdata = imageData.data;
assert_equals(imgdata[0], 0);
assert_equals(imgdata[1], 255);
assert_equals(imgdata[2], 0);
assert_equals(imgdata[3], 255);
imageData = ctx.getImageData(4, 4, 1, 1);
imgdata = imageData.data;
assert_equals(imgdata[0], 0);
assert_equals(imgdata[1], 255);
assert_equals(imgdata[2], 0);
assert_equals(imgdata[3], 255);
imageData = ctx.getImageData(4, 5, 1, 1);
imgdata = imageData.data;
assert_equals(imgdata[0], 0);
assert_equals(imgdata[1], 0);
assert_equals(imgdata[2], 0);
assert_equals(imgdata[3], 0);
imageData = ctx.getImageData(5, 4, 1, 1);
imgdata = imageData.data;
assert_equals(imgdata[0], 0);
assert_equals(imgdata[1], 0);
assert_equals(imgdata[2], 0);
assert_equals(imgdata[3], 0);
}, 'Tests drawImage with self as source image, copy composite operation, and downsized destination rect. Regression test for issue crbug.com/330711');
</script>
</body>