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..21a0ef5b12ae992c69e0c7c50bd1348b7789d570 100644 |
--- a/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc |
+++ b/content/renderer/scheduler/renderer_scheduler_impl_unittest.cc |
@@ -145,6 +145,18 @@ void PostingYieldingTestTask( |
*should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); |
} |
+void AnticipationTestTask(RendererSchedulerImpl* scheduler, |
+ bool simulate_input, |
+ bool* should_anticipate_before, |
+ bool* should_anticipate_after) { |
+ *should_anticipate_before = scheduler->ShouldAnticipateHighPriorityWork(); |
+ if (simulate_input) { |
+ scheduler->DidReceiveInputEventOnCompositorThread( |
+ blink::WebInputEvent::GestureFlingStart); |
+ } |
+ *should_anticipate_after = scheduler->ShouldAnticipateHighPriorityWork(); |
+} |
+ |
TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { |
int result = 0; |
default_task_runner_->PostTask(FROM_HERE, |
@@ -512,6 +524,45 @@ TEST_F(RendererSchedulerImplTest, TestCompositorPolicyEnds) { |
std::string("D2"), std::string("C2"))); |
} |
+TEST_F(RendererSchedulerImplTest, TestShouldAnticipate) { |
+ bool should_anticipate_before = false; |
+ bool should_anticipate_after = false; |
+ |
+ bool simulate_input = false; |
+ default_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
+ &should_anticipate_before, &should_anticipate_after)); |
+ RunUntilIdle(); |
+ // In its default state, without input receipt, the scheduler should indicate |
+ // that no high-priority is anticipated. |
+ EXPECT_FALSE(should_anticipate_before); |
+ EXPECT_FALSE(should_anticipate_after); |
+ |
+ simulate_input = true; |
+ default_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
+ &should_anticipate_before, &should_anticipate_after)); |
+ RunUntilIdle(); |
+ // When input is received, the scheduler should indicate that high-priority |
+ // work is anticipated. |
+ EXPECT_FALSE(should_anticipate_before); |
+ EXPECT_TRUE(should_anticipate_after); |
+ |
+ clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(200)); |
alex clarke (OOO till 29th)
2015/01/26 17:16:00
Maybe make this an multiple of RendererSchedulerIm
jdduke (slow)
2015/01/26 20:14:49
Ah, good call, didn't realize that was exposed. Do
|
+ simulate_input = false; |
+ default_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
+ &should_anticipate_before, &should_anticipate_after)); |
+ RunUntilIdle(); |
+ // Without additional input, the scheduler should indicate that high-priority |
+ // work is no longer anticipated. |
+ EXPECT_FALSE(should_anticipate_before); |
+ EXPECT_FALSE(should_anticipate_after); |
+} |
+ |
TEST_F(RendererSchedulerImplTest, TestShouldYield) { |
bool should_yield_before = false; |
bool should_yield_after = false; |