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/unittest.dart'); | 6 #import('../../pkg/unittest/unittest.dart'); |
7 #import('../../pkg/unittest/html_config.dart'); | 7 #import('../../pkg/unittest/html_config.dart'); |
8 #import('dart:html'); | 8 #import('dart:html'); |
9 | 9 |
10 main() { | 10 main() { |
11 useHtmlConfiguration(); | 11 useHtmlConfiguration(); |
12 | 12 |
13 Collection<String> _nodeStrings(Collection<Node> input) { | 13 Collection<String> _nodeStrings(Collection<Node> input) { |
14 final out = new List<String>(); | 14 final out = new List<String>(); |
15 for (Node n in input) { | 15 for (Node n in input) { |
16 if (n is Element) { | 16 if (n is Element) { |
17 Element e = n; | 17 Element e = n; |
18 out.add(e.tagName); | 18 out.add(e.tagName); |
19 } else { | 19 } else { |
20 out.add(n.text); | 20 out.add(n.text); |
21 } | 21 } |
22 } | 22 } |
23 return out; | 23 return out; |
24 }; | 24 }; |
25 | 25 |
26 testConstructor(String tagName, Function isExpectedClass) { | 26 testConstructor(String tagName, Function isExpectedClass) { |
27 test(tagName, () { | 27 test(tagName, () { |
28 Expect.isTrue(isExpectedClass(new SVGElement.tag(tagName))); | 28 expect(isExpectedClass(new SVGElement.tag(tagName)), isTrue); |
29 Expect.isTrue(isExpectedClass( | 29 expect(isExpectedClass( |
30 new SVGElement.svg('<$tagName></$tagName>'))); | 30 new SVGElement.svg('<$tagName></$tagName>')), isTrue); |
31 }); | 31 }); |
32 } | 32 } |
33 | 33 |
34 group('constructors', () { | 34 group('constructors', () { |
35 group('svg', () { | 35 group('svg', () { |
36 test('valid', () { | 36 test('valid', () { |
37 final svg = """ | 37 final svg = """ |
38 <svg version="1.1"> | 38 <svg version="1.1"> |
39 <circle></circle> | 39 <circle></circle> |
40 <path></path> | 40 <path></path> |
41 </svg>"""; | 41 </svg>"""; |
42 final el = new SVGElement.svg(svg); | 42 final el = new SVGElement.svg(svg); |
43 Expect.isTrue(el is SVGSVGElement); | 43 expect(el, new isInstanceOf<SVGSVGElement>('SVGSVGElement')); |
44 Expect.equals("<circle></circle><path></path>", el.innerHTML); | 44 expect(el.innerHTML, "<circle></circle><path></path>"); |
45 Expect.equals(svg, el.outerHTML); | 45 expect(el.outerHTML, svg); |
46 }); | 46 }); |
47 | 47 |
48 test('has no parent', () => | 48 test('has no parent', () => |
49 Expect.isNull(new SVGElement.svg('<circle/>').parent)); | 49 expect(new SVGElement.svg('<circle/>').parent, isNull) |
| 50 ); |
50 | 51 |
51 test('empty', () { | 52 test('empty', () { |
52 Expect.throws(() => new SVGElement.svg(""), | 53 expect(() => new SVGElement.svg(""), throwsArgumentError); |
53 (e) => e is ArgumentError); | |
54 }); | 54 }); |
55 | 55 |
56 test('too many elements', () { | 56 test('too many elements', () { |
57 Expect.throws( | 57 expect(() => new SVGElement.svg("<circle></circle><path></path>"), |
58 () => new SVGElement.svg("<circle></circle><path></path>"), | 58 throwsArgumentError); |
59 (e) => e is ArgumentError); | |
60 }); | 59 }); |
61 }); | 60 }); |
62 | 61 |
63 testConstructor('a', (e) => e is SVGAElement); | 62 testConstructor('a', (e) => e is SVGAElement); |
64 testConstructor('altGlyphDef', (e) => e is SVGAltGlyphDefElement); | 63 testConstructor('altGlyphDef', (e) => e is SVGAltGlyphDefElement); |
65 testConstructor('altGlyph', (e) => e is SVGAltGlyphElement); | 64 testConstructor('altGlyph', (e) => e is SVGAltGlyphElement); |
66 testConstructor('animateColor', (e) => e is SVGAnimateColorElement); | 65 testConstructor('animateColor', (e) => e is SVGAnimateColorElement); |
67 testConstructor('animate', (e) => e is SVGAnimateElement); | 66 testConstructor('animate', (e) => e is SVGAnimateElement); |
68 // WebKit doesn't recognize animateMotion | 67 // WebKit doesn't recognize animateMotion |
69 // testConstructor('animateMotion', (e) => e is SVGAnimateMotionElement); | 68 // testConstructor('animateMotion', (e) => e is SVGAnimateMotionElement); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 testConstructor('title', (e) => e is SVGTitleElement); | 141 testConstructor('title', (e) => e is SVGTitleElement); |
143 testConstructor('use', (e) => e is SVGUseElement); | 142 testConstructor('use', (e) => e is SVGUseElement); |
144 testConstructor('vkern', (e) => e is SVGVKernElement); | 143 testConstructor('vkern', (e) => e is SVGVKernElement); |
145 testConstructor('view', (e) => e is SVGViewElement); | 144 testConstructor('view', (e) => e is SVGViewElement); |
146 }); | 145 }); |
147 | 146 |
148 test('outerHTML', () { | 147 test('outerHTML', () { |
149 final el = new SVGSVGElement(); | 148 final el = new SVGSVGElement(); |
150 el.elements.add(new SVGElement.tag("circle")); | 149 el.elements.add(new SVGElement.tag("circle")); |
151 el.elements.add(new SVGElement.tag("path")); | 150 el.elements.add(new SVGElement.tag("path")); |
152 Expect.equals('<svg version="1.1"><circle></circle><path></path></svg>', | 151 expect(el.outerHTML, |
153 el.outerHTML); | 152 '<svg version="1.1"><circle></circle><path></path></svg>'); |
154 }); | 153 }); |
155 | 154 |
156 group('innerHTML', () { | 155 group('innerHTML', () { |
157 test('get', () { | 156 test('get', () { |
158 final el = new SVGSVGElement(); | 157 final el = new SVGSVGElement(); |
159 el.elements.add(new SVGElement.tag("circle")); | 158 el.elements.add(new SVGElement.tag("circle")); |
160 el.elements.add(new SVGElement.tag("path")); | 159 el.elements.add(new SVGElement.tag("path")); |
161 Expect.equals('<circle></circle><path></path>', el.innerHTML); | 160 expect(el.innerHTML, '<circle></circle><path></path>'); |
162 }); | 161 }); |
163 | 162 |
164 test('set', () { | 163 test('set', () { |
165 final el = new SVGSVGElement(); | 164 final el = new SVGSVGElement(); |
166 el.elements.add(new SVGElement.tag("circle")); | 165 el.elements.add(new SVGElement.tag("circle")); |
167 el.elements.add(new SVGElement.tag("path")); | 166 el.elements.add(new SVGElement.tag("path")); |
168 el.innerHTML = '<rect></rect><a></a>'; | 167 el.innerHTML = '<rect></rect><a></a>'; |
169 Expect.listEquals(["rect", "a"], _nodeStrings(el.elements)); | 168 expect(_nodeStrings(el.elements), ["rect", "a"]); |
170 }); | 169 }); |
171 }); | 170 }); |
172 | 171 |
173 group('elements', () { | 172 group('elements', () { |
174 test('get', () { | 173 test('get', () { |
175 final el = new SVGElement.svg(""" | 174 final el = new SVGElement.svg(""" |
176 <svg version="1.1"> | 175 <svg version="1.1"> |
177 <circle></circle> | 176 <circle></circle> |
178 <path></path> | 177 <path></path> |
179 text | 178 text |
180 </svg>"""); | 179 </svg>"""); |
181 Expect.listEquals(["circle", "path"], _nodeStrings(el.elements)); | 180 expect(_nodeStrings(el.elements), ["circle", "path"]); |
182 }); | 181 }); |
183 | 182 |
184 test('set', () { | 183 test('set', () { |
185 final el = new SVGSVGElement(); | 184 final el = new SVGSVGElement(); |
186 el.elements = [new SVGElement.tag("circle"), new SVGElement.tag("path")]; | 185 el.elements = [new SVGElement.tag("circle"), new SVGElement.tag("path")]; |
187 Expect.equals('<circle></circle><path></path>', el.innerHTML); | 186 expect(el.innerHTML, '<circle></circle><path></path>'); |
188 }); | 187 }); |
189 }); | 188 }); |
190 } | 189 } |
OLD | NEW |