OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library SvgElementTest; | 5 library SvgElementTest; |
6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
7 import '../../pkg/unittest/lib/html_individual_config.dart'; | 7 import '../../pkg/unittest/lib/html_individual_config.dart'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:svg' as svg; | 9 import 'dart:svg' as svg; |
10 | 10 |
11 main() { | 11 main() { |
12 useHtmlIndividualConfiguration(); | 12 useHtmlIndividualConfiguration(); |
13 | 13 |
14 var isSvgSvgElement = | 14 var isSvgSvgElement = |
15 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); | 15 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); |
16 | 16 |
17 Collection<String> _nodeStrings(Collection<Node> input) { | 17 Collection<String> _nodeStrings(Collection<Node> input) { |
18 final out = new List<String>(); | 18 final out = new List<String>(); |
19 for (Node n in input) { | 19 for (Node n in input) { |
20 if (n is Element) { | 20 if (n is Element) { |
21 Element e = n; | 21 Element e = n; |
22 out.add(e.tagName); | 22 out.add(e.tagName); |
23 } else { | 23 } else { |
24 out.add(n.text); | 24 out.add(n.text); |
25 } | 25 } |
26 } | 26 } |
27 return out; | 27 return out; |
28 }; | 28 }; |
29 | 29 |
30 testConstructor(String tagName, Function isExpectedClass) { | 30 testConstructor(String tagName, Function isExpectedClass, |
| 31 [bool expectation = true]) { |
31 test(tagName, () { | 32 test(tagName, () { |
32 expect(isExpectedClass(new svg.SvgElement.tag(tagName)), isTrue); | 33 expect(isExpectedClass(new svg.SvgElement.tag(tagName)), expectation); |
33 expect(isExpectedClass( | 34 expect(isExpectedClass( |
34 new svg.SvgElement.svg('<$tagName></$tagName>')), isTrue); | 35 new svg.SvgElement.svg('<$tagName></$tagName>')), expectation); |
35 }); | 36 }); |
36 } | 37 } |
37 group('additionalConstructors', () { | 38 group('additionalConstructors', () { |
38 group('svg', () { | 39 test('valid', () { |
39 test('valid', () { | 40 final svgContent = """ |
40 final svgContent = """ | |
41 <svg version="1.1"> | 41 <svg version="1.1"> |
42 <circle></circle> | 42 <circle></circle> |
43 <path></path> | 43 <path></path> |
44 </svg>"""; | 44 </svg>"""; |
45 final el = new svg.SvgElement.svg(svgContent); | 45 final el = new svg.SvgElement.svg(svgContent); |
46 expect(el, isSvgSvgElement); | 46 expect(el, isSvgSvgElement); |
47 expect(el.innerHtml, "<circle></circle><path></path>"); | 47 expect(el.innerHtml, anyOf("<circle></circle><path></path>", '<circle ' |
48 expect(el.outerHtml, svgContent); | 48 'xmlns="http://www.w3.org/2000/svg" /><path ' |
49 }); | 49 'xmlns="http://www.w3.org/2000/svg" />')); |
50 | 50 expect(el.outerHtml, anyOf(svgContent, |
51 test('has no parent', () => | 51 '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">\n ' |
52 expect(new svg.SvgElement.svg('<circle/>').parent, isNull) | 52 '<circle />\n <path />\n</svg>')); |
53 ); | 53 }); |
54 | 54 |
55 test('empty', () { | 55 test('has no parent', () => |
56 expect(() => new svg.SvgElement.svg(""), throwsArgumentError); | 56 expect(new svg.SvgElement.svg('<circle/>').parent, isNull) |
57 }); | 57 ); |
58 | 58 |
59 test('too many elements', () { | 59 test('empty', () { |
60 expect(() => new svg.SvgElement.svg("<circle></circle><path></path>"), | 60 expect(() => new svg.SvgElement.svg(""), throwsArgumentError); |
61 throwsArgumentError); | 61 }); |
62 }); | 62 |
63 }); | 63 test('too many elements', () { |
64 testConstructor('altGlyphDef', (e) => e is svg.AltGlyphDefElement); | 64 expect(() => new svg.SvgElement.svg("<circle></circle><path></path>"), |
65 testConstructor('altGlyph', (e) => e is svg.AltGlyphElement); | 65 throwsArgumentError); |
66 testConstructor('animateColor', (e) => e is svg.AnimateColorElement); | 66 }); |
67 testConstructor('animate', (e) => e is svg.AnimateElement); | 67 }); |
68 // WebKit doesn't recognize animateMotion | 68 |
69 // testConstructor('animateMotion', (e) => e is svg.AnimateMotionElement); | 69 // Unfortunately, because the filtering mechanism in unitttest is a regex done |
70 testConstructor('animateTransform', (e) => e is svg.AnimateTransformElement)
; | 70 group('supported_altGlyph', () { |
71 testConstructor('cursor', (e) => e is svg.CursorElement); | 71 test('supported', () { |
72 testConstructor('feBlend', (e) => e is svg.FEBlendElement); | 72 expect(svg.AltGlyphElement.supported, true); |
73 testConstructor('feColorMatrix', (e) => e is svg.FEColorMatrixElement); | 73 }); |
74 testConstructor('feComponentTransfer', | 74 }); |
75 (e) => e is svg.FEComponentTransferElement); | 75 |
76 testConstructor('feConvolveMatrix', (e) => e is svg.FEConvolveMatrixElement)
; | 76 group('supported_animate', () { |
77 testConstructor('feDiffuseLighting', | 77 test('supported', () { |
78 (e) => e is svg.FEDiffuseLightingElement); | 78 expect(svg.AnimateElement.supported, true); |
79 testConstructor('feDisplacementMap', | 79 }); |
80 (e) => e is svg.FEDisplacementMapElement); | 80 }); |
81 testConstructor('feDistantLight', (e) => e is svg.FEDistantLightElement); | 81 |
82 testConstructor('feDropShadow', (e) => e is svg.FEDropShadowElement); | 82 group('supported_animateMotion', () { |
83 testConstructor('feFlood', (e) => e is svg.FEFloodElement); | 83 test('supported', () { |
84 testConstructor('feFuncA', (e) => e is svg.FEFuncAElement); | 84 expect(svg.AnimateMotionElement.supported, true); |
85 testConstructor('feFuncB', (e) => e is svg.FEFuncBElement); | 85 }); |
86 testConstructor('feFuncG', (e) => e is svg.FEFuncGElement); | 86 }); |
87 testConstructor('feFuncR', (e) => e is svg.FEFuncRElement); | 87 |
88 testConstructor('feGaussianBlur', (e) => e is svg.FEGaussianBlurElement); | 88 group('supported_animateTransform', () { |
89 testConstructor('feImage', (e) => e is svg.FEImageElement); | 89 test('supported', () { |
90 testConstructor('feMerge', (e) => e is svg.FEMergeElement); | 90 expect(svg.AnimateTransformElement.supported, true); |
91 testConstructor('feMergeNode', (e) => e is svg.FEMergeNodeElement); | 91 }); |
92 testConstructor('feOffset', (e) => e is svg.FEOffsetElement); | 92 }); |
93 testConstructor('fePointLight', (e) => e is svg.FEPointLightElement); | 93 |
94 testConstructor('feSpecularLighting', | 94 group('supported_feBlend', () { |
95 (e) => e is svg.FESpecularLightingElement); | 95 test('supported', () { |
96 testConstructor('feSpotLight', (e) => e is svg.FESpotLightElement); | 96 expect(svg.FEBlendElement.supported, true); |
97 testConstructor('feTile', (e) => e is svg.FETileElement); | 97 }); |
98 testConstructor('feTurbulence', (e) => e is svg.FETurbulenceElement); | 98 }); |
99 testConstructor('filter', (e) => e is svg.FilterElement); | 99 |
100 testConstructor('font', (e) => e is svg.FontElement); | 100 group('supported_feColorMatrix', () { |
101 testConstructor('font-face', (e) => e is svg.FontFaceElement); | 101 test('supported', () { |
102 testConstructor('font-face-format', (e) => e is svg.FontFaceFormatElement); | 102 expect(svg.FEColorMatrixElement.supported, true); |
103 testConstructor('font-face-name', (e) => e is svg.FontFaceNameElement); | 103 }); |
104 testConstructor('font-face-src', (e) => e is svg.FontFaceSrcElement); | 104 }); |
105 testConstructor('font-face-uri', (e) => e is svg.FontFaceUriElement); | 105 |
106 testConstructor('foreignObject', (e) => e is svg.ForeignObjectElement); | 106 group('supported_feComponentTransfer', () { |
107 testConstructor('glyph', (e) => e is svg.GlyphElement); | 107 test('supported', () { |
108 testConstructor('glyphRef', (e) => e is svg.GlyphRefElement); | 108 expect(svg.FEComponentTransferElement.supported, true); |
109 testConstructor('metadata', (e) => e is svg.MetadataElement); | 109 }); |
110 testConstructor('missing-glyph', (e) => e is svg.MissingGlyphElement); | 110 }); |
111 testConstructor('set', (e) => e is svg.SetElement); | 111 |
112 testConstructor('tref', (e) => e is svg.TRefElement); | 112 group('supported_feConvolveMatrix', () { |
113 testConstructor('vkern', (e) => e is svg.VKernElement); | 113 test('supported', () { |
| 114 expect(svg.FEConvolveMatrixElement.supported, true); |
| 115 }); |
| 116 }); |
| 117 |
| 118 group('supported_feDiffuseLighting', () { |
| 119 test('supported', () { |
| 120 expect(svg.FEDiffuseLightingElement.supported, true); |
| 121 }); |
| 122 }); |
| 123 |
| 124 group('supported_feDisplacementMap', () { |
| 125 test('supported', () { |
| 126 expect(svg.FEDisplacementMapElement.supported, true); |
| 127 }); |
| 128 }); |
| 129 |
| 130 group('supported_feDistantLight', () { |
| 131 test('supported', () { |
| 132 expect(svg.FEDistantLightElement.supported, true); |
| 133 }); |
| 134 }); |
| 135 |
| 136 group('supported_feFlood', () { |
| 137 test('supported', () { |
| 138 expect(svg.FEFloodElement.supported, true); |
| 139 }); |
| 140 }); |
| 141 |
| 142 group('supported_feFuncA', () { |
| 143 test('supported', () { |
| 144 expect(svg.FEFuncAElement.supported, true); |
| 145 }); |
| 146 }); |
| 147 |
| 148 group('supported_feFuncB', () { |
| 149 test('supported', () { |
| 150 expect(svg.FEFuncBElement.supported, true); |
| 151 }); |
| 152 }); |
| 153 |
| 154 group('supported_feFuncG', () { |
| 155 test('supported', () { |
| 156 expect(svg.FEFuncGElement.supported, true); |
| 157 }); |
| 158 }); |
| 159 |
| 160 group('supported_feFuncR', () { |
| 161 test('supported', () { |
| 162 expect(svg.FEFuncRElement.supported, true); |
| 163 }); |
| 164 }); |
| 165 |
| 166 group('supported_feGaussianBlur', () { |
| 167 test('supported', () { |
| 168 expect(svg.FEGaussianBlurElement.supported, true); |
| 169 }); |
| 170 }); |
| 171 |
| 172 group('supported_feImage', () { |
| 173 test('supported', () { |
| 174 expect(svg.FEImageElement.supported, true); |
| 175 }); |
| 176 }); |
| 177 |
| 178 group('supported_feMerge', () { |
| 179 test('supported', () { |
| 180 expect(svg.FEMergeElement.supported, true); |
| 181 }); |
| 182 }); |
| 183 |
| 184 group('supported_feMergeNode', () { |
| 185 test('supported', () { |
| 186 expect(svg.FEMergeNodeElement.supported, true); |
| 187 }); |
| 188 }); |
| 189 |
| 190 group('supported_feOffset', () { |
| 191 test('supported', () { |
| 192 expect(svg.FEOffsetElement.supported, true); |
| 193 }); |
| 194 }); |
| 195 |
| 196 group('supported_feComponentTransfer', () { |
| 197 test('supported', () { |
| 198 expect(svg.FEPointLightElement.supported, true); |
| 199 }); |
| 200 }); |
| 201 |
| 202 group('supported_feSpecularLighting', () { |
| 203 test('supported', () { |
| 204 expect(svg.FESpecularLightingElement.supported, true); |
| 205 }); |
| 206 }); |
| 207 |
| 208 group('supported_feComponentTransfer', () { |
| 209 test('supported', () { |
| 210 expect(svg.FESpotLightElement.supported, true); |
| 211 }); |
| 212 }); |
| 213 |
| 214 group('supported_feTile', () { |
| 215 test('supported', () { |
| 216 expect(svg.FETileElement.supported, true); |
| 217 }); |
| 218 }); |
| 219 |
| 220 group('supported_feTurbulence', () { |
| 221 test('supported', () { |
| 222 expect(svg.FETurbulenceElement.supported, true); |
| 223 }); |
| 224 }); |
| 225 |
| 226 group('supported_filter', () { |
| 227 test('supported', () { |
| 228 expect(svg.FilterElement.supported, true); |
| 229 }); |
| 230 }); |
| 231 |
| 232 group('supported_foreignObject', () { |
| 233 test('supported', () { |
| 234 expect(svg.ForeignObjectElement.supported, true); |
| 235 }); |
| 236 }); |
| 237 |
| 238 group('supported_set', () { |
| 239 test('supported', () { |
| 240 expect(svg.SetElement.supported, true); |
| 241 }); |
114 }); | 242 }); |
115 | 243 |
116 group('constructors', () { | 244 group('constructors', () { |
117 testConstructor('a', (e) => e is svg.AElement); | 245 test('supported', () { |
118 testConstructor('circle', (e) => e is svg.CircleElement); | 246 testConstructor('a', (e) => e is svg.AElement); |
119 testConstructor('clipPath', (e) => e is svg.ClipPathElement); | 247 testConstructor('circle', (e) => e is svg.CircleElement); |
120 testConstructor('defs', (e) => e is svg.DefsElement); | 248 testConstructor('clipPath', (e) => e is svg.ClipPathElement); |
121 testConstructor('desc', (e) => e is svg.DescElement); | 249 testConstructor('defs', (e) => e is svg.DefsElement); |
122 testConstructor('ellipse', (e) => e is svg.EllipseElement); | 250 testConstructor('desc', (e) => e is svg.DescElement); |
123 testConstructor('g', (e) => e is svg.GElement); | 251 testConstructor('ellipse', (e) => e is svg.EllipseElement); |
124 // WebKit doesn't recognize hkern | 252 testConstructor('g', (e) => e is svg.GElement); |
125 // testConstructor('hkern', (e) => e is svg.HKernElement); | 253 testConstructor('image', (e) => e is svg.ImageElement); |
126 testConstructor('image', (e) => e is svg.ImageElement); | 254 testConstructor('line', (e) => e is svg.LineElement); |
127 testConstructor('line', (e) => e is svg.LineElement); | 255 testConstructor('linearGradient', (e) => e is svg.LinearGradientElement); |
128 testConstructor('linearGradient', (e) => e is svg.LinearGradientElement); | 256 testConstructor('marker', (e) => e is svg.MarkerElement); |
129 // WebKit doesn't recognize mpath | 257 testConstructor('mask', (e) => e is svg.MaskElement); |
130 // testConstructor('mpath', (e) => e is svg.MPathElement); | 258 testConstructor('path', (e) => e is svg.PathElement); |
131 testConstructor('marker', (e) => e is svg.MarkerElement); | 259 testConstructor('pattern', (e) => e is svg.PatternElement); |
132 testConstructor('mask', (e) => e is svg.MaskElement); | 260 testConstructor('polygon', (e) => e is svg.PolygonElement); |
133 testConstructor('path', (e) => e is svg.PathElement); | 261 testConstructor('polyline', (e) => e is svg.PolylineElement); |
134 testConstructor('pattern', (e) => e is svg.PatternElement); | 262 testConstructor('radialGradient', (e) => e is svg.RadialGradientElement); |
135 testConstructor('polygon', (e) => e is svg.PolygonElement); | 263 testConstructor('rect', (e) => e is svg.RectElement); |
136 testConstructor('polyline', (e) => e is svg.PolylineElement); | 264 testConstructor('script', (e) => e is svg.ScriptElement); |
137 testConstructor('radialGradient', (e) => e is svg.RadialGradientElement); | 265 testConstructor('stop', (e) => e is svg.StopElement); |
138 testConstructor('rect', (e) => e is svg.RectElement); | 266 testConstructor('style', (e) => e is svg.StyleElement); |
139 testConstructor('script', (e) => e is svg.ScriptElement); | 267 testConstructor('switch', (e) => e is svg.SwitchElement); |
140 testConstructor('stop', (e) => e is svg.StopElement); | 268 testConstructor('symbol', (e) => e is svg.SymbolElement); |
141 testConstructor('style', (e) => e is svg.StyleElement); | 269 testConstructor('tspan', (e) => e is svg.TSpanElement); |
142 testConstructor('switch', (e) => e is svg.SwitchElement); | 270 testConstructor('text', (e) => e is svg.TextElement); |
143 testConstructor('symbol', (e) => e is svg.SymbolElement); | 271 testConstructor('textPath', (e) => e is svg.TextPathElement); |
144 testConstructor('tspan', (e) => e is svg.TSpanElement); | 272 testConstructor('title', (e) => e is svg.TitleElement); |
145 testConstructor('text', (e) => e is svg.TextElement); | 273 testConstructor('use', (e) => e is svg.UseElement); |
146 testConstructor('textPath', (e) => e is svg.TextPathElement); | 274 testConstructor('view', (e) => e is svg.ViewElement); |
147 testConstructor('title', (e) => e is svg.TitleElement); | 275 testConstructor('altGlyph', (e) => e is svg.AltGlyphElement, |
148 testConstructor('use', (e) => e is svg.UseElement); | 276 svg.AltGlyphElement.supported); |
149 testConstructor('view', (e) => e is svg.ViewElement); | 277 testConstructor('animate', (e) => e is svg.AnimateElement, |
| 278 svg.AnimateElement.supported); |
| 279 testConstructor('animateMotion', (e) => e is svg.AnimateMotionElement, |
| 280 svg.AnimateMotionElement.supported); |
| 281 testConstructor('animateTransform', (e) => e is svg.AnimateTransformElemen
t, |
| 282 svg.AnimateTransformElement.supported); |
| 283 testConstructor('feBlend', (e) => e is svg.FEBlendElement, |
| 284 svg.FEBlendElement.supported); |
| 285 testConstructor('feColorMatrix', (e) => e is svg.FEColorMatrixElement, |
| 286 svg.FEColorMatrixElement.supported); |
| 287 testConstructor('feComponentTransfer', |
| 288 (e) => e is svg.FEComponentTransferElement, |
| 289 svg.FEComponentTransferElement.supported); |
| 290 testConstructor('feConvolveMatrix', |
| 291 (e) => e is svg.FEConvolveMatrixElement, |
| 292 svg.FEConvolveMatrixElement.supported); |
| 293 testConstructor('feDiffuseLighting', |
| 294 (e) => e is svg.FEDiffuseLightingElement, |
| 295 svg.FEDiffuseLightingElement.supported); |
| 296 testConstructor('feDisplacementMap', |
| 297 (e) => e is svg.FEDisplacementMapElement, |
| 298 svg.FEDisplacementMapElement.supported); |
| 299 testConstructor('feDistantLight', (e) => e is svg.FEDistantLightElement, |
| 300 svg.FEDistantLightElement.supported); |
| 301 testConstructor('feFlood', (e) => e is svg.FEFloodElement, |
| 302 svg.FEFloodElement.supported); |
| 303 testConstructor('feFuncA', (e) => e is svg.FEFuncAElement, |
| 304 svg.FEFuncAElement.supported); |
| 305 testConstructor('feFuncB', (e) => e is svg.FEFuncBElement, |
| 306 svg.FEFuncBElement.supported); |
| 307 testConstructor('feFuncG', (e) => e is svg.FEFuncGElement, |
| 308 svg.FEFuncGElement.supported); |
| 309 testConstructor('feFuncR', (e) => e is svg.FEFuncRElement, |
| 310 svg.FEFuncRElement.supported); |
| 311 testConstructor('feGaussianBlur', (e) => e is svg.FEGaussianBlurElement, |
| 312 svg.FEGaussianBlurElement.supported); |
| 313 testConstructor('feImage', (e) => e is svg.FEImageElement, |
| 314 svg.FEImageElement.supported); |
| 315 testConstructor('feMerge', (e) => e is svg.FEMergeElement, |
| 316 svg.FEMergeElement.supported); |
| 317 testConstructor('feMergeNode', (e) => e is svg.FEMergeNodeElement, |
| 318 svg.FEMergeNodeElement.supported); |
| 319 testConstructor('feOffset', (e) => e is svg.FEOffsetElement, |
| 320 svg.FEOffsetElement.supported); |
| 321 testConstructor('fePointLight', (e) => e is svg.FEPointLightElement, |
| 322 svg.FEPointLightElement.supported); |
| 323 testConstructor('feSpecularLighting', |
| 324 (e) => e is svg.FESpecularLightingElement, |
| 325 svg.FESpecularLightingElement.supported); |
| 326 testConstructor('feSpotLight', (e) => e is svg.FESpotLightElement, |
| 327 svg.FESpotLightElement.supported); |
| 328 testConstructor('feTile', (e) => e is svg.FETileElement, |
| 329 svg.FETileElement.supported); |
| 330 testConstructor('feTurbulence', (e) => e is svg.FETurbulenceElement, |
| 331 svg.FETurbulenceElement.supported); |
| 332 testConstructor('filter', (e) => e is svg.FilterElement, |
| 333 svg.FilterElement.supported); |
| 334 testConstructor('foreignObject', (e) => e is svg.ForeignObjectElement, |
| 335 svg.ForeignObjectElement.supported); |
| 336 testConstructor('metadata', (e) => e is svg.MetadataElement); |
| 337 testConstructor('set', (e) => e is svg.SetElement, |
| 338 svg.SetElement.supported); |
| 339 }); |
150 }); | 340 }); |
151 | 341 |
152 group('outerHtml', () { | 342 group('outerHtml', () { |
153 test('outerHtml', () { | 343 test('outerHtml', () { |
154 final el = new svg.SvgSvgElement(); | 344 final el = new svg.SvgSvgElement(); |
155 el.children.add(new svg.CircleElement()); | 345 el.children.add(new svg.CircleElement()); |
156 el.children.add(new svg.PathElement()); | 346 el.children.add(new svg.PathElement()); |
157 expect([ | 347 expect([ |
158 '<svg version="1.1"><circle></circle><path></path></svg>', | 348 '<svg version="1.1"><circle></circle><path></path></svg>', |
159 '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">' | 349 '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">' |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 var el = new svg.CircleElement(); | 415 var el = new svg.CircleElement(); |
226 var classes = el.classes; | 416 var classes = el.classes; |
227 expect(el.classes.length, 0); | 417 expect(el.classes.length, 0); |
228 classes.toggle('foo'); | 418 classes.toggle('foo'); |
229 expect(el.classes.length, 1); | 419 expect(el.classes.length, 1); |
230 classes.toggle('foo'); | 420 classes.toggle('foo'); |
231 expect(el.classes.length, 0); | 421 expect(el.classes.length, 0); |
232 }); | 422 }); |
233 }); | 423 }); |
234 } | 424 } |
OLD | NEW |