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

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
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | cc/base/time_util.h » ('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 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/base/time_util.h"
8 #include "cc/test/geometry_test_utils.h" 9 #include "cc/test/geometry_test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace cc { 12 namespace cc {
12 namespace { 13 namespace {
13 14
14 TEST(ScrollOffsetAnimationCurveTest, Duration) { 15 TEST(ScrollOffsetAnimationCurveTest, Duration) {
15 gfx::ScrollOffset target_value(100.f, 200.f); 16 gfx::ScrollOffset target_value(100.f, 200.f);
16 scoped_ptr<ScrollOffsetAnimationCurve> curve( 17 scoped_ptr<ScrollOffsetAnimationCurve> curve(
17 ScrollOffsetAnimationCurve::Create( 18 ScrollOffsetAnimationCurve::Create(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 57
57 TEST(ScrollOffsetAnimationCurveTest, GetValue) { 58 TEST(ScrollOffsetAnimationCurveTest, GetValue) {
58 gfx::ScrollOffset initial_value(2.f, 40.f); 59 gfx::ScrollOffset initial_value(2.f, 40.f);
59 gfx::ScrollOffset target_value(10.f, 20.f); 60 gfx::ScrollOffset target_value(10.f, 20.f);
60 scoped_ptr<ScrollOffsetAnimationCurve> curve( 61 scoped_ptr<ScrollOffsetAnimationCurve> curve(
61 ScrollOffsetAnimationCurve::Create( 62 ScrollOffsetAnimationCurve::Create(
62 target_value, 63 target_value,
63 EaseInOutTimingFunction::Create().Pass())); 64 EaseInOutTimingFunction::Create().Pass()));
64 curve->SetInitialValue(initial_value); 65 curve->SetInitialValue(initial_value);
65 66
66 double duration_in_seconds = curve->Duration().InSecondsF(); 67 base::TimeDelta duration = curve->Duration();
67 EXPECT_GT(curve->Duration().InSecondsF(), 0); 68 EXPECT_GT(curve->Duration().InSecondsF(), 0);
68 EXPECT_LT(curve->Duration().InSecondsF(), 0.1); 69 EXPECT_LT(curve->Duration().InSecondsF(), 0.1);
69 70
70 EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type()); 71 EXPECT_EQ(AnimationCurve::ScrollOffset, curve->Type());
71 EXPECT_EQ(duration_in_seconds, curve->Duration().InSecondsF()); 72 EXPECT_EQ(duration, curve->Duration());
72 73
73 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(-1.0)); 74 EXPECT_VECTOR2DF_EQ(initial_value,
74 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(0.0)); 75 curve->GetValue(base::TimeDelta::FromSecondsD(-1.0)));
75 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(6.f, 30.f), 76 EXPECT_VECTOR2DF_EQ(initial_value, curve->GetValue(base::TimeDelta()));
76 curve->GetValue(duration_in_seconds / 2.0)); 77 EXPECT_VECTOR2DF_NEAR(gfx::ScrollOffset(6.f, 30.f),
77 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds)); 78 curve->GetValue(TimeUtil::Scale(duration, 0.5f)),
78 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration_in_seconds + 1.0)); 79 0.00025);
80 EXPECT_VECTOR2DF_EQ(target_value, curve->GetValue(duration));
81 EXPECT_VECTOR2DF_EQ(
82 target_value,
83 curve->GetValue(duration + base::TimeDelta::FromSecondsD(1.0)));
79 84
80 // Verify that GetValue takes the timing function into account. 85 // Verify that GetValue takes the timing function into account.
81 gfx::ScrollOffset value = curve->GetValue(duration_in_seconds / 4.0); 86 gfx::ScrollOffset value = curve->GetValue(TimeUtil::Scale(duration, 0.25f));
82 EXPECT_NEAR(3.0333f, value.x(), 0.00015f); 87 EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
83 EXPECT_NEAR(37.4168f, value.y(), 0.00015f); 88 EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
84 } 89 }
85 90
86 // Verify that a clone behaves exactly like the original. 91 // Verify that a clone behaves exactly like the original.
87 TEST(ScrollOffsetAnimationCurveTest, Clone) { 92 TEST(ScrollOffsetAnimationCurveTest, Clone) {
88 gfx::ScrollOffset initial_value(2.f, 40.f); 93 gfx::ScrollOffset initial_value(2.f, 40.f);
89 gfx::ScrollOffset target_value(10.f, 20.f); 94 gfx::ScrollOffset target_value(10.f, 20.f);
90 scoped_ptr<ScrollOffsetAnimationCurve> curve( 95 scoped_ptr<ScrollOffsetAnimationCurve> curve(
91 ScrollOffsetAnimationCurve::Create( 96 ScrollOffsetAnimationCurve::Create(
92 target_value, 97 target_value,
93 EaseInOutTimingFunction::Create().Pass())); 98 EaseInOutTimingFunction::Create().Pass()));
94 curve->SetInitialValue(initial_value); 99 curve->SetInitialValue(initial_value);
95 double duration_in_seconds = curve->Duration().InSecondsF(); 100 base::TimeDelta duration = curve->Duration();
96 101
97 scoped_ptr<AnimationCurve> clone(curve->Clone().Pass()); 102 scoped_ptr<AnimationCurve> clone(curve->Clone().Pass());
98 103
99 EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type()); 104 EXPECT_EQ(AnimationCurve::ScrollOffset, clone->Type());
100 EXPECT_EQ(duration_in_seconds, clone->Duration().InSecondsF()); 105 EXPECT_EQ(duration, clone->Duration());
101 106
102 EXPECT_VECTOR2DF_EQ(initial_value, 107 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( 108 clone->ToScrollOffsetAnimationCurve()->GetValue(
108 duration_in_seconds / 2.0)); 109 base::TimeDelta::FromSecondsD(-1.0)));
109 EXPECT_VECTOR2DF_EQ( 110 EXPECT_VECTOR2DF_EQ(
110 target_value, 111 initial_value,
111 clone->ToScrollOffsetAnimationCurve()->GetValue(duration_in_seconds)); 112 clone->ToScrollOffsetAnimationCurve()->GetValue(base::TimeDelta()));
113 EXPECT_VECTOR2DF_NEAR(gfx::ScrollOffset(6.f, 30.f),
114 clone->ToScrollOffsetAnimationCurve()->GetValue(
115 TimeUtil::Scale(duration, 0.5f)),
116 0.00025);
117 EXPECT_VECTOR2DF_EQ(
118 target_value, clone->ToScrollOffsetAnimationCurve()->GetValue(duration));
112 EXPECT_VECTOR2DF_EQ(target_value, 119 EXPECT_VECTOR2DF_EQ(target_value,
113 clone->ToScrollOffsetAnimationCurve()->GetValue( 120 clone->ToScrollOffsetAnimationCurve()->GetValue(
114 duration_in_seconds + 1.0)); 121 duration + base::TimeDelta::FromSecondsD(1.f)));
115 122
116 // Verify that the timing function was cloned correctly. 123 // Verify that the timing function was cloned correctly.
117 gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue( 124 gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue(
118 duration_in_seconds / 4.0); 125 TimeUtil::Scale(duration, 0.25f));
119 EXPECT_NEAR(3.0333f, value.x(), 0.00015f); 126 EXPECT_NEAR(3.0333f, value.x(), 0.0002f);
120 EXPECT_NEAR(37.4168f, value.y(), 0.00015f); 127 EXPECT_NEAR(37.4168f, value.y(), 0.0002f);
121 } 128 }
122 129
123 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) { 130 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) {
124 gfx::ScrollOffset initial_value(0.f, 0.f); 131 gfx::ScrollOffset initial_value(0.f, 0.f);
125 gfx::ScrollOffset target_value(0.f, 3600.f); 132 gfx::ScrollOffset target_value(0.f, 3600.f);
126 scoped_ptr<ScrollOffsetAnimationCurve> curve( 133 scoped_ptr<ScrollOffsetAnimationCurve> curve(
127 ScrollOffsetAnimationCurve::Create( 134 ScrollOffsetAnimationCurve::Create(
128 target_value, EaseInOutTimingFunction::Create().Pass())); 135 target_value, EaseInOutTimingFunction::Create().Pass()));
129 curve->SetInitialValue(initial_value); 136 curve->SetInitialValue(initial_value);
130 EXPECT_EQ(1.0, curve->Duration().InSecondsF()); 137 EXPECT_EQ(1.0, curve->Duration().InSecondsF());
131 EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); 138 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
132 EXPECT_EQ(3600.0, curve->GetValue(1.0).y()); 139 EXPECT_EQ(3600.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y());
133 140
134 curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0)); 141 curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0));
135 142
136 EXPECT_EQ(2.0, curve->Duration().InSecondsF()); 143 EXPECT_EQ(2.0, curve->Duration().InSecondsF());
137 EXPECT_EQ(1800.0, curve->GetValue(0.5).y()); 144 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y());
138 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); 145 EXPECT_NEAR(5566.49, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
139 EXPECT_EQ(9900.0, curve->GetValue(2.0).y()); 146 0.01);
147 EXPECT_EQ(9900.0, curve->GetValue(base::TimeDelta::FromSecondsD(2.0)).y());
140 148
141 curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0)); 149 curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0));
142 150
143 EXPECT_NEAR(1.674, curve->Duration().InSecondsF(), 0.01); 151 EXPECT_NEAR(1.674, curve->Duration().InSecondsF(), 0.01);
144 EXPECT_NEAR(5566.49, curve->GetValue(1.0).y(), 0.01); 152 EXPECT_NEAR(5566.49, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(),
145 EXPECT_EQ(7200.0, curve->GetValue(1.674).y()); 153 0.01);
154 EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.674)).y());
146 } 155 }
147 156
148 } // namespace 157 } // namespace
149 } // namespace cc 158 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | cc/base/time_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698