OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCDelayBasedTimeSource.h" | 7 #include "CCDelayBasedTimeSource.h" |
8 | 8 |
9 #include "CCThread.h" | 9 #include "CCThread.h" |
10 #include "cc/test/scheduler_test_common.h" | 10 #include "cc/test/scheduler_test_common.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using namespace cc; | 13 using namespace cc; |
14 using namespace WebKitTests; | 14 using namespace WebKitTests; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 base::TimeDelta interval() | 18 base::TimeDelta interval() |
19 { | 19 { |
20 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond
/ 60); | 20 return base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond
/ 60); |
21 } | 21 } |
22 | 22 |
23 TEST(CCDelayBasedTimeSourceTest, TaskPostedAndTickCalled) | 23 TEST(DelayBasedTimeSourceTest, TaskPostedAndTickCalled) |
24 { | 24 { |
25 FakeCCThread thread; | 25 FakeThread thread; |
26 FakeCCTimeSourceClient client; | 26 FakeTimeSourceClient client; |
27 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 27 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
28 timer->setClient(&client); | 28 timer->setClient(&client); |
29 | 29 |
30 timer->setActive(true); | 30 timer->setActive(true); |
31 EXPECT_TRUE(timer->active()); | 31 EXPECT_TRUE(timer->active()); |
32 EXPECT_TRUE(thread.hasPendingTask()); | 32 EXPECT_TRUE(thread.hasPendingTask()); |
33 | 33 |
34 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(16)); | 34 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(16)); |
35 thread.runPendingTask(); | 35 thread.runPendingTask(); |
36 EXPECT_TRUE(timer->active()); | 36 EXPECT_TRUE(timer->active()); |
37 EXPECT_TRUE(client.tickCalled()); | 37 EXPECT_TRUE(client.tickCalled()); |
38 } | 38 } |
39 | 39 |
40 TEST(CCDelayBasedTimeSource, TickNotCalledWithTaskPosted) | 40 TEST(DelayBasedTimeSource, TickNotCalledWithTaskPosted) |
41 { | 41 { |
42 FakeCCThread thread; | 42 FakeThread thread; |
43 FakeCCTimeSourceClient client; | 43 FakeTimeSourceClient client; |
44 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 44 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
45 timer->setClient(&client); | 45 timer->setClient(&client); |
46 timer->setActive(true); | 46 timer->setActive(true); |
47 EXPECT_TRUE(thread.hasPendingTask()); | 47 EXPECT_TRUE(thread.hasPendingTask()); |
48 timer->setActive(false); | 48 timer->setActive(false); |
49 thread.runPendingTask(); | 49 thread.runPendingTask(); |
50 EXPECT_FALSE(client.tickCalled()); | 50 EXPECT_FALSE(client.tickCalled()); |
51 } | 51 } |
52 | 52 |
53 TEST(CCDelayBasedTimeSource, StartTwiceEnqueuesOneTask) | 53 TEST(DelayBasedTimeSource, StartTwiceEnqueuesOneTask) |
54 { | 54 { |
55 FakeCCThread thread; | 55 FakeThread thread; |
56 FakeCCTimeSourceClient client; | 56 FakeTimeSourceClient client; |
57 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 57 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
58 timer->setClient(&client); | 58 timer->setClient(&client); |
59 timer->setActive(true); | 59 timer->setActive(true); |
60 EXPECT_TRUE(thread.hasPendingTask()); | 60 EXPECT_TRUE(thread.hasPendingTask()); |
61 thread.reset(); | 61 thread.reset(); |
62 timer->setActive(true); | 62 timer->setActive(true); |
63 EXPECT_FALSE(thread.hasPendingTask()); | 63 EXPECT_FALSE(thread.hasPendingTask()); |
64 } | 64 } |
65 | 65 |
66 TEST(CCDelayBasedTimeSource, StartWhenRunningDoesntTick) | 66 TEST(DelayBasedTimeSource, StartWhenRunningDoesntTick) |
67 { | 67 { |
68 FakeCCThread thread; | 68 FakeThread thread; |
69 FakeCCTimeSourceClient client; | 69 FakeTimeSourceClient client; |
70 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 70 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
71 timer->setClient(&client); | 71 timer->setClient(&client); |
72 timer->setActive(true); | 72 timer->setActive(true); |
73 thread.runPendingTask(); | 73 thread.runPendingTask(); |
74 thread.reset(); | 74 thread.reset(); |
75 timer->setActive(true); | 75 timer->setActive(true); |
76 EXPECT_FALSE(thread.hasPendingTask()); | 76 EXPECT_FALSE(thread.hasPendingTask()); |
77 } | 77 } |
78 | 78 |
79 // At 60Hz, when the tick returns at exactly the requested next time, make sure | 79 // At 60Hz, when the tick returns at exactly the requested next time, make sure |
80 // a 16ms next delay is posted. | 80 // a 16ms next delay is posted. |
81 TEST(CCDelayBasedTimeSource, NextDelaySaneWhenExactlyOnRequestedTime) | 81 TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyOnRequestedTime) |
82 { | 82 { |
83 FakeCCThread thread; | 83 FakeThread thread; |
84 FakeCCTimeSourceClient client; | 84 FakeTimeSourceClient client; |
85 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 85 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
86 timer->setClient(&client); | 86 timer->setClient(&client); |
87 timer->setActive(true); | 87 timer->setActive(true); |
88 // Run the first task, as that activates the timer and picks up a timebase. | 88 // Run the first task, as that activates the timer and picks up a timebase. |
89 thread.runPendingTask(); | 89 thread.runPendingTask(); |
90 | 90 |
91 EXPECT_EQ(16, thread.pendingDelayMs()); | 91 EXPECT_EQ(16, thread.pendingDelayMs()); |
92 | 92 |
93 timer->setNow(timer->now() + interval()); | 93 timer->setNow(timer->now() + interval()); |
94 thread.runPendingTask(); | 94 thread.runPendingTask(); |
95 | 95 |
96 EXPECT_EQ(16, thread.pendingDelayMs()); | 96 EXPECT_EQ(16, thread.pendingDelayMs()); |
97 } | 97 } |
98 | 98 |
99 // At 60Hz, when the tick returns at slightly after the requested next time, mak
e sure | 99 // At 60Hz, when the tick returns at slightly after the requested next time, mak
e sure |
100 // a 16ms next delay is posted. | 100 // a 16ms next delay is posted. |
101 TEST(CCDelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterRequestedTime) | 101 TEST(DelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterRequestedTime) |
102 { | 102 { |
103 FakeCCThread thread; | 103 FakeThread thread; |
104 FakeCCTimeSourceClient client; | 104 FakeTimeSourceClient client; |
105 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 105 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
106 timer->setClient(&client); | 106 timer->setClient(&client); |
107 timer->setActive(true); | 107 timer->setActive(true); |
108 // Run the first task, as that activates the timer and picks up a timebase. | 108 // Run the first task, as that activates the timer and picks up a timebase. |
109 thread.runPendingTask(); | 109 thread.runPendingTask(); |
110 | 110 |
111 EXPECT_EQ(16, thread.pendingDelayMs()); | 111 EXPECT_EQ(16, thread.pendingDelayMs()); |
112 | 112 |
113 timer->setNow(timer->now() + interval() + base::TimeDelta::FromMicroseconds(
1)); | 113 timer->setNow(timer->now() + interval() + base::TimeDelta::FromMicroseconds(
1)); |
114 thread.runPendingTask(); | 114 thread.runPendingTask(); |
115 | 115 |
116 EXPECT_EQ(16, thread.pendingDelayMs()); | 116 EXPECT_EQ(16, thread.pendingDelayMs()); |
117 } | 117 } |
118 | 118 |
119 // At 60Hz, when the tick returns at exactly 2*interval after the requested next
time, make sure | 119 // At 60Hz, when the tick returns at exactly 2*interval after the requested next
time, make sure |
120 // a 16ms next delay is posted. | 120 // a 16ms next delay is posted. |
121 TEST(CCDelayBasedTimeSource, NextDelaySaneWhenExactlyTwiceAfterRequestedTime) | 121 TEST(DelayBasedTimeSource, NextDelaySaneWhenExactlyTwiceAfterRequestedTime) |
122 { | 122 { |
123 FakeCCThread thread; | 123 FakeThread thread; |
124 FakeCCTimeSourceClient client; | 124 FakeTimeSourceClient client; |
125 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 125 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
126 timer->setClient(&client); | 126 timer->setClient(&client); |
127 timer->setActive(true); | 127 timer->setActive(true); |
128 // Run the first task, as that activates the timer and picks up a timebase. | 128 // Run the first task, as that activates the timer and picks up a timebase. |
129 thread.runPendingTask(); | 129 thread.runPendingTask(); |
130 | 130 |
131 EXPECT_EQ(16, thread.pendingDelayMs()); | 131 EXPECT_EQ(16, thread.pendingDelayMs()); |
132 | 132 |
133 timer->setNow(timer->now() + 2 * interval()); | 133 timer->setNow(timer->now() + 2 * interval()); |
134 thread.runPendingTask(); | 134 thread.runPendingTask(); |
135 | 135 |
136 EXPECT_EQ(16, thread.pendingDelayMs()); | 136 EXPECT_EQ(16, thread.pendingDelayMs()); |
137 } | 137 } |
138 | 138 |
139 // At 60Hz, when the tick returns at 2*interval and a bit after the requested ne
xt time, make sure | 139 // At 60Hz, when the tick returns at 2*interval and a bit after the requested ne
xt time, make sure |
140 // a 16ms next delay is posted. | 140 // a 16ms next delay is posted. |
141 TEST(CCDelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterTwiceRequestedTime) | 141 TEST(DelayBasedTimeSource, NextDelaySaneWhenSlightlyAfterTwiceRequestedTime) |
142 { | 142 { |
143 FakeCCThread thread; | 143 FakeThread thread; |
144 FakeCCTimeSourceClient client; | 144 FakeTimeSourceClient client; |
145 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 145 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
146 timer->setClient(&client); | 146 timer->setClient(&client); |
147 timer->setActive(true); | 147 timer->setActive(true); |
148 // Run the first task, as that activates the timer and picks up a timebase. | 148 // Run the first task, as that activates the timer and picks up a timebase. |
149 thread.runPendingTask(); | 149 thread.runPendingTask(); |
150 | 150 |
151 EXPECT_EQ(16, thread.pendingDelayMs()); | 151 EXPECT_EQ(16, thread.pendingDelayMs()); |
152 | 152 |
153 timer->setNow(timer->now() + 2 * interval() + base::TimeDelta::FromMicroseco
nds(1)); | 153 timer->setNow(timer->now() + 2 * interval() + base::TimeDelta::FromMicroseco
nds(1)); |
154 thread.runPendingTask(); | 154 thread.runPendingTask(); |
155 | 155 |
156 EXPECT_EQ(16, thread.pendingDelayMs()); | 156 EXPECT_EQ(16, thread.pendingDelayMs()); |
157 } | 157 } |
158 | 158 |
159 // At 60Hz, when the tick returns halfway to the next frame time, make sure | 159 // At 60Hz, when the tick returns halfway to the next frame time, make sure |
160 // a correct next delay value is posted. | 160 // a correct next delay value is posted. |
161 TEST(CCDelayBasedTimeSource, NextDelaySaneWhenHalfAfterRequestedTime) | 161 TEST(DelayBasedTimeSource, NextDelaySaneWhenHalfAfterRequestedTime) |
162 { | 162 { |
163 FakeCCThread thread; | 163 FakeThread thread; |
164 FakeCCTimeSourceClient client; | 164 FakeTimeSourceClient client; |
165 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 165 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
166 timer->setClient(&client); | 166 timer->setClient(&client); |
167 timer->setActive(true); | 167 timer->setActive(true); |
168 // Run the first task, as that activates the timer and picks up a timebase. | 168 // Run the first task, as that activates the timer and picks up a timebase. |
169 thread.runPendingTask(); | 169 thread.runPendingTask(); |
170 | 170 |
171 EXPECT_EQ(16, thread.pendingDelayMs()); | 171 EXPECT_EQ(16, thread.pendingDelayMs()); |
172 | 172 |
173 timer->setNow(timer->now() + interval() + base::TimeDelta::FromMilliseconds(
8)); | 173 timer->setNow(timer->now() + interval() + base::TimeDelta::FromMilliseconds(
8)); |
174 thread.runPendingTask(); | 174 thread.runPendingTask(); |
175 | 175 |
176 EXPECT_EQ(8, thread.pendingDelayMs()); | 176 EXPECT_EQ(8, thread.pendingDelayMs()); |
177 } | 177 } |
178 | 178 |
179 // If the timebase and interval are updated with a jittery source, we want to | 179 // If the timebase and interval are updated with a jittery source, we want to |
180 // make sure we do not double tick. | 180 // make sure we do not double tick. |
181 TEST(CCDelayBasedTimeSource, SaneHandlingOfJitteryTimebase) | 181 TEST(DelayBasedTimeSource, SaneHandlingOfJitteryTimebase) |
182 { | 182 { |
183 FakeCCThread thread; | 183 FakeThread thread; |
184 FakeCCTimeSourceClient client; | 184 FakeTimeSourceClient client; |
185 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 185 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
186 timer->setClient(&client); | 186 timer->setClient(&client); |
187 timer->setActive(true); | 187 timer->setActive(true); |
188 // Run the first task, as that activates the timer and picks up a timebase. | 188 // Run the first task, as that activates the timer and picks up a timebase. |
189 thread.runPendingTask(); | 189 thread.runPendingTask(); |
190 | 190 |
191 EXPECT_EQ(16, thread.pendingDelayMs()); | 191 EXPECT_EQ(16, thread.pendingDelayMs()); |
192 | 192 |
193 // Jitter timebase ~1ms late | 193 // Jitter timebase ~1ms late |
194 timer->setNow(timer->now() + interval()); | 194 timer->setNow(timer->now() + interval()); |
195 timer->setTimebaseAndInterval(timer->now() + base::TimeDelta::FromMillisecon
ds(1), interval()); | 195 timer->setTimebaseAndInterval(timer->now() + base::TimeDelta::FromMillisecon
ds(1), interval()); |
196 thread.runPendingTask(); | 196 thread.runPendingTask(); |
197 | 197 |
198 // Without double tick prevention, pendingDelayMs would be 1. | 198 // Without double tick prevention, pendingDelayMs would be 1. |
199 EXPECT_EQ(17, thread.pendingDelayMs()); | 199 EXPECT_EQ(17, thread.pendingDelayMs()); |
200 | 200 |
201 // Jitter timebase ~1ms early | 201 // Jitter timebase ~1ms early |
202 timer->setNow(timer->now() + interval()); | 202 timer->setNow(timer->now() + interval()); |
203 timer->setTimebaseAndInterval(timer->now() - base::TimeDelta::FromMillisecon
ds(1), interval()); | 203 timer->setTimebaseAndInterval(timer->now() - base::TimeDelta::FromMillisecon
ds(1), interval()); |
204 thread.runPendingTask(); | 204 thread.runPendingTask(); |
205 | 205 |
206 EXPECT_EQ(15, thread.pendingDelayMs()); | 206 EXPECT_EQ(15, thread.pendingDelayMs()); |
207 } | 207 } |
208 | 208 |
209 TEST(CCDelayBasedTimeSource, HandlesSignificantTimebaseChangesImmediately) | 209 TEST(DelayBasedTimeSource, HandlesSignificantTimebaseChangesImmediately) |
210 { | 210 { |
211 FakeCCThread thread; | 211 FakeThread thread; |
212 FakeCCTimeSourceClient client; | 212 FakeTimeSourceClient client; |
213 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 213 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
214 timer->setClient(&client); | 214 timer->setClient(&client); |
215 timer->setActive(true); | 215 timer->setActive(true); |
216 // Run the first task, as that activates the timer and picks up a timebase. | 216 // Run the first task, as that activates the timer and picks up a timebase. |
217 thread.runPendingTask(); | 217 thread.runPendingTask(); |
218 | 218 |
219 EXPECT_EQ(16, thread.pendingDelayMs()); | 219 EXPECT_EQ(16, thread.pendingDelayMs()); |
220 | 220 |
221 // Tick, then shift timebase by +7ms. | 221 // Tick, then shift timebase by +7ms. |
222 timer->setNow(timer->now() + interval()); | 222 timer->setNow(timer->now() + interval()); |
223 thread.runPendingTask(); | 223 thread.runPendingTask(); |
(...skipping 17 matching lines...) Expand all Loading... |
241 | 241 |
242 client.reset(); | 242 client.reset(); |
243 thread.runPendingTaskOnOverwrite(true); | 243 thread.runPendingTaskOnOverwrite(true); |
244 timer->setTimebaseAndInterval(base::TimeTicks() + interval(), interval()); | 244 timer->setTimebaseAndInterval(base::TimeTicks() + interval(), interval()); |
245 thread.runPendingTaskOnOverwrite(false); | 245 thread.runPendingTaskOnOverwrite(false); |
246 | 246 |
247 EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. | 247 EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. |
248 EXPECT_EQ(16-7, thread.pendingDelayMs()); | 248 EXPECT_EQ(16-7, thread.pendingDelayMs()); |
249 } | 249 } |
250 | 250 |
251 TEST(CCDelayBasedTimeSource, HanldlesSignificantIntervalChangesImmediately) | 251 TEST(DelayBasedTimeSource, HanldlesSignificantIntervalChangesImmediately) |
252 { | 252 { |
253 FakeCCThread thread; | 253 FakeThread thread; |
254 FakeCCTimeSourceClient client; | 254 FakeTimeSourceClient client; |
255 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 255 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
256 timer->setClient(&client); | 256 timer->setClient(&client); |
257 timer->setActive(true); | 257 timer->setActive(true); |
258 // Run the first task, as that activates the timer and picks up a timebase. | 258 // Run the first task, as that activates the timer and picks up a timebase. |
259 thread.runPendingTask(); | 259 thread.runPendingTask(); |
260 | 260 |
261 EXPECT_EQ(16, thread.pendingDelayMs()); | 261 EXPECT_EQ(16, thread.pendingDelayMs()); |
262 | 262 |
263 // Tick, then double the interval. | 263 // Tick, then double the interval. |
264 timer->setNow(timer->now() + interval()); | 264 timer->setNow(timer->now() + interval()); |
265 thread.runPendingTask(); | 265 thread.runPendingTask(); |
(...skipping 16 matching lines...) Expand all Loading... |
282 | 282 |
283 client.reset(); | 283 client.reset(); |
284 thread.runPendingTaskOnOverwrite(true); | 284 thread.runPendingTaskOnOverwrite(true); |
285 timer->setTimebaseAndInterval(base::TimeTicks() + interval() * 3, interval()
); | 285 timer->setTimebaseAndInterval(base::TimeTicks() + interval() * 3, interval()
); |
286 thread.runPendingTaskOnOverwrite(false); | 286 thread.runPendingTaskOnOverwrite(false); |
287 | 287 |
288 EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. | 288 EXPECT_FALSE(client.tickCalled()); // Make sure pending tasks were canceled. |
289 EXPECT_EQ(16, thread.pendingDelayMs()); | 289 EXPECT_EQ(16, thread.pendingDelayMs()); |
290 } | 290 } |
291 | 291 |
292 TEST(CCDelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) | 292 TEST(DelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise) |
293 { | 293 { |
294 int numIterations = 10; | 294 int numIterations = 10; |
295 | 295 |
296 FakeCCThread thread; | 296 FakeThread thread; |
297 FakeCCTimeSourceClient client; | 297 FakeTimeSourceClient client; |
298 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 298 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
299 timer->setClient(&client); | 299 timer->setClient(&client); |
300 timer->setActive(true); | 300 timer->setActive(true); |
301 | 301 |
302 double totalFrameTime = 0; | 302 double totalFrameTime = 0; |
303 for (int i = 0; i < numIterations; ++i) { | 303 for (int i = 0; i < numIterations; ++i) { |
304 long long delayMs = thread.pendingDelayMs(); | 304 long long delayMs = thread.pendingDelayMs(); |
305 | 305 |
306 // accumulate the "delay" | 306 // accumulate the "delay" |
307 totalFrameTime += delayMs / 1000.0; | 307 totalFrameTime += delayMs / 1000.0; |
308 | 308 |
309 // Run the callback exactly when asked | 309 // Run the callback exactly when asked |
310 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(delayMs))
; | 310 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(delayMs))
; |
311 thread.runPendingTask(); | 311 thread.runPendingTask(); |
312 } | 312 } |
313 double averageInterval = totalFrameTime / static_cast<double>(numIterations)
; | 313 double averageInterval = totalFrameTime / static_cast<double>(numIterations)
; |
314 EXPECT_NEAR(1.0 / 60.0, averageInterval, 0.1); | 314 EXPECT_NEAR(1.0 / 60.0, averageInterval, 0.1); |
315 } | 315 } |
316 | 316 |
317 TEST(CCDelayBasedTimeSource, TestDeactivateWhilePending) | 317 TEST(DelayBasedTimeSource, TestDeactivateWhilePending) |
318 { | 318 { |
319 FakeCCThread thread; | 319 FakeThread thread; |
320 FakeCCTimeSourceClient client; | 320 FakeTimeSourceClient client; |
321 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 321 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
322 timer->setClient(&client); | 322 timer->setClient(&client); |
323 timer->setActive(true); // Should post a task. | 323 timer->setActive(true); // Should post a task. |
324 timer->setActive(false); | 324 timer->setActive(false); |
325 timer = NULL; | 325 timer = NULL; |
326 thread.runPendingTask(); // Should run the posted task without crashing. | 326 thread.runPendingTask(); // Should run the posted task without crashing. |
327 } | 327 } |
328 | 328 |
329 TEST(CCDelayBasedTimeSource, TestDeactivateAndReactivateBeforeNextTickTime) | 329 TEST(DelayBasedTimeSource, TestDeactivateAndReactivateBeforeNextTickTime) |
330 { | 330 { |
331 FakeCCThread thread; | 331 FakeThread thread; |
332 FakeCCTimeSourceClient client; | 332 FakeTimeSourceClient client; |
333 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 333 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
334 timer->setClient(&client); | 334 timer->setClient(&client); |
335 | 335 |
336 // Should run the activate task, and pick up a new timebase. | 336 // Should run the activate task, and pick up a new timebase. |
337 timer->setActive(true); | 337 timer->setActive(true); |
338 thread.runPendingTask(); | 338 thread.runPendingTask(); |
339 | 339 |
340 // Stop the timer | 340 // Stop the timer |
341 timer->setActive(false); | 341 timer->setActive(false); |
342 | 342 |
343 // Task will be pending anyway, run it | 343 // Task will be pending anyway, run it |
344 thread.runPendingTask(); | 344 thread.runPendingTask(); |
345 | 345 |
346 // Start the timer again, but before the next tick time the timer previously | 346 // Start the timer again, but before the next tick time the timer previously |
347 // planned on using. That same tick time should still be targeted. | 347 // planned on using. That same tick time should still be targeted. |
348 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(4)); | 348 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(4)); |
349 timer->setActive(true); | 349 timer->setActive(true); |
350 EXPECT_EQ(12, thread.pendingDelayMs()); | 350 EXPECT_EQ(12, thread.pendingDelayMs()); |
351 } | 351 } |
352 | 352 |
353 TEST(CCDelayBasedTimeSource, TestDeactivateAndReactivateAfterNextTickTime) | 353 TEST(DelayBasedTimeSource, TestDeactivateAndReactivateAfterNextTickTime) |
354 { | 354 { |
355 FakeCCThread thread; | 355 FakeThread thread; |
356 FakeCCTimeSourceClient client; | 356 FakeTimeSourceClient client; |
357 scoped_refptr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource
::create(interval(), &thread); | 357 scoped_refptr<FakeDelayBasedTimeSource> timer = FakeDelayBasedTimeSource::cr
eate(interval(), &thread); |
358 timer->setClient(&client); | 358 timer->setClient(&client); |
359 | 359 |
360 // Should run the activate task, and pick up a new timebase. | 360 // Should run the activate task, and pick up a new timebase. |
361 timer->setActive(true); | 361 timer->setActive(true); |
362 thread.runPendingTask(); | 362 thread.runPendingTask(); |
363 | 363 |
364 // Stop the timer | 364 // Stop the timer |
365 timer->setActive(false); | 365 timer->setActive(false); |
366 | 366 |
367 // Task will be pending anyway, run it | 367 // Task will be pending anyway, run it |
368 thread.runPendingTask(); | 368 thread.runPendingTask(); |
369 | 369 |
370 // Start the timer again, but before the next tick time the timer previously | 370 // Start the timer again, but before the next tick time the timer previously |
371 // planned on using. That same tick time should still be targeted. | 371 // planned on using. That same tick time should still be targeted. |
372 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(20)); | 372 timer->setNow(timer->now() + base::TimeDelta::FromMilliseconds(20)); |
373 timer->setActive(true); | 373 timer->setActive(true); |
374 EXPECT_EQ(13, thread.pendingDelayMs()); | 374 EXPECT_EQ(13, thread.pendingDelayMs()); |
375 } | 375 } |
376 | 376 |
377 } | 377 } |
OLD | NEW |