New Gallery UI reprise (#17031)

This commit is contained in:
Hans Muller
2018-04-27 08:11:20 -07:00
committed by GitHub
parent 4033937c89
commit bf3bd7667f
38 changed files with 2094 additions and 1253 deletions

View File

@@ -14,87 +14,82 @@ void main() {
testWidgets('Flutter Gallery drawer item test', (WidgetTester tester) async {
bool hasFeedback = false;
void mockOnSendFeedback() {
hasFeedback = true;
}
await tester.pumpWidget(new GalleryApp(onSendFeedback: mockOnSendFeedback));
await tester.pumpWidget(
new GalleryApp(
onSendFeedback: () {
hasFeedback = true;
},
),
);
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame
final Finder finder = find.byWidgetPredicate((Widget widget) {
return widget is Tooltip && widget.message == 'Open navigation menu';
});
expect(finder, findsOneWidget);
// Open drawer
await tester.tap(finder);
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
// Show the options page
await tester.tap(find.byTooltip('Show options page'));
await tester.pumpAndSettle();
MaterialApp app = find.byType(MaterialApp).evaluate().first.widget;
expect(app.theme.brightness, equals(Brightness.light));
// Change theme
await tester.tap(find.text('Dark'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
// Switch to the dark theme: first switch control
await tester.tap(find.byType(Switch).first);
await tester.pumpAndSettle();
app = find.byType(MaterialApp).evaluate().first.widget;
expect(app.theme.brightness, equals(Brightness.dark));
expect(app.theme.platform, equals(TargetPlatform.android));
// Change platform
await tester.tap(find.text('iOS'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
// Popup the platform menu: second menu button, choose 'Cupertino'
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(1));
await tester.pumpAndSettle();
await tester.tap(find.text('Cupertino').at(1));
await tester.pumpAndSettle();
app = find.byType(MaterialApp).evaluate().first.widget;
expect(app.theme.platform, equals(TargetPlatform.iOS));
// Verify the font scale.
final Size origTextSize = tester.getSize(find.text('Small'));
expect(origTextSize, equals(const Size(176.0, 14.0)));
final Size origTextSize = tester.getSize(find.text('Text size'));
expect(origTextSize, equals(const Size(144.0, 16.0)));
// Switch font scale.
// Popup the text size menu: first menu button, choose 'Small'
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
await tester.pumpAndSettle();
await tester.tap(find.text('Small'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
final Size textSize = tester.getSize(find.text('Small'));
expect(textSize, equals(const Size(176.0, 11.0)));
await tester.pumpAndSettle();
Size textSize = tester.getSize(find.text('Text size'));
expect(textSize, equals(const Size(116.0, 13.0)));
// Set font scale back to default.
// Set font scale back to the default.
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
await tester.pumpAndSettle();
await tester.tap(find.text('System Default'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
final Size newTextSize = tester.getSize(find.text('Small'));
expect(newTextSize, equals(origTextSize));
await tester.pumpAndSettle();
textSize = tester.getSize(find.text('Text size'));
expect(textSize, origTextSize);
// Scroll to the bottom of the menu.
await tester.drag(find.text('Small'), const Offset(0.0, -1000.0));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
// Test slow animations.
expect(timeDilation, equals(1.0));
await tester.tap(find.text('Animate Slowly'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
// Switch to slow animation: third switch control
expect(timeDilation, 1.0);
await tester.tap(find.byType(Switch).at(2));
await tester.pumpAndSettle();
expect(timeDilation, greaterThan(1.0));
// Put back time dilation (so as not to throw off tests after this one).
await tester.tap(find.text('Animate Slowly'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
expect(timeDilation, equals(1.0));
// Restore normal animation: third switch control
await tester.tap(find.byType(Switch).at(2));
await tester.pumpAndSettle();
expect(timeDilation, 1.0);
// Send feedback.
expect(hasFeedback, false);
// Scroll to the end
await tester.drag(find.text('Text size'), const Offset(0.0, -1000.0));
await tester.pumpAndSettle();
await tester.tap(find.text('Send feedback'));
await tester.pump();
await tester.pumpAndSettle();
expect(hasFeedback, true);
// Close drawer
await tester.tap(find.byType(DrawerController));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
// Hide the options page
await tester.tap(find.byTooltip('Show options page'));
await tester.pumpAndSettle();
});
}

View File

@@ -18,25 +18,16 @@ void main() {
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame
// Scroll the Buttons demo into view so that a tap will succeed
final Offset allDemosOrigin = tester.getTopRight(find.text('Vignettes'));
final Finder button = find.text('Buttons');
while (button.evaluate().isEmpty) {
await tester.dragFrom(allDemosOrigin, const Offset(0.0, -200.0));
await tester.pumpAndSettle();
}
Scrollable.ensureVisible(tester.element(find.text('Material')), alignment: 0.5);
await tester.pumpAndSettle();
await tester.tap(find.text('Material'));
await tester.pumpAndSettle();
// Launch the buttons demo and then prove that showing the example
// code dialog does not crash.
await tester.tap(find.text('Buttons'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
await tester.tap(find.text('RAISED'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Show example code'));
await tester.pump(); // start animation

View File

@@ -10,18 +10,15 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_gallery/gallery/app.dart';
import 'package:flutter_gallery/gallery/item.dart';
import 'package:flutter_gallery/gallery/demos.dart';
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
// Reports success or failure to the native code.
const MethodChannel _kTestChannel = const MethodChannel('io.flutter.demo.gallery/TestLifecycleListener');
// The titles for all of the Gallery demos.
final List<String> _kAllDemos = kAllGalleryItems.map((GalleryItem item) => item.title).toList();
// We don't want to wait for animations to complete before tapping the
// back button in the demos with these titles.
const List<String> _kUnsynchronizedDemos = const <String>[
const List<String> _kUnsynchronizedDemoTitles = const <String>[
'Progress indicators',
'Activity Indicator',
'Video',
@@ -29,38 +26,45 @@ const List<String> _kUnsynchronizedDemos = const <String>[
// These demos can't be backed out of by tapping a button whose
// tooltip is 'Back'.
const List<String> _kSkippedDemos = const <String>[
const List<String> _kSkippedDemoTitles = const <String>[
'Pull to refresh',
'Progress indicators',
'Activity Indicator',
'Video',
];
Future<Null> main() async {
try {
// Verify that _kUnsynchronizedDemos and _kSkippedDemos identify
// demos that actually exist.
if (!new Set<String>.from(_kAllDemos).containsAll(_kUnsynchronizedDemos))
fail('Unrecognized demo names in _kUnsynchronizedDemos: $_kUnsynchronizedDemos');
if (!new Set<String>.from(_kAllDemos).containsAll(_kSkippedDemos))
fail('Unrecognized demo names in _kSkippedDemos: $_kSkippedDemos');
final List<String> allDemoTitles = kAllGalleryDemos.map((GalleryDemo demo) => demo.title).toList();
if (!new Set<String>.from(allDemoTitles).containsAll(_kUnsynchronizedDemoTitles))
fail('Unrecognized demo titles in _kUnsynchronizedDemosTitles: $_kUnsynchronizedDemoTitles');
if (!new Set<String>.from(allDemoTitles).containsAll(_kSkippedDemoTitles))
fail('Unrecognized demo names in _kSkippedDemoTitles: $_kSkippedDemoTitles');
runApp(const GalleryApp());
final _LiveWidgetController controller = new _LiveWidgetController();
for (String demo in _kAllDemos) {
print('Testing "$demo" demo');
final Finder menuItem = find.text(demo);
await controller.scrollIntoView(menuItem, alignment: 0.5);
for (GalleryDemoCategory category in kAllGalleryDemoCategories) {
await controller.tap(find.text(category.name));
for (GalleryDemo demo in kGalleryCategoryToDemos[category]) {
final Finder demoItem = find.text(demo.title);
await controller.scrollIntoView(demoItem, alignment: 0.5);
if (_kSkippedDemos.contains(demo)) {
print('> skipped $demo');
continue;
}
if (_kSkippedDemoTitles.contains(demo.title)) {
print('> skipped $demo');
continue;
}
for (int i = 0; i < 2; i += 1) {
await controller.tap(menuItem); // Launch the demo
controller.frameSync = !_kUnsynchronizedDemos.contains(demo);
await controller.tap(find.byTooltip('Back'));
controller.frameSync = true;
for (int i = 0; i < 2; i += 1) {
await controller.tap(demoItem); // Launch the demo
controller.frameSync = !_kUnsynchronizedDemoTitles.contains(demo.title);
await controller.tap(find.byTooltip('Back'));
controller.frameSync = true;
}
print('Success');
}
print('Success');
await controller.tap(find.byTooltip('Back'));
}
_kTestChannel.invokeMethod('success');

View File

@@ -17,7 +17,7 @@ void main() {
// The bug only manifests itself when the screen's orientation is portrait
const Center(
child: const SizedBox(
width: 400.0,
width: 450.0,
height: 800.0,
child: const GalleryApp()
)
@@ -26,29 +26,32 @@ void main() {
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame
await tester.tap(find.text('Vignettes'));
await tester.pumpAndSettle();
await tester.tap(find.text('Pesto'));
await tester.pump(); // Launch pesto
await tester.pump(const Duration(seconds: 1)); // transition is complete
await tester.pumpAndSettle();
await tester.tap(find.text('Pesto Bruschetta'));
await tester.pump(); // Launch the recipe page
await tester.pump(const Duration(seconds: 1)); // transition is complete
await tester.pumpAndSettle();
await tester.drag(find.text('Pesto Bruschetta'), const Offset(0.0, -300.0));
await tester.pump();
await tester.pumpAndSettle();
Navigator.pop(find.byType(Scaffold).evaluate().single);
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // transition is complete
await tester.pumpAndSettle();
});
testWidgets('Pesto can be scrolled all the way down', (WidgetTester tester) async {
await tester.pumpWidget(const GalleryApp());
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame
await tester.tap(find.text('Vignettes'));
await tester.pumpAndSettle();
await tester.tap(find.text('Pesto'));
await tester.pump(); // Launch pesto
await tester.pump(const Duration(seconds: 1)); // transition is complete
await tester.pumpAndSettle();
await tester.fling(find.text('Pesto Bruschetta'), const Offset(0.0, -200.0), 10000.0);
await tester.pumpAndSettle(); // start and finish fling

View File

@@ -16,37 +16,29 @@ void main() {
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame
final Finder finder = find.byWidgetPredicate((Widget widget) {
return widget is Tooltip && widget.message == 'Open navigation menu';
});
expect(finder, findsOneWidget);
final Finder showOptionsPageButton = find.byTooltip('Show options page');
// Open drawer
await tester.tap(finder);
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
// Show the options page
await tester.tap(showOptionsPageButton);
await tester.pumpAndSettle();
// Change theme
await tester.tap(find.text('Dark'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
// Switch to the dark theme: the first switch control
await tester.tap(find.byType(Switch).first);
await tester.pumpAndSettle();
// Close drawer
await tester.tap(find.byType(DrawerController));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
// Close the options page
expect(showOptionsPageButton, findsOneWidget);
await tester.tap(showOptionsPageButton);
await tester.pumpAndSettle();
// Open Demos
// Show the vignettes
await tester.tap(find.text('Vignettes'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
await tester.pumpAndSettle();
// Open Flexible space toolbar
// Show the Contact profile demo and scroll it upwards
await tester.tap(find.text('Contact profile'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1)); // end animation
await tester.pumpAndSettle();
// Scroll it up
await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));
await tester.pump(const Duration(milliseconds: 200));
await tester.drag(find.text('(650) 555-1234'), const Offset(0.0, -50.0));

View File

@@ -2,31 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:collection' show LinkedHashSet;
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_gallery/gallery/item.dart' show GalleryItem, kAllGalleryItems;
import 'package:flutter_gallery/gallery/demos.dart';
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
const String kCaption = 'Flutter Gallery';
// This title is visible on the home and demo category pages. It's
// not visible when the demos are running.
const String kGalleryTitle = 'Flutter gallery';
final List<String> demoCategories = new LinkedHashSet<String>.from(
kAllGalleryItems.map<String>((GalleryItem item) => item.category)
).toList();
final List<String> routeNames =
kAllGalleryItems.map((GalleryItem item) => item.routeName).toList();
Finder findGalleryItemByRouteName(WidgetTester tester, String routeName) {
return find.byWidgetPredicate((Widget widget) {
return widget is GalleryItem && widget.routeName == routeName;
});
}
int errors = 0;
// All of the classes printed by debugDump etc, must have toString()
// values approved by verityToStringOutput().
int toStringErrors = 0;
void reportToStringError(String name, String route, int lineNumber, List<String> lines, String message) {
// If you're on line 12, then it has index 11.
@@ -36,7 +26,7 @@ void reportToStringError(String name, String route, int lineNumber, List<String>
final int firstLine = math.max(0, lineNumber - margin);
final int lastLine = math.min(lines.length, lineNumber + margin);
print('$name : $route : line $lineNumber of ${lines.length} : $message; nearby lines were:\n ${lines.sublist(firstLine, lastLine).join("\n ")}');
errors += 1;
toStringErrors += 1;
}
void verifyToStringOutput(String name, String route, String testString) {
@@ -56,22 +46,16 @@ void verifyToStringOutput(String name, String route, String testString) {
}
}
// Start a gallery demo and then go back. This function assumes that the
// we're starting on the home route and that the submenu that contains
// the item for a demo that pushes route 'routeName' is already open.
Future<Null> smokeDemo(WidgetTester tester, String routeName) async {
// Ensure that we're (likely to be) on the home page
final Finder menuItem = findGalleryItemByRouteName(tester, routeName);
expect(menuItem, findsOneWidget);
Future<Null> smokeDemo(WidgetTester tester, GalleryDemo demo) async {
print(demo);
// Don't use pumpUntilNoTransientCallbacks in this function, because some of
// the smoketests have infinitely-running animations (e.g. the progress
// indicators demo).
await tester.tap(menuItem);
await tester.tap(find.text(demo.title));
await tester.pump(); // Launch the demo.
await tester.pump(const Duration(milliseconds: 400)); // Wait until the demo has opened.
expect(find.text(kCaption), findsNothing);
expect(find.text(kGalleryTitle), findsNothing);
// Leave the demo on the screen briefly for manual testing.
await tester.pump(const Duration(milliseconds: 400));
@@ -85,6 +69,7 @@ Future<Null> smokeDemo(WidgetTester tester, String routeName) async {
await tester.pump(const Duration(milliseconds: 400));
// Verify that the dumps are pretty.
final String routeName = demo.routeName;
verifyToStringOutput('debugDumpApp', routeName, WidgetsBinding.instance.renderViewElement.toStringDeep());
verifyToStringOutput('debugDumpRenderTree', routeName, RendererBinding.instance?.renderView?.toStringDeep());
verifyToStringOutput('debugDumpLayerTree', routeName, RendererBinding.instance?.renderView?.debugLayer?.toStringDeep());
@@ -108,74 +93,85 @@ Future<Null> smokeDemo(WidgetTester tester, String routeName) async {
await tester.pump(); // Start the pop "back" operation.
await tester.pump(); // Complete the willPop() Future.
await tester.pump(const Duration(milliseconds: 400)); // Wait until it has finished.
return null;
}
Future<Null> runSmokeTest(WidgetTester tester) async {
bool hasFeedback = false;
void mockOnSendFeedback() {
hasFeedback = true;
}
Future<Null> smokeOptionsPage(WidgetTester tester) async {
final Finder showOptionsPageButton = find.byTooltip('Show options page');
await tester.pumpWidget(new GalleryApp(onSendFeedback: mockOnSendFeedback));
// Show the options page
await tester.tap(showOptionsPageButton);
await tester.pumpAndSettle();
// Switch to the dark theme: first switch control
await tester.tap(find.byType(Switch).first);
await tester.pumpAndSettle();
// Switch back to the light theme: first switch control again
await tester.tap(find.byType(Switch).first);
await tester.pumpAndSettle();
// Popup the text size menu: first menu button, choose 'Small'
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
await tester.pumpAndSettle();
await tester.tap(find.text('Small'));
await tester.pumpAndSettle();
// Popup the text size menu: first menu button, choose 'Normal'
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
await tester.pumpAndSettle();
await tester.tap(find.text('Normal'));
await tester.pumpAndSettle();
// Scroll the 'Send feedback' item into view
await tester.drag(find.text('Normal'), const Offset(0.0, -1000.0));
await tester.pumpAndSettle();
await tester.tap(find.text('Send feedback'));
await tester.pumpAndSettle();
// Close the options page
expect(showOptionsPageButton, findsOneWidget);
await tester.tap(showOptionsPageButton);
await tester.pumpAndSettle();
}
Future<Null> smokeGallery(WidgetTester tester) async {
bool sendFeedbackButtonPressed = false;
await tester.pumpWidget(
new GalleryApp(
onSendFeedback: () {
sendFeedbackButtonPressed = true; // see smokeOptionsPage()
},
),
);
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame
expect(find.text(kCaption), findsOneWidget);
expect(find.text(kGalleryTitle), findsOneWidget);
for (String routeName in routeNames) {
final Finder finder = findGalleryItemByRouteName(tester, routeName);
Scrollable.ensureVisible(tester.element(finder), alignment: 0.5);
for (GalleryDemoCategory category in kAllGalleryDemoCategories) {
await tester.tap(find.text(category.name));
await tester.pumpAndSettle();
for (GalleryDemo demo in kGalleryCategoryToDemos[category]) {
Scrollable.ensureVisible(tester.element(find.text(demo.title)), alignment: 0.5);
await smokeDemo(tester, demo);
tester.binding.debugAssertNoTransientCallbacks('A transient callback was still active after running $demo');
}
await tester.pageBack();
await tester.pumpAndSettle();
await smokeDemo(tester, routeName);
tester.binding.debugAssertNoTransientCallbacks('A transient callback was still active after leaving route $routeName');
}
expect(errors, 0);
expect(toStringErrors, 0);
final Finder navigationMenuButton = find.byTooltip('Open navigation menu');
expect(navigationMenuButton, findsOneWidget);
await tester.tap(navigationMenuButton);
await tester.pump(); // Start opening drawer.
await tester.pump(const Duration(seconds: 1)); // Wait until it's really opened.
// Switch theme.
await tester.tap(find.text('Dark'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
// Switch theme.
await tester.tap(find.text('Light'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
// Switch font scale.
await tester.tap(find.text('Small'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
// Switch font scale back to default.
await tester.tap(find.text('System Default'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
// Scroll the 'Send feedback' item into view.
await tester.drag(find.text('Small'), const Offset(0.0, -1000.0));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // Wait until it's changed.
// Send feedback.
expect(hasFeedback, false);
await tester.tap(find.text('Send feedback'));
await tester.pump();
expect(hasFeedback, true);
await smokeOptionsPage(tester);
expect(sendFeedbackButtonPressed, true);
}
void main() {
testWidgets('Flutter Gallery app smoke test', runSmokeTest);
testWidgets('Flutter Gallery app smoke test', smokeGallery);
testWidgets('Flutter Gallery app smoke test with semantics', (WidgetTester tester) async {
RendererBinding.instance.setSemanticsEnabled(true);
await runSmokeTest(tester);
await smokeGallery(tester);
RendererBinding.instance.setSemanticsEnabled(false);
});
}

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_gallery/gallery/app.dart';
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
Future<String> mockUpdateUrlFetcher() {
// A real implementation would connect to the network to retrieve this value
@@ -26,8 +26,8 @@ void main() {
await tester.tap(find.text('NO THANKS'));
await tester.pump();
await tester.tap(find.text('Shrine'));
await tester.pump(); // Launch shrine
await tester.tap(find.text('Vignettes'));
await tester.pump(); // Launch
await tester.pump(const Duration(seconds: 1)); // transition is complete
final Finder backButton = find.byTooltip('Back');