diff --git a/packages/flutter_test/lib/src/_goldens_io.dart b/packages/flutter_test/lib/src/_goldens_io.dart index 0406c712ea..e68fc06a93 100644 --- a/packages/flutter_test/lib/src/_goldens_io.dart +++ b/packages/flutter_test/lib/src/_goldens_io.dart @@ -175,13 +175,6 @@ mixin LocalComparisonOutput { /// Returns a [ComparisonResult] to describe the pixel differential of the /// [test] and [master] image bytes provided. Future compareLists(List? test, List? master) async { - if (identical(test, master)) { - return ComparisonResult( - passed: true, - diffPercent: 0.0, - ); - } - if (test == null || master == null || test.isEmpty || master.isEmpty) { return ComparisonResult( passed: false, @@ -190,6 +183,13 @@ Future compareLists(List? test, List? master) async ); } + if (listEquals(test, master)) { + return ComparisonResult( + passed: true, + diffPercent: 0.0, + ); + } + final Codec testImageCodec = await instantiateImageCodec(Uint8List.fromList(test)); final Image testImage = (await testImageCodec.getNextFrame()).image; diff --git a/packages/flutter_test/test/goldens_test.dart b/packages/flutter_test/test/goldens_test.dart index 33066a5782..ef52216583 100644 --- a/packages/flutter_test/test/goldens_test.dart +++ b/packages/flutter_test/test/goldens_test.dart @@ -9,8 +9,8 @@ import 'dart:ui' as ui; import 'package:file/memory.dart'; import 'package:flutter/foundation.dart' show DiagnosticLevel, DiagnosticPropertiesBuilder, DiagnosticsNode, FlutterError; -import 'package:flutter_test/flutter_test.dart' hide test; import 'package:flutter_test/flutter_test.dart' as test_package; +import 'package:flutter_test/flutter_test.dart' hide test; // 1x1 transparent pixel const List _kExpectedPngBytes = [ @@ -85,6 +85,15 @@ void main() { final LocalFileComparator comparator = goldenFileComparator as LocalFileComparator; expect(comparator.basedir.path, contains('flutter_test')); }); + + test('image comparison should not loop over all pixels when the data is the same', () async { + final List invalidImageData1 = Uint8List.fromList([127]); + final List invalidImageData2 = Uint8List.fromList([127]); + // This will fail if the comparison algorithm tries to generate the images + // to loop over every pixel which is not necessary when test and master + // is exactly the same (for performance reasons). + await GoldenFileComparator.compareLists(invalidImageData1, invalidImageData2); + }); }); group('LocalFileComparator', () {