Refactor rendering_tester
RenderView has to be a singleton for sanity during tests, otherwise they all end up in the dirty lists and we end up pumping all of them each frame.
This commit is contained in:
@@ -5,7 +5,6 @@ import '../../../../examples/rendering/sector_layout.dart';
|
||||
|
||||
void main() {
|
||||
test('Sector layout can paint', () {
|
||||
RenderingTester tester = new RenderingTester(root: buildSectorExample());
|
||||
tester.pumpFrame();
|
||||
layout(buildSectorExample(), phase: EnginePhase.composite);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void main() {
|
||||
];
|
||||
|
||||
RenderGrid grid = new RenderGrid(children: children, maxChildExtent: 100.0);
|
||||
RenderingTester tester = layout(grid, constraints: const BoxConstraints(maxWidth: 200.0));
|
||||
layout(grid, constraints: const BoxConstraints(maxWidth: 200.0));
|
||||
|
||||
children.forEach((child) {
|
||||
expect(child.size.width, equals(100.0), reason: "child width");
|
||||
@@ -27,7 +27,7 @@ void main() {
|
||||
grid.maxChildExtent = 60.0;
|
||||
expect(grid.needsLayout, equals(true));
|
||||
|
||||
tester.pumpFrame(phase: EnginePhase.layout);
|
||||
pumpFrame();
|
||||
|
||||
children.forEach((child) {
|
||||
expect(child.size.width, equals(50.0), reason: "child width");
|
||||
|
||||
@@ -22,19 +22,19 @@ void main() {
|
||||
child: new RenderDecoratedBox(decoration: new BoxDecoration())
|
||||
);
|
||||
RenderPositionedBox positioner = new RenderPositionedBox(child: sizer, shrinkWrap: ShrinkWrap.width);
|
||||
RenderingTester tester = layout(positioner, constraints: new BoxConstraints.loose(new Size(200.0, 200.0)));
|
||||
layout(positioner, constraints: new BoxConstraints.loose(new Size(200.0, 200.0)));
|
||||
|
||||
expect(positioner.size.width, equals(100.0), reason: "positioner width");
|
||||
expect(positioner.size.height, equals(200.0), reason: "positioner height");
|
||||
|
||||
positioner.shrinkWrap = ShrinkWrap.height;
|
||||
tester.pumpFrame(phase: EnginePhase.layout);
|
||||
pumpFrame();
|
||||
|
||||
expect(positioner.size.width, equals(200.0), reason: "positioner width");
|
||||
expect(positioner.size.height, equals(100.0), reason: "positioner height");
|
||||
|
||||
positioner.shrinkWrap = ShrinkWrap.both;
|
||||
tester.pumpFrame(phase: EnginePhase.layout);
|
||||
pumpFrame();
|
||||
|
||||
expect(positioner.size.width, equals(100.0), reason: "positioner width");
|
||||
expect(positioner.size.height, equals(100.0), reason: "positioner height");
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:sky/rendering.dart';
|
||||
const Size _kTestViewSize = const Size(800.0, 600.0);
|
||||
|
||||
class TestRenderView extends RenderView {
|
||||
TestRenderView({ RenderBox child }) : super(child: child) {
|
||||
TestRenderView() {
|
||||
attach();
|
||||
rootConstraints = new ViewConstraints(size: _kTestViewSize);
|
||||
scheduleInitialLayout();
|
||||
@@ -17,26 +17,18 @@ enum EnginePhase {
|
||||
composite
|
||||
}
|
||||
|
||||
class RenderingTester {
|
||||
RenderingTester({ RenderBox root }) {
|
||||
renderView = new TestRenderView(child: root);
|
||||
}
|
||||
RenderView _renderView;
|
||||
RenderView get renderView => _renderView;
|
||||
|
||||
RenderView renderView;
|
||||
void layout(RenderBox box, { BoxConstraints constraints, EnginePhase phase: EnginePhase.layout }) {
|
||||
assert(box != null); // if you want to just repump the last box, call pumpFrame().
|
||||
|
||||
void pumpFrame({ EnginePhase phase: EnginePhase.composite }) {
|
||||
RenderObject.flushLayout();
|
||||
if (phase == EnginePhase.layout)
|
||||
return;
|
||||
renderView.updateCompositingBits();
|
||||
RenderObject.flushPaint();
|
||||
if (phase == EnginePhase.paint)
|
||||
return;
|
||||
renderView.compositeFrame();
|
||||
}
|
||||
}
|
||||
if (renderView == null)
|
||||
_renderView = new TestRenderView();
|
||||
|
||||
if (renderView.child != null)
|
||||
renderView.child = null;
|
||||
|
||||
RenderingTester layout(RenderBox box, { BoxConstraints constraints }) {
|
||||
if (constraints != null) {
|
||||
box = new RenderPositionedBox(
|
||||
child: new RenderConstrainedBox(
|
||||
@@ -46,7 +38,18 @@ RenderingTester layout(RenderBox box, { BoxConstraints constraints }) {
|
||||
);
|
||||
}
|
||||
|
||||
RenderingTester tester = new RenderingTester(root: box);
|
||||
tester.pumpFrame(phase: EnginePhase.layout);
|
||||
return tester;
|
||||
renderView.child = box;
|
||||
|
||||
pumpFrame(phase: phase);
|
||||
}
|
||||
|
||||
void pumpFrame({ EnginePhase phase: EnginePhase.layout }) {
|
||||
RenderObject.flushLayout();
|
||||
if (phase == EnginePhase.layout)
|
||||
return;
|
||||
renderView.updateCompositingBits();
|
||||
RenderObject.flushPaint();
|
||||
if (phase == EnginePhase.paint)
|
||||
return;
|
||||
renderView.compositeFrame();
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@ void main() {
|
||||
child: size);
|
||||
|
||||
RenderViewport viewport = new RenderViewport(child: red, scrollOffset: new Offset(0.0, -10.0));
|
||||
RenderingTester tester = layout(viewport);
|
||||
layout(viewport);
|
||||
|
||||
HitTestResult result;
|
||||
|
||||
result = new HitTestResult();
|
||||
tester.renderView.hitTest(result, position: new Point(15.0, 0.0));
|
||||
renderView.hitTest(result, position: new Point(15.0, 0.0));
|
||||
expect(result.path.first.target, equals(viewport));
|
||||
|
||||
result = new HitTestResult();
|
||||
tester.renderView.hitTest(result, position: new Point(15.0, 15.0));
|
||||
renderView.hitTest(result, position: new Point(15.0, 15.0));
|
||||
expect(result.path.first.target, equals(size));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user