Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/scheduler/renderer/renderer_scheduler_impl_unittest.cc

Issue 1320633002: Optimize for TouchStart responsiveness (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests and prioritize default tasks when loading tasks are priotized. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/scheduler/renderer/renderer_scheduler_impl.h" 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "cc/output/begin_frame_args.h" 9 #include "cc/output/begin_frame_args.h"
10 #include "cc/test/ordered_simple_task_runner.h" 10 #include "cc/test/ordered_simple_task_runner.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); 119 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork();
120 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); 120 task_runner->PostTask(FROM_HERE, base::Bind(NullTask));
121 if (simulate_input) { 121 if (simulate_input) {
122 scheduler->DidHandleInputEventOnCompositorThread( 122 scheduler->DidHandleInputEventOnCompositorThread(
123 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 123 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
124 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 124 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
125 } 125 }
126 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); 126 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork();
127 } 127 }
128 128
129 enum class SimulateInputType { None, TouchStart, TouchEnd };
130
129 void AnticipationTestTask(RendererSchedulerImpl* scheduler, 131 void AnticipationTestTask(RendererSchedulerImpl* scheduler,
130 bool simulate_input, 132 SimulateInputType simulate_input,
131 bool* is_anticipated_before, 133 bool* is_anticipated_before,
132 bool* is_anticipated_after) { 134 bool* is_anticipated_after) {
133 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated(); 135 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated();
134 if (simulate_input) { 136 switch (simulate_input) {
135 scheduler->DidHandleInputEventOnCompositorThread( 137 case SimulateInputType::None:
136 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 138 break;
137 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 139
140 case SimulateInputType::TouchStart:
141 scheduler->DidHandleInputEventOnCompositorThread(
142 FakeInputEvent(blink::WebInputEvent::TouchStart),
143 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
144 break;
145
146 case SimulateInputType::TouchEnd:
147 scheduler->DidHandleInputEventOnCompositorThread(
148 FakeInputEvent(blink::WebInputEvent::TouchEnd),
149 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
150 break;
138 } 151 }
139 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); 152 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated();
140 } 153 }
141 154
142 }; // namespace 155 }; // namespace
143 156
144 class RendererSchedulerImplForTest : public RendererSchedulerImpl { 157 class RendererSchedulerImplForTest : public RendererSchedulerImpl {
145 public: 158 public:
146 using RendererSchedulerImpl::OnIdlePeriodEnded; 159 using RendererSchedulerImpl::OnIdlePeriodEnded;
147 using RendererSchedulerImpl::OnIdlePeriodStarted; 160 using RendererSchedulerImpl::OnIdlePeriodStarted;
148 using RendererSchedulerImpl::Policy;
149 using RendererSchedulerImpl::PolicyToString;
150 161
151 RendererSchedulerImplForTest( 162 RendererSchedulerImplForTest(
152 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner) 163 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner)
153 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} 164 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {}
154 165
155 void UpdatePolicyLocked(UpdateType update_type) override { 166 void UpdatePolicyLocked(UpdateType update_type) override {
156 update_policy_count_++; 167 update_policy_count_++;
157 RendererSchedulerImpl::UpdatePolicyLocked(update_type); 168 RendererSchedulerImpl::UpdatePolicyLocked(update_type);
169
170 std::string use_case =
171 RendererScheduler::UseCaseToString(MainThreadOnly().current_use_case);
172 if (MainThreadOnly().touchstart_expected_soon) {
173 use_cases_.push_back(use_case + " scroll expected");
174 } else {
175 use_cases_.push_back(use_case);
176 }
158 } 177 }
159 178
160 void EnsureUrgentPolicyUpdatePostedOnMainThread() { 179 void EnsureUrgentPolicyUpdatePostedOnMainThread() {
161 base::AutoLock lock(any_thread_lock_); 180 base::AutoLock lock(any_thread_lock_);
162 RendererSchedulerImpl::EnsureUrgentPolicyUpdatePostedOnMainThread( 181 RendererSchedulerImpl::EnsureUrgentPolicyUpdatePostedOnMainThread(
163 FROM_HERE); 182 FROM_HERE);
164 } 183 }
165 184
166 void ScheduleDelayedPolicyUpdate(base::TimeTicks now, base::TimeDelta delay) { 185 void ScheduleDelayedPolicyUpdate(base::TimeTicks now, base::TimeDelta delay) {
167 delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay, now); 186 delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay, now);
168 } 187 }
169 188
170 bool BeginMainFrameOnCriticalPath() { 189 bool BeginMainFrameOnCriticalPath() {
171 base::AutoLock lock(any_thread_lock_); 190 base::AutoLock lock(any_thread_lock_);
172 return AnyThread().begin_main_frame_on_critical_path_; 191 return AnyThread().begin_main_frame_on_critical_path;
173 } 192 }
174 193
175 int update_policy_count_; 194 int update_policy_count_;
195 std::vector<std::string> use_cases_;
176 }; 196 };
177 197
178 // Lets gtest print human readable Policy values. 198 // Lets gtest print human readable Policy values.
179 ::std::ostream& operator<<(::std::ostream& os, 199 ::std::ostream& operator<<(::std::ostream& os,
180 const RendererSchedulerImplForTest::Policy& policy) { 200 const RendererScheduler::UseCase& use_case) {
181 return os << RendererSchedulerImplForTest::PolicyToString(policy); 201 return os << RendererScheduler::UseCaseToString(use_case);
182 } 202 }
183 203
184 class RendererSchedulerImplTest : public testing::Test { 204 class RendererSchedulerImplTest : public testing::Test {
185 public: 205 public:
186 using Policy = RendererSchedulerImpl::Policy; 206 using UseCase = RendererSchedulerImpl::UseCase;
187 207
188 RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) { 208 RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) {
189 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); 209 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
190 } 210 }
191 211
192 RendererSchedulerImplTest(base::MessageLoop* message_loop) 212 RendererSchedulerImplTest(base::MessageLoop* message_loop)
193 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) { 213 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) {
194 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); 214 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
195 } 215 }
196 216
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void RunUntilIdle() { 262 void RunUntilIdle() {
243 // Only one of mock_task_runner_ or message_loop_ should be set. 263 // Only one of mock_task_runner_ or message_loop_ should be set.
244 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); 264 DCHECK(!mock_task_runner_.get() || !message_loop_.get());
245 if (mock_task_runner_.get()) 265 if (mock_task_runner_.get())
246 mock_task_runner_->RunUntilIdle(); 266 mock_task_runner_->RunUntilIdle();
247 else 267 else
248 message_loop_->RunUntilIdle(); 268 message_loop_->RunUntilIdle();
249 } 269 }
250 270
251 void DoMainFrame() { 271 void DoMainFrame() {
252 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 272 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create(
253 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), 273 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
254 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 274 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL);
275 begin_frame_args.on_critical_path = false;
276 scheduler_->WillBeginFrame(begin_frame_args);
255 scheduler_->DidCommitFrameToCompositor(); 277 scheduler_->DidCommitFrameToCompositor();
256 } 278 }
257 279
280 void ForceMainThreadScrollingUseCase() {
281 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create(
282 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
283 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL);
284 begin_frame_args.on_critical_path = true;
285 scheduler_->WillBeginFrame(begin_frame_args);
286 }
287
258 void EnableIdleTasks() { DoMainFrame(); } 288 void EnableIdleTasks() { DoMainFrame(); }
259 289
260 Policy CurrentPolicy() { 290 UseCase CurrentUseCase() {
261 return scheduler_->MainThreadOnly().current_policy_; 291 return scheduler_->MainThreadOnly().current_use_case;
292 }
293
294 UseCase ForceUpdatePolicyAndGetCurrentUseCase() {
295 scheduler_->ForceUpdatePolicy();
296 return scheduler_->MainThreadOnly().current_use_case;
297 }
298
299 bool TouchStartExpectedSoon() {
300 return scheduler_->MainThreadOnly().touchstart_expected_soon;
262 } 301 }
263 302
264 // Helper for posting several tasks of specific types. |task_descriptor| is a 303 // Helper for posting several tasks of specific types. |task_descriptor| is a
265 // string with space delimited task identifiers. The first letter of each 304 // string with space delimited task identifiers. The first letter of each
266 // task identifier specifies the task type: 305 // task identifier specifies the task type:
267 // - 'D': Default task 306 // - 'D': Default task
268 // - 'C': Compositor task 307 // - 'C': Compositor task
269 // - 'L': Loading task 308 // - 'L': Loading task
270 // - 'I': Idle task 309 // - 'I': Idle task
271 // - 'T': Timer task 310 // - 'T': Timer task
(...skipping 27 matching lines...) Expand all
299 break; 338 break;
300 default: 339 default:
301 NOTREACHED(); 340 NOTREACHED();
302 } 341 }
303 } 342 }
304 } 343 }
305 344
306 protected: 345 protected:
307 static base::TimeDelta priority_escalation_after_input_duration() { 346 static base::TimeDelta priority_escalation_after_input_duration() {
308 return base::TimeDelta::FromMilliseconds( 347 return base::TimeDelta::FromMilliseconds(
309 RendererSchedulerImpl::kPriorityEscalationAfterInputMillis); 348 UserModel::kGestureEstimationLimitMillis);
349 }
350
351 static base::TimeDelta subsequent_input_expected_after_input_duration() {
352 return base::TimeDelta::FromMilliseconds(
353 UserModel::kExpectSubsequentGestureMillis);
310 } 354 }
311 355
312 static base::TimeDelta maximum_idle_period_duration() { 356 static base::TimeDelta maximum_idle_period_duration() {
313 return base::TimeDelta::FromMilliseconds( 357 return base::TimeDelta::FromMilliseconds(
314 IdleHelper::kMaximumIdlePeriodMillis); 358 IdleHelper::kMaximumIdlePeriodMillis);
315 } 359 }
316 360
317 static base::TimeDelta end_idle_when_hidden_delay() { 361 static base::TimeDelta end_idle_when_hidden_delay() {
318 return base::TimeDelta::FromMilliseconds( 362 return base::TimeDelta::FromMilliseconds(
319 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis); 363 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis);
(...skipping 12 matching lines...) Expand all
332 template <typename E> 376 template <typename E>
333 static void CallForEachEnumValue(E first, 377 static void CallForEachEnumValue(E first,
334 E last, 378 E last,
335 const char* (*function)(E)) { 379 const char* (*function)(E)) {
336 for (E val = first; val < last; 380 for (E val = first; val < last;
337 val = static_cast<E>(static_cast<int>(val) + 1)) { 381 val = static_cast<E>(static_cast<int>(val) + 1)) {
338 (*function)(val); 382 (*function)(val);
339 } 383 }
340 } 384 }
341 385
342 static void CheckAllPolicyToString() { 386 static void CheckAllUseCaseToString() {
343 CallForEachEnumValue<RendererSchedulerImpl::Policy>( 387 CallForEachEnumValue<RendererSchedulerImpl::UseCase>(
344 RendererSchedulerImpl::Policy::FIRST_POLICY, 388 RendererSchedulerImpl::UseCase::FIRST_USE_CASE,
345 RendererSchedulerImpl::Policy::POLICY_COUNT, 389 RendererSchedulerImpl::UseCase::USE_CASE_COUNT,
346 &RendererSchedulerImpl::PolicyToString); 390 &RendererSchedulerImpl::UseCaseToString);
347 } 391 }
348 392
349 scoped_ptr<base::SimpleTestTickClock> clock_; 393 scoped_ptr<base::SimpleTestTickClock> clock_;
350 // Only one of mock_task_runner_ or message_loop_ will be set. 394 // Only one of mock_task_runner_ or message_loop_ will be set.
351 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 395 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
352 scoped_ptr<base::MessageLoop> message_loop_; 396 scoped_ptr<base::MessageLoop> message_loop_;
353 397
354 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; 398 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_;
355 scoped_ptr<RendererSchedulerImplForTest> scheduler_; 399 scoped_ptr<RendererSchedulerImplForTest> scheduler_;
356 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 400 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 612 }
569 613
570 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { 614 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) {
571 std::vector<std::string> run_order; 615 std::vector<std::string> run_order;
572 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 616 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2");
573 617
574 EnableIdleTasks(); 618 EnableIdleTasks();
575 RunUntilIdle(); 619 RunUntilIdle();
576 EXPECT_THAT(run_order, 620 EXPECT_THAT(run_order,
577 testing::ElementsAre(std::string("L1"), std::string("D1"), 621 testing::ElementsAre(std::string("L1"), std::string("D1"),
578 std::string("C1"), std::string("D2"), 622 std::string("D2"), std::string("C1"),
579 std::string("C2"), std::string("I1"))); 623 std::string("C2"), std::string("I1")));
624 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
580 } 625 }
581 626
582 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_CompositorHandlesInput) { 627 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_CompositorHandlesInput) {
583 std::vector<std::string> run_order; 628 std::vector<std::string> run_order;
584 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 629 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2");
585 630
586 scheduler_->DidHandleInputEventOnCompositorThread( 631 scheduler_->DidHandleInputEventOnCompositorThread(
587 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 632 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
588 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 633 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
589 EnableIdleTasks(); 634 EnableIdleTasks();
590 RunUntilIdle(); 635 RunUntilIdle();
591 EXPECT_THAT(run_order, 636 EXPECT_THAT(run_order,
592 testing::ElementsAre(std::string("C1"), std::string("C2"), 637 testing::ElementsAre(std::string("L1"), std::string("D1"),
593 std::string("L1"), std::string("D1"), 638 std::string("C1"), std::string("D2"),
594 std::string("D2"), std::string("I1"))); 639 std::string("C2"), std::string("I1")));
640 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
595 } 641 }
596 642
597 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_MainThreadHandlesInput) { 643 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_MainThreadHandlesInput) {
598 std::vector<std::string> run_order; 644 std::vector<std::string> run_order;
599 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 645 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2");
600 646
601 scheduler_->DidHandleInputEventOnCompositorThread( 647 scheduler_->DidHandleInputEventOnCompositorThread(
602 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 648 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
603 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 649 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
604 EnableIdleTasks(); 650 EnableIdleTasks();
605 RunUntilIdle(); 651 RunUntilIdle();
606 EXPECT_THAT(run_order, 652 EXPECT_THAT(run_order,
607 testing::ElementsAre(std::string("C1"), std::string("C2"), 653 testing::ElementsAre(std::string("L1"), std::string("D1"),
608 std::string("L1"), std::string("D1"), 654 std::string("C1"), std::string("D2"),
609 std::string("D2"), std::string("I1"))); 655 std::string("C2"), std::string("I1")));
656 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
610 scheduler_->DidHandleInputEventOnMainThread( 657 scheduler_->DidHandleInputEventOnMainThread(
611 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 658 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
612 } 659 }
613 660
614 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_DidAnimateForInput) { 661 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_DidAnimateForInput) {
615 std::vector<std::string> run_order; 662 std::vector<std::string> run_order;
616 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 663 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
617 664
618 scheduler_->DidAnimateForInputOnCompositorThread(); 665 scheduler_->DidAnimateForInputOnCompositorThread();
619 EnableIdleTasks(); 666 EnableIdleTasks();
620 RunUntilIdle(); 667 RunUntilIdle();
621 EXPECT_THAT(run_order, 668 EXPECT_THAT(run_order,
622 testing::ElementsAre(std::string("C1"), std::string("C2"), 669 testing::ElementsAre(std::string("D1"), std::string("C1"),
623 std::string("D1"), std::string("D2"), 670 std::string("D2"), std::string("C2"),
624 std::string("I1"))); 671 std::string("I1")));
672 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
625 } 673 }
626 674
627 TEST_F( 675 TEST_F(
628 RendererSchedulerImplTest, 676 RendererSchedulerImplTest,
629 TestCompositorPolicy_ExpensiveTimersDontRunWhenMainThreadOnCriticalPath) { 677 TestCompositorPolicy_ExpensiveTimersDontRunWhenMainThreadOnCriticalPath) {
630 std::vector<std::string> run_order; 678 std::vector<std::string> run_order;
631 679
632 // Simulate a bunch of expensive timer tasks 680 // Simulate a bunch of expensive timer tasks
633 for (int i = 0; i < 10; i++) { 681 for (int i = 0; i < 10; i++) {
634 timer_task_runner_->PostTask( 682 timer_task_runner_->PostTask(
635 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance, 683 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance,
636 base::Unretained(clock_.get()), 684 base::Unretained(clock_.get()),
637 base::TimeDelta::FromMilliseconds(500))); 685 base::TimeDelta::FromMilliseconds(500)));
638 } 686 }
639 RunUntilIdle(); 687 RunUntilIdle();
640 688
641 // Timers should now be disabled during main thread user userinteractions. 689 // Timers should now be disabled during main thread user userinteractions.
642 PostTestTasks(&run_order, "C1 T1"); 690 PostTestTasks(&run_order, "C1 T1");
643 691
644 scheduler_->DidAnimateForInputOnCompositorThread(); 692 scheduler_->DidAnimateForInputOnCompositorThread();
645 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 693 cc::BeginFrameArgs begin_frame_args1 = cc::BeginFrameArgs::Create(
646 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), 694 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
647 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); 695 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL);
696 begin_frame_args1.on_critical_path = true;
697 scheduler_->WillBeginFrame(begin_frame_args1);
698 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period
648 RunUntilIdle(); 699 RunUntilIdle();
649 700
650 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1"))); 701 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1")));
651 clock_->Advance(priority_escalation_after_input_duration() * 2); 702 clock_->Advance(priority_escalation_after_input_duration() * 2);
652 703
653 run_order.clear(); 704 run_order.clear();
654 RunUntilIdle(); 705 RunUntilIdle();
655 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T1"))); 706 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T1")));
656 } 707 }
657 708
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); 842 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin));
792 RunUntilIdle(); 843 RunUntilIdle();
793 844
794 EXPECT_THAT(run_order, 845 EXPECT_THAT(run_order,
795 testing::ElementsAre(std::string("L1"), std::string("T1"), 846 testing::ElementsAre(std::string("L1"), std::string("T1"),
796 std::string("T2"))); 847 std::string("T2")));
797 } 848 }
798 849
799 TEST_F(RendererSchedulerImplTest, LoadingPriorityPolicy) { 850 TEST_F(RendererSchedulerImplTest, LoadingPriorityPolicy) {
800 std::vector<std::string> run_order; 851 std::vector<std::string> run_order;
801 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 852 PostTestTasks(&run_order, "I1 D1 C1 T1 L1 D2 C2 T2 L2");
802 853
803 scheduler_->OnPageLoadStarted(); 854 scheduler_->OnPageLoadStarted();
804 EnableIdleTasks(); 855 EnableIdleTasks();
805 RunUntilIdle(); 856 RunUntilIdle();
806 // In loading policy compositor tasks are best effort and should be run last.
807 EXPECT_THAT(run_order,
808 testing::ElementsAre(std::string("L1"), std::string("D1"),
809 std::string("D2"), std::string("I1"),
810 std::string("C1"), std::string("C2")));
811 857
812 // Advance 1.5s and try again, the loading policy should have ended and the 858 // In loading policy, loading tasks are prioritized other others.
813 // task order should return to normal. 859 std::string loading_policy_expected[] = {
814 clock_->Advance(base::TimeDelta::FromMilliseconds(1500)); 860 std::string("L1"), std::string("L2"), std::string("D1"),
861 std::string("C1"), std::string("T1"), std::string("D2"),
862 std::string("C2"), std::string("T2"), std::string("I1")};
863 EXPECT_THAT(run_order, testing::ElementsAreArray(loading_policy_expected));
864 EXPECT_EQ(RendererScheduler::UseCase::LOADING, CurrentUseCase());
865
866 // Advance 15s and try again, the loading policy should have ended and the
867 // task order should return to the NONE use case where loading tasks
868 // are prioritized.
869 clock_->Advance(base::TimeDelta::FromMilliseconds(150000));
815 run_order.clear(); 870 run_order.clear();
816 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 871 PostTestTasks(&run_order, "I1 D1 C1 T1 L1 D2 C2 T2 L2");
817 EnableIdleTasks(); 872 EnableIdleTasks();
818 RunUntilIdle(); 873 RunUntilIdle();
819 EXPECT_THAT(run_order, 874 // Loading tasks are actually still priprized byd efault.
820 testing::ElementsAre(std::string("L1"), std::string("D1"), 875 std::string default_order_expected[] = {
821 std::string("C1"), std::string("D2"), 876 std::string("L1"), std::string("L2"), std::string("D1"),
822 std::string("C2"), std::string("I1"))); 877 std::string("C1"), std::string("T1"), std::string("D2"),
878 std::string("C2"), std::string("T2"), std::string("I1")};
879 EXPECT_THAT(run_order, testing::ElementsAreArray(default_order_expected));
880 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
823 } 881 }
824 882
825 TEST_F(RendererSchedulerImplTest, 883 TEST_F(RendererSchedulerImplTest,
826 EventConsumedOnCompositorThread_IgnoresMouseMove_WhenMouseUp) { 884 EventConsumedOnCompositorThread_IgnoresMouseMove_WhenMouseUp) {
827 std::vector<std::string> run_order; 885 std::vector<std::string> run_order;
828 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 886 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
829 887
888 ForceMainThreadScrollingUseCase();
889 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
830 scheduler_->DidHandleInputEventOnCompositorThread( 890 scheduler_->DidHandleInputEventOnCompositorThread(
831 FakeInputEvent(blink::WebInputEvent::MouseMove), 891 FakeInputEvent(blink::WebInputEvent::MouseMove),
832 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 892 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
833 EnableIdleTasks();
834 RunUntilIdle(); 893 RunUntilIdle();
835 // Note compositor tasks are not prioritized. 894 // Note compositor tasks are not prioritized.
895 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
836 EXPECT_THAT(run_order, 896 EXPECT_THAT(run_order,
837 testing::ElementsAre(std::string("D1"), std::string("C1"), 897 testing::ElementsAre(std::string("D1"), std::string("D2"),
838 std::string("D2"), std::string("C2"), 898 std::string("C1"), std::string("C2"),
839 std::string("I1"))); 899 std::string("I1")));
840 } 900 }
841 901
842 TEST_F(RendererSchedulerImplTest, 902 TEST_F(RendererSchedulerImplTest,
843 EventForwardedToMainThread_IgnoresMouseMove_WhenMouseUp) { 903 EventForwardedToMainThread_IgnoresMouseMove_WhenMouseUp) {
844 std::vector<std::string> run_order; 904 std::vector<std::string> run_order;
845 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 905 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
846 906
907 ForceMainThreadScrollingUseCase();
908 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
847 scheduler_->DidHandleInputEventOnCompositorThread( 909 scheduler_->DidHandleInputEventOnCompositorThread(
848 FakeInputEvent(blink::WebInputEvent::MouseMove), 910 FakeInputEvent(blink::WebInputEvent::MouseMove),
849 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 911 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
850 EnableIdleTasks();
851 RunUntilIdle(); 912 RunUntilIdle();
852 // Note compositor tasks are not prioritized. 913 // Note compositor tasks are not prioritized.
914 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
853 EXPECT_THAT(run_order, 915 EXPECT_THAT(run_order,
854 testing::ElementsAre(std::string("D1"), std::string("C1"), 916 testing::ElementsAre(std::string("D1"), std::string("D2"),
855 std::string("D2"), std::string("C2"), 917 std::string("C1"), std::string("C2"),
856 std::string("I1"))); 918 std::string("I1")));
857 scheduler_->DidHandleInputEventOnMainThread(
858 FakeInputEvent(blink::WebInputEvent::MouseMove));
859 } 919 }
860 920
861 TEST_F(RendererSchedulerImplTest, 921 TEST_F(RendererSchedulerImplTest,
862 EventConsumedOnCompositorThread_MouseMove_WhenMouseDown) { 922 EventConsumedOnCompositorThread_MouseMove_WhenMouseDown) {
863 std::vector<std::string> run_order; 923 std::vector<std::string> run_order;
864 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 924 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
865 925
926 ForceMainThreadScrollingUseCase();
927 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
866 scheduler_->DidHandleInputEventOnCompositorThread( 928 scheduler_->DidHandleInputEventOnCompositorThread(
867 FakeInputEvent(blink::WebInputEvent::MouseMove, 929 FakeInputEvent(blink::WebInputEvent::MouseMove,
868 blink::WebInputEvent::LeftButtonDown), 930 blink::WebInputEvent::LeftButtonDown),
869 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 931 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
870 EnableIdleTasks();
871 RunUntilIdle(); 932 RunUntilIdle();
872 // Note compositor tasks are prioritized. 933 // Note compositor tasks are prioritized.
873 EXPECT_THAT(run_order, 934 EXPECT_THAT(run_order,
874 testing::ElementsAre(std::string("C1"), std::string("C2"), 935 testing::ElementsAre(std::string("C1"), std::string("C2"),
875 std::string("D1"), std::string("D2"), 936 std::string("D1"), std::string("D2"),
876 std::string("I1"))); 937 std::string("I1")));
877 } 938 }
878 939
879 TEST_F(RendererSchedulerImplTest, 940 TEST_F(RendererSchedulerImplTest,
880 EventForwardedToMainThread_MouseMove_WhenMouseDown) { 941 EventForwardedToMainThread_MouseMove_WhenMouseDown) {
881 std::vector<std::string> run_order; 942 std::vector<std::string> run_order;
882 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 943 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
883 944
945 ForceMainThreadScrollingUseCase();
946 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
884 scheduler_->DidHandleInputEventOnCompositorThread( 947 scheduler_->DidHandleInputEventOnCompositorThread(
885 FakeInputEvent(blink::WebInputEvent::MouseMove, 948 FakeInputEvent(blink::WebInputEvent::MouseMove,
886 blink::WebInputEvent::LeftButtonDown), 949 blink::WebInputEvent::LeftButtonDown),
887 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 950 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
888 EnableIdleTasks();
889 RunUntilIdle(); 951 RunUntilIdle();
890 // Note compositor tasks are prioritized. 952 // Note compositor tasks are prioritized.
891 EXPECT_THAT(run_order, 953 EXPECT_THAT(run_order,
892 testing::ElementsAre(std::string("C1"), std::string("C2"), 954 testing::ElementsAre(std::string("C1"), std::string("C2"),
893 std::string("D1"), std::string("D2"), 955 std::string("D1"), std::string("D2"),
894 std::string("I1"))); 956 std::string("I1")));
895 scheduler_->DidHandleInputEventOnMainThread(FakeInputEvent( 957 scheduler_->DidHandleInputEventOnMainThread(FakeInputEvent(
896 blink::WebInputEvent::MouseMove, blink::WebInputEvent::LeftButtonDown)); 958 blink::WebInputEvent::MouseMove, blink::WebInputEvent::LeftButtonDown));
897 } 959 }
898 960
899 TEST_F(RendererSchedulerImplTest, EventConsumedOnCompositorThread_MouseWheel) { 961 TEST_F(RendererSchedulerImplTest, EventConsumedOnCompositorThread_MouseWheel) {
900 std::vector<std::string> run_order; 962 std::vector<std::string> run_order;
901 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 963 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
902 964
965 ForceMainThreadScrollingUseCase();
966 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
903 scheduler_->DidHandleInputEventOnCompositorThread( 967 scheduler_->DidHandleInputEventOnCompositorThread(
904 FakeInputEvent(blink::WebInputEvent::MouseWheel), 968 FakeInputEvent(blink::WebInputEvent::MouseWheel),
905 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 969 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
906 EnableIdleTasks();
907 RunUntilIdle(); 970 RunUntilIdle();
908 // Note compositor tasks are prioritized. 971 // Note compositor tasks are prioritized.
909 EXPECT_THAT(run_order, 972 EXPECT_THAT(run_order,
910 testing::ElementsAre(std::string("C1"), std::string("C2"), 973 testing::ElementsAre(std::string("C1"), std::string("C2"),
911 std::string("D1"), std::string("D2"), 974 std::string("D1"), std::string("D2"),
912 std::string("I1"))); 975 std::string("I1")));
913 } 976 }
914 977
915 TEST_F(RendererSchedulerImplTest, EventForwardedToMainThread_MouseWheel) { 978 TEST_F(RendererSchedulerImplTest, EventForwardedToMainThread_MouseWheel) {
916 std::vector<std::string> run_order; 979 std::vector<std::string> run_order;
917 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 980 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
918 981
982 ForceMainThreadScrollingUseCase();
983 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
919 scheduler_->DidHandleInputEventOnCompositorThread( 984 scheduler_->DidHandleInputEventOnCompositorThread(
920 FakeInputEvent(blink::WebInputEvent::MouseWheel), 985 FakeInputEvent(blink::WebInputEvent::MouseWheel),
921 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 986 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
922 EnableIdleTasks();
923 RunUntilIdle(); 987 RunUntilIdle();
924 // Note compositor tasks are prioritized. 988 // Note compositor tasks are prioritized.
925 EXPECT_THAT(run_order, 989 EXPECT_THAT(run_order,
926 testing::ElementsAre(std::string("C1"), std::string("C2"), 990 testing::ElementsAre(std::string("C1"), std::string("C2"),
927 std::string("D1"), std::string("D2"), 991 std::string("D1"), std::string("D2"),
928 std::string("I1"))); 992 std::string("I1")));
929 scheduler_->DidHandleInputEventOnMainThread( 993 EXPECT_EQ(RendererScheduler::UseCase::MAIN_THREAD_GESTURE, CurrentUseCase());
930 FakeInputEvent(blink::WebInputEvent::MouseWheel));
931 } 994 }
932 995
933 TEST_F(RendererSchedulerImplTest, 996 TEST_F(RendererSchedulerImplTest,
934 EventConsumedOnCompositorThread_IgnoresKeyboardEvents) { 997 EventConsumedOnCompositorThread_IgnoresKeyboardEvents) {
935 std::vector<std::string> run_order; 998 std::vector<std::string> run_order;
936 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 999 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
937 1000
1001 ForceMainThreadScrollingUseCase();
1002 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
938 scheduler_->DidHandleInputEventOnCompositorThread( 1003 scheduler_->DidHandleInputEventOnCompositorThread(
939 FakeInputEvent(blink::WebInputEvent::KeyDown), 1004 FakeInputEvent(blink::WebInputEvent::KeyDown),
940 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1005 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
941 EnableIdleTasks();
942 RunUntilIdle(); 1006 RunUntilIdle();
943 // Note compositor tasks are not prioritized. 1007 // Note compositor tasks are not prioritized.
944 EXPECT_THAT(run_order, 1008 EXPECT_THAT(run_order,
945 testing::ElementsAre(std::string("D1"), std::string("C1"), 1009 testing::ElementsAre(std::string("D1"), std::string("D2"),
Sami 2015/09/07 16:57:57 This should change back now that we're no longer p
alex clarke (OOO till 29th) 2015/09/07 17:14:29 It did. I think you're looking at the wrong patch
946 std::string("D2"), std::string("C2"), 1010 std::string("C1"), std::string("C2"),
947 std::string("I1"))); 1011 std::string("I1")));
1012 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
948 } 1013 }
949 1014
950 TEST_F(RendererSchedulerImplTest, 1015 TEST_F(RendererSchedulerImplTest,
951 EventForwardedToMainThread_IgnoresKeyboardEvents) { 1016 EventForwardedToMainThread_IgnoresKeyboardEvents) {
952 std::vector<std::string> run_order; 1017 std::vector<std::string> run_order;
953 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 1018 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
954 1019
1020 ForceMainThreadScrollingUseCase();
1021 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
955 scheduler_->DidHandleInputEventOnCompositorThread( 1022 scheduler_->DidHandleInputEventOnCompositorThread(
956 FakeInputEvent(blink::WebInputEvent::KeyDown), 1023 FakeInputEvent(blink::WebInputEvent::KeyDown),
957 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1024 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
958 EnableIdleTasks();
959 RunUntilIdle(); 1025 RunUntilIdle();
960 // Note compositor tasks are not prioritized. 1026 // Note compositor tasks are not prioritized.
961 EXPECT_THAT(run_order, 1027 EXPECT_THAT(run_order,
962 testing::ElementsAre(std::string("D1"), std::string("C1"), 1028 testing::ElementsAre(std::string("D1"), std::string("D2"),
963 std::string("D2"), std::string("C2"), 1029 std::string("C1"), std::string("C2"),
964 std::string("I1"))); 1030 std::string("I1")));
1031 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
1032 // Note compositor tasks are not prioritized.
965 scheduler_->DidHandleInputEventOnMainThread( 1033 scheduler_->DidHandleInputEventOnMainThread(
966 FakeInputEvent(blink::WebInputEvent::KeyDown)); 1034 FakeInputEvent(blink::WebInputEvent::KeyDown));
967 } 1035 }
968 1036
969 TEST_F(RendererSchedulerImplTest, 1037 TEST_F(RendererSchedulerImplTest,
970 TestCompositorPolicyDoesNotStarveDefaultTasks) { 1038 TestMainthreadScrollingUseCaseDoesNotStarveDefaultTasks) {
1039 ForceMainThreadScrollingUseCase();
1040 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
1041
971 std::vector<std::string> run_order; 1042 std::vector<std::string> run_order;
972 PostTestTasks(&run_order, "D1 C1"); 1043 PostTestTasks(&run_order, "D1 C1");
973 1044
974 for (int i = 0; i < 20; i++) { 1045 for (int i = 0; i < 20; i++) {
975 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); 1046 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask));
976 } 1047 }
977 PostTestTasks(&run_order, "C2"); 1048 PostTestTasks(&run_order, "C2");
978 1049
979 scheduler_->DidHandleInputEventOnCompositorThread( 1050 scheduler_->DidHandleInputEventOnCompositorThread(
980 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1051 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
981 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1052 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
982 RunUntilIdle(); 1053 RunUntilIdle();
983 // Ensure that the default D1 task gets to run at some point before the final 1054 // Ensure that the default D1 task gets to run at some point before the final
984 // C2 compositor task. 1055 // C2 compositor task.
985 EXPECT_THAT(run_order, 1056 EXPECT_THAT(run_order,
986 testing::ElementsAre(std::string("C1"), std::string("D1"), 1057 testing::ElementsAre(std::string("C1"), std::string("D1"),
987 std::string("C2"))); 1058 std::string("C2")));
988 } 1059 }
989 1060
990 TEST_F(RendererSchedulerImplTest, 1061 TEST_F(RendererSchedulerImplTest,
991 TestCompositorPolicyEnds_CompositorHandlesInput) { 1062 TestCompositorPolicyEnds_CompositorHandlesInput) {
992 std::vector<std::string> run_order;
993 PostTestTasks(&run_order, "D1 C1 D2 C2");
994
995 scheduler_->DidHandleInputEventOnCompositorThread( 1063 scheduler_->DidHandleInputEventOnCompositorThread(
996 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1064 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
997 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1065 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
998 RunUntilIdle(); 1066 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE,
999 EXPECT_THAT(run_order, 1067 ForceUpdatePolicyAndGetCurrentUseCase());
1000 testing::ElementsAre(std::string("C1"), std::string("C2"),
1001 std::string("D1"), std::string("D2")));
1002 1068
1003 run_order.clear();
1004 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); 1069 clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
1005 PostTestTasks(&run_order, "D1 C1 D2 C2"); 1070 EXPECT_EQ(UseCase::NONE, ForceUpdatePolicyAndGetCurrentUseCase());
1006
1007 // Compositor policy mode should have ended now that the clock has advanced.
1008 RunUntilIdle();
1009 EXPECT_THAT(run_order,
1010 testing::ElementsAre(std::string("D1"), std::string("C1"),
1011 std::string("D2"), std::string("C2")));
1012 } 1071 }
1013 1072
1014 TEST_F(RendererSchedulerImplTest, 1073 TEST_F(RendererSchedulerImplTest,
1015 TestCompositorPolicyEnds_MainThreadHandlesInput) { 1074 TestCompositorPolicyEnds_MainThreadHandlesInput) {
1016 std::vector<std::string> run_order;
1017 PostTestTasks(&run_order, "D1 C1 D2 C2");
1018
1019 scheduler_->DidHandleInputEventOnCompositorThread( 1075 scheduler_->DidHandleInputEventOnCompositorThread(
1020 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1076 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
1021 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1077 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
1022 scheduler_->DidHandleInputEventOnMainThread( 1078 scheduler_->DidHandleInputEventOnMainThread(
1023 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 1079 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
1024 RunUntilIdle(); 1080 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE,
1025 EXPECT_THAT(run_order, 1081 ForceUpdatePolicyAndGetCurrentUseCase());
1026 testing::ElementsAre(std::string("C1"), std::string("C2"),
1027 std::string("D1"), std::string("D2")));
1028 1082
1029 run_order.clear();
1030 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); 1083 clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
1031 PostTestTasks(&run_order, "D1 C1 D2 C2"); 1084 EXPECT_EQ(UseCase::NONE, ForceUpdatePolicyAndGetCurrentUseCase());
1032
1033 // Compositor policy mode should have ended now that the clock has advanced.
1034 RunUntilIdle();
1035 EXPECT_THAT(run_order,
1036 testing::ElementsAre(std::string("D1"), std::string("C1"),
1037 std::string("D2"), std::string("C2")));
1038 } 1085 }
1039 1086
1040 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { 1087 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) {
1041 std::vector<std::string> run_order; 1088 std::vector<std::string> run_order;
1042 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); 1089 PostTestTasks(&run_order, "L1 D1 C1 D2 C2");
1043 1090
1044 scheduler_->DidHandleInputEventOnCompositorThread( 1091 scheduler_->DidHandleInputEventOnCompositorThread(
1045 FakeInputEvent(blink::WebInputEvent::TouchStart), 1092 FakeInputEvent(blink::WebInputEvent::TouchStart),
1046 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1093 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
1047 RunUntilIdle(); 1094 RunUntilIdle();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 FakeInputEvent(blink::WebInputEvent::TouchMove), 1138 FakeInputEvent(blink::WebInputEvent::TouchMove),
1092 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1139 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
1093 RunUntilIdle(); 1140 RunUntilIdle();
1094 EXPECT_THAT(run_order, testing::ElementsAre(std::string("L1"))); 1141 EXPECT_THAT(run_order, testing::ElementsAre(std::string("L1")));
1095 } 1142 }
1096 1143
1097 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) { 1144 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) {
1098 bool is_anticipated_before = false; 1145 bool is_anticipated_before = false;
1099 bool is_anticipated_after = false; 1146 bool is_anticipated_after = false;
1100 1147
1101 bool simulate_input = false;
1102 default_task_runner_->PostTask( 1148 default_task_runner_->PostTask(
1103 FROM_HERE, 1149 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1104 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 1150 SimulateInputType::None, &is_anticipated_before,
1105 &is_anticipated_before, &is_anticipated_after)); 1151 &is_anticipated_after));
1106 RunUntilIdle(); 1152 RunUntilIdle();
1107 // In its default state, without input receipt, the scheduler should indicate 1153 // In its default state, without input receipt, the scheduler should indicate
1108 // that no high-priority is anticipated. 1154 // that no high-priority is anticipated.
1109 EXPECT_FALSE(is_anticipated_before); 1155 EXPECT_FALSE(is_anticipated_before);
1110 EXPECT_FALSE(is_anticipated_after); 1156 EXPECT_FALSE(is_anticipated_after);
1111 1157
1112 simulate_input = true;
1113 default_task_runner_->PostTask( 1158 default_task_runner_->PostTask(
1114 FROM_HERE, 1159 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1115 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 1160 SimulateInputType::TouchStart,
1116 &is_anticipated_before, &is_anticipated_after)); 1161 &is_anticipated_before, &is_anticipated_after));
1162 bool dummy;
1163 default_task_runner_->PostTask(
1164 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1165 SimulateInputType::TouchEnd, &dummy, &dummy));
1166
1117 RunUntilIdle(); 1167 RunUntilIdle();
1118 // When input is received, the scheduler should indicate that high-priority 1168 // When input is received, the scheduler should indicate that high-priority
1119 // work is anticipated. 1169 // work is anticipated.
1120 EXPECT_FALSE(is_anticipated_before); 1170 EXPECT_FALSE(is_anticipated_before);
1121 EXPECT_TRUE(is_anticipated_after); 1171 EXPECT_TRUE(is_anticipated_after);
1122 1172
1123 clock_->Advance(priority_escalation_after_input_duration() * 2); 1173 clock_->Advance(priority_escalation_after_input_duration() * 2);
1124 simulate_input = false;
1125 default_task_runner_->PostTask( 1174 default_task_runner_->PostTask(
1126 FROM_HERE, 1175 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1127 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 1176 SimulateInputType::None, &is_anticipated_before,
1128 &is_anticipated_before, &is_anticipated_after)); 1177 &is_anticipated_after));
1129 RunUntilIdle(); 1178 RunUntilIdle();
1130 // Without additional input, the scheduler should indicate that high-priority 1179 // Without additional input, the scheduler should go into NONE
1131 // work is no longer anticipated. 1180 // use case but with scrolling expected where high-priority work is still
1181 // anticipated.
1182 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1183 EXPECT_TRUE(TouchStartExpectedSoon());
1184 EXPECT_TRUE(is_anticipated_before);
1185 EXPECT_TRUE(is_anticipated_after);
1186
1187 clock_->Advance(subsequent_input_expected_after_input_duration() * 2);
1188 default_task_runner_->PostTask(
1189 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1190 SimulateInputType::None, &is_anticipated_before,
1191 &is_anticipated_after));
1192 RunUntilIdle();
1193 // Eventually the scheduler should go into the default use case where
1194 // high-priority work is no longer anticipated.
1195 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1196 EXPECT_FALSE(TouchStartExpectedSoon());
1132 EXPECT_FALSE(is_anticipated_before); 1197 EXPECT_FALSE(is_anticipated_before);
1133 EXPECT_FALSE(is_anticipated_after); 1198 EXPECT_FALSE(is_anticipated_after);
1134 } 1199 }
1135 1200
1136 TEST_F(RendererSchedulerImplTest, TestShouldYield) { 1201 TEST_F(RendererSchedulerImplTest, TestShouldYield) {
1137 bool should_yield_before = false; 1202 bool should_yield_before = false;
1138 bool should_yield_after = false; 1203 bool should_yield_after = false;
1139 1204
1205 ForceMainThreadScrollingUseCase();
1206
1140 default_task_runner_->PostTask( 1207 default_task_runner_->PostTask(
1141 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 1208 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
1142 default_task_runner_, false, &should_yield_before, 1209 default_task_runner_, false, &should_yield_before,
1143 &should_yield_after)); 1210 &should_yield_after));
1144 RunUntilIdle(); 1211 RunUntilIdle();
1145 // Posting to default runner shouldn't cause yielding. 1212 // Posting to default runner shouldn't cause yielding.
1146 EXPECT_FALSE(should_yield_before); 1213 EXPECT_FALSE(should_yield_before);
1147 EXPECT_FALSE(should_yield_after); 1214 EXPECT_FALSE(should_yield_after);
1148 1215
1149 default_task_runner_->PostTask( 1216 default_task_runner_->PostTask(
1150 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 1217 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
1151 compositor_task_runner_, false, 1218 compositor_task_runner_, false,
1152 &should_yield_before, &should_yield_after)); 1219 &should_yield_before, &should_yield_after));
1153 RunUntilIdle(); 1220 RunUntilIdle();
1154 // Posting while not in compositor priority shouldn't cause yielding. 1221 // Posting while not mainthread scrolling shouldn't cause yielding.
1155 EXPECT_FALSE(should_yield_before); 1222 EXPECT_FALSE(should_yield_before);
1156 EXPECT_FALSE(should_yield_after); 1223 EXPECT_FALSE(should_yield_after);
1157 1224
1158 default_task_runner_->PostTask( 1225 default_task_runner_->PostTask(
1159 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 1226 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
1160 compositor_task_runner_, true, &should_yield_before, 1227 compositor_task_runner_, true, &should_yield_before,
1161 &should_yield_after)); 1228 &should_yield_after));
1162 RunUntilIdle(); 1229 RunUntilIdle();
1163 // We should be able to switch to compositor priority mid-task. 1230 // We should be able to switch to compositor priority mid-task.
1164 EXPECT_FALSE(should_yield_before); 1231 EXPECT_FALSE(should_yield_before);
1165 EXPECT_TRUE(should_yield_after); 1232 EXPECT_TRUE(should_yield_after);
1233 }
1166 1234
1235 TEST_F(RendererSchedulerImplTest, TestShouldYield_TouchStart) {
1167 // Receiving a touchstart should immediately trigger yielding, even if 1236 // Receiving a touchstart should immediately trigger yielding, even if
1168 // there's no immediately pending work in the compositor queue. 1237 // there's no immediately pending work in the compositor queue.
1169 EXPECT_FALSE(scheduler_->ShouldYieldForHighPriorityWork()); 1238 EXPECT_FALSE(scheduler_->ShouldYieldForHighPriorityWork());
1170 scheduler_->DidHandleInputEventOnCompositorThread( 1239 scheduler_->DidHandleInputEventOnCompositorThread(
1171 FakeInputEvent(blink::WebInputEvent::TouchStart), 1240 FakeInputEvent(blink::WebInputEvent::TouchStart),
1172 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1241 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
1173 EXPECT_TRUE(scheduler_->ShouldYieldForHighPriorityWork()); 1242 EXPECT_TRUE(scheduler_->ShouldYieldForHighPriorityWork());
1174 RunUntilIdle(); 1243 RunUntilIdle();
1175 } 1244 }
1176 1245
1177 TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) { 1246 TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) {
1178 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 1247 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1179 1248
1180 // An input event should bump us into input priority. 1249 // An input event should bump us into input priority.
1181 scheduler_->DidHandleInputEventOnCompositorThread( 1250 scheduler_->DidHandleInputEventOnCompositorThread(
1182 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1251 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
1183 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1252 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
1184 RunUntilIdle(); 1253 RunUntilIdle();
1185 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 1254 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
1186 1255
1187 // Simulate the input event being queued for a very long time. The compositor 1256 // Simulate the input event being queued for a very long time. The compositor
1188 // task we post here represents the enqueued input task. 1257 // task we post here represents the enqueued input task.
1189 clock_->Advance(priority_escalation_after_input_duration() * 2); 1258 clock_->Advance(priority_escalation_after_input_duration() * 2);
1190 scheduler_->DidHandleInputEventOnMainThread( 1259 scheduler_->DidHandleInputEventOnMainThread(
1191 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 1260 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
1192 RunUntilIdle(); 1261 RunUntilIdle();
1193 1262
1194 // Even though we exceeded the input priority escalation period, we should 1263 // Even though we exceeded the input priority escalation period, we should
1195 // still be in compositor priority since the input remains queued. 1264 // still be in compositor priority since the input remains queued.
1196 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 1265 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
1197 1266
1198 // After the escalation period ends we should go back into normal mode. 1267 // After the escalation period ends we should go back into normal mode.
1199 clock_->Advance(priority_escalation_after_input_duration() * 2); 1268 clock_->Advance(priority_escalation_after_input_duration() * 2);
1200 RunUntilIdle(); 1269 RunUntilIdle();
1201 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 1270 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1202 } 1271 }
1203 1272
1204 class RendererSchedulerImplWithMockSchedulerTest 1273 class RendererSchedulerImplWithMockSchedulerTest
1205 : public RendererSchedulerImplTest { 1274 : public RendererSchedulerImplTest {
1206 public: 1275 public:
1207 void SetUp() override { 1276 void SetUp() override {
1208 mock_task_runner_ = make_scoped_refptr( 1277 mock_task_runner_ = make_scoped_refptr(
1209 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); 1278 new cc::OrderedSimpleTaskRunner(clock_.get(), false));
1210 main_task_runner_ = 1279 main_task_runner_ =
1211 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); 1280 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 scheduler_->ShouldYieldForHighPriorityWork(); 1463 scheduler_->ShouldYieldForHighPriorityWork();
1395 scheduler_->ShouldYieldForHighPriorityWork(); 1464 scheduler_->ShouldYieldForHighPriorityWork();
1396 1465
1397 scheduler_->DidHandleInputEventOnMainThread( 1466 scheduler_->DidHandleInputEventOnMainThread(
1398 FakeInputEvent(blink::WebInputEvent::TouchStart)); 1467 FakeInputEvent(blink::WebInputEvent::TouchStart));
1399 scheduler_->DidHandleInputEventOnMainThread( 1468 scheduler_->DidHandleInputEventOnMainThread(
1400 FakeInputEvent(blink::WebInputEvent::TouchMove)); 1469 FakeInputEvent(blink::WebInputEvent::TouchMove));
1401 1470
1402 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); 1471 EXPECT_EQ(1, mock_scheduler_->update_policy_count_);
1403 1472
1473 // We expect both the urgent and the delayed updates to run in addition to the
1474 // earlier updated cause by IsHighPriorityWorkAnticipated, a final update
1475 // transitions from 'not_scrolling scroll expected' to 'not_scrolling'.
1404 RunUntilIdle(); 1476 RunUntilIdle();
1405 // We expect both the urgent and the delayed updates to run in addition to the 1477 EXPECT_THAT(mock_scheduler_->use_cases_,
1406 // earlier updated cause by IsHighPriorityWorkAnticipated. 1478 testing::ElementsAre(
1407 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); 1479 std::string("touchstart"), std::string("touchstart"),
1480 std::string("none scroll expected"), std::string("none")));
1408 } 1481 }
1409 1482
1410 class RendererSchedulerImplWithMessageLoopTest 1483 class RendererSchedulerImplWithMessageLoopTest
1411 : public RendererSchedulerImplTest { 1484 : public RendererSchedulerImplTest {
1412 public: 1485 public:
1413 RendererSchedulerImplWithMessageLoopTest() 1486 RendererSchedulerImplWithMessageLoopTest()
1414 : RendererSchedulerImplTest(new base::MessageLoop()) {} 1487 : RendererSchedulerImplTest(new base::MessageLoop()) {}
1415 ~RendererSchedulerImplWithMessageLoopTest() override {} 1488 ~RendererSchedulerImplWithMessageLoopTest() override {}
1416 1489
1417 void PostFromNestedRunloop(std::vector< 1490 void PostFromNestedRunloop(std::vector<
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 scheduler_->ResumeTimerQueue(); 1825 scheduler_->ResumeTimerQueue();
1753 RunUntilIdle(); 1826 RunUntilIdle();
1754 EXPECT_TRUE(run_order.empty()); 1827 EXPECT_TRUE(run_order.empty());
1755 1828
1756 scheduler_->ResumeTimerQueue(); 1829 scheduler_->ResumeTimerQueue();
1757 RunUntilIdle(); 1830 RunUntilIdle();
1758 EXPECT_THAT(run_order, 1831 EXPECT_THAT(run_order,
1759 testing::ElementsAre(std::string("T1"), std::string("T2"))); 1832 testing::ElementsAre(std::string("T1"), std::string("T2")));
1760 } 1833 }
1761 1834
1762 TEST_F(RendererSchedulerImplTest, PolicyToString) { 1835 TEST_F(RendererSchedulerImplTest, UseCaseToString) {
1763 CheckAllPolicyToString(); 1836 CheckAllUseCaseToString();
1764 } 1837 }
1765 1838
1766 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) { 1839 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) {
1767 // This should not DCHECK because there was no corresponding compositor side 1840 // This should not DCHECK because there was no corresponding compositor side
1768 // call to DidHandleInputEventOnCompositorThread with 1841 // call to DidHandleInputEventOnCompositorThread with
1769 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the 1842 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the
1770 // compositor to not be there and we don't want to make debugging impossible. 1843 // compositor to not be there and we don't want to make debugging impossible.
1771 scheduler_->DidHandleInputEventOnMainThread( 1844 scheduler_->DidHandleInputEventOnMainThread(
1772 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 1845 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
1773 } 1846 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 EXPECT_THAT(run_order, 1901 EXPECT_THAT(run_order,
1829 testing::ElementsAre(std::string("T4"), std::string("T5"))); 1902 testing::ElementsAre(std::string("T4"), std::string("T5")));
1830 1903
1831 // Subsequent timer tasks should fire as usual. 1904 // Subsequent timer tasks should fire as usual.
1832 run_order.clear(); 1905 run_order.clear();
1833 PostTestTasks(&run_order, "T6"); 1906 PostTestTasks(&run_order, "T6");
1834 RunUntilIdle(); 1907 RunUntilIdle();
1835 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6"))); 1908 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6")));
1836 } 1909 }
1837 } // namespace scheduler 1910 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698