scroll_perf_test.dart 1.5 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';
Devon Carew's avatar
Devon Carew committed
6

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

10
void main() {
11 12 13 14 15 16 17 18 19 20 21 22
  group('scrolling performance test', () {
    FlutterDriver driver;

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

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

23
    test('measure', () async {
24
      final Timeline timeline = await driver.traceAction(() async {
25
        // Find the scrollable stock list
26
        final SerializableFinder stockList = find.byValueKey('stock-list');
27 28 29 30
        expect(stockList, isNotNull);

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

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

42
      final TimelineSummary summary = TimelineSummary.summarize(timeline);
43 44
      await summary.writeSummaryToFile('stocks_scroll_perf', pretty: true);
      await summary.writeTimelineToFile('stocks_scroll_perf', pretty: true);
45 46 47
    });
  });
}