GoldenFileComparators should dispose created Image objects. (#136716)
This commit is contained in:
parent
3d1d4532b5
commit
22f593e578
@ -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,11 +96,14 @@ class LocalFileComparator extends GoldenFileComparator with LocalComparisonOutpu
|
||||
await getGoldenBytes(golden),
|
||||
);
|
||||
|
||||
if (!result.passed) {
|
||||
final String error = await generateFailureOutput(result, golden, basedir);
|
||||
throw FlutterError(error);
|
||||
if (result.passed) {
|
||||
result.dispose();
|
||||
return true;
|
||||
}
|
||||
return result.passed;
|
||||
|
||||
final String error = await generateFailureOutput(result, golden, basedir);
|
||||
result.dispose();
|
||||
throw FlutterError(error);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user