From faacd683231bbd05042669c6fbb5f2a87fc16938 Mon Sep 17 00:00:00 2001 From: Hixie Date: Thu, 28 May 2015 17:35:59 -0700 Subject: [PATCH] Make our raw/ tests actually check the paint output. R=abarth@chromium.org Review URL: https://codereview.chromium.org/1153053012 --- tests/raw/render_box-expected.txt | 8 ++ tests/raw/render_box.dart | 5 +- tests/raw/render_flex-expected.txt | 34 +++++++ tests/raw/render_flex.dart | 6 +- tests/resources/display_list.dart | 145 +++++++++++++++++++++++++++++ 5 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 tests/resources/display_list.dart diff --git a/tests/raw/render_box-expected.txt b/tests/raw/render_box-expected.txt index ca5bf5c5009..63daffb92e3 100644 --- a/tests/raw/render_box-expected.txt +++ b/tests/raw/render_box-expected.txt @@ -1,4 +1,12 @@ 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. diff --git a/tests/raw/render_box.dart b/tests/raw/render_box.dart index 6d04e8f2cae..c2a068531c3 100644 --- a/tests/raw/render_box.dart +++ b/tests/raw/render_box.dart @@ -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 }); } diff --git a/tests/raw/render_flex-expected.txt b/tests/raw/render_flex-expected.txt index 64f9b21baf7..c248cde2eca 100644 --- a/tests/raw/render_flex-expected.txt +++ b/tests/raw/render_flex-expected.txt @@ -1,4 +1,38 @@ 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. diff --git a/tests/raw/render_flex.dart b/tests/raw/render_flex.dart index 5cc95895e2b..5a019fe8c4b 100644 --- a/tests/raw/render_flex.dart +++ b/tests/raw/render_flex.dart @@ -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)); diff --git a/tests/resources/display_list.dart b/tests/resources/display_list.dart new file mode 100644 index 00000000000..67a1ef7c7a0 --- /dev/null +++ b/tests/resources/display_list.dart @@ -0,0 +1,145 @@ + +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 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 + } + +}