Merge pull request #1761 from abarth/rm_old_text_painter

Delete OldTextPainter
This commit is contained in:
Adam Barth
2015-10-23 12:22:19 -07:00
14 changed files with 14 additions and 967 deletions

View File

@@ -1,60 +0,0 @@
import 'dart:ui';
import 'package:test/test.dart';
import 'dom_utils.dart';
void main() {
Document document = new Document();
test("should throw with invalid arguments", () {
var parent = document.createElement("div");
expect(() {
Function.apply(parent.appendChild, []);
}, throws);
expect(() {
parent.appendChild(null);
}, throws);
expect(() {
Function.apply(parent.appendChild, [{"tagName": "div"}]);
}, throws);
});
test("should insert children", () {
var parent = document.createElement("div");
var child1 = parent.appendChild(document.createElement("div"));
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));
expect(child3.parentNode, equals(parent));
expect(child4.parentNode, equals(parent));
expect(childNodeCount(parent), equals(4));
expect(childElementCount(parent), equals(2));
});
test("should insert children with a fragment", () {
var fragment = document.createDocumentFragment();
var child1 = fragment.appendChild(document.createElement("div"));
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);
expect(child1.parentNode, equals(parent));
expect(child2.parentNode, equals(parent));
expect(child3.parentNode, equals(parent));
expect(child4.parentNode, equals(parent));
expect(childNodeCount(parent), equals(4));
expect(childElementCount(parent), equals(2));
});
// TODO(dart): These might be real bugs too.
// test("should throw when appending to a text", () {
// var parent = new Text();
// expect(() {
// parent.appendChild(document.createElement("div"));
// }, throws);
// });
}

View File

@@ -1,87 +0,0 @@
import 'dart:ui';
import 'package:test/test.dart';
import 'dom_utils.dart';
void main() {
var doc;
setUp(() {
doc = new Document();
});
test("should allow replacing the document element", () {
var oldChild = doc.appendChild(doc.createElement("div"));
expect(childElementCount(doc), equals(1));
var newChild = doc.createElement("div");
oldChild.replaceWith([newChild]);
expect(childElementCount(doc), equals(1));
expect(newChild.parentNode, equals(doc));
expect(oldChild.parentNode, isNull);
});
test("should allow replacing a text child with an element", () {
var oldChild = doc.appendChild(doc.createText("text here"));
expect(childElementCount(doc), equals(0));
expect(childNodeCount(doc), equals(1));
var newChild = doc.createElement("div");
oldChild.replaceWith([newChild]);
expect(childElementCount(doc), equals(1));
expect(childNodeCount(doc), equals(1));
expect(newChild.parentNode, equals(doc));
expect(oldChild.parentNode, isNull);
});
test("should allow replacing the document element with text", () {
var oldChild = doc.appendChild(doc.createElement("div"));
expect(childElementCount(doc), equals(1));
var newChild = doc.createText(" text ");
oldChild.replaceWith([newChild]);
expect(childElementCount(doc), equals(0));
expect(childNodeCount(doc), equals(1));
expect(newChild.parentNode, equals(doc));
expect(oldChild.parentNode, isNull);
});
test("should allow inserting text with a fragment", () {
var fragment = doc.createDocumentFragment();
fragment.appendChild(doc.createText(" text "));
fragment.appendChild(doc.createText(" text "));
expect(childNodeCount(doc), equals(0));
doc.appendChild(fragment);
expect(childElementCount(doc), equals(0));
expect(childNodeCount(doc), equals(2));
});
test("should allow replacing the document element with a fragment", () {
var oldChild = doc.appendChild(doc.createElement("div"));
expect(childElementCount(doc), equals(1));
var fragment = doc.createDocumentFragment();
fragment.appendChild(doc.createText(" text "));
var newChild = fragment.appendChild(doc.createElement("div"));
fragment.appendChild(doc.createText(" "));
oldChild.replaceWith([fragment]);
expect(childElementCount(doc), equals(1));
expect(childNodeCount(doc), equals(3));
expect(newChild.parentNode, equals(doc));
expect(oldChild.parentNode, isNull);
});
test("should throw when inserting multiple elements", () {
doc.appendChild(doc.createElement("div"));
doc.appendChild(doc.createText(" text "));
expect(childElementCount(doc), equals(1));
doc.createElement("div");
});
test("should throw when inserting multiple elements with a fragment", () {
doc.appendChild(doc.createElement("div"));
expect(childElementCount(doc), equals(1));
var fragment = doc.createDocumentFragment();
fragment.appendChild(doc.createText(" text "));
fragment.appendChild(doc.createElement("div"));
fragment.appendChild(doc.createElement("div"));
fragment.appendChild(doc.createText(" "));
});
}

