Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: tests/html/svg_test.dart

Issue 12038036: SVG Library cleanups and adding supported tag. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 library SVGTest;
6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:html';
9 import 'dart:svg' as svg;
10
11 main() {
12 useHtmlIndividualConfiguration();
Emily Fortuna 2013/01/24 21:55:17 now that we have browser "multitests" (able to bre
13
14 group('svgPresence', () {
15 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement');
16
17 test('simpleRect', () {
18 var div = new Element.tag('div');
19 document.body.nodes.add(div);
20 div.innerHtml = r'''
21 <svg id='svg1' width='200' height='100'>
22 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect>
23 </svg>
24
25 ''';
26
27 var e = document.query('#svg1');
28 expect(e, isNotNull);
29
30 svg.RectElement r = document.query('#rect1');
31 expect(r.x.baseVal.value, 10);
32 expect(r.y.baseVal.value, 20);
33 expect(r.height.baseVal.value, 40);
34 expect(r.width.baseVal.value, 130);
35 expect(r.rx.baseVal.value, 5);
36 });
37
38 test('trailing newline', () {
39 // Ensures that we handle SVG with trailing newlines.
40 var logo = new svg.SvgElement.svg("""
41 <svg xmlns='http://www.w3.org/2000/svg' version='1.1'>
42 <path/>
43 </svg>
44 """);
45
46 expect(logo, isSvgElement);
47
48 });
49 });
50
51 group('svgInterfaceMatch', () {
52 // Test that SVG elements explicitly implement the IDL interfaces (is-checks
53 // only, see SVGTest3 for behavioural tests).
54 insertTestDiv() {
55 var element = new Element.tag('div');
56 element.innerHtml = r'''
57 <svg id='svg1' width='200' height='100'>
58 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect>
59 </svg>
60 ''';
61 document.body.nodes.add(element);
62 return element;
63 }
64
65
66 var isElement = predicate((x) => x is Element, 'is an Element');
67 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement');
68 var isSvgSvgElement =
69 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement');
70 var isNode = predicate((x) => x is Node, 'is a Node');
71 var isSvgTests = predicate((x) => x is svg.Tests, 'is a svg.Tests');
72 var isSvgLangSpace = predicate((x) => x is svg.LangSpace, 'is a svg.LangSpac e');
73 var isSvgExternalResourcesRequired =
74 predicate((x) => x is svg.ExternalResourcesRequired,
75 'is a svg.ExternalResourcesRequired');
76 var isSvgStylable = predicate((x) => x is svg.Stylable, 'is a svg.Stylable') ;
77 var isSvgTransformable =
78 predicate((x) => x is svg.Transformable, 'is a svg.Transformable');
79 var isSvgLocatable =
80 predicate((x) => x is svg.Locatable, 'is a svg.Locatable');
81 var isSvgNumber = predicate((x) => x is svg.Number, 'is a svg.Number');
82 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect');
83
84 test('rect_isChecks', () {
85 var div = insertTestDiv();
86 var r = document.query('#rect1');
87
88 // Direct inheritance chain
89 expect(r, isSvgElement);
90 expect(r, isElement);
91 expect(r, isNode);
92
93 // Other implemented interfaces.
94 expect(r, isSvgTests);
95 expect(r, isSvgLangSpace);
96 expect(r, isSvgExternalResourcesRequired);
97 expect(r, isSvgStylable);
98 expect(r, isSvgTransformable);
99 expect(r, isSvgLocatable);
100
101 // Interfaces not implemented.
102 expect(r, isNot(isSvgNumber));
103 expect(r, isNot(isSvgRect));
104 expect(r, isNot(isSvgSvgElement));
105
106 div.remove();
107 });
108 });
109
110 insertTestDiv() {
111 var element = new Element.tag('div');
112 element.innerHtml = r'''
113 <svg id='svg1' width='200' height='100'>
114 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect>
115 </svg>
116 ''';
117 document.body.nodes.add(element);
118 return element;
119 }
120
121 group('supported_externalResourcesRequired', () {
122 test('supported', () {
123 var div = insertTestDiv();
124 var r = document.query('#rect1');
125 expect(svg.ExternalResourcesRequired.supported(r), true);
blois 2013/01/24 23:20:47 Ditto.
126 div.remove();
127 });
128 });
129
130 group('supported_langSpace', () {
131 test('supported', () {
132 var div = insertTestDiv();
133 var r = document.query('#rect1');
134 expect(svg.LangSpace.supported(r), true);
blois 2013/01/24 23:20:47 This doesn't appear to match the syntax in the gen
135 div.remove();
136 });
137 });
138
139 group('supported_stylable', () {
140 test('supported', () {
141 var div = insertTestDiv();
142 var r = document.query('#rect1');
143 expect(svg.Stylable.supported(r), true);
blois 2013/01/24 23:20:47 Ditto.
144 div.remove();
145 });
146 });
147
148 group('svgBehavioral', () {
149
150 // Test that SVG elements have the operations advertised through all the IDL
151 // interfaces. This is a 'duck typing' test, and does not explicitly use
152 // 'is' checks on the expected interfaces (that is in the test group above).
153
154 var isString = predicate((x) => x is String, 'is a String');
155 var isStringList = predicate((x) => x is List<String>, 'is a List<String>');
156 var isSvgMatrix = predicate((x) => x is svg.Matrix, 'is a svg.Matrix');
157 var isSvgAnimatedBoolean =
158 predicate((x) => x is svg.AnimatedBoolean, 'is an svg.AnimatedBoolean');
159 var isSvgAnimatedString =
160 predicate((x) => x is svg.AnimatedString, 'is an svg.AnimatedString');
161 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect');
162 var isSvgAnimatedTransformList =
163 predicate((x) => x is svg.AnimatedTransformList,
164 'is an svg.AnimatedTransformList');
165 var isCssStyleDeclaration =
166 predicate((x) => x is CssStyleDeclaration, 'is a CssStyleDeclaration');
167 var isCssValue = predicate((x) => x is CssValue, 'is a CssValue');
168
169 /// Verifies that [e] supports the operations on the svg.Tests interface.
170 checkSvgTests(e) {
171 // Just check that the operations seem to exist.
172 var rx = e.requiredExtensions;
173 expect(rx, isStringList);
174 var rf = e.requiredFeatures;
175 expect(rf, isStringList);
176 var sl = e.systemLanguage;
177 expect(sl, isStringList);
178
179 bool hasDoDo = e.hasExtension("DoDo");
180 expect(hasDoDo, isFalse);
181 }
182
183 /// Verifies that [e] supports the operations on the svg.Stylable interface.
184 checkSvgStylable(e) {
185 if (svg.Stylable.supported(e)) {
186 var s = e.style;
187 expect(s, isCssStyleDeclaration);
188
189 var attributeA = e.getPresentationAttribute('A');
190 expect(attributeA, anyOf(isNull, isCssValue));
191 }
192 }
193
194 /// Verifies that [e] supports the operations on the svg.Locatable interface .
195 checkSvgLocatable(e) {
196 var v1 = e.farthestViewportElement;
197 var v2 = e.nearestViewportElement;
198 expect(v1, same(v2));
199
200 var bbox = e.getBBox();
201 expect(bbox, isSvgRect);
202
203 var ctm = e.getCtm();
204 expect(ctm, isSvgMatrix);
205
206 var sctm = e.getScreenCtm();
207 expect(sctm, isSvgMatrix);
208
209 var xf2e = e.getTransformToElement(e);
210 expect(xf2e, isSvgMatrix);
211 }
212
213 /**
214 * Verifies that [e] supports the operations on the svg.Transformable
215 * interface.
216 */
217 checkSvgTransformable(e) {
218 var trans = e.transform;
219 expect(trans, isSvgAnimatedTransformList);
220 }
221
222 testRect(name, checker) {
223 test(name, () {
224 var div = insertTestDiv();
225 var r = document.query('#rect1');
226 checker(r);
227 div.remove();
228 });
229 }
230
231 /**
232 * Verifies that [e] supports the operations on the svg.LangSpace interface.
233 */
234 checkSvgLangSpace(e) {
235 if (svg.LangSpace.supported(e)) {
236 // Just check that the attributes seem to exist.
237 var lang = e.xmllang;
238 e.xmllang = lang;
239
240 String space = e.xmlspace;
241 e.xmlspace = space;
242
243 expect(lang, isString);
244 expect(space, isString);
245 }
246 }
247
248 /**
249 * Verifies that [e] supports the operations on the
250 * svg.ExternalResourcesRequired interface.
251 */
252 checkSvgExternalResourcesRequired(e) {
253 if (svg.ExternalResourcesRequired.supported(e)) {
254 var b = e.externalResourcesRequired;
255 expect(b, isSvgAnimatedBoolean);
256 expect(b.baseVal, isFalse);
257 expect(b.animVal, isFalse);
258 }
259 }
260
261 testRect('rect_SvgTests', checkSvgTests);
262 testRect('rect_SvgLangSpace', checkSvgLangSpace);
263 testRect('rect_SvgExternalResourcesRequired',
264 checkSvgExternalResourcesRequired);
265 testRect('rect_SvgStylable', checkSvgStylable);
266 testRect('rect_SvgLocatable', checkSvgLocatable);
267 testRect('rect_SvgTransformable', checkSvgTransformable);
268 });
269
270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698