Chromium Code Reviews| Index: content/renderer/scheduler/renderer_scheduler_impl_unittest.cc |
| diff --git a/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc b/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc |
| index 36c85d3cf698afa5e30ae98609ae864efea56d30..9970b3a4c099cd433438455a03d14079bf06bfca 100644 |
| --- a/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc |
| +++ b/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc |
| @@ -49,6 +49,11 @@ class RendererSchedulerImplTest : public testing::Test { |
| } |
| protected: |
| + static base::TimeDelta compositor_priority_after_touch() { |
|
Sami
2015/01/27 14:06:06
nit: append "_duration" to the name?
jdduke (slow)
2015/01/27 16:59:09
Done.
|
| + return base::TimeDelta::FromMilliseconds( |
| + RendererSchedulerImpl::kCompositorPriorityAfterTouchMillis); |
| + } |
| + |
| scoped_refptr<cc::TestNowSource> clock_; |
| scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
| @@ -145,6 +150,18 @@ void PostingYieldingTestTask( |
| *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); |
| } |
| +void AnticipationTestTask(RendererSchedulerImpl* scheduler, |
| + bool simulate_input, |
| + bool* is_anticipated_before, |
| + bool* is_anticipated_after) { |
| + *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated(); |
| + if (simulate_input) { |
| + scheduler->DidReceiveInputEventOnCompositorThread( |
| + blink::WebInputEvent::GestureFlingStart); |
| + } |
| + *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); |
| +} |
| + |
| TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { |
| int result = 0; |
| default_task_runner_->PostTask(FROM_HERE, |
| @@ -512,6 +529,45 @@ TEST_F(RendererSchedulerImplTest, TestCompositorPolicyEnds) { |
| std::string("D2"), std::string("C2"))); |
| } |
| +TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) { |
| + bool is_anticipated_before = false; |
| + bool is_anticipated_after = false; |
| + |
| + bool simulate_input = false; |
| + default_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| + &is_anticipated_before, &is_anticipated_after)); |
| + RunUntilIdle(); |
| + // In its default state, without input receipt, the scheduler should indicate |
| + // that no high-priority is anticipated. |
| + EXPECT_FALSE(is_anticipated_before); |
| + EXPECT_FALSE(is_anticipated_after); |
| + |
| + simulate_input = true; |
| + default_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| + &is_anticipated_before, &is_anticipated_after)); |
| + RunUntilIdle(); |
| + // When input is received, the scheduler should indicate that high-priority |
| + // work is anticipated. |
| + EXPECT_FALSE(is_anticipated_before); |
| + EXPECT_TRUE(is_anticipated_after); |
| + |
| + clock_->AdvanceNow(compositor_priority_after_touch() * 2); |
| + simulate_input = false; |
| + default_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| + &is_anticipated_before, &is_anticipated_after)); |
| + RunUntilIdle(); |
| + // Without additional input, the scheduler should indicate that high-priority |
| + // work is no longer anticipated. |
| + EXPECT_FALSE(is_anticipated_before); |
| + EXPECT_FALSE(is_anticipated_after); |
| +} |
| + |
| TEST_F(RendererSchedulerImplTest, TestShouldYield) { |
| bool should_yield_before = false; |
| bool should_yield_after = false; |