OLD | NEW |
1 <sky> | 1 import "../resources/dom_utils.dart"; |
2 <import src="../resources/dom-utils.sky" as="DomUtils" /> | |
3 <script> | |
4 import "../resources/third_party/unittest/unittest.dart"; | 2 import "../resources/third_party/unittest/unittest.dart"; |
5 import "../resources/unit.dart"; | 3 import "../resources/unit.dart"; |
6 | 4 |
7 import "dart:sky"; | 5 import "dart:sky"; |
8 | 6 |
9 void main() { | 7 void main() { |
10 initUnit(); | 8 initUnit(); |
11 | 9 |
12 var childElementCount = DomUtils.childElementCount; | 10 Document document = new Document(); |
13 var childNodeCount = DomUtils.childNodeCount; | |
14 | 11 |
15 test("should throw with invalid arguments", () { | 12 test("should throw with invalid arguments", () { |
16 var parent = document.createElement("div"); | 13 var parent = document.createElement("div"); |
17 expect(() { | 14 expect(() { |
18 parent.appendChild(); | 15 parent.appendChild(); |
19 }, throws); | 16 }, throws); |
20 expect(() { | 17 expect(() { |
21 parent.appendChild(null); | 18 parent.appendChild(null); |
22 }, throws); | 19 }, throws); |
23 expect(() { | 20 expect(() { |
24 parent.appendChild({tagName: "div"}); | 21 parent.appendChild({tagName: "div"}); |
25 }, throws); | 22 }, throws); |
26 }); | 23 }); |
27 | 24 |
28 test("should insert children", () { | 25 test("should insert children", () { |
29 var parent = document.createElement("div"); | 26 var parent = document.createElement("div"); |
30 var child1 = parent.appendChild(document.createElement("div")); | 27 var child1 = parent.appendChild(document.createElement("div")); |
31 var child2 = parent.appendChild(new Text(" text ")); | 28 var child2 = parent.appendChild(document.createText(" text ")); |
32 var child3 = parent.appendChild(new Text(" ")); | 29 var child3 = parent.appendChild(document.createText(" ")); |
33 var child4 = parent.appendChild(document.createElement("div")); | 30 var child4 = parent.appendChild(document.createElement("div")); |
34 expect(child1.parentNode, equals(parent)); | 31 expect(child1.parentNode, equals(parent)); |
35 expect(child2.parentNode, equals(parent)); | 32 expect(child2.parentNode, equals(parent)); |
36 expect(child3.parentNode, equals(parent)); | 33 expect(child3.parentNode, equals(parent)); |
37 expect(child4.parentNode, equals(parent)); | 34 expect(child4.parentNode, equals(parent)); |
38 expect(childNodeCount(parent), equals(4)); | 35 expect(childNodeCount(parent), equals(4)); |
39 expect(childElementCount(parent), equals(2)); | 36 expect(childElementCount(parent), equals(2)); |
40 }); | 37 }); |
41 | 38 |
42 test("should insert children with a fragment", () { | 39 test("should insert children with a fragment", () { |
43 var fragment = document.createDocumentFragment(); | 40 var fragment = document.createDocumentFragment(); |
44 var child1 = fragment.appendChild(document.createElement("div")); | 41 var child1 = fragment.appendChild(document.createElement("div")); |
45 var child2 = fragment.appendChild(new Text(" text ")); | 42 var child2 = fragment.appendChild(document.createText(" text ")); |
46 var child3 = fragment.appendChild(new Text(" ")); | 43 var child3 = fragment.appendChild(document.createText(" ")); |
47 var child4 = fragment.appendChild(document.createElement("div")); | 44 var child4 = fragment.appendChild(document.createElement("div")); |
48 var parent = document.createElement("div"); | 45 var parent = document.createElement("div"); |
49 parent.appendChild(fragment); | 46 parent.appendChild(fragment); |
50 expect(child1.parentNode, equals(parent)); | 47 expect(child1.parentNode, equals(parent)); |
51 expect(child2.parentNode, equals(parent)); | 48 expect(child2.parentNode, equals(parent)); |
52 expect(child3.parentNode, equals(parent)); | 49 expect(child3.parentNode, equals(parent)); |
53 expect(child4.parentNode, equals(parent)); | 50 expect(child4.parentNode, equals(parent)); |
54 expect(childNodeCount(parent), equals(4)); | 51 expect(childNodeCount(parent), equals(4)); |
55 expect(childElementCount(parent), equals(2)); | 52 expect(childElementCount(parent), equals(2)); |
56 }); | 53 }); |
(...skipping 15 matching lines...) Expand all Loading... |
72 // }); | 69 // }); |
73 | 70 |
74 // TODO(dart): These might be real bugs too. | 71 // TODO(dart): These might be real bugs too. |
75 // test("should throw when appending to a text", () { | 72 // test("should throw when appending to a text", () { |
76 // var parent = new Text(); | 73 // var parent = new Text(); |
77 // expect(() { | 74 // expect(() { |
78 // parent.appendChild(document.createElement("div")); | 75 // parent.appendChild(document.createElement("div")); |
79 // }, throws); | 76 // }, throws); |
80 // }); | 77 // }); |
81 } | 78 } |
82 </script> | |
83 </sky> | |
OLD | NEW |