| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 321 |
| 322 EXPECT_EQ(2u, task_count); // There are two since the cancelled task runs in | 322 EXPECT_EQ(2u, task_count); // There are two since the cancelled task runs in |
| 323 // the same DoWork batch. | 323 // the same DoWork batch. |
| 324 | 324 |
| 325 EXPECT_THAT( | 325 EXPECT_THAT( |
| 326 run_times, | 326 run_times, |
| 327 ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(6), | 327 ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(6), |
| 328 base::TimeTicks() + base::TimeDelta::FromSeconds(16))); | 328 base::TimeTicks() + base::TimeDelta::FromSeconds(16))); |
| 329 } | 329 } |
| 330 | 330 |
| 331 TEST_F(ThrottlingHelperTest, TaskDelayIsBasedOnRealTime) { | |
| 332 std::vector<base::TimeTicks> run_times; | |
| 333 | |
| 334 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | |
| 335 | |
| 336 // Post an initial task that should run at the first aligned time period. | |
| 337 timer_queue_->PostDelayedTask(FROM_HERE, | |
| 338 base::Bind(&TestTask, &run_times, clock_.get()), | |
| 339 base::TimeDelta::FromMilliseconds(900.0)); | |
| 340 | |
| 341 mock_task_runner_->RunUntilIdle(); | |
| 342 | |
| 343 // Advance realtime. | |
| 344 clock_->Advance(base::TimeDelta::FromMilliseconds(250)); | |
| 345 | |
| 346 // Post a task that due to real time + delay must run in the third aligned | |
| 347 // time period. | |
| 348 timer_queue_->PostDelayedTask(FROM_HERE, | |
| 349 base::Bind(&TestTask, &run_times, clock_.get()), | |
| 350 base::TimeDelta::FromMilliseconds(900.0)); | |
| 351 | |
| 352 mock_task_runner_->RunUntilIdle(); | |
| 353 | |
| 354 EXPECT_THAT( | |
| 355 run_times, | |
| 356 ElementsAre( | |
| 357 base::TimeTicks() + base::TimeDelta::FromMilliseconds(1000.0), | |
| 358 base::TimeTicks() + base::TimeDelta::FromMilliseconds(3000.0))); | |
| 359 } | |
| 360 | |
| 361 } // namespace scheduler | 331 } // namespace scheduler |
| OLD | NEW |