blob: d646282e1c3f83b2c9be504ce865a957044d2792 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
#include <memory>
#include "base/mac/scoped_nsobject.h"
#import "ui/base/test/cocoa_helper.h"
// This class runs an animation for exactly two frames then end it.
@interface ConstrainedWindowAnimationTestDelegate
: NSObject<NSAnimationDelegate> {
@private
CGFloat frameCount_;
}
- (void)runAnimation:(NSAnimation*)animation;
@end
@implementation ConstrainedWindowAnimationTestDelegate
- (float)animation:(NSAnimation*)animation
valueForProgress:(NSAnimationProgress)progress {
++frameCount_;
if (frameCount_ >= 2)
[animation setDuration:0.0];
return frameCount_ == 1 ? 0.2 : 0.6;
}
- (void)animationDidEnd:(NSAnimation*)animation {
EXPECT_EQ(2, frameCount_);
}
- (void)runAnimation:(NSAnimation*)animation {
// This class will end the animation after 2 frames. Set a large duration to
// ensure that both frames are processed.
[animation setDuration:600];
[animation setDelegate:self];
[animation startAnimation];
EXPECT_EQ(2, frameCount_);
}
@end
class ConstrainedWindowAnimationTest : public ui::CocoaTest {
protected:
ConstrainedWindowAnimationTest() : CocoaTest() {
delegate_.reset([[ConstrainedWindowAnimationTestDelegate alloc] init]);
}
base::scoped_nsobject<ConstrainedWindowAnimationTestDelegate> delegate_;
};
// Test the show animation.
TEST_F(ConstrainedWindowAnimationTest, Show) {
base::scoped_nsobject<NSAnimation> animation(
[[ConstrainedWindowAnimationShow alloc] initWithWindow:test_window()]);
[delegate_ runAnimation:animation];
}
// Test the hide animation.
TEST_F(ConstrainedWindowAnimationTest, Hide) {
base::scoped_nsobject<NSAnimation> animation(
[[ConstrainedWindowAnimationHide alloc] initWithWindow:test_window()]);
[delegate_ runAnimation:animation];
}
// Test the pulse animation.
TEST_F(ConstrainedWindowAnimationTest, Pulse) {
base::scoped_nsobject<NSAnimation> animation(
[[ConstrainedWindowAnimationPulse alloc] initWithWindow:test_window()]);
[delegate_ runAnimation:animation];
}