Migrate gallery/transitions_perf test to e2e (#62064)
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package io.flutter.demo.gallery;
|
||||
|
||||
import android.support.test.filters.LargeTest;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class FlutterGalleryInstrumentationTest {
|
||||
@Rule
|
||||
public ActivityTestRule<MainActivity> mActivityRule =
|
||||
new ActivityTestRule<>(MainActivity.class);
|
||||
|
||||
private MainActivity activity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
activity = mActivityRule.getActivity();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void activityLoaded() throws Exception {
|
||||
FlutterGalleryInstrumentation instrumentation = activity.getInstrumentation();
|
||||
instrumentation.waitForTestToFinish();
|
||||
assertThat(instrumentation.isTestSuccessful(), is(true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package io.flutter.demo.gallery;
|
||||
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import dev.flutter.plugins.e2e.FlutterTestRunner;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(FlutterTestRunner.class)
|
||||
public class MainActivityTest {
|
||||
@Rule
|
||||
public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, true, false);
|
||||
}
|
||||
43
dev/integration_tests/flutter_gallery/lib/demo_lists.dart
Normal file
43
dev/integration_tests/flutter_gallery/lib/demo_lists.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Demos for which timeline data will be collected using
|
||||
// FlutterDriver.traceAction().
|
||||
//
|
||||
// Warning: The number of tests executed with timeline collection enabled
|
||||
// significantly impacts heap size of the running app. When run with
|
||||
// --trace-startup, as we do in this test, the VM stores trace events in an
|
||||
// endless buffer instead of a ring buffer.
|
||||
//
|
||||
// These names must match GalleryItem titles from kAllGalleryDemos
|
||||
// in dev/integration_tests/flutter_gallery/lib/gallery/demos.dart
|
||||
const List<String> kProfiledDemos = <String>[
|
||||
'Shrine@Studies',
|
||||
'Contact profile@Studies',
|
||||
'Animation@Studies',
|
||||
'Bottom navigation@Material',
|
||||
'Buttons@Material',
|
||||
'Cards@Material',
|
||||
'Chips@Material',
|
||||
'Dialogs@Material',
|
||||
'Pickers@Material',
|
||||
];
|
||||
|
||||
// There are 3 places where the Gallery demos are traversed.
|
||||
// 1- In widget tests such as dev/integration_tests/flutter_gallery/test/smoke_test.dart
|
||||
// 2- In driver tests such as dev/integration_tests/flutter_gallery/test_driver/transitions_perf_test.dart
|
||||
// 3- In on-device instrumentation tests such as dev/integration_tests/flutter_gallery/test/live_smoketest.dart
|
||||
//
|
||||
// If you change navigation behavior in the Gallery or in the framework, make
|
||||
// sure all 3 are covered.
|
||||
|
||||
// Demos that will be backed out of within FlutterDriver.runUnsynchronized();
|
||||
//
|
||||
// These names must match GalleryItem titles from kAllGalleryDemos
|
||||
// in dev/integration_tests/flutter_gallery/lib/gallery/demos.dart
|
||||
const List<String> kUnsynchronizedDemos = <String>[
|
||||
'Progress indicators@Material',
|
||||
'Activity Indicator@Cupertino',
|
||||
'Video@Media',
|
||||
];
|
||||
@@ -51,6 +51,7 @@ dev_dependencies:
|
||||
flutter_goldens:
|
||||
sdk: flutter
|
||||
test: 1.16.0-nullsafety.1
|
||||
e2e: 0.7.0
|
||||
|
||||
_fe_analyzer_shared: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
analyzer: 0.39.17 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@@ -275,4 +276,4 @@ flutter:
|
||||
- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Regular.ttf
|
||||
- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Light.ttf
|
||||
|
||||
# PUBSPEC CHECKSUM: 6b77
|
||||
# PUBSPEC CHECKSUM: 7fc2
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2014 The Flutter 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 'dart:ui';
|
||||
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:e2e/e2e.dart';
|
||||
|
||||
bool _firstRun = true;
|
||||
|
||||
// TODO(CareF): move this to e2e after FrameTimingSummarizer goes into stable
|
||||
// branch (#63537)
|
||||
/// watches the [FrameTiming] of `action` and report it to the e2e binding.
|
||||
Future<void> watchPerformance(
|
||||
E2EWidgetsFlutterBinding binding,
|
||||
Future<void> action(), {
|
||||
String reportKey = 'performance',
|
||||
}) async {
|
||||
assert(() {
|
||||
if (_firstRun) {
|
||||
debugPrint(kDebugWarning);
|
||||
_firstRun = false;
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
final List<FrameTiming> frameTimings = <FrameTiming>[];
|
||||
final TimingsCallback watcher = frameTimings.addAll;
|
||||
binding.addTimingsCallback(watcher);
|
||||
await action();
|
||||
binding.removeTimingsCallback(watcher);
|
||||
final FrameTimingSummarizer frameTimes = FrameTimingSummarizer(frameTimings);
|
||||
binding.reportData = <String, dynamic>{reportKey: frameTimes.summary};
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// Copyright 2014 The Flutter 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 'dart:ui';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:e2e/e2e.dart';
|
||||
|
||||
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
|
||||
import 'package:flutter_gallery/gallery/demos.dart';
|
||||
import 'package:flutter_gallery/demo_lists.dart';
|
||||
|
||||
import 'e2e_utils.dart';
|
||||
|
||||
const List<String> kSkippedDemos = <String>[];
|
||||
|
||||
// All of the gallery demos, identified as "title@category".
|
||||
//
|
||||
// These names are reported by the test app, see _handleMessages()
|
||||
// in transitions_perf.dart.
|
||||
List<String> _allDemos = kAllGalleryDemos.map(
|
||||
(GalleryDemo demo) => '${demo.title}@${demo.category.name}',
|
||||
).toList();
|
||||
|
||||
/// Scrolls each demo menu item into view, launches it, then returns to the
|
||||
/// home screen twice.
|
||||
Future<void> runDemos(List<String> demos, WidgetController controller) async {
|
||||
final Finder demoList = find.byType(Scrollable);
|
||||
String currentDemoCategory;
|
||||
|
||||
for (final String demo in demos) {
|
||||
if (kSkippedDemos.contains(demo))
|
||||
continue;
|
||||
|
||||
final String demoName = demo.substring(0, demo.indexOf('@'));
|
||||
final String demoCategory = demo.substring(demo.indexOf('@') + 1);
|
||||
print('> $demo');
|
||||
await controller.pump(const Duration(milliseconds: 250));
|
||||
|
||||
if (currentDemoCategory == null) {
|
||||
await controller.tap(find.text(demoCategory));
|
||||
await controller.pumpAndSettle();
|
||||
} else if (currentDemoCategory != demoCategory) {
|
||||
await controller.tap(find.byTooltip('Back'));
|
||||
await controller.pumpAndSettle();
|
||||
await controller.tap(find.text(demoCategory));
|
||||
await controller.pumpAndSettle();
|
||||
// Scroll back to the top
|
||||
await controller.drag(demoList, const Offset(0.0, 10000.0));
|
||||
await controller.pumpAndSettle(const Duration(milliseconds: 100));
|
||||
}
|
||||
currentDemoCategory = demoCategory;
|
||||
|
||||
final Finder demoItem = find.text(demoName);
|
||||
await controller.scrollUntilVisible(demoItem, 48.0);
|
||||
await controller.pumpAndSettle();
|
||||
|
||||
Future<void> pageBack() {
|
||||
Finder backButton = find.byTooltip('Back');
|
||||
if (backButton.evaluate().isEmpty) {
|
||||
backButton = find.byType(CupertinoNavigationBarBackButton);
|
||||
}
|
||||
return controller.tap(backButton);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i += 1) {
|
||||
await controller.tap(demoItem); // Launch the demo
|
||||
|
||||
if (kUnsynchronizedDemos.contains(demo)) {
|
||||
// These tests have animation, pumpAndSettle cannot be used.
|
||||
// This time is questionable. 300ms is the tested reasonable result.
|
||||
await controller.pump(const Duration(milliseconds: 300));
|
||||
await controller.pump();
|
||||
await pageBack();
|
||||
} else {
|
||||
await controller.pumpAndSettle();
|
||||
// page back
|
||||
await pageBack();
|
||||
}
|
||||
await controller.pumpAndSettle();
|
||||
}
|
||||
|
||||
print('< Success');
|
||||
}
|
||||
|
||||
// Return to the home screen
|
||||
await controller.tap(find.byTooltip('Back'));
|
||||
await controller.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main([List<String> args = const <String>[]]) {
|
||||
final bool withSemantics = args.contains('--with_semantics');
|
||||
final E2EWidgetsFlutterBinding binding =
|
||||
E2EWidgetsFlutterBinding.ensureInitialized() as E2EWidgetsFlutterBinding;
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
||||
group('flutter gallery transitions on e2e', () {
|
||||
testWidgets('find.bySemanticsLabel', (WidgetTester tester) async {
|
||||
runApp(const GalleryApp(testMode: true));
|
||||
await tester.pumpAndSettle();
|
||||
final int id = tester.getSemantics(find.bySemanticsLabel('Material')).id;
|
||||
expect(id, greaterThan(-1));
|
||||
}, skip: !withSemantics, semanticsEnabled: true);
|
||||
|
||||
testWidgets(
|
||||
'all demos',
|
||||
(WidgetTester tester) async {
|
||||
runApp(const GalleryApp(testMode: true));
|
||||
await tester.pumpAndSettle();
|
||||
// Collect timeline data for just a limited set of demos to avoid OOMs.
|
||||
await watchPerformance(binding, () async {
|
||||
await runDemos(kProfiledDemos, tester);
|
||||
});
|
||||
|
||||
// Execute the remaining tests.
|
||||
final Set<String> unprofiledDemos = Set<String>.from(_allDemos)
|
||||
..removeAll(kProfiledDemos);
|
||||
await runDemos(unprofiledDemos.toList(), tester);
|
||||
},
|
||||
timeout: const Timeout(Duration(minutes: 5)),
|
||||
semanticsEnabled: withSemantics,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2014 The Flutter 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:e2e/e2e_driver.dart' as driver;
|
||||
|
||||
Future<void> main() => driver.e2eDriver(
|
||||
timeout: const Duration(minutes: 5),
|
||||
responseDataCallback: (Map<String, dynamic> data) async {
|
||||
await driver.writeResponseData(
|
||||
data['performance'] as Map<String, dynamic>,
|
||||
testOutputFilename: 'e2e_perf_summary',
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright 2014 The Flutter 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 'transitions_perf_e2e.dart' as transitions_perf;
|
||||
|
||||
void main() {
|
||||
transitions_perf.main(<String>['--with_semantics']);
|
||||
}
|
||||
@@ -11,48 +11,10 @@ import 'package:flutter_driver/flutter_driver.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
|
||||
import 'package:flutter_gallery/demo_lists.dart';
|
||||
|
||||
const FileSystem _fs = LocalFileSystem();
|
||||
|
||||
// Demos for which timeline data will be collected using
|
||||
// FlutterDriver.traceAction().
|
||||
//
|
||||
// Warning: The number of tests executed with timeline collection enabled
|
||||
// significantly impacts heap size of the running app. When run with
|
||||
// --trace-startup, as we do in this test, the VM stores trace events in an
|
||||
// endless buffer instead of a ring buffer.
|
||||
//
|
||||
// These names must match GalleryItem titles from kAllGalleryDemos
|
||||
// in dev/integration_tests/flutter_gallery/lib/gallery/demos.dart
|
||||
const List<String> kProfiledDemos = <String>[
|
||||
'Shrine@Studies',
|
||||
'Contact profile@Studies',
|
||||
'Animation@Studies',
|
||||
'Bottom navigation@Material',
|
||||
'Buttons@Material',
|
||||
'Cards@Material',
|
||||
'Chips@Material',
|
||||
'Dialogs@Material',
|
||||
'Pickers@Material',
|
||||
];
|
||||
|
||||
// There are 3 places where the Gallery demos are traversed.
|
||||
// 1- In widget tests such as dev/integration_tests/flutter_gallery/test/smoke_test.dart
|
||||
// 2- In driver tests such as dev/integration_tests/flutter_gallery/test_driver/transitions_perf_test.dart
|
||||
// 3- In on-device instrumentation tests such as dev/integration_tests/flutter_gallery/test/live_smoketest.dart
|
||||
//
|
||||
// If you change navigation behavior in the Gallery or in the framework, make
|
||||
// sure all 3 are covered.
|
||||
|
||||
// Demos that will be backed out of within FlutterDriver.runUnsynchronized();
|
||||
//
|
||||
// These names must match GalleryItem titles from kAllGalleryDemos
|
||||
// in dev/integration_tests/flutter_gallery/lib/gallery/demos.dart
|
||||
const List<String> kUnsynchronizedDemos = <String>[
|
||||
'Progress indicators@Material',
|
||||
'Activity Indicator@Cupertino',
|
||||
'Video@Media',
|
||||
];
|
||||
|
||||
const List<String> kSkippedDemos = <String>[];
|
||||
|
||||
// All of the gallery demos, identified as "title@category".
|
||||
|
||||
Reference in New Issue
Block a user