From 2ec771aa9c25b8536907353a1b7316555bcef041 Mon Sep 17 00:00:00 2001 From: Binni Goel <41873024+droidbg@users.noreply.github.com> Date: Sat, 21 Oct 2023 09:41:47 +0530 Subject: [PATCH] Test cover painting for memory leaks (#136696) --- .../test/painting/decoration_image_lerp_test.dart | 9 ++++++--- packages/flutter/test/painting/gradient_test.dart | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/flutter/test/painting/decoration_image_lerp_test.dart b/packages/flutter/test/painting/decoration_image_lerp_test.dart index 44d2e3ede8..490e09f9bc 100644 --- a/packages/flutter/test/painting/decoration_image_lerp_test.dart +++ b/packages/flutter/test/painting/decoration_image_lerp_test.dart @@ -14,9 +14,10 @@ import 'dart:ui' as ui; 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'; void main() { - testWidgets('ImageDecoration.lerp', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ImageDecoration.lerp', (WidgetTester tester) async { final MemoryImage green = MemoryImage(Uint8List.fromList([ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x25, 0xdb, 0x56, @@ -159,6 +160,7 @@ void main() { if (!kIsWeb) { // TODO(ianh): https://github.com/flutter/flutter/issues/130610 final ui.Image image = (await tester.binding.runAsync(() => captureImage(find.byType(Wrap).evaluate().single)))!; + addTearDown(() => image.dispose()); final Uint8List bytes = (await tester.binding.runAsync(() => image.toByteData(format: ui.ImageByteFormat.rawStraightRgba)))!.buffer.asUint8List(); expect(image.width, 792); expect(image.height, 48); @@ -189,7 +191,7 @@ void main() { } }, skip: kIsWeb); // TODO(ianh): https://github.com/flutter/flutter/issues/130612, https://github.com/flutter/flutter/issues/130609 - testWidgets('ImageDecoration.lerp', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ImageDecoration.lerp', (WidgetTester tester) async { final MemoryImage cmyk = MemoryImage(Uint8List.fromList([ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x02, 0x03, 0x00, 0x00, 0x00, 0xd4, 0x9f, 0x76, @@ -355,6 +357,7 @@ void main() { if (!kIsWeb) { // TODO(ianh): https://github.com/flutter/flutter/issues/130610 final ui.Image image = (await tester.binding.runAsync(() => captureImage(find.byType(Wrap).evaluate().single)))!; + addTearDown(() => image.dispose()); final Uint8List bytes = (await tester.binding.runAsync(() => image.toByteData(format: ui.ImageByteFormat.rawStraightRgba)))!.buffer.asUint8List(); expect(image.width, 24 * 24); expect(image.height, 1 * 24); @@ -406,7 +409,7 @@ void main() { } }, skip: kIsWeb); // TODO(ianh): https://github.com/flutter/flutter/issues/130612, https://github.com/flutter/flutter/issues/130609 - testWidgets('ImageDecoration.lerp with colored background', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ImageDecoration.lerp with colored background', (WidgetTester tester) async { final MemoryImage cmyk = MemoryImage(Uint8List.fromList([ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x02, 0x03, 0x00, 0x00, 0x00, 0xd4, 0x9f, 0x76, diff --git a/packages/flutter/test/painting/gradient_test.dart b/packages/flutter/test/painting/gradient_test.dart index bd4d2b85e0..60b5919034 100644 --- a/packages/flutter/test/painting/gradient_test.dart +++ b/packages/flutter/test/painting/gradient_test.dart @@ -11,6 +11,7 @@ import 'dart:math' as math; 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() { test('LinearGradient scale test', () { @@ -881,7 +882,7 @@ void main() { group('Gradients - 45 degrees', () { for (final Gradient gradient in gradients45) { - testWidgets('$gradient', (WidgetTester tester) async { + testWidgetsWithLeakTracking('$gradient', (WidgetTester tester) async { await runTest(tester, gradient, 45); }); } @@ -889,7 +890,7 @@ void main() { group('Gradients - 90 degrees', () { for (final Gradient gradient in gradients90) { - testWidgets('$gradient', (WidgetTester tester) async { + testWidgetsWithLeakTracking('$gradient', (WidgetTester tester) async { await runTest(tester, gradient, 90); }); }