binding_first_frame_rasterized_test.dart 1.11 KB
Newer Older
1 2 3 4 5 6
// Copyright 2014 The Flutter 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 'dart:ui';

7
import 'package:fake_async/fake_async.dart';
8 9 10 11 12 13 14 15 16 17 18 19 20 21
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('Deferred frames will trigger the first frame callback', () {
    FakeAsync().run((FakeAsync fakeAsync) {
      final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
      binding.deferFirstFrame();

      runApp(const Placeholder());
      fakeAsync.flushTimers();

      // Simulates the engine completing a frame render to trigger the
      // appropriate callback setting [WidgetBinding.firstFrameRasterized].
22
      binding.platformDispatcher.onReportTimings!(<FrameTiming>[]);
23 24 25 26 27 28
      expect(binding.firstFrameRasterized, isFalse);

      binding.allowFirstFrame();
      fakeAsync.flushTimers();

      // Simulates the engine again.
29
      binding.platformDispatcher.onReportTimings!(<FrameTiming>[]);
30 31 32 33
      expect(binding.firstFrameRasterized, isTrue);
    });
  });
}