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

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

Issue 2332923002: Fix scroll animation UpdateTarget for zero-duration segments (Closed)
Patch Set: update tests Created 4 years, 3 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
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | no next file » | 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/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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 CubicBezierTimingFunction::EaseType::EASE_IN_OUT), 230 CubicBezierTimingFunction::EaseType::EASE_IN_OUT),
231 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA)); 231 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA));
232 curve->SetInitialValue(gfx::ScrollOffset(), 232 curve->SetInitialValue(gfx::ScrollOffset(),
233 base::TimeDelta::FromSecondsD(0.2)); 233 base::TimeDelta::FromSecondsD(0.2));
234 EXPECT_EQ(0.f, curve->Duration().InSecondsF()); 234 EXPECT_EQ(0.f, curve->Duration().InSecondsF());
235 235
236 // Re-targeting when animation duration is 0. 236 // Re-targeting when animation duration is 0.
237 curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 300.f)); 237 curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 300.f));
238 double duration = 238 double duration =
239 ScrollOffsetAnimationCurve::SegmentDuration( 239 ScrollOffsetAnimationCurve::SegmentDuration(
240 gfx::Vector2dF(0.f, 300.f), 240 gfx::Vector2dF(0.f, 200.f),
241 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA, 241 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA,
242 base::TimeDelta::FromSecondsD(0.01)) 242 base::TimeDelta::FromSecondsD(0.01))
243 .InSecondsF(); 243 .InSecondsF();
244 EXPECT_EQ(duration, curve->Duration().InSecondsF()); 244 EXPECT_EQ(duration, curve->Duration().InSecondsF());
245 245
246 // Re-targeting before last_retarget_, the difference should be accounted for 246 // Re-targeting before last_retarget_, the difference should be accounted for
247 // in duration. 247 // in duration.
248 curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 500.f)); 248 curve->UpdateTarget(-0.01, gfx::ScrollOffset(0.f, 500.f));
249 duration = ScrollOffsetAnimationCurve::SegmentDuration( 249 duration = ScrollOffsetAnimationCurve::SegmentDuration(
250 gfx::Vector2dF(0.f, 500.f), 250 gfx::Vector2dF(0.f, 500.f),
251 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA, 251 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA,
252 base::TimeDelta::FromSecondsD(0.01)) 252 base::TimeDelta::FromSecondsD(0.01))
253 .InSecondsF(); 253 .InSecondsF();
254 EXPECT_EQ(duration, curve->Duration().InSecondsF()); 254 EXPECT_EQ(duration, curve->Duration().InSecondsF());
255 255
256 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(0.f, 500.f), 256 EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(0.f, 500.f),
257 curve->GetValue(base::TimeDelta::FromSecondsD(1.0))); 257 curve->GetValue(base::TimeDelta::FromSecondsD(1.0)));
258 } 258 }
259 259
260 // This test verifies that if the last segment duration is zero, ::UpdateTarget
261 // simply updates the total animation duration see crbug.com/645317.
262 TEST(ScrollOffsetAnimationCurveTest, UpdateTargetZeroLastSegmentDuration) {
263 std::unique_ptr<ScrollOffsetAnimationCurve> curve(
264 ScrollOffsetAnimationCurve::Create(
265 gfx::ScrollOffset(0.f, 100.f),
266 CubicBezierTimingFunction::CreatePreset(
267 CubicBezierTimingFunction::EaseType::EASE_IN_OUT),
268 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA));
269 double duration_in_seconds = kInverseDeltaMaxDuration / kDurationDivisor;
270 double delay_in_seconds = 0.02;
271 double curve_duration = duration_in_seconds - delay_in_seconds;
272
273 curve->SetInitialValue(gfx::ScrollOffset(),
274 base::TimeDelta::FromSecondsD(delay_in_seconds));
275 EXPECT_NEAR(curve_duration, curve->Duration().InSecondsF(), 0.0002f);
276
277 // Re-target 1, this should set last_retarget_ to 0.05.
278 gfx::ScrollOffset new_delta =
279 gfx::ScrollOffset(0.f, 200.f) -
280 curve->GetValue(base::TimeDelta::FromSecondsD(0.05));
281 double expected_duration =
282 ScrollOffsetAnimationCurve::SegmentDuration(
283 gfx::Vector2dF(new_delta.x(), new_delta.y()),
284 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA,
285 base::TimeDelta())
286 .InSecondsF() +
287 0.05;
288 curve->UpdateTarget(0.05, gfx::ScrollOffset(0.f, 200.f));
289 EXPECT_NEAR(expected_duration, curve->Duration().InSecondsF(), 0.0002f);
290
291 // Re-target 2, this should set total_animation_duration to t, which is
292 // last_retarget_. This is what would cause the DCHECK failure in
293 // crbug.com/645317.
294 curve->UpdateTarget(-0.145, gfx::ScrollOffset(0.f, 300.f));
295 EXPECT_NEAR(0.05, curve->Duration().InSecondsF(), 0.0002f);
296
297 // Re-target 3, this should set total_animation_duration based on new_delta.
298 new_delta = gfx::ScrollOffset(0.f, 500.f) -
299 curve->GetValue(base::TimeDelta::FromSecondsD(0.05));
300 expected_duration =
301 ScrollOffsetAnimationCurve::SegmentDuration(
302 gfx::Vector2dF(new_delta.x(), new_delta.y()),
303 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA,
304 base::TimeDelta::FromSecondsD(0.15))
305 .InSecondsF();
306 curve->UpdateTarget(-0.1, gfx::ScrollOffset(0.f, 500.f));
307 EXPECT_NEAR(expected_duration, curve->Duration().InSecondsF(), 0.0002f);
308 }
309
260 } // namespace 310 } // namespace
261 } // namespace cc 311 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698