summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorvollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-21 22:08:47 +0000
committervollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-21 22:08:47 +0000
commit4dad47e1ae4b15f0bf1eb7272c2583526d305d7e (patch)
treef1ab3a26c0d627374ee17e7aa303a231d8b96bf8 /cc
parent0b1167d1d4ff375f35ec2fca03ecea3da3115d9b (diff)
downloadchromium_src-4dad47e1ae4b15f0bf1eb7272c2583526d305d7e.zip
chromium_src-4dad47e1ae4b15f0bf1eb7272c2583526d305d7e.tar.gz
chromium_src-4dad47e1ae4b15f0bf1eb7272c2583526d305d7e.tar.bz2
Gracefully handle zero duration curves in CCActiveAnimation
We should trim to time 0 in this case. BUG= Review URL: https://chromiumcodereview.appspot.com/10961036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158092 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/CCActiveAnimation.cpp4
-rw-r--r--cc/CCActiveAnimationTest.cpp18
-rw-r--r--cc/test/CCAnimationTestCommon.cpp8
-rw-r--r--cc/test/CCAnimationTestCommon.h4
4 files changed, 31 insertions, 3 deletions
diff --git a/cc/CCActiveAnimation.cpp b/cc/CCActiveAnimation.cpp
index f09209e..36c7c2b 100644
--- a/cc/CCActiveAnimation.cpp
+++ b/cc/CCActiveAnimation.cpp
@@ -154,6 +154,10 @@ double CCActiveAnimation::trimTimeToCurrentIteration(double monotonicTime) const
if (!m_iterations)
return 0;
+ // Don't attempt to trim if we have no duration.
+ if (m_curve->duration() <= 0)
+ return 0;
+
// If less than an iteration duration, just return trimmed.
if (trimmed < m_curve->duration())
return trimmed;
diff --git a/cc/CCActiveAnimationTest.cpp b/cc/CCActiveAnimationTest.cpp
index ec589b4..a29da0b 100644
--- a/cc/CCActiveAnimationTest.cpp
+++ b/cc/CCActiveAnimationTest.cpp
@@ -16,13 +16,18 @@ using namespace cc;
namespace {
-PassOwnPtr<CCActiveAnimation> createActiveAnimation(int iterations)
+PassOwnPtr<CCActiveAnimation> createActiveAnimation(int iterations, double duration)
{
- OwnPtr<CCActiveAnimation> toReturn(CCActiveAnimation::create(adoptPtr(new FakeFloatAnimationCurve), 0, 1, CCActiveAnimation::Opacity));
+ OwnPtr<CCActiveAnimation> toReturn(CCActiveAnimation::create(adoptPtr(new FakeFloatAnimationCurve(duration)), 0, 1, CCActiveAnimation::Opacity));
toReturn->setIterations(iterations);
return toReturn.release();
}
+PassOwnPtr<CCActiveAnimation> createActiveAnimation(int iterations)
+{
+ return createActiveAnimation(iterations, 1);
+}
+
TEST(CCActiveAnimationTest, TrimTimeZeroIterations)
{
OwnPtr<CCActiveAnimation> anim(createActiveAnimation(0));
@@ -107,6 +112,15 @@ TEST(CCActiveAnimationTest, TrimTimeSuspendResume)
EXPECT_EQ(1, anim->trimTimeToCurrentIteration(1024.5));
}
+TEST(CCActiveAnimationTest, TrimTimeZeroDuration)
+{
+ OwnPtr<CCActiveAnimation> anim(createActiveAnimation(0, 0));
+ anim->setRunState(CCActiveAnimation::Running, 0);
+ EXPECT_EQ(0, anim->trimTimeToCurrentIteration(-1));
+ EXPECT_EQ(0, anim->trimTimeToCurrentIteration(0));
+ EXPECT_EQ(0, anim->trimTimeToCurrentIteration(1));
+}
+
TEST(CCActiveAnimationTest, IsFinishedAtZeroIterations)
{
OwnPtr<CCActiveAnimation> anim(createActiveAnimation(0));
diff --git a/cc/test/CCAnimationTestCommon.cpp b/cc/test/CCAnimationTestCommon.cpp
index 62cb17a..6b7801c 100644
--- a/cc/test/CCAnimationTestCommon.cpp
+++ b/cc/test/CCAnimationTestCommon.cpp
@@ -58,6 +58,12 @@ void addAnimatedTransform(Target& target, double duration, int deltaX, int delta
namespace WebKitTests {
FakeFloatAnimationCurve::FakeFloatAnimationCurve()
+ : m_duration(1)
+{
+}
+
+FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration)
+ : m_duration(duration)
{
}
@@ -67,7 +73,7 @@ FakeFloatAnimationCurve::~FakeFloatAnimationCurve()
double FakeFloatAnimationCurve::duration() const
{
- return 1;
+ return m_duration;
}
float FakeFloatAnimationCurve::getValue(double now) const
diff --git a/cc/test/CCAnimationTestCommon.h b/cc/test/CCAnimationTestCommon.h
index 6995f77..6ebf199 100644
--- a/cc/test/CCAnimationTestCommon.h
+++ b/cc/test/CCAnimationTestCommon.h
@@ -22,11 +22,15 @@ namespace WebKitTests {
class FakeFloatAnimationCurve : public cc::CCFloatAnimationCurve {
public:
FakeFloatAnimationCurve();
+ explicit FakeFloatAnimationCurve(double duration);
virtual ~FakeFloatAnimationCurve();
virtual double duration() const OVERRIDE;
virtual float getValue(double now) const OVERRIDE;
virtual PassOwnPtr<cc::CCAnimationCurve> clone() const OVERRIDE;
+
+private:
+ double m_duration;
};
class FakeTransformTransition : public cc::CCTransformAnimationCurve {