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

Side by Side Diff: cc/animation/scroll_offset_animation_curve_unittest.cc

Issue 719453007: Make Keyframe use TimeTicks/TimeDelta to represent time instead of double. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/animation/scroll_offset_animation_curve.h" 5 #include "cc/animation/scroll_offset_animation_curve.h"
6 6
7 #include "cc/animation/timing_function.h" 7 #include "cc/animation/timing_function.h"
8 #include "cc/test/geometry_test_utils.h" 8 #include "cc/test/geometry_test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 EaseInOutTimingFunction::Create().Pass())); 63 EaseInOutTimingFunction::Create().Pass()));
64 curve->SetInitialValue(initial_value); 64 curve->SetInitialValue(initial_value);
65 65
66 double duration_in_seconds = curve->Duration().InSecondsF(); 66 double duration_in_seconds = curve->Duration().InSecondsF();
67 EXPECT_GT(curve->Duration().InSecondsF(), 0); 67 EXPECT_GT(curve->Duration().InSecondsF(), 0);
68 EXPECT_LT(curve->Duration().InSecondsF(), 0.1); 68 EXPECT_LT(curve->Duration().InSecondsF(), 0.1);
69 69
70 EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type()); 70 EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type());
71 EXPECT_EQ(duration_in_seconds, curve->Duration().InSecondsF()); 71 EXPECT_EQ(duration_in_seconds, curve->Duration().InSecondsF());
72 72
73 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(-1.0)); 73 EXPECT_VECTOR2DF_EQ(initial_value,
74 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(0.0)); 74 curve->GetValue(base::TimeDelta::FromSecondsD(-1.0)));
75 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(base::TimeDelta()));
75 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f), 76 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f),
76 curve->GetValue(duration_in_seconds / 2.0)); 77 curve->GetValue(base::TimeDelta::FromSecondsD(
77 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds)); 78 duration_in_seconds / 2.0)));
78 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds + 1.0)); 79 EXPECT_VECTOR2DF_EQ(
80 target_value,
81 curve->GetValue(base::TimeDelta::FromSecondsD(duration_in_seconds)));
82 EXPECT_VECTOR2DF_EQ(target_value,
83 curve->GetValue(base::TimeDelta::FromSecondsD(
84 duration_in_seconds + 1.0)));
79 85
80 // Verify that GetValue takes the timing function into account. 86 // Verify that GetValue takes the timing function into account.
81 gfx::ScrollOffset value = curve->GetValue(duration_in_seconds / 4.0); 87 gfx::ScrollOffset value =
88 curve->GetValue(base::TimeDelta::FromSecondsD(duration_in_seconds / 4.0));
82 EXPECT_NEAR(3.0333f, value.x(), 0.00015f); 89 EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
83 EXPECT_NEAR(37.4168f, value.y(), 0.00015f); 90 EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
84 } 91 }
85 92
86 // Verify that a clone behaves exactly like the original. 93 // Verify that a clone behaves exactly like the original.
87 TEST(ScrollOffsetAnimationCurveTest, Clone) { 94 TEST(ScrollOffsetAnimationCurveTest, Clone) {
88 gfx::ScrollOffset initial_value(2.f, 40.f); 95 gfx::ScrollOffset initial_value(2.f, 40.f);
89 gfx::ScrollOffset target_value(10.f, 20.f); 96 gfx::ScrollOffset target_value(10.f, 20.f);
90 scoped_ptr<ScrollOffsetAnimationCurve> curve( 97 scoped_ptr<ScrollOffsetAnimationCurve> curve(
91 ScrollOffsetAnimationCurve::Create( 98 ScrollOffsetAnimationCurve::Create(
92 target_value, 99 target_value,
93 EaseInOutTimingFunction::Create().Pass())); 100 EaseInOutTimingFunction::Create().Pass()));
94 curve->SetInitialValue(initial_value); 101 curve->SetInitialValue(initial_value);
95 double duration_in_seconds = curve->Duration().InSecondsF(); 102 double duration_in_seconds = curve->Duration().InSecondsF();
ajuma 2014/11/14 15:12:33 We should just use duration as a TimeDelta rather
patro 2014/11/17 13:26:47 Done.
96 103
97 scoped_ptr<AnimationCurve> clone(curve->Clone().Pass()); 104 scoped_ptr<AnimationCurve> clone(curve->Clone().Pass());
98 105
99 EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type()); 106 EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type());
100 EXPECT_EQ(duration_in_seconds, clone->Duration().InSecondsF()); 107 EXPECT_EQ(duration_in_seconds, clone->Duration().InSecondsF());
101 108
102 EXPECT_VECTOR2DF_EQ(initial_value, 109 EXPECT_VECTOR2DF_EQ(initial_value,
103 clone->ToScrollOffsetAnimationCurve()->GetValue(-1.0));
104 EXPECT_VECTOR2DF_EQ(initial_value,
105 clone->ToScrollOffsetAnimationCurve()->GetValue(0.0));
106 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f),
107 clone->ToScrollOffsetAnimationCurve()->GetValue( 110 clone->ToScrollOffsetAnimationCurve()->GetValue(
108 duration_in_seconds / 2.0)); 111 base::TimeDelta::FromSecondsD(-1.0)));
112 EXPECT_VECTOR2DF_EQ(
113 initial_value,
114 clone->ToScrollOffsetAnimationCurve()->GetValue(base::TimeDelta()));
115 EXPECT_VECTOR2DF_EQ(
116 gfx::ScrollOffset(6.f, 30.f),
117 clone->ToScrollOffsetAnimationCurve()->GetValue(
118 base::TimeDelta::FromSecondsD(duration_in_seconds / 2.0)));
119 EXPECT_VECTOR2DF_EQ(target_value,
120 clone->ToScrollOffsetAnimationCurve()->GetValue(
121 base::TimeDelta::FromSecondsD(duration_in_seconds)));
109 EXPECT_VECTOR2DF_EQ( 122 EXPECT_VECTOR2DF_EQ(
110 target_value, 123 target_value,
111 clone->ToScrollOffsetAnimationCurve()->GetValue(duration_in_seconds)); 124 clone->ToScrollOffsetAnimationCurve()->GetValue(
112 EXPECT_VECTOR2DF_EQ(target_value, 125 base::TimeDelta::FromSecondsD(duration_in_seconds + 1.0)));
113 clone->ToScrollOffsetAnimationCurve()->GetValue(
114 duration_in_seconds + 1.0));
115 126
116 // Verify that the timing function was cloned correctly. 127 // Verify that the timing function was cloned correctly.
117 gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue( 128 gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue(
118 duration_in_seconds / 4.0); 129 base::TimeDelta::FromSecondsD(duration_in_seconds / 4.0));
119 EXPECT_NEAR(3.0333f, value.x(), 0.00015f); 130 EXPECT_NEAR(3.0333f, value.x(), 0.00015f);
120 EXPECT_NEAR(37.4168f, value.y(), 0.00015f); 131 EXPECT_NEAR(37.4168f, value.y(), 0.00015f);
121 } 132 }
122 133
123 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) { 134 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
124 gfx::ScrollOffset initial_value(0.f, 0.f); 135 gfx::ScrollOffset initial_value(0.f, 0.f);
125 gfx::ScrollOffset target_value(0.f, 3600.f); 136 gfx::ScrollOffset target_value(0.f, 3600.f);
126 scoped_ptr<ScrollOffsetAnimationCurve> curve( 137 scoped_ptr<ScrollOffsetAnimationCurve> curve(
127 ScrollOffsetAnimationCurve::Create( 138 ScrollOffsetAnimationCurve::Create(
128 target_value, EaseInOutTimingFunction::Create().Pass())); 139 target_value, EaseInOutTimingFunction::Create().Pass()));
129 curve->SetInitialValue(initial_value); 140 curve->SetInitialValue(initial_value);
130 EXPECT_EQ(1.0, curve->Duration().InSecondsF()); 141 EXPECT_EQ(1.0, curve->Duration().InSecondsF());
131 EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); 142 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
132 EXPECT_EQ(3600.0, curve->GetValue(1.0).y()); 143 EXPECT_EQ(3600.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y());
133 144
134 curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0)); 145 curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0));
135 146
136 EXPECT_EQ(2.0, curve->Duration().InSecondsF()); 147 EXPECT_EQ(2.0, curve->Duration().InSecondsF());
137 EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); 148 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
138 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); 149 EXPECT_NEAR(5566.49, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
139 EXPECT_EQ(9900.0, curve->GetValue(2.0).y()); 150 0.01);
151 EXPECT_EQ(9900.0, curve->GetValue(base::TimeDelta::FromSecondsD(2.0)).y());
140 152
141 curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0)); 153 curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0));
142 154
143 EXPECT_NEAR(1.674, curve->Duration().InSecondsF(), 0.01); 155 EXPECT_NEAR(1.674, curve->Duration().InSecondsF(), 0.01);
144 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); 156 EXPECT_NEAR(5566.49, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
145 EXPECT_EQ(7200.0, curve->GetValue(1.674).y()); 157 0.01);
158 EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.674)).y());
146 } 159 }
147 160
148 } // namespace 161 } // namespace
149 } // namespace cc 162 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698