scroll_perf_test.dart 1.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
// 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();
    });

    test('measure', () async {
23
      Timeline timeline = await driver.traceAction(() async {
24
        // Find the scrollable stock list
25
        SerializableFinder stockList = find.byValueKey('main-scroll');
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
        expect(stockList, isNotNull);

        // 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));
        }
      });

41 42 43
      TimelineSummary summary = new TimelineSummary.summarize(timeline);
      summary.writeSummaryToFile('complex_layout_scroll_perf', pretty: true);
      summary.writeTimelineToFile('complex_layout_scroll_perf', pretty: true);
44 45 46
    });
  });
}