| 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'; | 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 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 test(tagName, () { | 31 test(tagName, () { |
| 32 expect(isExpectedClass(new SVGElement.tag(tagName)), isTrue); | 32 expect(isExpectedClass(new svg.SvgElement.tag(tagName)), isTrue); |
| 33 expect(isExpectedClass( | 33 expect(isExpectedClass( |
| 34 new SVGElement.svg('<$tagName></$tagName>')), isTrue); | 34 new svg.SvgElement.svg('<$tagName></$tagName>')), isTrue); |
| 35 }); | 35 }); |
| 36 } | 36 } |
| 37 group('additionalConstructors', () { | 37 group('additionalConstructors', () { |
| 38 group('svg', () { | 38 group('svg', () { |
| 39 test('valid', () { | 39 test('valid', () { |
| 40 final svg = """ | 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 SVGElement.svg(svg); | 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, "<circle></circle><path></path>"); |
| 48 expect(el.outerHTML, svg); | 48 expect(el.outerHTML, svgContent); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 test('has no parent', () => | 51 test('has no parent', () => |
| 52 expect(new SVGElement.svg('<circle/>').parent, isNull) | 52 expect(new svg.SvgElement.svg('<circle/>').parent, isNull) |
| 53 ); | 53 ); |
| 54 | 54 |
| 55 test('empty', () { | 55 test('empty', () { |
| 56 expect(() => new SVGElement.svg(""), throwsArgumentError); | 56 expect(() => new svg.SvgElement.svg(""), throwsArgumentError); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 test('too many elements', () { | 59 test('too many elements', () { |
| 60 expect(() => new SVGElement.svg("<circle></circle><path></path>"), | 60 expect(() => new svg.SvgElement.svg("<circle></circle><path></path>"), |
| 61 throwsArgumentError); | 61 throwsArgumentError); |
| 62 }); | 62 }); |
| 63 }); | 63 }); |
| 64 testConstructor('altGlyphDef', (e) => e is SVGAltGlyphDefElement); | 64 testConstructor('altGlyphDef', (e) => e is svg.AltGlyphDefElement); |
| 65 testConstructor('altGlyph', (e) => e is SVGAltGlyphElement); | 65 testConstructor('altGlyph', (e) => e is svg.AltGlyphElement); |
| 66 testConstructor('animateColor', (e) => e is SVGAnimateColorElement); | 66 testConstructor('animateColor', (e) => e is svg.AnimateColorElement); |
| 67 testConstructor('animate', (e) => e is SVGAnimateElement); | 67 testConstructor('animate', (e) => e is svg.AnimateElement); |
| 68 // WebKit doesn't recognize animateMotion | 68 // WebKit doesn't recognize animateMotion |
| 69 // testConstructor('animateMotion', (e) => e is SVGAnimateMotionElement); | 69 // testConstructor('animateMotion', (e) => e is svg.AnimateMotionElement); |
| 70 testConstructor('animateTransform', (e) => e is SVGAnimateTransformElement); | 70 testConstructor('animateTransform', (e) => e is svg.AnimateTransformElement)
; |
| 71 testConstructor('cursor', (e) => e is SVGCursorElement); | 71 testConstructor('cursor', (e) => e is svg.CursorElement); |
| 72 testConstructor('feBlend', (e) => e is SVGFEBlendElement); | 72 testConstructor('feBlend', (e) => e is svg.FEBlendElement); |
| 73 testConstructor('feColorMatrix', (e) => e is SVGFEColorMatrixElement); | 73 testConstructor('feColorMatrix', (e) => e is svg.FEColorMatrixElement); |
| 74 testConstructor('feComponentTransfer', | 74 testConstructor('feComponentTransfer', |
| 75 (e) => e is SVGFEComponentTransferElement); | 75 (e) => e is svg.FEComponentTransferElement); |
| 76 testConstructor('feConvolveMatrix', (e) => e is SVGFEConvolveMatrixElement); | 76 testConstructor('feConvolveMatrix', (e) => e is svg.FEConvolveMatrixElement)
; |
| 77 testConstructor('feDiffuseLighting', | 77 testConstructor('feDiffuseLighting', |
| 78 (e) => e is SVGFEDiffuseLightingElement); | 78 (e) => e is svg.FEDiffuseLightingElement); |
| 79 testConstructor('feDisplacementMap', | 79 testConstructor('feDisplacementMap', |
| 80 (e) => e is SVGFEDisplacementMapElement); | 80 (e) => e is svg.FEDisplacementMapElement); |
| 81 testConstructor('feDistantLight', (e) => e is SVGFEDistantLightElement); | 81 testConstructor('feDistantLight', (e) => e is svg.FEDistantLightElement); |
| 82 testConstructor('feDropShadow', (e) => e is SVGFEDropShadowElement); | 82 testConstructor('feDropShadow', (e) => e is svg.FEDropShadowElement); |
| 83 testConstructor('feFlood', (e) => e is SVGFEFloodElement); | 83 testConstructor('feFlood', (e) => e is svg.FEFloodElement); |
| 84 testConstructor('feFuncA', (e) => e is SVGFEFuncAElement); | 84 testConstructor('feFuncA', (e) => e is svg.FEFuncAElement); |
| 85 testConstructor('feFuncB', (e) => e is SVGFEFuncBElement); | 85 testConstructor('feFuncB', (e) => e is svg.FEFuncBElement); |
| 86 testConstructor('feFuncG', (e) => e is SVGFEFuncGElement); | 86 testConstructor('feFuncG', (e) => e is svg.FEFuncGElement); |
| 87 testConstructor('feFuncR', (e) => e is SVGFEFuncRElement); | 87 testConstructor('feFuncR', (e) => e is svg.FEFuncRElement); |
| 88 testConstructor('feGaussianBlur', (e) => e is SVGFEGaussianBlurElement); | 88 testConstructor('feGaussianBlur', (e) => e is svg.FEGaussianBlurElement); |
| 89 testConstructor('feImage', (e) => e is SVGFEImageElement); | 89 testConstructor('feImage', (e) => e is svg.FEImageElement); |
| 90 testConstructor('feMerge', (e) => e is SVGFEMergeElement); | 90 testConstructor('feMerge', (e) => e is svg.FEMergeElement); |
| 91 testConstructor('feMergeNode', (e) => e is SVGFEMergeNodeElement); | 91 testConstructor('feMergeNode', (e) => e is svg.FEMergeNodeElement); |
| 92 testConstructor('feOffset', (e) => e is SVGFEOffsetElement); | 92 testConstructor('feOffset', (e) => e is svg.FEOffsetElement); |
| 93 testConstructor('fePointLight', (e) => e is SVGFEPointLightElement); | 93 testConstructor('fePointLight', (e) => e is svg.FEPointLightElement); |
| 94 testConstructor('feSpecularLighting', | 94 testConstructor('feSpecularLighting', |
| 95 (e) => e is SVGFESpecularLightingElement); | 95 (e) => e is svg.FESpecularLightingElement); |
| 96 testConstructor('feSpotLight', (e) => e is SVGFESpotLightElement); | 96 testConstructor('feSpotLight', (e) => e is svg.FESpotLightElement); |
| 97 testConstructor('feTile', (e) => e is SVGFETileElement); | 97 testConstructor('feTile', (e) => e is svg.FETileElement); |
| 98 testConstructor('feTurbulence', (e) => e is SVGFETurbulenceElement); | 98 testConstructor('feTurbulence', (e) => e is svg.FETurbulenceElement); |
| 99 testConstructor('filter', (e) => e is SVGFilterElement); | 99 testConstructor('filter', (e) => e is svg.FilterElement); |
| 100 testConstructor('font', (e) => e is SVGFontElement); | 100 testConstructor('font', (e) => e is svg.FontElement); |
| 101 testConstructor('font-face', (e) => e is SVGFontFaceElement); | 101 testConstructor('font-face', (e) => e is svg.FontFaceElement); |
| 102 testConstructor('font-face-format', (e) => e is SVGFontFaceFormatElement); | 102 testConstructor('font-face-format', (e) => e is svg.FontFaceFormatElement); |
| 103 testConstructor('font-face-name', (e) => e is SVGFontFaceNameElement); | 103 testConstructor('font-face-name', (e) => e is svg.FontFaceNameElement); |
| 104 testConstructor('font-face-src', (e) => e is SVGFontFaceSrcElement); | 104 testConstructor('font-face-src', (e) => e is svg.FontFaceSrcElement); |
| 105 testConstructor('font-face-uri', (e) => e is SVGFontFaceUriElement); | 105 testConstructor('font-face-uri', (e) => e is svg.FontFaceUriElement); |
| 106 testConstructor('foreignObject', (e) => e is SVGForeignObjectElement); | 106 testConstructor('foreignObject', (e) => e is svg.ForeignObjectElement); |
| 107 testConstructor('glyph', (e) => e is SVGGlyphElement); | 107 testConstructor('glyph', (e) => e is svg.GlyphElement); |
| 108 testConstructor('glyphRef', (e) => e is SVGGlyphRefElement); | 108 testConstructor('glyphRef', (e) => e is svg.GlyphRefElement); |
| 109 testConstructor('metadata', (e) => e is SVGMetadataElement); | 109 testConstructor('metadata', (e) => e is svg.MetadataElement); |
| 110 testConstructor('missing-glyph', (e) => e is SVGMissingGlyphElement); | 110 testConstructor('missing-glyph', (e) => e is svg.MissingGlyphElement); |
| 111 testConstructor('set', (e) => e is SVGSetElement); | 111 testConstructor('set', (e) => e is svg.SetElement); |
| 112 testConstructor('tref', (e) => e is SVGTRefElement); | 112 testConstructor('tref', (e) => e is svg.TRefElement); |
| 113 testConstructor('vkern', (e) => e is SVGVKernElement); | 113 testConstructor('vkern', (e) => e is svg.VKernElement); |
| 114 }); | 114 }); |
| 115 | 115 |
| 116 group('constructors', () { | 116 group('constructors', () { |
| 117 testConstructor('a', (e) => e is SVGAElement); | 117 testConstructor('a', (e) => e is svg.AElement); |
| 118 testConstructor('circle', (e) => e is SVGCircleElement); | 118 testConstructor('circle', (e) => e is svg.CircleElement); |
| 119 testConstructor('clipPath', (e) => e is SVGClipPathElement); | 119 testConstructor('clipPath', (e) => e is svg.ClipPathElement); |
| 120 testConstructor('defs', (e) => e is SVGDefsElement); | 120 testConstructor('defs', (e) => e is svg.DefsElement); |
| 121 testConstructor('desc', (e) => e is SVGDescElement); | 121 testConstructor('desc', (e) => e is svg.DescElement); |
| 122 testConstructor('ellipse', (e) => e is SVGEllipseElement); | 122 testConstructor('ellipse', (e) => e is svg.EllipseElement); |
| 123 testConstructor('g', (e) => e is SVGGElement); | 123 testConstructor('g', (e) => e is svg.GElement); |
| 124 // WebKit doesn't recognize hkern | 124 // WebKit doesn't recognize hkern |
| 125 // testConstructor('hkern', (e) => e is SVGHKernElement); | 125 // testConstructor('hkern', (e) => e is svg.HKernElement); |
| 126 testConstructor('image', (e) => e is SVGImageElement); | 126 testConstructor('image', (e) => e is svg.ImageElement); |
| 127 testConstructor('line', (e) => e is SVGLineElement); | 127 testConstructor('line', (e) => e is svg.LineElement); |
| 128 testConstructor('linearGradient', (e) => e is SVGLinearGradientElement); | 128 testConstructor('linearGradient', (e) => e is svg.LinearGradientElement); |
| 129 // WebKit doesn't recognize mpath | 129 // WebKit doesn't recognize mpath |
| 130 // testConstructor('mpath', (e) => e is SVGMPathElement); | 130 // testConstructor('mpath', (e) => e is svg.MPathElement); |
| 131 testConstructor('marker', (e) => e is SVGMarkerElement); | 131 testConstructor('marker', (e) => e is svg.MarkerElement); |
| 132 testConstructor('mask', (e) => e is SVGMaskElement); | 132 testConstructor('mask', (e) => e is svg.MaskElement); |
| 133 testConstructor('path', (e) => e is SVGPathElement); | 133 testConstructor('path', (e) => e is svg.PathElement); |
| 134 testConstructor('pattern', (e) => e is SVGPatternElement); | 134 testConstructor('pattern', (e) => e is svg.PatternElement); |
| 135 testConstructor('polygon', (e) => e is SVGPolygonElement); | 135 testConstructor('polygon', (e) => e is svg.PolygonElement); |
| 136 testConstructor('polyline', (e) => e is SVGPolylineElement); | 136 testConstructor('polyline', (e) => e is svg.PolylineElement); |
| 137 testConstructor('radialGradient', (e) => e is SVGRadialGradientElement); | 137 testConstructor('radialGradient', (e) => e is svg.RadialGradientElement); |
| 138 testConstructor('rect', (e) => e is SVGRectElement); | 138 testConstructor('rect', (e) => e is svg.RectElement); |
| 139 testConstructor('script', (e) => e is SVGScriptElement); | 139 testConstructor('script', (e) => e is svg.ScriptElement); |
| 140 testConstructor('stop', (e) => e is SVGStopElement); | 140 testConstructor('stop', (e) => e is svg.StopElement); |
| 141 testConstructor('style', (e) => e is SVGStyleElement); | 141 testConstructor('style', (e) => e is svg.StyleElement); |
| 142 testConstructor('switch', (e) => e is SVGSwitchElement); | 142 testConstructor('switch', (e) => e is svg.SwitchElement); |
| 143 testConstructor('symbol', (e) => e is SVGSymbolElement); | 143 testConstructor('symbol', (e) => e is svg.SymbolElement); |
| 144 testConstructor('tspan', (e) => e is SVGTSpanElement); | 144 testConstructor('tspan', (e) => e is svg.TSpanElement); |
| 145 testConstructor('text', (e) => e is SVGTextElement); | 145 testConstructor('text', (e) => e is svg.TextElement); |
| 146 testConstructor('textPath', (e) => e is SVGTextPathElement); | 146 testConstructor('textPath', (e) => e is svg.TextPathElement); |
| 147 testConstructor('title', (e) => e is SVGTitleElement); | 147 testConstructor('title', (e) => e is svg.TitleElement); |
| 148 testConstructor('use', (e) => e is SVGUseElement); | 148 testConstructor('use', (e) => e is svg.UseElement); |
| 149 testConstructor('view', (e) => e is SVGViewElement); | 149 testConstructor('view', (e) => e is svg.ViewElement); |
| 150 }); | 150 }); |
| 151 | 151 |
| 152 group('outerHTML', () { | 152 group('outerHTML', () { |
| 153 test('outerHTML', () { | 153 test('outerHTML', () { |
| 154 final el = new SVGSVGElement(); | 154 final el = new svg.SvgSvgElement(); |
| 155 el.elements.add(new SVGCircleElement()); | 155 el.elements.add(new svg.CircleElement()); |
| 156 el.elements.add(new SVGPathElement()); | 156 el.elements.add(new svg.PathElement()); |
| 157 expect(el.outerHTML, | 157 expect(el.outerHTML, |
| 158 '<svg version="1.1"><circle></circle><path></path></svg>'); | 158 '<svg version="1.1"><circle></circle><path></path></svg>'); |
| 159 }); | 159 }); |
| 160 }); | 160 }); |
| 161 | 161 |
| 162 group('innerHTML', () { | 162 group('innerHTML', () { |
| 163 test('get', () { | 163 test('get', () { |
| 164 final el = new SVGSVGElement(); | 164 final el = new svg.SvgSvgElement(); |
| 165 el.elements.add(new SVGCircleElement()); | 165 el.elements.add(new svg.CircleElement()); |
| 166 el.elements.add(new SVGPathElement()); | 166 el.elements.add(new svg.PathElement()); |
| 167 expect(el.innerHTML, '<circle></circle><path></path>'); | 167 expect(el.innerHTML, '<circle></circle><path></path>'); |
| 168 }); | 168 }); |
| 169 | 169 |
| 170 test('set', () { | 170 test('set', () { |
| 171 final el = new SVGSVGElement(); | 171 final el = new svg.SvgSvgElement(); |
| 172 el.elements.add(new SVGCircleElement()); | 172 el.elements.add(new svg.CircleElement()); |
| 173 el.elements.add(new SVGPathElement()); | 173 el.elements.add(new svg.PathElement()); |
| 174 el.innerHTML = '<rect></rect><a></a>'; | 174 el.innerHTML = '<rect></rect><a></a>'; |
| 175 expect(_nodeStrings(el.elements), ["rect", "a"]); | 175 expect(_nodeStrings(el.elements), ["rect", "a"]); |
| 176 }); | 176 }); |
| 177 }); | 177 }); |
| 178 | 178 |
| 179 group('elementget', () { | 179 group('elementget', () { |
| 180 test('get', () { | 180 test('get', () { |
| 181 final el = new SVGElement.svg(""" | 181 final el = new svg.SvgElement.svg(""" |
| 182 <svg version="1.1"> | 182 <svg version="1.1"> |
| 183 <circle></circle> | 183 <circle></circle> |
| 184 <path></path> | 184 <path></path> |
| 185 text | 185 text |
| 186 </svg>"""); | 186 </svg>"""); |
| 187 expect(_nodeStrings(el.elements), ["circle", "path"]); | 187 expect(_nodeStrings(el.elements), ["circle", "path"]); |
| 188 }); | 188 }); |
| 189 }); | 189 }); |
| 190 | 190 |
| 191 group('elementset', () { | 191 group('elementset', () { |
| 192 test('set', () { | 192 test('set', () { |
| 193 final el = new SVGSVGElement(); | 193 final el = new svg.SvgSvgElement(); |
| 194 el.elements = [new SVGElement.tag("circle"), new SVGElement.tag("path")]; | 194 el.elements = [new svg.SvgElement.tag("circle"), new svg.SvgElement.tag("p
ath")]; |
| 195 expect(el.innerHTML, '<circle></circle><path></path>'); | 195 expect(el.innerHTML, '<circle></circle><path></path>'); |
| 196 }); | 196 }); |
| 197 }); | 197 }); |
| 198 | 198 |
| 199 group('css', () { | 199 group('css', () { |
| 200 test('classes', () { | 200 test('classes', () { |
| 201 var el = new SVGElement.tag("circle"); | 201 var el = new svg.CircleElement(); |
| 202 var classes = el.classes; | 202 var classes = el.classes; |
| 203 expect(el.classes.length, 0); | 203 expect(el.classes.length, 0); |
| 204 classes.toggle('foo'); | 204 classes.toggle('foo'); |
| 205 expect(el.classes.length, 1); | 205 expect(el.classes.length, 1); |
| 206 classes.toggle('foo'); | 206 classes.toggle('foo'); |
| 207 expect(el.classes.length, 0); | 207 expect(el.classes.length, 0); |
| 208 }); | 208 }); |
| 209 }); | 209 }); |
| 210 } | 210 } |
| OLD | NEW |