blob: 53d79e946b5591780ab9efe4299dcc38940eb74a [file] [log] [blame]
// Copyright 2013 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:async';
import 'package:test/test.dart';
import 'package:ui/ui.dart' as ui;
/// Tests frame timings in a renderer-agnostic way.
/// See CanvasKit-specific and HTML-specific test files `frame_timings_test.dart`.
Future<void> runFrameTimingsTest() async {
List<ui.FrameTiming>? timings;
ui.window.onReportTimings = (List<ui.FrameTiming> data) {
timings = data;
Completer<void> frameDone = Completer<void>();
ui.window.onDrawFrame = () {
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder();
..pushOffset(0, 0)
// Frame 1.
await frameDone.future;
expect(timings, isNull, reason: '100 ms hasn\'t passed yet');
await Future<void>.delayed(const Duration(milliseconds: 150));
// Frame 2.
frameDone = Completer<void>();
await frameDone.future;
expect(timings, hasLength(2), reason: '100 ms passed. 2 frames pumped.');
for (final ui.FrameTiming timing in timings!) {
expect(timing.vsyncOverhead, greaterThanOrEqualTo(;
expect(timing.buildDuration, greaterThanOrEqualTo(;
expect(timing.rasterDuration, greaterThanOrEqualTo(;
expect(timing.totalSpan, greaterThanOrEqualTo(;
expect(timing.layerCacheCount, equals(0));
expect(timing.layerCacheBytes, equals(0));
expect(timing.pictureCacheCount, equals(0));
expect(timing.pictureCacheBytes, equals(0));