| 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_config.dart'; | 7 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 useHtmlConfiguration(); | 11 useHtmlIndividualConfiguration(); |
| 12 | 12 |
| 13 var isSVGSVGElement = | 13 var isSVGSVGElement = |
| 14 predicate((x) => x is SVGSVGElement, 'is a SVGSVGElement'); | 14 predicate((x) => x is SVGSVGElement, 'is a SVGSVGElement'); |
| 15 | 15 |
| 16 Collection<String> _nodeStrings(Collection<Node> input) { | 16 Collection<String> _nodeStrings(Collection<Node> input) { |
| 17 final out = new List<String>(); | 17 final out = new List<String>(); |
| 18 for (Node n in input) { | 18 for (Node n in input) { |
| 19 if (n is Element) { | 19 if (n is Element) { |
| 20 Element e = n; | 20 Element e = n; |
| 21 out.add(e.tagName); | 21 out.add(e.tagName); |
| 22 } else { | 22 } else { |
| 23 out.add(n.text); | 23 out.add(n.text); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 return out; | 26 return out; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 testConstructor(String tagName, Function isExpectedClass) { | 29 testConstructor(String tagName, Function isExpectedClass) { |
| 30 test(tagName, () { | 30 test(tagName, () { |
| 31 expect(isExpectedClass(new SVGElement.tag(tagName)), isTrue); | 31 expect(isExpectedClass(new SVGElement.tag(tagName)), isTrue); |
| 32 expect(isExpectedClass( | 32 expect(isExpectedClass( |
| 33 new SVGElement.svg('<$tagName></$tagName>')), isTrue); | 33 new SVGElement.svg('<$tagName></$tagName>')), isTrue); |
| 34 }); | 34 }); |
| 35 } | 35 } |
| 36 | 36 group('additionalConstructors', () { |
| 37 group('constructors', () { | |
| 38 group('svg', () { | 37 group('svg', () { |
| 39 test('valid', () { | 38 test('valid', () { |
| 40 final svg = """ | 39 final svg = """ |
| 41 <svg version="1.1"> | 40 <svg version="1.1"> |
| 42 <circle></circle> | 41 <circle></circle> |
| 43 <path></path> | 42 <path></path> |
| 44 </svg>"""; | 43 </svg>"""; |
| 45 final el = new SVGElement.svg(svg); | 44 final el = new SVGElement.svg(svg); |
| 46 expect(el, isSVGSVGElement); | 45 expect(el, isSVGSVGElement); |
| 47 expect(el.innerHTML, "<circle></circle><path></path>"); | 46 expect(el.innerHTML, "<circle></circle><path></path>"); |
| 48 expect(el.outerHTML, svg); | 47 expect(el.outerHTML, svg); |
| 49 }); | 48 }); |
| 50 | 49 |
| 51 test('has no parent', () => | 50 test('has no parent', () => |
| 52 expect(new SVGElement.svg('<circle/>').parent, isNull) | 51 expect(new SVGElement.svg('<circle/>').parent, isNull) |
| 53 ); | 52 ); |
| 54 | 53 |
| 55 test('empty', () { | 54 test('empty', () { |
| 56 expect(() => new SVGElement.svg(""), throwsArgumentError); | 55 expect(() => new SVGElement.svg(""), throwsArgumentError); |
| 57 }); | 56 }); |
| 58 | 57 |
| 59 test('too many elements', () { | 58 test('too many elements', () { |
| 60 expect(() => new SVGElement.svg("<circle></circle><path></path>"), | 59 expect(() => new SVGElement.svg("<circle></circle><path></path>"), |
| 61 throwsArgumentError); | 60 throwsArgumentError); |
| 62 }); | 61 }); |
| 63 }); | 62 }); |
| 64 | |
| 65 testConstructor('a', (e) => e is SVGAElement); | |
| 66 testConstructor('altGlyphDef', (e) => e is SVGAltGlyphDefElement); | 63 testConstructor('altGlyphDef', (e) => e is SVGAltGlyphDefElement); |
| 67 testConstructor('altGlyph', (e) => e is SVGAltGlyphElement); | 64 testConstructor('altGlyph', (e) => e is SVGAltGlyphElement); |
| 68 testConstructor('animateColor', (e) => e is SVGAnimateColorElement); | 65 testConstructor('animateColor', (e) => e is SVGAnimateColorElement); |
| 69 testConstructor('animate', (e) => e is SVGAnimateElement); | 66 testConstructor('animate', (e) => e is SVGAnimateElement); |
| 70 // WebKit doesn't recognize animateMotion | 67 // WebKit doesn't recognize animateMotion |
| 71 // testConstructor('animateMotion', (e) => e is SVGAnimateMotionElement); | 68 // testConstructor('animateMotion', (e) => e is SVGAnimateMotionElement); |
| 72 testConstructor('animateTransform', (e) => e is SVGAnimateTransformElement); | 69 testConstructor('animateTransform', (e) => e is SVGAnimateTransformElement); |
| 73 testConstructor('circle', (e) => e is SVGCircleElement); | |
| 74 testConstructor('clipPath', (e) => e is SVGClipPathElement); | |
| 75 testConstructor('cursor', (e) => e is SVGCursorElement); | 70 testConstructor('cursor', (e) => e is SVGCursorElement); |
| 76 testConstructor('defs', (e) => e is SVGDefsElement); | |
| 77 testConstructor('desc', (e) => e is SVGDescElement); | |
| 78 testConstructor('ellipse', (e) => e is SVGEllipseElement); | |
| 79 testConstructor('feBlend', (e) => e is SVGFEBlendElement); | 71 testConstructor('feBlend', (e) => e is SVGFEBlendElement); |
| 80 testConstructor('feColorMatrix', (e) => e is SVGFEColorMatrixElement); | 72 testConstructor('feColorMatrix', (e) => e is SVGFEColorMatrixElement); |
| 81 testConstructor('feComponentTransfer', | 73 testConstructor('feComponentTransfer', |
| 82 (e) => e is SVGFEComponentTransferElement); | 74 (e) => e is SVGFEComponentTransferElement); |
| 83 testConstructor('feConvolveMatrix', (e) => e is SVGFEConvolveMatrixElement); | 75 testConstructor('feConvolveMatrix', (e) => e is SVGFEConvolveMatrixElement); |
| 84 testConstructor('feDiffuseLighting', | 76 testConstructor('feDiffuseLighting', |
| 85 (e) => e is SVGFEDiffuseLightingElement); | 77 (e) => e is SVGFEDiffuseLightingElement); |
| 86 testConstructor('feDisplacementMap', | 78 testConstructor('feDisplacementMap', |
| 87 (e) => e is SVGFEDisplacementMapElement); | 79 (e) => e is SVGFEDisplacementMapElement); |
| 88 testConstructor('feDistantLight', (e) => e is SVGFEDistantLightElement); | 80 testConstructor('feDistantLight', (e) => e is SVGFEDistantLightElement); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 testConstructor('feTile', (e) => e is SVGFETileElement); | 96 testConstructor('feTile', (e) => e is SVGFETileElement); |
| 105 testConstructor('feTurbulence', (e) => e is SVGFETurbulenceElement); | 97 testConstructor('feTurbulence', (e) => e is SVGFETurbulenceElement); |
| 106 testConstructor('filter', (e) => e is SVGFilterElement); | 98 testConstructor('filter', (e) => e is SVGFilterElement); |
| 107 testConstructor('font', (e) => e is SVGFontElement); | 99 testConstructor('font', (e) => e is SVGFontElement); |
| 108 testConstructor('font-face', (e) => e is SVGFontFaceElement); | 100 testConstructor('font-face', (e) => e is SVGFontFaceElement); |
| 109 testConstructor('font-face-format', (e) => e is SVGFontFaceFormatElement); | 101 testConstructor('font-face-format', (e) => e is SVGFontFaceFormatElement); |
| 110 testConstructor('font-face-name', (e) => e is SVGFontFaceNameElement); | 102 testConstructor('font-face-name', (e) => e is SVGFontFaceNameElement); |
| 111 testConstructor('font-face-src', (e) => e is SVGFontFaceSrcElement); | 103 testConstructor('font-face-src', (e) => e is SVGFontFaceSrcElement); |
| 112 testConstructor('font-face-uri', (e) => e is SVGFontFaceUriElement); | 104 testConstructor('font-face-uri', (e) => e is SVGFontFaceUriElement); |
| 113 testConstructor('foreignObject', (e) => e is SVGForeignObjectElement); | 105 testConstructor('foreignObject', (e) => e is SVGForeignObjectElement); |
| 114 testConstructor('g', (e) => e is SVGGElement); | |
| 115 testConstructor('glyph', (e) => e is SVGGlyphElement); | 106 testConstructor('glyph', (e) => e is SVGGlyphElement); |
| 116 testConstructor('glyphRef', (e) => e is SVGGlyphRefElement); | 107 testConstructor('glyphRef', (e) => e is SVGGlyphRefElement); |
| 108 testConstructor('metadata', (e) => e is SVGMetadataElement); |
| 109 testConstructor('missing-glyph', (e) => e is SVGMissingGlyphElement); |
| 110 testConstructor('set', (e) => e is SVGSetElement); |
| 111 testConstructor('tref', (e) => e is SVGTRefElement); |
| 112 testConstructor('vkern', (e) => e is SVGVKernElement); |
| 113 }); |
| 114 |
| 115 group('constructors', () { |
| 116 testConstructor('a', (e) => e is SVGAElement); |
| 117 testConstructor('circle', (e) => e is SVGCircleElement); |
| 118 testConstructor('clipPath', (e) => e is SVGClipPathElement); |
| 119 testConstructor('defs', (e) => e is SVGDefsElement); |
| 120 testConstructor('desc', (e) => e is SVGDescElement); |
| 121 testConstructor('ellipse', (e) => e is SVGEllipseElement); |
| 122 testConstructor('g', (e) => e is SVGGElement); |
| 117 // WebKit doesn't recognize hkern | 123 // WebKit doesn't recognize hkern |
| 118 // testConstructor('hkern', (e) => e is SVGHKernElement); | 124 // testConstructor('hkern', (e) => e is SVGHKernElement); |
| 119 testConstructor('image', (e) => e is SVGImageElement); | 125 testConstructor('image', (e) => e is SVGImageElement); |
| 120 testConstructor('line', (e) => e is SVGLineElement); | 126 testConstructor('line', (e) => e is SVGLineElement); |
| 121 testConstructor('linearGradient', (e) => e is SVGLinearGradientElement); | 127 testConstructor('linearGradient', (e) => e is SVGLinearGradientElement); |
| 122 // WebKit doesn't recognize mpath | 128 // WebKit doesn't recognize mpath |
| 123 // testConstructor('mpath', (e) => e is SVGMPathElement); | 129 // testConstructor('mpath', (e) => e is SVGMPathElement); |
| 124 testConstructor('marker', (e) => e is SVGMarkerElement); | 130 testConstructor('marker', (e) => e is SVGMarkerElement); |
| 125 testConstructor('mask', (e) => e is SVGMaskElement); | 131 testConstructor('mask', (e) => e is SVGMaskElement); |
| 126 testConstructor('metadata', (e) => e is SVGMetadataElement); | |
| 127 testConstructor('missing-glyph', (e) => e is SVGMissingGlyphElement); | |
| 128 testConstructor('path', (e) => e is SVGPathElement); | 132 testConstructor('path', (e) => e is SVGPathElement); |
| 129 testConstructor('pattern', (e) => e is SVGPatternElement); | 133 testConstructor('pattern', (e) => e is SVGPatternElement); |
| 130 testConstructor('polygon', (e) => e is SVGPolygonElement); | 134 testConstructor('polygon', (e) => e is SVGPolygonElement); |
| 131 testConstructor('polyline', (e) => e is SVGPolylineElement); | 135 testConstructor('polyline', (e) => e is SVGPolylineElement); |
| 132 testConstructor('radialGradient', (e) => e is SVGRadialGradientElement); | 136 testConstructor('radialGradient', (e) => e is SVGRadialGradientElement); |
| 133 testConstructor('rect', (e) => e is SVGRectElement); | 137 testConstructor('rect', (e) => e is SVGRectElement); |
| 134 testConstructor('script', (e) => e is SVGScriptElement); | 138 testConstructor('script', (e) => e is SVGScriptElement); |
| 135 testConstructor('set', (e) => e is SVGSetElement); | |
| 136 testConstructor('stop', (e) => e is SVGStopElement); | 139 testConstructor('stop', (e) => e is SVGStopElement); |
| 137 testConstructor('style', (e) => e is SVGStyleElement); | 140 testConstructor('style', (e) => e is SVGStyleElement); |
| 138 testConstructor('switch', (e) => e is SVGSwitchElement); | 141 testConstructor('switch', (e) => e is SVGSwitchElement); |
| 139 testConstructor('symbol', (e) => e is SVGSymbolElement); | 142 testConstructor('symbol', (e) => e is SVGSymbolElement); |
| 140 testConstructor('tref', (e) => e is SVGTRefElement); | |
| 141 testConstructor('tspan', (e) => e is SVGTSpanElement); | 143 testConstructor('tspan', (e) => e is SVGTSpanElement); |
| 142 testConstructor('text', (e) => e is SVGTextElement); | 144 testConstructor('text', (e) => e is SVGTextElement); |
| 143 testConstructor('textPath', (e) => e is SVGTextPathElement); | 145 testConstructor('textPath', (e) => e is SVGTextPathElement); |
| 144 testConstructor('title', (e) => e is SVGTitleElement); | 146 testConstructor('title', (e) => e is SVGTitleElement); |
| 145 testConstructor('use', (e) => e is SVGUseElement); | 147 testConstructor('use', (e) => e is SVGUseElement); |
| 146 testConstructor('vkern', (e) => e is SVGVKernElement); | |
| 147 testConstructor('view', (e) => e is SVGViewElement); | 148 testConstructor('view', (e) => e is SVGViewElement); |
| 148 }); | 149 }); |
| 149 | 150 |
| 150 test('outerHTML', () { | 151 group('outerHTML', () { |
| 151 final el = new SVGSVGElement(); | 152 test('outerHTML', () { |
| 152 el.elements.add(new SVGElement.tag("circle")); | 153 final el = new SVGSVGElement(); |
| 153 el.elements.add(new SVGElement.tag("path")); | 154 el.elements.add(new SVGElement.tag("circle")); |
| 154 expect(el.outerHTML, | 155 el.elements.add(new SVGElement.tag("path")); |
| 155 '<svg version="1.1"><circle></circle><path></path></svg>'); | 156 expect(el.outerHTML, |
| 157 '<svg version="1.1"><circle></circle><path></path></svg>'); |
| 158 }); |
| 156 }); | 159 }); |
| 157 | 160 |
| 158 group('innerHTML', () { | 161 group('innerHTML', () { |
| 159 test('get', () { | 162 test('get', () { |
| 160 final el = new SVGSVGElement(); | 163 final el = new SVGSVGElement(); |
| 161 el.elements.add(new SVGElement.tag("circle")); | 164 el.elements.add(new SVGElement.tag("circle")); |
| 162 el.elements.add(new SVGElement.tag("path")); | 165 el.elements.add(new SVGElement.tag("path")); |
| 163 expect(el.innerHTML, '<circle></circle><path></path>'); | 166 expect(el.innerHTML, '<circle></circle><path></path>'); |
| 164 }); | 167 }); |
| 165 | 168 |
| 166 test('set', () { | 169 test('set', () { |
| 167 final el = new SVGSVGElement(); | 170 final el = new SVGSVGElement(); |
| 168 el.elements.add(new SVGElement.tag("circle")); | 171 el.elements.add(new SVGElement.tag("circle")); |
| 169 el.elements.add(new SVGElement.tag("path")); | 172 el.elements.add(new SVGElement.tag("path")); |
| 170 el.innerHTML = '<rect></rect><a></a>'; | 173 el.innerHTML = '<rect></rect><a></a>'; |
| 171 expect(_nodeStrings(el.elements), ["rect", "a"]); | 174 expect(_nodeStrings(el.elements), ["rect", "a"]); |
| 172 }); | 175 }); |
| 173 }); | 176 }); |
| 174 | 177 |
| 175 group('elements', () { | 178 group('elementget', () { |
| 176 test('get', () { | 179 test('get', () { |
| 177 final el = new SVGElement.svg(""" | 180 final el = new SVGElement.svg(""" |
| 178 <svg version="1.1"> | 181 <svg version="1.1"> |
| 179 <circle></circle> | 182 <circle></circle> |
| 180 <path></path> | 183 <path></path> |
| 181 text | 184 text |
| 182 </svg>"""); | 185 </svg>"""); |
| 183 expect(_nodeStrings(el.elements), ["circle", "path"]); | 186 expect(_nodeStrings(el.elements), ["circle", "path"]); |
| 184 }); | 187 }); |
| 188 }); |
| 185 | 189 |
| 190 group('elementset', () { |
| 186 test('set', () { | 191 test('set', () { |
| 187 final el = new SVGSVGElement(); | 192 final el = new SVGSVGElement(); |
| 188 el.elements = [new SVGElement.tag("circle"), new SVGElement.tag("path")]; | 193 el.elements = [new SVGElement.tag("circle"), new SVGElement.tag("path")]; |
| 189 expect(el.innerHTML, '<circle></circle><path></path>'); | 194 expect(el.innerHTML, '<circle></circle><path></path>'); |
| 190 }); | 195 }); |
| 191 }); | 196 }); |
| 192 } | 197 } |
| OLD | NEW |