Unverified Commit 22f593e5 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

GoldenFileComparators should dispose created Image objects. (#136716)

parent 3d1d4532
......@@ -137,7 +137,5 @@ void main() {
);
},
skip: isBrowser, // [intended] https://github.com/flutter/flutter/issues/56001
// TODO(polina-c): remove after fixing https://github.com/flutter/flutter/issues/136513
leakTrackingTestConfig: const LeakTrackingTestConfig(notDisposedAllowList: <String, int?>{'Image': 4}),
);
}
......@@ -534,10 +534,12 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
);
if (result.passed) {
result.dispose();
return true;
}
final String error = await generateFailureOutput(result, golden, basedir);
result.dispose();
throw FlutterError(error);
}
}
......@@ -96,12 +96,15 @@ class LocalFileComparator extends GoldenFileComparator with LocalComparisonOutpu
await getGoldenBytes(golden),
);
if (!result.passed) {
if (result.passed) {
result.dispose();
return true;
}
final String error = await generateFailureOutput(result, golden, basedir);
result.dispose();
throw FlutterError(error);
}
return result.passed;
}
@override
Future<void> update(Uri golden, Uint8List imageBytes) async {
......
......@@ -5,6 +5,7 @@
import 'dart:typed_data';
import 'dart:ui';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import '_goldens_io.dart' if (dart.library.html) '_goldens_web.dart' as goldens;
......@@ -342,4 +343,16 @@ class ComparisonResult {
/// The calculated percentage of pixel difference between two images.
final double diffPercent;
/// Disposes the images held by this [ComparisonResult].
@mustCallSuper
void dispose() {
if (diffs == null) {
return;
}
for (final MapEntry<String, Image> entry in diffs!.entries) {
entry.value.dispose();
}
}
}
......@@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:io' as io;
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:file/memory.dart';
import 'package:flutter/foundation.dart' show DiagnosticLevel, DiagnosticPropertiesBuilder, DiagnosticsNode, FlutterError;
......@@ -322,4 +323,34 @@ void main() {
});
});
});
group('ComparisonResult', () {
group('dispose', () {
test('disposes diffs images', () async {
final ui.Image image1 = await createTestImage(width: 10, height: 10, cache: false);
final ui.Image image2 = await createTestImage(width: 15, height: 5, cache: false);
final ui.Image image3 = await createTestImage(width: 5, height: 10, cache: false);
final ComparisonResult result = ComparisonResult(
passed: false,
diffPercent: 1.0,
diffs: <String, ui.Image>{
'image1': image1,
'image2': image2,
'image3': image3,
}
);
expect(image1.debugDisposed, isFalse);
expect(image2.debugDisposed, isFalse);
expect(image3.debugDisposed, isFalse);
result.dispose();
expect(image1.debugDisposed, isTrue);
expect(image2.debugDisposed, isTrue);
expect(image3.debugDisposed, isTrue);
});
});
});
}
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