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

Side by Side Diff: Source/core/animation/AnimationClockTest.cpp

Issue 275863002: Revert of Web Animations: Timeline should not advance during task execution (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/AnimationClock.cpp ('k') | Source/core/animation/DocumentAnimations.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
32 #include "core/animation/AnimationClock.h" 32 #include "core/animation/AnimationClock.h"
33 33
34 #include "wtf/OwnPtr.h" 34 #include "wtf/OwnPtr.h"
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 public:
43 AnimationAnimationClockTest()
44 : animationClock(mockTimeFunction)
45 {}
46 protected: 42 protected:
47 virtual void SetUp() 43 virtual void SetUp()
48 { 44 {
49 mockTime = 0; 45 animationClock = AnimationClock::create(mockTimeFunction);
50 animationClock.resetTimeForTesting(); 46 mockTime = 200;
51 } 47 }
52 48
53 static double mockTimeFunction() 49 static double mockTimeFunction()
54 { 50 {
55 return mockTime; 51 return mockTime;
56 } 52 }
57 53
58 static double mockTime; 54 static double mockTime;
59 AnimationClock animationClock; 55 OwnPtr<AnimationClock> animationClock;
60 }; 56 };
61 57
62 double AnimationAnimationClockTest::mockTime; 58 double AnimationAnimationClockTest::mockTime;
63 59
64 TEST_F(AnimationAnimationClockTest, TimeIsGreaterThanZeroForUnitTests) 60 TEST_F(AnimationAnimationClockTest, CurrentTime)
65 { 61 {
66 AnimationClock clock; 62 // Current time should not advance until minTimeBeforeUnsynchronizedTick has elapsed
67 // unit tests outside core/animation shouldn't need to do anything to get 63 EXPECT_EQ(200, animationClock->currentTime());
68 // a non-zero currentTime(). 64 mockTime = 200 + minTimeBeforeUnsynchronizedAnimationClockTick / 2.0;
69 EXPECT_GT(clock.currentTime(), 0); 65 EXPECT_EQ(200, animationClock->currentTime());
66
67 mockTime = 200 + minTimeBeforeUnsynchronizedAnimationClockTick;
68 EXPECT_EQ(mockTime, animationClock->currentTime());
70 } 69 }
71 70
72 TEST_F(AnimationAnimationClockTest, TimeDoesNotChange) 71 TEST_F(AnimationAnimationClockTest, UpdateTime)
73 { 72 {
74 animationClock.updateTime(100); 73 animationClock->updateTime(100);
75 EXPECT_EQ(100, animationClock.currentTime()); 74 EXPECT_EQ(100, animationClock->currentTime());
76 EXPECT_EQ(100, animationClock.currentTime()); 75 mockTime = 200;
77 } 76 EXPECT_EQ(100, animationClock->currentTime());
78 77
79 TEST_F(AnimationAnimationClockTest, TimeAdvancesWhenUpdated) 78 animationClock->unfreeze();
80 { 79 EXPECT_EQ(200, animationClock->currentTime());
81 animationClock.updateTime(100);
82 EXPECT_EQ(100, animationClock.currentTime());
83 80
84 animationClock.updateTime(200); 81 animationClock->updateTime(300);
85 EXPECT_EQ(200, animationClock.currentTime()); 82 EXPECT_EQ(300, animationClock->currentTime());
86 } 83 mockTime = 400;
87 84 EXPECT_EQ(300, animationClock->currentTime());
88 TEST_F(AnimationAnimationClockTest, TimeAdvancesToTaskTime)
89 {
90 animationClock.updateTime(100);
91 EXPECT_EQ(100, animationClock.currentTime());
92
93 mockTime = 150;
94 AnimationClock::notifyTaskStart();
95 EXPECT_GE(animationClock.currentTime(), mockTime);
96 }
97
98 TEST_F(AnimationAnimationClockTest, TimeAdvancesToTaskTimeOnlyWhenRequired)
99 {
100 animationClock.updateTime(100);
101 EXPECT_EQ(100, animationClock.currentTime());
102
103 AnimationClock::notifyTaskStart();
104 animationClock.updateTime(125);
105 EXPECT_EQ(125, animationClock.currentTime());
106 }
107
108 TEST_F(AnimationAnimationClockTest, UpdateTimeIsMonotonic)
109 {
110 animationClock.updateTime(100);
111 EXPECT_EQ(100, animationClock.currentTime());
112
113 // Update can't go backwards.
114 animationClock.updateTime(50);
115 EXPECT_EQ(100, animationClock.currentTime());
116
117 mockTime = 50;
118 AnimationClock::notifyTaskStart();
119 EXPECT_EQ(100, animationClock.currentTime());
120
121 mockTime = 150;
122 AnimationClock::notifyTaskStart();
123 EXPECT_GE(animationClock.currentTime(), mockTime);
124
125 // Update can't go backwards after advance to estimate.
126 animationClock.updateTime(100);
127 EXPECT_GE(animationClock.currentTime(), mockTime);
128 }
129
130 TEST_F(AnimationAnimationClockTest, CurrentTimeUpdatesTask)
131 {
132 animationClock.updateTime(100);
133 EXPECT_EQ(100, animationClock.currentTime());
134
135 mockTime = 100;
136 AnimationClock::notifyTaskStart();
137 EXPECT_EQ(100, animationClock.currentTime());
138
139 mockTime = 150;
140 EXPECT_EQ(100, animationClock.currentTime());
141 } 85 }
142 86
143 } 87 }
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationClock.cpp ('k') | Source/core/animation/DocumentAnimations.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698