From 30738982b40b4a7b2045377636531f7627450358 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 3 Apr 2020 16:05:43 -0700 Subject: [PATCH] Remove network images from cache on any exception during loading (#53875) * Remove network images from cache on any exception during loading --- .../lib/src/painting/_network_image_io.dart | 11 ++++++- .../test/painting/image_provider_test.dart | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/painting/_network_image_io.dart b/packages/flutter/lib/src/painting/_network_image_io.dart index 12c1aa698e..5eaf04518d 100644 --- a/packages/flutter/lib/src/painting/_network_image_io.dart +++ b/packages/flutter/lib/src/painting/_network_image_io.dart @@ -82,7 +82,9 @@ class NetworkImage extends image_provider.ImageProvider throw const SocketException('test exception')); + debugNetworkImageHttpClientProvider = () => mockHttpClient; + + + final ImageProvider imageProvider = NetworkImage(nonconst('testing.url')); + expect(imageCache.pendingImageCount, 0); + expect(imageCache.statusForKey(imageProvider).untracked, true); + + final ImageStream result = imageProvider.resolve(ImageConfiguration.empty); + + expect(imageCache.pendingImageCount, 1); + expect(imageCache.statusForKey(imageProvider).pending, true); + final Completer caughtError = Completer(); + result.addListener(ImageStreamListener( + (ImageInfo info, bool syncCall) {}, + onError: (dynamic error, StackTrace stackTrace) { + caughtError.complete(error); + }, + )); + + final dynamic err = await caughtError.future; + + expect(err, isA()); + + expect(imageCache.pendingImageCount, 0); + expect(imageCache.statusForKey(imageProvider).untracked, true); + expect(imageCache.containsKey(result), isFalse); + + debugNetworkImageHttpClientProvider = null; + }, skip: isBrowser); // Browser does not resolve images this way. }); });