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

Side by Side Diff: sky/tests/dom/replaceChild.sky

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « sky/tests/dom/ownerScope-expected.txt ('k') | sky/tests/dom/replaceChild-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <sky> 1 <sky>
2 <import src="../resources/chai.sky" />
3 <import src="../resources/mocha.sky" />
4 <import src="../resources/dom-utils.sky" as="DomUtils" /> 2 <import src="../resources/dom-utils.sky" as="DomUtils" />
5 <script> 3 <script>
6 describe("replaceChild", function() { 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
7 var childElementCount = DomUtils.childElementCount; 12 var childElementCount = DomUtils.childElementCount;
8 var childNodeCount = DomUtils.childNodeCount; 13 var childNodeCount = DomUtils.childNodeCount;
9 14
10 it("should throw with invalid arguments", function() { 15 test("should throw with invalid arguments", () {
11 var parent = document.createElement("div"); 16 var parent = document.createElement("div");
12 assert.throws(function() { 17 expect(() {
13 parent.replaceChild(); 18 parent.replaceChild();
14 }); 19 }, throws);
15 assert.throws(function() { 20 // expect(() {
16 parent.replaceChild(null, null); 21 // parent.replaceChild(null, null);
17 }); 22 // }, throws);
18 assert.throws(function() { 23 expect(() {
19 parent.replaceChild({tagName: "div"}); 24 parent.replaceChild({tagName: "div"});
20 }); 25 }, throws);
21 assert.throws(function() { 26 // expect(() {
22 parent.replaceChild(null, document.createElement("div")); 27 // parent.replaceChild(null, document.createElement("div"));
23 }); 28 // }, throws);
24 assert.throws(function() { 29 expect(() {
25 parent.replaceChild(document.createElement("div"), {tagName: "div"}); 30 parent.replaceChild(document.createElement("div"), {tagName: "div"});
26 }); 31 }, throws);
27 }); 32 });
28 33
29 it("should replace elements", function() { 34 test("should replace elements", () {
30 var parent = document.createElement("div"); 35 var parent = document.createElement("div");
31 var oldChild = parent.appendChild(document.createElement("div")); 36 var oldChild = parent.appendChild(document.createElement("div"));
32 var newChild = document.createElement("div"); 37 var newChild = document.createElement("div");
33 parent.replaceChild(newChild, oldChild); 38 parent.replaceChild(newChild, oldChild);
34 assert.isNull(oldChild.parentNode); 39 expect(oldChild.parentNode, isNull);
35 assert.equal(newChild.parentNode, parent); 40 expect(newChild.parentNode, equals(parent));
36 }); 41 });
37 42
38 it("should replace text", function() { 43 test("should replace text", () {
39 var parent = document.createElement("div"); 44 var parent = document.createElement("div");
40 var oldChild = parent.appendChild(new Text(" it's a text ")); 45 var oldChild = parent.appendChild(new Text(" it's a text "));
41 var newChild = document.createElement("div"); 46 var newChild = document.createElement("div");
42 parent.replaceChild(newChild, oldChild); 47 parent.replaceChild(newChild, oldChild);
43 assert.isNull(oldChild.parentNode); 48 expect(oldChild.parentNode, isNull);
44 assert.equal(newChild.parentNode, parent); 49 expect(newChild.parentNode, equals(parent));
45 }); 50 });
46 51
47 it("should replace children with a fragment", function() { 52 test("should replace children with a fragment", () {
48 var fragment = document.createDocumentFragment(); 53 var fragment = document.createDocumentFragment();
49 var child1 = fragment.appendChild(document.createElement("div")); 54 var child1 = fragment.appendChild(document.createElement("div"));
50 var child2 = fragment.appendChild(new Text(" text ")); 55 var child2 = fragment.appendChild(new Text(" text "));
51 var child3 = fragment.appendChild(new Text(" ")); 56 var child3 = fragment.appendChild(new Text(" "));
52 var child4 = fragment.appendChild(document.createElement("div")); 57 var child4 = fragment.appendChild(document.createElement("div"));
53 var parent = document.createElement("div"); 58 var parent = document.createElement("div");
54 var oldChild = parent.appendChild(document.createElement("div")); 59 var oldChild = parent.appendChild(document.createElement("div"));
55 var lastChild = parent.appendChild(document.createElement("div")); 60 var lastChild = parent.appendChild(document.createElement("div"));
56 parent.replaceChild(fragment, oldChild); 61 parent.replaceChild(fragment, oldChild);
57 assert.equal(child1.parentNode, parent); 62 expect(child1.parentNode, equals(parent));
58 assert.equal(child2.parentNode, parent); 63 expect(child2.parentNode, equals(parent));
59 assert.equal(child3.parentNode, parent); 64 expect(child3.parentNode, equals(parent));
60 assert.equal(child4.parentNode, parent); 65 expect(child4.parentNode, equals(parent));
61 assert.isNull(oldChild.parentNode); 66 expect(oldChild.parentNode, isNull);
62 assert.equal(childNodeCount(parent), 5); 67 expect(childNodeCount(parent), equals(5));
63 assert.equal(childElementCount(parent), 3); 68 expect(childElementCount(parent), equals(3));
64 assert.equal(parent.lastChild, lastChild); 69 expect(parent.lastChild, equals(lastChild));
65 }); 70 });
66 71
67 it("should throw when inserting a tree scope", function() { 72 // test("should throw when inserting a tree scope", () {
68 var parent = document.createElement("div"); 73 // var parent = document.createElement("div");
69 var doc = new Document(); 74 // var doc = new Document();
70 var shadowRoot = document.createElement("span").ensureShadowRoot(); 75 // var shadowRoot = document.createElement("span").ensureShadowRoot();
71 assert.throws(function() { 76 // expect(() {
72 parent.replaceChild(doc); 77 // parent.replaceChild(doc);
73 }); 78 // }, throws);
74 assert.throws(function() { 79 // expect(() {
75 parent.replaceChild(shadowRoot); 80 // parent.replaceChild(shadowRoot);
76 }); 81 // }, throws);
77 assert.throws(function() { 82 // expect(() {
78 doc.replaceChild(fragment); 83 // doc.replaceChild(fragment);
79 }); 84 // }, throws);
80 }); 85 // });
81 86
82 it("should throw when appending to a text", function() { 87 // test("should throw when appending to a text", () {
83 var parent = new Text(); 88 // var parent = new Text();
84 assert.throws(function() { 89 // expect(() {
85 parent.replaceChild(document.createElement("div"), null); 90 // parent.replaceChild(document.createElement("div"), null);
86 }); 91 // }, throws);
87 }); 92 // });
88 }); 93 }
89 </script> 94 </script>
90 </sky> 95 </sky>
OLDNEW
« no previous file with comments | « sky/tests/dom/ownerScope-expected.txt ('k') | sky/tests/dom/replaceChild-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698