3 import "testhelper.js" as Helper
6 id:canvas; width:1;height:1;renderTarget:Canvas.Image
8 name: "fillStyle"; when: windowShown
9 function test_default() {
10 var ctx = canvas.getContext('2d');
12 verify(ctx.fillStyle, "#000000");
13 ctx.clearRect(0, 0, 1, 1);
14 compare(ctx.fillStyle, "#000000");
17 var ctx = canvas.getContext('2d');
19 ctx.fillStyle = '#fa0';
20 compare(ctx.fillStyle, '#ffaa00');
21 ctx.fillStyle = Qt.rgba(0,0,0,0);
22 compare(ctx.fillStyle, 'rgba(0, 0, 0, 0.0)');
25 var ctx = canvas.getContext('2d');
27 ctx.fillStyle = '#f00';
28 compare(ctx.fillStyle, '#ff0000');
29 ctx.fillStyle = "#0f0";
30 compare(ctx.fillStyle, '#00ff00');
31 ctx.fillStyle = "#0fF";
32 compare(ctx.fillStyle, '#00ffff');
33 ctx.fillStyle = "#0aCCfb";
34 compare(ctx.fillStyle, '#0accfb');
37 function test_invalid() {
38 var ctx = canvas.getContext('2d');
40 ctx.fillStyle = '#fa0';
41 compare(ctx.fillStyle, '#ffaa00');
42 ctx.fillStyle = "invalid";
43 compare(ctx.fillStyle, '#ffaa00');
44 ctx.fillStyle = "rgb (1, 2, 3)";
45 compare(ctx.fillStyle, '#ffaa00');
46 ctx.fillStyle = '#fa0';
48 ctx.fillStyle = "rgba(3, 1, 2)";
49 compare(ctx.fillStyle, '#ffaa00');
50 ctx.fillStyle = "rgb((3,4,1)";
51 compare(ctx.fillStyle, '#ffaa00');
52 ctx.fillStyle = "rgb(1, 3, 4, 0.5)";
53 compare(ctx.fillStyle, '#ffaa00');
54 ctx.fillStyle = "hsl(2, 3, 4, 0.8)";
55 compare(ctx.fillStyle, '#ffaa00');
56 ctx.fillStyle = "hsl(2, 3, 4";
57 compare(ctx.fillStyle, '#ffaa00');
59 function test_saverestore() {
60 var ctx = canvas.getContext('2d');
61 var old = ctx.fillStyle;
63 ctx.fillStyle = "#ffaaff";
65 compare(ctx.fillStyle, old);
67 ctx.fillStyle = "#ffcc88";
70 compare(ctx.fillStyle, old);
73 function test_namedColor() {
74 var ctx = canvas.getContext('2d');
76 ctx.fillStyle = "red";
77 ctx.fillRect(0,0,1,1);
78 verify(Helper.comparePixel(ctx,0,0,255,0,0,255));
80 ctx.fillStyle = "black";
81 ctx.fillRect(0,0,1,1);
82 verify(Helper.comparePixel(ctx,0,0,0,0,0,255));
84 ctx.fillStyle = "white";
85 ctx.fillRect(0,0,1,1);
86 verify(Helper.comparePixel(ctx,0,0,255,255,255,255));
88 function test_rgba() {
89 var ctx = canvas.getContext('2d');
91 ctx.fillStyle = "rgb(-100, 300, 255)";
92 compare(ctx.fillStyle, "#00ffff");
93 ctx.fillStyle = "rgba(-100, 300, 255, 0.0)";
94 compare(ctx.fillStyle, "rgba(0, 255, 255, 0.0)");
95 ctx.fillStyle = "rgb(-10%, 110%, 50%)";
96 compare(ctx.fillStyle, "#00ff80");
98 ctx.clearRect(0, 0, 1, 1);
99 ctx.fillStyle = 'rgba(0%, 100%, 0%, 0.499)';
100 ctx.fillRect(0, 0, 1, 1);
101 verify(Helper.comparePixel(ctx, 0,0, 0,255,0,127));
104 function test_hsla() {
105 var ctx = canvas.getContext('2d');
107 ctx.fillStyle = "hsla(120, 100%, 50%, 0.499)";
108 ctx.fillRect(0, 0, 1, 1);
109 verify(Helper.comparePixel(ctx,0,0,0,255,0,127));