OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/scheduler/renderer/throttling_helper.h" | 5 #include "components/scheduler/renderer/throttling_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 269 |
270 EXPECT_EQ(2u, task_count); // There are two since the cancelled task runs in | 270 EXPECT_EQ(2u, task_count); // There are two since the cancelled task runs in |
271 // the same DoWork batch. | 271 // the same DoWork batch. |
272 | 272 |
273 EXPECT_THAT( | 273 EXPECT_THAT( |
274 run_times, | 274 run_times, |
275 ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(6), | 275 ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(6), |
276 base::TimeTicks() + base::TimeDelta::FromSeconds(16))); | 276 base::TimeTicks() + base::TimeDelta::FromSeconds(16))); |
277 } | 277 } |
278 | 278 |
279 TEST_F(ThrottlingHelperTest, TaskDelayIsBasedOnRealTime) { | |
280 std::vector<base::TimeTicks> run_times; | |
281 | |
282 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | |
283 | |
284 // Post an initial task that should run at the first aligned time period. | |
285 timer_queue_->PostDelayedTask(FROM_HERE, | |
286 base::Bind(&TestTask, &run_times, clock_.get()), | |
287 base::TimeDelta::FromMilliseconds(900.0)); | |
288 | |
289 mock_task_runner_->RunUntilIdle(); | |
290 | |
291 // Advance realtime. | |
292 clock_->Advance(base::TimeDelta::FromMilliseconds(250)); | |
293 | |
294 // Post a task that due to real time + delay must run in the third aligned | |
295 // time period. | |
296 timer_queue_->PostDelayedTask(FROM_HERE, | |
297 base::Bind(&TestTask, &run_times, clock_.get()), | |
298 base::TimeDelta::FromMilliseconds(900.0)); | |
299 | |
300 mock_task_runner_->RunUntilIdle(); | |
301 | |
302 EXPECT_THAT( | |
303 run_times, | |
304 ElementsAre( | |
305 base::TimeTicks() + base::TimeDelta::FromMilliseconds(1000.0), | |
306 base::TimeTicks() + base::TimeDelta::FromMilliseconds(3000.0))); | |
307 } | |
308 | |
309 } // namespace scheduler | 279 } // namespace scheduler |
OLD | NEW |