| 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 <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 323 |
| 324 EXPECT_EQ(2u, task_count); // There are two since the cancelled task runs in | 324 EXPECT_EQ(2u, task_count); // There are two since the cancelled task runs in |
| 325 // the same DoWork batch. | 325 // the same DoWork batch. |
| 326 | 326 |
| 327 EXPECT_THAT( | 327 EXPECT_THAT( |
| 328 run_times, | 328 run_times, |
| 329 ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(6), | 329 ElementsAre(base::TimeTicks() + base::TimeDelta::FromSeconds(6), |
| 330 base::TimeTicks() + base::TimeDelta::FromSeconds(16))); | 330 base::TimeTicks() + base::TimeDelta::FromSeconds(16))); |
| 331 } | 331 } |
| 332 | 332 |
| 333 TEST_F(ThrottlingHelperTest, TaskDelayIsBasedOnRealTime) { | 333 TEST_F(ThrottlingHelperTest, ThrottledTasksReportRealTimeToBlink) { |
| 334 std::vector<base::TimeTicks> run_times; | 334 clock_->Advance(base::TimeDelta::FromSeconds(1)); |
| 335 |
| 336 EXPECT_EQ(timer_queue_->GetTimeDomain()->BlinkNow(), clock_->NowTicks()); |
| 335 | 337 |
| 336 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | 338 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 339 // Note the throttled time domain's view of time is usally in the past. |
| 340 EXPECT_LT(timer_queue_->GetTimeDomain()->Now(), clock_->NowTicks()); |
| 341 // But we report the current real time to blink. |
| 342 EXPECT_EQ(timer_queue_->GetTimeDomain()->BlinkNow(), clock_->NowTicks()); |
| 337 | 343 |
| 338 // Post an initial task that should run at the first aligned time period. | 344 // Advance realtime, and make sure BlinkNow advances too. |
| 339 timer_queue_->PostDelayedTask(FROM_HERE, | |
| 340 base::Bind(&TestTask, &run_times, clock_.get()), | |
| 341 base::TimeDelta::FromMilliseconds(900.0)); | |
| 342 | |
| 343 mock_task_runner_->RunUntilIdle(); | |
| 344 | |
| 345 // Advance realtime. | |
| 346 clock_->Advance(base::TimeDelta::FromMilliseconds(250)); | 345 clock_->Advance(base::TimeDelta::FromMilliseconds(250)); |
| 347 | 346 EXPECT_LT(timer_queue_->GetTimeDomain()->Now(), clock_->NowTicks()); |
| 348 // Post a task that due to real time + delay must run in the third aligned | 347 EXPECT_EQ(timer_queue_->GetTimeDomain()->BlinkNow(), clock_->NowTicks()); |
| 349 // time period. | |
| 350 timer_queue_->PostDelayedTask(FROM_HERE, | |
| 351 base::Bind(&TestTask, &run_times, clock_.get()), | |
| 352 base::TimeDelta::FromMilliseconds(900.0)); | |
| 353 | |
| 354 mock_task_runner_->RunUntilIdle(); | |
| 355 | |
| 356 EXPECT_THAT( | |
| 357 run_times, | |
| 358 ElementsAre( | |
| 359 base::TimeTicks() + base::TimeDelta::FromMilliseconds(1000.0), | |
| 360 base::TimeTicks() + base::TimeDelta::FromMilliseconds(3000.0))); | |
| 361 } | 348 } |
| 362 | 349 |
| 363 TEST_F(ThrottlingHelperTest, TaskQueueDisabledTillPump) { | 350 TEST_F(ThrottlingHelperTest, TaskQueueDisabledTillPump) { |
| 364 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); | 351 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
| 365 | 352 |
| 366 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); | 353 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 367 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | 354 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 368 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); | 355 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 369 | 356 |
| 370 mock_task_runner_->RunUntilIdle(); // Wait until the pump. | 357 mock_task_runner_->RunUntilIdle(); // Wait until the pump. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); | 421 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 435 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | 422 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 436 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | 423 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 437 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); | 424 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 438 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); | 425 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); |
| 439 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); | 426 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); |
| 440 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); | 427 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 441 } | 428 } |
| 442 | 429 |
| 443 } // namespace scheduler | 430 } // namespace scheduler |
| OLD | NEW |