scroll_perf_test.dart 1.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// 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';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

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

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

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

22
    Future<Null> testScrollPerf(String listKey, String summaryName) async {
23
      final Timeline timeline = await driver.traceAction(() async {
24
        // Find the scrollable stock list
25 26
        final SerializableFinder list = find.byValueKey(listKey);
        expect(list, isNotNull);
27 28 29

        // Scroll down
        for (int i = 0; i < 5; i++) {
30
          await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
31
          await new Future<Null>.delayed(const Duration(milliseconds: 500));
32 33 34 35
        }

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

41
      final TimelineSummary summary = new TimelineSummary.summarize(timeline);
42 43 44 45 46 47 48 49 50 51 52 53
      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');
54 55 56
    });
  });
}