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 18 matching lines...) Expand all Loading... |
29 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } | 29 void RunUntilIdle() { mock_task_runner_->RunUntilIdle(); } |
30 | 30 |
31 void EnableIdleTasks() { | 31 void EnableIdleTasks() { |
32 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 32 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
33 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 33 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), |
34 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 34 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
35 scheduler_->DidCommitFrameToCompositor(); | 35 scheduler_->DidCommitFrameToCompositor(); |
36 } | 36 } |
37 | 37 |
38 protected: | 38 protected: |
39 static base::TimeDelta compositor_priority_after_touch_duration() { | |
40 return base::TimeDelta::FromMilliseconds( | |
41 RendererSchedulerImpl::kCompositorPriorityAfterTouchMillis); | |
42 } | |
43 | |
44 scoped_refptr<cc::TestNowSource> clock_; | 39 scoped_refptr<cc::TestNowSource> clock_; |
45 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 40 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
46 | 41 |
47 scoped_ptr<RendererSchedulerImpl> scheduler_; | 42 scoped_ptr<RendererSchedulerImpl> scheduler_; |
48 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 43 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
49 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 44 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
50 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; | 45 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; |
51 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 46 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
52 | 47 |
53 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest); | 48 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 bool* should_yield_after) { | 125 bool* should_yield_after) { |
131 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); | 126 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); |
132 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); | 127 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); |
133 if (simulate_input) { | 128 if (simulate_input) { |
134 scheduler->DidReceiveInputEventOnCompositorThread( | 129 scheduler->DidReceiveInputEventOnCompositorThread( |
135 blink::WebInputEvent::GestureFlingStart); | 130 blink::WebInputEvent::GestureFlingStart); |
136 } | 131 } |
137 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); | 132 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); |
138 } | 133 } |
139 | 134 |
140 void AnticipationTestTask(RendererSchedulerImpl* scheduler, | |
141 bool simulate_input, | |
142 bool* is_anticipated_before, | |
143 bool* is_anticipated_after) { | |
144 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated(); | |
145 if (simulate_input) { | |
146 scheduler->DidReceiveInputEventOnCompositorThread( | |
147 blink::WebInputEvent::GestureFlingStart); | |
148 } | |
149 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); | |
150 } | |
151 | |
152 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { | 135 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { |
153 int result = 0; | 136 int result = 0; |
154 default_task_runner_->PostTask(FROM_HERE, | 137 default_task_runner_->PostTask(FROM_HERE, |
155 base::Bind(OrderedTestTask, 1, &result)); | 138 base::Bind(OrderedTestTask, 1, &result)); |
156 default_task_runner_->PostTask(FROM_HERE, | 139 default_task_runner_->PostTask(FROM_HERE, |
157 base::Bind(OrderedTestTask, 2, &result)); | 140 base::Bind(OrderedTestTask, 2, &result)); |
158 default_task_runner_->PostTask(FROM_HERE, | 141 default_task_runner_->PostTask(FROM_HERE, |
159 base::Bind(OrderedTestTask, 3, &result)); | 142 base::Bind(OrderedTestTask, 3, &result)); |
160 default_task_runner_->PostTask(FROM_HERE, | 143 default_task_runner_->PostTask(FROM_HERE, |
161 base::Bind(OrderedTestTask, 4, &result)); | 144 base::Bind(OrderedTestTask, 4, &result)); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 FROM_HERE, | 492 FROM_HERE, |
510 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); | 493 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
511 | 494 |
512 // Compositor policy mode should have ended now that the clock has advanced. | 495 // Compositor policy mode should have ended now that the clock has advanced. |
513 RunUntilIdle(); | 496 RunUntilIdle(); |
514 EXPECT_THAT(order, | 497 EXPECT_THAT(order, |
515 testing::ElementsAre(std::string("D1"), std::string("C1"), | 498 testing::ElementsAre(std::string("D1"), std::string("C1"), |
516 std::string("D2"), std::string("C2"))); | 499 std::string("D2"), std::string("C2"))); |
517 } | 500 } |
518 | 501 |
519 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) { | |
520 bool is_anticipated_before = false; | |
521 bool is_anticipated_after = false; | |
522 | |
523 bool simulate_input = false; | |
524 default_task_runner_->PostTask( | |
525 FROM_HERE, | |
526 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | |
527 &is_anticipated_before, &is_anticipated_after)); | |
528 RunUntilIdle(); | |
529 // In its default state, without input receipt, the scheduler should indicate | |
530 // that no high-priority is anticipated. | |
531 EXPECT_FALSE(is_anticipated_before); | |
532 EXPECT_FALSE(is_anticipated_after); | |
533 | |
534 simulate_input = true; | |
535 default_task_runner_->PostTask( | |
536 FROM_HERE, | |
537 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | |
538 &is_anticipated_before, &is_anticipated_after)); | |
539 RunUntilIdle(); | |
540 // When input is received, the scheduler should indicate that high-priority | |
541 // work is anticipated. | |
542 EXPECT_FALSE(is_anticipated_before); | |
543 EXPECT_TRUE(is_anticipated_after); | |
544 | |
545 clock_->AdvanceNow(compositor_priority_after_touch_duration() * 2); | |
546 simulate_input = false; | |
547 default_task_runner_->PostTask( | |
548 FROM_HERE, | |
549 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | |
550 &is_anticipated_before, &is_anticipated_after)); | |
551 RunUntilIdle(); | |
552 // Without additional input, the scheduler should indicate that high-priority | |
553 // work is no longer anticipated. | |
554 EXPECT_FALSE(is_anticipated_before); | |
555 EXPECT_FALSE(is_anticipated_after); | |
556 } | |
557 | |
558 TEST_F(RendererSchedulerImplTest, TestShouldYield) { | 502 TEST_F(RendererSchedulerImplTest, TestShouldYield) { |
559 bool should_yield_before = false; | 503 bool should_yield_before = false; |
560 bool should_yield_after = false; | 504 bool should_yield_after = false; |
561 | 505 |
562 default_task_runner_->PostTask( | 506 default_task_runner_->PostTask( |
563 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 507 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
564 default_task_runner_, false, &should_yield_before, | 508 default_task_runner_, false, &should_yield_before, |
565 &should_yield_after)); | 509 &should_yield_after)); |
566 RunUntilIdle(); | 510 RunUntilIdle(); |
567 // Posting to default runner shouldn't cause yielding. | 511 // Posting to default runner shouldn't cause yielding. |
(...skipping 13 matching lines...) Expand all Loading... |
581 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 525 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
582 compositor_task_runner_, true, &should_yield_before, | 526 compositor_task_runner_, true, &should_yield_before, |
583 &should_yield_after)); | 527 &should_yield_after)); |
584 RunUntilIdle(); | 528 RunUntilIdle(); |
585 // We should be able to switch to compositor priority mid-task. | 529 // We should be able to switch to compositor priority mid-task. |
586 EXPECT_FALSE(should_yield_before); | 530 EXPECT_FALSE(should_yield_before); |
587 EXPECT_TRUE(should_yield_after); | 531 EXPECT_TRUE(should_yield_after); |
588 } | 532 } |
589 | 533 |
590 } // namespace content | 534 } // namespace content |
OLD | NEW |