提交 661906e7 编写于 作者: A Adam Barth

Port remaining Sky tests to the new world

These tests now run in the DOM-less world.

R=ianh@google.com

Review URL: https://codereview.chromium.org/1212163009.
上级 42490925
# This test depends on events.md being implemented
crbug.com/1 events/dispatcher.sky [ Skip ]
crbug.com/1 events/dispatcher.dart [ Skip ]
<sky>
<import src="../resources/dom-utils.sky" as="DomUtils" />
<script>
import "../resources/dom_utils.dart";
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
......@@ -9,8 +7,7 @@ import "dart:sky";
void main() {
initUnit();
var childElementCount = DomUtils.childElementCount;
var childNodeCount = DomUtils.childNodeCount;
Document document = new Document();
test("should throw with invalid arguments", () {
var parent = document.createElement("div");
......@@ -28,8 +25,8 @@ void main() {
test("should insert children", () {
var parent = document.createElement("div");
var child1 = parent.appendChild(document.createElement("div"));
var child2 = parent.appendChild(new Text(" text "));
var child3 = parent.appendChild(new Text(" "));
var child2 = parent.appendChild(document.createText(" text "));
var child3 = parent.appendChild(document.createText(" "));
var child4 = parent.appendChild(document.createElement("div"));
expect(child1.parentNode, equals(parent));
expect(child2.parentNode, equals(parent));
......@@ -42,8 +39,8 @@ void main() {
test("should insert children with a fragment", () {
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 child2 = fragment.appendChild(document.createText(" text "));
var child3 = fragment.appendChild(document.createText(" "));
var child4 = fragment.appendChild(document.createElement("div"));
var parent = document.createElement("div");
parent.appendChild(fragment);
......@@ -79,5 +76,3 @@ void main() {
// }, throws);
// });
}
</script>
</sky>
\ No newline at end of file
<html>
<script>
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
......@@ -10,6 +8,7 @@ void main() {
var div;
setUp(() {
var document = new Document();
div = document.createElement("div");
});
......@@ -63,5 +62,3 @@ void main() {
expect(oldAttributes[2].value, equals("2"));
});
}
</script>
</html>
<sky>
<import src="../resources/dom-utils.sky" as="DomUtils" />
<script>
import "../resources/dom_utils.dart";
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
......@@ -11,9 +9,6 @@ void main() {
var doc;
var childElementCount = DomUtils.childElementCount;
var childNodeCount = DomUtils.childNodeCount;
setUp(() {
doc = new Document();
});
......@@ -29,7 +24,7 @@ void main() {
});
test("should allow replacing a text child with an element", () {
var oldChild = doc.appendChild(new Text("text here"));
var oldChild = doc.appendChild(doc.createText("text here"));
expect(childElementCount(doc), equals(0));
expect(childNodeCount(doc), equals(1));
var newChild = doc.createElement("div");
......@@ -43,7 +38,7 @@ void main() {
test("should allow replacing the document element with text", () {
var oldChild = doc.appendChild(doc.createElement("div"));
expect(childElementCount(doc), equals(1));
var newChild = new Text(" text ");
var newChild = doc.createText(" text ");
oldChild.replaceWith([newChild]);
expect(childElementCount(doc), equals(0));
expect(childNodeCount(doc), equals(1));
......@@ -53,8 +48,8 @@ void main() {
test("should allow inserting text with a fragment", () {
var fragment = doc.createDocumentFragment();
fragment.appendChild(new Text(" text "));
fragment.appendChild(new Text(" text "));
fragment.appendChild(doc.createText(" text "));
fragment.appendChild(doc.createText(" text "));
expect(childNodeCount(doc), equals(0));
doc.appendChild(fragment);
expect(childElementCount(doc), equals(0));
......@@ -65,9 +60,9 @@ void main() {
var oldChild = doc.appendChild(doc.createElement("div"));
expect(childElementCount(doc), equals(1));
var fragment = doc.createDocumentFragment();
fragment.appendChild(new Text(" text "));
fragment.appendChild(doc.createText(" text "));
var newChild = fragment.appendChild(doc.createElement("div"));
fragment.appendChild(new Text(" "));
fragment.appendChild(doc.createText(" "));
oldChild.replaceWith([fragment]);
expect(childElementCount(doc), equals(1));
expect(childNodeCount(doc), equals(3));
......@@ -77,7 +72,7 @@ void main() {
test("should throw when inserting multiple elements", () {
doc.appendChild(doc.createElement("div"));
var oldChild = doc.appendChild(new Text(" text "));
var oldChild = doc.appendChild(doc.createText(" text "));
expect(childElementCount(doc), equals(1));
var newChild = doc.createElement("div");
// expect(() {
......@@ -92,10 +87,10 @@ void main() {
var oldChild = doc.appendChild(doc.createElement("div"));
expect(childElementCount(doc), equals(1));
var fragment = doc.createDocumentFragment();
fragment.appendChild(new Text(" text "));
fragment.appendChild(doc.createText(" text "));
fragment.appendChild(doc.createElement("div"));
fragment.appendChild(doc.createElement("div"));
fragment.appendChild(new Text(" "));
fragment.appendChild(doc.createText(" "));
// expect(() {
// doc.replaceChild(fragment, 0);
// }, throws);
......@@ -104,5 +99,3 @@ void main() {
// }, throws);
});
}
</script>
</sky>
\ No newline at end of file
<parent>
<child1>
<grandchild />
</child1>
<child2 />
</parent>
<script>
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
......@@ -15,12 +7,20 @@ void main() {
initUnit();
test("getChildElements should only include immediate children", () {
var parent = document.querySelector('parent');
var doc = new Document();
var parent = doc.createElement('parent');
var child1 = doc.createElement('child1');
var child2 = doc.createElement('child1');
var grandchild = doc.createElement('grandchild');
doc.appendChild(parent);
parent.appendChild(child1);
parent.appendChild(child2);
child1.appendChild(grandchild);
var children = parent.getChildElements();
expect(children.length, equals(2));
expect(children[0], equals(document.querySelector('child1')));
expect(children[1], equals(document.querySelector('child2')));
expect(children[0], equals(child1));
expect(children[1], equals(child2));
});
}
</script>
</sky>
\ No newline at end of file
CONSOLE: unittest-suite-wait-for-done
CONSOLE: PASS: should be able to insert in DOM
CONSOLE:
CONSOLE: All 1 tests passed.
CONSOLE: unittest-suite-success
DONE
<sky>
<script>
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
import "dart:sky";
class CustomText extends Text {
CustomText() : super("awesome");
bool get isCustom => true;
}
void main() {
initUnit();
test("should be able to insert in DOM", () {
var child = new CustomText();
expect(child.isCustom, isTrue);
expect(child.parentNode, isNull);
expect(child.data, equals("awesome"));
var parent = document.createElement("div");
parent.appendChild(child);
expect(child.parentNode, equals(parent));
expect(parent.firstChild, equals(child));
expect(parent.firstChild.isCustom, isTrue);
});
}
</script>
</sky>
<sky>
<script>
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
......@@ -47,5 +45,3 @@ void main() {
expect(child.owner, isNull);
});
}
</script>
</sky>
\ No newline at end of file
<sky>
<import src="../resources/dom-utils.sky" as="DomUtils" />
<script>
import "../resources/dom_utils.dart";
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
......@@ -9,8 +7,7 @@ import "dart:sky";
void main() {
initUnit();
var childElementCount = DomUtils.childElementCount;
var childNodeCount = DomUtils.childNodeCount;
var document = new Document();
test("should replace elements", () {
var parent = document.createElement("div");
......@@ -23,7 +20,7 @@ void main() {
test("should replace text", () {
var parent = document.createElement("div");
var oldChild = parent.appendChild(new Text(" it's a text "));
var oldChild = parent.appendChild(document.createText(" it's a text "));
var newChild = document.createElement("div");
oldChild.replaceWith([newChild]);
expect(oldChild.parentNode, isNull);
......@@ -33,8 +30,8 @@ void main() {
test("should replace children with a fragment", () {
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 child2 = fragment.appendChild(document.createText(" text "));
var child3 = fragment.appendChild(document.createText(" "));
var child4 = fragment.appendChild(document.createElement("div"));
var parent = document.createElement("div");
var oldChild = parent.appendChild(document.createElement("div"));
......@@ -72,5 +69,3 @@ void main() {
// }, throws);
// });
}
</script>
</sky>
\ No newline at end of file
<script>
import "../resources/third_party/unittest/unittest.dart";
import "../resources/unit.dart";
import "dart:sky";
......@@ -100,4 +99,3 @@ void main() {
});
}
</script>
??????????????????????????????????????????????????????????
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册