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

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

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

Powered by Google App Engine
This is Rietveld 408576698