<!-- Test based on that found at
http://philip.html5.org/tests/canvas/suite/tests/2d.drawImage.negativesource.html
-->
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<canvas id="canvas" width="100" height="100"></canvas>
<script>
test(function(){
var canvas2 = document.createElement('canvas');
canvas2.width = 100;
canvas2.height = 100;
var ctx2 = canvas2.getContext('2d');
ctx2.fillStyle = '#f00';
ctx2.fillRect(0, 0, 100, 50);
ctx2.fillStyle = '#0f0';
ctx2.fillRect(0, 50, 100, 50);
var canvas = document.getElementById('canvas').getContext('2d');
canvas.drawImage(canvas2, 100, 50, -50, 50, 0, 0, 50, 50);
canvas.drawImage(canvas2, 100, 100, -50, -50, 0, 100, 50, -50);
canvas.drawImage(canvas2, 0, 100, 100, -50, 100, 100, -50, -50);
canvas.drawImage(canvas2, 0, 50, 100, 50, 100, 0, -50, 50);
var imageData = canvas.getImageData(1, 0, 1, 1).data;
assert_array_equals(imageData.slice(0,3), [0, 255, 0]);
// test width or height -1
canvas.fillStyle = '#000';
canvas.fillRect(0, 0, 1, 2);
canvas.drawImage(canvas2, 0, 0, 1, 1, 1, 1, -1, -1);
var imageData = canvas.getImageData(0, 0, 1, 2).data;
assert_array_equals(imageData.slice(0,3), [255, 0, 0]);
assert_array_equals(imageData.slice(4,7), [0, 0, 0]);
}, "Series of tests to ensure correct behaviour on negative source/destination of a HTMLCanvasElement");
</script>