Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / canvas / test / test_2d.transformation.setTransform.skewed.html
blob91077b273e48dc62447c372516738d4a73f962a0
1 <!DOCTYPE HTML>
2 <title>Canvas test: 2d.transformation.setTransform.skewed</title>
3 <script src="/MochiKit/MochiKit.js"></script>
4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
5 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
6 <body>
7 <canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
8 <script>
9 function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) {
10 var pixel = ctx.getImageData(x, y, 1, 1);
11 var pr = pixel.data[0],
12 pg = pixel.data[1],
13 pb = pixel.data[2],
14 pa = pixel.data[3];
15 ok(r-d <= pr && pr <= r+d &&
16 g-d <= pg && pg <= g+d &&
17 b-d <= pb && pb <= b+d &&
18 a-d <= pa && pa <= a+d,
19 "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
22 SimpleTest.waitForExplicitFinish();
23 MochiKit.DOM.addLoadEvent(function () {
25 var canvas = document.getElementById('c');
26 var ctx = canvas.getContext('2d');
28 // Create green with a red square ring inside it
29 ctx.fillStyle = '#0f0';
30 ctx.fillRect(0, 0, 100, 50);
31 ctx.fillStyle = '#f00';
32 ctx.fillRect(20, 10, 60, 30);
33 ctx.fillStyle = '#0f0';
34 ctx.fillRect(40, 20, 20, 10);
36 // Draw a skewed shape to fill that gap, to make sure it is aligned correctly
37 ctx.setTransform(1,4, 2,3, 5,6);
38 // Post-transform coordinates:
39 // [[20,10],[80,10],[80,40],[20,40],[20,10],[40,20],[40,30],[60,30],[60,20],[40,20],[20,10]];
40 // Hence pre-transform coordinates:
41 var pts=[[-7.4,11.2],[-43.4,59.2],[-31.4,53.2],[4.6,5.2],[-7.4,11.2],
42 [-15.4,25.2],[-11.4,23.2],[-23.4,39.2],[-27.4,41.2],[-15.4,25.2],
43 [-7.4,11.2]];
44 ctx.beginPath();
45 ctx.moveTo(pts[0][0], pts[0][1]);
46 for (var i = 0; i < pts.length; ++i)
47 ctx.lineTo(pts[i][0], pts[i][1]);
48 ctx.fill();
49 isPixel(ctx, 21,11, 0,255,0,255, "21,11", "0,255,0,255", 0);
50 isPixel(ctx, 79,11, 0,255,0,255, "79,11", "0,255,0,255", 0);
51 isPixel(ctx, 21,39, 0,255,0,255, "21,39", "0,255,0,255", 0);
52 isPixel(ctx, 79,39, 0,255,0,255, "79,39", "0,255,0,255", 0);
53 isPixel(ctx, 39,19, 0,255,0,255, "39,19", "0,255,0,255", 0);
54 isPixel(ctx, 61,19, 0,255,0,255, "61,19", "0,255,0,255", 0);
55 isPixel(ctx, 39,31, 0,255,0,255, "39,31", "0,255,0,255", 0);
56 isPixel(ctx, 61,31, 0,255,0,255, "61,31", "0,255,0,255", 0);
58 SimpleTest.finish();
60 });
61 </script>