From 6c21e43608dbc53005a7baa2e2e804e7cf4d6cbf Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Wed, 5 Jan 2022 10:05:05 -0800 Subject: [PATCH] stabilize the way we navigate multiple pages for E2E macrobenchmarks (#96157) --- .../macrobenchmarks/lib/common.dart | 1 + .../lib/src/opacity_peephole.dart | 2 +- ...opacity_peephole_col_of_rows_perf_e2e.dart | 7 ++- ...eephole_fade_transition_text_perf_e2e.dart | 7 ++- ...ity_peephole_grid_of_opacity_perf_e2e.dart | 7 ++- .../opacity_peephole_one_rect_perf_e2e.dart | 7 ++- ...ity_peephole_opacity_of_grid_perf_e2e.dart | 7 ++- dev/benchmarks/macrobenchmarks/test/util.dart | 49 +++++++++++++++---- 8 files changed, 67 insertions(+), 20 deletions(-) diff --git a/dev/benchmarks/macrobenchmarks/lib/common.dart b/dev/benchmarks/macrobenchmarks/lib/common.dart index 2adf39b83d..aec0147c68 100644 --- a/dev/benchmarks/macrobenchmarks/lib/common.dart +++ b/dev/benchmarks/macrobenchmarks/lib/common.dart @@ -34,5 +34,6 @@ const String kOpacityPeepholeOpacityOfColOfRowsRouteName = '$kOpacityPeepholeRou const String kOpacityPeepholeFadeTransitionTextRouteName = '$kOpacityPeepholeRouteName/fade_transition_text'; const String kScrollableName = '/macrobenchmark_listview'; +const String kOpacityScrollableName = '$kOpacityPeepholeRouteName/listview'; const String kStackSizeKey = 'stack_size'; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/opacity_peephole.dart b/dev/benchmarks/macrobenchmarks/lib/src/opacity_peephole.dart index 9562849e94..19001375d0 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/opacity_peephole.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/opacity_peephole.dart @@ -17,7 +17,7 @@ class OpacityPeepholePage extends StatelessWidget { return Scaffold( appBar: AppBar(title: const Text('Opacity Peephole tests')), body: ListView( - key: const Key('${kOpacityPeepholeRouteName}_listview'), + key: const Key(kOpacityScrollableName), children: [ for (OpacityPeepholeCase variant in allOpacityPeepholeCases) ElevatedButton( diff --git a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_col_of_rows_perf_e2e.dart b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_col_of_rows_perf_e2e.dart index ded3af7c89..cf9129ef88 100644 --- a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_col_of_rows_perf_e2e.dart +++ b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_col_of_rows_perf_e2e.dart @@ -7,9 +7,12 @@ import 'package:macrobenchmarks/common.dart'; import 'util.dart'; void main() { - macroPerfTestE2E( + macroPerfTestMultiPageE2E( 'opacity_peephole_col_of_rows_perf', - kOpacityPeepholeOpacityOfColOfRowsRouteName, + [ + ScrollableButtonRoute(kScrollableName, kOpacityPeepholeRouteName), + ScrollableButtonRoute(kOpacityScrollableName, kOpacityPeepholeOpacityOfColOfRowsRouteName) + ], pageDelay: const Duration(seconds: 1), duration: const Duration(seconds: 10), ); diff --git a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_fade_transition_text_perf_e2e.dart b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_fade_transition_text_perf_e2e.dart index c7a4b4c241..269cfd1e8b 100644 --- a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_fade_transition_text_perf_e2e.dart +++ b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_fade_transition_text_perf_e2e.dart @@ -7,9 +7,12 @@ import 'package:macrobenchmarks/common.dart'; import 'util.dart'; void main() { - macroPerfTestE2E( + macroPerfTestMultiPageE2E( 'opacity_peephole_fade_transition_text_perf', - kOpacityPeepholeFadeTransitionTextRouteName, + [ + ScrollableButtonRoute(kScrollableName, kOpacityPeepholeRouteName), + ScrollableButtonRoute(kOpacityScrollableName, kOpacityPeepholeFadeTransitionTextRouteName) + ], pageDelay: const Duration(seconds: 1), duration: const Duration(seconds: 10), ); diff --git a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_grid_of_opacity_perf_e2e.dart b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_grid_of_opacity_perf_e2e.dart index f063397c0e..068c21cce6 100644 --- a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_grid_of_opacity_perf_e2e.dart +++ b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_grid_of_opacity_perf_e2e.dart @@ -7,9 +7,12 @@ import 'package:macrobenchmarks/common.dart'; import 'util.dart'; void main() { - macroPerfTestE2E( + macroPerfTestMultiPageE2E( 'opacity_peephole_grid_of_opacity_perf', - kOpacityPeepholeGridOfOpacityRouteName, + [ + ScrollableButtonRoute(kScrollableName, kOpacityPeepholeRouteName), + ScrollableButtonRoute(kOpacityScrollableName, kOpacityPeepholeGridOfOpacityRouteName) + ], pageDelay: const Duration(seconds: 1), duration: const Duration(seconds: 10), ); diff --git a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_one_rect_perf_e2e.dart b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_one_rect_perf_e2e.dart index 4a64d9eb21..63313da618 100644 --- a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_one_rect_perf_e2e.dart +++ b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_one_rect_perf_e2e.dart @@ -7,9 +7,12 @@ import 'package:macrobenchmarks/common.dart'; import 'util.dart'; void main() { - macroPerfTestE2E( + macroPerfTestMultiPageE2E( 'opacity_peephole_one_rect_perf', - kOpacityPeepholeOneRectRouteName, + [ + ScrollableButtonRoute(kScrollableName, kOpacityPeepholeRouteName), + ScrollableButtonRoute(kOpacityScrollableName, kOpacityPeepholeOneRectRouteName) + ], pageDelay: const Duration(seconds: 1), duration: const Duration(seconds: 10), ); diff --git a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_opacity_of_grid_perf_e2e.dart b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_opacity_of_grid_perf_e2e.dart index 3b19343b72..ca6082830b 100644 --- a/dev/benchmarks/macrobenchmarks/test/opacity_peephole_opacity_of_grid_perf_e2e.dart +++ b/dev/benchmarks/macrobenchmarks/test/opacity_peephole_opacity_of_grid_perf_e2e.dart @@ -7,9 +7,12 @@ import 'package:macrobenchmarks/common.dart'; import 'util.dart'; void main() { - macroPerfTestE2E( + macroPerfTestMultiPageE2E( 'opacity_peephole_opacity_of_grid_perf', - kOpacityPeepholeOpacityOfGridRouteName, + [ + ScrollableButtonRoute(kScrollableName, kOpacityPeepholeRouteName), + ScrollableButtonRoute(kOpacityScrollableName, kOpacityPeepholeOpacityOfGridRouteName) + ], pageDelay: const Duration(seconds: 1), duration: const Duration(seconds: 10), ); diff --git a/dev/benchmarks/macrobenchmarks/test/util.dart b/dev/benchmarks/macrobenchmarks/test/util.dart index 64fd7303d7..015da80449 100644 --- a/dev/benchmarks/macrobenchmarks/test/util.dart +++ b/dev/benchmarks/macrobenchmarks/test/util.dart @@ -5,10 +5,18 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; +import 'package:macrobenchmarks/common.dart'; import 'package:macrobenchmarks/main.dart' as app; typedef ControlCallback = Future Function(WidgetController controller); +class ScrollableButtonRoute { + ScrollableButtonRoute(this.listViewKey, this.buttonKey); + + final String listViewKey; + final String buttonKey; +} + void macroPerfTestE2E( String testName, String routeName, { @@ -17,6 +25,19 @@ void macroPerfTestE2E( ControlCallback? body, ControlCallback? setup, }) { + macroPerfTestMultiPageE2E(testName, [ + ScrollableButtonRoute(kScrollableName, routeName), + ]); +} + +void macroPerfTestMultiPageE2E( + String testName, + List routes, { + Duration? pageDelay, + Duration duration = const Duration(seconds: 3), + ControlCallback? body, + ControlCallback? setup, + }) { final WidgetsBinding _binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); assert(_binding is IntegrationTestWidgetsFlutterBinding); final IntegrationTestWidgetsFlutterBinding binding = _binding as IntegrationTestWidgetsFlutterBinding; @@ -33,16 +54,26 @@ void macroPerfTestE2E( // See: https://github.com/flutter/flutter/issues/19434 await tester.binding.delayed(const Duration(microseconds: 250)); - expect(routeName, startsWith('/')); - int i = 0; - while (i < routeName.length) { - i = routeName.indexOf('/', i + 1); - if (i < 0) { - i = routeName.length; - } - final Finder button = find.byKey(ValueKey(routeName.substring(0, i)), skipOffstage: false); - await tester.scrollUntilVisible(button, 50); + for (final ScrollableButtonRoute route in routes) { + expect(route.listViewKey, startsWith('/')); + expect(route.buttonKey, startsWith('/')); + + // Make sure each list view page is settled + await tester.pumpAndSettle(); + + final Finder listView = find.byKey(ValueKey(route.listViewKey)); + // ListView is not a Scrollable, but it contains one + final Finder scrollable = find.descendant(of: listView, matching: find.byType(Scrollable)); + // scrollable should find one widget as soon as the page is loaded + expect(scrollable, findsOneWidget); + + final Finder button = find.byKey(ValueKey(route.buttonKey), skipOffstage: false); + // button may or may not find a widget right away until we scroll to it + await tester.scrollUntilVisible(button, 50, scrollable: scrollable); + // After scrolling, button should find one Widget expect(button, findsOneWidget); + + // Allow scrolling to settle await tester.pumpAndSettle(); await tester.tap(button); // Cannot be pumpAndSettle because some tests have infinite animation.