OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "base/memory/scoped_nsobject.h" |
| 6 #include "base/message_pump_mac.h" |
| 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_animation
.h" |
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 9 |
| 10 // This class runs an animation for exactly two frames then end its. |
| 11 @interface ConstrainedWindowAnimationTestDelegate : NSObject |
| 12 <NSAnimationDelegate> { |
| 13 @private |
| 14 CGFloat frameCount_; |
| 15 scoped_refptr<base::MessagePumpNSRunLoop> message_pump_; |
| 16 } |
| 17 |
| 18 - (void)runAnimation:(NSAnimation*)animation; |
| 19 |
| 20 @end |
| 21 |
| 22 @implementation ConstrainedWindowAnimationTestDelegate |
| 23 |
| 24 - (id)init { |
| 25 if ((self = [super init])) |
| 26 message_pump_ = new base::MessagePumpNSRunLoop; |
| 27 return self; |
| 28 } |
| 29 |
| 30 - (float)animation:(NSAnimation *)animation |
| 31 valueForProgress:(NSAnimationProgress)progress { |
| 32 frameCount_++; |
| 33 if (frameCount_ >= 2) |
| 34 [animation setDuration:0.0]; |
| 35 return frameCount_ == 1 ? 0.2 : 0.6; |
| 36 } |
| 37 |
| 38 - (void)animationDidEnd:(NSAnimation*)animation { |
| 39 EXPECT_EQ(2, frameCount_); |
| 40 message_pump_->Quit(); |
| 41 } |
| 42 |
| 43 - (void)runAnimation:(NSAnimation*)animation { |
| 44 // This class will end the animation after 2 frames. Set a large duration to |
| 45 // ensure that get both frames are processed. |
| 46 [animation setDuration:600]; |
| 47 [animation setDelegate:self]; |
| 48 [animation startAnimation]; |
| 49 message_pump_->Run(NULL); |
| 50 } |
| 51 |
| 52 @end |
| 53 |
| 54 class ConstrainedWindowAnimationTest : public CocoaTest { |
| 55 protected: |
| 56 ConstrainedWindowAnimationTest() : CocoaTest() { |
| 57 delegate_.reset([[ConstrainedWindowAnimationTestDelegate alloc] init]); |
| 58 } |
| 59 |
| 60 scoped_nsobject<ConstrainedWindowAnimationTestDelegate> delegate_; |
| 61 }; |
| 62 |
| 63 // Test the show animation. |
| 64 TEST_F(ConstrainedWindowAnimationTest, Show) { |
| 65 scoped_nsobject<NSAnimation> animation( |
| 66 [[ConstrainedWindowAnimationShow alloc] initWithWindow:test_window()]); |
| 67 ASSERT_TRUE(animation.get()); |
| 68 [delegate_ runAnimation:animation]; |
| 69 } |
| 70 |
| 71 // Test the hide animation. |
| 72 TEST_F(ConstrainedWindowAnimationTest, Hide) { |
| 73 scoped_nsobject<NSAnimation> animation( |
| 74 [[ConstrainedWindowAnimationHide alloc] initWithWindow:test_window()]); |
| 75 ASSERT_TRUE(animation.get()); |
| 76 [delegate_ runAnimation:animation]; |
| 77 } |
| 78 |
| 79 // Test the pulse animation. |
| 80 TEST_F(ConstrainedWindowAnimationTest, Pulse) { |
| 81 scoped_nsobject<NSAnimation> animation( |
| 82 [[ConstrainedWindowAnimationPulse alloc] initWithWindow:test_window()]); |
| 83 ASSERT_TRUE(animation.get()); |
| 84 [delegate_ runAnimation:animation]; |
| 85 } |
OLD | NEW |