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

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

Issue 732203004: Clean up child checks in ContainerNode. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add back secondary hierarchy checks. Created 6 years, 1 month 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/chai.sky" />
3 <import src="../resources/mocha.sky" />
4 <import src="../resources/dom-utils.sky" as="DomUtils" />
5 <script>
6 describe("Document", function() {
7 var doc;
8
9 var childElementCount = DomUtils.childElementCount;
10 var childNodeCount = DomUtils.childNodeCount;
11
12 beforeEach(function() {
13 doc = new Document();
14 });
15
16 it("should allow replacing the document element", function() {
17 var oldChild = doc.appendChild(doc.createElement("div"));
18 assert.equal(childElementCount(doc), 1);
19 var newChild = doc.createElement("div");
20 doc.replaceChild(newChild, oldChild);
21 assert.equal(childElementCount(doc), 1);
22 assert.equal(newChild.parentNode, doc);
23 assert.isNull(oldChild.parentNode);
24 });
25
26 it("should allow replacing a text child with an element", function() {
27 var oldChild = doc.appendChild(new Text("text here"));
28 assert.equal(childElementCount(doc), 0);
29 assert.equal(childNodeCount(doc), 1);
30 var newChild = doc.createElement("div");
31 doc.replaceChild(newChild, oldChild);
32 assert.equal(childElementCount(doc), 1);
33 assert.equal(childNodeCount(doc), 1);
34 assert.equal(newChild.parentNode, doc);
35 assert.isNull(oldChild.parentNode);
36 });
37
38 it("should allow replacing the document element with text", function() {
39 var oldChild = doc.appendChild(doc.createElement("div"));
40 assert.equal(childElementCount(doc), 1);
41 var newChild = new Text(" text ");
42 doc.replaceChild(newChild, oldChild);
43 assert.equal(childElementCount(doc), 0);
44 assert.equal(childNodeCount(doc), 1);
45 assert.equal(newChild.parentNode, doc);
46 assert.isNull(oldChild.parentNode);
47 });
48
49 it("should allow inserting text with a fragment", function() {
50 var fragment = doc.createDocumentFragment();
51 fragment.appendChild(new Text(" text "));
52 fragment.appendChild(new Text(" text "));
53 assert.equal(childNodeCount(doc), 0);
54 doc.appendChild(fragment);
55 assert.equal(childElementCount(doc), 0);
56 assert.equal(childNodeCount(doc), 2);
57 });
58
59 it("should allow replacing the document element with a fragment", function() {
60 var oldChild = doc.appendChild(doc.createElement("div"));
61 assert.equal(childElementCount(doc), 1);
62 var fragment = doc.createDocumentFragment();
63 fragment.appendChild(new Text(" text "));
64 var newChild = fragment.appendChild(doc.createElement("div"));
65 fragment.appendChild(new Text(" "));
66 doc.replaceChild(fragment, oldChild);
67 assert.equal(childElementCount(doc), 1);
68 assert.equal(childNodeCount(doc), 3);
69 assert.equal(newChild.parentNode, doc);
70 assert.isNull(oldChild.parentNode);
71 });
72
73 it("should throw when inserting multiple elements", function() {
74 doc.appendChild(doc.createElement("div"));
75 var oldChild = doc.appendChild(new Text(" text "));
76 assert.equal(childElementCount(doc), 1);
77 var newChild = doc.createElement("div");
78 assert.throws(function() {
79 doc.replaceChild(newChild, 0);
80 });
81 assert.throws(function() {
82 doc.insertBefore(newChild, oldChild);
83 });
84 });
85
86 it("should throw when inserting multiple elements with a fragment", function() {
87 var oldChild = doc.appendChild(doc.createElement("div"));
88 assert.equal(childElementCount(doc), 1);
89 var fragment = doc.createDocumentFragment();
90 fragment.appendChild(new Text(" text "));
91 fragment.appendChild(doc.createElement("div"));
92 fragment.appendChild(doc.createElement("div"));
93 fragment.appendChild(new Text(" "));
94 assert.throws(function() {
95 doc.replaceChild(fragment, 0);
96 });
97 assert.throws(function() {
98 doc.insertBefore(fragment, oldChild);
99 });
100 });
101 });
102 </script>
103 </sky>
OLDNEW
« no previous file with comments | « sky/tests/dom/appendChild-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