canvas_colorsandstyles_createlineargradient_001.htm
<!doctype HTML>
<html>
<head>
<title>HTML5 Canvas Test: createlinearGradient() with two points same</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com" />
<link rel="help" href="http://www.w3.org/TR/2dcontext/#dom-context-2d-createlineargradient" />
<meta name="assert" content="If the two points in a linear gradient have identical x,y coordinates, the canvas must paint nothing." />
<script type="text/javascript">
function runTest()
{
var canvas = document.getElementById("canvas1");
var ctx = canvas.getContext("2d");
// Start by drawing a left to right, green-to-blue linear gradient.
var lingrad = ctx.createLinearGradient(0, 50, 100, 50);
lingrad.addColorStop(0, "rgba(0, 255, 0, 1.0)");
lingrad.addColorStop(1, "rgba(0, 0, 255, 1.0)");
ctx.fillStyle = lingrad;
ctx.fillRect(0, 0, 100, 50);
// Nothing must be drawn if the two points in the linear gradient are the same.
lingrad = ctx.createLinearGradient(100, 100, 100, 100);
lingrad.addColorStop(0, "rgba(255, 0, 0, 1.0)");
lingrad.addColorStop(1, "rgba(255, 0, 0, 1.0)");
ctx.fillStyle = lingrad;
ctx.fillRect(0, 0, 300, 150);
}
</script>
</head>
<body onload="runTest()">
<p>Description: If the two points in a linear gradient have identical x,y coordinates, the canvas must paint nothing.</p>
<p>Test passes if there is one left-to-right, green-to-blue linear gradient seen on the page and no red is seen on the page.</p>
<canvas id="canvas1" width="300" height="150">Browser does not support HTML5 Canvas.</canvas>
</body>
</html>