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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tests/dom/document-child-mutations.sky
diff --git a/sky/tests/dom/document-child-mutations.sky b/sky/tests/dom/document-child-mutations.sky
new file mode 100644
index 0000000000000000000000000000000000000000..99e0e440982e6f0af0f504dd2d89a62b43ba7ae9
--- /dev/null
+++ b/sky/tests/dom/document-child-mutations.sky
@@ -0,0 +1,103 @@
+<sky>
+<import src="../resources/chai.sky" />
+<import src="../resources/mocha.sky" />
+<import src="../resources/dom-utils.sky" as="DomUtils" />
+<script>
+describe("Document", function() {
+ var doc;
+
+ var childElementCount = DomUtils.childElementCount;
+ var childNodeCount = DomUtils.childNodeCount;
+
+ beforeEach(function() {
+ doc = new Document();
+ });
+
+ it("should allow replacing the document element", function() {
+ var oldChild = doc.appendChild(doc.createElement("div"));
+ assert.equal(childElementCount(doc), 1);
+ var newChild = doc.createElement("div");
+ doc.replaceChild(newChild, oldChild);
+ assert.equal(childElementCount(doc), 1);
+ assert.equal(newChild.parentNode, doc);
+ assert.isNull(oldChild.parentNode);
+ });
+
+ it("should allow replacing a text child with an element", function() {
+ var oldChild = doc.appendChild(new Text("text here"));
+ assert.equal(childElementCount(doc), 0);
+ assert.equal(childNodeCount(doc), 1);
+ var newChild = doc.createElement("div");
+ doc.replaceChild(newChild, oldChild);
+ assert.equal(childElementCount(doc), 1);
+ assert.equal(childNodeCount(doc), 1);
+ assert.equal(newChild.parentNode, doc);
+ assert.isNull(oldChild.parentNode);
+ });
+
+ it("should allow replacing the document element with text", function() {
+ var oldChild = doc.appendChild(doc.createElement("div"));
+ assert.equal(childElementCount(doc), 1);
+ var newChild = new Text(" text ");
+ doc.replaceChild(newChild, oldChild);
+ assert.equal(childElementCount(doc), 0);
+ assert.equal(childNodeCount(doc), 1);
+ assert.equal(newChild.parentNode, doc);
+ assert.isNull(oldChild.parentNode);
+ });
+
+ it("should allow inserting text with a fragment", function() {
+ var fragment = doc.createDocumentFragment();
+ fragment.appendChild(new Text(" text "));
+ fragment.appendChild(new Text(" text "));
+ assert.equal(childNodeCount(doc), 0);
+ doc.appendChild(fragment);
+ assert.equal(childElementCount(doc), 0);
+ assert.equal(childNodeCount(doc), 2);
+ });
+
+ it("should allow replacing the document element with a fragment", function() {
+ var oldChild = doc.appendChild(doc.createElement("div"));
+ assert.equal(childElementCount(doc), 1);
+ var fragment = doc.createDocumentFragment();
+ fragment.appendChild(new Text(" text "));
+ var newChild = fragment.appendChild(doc.createElement("div"));
+ fragment.appendChild(new Text(" "));
+ doc.replaceChild(fragment, oldChild);
+ assert.equal(childElementCount(doc), 1);
+ assert.equal(childNodeCount(doc), 3);
+ assert.equal(newChild.parentNode, doc);
+ assert.isNull(oldChild.parentNode);
+ });
+
+ it("should throw when inserting multiple elements", function() {
+ doc.appendChild(doc.createElement("div"));
+ var oldChild = doc.appendChild(new Text(" text "));
+ assert.equal(childElementCount(doc), 1);
+ var newChild = doc.createElement("div");
+ assert.throws(function() {
+ doc.replaceChild(newChild, 0);
+ });
+ assert.throws(function() {
+ doc.insertBefore(newChild, oldChild);
+ });
+ });
+
+ it("should throw when inserting multiple elements with a fragment", function() {
+ var oldChild = doc.appendChild(doc.createElement("div"));
+ assert.equal(childElementCount(doc), 1);
+ var fragment = doc.createDocumentFragment();
+ fragment.appendChild(new Text(" text "));
+ fragment.appendChild(doc.createElement("div"));
+ fragment.appendChild(doc.createElement("div"));
+ fragment.appendChild(new Text(" "));
+ assert.throws(function() {
+ doc.replaceChild(fragment, 0);
+ });
+ assert.throws(function() {
+ doc.insertBefore(fragment, oldChild);
+ });
+ });
+});
+</script>
+</sky>
« 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