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 '../../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(); |
| 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 isSvgTransformable = |
| 77 predicate((x) => x is svg.Transformable, 'is a svg.Transformable'); |
| 78 var isSvgLocatable = |
| 79 predicate((x) => x is svg.Locatable, 'is a svg.Locatable'); |
| 80 var isSvgNumber = predicate((x) => x is svg.Number, 'is a svg.Number'); |
| 81 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 82 |
| 83 test('rect_isChecks', () { |
| 84 var div = insertTestDiv(); |
| 85 var r = document.query('#rect1'); |
| 86 |
| 87 // Direct inheritance chain |
| 88 expect(r, isSvgElement); |
| 89 expect(r, isElement); |
| 90 expect(r, isNode); |
| 91 |
| 92 // Other implemented interfaces. |
| 93 expect(r, isSvgTests); |
| 94 expect(r, isSvgLangSpace); |
| 95 expect(r, isSvgExternalResourcesRequired); |
| 96 expect(r, isSvgTransformable); |
| 97 expect(r, isSvgLocatable); |
| 98 |
| 99 // Interfaces not implemented. |
| 100 expect(r, isNot(isSvgNumber)); |
| 101 expect(r, isNot(isSvgRect)); |
| 102 expect(r, isNot(isSvgSvgElement)); |
| 103 |
| 104 div.remove(); |
| 105 }); |
| 106 }); |
| 107 |
| 108 insertTestDiv() { |
| 109 var element = new Element.tag('div'); |
| 110 element.innerHtml = r''' |
| 111 <svg id='svg1' width='200' height='100'> |
| 112 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| 113 </svg> |
| 114 '''; |
| 115 document.body.nodes.add(element); |
| 116 return element; |
| 117 } |
| 118 |
| 119 group('supported_externalResourcesRequired', () { |
| 120 test('supported', () { |
| 121 var div = insertTestDiv(); |
| 122 var r = document.query('#rect1'); |
| 123 expect(svg.ExternalResourcesRequired.supported(r), true); |
| 124 div.remove(); |
| 125 }); |
| 126 }); |
| 127 |
| 128 group('supported_langSpace', () { |
| 129 test('supported', () { |
| 130 var div = insertTestDiv(); |
| 131 var r = document.query('#rect1'); |
| 132 expect(svg.LangSpace.supported(r), true); |
| 133 div.remove(); |
| 134 }); |
| 135 }); |
| 136 |
| 137 group('svgBehavioral', () { |
| 138 |
| 139 // Test that SVG elements have the operations advertised through all the IDL |
| 140 // interfaces. This is a 'duck typing' test, and does not explicitly use |
| 141 // 'is' checks on the expected interfaces (that is in the test group above). |
| 142 |
| 143 var isString = predicate((x) => x is String, 'is a String'); |
| 144 var isStringList = predicate((x) => x is List<String>, 'is a List<String>'); |
| 145 var isSvgMatrix = predicate((x) => x is svg.Matrix, 'is a svg.Matrix'); |
| 146 var isSvgAnimatedBoolean = |
| 147 predicate((x) => x is svg.AnimatedBoolean, 'is an svg.AnimatedBoolean'); |
| 148 var isSvgAnimatedString = |
| 149 predicate((x) => x is svg.AnimatedString, 'is an svg.AnimatedString'); |
| 150 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 151 var isSvgAnimatedTransformList = |
| 152 predicate((x) => x is svg.AnimatedTransformList, |
| 153 'is an svg.AnimatedTransformList'); |
| 154 var isCssStyleDeclaration = |
| 155 predicate((x) => x is CssStyleDeclaration, 'is a CssStyleDeclaration'); |
| 156 var isCssValue = predicate((x) => x is CssValue, 'is a CssValue'); |
| 157 |
| 158 /// Verifies that [e] supports the operations on the svg.Tests interface. |
| 159 checkSvgTests(e) { |
| 160 // Just check that the operations seem to exist. |
| 161 var rx = e.requiredExtensions; |
| 162 expect(rx, isStringList); |
| 163 var rf = e.requiredFeatures; |
| 164 expect(rf, isStringList); |
| 165 var sl = e.systemLanguage; |
| 166 expect(sl, isStringList); |
| 167 |
| 168 bool hasDoDo = e.hasExtension("DoDo"); |
| 169 expect(hasDoDo, isFalse); |
| 170 } |
| 171 |
| 172 /// Verifies that [e] supports the operations on the svg.Locatable interface
. |
| 173 checkSvgLocatable(e) { |
| 174 var v1 = e.farthestViewportElement; |
| 175 var v2 = e.nearestViewportElement; |
| 176 expect(v1, same(v2)); |
| 177 |
| 178 var bbox = e.getBBox(); |
| 179 expect(bbox, isSvgRect); |
| 180 |
| 181 var ctm = e.getCtm(); |
| 182 expect(ctm, isSvgMatrix); |
| 183 |
| 184 var sctm = e.getScreenCtm(); |
| 185 expect(sctm, isSvgMatrix); |
| 186 |
| 187 var xf2e = e.getTransformToElement(e); |
| 188 expect(xf2e, isSvgMatrix); |
| 189 } |
| 190 |
| 191 /** |
| 192 * Verifies that [e] supports the operations on the svg.Transformable |
| 193 * interface. |
| 194 */ |
| 195 checkSvgTransformable(e) { |
| 196 var trans = e.transform; |
| 197 expect(trans, isSvgAnimatedTransformList); |
| 198 } |
| 199 |
| 200 testRect(name, checker) { |
| 201 test(name, () { |
| 202 var div = insertTestDiv(); |
| 203 var r = document.query('#rect1'); |
| 204 checker(r); |
| 205 div.remove(); |
| 206 }); |
| 207 } |
| 208 |
| 209 /** |
| 210 * Verifies that [e] supports the operations on the svg.LangSpace interface. |
| 211 */ |
| 212 checkSvgLangSpace(e) { |
| 213 if (svg.LangSpace.supported(e)) { |
| 214 // Just check that the attributes seem to exist. |
| 215 var lang = e.xmllang; |
| 216 e.xmllang = lang; |
| 217 |
| 218 String space = e.xmlspace; |
| 219 e.xmlspace = space; |
| 220 |
| 221 expect(lang, isString); |
| 222 expect(space, isString); |
| 223 } |
| 224 } |
| 225 |
| 226 /** |
| 227 * Verifies that [e] supports the operations on the |
| 228 * svg.ExternalResourcesRequired interface. |
| 229 */ |
| 230 checkSvgExternalResourcesRequired(e) { |
| 231 if (svg.ExternalResourcesRequired.supported(e)) { |
| 232 var b = e.externalResourcesRequired; |
| 233 expect(b, isSvgAnimatedBoolean); |
| 234 expect(b.baseVal, isFalse); |
| 235 expect(b.animVal, isFalse); |
| 236 } |
| 237 } |
| 238 |
| 239 testRect('rect_SvgTests', checkSvgTests); |
| 240 testRect('rect_SvgLangSpace', checkSvgLangSpace); |
| 241 testRect('rect_SvgExternalResourcesRequired', |
| 242 checkSvgExternalResourcesRequired); |
| 243 testRect('rect_SvgLocatable', checkSvgLocatable); |
| 244 testRect('rect_SvgTransformable', checkSvgTransformable); |
| 245 }); |
| 246 |
| 247 } |
OLD | NEW |