OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include <gtest/gtest.h> | 35 #include <gtest/gtest.h> |
36 | 36 |
37 using namespace WebCore; | 37 using namespace WebCore; |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 class AnimationAnimationClockTest : public ::testing::Test { | 41 class AnimationAnimationClockTest : public ::testing::Test { |
42 protected: | 42 protected: |
43 virtual void SetUp() | 43 virtual void SetUp() |
44 { | 44 { |
45 animationClock = AnimationClock::create(mockTimeFunction); | 45 animationClock = AnimationClock(); |
46 mockTime = 200; | 46 animationClock.resetTimeForTesting(); |
47 } | 47 } |
48 | 48 |
49 static double mockTimeFunction() | 49 AnimationClock animationClock; |
50 { | |
51 return mockTime; | |
52 } | |
53 | |
54 static double mockTime; | |
55 OwnPtr<AnimationClock> animationClock; | |
56 }; | 50 }; |
57 | 51 |
58 double AnimationAnimationClockTest::mockTime; | 52 TEST_F(AnimationAnimationClockTest, TimeDoesNotChange) |
59 | |
60 TEST_F(AnimationAnimationClockTest, CurrentTime) | |
61 { | 53 { |
62 // Current time should not advance until minTimeBeforeUnsynchronizedTick has elapsed | 54 animationClock.updateTime(100); |
63 EXPECT_EQ(200, animationClock->currentTime()); | 55 EXPECT_EQ(100, animationClock.currentTime()); |
64 mockTime = 200 + minTimeBeforeUnsynchronizedAnimationClockTick / 2.0; | 56 EXPECT_EQ(100, animationClock.currentTime()); |
shans
2014/04/30 20:43:07
maybe insert an artificial pause between these two
| |
65 EXPECT_EQ(200, animationClock->currentTime()); | |
66 | |
67 mockTime = 200 + minTimeBeforeUnsynchronizedAnimationClockTick; | |
68 EXPECT_EQ(mockTime, animationClock->currentTime()); | |
69 } | 57 } |
70 | 58 |
71 TEST_F(AnimationAnimationClockTest, UpdateTime) | 59 TEST_F(AnimationAnimationClockTest, TimeAdvancesWhenUpdated) |
72 { | 60 { |
73 animationClock->updateTime(100); | 61 animationClock.updateTime(100); |
74 EXPECT_EQ(100, animationClock->currentTime()); | 62 EXPECT_EQ(100, animationClock.currentTime()); |
75 mockTime = 200; | |
76 EXPECT_EQ(100, animationClock->currentTime()); | |
77 | 63 |
78 animationClock->unfreeze(); | 64 animationClock.updateTime(200); |
79 EXPECT_EQ(200, animationClock->currentTime()); | 65 EXPECT_EQ(200, animationClock.currentTime()); |
66 } | |
80 | 67 |
81 animationClock->updateTime(300); | 68 TEST_F(AnimationAnimationClockTest, TimeAdvancesToTaskTime) |
82 EXPECT_EQ(300, animationClock->currentTime()); | 69 { |
83 mockTime = 400; | 70 animationClock.updateTime(100); |
84 EXPECT_EQ(300, animationClock->currentTime()); | 71 EXPECT_EQ(100, animationClock.currentTime()); |
72 | |
73 AnimationClock::notifyTaskStartTime(150); | |
74 EXPECT_EQ(150, animationClock.currentTime()); | |
75 } | |
76 | |
77 TEST_F(AnimationAnimationClockTest, TimeAdvancesToTaskTimeOnlyWhenRequired) | |
78 { | |
79 animationClock.updateTime(100); | |
80 EXPECT_EQ(100, animationClock.currentTime()); | |
81 | |
82 AnimationClock::notifyTaskStartTime(150); | |
83 animationClock.updateTime(125); | |
84 EXPECT_EQ(125, animationClock.currentTime()); | |
85 } | |
86 | |
87 TEST_F(AnimationAnimationClockTest, UpdateTimeIsMonotonic) | |
88 { | |
89 animationClock.updateTime(100); | |
90 EXPECT_EQ(100, animationClock.currentTime()); | |
91 | |
92 animationClock.updateTime(50); | |
93 EXPECT_EQ(100, animationClock.currentTime()); | |
85 } | 94 } |
86 | 95 |
87 } | 96 } |
OLD | NEW |