Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 library SVGTest; | 5 library SVGTest; |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 7 import '../../pkg/unittest/lib/html_individual_config.dart'; | 7 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'dart:svg' as svg; | 9 import 'dart:svg' as svg; |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 document.body.append(element); | 61 document.body.append(element); |
| 62 return element; | 62 return element; |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 var isElement = predicate((x) => x is Element, 'is an Element'); | 66 var isElement = predicate((x) => x is Element, 'is an Element'); |
| 67 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement'); | 67 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement'); |
| 68 var isSvgSvgElement = | 68 var isSvgSvgElement = |
| 69 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); | 69 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); |
| 70 var isNode = predicate((x) => x is Node, 'is a Node'); | 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'); | 71 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'); | 72 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 82 | 73 |
| 83 test('rect_isChecks', () { | 74 test('rect_isChecks', () { |
| 84 var div = insertTestDiv(); | 75 var div = insertTestDiv(); |
| 85 var r = document.query('#rect1'); | 76 var r = document.query('#rect1'); |
| 86 | 77 |
| 87 // Direct inheritance chain | 78 // Direct inheritance chain |
| 88 expect(r, isSvgElement); | 79 expect(r, isSvgElement); |
| 89 expect(r, isElement); | 80 expect(r, isElement); |
| 90 expect(r, isNode); | 81 expect(r, isNode); |
| 91 | 82 |
| 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. | 83 // Interfaces not implemented. |
| 100 expect(r, isNot(isSvgNumber)); | 84 expect(r, isNot(isSvgNumber)); |
| 101 expect(r, isNot(isSvgRect)); | 85 expect(r, isNot(isSvgRect)); |
| 102 expect(r, isNot(isSvgSvgElement)); | 86 expect(r, isNot(isSvgSvgElement)); |
| 103 | 87 |
| 104 div.remove(); | 88 div.remove(); |
| 105 }); | 89 }); |
| 106 }); | 90 }); |
| 107 | 91 |
| 108 insertTestDiv() { | 92 insertTestDiv() { |
| 109 var element = new Element.tag('div'); | 93 var element = new Element.tag('div'); |
| 110 element.innerHtml = r''' | 94 element.innerHtml = r''' |
| 111 <svg id='svg1' width='200' height='100'> | 95 <svg id='svg1' width='200' height='100'> |
| 112 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> | 96 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| 113 </svg> | 97 </svg> |
| 114 '''; | 98 '''; |
| 115 document.body.append(element); | 99 document.body.append(element); |
| 116 return element; | 100 return element; |
| 117 } | 101 } |
| 118 | 102 |
| 119 group('supported_externalResourcesRequired', () { | |
|
blois
2013/05/21 17:08:00
Can you remove the test failures for these from ht
| |
| 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', () { | 103 group('svgBehavioral', () { |
| 138 | 104 |
| 139 // Test that SVG elements have the operations advertised through all the IDL | 105 // 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 | 106 // 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). | 107 // 'is' checks on the expected interfaces (that is in the test group above). |
| 142 | 108 |
| 143 var isString = predicate((x) => x is String, 'is a String'); | 109 var isString = predicate((x) => x is String, 'is a String'); |
| 144 var isStringList = predicate((x) => x is List<String>, 'is a List<String>'); | 110 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'); | 111 var isSvgMatrix = predicate((x) => x is svg.Matrix, 'is a svg.Matrix'); |
| 146 var isSvgAnimatedBoolean = | 112 var isSvgAnimatedBoolean = |
| 147 predicate((x) => x is svg.AnimatedBoolean, 'is an svg.AnimatedBoolean'); | 113 predicate((x) => x is svg.AnimatedBoolean, 'is an svg.AnimatedBoolean'); |
| 148 var isSvgAnimatedString = | 114 var isSvgAnimatedString = |
| 149 predicate((x) => x is svg.AnimatedString, 'is an svg.AnimatedString'); | 115 predicate((x) => x is svg.AnimatedString, 'is an svg.AnimatedString'); |
| 150 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); | 116 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 151 var isSvgAnimatedTransformList = | 117 var isSvgAnimatedTransformList = |
| 152 predicate((x) => x is svg.AnimatedTransformList, | 118 predicate((x) => x is svg.AnimatedTransformList, |
| 153 'is an svg.AnimatedTransformList'); | 119 'is an svg.AnimatedTransformList'); |
| 154 var isCssStyleDeclaration = | 120 var isCssStyleDeclaration = |
| 155 predicate((x) => x is CssStyleDeclaration, 'is a CssStyleDeclaration'); | 121 predicate((x) => x is CssStyleDeclaration, 'is a CssStyleDeclaration'); |
| 156 | 122 |
| 157 /// Verifies that [e] supports the operations on the svg.Tests interface. | |
| 158 checkSvgTests(e) { | |
| 159 // Just check that the operations seem to exist. | |
| 160 var rx = e.requiredExtensions; | |
| 161 expect(rx, isStringList); | |
| 162 var rf = e.requiredFeatures; | |
| 163 expect(rf, isStringList); | |
| 164 var sl = e.systemLanguage; | |
| 165 expect(sl, isStringList); | |
| 166 | |
| 167 bool hasDoDo = e.hasExtension("DoDo"); | |
| 168 expect(hasDoDo, isFalse); | |
| 169 } | |
| 170 | |
| 171 /// Verifies that [e] supports the operations on the svg.Locatable interface . | |
| 172 checkSvgLocatable(e) { | |
| 173 var v1 = e.farthestViewportElement; | |
| 174 var v2 = e.nearestViewportElement; | |
| 175 expect(v1, same(v2)); | |
| 176 | |
| 177 var bbox = e.getBBox(); | |
| 178 expect(bbox, isSvgRect); | |
| 179 | |
| 180 var ctm = e.getCtm(); | |
| 181 expect(ctm, isSvgMatrix); | |
| 182 | |
| 183 var sctm = e.getScreenCtm(); | |
| 184 expect(sctm, isSvgMatrix); | |
| 185 | |
| 186 var xf2e = e.getTransformToElement(e); | |
| 187 expect(xf2e, isSvgMatrix); | |
| 188 } | |
| 189 | |
| 190 /** | |
| 191 * Verifies that [e] supports the operations on the svg.Transformable | |
| 192 * interface. | |
| 193 */ | |
| 194 checkSvgTransformable(e) { | |
| 195 var trans = e.transform; | |
| 196 expect(trans, isSvgAnimatedTransformList); | |
| 197 } | |
| 198 | 123 |
| 199 testRect(name, checker) { | 124 testRect(name, checker) { |
| 200 test(name, () { | 125 test(name, () { |
| 201 var div = insertTestDiv(); | 126 var div = insertTestDiv(); |
| 202 var r = document.query('#rect1'); | 127 var r = document.query('#rect1'); |
| 203 checker(r); | 128 checker(r); |
| 204 div.remove(); | 129 div.remove(); |
| 205 }); | 130 }); |
| 206 } | 131 } |
| 207 | |
| 208 /** | |
| 209 * Verifies that [e] supports the operations on the svg.LangSpace interface. | |
| 210 */ | |
| 211 checkSvgLangSpace(e) { | |
| 212 if (svg.LangSpace.supported(e)) { | |
| 213 // Just check that the attributes seem to exist. | |
| 214 var lang = e.xmllang; | |
| 215 e.xmllang = lang; | |
| 216 | |
| 217 String space = e.xmlspace; | |
| 218 e.xmlspace = space; | |
| 219 | |
| 220 expect(lang, isString); | |
| 221 expect(space, isString); | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 /** | |
| 226 * Verifies that [e] supports the operations on the | |
| 227 * svg.ExternalResourcesRequired interface. | |
| 228 */ | |
| 229 checkSvgExternalResourcesRequired(e) { | |
| 230 if (svg.ExternalResourcesRequired.supported(e)) { | |
| 231 var b = e.externalResourcesRequired; | |
| 232 expect(b, isSvgAnimatedBoolean); | |
| 233 expect(b.baseVal, isFalse); | |
| 234 expect(b.animVal, isFalse); | |
| 235 } | |
| 236 } | |
| 237 | |
| 238 testRect('rect_SvgTests', checkSvgTests); | |
| 239 testRect('rect_SvgLangSpace', checkSvgLangSpace); | |
| 240 testRect('rect_SvgExternalResourcesRequired', | |
| 241 checkSvgExternalResourcesRequired); | |
| 242 testRect('rect_SvgLocatable', checkSvgLocatable); | |
| 243 testRect('rect_SvgTransformable', checkSvgTransformable); | |
| 244 }); | 132 }); |
| 245 | 133 |
| 246 } | 134 } |
| OLD | NEW |