2 <style type=
"text/css">
3 canvas
{ border: 1px solid black
; }
6 Each square canvas should contain a colored gradient bordered by a narrow white margin and a black line.
7 The column on the left contains linear gradients, the column on the right radial gradients.
<br>
10 if (window
.testRunner
)
11 testRunner
.dumpAsTextWithPixelResults();
14 function Test(description
, gradient
) {
15 // Create canvas elements
16 var lin
= document
.createElement('canvas');
17 lin
.setAttribute('id', 'canvas' + counter
+ 'lin');
18 lin
.setAttribute('height', 50);
19 lin
.setAttribute('width', 50);
20 var rad
= document
.createElement('canvas');
21 rad
.setAttribute('id', 'canvas' + counter
+ 'rad');
22 rad
.setAttribute('height', 50);
23 rad
.setAttribute('width', 50);
25 document
.body
.appendChild(lin
);
26 document
.body
.appendChild(rad
);
27 document
.body
.appendChild(document
.createTextNode(' ' + description
));
28 document
.body
.appendChild(document
.createElement('br'));
30 // Find canvas contexts
31 var linctx
= lin
.getContext('2d')
32 var radctx
= rad
.getContext('2d')
34 // Create linear and radial gradients from array
35 var lingrad
= linctx
.createLinearGradient(0, 0, 0, 50);
36 var radgrad
= linctx
.createRadialGradient(25, 25, 0, 25, 25, 25);
37 for (var i
= 0; i
< gradient
.length
- 1; i
+=2) {
38 lingrad
.addColorStop(gradient
[i
], gradient
[i
+ 1]);
39 radgrad
.addColorStop(gradient
[i
], gradient
[i
+ 1]);
43 linctx
.fillStyle
= lingrad
;
44 linctx
.fillRect(2, 2, 46, 46);
45 radctx
.fillStyle
= radgrad
;
46 radctx
.fillRect(2, 2, 46, 46);
51 // Note: This test won't be as useful with many more cases added, since
52 // they'll scroll below the pixel-test boundary.
55 Test('Green to white',
60 Test('Green to white to red',
65 // No stops at 0.0 or 1.0
66 Test('Larger green to white to larger red',
67 new Array(0.4, '#0f0',
71 // Only one stop, at zero
73 new Array(0.0, '#f00'));
75 // Only one stop, at 1.0
77 new Array(1.0, '#f00'));
79 // Only one stop, in the middle
81 new Array(0.5, '#f00'));
83 // Disjoint gradients (multiple stops at the same offset)
84 Test('Blue to white in the top (inner) half, red to yellow in the bottom (outer) half',
91 Test('Blue to white, red to yellow (same as previous)',
100 Test('Blue to white, red to yellow (same as previous)',
101 new Array(0.5, '#fff',