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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } | 42 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } |
43 | 43 |
44 void EnableIdleTasks() { | 44 void EnableIdleTasks() { |
45 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 45 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
46 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 46 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), |
47 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 47 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
48 scheduler_->DidCommitFrameToCompositor(); | 48 scheduler_->DidCommitFrameToCompositor(); |
49 } | 49 } |
50 | 50 |
51 protected: | 51 protected: |
| 52 static base::TimeDelta compositor_priority_after_touch_duration() { |
| 53 return base::TimeDelta::FromMilliseconds( |
| 54 RendererSchedulerImpl::kCompositorPriorityAfterTouchMillis); |
| 55 } |
| 56 |
52 scoped_refptr<cc::TestNowSource> clock_; | 57 scoped_refptr<cc::TestNowSource> clock_; |
53 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 58 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
54 | 59 |
55 scoped_ptr<RendererSchedulerImpl> scheduler_; | 60 scoped_ptr<RendererSchedulerImpl> scheduler_; |
56 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 61 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
57 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 62 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
58 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; | 63 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; |
59 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 64 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
60 | 65 |
61 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest); | 66 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 bool* should_yield_after) { | 143 bool* should_yield_after) { |
139 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); | 144 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); |
140 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); | 145 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); |
141 if (simulate_input) { | 146 if (simulate_input) { |
142 scheduler->DidReceiveInputEventOnCompositorThread( | 147 scheduler->DidReceiveInputEventOnCompositorThread( |
143 blink::WebInputEvent::GestureFlingStart); | 148 blink::WebInputEvent::GestureFlingStart); |
144 } | 149 } |
145 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); | 150 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); |
146 } | 151 } |
147 | 152 |
| 153 void AnticipationTestTask(RendererSchedulerImpl* scheduler, |
| 154 bool simulate_input, |
| 155 bool* is_anticipated_before, |
| 156 bool* is_anticipated_after) { |
| 157 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated(); |
| 158 if (simulate_input) { |
| 159 scheduler->DidReceiveInputEventOnCompositorThread( |
| 160 blink::WebInputEvent::GestureFlingStart); |
| 161 } |
| 162 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); |
| 163 } |
| 164 |
148 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { | 165 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { |
149 int result = 0; | 166 int result = 0; |
150 default_task_runner_->PostTask(FROM_HERE, | 167 default_task_runner_->PostTask(FROM_HERE, |
151 base::Bind(OrderedTestTask, 1, &result)); | 168 base::Bind(OrderedTestTask, 1, &result)); |
152 default_task_runner_->PostTask(FROM_HERE, | 169 default_task_runner_->PostTask(FROM_HERE, |
153 base::Bind(OrderedTestTask, 2, &result)); | 170 base::Bind(OrderedTestTask, 2, &result)); |
154 default_task_runner_->PostTask(FROM_HERE, | 171 default_task_runner_->PostTask(FROM_HERE, |
155 base::Bind(OrderedTestTask, 3, &result)); | 172 base::Bind(OrderedTestTask, 3, &result)); |
156 default_task_runner_->PostTask(FROM_HERE, | 173 default_task_runner_->PostTask(FROM_HERE, |
157 base::Bind(OrderedTestTask, 4, &result)); | 174 base::Bind(OrderedTestTask, 4, &result)); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 FROM_HERE, | 522 FROM_HERE, |
506 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); | 523 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
507 | 524 |
508 // Compositor policy mode should have ended now that the clock has advanced. | 525 // Compositor policy mode should have ended now that the clock has advanced. |
509 RunUntilIdle(); | 526 RunUntilIdle(); |
510 EXPECT_THAT(order, | 527 EXPECT_THAT(order, |
511 testing::ElementsAre(std::string("D1"), std::string("C1"), | 528 testing::ElementsAre(std::string("D1"), std::string("C1"), |
512 std::string("D2"), std::string("C2"))); | 529 std::string("D2"), std::string("C2"))); |
513 } | 530 } |
514 | 531 |
| 532 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) { |
| 533 bool is_anticipated_before = false; |
| 534 bool is_anticipated_after = false; |
| 535 |
| 536 bool simulate_input = false; |
| 537 default_task_runner_->PostTask( |
| 538 FROM_HERE, |
| 539 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| 540 &is_anticipated_before, &is_anticipated_after)); |
| 541 RunUntilIdle(); |
| 542 // In its default state, without input receipt, the scheduler should indicate |
| 543 // that no high-priority is anticipated. |
| 544 EXPECT_FALSE(is_anticipated_before); |
| 545 EXPECT_FALSE(is_anticipated_after); |
| 546 |
| 547 simulate_input = true; |
| 548 default_task_runner_->PostTask( |
| 549 FROM_HERE, |
| 550 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| 551 &is_anticipated_before, &is_anticipated_after)); |
| 552 RunUntilIdle(); |
| 553 // When input is received, the scheduler should indicate that high-priority |
| 554 // work is anticipated. |
| 555 EXPECT_FALSE(is_anticipated_before); |
| 556 EXPECT_TRUE(is_anticipated_after); |
| 557 |
| 558 clock_->AdvanceNow(compositor_priority_after_touch_duration() * 2); |
| 559 simulate_input = false; |
| 560 default_task_runner_->PostTask( |
| 561 FROM_HERE, |
| 562 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
| 563 &is_anticipated_before, &is_anticipated_after)); |
| 564 RunUntilIdle(); |
| 565 // Without additional input, the scheduler should indicate that high-priority |
| 566 // work is no longer anticipated. |
| 567 EXPECT_FALSE(is_anticipated_before); |
| 568 EXPECT_FALSE(is_anticipated_after); |
| 569 } |
| 570 |
515 TEST_F(RendererSchedulerImplTest, TestShouldYield) { | 571 TEST_F(RendererSchedulerImplTest, TestShouldYield) { |
516 bool should_yield_before = false; | 572 bool should_yield_before = false; |
517 bool should_yield_after = false; | 573 bool should_yield_after = false; |
518 | 574 |
519 default_task_runner_->PostTask( | 575 default_task_runner_->PostTask( |
520 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 576 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
521 default_task_runner_, false, &should_yield_before, | 577 default_task_runner_, false, &should_yield_before, |
522 &should_yield_after)); | 578 &should_yield_after)); |
523 RunUntilIdle(); | 579 RunUntilIdle(); |
524 // Posting to default runner shouldn't cause yielding. | 580 // Posting to default runner shouldn't cause yielding. |
(...skipping 13 matching lines...) Expand all Loading... |
538 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 594 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
539 compositor_task_runner_, true, &should_yield_before, | 595 compositor_task_runner_, true, &should_yield_before, |
540 &should_yield_after)); | 596 &should_yield_after)); |
541 RunUntilIdle(); | 597 RunUntilIdle(); |
542 // We should be able to switch to compositor priority mid-task. | 598 // We should be able to switch to compositor priority mid-task. |
543 EXPECT_FALSE(should_yield_before); | 599 EXPECT_FALSE(should_yield_before); |
544 EXPECT_TRUE(should_yield_after); | 600 EXPECT_TRUE(should_yield_after); |
545 } | 601 } |
546 | 602 |
547 } // namespace content | 603 } // namespace content |
OLD | NEW |