1 description("This test checks the SVGPaint API");
3 // Setup a real SVG document, as we want to access CSS style information.
4 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
5 svgElement.setAttribute("width", "150");
6 svgElement.setAttribute("height", "50");
8 var rectElement = document.createElementNS("http://www.w3.org/2000/svg", "rect");
9 rectElement.setAttribute("style", "color: lime; fill: green");
10 rectElement.setAttribute("width", "150");
11 rectElement.setAttribute("height", "50");
12 svgElement.appendChild(rectElement);
13 document.getElementById("description").appendChild(svgElement);
15 // FIXME: Most tests that examine the computed style after modifying the SVGPaint object fail, as we don't support
16 // invalidation of the style, if a CSSValue changes, it's also dangerous, as the CSSValues are possibly shared.
17 // We would need copy-on-write support for CSSValue first, to make this work. It's low priority though.
18 // No-one supports modifying the SVGPaint object.
20 function resetStyle() {
22 debug("Reset style to initial value");
23 rectElement.setAttribute("style", "color: lime; fill: green");
24 shouldBeEqualToString("(fillPaint = rectElement.style.getPropertyCSSValue('fill')).toString()", "[object SVGPaint]");
25 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
26 shouldBeEqualToString("rectElement.style.fill", "#008000");
27 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
30 function checkFillColor(type, red, green, blue) {
31 shouldBe("fillPaint.colorType", type);
32 shouldBeEqualToString("(fillColor = fillPaint.rgbColor).toString()", "[object RGBColor]");
33 shouldBe("fillColor.red.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + red);
34 shouldBe("fillColor.green.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + green);
35 shouldBe("fillColor.blue.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + blue);
39 debug("Check initial paint values");
40 shouldBeEqualToString("(fillPaint = rectElement.style.getPropertyCSSValue('fill')).toString()", "[object SVGPaint]");
41 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
42 shouldBeEqualToString("fillPaint.uri", "");
43 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
44 shouldBeEqualToString("rectElement.style.fill", "#008000");
45 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
48 debug("Try invalid arguments for setPaint()");
49 shouldThrow("fillPaint.setPaint(null, null, null, null)");
50 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_RGBCOLOR, svgElement, '', '');");
51 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_RGBCOLOR, '', '')");
52 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR + 1, '', '', '');");
53 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_NONE - 1, '', '', '');");
54 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI + 1, '', '', '');");
55 shouldThrow("fillPaint.setPaint()");
56 shouldThrow("fillPaint.setPaint(fillPaint)");
59 debug("Try invalid arguments for setUri()");
60 shouldThrow("fillPaint.setUri()");
63 debug("Try assigning to the readonly paintType property, which silently fails");
64 shouldBeUndefined("fillPaint.paintType = SVGPaint.SVG_PAINTTYPE_UNKKNOWN;");
65 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
66 shouldBeEqualToString("rectElement.style.fill", "#008000");
67 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
70 debug("Test using setPaint() and SVG_PAINTTYPE_UNKNOWN");
71 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_UNKKNOWN, '', '', '')");
72 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_UNKKNOWN, 'url(#foo)', '', '')");
73 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_UNKKNOWN, '', 'rgb(0,128,128)', '')");
74 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_UNKKNOWN, '', '', 'icc-color(myRGB, 0, 1, 2)')");
75 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_UNKKNOWN, 'url(#foo)', 'rgb(0,0,0)', 'icc-color(myRGB, 0, 1, 2)')");
78 debug("Test using setPaint() and SVG_PAINTTYPE_NONE - a");
79 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_NONE, '', '', '')");
80 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
81 shouldBeEqualToString("rectElement.style.fill", "#008000");
82 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
86 debug("Test using setPaint() and SVG_PAINTTYPE_NONE - b");
87 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_NONE, 'url(#foo)', '', '')");
88 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
89 shouldBeEqualToString("rectElement.style.fill", "#008000");
90 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
94 debug("Test using setPaint() and SVG_PAINTTYPE_NONE - c");
95 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_NONE, '', 'rgb(0,128,128)', '')");
96 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
97 shouldBeEqualToString("rectElement.style.fill", "#008000");
98 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
102 debug("Test using setPaint() and SVG_PAINTTYPE_NONE - d");
103 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_NONE, '', '', 'icc-color(myRGB, 0, 1, 2)')");
104 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
105 shouldBeEqualToString("rectElement.style.fill", "#008000");
106 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
110 debug("Test using setPaint() and SVG_PAINTTYPE_NONE - e");
111 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_NONE, 'url(#foo)', 'rgb(0,0,0)', 'icc-color(myRGB, 0, 1, 2)')");
112 shouldBeEqualToString("rectElement.style.fill", "#008000");
113 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
116 debug("Test using setPaint() and SVG_PAINTTYPE_URI - a");
117 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, '', '', '')");
118 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
119 shouldBeEqualToString("rectElement.style.fill", "#008000");
120 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
123 debug("Test using setPaint() and SVG_PAINTTYPE_URI - b");
124 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, '', 'rgb(0,128,128)', '')");
125 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
126 shouldBeEqualToString("rectElement.style.fill", "#008000");
127 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
130 debug("Test using setPaint() and SVG_PAINTTYPE_URI - c");
131 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, '', '', 'icc-color(myRGB, 0, 1, 2)')");
132 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
133 shouldBeEqualToString("rectElement.style.fill", "#008000");
134 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
137 debug("Test using setPaint() and SVG_PAINTTYPE_URI - d");
138 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, 'url(#test)', '', '')");
139 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
140 shouldBeEqualToString("fillPaint.uri", "");
141 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
142 shouldBeEqualToString("rectElement.style.fill", "#008000");
143 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
147 debug("Test using setPaint() and SVG_PAINTTYPE_URI - e");
148 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, 'url(#foo)', 'rgb(0,0,0)', 'icc-color(myRGB, 0, 1, 2)')");
149 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
150 shouldBeEqualToString("fillPaint.uri", "");
151 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
152 shouldBeEqualToString("rectElement.style.fill", "#008000");
153 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
156 debug("Test using setPaint() and SVG_PAINTTYPE_URI_NONE");
157 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI_NONE, 'url(#test)', 'rgb(0,0,0)', 'icc-color(myRGB, 0, 1, 2)')");
158 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
159 shouldBeEqualToString("fillPaint.uri", "");
160 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
161 shouldBeEqualToString("rectElement.style.fill", "#008000");
162 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
165 debug("Test using setPaint() and SVG_PAINTTYPE_URI_CURRENTCOLOR");
166 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR, 'url(#foo)', 'rgb(0,0,0)', 'icc-color(myRGB, 0, 1, 2)')");
167 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
168 shouldBeEqualToString("fillPaint.uri", "");
169 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
170 shouldBeEqualToString("rectElement.style.fill", "#008000");
171 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
174 debug("Test using setPaint() and SVG_PAINTTYPE_URI_RGBCOLOR");
175 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR, 'url(#test)', 'rgb(77,0,77)', 'icc-color(myRGB, 0, 1, 2)')");
176 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
177 shouldBeEqualToString("fillPaint.uri", "");
178 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
179 shouldBeEqualToString("rectElement.style.fill", "#008000");
180 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
183 debug("Test using setPaint() and SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR");
184 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR, 'url(#foo)', 'rgb(77,0,77)', 'icc-color(myRGB, 0, 1, 2)')");
185 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
186 shouldBeEqualToString("fillPaint.uri", "");
187 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
188 shouldBeEqualToString("rectElement.style.fill", "#008000");
189 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
192 debug("Test using setPaint() and SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR");
193 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR, 'url(#test)', 'rgb(77,0,77)', 'icc-color(myRGB, 0, 1, 2)')");
194 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
195 shouldBeEqualToString("fillPaint.uri", "");
196 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
197 shouldBeEqualToString("rectElement.style.fill", "#008000");
198 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
201 debug("Test using setPaint() and SVG_PAINTTYPE_CURRENTCOLOR");
202 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_CURRENTCOLOR, 'url(#foo)', 'rgb(77,0,77)', 'icc-color(myRGB, 0, 1, 2)')");
203 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
204 shouldBeEqualToString("fillPaint.uri", "");
205 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
206 shouldBeEqualToString("rectElement.style.fill", "#008000");
207 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
210 debug("Test using setPaint() and SVG_PAINTTYPE_RGBCOLOR");
211 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_RGBCOLOR, 'url(#test)', 'rgb(0,77,0)', 'icc-color(myRGB, 0, 1, 2)')");
212 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
213 shouldBeEqualToString("fillPaint.uri", "");
214 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
215 shouldBeEqualToString("rectElement.style.fill", "#008000");
216 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
219 debug("Test using setUri()");
220 shouldBeUndefined("fillPaint.setUri('url(#foobar)');");
221 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
222 shouldBeEqualToString("fillPaint.uri", "");
223 checkFillColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 0, 128, 0);
224 shouldBeEqualToString("rectElement.style.fill", "#008000");
225 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fill", "#008000");
227 successfullyParsed = true;