Skip to content

Commit 2396a41

Browse files
authored
Cover more test/widgets tests with leak tracking #6 (flutter#134884)
1 parent 658710b commit 2396a41

20 files changed

+366
-203
lines changed

packages/flutter/test/widgets/notification_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
import 'package:flutter/widgets.dart';
66
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
78

89
class MyNotification extends Notification { }
910

1011
void main() {
11-
testWidgets('Notification basics - toString', (WidgetTester tester) async {
12+
testWidgetsWithLeakTracking('Notification basics - toString', (WidgetTester tester) async {
1213
expect(MyNotification(), hasOneLineDescription);
1314
});
1415

15-
testWidgets('Notification basics - dispatch', (WidgetTester tester) async {
16+
testWidgetsWithLeakTracking('Notification basics - dispatch', (WidgetTester tester) async {
1617
final List<dynamic> log = <dynamic>[];
1718
final GlobalKey key = GlobalKey();
1819
await tester.pumpWidget(NotificationListener<MyNotification>(
@@ -36,7 +37,7 @@ void main() {
3637
expect(log, <dynamic>['b', notification, 'a', notification]);
3738
});
3839

39-
testWidgets('Notification basics - cancel', (WidgetTester tester) async {
40+
testWidgetsWithLeakTracking('Notification basics - cancel', (WidgetTester tester) async {
4041
final List<dynamic> log = <dynamic>[];
4142
final GlobalKey key = GlobalKey();
4243
await tester.pumpWidget(NotificationListener<MyNotification>(
@@ -60,7 +61,7 @@ void main() {
6061
expect(log, <dynamic>['b', notification]);
6162
});
6263

63-
testWidgets('Notification basics - listener null return value', (WidgetTester tester) async {
64+
testWidgetsWithLeakTracking('Notification basics - listener null return value', (WidgetTester tester) async {
6465
final List<Type> log = <Type>[];
6566
final GlobalKey key = GlobalKey();
6667
await tester.pumpWidget(NotificationListener<MyNotification>(
@@ -77,7 +78,7 @@ void main() {
7778
expect(log, <Type>[MyNotification]);
7879
});
7980

80-
testWidgets('Notification basics - listener null return value', (WidgetTester tester) async {
81+
testWidgetsWithLeakTracking('Notification basics - listener null return value', (WidgetTester tester) async {
8182
await tester.pumpWidget(const Placeholder());
8283
final ScrollMetricsNotification n1 = ScrollMetricsNotification(
8384
metrics: FixedScrollMetrics(

packages/flutter/test/widgets/obscured_animated_image_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:ui' as ui show Image;
88
import 'package:flutter/material.dart';
99
import 'package:flutter/rendering.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1112

1213
import '../image_data.dart';
1314
import '../painting/fake_codec.dart';
@@ -17,7 +18,7 @@ Future<void> main() async {
1718
final FakeCodec fakeCodec = await FakeCodec.fromData(Uint8List.fromList(kAnimatedGif));
1819
final FakeImageProvider fakeImageProvider = FakeImageProvider(fakeCodec);
1920

20-
testWidgets('Obscured image does not animate', (WidgetTester tester) async {
21+
testWidgetsWithLeakTracking('Obscured image does not animate', (WidgetTester tester) async {
2122
final GlobalKey imageKey = GlobalKey();
2223
await tester.pumpWidget(
2324
MaterialApp(

packages/flutter/test/widgets/opacity_repaint_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter/rendering.dart';
77
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
89

910
void main() {
10-
testWidgets('RenderOpacity avoids repainting and does not drop layer at fully opaque', (WidgetTester tester) async {
11+
testWidgetsWithLeakTracking('RenderOpacity avoids repainting and does not drop layer at fully opaque', (WidgetTester tester) async {
1112
RenderTestObject.paintCount = 0;
1213
await tester.pumpWidget(
1314
const ColoredBox(
@@ -46,7 +47,7 @@ void main() {
4647
expect(RenderTestObject.paintCount, 1);
4748
});
4849

49-
testWidgets('RenderOpacity allows opacity layer to be dropped at 0 opacity', (WidgetTester tester) async {
50+
testWidgetsWithLeakTracking('RenderOpacity allows opacity layer to be dropped at 0 opacity', (WidgetTester tester) async {
5051
RenderTestObject.paintCount = 0;
5152

5253
await tester.pumpWidget(

packages/flutter/test/widgets/opacity_test.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
@Tags(<String>['reduced-test-set'])
88
library;
99

10+
import 'dart:ui' as ui;
11+
1012
import 'package:flutter/material.dart';
1113
import 'package:flutter/rendering.dart';
1214
import 'package:flutter_test/flutter_test.dart';
15+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1316

1417
import 'semantics_tester.dart';
1518

1619
void main() {
17-
testWidgets('Opacity', (WidgetTester tester) async {
20+
testWidgetsWithLeakTracking('Opacity', (WidgetTester tester) async {
1821
final SemanticsTester semantics = SemanticsTester(tester);
1922

2023
// Opacity 1.0: Semantics and painting
@@ -151,7 +154,7 @@ void main() {
151154
semantics.dispose();
152155
});
153156

154-
testWidgets('offset is correctly handled in Opacity', (WidgetTester tester) async {
157+
testWidgetsWithLeakTracking('offset is correctly handled in Opacity', (WidgetTester tester) async {
155158
await tester.pumpWidget(
156159
MaterialApp(
157160
theme: ThemeData(useMaterial3: false),
@@ -184,18 +187,19 @@ void main() {
184187
);
185188
});
186189

187-
testWidgets('empty opacity does not crash', (WidgetTester tester) async {
190+
testWidgetsWithLeakTracking('empty opacity does not crash', (WidgetTester tester) async {
188191
await tester.pumpWidget(
189192
RepaintBoundary(child: Opacity(opacity: 0.5, child: Container())),
190193
);
191194
final Element element = find.byType(RepaintBoundary).first.evaluate().single;
192195
// The following line will send the layer to engine and cause crash if an
193196
// empty opacity layer is sent.
194197
final OffsetLayer offsetLayer = element.renderObject!.debugLayer! as OffsetLayer;
195-
await offsetLayer.toImage(const Rect.fromLTRB(0.0, 0.0, 1.0, 1.0));
198+
final ui.Image image = await offsetLayer.toImage(const Rect.fromLTRB(0.0, 0.0, 1.0, 1.0));
199+
image.dispose();
196200
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/49857
197201

198-
testWidgets('Child shows up in the right spot when opacity is disabled', (WidgetTester tester) async {
202+
testWidgetsWithLeakTracking('Child shows up in the right spot when opacity is disabled', (WidgetTester tester) async {
199203
debugDisableOpacityLayers = true;
200204
final GlobalKey key = GlobalKey();
201205
await tester.pumpWidget(

packages/flutter/test/widgets/overflow_bar_test.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import 'package:flutter/widgets.dart';
66
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
78

89
void main() {
9-
testWidgets('OverflowBar documented defaults', (WidgetTester tester) async {
10+
testWidgetsWithLeakTracking('OverflowBar documented defaults', (WidgetTester tester) async {
1011
const OverflowBar bar = OverflowBar();
1112
expect(bar.spacing, 0);
1213
expect(bar.alignment, null);
@@ -17,7 +18,7 @@ void main() {
1718
expect(bar.children, const <Widget>[]);
1819
});
1920

20-
testWidgets('Empty OverflowBar', (WidgetTester tester) async {
21+
testWidgetsWithLeakTracking('Empty OverflowBar', (WidgetTester tester) async {
2122
const Size size = Size(16, 24);
2223

2324
await tester.pumpWidget(
@@ -46,7 +47,7 @@ void main() {
4647
expect(tester.getSize(find.byType(OverflowBar)), Size.zero);
4748
});
4849

49-
testWidgets('OverflowBar horizontal layout', (WidgetTester tester) async {
50+
testWidgetsWithLeakTracking('OverflowBar horizontal layout', (WidgetTester tester) async {
5051
final Key child1Key = UniqueKey();
5152
final Key child2Key = UniqueKey();
5253
final Key child3Key = UniqueKey();
@@ -93,7 +94,7 @@ void main() {
9394
expect(tester.getRect(find.byKey(child1Key)), const Rect.fromLTRB(10.0 + 96 + 10.0, 8, 10.0 + 10.0 + 144, 56));
9495
});
9596

96-
testWidgets('OverflowBar vertical layout', (WidgetTester tester) async {
97+
testWidgetsWithLeakTracking('OverflowBar vertical layout', (WidgetTester tester) async {
9798
final Key child1Key = UniqueKey();
9899
final Key child2Key = UniqueKey();
99100
final Key child3Key = UniqueKey();
@@ -174,7 +175,7 @@ void main() {
174175
expect(tester.getRect(find.byKey(child3Key)), const Rect.fromLTRB(100.0/2.0 - 32/2, 112, 100.0/2.0 + 32/2, 144));
175176
});
176177

177-
testWidgets('OverflowBar intrinsic width', (WidgetTester tester) async {
178+
testWidgetsWithLeakTracking('OverflowBar intrinsic width', (WidgetTester tester) async {
178179
Widget buildFrame({ required double width }) {
179180
return Directionality(
180181
textDirection: TextDirection.ltr,
@@ -205,7 +206,7 @@ void main() {
205206
expect(tester.getSize(find.byType(OverflowBar)).width, 150);
206207
});
207208

208-
testWidgets('OverflowBar intrinsic height', (WidgetTester tester) async {
209+
testWidgetsWithLeakTracking('OverflowBar intrinsic height', (WidgetTester tester) async {
209210
Widget buildFrame({ required double maxWidth }) {
210211
return Directionality(
211212
textDirection: TextDirection.ltr,
@@ -237,7 +238,7 @@ void main() {
237238
});
238239

239240

240-
testWidgets('OverflowBar is wider that its intrinsic width', (WidgetTester tester) async {
241+
testWidgetsWithLeakTracking('OverflowBar is wider that its intrinsic width', (WidgetTester tester) async {
241242
final Key key0 = UniqueKey();
242243
final Key key1 = UniqueKey();
243244
final Key key2 = UniqueKey();
@@ -273,7 +274,7 @@ void main() {
273274
expect(tester.getTopLeft(find.byKey(key2)).dx, 600);
274275
});
275276

276-
testWidgets('OverflowBar with alignment should match Row with mainAxisAlignment', (WidgetTester tester) async {
277+
testWidgetsWithLeakTracking('OverflowBar with alignment should match Row with mainAxisAlignment', (WidgetTester tester) async {
277278
final Key key0 = UniqueKey();
278279
final Key key1 = UniqueKey();
279280
final Key key2 = UniqueKey();

packages/flutter/test/widgets/overflow_box_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import 'package:flutter/rendering.dart';
66
import 'package:flutter/widgets.dart';
77
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
89

910
void main() {
10-
testWidgets('OverflowBox control test', (WidgetTester tester) async {
11+
testWidgetsWithLeakTracking('OverflowBox control test', (WidgetTester tester) async {
1112
final GlobalKey inner = GlobalKey();
1213
await tester.pumpWidget(Align(
1314
alignment: Alignment.bottomRight,
@@ -30,7 +31,7 @@ void main() {
3031
expect(box.size, equals(const Size(100.0, 50.0)));
3132
});
3233

33-
testWidgets('OverflowBox implements debugFillProperties', (WidgetTester tester) async {
34+
testWidgetsWithLeakTracking('OverflowBox implements debugFillProperties', (WidgetTester tester) async {
3435
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
3536
const OverflowBox(
3637
minWidth: 1.0,
@@ -50,7 +51,7 @@ void main() {
5051
]);
5152
});
5253

53-
testWidgets('SizedOverflowBox alignment', (WidgetTester tester) async {
54+
testWidgetsWithLeakTracking('SizedOverflowBox alignment', (WidgetTester tester) async {
5455
final GlobalKey inner = GlobalKey();
5556
await tester.pumpWidget(Directionality(
5657
textDirection: TextDirection.rtl,
@@ -73,7 +74,7 @@ void main() {
7374
);
7475
});
7576

76-
testWidgets('SizedOverflowBox alignment (direction-sensitive)', (WidgetTester tester) async {
77+
testWidgetsWithLeakTracking('SizedOverflowBox alignment (direction-sensitive)', (WidgetTester tester) async {
7778
final GlobalKey inner = GlobalKey();
7879
await tester.pumpWidget(Directionality(
7980
textDirection: TextDirection.rtl,

0 commit comments

Comments
 (0)