提交 faacd683 编写于 作者: H Hixie

Make our raw/ tests actually check the paint output.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1153053012
上级 b8953a4b
CONSOLE: unittest-suite-wait-for-done
CONSOLE: TestView enabled
CONSOLE:
PAINT FOR FRAME #1 ----------------------------------------------
1 | TestDisplayList() constructor: 800.0 x 600.0
1 | paintChild at 0.0,0.0
1 | | TestDisplayList() constructor: 800.0 x 600.0
1 | | drawRect(0.0:0.0:600.0:800.0, Paint(0xff00ff00))
------------------------------------------------------------------------
CONSOLE: PASS: should size to render view
CONSOLE:
CONSOLE: All 1 tests passed.
......
......@@ -4,6 +4,7 @@
import '../resources/third_party/unittest/unittest.dart';
import '../resources/unit.dart';
import '../resources/display_list.dart';
import 'dart:sky' as sky;
import 'package:sky/framework/rendering/render_box.dart';
......@@ -16,9 +17,11 @@ void main() {
decoration: new BoxDecoration(backgroundColor: 0xFF00FF00)
)
);
RenderView renderView = new RenderView(child: root);
TestView renderView = new TestView(child: root);
renderView.layout(new ViewConstraints(width: sky.view.width, height: sky.view.height));
expect(root.size.width, equals(sky.view.width));
expect(root.size.height, equals(sky.view.height));
renderView.paintFrame();
print(renderView.lastPaint); // TODO(ianh): figure out how to make this fit the unit testing framework better
});
}
CONSOLE: unittest-suite-wait-for-done
CONSOLE: TestView enabled
CONSOLE:
PAINT FOR FRAME #1 ----------------------------------------------
1 | TestDisplayList() constructor: 800.0 x 600.0
1 | paintChild at 0.0,0.0
1 | | TestDisplayList() constructor: 800.0 x 600.0
1 | | drawRect(0.0:0.0:600.0:800.0, Paint(0xff000000))
1 | | paintChild at 0.0,0.0
1 | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | drawRect(0.0:0.0:82.5:800.0, Paint(0xffffff00))
1 | | paintChild at 350.0,82.5
1 | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | drawRect(0.0:0.0:100.0:100.0, Paint(0x7700ffff))
1 | | paintChild at 0.0,182.5
1 | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | paintChild at 10.0,10.0
1 | | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | | drawRect(0.0:0.0:150.0:780.0, Paint(0xffffffff))
1 | | | | paintChild at 0.0,0.0
1 | | | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | | | drawRect(0.0:0.0:50.0:780.0, Paint(0xff00ff00))
1 | | | | paintChild at 0.0,50.0
1 | | | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | | | drawRect(0.0:0.0:100.0:780.0, Paint(0x7700ffff))
1 | | paintChild at 0.0,352.5
1 | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | drawRect(0.0:0.0:247.5:800.0, Paint(0xff333333))
1 | | | paintChild at 0.0,0.0
1 | | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | | drawRect(0.0:0.0:247.5:266.6666564941406, Paint(0x77ff00ff))
1 | | | paintChild at 266.6666666666667,0.0
1 | | | | TestDisplayList() constructor: 800.0 x 600.0
1 | | | | drawRect(0.0:0.0:247.5:533.3333129882812, Paint(0xff0000ff))
------------------------------------------------------------------------
CONSOLE: PASS: should flex
CONSOLE:
CONSOLE: All 1 tests passed.
......
......@@ -4,6 +4,7 @@
import '../resources/third_party/unittest/unittest.dart';
import '../resources/unit.dart';
import '../resources/display_list.dart';
import 'dart:sky' as sky;
import 'package:sky/framework/app.dart';
import 'package:sky/framework/rendering/render_block.dart';
......@@ -35,7 +36,7 @@ class RenderSolidColor extends RenderDecoratedBox {
}
}
AppView app;
TestApp app;
void main() {
initUnit();
......@@ -86,8 +87,7 @@ void main() {
flexRoot.add(decoratedRow);
decoratedRow.parentData.flex = 3;
app = new AppView(root);
app = new TestApp(root);
expect(root.size.width, equals(sky.view.width));
expect(root.size.height, equals(sky.view.height));
......
import 'package:sky/framework/rendering/render_node.dart';
import 'package:sky/framework/rendering/render_box.dart';
import 'dart:sky' as sky;
typedef void Logger (String s);
class TestDisplayList extends RenderNodeDisplayList {
TestDisplayList(double width, double height, this.logger, { this.indent: '' }) :
this.width = width,
this.height = height,
super(width, height) {
log("TestDisplayList() constructor: $width x $height");
}
final String indent;
final double width;
final double height;
Logger logger;
void log(String s) {
logger("${indent} ${s}");
}
String explainPaint(sky.Paint paint) {
return "Paint(0x${paint.color.toRadixString(16).padLeft(8, '0')})";
}
void save() {
log("save");
}
void saveLayer(sky.Rect bounds, sky.Paint paint) {
log("saveLayer(${bounds.top}:${bounds.left}:${bounds.bottom}:${bounds.right}, ${explainPaint(paint)})");
}
void restore() {
log("restore");
}
void translate(double dx, double dy) {
log("translate($dx, $dy)");
}
void scale(double sx, double sy) {
log("scale($sx, $sy)");
}
void rotateDegrees(double degrees) {
log("rotateDegrees($degrees)");
}
void skew(double sx, double sy) {
log("skew($sx, $sy)");
}
void concat(List<double> matrix9) {
log("concat($matrix9)");
}
void clipRect(sky.Rect rect) {
log("clipRect(${rect.top}:${rect.left}:${rect.bottom}:${rect.right})");
}
void drawPicture(sky.Picture picture) {
log("drawPicture()");
}
void drawPaint(sky.Paint paint) {
log("drawPaint(${explainPaint(paint)})");
}
void drawRect(sky.Rect rect, sky.Paint paint) {
log("drawRect(${rect.top}:${rect.left}:${rect.bottom}:${rect.right}, ${explainPaint(paint)})");
}
void drawOval(sky.Rect rect, sky.Paint paint) {
log("drawOval(${rect.top}:${rect.left}:${rect.bottom}:${rect.right}, ${explainPaint(paint)})");
}
void drawCircle(double x, double y, double radius, sky.Paint paint) {
log("drawCircle($x, $y, $radius, ${explainPaint(paint)})");
}
void drawPath(sky.Path path, sky.Paint paint) {
log("drawPath(Path, ${explainPaint(paint)})");
}
void paintChild(RenderNode child, sky.Point position) {
log("paintChild at ${position.x},${position.y}");
child.paint(new TestDisplayList(width, height, logger, indent: "$indent |"));
}
}
class TestView extends RenderView {
TestView({
RenderBox child,
Duration timeForRotation
}) : super(child: child, timeForRotation: timeForRotation) {
print("TestView enabled");
}
int frame = 0;
String lastPaint = '';
void log(String s) {
lastPaint += "\n$s";
}
void paintFrame() {
RenderNode.debugDoingPaint = true;
frame += 1;
log("PAINT FOR FRAME #${frame} ----------------------------------------------");
var canvas = new TestDisplayList(sky.view.width, sky.view.height, log, indent: "${frame} |");
paint(canvas);
log("------------------------------------------------------------------------");
RenderNode.debugDoingPaint = false;
}
}
class TestApp {
TestApp(RenderBox root) {
_renderView = new TestView(child: root);
_renderView.attach();
_renderView.layout(new ViewConstraints(width: sky.view.width, height: sky.view.height));
_renderView.paintFrame();
print(_renderView.lastPaint); // TODO(ianh): figure out how to make this fit the unit testing framework better
}
RenderView _renderView;
RenderBox get root => _renderView.child;
void set root(RenderBox value) {
_renderView.child = value;
}
void _beginFrame(double timeStamp) {
RenderNode.flushLayout();
_renderView.paintFrame();
print(_renderView.lastPaint); // TODO(ianh): figure out how to make this fit the unit testing framework better
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册