|
| 1 | +// Copyright 2020 The Flutter team. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | +import 'package:flutter_test/flutter_test.dart'; |
| 7 | +import 'package:integration_test/integration_test.dart'; |
| 8 | +import 'package:testing_app/main.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + group('Testing App Performance Tests', () { |
| 12 | + final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() |
| 13 | + as IntegrationTestWidgetsFlutterBinding; |
| 14 | + |
| 15 | + // The fullyLive frame policy simulates |
| 16 | + // the way Flutter responds to animations. |
| 17 | + binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive; |
| 18 | + |
| 19 | + testWidgets('Scrolling test', (tester) async { |
| 20 | + await tester.pumpWidget(TestingApp()); |
| 21 | + |
| 22 | + // Create variables for finders that are used multiple times. |
| 23 | + final listFinder = find.byType(ListView); |
| 24 | + final scroller = tester.widget<ListView>(listFinder).controller; |
| 25 | + |
| 26 | + // Record the performance timeline of the following operations. |
| 27 | + await binding.traceAction( |
| 28 | + () async { |
| 29 | + // Record the performance summary as the app scrolls through |
| 30 | + // the list of items. |
| 31 | + await binding.watchPerformance( |
| 32 | + () async { |
| 33 | + // Quickly scroll all the way down. |
| 34 | + await scroller.animateTo( |
| 35 | + 7000, |
| 36 | + duration: const Duration(seconds: 1), |
| 37 | + curve: Curves.linear, |
| 38 | + ); |
| 39 | + await tester.pumpAndSettle(); |
| 40 | + |
| 41 | + // Quickly scroll back up all the way. |
| 42 | + await scroller.animateTo( |
| 43 | + -7000, |
| 44 | + duration: const Duration(seconds: 1), |
| 45 | + curve: Curves.linear, |
| 46 | + ); |
| 47 | + await tester.pumpAndSettle(); |
| 48 | + }, |
| 49 | + // Send the performance summary to the driver. |
| 50 | + reportKey: 'scrolling_summary', |
| 51 | + ); |
| 52 | + }, |
| 53 | + // Send the timeline data to the driver. |
| 54 | + // This timeline can be opened in the Chrome browser's tracing tools |
| 55 | + // by navigating to chrome://tracing. |
| 56 | + reportKey: 'scrolling_timeline', |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + testWidgets('Favorites operations test', (tester) async { |
| 61 | + await tester.pumpWidget(TestingApp()); |
| 62 | + |
| 63 | + // Record the performance timeline of the following operations. |
| 64 | + await binding.traceAction( |
| 65 | + () async { |
| 66 | + // Record the performance summary as operations are performed |
| 67 | + // on the favorites list. |
| 68 | + await binding.watchPerformance( |
| 69 | + () async { |
| 70 | + // Create a list of icon keys. |
| 71 | + final iconKeys = [ |
| 72 | + 'icon_0', |
| 73 | + 'icon_1', |
| 74 | + 'icon_2', |
| 75 | + ]; |
| 76 | + |
| 77 | + // Add first three items to favorites. |
| 78 | + for (var icon in iconKeys) { |
| 79 | + // Tap onto the icon. |
| 80 | + await tester.tap(find.byKey(ValueKey(icon))); |
| 81 | + await tester.pumpAndSettle(); |
| 82 | + |
| 83 | + // Verify if appropriate message appears. |
| 84 | + expect(find.text('Added to favorites.'), findsOneWidget); |
| 85 | + } |
| 86 | + |
| 87 | + // Tap onto the favorites button on the AppBar. |
| 88 | + // The Favorites List should appear. |
| 89 | + await tester.tap(find.text('Favorites')); |
| 90 | + await tester.pumpAndSettle(); |
| 91 | + |
| 92 | + final removeIconKeys = [ |
| 93 | + 'remove_icon_0', |
| 94 | + 'remove_icon_1', |
| 95 | + 'remove_icon_2', |
| 96 | + ]; |
| 97 | + |
| 98 | + // Remove all the items from favorites. |
| 99 | + for (final iconKey in removeIconKeys) { |
| 100 | + // Tap onto the remove icon. |
| 101 | + await tester.tap(find.byKey(ValueKey(iconKey))); |
| 102 | + await tester.pumpAndSettle(); |
| 103 | + |
| 104 | + // Verify if appropriate message appears. |
| 105 | + expect(find.text('Removed from favorites.'), findsOneWidget); |
| 106 | + } |
| 107 | + }, |
| 108 | + // Send the performance summary to the driver. |
| 109 | + reportKey: 'favorites_operations_summary', |
| 110 | + ); |
| 111 | + }, |
| 112 | + // Send the timeline data to the driver. |
| 113 | + // This timeline can be opened in the Chrome browser's tracing tools |
| 114 | + // by navigating to chrome://tracing. |
| 115 | + reportKey: 'favorites_operations_timeline', |
| 116 | + ); |
| 117 | + }); |
| 118 | + }); |
| 119 | +} |
0 commit comments