scroll_perf_test.dart 2.16 KB
Newer Older
1 2 3 4 5
// Copyright 2016 The Chromium 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';
6

7
import 'package:flutter_driver/flutter_driver.dart';
8
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
9 10 11 12 13 14 15 16 17 18 19 20 21 22

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

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

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

23
    Future<void> testScrollPerf(String listKey, String summaryName) async {
24 25 26 27
      // 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
28
      await Future<void>.delayed(const Duration(milliseconds: 250));
29
      final Timeline timeline = await driver.traceAction(() async {
30
        // Find the scrollable stock list
31 32
        final SerializableFinder list = find.byValueKey(listKey);
        expect(list, isNotNull);
33 34

        // Scroll down
35
        for (int i = 0; i < 5; i += 1) {
36
          await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
37
          await Future<void>.delayed(const Duration(milliseconds: 500));
38 39 40
        }

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

47
      final TimelineSummary summary = TimelineSummary.summarize(timeline);
48 49 50 51 52 53 54 55 56 57 58 59
      summary.writeSummaryToFile(summaryName, pretty: true);
      summary.writeTimelineToFile(summaryName, pretty: true);
    }

    test('complex_layout_scroll_perf', () async {
      await testScrollPerf('complex-scroll', 'complex_layout_scroll_perf');
    });

    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');
60 61 62
    });
  });
}