Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: sky/tests/dom/document-child-mutations.sky

Issue 1212163009: Port remaining Sky tests to the new world (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: add Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <sky>
2 <import src="../resources/dom-utils.sky" as="DomUtils" />
3 <script>
4 import "../resources/third_party/unittest/unittest.dart";
5 import "../resources/unit.dart";
6
7 import "dart:sky";
8
9 void main() {
10 initUnit();
11
12 var doc;
13
14 var childElementCount = DomUtils.childElementCount;
15 var childNodeCount = DomUtils.childNodeCount;
16
17 setUp(() {
18 doc = new Document();
19 });
20
21 test("should allow replacing the document element", () {
22 var oldChild = doc.appendChild(doc.createElement("div"));
23 expect(childElementCount(doc), equals(1));
24 var newChild = doc.createElement("div");
25 oldChild.replaceWith([newChild]);
26 expect(childElementCount(doc), equals(1));
27 expect(newChild.parentNode, equals(doc));
28 expect(oldChild.parentNode, isNull);
29 });
30
31 test("should allow replacing a text child with an element", () {
32 var oldChild = doc.appendChild(new Text("text here"));
33 expect(childElementCount(doc), equals(0));
34 expect(childNodeCount(doc), equals(1));
35 var newChild = doc.createElement("div");
36 oldChild.replaceWith([newChild]);
37 expect(childElementCount(doc), equals(1));
38 expect(childNodeCount(doc), equals(1));
39 expect(newChild.parentNode, equals(doc));
40 expect(oldChild.parentNode, isNull);
41 });
42
43 test("should allow replacing the document element with text", () {
44 var oldChild = doc.appendChild(doc.createElement("div"));
45 expect(childElementCount(doc), equals(1));
46 var newChild = new Text(" text ");
47 oldChild.replaceWith([newChild]);
48 expect(childElementCount(doc), equals(0));
49 expect(childNodeCount(doc), equals(1));
50 expect(newChild.parentNode, equals(doc));
51 expect(oldChild.parentNode, isNull);
52 });
53
54 test("should allow inserting text with a fragment", () {
55 var fragment = doc.createDocumentFragment();
56 fragment.appendChild(new Text(" text "));
57 fragment.appendChild(new Text(" text "));
58 expect(childNodeCount(doc), equals(0));
59 doc.appendChild(fragment);
60 expect(childElementCount(doc), equals(0));
61 expect(childNodeCount(doc), equals(2));
62 });
63
64 test("should allow replacing the document element with a fragment", () {
65 var oldChild = doc.appendChild(doc.createElement("div"));
66 expect(childElementCount(doc), equals(1));
67 var fragment = doc.createDocumentFragment();
68 fragment.appendChild(new Text(" text "));
69 var newChild = fragment.appendChild(doc.createElement("div"));
70 fragment.appendChild(new Text(" "));
71 oldChild.replaceWith([fragment]);
72 expect(childElementCount(doc), equals(1));
73 expect(childNodeCount(doc), equals(3));
74 expect(newChild.parentNode, equals(doc));
75 expect(oldChild.parentNode, isNull);
76 });
77
78 test("should throw when inserting multiple elements", () {
79 doc.appendChild(doc.createElement("div"));
80 var oldChild = doc.appendChild(new Text(" text "));
81 expect(childElementCount(doc), equals(1));
82 var newChild = doc.createElement("div");
83 // expect(() {
84 // doc.replaceChild(newChild, 0);
85 // }, throws);
86 // expect(() {
87 // doc.insertBefore(newChild, oldChild);
88 // }, throws);
89 });
90
91 test("should throw when inserting multiple elements with a fragment", () {
92 var oldChild = doc.appendChild(doc.createElement("div"));
93 expect(childElementCount(doc), equals(1));
94 var fragment = doc.createDocumentFragment();
95 fragment.appendChild(new Text(" text "));
96 fragment.appendChild(doc.createElement("div"));
97 fragment.appendChild(doc.createElement("div"));
98 fragment.appendChild(new Text(" "));
99 // expect(() {
100 // doc.replaceChild(fragment, 0);
101 // }, throws);
102 // expect(() {
103 // doc.insertBefore(fragment, oldChild);
104 // }, throws);
105 });
106 }
107 </script>
108 </sky>
OLDNEW
« no previous file with comments | « sky/tests/dom/attribute_collection-expected.txt ('k') | sky/tests/dom/document-child-mutations-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698