scroll_perf_test.dart 2.25 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
    });

    tearDownAll(() async {
21
      if (driver != null) {
22
        driver.close();
23
      }
24 25
    });

26
    Future<void> testScrollPerf(String listKey, String summaryName) async {
27 28 29 30
      // 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
31
      await Future<void>.delayed(const Duration(milliseconds: 250));
32 33 34

      await driver.forceGC();

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

        // Scroll down
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
        }

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

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

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

    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');
65
    }, timeout: Timeout.none);
66 67
  });
}