animation_test.dart 1.65 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/foundation.dart';
6
import 'package:flutter/scheduler.dart';
7
import 'package:flutter/services.dart';
8 9

import '../flutter_test_alternative.dart';
10

11 12
import 'scheduler_tester.dart';

13
class TestSchedulerBinding extends BindingBase with ServicesBinding, SchedulerBinding { }
Ian Hickson's avatar
Ian Hickson committed
14

15
void main() {
16
  final SchedulerBinding scheduler = TestSchedulerBinding();
Ian Hickson's avatar
Ian Hickson committed
17

18
  test('Check for a time dilation being in effect', () {
19 20 21
    expect(timeDilation, equals(1.0));
  });

22
  test('Can cancel queued callback', () {
23 24 25 26 27
    int secondId;

    bool firstCallbackRan = false;
    bool secondCallbackRan = false;

28
    void firstCallback(Duration timeStamp) {
29 30
      expect(firstCallbackRan, isFalse);
      expect(secondCallbackRan, isFalse);
31
      expect(timeStamp.inMilliseconds, equals(0));
32
      firstCallbackRan = true;
33
      scheduler.cancelFrameCallbackWithId(secondId);
34 35
    }

36
    void secondCallback(Duration timeStamp) {
37 38
      expect(firstCallbackRan, isTrue);
      expect(secondCallbackRan, isFalse);
39
      expect(timeStamp.inMilliseconds, equals(0));
40 41 42
      secondCallbackRan = true;
    }

43 44
    scheduler.scheduleFrameCallback(firstCallback);
    secondId = scheduler.scheduleFrameCallback(secondCallback);
45

46
    tick(const Duration(milliseconds: 16));
47 48 49 50 51 52 53

    expect(firstCallbackRan, isTrue);
    expect(secondCallbackRan, isFalse);

    firstCallbackRan = false;
    secondCallbackRan = false;

54
    tick(const Duration(milliseconds: 32));
55 56 57 58 59

    expect(firstCallbackRan, isFalse);
    expect(secondCallbackRan, isFalse);
  });
}