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

Unified Diff: sky/tests/dom/replaceChild.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/document-child-mutations-expected.txt ('k') | sky/tests/dom/replaceChild-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tests/dom/replaceChild.sky
diff --git a/sky/tests/dom/replaceChild.sky b/sky/tests/dom/replaceChild.sky
new file mode 100644
index 0000000000000000000000000000000000000000..17cc7ad7bb21360e9bde8f800122841bb78e1410
--- /dev/null
+++ b/sky/tests/dom/replaceChild.sky
@@ -0,0 +1,90 @@
+<sky>
+<import src="../resources/chai.sky" />
+<import src="../resources/mocha.sky" />
+<import src="../resources/dom-utils.sky" as="DomUtils" />
+<script>
+describe("replaceChild", function() {
+ var childElementCount = DomUtils.childElementCount;
+ var childNodeCount = DomUtils.childNodeCount;
+
+ it("should throw with invalid arguments", function() {
+ var parent = document.createElement("div");
+ assert.throws(function() {
+ parent.replaceChild();
+ });
+ assert.throws(function() {
+ parent.replaceChild(null, null);
+ });
+ assert.throws(function() {
+ parent.replaceChild({tagName: "div"});
+ });
+ assert.throws(function() {
+ parent.replaceChild(null, document.createElement("div"));
+ });
+ assert.throws(function() {
+ parent.replaceChild(document.createElement("div"), {tagName: "div"});
+ });
+ });
+
+ it("should replace elements", function() {
+ var parent = document.createElement("div");
+ var oldChild = parent.appendChild(document.createElement("div"));
+ var newChild = document.createElement("div");
+ parent.replaceChild(newChild, oldChild);
+ assert.isNull(oldChild.parentNode);
+ assert.equal(newChild.parentNode, parent);
+ });
+
+ it("should replace text", function() {
+ var parent = document.createElement("div");
+ var oldChild = parent.appendChild(new Text(" it's a text "));
+ var newChild = document.createElement("div");
+ parent.replaceChild(newChild, oldChild);
+ assert.isNull(oldChild.parentNode);
+ assert.equal(newChild.parentNode, parent);
+ });
+
+ it("should replace children with a fragment", function() {
+ var fragment = document.createDocumentFragment();
+ var child1 = fragment.appendChild(document.createElement("div"));
+ var child2 = fragment.appendChild(new Text(" text "));
+ var child3 = fragment.appendChild(new Text(" "));
+ var child4 = fragment.appendChild(document.createElement("div"));
+ var parent = document.createElement("div");
+ var oldChild = parent.appendChild(document.createElement("div"));
+ var lastChild = parent.appendChild(document.createElement("div"));
+ parent.replaceChild(fragment, oldChild);
+ assert.equal(child1.parentNode, parent);
+ assert.equal(child2.parentNode, parent);
+ assert.equal(child3.parentNode, parent);
+ assert.equal(child4.parentNode, parent);
+ assert.isNull(oldChild.parentNode);
+ assert.equal(childNodeCount(parent), 5);
+ assert.equal(childElementCount(parent), 3);
+ assert.equal(parent.lastChild, lastChild);
+ });
+
+ it("should throw when inserting a tree scope", function() {
+ var parent = document.createElement("div");
+ var doc = new Document();
+ var shadowRoot = document.createElement("span").createShadowRoot();
+ assert.throws(function() {
+ parent.replaceChild(doc);
+ });
+ assert.throws(function() {
+ parent.replaceChild(shadowRoot);
+ });
+ assert.throws(function() {
+ doc.replaceChild(fragment);
+ });
+ });
+
+ it("should throw when appending to a text", function() {
+ var parent = new Text();
+ assert.throws(function() {
+ parent.replaceChild(document.createElement("div"), null);
+ });
+ });
+});
+</script>
+</sky>
« no previous file with comments | « sky/tests/dom/document-child-mutations-expected.txt ('k') | sky/tests/dom/replaceChild-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698