Unverified Commit 3dbe90e1 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Add TargetPlatform.macOS tests to the material library (#48996)

This contains the test changes for adding TargetPlatform.macOS, which was done in #43457.

The main goal of this PR is to enable tests in the material library that are currently running only on iOS to also run on macOS, but only for the tests where that makes sense. For instance, we don't run any of the haptic feedback tests on macOS.
parent e8222aaf
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -83,66 +84,68 @@ void main() { ...@@ -83,66 +84,68 @@ void main() {
Size size = tester.getSize(title); Size size = tester.getSize(title);
expect(center.dx, lessThan(400 - size.width / 2.0)); expect(center.dx, lessThan(400 - size.width / 2.0));
// Clear the widget tree to avoid animating between Android and iOS. for (final TargetPlatform platform in <TargetPlatform>[TargetPlatform.iOS, TargetPlatform.macOS]) {
await tester.pumpWidget(Container(key: UniqueKey())); // Clear the widget tree to avoid animating between platforms.
await tester.pumpWidget(Container(key: UniqueKey()));
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), theme: ThemeData(platform: platform),
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('X'), title: const Text('X'),
),
), ),
), ),
), );
);
center = tester.getCenter(title); center = tester.getCenter(title);
size = tester.getSize(title); size = tester.getSize(title);
expect(center.dx, greaterThan(400 - size.width / 2.0)); expect(center.dx, greaterThan(400 - size.width / 2.0), reason: 'on ${describeEnum(platform)}');
expect(center.dx, lessThan(400 + size.width / 2.0)); expect(center.dx, lessThan(400 + size.width / 2.0), reason: 'on ${describeEnum(platform)}');
// One action is still centered. // One action is still centered.
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), theme: ThemeData(platform: platform),
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('X'), title: const Text('X'),
actions: const <Widget>[ actions: const <Widget>[
Icon(Icons.thumb_up), Icon(Icons.thumb_up),
], ],
),
), ),
), ),
), );
);
center = tester.getCenter(title); center = tester.getCenter(title);
size = tester.getSize(title); size = tester.getSize(title);
expect(center.dx, greaterThan(400 - size.width / 2.0)); expect(center.dx, greaterThan(400 - size.width / 2.0), reason: 'on ${describeEnum(platform)}');
expect(center.dx, lessThan(400 + size.width / 2.0)); expect(center.dx, lessThan(400 + size.width / 2.0), reason: 'on ${describeEnum(platform)}');
// Two actions is left aligned again. // Two actions is left aligned again.
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), theme: ThemeData(platform: platform),
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('X'), title: const Text('X'),
actions: const <Widget>[ actions: const <Widget>[
Icon(Icons.thumb_up), Icon(Icons.thumb_up),
Icon(Icons.thumb_up), Icon(Icons.thumb_up),
], ],
),
), ),
), ),
), );
);
center = tester.getCenter(title); center = tester.getCenter(title);
size = tester.getSize(title); size = tester.getSize(title);
expect(center.dx, lessThan(400 - size.width / 2.0)); expect(center.dx, lessThan(400 - size.width / 2.0), reason: 'on ${describeEnum(platform)}');
}
}); });
testWidgets('AppBar centerTitle:true centers on Android', (WidgetTester tester) async { testWidgets('AppBar centerTitle:true centers on Android', (WidgetTester tester) async {
......
...@@ -66,30 +66,37 @@ void main() { ...@@ -66,30 +66,37 @@ void main() {
}); });
testWidgets('BackButton icon', (WidgetTester tester) async { testWidgets('BackButton icon', (WidgetTester tester) async {
final Key iOSKey = UniqueKey();
final Key androidKey = UniqueKey(); final Key androidKey = UniqueKey();
final Key iOSKey = UniqueKey();
final Key macOSKey = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Column( home: Column(
children: <Widget>[ children: <Widget>[
Theme(
data: ThemeData(platform: TargetPlatform.android),
child: BackButtonIcon(key: androidKey),
),
Theme( Theme(
data: ThemeData(platform: TargetPlatform.iOS), data: ThemeData(platform: TargetPlatform.iOS),
child: BackButtonIcon(key: iOSKey), child: BackButtonIcon(key: iOSKey),
), ),
Theme( Theme(
data: ThemeData(platform: TargetPlatform.android), data: ThemeData(platform: TargetPlatform.macOS),
child: BackButtonIcon(key: androidKey), child: BackButtonIcon(key: macOSKey),
), ),
], ],
), ),
), ),
); );
final Icon iOSIcon = tester.widget(find.descendant(of: find.byKey(iOSKey), matching: find.byType(Icon)));
final Icon androidIcon = tester.widget(find.descendant(of: find.byKey(androidKey), matching: find.byType(Icon))); final Icon androidIcon = tester.widget(find.descendant(of: find.byKey(androidKey), matching: find.byType(Icon)));
expect(iOSIcon == androidIcon, false); final Icon iOSIcon = tester.widget(find.descendant(of: find.byKey(iOSKey), matching: find.byType(Icon)));
final Icon macOSIcon = tester.widget(find.descendant(of: find.byKey(macOSKey), matching: find.byType(Icon)));
expect(iOSIcon.icon == androidIcon.icon, isFalse);
expect(macOSIcon.icon == androidIcon.icon, isFalse);
expect(macOSIcon.icon == iOSIcon.icon, isTrue);
}); });
testWidgets('BackButton semantics', (WidgetTester tester) async { testWidgets('BackButton semantics', (WidgetTester tester) async {
......
...@@ -57,9 +57,8 @@ void main() { ...@@ -57,9 +57,8 @@ void main() {
expect(find.text('header'), findsOneWidget); expect(find.text('header'), findsOneWidget);
}); });
testWidgets('Drawer dismiss barrier has label on iOS', (WidgetTester tester) async { testWidgets('Drawer dismiss barrier has label', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Scaffold( home: Scaffold(
...@@ -80,10 +79,9 @@ void main() { ...@@ -80,10 +79,9 @@ void main() {
)); ));
semantics.dispose(); semantics.dispose();
debugDefaultTargetPlatformOverride = null; }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
});
testWidgets('Drawer dismiss barrier has no label on Android', (WidgetTester tester) async { testWidgets('Drawer dismiss barrier has no label', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
...@@ -105,7 +103,7 @@ void main() { ...@@ -105,7 +103,7 @@ void main() {
))); )));
semantics.dispose(); semantics.dispose();
}); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('Scaffold drawerScrimColor', (WidgetTester tester) async { testWidgets('Scaffold drawerScrimColor', (WidgetTester tester) async {
// The scrim is a Container within a Semantics node labeled "Dismiss", // The scrim is a Container within a Semantics node labeled "Dismiss",
......
...@@ -58,7 +58,6 @@ void main() { ...@@ -58,7 +58,6 @@ void main() {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
theme: ThemeData( theme: ThemeData(
platform: TargetPlatform.iOS,
dividerColor: _dividerColor, dividerColor: _dividerColor,
), ),
home: Material( home: Material(
...@@ -154,7 +153,7 @@ void main() { ...@@ -154,7 +153,7 @@ void main() {
expect(collapsedContainerDecoration.color, Colors.transparent); expect(collapsedContainerDecoration.color, Colors.transparent);
expect(collapsedContainerDecoration.border.top.color, _dividerColor); expect(collapsedContainerDecoration.border.top.color, _dividerColor);
expect(collapsedContainerDecoration.border.bottom.color, _dividerColor); expect(collapsedContainerDecoration.border.bottom.color, _dividerColor);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('ListTileTheme', (WidgetTester tester) async { testWidgets('ListTileTheme', (WidgetTester tester) async {
final Key expandedTitleKey = UniqueKey(); final Key expandedTitleKey = UniqueKey();
...@@ -165,7 +164,6 @@ void main() { ...@@ -165,7 +164,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData( theme: ThemeData(
platform: TargetPlatform.iOS,
accentColor: _accentColor, accentColor: _accentColor,
unselectedWidgetColor: _unselectedWidgetColor, unselectedWidgetColor: _unselectedWidgetColor,
textTheme: const TextTheme(subhead: TextStyle(color: _headerColor)), textTheme: const TextTheme(subhead: TextStyle(color: _headerColor)),
...@@ -214,7 +212,7 @@ void main() { ...@@ -214,7 +212,7 @@ void main() {
expect(textColor(collapsedTitleKey), _accentColor); expect(textColor(collapsedTitleKey), _accentColor);
expect(iconColor(expandedIconKey), _unselectedWidgetColor); expect(iconColor(expandedIconKey), _unselectedWidgetColor);
expect(iconColor(collapsedIconKey), _accentColor); expect(iconColor(collapsedIconKey), _accentColor);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('ExpansionTile subtitle', (WidgetTester tester) async { testWidgets('ExpansionTile subtitle', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -10,10 +11,10 @@ const double expandedAppbarHeight = 250.0; ...@@ -10,10 +11,10 @@ const double expandedAppbarHeight = 250.0;
final Key appbarContainerKey = UniqueKey(); final Key appbarContainerKey = UniqueKey();
void main() { void main() {
testWidgets('FlexibleSpaceBar collapse mode none on Android', (WidgetTester tester) async { testWidgets('FlexibleSpaceBar collapse mode none', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.android), theme: ThemeData(platform: debugDefaultTargetPlatformOverride),
home: Scaffold( home: Scaffold(
body: CustomScrollView( body: CustomScrollView(
key: blockKey, key: blockKey,
...@@ -46,88 +47,12 @@ void main() { ...@@ -46,88 +47,12 @@ void main() {
expect(topBeforeScroll.dy, equals(0.0)); expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, equals(0.0)); expect(topAfterScroll.dy, equals(0.0));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('FlexibleSpaceBar collapse mode none on IOS', (WidgetTester tester) async { testWidgets('FlexibleSpaceBar collapse mode pin', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), theme: ThemeData(platform: debugDefaultTargetPlatformOverride),
home: Scaffold(
body: CustomScrollView(
key: blockKey,
slivers: <Widget>[
SliverAppBar(
expandedHeight: expandedAppbarHeight,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
background: Container(
key: appbarContainerKey,
),
collapseMode: CollapseMode.none,
),
),
SliverToBoxAdapter(
child: Container(
height: 10000.0,
),
),
],
),
),
),
);
final Finder appbarContainer = find.byKey(appbarContainerKey);
final Offset topBeforeScroll = tester.getTopLeft(appbarContainer);
await slowDrag(tester, blockKey, const Offset(0.0, -100.0));
final Offset topAfterScroll = tester.getTopLeft(appbarContainer);
expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, equals(0.0));
});
testWidgets('FlexibleSpaceBar collapse mode pin on Android', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(
body: CustomScrollView(
key: blockKey,
slivers: <Widget>[
SliverAppBar(
expandedHeight: expandedAppbarHeight,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
background: Container(
key: appbarContainerKey,
),
collapseMode: CollapseMode.pin,
),
),
SliverToBoxAdapter(
child: Container(
height: 10000.0,
),
),
],
),
),
),
);
final Finder appbarContainer = find.byKey(appbarContainerKey);
final Offset topBeforeScroll = tester.getTopLeft(appbarContainer);
await slowDrag(tester, blockKey, const Offset(0.0, -100.0));
final Offset topAfterScroll = tester.getTopLeft(appbarContainer);
expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, equals(-100.0));
});
testWidgets('FlexibleSpaceBar collapse mode pin on IOS', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Scaffold( home: Scaffold(
body: CustomScrollView( body: CustomScrollView(
key: blockKey, key: blockKey,
...@@ -160,53 +85,12 @@ void main() { ...@@ -160,53 +85,12 @@ void main() {
expect(topBeforeScroll.dy, equals(0.0)); expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, equals(-100.0)); expect(topAfterScroll.dy, equals(-100.0));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('FlexibleSpaceBar collapse mode parallax on Android', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(
body: CustomScrollView(
key: blockKey,
slivers: <Widget>[
SliverAppBar(
expandedHeight: expandedAppbarHeight,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
background: Container(
key: appbarContainerKey,
),
collapseMode: CollapseMode.parallax,
),
),
SliverToBoxAdapter(
child: Container(
height: 10000.0,
),
),
],
),
),
),
);
final Finder appbarContainer = find.byKey(appbarContainerKey);
final Offset topBeforeScroll = tester.getTopLeft(appbarContainer);
await slowDrag(tester, blockKey, const Offset(0.0, -100.0));
final Offset topAfterScroll = tester.getTopLeft(appbarContainer);
expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, lessThan(10.0));
expect(topAfterScroll.dy, greaterThan(-50.0));
});
testWidgets('FlexibleSpaceBar collapse mode parallax on IOS', (WidgetTester tester) async { testWidgets('FlexibleSpaceBar collapse mode parallax', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), theme: ThemeData(platform: debugDefaultTargetPlatformOverride),
home: Scaffold( home: Scaffold(
body: CustomScrollView( body: CustomScrollView(
key: blockKey, key: blockKey,
...@@ -240,7 +124,7 @@ void main() { ...@@ -240,7 +124,7 @@ void main() {
expect(topBeforeScroll.dy, equals(0.0)); expect(topBeforeScroll.dy, equals(0.0));
expect(topAfterScroll.dy, lessThan(10.0)); expect(topAfterScroll.dy, lessThan(10.0));
expect(topAfterScroll.dy, greaterThan(-50.0)); expect(topAfterScroll.dy, greaterThan(-50.0));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS, TargetPlatform.macOS }));
} }
Future<void> slowDrag(WidgetTester tester, Key widget, Offset offset) async { Future<void> slowDrag(WidgetTester tester, Key widget, Offset offset) async {
......
...@@ -25,26 +25,28 @@ void main() { ...@@ -25,26 +25,28 @@ void main() {
Size size = tester.getSize(title); Size size = tester.getSize(title);
expect(center.dx, lessThan(400.0 - size.width / 2.0)); expect(center.dx, lessThan(400.0 - size.width / 2.0));
// Clear the widget tree to avoid animating between Android and iOS. for (final TargetPlatform platform in <TargetPlatform>[ TargetPlatform.iOS, TargetPlatform.macOS ]) {
await tester.pumpWidget(Container(key: UniqueKey())); // Clear the widget tree to avoid animating between platforms.
await tester.pumpWidget(Container(key: UniqueKey()));
await tester.pumpWidget(
MaterialApp( await tester.pumpWidget(
theme: ThemeData(platform: TargetPlatform.iOS), MaterialApp(
home: Scaffold( theme: ThemeData(platform: platform),
appBar: AppBar( home: Scaffold(
flexibleSpace: const FlexibleSpaceBar( appBar: AppBar(
title: Text('X'), flexibleSpace: const FlexibleSpaceBar(
title: Text('X'),
),
), ),
), ),
), ),
), );
);
center = tester.getCenter(title); center = tester.getCenter(title);
size = tester.getSize(title); size = tester.getSize(title);
expect(center.dx, greaterThan(400.0 - size.width / 2.0)); expect(center.dx, greaterThan(400.0 - size.width / 2.0));
expect(center.dx, lessThan(400.0 + size.width / 2.0)); expect(center.dx, lessThan(400.0 + size.width / 2.0));
}
}); });
testWidgets('FlexibleSpaceBarSettings provides settings to a FlexibleSpaceBar', (WidgetTester tester) async { testWidgets('FlexibleSpaceBarSettings provides settings to a FlexibleSpaceBar', (WidgetTester tester) async {
...@@ -154,6 +156,15 @@ void main() { ...@@ -154,6 +156,15 @@ void main() {
await tester.pumpWidget(buildFrame(TargetPlatform.iOS, false)); await tester.pumpWidget(buildFrame(TargetPlatform.iOS, false));
expect(getTitleBottomLeft(), const Offset(72.0, 16.0)); expect(getTitleBottomLeft(), const Offset(72.0, 16.0));
// Clear the widget tree to avoid animating between iOS and macOS.
await tester.pumpWidget(Container(key: UniqueKey()));
await tester.pumpWidget(buildFrame(TargetPlatform.macOS, null));
expect(getTitleBottomLeft(), const Offset(390.0, 16.0));
await tester.pumpWidget(buildFrame(TargetPlatform.macOS, false));
expect(getTitleBottomLeft(), const Offset(72.0, 16.0));
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('FlexibleSpaceBar test titlePadding override', (WidgetTester tester) async { testWidgets('FlexibleSpaceBar test titlePadding override', (WidgetTester tester) async {
...@@ -195,6 +206,15 @@ void main() { ...@@ -195,6 +206,15 @@ void main() {
await tester.pumpWidget(buildFrame(TargetPlatform.iOS, false)); await tester.pumpWidget(buildFrame(TargetPlatform.iOS, false));
expect(getTitleBottomLeft(), Offset.zero); expect(getTitleBottomLeft(), Offset.zero);
// Clear the widget tree to avoid animating between iOS and macOS.
await tester.pumpWidget(Container(key: UniqueKey()));
await tester.pumpWidget(buildFrame(TargetPlatform.macOS, null));
expect(getTitleBottomLeft(), const Offset(390.0, 0.0));
await tester.pumpWidget(buildFrame(TargetPlatform.macOS, false));
expect(getTitleBottomLeft(), Offset.zero);
}, skip: isBrowser); }, skip: isBrowser);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart' show CupertinoPageRoute; import 'package:flutter/cupertino.dart' show CupertinoPageRoute;
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -10,10 +11,9 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -10,10 +11,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
void main() { void main() {
testWidgets('test Android page transition', (WidgetTester tester) async { testWidgets('test page transition', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: const Material(child: Text('Page 1')), home: const Material(child: Text('Page 1')),
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/next': (BuildContext context) { '/next': (BuildContext context) {
...@@ -66,13 +66,12 @@ void main() { ...@@ -66,13 +66,12 @@ void main() {
expect(find.text('Page 1'), isOnstage); expect(find.text('Page 1'), isOnstage);
expect(find.text('Page 2'), findsNothing); expect(find.text('Page 2'), findsNothing);
}); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('test iOS page transition', (WidgetTester tester) async { testWidgets('test page transition', (WidgetTester tester) async {
final Key page2Key = UniqueKey(); final Key page2Key = UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: const Material(child: Text('Page 1')), home: const Material(child: Text('Page 1')),
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/next': (BuildContext context) { '/next': (BuildContext context) {
...@@ -145,13 +144,12 @@ void main() { ...@@ -145,13 +144,12 @@ void main() {
// Page 1 is back where it started. // Page 1 is back where it started.
expect(widget1InitialTopLeft == widget1TransientTopLeft, true); expect(widget1InitialTopLeft == widget1TransientTopLeft, true);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('test iOS fullscreen dialog transition', (WidgetTester tester) async { testWidgets('test fullscreen dialog transition', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( const MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), home: Material(child: Text('Page 1')),
home: const Material(child: Text('Page 1')),
), ),
); );
...@@ -206,12 +204,11 @@ void main() { ...@@ -206,12 +204,11 @@ void main() {
// Page 1 is back where it started. // Page 1 is back where it started.
expect(widget1InitialTopLeft == widget1TransientTopLeft, true); expect(widget1InitialTopLeft == widget1TransientTopLeft, true);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('test no back gesture on Android', (WidgetTester tester) async { testWidgets('test no back gesture on Android', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: const Scaffold(body: Text('Page 1')), home: const Scaffold(body: Text('Page 1')),
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/next': (BuildContext context) { '/next': (BuildContext context) {
...@@ -237,12 +234,11 @@ void main() { ...@@ -237,12 +234,11 @@ void main() {
// Page 2 didn't move // Page 2 didn't move
expect(tester.getTopLeft(find.text('Page 2')), Offset.zero); expect(tester.getTopLeft(find.text('Page 2')), Offset.zero);
}); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('test back gesture on iOS', (WidgetTester tester) async { testWidgets('test back gesture', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: const Scaffold(body: Text('Page 1')), home: const Scaffold(body: Text('Page 1')),
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/next': (BuildContext context) { '/next': (BuildContext context) {
...@@ -279,7 +275,7 @@ void main() { ...@@ -279,7 +275,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(tester.getTopLeft(find.text('Page 2')), const Offset(100.0, 0.0)); expect(tester.getTopLeft(find.text('Page 2')), const Offset(100.0, 0.0));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('back gesture while OS changes', (WidgetTester tester) async { testWidgets('back gesture while OS changes', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
...@@ -346,13 +342,36 @@ void main() { ...@@ -346,13 +342,36 @@ void main() {
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 3); expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 3);
expect(find.text('PUSH'), findsOneWidget); expect(find.text('PUSH'), findsOneWidget);
expect(find.text('HELLO'), findsNothing); expect(find.text('HELLO'), findsNothing);
});
testWidgets('test no back gesture on iOS fullscreen dialogs', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), theme: ThemeData(platform: TargetPlatform.macOS),
home: const Scaffold(body: Text('Page 1')), routes: routes,
),
);
await tester.tap(find.text('PUSH'));
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2);
expect(find.text('PUSH'), findsNothing);
expect(find.text('HELLO'), findsOneWidget);
final Offset helloPosition5 = tester.getCenter(find.text('HELLO'));
await gesture.down(const Offset(2.5, 300.0));
await tester.pump(const Duration(milliseconds: 20));
await gesture.moveBy(const Offset(100.0, 0.0));
expect(find.text('PUSH'), findsNothing);
expect(find.text('HELLO'), findsOneWidget);
await tester.pump(const Duration(milliseconds: 20));
expect(find.text('PUSH'), findsOneWidget);
expect(find.text('HELLO'), findsOneWidget);
final Offset helloPosition6 = tester.getCenter(find.text('HELLO'));
expect(helloPosition5.dx, lessThan(helloPosition6.dx));
expect(helloPosition5.dy, helloPosition6.dy);
expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.macOS);
});
testWidgets('test no back gesture on fullscreen dialogs', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(body: Text('Page 1')),
), ),
); );
...@@ -377,7 +396,7 @@ void main() { ...@@ -377,7 +396,7 @@ void main() {
// Page 2 didn't move // Page 2 didn't move
expect(tester.getTopLeft(find.text('Page 2')), Offset.zero); expect(tester.getTopLeft(find.text('Page 2')), Offset.zero);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('test adaptable transitions switch during execution', (WidgetTester tester) async { testWidgets('test adaptable transitions switch during execution', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -417,7 +436,6 @@ void main() { ...@@ -417,7 +436,6 @@ void main() {
// Re-pump the same app but with iOS instead of Android. // Re-pump the same app but with iOS instead of Android.
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: const Material(child: Text('Page 1')), home: const Material(child: Text('Page 1')),
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/next': (BuildContext context) { '/next': (BuildContext context) {
...@@ -452,7 +470,7 @@ void main() { ...@@ -452,7 +470,7 @@ void main() {
// Page 1 is back where it started. // Page 1 is back where it started.
expect(widget1InitialTopLeft == widget1TransientTopLeft, true); expect(widget1InitialTopLeft == widget1TransientTopLeft, true);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('throws when builder returns null', (WidgetTester tester) async { testWidgets('throws when builder returns null', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp( await tester.pumpWidget(const MaterialApp(
...@@ -478,10 +496,9 @@ void main() { ...@@ -478,10 +496,9 @@ void main() {
)); ));
}); });
testWidgets('test iOS edge swipe then drop back at starting point works', (WidgetTester tester) async { testWidgets('test edge swipe then drop back at starting point works', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
onGenerateRoute: (RouteSettings settings) { onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<void>( return MaterialPageRoute<void>(
settings: settings, settings: settings,
...@@ -512,12 +529,11 @@ void main() { ...@@ -512,12 +529,11 @@ void main() {
expect(find.text('Page 1'), findsNothing); expect(find.text('Page 1'), findsNothing);
expect(find.text('Page 2'), isOnstage); expect(find.text('Page 2'), isOnstage);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('test iOS edge swipe then drop back at ending point works', (WidgetTester tester) async { testWidgets('test edge swipe then drop back at ending point works', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
onGenerateRoute: (RouteSettings settings) { onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<void>( return MaterialPageRoute<void>(
settings: settings, settings: settings,
...@@ -546,7 +562,7 @@ void main() { ...@@ -546,7 +562,7 @@ void main() {
expect(find.text('Page 1'), isOnstage); expect(find.text('Page 1'), isOnstage);
expect(find.text('Page 2'), findsNothing); expect(find.text('Page 2'), findsNothing);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('Back swipe dismiss interrupted by route push', (WidgetTester tester) async { testWidgets('Back swipe dismiss interrupted by route push', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/28728 // Regression test for https://github.com/flutter/flutter/issues/28728
...@@ -554,7 +570,6 @@ void main() { ...@@ -554,7 +570,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Scaffold( home: Scaffold(
key: scaffoldKey, key: scaffoldKey,
body: Center( body: Center(
...@@ -642,7 +657,7 @@ void main() { ...@@ -642,7 +657,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('route'), findsOneWidget); expect(find.text('route'), findsOneWidget);
expect(find.text('push'), findsNothing); expect(find.text('push'), findsNothing);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('During back swipe the route ignores input', (WidgetTester tester) async { testWidgets('During back swipe the route ignores input', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/39989 // Regression test for https://github.com/flutter/flutter/issues/39989
...@@ -654,7 +669,6 @@ void main() { ...@@ -654,7 +669,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Scaffold( home: Scaffold(
key: homeScaffoldKey, key: homeScaffoldKey,
body: GestureDetector( body: GestureDetector(
...@@ -713,7 +727,7 @@ void main() { ...@@ -713,7 +727,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(tester.getTopLeft(find.byKey(pageScaffoldKey)), const Offset(400, 0)); expect(tester.getTopLeft(find.byKey(pageScaffoldKey)), const Offset(400, 0));
expect(tester.getTopLeft(find.byKey(homeScaffoldKey)).dx, lessThan(0)); expect(tester.getTopLeft(find.byKey(homeScaffoldKey)).dx, lessThan(0));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('After a pop caused by a back-swipe, input reaches the exposed route', (WidgetTester tester) async { testWidgets('After a pop caused by a back-swipe, input reaches the exposed route', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/41024 // Regression test for https://github.com/flutter/flutter/issues/41024
...@@ -725,7 +739,6 @@ void main() { ...@@ -725,7 +739,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Scaffold( home: Scaffold(
key: homeScaffoldKey, key: homeScaffoldKey,
body: GestureDetector( body: GestureDetector(
...@@ -785,9 +798,9 @@ void main() { ...@@ -785,9 +798,9 @@ void main() {
await tester.tap(find.byKey(homeScaffoldKey)); await tester.tap(find.byKey(homeScaffoldKey));
expect(homeTapCount, 2); expect(homeTapCount, 2);
expect(pageTapCount, 1); expect(pageTapCount, 1);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('On iOS, a MaterialPageRoute should slide out with CupertinoPageTransition when a compatible PageRoute is pushed on top of it', (WidgetTester tester) async { testWidgets('A MaterialPageRoute should slide out with CupertinoPageTransition when a compatible PageRoute is pushed on top of it', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/44864. // Regression test for https://github.com/flutter/flutter/issues/44864.
await tester.pumpWidget( await tester.pumpWidget(
...@@ -813,5 +826,5 @@ void main() { ...@@ -813,5 +826,5 @@ void main() {
// Title of the first route slides to the left. // Title of the first route slides to the left.
expect(titleInitialTopLeft.dy, equals(titleTransientTopLeft.dy)); expect(titleInitialTopLeft.dy, equals(titleTransientTopLeft.dy));
expect(titleInitialTopLeft.dx, greaterThan(titleTransientTopLeft.dx)); expect(titleInitialTopLeft.dx, greaterThan(titleTransientTopLeft.dx));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -11,11 +12,16 @@ void main() { ...@@ -11,11 +12,16 @@ void main() {
await tester.pumpWidget(const MaterialApp(home: Text('home'))); await tester.pumpWidget(const MaterialApp(home: Text('home')));
final PageTransitionsTheme theme = Theme.of(tester.element(find.text('home'))).pageTransitionsTheme; final PageTransitionsTheme theme = Theme.of(tester.element(find.text('home'))).pageTransitionsTheme;
expect(theme.builders, isNotNull); expect(theme.builders, isNotNull);
expect(theme.builders[TargetPlatform.android], isNotNull); for (final TargetPlatform platform in TargetPlatform.values) {
expect(theme.builders[TargetPlatform.iOS], isNotNull); if (platform == TargetPlatform.fuchsia) {
// No builder on Fuchsia.
continue;
}
expect(theme.builders[platform], isNotNull, reason: 'theme builder for $platform is null');
}
}); });
testWidgets('Default PageTranstionsTheme builds a CupertionPageTransition for iOS', (WidgetTester tester) async { testWidgets('Default PageTranstionsTheme builds a CupertionPageTransition', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: FlatButton( child: FlatButton(
...@@ -28,19 +34,18 @@ void main() { ...@@ -28,19 +34,18 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
routes: routes, routes: routes,
), ),
); );
expect(Theme.of(tester.element(find.text('push'))).platform, TargetPlatform.iOS); expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride);
expect(find.byType(CupertinoPageTransition), findsOneWidget); expect(find.byType(CupertinoPageTransition), findsOneWidget);
await tester.tap(find.text('push')); await tester.tap(find.text('push'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget); expect(find.text('page b'), findsOneWidget);
expect(find.byType(CupertinoPageTransition), findsOneWidget); expect(find.byType(CupertinoPageTransition), findsOneWidget);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('Default PageTranstionsTheme builds a _FadeUpwardsPageTransition for android', (WidgetTester tester) async { testWidgets('Default PageTranstionsTheme builds a _FadeUpwardsPageTransition for android', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
...@@ -55,7 +60,6 @@ void main() { ...@@ -55,7 +60,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
routes: routes, routes: routes,
), ),
); );
...@@ -67,16 +71,16 @@ void main() { ...@@ -67,16 +71,16 @@ void main() {
); );
} }
expect(Theme.of(tester.element(find.text('push'))).platform, TargetPlatform.android); expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride);
expect(findFadeUpwardsPageTransition(), findsOneWidget); expect(findFadeUpwardsPageTransition(), findsOneWidget);
await tester.tap(find.text('push')); await tester.tap(find.text('push'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget); expect(find.text('page b'), findsOneWidget);
expect(findFadeUpwardsPageTransition(), findsOneWidget); expect(findFadeUpwardsPageTransition(), findsOneWidget);
}); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('pageTranstionsTheme override builds a _OpenUpwardsPageTransition for android', (WidgetTester tester) async { testWidgets('pageTranstionsTheme override builds a _OpenUpwardsPageTransition', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: FlatButton( child: FlatButton(
...@@ -90,7 +94,6 @@ void main() { ...@@ -90,7 +94,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData( theme: ThemeData(
platform: TargetPlatform.android,
pageTransitionsTheme: const PageTransitionsTheme( pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{ builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: OpenUpwardsPageTransitionsBuilder(), // creates a _OpenUpwardsPageTransition TargetPlatform.android: OpenUpwardsPageTransitionsBuilder(), // creates a _OpenUpwardsPageTransition
...@@ -108,16 +111,16 @@ void main() { ...@@ -108,16 +111,16 @@ void main() {
); );
} }
expect(Theme.of(tester.element(find.text('push'))).platform, TargetPlatform.android); expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride);
expect(findOpenUpwardsPageTransition(), findsOneWidget); expect(findOpenUpwardsPageTransition(), findsOneWidget);
await tester.tap(find.text('push')); await tester.tap(find.text('push'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget); expect(find.text('page b'), findsOneWidget);
expect(findOpenUpwardsPageTransition(), findsOneWidget); expect(findOpenUpwardsPageTransition(), findsOneWidget);
}); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('pageTranstionsTheme override builds a _ZoomPageTransition for android', (WidgetTester tester) async { testWidgets('pageTranstionsTheme override builds a _ZoomPageTransition', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: FlatButton( child: FlatButton(
...@@ -131,7 +134,6 @@ void main() { ...@@ -131,7 +134,6 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData( theme: ThemeData(
platform: TargetPlatform.android,
pageTransitionsTheme: const PageTransitionsTheme( pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{ builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: ZoomPageTransitionsBuilder(), // creates a _ZoomPageTransition TargetPlatform.android: ZoomPageTransitionsBuilder(), // creates a _ZoomPageTransition
...@@ -149,12 +151,12 @@ void main() { ...@@ -149,12 +151,12 @@ void main() {
); );
} }
expect(Theme.of(tester.element(find.text('push'))).platform, TargetPlatform.android); expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride);
expect(findZoomPageTransition(), findsOneWidget); expect(findZoomPageTransition(), findsOneWidget);
await tester.tap(find.text('push')); await tester.tap(find.text('push'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget); expect(find.text('page b'), findsOneWidget);
expect(findZoomPageTransition(), findsOneWidget); expect(findZoomPageTransition(), findsOneWidget);
}); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
} }
...@@ -325,6 +325,12 @@ void main() { ...@@ -325,6 +325,12 @@ void main() {
expect(find.byIcon(Icons.more_vert), findsNothing); expect(find.byIcon(Icons.more_vert), findsNothing);
expect(find.byIcon(Icons.more_horiz), findsOneWidget); expect(find.byIcon(Icons.more_horiz), findsOneWidget);
await tester.pumpWidget(build(TargetPlatform.macOS));
await tester.pumpAndSettle(); // Run theme change animation.
expect(find.byIcon(Icons.more_vert), findsNothing);
expect(find.byIcon(Icons.more_horiz), findsOneWidget);
}); });
group('PopupMenuButton with Icon', () { group('PopupMenuButton with Icon', () {
......
...@@ -387,8 +387,7 @@ void main() { ...@@ -387,8 +387,7 @@ void main() {
expect(tester.takeException(), isFlutterError); expect(tester.takeException(), isFlutterError);
}); });
testWidgets('Refresh starts while scroll view moves back to 0.0 after overscroll on iOS', (WidgetTester tester) async { testWidgets('Refresh starts while scroll view moves back to 0.0 after overscroll', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
refreshCalled = false; refreshCalled = false;
double lastScrollOffset; double lastScrollOffset;
final ScrollController controller = ScrollController(); final ScrollController controller = ScrollController();
...@@ -420,7 +419,5 @@ void main() { ...@@ -420,7 +419,5 @@ void main() {
expect(controller.offset, greaterThan(lastScrollOffset)); expect(controller.offset, greaterThan(lastScrollOffset));
expect(controller.offset, lessThan(0.0)); expect(controller.offset, lessThan(0.0));
expect(refreshCalled, isTrue); expect(refreshCalled, isTrue);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null;
});
} }
...@@ -320,17 +320,17 @@ void main() { ...@@ -320,17 +320,17 @@ void main() {
); );
} }
testWidgets('Tapping the status bar scrolls to top on iOS', (WidgetTester tester) async { testWidgets('Tapping the status bar scrolls to top', (WidgetTester tester) async {
await tester.pumpWidget(_buildStatusBarTestApp(TargetPlatform.iOS)); await tester.pumpWidget(_buildStatusBarTestApp(debugDefaultTargetPlatformOverride));
final ScrollableState scrollable = tester.state(find.byType(Scrollable)); final ScrollableState scrollable = tester.state(find.byType(Scrollable));
scrollable.position.jumpTo(500.0); scrollable.position.jumpTo(500.0);
expect(scrollable.position.pixels, equals(500.0)); expect(scrollable.position.pixels, equals(500.0));
await tester.tapAt(const Offset(100.0, 10.0)); await tester.tapAt(const Offset(100.0, 10.0));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(scrollable.position.pixels, equals(0.0)); expect(scrollable.position.pixels, equals(0.0));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('Tapping the status bar does not scroll to top on Android', (WidgetTester tester) async { testWidgets('Tapping the status bar does not scroll to top', (WidgetTester tester) async {
await tester.pumpWidget(_buildStatusBarTestApp(TargetPlatform.android)); await tester.pumpWidget(_buildStatusBarTestApp(TargetPlatform.android));
final ScrollableState scrollable = tester.state(find.byType(Scrollable)); final ScrollableState scrollable = tester.state(find.byType(Scrollable));
scrollable.position.jumpTo(500.0); scrollable.position.jumpTo(500.0);
...@@ -339,7 +339,7 @@ void main() { ...@@ -339,7 +339,7 @@ void main() {
await tester.pump(); await tester.pump();
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
expect(scrollable.position.pixels, equals(500.0)); expect(scrollable.position.pixels, equals(500.0));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android }));
testWidgets('Bottom sheet cannot overlap app bar', (WidgetTester tester) async { testWidgets('Bottom sheet cannot overlap app bar', (WidgetTester tester) async {
final Key sheetKey = UniqueKey(); final Key sheetKey = UniqueKey();
...@@ -506,7 +506,7 @@ void main() { ...@@ -506,7 +506,7 @@ void main() {
}); });
group('back arrow', () { group('back arrow', () {
Future<void> expectBackIcon(WidgetTester tester, TargetPlatform platform, IconData expectedIcon) async { Future<void> expectBackIcon(WidgetTester tester, IconData expectedIcon) async {
final GlobalKey rootKey = GlobalKey(); final GlobalKey rootKey = GlobalKey();
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (_) => Container(key: rootKey, child: const Text('Home')), '/': (_) => Container(key: rootKey, child: const Text('Home')),
...@@ -515,9 +515,7 @@ void main() { ...@@ -515,9 +515,7 @@ void main() {
body: const Text('Scaffold'), body: const Text('Scaffold'),
), ),
}; };
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(routes: routes));
MaterialApp(theme: ThemeData(platform: platform), routes: routes)
);
Navigator.pushNamed(rootKey.currentContext, '/scaffold'); Navigator.pushNamed(rootKey.currentContext, '/scaffold');
await tester.pump(); await tester.pump();
...@@ -527,24 +525,20 @@ void main() { ...@@ -527,24 +525,20 @@ void main() {
expect(icon.icon, expectedIcon); expect(icon.icon, expectedIcon);
} }
testWidgets('Back arrow uses correct default on Android', (WidgetTester tester) async { testWidgets('Back arrow uses correct default', (WidgetTester tester) async {
await expectBackIcon(tester, TargetPlatform.android, Icons.arrow_back); await expectBackIcon(tester, Icons.arrow_back);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
testWidgets('Back arrow uses correct default on Fuchsia', (WidgetTester tester) async {
await expectBackIcon(tester, TargetPlatform.fuchsia, Icons.arrow_back);
});
testWidgets('Back arrow uses correct default on iOS', (WidgetTester tester) async { testWidgets('Back arrow uses correct default', (WidgetTester tester) async {
await expectBackIcon(tester, TargetPlatform.iOS, Icons.arrow_back_ios); await expectBackIcon(tester, Icons.arrow_back_ios);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
}); });
group('close button', () { group('close button', () {
Future<void> expectCloseIcon(WidgetTester tester, TargetPlatform platform, IconData expectedIcon, PageRoute<void> routeBuilder()) async { Future<void> expectCloseIcon(WidgetTester tester, PageRoute<void> routeBuilder(), String type) async {
const IconData expectedIcon = Icons.close;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: platform),
home: Scaffold(appBar: AppBar(), body: const Text('Page 1')), home: Scaffold(appBar: AppBar(), body: const Text('Page 1')),
), ),
); );
...@@ -555,8 +549,8 @@ void main() { ...@@ -555,8 +549,8 @@ void main() {
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
final Icon icon = tester.widget(find.byType(Icon)); final Icon icon = tester.widget(find.byType(Icon));
expect(icon.icon, expectedIcon); expect(icon.icon, expectedIcon, reason: "didn't find close icon for $type");
expect(find.byType(CloseButton), findsOneWidget); expect(find.byType(CloseButton), findsOneWidget, reason: "didn't find close button for $type");
} }
PageRoute<void> materialRouteBuilder() { PageRoute<void> materialRouteBuilder() {
...@@ -586,41 +580,17 @@ void main() { ...@@ -586,41 +580,17 @@ void main() {
); );
} }
testWidgets('Close button shows correctly on Android', (WidgetTester tester) async { testWidgets('Close button shows correctly', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.android, Icons.close, materialRouteBuilder); await expectCloseIcon(tester, materialRouteBuilder, 'materialRouteBuilder');
}); }, variant: TargetPlatformVariant.all());
testWidgets('Close button shows correctly on Fuchsia', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.fuchsia, Icons.close, materialRouteBuilder);
});
testWidgets('Close button shows correctly on iOS', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.iOS, Icons.close, materialRouteBuilder);
});
testWidgets('Close button shows correctly with PageRouteBuilder on Android', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.android, Icons.close, pageRouteBuilder);
});
testWidgets('Close button shows correctly with PageRouteBuilder on Fuchsia', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.fuchsia, Icons.close, pageRouteBuilder);
});
testWidgets('Close button shows correctly with PageRouteBuilder on iOS', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.iOS, Icons.close, pageRouteBuilder);
});
testWidgets('Close button shows correctly with custom page route on Android', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.android, Icons.close, customPageRouteBuilder);
});
testWidgets('Close button shows correctly with custom page route on Fuchsia', (WidgetTester tester) async { testWidgets('Close button shows correctly with PageRouteBuilder', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.fuchsia, Icons.close, customPageRouteBuilder); await expectCloseIcon(tester, pageRouteBuilder, 'pageRouteBuilder');
}); }, variant: TargetPlatformVariant.all());
testWidgets('Close button shows correctly with custom page route on iOS', (WidgetTester tester) async { testWidgets('Close button shows correctly with custom page route', (WidgetTester tester) async {
await expectCloseIcon(tester, TargetPlatform.iOS, Icons.close, customPageRouteBuilder); await expectCloseIcon(tester, customPageRouteBuilder, 'customPageRouteBuilder');
}); }, variant: TargetPlatformVariant.all());
}); });
group('body size', () { group('body size', () {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -152,6 +153,20 @@ void main() { ...@@ -152,6 +153,20 @@ void main() {
await tester.drag(find.byType(SingleChildScrollView), const Offset(0.0, -10.0)); await tester.drag(find.byType(SingleChildScrollView), const Offset(0.0, -10.0));
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
expect(find.byType(Scrollbar), paints..rrect());
expect(find.byType(CupertinoScrollbar), paints..rrect());
await gesture.up();
await tester.pumpAndSettle();
await tester.pumpWidget(viewWithScroll(TargetPlatform.macOS));
await gesture.down(
tester.getCenter(find.byType(SingleChildScrollView)),
);
await gesture.moveBy(const Offset(0.0, -10.0));
await tester.drag(find.byType(SingleChildScrollView), const Offset(0.0, -10.0));
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
expect(find.byType(Scrollbar), paints..rrect());
expect(find.byType(CupertinoScrollbar), paints..rrect()); expect(find.byType(CupertinoScrollbar), paints..rrect());
}); });
...@@ -173,7 +188,7 @@ void main() { ...@@ -173,7 +188,7 @@ void main() {
); );
} }
await tester.pumpWidget(viewWithScroll(TargetPlatform.iOS)); await tester.pumpWidget(viewWithScroll(debugDefaultTargetPlatformOverride));
final TestGesture gesture = await tester.startGesture( final TestGesture gesture = await tester.startGesture(
tester.getCenter(find.byType(SingleChildScrollView)) tester.getCenter(find.byType(SingleChildScrollView))
); );
...@@ -184,6 +199,6 @@ void main() { ...@@ -184,6 +199,6 @@ void main() {
expect(find.byType(CupertinoScrollbar), paints..rrect()); expect(find.byType(CupertinoScrollbar), paints..rrect());
final CupertinoScrollbar scrollbar = find.byType(CupertinoScrollbar).evaluate().first.widget as CupertinoScrollbar; final CupertinoScrollbar scrollbar = find.byType(CupertinoScrollbar).evaluate().first.widget as CupertinoScrollbar;
expect(scrollbar.controller, isNotNull); expect(scrollbar.controller, isNotNull);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
} }
...@@ -573,7 +573,8 @@ void main() { ...@@ -573,7 +573,8 @@ void main() {
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
SemanticsFlag.isHeader, SemanticsFlag.isHeader,
if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS) SemanticsFlag.namesRoute, if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS &&
debugDefaultTargetPlatformOverride != TargetPlatform.macOS) SemanticsFlag.namesRoute,
], ],
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap, SemanticsAction.tap,
...@@ -622,8 +623,7 @@ void main() { ...@@ -622,8 +623,7 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('does not include routeName on iOS', (WidgetTester tester) async { testWidgets('does not include routeName', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final _TestSearchDelegate delegate = _TestSearchDelegate(); final _TestSearchDelegate delegate = _TestSearchDelegate();
await tester.pumpWidget(TestHomePage( await tester.pumpWidget(TestHomePage(
...@@ -636,9 +636,8 @@ void main() { ...@@ -636,9 +636,8 @@ void main() {
expect(semantics, hasSemantics(buildExpected(routeName: ''), expect(semantics, hasSemantics(buildExpected(routeName: ''),
ignoreId: true, ignoreRect: true, ignoreTransform: true)); ignoreId: true, ignoreRect: true, ignoreTransform: true));
debugDefaultTargetPlatformOverride = null;
semantics.dispose(); semantics.dispose();
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
}); });
} }
......
...@@ -1250,16 +1250,14 @@ void main() { ...@@ -1250,16 +1250,14 @@ void main() {
)); ));
semantics.dispose(); semantics.dispose();
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
testWidgets('Slider Semantics - iOS', (WidgetTester tester) async { testWidgets('Slider Semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget( await tester.pumpWidget(
Theme( Theme(
data: ThemeData.light().copyWith( data: ThemeData.light(),
platform: TargetPlatform.iOS,
),
child: Directionality( child: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: MediaQuery( child: MediaQuery(
...@@ -1294,7 +1292,7 @@ void main() { ...@@ -1294,7 +1292,7 @@ void main() {
ignoreTransform: true, ignoreTransform: true,
)); ));
semantics.dispose(); semantics.dispose();
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('Slider semantics with custom formatter', (WidgetTester tester) async { testWidgets('Slider semantics with custom formatter', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
...@@ -1485,27 +1483,34 @@ void main() { ...@@ -1485,27 +1483,34 @@ void main() {
); );
} }
await tester.pumpWidget(buildFrame(TargetPlatform.iOS)); for (final TargetPlatform platform in <TargetPlatform>[TargetPlatform.iOS, TargetPlatform.macOS]) {
expect(find.byType(Slider), findsOneWidget); value = 0.5;
expect(find.byType(CupertinoSlider), findsOneWidget); await tester.pumpWidget(buildFrame(platform));
expect(find.byType(Slider), findsOneWidget);
expect(value, 0.5); expect(find.byType(CupertinoSlider), findsOneWidget);
TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(CupertinoSlider)));
// Drag to the right end of the track. expect(value, 0.5, reason: 'on ${describeEnum(platform)}');
await gesture.moveBy(const Offset(600.0, 0.0)); final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(CupertinoSlider)));
expect(value, 1.0); // Drag to the right end of the track.
await gesture.moveBy(const Offset(600.0, 0.0));
value = 0.5; expect(value, 1.0, reason: 'on ${describeEnum(platform)}');
await tester.pumpWidget(buildFrame(TargetPlatform.android)); await gesture.up();
await tester.pumpAndSettle(); // Finish the theme change animation. }
expect(find.byType(Slider), findsOneWidget);
expect(find.byType(CupertinoSlider), findsNothing); for (final TargetPlatform platform in <TargetPlatform>[TargetPlatform.android, TargetPlatform.fuchsia]) {
value = 0.5;
expect(value, 0.5); await tester.pumpWidget(buildFrame(platform));
gesture = await tester.startGesture(tester.getCenter(find.byType(Slider))); await tester.pumpAndSettle(); // Finish the theme change animation.
// Drag to the right end of the track. expect(find.byType(Slider), findsOneWidget);
await gesture.moveBy(const Offset(600.0, 0.0)); expect(find.byType(CupertinoSlider), findsNothing);
expect(value, 1.0);
expect(value, 0.5, reason: 'on ${describeEnum(platform)}');
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(Slider)));
// Drag to the right end of the track.
await gesture.moveBy(const Offset(600.0, 0.0));
expect(value, 1.0, reason: 'on ${describeEnum(platform)}');
await gesture.up();
}
}); });
testWidgets('Slider respects height from theme', (WidgetTester tester) async { testWidgets('Slider respects height from theme', (WidgetTester tester) async {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
...@@ -85,20 +86,26 @@ void main() { ...@@ -85,20 +86,26 @@ void main() {
); );
} }
await tester.pumpWidget(buildFrame(TargetPlatform.iOS)); for (final TargetPlatform platform in <TargetPlatform>[ TargetPlatform.iOS, TargetPlatform.macOS ]) {
expect(find.byType(CupertinoSwitch), findsOneWidget); value = false;
expect(value, isFalse); await tester.pumpWidget(buildFrame(platform));
expect(find.byType(CupertinoSwitch), findsOneWidget);
expect(value, isFalse, reason: 'on ${describeEnum(platform)}');
await tester.tap(find.byType(SwitchListTile)); await tester.tap(find.byType(SwitchListTile));
expect(value, isTrue); expect(value, isTrue, reason: 'on ${describeEnum(platform)}');
}
await tester.pumpWidget(buildFrame(TargetPlatform.android)); for (final TargetPlatform platform in <TargetPlatform>[ TargetPlatform.android, TargetPlatform.fuchsia ]) {
await tester.pumpAndSettle(); // Finish the theme change animation. value = false;
await tester.pumpWidget(buildFrame(platform));
await tester.pumpAndSettle(); // Finish the theme change animation.
expect(find.byType(CupertinoSwitch), findsNothing); expect(find.byType(CupertinoSwitch), findsNothing);
expect(value, isTrue); expect(value, isFalse, reason: 'on ${describeEnum(platform)}');
await tester.tap(find.byType(SwitchListTile)); await tester.tap(find.byType(SwitchListTile));
expect(value, isFalse); expect(value, isTrue, reason: 'on ${describeEnum(platform)}');
}
}); });
testWidgets('SwitchListTile contentPadding', (WidgetTester tester) async { testWidgets('SwitchListTile contentPadding', (WidgetTester tester) async {
......
...@@ -610,23 +610,28 @@ void main() { ...@@ -610,23 +610,28 @@ void main() {
); );
} }
await tester.pumpWidget(buildFrame(TargetPlatform.iOS)); for (final TargetPlatform platform in <TargetPlatform>[ TargetPlatform.iOS, TargetPlatform.macOS ]) {
expect(find.byType(CupertinoSwitch), findsOneWidget); value = false;
await tester.pumpWidget(buildFrame(platform));
expect(find.byType(CupertinoSwitch), findsOneWidget, reason: 'on ${describeEnum(platform)}');
final CupertinoSwitch adaptiveSwitch = tester.widget(find.byType(CupertinoSwitch)); final CupertinoSwitch adaptiveSwitch = tester.widget(find.byType(CupertinoSwitch));
expect(adaptiveSwitch.trackColor, inactiveTrackColor); expect(adaptiveSwitch.trackColor, inactiveTrackColor, reason: 'on ${describeEnum(platform)}');
expect(value, isFalse); expect(value, isFalse, reason: 'on ${describeEnum(platform)}');
await tester.tap(find.byType(Switch)); await tester.tap(find.byType(Switch));
expect(value, isTrue); expect(value, isTrue, reason: 'on ${describeEnum(platform)}');
}
await tester.pumpWidget(buildFrame(TargetPlatform.android));
await tester.pumpAndSettle(); // Finish the theme change animation.
expect(find.byType(CupertinoSwitch), findsNothing);
expect(value, isTrue);
await tester.tap(find.byType(Switch));
expect(value, isFalse);
for (final TargetPlatform platform in <TargetPlatform>[ TargetPlatform.android, TargetPlatform.fuchsia ]) {
value = false;
await tester.pumpWidget(buildFrame(platform));
await tester.pumpAndSettle(); // Finish the theme change animation.
expect(find.byType(CupertinoSwitch), findsNothing);
expect(value, isFalse, reason: 'on ${describeEnum(platform)}');
await tester.tap(find.byType(Switch));
expect(value, isTrue, reason: 'on ${describeEnum(platform)}');
}
}); });
testWidgets('Switch is focusable and has correct focus color', (WidgetTester tester) async { testWidgets('Switch is focusable and has correct focus color', (WidgetTester tester) async {
......
...@@ -304,9 +304,7 @@ void main() { ...@@ -304,9 +304,7 @@ void main() {
await checkCursorToggle(); await checkCursorToggle();
}); });
testWidgets('Cursor animates on iOS', (WidgetTester tester) async { testWidgets('Cursor animates', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Material( home: Material(
...@@ -340,13 +338,9 @@ void main() { ...@@ -340,13 +338,9 @@ void main() {
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
expect(renderEditable.cursorColor.alpha, 0); expect(renderEditable.cursorColor.alpha, 0);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null; testWidgets('Cursor radius is 2.0', (WidgetTester tester) async {
});
testWidgets('Cursor radius is 2.0 on iOS', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Material( home: Material(
...@@ -359,9 +353,7 @@ void main() { ...@@ -359,9 +353,7 @@ void main() {
final RenderEditable renderEditable = editableTextState.renderEditable; final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorRadius, const Radius.circular(2.0)); expect(renderEditable.cursorRadius, const Radius.circular(2.0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null;
});
testWidgets('cursor has expected defaults', (WidgetTester tester) async { testWidgets('cursor has expected defaults', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -416,9 +408,7 @@ void main() { ...@@ -416,9 +408,7 @@ void main() {
); );
}); });
testWidgets('Material cursor iOS golden', (WidgetTester tester) async { testWidgets('Material cursor golden', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final Widget widget = overlay( final Widget widget = overlay(
child: const RepaintBoundary( child: const RepaintBoundary(
key: ValueKey<int>(1), key: ValueKey<int>(1),
...@@ -438,12 +428,13 @@ void main() { ...@@ -438,12 +428,13 @@ void main() {
await tester.tapAt(textOffsetToPosition(tester, testValue.length)); await tester.tapAt(textOffsetToPosition(tester, testValue.length));
await tester.pump(); await tester.pump();
debugDefaultTargetPlatformOverride = null;
await expectLater( await expectLater(
find.byKey(const ValueKey<int>(1)), find.byKey(const ValueKey<int>(1)),
matchesGoldenFile('text_field_cursor_test.material.1.png'), matchesGoldenFile(
'text_field_cursor_test_${describeEnum(debugDefaultTargetPlatformOverride).toLowerCase()}.material.1.png',
),
); );
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('text field selection toolbar renders correctly inside opacity', (WidgetTester tester) async { testWidgets('text field selection toolbar renders correctly inside opacity', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -496,14 +487,13 @@ void main() { ...@@ -496,14 +487,13 @@ void main() {
); );
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('text field toolbar options correctly changes options (iOS)', testWidgets('text field toolbar options correctly changes options',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -544,9 +534,9 @@ void main() { ...@@ -544,9 +534,9 @@ void main() {
expect(find.text('Copy'), findsOneWidget); expect(find.text('Copy'), findsOneWidget);
expect(find.text('Cut'), findsNothing); expect(find.text('Cut'), findsNothing);
expect(find.text('Select All'), findsNothing); expect(find.text('Select All'), findsNothing);
}, skip: isBrowser); }, skip: isBrowser, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('text field toolbar options correctly changes options (Android)', testWidgets('text field toolbar options correctly changes options',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
...@@ -577,10 +567,8 @@ void main() { ...@@ -577,10 +567,8 @@ void main() {
expect(find.text('COPY'), findsOneWidget); expect(find.text('COPY'), findsOneWidget);
expect(find.text('CUT'), findsNothing); expect(find.text('CUT'), findsNothing);
expect(find.text('SELECT ALL'), findsNothing); expect(find.text('SELECT ALL'), findsNothing);
}, skip: isBrowser); }, skip: isBrowser, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
// TODO(hansmuller): restore these tests after the fix for #24876 has landed.
/*
testWidgets('cursor layout has correct width', (WidgetTester tester) async { testWidgets('cursor layout has correct width', (WidgetTester tester) async {
EditableText.debugDeterministicCursor = true; EditableText.debugDeterministicCursor = true;
await tester.pumpWidget( await tester.pumpWidget(
...@@ -597,10 +585,10 @@ void main() { ...@@ -597,10 +585,10 @@ void main() {
await expectLater( await expectLater(
find.byType(TextField), find.byType(TextField),
matchesGoldenFile('text_field_test.0.0.png'), matchesGoldenFile('text_field_cursor_width_test.0.0.png', version: 0),
); );
EditableText.debugDeterministicCursor = false; EditableText.debugDeterministicCursor = false;
}, skip: !Platform.isLinux); }, skip: !isLinux);
testWidgets('cursor layout has correct radius', (WidgetTester tester) async { testWidgets('cursor layout has correct radius', (WidgetTester tester) async {
EditableText.debugDeterministicCursor = true; EditableText.debugDeterministicCursor = true;
...@@ -619,11 +607,10 @@ void main() { ...@@ -619,11 +607,10 @@ void main() {
await expectLater( await expectLater(
find.byType(TextField), find.byType(TextField),
matchesGoldenFile('text_field_test.1.0.png'), matchesGoldenFile('text_field_cursor_width_test.1.0.png', version: 0),
); );
EditableText.debugDeterministicCursor = false; EditableText.debugDeterministicCursor = false;
}, skip: !Platform.isLinux); }, skip: !isLinux);
*/
testWidgets('Overflowing a line with spaces stops the cursor at the end', (WidgetTester tester) async { testWidgets('Overflowing a line with spaces stops the cursor at the end', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(); final TextEditingController controller = TextEditingController();
...@@ -978,11 +965,10 @@ void main() { ...@@ -978,11 +965,10 @@ void main() {
expect(find.text('CUT'), findsNothing); expect(find.text('CUT'), findsNothing);
}); });
testWidgets('does not paint toolbar when no options available on ios', (WidgetTester tester) async { testWidgets('does not paint toolbar when no options available', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( const MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS), home: Material(
home: const Material(
child: TextField( child: TextField(
readOnly: true, readOnly: true,
), ),
...@@ -998,9 +984,9 @@ void main() { ...@@ -998,9 +984,9 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byType(CupertinoTextSelectionToolbar), paintsNothing); expect(find.byType(CupertinoTextSelectionToolbar), paintsNothing);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('text field build empty toolbar when no options available android', (WidgetTester tester) async { testWidgets('text field build empty toolbar when no options available', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Material( home: Material(
...@@ -1022,7 +1008,7 @@ void main() { ...@@ -1022,7 +1008,7 @@ void main() {
matching: find.byType(Container), matching: find.byType(Container),
)); ));
expect(container.size, Size.zero); expect(container.size, Size.zero);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
testWidgets('Sawping controllers should update selection', (WidgetTester tester) async { testWidgets('Sawping controllers should update selection', (WidgetTester tester) async {
TextEditingController controller = TextEditingController(text: 'readonly'); TextEditingController controller = TextEditingController(text: 'readonly');
...@@ -5500,14 +5486,13 @@ void main() { ...@@ -5500,14 +5486,13 @@ void main() {
}); });
testWidgets( testWidgets(
'tap moves cursor to the edge of the word it tapped on (iOS)', 'tap moves cursor to the edge of the word it tapped',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -5531,12 +5516,9 @@ void main() { ...@@ -5531,12 +5516,9 @@ void main() {
// But don't trigger the toolbar. // But don't trigger the toolbar.
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets('tap moves cursor to the position tapped', (WidgetTester tester) async {
'tap moves cursor to the position tapped (Android)',
(WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
...@@ -5565,18 +5547,16 @@ void main() { ...@@ -5565,18 +5547,16 @@ void main() {
// But don't trigger the toolbar. // But don't trigger the toolbar.
expect(find.byType(FlatButton), findsNothing); expect(find.byType(FlatButton), findsNothing);
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
);
testWidgets( testWidgets(
'two slow taps do not trigger a word selection (iOS)', 'two slow taps do not trigger a word selection',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -5602,18 +5582,16 @@ void main() { ...@@ -5602,18 +5582,16 @@ void main() {
// No toolbar. // No toolbar.
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets(
'double tap selects word and first tap of double tap moves cursor (iOS)', 'double tap selects word and first tap of double tap moves cursor',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -5649,11 +5627,10 @@ void main() { ...@@ -5649,11 +5627,10 @@ void main() {
// Selected text shows 3 toolbar buttons. // Selected text shows 3 toolbar buttons.
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), findsNWidgets(3));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets(
'double tap selects word and first tap of double tap moves cursor and shows toolbar (Android)', 'double tap selects word and first tap of double tap moves cursor and shows toolbar',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
...@@ -5695,11 +5672,10 @@ void main() { ...@@ -5695,11 +5672,10 @@ void main() {
// Selected text shows 4 toolbar buttons: cut, copy, paste, select all // Selected text shows 4 toolbar buttons: cut, copy, paste, select all
expect(find.byType(FlatButton), findsNWidgets(4)); expect(find.byType(FlatButton), findsNWidgets(4));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
);
testWidgets( testWidgets(
'double tap on top of cursor also selects word (Android)', 'double tap on top of cursor also selects word',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
...@@ -5745,8 +5721,7 @@ void main() { ...@@ -5745,8 +5721,7 @@ void main() {
// Selected text shows 4 toolbar buttons: cut, copy, paste, select all // Selected text shows 4 toolbar buttons: cut, copy, paste, select all
expect(find.byType(FlatButton), findsNWidgets(4)); expect(find.byType(FlatButton), findsNWidgets(4));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
);
testWidgets( testWidgets(
'double double tap just shows the selection menu', 'double double tap just shows the selection menu',
...@@ -5873,14 +5848,13 @@ void main() { ...@@ -5873,14 +5848,13 @@ void main() {
); );
testWidgets( testWidgets(
'double tap hold selects word (iOS)', 'double tap hold selects word',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -5918,18 +5892,16 @@ void main() { ...@@ -5918,18 +5892,16 @@ void main() {
); );
// The toolbar is still showing. // The toolbar is still showing.
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), findsNWidgets(3));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets(
'tap after a double tap select is not affected (iOS)', 'tap after a double tap select is not affected',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -5966,18 +5938,16 @@ void main() { ...@@ -5966,18 +5938,16 @@ void main() {
// No toolbar. // No toolbar.
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets(
'long press moves cursor to the exact long press position and shows toolbar (iOS)', 'long press moves cursor to the exact long press position and shows toolbar',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -6001,11 +5971,10 @@ void main() { ...@@ -6001,11 +5971,10 @@ void main() {
// Collapsed toolbar shows 2 buttons. // Collapsed toolbar shows 2 buttons.
expect(find.byType(CupertinoButton), findsNWidgets(2)); expect(find.byType(CupertinoButton), findsNWidgets(2));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets(
'long press selects word and shows toolbar (Android)', 'long press selects word and shows toolbar',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
...@@ -6034,18 +6003,16 @@ void main() { ...@@ -6034,18 +6003,16 @@ void main() {
// Collapsed toolbar shows 4 buttons: cut, copy, paste, select all // Collapsed toolbar shows 4 buttons: cut, copy, paste, select all
expect(find.byType(FlatButton), findsNWidgets(4)); expect(find.byType(FlatButton), findsNWidgets(4));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
);
testWidgets( testWidgets(
'long press tap cannot initiate a double tap (iOS)', 'long press tap cannot initiate a double tap',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -6073,18 +6040,16 @@ void main() { ...@@ -6073,18 +6040,16 @@ void main() {
// Collapsed toolbar shows 2 buttons. // Collapsed toolbar shows 2 buttons.
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets(
'long press drag moves the cursor under the drag and shows toolbar on lift (iOS)', 'long press drag moves the cursor under the drag and shows toolbar on lift',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -6141,16 +6106,14 @@ void main() { ...@@ -6141,16 +6106,14 @@ void main() {
); );
// The toolbar now shows up. // The toolbar now shows up.
expect(find.byType(CupertinoButton), findsNWidgets(2)); expect(find.byType(CupertinoButton), findsNWidgets(2));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets('long press drag can edge scroll (iOS)', (WidgetTester tester) async { testWidgets('long press drag can edge scroll', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neiges', text: 'Atwater Peel Sherbrooke Bonaventure Angrignon Peel Côte-des-Neiges',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -6232,17 +6195,16 @@ void main() { ...@@ -6232,17 +6195,16 @@ void main() {
expect(firstCharEndpoint.length, 1); expect(firstCharEndpoint.length, 1);
// The first character is now offscreen to the left. // The first character is now offscreen to the left.
expect(firstCharEndpoint[0].point.dx, moreOrLessEquals(-257, epsilon: 1)); expect(firstCharEndpoint[0].point.dx, moreOrLessEquals(-257, epsilon: 1));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets( testWidgets(
'long tap after a double tap select is not affected (iOS)', 'long tap after a double tap select is not affected',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -6276,18 +6238,16 @@ void main() { ...@@ -6276,18 +6238,16 @@ void main() {
// Long press toolbar. // Long press toolbar.
expect(find.byType(CupertinoButton), findsNWidgets(2)); expect(find.byType(CupertinoButton), findsNWidgets(2));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets(
'double tap after a long tap is not affected (iOS)', 'double tap after a long tap is not affected',
(WidgetTester tester) async { (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -6319,18 +6279,14 @@ void main() { ...@@ -6319,18 +6279,14 @@ void main() {
const TextSelection(baseOffset: 8, extentOffset: 12), const TextSelection(baseOffset: 8, extentOffset: 12),
); );
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), findsNWidgets(3));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets( testWidgets('double tap chains work', (WidgetTester tester) async {
'double tap chains work (iOS)',
(WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
...@@ -6387,10 +6343,9 @@ void main() { ...@@ -6387,10 +6343,9 @@ void main() {
const TextSelection(baseOffset: 8, extentOffset: 12), const TextSelection(baseOffset: 8, extentOffset: 12),
); );
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), findsNWidgets(3));
}, }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
);
testWidgets('force press does not select a word on (android)', (WidgetTester tester) async { testWidgets('force press does not select a word', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
...@@ -6418,7 +6373,7 @@ void main() { ...@@ -6418,7 +6373,7 @@ void main() {
pressureMin: 0.0, pressureMin: 0.0,
), ),
); );
await gesture.updateWithCustomEvent(PointerMoveEvent(pointer: pointerValue, position: offset + const Offset(150.0, 9.0), pressure: 0.5, pressureMin: 0, pressureMax: 1)); await gesture.updateWithCustomEvent(PointerMoveEvent(pointer: pointerValue, position: offset + const Offset(150.0, 9.0), pressure: 0.5, pressureMin: 0, pressureMax: 1,),);
// We don't want this gesture to select any word on Android. // We don't want this gesture to select any word on Android.
expect(controller.selection, const TextSelection.collapsed(offset: -1)); expect(controller.selection, const TextSelection.collapsed(offset: -1));
...@@ -6426,15 +6381,14 @@ void main() { ...@@ -6426,15 +6381,14 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pump(); await tester.pump();
expect(find.byType(FlatButton), findsNothing); expect(find.byType(FlatButton), findsNothing);
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia }));
testWidgets('force press selects word (iOS)', (WidgetTester tester) async { testWidgets('force press selects word', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: TextField( child: TextField(
controller: controller, controller: controller,
...@@ -6459,7 +6413,15 @@ void main() { ...@@ -6459,7 +6413,15 @@ void main() {
), ),
); );
await gesture.updateWithCustomEvent(PointerMoveEvent(pointer: pointerValue, position: textfieldStart + const Offset(150.0, 9.0), pressure: 0.5, pressureMin: 0, pressureMax: 1)); await gesture.updateWithCustomEvent(
PointerMoveEvent(
pointer: pointerValue,
position: textfieldStart + const Offset(150.0, 9.0),
pressure: 0.5,
pressureMin: 0,
pressureMax: 1,
),
);
// We expect the force press to select a word at the given location. // We expect the force press to select a word at the given location.
expect( expect(
controller.selection, controller.selection,
...@@ -6469,15 +6431,15 @@ void main() { ...@@ -6469,15 +6431,15 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pump(); await tester.pump();
expect(find.byType(CupertinoButton), findsNWidgets(3)); expect(find.byType(CupertinoButton), findsNWidgets(3));
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('tap on non-force-press-supported devices work (iOS)', (WidgetTester tester) async { testWidgets('tap on non-force-press-supported devices work', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure', text: 'Atwater Peel Sherbrooke Bonaventure',
); );
await tester.pumpWidget(Container(key: GlobalKey()));
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: Material( home: Material(
child: TextField( child: TextField(
controller: controller, controller: controller,
...@@ -6503,7 +6465,15 @@ void main() { ...@@ -6503,7 +6465,15 @@ void main() {
), ),
); );
await gesture.updateWithCustomEvent(PointerMoveEvent(pointer: pointerValue, position: textfieldStart + const Offset(150.0, 9.0), pressure: 0.5, pressureMin: 0, pressureMax: 1)); await gesture.updateWithCustomEvent(
PointerMoveEvent(
pointer: pointerValue,
position: textfieldStart + const Offset(150.0, 9.0),
pressure: 0.5,
pressureMin: 0,
pressureMax: 1,
),
);
await gesture.up(); await gesture.up();
// The event should fallback to a normal tap and move the cursor. // The event should fallback to a normal tap and move the cursor.
// Single taps selects the edge of the word. // Single taps selects the edge of the word.
...@@ -6515,7 +6485,10 @@ void main() { ...@@ -6515,7 +6485,10 @@ void main() {
await tester.pump(); await tester.pump();
// Single taps shouldn't trigger the toolbar. // Single taps shouldn't trigger the toolbar.
expect(find.byType(CupertinoButton), findsNothing); expect(find.byType(CupertinoButton), findsNothing);
});
// TODO(gspencergoog): Add in TargetPlatform.macOS in the line below when we figure out what global state is leaking.
// https://github.com/flutter/flutter/issues/43445
}, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
testWidgets('default TextField debugFillProperties', (WidgetTester tester) async { testWidgets('default TextField debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
...@@ -6922,7 +6895,6 @@ void main() { ...@@ -6922,7 +6895,6 @@ void main() {
}); });
testWidgets('iOS selection handles are rendered and not faded away', (WidgetTester tester) async { testWidgets('iOS selection handles are rendered and not faded away', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
const String testText = 'lorem ipsum'; const String testText = 'lorem ipsum';
final TextEditingController controller = TextEditingController(text: testText); final TextEditingController controller = TextEditingController(text: testText);
...@@ -6951,9 +6923,7 @@ void main() { ...@@ -6951,9 +6923,7 @@ void main() {
expect(left.opacity.value, equals(1.0)); expect(left.opacity.value, equals(1.0));
expect(right.opacity.value, equals(1.0)); expect(right.opacity.value, equals(1.0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null;
});
testWidgets('Tap shows handles but not toolbar', (WidgetTester tester) async { testWidgets('Tap shows handles but not toolbar', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
......
...@@ -196,6 +196,7 @@ void main() { ...@@ -196,6 +196,7 @@ void main() {
const PageTransitionsTheme pageTransitionTheme = PageTransitionsTheme( const PageTransitionsTheme pageTransitionTheme = PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{ builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
}, },
); );
......
...@@ -21,16 +21,16 @@ void main() { ...@@ -21,16 +21,16 @@ void main() {
expect(Typography(platform: TargetPlatform.fuchsia).black.title.fontFamily, 'Roboto'); expect(Typography(platform: TargetPlatform.fuchsia).black.title.fontFamily, 'Roboto');
}); });
test('Typography on iOS defaults to the correct SF font family based on size', () { // Ref: https://developer.apple.com/ios/human-interface-guidelines/visual-design/typography/
// Ref: https://developer.apple.com/ios/human-interface-guidelines/visual-design/typography/ final Matcher isDisplayFont = predicate((TextStyle s) {
final Matcher isDisplayFont = predicate((TextStyle s) { return s.fontFamily == '.SF UI Display';
return s.fontFamily == '.SF UI Display'; }, 'Uses SF Display font');
}, 'Uses SF Display font');
final Matcher isTextFont = predicate((TextStyle s) { final Matcher isTextFont = predicate((TextStyle s) {
return s.fontFamily == '.SF UI Text'; return s.fontFamily == '.SF UI Text';
}, 'Uses SF Text font'); }, 'Uses SF Text font');
test('Typography on iOS defaults to the correct SF font family based on size', () {
final Typography typography = Typography(platform: TargetPlatform.iOS); final Typography typography = Typography(platform: TargetPlatform.iOS);
for (final TextTheme textTheme in <TextTheme>[typography.black, typography.white]) { for (final TextTheme textTheme in <TextTheme>[typography.black, typography.white]) {
expect(textTheme.display4, isDisplayFont); expect(textTheme.display4, isDisplayFont);
...@@ -49,6 +49,25 @@ void main() { ...@@ -49,6 +49,25 @@ void main() {
} }
}); });
test('Typography on macOS defaults to the correct SF font family based on size', () {
final Typography typography = Typography(platform: TargetPlatform.macOS);
for (final TextTheme textTheme in <TextTheme>[typography.black, typography.white]) {
expect(textTheme.display4, isDisplayFont);
expect(textTheme.display3, isDisplayFont);
expect(textTheme.display2, isDisplayFont);
expect(textTheme.display1, isDisplayFont);
expect(textTheme.headline, isDisplayFont);
expect(textTheme.title, isDisplayFont);
expect(textTheme.subhead, isTextFont);
expect(textTheme.body2, isTextFont);
expect(textTheme.body1, isTextFont);
expect(textTheme.caption, isTextFont);
expect(textTheme.button, isTextFont);
expect(textTheme.subtitle, isTextFont);
expect(textTheme.overline, isTextFont);
}
});
testWidgets('Typography implements debugFillProperties', (WidgetTester tester) async { testWidgets('Typography implements debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
Typography( Typography(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment