Unverified Commit a813dc55 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add more test coverage to image handling (#30078)

parent ec93c87c
......@@ -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 {}
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