Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / canvas / test / test_toDataURL.complexcolours.html
blob9a04b4150240885e9a87750190245e08ec36933f
1 <!DOCTYPE HTML>
2 <title>Canvas test: toDataURL.complexcolours</title>
3 <!-- Testing: toDataURL handles non-primary and non-solid colours correctly -->
4 <script src="/MochiKit/MochiKit.js"></script>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
7 <body>
8 <canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
9 <script>
10 function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) {
11 var pixel = ctx.getImageData(x, y, 1, 1);
12 var pr = pixel.data[0],
13 pg = pixel.data[1],
14 pb = pixel.data[2],
15 pa = pixel.data[3];
16 ok(r-d <= pr && pr <= r+d &&
17 g-d <= pg && pg <= g+d &&
18 b-d <= pb && pb <= b+d &&
19 a-d <= pa && pa <= a+d,
20 "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
22 function deferTest() {
23 _deferred = true;
25 function wrapFunction(f) {
26 return function () {
27 f.apply(null, arguments);
28 SimpleTest.finish();
32 SimpleTest.waitForExplicitFinish();
33 MochiKit.DOM.addLoadEvent(function () {
35 var canvas = document.getElementById('c');
36 var ctx = canvas.getContext('2d');
38 // (These values are chosen to survive relatively alright through being premultiplied)
39 ctx.fillStyle = 'rgba(1, 3, 254, 1)';
40 ctx.fillRect(0, 0, 25, 25);
41 ctx.fillStyle = 'rgba(8, 252, 248, 0.75)';
42 ctx.fillRect(25, 0, 25, 25);
43 ctx.fillStyle = 'rgba(6, 10, 250, 0.502)';
44 ctx.fillRect(50, 0, 25, 25);
45 ctx.fillStyle = 'rgba(12, 16, 244, 0.25)';
46 ctx.fillRect(75, 0, 25, 25);
47 var img = new Image();
48 deferTest();
49 img.onload = wrapFunction(function ()
51 ctx.drawImage(img, 0, 25);
52 // (The alpha values do not really survive float->int conversion, so just
53 // do approximate comparisons)
54 netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
55 isPixel(ctx, 12,40, 1,3,254,255, "12,40", "1,3,254,255", 0);
56 isPixel(ctx, 37,40, 8,252,248,191, "37,40", "8,252,248,191", 2);
57 isPixel(ctx, 62,40, 6,10,250,127, "62,40", "6,10,250,127", 4);
58 isPixel(ctx, 87,40, 12,16,244,63, "87,40", "12,16,244,63", 8);
59 });
60 img.src = canvas.toDataURL();
63 });
64 </script>