1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/test_2d.gradient.radial.cone.shape2.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<title>Canvas test: 2d.gradient.radial.cone.shape2</title> 1.6 +<script src="/tests/SimpleTest/SimpleTest.js"></script> 1.7 +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> 1.8 +<body> 1.9 +<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 1.10 +<script> 1.11 +function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) { 1.12 + var pixel = ctx.getImageData(x, y, 1, 1); 1.13 + var pr = pixel.data[0], 1.14 + pg = pixel.data[1], 1.15 + pb = pixel.data[2], 1.16 + pa = pixel.data[3]; 1.17 + ok(r-d <= pr && pr <= r+d && 1.18 + g-d <= pg && pg <= g+d && 1.19 + b-d <= pb && pb <= b+d && 1.20 + a-d <= pa && pa <= a+d, 1.21 + "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d); 1.22 +} 1.23 +function todo_isPixel(ctx, x,y, r,g,b,a, pos, colour, d) { 1.24 + var pixel = ctx.getImageData(x, y, 1, 1); 1.25 + var pr = pixel.data[0], 1.26 + pg = pixel.data[1], 1.27 + pb = pixel.data[2], 1.28 + pa = pixel.data[3]; 1.29 + todo(r-d <= pr && pr <= r+d && 1.30 + g-d <= pg && pg <= g+d && 1.31 + b-d <= pb && pb <= b+d && 1.32 + a-d <= pa && pa <= a+d, 1.33 + "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d); 1.34 +} 1.35 + 1.36 +SimpleTest.waitForExplicitFinish(); 1.37 +addLoadEvent(function () { 1.38 + 1.39 +var canvas = document.getElementById('c'); 1.40 +var ctx = canvas.getContext('2d'); 1.41 + 1.42 +var tol = 1; // tolerance to avoid antialiasing artifacts 1.43 + 1.44 +ctx.fillStyle = '#0f0'; 1.45 +ctx.fillRect(0, 0, 100, 50); 1.46 + 1.47 +var g = ctx.createRadialGradient(30+10*5/2, 40, 10*3/2, 30+10*15/4, 40, 10*9/4); 1.48 +g.addColorStop(0, '#f00'); 1.49 +g.addColorStop(1, '#f00'); 1.50 +ctx.fillStyle = g; 1.51 +ctx.fillRect(0, 0, 100, 50); 1.52 + 1.53 +ctx.fillStyle = '#0f0'; 1.54 +ctx.beginPath(); 1.55 +ctx.moveTo(30-tol, 40); 1.56 +ctx.lineTo(110, -20-tol); 1.57 +ctx.lineTo(110, 100+tol); 1.58 +ctx.fill(); 1.59 + 1.60 +isPixel(ctx, 1,1, 0,255,0,255, "1,1", "0,255,0,255", 0); 1.61 +isPixel(ctx, 50,1, 0,255,0,255, "50,1", "0,255,0,255", 0); 1.62 +isPixel(ctx, 98,1, 0,255,0,255, "98,1", "0,255,0,255", 0); 1.63 +isPixel(ctx, 1,25, 0,255,0,255, "1,25", "0,255,0,255", 0); 1.64 +isPixel(ctx, 50,25, 0,255,0,255, "50,25", "0,255,0,255", 0); 1.65 +isPixel(ctx, 98,25, 0,255,0,255, "98,25", "0,255,0,255", 0); 1.66 +isPixel(ctx, 1,48, 0,255,0,255, "1,48", "0,255,0,255", 0); 1.67 +isPixel(ctx, 50,48, 0,255,0,255, "50,48", "0,255,0,255", 0); 1.68 +isPixel(ctx, 98,48, 0,255,0,255, "98,48", "0,255,0,255", 0); 1.69 + 1.70 +SimpleTest.finish(); 1.71 + 1.72 +}); 1.73 +</script> 1.74 +