| 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; | |
| 6 import 'dart:html'; | 5 import 'dart:html'; |
| 7 import 'dart:svg' as svg; | 6 import 'dart:svg' as svg; |
| 8 import 'package:unittest/html_individual_config.dart'; | 7 |
| 9 import 'package:unittest/unittest.dart'; | 8 import 'package:expect/minitest.dart'; |
| 10 | 9 |
| 11 main() { | 10 main() { |
| 12 useHtmlIndividualConfiguration(); | |
| 13 | |
| 14 group('svgPresence', () { | 11 group('svgPresence', () { |
| 15 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement'); | 12 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement'); |
| 16 | 13 |
| 17 test('simpleRect', () { | 14 test('simpleRect', () { |
| 18 var div = new Element.tag('div'); | 15 var div = new Element.tag('div'); |
| 19 document.body.append(div); | 16 document.body.append(div); |
| 20 div.setInnerHtml(r''' | 17 div.setInnerHtml(r''' |
| 21 <svg id='svg1' width='200' height='100'> | 18 <svg id='svg1' width='200' height='100'> |
| 22 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> | 19 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| 23 </svg> | 20 </svg> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 }); | 32 }); |
| 36 | 33 |
| 37 test('trailing newline', () { | 34 test('trailing newline', () { |
| 38 // Ensures that we handle SVG with trailing newlines. | 35 // Ensures that we handle SVG with trailing newlines. |
| 39 var logo = new svg.SvgElement.svg(""" | 36 var logo = new svg.SvgElement.svg(""" |
| 40 <svg xmlns='http://www.w3.org/2000/svg' version='1.1'> | 37 <svg xmlns='http://www.w3.org/2000/svg' version='1.1'> |
| 41 <path/> | 38 <path/> |
| 42 </svg> | 39 </svg> |
| 43 """); | 40 """); |
| 44 | 41 |
| 45 expect(logo, isSvgElement); | 42 expect(logo, isSvgElement); |
| 46 | |
| 47 }); | 43 }); |
| 48 }); | 44 }); |
| 49 | 45 |
| 50 group('svgInterfaceMatch', () { | 46 group('svgInterfaceMatch', () { |
| 51 // Test that SVG elements explicitly implement the IDL interfaces (is-checks | 47 // Test that SVG elements explicitly implement the IDL interfaces (is-checks |
| 52 // only, see SVGTest3 for behavioural tests). | 48 // only, see SVGTest3 for behavioural tests). |
| 53 insertTestDiv() { | 49 insertTestDiv() { |
| 54 var element = new Element.tag('div'); | 50 var element = new Element.tag('div'); |
| 55 element.setInnerHtml(r''' | 51 element.setInnerHtml(r''' |
| 56 <svg id='svg1' width='200' height='100'> | 52 <svg id='svg1' width='200' height='100'> |
| 57 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> | 53 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| 58 </svg> | 54 </svg> |
| 59 ''', validator: new NodeValidatorBuilder()..allowSvg()); | 55 ''', validator: new NodeValidatorBuilder()..allowSvg()); |
| 60 document.body.append(element); | 56 document.body.append(element); |
| 61 return element; | 57 return element; |
| 62 } | 58 } |
| 63 | 59 |
| 64 | 60 |
| 65 var isElement = predicate((x) => x is Element, 'is an Element'); | 61 var isElement = predicate((x) => x is Element, 'is an Element'); |
| 66 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement'); | 62 var isSvgElement = predicate((x) => x is svg.SvgElement, 'is a SvgElement'); |
| 67 var isSvgSvgElement = | 63 var isSvgSvgElement = |
| 68 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); | 64 predicate((x) => x is svg.SvgSvgElement, 'is a SvgSvgElement'); |
| 65 var isNotSvgSvgElement = |
| 66 predicate((x) => x is! svg.SvgSvgElement, 'is not a SvgSvgElement'); |
| 69 var isNode = predicate((x) => x is Node, 'is a Node'); | 67 var isNode = predicate((x) => x is Node, 'is a Node'); |
| 70 var isSvgNumber = predicate((x) => x is svg.Number, 'is a svg.Number'); | 68 var isSvgNumber = predicate((x) => x is svg.Number, 'is a svg.Number'); |
| 69 var isNotSvgNumber = predicate((x) => x is! svg.Number, 'is not a svg.Number
'); |
| 71 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); | 70 var isSvgRect = predicate((x) => x is svg.Rect, 'is a svg.Rect'); |
| 71 var isNotSvgRect = predicate((x) => x is! svg.Rect, 'is not a svg.Rect'); |
| 72 | 72 |
| 73 test('rect_isChecks', () { | 73 test('rect_isChecks', () { |
| 74 var div = insertTestDiv(); | 74 var div = insertTestDiv(); |
| 75 var r = document.query('#rect1'); | 75 var r = document.query('#rect1'); |
| 76 | 76 |
| 77 // Direct inheritance chain | 77 // Direct inheritance chain |
| 78 expect(r, isSvgElement); | 78 expect(r, isSvgElement); |
| 79 expect(r, isElement); | 79 expect(r, isElement); |
| 80 expect(r, isNode); | 80 expect(r, isNode); |
| 81 | 81 |
| 82 // Interfaces not implemented. | 82 // Interfaces not implemented. |
| 83 expect(r, isNot(isSvgNumber)); | 83 expect(r, isNotSvgNumber); |
| 84 expect(r, isNot(isSvgRect)); | 84 expect(r, isNotSvgRect); |
| 85 expect(r, isNot(isSvgSvgElement)); | 85 expect(r, isNotSvgSvgElement); |
| 86 | 86 |
| 87 div.remove(); | 87 div.remove(); |
| 88 }); | 88 }); |
| 89 }); | 89 }); |
| 90 | 90 |
| 91 insertTestDiv() { | 91 insertTestDiv() { |
| 92 var element = new Element.tag('div'); | 92 var element = new Element.tag('div'); |
| 93 element.innerHtml = r''' | 93 element.innerHtml = r''' |
| 94 <svg id='svg1' width='200' height='100'> | 94 <svg id='svg1' width='200' height='100'> |
| 95 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> | 95 <rect id='rect1' x='10' y='20' width='130' height='40' rx='5'fill='blue'></rect> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 124 test(name, () { | 124 test(name, () { |
| 125 var div = insertTestDiv(); | 125 var div = insertTestDiv(); |
| 126 var r = document.query('#rect1'); | 126 var r = document.query('#rect1'); |
| 127 checker(r); | 127 checker(r); |
| 128 div.remove(); | 128 div.remove(); |
| 129 }); | 129 }); |
| 130 } | 130 } |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 } | 133 } |
| OLD | NEW |