scroll_perf_test.dart 2.24 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 'dart:async';
6

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

void main() {
  group('scrolling performance test', () {
12
    late FlutterDriver driver;
13 14 15

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

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

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

25
    Future<void> testScrollPerf(String listKey, String summaryName) async {
26 27 28 29
      // The slight initial delay avoids starting the timing during a
      // period of increased load on the device. Without this delay, the
      // benchmark has greater noise.
      // See: https://github.com/flutter/flutter/issues/19434
30
      await Future<void>.delayed(const Duration(milliseconds: 250));
31 32 33

      await driver.forceGC();

34
      final Timeline timeline = await driver.traceAction(() async {
35
        // Find the scrollable stock list
36 37
        final SerializableFinder list = find.byValueKey(listKey);
        expect(list, isNotNull);
38 39

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

        // Scroll up
46
        for (int i = 0; i < 5; i += 1) {
47
          await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
48
          await Future<void>.delayed(const Duration(milliseconds: 500));
49 50 51
        }
      });

52
      final TimelineSummary summary = TimelineSummary.summarize(timeline);
53
      await summary.writeTimelineToFile(summaryName, pretty: true);
54 55 56 57
    }

    test('complex_layout_scroll_perf', () async {
      await testScrollPerf('complex-scroll', 'complex_layout_scroll_perf');
58
    }, timeout: Timeout.none);
59 60 61 62 63

    test('tiles_scroll_perf', () async {
      await driver.tap(find.byTooltip('Open navigation menu'));
      await driver.tap(find.byValueKey('scroll-switcher'));
      await testScrollPerf('tiles-scroll', 'tiles_scroll_perf');
64
    }, timeout: Timeout.none);
65 66
  });
}