Unverified Commit 56cbf3e1 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

Cover more test/widgets tests with leak tracking #5 (#134869)

parent abf8361a
......@@ -1976,9 +1976,7 @@ void main() {
);
expect(controller.value, <MaterialState>{MaterialState.disabled});
expect(count, 1);
},
leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(),
);
});
}
......
......@@ -2544,7 +2544,6 @@ void main() {
});
testWidgetsWithLeakTracking('Should have only one SnackBar during back swipe navigation',
leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(),
(WidgetTester tester) async {
const String snackBarText = 'hello snackbar';
const Key snackTarget = Key('snack-target');
......
......@@ -8,11 +8,12 @@ import 'package:flutter/gestures.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 'gesture_utils.dart';
void main() {
testWidgets('Events bubble up the tree', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Events bubble up the tree', (WidgetTester tester) async {
final List<String> log = <String>[];
await tester.pumpWidget(
......@@ -46,7 +47,7 @@ void main() {
]));
});
testWidgets('Detects hover events from touch devices', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Detects hover events from touch devices', (WidgetTester tester) async {
final List<String> log = <String>[];
await tester.pumpWidget(
......@@ -74,7 +75,7 @@ void main() {
});
group('transformed events', () {
testWidgets('simple offset for touch/signal', (WidgetTester tester) async {
testWidgetsWithLeakTracking('simple offset for touch/signal', (WidgetTester tester) async {
final List<PointerEvent> events = <PointerEvent>[];
final Key key = UniqueKey();
......@@ -145,7 +146,7 @@ void main() {
expect(events.single.transform, expectedTransform);
});
testWidgets('scaled for touch/signal', (WidgetTester tester) async {
testWidgetsWithLeakTracking('scaled for touch/signal', (WidgetTester tester) async {
final List<PointerEvent> events = <PointerEvent>[];
final Key key = UniqueKey();
......@@ -222,7 +223,7 @@ void main() {
expect(events.single.transform, expectedTransform);
});
testWidgets('scaled and offset for touch/signal', (WidgetTester tester) async {
testWidgetsWithLeakTracking('scaled and offset for touch/signal', (WidgetTester tester) async {
final List<PointerEvent> events = <PointerEvent>[];
final Key key = UniqueKey();
......@@ -300,7 +301,7 @@ void main() {
expect(events.single.transform, expectedTransform);
});
testWidgets('rotated for touch/signal', (WidgetTester tester) async {
testWidgetsWithLeakTracking('rotated for touch/signal', (WidgetTester tester) async {
final List<PointerEvent> events = <PointerEvent>[];
final Key key = UniqueKey();
......@@ -378,9 +379,12 @@ void main() {
});
});
testWidgets("RenderPointerListener's debugFillProperties when default", (WidgetTester tester) async {
testWidgetsWithLeakTracking("RenderPointerListener's debugFillProperties when default", (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
RenderPointerListener().debugFillProperties(builder);
final RenderPointerListener renderListener = RenderPointerListener();
addTearDown(renderListener.dispose);
renderListener.debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
......@@ -396,9 +400,13 @@ void main() {
]);
});
testWidgets("RenderPointerListener's debugFillProperties when full", (WidgetTester tester) async {
testWidgetsWithLeakTracking("RenderPointerListener's debugFillProperties when full", (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
RenderPointerListener(
final RenderErrorBox renderErrorBox = RenderErrorBox();
addTearDown(() => renderErrorBox.dispose());
final RenderPointerListener renderListener = RenderPointerListener(
onPointerDown: (PointerDownEvent event) {},
onPointerUp: (PointerUpEvent event) {},
onPointerMove: (PointerMoveEvent event) {},
......@@ -406,8 +414,11 @@ void main() {
onPointerCancel: (PointerCancelEvent event) {},
onPointerSignal: (PointerSignalEvent event) {},
behavior: HitTestBehavior.opaque,
child: RenderErrorBox(),
).debugFillProperties(builder);
child: renderErrorBox,
);
addTearDown(renderListener.dispose);
renderListener.debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
......
......@@ -5,9 +5,10 @@
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';
void main() {
testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/9506
Widget buildFrame(int itemCount) {
......@@ -35,7 +36,7 @@ void main() {
expect(find.text('item 3'), findsOneWidget);
});
testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
testWidgetsWithLeakTracking('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/9506
Widget buildFrame(int itemCount) {
......
......@@ -6,11 +6,12 @@ import 'dart:async';
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() {
final TestAutomatedTestWidgetsFlutterBinding binding = TestAutomatedTestWidgetsFlutterBinding();
testWidgets('Locale is available when Localizations widget stops deferring frames', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Locale is available when Localizations widget stops deferring frames', (WidgetTester tester) async {
final FakeLocalizationsDelegate delegate = FakeLocalizationsDelegate();
await tester.pumpWidget(Localizations(
locale: const Locale('fo'),
......@@ -37,7 +38,7 @@ void main() {
expect(find.text('loaded'), findsOneWidget);
});
testWidgets('Localizations.localeOf throws when no localizations exist', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Localizations.localeOf throws when no localizations exist', (WidgetTester tester) async {
final GlobalKey contextKey = GlobalKey(debugLabel: 'Test Key');
await tester.pumpWidget(Container(key: contextKey));
......@@ -48,7 +49,7 @@ void main() {
)));
});
testWidgets('Localizations.maybeLocaleOf returns null when no localizations exist', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Localizations.maybeLocaleOf returns null when no localizations exist', (WidgetTester tester) async {
final GlobalKey contextKey = GlobalKey(debugLabel: 'Test Key');
await tester.pumpWidget(Container(key: contextKey));
......
......@@ -9,6 +9,7 @@ import 'package:fake_async/fake_async.dart';
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 _MockAnimationController extends AnimationController {
_MockAnimationController()
......@@ -42,7 +43,7 @@ void main() {
}
group('Raw Magnifier', () {
testWidgets('should render with correct focal point and decoration',
testWidgetsWithLeakTracking('should render with correct focal point and decoration',
(WidgetTester tester) async {
final Key appKey = UniqueKey();
const Size magnifierSize = Size(100, 100);
......@@ -116,7 +117,7 @@ void main() {
magnifierController.removeFromOverlay();
});
testWidgets(
testWidgetsWithLeakTracking(
'should immediately remove from overlay on no animation controller',
(WidgetTester tester) async {
await runFakeAsync((FakeAsync async) async {
......@@ -149,7 +150,7 @@ void main() {
});
});
testWidgets('should update shown based on animation status',
testWidgetsWithLeakTracking('should update shown based on animation status',
(WidgetTester tester) async {
await runFakeAsync((FakeAsync async) async {
final MagnifierController magnifierController =
......@@ -214,7 +215,7 @@ void main() {
});
group('show', () {
testWidgets('should insert below below widget', (WidgetTester tester) async {
testWidgetsWithLeakTracking('should insert below below widget', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Text('text'),
));
......@@ -226,6 +227,7 @@ void main() {
final OverlayEntry fakeBeforeOverlayEntry =
OverlayEntry(builder: (_) => fakeBefore);
addTearDown(() => fakeBeforeOverlayEntry..remove()..dispose());
Overlay.of(context).insert(fakeBeforeOverlayEntry);
magnifierController.show(
......@@ -247,7 +249,7 @@ void main() {
expect(allOverlayChildren.first.widget.key, fakeMagnifier.key);
});
testWidgets('should insert newly built widget without animating out if overlay != null',
testWidgetsWithLeakTracking('should insert newly built widget without animating out if overlay != null',
(WidgetTester tester) async {
await runFakeAsync((FakeAsync async) async {
final _MockAnimationController animationController =
......
......@@ -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('setState can be called from build, initState, didChangeDependencies, and didUpdateWidget', (WidgetTester tester) async {
testWidgetsWithLeakTracking('setState can be called from build, initState, didChangeDependencies, and didUpdateWidget', (WidgetTester tester) async {
// Initial build.
await tester.pumpWidget(
const Directionality(
......
......@@ -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('runApp uses deprecated pipelineOwner and renderView', (WidgetTester tester) async {
testWidgetsWithLeakTracking('runApp uses deprecated pipelineOwner and renderView', (WidgetTester tester) async {
runApp(const SizedBox());
final RenderObject renderObject = tester.renderObject(find.byType(SizedBox));
......@@ -21,7 +22,7 @@ void main() {
expect(renderObject.owner, equals(tester.binding.pipelineOwner));
});
testWidgets('can manually attach RootWidget to build owner', (WidgetTester tester) async {
testWidgetsWithLeakTracking('can manually attach RootWidget to build owner', (WidgetTester tester) async {
expect(find.byType(ColoredBox), findsNothing);
final RootWidget rootWidget = RootWidget(
......
......@@ -7,9 +7,10 @@ import 'dart:ui';
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('Widgets in view update as expected', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Widgets in view update as expected', (WidgetTester tester) async {
final Widget widget = View(
view: tester.view,
child: const TestWidget(),
......@@ -49,7 +50,7 @@ void main() {
expect(tester.renderObject<RenderParagraph>(find.byType(Text)).text.toPlainText(), 'FooBar');
});
testWidgets('Views in ViewCollection update as expected', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Views in ViewCollection update as expected', (WidgetTester tester) async {
Iterable<String> renderParagraphTexts() {
return tester.renderObjectList<RenderParagraph>(find.byType(Text)).map((RenderParagraph r) => r.text.toPlainText());
}
......@@ -103,7 +104,7 @@ void main() {
expect(renderParagraphTexts(), <String>['Guten', 'Morgen']);
});
testWidgets('Views in ViewAnchor update as expected', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Views in ViewAnchor update as expected', (WidgetTester tester) async {
Iterable<String> renderParagraphTexts() {
return tester.renderObjectList<RenderParagraph>(find.byType(Text)).map((RenderParagraph r) => r.text.toPlainText());
}
......
......@@ -5,6 +5,7 @@
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 'test_widgets.dart';
......@@ -32,7 +33,7 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) {
}
void main() {
testWidgets('MultiChildRenderObjectElement control test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('MultiChildRenderObjectElement control test', (WidgetTester tester) async {
await tester.pumpWidget(
const Stack(
......@@ -117,7 +118,7 @@ void main() {
});
testWidgets('MultiChildRenderObjectElement with stateless widgets', (WidgetTester tester) async {
testWidgetsWithLeakTracking('MultiChildRenderObjectElement with stateless widgets', (WidgetTester tester) async {
await tester.pumpWidget(
const Stack(
......@@ -243,7 +244,7 @@ void main() {
checkTree(tester, <BoxDecoration>[]);
});
testWidgets('MultiChildRenderObjectElement with stateful widgets', (WidgetTester tester) async {
testWidgetsWithLeakTracking('MultiChildRenderObjectElement with stateful widgets', (WidgetTester tester) async {
await tester.pumpWidget(
const Stack(
textDirection: TextDirection.ltr,
......
......@@ -5,9 +5,10 @@
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';
void main() {
testWidgets('Render and element tree stay in sync when keyed children move around', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Render and element tree stay in sync when keyed children move around', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/48855.
await tester.pumpWidget(
......@@ -59,7 +60,7 @@ void main() {
);
});
testWidgets('Building a new MultiChildRenderObjectElement with children having duplicated keys throws', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Building a new MultiChildRenderObjectElement with children having duplicated keys throws', (WidgetTester tester) async {
const ValueKey<int> duplicatedKey = ValueKey<int>(1);
await tester.pumpWidget(const Column(
......@@ -79,7 +80,7 @@ void main() {
);
});
testWidgets('Updating a MultiChildRenderObjectElement to have children with duplicated keys throws', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Updating a MultiChildRenderObjectElement to have children with duplicated keys throws', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/81541
const ValueKey<int> key1 = ValueKey<int>(1);
......
......@@ -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';
import 'test_widgets.dart';
......@@ -26,7 +27,7 @@ class TestCustomPainter extends CustomPainter {
}
void main() {
testWidgets('Do we paint when coming back from a navigation', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Do we paint when coming back from a navigation', (WidgetTester tester) async {
final List<String> log = <String>[];
log.add('0');
await tester.pumpWidget(
......
......@@ -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 'observer_tester.dart';
void main() {
testWidgets('Back during pushReplacement', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Back during pushReplacement', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: const Material(child: Text('home')),
routes: <String, WidgetBuilder>{
......@@ -42,7 +43,7 @@ void main() {
});
group('pushAndRemoveUntil', () {
testWidgets('notifies appropriately', (WidgetTester tester) async {
testWidgetsWithLeakTracking('notifies appropriately', (WidgetTester tester) async {
final TestObserver observer = TestObserver();
final Widget myApp = MaterialApp(
home: const Material(child: Text('home')),
......@@ -110,7 +111,7 @@ void main() {
]));
});
testWidgets('triggers page transition animation for pushed route', (WidgetTester tester) async {
testWidgetsWithLeakTracking('triggers page transition animation for pushed route', (WidgetTester tester) async {
final Widget myApp = MaterialApp(
home: const Material(child: Text('home')),
routes: <String, WidgetBuilder>{
......@@ -139,7 +140,7 @@ void main() {
expect(find.text('b'), findsOneWidget);
});
testWidgets('Hero transition triggers when preceding route contains hero, and predicate route does not', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Hero transition triggers when preceding route contains hero, and predicate route does not', (WidgetTester tester) async {
const String kHeroTag = 'hero';
final Widget myApp = MaterialApp(
initialRoute: '/',
......@@ -184,7 +185,7 @@ void main() {
expect(find.text('b'), isOnstage);
});
testWidgets('Hero transition does not trigger when preceding route does not contain hero, but predicate route does', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Hero transition does not trigger when preceding route does not contain hero, but predicate route does', (WidgetTester tester) async {
const String kHeroTag = 'hero';
final Widget myApp = MaterialApp(
theme: ThemeData(
......
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