2 * Copyright (c) 2013, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/animation/AnimationClock.h"
34 #include "wtf/OwnPtr.h"
35 #include <gtest/gtest.h>
37 using namespace blink
;
41 class AnimationAnimationClockTest
: public ::testing::Test
{
43 AnimationAnimationClockTest()
44 : animationClock(mockTimeFunction
)
50 animationClock
.resetTimeForTesting();
53 static double mockTimeFunction()
58 static double mockTime
;
59 AnimationClock animationClock
;
62 double AnimationAnimationClockTest::mockTime
;
64 TEST_F(AnimationAnimationClockTest
, TimeIsGreaterThanZeroForUnitTests
)
67 // unit tests outside core/animation shouldn't need to do anything to get
68 // a non-zero currentTime().
69 EXPECT_GT(clock
.currentTime(), 0);
72 TEST_F(AnimationAnimationClockTest
, TimeDoesNotChange
)
74 animationClock
.updateTime(100);
75 EXPECT_EQ(100, animationClock
.currentTime());
76 EXPECT_EQ(100, animationClock
.currentTime());
79 TEST_F(AnimationAnimationClockTest
, TimeAdvancesWhenUpdated
)
81 animationClock
.updateTime(100);
82 EXPECT_EQ(100, animationClock
.currentTime());
84 animationClock
.updateTime(200);
85 EXPECT_EQ(200, animationClock
.currentTime());
88 TEST_F(AnimationAnimationClockTest
, TimeAdvancesToTaskTime
)
90 animationClock
.updateTime(100);
91 EXPECT_EQ(100, animationClock
.currentTime());
94 AnimationClock::notifyTaskStart();
95 EXPECT_GE(animationClock
.currentTime(), mockTime
);
98 TEST_F(AnimationAnimationClockTest
, TimeAdvancesToTaskTimeOnlyWhenRequired
)
100 animationClock
.updateTime(100);
101 EXPECT_EQ(100, animationClock
.currentTime());
103 AnimationClock::notifyTaskStart();
104 animationClock
.updateTime(125);
105 EXPECT_EQ(125, animationClock
.currentTime());
108 TEST_F(AnimationAnimationClockTest
, UpdateTimeIsMonotonic
)
110 animationClock
.updateTime(100);
111 EXPECT_EQ(100, animationClock
.currentTime());
113 // Update can't go backwards.
114 animationClock
.updateTime(50);
115 EXPECT_EQ(100, animationClock
.currentTime());
118 AnimationClock::notifyTaskStart();
119 EXPECT_EQ(100, animationClock
.currentTime());
122 AnimationClock::notifyTaskStart();
123 EXPECT_GE(animationClock
.currentTime(), mockTime
);
125 // Update can't go backwards after advance to estimate.
126 animationClock
.updateTime(100);
127 EXPECT_GE(animationClock
.currentTime(), mockTime
);
130 TEST_F(AnimationAnimationClockTest
, CurrentTimeUpdatesTask
)
132 animationClock
.updateTime(100);
133 EXPECT_EQ(100, animationClock
.currentTime());
136 AnimationClock::notifyTaskStart();
137 EXPECT_EQ(100, animationClock
.currentTime());
140 EXPECT_EQ(100, animationClock
.currentTime());