| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); | 364 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
| 365 | 365 |
| 366 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); | 366 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 367 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | 367 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 368 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); | 368 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 369 | 369 |
| 370 mock_task_runner_->RunUntilIdle(); // Wait until the pump. | 370 mock_task_runner_->RunUntilIdle(); // Wait until the pump. |
| 371 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); | 371 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 372 } | 372 } |
| 373 | 373 |
| 374 TEST_F(ThrottlingHelperTest, TaskQueueEnabledOnUnthrottle) { | 374 TEST_F(ThrottlingHelperTest, TaskQueueUnthrottle_InitiallyEnabled) { |
| 375 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); | 375 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
| 376 | 376 |
| 377 timer_queue_->SetQueueEnabled(true); // NOP |
| 377 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); | 378 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 378 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); | 379 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 379 | 380 |
| 380 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); | 381 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); |
| 381 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); | 382 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 382 } | 383 } |
| 383 | 384 |
| 385 TEST_F(ThrottlingHelperTest, TaskQueueUnthrottle_InitiallyDisabled) { |
| 386 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
| 387 |
| 388 timer_queue_->SetQueueEnabled(false); |
| 389 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 390 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 391 |
| 392 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); |
| 393 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 394 } |
| 395 |
| 396 TEST_F(ThrottlingHelperTest, SetQueueEnabled_Unthrottled) { |
| 397 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
| 398 |
| 399 throttling_helper_->SetQueueEnabled(timer_queue_.get(), false); |
| 400 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 401 |
| 402 throttling_helper_->SetQueueEnabled(timer_queue_.get(), true); |
| 403 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 404 } |
| 405 |
| 406 TEST_F(ThrottlingHelperTest, SetQueueEnabled_DisabledWhileThrottled) { |
| 407 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
| 408 |
| 409 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 410 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 411 |
| 412 throttling_helper_->SetQueueEnabled(timer_queue_.get(), false); |
| 413 throttling_helper_->DecreaseThrottleRefCount(timer_queue_.get()); |
| 414 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 415 } |
| 416 |
| 417 TEST_F(ThrottlingHelperTest, TaskQueueDisabledTillPump_ThenManuallyDisabled) { |
| 418 timer_queue_->PostTask(FROM_HERE, base::Bind(&NopTask)); |
| 419 |
| 420 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 421 throttling_helper_->IncreaseThrottleRefCount(timer_queue_.get()); |
| 422 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 423 |
| 424 mock_task_runner_->RunUntilIdle(); // Wait until the pump. |
| 425 EXPECT_TRUE(timer_queue_->IsQueueEnabled()); |
| 426 |
| 427 throttling_helper_->SetQueueEnabled(timer_queue_.get(), false); |
| 428 EXPECT_FALSE(timer_queue_->IsQueueEnabled()); |
| 429 } |
| 430 |
| 384 } // namespace scheduler | 431 } // namespace scheduler |
| OLD | NEW |