scroll_perf_test.dart 1.63 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_driver/flutter_driver.dart';
6
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
7 8 9 10 11 12 13

void main() {
  group('scrolling performance test', () {
    FlutterDriver driver;

    setUpAll(() async {
      driver = await FlutterDriver.connect();
14

15
      await driver.waitUntilFirstFrameRasterized();
16 17 18 19 20 21 22 23
    });

    tearDownAll(() async {
      if (driver != null)
        driver.close();
    });

    test('measure', () async {
24
      final Timeline timeline = await driver.traceAction(() async {
25
        await driver.tap(find.text('Material'));
26

27
        final SerializableFinder demoList = find.byValueKey('GalleryDemoList');
28

Josh Soref's avatar
Josh Soref committed
29
        // TODO(eseidel): These are very artificial scrolls, we should use better
Eric Seidel's avatar
Eric Seidel committed
30
        // https://github.com/flutter/flutter/issues/3316
31 32
        // Scroll down
        for (int i = 0; i < 5; i++) {
33
          await driver.scroll(demoList, 0.0, -300.0, const Duration(milliseconds: 300));
34
          await Future<void>.delayed(const Duration(milliseconds: 500));
35 36 37 38
        }

        // Scroll up
        for (int i = 0; i < 5; i++) {
39
          await driver.scroll(demoList, 0.0, 300.0, const Duration(milliseconds: 300));
40
          await Future<void>.delayed(const Duration(milliseconds: 500));
41 42 43
        }
      });

44 45 46
      final TimelineSummary summary = TimelineSummary.summarize(timeline);
      await summary.writeSummaryToFile('home_scroll_perf', pretty: true);
      await summary.writeTimelineToFile('home_scroll_perf', pretty: true);
47 48 49
    });
  });
}