OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/animation/slide_animation.h" | 5 #include "ui/gfx/animation/slide_animation.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
36 // SlideAnimationTest | 36 // SlideAnimationTest |
37 class SlideAnimationTest: public testing::Test { | 37 class SlideAnimationTest: public testing::Test { |
38 private: | 38 private: |
39 base::MessageLoopForUI message_loop_; | 39 base::MessageLoopForUI message_loop_; |
40 }; | 40 }; |
41 | 41 |
42 // Tests animation construction. | 42 // Tests animation construction. |
43 TEST_F(SlideAnimationTest, InitialState) { | 43 TEST_F(SlideAnimationTest, InitialState) { |
44 SlideAnimation animation(NULL); | 44 SlideAnimation animation(nullptr); |
45 // By default, slide animations are 60 Hz, so the timer interval should be | 45 // By default, slide animations are 60 Hz, so the timer interval should be |
46 // 1/60th of a second. | 46 // 1/60th of a second. |
47 EXPECT_EQ(1000 / 60, animation.timer_interval().InMilliseconds()); | 47 EXPECT_EQ(1000 / 60, animation.timer_interval().InMilliseconds()); |
48 // Duration defaults to 120 ms. | 48 // Duration defaults to 120 ms. |
49 EXPECT_EQ(120, animation.GetSlideDuration()); | 49 EXPECT_EQ(120, animation.GetSlideDuration()); |
50 // Slide is neither showing nor closing. | 50 // Slide is neither showing nor closing. |
51 EXPECT_FALSE(animation.IsShowing()); | 51 EXPECT_FALSE(animation.IsShowing()); |
52 EXPECT_FALSE(animation.IsClosing()); | 52 EXPECT_FALSE(animation.IsClosing()); |
53 // Starts at 0. | 53 // Starts at 0. |
54 EXPECT_EQ(0.0, animation.GetCurrentValue()); | 54 EXPECT_EQ(0.0, animation.GetCurrentValue()); |
55 } | 55 } |
56 | 56 |
57 TEST_F(SlideAnimationTest, Basics) { | 57 TEST_F(SlideAnimationTest, Basics) { |
58 SlideAnimation animation(NULL); | 58 SlideAnimation animation(nullptr); |
59 SlideAnimation::TestApi test_api(&animation); | 59 SlideAnimation::TestApi test_api(&animation); |
60 | 60 |
61 // Use linear tweening to make the math easier below. | 61 // Use linear tweening to make the math easier below. |
62 animation.SetTweenType(Tween::LINEAR); | 62 animation.SetTweenType(Tween::LINEAR); |
63 | 63 |
64 // Duration can be set after construction. | 64 // Duration can be set after construction. |
65 animation.SetSlideDuration(100); | 65 animation.SetSlideDuration(100); |
66 EXPECT_EQ(100, animation.GetSlideDuration()); | 66 EXPECT_EQ(100, animation.GetSlideDuration()); |
67 | 67 |
68 // Show toggles the appropriate state. | 68 // Show toggles the appropriate state. |
(...skipping 11 matching lines...) Expand all Loading... |
80 EXPECT_FALSE(animation.IsShowing()); | 80 EXPECT_FALSE(animation.IsShowing()); |
81 EXPECT_TRUE(animation.IsClosing()); | 81 EXPECT_TRUE(animation.IsClosing()); |
82 | 82 |
83 // Reset stops the animation. | 83 // Reset stops the animation. |
84 animation.Reset(); | 84 animation.Reset(); |
85 EXPECT_EQ(0.0, animation.GetCurrentValue()); | 85 EXPECT_EQ(0.0, animation.GetCurrentValue()); |
86 EXPECT_FALSE(animation.IsShowing()); | 86 EXPECT_FALSE(animation.IsShowing()); |
87 EXPECT_FALSE(animation.IsClosing()); | 87 EXPECT_FALSE(animation.IsClosing()); |
88 } | 88 } |
89 | 89 |
| 90 TEST_F(SlideAnimationTest, ShowAndHideImmediately) { |
| 91 SlideAnimation animation(nullptr); |
| 92 SlideAnimation::TestApi test_api(&animation); |
| 93 |
| 94 EXPECT_NE(1.0, animation.GetCurrentValue()); |
| 95 |
| 96 animation.ShowImmediately(); |
| 97 EXPECT_FALSE(animation.is_animating()); |
| 98 EXPECT_TRUE(animation.IsShowing()); |
| 99 EXPECT_EQ(1.0, animation.GetCurrentValue()); |
| 100 |
| 101 animation.HideImmediately(); |
| 102 EXPECT_FALSE(animation.is_animating()); |
| 103 EXPECT_EQ(0.0, animation.GetCurrentValue()); |
| 104 } |
| 105 |
90 // Tests that delegate is not notified when animation is running and is deleted. | 106 // Tests that delegate is not notified when animation is running and is deleted. |
91 // (Such a scenario would cause problems for BoundsAnimator). | 107 // (Such a scenario would cause problems for BoundsAnimator). |
92 TEST_F(SlideAnimationTest, DontNotifyOnDelete) { | 108 TEST_F(SlideAnimationTest, DontNotifyOnDelete) { |
93 TestAnimationDelegate delegate; | 109 TestAnimationDelegate delegate; |
94 std::unique_ptr<SlideAnimation> animation(new SlideAnimation(&delegate)); | 110 std::unique_ptr<SlideAnimation> animation(new SlideAnimation(&delegate)); |
95 | 111 |
96 // Start the animation. | 112 // Start the animation. |
97 animation->Show(); | 113 animation->Show(); |
98 | 114 |
99 // Delete the animation. | 115 // Delete the animation. |
100 animation.reset(); | 116 animation.reset(); |
101 | 117 |
102 // Make sure the delegate wasn't notified. | 118 // Make sure the delegate wasn't notified. |
103 EXPECT_FALSE(delegate.finished()); | 119 EXPECT_FALSE(delegate.finished()); |
104 EXPECT_FALSE(delegate.canceled()); | 120 EXPECT_FALSE(delegate.canceled()); |
105 } | 121 } |
106 | 122 |
107 } // namespace gfx | 123 } // namespace gfx |
OLD | NEW |