|
#import <XCTest/XCTest.h> |
|
#import <KIF/KIF.h> |
|
|
|
#import "KSScrollPerformanceDetector.h" |
|
#import "usage.h" |
|
|
|
// This is specifically chosen to be the right speed to not trigger optimizations |
|
static const CGFloat KSScrollPerformanceTestsVelocity = -0.15f; |
|
|
|
@interface ButtonScrollPerformanceTests : KIFTestCase <KSScrollPerformanceDetectorDelegate> |
|
|
|
@property(nonatomic, assign, readwrite) NSInteger droppedFramesLimit; |
|
@property(nonatomic, assign, readwrite) NSInteger frameDropEventsLimit; |
|
@property(nonatomic, strong, nonnull) KSScrollPerformanceDetector *scrollPerformanceDetector; |
|
@property(nonatomic, strong, nonnull) UITableView *tableView; |
|
|
|
@end |
|
|
|
@implementation ButtonScrollPerformanceTests |
|
|
|
- (void)beforeEach { |
|
self.scrollPerformanceDetector = [[KSScrollPerformanceDetector alloc] init]; |
|
self.scrollPerformanceDetector.delegate = self; |
|
self.droppedFramesLimit = 3; |
|
self.frameDropEventsLimit = 3; |
|
} |
|
|
|
- (void)setUp { |
|
[super setUp]; |
|
// Put setup code here. This method is called before the invocation of each test method in the class. |
|
self.continueAfterFailure = YES; |
|
} |
|
|
|
- (void)testButtonPerformance { |
|
[tester tapViewWithAccessibilityLabel:@"Button"]; |
|
[tester tapViewWithAccessibilityLabel:@"Performance"]; |
|
[self scrollTableToEndWithIdentifier:@"performance-test-table"]; |
|
} |
|
|
|
- (void)scrollTableToEndWithIdentifier:(NSString *)accessibilityIdentifier { |
|
UITableView *tableView; |
|
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:accessibilityIdentifier tappable:NO]; |
|
self.tableView = tableView; |
|
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:[self.tableView numberOfRowsInSection:0] - 1 inSection:0]; |
|
NSArray<NSIndexPath *> *visibleIndexPaths = [self.tableView indexPathsForVisibleRows]; |
|
|
|
[self.scrollPerformanceDetector resume]; |
|
while (![visibleIndexPaths containsObject:lastIndexPath]) { |
|
[tester scrollViewWithAccessibilityIdentifier:accessibilityIdentifier byFractionOfSizeHorizontal:0.0f vertical:KSScrollPerformanceTestsVelocity]; |
|
visibleIndexPaths = [self.tableView indexPathsForVisibleRows]; |
|
[self.scrollPerformanceDetector clearFrameDropCount]; |
|
} |
|
[self.scrollPerformanceDetector pause]; |
|
} |
|
|
|
- (void)framesDropped:(NSInteger)framesDroppedCount cumulativeFramesDropped:(NSInteger)cumulativeFramesDropped cumulativeFrameDropEvents:(NSInteger)cumulativeFrameDropEvents { |
|
if (framesDroppedCount >= self.droppedFramesLimit) { |
|
XCTFail(@"Past limit for number of dropped frames"); |
|
} |
|
|
|
if (cumulativeFrameDropEvents >= self.frameDropEventsLimit) { |
|
XCTFail(@"Past limit for number of frame drop events"); |
|
} |
|
} |
|
|
|
@end |