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

Side by Side Diff: tests/lib_strong/html/svgelement_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
OLDNEW
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 import 'dart:html'; 5 import 'dart:html';
6 import 'dart:svg' as svg; 6 import 'dart:svg' as svg;
7 7
8 import 'package:expect/minitest.dart'; 8 import 'package:expect/minitest.dart';
9 9
10 main() { 10 main() {
11 var isSvgSvgElement = 11 var isSvgSvgElement =
12 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); 12 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement');
13 13
14 List<String> _nodeStrings(Iterable<Node> input) { 14 List<String> _nodeStrings(Iterable<Node> input) {
15 final out = new List<String>(); 15 final out = new List<String>();
16 for (Node n in input) { 16 for (Node n in input) {
17 if (n is Element) { 17 if (n is Element) {
18 Element e = n; 18 Element e = n;
19 out.add(e.tagName); 19 out.add(e.tagName);
20 } else { 20 } else {
21 out.add(n.text); 21 out.add(n.text);
22 } 22 }
23 } 23 }
24 return out; 24 return out;
25 }; 25 }
26
27 ;
26 28
27 testConstructor(String tagName, Function isExpectedClass, 29 testConstructor(String tagName, Function isExpectedClass,
28 [bool expectation = true, allowsInnerHtml = true]) { 30 [bool expectation = true, allowsInnerHtml = true]) {
29 test(tagName, () { 31 test(tagName, () {
30 expect(isExpectedClass(new svg.SvgElement.tag(tagName)), expectation); 32 expect(isExpectedClass(new svg.SvgElement.tag(tagName)), expectation);
31 if (allowsInnerHtml) { 33 if (allowsInnerHtml) {
32 expect(isExpectedClass(new svg.SvgElement.svg('<$tagName></$tagName>')), 34 expect(isExpectedClass(new svg.SvgElement.svg('<$tagName></$tagName>')),
33 expectation && allowsInnerHtml); 35 expectation && allowsInnerHtml);
34 } 36 }
35 }); 37 });
36 } 38 }
39
37 group('additionalConstructors', () { 40 group('additionalConstructors', () {
38 test('valid', () { 41 test('valid', () {
39 final svgContent = 42 final svgContent = "<svg version=\"1.1\">\n"
40 "<svg version=\"1.1\">\n"
41 " <circle></circle>\n" 43 " <circle></circle>\n"
42 " <path></path>\n" 44 " <path></path>\n"
43 "</svg>"; 45 "</svg>";
44 final el = new svg.SvgElement.svg(svgContent); 46 final el = new svg.SvgElement.svg(svgContent);
45 expect(el, isSvgSvgElement); 47 expect(el, isSvgSvgElement);
46 expect(el.innerHtml, anyOf(["<circle></circle><path></path>", '<circle ' 48 expect(
47 'xmlns="http://www.w3.org/2000/svg" /><path ' 49 el.innerHtml,
48 'xmlns="http://www.w3.org/2000/svg" />'])); 50 anyOf([
49 expect(el.outerHtml, anyOf([svgContent, 51 "<circle></circle><path></path>",
50 '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">\n ' 52 '<circle '
51 '<circle />\n <path />\n</svg>'])); 53 'xmlns="http://www.w3.org/2000/svg" /><path '
54 'xmlns="http://www.w3.org/2000/svg" />'
55 ]));
56 expect(
57 el.outerHtml,
58 anyOf([
59 svgContent,
60 '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">\n '
61 '<circle />\n <path />\n</svg>'
62 ]));
52 }); 63 });
53 64
54 test('has no parent', () => 65 test('has no parent',
55 expect(new svg.SvgElement.svg('<circle/>').parent, isNull) 66 () => expect(new svg.SvgElement.svg('<circle/>').parent, isNull));
56 );
57 67
58 test('empty', () { 68 test('empty', () {
59 expect(() => new svg.SvgElement.svg(""), throwsStateError); 69 expect(() => new svg.SvgElement.svg(""), throwsStateError);
60 }); 70 });
61 71
62 test('too many elements', () { 72 test('too many elements', () {
63 expect(() => new svg.SvgElement.svg("<circle></circle><path></path>"), 73 expect(() => new svg.SvgElement.svg("<circle></circle><path></path>"),
64 throwsStateError); 74 throwsStateError);
65 }); 75 });
66 }); 76 });
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 }); 238 });
229 }); 239 });
230 240
231 group('supported_set', () { 241 group('supported_set', () {
232 test('supported', () { 242 test('supported', () {
233 expect(svg.SetElement.supported, true); 243 expect(svg.SetElement.supported, true);
234 }); 244 });
235 }); 245 });
236 246
237 group('constructors', () { 247 group('constructors', () {
238 testConstructor('a', (e) => e is svg.AElement); 248 testConstructor('a', (e) => e is svg.AElement);
239 testConstructor('circle', (e) => e is svg.CircleElement); 249 testConstructor('circle', (e) => e is svg.CircleElement);
240 testConstructor('clipPath', (e) => e is svg.ClipPathElement); 250 testConstructor('clipPath', (e) => e is svg.ClipPathElement);
241 testConstructor('defs', (e) => e is svg.DefsElement); 251 testConstructor('defs', (e) => e is svg.DefsElement);
242 testConstructor('desc', (e) => e is svg.DescElement); 252 testConstructor('desc', (e) => e is svg.DescElement);
243 testConstructor('ellipse', (e) => e is svg.EllipseElement); 253 testConstructor('ellipse', (e) => e is svg.EllipseElement);
244 testConstructor('g', (e) => e is svg.GElement); 254 testConstructor('g', (e) => e is svg.GElement);
245 testConstructor('image', (e) => e is svg.ImageElement); 255 testConstructor('image', (e) => e is svg.ImageElement);
246 testConstructor('line', (e) => e is svg.LineElement); 256 testConstructor('line', (e) => e is svg.LineElement);
247 testConstructor('linearGradient', (e) => e is svg.LinearGradientElement); 257 testConstructor('linearGradient', (e) => e is svg.LinearGradientElement);
248 testConstructor('marker', (e) => e is svg.MarkerElement); 258 testConstructor('marker', (e) => e is svg.MarkerElement);
249 testConstructor('mask', (e) => e is svg.MaskElement); 259 testConstructor('mask', (e) => e is svg.MaskElement);
250 testConstructor('path', (e) => e is svg.PathElement); 260 testConstructor('path', (e) => e is svg.PathElement);
251 testConstructor('pattern', (e) => e is svg.PatternElement); 261 testConstructor('pattern', (e) => e is svg.PatternElement);
252 testConstructor('polygon', (e) => e is svg.PolygonElement); 262 testConstructor('polygon', (e) => e is svg.PolygonElement);
253 testConstructor('polyline', (e) => e is svg.PolylineElement); 263 testConstructor('polyline', (e) => e is svg.PolylineElement);
254 testConstructor('radialGradient', (e) => e is svg.RadialGradientElement); 264 testConstructor('radialGradient', (e) => e is svg.RadialGradientElement);
255 testConstructor('rect', (e) => e is svg.RectElement); 265 testConstructor('rect', (e) => e is svg.RectElement);
256 test('script', () { 266 test('script', () {
257 expect(new svg.SvgElement.tag('script') is svg.ScriptElement, isTrue); 267 expect(new svg.SvgElement.tag('script') is svg.ScriptElement, isTrue);
258 }); 268 });
259 testConstructor('stop', (e) => e is svg.StopElement); 269 testConstructor('stop', (e) => e is svg.StopElement);
260 testConstructor('style', (e) => e is svg.StyleElement); 270 testConstructor('style', (e) => e is svg.StyleElement);
261 testConstructor('switch', (e) => e is svg.SwitchElement); 271 testConstructor('switch', (e) => e is svg.SwitchElement);
262 testConstructor('symbol', (e) => e is svg.SymbolElement); 272 testConstructor('symbol', (e) => e is svg.SymbolElement);
263 testConstructor('tspan', (e) => e is svg.TSpanElement); 273 testConstructor('tspan', (e) => e is svg.TSpanElement);
264 testConstructor('text', (e) => e is svg.TextElement); 274 testConstructor('text', (e) => e is svg.TextElement);
265 testConstructor('textPath', (e) => e is svg.TextPathElement); 275 testConstructor('textPath', (e) => e is svg.TextPathElement);
266 testConstructor('title', (e) => e is svg.TitleElement); 276 testConstructor('title', (e) => e is svg.TitleElement);
267 testConstructor('use', (e) => e is svg.UseElement); 277 testConstructor('use', (e) => e is svg.UseElement);
268 testConstructor('view', (e) => e is svg.ViewElement); 278 testConstructor('view', (e) => e is svg.ViewElement);
269 // TODO(alanknight): Issue 23144 279 // TODO(alanknight): Issue 23144
270 testConstructor('animate', (e) => e is svg.AnimateElement, 280 testConstructor('animate', (e) => e is svg.AnimateElement,
271 svg.AnimateElement.supported); 281 svg.AnimateElement.supported);
272 testConstructor('animateMotion', (e) => e is svg.AnimateMotionElement, 282 testConstructor('animateMotion', (e) => e is svg.AnimateMotionElement,
273 svg.AnimateMotionElement.supported); 283 svg.AnimateMotionElement.supported);
274 testConstructor('animateTransform', (e) => e is svg.AnimateTransformElemen t, 284 testConstructor('animateTransform', (e) => e is svg.AnimateTransformElement,
275 svg.AnimateTransformElement.supported); 285 svg.AnimateTransformElement.supported);
276 testConstructor('feBlend', (e) => e is svg.FEBlendElement, 286 testConstructor('feBlend', (e) => e is svg.FEBlendElement,
277 svg.FEBlendElement.supported); 287 svg.FEBlendElement.supported);
278 testConstructor('feColorMatrix', (e) => e is svg.FEColorMatrixElement, 288 testConstructor('feColorMatrix', (e) => e is svg.FEColorMatrixElement,
279 svg.FEColorMatrixElement.supported); 289 svg.FEColorMatrixElement.supported);
280 testConstructor('feComponentTransfer', 290 testConstructor(
281 (e) => e is svg.FEComponentTransferElement, 291 'feComponentTransfer',
282 svg.FEComponentTransferElement.supported); 292 (e) => e is svg.FEComponentTransferElement,
283 testConstructor('feConvolveMatrix', 293 svg.FEComponentTransferElement.supported);
284 (e) => e is svg.FEConvolveMatrixElement, 294 testConstructor('feConvolveMatrix', (e) => e is svg.FEConvolveMatrixElement,
285 svg.FEConvolveMatrixElement.supported); 295 svg.FEConvolveMatrixElement.supported);
286 testConstructor('feDiffuseLighting', 296 testConstructor(
287 (e) => e is svg.FEDiffuseLightingElement, 297 'feDiffuseLighting',
288 svg.FEDiffuseLightingElement.supported); 298 (e) => e is svg.FEDiffuseLightingElement,
289 testConstructor('feDisplacementMap', 299 svg.FEDiffuseLightingElement.supported);
290 (e) => e is svg.FEDisplacementMapElement, 300 testConstructor(
291 svg.FEDisplacementMapElement.supported); 301 'feDisplacementMap',
292 testConstructor('feDistantLight', (e) => e is svg.FEDistantLightElement, 302 (e) => e is svg.FEDisplacementMapElement,
293 svg.FEDistantLightElement.supported); 303 svg.FEDisplacementMapElement.supported);
294 testConstructor('feFlood', (e) => e is svg.FEFloodElement, 304 testConstructor('feDistantLight', (e) => e is svg.FEDistantLightElement,
295 svg.FEFloodElement.supported); 305 svg.FEDistantLightElement.supported);
296 testConstructor('feFuncA', (e) => e is svg.FEFuncAElement, 306 testConstructor('feFlood', (e) => e is svg.FEFloodElement,
297 svg.FEFuncAElement.supported); 307 svg.FEFloodElement.supported);
298 testConstructor('feFuncB', (e) => e is svg.FEFuncBElement, 308 testConstructor('feFuncA', (e) => e is svg.FEFuncAElement,
299 svg.FEFuncBElement.supported); 309 svg.FEFuncAElement.supported);
300 testConstructor('feFuncG', (e) => e is svg.FEFuncGElement, 310 testConstructor('feFuncB', (e) => e is svg.FEFuncBElement,
301 svg.FEFuncGElement.supported); 311 svg.FEFuncBElement.supported);
302 testConstructor('feFuncR', (e) => e is svg.FEFuncRElement, 312 testConstructor('feFuncG', (e) => e is svg.FEFuncGElement,
303 svg.FEFuncRElement.supported); 313 svg.FEFuncGElement.supported);
304 testConstructor('feGaussianBlur', (e) => e is svg.FEGaussianBlurElement, 314 testConstructor('feFuncR', (e) => e is svg.FEFuncRElement,
305 svg.FEGaussianBlurElement.supported); 315 svg.FEFuncRElement.supported);
306 testConstructor('feImage', (e) => e is svg.FEImageElement, 316 testConstructor('feGaussianBlur', (e) => e is svg.FEGaussianBlurElement,
307 svg.FEImageElement.supported); 317 svg.FEGaussianBlurElement.supported);
308 testConstructor('feMerge', (e) => e is svg.FEMergeElement, 318 testConstructor('feImage', (e) => e is svg.FEImageElement,
309 svg.FEMergeElement.supported); 319 svg.FEImageElement.supported);
310 testConstructor('feMergeNode', (e) => e is svg.FEMergeNodeElement, 320 testConstructor('feMerge', (e) => e is svg.FEMergeElement,
311 svg.FEMergeNodeElement.supported); 321 svg.FEMergeElement.supported);
312 testConstructor('feOffset', (e) => e is svg.FEOffsetElement, 322 testConstructor('feMergeNode', (e) => e is svg.FEMergeNodeElement,
313 svg.FEOffsetElement.supported); 323 svg.FEMergeNodeElement.supported);
314 testConstructor('fePointLight', (e) => e is svg.FEPointLightElement, 324 testConstructor('feOffset', (e) => e is svg.FEOffsetElement,
315 svg.FEPointLightElement.supported); 325 svg.FEOffsetElement.supported);
316 testConstructor('feSpecularLighting', 326 testConstructor('fePointLight', (e) => e is svg.FEPointLightElement,
317 (e) => e is svg.FESpecularLightingElement, 327 svg.FEPointLightElement.supported);
318 svg.FESpecularLightingElement.supported); 328 testConstructor(
319 testConstructor('feSpotLight', (e) => e is svg.FESpotLightElement, 329 'feSpecularLighting',
320 svg.FESpotLightElement.supported); 330 (e) => e is svg.FESpecularLightingElement,
321 testConstructor('feTile', (e) => e is svg.FETileElement, 331 svg.FESpecularLightingElement.supported);
322 svg.FETileElement.supported); 332 testConstructor('feSpotLight', (e) => e is svg.FESpotLightElement,
323 testConstructor('feTurbulence', (e) => e is svg.FETurbulenceElement, 333 svg.FESpotLightElement.supported);
324 svg.FETurbulenceElement.supported); 334 testConstructor(
325 testConstructor('filter', (e) => e is svg.FilterElement, 335 'feTile', (e) => e is svg.FETileElement, svg.FETileElement.supported);
326 svg.FilterElement.supported); 336 testConstructor('feTurbulence', (e) => e is svg.FETurbulenceElement,
327 testConstructor('foreignObject', (e) => e is svg.ForeignObjectElement, 337 svg.FETurbulenceElement.supported);
328 svg.ForeignObjectElement.supported, false); 338 testConstructor(
329 testConstructor('metadata', (e) => e is svg.MetadataElement); 339 'filter', (e) => e is svg.FilterElement, svg.FilterElement.supported);
330 testConstructor('set', (e) => e is svg.SetElement, 340 testConstructor('foreignObject', (e) => e is svg.ForeignObjectElement,
331 svg.SetElement.supported); 341 svg.ForeignObjectElement.supported, false);
342 testConstructor('metadata', (e) => e is svg.MetadataElement);
343 testConstructor(
344 'set', (e) => e is svg.SetElement, svg.SetElement.supported);
332 }); 345 });
333 346
334 group('outerHtml', () { 347 group('outerHtml', () {
335 test('outerHtml', () { 348 test('outerHtml', () {
336 final el = new svg.SvgSvgElement(); 349 final el = new svg.SvgSvgElement();
337 el.children.add(new svg.CircleElement()); 350 el.children.add(new svg.CircleElement());
338 el.children.add(new svg.PathElement()); 351 el.children.add(new svg.PathElement());
339 expect([ 352 expect(
340 '<svg version="1.1"><circle></circle><path></path></svg>', 353 [
341 '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">' 354 '<svg version="1.1"><circle></circle><path></path></svg>',
342 '<circle /><path /></svg>', 355 '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">'
343 ].contains(el.outerHtml), true); 356 '<circle /><path /></svg>',
357 ].contains(el.outerHtml),
358 true);
344 }); 359 });
345 }); 360 });
346 361
347 group('innerHtml', () { 362 group('innerHtml', () {
348 test('get', () { 363 test('get', () {
349 final el = new svg.SvgSvgElement(); 364 final el = new svg.SvgSvgElement();
350 el.children.add(new svg.CircleElement()); 365 el.children.add(new svg.CircleElement());
351 el.children.add(new svg.PathElement()); 366 el.children.add(new svg.PathElement());
352 // Allow for odd IE serialization. 367 // Allow for odd IE serialization.
353 expect([ 368 expect(
354 '<circle></circle><path></path>', 369 [
355 '<circle xmlns="http://www.w3.org/2000/svg" />' 370 '<circle></circle><path></path>',
356 '<path xmlns="http://www.w3.org/2000/svg" />' 371 '<circle xmlns="http://www.w3.org/2000/svg" />'
357 ].contains(el.innerHtml), true); 372 '<path xmlns="http://www.w3.org/2000/svg" />'
373 ].contains(el.innerHtml),
374 true);
358 }); 375 });
359 376
360 test('set', () { 377 test('set', () {
361 final el = new svg.SvgSvgElement(); 378 final el = new svg.SvgSvgElement();
362 el.children.add(new svg.CircleElement()); 379 el.children.add(new svg.CircleElement());
363 el.children.add(new svg.PathElement()); 380 el.children.add(new svg.PathElement());
364 el.innerHtml = '<rect></rect><a></a>'; 381 el.innerHtml = '<rect></rect><a></a>';
365 expect(_nodeStrings(el.children), ["rect", "a"]); 382 expect(_nodeStrings(el.children), ["rect", "a"]);
366 }); 383 });
367 }); 384 });
(...skipping 20 matching lines...) Expand all
388 expect(el.children.contains(items[1]), false); 405 expect(el.children.contains(items[1]), false);
389 406
390 el.children.length = 0; 407 el.children.length = 0;
391 expect(el.children.contains(items[0]), false); 408 expect(el.children.contains(items[0]), false);
392 }); 409 });
393 }); 410 });
394 411
395 group('elementset', () { 412 group('elementset', () {
396 test('set', () { 413 test('set', () {
397 final el = new svg.SvgSvgElement(); 414 final el = new svg.SvgSvgElement();
398 el.children = [new svg.SvgElement.tag("circle"), new svg.SvgElement.tag("p ath")]; 415 el.children = [
416 new svg.SvgElement.tag("circle"),
417 new svg.SvgElement.tag("path")
418 ];
399 expect(el.nodes.length, 2); 419 expect(el.nodes.length, 2);
400 expect(el.nodes[0] is svg.CircleElement, true); 420 expect(el.nodes[0] is svg.CircleElement, true);
401 expect(el.nodes[1] is svg.PathElement, true); 421 expect(el.nodes[1] is svg.PathElement, true);
402 }); 422 });
403 }); 423 });
404 424
405 group('css', () { 425 group('css', () {
406 test('classes', () { 426 test('classes', () {
407 var el = new svg.CircleElement(); 427 var el = new svg.CircleElement();
408 var classes = el.classes; 428 var classes = el.classes;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 group('PathElement', () { 481 group('PathElement', () {
462 test('pathSegList', () { 482 test('pathSegList', () {
463 svg.PathElement path = 483 svg.PathElement path =
464 new svg.SvgElement.svg('<path d="M 100 100 L 300 100 L 200 300 z"/>'); 484 new svg.SvgElement.svg('<path d="M 100 100 L 300 100 L 200 300 z"/>');
465 for (var seg in path.pathSegList) { 485 for (var seg in path.pathSegList) {
466 expect(seg is svg.PathSeg, isTrue); 486 expect(seg is svg.PathSeg, isTrue);
467 } 487 }
468 }); 488 });
469 }); 489 });
470 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698