Add more tests to ensure the callback been called, even we cancel the operation, impact the view category and prefetcher
This commit is contained in:
parent
4e51f1deac
commit
b444652412
|
@ -209,6 +209,21 @@
|
|||
expect([imageView sd_imageLoadOperationForKey:operationKey]).beNil();
|
||||
}
|
||||
|
||||
- (void)testUIViewCancelCallbackWithError {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView internalSetImageWithURL cancel callback error"];
|
||||
|
||||
UIView *imageView = [[UIView alloc] init];
|
||||
NSURL *originalImageURL = [NSURL URLWithString:kTestJPEGURL];
|
||||
[imageView sd_internalSetImageWithURL:originalImageURL placeholderImage:nil options:0 context:nil setImageBlock:nil progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||||
expect(error).notTo.beNil();
|
||||
expect(error.code).equal(SDWebImageErrorCancelled);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
[imageView sd_cancelCurrentImageLoad];
|
||||
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)testUIViewImageProgressKVOWork {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"UIView imageProgressKVO failed"];
|
||||
UIView *view = [[UIView alloc] init];
|
||||
|
|
|
@ -151,6 +151,31 @@
|
|||
expect(prefetcher.runningTokens.count).equal(0);
|
||||
}
|
||||
|
||||
- (void)test07DownloaderCancelDuringPrefetching {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"Downloader cancel during prefetch should not hung up"];
|
||||
|
||||
NSArray *imageURLs = @[@"http://via.placeholder.com/3000x3000.jpg",
|
||||
@"http://via.placeholder.com/4000x4000.jpg",
|
||||
@"http://via.placeholder.com/5000x5000.jpg"];
|
||||
for (NSString *url in imageURLs) {
|
||||
[SDImageCache.sharedImageCache removeImageFromDiskForKey:url];
|
||||
}
|
||||
SDWebImagePrefetcher *prefetcher = [[SDWebImagePrefetcher alloc] init];
|
||||
prefetcher.maxConcurrentPrefetchCount = 3;
|
||||
[prefetcher prefetchURLs:imageURLs progress:nil completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
|
||||
expect(noOfSkippedUrls).equal(3);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
|
||||
// Cancel all download, should not effect the prefetcher logic or cause hung up
|
||||
// Prefetch is not sync, so using wait for testing
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, kMinDelayNanosecond), dispatch_get_main_queue(), ^{
|
||||
[SDWebImageDownloader.sharedDownloader cancelAllDownloads];
|
||||
});
|
||||
|
||||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount {
|
||||
expect(imagePrefetcher).to.equal(self.prefetcher);
|
||||
self.skippedCount = skippedCount;
|
||||
|
|
Loading…
Reference in New Issue