Unverified Commit 98ebab58 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

Cover more test/widgets tests with leak tracking #8 (#135045)

parent c3db0209
......@@ -4,9 +4,10 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgets('Scroll flings twice in a row does not crash', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Scroll flings twice in a row does not crash', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
......
......@@ -5,9 +5,10 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgets('ScrollMetricsNotification test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ScrollMetricsNotification test', (WidgetTester tester) async {
final List<Notification> events = <Notification>[];
Widget buildFrame(double height) {
return NotificationListener<Notification>(
......@@ -62,7 +63,7 @@ void main() {
expect(events.length, 0);
});
testWidgets('Scroll notification basics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Scroll notification basics', (WidgetTester tester) async {
late ScrollNotification notification;
await tester.pumpWidget(NotificationListener<ScrollNotification>(
......@@ -103,7 +104,7 @@ void main() {
expect(end.dragDetails!.velocity, equals(Velocity.zero));
});
testWidgets('Scroll notification depth', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Scroll notification depth', (WidgetTester tester) async {
final List<Type> depth0Types = <Type>[];
final List<Type> depth1Types = <Type>[];
final List<int> depth0Values = <int>[];
......@@ -158,7 +159,7 @@ void main() {
expect(depth1Values, equals(<int>[1, 1, 1, 1, 1]));
});
testWidgets('ScrollNotifications bubble past Scaffold Material', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ScrollNotifications bubble past Scaffold Material', (WidgetTester tester) async {
final List<Type> notificationTypes = <Type>[];
await tester.pumpWidget(
......@@ -206,7 +207,7 @@ void main() {
expect(notificationTypes, equals(types));
});
testWidgets('ScrollNotificationObserver', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ScrollNotificationObserver', (WidgetTester tester) async {
late ScrollNotificationObserverState observer;
ScrollNotification? notification;
......
......@@ -5,6 +5,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
class TestScrollPhysics extends ScrollPhysics {
const TestScrollPhysics({
......@@ -339,7 +340,7 @@ FlutterError
}
});
testWidgets('PageScrollPhysics work with NestedScrollView', (WidgetTester tester) async {
testWidgetsWithLeakTracking('PageScrollPhysics work with NestedScrollView', (WidgetTester tester) async {
// Regression test for: https://github.com/flutter/flutter/issues/47850
await tester.pumpWidget(Material(
child: Directionality(
......
......@@ -4,6 +4,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
ScrollController _controller = ScrollController(
initialScrollOffset: 110.0,
......@@ -140,7 +141,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async {
}
void main() {
testWidgets("ScrollPosition jumpTo() doesn't call notifyListeners twice", (WidgetTester tester) async {
testWidgetsWithLeakTracking("ScrollPosition jumpTo() doesn't call notifyListeners twice", (WidgetTester tester) async {
int count = 0;
await tester.pumpWidget(MaterialApp(
home: ListView.builder(
......@@ -159,15 +160,22 @@ void main() {
expect(count, 1);
});
testWidgets('whether we remember our scroll position', (WidgetTester tester) async {
testWidgetsWithLeakTracking('whether we remember our scroll position', (WidgetTester tester) async {
await performTest(tester, true);
await performTest(tester, false);
});
testWidgets('scroll alignment is honored by ensureVisible', (WidgetTester tester) async {
testWidgetsWithLeakTracking('scroll alignment is honored by ensureVisible', (WidgetTester tester) async {
final List<int> items = List<int>.generate(11, (int index) => index).toList();
final List<FocusNode> nodes = List<FocusNode>.generate(11, (int index) => FocusNode(debugLabel: 'Item ${index + 1}')).toList();
addTearDown(() {
for (final FocusNode node in nodes) {
node.dispose();
}
});
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
home: ListView(
......@@ -226,7 +234,7 @@ void main() {
expect(controller.position.pixels, equals(0.0));
});
testWidgets('jumpTo recommends deferred loading', (WidgetTester tester) async {
testWidgetsWithLeakTracking('jumpTo recommends deferred loading', (WidgetTester tester) async {
int loadedWithDeferral = 0;
int buildCount = 0;
const double height = 500;
......
......@@ -5,10 +5,12 @@
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgets('Does not animate if already at target position', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Does not animate if already at target position', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
......@@ -27,8 +29,9 @@ void main() {
expect(controller.position.pixels, currentPosition);
});
testWidgets('Does not animate if already at target position within tolerance', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Does not animate if already at target position within tolerance', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
......@@ -50,8 +53,9 @@ void main() {
expect(controller.position.pixels, targetPosition);
});
testWidgets('Animates if going to a position outside of tolerance', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Animates if going to a position outside of tolerance', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
......
......@@ -4,11 +4,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'test_widgets.dart';
void main() {
testWidgets('simultaneously dispose a widget and end the scroll animation', (WidgetTester tester) async {
testWidgetsWithLeakTracking('simultaneously dispose a widget and end the scroll animation', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
......@@ -26,10 +27,11 @@ void main() {
await tester.pump(const Duration(hours: 5));
});
testWidgets('Disposing a (nested) Scrollable while holding in overscroll does not crash', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Disposing a (nested) Scrollable while holding in overscroll does not crash', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/27707.
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
final Key outerContainer = GlobalKey();
await tester.pumpWidget(
......
......@@ -5,6 +5,7 @@
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
const TextStyle testFont = TextStyle(
color: Color(0xFF00FF00),
......@@ -31,7 +32,7 @@ Future<void> pumpTest(WidgetTester tester, TargetPlatform platform) async {
const double dragOffset = 213.82;
void main() {
testWidgets('Flings on different platforms', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Flings on different platforms', (WidgetTester tester) async {
double getCurrentOffset() {
return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels;
}
......@@ -96,7 +97,7 @@ void main() {
expect(linuxResult, equals(androidResult));
});
testWidgets('fling and tap to stop', (WidgetTester tester) async {
testWidgetsWithLeakTracking('fling and tap to stop', (WidgetTester tester) async {
final List<String> log = <String>[];
await tester.pumpWidget(
Directionality(
......@@ -126,7 +127,7 @@ void main() {
expect(log, equals(<String>['tap 21', 'tap 35']));
});
testWidgets('fling and wait and tap', (WidgetTester tester) async {
testWidgetsWithLeakTracking('fling and wait and tap', (WidgetTester tester) async {
final List<String> log = <String>[];
await tester.pumpWidget(
Directionality(
......
......@@ -4,9 +4,10 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgets('GridView default control', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView default control', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
......@@ -20,7 +21,7 @@ void main() {
});
// Tests https://github.com/flutter/flutter/issues/5522
testWidgets('GridView displays correct children with nonzero padding', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView displays correct children with nonzero padding', (WidgetTester tester) async {
const EdgeInsets padding = EdgeInsets.fromLTRB(0.0, 100.0, 0.0, 0.0);
final Widget testWidget = Directionality(
......@@ -76,7 +77,7 @@ void main() {
expect(find.text('4'), findsNothing);
});
testWidgets('GridView.count() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView.count() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/9506
Widget buildFrame(int itemCount) {
return Directionality(
......
......@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
final LogicalKeyboardKey modifierKey = defaultTargetPlatform == TargetPlatform.macOS
? LogicalKeyboardKey.metaLeft
......@@ -13,8 +14,9 @@ final LogicalKeyboardKey modifierKey = defaultTargetPlatform == TargetPlatform.m
void main() {
group('ScrollableDetails', (){
final ScrollController controller = ScrollController();
test('copyWith / == / hashCode', () {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
final ScrollableDetails details = ScrollableDetails(
direction: AxisDirection.down,
controller: controller,
......@@ -42,6 +44,8 @@ void main() {
});
test('toString', (){
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
const ScrollableDetails bareDetails = ScrollableDetails(
direction: AxisDirection.right,
);
......@@ -86,8 +90,9 @@ void main() {
});
});
testWidgets("Keyboard scrolling doesn't happen if scroll physics are set to NeverScrollableScrollPhysics", (WidgetTester tester) async {
testWidgetsWithLeakTracking("Keyboard scrolling doesn't happen if scroll physics are set to NeverScrollableScrollPhysics", (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.fuchsia),
......@@ -152,8 +157,9 @@ void main() {
);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgets('Vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.fuchsia),
......@@ -223,8 +229,9 @@ void main() {
);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgets('Horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.fuchsia),
......@@ -283,8 +290,9 @@ void main() {
);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgets('Horizontal scrollables are scrolled the correct direction in RTL locales.', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Horizontal scrollables are scrolled the correct direction in RTL locales.', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.fuchsia),
......@@ -346,9 +354,11 @@ void main() {
);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgets('Reversed vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Reversed vertical scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
final FocusNode focusNode = FocusNode(debugLabel: 'SizedBox');
addTearDown(focusNode.dispose);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.fuchsia),
......@@ -420,9 +430,11 @@ void main() {
);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgets('Reversed horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Reversed horizontal scrollables are scrolled when activated via keyboard.', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
final FocusNode focusNode = FocusNode(debugLabel: 'SizedBox');
addTearDown(focusNode.dispose);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.fuchsia),
......@@ -479,8 +491,9 @@ void main() {
await tester.pumpAndSettle();
}, variant: KeySimulatorTransitModeVariant.all());
testWidgets('Custom scrollables with a center sliver are scrolled when activated via keyboard.', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Custom scrollables with a center sliver are scrolled when activated via keyboard.', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
final List<String> items = List<String>.generate(20, (int index) => 'Item $index');
await tester.pumpWidget(
MaterialApp(
......@@ -550,7 +563,7 @@ void main() {
);
}, variant: KeySimulatorTransitModeVariant.all());
testWidgets('Can scroll using intents only', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can scroll using intents only', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: ListView(
......
......@@ -4,6 +4,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
test('Can dispose ScrollPosition when hasPixels is false', () {
......@@ -18,9 +19,10 @@ void main() {
position.dispose(); // Should not throw/assert.
});
testWidgets('scrollable in hidden overlay does not crash when unhidden', (WidgetTester tester) async {
testWidgetsWithLeakTracking('scrollable in hidden overlay does not crash when unhidden', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/44269.
final TabController controller = TabController(vsync: const TestVSync(), length: 1);
addTearDown(controller.dispose);
final OverlayEntry entry1 = OverlayEntry(
maintainState: true,
......
......@@ -5,11 +5,12 @@
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
const List<int> items = <int>[0, 1, 2, 3, 4, 5];
void main() {
testWidgets('Tap item after scroll - horizontal', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Tap item after scroll - horizontal', (WidgetTester tester) async {
final List<int> tapped = <int>[];
await tester.pumpWidget(
Directionality(
......@@ -51,7 +52,7 @@ void main() {
expect(tapped, equals(<int>[2]));
});
testWidgets('Tap item after scroll - vertical', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Tap item after scroll - vertical', (WidgetTester tester) async {
final List<int> tapped = <int>[];
await tester.pumpWidget(
Directionality(
......@@ -94,7 +95,7 @@ void main() {
expect(tapped, equals(<int>[1])); // the center of the third item is off-screen so it shouldn't get hit
});
testWidgets('Padding scroll anchor start', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Padding scroll anchor start', (WidgetTester tester) async {
final List<int> tapped = <int>[];
await tester.pumpWidget(
......@@ -126,7 +127,7 @@ void main() {
expect(tapped, equals(<int>[0, 1, 1]));
});
testWidgets('Padding scroll anchor end', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Padding scroll anchor end', (WidgetTester tester) async {
final List<int> tapped = <int>[];
await tester.pumpWidget(
......@@ -159,7 +160,7 @@ void main() {
expect(tapped, equals(<int>[0, 1, 1]));
});
testWidgets('Tap immediately following clamped overscroll', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Tap immediately following clamped overscroll', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/5709
final List<int> tapped = <int>[];
......
......@@ -4,6 +4,7 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
class ScrollPositionListener extends StatefulWidget {
const ScrollPositionListener({ super.key, required this.child, required this.log});
......@@ -123,9 +124,10 @@ class TestChildState extends State<TestChild> {
}
void main() {
testWidgets('Scrollable.of() dependent rebuilds when Scrollable position changes', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Scrollable.of() dependent rebuilds when Scrollable position changes', (WidgetTester tester) async {
late String logValue;
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
// Changing the SingleChildScrollView's physics causes the
// ScrollController's ScrollPosition to be rebuilt.
......@@ -163,7 +165,7 @@ void main() {
expect(logValue, 'listener 400.0');
});
testWidgets('Scrollable.of() is possible using ScrollNotification context', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Scrollable.of() is possible using ScrollNotification context', (WidgetTester tester) async {
late ScrollNotification notification;
await tester.pumpWidget(NotificationListener<ScrollNotification>(
......@@ -183,9 +185,11 @@ void main() {
expect(Scrollable.of(notification.context!), equals(scrollableElement.state));
});
testWidgets('Static Scrollable methods can target a specific axis', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Static Scrollable methods can target a specific axis', (WidgetTester tester) async {
final TestScrollController horizontalController = TestScrollController(deferLoading: true);
addTearDown(horizontalController.dispose);
final TestScrollController verticalController = TestScrollController(deferLoading: false);
addTearDown(verticalController.dispose);
late final AxisDirection foundAxisDirection;
late final bool foundRecommendation;
......@@ -218,7 +222,7 @@ void main() {
expect(foundRecommendation, isTrue);
});
testWidgets('Axis targeting scrollables establishes the correct dependencies', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Axis targeting scrollables establishes the correct dependencies', (WidgetTester tester) async {
final GlobalKey<TestScrollableState> verticalKey = GlobalKey<TestScrollableState>();
final GlobalKey<TestChildState> childKey = GlobalKey<TestChildState>();
......@@ -237,12 +241,15 @@ void main() {
expect(verticalKey.currentState!.dependenciesChanged, 1);
expect(childKey.currentState!.dependenciesChanged, 1);
final ScrollController controller = ScrollController();
addTearDown(controller.dispose);
// Change the horizontal ScrollView, adding a controller
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
controller: ScrollController(),
controller: controller,
child: TestScrollable(
key: verticalKey,
child: TestChild(key: childKey),
......
......@@ -5,9 +5,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgets('CustomScrollView restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('CustomScrollView restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: CustomScrollView(
......@@ -33,7 +34,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('ListView restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListView restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: ListView(
......@@ -53,7 +54,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('ListView.builder restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListView.builder restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: ListView.builder(
......@@ -70,7 +71,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('ListView.separated restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListView.separated restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: ListView.separated(
......@@ -89,7 +90,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('ListView.custom restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListView.custom restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: ListView.custom(
......@@ -111,7 +112,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('GridView restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: GridView(
......@@ -132,7 +133,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('GridView.builder restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView.builder restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: GridView.builder(
......@@ -150,7 +151,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('GridView.custom restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView.custom restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: GridView.custom(
......@@ -173,7 +174,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('GridView.count restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView.count restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: GridView.count(
......@@ -194,7 +195,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('GridView.extent restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('GridView.extent restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: GridView.extent(
......@@ -215,7 +216,7 @@ void main() {
await restoreScrollAndVerify(tester);
});
testWidgets('SingleChildScrollView restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SingleChildScrollView restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: SingleChildScrollView(
......@@ -262,7 +263,7 @@ void main() {
expect(tester.getTopLeft(find.text('Tile 1')), const Offset(0, -475));
});
testWidgets('PageView restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('PageView restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: PageView(
......@@ -278,7 +279,7 @@ void main() {
await pageViewScrollAndRestore(tester);
});
testWidgets('PageView.builder restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('PageView.builder restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: PageView.builder(
......@@ -294,7 +295,7 @@ void main() {
await pageViewScrollAndRestore(tester);
});
testWidgets('PageView.custom restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('PageView.custom restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: PageView.custom(
......@@ -315,7 +316,7 @@ void main() {
await pageViewScrollAndRestore(tester);
});
testWidgets('ListWheelScrollView restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListWheelScrollView restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: ListWheelScrollView(
......@@ -332,7 +333,7 @@ void main() {
await restoreScrollAndVerify(tester, secondOffset: 542);
});
testWidgets('ListWheelScrollView.useDelegate restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListWheelScrollView.useDelegate restoration', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: ListWheelScrollView.useDelegate(
......@@ -354,7 +355,7 @@ void main() {
await restoreScrollAndVerify(tester, secondOffset: 542);
});
testWidgets('NestedScrollView restoration', (WidgetTester tester) async {
testWidgetsWithLeakTracking('NestedScrollView restoration', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestHarness(
......@@ -422,7 +423,7 @@ void main() {
expect(find.text('Tile 10'), findsOneWidget);
});
testWidgets('RestorationData is flushed even if no frame is scheduled', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RestorationData is flushed even if no frame is scheduled', (WidgetTester tester) async {
await tester.pumpWidget(
TestHarness(
child: ListView(
......
......@@ -6,6 +6,7 @@ import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'semantics_tester.dart';
......@@ -16,7 +17,7 @@ void main() {
debugResetSemanticsIdCounter();
});
testWidgets('scrollable exposes the correct semantic actions', (WidgetTester tester) async {
testWidgetsWithLeakTracking('scrollable exposes the correct semantic actions', (WidgetTester tester) async {
semantics = SemanticsTester(tester);
await tester.pumpWidget(
Directionality(
......@@ -42,7 +43,7 @@ void main() {
semantics.dispose();
});
testWidgets('showOnScreen works in scrollable', (WidgetTester tester) async {
testWidgetsWithLeakTracking('showOnScreen works in scrollable', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
const double kItemHeight = 40.0;
......@@ -57,6 +58,7 @@ void main() {
final ScrollController scrollController = ScrollController(
initialScrollOffset: kItemHeight / 2,
);
addTearDown(scrollController.dispose);
await tester.pumpWidget(
Directionality(
......@@ -80,7 +82,7 @@ void main() {
semantics.dispose();
});
testWidgets('showOnScreen works with pinned app bar and sliver list', (WidgetTester tester) async {
testWidgetsWithLeakTracking('showOnScreen works with pinned app bar and sliver list', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
const double kItemHeight = 100.0;
......@@ -96,6 +98,7 @@ void main() {
final ScrollController scrollController = ScrollController(
initialScrollOffset: kItemHeight / 2,
);
addTearDown(scrollController.dispose);
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
......@@ -142,7 +145,7 @@ void main() {
semantics.dispose();
});
testWidgets('showOnScreen works with pinned app bar and individual slivers', (WidgetTester tester) async {
testWidgetsWithLeakTracking('showOnScreen works with pinned app bar and individual slivers', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
const double kItemHeight = 100.0;
......@@ -166,6 +169,7 @@ void main() {
final ScrollController scrollController = ScrollController(
initialScrollOffset: 2.5 * kItemHeight,
);
addTearDown(scrollController.dispose);
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
......@@ -210,7 +214,7 @@ void main() {
semantics.dispose();
});
testWidgets('correct scrollProgress', (WidgetTester tester) async {
testWidgetsWithLeakTracking('correct scrollProgress', (WidgetTester tester) async {
semantics = SemanticsTester(tester);
await tester.pumpWidget(Directionality(
......@@ -253,7 +257,7 @@ void main() {
semantics.dispose();
});
testWidgets('correct scrollProgress for unbound', (WidgetTester tester) async {
testWidgetsWithLeakTracking('correct scrollProgress for unbound', (WidgetTester tester) async {
semantics = SemanticsTester(tester);
await tester.pumpWidget(Directionality(
......@@ -303,7 +307,7 @@ void main() {
semantics.dispose();
});
testWidgets('Semantics tree is populated mid-scroll', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics tree is populated mid-scroll', (WidgetTester tester) async {
semantics = SemanticsTester(tester);
final List<Widget> children = List<Widget>.generate(80, (int i) => SizedBox(
......@@ -328,7 +332,7 @@ void main() {
semantics.dispose();
});
testWidgets('Can toggle semantics on, off, on without crash', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can toggle semantics on, off, on without crash', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
......@@ -434,7 +438,7 @@ void main() {
});
testWidgets('brings item above leading edge to leading edge', (WidgetTester tester) async {
testWidgetsWithLeakTracking('brings item above leading edge to leading edge', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
await tester.pumpWidget(widgetUnderTest);
......@@ -450,7 +454,7 @@ void main() {
semantics.dispose();
});
testWidgets('brings item below trailing edge to trailing edge', (WidgetTester tester) async {
testWidgetsWithLeakTracking('brings item below trailing edge to trailing edge', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
await tester.pumpWidget(widgetUnderTest);
......@@ -466,7 +470,7 @@ void main() {
semantics.dispose();
});
testWidgets('does not change position of items already fully on-screen', (WidgetTester tester) async {
testWidgetsWithLeakTracking('does not change position of items already fully on-screen', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
await tester.pumpWidget(widgetUnderTest);
......@@ -536,10 +540,13 @@ void main() {
),
),
);
});
tearDown(() {
scrollController.dispose();
});
testWidgets('brings item above leading edge to leading edge', (WidgetTester tester) async {
testWidgetsWithLeakTracking('brings item above leading edge to leading edge', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
await tester.pumpWidget(widgetUnderTest);
......@@ -555,7 +562,7 @@ void main() {
semantics.dispose();
});
testWidgets('brings item below trailing edge to trailing edge', (WidgetTester tester) async {
testWidgetsWithLeakTracking('brings item below trailing edge to trailing edge', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
await tester.pumpWidget(widgetUnderTest);
......@@ -571,7 +578,7 @@ void main() {
semantics.dispose();
});
testWidgets('does not change position of items already fully on-screen', (WidgetTester tester) async {
testWidgetsWithLeakTracking('does not change position of items already fully on-screen', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
await tester.pumpWidget(widgetUnderTest);
......@@ -589,7 +596,7 @@ void main() {
});
testWidgets('transform of inner node from useTwoPaneSemantics scrolls correctly with nested scrollables', (WidgetTester tester) async {
testWidgetsWithLeakTracking('transform of inner node from useTwoPaneSemantics scrolls correctly with nested scrollables', (WidgetTester tester) async {
semantics = SemanticsTester(tester); // enables semantics tree generation
// Context: https://github.com/flutter/flutter/issues/61631
......
......@@ -5,13 +5,17 @@
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'semantics_tester.dart';
void main() {
testWidgets('Traversal Order of SliverList', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Traversal Order of SliverList', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final ScrollController controller = ScrollController(initialScrollOffset: 3000.0);
addTearDown(controller.dispose);
final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
return SizedBox(
height: 200.0,
......@@ -38,7 +42,7 @@ void main() {
child: MediaQuery(
data: const MediaQueryData(),
child: CustomScrollView(
controller: ScrollController(initialScrollOffset: 3000.0),
controller: controller,
semanticChildCount: 30,
slivers: <Widget>[
SliverList(
......@@ -182,9 +186,12 @@ void main() {
semantics.dispose();
});
testWidgets('Traversal Order of SliverFixedExtentList', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Traversal Order of SliverFixedExtentList', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final ScrollController controller = ScrollController(initialScrollOffset: 3000.0);
addTearDown(controller.dispose);
final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
return SizedBox(
height: 200.0,
......@@ -211,7 +218,7 @@ void main() {
child: MediaQuery(
data: const MediaQueryData(),
child: CustomScrollView(
controller: ScrollController(initialScrollOffset: 3000.0),
controller: controller,
slivers: <Widget>[
SliverFixedExtentList(
itemExtent: 200.0,
......@@ -321,9 +328,12 @@ void main() {
semantics.dispose();
});
testWidgets('Traversal Order of SliverGrid', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Traversal Order of SliverGrid', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final ScrollController controller = ScrollController(initialScrollOffset: 1600.0);
addTearDown(controller.dispose);
final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
return SizedBox(
height: 200.0,
......@@ -338,7 +348,7 @@ void main() {
child: MediaQuery(
data: const MediaQueryData(),
child: CustomScrollView(
controller: ScrollController(initialScrollOffset: 1600.0),
controller: controller,
slivers: <Widget>[
SliverGrid.count(
crossAxisCount: 2,
......@@ -449,9 +459,12 @@ void main() {
semantics.dispose();
});
testWidgets('Traversal Order of List of individual slivers', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Traversal Order of List of individual slivers', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final ScrollController controller = ScrollController(initialScrollOffset: 3000.0);
addTearDown(controller.dispose);
final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
return SliverToBoxAdapter(
child: SizedBox(
......@@ -480,7 +493,7 @@ void main() {
child: MediaQuery(
data: const MediaQueryData(),
child: CustomScrollView(
controller: ScrollController(initialScrollOffset: 3000.0),
controller: controller,
slivers: listChildren,
),
),
......@@ -585,9 +598,12 @@ void main() {
semantics.dispose();
});
testWidgets('Traversal Order of in a SingleChildScrollView', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Traversal Order of in a SingleChildScrollView', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final ScrollController controller = ScrollController(initialScrollOffset: 3000.0);
addTearDown(controller.dispose);
final List<Widget> listChildren = List<Widget>.generate(30, (int i) {
return SizedBox(
height: 200.0,
......@@ -614,7 +630,7 @@ void main() {
child: MediaQuery(
data: const MediaQueryData(),
child: SingleChildScrollView(
controller: ScrollController(initialScrollOffset: 3000.0),
controller: controller,
child: Column(
children: listChildren,
),
......@@ -671,7 +687,7 @@ void main() {
semantics.dispose();
});
testWidgets('Traversal Order with center child', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Traversal Order with center child', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(Semantics(
......
......@@ -9,6 +9,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'package:web/web.dart' as web;
extension on web.HTMLCollection {
......@@ -59,8 +60,9 @@ void main() {
expect(foundStyle, isTrue);
});
testWidgets('right click can trigger select word', (WidgetTester tester) async {
testWidgetsWithLeakTracking('right click can trigger select word', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
final UniqueKey spy = UniqueKey();
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