Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / svg / css / script-tests / svg-attribute-parser-mode.js
blob32c00380057dfef5ce2284a3b12bbc89e0740beb
1 if (window.testRunner)
2 testRunner.dumpAsText();
4 description("Test strict color parsing on SVG presentation attributes.")
5 createSVGTestCase();
7 var rect = createSVGElement("rect");
8 rect.setAttribute("id", "rect");
9 rect.setAttribute("width", "100px");
10 rect.setAttribute("height", "100px");
11 rootSVGElement.appendChild(rect);
14 // Testing 'fill'
15 // The default for fill is rgb(0, 0, 0).
16 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 0, 0)");
18 // Set the fill color to green.
19 rect.setAttribute("fill", "green");
20 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
22 // Set following colors should be invalid.
23 rect.setAttribute("fill", "f00");
24 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 0, 0)");
25 // Reset to green.
26 rect.setAttribute("fill", "green");
27 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
29 rect.setAttribute("fill", "ff00");
30 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 0, 0)");
31 // Reset to green.
32 rect.setAttribute("fill", "green");
33 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
35 rect.setAttribute("fill", "ff0000");
36 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 0, 0)");
37 // Reset to green.
38 rect.setAttribute("fill", "green");
39 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
41 rect.setAttribute("fill", "ff00");
42 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 0, 0)");
43 // Reset to green.
44 rect.setAttribute("fill", "green");
45 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
47 rect.setAttribute("fill", "");
48 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 0, 0)");
49 // Reset to green.
50 rect.setAttribute("fill", "green");
51 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
53 rect.setAttribute("fill", "url(#reference)");
54 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "url(#reference)");
55 // Reset to green.
56 rect.setAttribute("fill", "green");
57 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
59 rect.setAttribute("fill", "url(#reference) green");
60 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "url(#reference) rgb(0, 128, 0)");
61 // Reset to green.
62 rect.setAttribute("fill", "green");
63 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).fill", "rgb(0, 128, 0)");
66 // Testing 'stroke'
67 // The default stroke value should be 'none'.
68 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "none");
70 // Set the stroke color to green.
71 rect.setAttribute("stroke", "green");
72 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
74 // Set following colors should be invalid.
75 rect.setAttribute("stroke", "f00");
76 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "none");
77 // Reset to green.
78 rect.setAttribute("stroke", "green");
79 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
81 rect.setAttribute("stroke", "ff00");
82 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "none");
83 // Reset to green.
84 rect.setAttribute("stroke", "green");
85 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
87 rect.setAttribute("stroke", "ff0000");
88 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "none");
89 // Reset to green.
90 rect.setAttribute("stroke", "green");
91 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
93 rect.setAttribute("stroke", "ff00");
94 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "none");
95 // Reset to green.
96 rect.setAttribute("stroke", "green");
97 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
99 rect.setAttribute("stroke", "");
100 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "none");
101 // Reset to green.
102 rect.setAttribute("stroke", "green");
103 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
105 rect.setAttribute("stroke", "url(#reference)");
106 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "url(#reference)");
107 // Reset to green.
108 rect.setAttribute("stroke", "green");
109 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
111 rect.setAttribute("stroke", "url(#reference) green");
112 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "url(#reference) rgb(0, 128, 0)");
113 // Reset to green.
114 rect.setAttribute("stroke", "green");
115 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stroke", "rgb(0, 128, 0)");
118 // Testing 'color'
119 // The default for color is rgb(0, 0, 0).
120 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 0, 0)");
122 // Set color to green.
123 rect.setAttribute("color", "green");
124 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 128, 0)");
126 // Set following colors should be invalid.
127 rect.setAttribute("color", "f00");
128 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 0, 0)");
129 // Reset to green.
130 rect.setAttribute("color", "green");
131 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 128, 0)");
133 rect.setAttribute("color", "ff00");
134 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 0, 0)");
135 // Reset to green.
136 rect.setAttribute("color", "green");
137 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 128, 0)");
139 rect.setAttribute("color", "ff0000");
140 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 0, 0)");
141 // Reset to green.
142 rect.setAttribute("color", "green");
143 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 128, 0)");
145 rect.setAttribute("color", "ff00");
146 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 0, 0)");
147 // Reset to green.
148 rect.setAttribute("color", "green");
149 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 128, 0)");
151 rect.setAttribute("color", "");
152 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 0, 0)");
153 // Reset to green.
154 rect.setAttribute("color", "green");
155 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).color", "rgb(0, 128, 0)");
158 // Testing 'stop-color'
159 // The default for stop-color is rgb(0, 0, 0).
160 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 0, 0)");
162 // Set color to green.
163 rect.setAttribute("stop-color", "green");
164 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 128, 0)");
166 // Set following colors should be invalid.
167 rect.setAttribute("stop-color", "f00");
168 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 0, 0)");
169 // Reset to green.
170 rect.setAttribute("stop-color", "green");
171 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 128, 0)");
173 rect.setAttribute("stop-color", "ff00");
174 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 0, 0)");
175 // Reset to green.
176 rect.setAttribute("stop-color", "green");
177 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 128, 0)");
179 rect.setAttribute("stop-color", "ff0000");
180 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 0, 0)");
181 // Reset to green.
182 rect.setAttribute("stop-color", "green");
183 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 128, 0)");
185 rect.setAttribute("stop-color", "ff00");
186 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 0, 0)");
187 // Reset to green.
188 rect.setAttribute("stop-color", "green");
189 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 128, 0)");
191 rect.setAttribute("stop-color", "");
192 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 0, 0)");
193 // Reset to green.
194 rect.setAttribute("stop-color", "green");
195 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).stopColor", "rgb(0, 128, 0)");
198 // Testing 'flood-color'
199 // The default for flood-color is rgb(0, 0, 0).
200 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 0, 0)");
202 // Set color to green.
203 rect.setAttribute("flood-color", "green");
204 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 128, 0)");
206 // Set following colors should be invalid.
207 rect.setAttribute("flood-color", "f00");
208 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 0, 0)");
209 // Reset to green.
210 rect.setAttribute("flood-color", "green");
211 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 128, 0)");
213 rect.setAttribute("flood-color", "ff00");
214 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 0, 0)");
215 // Reset to green.
216 rect.setAttribute("flood-color", "green");
217 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 128, 0)");
219 rect.setAttribute("flood-color", "ff0000");
220 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 0, 0)");
221 // Reset to green.
222 rect.setAttribute("flood-color", "green");
223 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 128, 0)");
225 rect.setAttribute("flood-color", "ff00");
226 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 0, 0)");
227 // Reset to green.
228 rect.setAttribute("flood-color", "green");
229 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 128, 0)");
231 rect.setAttribute("flood-color", "");
232 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 0, 0)");
233 // Reset to green.
234 rect.setAttribute("flood-color", "green");
235 shouldBeEqualToString("document.defaultView.getComputedStyle(rect, null).floodColor", "rgb(0, 128, 0)");
237 var successfullyParsed = true;
239 completeTest();