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

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: Try set OnPageLoadStarted in RenderFrameImpl::OnNavigate 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 {
130 None,
131 TouchStart,
132 TouchEnd,
133 GestureScrollBegin,
134 GestureScrollEnd
135 };
136
129 void AnticipationTestTask(RendererSchedulerImpl* scheduler, 137 void AnticipationTestTask(RendererSchedulerImpl* scheduler,
130 bool simulate_input, 138 SimulateInputType simulate_input,
131 bool* is_anticipated_before, 139 bool* is_anticipated_before,
132 bool* is_anticipated_after) { 140 bool* is_anticipated_after) {
133 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated(); 141 *is_anticipated_before = scheduler->IsHighPriorityWorkAnticipated();
134 if (simulate_input) { 142 switch (simulate_input) {
135 scheduler->DidHandleInputEventOnCompositorThread( 143 case SimulateInputType::None:
136 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 144 break;
137 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 145
146 case SimulateInputType::TouchStart:
147 scheduler->DidHandleInputEventOnCompositorThread(
148 FakeInputEvent(blink::WebInputEvent::TouchStart),
149 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
150 break;
151
152 case SimulateInputType::TouchEnd:
153 scheduler->DidHandleInputEventOnCompositorThread(
154 FakeInputEvent(blink::WebInputEvent::TouchEnd),
155 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
156 break;
157
158 case SimulateInputType::GestureScrollBegin:
159 scheduler->DidHandleInputEventOnCompositorThread(
160 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin),
161 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
162 break;
163
164 case SimulateInputType::GestureScrollEnd:
165 scheduler->DidHandleInputEventOnCompositorThread(
166 FakeInputEvent(blink::WebInputEvent::GestureScrollEnd),
167 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
168 break;
138 } 169 }
139 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); 170 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated();
140 } 171 }
141 172
142 }; // namespace 173 }; // namespace
143 174
144 class RendererSchedulerImplForTest : public RendererSchedulerImpl { 175 class RendererSchedulerImplForTest : public RendererSchedulerImpl {
145 public: 176 public:
146 using RendererSchedulerImpl::OnIdlePeriodEnded; 177 using RendererSchedulerImpl::OnIdlePeriodEnded;
147 using RendererSchedulerImpl::OnIdlePeriodStarted; 178 using RendererSchedulerImpl::OnIdlePeriodStarted;
148 using RendererSchedulerImpl::Policy;
149 using RendererSchedulerImpl::PolicyToString;
150 179
151 RendererSchedulerImplForTest( 180 RendererSchedulerImplForTest(
152 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner) 181 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner)
153 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} 182 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {}
154 183
155 void UpdatePolicyLocked(UpdateType update_type) override { 184 void UpdatePolicyLocked(UpdateType update_type) override {
156 update_policy_count_++; 185 update_policy_count_++;
157 RendererSchedulerImpl::UpdatePolicyLocked(update_type); 186 RendererSchedulerImpl::UpdatePolicyLocked(update_type);
187
188 std::string use_case =
189 RendererScheduler::UseCaseToString(MainThreadOnly().current_use_case);
190 if (MainThreadOnly().touchstart_expected_soon) {
191 use_cases_.push_back(use_case + " scroll expected");
192 } else {
193 use_cases_.push_back(use_case);
194 }
158 } 195 }
159 196
160 void EnsureUrgentPolicyUpdatePostedOnMainThread() { 197 void EnsureUrgentPolicyUpdatePostedOnMainThread() {
161 base::AutoLock lock(any_thread_lock_); 198 base::AutoLock lock(any_thread_lock_);
162 RendererSchedulerImpl::EnsureUrgentPolicyUpdatePostedOnMainThread( 199 RendererSchedulerImpl::EnsureUrgentPolicyUpdatePostedOnMainThread(
163 FROM_HERE); 200 FROM_HERE);
164 } 201 }
165 202
166 void ScheduleDelayedPolicyUpdate(base::TimeTicks now, base::TimeDelta delay) { 203 void ScheduleDelayedPolicyUpdate(base::TimeTicks now, base::TimeDelta delay) {
167 delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay, now); 204 delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay, now);
168 } 205 }
169 206
170 bool BeginMainFrameOnCriticalPath() { 207 bool BeginMainFrameOnCriticalPath() {
171 base::AutoLock lock(any_thread_lock_); 208 base::AutoLock lock(any_thread_lock_);
172 return AnyThread().begin_main_frame_on_critical_path_; 209 return AnyThread().begin_main_frame_on_critical_path;
173 } 210 }
174 211
175 int update_policy_count_; 212 int update_policy_count_;
213 std::vector<std::string> use_cases_;
176 }; 214 };
177 215
178 // Lets gtest print human readable Policy values. 216 // Lets gtest print human readable Policy values.
179 ::std::ostream& operator<<(::std::ostream& os, 217 ::std::ostream& operator<<(::std::ostream& os,
180 const RendererSchedulerImplForTest::Policy& policy) { 218 const RendererScheduler::UseCase& use_case) {
181 return os << RendererSchedulerImplForTest::PolicyToString(policy); 219 return os << RendererScheduler::UseCaseToString(use_case);
182 } 220 }
183 221
184 class RendererSchedulerImplTest : public testing::Test { 222 class RendererSchedulerImplTest : public testing::Test {
185 public: 223 public:
186 using Policy = RendererSchedulerImpl::Policy; 224 using UseCase = RendererSchedulerImpl::UseCase;
187 225
188 RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) { 226 RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) {
189 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); 227 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
190 } 228 }
191 229
192 RendererSchedulerImplTest(base::MessageLoop* message_loop) 230 RendererSchedulerImplTest(base::MessageLoop* message_loop)
193 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) { 231 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) {
194 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); 232 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
195 } 233 }
196 234
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void RunUntilIdle() { 280 void RunUntilIdle() {
243 // Only one of mock_task_runner_ or message_loop_ should be set. 281 // Only one of mock_task_runner_ or message_loop_ should be set.
244 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); 282 DCHECK(!mock_task_runner_.get() || !message_loop_.get());
245 if (mock_task_runner_.get()) 283 if (mock_task_runner_.get())
246 mock_task_runner_->RunUntilIdle(); 284 mock_task_runner_->RunUntilIdle();
247 else 285 else
248 message_loop_->RunUntilIdle(); 286 message_loop_->RunUntilIdle();
249 } 287 }
250 288
251 void DoMainFrame() { 289 void DoMainFrame() {
252 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 290 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create(
253 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), 291 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
254 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 292 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL);
293 begin_frame_args.on_critical_path = false;
294 scheduler_->WillBeginFrame(begin_frame_args);
255 scheduler_->DidCommitFrameToCompositor(); 295 scheduler_->DidCommitFrameToCompositor();
256 } 296 }
257 297
298 void ForceMainThreadScrollingUseCase() {
299 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create(
300 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
301 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL);
302 begin_frame_args.on_critical_path = true;
303 scheduler_->WillBeginFrame(begin_frame_args);
304 }
305
258 void EnableIdleTasks() { DoMainFrame(); } 306 void EnableIdleTasks() { DoMainFrame(); }
259 307
260 Policy CurrentPolicy() { 308 UseCase CurrentUseCase() {
261 return scheduler_->MainThreadOnly().current_policy_; 309 return scheduler_->MainThreadOnly().current_use_case;
310 }
311
312 UseCase ForceUpdatePolicyAndGetCurrentUseCase() {
313 scheduler_->ForceUpdatePolicy();
314 return scheduler_->MainThreadOnly().current_use_case;
315 }
316
317 bool TouchStartExpectedSoon() {
318 return scheduler_->MainThreadOnly().touchstart_expected_soon;
319 }
320
321 bool HaveSeenABeginMainframe() {
322 return scheduler_->MainThreadOnly().have_seen_a_begin_main_frame;
323 }
324
325 bool LoadingTasksSeemExpensive() {
326 return scheduler_->MainThreadOnly().loading_tasks_seem_expensive;
327 }
328
329 bool TimerTasksSeemExpensive() {
330 return scheduler_->MainThreadOnly().timer_tasks_seem_expensive;
262 } 331 }
263 332
264 // Helper for posting several tasks of specific types. |task_descriptor| is a 333 // Helper for posting several tasks of specific types. |task_descriptor| is a
265 // string with space delimited task identifiers. The first letter of each 334 // string with space delimited task identifiers. The first letter of each
266 // task identifier specifies the task type: 335 // task identifier specifies the task type:
267 // - 'D': Default task 336 // - 'D': Default task
268 // - 'C': Compositor task 337 // - 'C': Compositor task
269 // - 'L': Loading task 338 // - 'L': Loading task
270 // - 'I': Idle task 339 // - 'I': Idle task
271 // - 'T': Timer task 340 // - 'T': Timer task
(...skipping 27 matching lines...) Expand all
299 break; 368 break;
300 default: 369 default:
301 NOTREACHED(); 370 NOTREACHED();
302 } 371 }
303 } 372 }
304 } 373 }
305 374
306 protected: 375 protected:
307 static base::TimeDelta priority_escalation_after_input_duration() { 376 static base::TimeDelta priority_escalation_after_input_duration() {
308 return base::TimeDelta::FromMilliseconds( 377 return base::TimeDelta::FromMilliseconds(
309 RendererSchedulerImpl::kPriorityEscalationAfterInputMillis); 378 UserModel::kGestureEstimationLimitMillis);
379 }
380
381 static base::TimeDelta subsequent_input_expected_after_input_duration() {
382 return base::TimeDelta::FromMilliseconds(
383 UserModel::kExpectSubsequentGestureMillis);
310 } 384 }
311 385
312 static base::TimeDelta maximum_idle_period_duration() { 386 static base::TimeDelta maximum_idle_period_duration() {
313 return base::TimeDelta::FromMilliseconds( 387 return base::TimeDelta::FromMilliseconds(
314 IdleHelper::kMaximumIdlePeriodMillis); 388 IdleHelper::kMaximumIdlePeriodMillis);
315 } 389 }
316 390
317 static base::TimeDelta end_idle_when_hidden_delay() { 391 static base::TimeDelta end_idle_when_hidden_delay() {
318 return base::TimeDelta::FromMilliseconds( 392 return base::TimeDelta::FromMilliseconds(
319 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis); 393 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis);
(...skipping 12 matching lines...) Expand all
332 template <typename E> 406 template <typename E>
333 static void CallForEachEnumValue(E first, 407 static void CallForEachEnumValue(E first,
334 E last, 408 E last,
335 const char* (*function)(E)) { 409 const char* (*function)(E)) {
336 for (E val = first; val < last; 410 for (E val = first; val < last;
337 val = static_cast<E>(static_cast<int>(val) + 1)) { 411 val = static_cast<E>(static_cast<int>(val) + 1)) {
338 (*function)(val); 412 (*function)(val);
339 } 413 }
340 } 414 }
341 415
342 static void CheckAllPolicyToString() { 416 static void CheckAllUseCaseToString() {
343 CallForEachEnumValue<RendererSchedulerImpl::Policy>( 417 CallForEachEnumValue<RendererSchedulerImpl::UseCase>(
344 RendererSchedulerImpl::Policy::FIRST_POLICY, 418 RendererSchedulerImpl::UseCase::FIRST_USE_CASE,
345 RendererSchedulerImpl::Policy::POLICY_COUNT, 419 RendererSchedulerImpl::UseCase::USE_CASE_COUNT,
346 &RendererSchedulerImpl::PolicyToString); 420 &RendererSchedulerImpl::UseCaseToString);
347 } 421 }
348 422
349 scoped_ptr<base::SimpleTestTickClock> clock_; 423 scoped_ptr<base::SimpleTestTickClock> clock_;
350 // Only one of mock_task_runner_ or message_loop_ will be set. 424 // Only one of mock_task_runner_ or message_loop_ will be set.
351 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 425 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
352 scoped_ptr<base::MessageLoop> message_loop_; 426 scoped_ptr<base::MessageLoop> message_loop_;
353 427
354 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; 428 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_;
355 scoped_ptr<RendererSchedulerImplForTest> scheduler_; 429 scoped_ptr<RendererSchedulerImplForTest> scheduler_;
356 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 430 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { 644 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) {
571 std::vector<std::string> run_order; 645 std::vector<std::string> run_order;
572 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 646 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2");
573 647
574 EnableIdleTasks(); 648 EnableIdleTasks();
575 RunUntilIdle(); 649 RunUntilIdle();
576 EXPECT_THAT(run_order, 650 EXPECT_THAT(run_order,
577 testing::ElementsAre(std::string("L1"), std::string("D1"), 651 testing::ElementsAre(std::string("L1"), std::string("D1"),
578 std::string("C1"), std::string("D2"), 652 std::string("C1"), std::string("D2"),
579 std::string("C2"), std::string("I1"))); 653 std::string("C2"), std::string("I1")));
654 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
580 } 655 }
581 656
582 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_CompositorHandlesInput) { 657 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_CompositorHandlesInput) {
583 std::vector<std::string> run_order; 658 std::vector<std::string> run_order;
584 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 659 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2");
585 660
586 scheduler_->DidHandleInputEventOnCompositorThread( 661 scheduler_->DidHandleInputEventOnCompositorThread(
587 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 662 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
588 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 663 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
589 EnableIdleTasks(); 664 EnableIdleTasks();
590 RunUntilIdle(); 665 RunUntilIdle();
591 EXPECT_THAT(run_order, 666 EXPECT_THAT(run_order,
592 testing::ElementsAre(std::string("C1"), std::string("C2"), 667 testing::ElementsAre(std::string("L1"), std::string("D1"),
593 std::string("L1"), std::string("D1"), 668 std::string("C1"), std::string("D2"),
594 std::string("D2"), std::string("I1"))); 669 std::string("C2"), std::string("I1")));
670 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
595 } 671 }
596 672
597 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_MainThreadHandlesInput) { 673 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_MainThreadHandlesInput) {
598 std::vector<std::string> run_order; 674 std::vector<std::string> run_order;
599 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 675 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2");
600 676
601 scheduler_->DidHandleInputEventOnCompositorThread( 677 scheduler_->DidHandleInputEventOnCompositorThread(
602 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 678 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
603 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 679 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
604 EnableIdleTasks(); 680 EnableIdleTasks();
605 RunUntilIdle(); 681 RunUntilIdle();
606 EXPECT_THAT(run_order, 682 EXPECT_THAT(run_order,
607 testing::ElementsAre(std::string("C1"), std::string("C2"), 683 testing::ElementsAre(std::string("L1"), std::string("D1"),
608 std::string("L1"), std::string("D1"), 684 std::string("C1"), std::string("D2"),
609 std::string("D2"), std::string("I1"))); 685 std::string("C2"), std::string("I1")));
686 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
610 scheduler_->DidHandleInputEventOnMainThread( 687 scheduler_->DidHandleInputEventOnMainThread(
611 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 688 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
612 } 689 }
613 690
614 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_DidAnimateForInput) { 691 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_DidAnimateForInput) {
615 std::vector<std::string> run_order; 692 std::vector<std::string> run_order;
616 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 693 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
617 694
618 scheduler_->DidAnimateForInputOnCompositorThread(); 695 scheduler_->DidAnimateForInputOnCompositorThread();
619 EnableIdleTasks(); 696 EnableIdleTasks();
620 RunUntilIdle(); 697 RunUntilIdle();
621 EXPECT_THAT(run_order, 698 EXPECT_THAT(run_order,
622 testing::ElementsAre(std::string("C1"), std::string("C2"), 699 testing::ElementsAre(std::string("D1"), std::string("C1"),
623 std::string("D1"), std::string("D2"), 700 std::string("D2"), std::string("C2"),
624 std::string("I1"))); 701 std::string("I1")));
702 EXPECT_EQ(RendererScheduler::UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
625 } 703 }
626 704
627 TEST_F( 705 TEST_F(
628 RendererSchedulerImplTest, 706 RendererSchedulerImplTest,
629 TestCompositorPolicy_ExpensiveTimersDontRunWhenMainThreadOnCriticalPath) { 707 TestCompositorPolicy_ExpensiveTimersDontRunWhenMainThreadOnCriticalPath) {
630 std::vector<std::string> run_order; 708 std::vector<std::string> run_order;
631 709
710 // RunUntilIdle won't actually run all of the SimpleTestTickClock::Advance
711 // tasks unless we set AutoAdvanceNow to true :/
712 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
713
632 // Simulate a bunch of expensive timer tasks 714 // Simulate a bunch of expensive timer tasks
633 for (int i = 0; i < 10; i++) { 715 for (int i = 0; i < 10; i++) {
634 timer_task_runner_->PostTask( 716 timer_task_runner_->PostTask(
635 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance, 717 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance,
636 base::Unretained(clock_.get()), 718 base::Unretained(clock_.get()),
637 base::TimeDelta::FromMilliseconds(500))); 719 base::TimeDelta::FromMilliseconds(500)));
638 } 720 }
721
639 RunUntilIdle(); 722 RunUntilIdle();
640 723
641 // Timers should now be disabled during main thread user userinteractions. 724 // Switch back to not auto-advancing because we want to be in control of when
725 // time advances.
726 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(false);
727
728 // Timers should now be disabled during main thread user user interactions.
729 PostTestTasks(&run_order, "C1 T1");
730
731 // Trigger main_thread_gesture UseCase
732 scheduler_->DidAnimateForInputOnCompositorThread();
733 cc::BeginFrameArgs begin_frame_args1 = cc::BeginFrameArgs::Create(
734 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
735 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL);
736 begin_frame_args1.on_critical_path = true;
737 scheduler_->WillBeginFrame(begin_frame_args1);
738 RunUntilIdle();
739 EXPECT_EQ(RendererScheduler::UseCase::MAIN_THREAD_GESTURE, CurrentUseCase());
740
741 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1")));
742 clock_->Advance(subsequent_input_expected_after_input_duration() * 2);
743
744 run_order.clear();
745 RunUntilIdle();
746 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
747 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T1")));
748 }
749
750 TEST_F(RendererSchedulerImplTest, Navigation_ResetsTaskCostEstimations) {
751 std::vector<std::string> run_order;
752
753 // RunUntilIdle won't actually run all of the SimpleTestTickClock::Advance
754 // tasks unless we set AutoAdvanceNow to true :/
755 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
756
757 // Simulate a bunch of expensive timer tasks
758 for (int i = 0; i < 10; i++) {
759 timer_task_runner_->PostTask(
760 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance,
761 base::Unretained(clock_.get()),
762 base::TimeDelta::FromMilliseconds(500)));
763 }
764
765 RunUntilIdle();
766
767 // Switch back to not auto-advancing because we want to be in control of when
768 // time advances.
769 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(false);
770
771 scheduler_->OnPageLoadStarted();
642 PostTestTasks(&run_order, "C1 T1"); 772 PostTestTasks(&run_order, "C1 T1");
643 773
644 scheduler_->DidAnimateForInputOnCompositorThread(); 774 scheduler_->DidAnimateForInputOnCompositorThread();
645 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 775 cc::BeginFrameArgs begin_frame_args1 = cc::BeginFrameArgs::Create(
646 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), 776 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
647 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); 777 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL);
648 RunUntilIdle(); 778 begin_frame_args1.on_critical_path = true;
649 779 scheduler_->WillBeginFrame(begin_frame_args1);
650 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1"))); 780 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period
651 clock_->Advance(priority_escalation_after_input_duration() * 2);
652
653 run_order.clear();
654 RunUntilIdle();
655 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T1")));
656 }
657
658 TEST_F(RendererSchedulerImplTest,
659 TestCompositorPolicy_TimersAlwaysRunIfNoRecentIdlePeriod) {
660 std::vector<std::string> run_order;
661 PostTestTasks(&run_order, "C1 T1");
662
663 // Simulate no recent idle period.
664 clock_->Advance(idle_period_starvation_threshold() * 2);
665
666 scheduler_->DidAnimateForInputOnCompositorThread();
667 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
668 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
669 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL));
670
671 RunUntilIdle(); 781 RunUntilIdle();
672 782
673 EXPECT_THAT(run_order, 783 EXPECT_THAT(run_order,
674 testing::ElementsAre(std::string("C1"), std::string("T1"))); 784 testing::ElementsAre(std::string("C1"), std::string("T1")));
675 } 785 }
676 786
677 TEST_F(RendererSchedulerImplTest, 787 TEST_F(RendererSchedulerImplTest,
678 TestCompositorPolicy_TimersAlwaysRun_MainThreadNotOnCriticalPath) { 788 TestCompositorPolicy_TimersAlwaysRun_MainThreadNotOnCriticalPath) {
679 std::vector<std::string> run_order; 789 std::vector<std::string> run_order;
680 PostTestTasks(&run_order, "C1 T1"); 790 PostTestTasks(&run_order, "C1 T1");
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 899 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
790 scheduler_->DidHandleInputEventOnMainThread( 900 scheduler_->DidHandleInputEventOnMainThread(
791 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); 901 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin));
792 RunUntilIdle(); 902 RunUntilIdle();
793 903
794 EXPECT_THAT(run_order, 904 EXPECT_THAT(run_order,
795 testing::ElementsAre(std::string("L1"), std::string("T1"), 905 testing::ElementsAre(std::string("L1"), std::string("T1"),
796 std::string("T2"))); 906 std::string("T2")));
797 } 907 }
798 908
799 TEST_F(RendererSchedulerImplTest, LoadingPriorityPolicy) { 909 // TODO(alexclarke): Reenable once we've reinstaed the Loading UseCase.
910 TEST_F(RendererSchedulerImplTest, DISABLED_LoadingUseCase) {
800 std::vector<std::string> run_order; 911 std::vector<std::string> run_order;
801 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 912 PostTestTasks(&run_order, "I1 D1 C1 T1 L1 D2 C2 T2 L2");
802 913
803 scheduler_->OnPageLoadStarted(); 914 scheduler_->OnPageLoadStarted();
804 EnableIdleTasks(); 915 EnableIdleTasks();
805 RunUntilIdle(); 916 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 917
812 // Advance 1.5s and try again, the loading policy should have ended and the 918 // In loading policy, loading tasks are prioritized other others.
813 // task order should return to normal. 919 std::string loading_policy_expected[] = {
814 clock_->Advance(base::TimeDelta::FromMilliseconds(1500)); 920 std::string("D1"), std::string("L1"), std::string("D2"),
921 std::string("L2"), std::string("C1"), std::string("T1"),
922 std::string("C2"), std::string("T2"), std::string("I1")};
923 EXPECT_THAT(run_order, testing::ElementsAreArray(loading_policy_expected));
924 EXPECT_EQ(RendererScheduler::UseCase::LOADING, CurrentUseCase());
925
926 // Advance 15s and try again, the loading policy should have ended and the
927 // task order should return to the NONE use case where loading tasks are no
928 // longer prioritized.
929 clock_->Advance(base::TimeDelta::FromMilliseconds(150000));
815 run_order.clear(); 930 run_order.clear();
816 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 931 PostTestTasks(&run_order, "I1 D1 C1 T1 L1 D2 C2 T2 L2");
817 EnableIdleTasks(); 932 EnableIdleTasks();
818 RunUntilIdle(); 933 RunUntilIdle();
819 EXPECT_THAT(run_order, 934
820 testing::ElementsAre(std::string("L1"), std::string("D1"), 935 std::string default_order_expected[] = {
821 std::string("C1"), std::string("D2"), 936 std::string("D1"), std::string("C1"), std::string("T1"),
822 std::string("C2"), std::string("I1"))); 937 std::string("L1"), std::string("D2"), std::string("C2"),
938 std::string("T2"), std::string("L2"), std::string("I1")};
939 EXPECT_THAT(run_order, testing::ElementsAreArray(default_order_expected));
940 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
823 } 941 }
824 942
825 TEST_F(RendererSchedulerImplTest, 943 TEST_F(RendererSchedulerImplTest,
826 EventConsumedOnCompositorThread_IgnoresMouseMove_WhenMouseUp) { 944 EventConsumedOnCompositorThread_IgnoresMouseMove_WhenMouseUp) {
827 std::vector<std::string> run_order; 945 std::vector<std::string> run_order;
828 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 946 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
829 947
948 ForceMainThreadScrollingUseCase();
949 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
830 scheduler_->DidHandleInputEventOnCompositorThread( 950 scheduler_->DidHandleInputEventOnCompositorThread(
831 FakeInputEvent(blink::WebInputEvent::MouseMove), 951 FakeInputEvent(blink::WebInputEvent::MouseMove),
832 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 952 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
833 EnableIdleTasks();
834 RunUntilIdle(); 953 RunUntilIdle();
835 // Note compositor tasks are not prioritized. 954 // Note compositor tasks are not prioritized.
955 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
836 EXPECT_THAT(run_order, 956 EXPECT_THAT(run_order,
837 testing::ElementsAre(std::string("D1"), std::string("C1"), 957 testing::ElementsAre(std::string("D1"), std::string("C1"),
838 std::string("D2"), std::string("C2"), 958 std::string("D2"), std::string("C2"),
839 std::string("I1"))); 959 std::string("I1")));
840 } 960 }
841 961
842 TEST_F(RendererSchedulerImplTest, 962 TEST_F(RendererSchedulerImplTest,
843 EventForwardedToMainThread_IgnoresMouseMove_WhenMouseUp) { 963 EventForwardedToMainThread_IgnoresMouseMove_WhenMouseUp) {
844 std::vector<std::string> run_order; 964 std::vector<std::string> run_order;
845 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 965 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
846 966
967 ForceMainThreadScrollingUseCase();
968 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
847 scheduler_->DidHandleInputEventOnCompositorThread( 969 scheduler_->DidHandleInputEventOnCompositorThread(
848 FakeInputEvent(blink::WebInputEvent::MouseMove), 970 FakeInputEvent(blink::WebInputEvent::MouseMove),
849 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 971 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
850 EnableIdleTasks();
851 RunUntilIdle(); 972 RunUntilIdle();
852 // Note compositor tasks are not prioritized. 973 // Note compositor tasks are not prioritized.
974 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
853 EXPECT_THAT(run_order, 975 EXPECT_THAT(run_order,
854 testing::ElementsAre(std::string("D1"), std::string("C1"), 976 testing::ElementsAre(std::string("D1"), std::string("C1"),
855 std::string("D2"), std::string("C2"), 977 std::string("D2"), std::string("C2"),
856 std::string("I1"))); 978 std::string("I1")));
857 scheduler_->DidHandleInputEventOnMainThread(
858 FakeInputEvent(blink::WebInputEvent::MouseMove));
859 } 979 }
860 980
861 TEST_F(RendererSchedulerImplTest, 981 TEST_F(RendererSchedulerImplTest,
862 EventConsumedOnCompositorThread_MouseMove_WhenMouseDown) { 982 EventConsumedOnCompositorThread_MouseMove_WhenMouseDown) {
863 std::vector<std::string> run_order; 983 std::vector<std::string> run_order;
864 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 984 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
865 985
986 ForceMainThreadScrollingUseCase();
987 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
866 scheduler_->DidHandleInputEventOnCompositorThread( 988 scheduler_->DidHandleInputEventOnCompositorThread(
867 FakeInputEvent(blink::WebInputEvent::MouseMove, 989 FakeInputEvent(blink::WebInputEvent::MouseMove,
868 blink::WebInputEvent::LeftButtonDown), 990 blink::WebInputEvent::LeftButtonDown),
869 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 991 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
870 EnableIdleTasks();
871 RunUntilIdle(); 992 RunUntilIdle();
872 // Note compositor tasks are prioritized. 993 // Note compositor tasks are prioritized.
873 EXPECT_THAT(run_order, 994 EXPECT_THAT(run_order,
874 testing::ElementsAre(std::string("C1"), std::string("C2"), 995 testing::ElementsAre(std::string("C1"), std::string("C2"),
875 std::string("D1"), std::string("D2"), 996 std::string("D1"), std::string("D2"),
876 std::string("I1"))); 997 std::string("I1")));
877 } 998 }
878 999
879 TEST_F(RendererSchedulerImplTest, 1000 TEST_F(RendererSchedulerImplTest,
880 EventForwardedToMainThread_MouseMove_WhenMouseDown) { 1001 EventForwardedToMainThread_MouseMove_WhenMouseDown) {
881 std::vector<std::string> run_order; 1002 std::vector<std::string> run_order;
882 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 1003 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
883 1004
1005 ForceMainThreadScrollingUseCase();
1006 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
884 scheduler_->DidHandleInputEventOnCompositorThread( 1007 scheduler_->DidHandleInputEventOnCompositorThread(
885 FakeInputEvent(blink::WebInputEvent::MouseMove, 1008 FakeInputEvent(blink::WebInputEvent::MouseMove,
886 blink::WebInputEvent::LeftButtonDown), 1009 blink::WebInputEvent::LeftButtonDown),
887 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1010 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
888 EnableIdleTasks();
889 RunUntilIdle(); 1011 RunUntilIdle();
890 // Note compositor tasks are prioritized. 1012 // Note compositor tasks are prioritized.
891 EXPECT_THAT(run_order, 1013 EXPECT_THAT(run_order,
892 testing::ElementsAre(std::string("C1"), std::string("C2"), 1014 testing::ElementsAre(std::string("C1"), std::string("C2"),
893 std::string("D1"), std::string("D2"), 1015 std::string("D1"), std::string("D2"),
894 std::string("I1"))); 1016 std::string("I1")));
895 scheduler_->DidHandleInputEventOnMainThread(FakeInputEvent( 1017 scheduler_->DidHandleInputEventOnMainThread(FakeInputEvent(
896 blink::WebInputEvent::MouseMove, blink::WebInputEvent::LeftButtonDown)); 1018 blink::WebInputEvent::MouseMove, blink::WebInputEvent::LeftButtonDown));
897 } 1019 }
898 1020
899 TEST_F(RendererSchedulerImplTest, EventConsumedOnCompositorThread_MouseWheel) { 1021 TEST_F(RendererSchedulerImplTest, EventConsumedOnCompositorThread_MouseWheel) {
900 std::vector<std::string> run_order; 1022 std::vector<std::string> run_order;
901 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 1023 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
902 1024
1025 ForceMainThreadScrollingUseCase();
1026 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
903 scheduler_->DidHandleInputEventOnCompositorThread( 1027 scheduler_->DidHandleInputEventOnCompositorThread(
904 FakeInputEvent(blink::WebInputEvent::MouseWheel), 1028 FakeInputEvent(blink::WebInputEvent::MouseWheel),
905 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1029 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
906 EnableIdleTasks();
907 RunUntilIdle(); 1030 RunUntilIdle();
908 // Note compositor tasks are prioritized. 1031 // Note compositor tasks are prioritized.
909 EXPECT_THAT(run_order, 1032 EXPECT_THAT(run_order,
910 testing::ElementsAre(std::string("C1"), std::string("C2"), 1033 testing::ElementsAre(std::string("C1"), std::string("C2"),
911 std::string("D1"), std::string("D2"), 1034 std::string("D1"), std::string("D2"),
912 std::string("I1"))); 1035 std::string("I1")));
913 } 1036 }
914 1037
915 TEST_F(RendererSchedulerImplTest, EventForwardedToMainThread_MouseWheel) { 1038 TEST_F(RendererSchedulerImplTest, EventForwardedToMainThread_MouseWheel) {
916 std::vector<std::string> run_order; 1039 std::vector<std::string> run_order;
917 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 1040 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
918 1041
1042 ForceMainThreadScrollingUseCase();
1043 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
919 scheduler_->DidHandleInputEventOnCompositorThread( 1044 scheduler_->DidHandleInputEventOnCompositorThread(
920 FakeInputEvent(blink::WebInputEvent::MouseWheel), 1045 FakeInputEvent(blink::WebInputEvent::MouseWheel),
921 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1046 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
922 EnableIdleTasks();
923 RunUntilIdle(); 1047 RunUntilIdle();
924 // Note compositor tasks are prioritized. 1048 // Note compositor tasks are prioritized.
925 EXPECT_THAT(run_order, 1049 EXPECT_THAT(run_order,
926 testing::ElementsAre(std::string("C1"), std::string("C2"), 1050 testing::ElementsAre(std::string("C1"), std::string("C2"),
927 std::string("D1"), std::string("D2"), 1051 std::string("D1"), std::string("D2"),
928 std::string("I1"))); 1052 std::string("I1")));
929 scheduler_->DidHandleInputEventOnMainThread( 1053 EXPECT_EQ(RendererScheduler::UseCase::MAIN_THREAD_GESTURE, CurrentUseCase());
930 FakeInputEvent(blink::WebInputEvent::MouseWheel));
931 } 1054 }
932 1055
933 TEST_F(RendererSchedulerImplTest, 1056 TEST_F(RendererSchedulerImplTest,
934 EventConsumedOnCompositorThread_IgnoresKeyboardEvents) { 1057 EventConsumedOnCompositorThread_IgnoresKeyboardEvents) {
935 std::vector<std::string> run_order; 1058 std::vector<std::string> run_order;
936 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 1059 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
937 1060
1061 ForceMainThreadScrollingUseCase();
1062 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
938 scheduler_->DidHandleInputEventOnCompositorThread( 1063 scheduler_->DidHandleInputEventOnCompositorThread(
939 FakeInputEvent(blink::WebInputEvent::KeyDown), 1064 FakeInputEvent(blink::WebInputEvent::KeyDown),
940 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1065 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
941 EnableIdleTasks();
942 RunUntilIdle(); 1066 RunUntilIdle();
943 // Note compositor tasks are not prioritized. 1067 // Note compositor tasks are not prioritized.
944 EXPECT_THAT(run_order, 1068 EXPECT_THAT(run_order,
945 testing::ElementsAre(std::string("D1"), std::string("C1"), 1069 testing::ElementsAre(std::string("D1"), std::string("C1"),
946 std::string("D2"), std::string("C2"), 1070 std::string("D2"), std::string("C2"),
947 std::string("I1"))); 1071 std::string("I1")));
1072 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
948 } 1073 }
949 1074
950 TEST_F(RendererSchedulerImplTest, 1075 TEST_F(RendererSchedulerImplTest,
951 EventForwardedToMainThread_IgnoresKeyboardEvents) { 1076 EventForwardedToMainThread_IgnoresKeyboardEvents) {
952 std::vector<std::string> run_order; 1077 std::vector<std::string> run_order;
953 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); 1078 PostTestTasks(&run_order, "I1 D1 C1 D2 C2");
954 1079
1080 ForceMainThreadScrollingUseCase();
1081 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
955 scheduler_->DidHandleInputEventOnCompositorThread( 1082 scheduler_->DidHandleInputEventOnCompositorThread(
956 FakeInputEvent(blink::WebInputEvent::KeyDown), 1083 FakeInputEvent(blink::WebInputEvent::KeyDown),
957 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1084 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
958 EnableIdleTasks();
959 RunUntilIdle(); 1085 RunUntilIdle();
960 // Note compositor tasks are not prioritized. 1086 // Note compositor tasks are not prioritized.
961 EXPECT_THAT(run_order, 1087 EXPECT_THAT(run_order,
962 testing::ElementsAre(std::string("D1"), std::string("C1"), 1088 testing::ElementsAre(std::string("D1"), std::string("C1"),
963 std::string("D2"), std::string("C2"), 1089 std::string("D2"), std::string("C2"),
964 std::string("I1"))); 1090 std::string("I1")));
1091 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
1092 // Note compositor tasks are not prioritized.
965 scheduler_->DidHandleInputEventOnMainThread( 1093 scheduler_->DidHandleInputEventOnMainThread(
966 FakeInputEvent(blink::WebInputEvent::KeyDown)); 1094 FakeInputEvent(blink::WebInputEvent::KeyDown));
967 } 1095 }
968 1096
969 TEST_F(RendererSchedulerImplTest, 1097 TEST_F(RendererSchedulerImplTest,
970 TestCompositorPolicyDoesNotStarveDefaultTasks) { 1098 TestMainthreadScrollingUseCaseDoesNotStarveDefaultTasks) {
1099 ForceMainThreadScrollingUseCase();
1100 scheduler_->DidCommitFrameToCompositor(); // Enable Idle tasks.
1101
971 std::vector<std::string> run_order; 1102 std::vector<std::string> run_order;
972 PostTestTasks(&run_order, "D1 C1"); 1103 PostTestTasks(&run_order, "D1 C1");
973 1104
974 for (int i = 0; i < 20; i++) { 1105 for (int i = 0; i < 20; i++) {
975 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); 1106 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask));
976 } 1107 }
977 PostTestTasks(&run_order, "C2"); 1108 PostTestTasks(&run_order, "C2");
978 1109
979 scheduler_->DidHandleInputEventOnCompositorThread( 1110 scheduler_->DidHandleInputEventOnCompositorThread(
980 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1111 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
981 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1112 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
982 RunUntilIdle(); 1113 RunUntilIdle();
983 // Ensure that the default D1 task gets to run at some point before the final 1114 // Ensure that the default D1 task gets to run at some point before the final
984 // C2 compositor task. 1115 // C2 compositor task.
985 EXPECT_THAT(run_order, 1116 EXPECT_THAT(run_order,
986 testing::ElementsAre(std::string("C1"), std::string("D1"), 1117 testing::ElementsAre(std::string("C1"), std::string("D1"),
987 std::string("C2"))); 1118 std::string("C2")));
988 } 1119 }
989 1120
990 TEST_F(RendererSchedulerImplTest, 1121 TEST_F(RendererSchedulerImplTest,
991 TestCompositorPolicyEnds_CompositorHandlesInput) { 1122 TestCompositorPolicyEnds_CompositorHandlesInput) {
992 std::vector<std::string> run_order;
993 PostTestTasks(&run_order, "D1 C1 D2 C2");
994
995 scheduler_->DidHandleInputEventOnCompositorThread( 1123 scheduler_->DidHandleInputEventOnCompositorThread(
996 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1124 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
997 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1125 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
998 RunUntilIdle(); 1126 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE,
999 EXPECT_THAT(run_order, 1127 ForceUpdatePolicyAndGetCurrentUseCase());
1000 testing::ElementsAre(std::string("C1"), std::string("C2"),
1001 std::string("D1"), std::string("D2")));
1002 1128
1003 run_order.clear();
1004 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); 1129 clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
1005 PostTestTasks(&run_order, "D1 C1 D2 C2"); 1130 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 } 1131 }
1013 1132
1014 TEST_F(RendererSchedulerImplTest, 1133 TEST_F(RendererSchedulerImplTest,
1015 TestCompositorPolicyEnds_MainThreadHandlesInput) { 1134 TestCompositorPolicyEnds_MainThreadHandlesInput) {
1016 std::vector<std::string> run_order;
1017 PostTestTasks(&run_order, "D1 C1 D2 C2");
1018
1019 scheduler_->DidHandleInputEventOnCompositorThread( 1135 scheduler_->DidHandleInputEventOnCompositorThread(
1020 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1136 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
1021 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1137 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
1022 scheduler_->DidHandleInputEventOnMainThread( 1138 scheduler_->DidHandleInputEventOnMainThread(
1023 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 1139 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
1024 RunUntilIdle(); 1140 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE,
1025 EXPECT_THAT(run_order, 1141 ForceUpdatePolicyAndGetCurrentUseCase());
1026 testing::ElementsAre(std::string("C1"), std::string("C2"),
1027 std::string("D1"), std::string("D2")));
1028 1142
1029 run_order.clear();
1030 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); 1143 clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
1031 PostTestTasks(&run_order, "D1 C1 D2 C2"); 1144 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 } 1145 }
1039 1146
1040 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { 1147 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) {
1041 std::vector<std::string> run_order; 1148 std::vector<std::string> run_order;
1042 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); 1149 PostTestTasks(&run_order, "L1 D1 C1 D2 C2");
1043 1150
1044 scheduler_->DidHandleInputEventOnCompositorThread( 1151 scheduler_->DidHandleInputEventOnCompositorThread(
1045 FakeInputEvent(blink::WebInputEvent::TouchStart), 1152 FakeInputEvent(blink::WebInputEvent::TouchStart),
1046 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1153 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
1047 RunUntilIdle(); 1154 RunUntilIdle();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 FakeInputEvent(blink::WebInputEvent::TouchMove), 1198 FakeInputEvent(blink::WebInputEvent::TouchMove),
1092 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1199 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
1093 RunUntilIdle(); 1200 RunUntilIdle();
1094 EXPECT_THAT(run_order, testing::ElementsAre(std::string("L1"))); 1201 EXPECT_THAT(run_order, testing::ElementsAre(std::string("L1")));
1095 } 1202 }
1096 1203
1097 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) { 1204 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) {
1098 bool is_anticipated_before = false; 1205 bool is_anticipated_before = false;
1099 bool is_anticipated_after = false; 1206 bool is_anticipated_after = false;
1100 1207
1101 bool simulate_input = false;
1102 default_task_runner_->PostTask( 1208 default_task_runner_->PostTask(
1103 FROM_HERE, 1209 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1104 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 1210 SimulateInputType::None, &is_anticipated_before,
1105 &is_anticipated_before, &is_anticipated_after)); 1211 &is_anticipated_after));
1106 RunUntilIdle(); 1212 RunUntilIdle();
1107 // In its default state, without input receipt, the scheduler should indicate 1213 // In its default state, without input receipt, the scheduler should indicate
1108 // that no high-priority is anticipated. 1214 // that no high-priority is anticipated.
1109 EXPECT_FALSE(is_anticipated_before); 1215 EXPECT_FALSE(is_anticipated_before);
1110 EXPECT_FALSE(is_anticipated_after); 1216 EXPECT_FALSE(is_anticipated_after);
1111 1217
1112 simulate_input = true; 1218 default_task_runner_->PostTask(
1219 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1220 SimulateInputType::TouchStart,
1221 &is_anticipated_before, &is_anticipated_after));
1222 bool dummy;
1223 default_task_runner_->PostTask(
1224 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1225 SimulateInputType::TouchEnd, &dummy, &dummy));
1113 default_task_runner_->PostTask( 1226 default_task_runner_->PostTask(
1114 FROM_HERE, 1227 FROM_HERE,
1115 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 1228 base::Bind(&AnticipationTestTask, scheduler_.get(),
1116 &is_anticipated_before, &is_anticipated_after)); 1229 SimulateInputType::GestureScrollBegin, &dummy, &dummy));
1230 default_task_runner_->PostTask(
1231 FROM_HERE,
1232 base::Bind(&AnticipationTestTask, scheduler_.get(),
1233 SimulateInputType::GestureScrollEnd, &dummy, &dummy));
1234
1117 RunUntilIdle(); 1235 RunUntilIdle();
1118 // When input is received, the scheduler should indicate that high-priority 1236 // When input is received, the scheduler should indicate that high-priority
1119 // work is anticipated. 1237 // work is anticipated.
1120 EXPECT_FALSE(is_anticipated_before); 1238 EXPECT_FALSE(is_anticipated_before);
1121 EXPECT_TRUE(is_anticipated_after); 1239 EXPECT_TRUE(is_anticipated_after);
1122 1240
1123 clock_->Advance(priority_escalation_after_input_duration() * 2); 1241 clock_->Advance(priority_escalation_after_input_duration() * 2);
1124 simulate_input = false;
1125 default_task_runner_->PostTask( 1242 default_task_runner_->PostTask(
1126 FROM_HERE, 1243 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1127 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 1244 SimulateInputType::None, &is_anticipated_before,
1128 &is_anticipated_before, &is_anticipated_after)); 1245 &is_anticipated_after));
1129 RunUntilIdle(); 1246 RunUntilIdle();
1130 // Without additional input, the scheduler should indicate that high-priority 1247 // Without additional input, the scheduler should go into NONE
1131 // work is no longer anticipated. 1248 // use case but with scrolling expected where high-priority work is still
1249 // anticipated.
1250 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1251 EXPECT_TRUE(TouchStartExpectedSoon());
1252 EXPECT_TRUE(is_anticipated_before);
1253 EXPECT_TRUE(is_anticipated_after);
1254
1255 clock_->Advance(subsequent_input_expected_after_input_duration() * 2);
1256 default_task_runner_->PostTask(
1257 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(),
1258 SimulateInputType::None, &is_anticipated_before,
1259 &is_anticipated_after));
1260 RunUntilIdle();
1261 // Eventually the scheduler should go into the default use case where
1262 // high-priority work is no longer anticipated.
1263 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1264 EXPECT_FALSE(TouchStartExpectedSoon());
1132 EXPECT_FALSE(is_anticipated_before); 1265 EXPECT_FALSE(is_anticipated_before);
1133 EXPECT_FALSE(is_anticipated_after); 1266 EXPECT_FALSE(is_anticipated_after);
1134 } 1267 }
1135 1268
1136 TEST_F(RendererSchedulerImplTest, TestShouldYield) { 1269 TEST_F(RendererSchedulerImplTest, TestShouldYield) {
1137 bool should_yield_before = false; 1270 bool should_yield_before = false;
1138 bool should_yield_after = false; 1271 bool should_yield_after = false;
1139 1272
1273 ForceMainThreadScrollingUseCase();
1274
1140 default_task_runner_->PostTask( 1275 default_task_runner_->PostTask(
1141 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 1276 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
1142 default_task_runner_, false, &should_yield_before, 1277 default_task_runner_, false, &should_yield_before,
1143 &should_yield_after)); 1278 &should_yield_after));
1144 RunUntilIdle(); 1279 RunUntilIdle();
1145 // Posting to default runner shouldn't cause yielding. 1280 // Posting to default runner shouldn't cause yielding.
1146 EXPECT_FALSE(should_yield_before); 1281 EXPECT_FALSE(should_yield_before);
1147 EXPECT_FALSE(should_yield_after); 1282 EXPECT_FALSE(should_yield_after);
1148 1283
1149 default_task_runner_->PostTask( 1284 default_task_runner_->PostTask(
1150 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 1285 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
1151 compositor_task_runner_, false, 1286 compositor_task_runner_, false,
1152 &should_yield_before, &should_yield_after)); 1287 &should_yield_before, &should_yield_after));
1153 RunUntilIdle(); 1288 RunUntilIdle();
1154 // Posting while not in compositor priority shouldn't cause yielding. 1289 // Posting while not mainthread scrolling shouldn't cause yielding.
1155 EXPECT_FALSE(should_yield_before); 1290 EXPECT_FALSE(should_yield_before);
1156 EXPECT_FALSE(should_yield_after); 1291 EXPECT_FALSE(should_yield_after);
1157 1292
1158 default_task_runner_->PostTask( 1293 default_task_runner_->PostTask(
1159 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), 1294 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(),
1160 compositor_task_runner_, true, &should_yield_before, 1295 compositor_task_runner_, true, &should_yield_before,
1161 &should_yield_after)); 1296 &should_yield_after));
1162 RunUntilIdle(); 1297 RunUntilIdle();
1163 // We should be able to switch to compositor priority mid-task. 1298 // We should be able to switch to compositor priority mid-task.
1164 EXPECT_FALSE(should_yield_before); 1299 EXPECT_FALSE(should_yield_before);
1165 EXPECT_TRUE(should_yield_after); 1300 EXPECT_TRUE(should_yield_after);
1301 }
1166 1302
1303 TEST_F(RendererSchedulerImplTest, TestShouldYield_TouchStart) {
1167 // Receiving a touchstart should immediately trigger yielding, even if 1304 // Receiving a touchstart should immediately trigger yielding, even if
1168 // there's no immediately pending work in the compositor queue. 1305 // there's no immediately pending work in the compositor queue.
1169 EXPECT_FALSE(scheduler_->ShouldYieldForHighPriorityWork()); 1306 EXPECT_FALSE(scheduler_->ShouldYieldForHighPriorityWork());
1170 scheduler_->DidHandleInputEventOnCompositorThread( 1307 scheduler_->DidHandleInputEventOnCompositorThread(
1171 FakeInputEvent(blink::WebInputEvent::TouchStart), 1308 FakeInputEvent(blink::WebInputEvent::TouchStart),
1172 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); 1309 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR);
1173 EXPECT_TRUE(scheduler_->ShouldYieldForHighPriorityWork()); 1310 EXPECT_TRUE(scheduler_->ShouldYieldForHighPriorityWork());
1174 RunUntilIdle(); 1311 RunUntilIdle();
1175 } 1312 }
1176 1313
1177 TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) { 1314 TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) {
1178 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 1315 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1179 1316
1180 // An input event should bump us into input priority. 1317 // An input event should bump us into input priority.
1181 scheduler_->DidHandleInputEventOnCompositorThread( 1318 scheduler_->DidHandleInputEventOnCompositorThread(
1182 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), 1319 FakeInputEvent(blink::WebInputEvent::GestureFlingStart),
1183 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1320 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
1184 RunUntilIdle(); 1321 RunUntilIdle();
1185 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 1322 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
1186 1323
1187 // Simulate the input event being queued for a very long time. The compositor 1324 // Simulate the input event being queued for a very long time. The compositor
1188 // task we post here represents the enqueued input task. 1325 // task we post here represents the enqueued input task.
1189 clock_->Advance(priority_escalation_after_input_duration() * 2); 1326 clock_->Advance(priority_escalation_after_input_duration() * 2);
1190 scheduler_->DidHandleInputEventOnMainThread( 1327 scheduler_->DidHandleInputEventOnMainThread(
1191 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 1328 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
1192 RunUntilIdle(); 1329 RunUntilIdle();
1193 1330
1194 // Even though we exceeded the input priority escalation period, we should 1331 // Even though we exceeded the input priority escalation period, we should
1195 // still be in compositor priority since the input remains queued. 1332 // still be in compositor priority since the input remains queued.
1196 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 1333 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, CurrentUseCase());
1197 1334
1198 // After the escalation period ends we should go back into normal mode. 1335 // After the escalation period ends we should go back into normal mode.
1199 clock_->Advance(priority_escalation_after_input_duration() * 2); 1336 clock_->Advance(priority_escalation_after_input_duration() * 2);
1200 RunUntilIdle(); 1337 RunUntilIdle();
1201 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 1338 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1202 } 1339 }
1203 1340
1204 class RendererSchedulerImplWithMockSchedulerTest 1341 class RendererSchedulerImplWithMockSchedulerTest
1205 : public RendererSchedulerImplTest { 1342 : public RendererSchedulerImplTest {
1206 public: 1343 public:
1207 void SetUp() override { 1344 void SetUp() override {
1208 mock_task_runner_ = make_scoped_refptr( 1345 mock_task_runner_ = make_scoped_refptr(
1209 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); 1346 new cc::OrderedSimpleTaskRunner(clock_.get(), false));
1210 main_task_runner_ = 1347 main_task_runner_ =
1211 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); 1348 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 } 1506 }
1370 1507
1371 TEST_F(RendererSchedulerImplWithMockSchedulerTest, 1508 TEST_F(RendererSchedulerImplWithMockSchedulerTest,
1372 EnsureUpdatePolicyNotTriggeredTooOften) { 1509 EnsureUpdatePolicyNotTriggeredTooOften) {
1373 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); 1510 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
1374 1511
1375 scheduler_->DidHandleInputEventOnCompositorThread( 1512 scheduler_->DidHandleInputEventOnCompositorThread(
1376 FakeInputEvent(blink::WebInputEvent::TouchStart), 1513 FakeInputEvent(blink::WebInputEvent::TouchStart),
1377 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1514 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
1378 scheduler_->DidHandleInputEventOnCompositorThread( 1515 scheduler_->DidHandleInputEventOnCompositorThread(
1379 FakeInputEvent(blink::WebInputEvent::TouchMove), 1516 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin),
1380 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); 1517 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD);
1381 1518
1382 // We expect the first call to IsHighPriorityWorkAnticipated to be called 1519 // We expect the first call to IsHighPriorityWorkAnticipated to be called
1383 // after recieving an input event (but before the UpdateTask was processed) to 1520 // after recieving an input event (but before the UpdateTask was processed) to
1384 // call UpdatePolicy. 1521 // call UpdatePolicy.
1385 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); 1522 EXPECT_EQ(0, mock_scheduler_->update_policy_count_);
1386 scheduler_->IsHighPriorityWorkAnticipated(); 1523 scheduler_->IsHighPriorityWorkAnticipated();
1387 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); 1524 EXPECT_EQ(1, mock_scheduler_->update_policy_count_);
1388 // Subsequent calls should not call UpdatePolicy. 1525 // Subsequent calls should not call UpdatePolicy.
1389 scheduler_->IsHighPriorityWorkAnticipated(); 1526 scheduler_->IsHighPriorityWorkAnticipated();
1390 scheduler_->IsHighPriorityWorkAnticipated(); 1527 scheduler_->IsHighPriorityWorkAnticipated();
1391 scheduler_->IsHighPriorityWorkAnticipated(); 1528 scheduler_->IsHighPriorityWorkAnticipated();
1392 scheduler_->ShouldYieldForHighPriorityWork(); 1529 scheduler_->ShouldYieldForHighPriorityWork();
1393 scheduler_->ShouldYieldForHighPriorityWork(); 1530 scheduler_->ShouldYieldForHighPriorityWork();
1394 scheduler_->ShouldYieldForHighPriorityWork(); 1531 scheduler_->ShouldYieldForHighPriorityWork();
1395 scheduler_->ShouldYieldForHighPriorityWork(); 1532 scheduler_->ShouldYieldForHighPriorityWork();
1396 1533
1397 scheduler_->DidHandleInputEventOnMainThread( 1534 scheduler_->DidHandleInputEventOnMainThread(
1398 FakeInputEvent(blink::WebInputEvent::TouchStart)); 1535 FakeInputEvent(blink::WebInputEvent::TouchStart));
1399 scheduler_->DidHandleInputEventOnMainThread( 1536 scheduler_->DidHandleInputEventOnMainThread(
1400 FakeInputEvent(blink::WebInputEvent::TouchMove)); 1537 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin));
1401 1538
1402 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); 1539 EXPECT_EQ(1, mock_scheduler_->update_policy_count_);
1403 1540
1541 // We expect both the urgent and the delayed updates to run in addition to the
1542 // earlier updated cause by IsHighPriorityWorkAnticipated, a final update
1543 // transitions from 'not_scrolling scroll expected' to 'not_scrolling'.
1404 RunUntilIdle(); 1544 RunUntilIdle();
1405 // We expect both the urgent and the delayed updates to run in addition to the 1545 EXPECT_THAT(mock_scheduler_->use_cases_,
1406 // earlier updated cause by IsHighPriorityWorkAnticipated. 1546 testing::ElementsAre(std::string("compositor_gesture"),
1407 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); 1547 std::string("compositor_gesture"),
1548 std::string("none scroll expected"),
1549 std::string("none")));
1408 } 1550 }
1409 1551
1410 class RendererSchedulerImplWithMessageLoopTest 1552 class RendererSchedulerImplWithMessageLoopTest
1411 : public RendererSchedulerImplTest { 1553 : public RendererSchedulerImplTest {
1412 public: 1554 public:
1413 RendererSchedulerImplWithMessageLoopTest() 1555 RendererSchedulerImplWithMessageLoopTest()
1414 : RendererSchedulerImplTest(new base::MessageLoop()) {} 1556 : RendererSchedulerImplTest(new base::MessageLoop()) {}
1415 ~RendererSchedulerImplWithMessageLoopTest() override {} 1557 ~RendererSchedulerImplWithMessageLoopTest() override {}
1416 1558
1417 void PostFromNestedRunloop(std::vector< 1559 void PostFromNestedRunloop(std::vector<
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 scheduler_->ResumeTimerQueue(); 1894 scheduler_->ResumeTimerQueue();
1753 RunUntilIdle(); 1895 RunUntilIdle();
1754 EXPECT_TRUE(run_order.empty()); 1896 EXPECT_TRUE(run_order.empty());
1755 1897
1756 scheduler_->ResumeTimerQueue(); 1898 scheduler_->ResumeTimerQueue();
1757 RunUntilIdle(); 1899 RunUntilIdle();
1758 EXPECT_THAT(run_order, 1900 EXPECT_THAT(run_order,
1759 testing::ElementsAre(std::string("T1"), std::string("T2"))); 1901 testing::ElementsAre(std::string("T1"), std::string("T2")));
1760 } 1902 }
1761 1903
1762 TEST_F(RendererSchedulerImplTest, PolicyToString) { 1904 TEST_F(RendererSchedulerImplTest, UseCaseToString) {
1763 CheckAllPolicyToString(); 1905 CheckAllUseCaseToString();
1764 } 1906 }
1765 1907
1766 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) { 1908 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) {
1767 // This should not DCHECK because there was no corresponding compositor side 1909 // This should not DCHECK because there was no corresponding compositor side
1768 // call to DidHandleInputEventOnCompositorThread with 1910 // call to DidHandleInputEventOnCompositorThread with
1769 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the 1911 // 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. 1912 // compositor to not be there and we don't want to make debugging impossible.
1771 scheduler_->DidHandleInputEventOnMainThread( 1913 scheduler_->DidHandleInputEventOnMainThread(
1772 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 1914 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
1773 } 1915 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 RunUntilIdle(); 1969 RunUntilIdle();
1828 EXPECT_THAT(run_order, 1970 EXPECT_THAT(run_order,
1829 testing::ElementsAre(std::string("T4"), std::string("T5"))); 1971 testing::ElementsAre(std::string("T4"), std::string("T5")));
1830 1972
1831 // Subsequent timer tasks should fire as usual. 1973 // Subsequent timer tasks should fire as usual.
1832 run_order.clear(); 1974 run_order.clear();
1833 PostTestTasks(&run_order, "T6"); 1975 PostTestTasks(&run_order, "T6");
1834 RunUntilIdle(); 1976 RunUntilIdle();
1835 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6"))); 1977 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6")));
1836 } 1978 }
1979
1980 TEST_F(RendererSchedulerImplTest,
1981 ExpensiveLoadingTasksNotBlockedTillFirstBeginMainFrame) {
1982 std::vector<std::string> run_order;
1983
1984 // RunUntilIdle won't actually run all of the SimpleTestTickClock::Advance
1985 // tasks unless we set AutoAdvanceNow to true :/
1986 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
1987
1988 // Simulate a bunch of expensive loading tasks
1989 for (int i = 0; i < 10; i++) {
1990 loading_task_runner_->PostTask(
1991 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance,
1992 base::Unretained(clock_.get()),
1993 base::TimeDelta::FromMilliseconds(500)));
1994 }
1995
1996 RunUntilIdle();
1997
1998 PostTestTasks(&run_order, "L1 D1");
1999 RunUntilIdle();
2000
2001 EXPECT_EQ(UseCase::NONE, ForceUpdatePolicyAndGetCurrentUseCase());
2002 EXPECT_FALSE(HaveSeenABeginMainframe());
2003 EXPECT_TRUE(LoadingTasksSeemExpensive());
2004 EXPECT_FALSE(TimerTasksSeemExpensive());
2005 EXPECT_THAT(run_order,
2006 testing::ElementsAre(std::string("L1"), std::string("D1")));
2007
2008 // Emit a BeginMainFrame, and the loading task should get blocked.
2009 DoMainFrame();
2010 run_order.clear();
2011
2012 PostTestTasks(&run_order, "L1 D1");
2013 RunUntilIdle();
2014
2015 EXPECT_EQ(RendererScheduler::UseCase::NONE, CurrentUseCase());
2016 EXPECT_TRUE(HaveSeenABeginMainframe());
2017 EXPECT_TRUE(LoadingTasksSeemExpensive());
2018 EXPECT_FALSE(TimerTasksSeemExpensive());
2019 EXPECT_THAT(run_order,
2020 testing::ElementsAre(std::string("L1"), std::string("D1")));
2021 }
2022
1837 } // namespace scheduler 2023 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/renderer_scheduler_impl.cc ('k') | components/scheduler/renderer/task_cost_estimator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698