1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/mac/scoped_nsobject.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop/message_pump_mac.h"
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_animation.h"
11 // This class runs an animation for exactly two frames then end it.
12 @interface ConstrainedWindowAnimationTestDelegate : NSObject
13 <NSAnimationDelegate> {
16 scoped_ptr<base::MessagePumpNSRunLoop> message_pump_;
19 - (void)runAnimation:(NSAnimation*)animation;
23 @implementation ConstrainedWindowAnimationTestDelegate
26 if ((self = [super init]))
27 message_pump_.reset(new base::MessagePumpNSRunLoop);
31 - (float)animation:(NSAnimation*)animation
32 valueForProgress:(NSAnimationProgress)progress {
35 [animation setDuration:0.0];
36 return frameCount_ == 1 ? 0.2 : 0.6;
39 - (void)animationDidEnd:(NSAnimation*)animation {
40 EXPECT_EQ(2, frameCount_);
41 message_pump_->Quit();
44 - (void)runAnimation:(NSAnimation*)animation {
45 // This class will end the animation after 2 frames. Set a large duration to
46 // ensure that both frames are processed.
47 [animation setDuration:600];
48 [animation setDelegate:self];
49 [animation startAnimation];
50 message_pump_->Run(NULL);
55 class ConstrainedWindowAnimationTest : public CocoaTest {
57 ConstrainedWindowAnimationTest() : CocoaTest() {
58 delegate_.reset([[ConstrainedWindowAnimationTestDelegate alloc] init]);
61 base::scoped_nsobject<ConstrainedWindowAnimationTestDelegate> delegate_;
64 // Test the show animation.
65 TEST_F(ConstrainedWindowAnimationTest, Show) {
66 base::scoped_nsobject<NSAnimation> animation(
67 [[ConstrainedWindowAnimationShow alloc] initWithWindow:test_window()]);
68 [delegate_ runAnimation:animation];
71 // Test the hide animation.
72 TEST_F(ConstrainedWindowAnimationTest, Hide) {
73 base::scoped_nsobject<NSAnimation> animation(
74 [[ConstrainedWindowAnimationHide alloc] initWithWindow:test_window()]);
75 [delegate_ runAnimation:animation];
78 // Test the pulse animation.
79 TEST_F(ConstrainedWindowAnimationTest, Pulse) {
80 base::scoped_nsobject<NSAnimation> animation(
81 [[ConstrainedWindowAnimationPulse alloc] initWithWindow:test_window()]);
82 [delegate_ runAnimation:animation];