Update the test to ensure minimumProgressInterval works

This commit is contained in:
DreamPiggy 2018-08-02 13:18:25 +08:00
parent 67e0df75c6
commit 6a3aa48410
2 changed files with 28 additions and 1 deletions

View File

@ -265,6 +265,34 @@
[self waitForExpectationsWithCommonTimeout];
}
- (void)test17ThatMinimumProgressIntervalWorks {
XCTestExpectation *expectation = [self expectationWithDescription:@"Minimum progress interval"];
SDWebImageDownloaderConfig *config = SDWebImageDownloaderConfig.defaultDownloaderConfig;
config.minimumProgressInterval = 0.51; // This will make the progress only callback once
SDWebImageDownloader *downloader = [[SDWebImageDownloader alloc] initWithConfig:config];
NSURL *imageURL = [NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"];
__block NSUInteger allProgressCount = 0; // All progress (including operation start / first HTTP response, etc)
__block NSUInteger validProgressCount = 0; // Only progress from `URLSession:dataTask:didReceiveData:`
[downloader downloadImageWithURL:imageURL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
allProgressCount++;
if (expectedSize <= 0 || receivedSize <= 0) {
// ignore the progress callback until we receive data
return;
}
validProgressCount++;
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (allProgressCount > 1 && validProgressCount == 1) {
[expectation fulfill];
} else {
XCTFail(@"Progress callback more than once");
}
}];
[self waitForExpectationsWithCommonTimeoutUsingHandler:^(NSError * _Nullable error) {
[downloader invalidateSessionAndCancel:YES];
}];
}
/**
* Per #883 - Fix multiple requests for same image and then canceling one
* Old SDWebImage (3.x) could not handle correctly multiple requests for the same image + cancel

View File

@ -15,7 +15,6 @@
*/
@interface SDWebImageTestDownloadOperation : NSOperation <SDWebImageDownloaderOperation>
@property (nonatomic, strong, nullable) NSURLCredential *credential;
@property (nonatomic, strong, nullable) NSURLRequest *request;
@property (nonatomic, strong, nullable) NSURLResponse *response;