| OLD | NEW |
| 1 library SVG3Test; | 1 library SVG3Test; |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 import '../../pkg/unittest/lib/unittest.dart'; |
| 3 import '../../pkg/unittest/lib/html_config.dart'; | 3 import '../../pkg/unittest/lib/html_config.dart'; |
| 4 import 'dart:html'; | 4 import 'dart:html'; |
| 5 import 'dart:svg'; | 5 import 'dart:svg' as svg; |
| 6 | 6 |
| 7 // Test that SVG elements have the operations advertised through all the IDL | 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' | 8 // interfaces. This is a 'duck typing' test, and does not explicitly use 'is' |
| 9 // checks on the expected interfaces (that is in SVGTest2). | 9 // checks on the expected interfaces (that is in SVGTest2). |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 | 12 |
| 13 var isString = predicate((x) => x is String, 'is a String'); | 13 var isString = predicate((x) => x is String, 'is a String'); |
| 14 var isStringList = predicate((x) => x is List<String>, 'is a List<String>'); | 14 var isStringList = predicate((x) => x is List<String>, 'is a List<String>'); |
| 15 var isSVGMatrix = predicate((x) => x is SVGMatrix, 'is a SVGMatrix'); | 15 var isSvgMatrix = predicate((x) => x is svg.Matrix, 'is a svg.Matrix'); |
| 16 var isSVGAnimatedBoolean = | 16 var isSvgAnimatedBoolean = |
| 17 predicate((x) => x is SVGAnimatedBoolean, 'is an SVGAnimatedBoolean'); | 17 predicate((x) => x is svg.AnimatedBoolean, 'is an svg.AnimatedBoolean'); |
| 18 var isSVGAnimatedString = | 18 var isSvgAnimatedString = |
| 19 predicate((x) => x is SVGAnimatedString, 'is an SVGAnimatedString'); | 19 predicate((x) => x is svg.AnimatedString, 'is an svg.AnimatedString'); |
| 20 var isSVGRect = predicate((x) => x is SVGRect, 'is a SVGRect'); | 20 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 21 var isSVGAnimatedTransformList = | 21 var isSvgAnimatedTransformList = |
| 22 predicate((x) => x is SVGAnimatedTransformList, | 22 predicate((x) => x is svg.AnimatedTransformList, |
| 23 'is an SVGAnimatedTransformList'); | 23 'is an svg.AnimatedTransformList'); |
| 24 var isCSSStyleDeclaration = | 24 var isCSSStyleDeclaration = |
| 25 predicate((x) => x is CSSStyleDeclaration, 'is a CSSStyleDeclaration'); | 25 predicate((x) => x is CSSStyleDeclaration, 'is a CSSStyleDeclaration'); |
| 26 var isCSSValue = predicate((x) => x is CSSValue, 'is a CSSValue'); | 26 var isCSSValue = predicate((x) => x is CSSValue, 'is a CSSValue'); |
| 27 | 27 |
| 28 insertTestDiv() { | 28 insertTestDiv() { |
| 29 var element = new Element.tag('div'); | 29 var element = new Element.tag('div'); |
| 30 element.innerHTML = r''' | 30 element.innerHTML = r''' |
| 31 <svg id='svg1' width='200' height='100'> | 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> | 32 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| 33 </svg> | 33 </svg> |
| 34 '''; | 34 '''; |
| 35 document.body.nodes.add(element); | 35 document.body.nodes.add(element); |
| 36 return element; | 36 return element; |
| 37 } | 37 } |
| 38 | 38 |
| 39 useHtmlConfiguration(); | 39 useHtmlConfiguration(); |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Verifies that [e] supports the operations on the SVGTests interface. | 42 * Verifies that [e] supports the operations on the svg.Tests interface. |
| 43 */ | 43 */ |
| 44 checkSVGTests(e) { | 44 checkSvgTests(e) { |
| 45 // Just check that the operations seem to exist. | 45 // Just check that the operations seem to exist. |
| 46 var rx = e.requiredExtensions; | 46 var rx = e.requiredExtensions; |
| 47 expect(rx, isStringList); | 47 expect(rx, isStringList); |
| 48 var rf = e.requiredFeatures; | 48 var rf = e.requiredFeatures; |
| 49 expect(rf, isStringList); | 49 expect(rf, isStringList); |
| 50 var sl = e.systemLanguage; | 50 var sl = e.systemLanguage; |
| 51 expect(sl, isStringList); | 51 expect(sl, isStringList); |
| 52 | 52 |
| 53 bool hasDoDo = e.hasExtension("DoDo"); | 53 bool hasDoDo = e.hasExtension("DoDo"); |
| 54 expect(hasDoDo, isFalse); | 54 expect(hasDoDo, isFalse); |
| 55 } | 55 } |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * Verifies that [e] supports the operations on the SVGLangSpace interface. | 58 * Verifies that [e] supports the operations on the svg.LangSpace interface. |
| 59 */ | 59 */ |
| 60 checkSVGLangSpace(e) { | 60 checkSvgLangSpace(e) { |
| 61 // Just check that the attribtes seem to exist. | 61 // Just check that the attribtes seem to exist. |
| 62 var lang = e.xmllang; | 62 var lang = e.xmllang; |
| 63 e.xmllang = lang; | 63 e.xmllang = lang; |
| 64 | 64 |
| 65 String space = e.xmlspace; | 65 String space = e.xmlspace; |
| 66 e.xmlspace = space; | 66 e.xmlspace = space; |
| 67 | 67 |
| 68 expect(lang, isString); | 68 expect(lang, isString); |
| 69 expect(space, isString); | 69 expect(space, isString); |
| 70 } | 70 } |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Verifies that [e] supports the operations on the | 73 * Verifies that [e] supports the operations on the |
| 74 * SVGExternalResourcesRequired interface. | 74 * svg.ExternalResourcesRequired interface. |
| 75 */ | 75 */ |
| 76 checkSVGExternalResourcesRequired(e) { | 76 checkSvgExternalResourcesRequired(e) { |
| 77 var b = e.externalResourcesRequired; | 77 var b = e.externalResourcesRequired; |
| 78 expect(b, isSVGAnimatedBoolean); | 78 expect(b, isSvgAnimatedBoolean); |
| 79 expect(b.baseVal, isFalse); | 79 expect(b.baseVal, isFalse); |
| 80 expect(b.animVal, isFalse); | 80 expect(b.animVal, isFalse); |
| 81 } | 81 } |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Verifies that [e] supports the operations on the SVGStylable interface. | 84 * Verifies that [e] supports the operations on the svg.Stylable interface. |
| 85 */ | 85 */ |
| 86 checkSVGStylable(e) { | 86 checkSvgStylable(e) { |
| 87 var className = e.$dom_svgClassName; | 87 var className = e.$dom_svgClassName; |
| 88 expect(className, isSVGAnimatedString); | 88 expect(className, isSvgAnimatedString); |
| 89 | 89 |
| 90 var s = e.style; | 90 var s = e.style; |
| 91 expect(s, isCSSStyleDeclaration); | 91 expect(s, isCSSStyleDeclaration); |
| 92 | 92 |
| 93 var attributeA = e.getPresentationAttribute('A'); | 93 var attributeA = e.getPresentationAttribute('A'); |
| 94 expect(attributeA, anyOf(isNull, isCSSValue)); | 94 expect(attributeA, anyOf(isNull, isCSSValue)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Verifies that [e] supports the operations on the SVGLocatable interface. | 98 * Verifies that [e] supports the operations on the svg.Locatable interface. |
| 99 */ | 99 */ |
| 100 checkSVGLocatable(e) { | 100 checkSvgLocatable(e) { |
| 101 var v1 = e.farthestViewportElement; | 101 var v1 = e.farthestViewportElement; |
| 102 var v2 = e.nearestViewportElement; | 102 var v2 = e.nearestViewportElement; |
| 103 expect(v1, same(v2)); | 103 expect(v1, same(v2)); |
| 104 | 104 |
| 105 var bbox = e.getBBox(); | 105 var bbox = e.getBBox(); |
| 106 expect(bbox, isSVGRect); | 106 expect(bbox, isSvgRect); |
| 107 | 107 |
| 108 var ctm = e.getCTM(); | 108 var ctm = e.getCTM(); |
| 109 expect(ctm, isSVGMatrix); | 109 expect(ctm, isSvgMatrix); |
| 110 | 110 |
| 111 var sctm = e.getScreenCTM(); | 111 var sctm = e.getScreenCTM(); |
| 112 expect(sctm, isSVGMatrix); | 112 expect(sctm, isSvgMatrix); |
| 113 | 113 |
| 114 var xf2e = e.getTransformToElement(e); | 114 var xf2e = e.getTransformToElement(e); |
| 115 expect(xf2e, isSVGMatrix); | 115 expect(xf2e, isSvgMatrix); |
| 116 } | 116 } |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * Verifies that [e] supports the operations on the SVGTransformable | 119 * Verifies that [e] supports the operations on the svg.Transformable |
| 120 * interface. | 120 * interface. |
| 121 */ | 121 */ |
| 122 checkSVGTransformable(e) { | 122 checkSvgTransformable(e) { |
| 123 var trans = e.transform; | 123 var trans = e.transform; |
| 124 expect(trans, isSVGAnimatedTransformList); | 124 expect(trans, isSvgAnimatedTransformList); |
| 125 } | 125 } |
| 126 | 126 |
| 127 testRect(name, checker) { | 127 testRect(name, checker) { |
| 128 test(name, () { | 128 test(name, () { |
| 129 var div = insertTestDiv(); | 129 var div = insertTestDiv(); |
| 130 var r = document.query('#rect1'); | 130 var r = document.query('#rect1'); |
| 131 checker(r); | 131 checker(r); |
| 132 div.remove(); | 132 div.remove(); |
| 133 }); | 133 }); |
| 134 } | 134 } |
| 135 | 135 |
| 136 testRect('rect_SVGTests', checkSVGTests); | 136 testRect('rect_SvgTests', checkSvgTests); |
| 137 testRect('rect_SVGLangSpace', checkSVGLangSpace); | 137 testRect('rect_SvgLangSpace', checkSvgLangSpace); |
| 138 testRect('rect_SVGExternalResourcesRequired', | 138 testRect('rect_SvgExternalResourcesRequired', |
| 139 checkSVGExternalResourcesRequired); | 139 checkSvgExternalResourcesRequired); |
| 140 testRect('rect_SVGStylable', checkSVGStylable); | 140 testRect('rect_SvgStylable', checkSvgStylable); |
| 141 testRect('rect_SVGLocatable', checkSVGLocatable); | 141 testRect('rect_SvgLocatable', checkSvgLocatable); |
| 142 testRect('rect_SVGTransformable', checkSVGTransformable); | 142 testRect('rect_SvgTransformable', checkSvgTransformable); |
| 143 | 143 |
| 144 } | 144 } |
| OLD | NEW |