flutter/packages/unit/test/fn3/widget_tester.dart
Hixie b73b06e4ad fn3: Add a binding for fn3 and sky.
- I extracted the BuildScheduler into a separate binding.dart file.
- Various changes to expose private members that are needed by
  binding.dart.
- Registering the render objects for event dispatch.
- Convert the tests to use the new binding mechanism.

This doesn't yet have a RenderView or event handling.
2015-09-22 12:30:37 -07:00

66 lines
1.6 KiB
Dart

import 'package:sky/src/fn3.dart';
class RootComponent extends StatefulComponent {
RootComponentState createState() => new RootComponentState(this);
}
class RootComponentState extends ComponentState<RootComponent> {
RootComponentState(RootComponent widget) : super(widget);
Widget _child = new DecoratedBox(decoration: new BoxDecoration());
Widget get child => _child;
void set child(Widget value) {
if (value != _child) {
setState(() {
_child = value;
});
}
}
Widget build() => child;
}
const Object _rootSlot = const Object();
class WidgetTester {
WidgetTester() {
WidgetSkyBinding.initWidgetSkyBinding();
_rootElement = new StatefulComponentElement(new RootComponent());
_rootElement.mount(null, _rootSlot);
}
StatefulComponentElement _rootElement;
void walkElements(ElementVisitor visitor) {
void walk(Element element) {
visitor(element);
element.visitChildren(walk);
}
_rootElement.visitChildren(walk);
}
Element findElement(bool predicate(Element widget)) {
try {
walkElements((Element widget) {
if (predicate(widget))
throw widget;
});
} catch (e) {
if (e is Element)
return e;
rethrow;
}
return null;
}
void pumpFrame(Widget widget) {
(_rootElement.state as RootComponentState).child = widget;
WidgetSkyBinding.instance.beginFrame(0.0); // TODO(ianh): https://github.com/flutter/engine/issues/1084
}
void pumpFrameWithoutChange() {
WidgetSkyBinding.instance.beginFrame(0.0); // TODO(ianh): https://github.com/flutter/engine/issues/1084
}
}