Add more test coverage to image handling (#30078)
This commit is contained in:
@@ -86,4 +86,32 @@ void main() {
|
||||
});
|
||||
expect(await caughtError.future, true);
|
||||
});
|
||||
|
||||
test('ImageProvider.resolve sync errors will be caught', () async {
|
||||
final ImageProvider imageProvider = LoadErrorImageProvider();
|
||||
final Completer<bool> caughtError = Completer<bool>();
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
caughtError.complete(false);
|
||||
};
|
||||
final ImageStream result = imageProvider.resolve(ImageConfiguration.empty);
|
||||
result.addListener((ImageInfo info, bool syncCall) {
|
||||
}, onError: (dynamic error, StackTrace stackTrace) {
|
||||
caughtError.complete(true);
|
||||
});
|
||||
expect(await caughtError.future, true);
|
||||
});
|
||||
|
||||
test('ImageProvider.resolve errors in the completer will be caught', () async {
|
||||
final ImageProvider imageProvider = LoadErrorCompleterImageProvider();
|
||||
final Completer<bool> caughtError = Completer<bool>();
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
caughtError.complete(false);
|
||||
};
|
||||
final ImageStream result = imageProvider.resolve(ImageConfiguration.empty);
|
||||
result.addListener((ImageInfo info, bool syncCall) {
|
||||
}, onError: (dynamic error, StackTrace stackTrace) {
|
||||
caughtError.complete(true);
|
||||
});
|
||||
expect(await caughtError.future, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,4 +106,28 @@ class ObtainKeyErrorImageProvider extends ImageProvider<ObtainKeyErrorImageProvi
|
||||
}
|
||||
}
|
||||
|
||||
class LoadErrorImageProvider extends ImageProvider<LoadErrorImageProvider> {
|
||||
@override
|
||||
ImageStreamCompleter load(LoadErrorImageProvider key) {
|
||||
throw Error();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadErrorImageProvider> obtainKey(ImageConfiguration configuration) {
|
||||
return SynchronousFuture<LoadErrorImageProvider>(this);
|
||||
}
|
||||
}
|
||||
|
||||
class LoadErrorCompleterImageProvider extends ImageProvider<LoadErrorCompleterImageProvider> {
|
||||
@override
|
||||
ImageStreamCompleter load(LoadErrorCompleterImageProvider key) {
|
||||
return OneFrameImageStreamCompleter(SynchronousFuture<ImageInfo>(null).then((_) => throw Error()));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadErrorCompleterImageProvider> obtainKey(ImageConfiguration configuration) {
|
||||
return SynchronousFuture<LoadErrorCompleterImageProvider>(this);
|
||||
}
|
||||
}
|
||||
|
||||
class TestImageStreamCompleter extends ImageStreamCompleter {}
|
||||
|
||||
Reference in New Issue
Block a user