| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 DocumentFragmentTest; | |
| 6 import 'package:unittest/unittest.dart'; | |
| 7 import 'package:unittest/html_config.dart'; | |
| 8 import 'util.dart'; | |
| 9 import 'dart:html'; | 5 import 'dart:html'; |
| 10 | 6 |
| 7 import 'package:minitest/minitest.dart'; |
| 8 |
| 9 import 'util.dart'; |
| 10 |
| 11 main() { | 11 main() { |
| 12 useHtmlConfiguration(); | |
| 13 | |
| 14 var isAnchorElement = | 12 var isAnchorElement = |
| 15 predicate((x) => x is AnchorElement, 'is an AnchorElement'); | 13 predicate((x) => x is AnchorElement, 'is an AnchorElement'); |
| 16 | 14 |
| 17 List<String> _nodeStrings(Iterable<Node> input) { | 15 List<String> _nodeStrings(Iterable<Node> input) { |
| 18 var out = new List<String>(); | 16 var out = new List<String>(); |
| 19 for (Node n in input) { | 17 for (Node n in input) { |
| 20 if (n is Element) { | 18 if (n is Element) { |
| 21 Element e = n; | 19 Element e = n; |
| 22 out.add(e.tagName); | 20 out.add(e.tagName); |
| 23 } else { | 21 } else { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 return; | 33 return; |
| 36 } | 34 } |
| 37 } | 35 } |
| 38 expect(true, isFalse, reason: 'Expected immutability error'); | 36 expect(true, isFalse, reason: 'Expected immutability error'); |
| 39 }; | 37 }; |
| 40 | 38 |
| 41 void expectEmptyStyleDeclaration(CssStyleDeclaration style) { | 39 void expectEmptyStyleDeclaration(CssStyleDeclaration style) { |
| 42 expect(style.cssText, equals('')); | 40 expect(style.cssText, equals('')); |
| 43 expect(style.getPropertyPriority('color'), equals('')); | 41 expect(style.getPropertyPriority('color'), equals('')); |
| 44 expect(style.item(0), equals('')); | 42 expect(style.item(0), equals('')); |
| 45 expect(style.length, isZero); | 43 expect(style.length, equals(0)); |
| 46 // TODO(jacobr): these checks throw UnimplementedErrors in dartium. | 44 // TODO(jacobr): these checks throw UnimplementedErrors in dartium. |
| 47 // expect(style.parentRule, isNull); | 45 // expect(style.parentRule, isNull); |
| 48 // expect(style.getPropertyCssValue('color'), isNull); | 46 // expect(style.getPropertyCssValue('color'), isNull); |
| 49 // expect(style.getPropertyShorthand('color'), isNull); | 47 // expect(style.getPropertyShorthand('color'), isNull); |
| 50 // expect(style.isPropertyImplicit('color'), isFalse); | 48 // expect(style.isPropertyImplicit('color'), isFalse); |
| 51 | 49 |
| 52 // Ideally these would throw errors, but it's not possible to create a class | 50 // Ideally these would throw errors, but it's not possible to create a class |
| 53 // that'll intercept these calls without implementing the entire | 51 // that'll intercept these calls without implementing the entire |
| 54 // CssStyleDeclaration interface, so we'll settle for them being no-ops. | 52 // CssStyleDeclaration interface, so we'll settle for them being no-ops. |
| 55 style.cssText = '* {color: blue}'; | 53 style.cssText = '* {color: blue}'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 // }); | 72 // }); |
| 75 | 73 |
| 76 // TODO(nweiz): enable this once XML is ported. | 74 // TODO(nweiz): enable this once XML is ported. |
| 77 // test('.xml parses input as XML', () { | 75 // test('.xml parses input as XML', () { |
| 78 // final fragment = new DocumentFragment.xml('<a>foo</a>'); | 76 // final fragment = new DocumentFragment.xml('<a>foo</a>'); |
| 79 // expect(fragment.children[0] is XMLElement, isTrue); | 77 // expect(fragment.children[0] is XMLElement, isTrue); |
| 80 // }); | 78 // }); |
| 81 }); | 79 }); |
| 82 | 80 |
| 83 group('children', () { | 81 group('children', () { |
| 84 var fragment; | 82 DocumentFragment fragment; |
| 85 var children; | 83 List<Element> children; |
| 86 | 84 |
| 87 init() { | 85 init() { |
| 88 fragment = new DocumentFragment(); | 86 fragment = new DocumentFragment(); |
| 89 children = fragment.children; | 87 children = fragment.children; |
| 90 fragment.nodes.addAll( | 88 fragment.nodes.addAll( |
| 91 [new Text("1"), new Element.tag("A"), new Element.tag("B"), | 89 [new Text("1"), new Element.tag("A"), new Element.tag("B"), |
| 92 new Text("2"), new Element.tag("I"), new Text("3"), | 90 new Text("2"), new Element.tag("I"), new Text("3"), |
| 93 new Element.tag("U")]); | 91 new Element.tag("U")]); |
| 94 }; | 92 }; |
| 95 | 93 |
| 96 test('is initially empty', () { | 94 test('is initially empty', () { |
| 97 children = new DocumentFragment().children; | 95 children = new DocumentFragment().children; |
| 98 expect(children, equals([])); | 96 expect(children, equals([])); |
| 99 expect(children.isEmpty, isTrue); | 97 expect(children.isEmpty, isTrue); |
| 100 }); | 98 }); |
| 101 | 99 |
| 102 test('filters out non-element nodes', () { | 100 test('filters out non-element nodes', () { |
| 103 init(); | 101 init(); |
| 104 expect(_nodeStrings(fragment.nodes), | 102 expect(_nodeStrings(fragment.nodes), |
| 105 orderedEquals(["1", "A", "B", "2", "I", "3", "U"])); | 103 equals(["1", "A", "B", "2", "I", "3", "U"])); |
| 106 expect(_nodeStrings(children), | 104 expect(_nodeStrings(children), |
| 107 orderedEquals(["A", "B", "I", "U"])); | 105 equals(["A", "B", "I", "U"])); |
| 108 }); | 106 }); |
| 109 | 107 |
| 110 test('only indexes children, not other nodes', () { | 108 test('only indexes children, not other nodes', () { |
| 111 init(); | 109 init(); |
| 112 children[1] = new Element.tag("BR"); | 110 children[1] = new Element.tag("BR"); |
| 113 expect(_nodeStrings(fragment.nodes), | 111 expect(_nodeStrings(fragment.nodes), |
| 114 orderedEquals(["1", "A", "BR", "2", "I", "3", "U"])); | 112 equals(["1", "A", "BR", "2", "I", "3", "U"])); |
| 115 expect(_nodeStrings(children), | 113 expect(_nodeStrings(children), |
| 116 orderedEquals(["A", "BR", "I", "U"])); | 114 equals(["A", "BR", "I", "U"])); |
| 117 }); | 115 }); |
| 118 | 116 |
| 119 test('adds to both children and nodes', () { | 117 test('adds to both children and nodes', () { |
| 120 init(); | 118 init(); |
| 121 children.add(new Element.tag("UL")); | 119 children.add(new Element.tag("UL")); |
| 122 expect(_nodeStrings(fragment.nodes), | 120 expect(_nodeStrings(fragment.nodes), |
| 123 orderedEquals(["1", "A", "B", "2", "I", "3", "U", "UL"])); | 121 equals(["1", "A", "B", "2", "I", "3", "U", "UL"])); |
| 124 expect(_nodeStrings(children), | 122 expect(_nodeStrings(children), |
| 125 orderedEquals(["A", "B", "I", "U", "UL"])); | 123 equals(["A", "B", "I", "U", "UL"])); |
| 126 }); | 124 }); |
| 127 | 125 |
| 128 test('removes only children, from both children and nodes', () { | 126 test('removes only children, from both children and nodes', () { |
| 129 init(); | 127 init(); |
| 130 expect(children.removeLast().tagName, equals('U')); | 128 expect(children.removeLast().tagName, equals('U')); |
| 131 expect(_nodeStrings(fragment.nodes), | 129 expect(_nodeStrings(fragment.nodes), |
| 132 orderedEquals(["1", "A", "B", "2", "I", "3"])); | 130 equals(["1", "A", "B", "2", "I", "3"])); |
| 133 expect(_nodeStrings(children), | 131 expect(_nodeStrings(children), |
| 134 orderedEquals(["A", "B", "I"])); | 132 equals(["A", "B", "I"])); |
| 135 | 133 |
| 136 expect(children.removeLast().tagName, "I"); | 134 expect(children.removeLast().tagName, "I"); |
| 137 expect(_nodeStrings(fragment.nodes), | 135 expect(_nodeStrings(fragment.nodes), |
| 138 equals(["1", "A", "B", "2", "3"])); | 136 equals(["1", "A", "B", "2", "3"])); |
| 139 expect(_nodeStrings(children), equals(["A", "B"])); | 137 expect(_nodeStrings(children), equals(["A", "B"])); |
| 140 }); | 138 }); |
| 141 | 139 |
| 142 test('accessors are wrapped', () { | 140 test('accessors are wrapped', () { |
| 143 init(); | 141 init(); |
| 144 expect(children[0].tagName, "A"); | 142 expect(children[0].tagName, "A"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 171 expect(fragment.innerHtml, "foo<a>bar</a>"); | 169 expect(fragment.innerHtml, "foo<a>bar</a>"); |
| 172 }); | 170 }); |
| 173 | 171 |
| 174 test('query searches the fragment', () { | 172 test('query searches the fragment', () { |
| 175 var fragment = new DocumentFragment.html( | 173 var fragment = new DocumentFragment.html( |
| 176 "<div class='foo'><a>foo</a><b>bar</b></div>"); | 174 "<div class='foo'><a>foo</a><b>bar</b></div>"); |
| 177 expect(fragment.query(".foo a").tagName, "A"); | 175 expect(fragment.query(".foo a").tagName, "A"); |
| 178 expect(_nodeStrings(fragment.queryAll(".foo *")), equals(["A", "B"])); | 176 expect(_nodeStrings(fragment.queryAll(".foo *")), equals(["A", "B"])); |
| 179 }); | 177 }); |
| 180 } | 178 } |
| OLD | NEW |