viewport_test.dart 1.27 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/rendering.dart';
6 7
import 'package:test/test.dart';

8
import 'rendering_tester.dart';
9 10

void main() {
11
  test('Should be able to hit with positive paint offset', () {
Adam Barth's avatar
Adam Barth committed
12 13 14 15 16
    RenderBox green = new RenderDecoratedBox(
      decoration: new BoxDecoration(
        backgroundColor: const Color(0xFF00FF00)
      ));

17
    RenderBox size = new RenderConstrainedBox(
Adam Barth's avatar
Adam Barth committed
18 19
      additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)),
      child: green);
20 21 22 23 24 25 26

    RenderBox red = new RenderDecoratedBox(
      decoration: new BoxDecoration(
        backgroundColor: const Color(0xFFFF0000)
      ),
      child: size);

27
    RenderViewport viewport = new RenderViewport(child: red, paintOffset: new Offset(0.0, 10.0));
Hixie's avatar
Hixie committed
28
    layout(viewport);
29 30 31 32

    HitTestResult result;

    result = new HitTestResult();
Ian Hickson's avatar
Ian Hickson committed
33
    renderer.renderView.hitTest(result, position: new Point(15.0, 0.0));
34
    expect(result.path.first.target.runtimeType, equals(RenderView));
35 36

    result = new HitTestResult();
Ian Hickson's avatar
Ian Hickson committed
37
    renderer.renderView.hitTest(result, position: new Point(15.0, 15.0));
Adam Barth's avatar
Adam Barth committed
38
    expect(result.path.first.target, equals(green));
39 40
  });
}