Commit 855b8eb2 authored by Adam Barth's avatar Adam Barth

Merge pull request #740 from abarth/migrate_more_tests

Migrate sky/tests/layout to sky/unit/test
parents ce877f09 ccd00bc5
import 'dart:sky' as sky;
import 'package:sky/rendering.dart';
import 'package:test/test.dart';
import 'layout_utils.dart';
class SquareImage implements sky.Image {
int get width => 10;
int get height => 10;
}
class WideImage implements sky.Image {
int get width => 20;
int get height => 10;
}
class TallImage implements sky.Image {
int get width => 10;
int get height => 20;
}
void main() {
test('Image sizing', () {
RenderImage image;
image = new RenderImage(image: new SquareImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 25.0,
minHeight: 25.0,
maxWidth: 100.0,
maxHeight: 100.0));
expect(image.size.width, equals(25.0));
expect(image.size.height, equals(25.0));
image = new RenderImage(image: new WideImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 5.0,
minHeight: 30.0,
maxWidth: 100.0,
maxHeight: 100.0));
expect(image.size.width, equals(60.0));
expect(image.size.height, equals(30.0));
image = new RenderImage(image: new TallImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 50.0,
minHeight: 5.0,
maxWidth: 75.0,
maxHeight: 75.0));
expect(image.size.width, equals(50.0));
expect(image.size.height, equals(75.0));
image = new RenderImage(image: new WideImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 5.0,
minHeight: 5.0,
maxWidth: 100.0,
maxHeight: 100.0));
expect(image.size.width, equals(20.0));
expect(image.size.height, equals(10.0));
image = new RenderImage(image: new WideImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 5.0,
minHeight: 5.0,
maxWidth: 16.0,
maxHeight: 16.0));
expect(image.size.width, equals(16.0));
expect(image.size.height, equals(8.0));
image = new RenderImage(image: new TallImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 5.0,
minHeight: 5.0,
maxWidth: 16.0,
maxHeight: 16.0));
expect(image.size.width, equals(8.0));
expect(image.size.height, equals(16.0));
image = new RenderImage(image: new SquareImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 4.0,
minHeight: 4.0,
maxWidth: 8.0,
maxHeight: 8.0));
expect(image.size.width, equals(8.0));
expect(image.size.height, equals(8.0));
image = new RenderImage(image: new WideImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 20.0,
minHeight: 20.0,
maxWidth: 30.0,
maxHeight: 30.0));
expect(image.size.width, equals(30.0));
expect(image.size.height, equals(20.0));
image = new RenderImage(image: new TallImage());
layout(image,
constraints: new BoxConstraints(
minWidth: 20.0,
minHeight: 20.0,
maxWidth: 30.0,
maxHeight: 30.0));
expect(image.size.width, equals(20.0));
expect(image.size.height, equals(30.0));
});
test('Null image sizing', () {
RenderImage image;
image = new RenderImage();
layout(image,
constraints: new BoxConstraints(
minWidth: 25.0,
minHeight: 25.0,
maxWidth: 100.0,
maxHeight: 100.0));
expect(image.size.width, equals(25.0));
expect(image.size.height, equals(25.0));
image = new RenderImage(width: 50.0);
layout(image,
constraints: new BoxConstraints(
minWidth: 25.0,
minHeight: 25.0,
maxWidth: 100.0,
maxHeight: 100.0));
expect(image.size.width, equals(50.0));
expect(image.size.height, equals(25.0));
image = new RenderImage(height: 50.0);
layout(image,
constraints: new BoxConstraints(
minWidth: 25.0,
minHeight: 25.0,
maxWidth: 100.0,
maxHeight: 100.0));
expect(image.size.width, equals(25.0));
expect(image.size.height, equals(50.0));
image = new RenderImage(width: 100.0, height: 100.0);
layout(image,
constraints: new BoxConstraints(
minWidth: 25.0,
minHeight: 25.0,
maxWidth: 75.0,
maxHeight: 75.0));
expect(image.size.width, equals(75.0));
expect(image.size.height, equals(75.0));
});
}
import 'package:sky/rendering.dart';
const Size _kTestViewSize = const Size(800.0, 600.0);
class TestRenderView extends RenderView {
TestRenderView({ RenderBox child }) : super(child: child) {
attach();
rootConstraints = new ViewConstraints(size: _kTestViewSize);
scheduleInitialLayout();
}
void beginFrame(double timeStamp) {
RenderObject.flushLayout();
}
}
RenderView layout(RenderBox box, { BoxConstraints constraints }) {
if (constraints != null) {
box = new RenderPositionedBox(
child: new RenderConstrainedBox(
additionalConstraints: constraints,
child: box
)
);
}
TestRenderView renderView = new TestRenderView(child: box);
renderView.beginFrame(0.0);
return renderView;
}
import 'package:sky/rendering.dart';
import 'package:test/test.dart';
import 'layout_utils.dart';
void main() {
test('Stack can layout with top, right, bottom, left 0.0', () {
RenderBox size = new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)));
RenderBox red = new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: const Color(0xFFFF0000)
),
child: size);
RenderBox green = new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: const Color(0xFFFF0000)
));
RenderBox stack = new RenderStack(children: [red, green]);
(green.parentData as StackParentData)
..top = 0.0
..right = 0.0
..bottom = 0.0
..left = 0.0;
layout(stack, constraints: const BoxConstraints());
expect(stack.size.width, equals(100.0));
expect(stack.size.height, equals(100.0));
expect(red.size.width, equals(100.0));
expect(red.size.height, equals(100.0));
expect(green.size.width, equals(100.0));
expect(green.size.height, equals(100.0));
});
}
import 'package:sky/rendering.dart';
import 'package:test/test.dart';
import 'layout_utils.dart';
void main() {
test('Should be able to hit with negative scroll offset', () {
RenderBox size = new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)));
RenderBox red = new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: const Color(0xFFFF0000)
),
child: size);
RenderViewport viewport = new RenderViewport(child: red, scrollOffset: new Offset(0.0, -10.0));
RenderView renderView = layout(viewport);
HitTestResult result;
result = new HitTestResult();
renderView.hitTest(result, position: new Point(15.0, 0.0));
expect(result.path.first.target, equals(viewport));
result = new HitTestResult();
renderView.hitTest(result, position: new Point(15.0, 15.0));
expect(result.path.first.target, equals(size));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment