diff --git a/AppKit/CPAnimation.j b/AppKit/CPAnimation.j index c79f1e2bb..67b4ae7fb 100644 --- a/AppKit/CPAnimation.j +++ b/AppKit/CPAnimation.j @@ -236,7 +236,9 @@ ACTUAL_FRAME_RATE = 0; ACTUAL_FRAME_RATE = 0; _lastTime = new Date(); - _timer = [CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(animationTimerDidFire:) userInfo:nil repeats:YES]; + var timerInterval = _frameRate <= 0.0 ? 0.0001 : 1.0/_frameRate; + + _timer = [CPTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selector(animationTimerDidFire:) userInfo:nil repeats:YES]; } /* diff --git a/Tests/AppKit/CPAnimationTest.j b/Tests/AppKit/CPAnimationTest.j new file mode 100644 index 000000000..d151d82bc --- /dev/null +++ b/Tests/AppKit/CPAnimationTest.j @@ -0,0 +1,47 @@ +@import +@import + +[CPApplication sharedApplication]; + +@implementation CPAnimation (TestMethods) +{ +} + +- (CPTimer)timer +{ + return _timer; +} + +@end + +@implementation CPAnimationTest : OJTestCase +{ +} + +- (void)testScheduleTimerWithIntervalBasedOnDefaultFrameRate +{ + var animation = [[CPAnimation alloc] initWithDuration:0.1 animationCurve:CPAnimationLinear]; + [animation startAnimation]; + + [self assert:1.0/60.0 equals:[[animation timer] timeInterval]]; +} + +- (void)testScheduleTimerWithIntervalBasedOnCustomFrameRate +{ + var animation = [[CPAnimation alloc] initWithDuration:0.1 animationCurve:CPAnimationLinear]; + [animation setFrameRate:30]; + [animation startAnimation]; + + [self assert:1.0/30.0 equals:[[animation timer] timeInterval]]; +} + +- (void)testScheduleTimerWithIntervalBasedOnAsFastAsPossibleFrameRate +{ + var animation = [[CPAnimation alloc] initWithDuration:0.1 animationCurve:CPAnimationLinear]; + [animation setFrameRate:0]; + [animation startAnimation]; + + [self assert:0.0001 equals:[[animation timer] timeInterval]]; +} + +@end