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

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

Issue 140253013: Define accelerated steps time function. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new patch Created 6 years, 10 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 | « no previous file | cc/animation/timing_function.h » ('j') | ui/gfx/geometry/steps.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/keyframed_animation_curve.h" 5 #include "cc/animation/keyframed_animation_curve.h"
6 6
7 #include "cc/animation/transform_operations.h" 7 #include "cc/animation/transform_operations.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/animation/tween.h" 10 #include "ui/gfx/animation/tween.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 420
421 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f)); 421 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f));
422 EXPECT_LT(0.f, curve->GetValue(0.25f)); 422 EXPECT_LT(0.f, curve->GetValue(0.25f));
423 EXPECT_GT(0.25f, curve->GetValue(0.25f)); 423 EXPECT_GT(0.25f, curve->GetValue(0.25f));
424 EXPECT_NEAR(curve->GetValue(0.5f), 0.5f, 0.00015f); 424 EXPECT_NEAR(curve->GetValue(0.5f), 0.5f, 0.00015f);
425 EXPECT_LT(0.75f, curve->GetValue(0.75f)); 425 EXPECT_LT(0.75f, curve->GetValue(0.75f));
426 EXPECT_GT(1.f, curve->GetValue(0.75f)); 426 EXPECT_GT(1.f, curve->GetValue(0.75f));
427 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f)); 427 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f));
428 } 428 }
429 429
430 // Tests that a steps timing function works as expected.
431 TEST(KeyframedAnimationCurveTest, StepsTimingFunction) {
432 scoped_ptr<KeyframedFloatAnimationCurve> curve(
433 KeyframedFloatAnimationCurve::Create());
434 curve->AddKeyframe(FloatKeyframe::Create(
435 0.0,
436 0.f,
437 StepsTimingFunction::Create(36, false)
438 .PassAs<TimingFunction>()));
439 curve->AddKeyframe(
440 FloatKeyframe::Create(1.0, 1.f, scoped_ptr<TimingFunction>()));
441
442 EXPECT_FLOAT_EQ(0.f, curve->GetValue(0.f));
443 EXPECT_FLOAT_EQ(0.25f, curve->GetValue(0.25));
ajuma 2014/02/24 21:11:16 0.25f
444 EXPECT_FLOAT_EQ(0.5f, curve->GetValue(0.5f));
445 EXPECT_FLOAT_EQ(0.75f, curve->GetValue(0.75));
ajuma 2014/02/24 21:11:16 0.75f
446 EXPECT_FLOAT_EQ(1.f, curve->GetValue(1.f));
ajuma 2014/02/24 21:11:16 It'd be good to also test values that don't land e
447 }
448
430 // Tests that animated bounds are computed as expected. 449 // Tests that animated bounds are computed as expected.
431 TEST(KeyframedAnimationCurveTest, AnimatedBounds) { 450 TEST(KeyframedAnimationCurveTest, AnimatedBounds) {
432 scoped_ptr<KeyframedTransformAnimationCurve> curve( 451 scoped_ptr<KeyframedTransformAnimationCurve> curve(
433 KeyframedTransformAnimationCurve::Create()); 452 KeyframedTransformAnimationCurve::Create());
434 453
435 TransformOperations operations1; 454 TransformOperations operations1;
436 curve->AddKeyframe(TransformKeyframe::Create( 455 curve->AddKeyframe(TransformKeyframe::Create(
437 0.0, operations1, scoped_ptr<TimingFunction>())); 456 0.0, operations1, scoped_ptr<TimingFunction>()));
438 operations1.AppendTranslate(2.0, 3.0, -1.0); 457 operations1.AppendTranslate(2.0, 3.0, -1.0);
439 curve->AddKeyframe(TransformKeyframe::Create( 458 curve->AddKeyframe(TransformKeyframe::Create(
440 0.5, operations1, scoped_ptr<TimingFunction>())); 459 0.5, operations1, scoped_ptr<TimingFunction>()));
441 TransformOperations operations2; 460 TransformOperations operations2;
442 operations2.AppendTranslate(4.0, 1.0, 2.0); 461 operations2.AppendTranslate(4.0, 1.0, 2.0);
443 curve->AddKeyframe(TransformKeyframe::Create( 462 curve->AddKeyframe(TransformKeyframe::Create(
444 1.0, operations2, EaseTimingFunction::Create())); 463 1.0, operations2, EaseTimingFunction::Create()));
445 464
446 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f); 465 gfx::BoxF box(2.f, 3.f, 4.f, 1.f, 3.f, 2.f);
447 gfx::BoxF bounds; 466 gfx::BoxF bounds;
448 467
449 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds)); 468 EXPECT_TRUE(curve->AnimatedBoundsForBox(box, &bounds));
450 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(), 469 EXPECT_EQ(gfx::BoxF(2.f, 3.f, 3.f, 5.f, 6.f, 5.f).ToString(),
451 bounds.ToString()); 470 bounds.ToString());
452 } 471 }
453 472
454 } // namespace 473 } // namespace
455 } // namespace cc 474 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/animation/timing_function.h » ('j') | ui/gfx/geometry/steps.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698