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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 bool* should_yield_after) { | 136 bool* should_yield_after) { |
137 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); | 137 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); |
138 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); | 138 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); |
139 if (simulate_input) { | 139 if (simulate_input) { |
140 scheduler->DidReceiveInputEventOnCompositorThread( | 140 scheduler->DidReceiveInputEventOnCompositorThread( |
141 blink::WebInputEvent::GestureFlingStart); | 141 blink::WebInputEvent::GestureFlingStart); |
142 } | 142 } |
143 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); | 143 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); |
144 } | 144 } |
145 | 145 |
| 146 void AnticipationTestTask(RendererSchedulerImpl* scheduler, |
| 147 bool simulate_input, |
| 148 bool* should_anticipate_before, |
| 149 bool* should_anticipate_after) { |
| 150 *should_anticipate_before = scheduler->ShouldAnticipateHighPriorityWork(); |
| 151 if (simulate_input) { |
| 152 scheduler->DidReceiveInputEventOnCompositorThread( |
| 153 blink::WebInputEvent::GestureFlingStart); |
| 154 } |
| 155 *should_anticipate_after = scheduler->ShouldAnticipateHighPriorityWork(); |
| 156 } |
| 157 |
146 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { | 158 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { |
147 int result = 0; | 159 int result = 0; |
148 default_task_runner_->PostTask(FROM_HERE, | 160 default_task_runner_->PostTask(FROM_HERE, |
149 base::Bind(OrderedTestTask, 1, &result)); | 161 base::Bind(OrderedTestTask, 1, &result)); |
150 default_task_runner_->PostTask(FROM_HERE, | 162 default_task_runner_->PostTask(FROM_HERE, |
151 base::Bind(OrderedTestTask, 2, &result)); | 163 base::Bind(OrderedTestTask, 2, &result)); |
152 default_task_runner_->PostTask(FROM_HERE, | 164 default_task_runner_->PostTask(FROM_HERE, |
153 base::Bind(OrderedTestTask, 3, &result)); | 165 base::Bind(OrderedTestTask, 3, &result)); |
154 default_task_runner_->PostTask(FROM_HERE, | 166 default_task_runner_->PostTask(FROM_HERE, |
155 base::Bind(OrderedTestTask, 4, &result)); | 167 base::Bind(OrderedTestTask, 4, &result)); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 FROM_HERE, | 472 FROM_HERE, |
461 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); | 473 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
462 | 474 |
463 // Compositor policy mode should have ended now that the clock has advanced. | 475 // Compositor policy mode should have ended now that the clock has advanced. |
464 RunUntilIdle(); | 476 RunUntilIdle(); |
465 EXPECT_THAT(order, | 477 EXPECT_THAT(order, |
466 testing::ElementsAre(std::string("D1"), std::string("C1"), | 478 testing::ElementsAre(std::string("D1"), std::string("C1"), |
467 std::string("D2"), std::string("C2"))); | 479 std::string("D2"), std::string("C2"))); |
468 } | 480 } |
469 | 481 |
| 482 TEST_F(RendererSchedulerImplTest, TestShouldAnticipate) { |
| 483 bool should_anticipate_before = false; |
| 484 bool should_anticipate_after = false; |
| 485 |
| 486 bool simulate_input = false; |
| 487 default_task_runner_->PostTask( |
| 488 FROM_HERE, |
| 489 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| 490 &should_anticipate_before, &should_anticipate_after)); |
| 491 RunUntilIdle(); |
| 492 // In its default state, without input receipt, the scheduler should indicate |
| 493 // that no high-priority is anticipated. |
| 494 EXPECT_FALSE(should_anticipate_before); |
| 495 EXPECT_FALSE(should_anticipate_after); |
| 496 |
| 497 simulate_input = true; |
| 498 default_task_runner_->PostTask( |
| 499 FROM_HERE, |
| 500 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| 501 &should_anticipate_before, &should_anticipate_after)); |
| 502 RunUntilIdle(); |
| 503 // When input is received, the scheduler should indicate that high-priority |
| 504 // work is anticipated. |
| 505 EXPECT_FALSE(should_anticipate_before); |
| 506 EXPECT_TRUE(should_anticipate_after); |
| 507 |
| 508 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(200)); |
| 509 simulate_input = false; |
| 510 default_task_runner_->PostTask( |
| 511 FROM_HERE, |
| 512 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| 513 &should_anticipate_before, &should_anticipate_after)); |
| 514 RunUntilIdle(); |
| 515 // Without additional input, the scheduler should indicate that high-priority |
| 516 // work is no longer anticipated. |
| 517 EXPECT_FALSE(should_anticipate_before); |
| 518 EXPECT_FALSE(should_anticipate_after); |
| 519 } |
| 520 |
470 TEST_F(RendererSchedulerImplTest, TestShouldYield) { | 521 TEST_F(RendererSchedulerImplTest, TestShouldYield) { |
471 bool should_yield_before = false; | 522 bool should_yield_before = false; |
472 bool should_yield_after = false; | 523 bool should_yield_after = false; |
473 | 524 |
474 default_task_runner_->PostTask( | 525 default_task_runner_->PostTask( |
475 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 526 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
476 default_task_runner_, false, &should_yield_before, | 527 default_task_runner_, false, &should_yield_before, |
477 &should_yield_after)); | 528 &should_yield_after)); |
478 RunUntilIdle(); | 529 RunUntilIdle(); |
479 // Posting to default runner shouldn't cause yielding. | 530 // Posting to default runner shouldn't cause yielding. |
(...skipping 13 matching lines...) Expand all Loading... |
493 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 544 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
494 compositor_task_runner_, true, &should_yield_before, | 545 compositor_task_runner_, true, &should_yield_before, |
495 &should_yield_after)); | 546 &should_yield_after)); |
496 RunUntilIdle(); | 547 RunUntilIdle(); |
497 // We should be able to switch to compositor priority mid-task. | 548 // We should be able to switch to compositor priority mid-task. |
498 EXPECT_FALSE(should_yield_before); | 549 EXPECT_FALSE(should_yield_before); |
499 EXPECT_TRUE(should_yield_after); | 550 EXPECT_TRUE(should_yield_after); |
500 } | 551 } |
501 | 552 |
502 } // namespace content | 553 } // namespace content |
OLD | NEW |