scroll_perf_test.dart 1.4 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
  group('scrolling performance test', () {
12
    late FlutterDriver driver;
13 14 15 16 17 18

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

    tearDownAll(() async {
19
      driver.close();
20 21
    });

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

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

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

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