1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/test_2d.line.cap.closed.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,53 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<title>Canvas test: 2d.line.cap.closed</title> 1.6 +<!-- Testing: Line caps are not drawn at the corners of an unclosed rectangle --> 1.7 +<script src="/tests/SimpleTest/SimpleTest.js"></script> 1.8 +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> 1.9 +<body> 1.10 +<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 1.11 +<script> 1.12 +function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) { 1.13 + var pixel = ctx.getImageData(x, y, 1, 1); 1.14 + var pr = pixel.data[0], 1.15 + pg = pixel.data[1], 1.16 + pb = pixel.data[2], 1.17 + pa = pixel.data[3]; 1.18 + ok(r-d <= pr && pr <= r+d && 1.19 + g-d <= pg && pg <= g+d && 1.20 + b-d <= pb && pb <= b+d && 1.21 + a-d <= pa && pa <= a+d, 1.22 + "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d); 1.23 +} 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 +addLoadEvent(function () { 1.27 + 1.28 +var canvas = document.getElementById('c'); 1.29 +var ctx = canvas.getContext('2d'); 1.30 + 1.31 +ctx.fillStyle = '#0f0'; 1.32 +ctx.strokeStyle = '#f00'; 1.33 +ctx.fillRect(0, 0, 100, 50); 1.34 + 1.35 +ctx.lineJoin = 'bevel'; 1.36 +ctx.lineCap = 'square'; 1.37 +ctx.lineWidth = 400; 1.38 + 1.39 +ctx.beginPath(); 1.40 +ctx.moveTo(200, 200); 1.41 +ctx.lineTo(200, 1000); 1.42 +ctx.lineTo(1000, 1000); 1.43 +ctx.lineTo(1000, 200); 1.44 +ctx.closePath(); 1.45 +ctx.stroke(); 1.46 + 1.47 +isPixel(ctx, 1,1, 0,255,0,255, "1,1", "0,255,0,255", 0); 1.48 +isPixel(ctx, 48,1, 0,255,0,255, "48,1", "0,255,0,255", 0); 1.49 +isPixel(ctx, 48,48, 0,255,0,255, "48,48", "0,255,0,255", 0); 1.50 +isPixel(ctx, 1,48, 0,255,0,255, "1,48", "0,255,0,255", 0); 1.51 + 1.52 +SimpleTest.finish(); 1.53 + 1.54 +}); 1.55 +</script> 1.56 +