mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This CL flips the switch to make Sky use Dart. TBR=eseidel@chromium.org BUG=454613 Review URL: https://codereview.chromium.org/922893002
95 lines
3.1 KiB
Plaintext
95 lines
3.1 KiB
Plaintext
<sky>
|
|
<import src="../resources/dom-utils.sky" as="DomUtils" />
|
|
<script>
|
|
import "../resources/third_party/unittest/unittest.dart";
|
|
import "../resources/unit.dart";
|
|
|
|
import "dart:sky";
|
|
|
|
void main() {
|
|
initUnit();
|
|
|
|
var childElementCount = DomUtils.childElementCount;
|
|
var childNodeCount = DomUtils.childNodeCount;
|
|
|
|
test("should throw with invalid arguments", () {
|
|
var parent = document.createElement("div");
|
|
expect(() {
|
|
parent.replaceChild();
|
|
}, throws);
|
|
// expect(() {
|
|
// parent.replaceChild(null, null);
|
|
// }, throws);
|
|
expect(() {
|
|
parent.replaceChild({tagName: "div"});
|
|
}, throws);
|
|
// expect(() {
|
|
// parent.replaceChild(null, document.createElement("div"));
|
|
// }, throws);
|
|
expect(() {
|
|
parent.replaceChild(document.createElement("div"), {tagName: "div"});
|
|
}, throws);
|
|
});
|
|
|
|
test("should replace elements", () {
|
|
var parent = document.createElement("div");
|
|
var oldChild = parent.appendChild(document.createElement("div"));
|
|
var newChild = document.createElement("div");
|
|
parent.replaceChild(newChild, oldChild);
|
|
expect(oldChild.parentNode, isNull);
|
|
expect(newChild.parentNode, equals(parent));
|
|
});
|
|
|
|
test("should replace text", () {
|
|
var parent = document.createElement("div");
|
|
var oldChild = parent.appendChild(new Text(" it's a text "));
|
|
var newChild = document.createElement("div");
|
|
parent.replaceChild(newChild, oldChild);
|
|
expect(oldChild.parentNode, isNull);
|
|
expect(newChild.parentNode, equals(parent));
|
|
});
|
|
|
|
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 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);
|
|
expect(child1.parentNode, equals(parent));
|
|
expect(child2.parentNode, equals(parent));
|
|
expect(child3.parentNode, equals(parent));
|
|
expect(child4.parentNode, equals(parent));
|
|
expect(oldChild.parentNode, isNull);
|
|
expect(childNodeCount(parent), equals(5));
|
|
expect(childElementCount(parent), equals(3));
|
|
expect(parent.lastChild, equals(lastChild));
|
|
});
|
|
|
|
// test("should throw when inserting a tree scope", () {
|
|
// var parent = document.createElement("div");
|
|
// var doc = new Document();
|
|
// var shadowRoot = document.createElement("span").ensureShadowRoot();
|
|
// expect(() {
|
|
// parent.replaceChild(doc);
|
|
// }, throws);
|
|
// expect(() {
|
|
// parent.replaceChild(shadowRoot);
|
|
// }, throws);
|
|
// expect(() {
|
|
// doc.replaceChild(fragment);
|
|
// }, throws);
|
|
// });
|
|
|
|
// test("should throw when appending to a text", () {
|
|
// var parent = new Text();
|
|
// expect(() {
|
|
// parent.replaceChild(document.createElement("div"), null);
|
|
// }, throws);
|
|
// });
|
|
}
|
|
</script>
|
|
</sky> |