Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: LayoutTests/svg/dom/script-tests/SVGPaint.js

Issue 114373004: Remove the SVGColor and SVGPaint DOM interfaces (were deprecated). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: text diff fix Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 description("This test checks the SVGPaint API");
2
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");
7
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);
14
15 // FIXME: Most tests that examine the computed style after modifying the SVGPain t 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.
19
20 function resetStyle() {
21 debug("");
22 debug("Reset style to initial value");
23 rectElement.setAttribute("style", "color: lime; fill: green");
24 shouldBeEqualToString("(fillPaint = rectElement.style.getPropertyCSSValue('f ill')).toString()", "[object SVGPaint]");
25 shouldBe("fillPaint.paintType", "SVGPaint.SVG_PAINTTYPE_RGBCOLOR");
26 shouldBeEqualToString("rectElement.style.fill", "#008000");
27 shouldBeEqualToString("document.defaultView.getComputedStyle(rectElement).fi ll", "#008000");
28 }
29
30 function checkFillColor(type, red, green, blue) {
31 shouldBe("fillPaint.colorType", type);
32 shouldBeEqualToString("(fillColor = fillPaint.rgbColor).toString()", "[objec t RGBColor]");
33 shouldBe("fillColor.red.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + r ed);
34 shouldBe("fillColor.green.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + green);
35 shouldBe("fillColor.blue.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + blue);
36 }
37
38 debug("");
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");
46
47 debug("");
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)");
57
58 debug("");
59 debug("Try invalid arguments for setUri()");
60 shouldThrow("fillPaint.setUri()");
61
62 debug("");
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");
68
69 debug("");
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-co lor(myRGB, 0, 1, 2)')");
75 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_UNKKNOWN, 'url(#foo)', 'r gb(0,0,0)', 'icc-color(myRGB, 0, 1, 2)')");
76
77 debug("");
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");
83 resetStyle();
84
85 debug("");
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");
91 resetStyle();
92
93 debug("");
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");
99 resetStyle();
100
101 debug("");
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");
107 resetStyle();
108
109 debug("");
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");
114
115 debug("");
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");
121
122 debug("");
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");
128
129 debug("");
130 debug("Test using setPaint() and SVG_PAINTTYPE_URI - c");
131 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, '', '', 'icc-color(m yRGB, 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");
135
136 debug("");
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");
144 resetStyle();
145
146 debug("");
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");
154
155 debug("");
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");
163
164 debug("");
165 debug("Test using setPaint() and SVG_PAINTTYPE_URI_CURRENTCOLOR");
166 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR, 'url(#f oo)', '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");
172
173 debug("");
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");
181
182 debug("");
183 debug("Test using setPaint() and SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR");
184 shouldThrow("fillPaint.setPaint(SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR, 'u rl(#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");
190
191 debug("");
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");
199
200 debug("");
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");
208
209 debug("");
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");
217
218 debug("");
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");
226
227 successfullyParsed = true;
OLDNEW
« no previous file with comments | « LayoutTests/svg/dom/script-tests/SVGColor.js ('k') | LayoutTests/transitions/svg-transitions-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698