pointer_router_test.dart 1.35 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.

Adam Barth's avatar
Adam Barth committed
5
import 'package:flutter_test/flutter_test.dart';
6
import 'package:flutter/gestures.dart';
7 8 9 10 11
import 'package:test/test.dart';

void main() {
  test('Should route pointers', () {
    bool callbackRan = false;
Ian Hickson's avatar
Ian Hickson committed
12
    void callback(PointerEvent event) {
13 14 15
      callbackRan = true;
    }

16 17 18
    TestPointer pointer2 = new TestPointer(2);
    TestPointer pointer3 = new TestPointer(3);

19 20
    PointerRouter router = new PointerRouter();
    router.addRoute(3, callback);
21
    router.route(pointer2.down(Point.origin));
22
    expect(callbackRan, isFalse);
23
    router.route(pointer3.down(Point.origin));
24 25 26
    expect(callbackRan, isTrue);
    callbackRan = false;
    router.removeRoute(3, callback);
27
    router.route(pointer3.up());
28 29
    expect(callbackRan, isFalse);
  });
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

  test('Supports re-entrant cancellation', () {
    bool callbackRan = false;
    void callback(PointerEvent event) {
      callbackRan = true;
    }
    PointerRouter router = new PointerRouter();
    router.addRoute(2, (PointerEvent event) {
      router.removeRoute(2, callback);
    });
    router.addRoute(2, callback);
    TestPointer pointer2 = new TestPointer(2);
    router.route(pointer2.down(Point.origin));
    expect(callbackRan, isFalse);
  });
45
}