| OLD | NEW |
| 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/base/time_util.h" |
| 9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue( | 121 gfx::ScrollOffset value = clone->ToScrollOffsetAnimationCurve()->GetValue( |
| 122 TimeUtil::Scale(duration, 0.25f)); | 122 TimeUtil::Scale(duration, 0.25f)); |
| 123 EXPECT_NEAR(3.0333f, value.x(), 0.0002f); | 123 EXPECT_NEAR(3.0333f, value.x(), 0.0002f); |
| 124 EXPECT_NEAR(37.4168f, value.y(), 0.0002f); | 124 EXPECT_NEAR(37.4168f, value.y(), 0.0002f); |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) { | 127 TEST(ScrollOffsetAnimationCurveTest, UpdateTarget) { |
| 128 gfx::ScrollOffset initial_value(0.f, 0.f); | 128 gfx::ScrollOffset initial_value(0.f, 0.f); |
| 129 gfx::ScrollOffset target_value(0.f, 3600.f); | 129 gfx::ScrollOffset target_value(0.f, 3600.f); |
| 130 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 130 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 131 ScrollOffsetAnimationCurve::Create(target_value, | |
| 132 EaseInOutTimingFunction::Create())); | |
| 133 curve->SetInitialValue(initial_value); | |
| 134 EXPECT_EQ(1.0, curve->Duration().InSecondsF()); | |
| 135 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y()); | |
| 136 EXPECT_EQ(3600.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y()); | |
| 137 | |
| 138 curve->UpdateTarget(0.5, gfx::ScrollOffset(0.0, 9900.0)); | |
| 139 | |
| 140 EXPECT_EQ(2.0, curve->Duration().InSecondsF()); | |
| 141 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.5)).y()); | |
| 142 EXPECT_NEAR(5410.05, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(), | |
| 143 0.01); | |
| 144 EXPECT_EQ(9900.0, curve->GetValue(base::TimeDelta::FromSecondsD(2.0)).y()); | |
| 145 | |
| 146 curve->UpdateTarget(1.0, gfx::ScrollOffset(0.0, 7200.0)); | |
| 147 | |
| 148 EXPECT_NEAR(1.705, curve->Duration().InSecondsF(), 0.01); | |
| 149 EXPECT_NEAR(5410.05, curve->GetValue(base::TimeDelta::FromSecondsD(1.0)).y(), | |
| 150 0.01); | |
| 151 EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(1.705)).y()); | |
| 152 } | |
| 153 | |
| 154 TEST(ScrollOffsetAnimationCurveTest, UpdateTargetWithLargeVelocity) { | |
| 155 gfx::ScrollOffset initial_value(0.f, 0.f); | |
| 156 gfx::ScrollOffset target_value(0.f, 900.f); | |
| 157 scoped_ptr<ScrollOffsetAnimationCurve> curve( | |
| 158 ScrollOffsetAnimationCurve::Create(target_value, | |
| 159 EaseInOutTimingFunction::Create())); | |
| 160 curve->SetInitialValue(initial_value); | |
| 161 EXPECT_EQ(0.5, curve->Duration().InSecondsF()); | |
| 162 | |
| 163 EXPECT_EQ(450.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.25)).y()); | |
| 164 | |
| 165 // This leads to a new computed velocity larger than 5000. | |
| 166 curve->UpdateTarget(0.25, gfx::ScrollOffset(0.0, 450.0001)); | |
| 167 | |
| 168 EXPECT_NEAR(0.25015, curve->Duration().InSecondsF(), 0.0001); | |
| 169 EXPECT_NEAR(450.0, | |
| 170 curve->GetValue(base::TimeDelta::FromSecondsD(0.22501)).y(), | |
| 171 0.001); | |
| 172 EXPECT_NEAR(450.0, | |
| 173 curve->GetValue(base::TimeDelta::FromSecondsD(0.225015)).y(), | |
| 174 0.001); | |
| 175 } | |
| 176 | |
| 177 TEST(ScrollOffsetAnimationCurveTest, UpdateTargetConstantDuration) { | |
| 178 gfx::ScrollOffset initial_value(0.f, 0.f); | |
| 179 gfx::ScrollOffset target_value(0.f, 3600.f); | |
| 180 scoped_ptr<ScrollOffsetAnimationCurve> curve( | |
| 181 ScrollOffsetAnimationCurve::Create( | 131 ScrollOffsetAnimationCurve::Create( |
| 182 target_value, EaseInOutTimingFunction::Create(), | 132 target_value, EaseInOutTimingFunction::Create(), |
| 183 ScrollOffsetAnimationCurve::DurationBehavior::CONSTANT)); | 133 ScrollOffsetAnimationCurve::DurationBehavior::CONSTANT)); |
| 184 curve->SetInitialValue(initial_value); | 134 curve->SetInitialValue(initial_value); |
| 185 EXPECT_EQ(0.2, curve->Duration().InSecondsF()); | 135 EXPECT_EQ(0.2, curve->Duration().InSecondsF()); |
| 136 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.1)).y()); |
| 137 EXPECT_EQ(3600.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.2)).y()); |
| 186 | 138 |
| 187 curve->UpdateTarget(0.1, gfx::ScrollOffset(0.0, 9900.0)); | 139 curve->UpdateTarget(0.1, gfx::ScrollOffset(0.0, 9900.0)); |
| 140 |
| 188 EXPECT_EQ(0.3, curve->Duration().InSecondsF()); | 141 EXPECT_EQ(0.3, curve->Duration().InSecondsF()); |
| 142 EXPECT_EQ(1800.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.1)).y()); |
| 143 EXPECT_NEAR(6827.59, curve->GetValue(base::TimeDelta::FromSecondsD(0.2)).y(), |
| 144 0.01); |
| 145 EXPECT_EQ(9900.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.3)).y()); |
| 146 |
| 147 curve->UpdateTarget(0.2, gfx::ScrollOffset(0.0, 7200.0)); |
| 148 |
| 149 // A closer target at high velocity reduces the duration. |
| 150 EXPECT_NEAR(0.22, curve->Duration().InSecondsF(), 0.01); |
| 151 EXPECT_NEAR(6827.59, curve->GetValue(base::TimeDelta::FromSecondsD(0.2)).y(), |
| 152 0.01); |
| 153 EXPECT_EQ(7200.0, curve->GetValue(base::TimeDelta::FromSecondsD(0.22)).y()); |
| 189 } | 154 } |
| 190 | 155 |
| 191 } // namespace | 156 } // namespace |
| 192 } // namespace cc | 157 } // namespace cc |
| OLD | NEW |