mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Fix ASBasicImageDownloader tests - prevent use of init / new instead of +sharedImageDownloader.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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"];
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user