From 237f1ac26389effd54c04c92d6f6d28d47b00672 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Wed, 13 Apr 2016 13:56:25 -0700 Subject: [PATCH] Add a basic scrolling test for the Gallery home page. Current numbers from my Nexus 5: "average_frame_build_time_millis": 22.6854, "missed_frame_build_budget_count": 15, "frame_count": 15 Filed https://github.com/flutter/flutter/issues/3296 @yjbanov @hansmuller @vlidholt --- examples/material_gallery/pubspec.yaml | 2 + .../test_driver/scroll_perf.dart | 11 ++++ .../test_driver/scroll_perf_test.dart | 50 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 examples/material_gallery/test_driver/scroll_perf.dart create mode 100644 examples/material_gallery/test_driver/scroll_perf_test.dart diff --git a/examples/material_gallery/pubspec.yaml b/examples/material_gallery/pubspec.yaml index 38040c26ad..954510c012 100644 --- a/examples/material_gallery/pubspec.yaml +++ b/examples/material_gallery/pubspec.yaml @@ -16,3 +16,5 @@ dev_dependencies: test: any # flutter_test provides the version constraints flutter_test: path: ../../packages/flutter_test + flutter_driver: + path: ../../packages/flutter_driver diff --git a/examples/material_gallery/test_driver/scroll_perf.dart b/examples/material_gallery/test_driver/scroll_perf.dart new file mode 100644 index 0000000000..1b0b033f24 --- /dev/null +++ b/examples/material_gallery/test_driver/scroll_perf.dart @@ -0,0 +1,11 @@ +// 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 'package:flutter_driver/driver_extension.dart'; +import 'package:material_gallery/main.dart' as app; + +void main() { + enableFlutterDriverExtension(); + app.main(); +} diff --git a/examples/material_gallery/test_driver/scroll_perf_test.dart b/examples/material_gallery/test_driver/scroll_perf_test.dart new file mode 100644 index 0000000000..c07b571b00 --- /dev/null +++ b/examples/material_gallery/test_driver/scroll_perf_test.dart @@ -0,0 +1,50 @@ +// 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 { + Timeline timeline = await driver.traceAction(() async { + // Find the scrollable stock list + ObjectRef stockList = await driver.findByValueKey('Gallery List'); + expect(stockList, isNotNull); + + await driver.tap(await driver.findByText('Demos')); + await driver.tap(await driver.findByText('Components')); + await driver.tap(await driver.findByText('Style')); + + // Scroll down + for (int i = 0; i < 5; i++) { + await driver.scroll(stockList, 0.0, -300.0, new Duration(milliseconds: 300)); + await new Future.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.delayed(new Duration(milliseconds: 500)); + } + }); + + TimelineSummary summary = new TimelineSummary.summarize(timeline); + summary.writeSummaryToFile('home_scroll_perf', pretty: true); + summary.writeTimelineToFile('home_scroll_perf', pretty: true); + }); + }); +}