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

Side by Side Diff: ui/base/animation/multi_animation_unittest.cc

Issue 11274063: Make MultiAnimation take time param and slow down tab highlight (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bad var name Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/animation/multi_animation.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/base/animation/animation_container_element.h" 6 #include "ui/base/animation/animation_container_element.h"
7 #include "ui/base/animation/multi_animation.h" 7 #include "ui/base/animation/multi_animation.h"
8 8
9 namespace ui { 9 namespace ui {
10 10
11 TEST(MultiAnimationTest, Basic) { 11 TEST(MultiAnimationTest, Basic) {
12 // Create a MultiAnimation with two parts. 12 // Create a MultiAnimation with two parts.
13 MultiAnimation::Parts parts; 13 MultiAnimation::Parts parts;
14 parts.push_back(MultiAnimation::Part(100, Tween::LINEAR)); 14 parts.push_back(MultiAnimation::Part(100, Tween::LINEAR));
15 parts.push_back(MultiAnimation::Part(100, Tween::EASE_OUT)); 15 parts.push_back(MultiAnimation::Part(100, Tween::EASE_OUT));
16 16
17 MultiAnimation animation(parts); 17 MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
18 AnimationContainerElement* as_element = 18 AnimationContainerElement* as_element =
19 static_cast<AnimationContainerElement*>(&animation); 19 static_cast<AnimationContainerElement*>(&animation);
20 as_element->SetStartTime(base::TimeTicks()); 20 as_element->SetStartTime(base::TimeTicks());
21 21
22 // Step to 50, which is half way through the first part. 22 // Step to 50, which is half way through the first part.
23 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(50)); 23 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(50));
24 EXPECT_EQ(.5, animation.GetCurrentValue()); 24 EXPECT_EQ(.5, animation.GetCurrentValue());
25 25
26 // Step to 120, which is 20% through the second part. 26 // Step to 120, which is 20% through the second part.
27 as_element->Step(base::TimeTicks() + 27 as_element->Step(base::TimeTicks() +
28 base::TimeDelta::FromMilliseconds(120)); 28 base::TimeDelta::FromMilliseconds(120));
29 EXPECT_DOUBLE_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2), 29 EXPECT_DOUBLE_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
30 animation.GetCurrentValue()); 30 animation.GetCurrentValue());
31 31
32 // Step to 320, which is 20% through the second part. 32 // Step to 320, which is 20% through the second part.
33 as_element->Step(base::TimeTicks() + 33 as_element->Step(base::TimeTicks() +
34 base::TimeDelta::FromMilliseconds(320)); 34 base::TimeDelta::FromMilliseconds(320));
35 EXPECT_DOUBLE_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2), 35 EXPECT_DOUBLE_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
36 animation.GetCurrentValue()); 36 animation.GetCurrentValue());
37 } 37 }
38 38
39 TEST(MultiAnimationTest, DifferingStartAndEnd) { 39 TEST(MultiAnimationTest, DifferingStartAndEnd) {
40 // Create a MultiAnimation with two parts. 40 // Create a MultiAnimation with two parts.
41 MultiAnimation::Parts parts; 41 MultiAnimation::Parts parts;
42 parts.push_back(MultiAnimation::Part(200, Tween::LINEAR)); 42 parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
43 parts[0].start_time_ms = 100; 43 parts[0].start_time_ms = 100;
44 parts[0].end_time_ms = 400; 44 parts[0].end_time_ms = 400;
45 45
46 MultiAnimation animation(parts); 46 MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
47 AnimationContainerElement* as_element = 47 AnimationContainerElement* as_element =
48 static_cast<AnimationContainerElement*>(&animation); 48 static_cast<AnimationContainerElement*>(&animation);
49 as_element->SetStartTime(base::TimeTicks()); 49 as_element->SetStartTime(base::TimeTicks());
50 50
51 // Step to 0. Because the start_time is 100, this should be 100ms into the 51 // Step to 0. Because the start_time is 100, this should be 100ms into the
52 // animation 52 // animation
53 as_element->Step(base::TimeTicks()); 53 as_element->Step(base::TimeTicks());
54 EXPECT_EQ(.25, animation.GetCurrentValue()); 54 EXPECT_EQ(.25, animation.GetCurrentValue());
55 55
56 // Step to 100, which is effectively 200ms into the animation. 56 // Step to 100, which is effectively 200ms into the animation.
57 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(100)); 57 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(100));
58 EXPECT_EQ(.5, animation.GetCurrentValue()); 58 EXPECT_EQ(.5, animation.GetCurrentValue());
59 } 59 }
60 60
61 // Makes sure multi-animation stops if cycles is false. 61 // Makes sure multi-animation stops if cycles is false.
62 TEST(MultiAnimationTest, DontCycle) { 62 TEST(MultiAnimationTest, DontCycle) {
63 MultiAnimation::Parts parts; 63 MultiAnimation::Parts parts;
64 parts.push_back(MultiAnimation::Part(200, Tween::LINEAR)); 64 parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
65 MultiAnimation animation(parts); 65 MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
66 AnimationContainerElement* as_element = 66 AnimationContainerElement* as_element =
67 static_cast<AnimationContainerElement*>(&animation); 67 static_cast<AnimationContainerElement*>(&animation);
68 as_element->SetStartTime(base::TimeTicks()); 68 as_element->SetStartTime(base::TimeTicks());
69 animation.set_continuous(false); 69 animation.set_continuous(false);
70 70
71 // Step to 300, which is greater than the cycle time. 71 // Step to 300, which is greater than the cycle time.
72 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300)); 72 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
73 EXPECT_EQ(1.0, animation.GetCurrentValue()); 73 EXPECT_EQ(1.0, animation.GetCurrentValue());
74 EXPECT_FALSE(animation.is_animating()); 74 EXPECT_FALSE(animation.is_animating());
75 } 75 }
76 76
77 // Makes sure multi-animation cycles correctly. 77 // Makes sure multi-animation cycles correctly.
78 TEST(MultiAnimationTest, Cycle) { 78 TEST(MultiAnimationTest, Cycle) {
79 MultiAnimation::Parts parts; 79 MultiAnimation::Parts parts;
80 parts.push_back(MultiAnimation::Part(200, Tween::LINEAR)); 80 parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
81 MultiAnimation animation(parts); 81 MultiAnimation animation(parts, MultiAnimation::GetDefaultTimerInterval());
82 AnimationContainerElement* as_element = 82 AnimationContainerElement* as_element =
83 static_cast<AnimationContainerElement*>(&animation); 83 static_cast<AnimationContainerElement*>(&animation);
84 as_element->SetStartTime(base::TimeTicks()); 84 as_element->SetStartTime(base::TimeTicks());
85 85
86 // Step to 300, which is greater than the cycle time. 86 // Step to 300, which is greater than the cycle time.
87 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300)); 87 as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
88 EXPECT_EQ(.5, animation.GetCurrentValue()); 88 EXPECT_EQ(.5, animation.GetCurrentValue());
89 } 89 }
90 90
91 } // namespace ui 91 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/animation/multi_animation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698