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

Side by Side Diff: app/multi_animation_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698