Add default PINRemoteImageDownloader

This commit is contained in:
Garrett Moon
2016-02-08 16:00:19 -08:00
parent 08017071bf
commit 5a4e4dcac4
10 changed files with 457 additions and 89 deletions

View File

@@ -145,14 +145,14 @@ static BOOL ASRunRunLoopUntilBlockIsTrue(BOOL (^block)())
NSArray *URL;
[inv getArgument:&URL atIndex:2];
void (^completionBlock)(CGImageRef);
ASImageCacherCompletion completionBlock;
[inv getArgument:&completionBlock atIndex:4];
// Call the completion block with our test image and URL.
NSURL *testImageURL = [self _testImageURL];
XCTAssertEqualObjects(URL, testImageURL, @"Fetching URL other than test image");
completionBlock([self _testImage].CGImage);
}] fetchCachedImageWithURL:[OCMArg any] callbackQueue:[OCMArg any] completion:[OCMArg any]];
completionBlock([self _testImage]);
}] cachedImageWithURL:[OCMArg any] callbackQueue:[OCMArg any] completion:[OCMArg any]];
imageNode.imageIdentifiers = @[imageIdentifier];
// Kick off loading.
@@ -302,25 +302,25 @@ static BOOL ASRunRunLoopUntilBlockIsTrue(BOOL (^block)())
// Mock a cache miss.
id mockCache = [OCMockObject mockForProtocol:@protocol(ASImageCacheProtocol)];
[[[mockCache stub] andDo:^(NSInvocation *inv) {
void (^completion)(CGImageRef imageFromCache);
ASImageCacherCompletion completion;
[inv getArgument:&completion atIndex:4];
completion(nil);
}] fetchCachedImageWithURL:[OCMArg any] callbackQueue:[OCMArg any] completion:[OCMArg any]];
}] cachedImageWithURL:[OCMArg any] callbackQueue:[OCMArg any] completion:[OCMArg any]];
// Mock a 50%-progress URL download.
id mockDownloader = [OCMockObject mockForProtocol:@protocol(ASImageDownloaderProtocol)];
const CGFloat mockedProgress = 0.5;
[[[mockDownloader stub] andDo:^(NSInvocation *inv) {
// Simulate progress.
void (^progressBlock)(CGFloat progress);
ASImageDownloaderProgress progressBlock;
[inv getArgument:&progressBlock atIndex:4];
progressBlock(mockedProgress);
// Simulate completion.
void (^completionBlock)(CGImageRef image, NSError *error);
ASImageDownloaderCompletion completionBlock;
[inv getArgument:&completionBlock atIndex:5];
completionBlock([self _testImage].CGImage, nil);
}] downloadImageWithURL:[OCMArg any] callbackQueue:[OCMArg any] downloadProgressBlock:[OCMArg any] completion:[OCMArg any]];
completionBlock([self _testImage], nil, nil);
}] downloadImageWithURL:[OCMArg any] callbackQueue:[OCMArg any] downloadProgress:[OCMArg any] completion:[OCMArg any]];
ASMultiplexImageNode *imageNode = [[ASMultiplexImageNode alloc] initWithCache:mockCache downloader:mockDownloader];
NSNumber *imageIdentifier = @1;