clip_test.dart 1.67 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// 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.

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

final List<String> log = <String>[];

class PathClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    log.add('getClip');
    return new Path()
      ..addRect(new Rect.fromLTWH(50.0, 50.0, 100.0, 100.0));
  }
  @override
  bool shouldRepaint(PathClipper oldWidget) => false;
}

void main() {
22 23
  testWidgets('ClipPath', (WidgetTester tester) async {
    await tester.pumpWidget(
Ian Hickson's avatar
Ian Hickson committed
24 25 26 27 28 29 30 31 32
      new ClipPath(
        clipper: new PathClipper(),
        child: new GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () { log.add('tap'); },
          child: new Container()
        )
      )
    );
33
    expect(log, equals(<String>['getClip']));
Ian Hickson's avatar
Ian Hickson committed
34

35
    await tester.tapAt(new Point(10.0, 10.0));
36
    expect(log, equals(<String>['getClip']));
Ian Hickson's avatar
Ian Hickson committed
37 38
    log.clear();

39
    await tester.tapAt(new Point(100.0, 100.0));
40
    expect(log, equals(<String>['tap']));
Ian Hickson's avatar
Ian Hickson committed
41 42 43
    log.clear();
  });

44 45
  testWidgets('ClipOval', (WidgetTester tester) async {
    await tester.pumpWidget(
Ian Hickson's avatar
Ian Hickson committed
46 47 48 49 50 51 52 53
      new ClipOval(
        child: new GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () { log.add('tap'); },
          child: new Container()
        )
      )
    );
54
    expect(log, equals(<String>[]));
Ian Hickson's avatar
Ian Hickson committed
55

56
    await tester.tapAt(new Point(10.0, 10.0));
57
    expect(log, equals(<String>[]));
Ian Hickson's avatar
Ian Hickson committed
58 59
    log.clear();

60
    await tester.tapAt(new Point(400.0, 300.0));
61
    expect(log, equals(<String>['tap']));
Ian Hickson's avatar
Ian Hickson committed
62 63 64
    log.clear();
  });
}