Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/scheduler/renderer_scheduler_impl.h" | 5 #include "content/renderer/scheduler/renderer_scheduler_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "cc/output/begin_frame_args.h" | 8 #include "cc/output/begin_frame_args.h" |
| 9 #include "cc/test/ordered_simple_task_runner.h" | 9 #include "cc/test/ordered_simple_task_runner.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 bool* should_yield_after) { | 138 bool* should_yield_after) { |
| 139 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); | 139 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); |
| 140 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); | 140 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); |
| 141 if (simulate_input) { | 141 if (simulate_input) { |
| 142 scheduler->DidReceiveInputEventOnCompositorThread( | 142 scheduler->DidReceiveInputEventOnCompositorThread( |
| 143 blink::WebInputEvent::GestureFlingStart); | 143 blink::WebInputEvent::GestureFlingStart); |
| 144 } | 144 } |
| 145 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); | 145 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void AnticipationTestTask(RendererSchedulerImpl* scheduler, | |
| 149 bool simulate_input, | |
| 150 bool* should_anticipate_before, | |
| 151 bool* should_anticipate_after) { | |
| 152 *should_anticipate_before = scheduler->ShouldAnticipateHighPriorityWork(); | |
| 153 if (simulate_input) { | |
| 154 scheduler->DidReceiveInputEventOnCompositorThread( | |
| 155 blink::WebInputEvent::GestureFlingStart); | |
| 156 } | |
| 157 *should_anticipate_after = scheduler->ShouldAnticipateHighPriorityWork(); | |
| 158 } | |
| 159 | |
| 148 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { | 160 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { |
| 149 int result = 0; | 161 int result = 0; |
| 150 default_task_runner_->PostTask(FROM_HERE, | 162 default_task_runner_->PostTask(FROM_HERE, |
| 151 base::Bind(OrderedTestTask, 1, &result)); | 163 base::Bind(OrderedTestTask, 1, &result)); |
| 152 default_task_runner_->PostTask(FROM_HERE, | 164 default_task_runner_->PostTask(FROM_HERE, |
| 153 base::Bind(OrderedTestTask, 2, &result)); | 165 base::Bind(OrderedTestTask, 2, &result)); |
| 154 default_task_runner_->PostTask(FROM_HERE, | 166 default_task_runner_->PostTask(FROM_HERE, |
| 155 base::Bind(OrderedTestTask, 3, &result)); | 167 base::Bind(OrderedTestTask, 3, &result)); |
| 156 default_task_runner_->PostTask(FROM_HERE, | 168 default_task_runner_->PostTask(FROM_HERE, |
| 157 base::Bind(OrderedTestTask, 4, &result)); | 169 base::Bind(OrderedTestTask, 4, &result)); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 FROM_HERE, | 517 FROM_HERE, |
| 506 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); | 518 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
| 507 | 519 |
| 508 // Compositor policy mode should have ended now that the clock has advanced. | 520 // Compositor policy mode should have ended now that the clock has advanced. |
| 509 RunUntilIdle(); | 521 RunUntilIdle(); |
| 510 EXPECT_THAT(order, | 522 EXPECT_THAT(order, |
| 511 testing::ElementsAre(std::string("D1"), std::string("C1"), | 523 testing::ElementsAre(std::string("D1"), std::string("C1"), |
| 512 std::string("D2"), std::string("C2"))); | 524 std::string("D2"), std::string("C2"))); |
| 513 } | 525 } |
| 514 | 526 |
| 527 TEST_F(RendererSchedulerImplTest, TestShouldAnticipate) { | |
| 528 bool should_anticipate_before = false; | |
| 529 bool should_anticipate_after = false; | |
| 530 | |
| 531 bool simulate_input = false; | |
| 532 default_task_runner_->PostTask( | |
| 533 FROM_HERE, | |
| 534 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | |
| 535 &should_anticipate_before, &should_anticipate_after)); | |
| 536 RunUntilIdle(); | |
| 537 // In its default state, without input receipt, the scheduler should indicate | |
| 538 // that no high-priority is anticipated. | |
| 539 EXPECT_FALSE(should_anticipate_before); | |
| 540 EXPECT_FALSE(should_anticipate_after); | |
| 541 | |
| 542 simulate_input = true; | |
| 543 default_task_runner_->PostTask( | |
| 544 FROM_HERE, | |
| 545 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | |
| 546 &should_anticipate_before, &should_anticipate_after)); | |
| 547 RunUntilIdle(); | |
| 548 // When input is received, the scheduler should indicate that high-priority | |
| 549 // work is anticipated. | |
| 550 EXPECT_FALSE(should_anticipate_before); | |
| 551 EXPECT_TRUE(should_anticipate_after); | |
| 552 | |
| 553 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
| |
| 554 simulate_input = false; | |
| 555 default_task_runner_->PostTask( | |
| 556 FROM_HERE, | |
| 557 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | |
| 558 &should_anticipate_before, &should_anticipate_after)); | |
| 559 RunUntilIdle(); | |
| 560 // Without additional input, the scheduler should indicate that high-priority | |
| 561 // work is no longer anticipated. | |
| 562 EXPECT_FALSE(should_anticipate_before); | |
| 563 EXPECT_FALSE(should_anticipate_after); | |
| 564 } | |
| 565 | |
| 515 TEST_F(RendererSchedulerImplTest, TestShouldYield) { | 566 TEST_F(RendererSchedulerImplTest, TestShouldYield) { |
| 516 bool should_yield_before = false; | 567 bool should_yield_before = false; |
| 517 bool should_yield_after = false; | 568 bool should_yield_after = false; |
| 518 | 569 |
| 519 default_task_runner_->PostTask( | 570 default_task_runner_->PostTask( |
| 520 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 571 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
| 521 default_task_runner_, false, &should_yield_before, | 572 default_task_runner_, false, &should_yield_before, |
| 522 &should_yield_after)); | 573 &should_yield_after)); |
| 523 RunUntilIdle(); | 574 RunUntilIdle(); |
| 524 // Posting to default runner shouldn't cause yielding. | 575 // Posting to default runner shouldn't cause yielding. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 538 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 589 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
| 539 compositor_task_runner_, true, &should_yield_before, | 590 compositor_task_runner_, true, &should_yield_before, |
| 540 &should_yield_after)); | 591 &should_yield_after)); |
| 541 RunUntilIdle(); | 592 RunUntilIdle(); |
| 542 // We should be able to switch to compositor priority mid-task. | 593 // We should be able to switch to compositor priority mid-task. |
| 543 EXPECT_FALSE(should_yield_before); | 594 EXPECT_FALSE(should_yield_before); |
| 544 EXPECT_TRUE(should_yield_after); | 595 EXPECT_TRUE(should_yield_after); |
| 545 } | 596 } |
| 546 | 597 |
| 547 } // namespace content | 598 } // namespace content |
| OLD | NEW |