gesture_tester.dart 1.12 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
import 'package:quiver/testing/async.dart';
9

10 11
import '../flutter_test_alternative.dart';

12
class TestGestureFlutterBinding extends BindingBase with GestureBinding { }
13

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

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();
  }
}

35
typedef GestureTest = void Function(GestureTester tester);
36

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