| OLD | NEW |
| (Empty) |
| 1 library SVG3Test; | |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | |
| 3 import '../../pkg/unittest/lib/html_config.dart'; | |
| 4 import 'dart:html'; | |
| 5 import 'dart:svg' as svg; | |
| 6 | |
| 7 // Test that SVG elements have the operations advertised through all the IDL | |
| 8 // interfaces. This is a 'duck typing' test, and does not explicitly use 'is' | |
| 9 // checks on the expected interfaces (that is in SVGTest2). | |
| 10 | |
| 11 main() { | |
| 12 | |
| 13 var isString = predicate((x) => x is String, 'is a String'); | |
| 14 var isStringList = predicate((x) => x is List<String>, 'is a List<String>'); | |
| 15 var isSvgMatrix = predicate((x) => x is svg.Matrix, 'is a svg.Matrix'); | |
| 16 var isSvgAnimatedBoolean = | |
| 17 predicate((x) => x is svg.AnimatedBoolean, 'is an svg.AnimatedBoolean'); | |
| 18 var isSvgAnimatedString = | |
| 19 predicate((x) => x is svg.AnimatedString, 'is an svg.AnimatedString'); | |
| 20 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); | |
| 21 var isSvgAnimatedTransformList = | |
| 22 predicate((x) => x is svg.AnimatedTransformList, | |
| 23 'is an svg.AnimatedTransformList'); | |
| 24 var isCssStyleDeclaration = | |
| 25 predicate((x) => x is CssStyleDeclaration, 'is a CssStyleDeclaration'); | |
| 26 var isCssValue = predicate((x) => x is CssValue, 'is a CssValue'); | |
| 27 | |
| 28 insertTestDiv() { | |
| 29 var element = new Element.tag('div'); | |
| 30 element.innerHtml = r''' | |
| 31 <svg id='svg1' width='200' height='100'> | |
| 32 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> | |
| 33 </svg> | |
| 34 '''; | |
| 35 document.body.nodes.add(element); | |
| 36 return element; | |
| 37 } | |
| 38 | |
| 39 useHtmlConfiguration(); | |
| 40 | |
| 41 /** | |
| 42 * Verifies that [e] supports the operations on the svg.Tests interface. | |
| 43 */ | |
| 44 checkSvgTests(e) { | |
| 45 // Just check that the operations seem to exist. | |
| 46 var rx = e.requiredExtensions; | |
| 47 expect(rx, isStringList); | |
| 48 var rf = e.requiredFeatures; | |
| 49 expect(rf, isStringList); | |
| 50 var sl = e.systemLanguage; | |
| 51 expect(sl, isStringList); | |
| 52 | |
| 53 bool hasDoDo = e.hasExtension("DoDo"); | |
| 54 expect(hasDoDo, isFalse); | |
| 55 } | |
| 56 | |
| 57 /** | |
| 58 * Verifies that [e] supports the operations on the svg.LangSpace interface. | |
| 59 */ | |
| 60 checkSvgLangSpace(e) { | |
| 61 // Just check that the attribtes seem to exist. | |
| 62 var lang = e.xmllang; | |
| 63 e.xmllang = lang; | |
| 64 | |
| 65 String space = e.xmlspace; | |
| 66 e.xmlspace = space; | |
| 67 | |
| 68 expect(lang, isString); | |
| 69 expect(space, isString); | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * Verifies that [e] supports the operations on the | |
| 74 * svg.ExternalResourcesRequired interface. | |
| 75 */ | |
| 76 checkSvgExternalResourcesRequired(e) { | |
| 77 var b = e.externalResourcesRequired; | |
| 78 expect(b, isSvgAnimatedBoolean); | |
| 79 expect(b.baseVal, isFalse); | |
| 80 expect(b.animVal, isFalse); | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * Verifies that [e] supports the operations on the svg.Locatable interface. | |
| 85 */ | |
| 86 checkSvgLocatable(e) { | |
| 87 var v1 = e.farthestViewportElement; | |
| 88 var v2 = e.nearestViewportElement; | |
| 89 expect(v1, same(v2)); | |
| 90 | |
| 91 var bbox = e.getBBox(); | |
| 92 expect(bbox, isSvgRect); | |
| 93 | |
| 94 var ctm = e.getCtm(); | |
| 95 expect(ctm, isSvgMatrix); | |
| 96 | |
| 97 var sctm = e.getScreenCtm(); | |
| 98 expect(sctm, isSvgMatrix); | |
| 99 | |
| 100 var xf2e = e.getTransformToElement(e); | |
| 101 expect(xf2e, isSvgMatrix); | |
| 102 } | |
| 103 | |
| 104 /** | |
| 105 * Verifies that [e] supports the operations on the svg.Transformable | |
| 106 * interface. | |
| 107 */ | |
| 108 checkSvgTransformable(e) { | |
| 109 var trans = e.transform; | |
| 110 expect(trans, isSvgAnimatedTransformList); | |
| 111 } | |
| 112 | |
| 113 testRect(name, checker) { | |
| 114 test(name, () { | |
| 115 var div = insertTestDiv(); | |
| 116 var r = document.query('#rect1'); | |
| 117 checker(r); | |
| 118 div.remove(); | |
| 119 }); | |
| 120 } | |
| 121 | |
| 122 testRect('rect_SvgTests', checkSvgTests); | |
| 123 testRect('rect_SvgLangSpace', checkSvgLangSpace); | |
| 124 testRect('rect_SvgExternalResourcesRequired', | |
| 125 checkSvgExternalResourcesRequired); | |
| 126 testRect('rect_SvgLocatable', checkSvgLocatable); | |
| 127 testRect('rect_SvgTransformable', checkSvgTransformable); | |
| 128 | |
| 129 } | |
| OLD | NEW |