• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:async';
6
7import 'package:flutter_driver/flutter_driver.dart';
8import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
9
10void macroPerfTest(
11    String testName,
12    String routeName,
13    {Duration pageDelay, Duration duration = const Duration(seconds: 3)}) {
14  test(testName, () async {
15    final FlutterDriver driver = await FlutterDriver.connect();
16
17    // The slight initial delay avoids starting the timing during a
18    // period of increased load on the device. Without this delay, the
19    // benchmark has greater noise.
20    // See: https://github.com/flutter/flutter/issues/19434
21    await Future<void>.delayed(const Duration(milliseconds: 250));
22
23    await driver.forceGC();
24
25    final SerializableFinder button = find.byValueKey(routeName);
26    expect(button, isNotNull);
27    await driver.tap(button);
28
29    if (pageDelay != null) {
30      // Wait for the page to load
31      await Future<void>.delayed(pageDelay);
32    }
33
34    final Timeline timeline = await driver.traceAction(() async {
35      await Future<void>.delayed(duration);
36    });
37
38    final TimelineSummary summary = TimelineSummary.summarize(timeline);
39    summary.writeSummaryToFile(testName, pretty: true);
40    summary.writeTimelineToFile(testName, pretty: true);
41
42    driver.close();
43  });
44}
45