scroll_perf_test.dart 1.68 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 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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();
    });

    test('measure', () async {
      Timeline timeline = await driver.traceAction(() async {
        // Find the scrollable stock list
26
        SerializableFinder stockList = find.byValueKey('Gallery List');
27 28
        expect(stockList, isNotNull);

29 30 31
        await driver.tap(find.text('Demos'));
        await driver.tap(find.text('Components'));
        await driver.tap(find.text('Style'));
32

Eric Seidel's avatar
Eric Seidel committed
33 34
        // TODO(eseidel): These are very artifical scrolls, we should use better
        // https://github.com/flutter/flutter/issues/3316
35 36 37 38 39 40 41 42 43 44 45 46 47
        // Scroll down
        for (int i = 0; i < 5; i++) {
          await driver.scroll(stockList, 0.0, -300.0, new Duration(milliseconds: 300));
          await new Future<Null>.delayed(new Duration(milliseconds: 500));
        }

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

Eric Seidel's avatar
Eric Seidel committed
48 49 50
      new TimelineSummary.summarize(timeline)
        ..writeSummaryToFile('home_scroll_perf', pretty: true)
        ..writeTimelineToFile('home_scroll_perf', pretty: true);
51 52 53
    });
  });
}