Skip to content

Commit

Permalink
Cover more test/widgets tests with leak tracking #4 (flutter#134663)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksokolovskyi authored Sep 13, 2023
1 parent f38dcb1 commit 7cd8b40
Show file tree
Hide file tree
Showing 31 changed files with 301 additions and 246 deletions.
52 changes: 27 additions & 25 deletions packages/flutter/test/widgets/implicit_animations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

class MockOnEndFunction {
int called = 0;
Expand All @@ -24,7 +25,7 @@ void main() {
mockOnEndFunction = MockOnEndFunction();
});

testWidgets('BoxConstraintsTween control test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('BoxConstraintsTween control test', (WidgetTester tester) async {
final BoxConstraintsTween tween = BoxConstraintsTween(
begin: BoxConstraints.tight(const Size(20.0, 50.0)),
end: BoxConstraints.tight(const Size(10.0, 30.0)),
Expand All @@ -36,7 +37,7 @@ void main() {
expect(result.maxHeight, 45.0);
});

testWidgets('DecorationTween control test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('DecorationTween control test', (WidgetTester tester) async {
final DecorationTween tween = DecorationTween(
begin: const BoxDecoration(color: Color(0xFF00FF00)),
end: const BoxDecoration(color: Color(0xFFFFFF00)),
Expand All @@ -45,7 +46,7 @@ void main() {
expect(result.color, const Color(0xFF3FFF00));
});

testWidgets('EdgeInsetsTween control test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('EdgeInsetsTween control test', (WidgetTester tester) async {
final EdgeInsetsTween tween = EdgeInsetsTween(
begin: const EdgeInsets.symmetric(vertical: 50.0),
end: const EdgeInsets.only(top: 10.0, bottom: 30.0),
Expand All @@ -57,7 +58,7 @@ void main() {
expect(result.bottom, 45.0);
});

testWidgets('Matrix4Tween control test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Matrix4Tween control test', (WidgetTester tester) async {
final Matrix4Tween tween = Matrix4Tween(
begin: Matrix4.translationValues(10.0, 20.0, 30.0),
end: Matrix4.translationValues(14.0, 24.0, 34.0),
Expand All @@ -66,7 +67,7 @@ void main() {
expect(result, equals(Matrix4.translationValues(11.0, 21.0, 31.0)));
});

testWidgets('AnimatedContainer onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedContainer onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -89,7 +90,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedPadding onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedPadding onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -112,7 +113,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedAlign onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedAlign onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -135,7 +136,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedPositioned onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedPositioned onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -158,7 +159,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedPositionedDirectional onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedPositionedDirectional onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -181,7 +182,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedSlide onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedSlide onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -203,7 +204,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedSlide transition test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedSlide transition test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
switchKey: switchKey,
Expand Down Expand Up @@ -241,7 +242,7 @@ void main() {
expect(state.builds, equals(2));
});

testWidgets('AnimatedScale onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedScale onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -263,7 +264,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedScale transition test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedScale transition test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
switchKey: switchKey,
Expand Down Expand Up @@ -301,7 +302,7 @@ void main() {
expect(state.builds, equals(2));
});

testWidgets('AnimatedRotation onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedRotation onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -323,7 +324,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedRotation transition test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedRotation transition test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
switchKey: switchKey,
Expand Down Expand Up @@ -361,7 +362,7 @@ void main() {
expect(state.builds, equals(2));
});

testWidgets('AnimatedOpacity onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedOpacity onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -383,7 +384,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedOpacity transition test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedOpacity transition test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
switchKey: switchKey,
Expand Down Expand Up @@ -421,7 +422,7 @@ void main() {
expect(state.builds, equals(2));
});

testWidgets('AnimatedFractionallySizedBox onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedFractionallySizedBox onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -443,7 +444,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('SliverAnimatedOpacity onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SliverAnimatedOpacity onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(TestAnimatedWidget(
callback: mockOnEndFunction.handler,
switchKey: switchKey,
Expand All @@ -464,7 +465,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('SliverAnimatedOpacity transition test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SliverAnimatedOpacity transition test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
switchKey: switchKey,
Expand Down Expand Up @@ -502,7 +503,7 @@ void main() {
expect(state.builds, equals(2));
});

testWidgets('AnimatedDefaultTextStyle onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedDefaultTextStyle onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -525,7 +526,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedPhysicalModel onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedPhysicalModel onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -548,7 +549,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('TweenAnimationBuilder onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('TweenAnimationBuilder onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -571,7 +572,7 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('AnimatedTheme onEnd callback test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('AnimatedTheme onEnd callback test', (WidgetTester tester) async {
await tester.pumpWidget(wrap(
child: TestAnimatedWidget(
callback: mockOnEndFunction.handler,
Expand All @@ -594,11 +595,12 @@ void main() {
await tapTest2and3(tester, widgetFinder, mockOnEndFunction);
});

testWidgets('Ensure CurvedAnimations are disposed on widget change',
testWidgetsWithLeakTracking('Ensure CurvedAnimations are disposed on widget change',
(WidgetTester tester) async {
final GlobalKey<ImplicitlyAnimatedWidgetState<AnimatedOpacity>> key =
GlobalKey<ImplicitlyAnimatedWidgetState<AnimatedOpacity>>();
final ValueNotifier<Curve> curve = ValueNotifier<Curve>(const Interval(0.0, 0.5));
addTearDown(curve.dispose);
await tester.pumpWidget(wrap(
child: ValueListenableBuilder<Curve>(
valueListenable: curve,
Expand Down
5 changes: 3 additions & 2 deletions packages/flutter/test/widgets/implicit_semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.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('Implicit Semantics merge behavior', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Implicit Semantics merge behavior', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(
Expand Down Expand Up @@ -172,7 +173,7 @@ void main() {
semantics.dispose();
});

testWidgets('Do not merge with conflicts', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Do not merge with conflicts', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import 'package:flutter/src/widgets/basic.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
testWidgets('InheritedWidget dependencies show up in diagnostic properties', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InheritedWidget dependencies show up in diagnostic properties', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(Directionality(
key: key,
Expand Down
9 changes: 5 additions & 4 deletions packages/flutter/test/widgets/inherited_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

// A simple "flat" InheritedModel: the data model is just 3 integer
// valued fields: a, b, c.
Expand Down Expand Up @@ -73,7 +74,7 @@ class _ShowABCFieldState extends State<ShowABCField> {
}

void main() {
testWidgets('InheritedModel basics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InheritedModel basics', (WidgetTester tester) async {
int a = 0;
int b = 1;
int c = 2;
Expand Down Expand Up @@ -189,7 +190,7 @@ void main() {
expect(find.text('a: 2 b: 2 c: 3'), findsOneWidget);
});

testWidgets('Looking up an non existent InheritedModel ancestor returns null', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Looking up an non existent InheritedModel ancestor returns null', (WidgetTester tester) async {
ABCModel? inheritedModel;

await tester.pumpWidget(
Expand All @@ -205,7 +206,7 @@ void main() {
expect(inheritedModel, null);
});

testWidgets('Inner InheritedModel shadows the outer one', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Inner InheritedModel shadows the outer one', (WidgetTester tester) async {
int a = 0;
int b = 1;
int c = 2;
Expand Down Expand Up @@ -323,7 +324,7 @@ void main() {
expect(find.text('a: 102 b: 102 c: null'), findsOneWidget);
});

testWidgets('InheritedModel inner models supported aspect change', (WidgetTester tester) async {
testWidgetsWithLeakTracking('InheritedModel inner models supported aspect change', (WidgetTester tester) async {
int a = 0;
int b = 1;
int c = 2;
Expand Down
Loading

0 comments on commit 7cd8b40

Please sign in to comment.