Fix ASBasicImageDownloader tests - prevent use of init / new instead of +sharedImageDownloader.

This commit is contained in:
Scott Goodson
2015-12-20 15:42:57 -08:00
parent 97bb05d326
commit b8602d1073
6 changed files with 26 additions and 10 deletions

View File

@@ -1251,6 +1251,19 @@ static NSInteger incrementIfFound(NSInteger i) {
}
}
- (BOOL)__visibilityNotificationsDisabled
{
// Currently, this method is only used by the testing infrastructure to verify this internal feature.
ASDN::MutexLocker l(_propertyLock);
return _flags.visibilityNotificationsDisabled > 0;
}
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled
{
ASDN::MutexLocker l(_propertyLock);
return (_hierarchyState & ASHierarchyStateTransitioningSupernodes);
}
- (void)__incrementVisibilityNotificationsDisabled
{
ASDN::MutexLocker l(_propertyLock);
@@ -1282,12 +1295,6 @@ static NSInteger incrementIfFound(NSInteger i) {
}
}
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled
{
ASDN::MutexLocker l(_propertyLock);
return (_hierarchyState & ASHierarchyStateTransitioningSupernodes);
}
- (void)__enterHierarchy
{
ASDisplayNodeAssertMainThread();

View File

@@ -16,4 +16,7 @@
+ (instancetype)sharedImageDownloader;
+ (instancetype)new __attribute__((unavailable("+[ASBasicImageDownloader sharedImageDownloader] must be used.")));
- (instancetype)init __attribute__((unavailable("+[ASBasicImageDownloader sharedImageDownloader] must be used.")));
@end

View File

@@ -205,14 +205,14 @@ static const char *kContextKey = NSStringFromClass(ASBasicImageDownloaderContext
static ASBasicImageDownloader *sharedImageDownloader = nil;
static dispatch_once_t once = 0;
dispatch_once(&once, ^{
sharedImageDownloader = [[ASBasicImageDownloader alloc] init];
sharedImageDownloader = [[ASBasicImageDownloader alloc] _init];
});
return sharedImageDownloader;
}
#pragma mark Lifecycle.
- (instancetype)init
- (instancetype)_init
{
if (!(self = [super init]))
return nil;

View File

@@ -135,6 +135,7 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides)
// Private API for helper functions / unit tests. Use ASDisplayNodeDisableHierarchyNotifications() to control this.
- (BOOL)__visibilityNotificationsDisabled;
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled;
- (void)__incrementVisibilityNotificationsDisabled;
- (void)__decrementVisibilityNotificationsDisabled;

View File

@@ -16,8 +16,9 @@
@implementation ASBasicImageDownloaderTests
- (void)testAsynchronouslyDownloadTheSameURLTwice {
ASBasicImageDownloader *downloader = [ASBasicImageDownloader new];
- (void)testAsynchronouslyDownloadTheSameURLTwice
{
ASBasicImageDownloader *downloader = [ASBasicImageDownloader sharedImageDownloader];
NSURL *URL = [NSURL URLWithString:@"http://wrongPath/wrongResource.png"];

View File

@@ -49,6 +49,7 @@ static dispatch_block_t modifyMethodByAddingPrologueBlockAndReturnCleanupBlock(C
@interface ASDisplayNode (PrivateStuffSoWeDontPullInCPPInternalH)
- (BOOL)__visibilityNotificationsDisabled;
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled;
- (id)initWithViewClass:(Class)viewClass;
- (id)initWithLayerClass:(Class)layerClass;
@end
@@ -360,6 +361,7 @@ static UIView *viewWithName(NSString *name) {
}
if (useManualDisable) {
XCTAssertTrue([child __visibilityNotificationsDisabled], @"Should not have re-enabled yet");
XCTAssertTrue([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet");
ASDisplayNodeEnableHierarchyNotifications(child);
}
@@ -377,6 +379,7 @@ static UIView *viewWithName(NSString *name) {
}
if (useManualDisable) {
XCTAssertTrue([child __visibilityNotificationsDisabled], @"Should not have re-enabled yet");
XCTAssertTrue([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet");
ASDisplayNodeEnableHierarchyNotifications(child);
}
@@ -390,6 +393,7 @@ static UIView *viewWithName(NSString *name) {
// Make sure that we don't leave these unbalanced
XCTAssertFalse([child __visibilityNotificationsDisabled], @"Unbalanced visibility notifications calls");
XCTAssertFalse([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet");
[window release];
}