gesture_tester.dart 1.11 KB
Newer Older
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/foundation.dart';
6
import 'package:flutter/gestures.dart';
7
import 'package:meta/meta.dart';
8 9
import 'package:test/test.dart';
import 'package:quiver/testing/async.dart';
10

11
class TestGestureFlutterBinding extends BindingBase with GestureBinding { }
12

13 14
void ensureGestureBinding() {
  if (GestureBinding.instance == null)
15
    new TestGestureFlutterBinding();
16
  assert(GestureBinding.instance != null);
17
}
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

class GestureTester {
  GestureTester._(this.async);

  final FakeAsync async;

  void closeArena(int pointer) {
    GestureBinding.instance.gestureArena.close(pointer);
  }

  void route(PointerEvent event) {
    GestureBinding.instance.pointerRouter.route(event);
    async.flushMicrotasks();
  }
}

34
typedef void GestureTest(GestureTester tester);
35

36
@isTest
37 38 39 40 41 42 43
void testGesture(String description, GestureTest callback) {
  test(description, () {
    new FakeAsync().run((FakeAsync async) {
      callback(new GestureTester._(async));
    });
  });
}