Unverified Commit d5e7f407 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Test cover some leak-free code. (#130543)

parent 93919232
......@@ -5,6 +5,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../foundation/leak_tracking.dart';
Widget wrap({ required Widget child, ThemeData? theme }) {
return MaterialApp(
theme: theme,
......@@ -15,7 +17,7 @@ Widget wrap({ required Widget child, ThemeData? theme }) {
}
void main() {
testWidgets('ExpandIcon test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon test', (WidgetTester tester) async {
bool expanded = false;
IconTheme iconTheme;
......@@ -73,7 +75,7 @@ void main() {
expect(iconTheme.data.color, equals(Colors.white60));
});
testWidgets('ExpandIcon disabled', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon disabled', (WidgetTester tester) async {
IconTheme iconTheme;
// Light mode test
await tester.pumpWidget(wrap(
......@@ -96,7 +98,7 @@ void main() {
expect(iconTheme.data.color, equals(Colors.white38));
});
testWidgets('ExpandIcon test isExpanded does not trigger callback', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon test isExpanded does not trigger callback', (WidgetTester tester) async {
bool expanded = false;
await tester.pumpWidget(wrap(
......@@ -119,7 +121,7 @@ void main() {
expect(expanded, isFalse);
});
testWidgets('ExpandIcon is rotated initially if isExpanded is true on first build', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon is rotated initially if isExpanded is true on first build', (WidgetTester tester) async {
bool expanded = true;
await tester.pumpWidget(wrap(
......@@ -134,7 +136,7 @@ void main() {
expect(rotation.turns.value, 0.5);
});
testWidgets('ExpandIcon default size is 24', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon default size is 24', (WidgetTester tester) async {
final ExpandIcon expandIcon = ExpandIcon(
onPressed: (bool isExpanded) {},
);
......@@ -147,7 +149,7 @@ void main() {
expect(icon.size, 24);
});
testWidgets('ExpandIcon has the correct given size', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon has the correct given size', (WidgetTester tester) async {
ExpandIcon expandIcon = ExpandIcon(
size: 36,
onPressed: (bool isExpanded) {},
......@@ -173,7 +175,7 @@ void main() {
expect(icon.size, 48);
});
testWidgets('ExpandIcon has correct semantic hints', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon has correct semantic hints', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations();
await tester.pumpWidget(wrap(
......@@ -210,7 +212,7 @@ void main() {
handle.dispose();
});
testWidgets('ExpandIcon uses custom icon color and expanded icon color', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon uses custom icon color and expanded icon color', (WidgetTester tester) async {
bool expanded = false;
IconTheme iconTheme;
......@@ -271,7 +273,7 @@ void main() {
expect(iconTheme.data.color, equals(Colors.indigo));
});
testWidgets('ExpandIcon uses custom disabled icon color', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ExpandIcon uses custom disabled icon color', (WidgetTester tester) async {
IconTheme iconTheme;
await tester.pumpWidget(wrap(
......
......@@ -11,10 +11,11 @@ import 'package:flutter/material.dart';
import 'package:flutter/src/foundation/constants.dart';
import 'package:flutter_test/flutter_test.dart';
import '../foundation/leak_tracking.dart';
import '../rendering/mock_canvas.dart';
void main() {
testWidgets('InkSparkle in a Button compiles and does not crash', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InkSparkle in a Button compiles and does not crash', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Center(
......@@ -34,7 +35,7 @@ void main() {
skip: kIsWeb, // [intended] shaders are not yet supported for web.
);
testWidgets('InkSparkle default splashFactory paints with drawRect when bounded', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InkSparkle default splashFactory paints with drawRect when bounded', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Center(
......@@ -65,7 +66,7 @@ void main() {
skip: kIsWeb, // [intended] shaders are not yet supported for web.
);
testWidgets('InkSparkle default splashFactory paints with drawPaint when unbounded', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InkSparkle default splashFactory paints with drawPaint when unbounded', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Center(
......@@ -92,19 +93,19 @@ void main() {
// Goldens //
/////////////
testWidgets('InkSparkle renders with sparkles when top left of button is tapped', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InkSparkle renders with sparkles when top left of button is tapped', (WidgetTester tester) async {
await _runTest(tester, 'top_left', 0.2);
},
skip: kIsWeb, // [intended] shaders are not yet supported for web.
);
testWidgets('InkSparkle renders with sparkles when center of button is tapped', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InkSparkle renders with sparkles when center of button is tapped', (WidgetTester tester) async {
await _runTest(tester, 'center', 0.5);
},
skip: kIsWeb, // [intended] shaders are not yet supported for web.
);
testWidgets('InkSparkle renders with sparkles when bottom right of button is tapped', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InkSparkle renders with sparkles when bottom right of button is tapped', (WidgetTester tester) async {
await _runTest(tester, 'bottom_right', 0.8);
},
skip: kIsWeb, // [intended] shaders are not yet supported for web.
......
......@@ -14,10 +14,11 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../foundation/leak_tracking.dart';
import '../rendering/mock_canvas.dart';
void main() {
testWidgets('Navigation bar updates destinations when tapped', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Navigation bar updates destinations when tapped', (WidgetTester tester) async {
int mutatedIndex = -1;
final Widget widget = _buildWidget(
NavigationBar(
......@@ -49,7 +50,7 @@ void main() {
expect(mutatedIndex, 0);
});
testWidgets('NavigationBar can update background color', (WidgetTester tester) async {
testWidgetsWithLeakTracking('NavigationBar can update background color', (WidgetTester tester) async {
const Color color = Colors.yellow;
await tester.pumpWidget(
......@@ -74,7 +75,7 @@ void main() {
expect(_getMaterial(tester).color, equals(color));
});
testWidgets('NavigationBar can update elevation', (WidgetTester tester) async {
testWidgetsWithLeakTracking('NavigationBar can update elevation', (WidgetTester tester) async {
const double elevation = 42.0;
await tester.pumpWidget(
......@@ -99,7 +100,7 @@ void main() {
expect(_getMaterial(tester).elevation, equals(elevation));
});
testWidgets('NavigationBar adds bottom padding to height', (WidgetTester tester) async {
testWidgetsWithLeakTracking('NavigationBar adds bottom padding to height', (WidgetTester tester) async {
const double bottomPadding = 40.0;
await tester.pumpWidget(
......@@ -148,7 +149,7 @@ void main() {
expect(tester.getSize(find.byType(NavigationBar)).height, expectedHeight);
});
testWidgets('NavigationBar respects the notch/system navigation bar in landscape mode', (WidgetTester tester) async {
testWidgetsWithLeakTracking('NavigationBar respects the notch/system navigation bar in landscape mode', (WidgetTester tester) async {
const double safeAreaPadding = 40.0;
Widget navigationBar() {
return NavigationBar(
......@@ -246,7 +247,7 @@ void main() {
);
});
testWidgets('Material2 - NavigationBar uses proper defaults when no parameters are given', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material2 - NavigationBar uses proper defaults when no parameters are given', (WidgetTester tester) async {
// M2 settings that were hand coded.
await tester.pumpWidget(
_buildWidget(
......@@ -275,7 +276,7 @@ void main() {
expect(_getIndicatorDecoration(tester)?.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)));
});
testWidgets('Material3 - NavigationBar uses proper defaults when no parameters are given', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material3 - NavigationBar uses proper defaults when no parameters are given', (WidgetTester tester) async {
// M3 settings from the token database.
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
......@@ -305,7 +306,7 @@ void main() {
expect(_getIndicatorDecoration(tester)?.shape, const StadiumBorder());
});
testWidgets('Material2 - NavigationBar shows tooltips with text scaling', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material2 - NavigationBar shows tooltips with text scaling', (WidgetTester tester) async {
const String label = 'A';
Widget buildApp({ required double textScaleFactor }) {
......@@ -364,7 +365,7 @@ void main() {
expect(tester.getSize(find.text(label).last), Size(defaultTooltipSize.width * 4, defaultTooltipSize.height * 4));
});
testWidgets('Material3 - NavigationBar shows tooltips with text scaling', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material3 - NavigationBar shows tooltips with text scaling', (WidgetTester tester) async {
const String label = 'A';
Widget buildApp({ required double textScaleFactor }) {
......@@ -430,7 +431,7 @@ void main() {
}
});
testWidgets('Custom tooltips in NavigationBarDestination', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Custom tooltips in NavigationBarDestination', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
......@@ -470,7 +471,7 @@ void main() {
});
testWidgets('Navigation bar semantics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Navigation bar semantics', (WidgetTester tester) async {
Widget widget({int selectedIndex = 0}) {
return _buildWidget(
NavigationBar(
......@@ -534,7 +535,7 @@ void main() {
);
});
testWidgets('Navigation bar semantics with some labels hidden', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Navigation bar semantics with some labels hidden', (WidgetTester tester) async {
Widget widget({int selectedIndex = 0}) {
return _buildWidget(
NavigationBar(
......@@ -599,7 +600,7 @@ void main() {
);
});
testWidgets('Navigation bar does not grow with text scale factor', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Navigation bar does not grow with text scale factor', (WidgetTester tester) async {
const int animationMilliseconds = 800;
Widget widget({double textScaleFactor = 1}) {
......@@ -632,7 +633,7 @@ void main() {
expect(newHeight, equals(initialHeight));
});
testWidgets('Material3 - Navigation indicator renders ripple', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material3 - Navigation indicator renders ripple', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/116751.
int selectedIndex = 0;
......@@ -833,7 +834,7 @@ void main() {
);
});
testWidgets('Material3 - Navigation indicator ripple golden test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material3 - Navigation indicator ripple golden test', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/117420.
Widget buildWidget({ NavigationDestinationLabelBehavior? labelBehavior }) {
......@@ -890,7 +891,7 @@ void main() {
await expectLater(find.byType(NavigationBar), matchesGoldenFile('indicator_onlyShowSelected_unselected_m3.png'));
});
testWidgets('Navigation indicator scale transform', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Navigation indicator scale transform', (WidgetTester tester) async {
int selectedIndex = 0;
Widget buildNavigationBar() {
......@@ -941,7 +942,7 @@ void main() {
expect(transform.getColumn(0)[0], 1.0);
});
testWidgets('Material3 - Navigation destination updates indicator color and shape', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material3 - Navigation destination updates indicator color and shape', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
const Color color = Color(0xff0000ff);
const ShapeBorder shape = RoundedRectangleBorder();
......@@ -987,7 +988,7 @@ void main() {
// support is deprecated and the APIs are removed, these tests
// can be deleted.
testWidgets('Material2 - Navigation destination updates indicator color and shape', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material2 - Navigation destination updates indicator color and shape', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: false);
const Color color = Color(0xff0000ff);
const ShapeBorder shape = RoundedRectangleBorder();
......@@ -1031,7 +1032,7 @@ void main() {
expect(_getIndicatorDecoration(tester)?.shape, shape);
});
testWidgets('Material2 - Navigation indicator renders ripple', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material2 - Navigation indicator renders ripple', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/116751.
int selectedIndex = 0;
......@@ -1232,7 +1233,7 @@ void main() {
);
});
testWidgets('Material2 - Navigation indicator ripple golden test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Material2 - Navigation indicator ripple golden test', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/117420.
Widget buildWidget({ NavigationDestinationLabelBehavior? labelBehavior }) {
......@@ -1289,7 +1290,7 @@ void main() {
await expectLater(find.byType(NavigationBar), matchesGoldenFile('indicator_onlyShowSelected_unselected_m2.png'));
});
testWidgets('Destination icon does not rebuild when tapped', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Destination icon does not rebuild when tapped', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/122811.
Widget buildNavigationBar() {
......
......@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import '../foundation/leak_tracking.dart';
void main() {
// Pumps and ensures that the BottomSheet animates non-linearly.
Future<void> checkNonLinearAnimation(WidgetTester tester) async {
......@@ -95,7 +97,7 @@ void main() {
await tester.pumpWidget(buildFrame(const Text('I love Flutter!')));
});
testWidgets('Verify that a BottomSheet can be rebuilt with ScaffoldFeatureController.setState()', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify that a BottomSheet can be rebuilt with ScaffoldFeatureController.setState()', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
int buildCount = 0;
......@@ -122,7 +124,7 @@ void main() {
expect(buildCount, equals(2));
});
testWidgets('Verify that a persistent BottomSheet cannot be dismissed', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify that a persistent BottomSheet cannot be dismissed', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: const Center(child: Text('body')),
......@@ -153,7 +155,7 @@ void main() {
expect(find.text('Two'), findsOneWidget);
});
testWidgets('Verify that a scrollable BottomSheet can be dismissed', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify that a scrollable BottomSheet can be dismissed', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(MaterialApp(
......@@ -185,7 +187,7 @@ void main() {
expect(find.text('Two'), findsNothing);
});
testWidgets('Verify DraggableScrollableSheet.shouldCloseOnMinExtent == false prevents dismissal', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify DraggableScrollableSheet.shouldCloseOnMinExtent == false prevents dismissal', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(MaterialApp(
......@@ -223,7 +225,7 @@ void main() {
expect(find.text('Two'), findsOneWidget);
});
testWidgets('Verify that a BottomSheet animates non-linearly', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify that a BottomSheet animates non-linearly', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(MaterialApp(
......@@ -297,7 +299,7 @@ void main() {
expect(find.text('Two'), findsNothing);
});
testWidgets('Verify that a persistent BottomSheet can fling up and hide the fab', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify that a persistent BottomSheet can fling up and hide the fab', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
......@@ -408,7 +410,7 @@ void main() {
expect(find.text('Item 22'), findsNothing);
});
testWidgets('Verify that a scrollable BottomSheet hides the fab when scrolled up', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify that a scrollable BottomSheet hides the fab when scrolled up', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(MaterialApp(
......@@ -462,7 +464,7 @@ void main() {
expect(find.byType(FloatingActionButton).hitTestable(), findsNothing);
});
testWidgets('showBottomSheet()', (WidgetTester tester) async {
testWidgetsWithLeakTracking('showBottomSheet()', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
......@@ -486,7 +488,7 @@ void main() {
expect(buildCount, equals(1));
});
testWidgets('Scaffold removes top MediaQuery padding', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Scaffold removes top MediaQuery padding', (WidgetTester tester) async {
late BuildContext scaffoldContext;
late BuildContext bottomSheetContext;
......@@ -588,7 +590,7 @@ void main() {
});
// Regression test for https://github.com/flutter/flutter/issues/71435
testWidgets(
testWidgetsWithLeakTracking(
'Scaffold.bottomSheet should be updated without creating a new RO'
' when the new widget has the same key and type.',
(WidgetTester tester) async {
......@@ -612,7 +614,7 @@ void main() {
},
);
testWidgets('Verify that visual properties are passed through', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Verify that visual properties are passed through', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
const Color color = Colors.pink;
const double elevation = 9.0;
......@@ -647,7 +649,7 @@ void main() {
expect(bottomSheet.clipBehavior, clipBehavior);
});
testWidgets('PersistentBottomSheetController.close dismisses the bottom sheet', (WidgetTester tester) async {
testWidgetsWithLeakTracking('PersistentBottomSheetController.close dismisses the bottom sheet', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
......
......@@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import '../foundation/leak_tracking.dart';
import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
......@@ -22,7 +23,7 @@ Widget boilerplate({required Widget child}) {
void main() {
testWidgets('SegmentedButton is built with Material of type MaterialType.transparency', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SegmentedButton is built with Material of type MaterialType.transparency', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
......@@ -330,7 +331,7 @@ testWidgets('SegmentedButton shows checkboxes for selected segments', (WidgetTes
});
testWidgets('SegmentedButtons have correct semantics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SegmentedButtons have correct semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
......@@ -409,7 +410,7 @@ testWidgets('SegmentedButton shows checkboxes for selected segments', (WidgetTes
});
testWidgets('Multi-select SegmentedButtons have correct semantics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Multi-select SegmentedButtons have correct semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
......@@ -486,7 +487,7 @@ testWidgets('SegmentedButton shows checkboxes for selected segments', (WidgetTes
semantics.dispose();
});
testWidgets('SegmentedButton default overlayColor and foregroundColor resolve pressed state', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SegmentedButton default overlayColor and foregroundColor resolve pressed state', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
......@@ -534,7 +535,7 @@ testWidgets('SegmentedButton shows checkboxes for selected segments', (WidgetTes
expect(material.textStyle?.color, theme.colorScheme.onSurface);
});
testWidgets('SegmentedButton has no tooltips by default', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SegmentedButton has no tooltips by default', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
......@@ -558,7 +559,7 @@ testWidgets('SegmentedButton shows checkboxes for selected segments', (WidgetTes
expect(find.byType(Tooltip), findsNothing);
});
testWidgets('SegmentedButton has correct tooltips', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SegmentedButton has correct tooltips', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
......
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