Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / canvas / test / test_toDataURL.primarycolours.html
blob1ca5f8798ba96b60e9e171a297153bfb9dfb7448
1 <!DOCTYPE HTML>
2 <title>Canvas test: toDataURL.primarycolours</title>
3 <!-- Testing: toDataURL handles simple 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 ctx.fillStyle = '#ff0';
39 ctx.fillRect(0, 0, 25, 40);
40 ctx.fillStyle = '#0ff';
41 ctx.fillRect(25, 0, 50, 40);
42 ctx.fillStyle = '#00f';
43 ctx.fillRect(75, 0, 25, 40);
44 ctx.fillStyle = '#fff';
45 ctx.fillRect(0, 40, 100, 10);
46 var data = canvas.toDataURL();
47 ctx.fillStyle = '#f00';
48 ctx.fillRect(0, 0, 100, 50);
49 var img = new Image();
50 deferTest();
51 img.onload = wrapFunction(function ()
53 ctx.drawImage(img, 0, 0);
54 netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
55 isPixel(ctx, 12,20, 255,255,0,255, "12,20", "255,255,0,255", 0);
56 isPixel(ctx, 50,20, 0,255,255,255, "50,20", "0,255,255,255", 0);
57 isPixel(ctx, 87,20, 0,0,255,255, "87,20", "0,0,255,255", 0);
58 isPixel(ctx, 50,45, 255,255,255,255, "50,45", "255,255,255,255", 0);
59 });
60 img.src = data;
63 });
64 </script>