Skip to content

Commit

Permalink
Clean leaky tests. (#150335)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Jun 20, 2024
1 parent 64dd1ca commit bfdcb51
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import 'dart:typed_data';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

import '../../image_data.dart';

late List<int> selectedTabs;

void main() {
// TODO(polina-c): dispose ImageStreamCompleterHandle, https://github.com/flutter/flutter/issues/145599 [leaks-to-clean]
LeakTesting.settings = LeakTesting.settings.withIgnoredAll();

setUp(() {
selectedTabs = <int>[];
});
Expand Down Expand Up @@ -328,6 +324,7 @@ void main() {

expect(contents.length, greaterThan(0));
expect(contents, isNot(contains(predicate((RichText t) => t.textScaler != const TextScaler.linear(99.0)))));
imageCache.clear();
});
}

Expand Down
7 changes: 2 additions & 5 deletions packages/flutter/test/material/circle_avatar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'dart:typed_data';
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 '../image_data.dart';
import '../painting/mocks_for_image_cache.dart';

Expand Down Expand Up @@ -95,10 +94,8 @@ void main() {
expect(decoration.image!.fit, equals(BoxFit.cover));
});

testWidgets('CircleAvatar backgroundImage is used as a fallback for foregroundImage',
// TODO(polina-c): make sure images are disposed, https://github.com/flutter/flutter/issues/141388 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
testWidgets('CircleAvatar backgroundImage is used as a fallback for foregroundImage', (WidgetTester tester) async {
addTearDown(imageCache.clear);
final ErrorImageProvider errorImage = ErrorImageProvider();
bool caughtForegroundImageError = false;
await tester.pumpWidget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'dart:ui' as ui show Image;
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 '../image_data.dart';
import '../painting/fake_codec.dart';
Expand All @@ -18,10 +17,7 @@ Future<void> main() async {
final FakeCodec fakeCodec = await FakeCodec.fromData(Uint8List.fromList(kAnimatedGif));
final FakeImageProvider fakeImageProvider = FakeImageProvider(fakeCodec);

testWidgets('Obscured image does not animate',
// TODO(polina-c): dispose ImageStreamCompleterHandle, https://github.com/flutter/flutter/issues/145599 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
testWidgets('Obscured image does not animate', (WidgetTester tester) async {
final GlobalKey imageKey = GlobalKey();
await tester.pumpWidget(
MaterialApp(
Expand All @@ -47,5 +43,6 @@ Future<void> main() async {
await tester.pump(const Duration(milliseconds: 100));
final ui.Image? image4 = renderImage.image;
expect(image3, same(image4));
imageCache.clear();
});
}
13 changes: 4 additions & 9 deletions packages/flutter/test/widgets/shape_decoration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'dart:ui' as ui show Image;

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

import '../image_data.dart';
import '../painting/mocks_for_image_cache.dart';
Expand All @@ -18,10 +17,8 @@ Future<void> main() async {
final ui.Image rawImage = await decodeImageFromList(Uint8List.fromList(kTransparentImage));
final ImageProvider image = TestImageProvider(0, 0, image: rawImage);

testWidgets('ShapeDecoration.image',
// TODO(polina-c): dispose ImageStreamCompleterHandle, https://github.com/flutter/flutter/issues/145599 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
testWidgets('ShapeDecoration.image', (WidgetTester tester) async {
addTearDown(imageCache.clear);
await tester.pumpWidget(
MaterialApp(
home: DecoratedBox(
Expand Down Expand Up @@ -94,10 +91,8 @@ Future<void> main() async {
);
});

testWidgets('TestBorder and Directionality - 2',
// TODO(polina-c): dispose ImageStreamCompleterHandle, https://github.com/flutter/flutter/issues/145599 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
testWidgets('TestBorder and Directionality - 2', (WidgetTester tester) async {
addTearDown(imageCache.clear);
final List<String> log = <String>[];
await tester.pumpWidget(
Directionality(
Expand Down

0 comments on commit bfdcb51

Please sign in to comment.