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