2 <title>Canvas Tests
</title>
3 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
8 SimpleTest
.waitForExplicitFinish();
9 const Cc
= SpecialPowers
.Cc
;
10 const Cr
= SpecialPowers
.Cr
;
12 function isPixel(ctx
, x
,y
, r
,g
,b
,a
, d
) {
13 var pos
= x
+ "," + y
;
14 var colour
= r
+ "," + g
+ "," + b
+ "," + a
;
15 var pixel
= ctx
.getImageData(x
, y
, 1, 1);
16 var pr
= pixel
.data
[0],
20 ok(r
-d
<= pr
&& pr
<= r
+d
&&
21 g
-d
<= pg
&& pg
<= g
+d
&&
22 b
-d
<= pb
&& pb
<= b
+d
&&
23 a
-d
<= pa
&& pa
<= a
+d
,
24 "pixel "+pos
+" of "+ctx
.canvas
.id
+" is "+pr
+","+pg
+","+pb
+","+pa
+"; expected "+colour
+" +/- "+d
);
28 <p>Canvas test:
2d.composite.canvaspattern.setTransform
</p>
29 <canvas id=
"ctx" width=
"100" height=
"50"><p class=
"fallback">FAIL
30 (fallback content)
</p></canvas>
31 <img src=
"image_rgrg-256x256.png" id=
"rgrg-256x256.png" width=
"32"
32 height=
"32" class=
"resource">
36 function test_2d_canvaspattern_setTransform() {
38 var canvas
= document
.getElementById('ctx');
39 var ctx
= canvas
.getContext('2d');
40 ctx
.clearRect(0,0,canvas
.width
,canvas
.height
);
41 var img
= document
.getElementById("rgrg-256x256.png");
42 var pat
= ctx
.createPattern(img
,"repeat");
44 var mtx
= new DOMMatrix()
45 pat
.setTransform(mtx
.rotate(-45).scale(0.1));
47 ctx
.fillRect(0, 0, 100, 50);
49 // If the pattern doesn't get transformed, or only gets rotated or
50 // scaled, but not both, this will not be green and will fail.
51 isPixel(ctx
, 90,14, 0,255,0,255, 0);
59 test_2d_canvaspattern_setTransform();
61 ok(false, "unexpected exception thrown in: test_2d_canvaspattern_setTransform");
67 addLoadEvent(function() {
68 SpecialPowers
.pushPrefEnv({"set":[["canvas.path.enabled", true]]}, runTests
)
71 // Don't leak the world via the Path2D reference to its window.
73 window
.p
= new Path2D();