View File

@@ -1,15 +0,0 @@
import 'dart:ui';
int childNodeCount(parent) {
int count = 0;
for (Node node = parent.firstChild; node != null; node = node.nextSibling)
++count;
return count;
}
int childElementCount(parent) {
int count = 0;
for (Element element = parent.firstElementChild; element != null; element = element.nextElementSibling)
++count;
return count;
}

View File

@@ -1,23 +0,0 @@
import 'dart:ui';
import 'package:test/test.dart';
void main() {
test("getChildElements should only include immediate children", () {
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(child1));
expect(children[1], equals(child2));
});
}

View File

@@ -1,38 +0,0 @@
import 'dart:ui' as ui;
import 'package:test/test.dart';
void main() {
test('should be settable using "style" attribute', () {
ui.LayoutRoot layoutRoot = new ui.LayoutRoot();
var document = new ui.Document();
var foo = document.createElement('foo');
layoutRoot.rootElement = foo;
foo.setAttribute('style', 'color: red');
expect(foo.getAttribute('style'), equals('color: red'));
expect(foo.style["color"], equals('rgb(255, 0, 0)'));
});
test('should not crash when setting style to null', () {
ui.LayoutRoot layoutRoot = new ui.LayoutRoot();
var document = new ui.Document();
var foo = document.createElement('foo');
layoutRoot.rootElement = foo;
expect(foo.style['color'], isNull);
foo.style["color"] = null; // This used to crash.
expect(foo.style['color'], isNull);
foo.style["color"] = "blue";
expect(foo.style['color'], equals("rgb(0, 0, 255)"));
foo.style["color"] = null;
expect(foo.style['color'], isNull);
foo.style["color"] = "blue";
expect(foo.style['color'], equals("rgb(0, 0, 255)"));
foo.style.removeProperty("color");
expect(foo.style['color'], isNull);
layoutRoot.layout();
});
}

View File

@@ -1,21 +0,0 @@
import 'dart:ui';
import 'package:test/test.dart';
void main() {
Document document = new Document();
test("should throw with invalid arguments", () {
Element parent = document.createElement("div");
Element child = document.createElement("div");
parent.appendChild(child);
// TODO(eseidel): This should throw!
// expect(() {
// parent.insertBefore([parent]);
// }, throws);
expect(() {
child.insertBefore(<Node>[parent]);
}, throws);
});
}

View File

@@ -1,17 +0,0 @@
import 'dart:ui';
import 'package:test/test.dart';
void main() {
test("should return null for elements not a child of a scope", () {
var doc = new Document();
var element = doc.createElement("div");
expect(element.owner, isNull);
});
test("should return the document for elements in the document scope", () {
var doc = new Document();
var element = doc.createElement("div");
doc.appendChild(element);
expect(element.owner, equals(doc));
});
}

View File

@@ -1,54 +0,0 @@
import 'dart:ui';
import 'package:test/test.dart';
import 'dom_utils.dart';
void main() {
Document document = new Document();
test("should replace elements", () {
Element parent = document.createElement("div");
Element oldChild = parent.appendChild(document.createElement("div"));
Element newChild = document.createElement("div");
oldChild.replaceWith(<Node>[newChild]);
expect(oldChild.parentNode, isNull);
expect(newChild.parentNode, equals(parent));
});
test("should replace text", () {
Element parent = document.createElement("div");
Node oldChild = parent.appendChild(document.createText(" it's a text "));
Element newChild = document.createElement("div");
oldChild.replaceWith(<Node>[newChild]);
expect(oldChild.parentNode, isNull);
expect(newChild.parentNode, equals(parent));
});
test("should replace children with a fragment", () {
DocumentFragment fragment = document.createDocumentFragment();
Element child1 = fragment.appendChild(document.createElement("div"));
Node child2 = fragment.appendChild(document.createText(" text "));
Node child3 = fragment.appendChild(document.createText(" "));
Element child4 = fragment.appendChild(document.createElement("div"));
Element parent = document.createElement("div");
Element oldChild = parent.appendChild(document.createElement("div"));
Element lastChild = parent.appendChild(document.createElement("div"));
oldChild.replaceWith(<Node>[fragment]);
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 appending to a text", () {
// var parent = new Text();
// expect(() {
// parent.replaceChild(document.createElement("div"), null);
// }, throws);
// });
}

View File

@@ -1,10 +0,0 @@
import 'dart:ui' as ui;
import 'package:test/test.dart';
void main() {
test("createText(null) shouldn't crash", () {
var doc = new ui.Document();
doc.createText(null);
});
}