Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: ui/gfx/animation/slide_animation_unittest.cc

Issue 2976873003: Added a nested class to gfx::Animation (Closed)
Patch Set: Removed animation export macro. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/animation/animation_test_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test/scoped_task_environment.h" 10 #include "base/test/scoped_task_environment.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/animation/animation_test_api.h"
13 #include "ui/gfx/animation/test_animation_delegate.h" 14 #include "ui/gfx/animation/test_animation_delegate.h"
14 15
15 namespace gfx { 16 namespace gfx {
16 17
17 // Class to provide access to SlideAnimation internals for testing.
18 class SlideAnimation::TestApi {
19 public:
20 explicit TestApi(SlideAnimation* animation) : animation_(animation) {}
21
22 void SetStartTime(base::TimeTicks ticks) {
23 animation_->SetStartTime(ticks);
24 }
25
26 void Step(base::TimeTicks ticks) {
27 animation_->Step(ticks);
28 }
29
30 private:
31 SlideAnimation* animation_;
32
33 DISALLOW_COPY_AND_ASSIGN(TestApi);
34 };
35
36 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
37 // SlideAnimationTest 19 // SlideAnimationTest
38 class SlideAnimationTest: public testing::Test { 20 class SlideAnimationTest : public testing::Test {
39 protected: 21 protected:
40 SlideAnimationTest() 22 SlideAnimationTest()
41 : scoped_task_environment_( 23 : scoped_task_environment_(
42 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} 24 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
43 25
44 private: 26 private:
45 base::test::ScopedTaskEnvironment scoped_task_environment_; 27 base::test::ScopedTaskEnvironment scoped_task_environment_;
46 }; 28 };
47 29
48 // Tests animation construction. 30 // Tests animation construction.
49 TEST_F(SlideAnimationTest, InitialState) { 31 TEST_F(SlideAnimationTest, InitialState) {
50 SlideAnimation animation(nullptr); 32 SlideAnimation animation(nullptr);
51 // By default, slide animations are 60 Hz, so the timer interval should be 33 // By default, slide animations are 60 Hz, so the timer interval should be
52 // 1/60th of a second. 34 // 1/60th of a second.
53 EXPECT_EQ(1000 / 60, animation.timer_interval().InMilliseconds()); 35 EXPECT_EQ(1000 / 60, animation.timer_interval().InMilliseconds());
54 // Duration defaults to 120 ms. 36 // Duration defaults to 120 ms.
55 EXPECT_EQ(120, animation.GetSlideDuration()); 37 EXPECT_EQ(120, animation.GetSlideDuration());
56 // Slide is neither showing nor closing. 38 // Slide is neither showing nor closing.
57 EXPECT_FALSE(animation.IsShowing()); 39 EXPECT_FALSE(animation.IsShowing());
58 EXPECT_FALSE(animation.IsClosing()); 40 EXPECT_FALSE(animation.IsClosing());
59 // Starts at 0. 41 // Starts at 0.
60 EXPECT_EQ(0.0, animation.GetCurrentValue()); 42 EXPECT_EQ(0.0, animation.GetCurrentValue());
61 } 43 }
62 44
63 TEST_F(SlideAnimationTest, Basics) { 45 TEST_F(SlideAnimationTest, Basics) {
64 SlideAnimation animation(nullptr); 46 SlideAnimation animation(nullptr);
65 SlideAnimation::TestApi test_api(&animation); 47 AnimationTestApi test_api(&animation);
66 48
67 // Use linear tweening to make the math easier below. 49 // Use linear tweening to make the math easier below.
68 animation.SetTweenType(Tween::LINEAR); 50 animation.SetTweenType(Tween::LINEAR);
69 51
70 // Duration can be set after construction. 52 // Duration can be set after construction.
71 animation.SetSlideDuration(100); 53 animation.SetSlideDuration(100);
72 EXPECT_EQ(100, animation.GetSlideDuration()); 54 EXPECT_EQ(100, animation.GetSlideDuration());
73 55
74 // Show toggles the appropriate state. 56 // Show toggles the appropriate state.
75 animation.Show(); 57 animation.Show();
(...skipping 28 matching lines...) Expand all
104 86
105 // Delete the animation. 87 // Delete the animation.
106 animation.reset(); 88 animation.reset();
107 89
108 // Make sure the delegate wasn't notified. 90 // Make sure the delegate wasn't notified.
109 EXPECT_FALSE(delegate.finished()); 91 EXPECT_FALSE(delegate.finished());
110 EXPECT_FALSE(delegate.canceled()); 92 EXPECT_FALSE(delegate.canceled());
111 } 93 }
112 94
113 } // namespace gfx 95 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/animation/animation_test_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698