OLD | NEW |
(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 'dart:html'; |
| 7 import 'dart:svg' as svg; |
| 8 import 'package:unittest/html_individual_config.dart'; |
| 9 import 'package:unittest/unittest.dart'; |
| 10 |
| 11 main() { |
| 12 useHtmlIndividualConfiguration(); |
| 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.append(div); |
| 20 div.setInnerHtml(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 ''', validator: new NodeValidatorBuilder()..allowSvg()); |
| 25 |
| 26 var e = document.query('#svg1'); |
| 27 expect(e, isNotNull); |
| 28 |
| 29 svg.RectElement r = document.query('#rect1'); |
| 30 expect(r.x.baseVal.value, 10); |
| 31 expect(r.y.baseVal.value, 20); |
| 32 expect(r.height.baseVal.value, 40); |
| 33 expect(r.width.baseVal.value, 130); |
| 34 expect(r.rx.baseVal.value, 5); |
| 35 }); |
| 36 |
| 37 test('trailing newline', () { |
| 38 // Ensures that we handle SVG with trailing newlines. |
| 39 var logo = new svg.SvgElement.svg(""" |
| 40 <svg xmlns='http://www.w3.org/2000/svg' version='1.1'> |
| 41 <path/> |
| 42 </svg> |
| 43 """); |
| 44 |
| 45 expect(logo, isSvgElement); |
| 46 |
| 47 }); |
| 48 }); |
| 49 |
| 50 group('svgInterfaceMatch', () { |
| 51 // Test that SVG elements explicitly implement the IDL interfaces (is-checks |
| 52 // only, see SVGTest3 for behavioural tests). |
| 53 insertTestDiv() { |
| 54 var element = new Element.tag('div'); |
| 55 element.setInnerHtml(r''' |
| 56 <svg id='svg1' width='200' height='100'> |
| 57 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| 58 </svg> |
| 59 ''', validator: new NodeValidatorBuilder()..allowSvg()); |
| 60 document.body.append(element); |
| 61 return element; |
| 62 } |
| 63 |
| 64 |
| 65 var isElement = predicate((x) => x is Element, 'is an Element'); |
| 66 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement'); |
| 67 var isSvgSvgElement = |
| 68 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); |
| 69 var isNode = predicate((x) => x is Node, 'is a Node'); |
| 70 var isSvgNumber = predicate((x) => x is svg.Number, 'is a svg.Number'); |
| 71 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 72 |
| 73 test('rect_isChecks', () { |
| 74 var div = insertTestDiv(); |
| 75 var r = document.query('#rect1'); |
| 76 |
| 77 // Direct inheritance chain |
| 78 expect(r, isSvgElement); |
| 79 expect(r, isElement); |
| 80 expect(r, isNode); |
| 81 |
| 82 // Interfaces not implemented. |
| 83 expect(r, isNot(isSvgNumber)); |
| 84 expect(r, isNot(isSvgRect)); |
| 85 expect(r, isNot(isSvgSvgElement)); |
| 86 |
| 87 div.remove(); |
| 88 }); |
| 89 }); |
| 90 |
| 91 insertTestDiv() { |
| 92 var element = new Element.tag('div'); |
| 93 element.innerHtml = r''' |
| 94 <svg id='svg1' width='200' height='100'> |
| 95 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| 96 </svg> |
| 97 '''; |
| 98 document.body.append(element); |
| 99 return element; |
| 100 } |
| 101 |
| 102 group('svgBehavioral', () { |
| 103 |
| 104 // Test that SVG elements have the operations advertised through all the IDL |
| 105 // interfaces. This is a 'duck typing' test, and does not explicitly use |
| 106 // 'is' checks on the expected interfaces (that is in the test group above). |
| 107 |
| 108 var isString = predicate((x) => x is String, 'is a String'); |
| 109 var isStringList = predicate((x) => x is List<String>, 'is a List<String>'); |
| 110 var isSvgMatrix = predicate((x) => x is svg.Matrix, 'is a svg.Matrix'); |
| 111 var isSvgAnimatedBoolean = |
| 112 predicate((x) => x is svg.AnimatedBoolean, 'is an svg.AnimatedBoolean'); |
| 113 var isSvgAnimatedString = |
| 114 predicate((x) => x is svg.AnimatedString, 'is an svg.AnimatedString'); |
| 115 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 116 var isSvgAnimatedTransformList = |
| 117 predicate((x) => x is svg.AnimatedTransformList, |
| 118 'is an svg.AnimatedTransformList'); |
| 119 var isCssStyleDeclaration = |
| 120 predicate((x) => x is CssStyleDeclaration, 'is a CssStyleDeclaration'); |
| 121 |
| 122 |
| 123 testRect(name, checker) { |
| 124 test(name, () { |
| 125 var div = insertTestDiv(); |
| 126 var r = document.query('#rect1'); |
| 127 checker(r); |
| 128 div.remove(); |
| 129 }); |
| 130 } |
| 131 }); |
| 132 |
| 133 } |
OLD | NEW |