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

Unified Diff: cc/animation/animation_unittest.cc

Issue 227733004: Handle direction control in compositor Animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new patch: fixes build failure in web_animation_unittest.cc Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: cc/animation/animation_unittest.cc
diff --git a/cc/animation/animation_unittest.cc b/cc/animation/animation_unittest.cc
index 8223cee5855d10a69fa91b4155fc5f5cd81a2eec..7a9019d209fa8105b5b4cee657e3eb39b6f32125 100644
--- a/cc/animation/animation_unittest.cc
+++ b/cc/animation/animation_unittest.cc
@@ -49,15 +49,39 @@ TEST(AnimationTest, TrimTimeInfiniteIterations) {
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(1.5));
}
-TEST(AnimationTest, TrimTimeAlternating) {
+TEST(AnimationTest, TrimTimeReverse) {
scoped_ptr<Animation> anim(CreateAnimation(-1));
- anim->set_alternates_direction(true);
+ anim->set_direction(Animation::Reverse);
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0));
+ EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
+ EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
+ EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.75));
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(1.0));
+ EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
+}
+
+TEST(AnimationTest, TrimTimeAlternate) {
+ scoped_ptr<Animation> anim(CreateAnimation(-1));
+ anim->set_direction(Animation::Alternate);
EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
+ EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.25));
EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
+ EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.75));
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1.25));
}
+TEST(AnimationTest, TrimTimeAlternateReverse) {
+ scoped_ptr<Animation> anim(CreateAnimation(-1));
+ anim->set_direction(Animation::AlternateReverse);
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
+ EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
+ EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
+ EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(0.75));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
+ EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1.25));
+}
+
TEST(AnimationTest, TrimTimeStartTime) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_start_time(4);
@@ -68,6 +92,17 @@ TEST(AnimationTest, TrimTimeStartTime) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(6.0));
}
+TEST(AnimationTest, TrimTimeStartTimeReverse) {
+ scoped_ptr<Animation> anim(CreateAnimation(1));
+ anim->set_start_time(4);
+ anim->set_direction(Animation::Reverse);
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(4.0));
+ EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(5.0));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(6.0));
+}
+
TEST(AnimationTest, TrimTimeTimeOffset) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_time_offset(4);
@@ -78,6 +113,17 @@ TEST(AnimationTest, TrimTimeTimeOffset) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1.0));
}
+TEST(AnimationTest, TrimTimeTimeOffsetReverse) {
+ scoped_ptr<Animation> anim(CreateAnimation(1));
+ anim->set_time_offset(4);
+ anim->set_start_time(4);
+ anim->set_direction(Animation::Reverse);
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
+ EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1.0));
+}
+
TEST(AnimationTest, TrimTimeNegativeTimeOffset) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->set_time_offset(-4);
@@ -88,6 +134,17 @@ TEST(AnimationTest, TrimTimeNegativeTimeOffset) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(5.0));
}
+TEST(AnimationTest, TrimTimeNegativeTimeOffsetReverse) {
+ scoped_ptr<Animation> anim(CreateAnimation(1));
+ anim->set_time_offset(-4);
+ anim->set_direction(Animation::Reverse);
+
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(0.0));
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(4.0));
+ EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(4.5));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(5.0));
+}
+
TEST(AnimationTest, TrimTimePauseResume) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
@@ -100,6 +157,19 @@ TEST(AnimationTest, TrimTimePauseResume) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
}
+TEST(AnimationTest, TrimTimePauseResumeReverse) {
+ scoped_ptr<Animation> anim(CreateAnimation(1));
+ anim->set_direction(Animation::Reverse);
+ anim->SetRunState(Animation::Running, 0.0);
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
+ EXPECT_EQ(0.5, anim->TrimTimeToCurrentIteration(0.5));
+ anim->SetRunState(Animation::Paused, 0.25);
+ EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1024.0));
+ anim->SetRunState(Animation::Running, 1024.0);
+ EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(1024.0));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1024.75));
+}
+
TEST(AnimationTest, TrimTimeSuspendResume) {
scoped_ptr<Animation> anim(CreateAnimation(1));
anim->SetRunState(Animation::Running, 0.0);
@@ -112,6 +182,19 @@ TEST(AnimationTest, TrimTimeSuspendResume) {
EXPECT_EQ(1, anim->TrimTimeToCurrentIteration(1024.5));
}
+TEST(AnimationTest, TrimTimeSuspendResumeReverse) {
+ scoped_ptr<Animation> anim(CreateAnimation(1));
+ anim->set_direction(Animation::Reverse);
+ anim->SetRunState(Animation::Running, 0.0);
+ EXPECT_EQ(1.0, anim->TrimTimeToCurrentIteration(0.0));
+ EXPECT_EQ(0.75, anim->TrimTimeToCurrentIteration(0.25));
+ anim->Suspend(0.75);
+ EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1024.0));
+ anim->Resume(1024);
+ EXPECT_EQ(0.25, anim->TrimTimeToCurrentIteration(1024.0));
+ EXPECT_EQ(0, anim->TrimTimeToCurrentIteration(1024.25));
+}
+
TEST(AnimationTest, TrimTimeZeroDuration) {
scoped_ptr<Animation> anim(CreateAnimation(0, 0));
anim->SetRunState(Animation::Running, 0.0);

Powered by Google App Engine
This is Rietveld 408576698