| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "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 Loading... |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 scheduler_->WillBeginFrame(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)); |
| 255 scheduler_->DidCommitFrameToCompositor(); | 275 scheduler_->DidCommitFrameToCompositor(); |
| 256 } | 276 } |
| 257 | 277 |
| 278 void ForceMainthreadScrollingUseCase() { |
| 279 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create( |
| 280 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
| 281 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); |
| 282 begin_frame_args.on_critical_path = true; |
| 283 scheduler_->WillBeginFrame(begin_frame_args); |
| 284 } |
| 285 |
| 258 void EnableIdleTasks() { DoMainFrame(); } | 286 void EnableIdleTasks() { DoMainFrame(); } |
| 259 | 287 |
| 260 Policy CurrentPolicy() { | 288 UseCase CurrentUseCase() { |
| 261 return scheduler_->MainThreadOnly().current_policy_; | 289 return scheduler_->MainThreadOnly().current_use_case; |
| 290 } |
| 291 |
| 292 UseCase ForceUpdatePolicyAndGetCurrentUseCase() { |
| 293 scheduler_->ForceUpdatePolicy(); |
| 294 return scheduler_->MainThreadOnly().current_use_case; |
| 295 } |
| 296 |
| 297 bool TouchStartExpectedSoon() { |
| 298 return scheduler_->MainThreadOnly().touchstart_expected_soon; |
| 262 } | 299 } |
| 263 | 300 |
| 264 // Helper for posting several tasks of specific types. |task_descriptor| is a | 301 // Helper for posting several tasks of specific types. |task_descriptor| is a |
| 265 // string with space delimited task identifiers. The first letter of each | 302 // string with space delimited task identifiers. The first letter of each |
| 266 // task identifier specifies the task type: | 303 // task identifier specifies the task type: |
| 267 // - 'D': Default task | 304 // - 'D': Default task |
| 268 // - 'C': Compositor task | 305 // - 'C': Compositor task |
| 269 // - 'L': Loading task | 306 // - 'L': Loading task |
| 270 // - 'I': Idle task | 307 // - 'I': Idle task |
| 271 // - 'T': Timer task | 308 // - 'T': Timer task |
| (...skipping 27 matching lines...) Expand all Loading... |
| 299 break; | 336 break; |
| 300 default: | 337 default: |
| 301 NOTREACHED(); | 338 NOTREACHED(); |
| 302 } | 339 } |
| 303 } | 340 } |
| 304 } | 341 } |
| 305 | 342 |
| 306 protected: | 343 protected: |
| 307 static base::TimeDelta priority_escalation_after_input_duration() { | 344 static base::TimeDelta priority_escalation_after_input_duration() { |
| 308 return base::TimeDelta::FromMilliseconds( | 345 return base::TimeDelta::FromMilliseconds( |
| 309 RendererSchedulerImpl::kPriorityEscalationAfterInputMillis); | 346 UserModel::kGestureEstimationLimitMillis); |
| 347 } |
| 348 |
| 349 static base::TimeDelta subsequent_input_expected_after_input_duration() { |
| 350 return base::TimeDelta::FromMilliseconds( |
| 351 UserModel::kExpectSubsequentGestureMillis); |
| 310 } | 352 } |
| 311 | 353 |
| 312 static base::TimeDelta maximum_idle_period_duration() { | 354 static base::TimeDelta maximum_idle_period_duration() { |
| 313 return base::TimeDelta::FromMilliseconds( | 355 return base::TimeDelta::FromMilliseconds( |
| 314 IdleHelper::kMaximumIdlePeriodMillis); | 356 IdleHelper::kMaximumIdlePeriodMillis); |
| 315 } | 357 } |
| 316 | 358 |
| 317 static base::TimeDelta end_idle_when_hidden_delay() { | 359 static base::TimeDelta end_idle_when_hidden_delay() { |
| 318 return base::TimeDelta::FromMilliseconds( | 360 return base::TimeDelta::FromMilliseconds( |
| 319 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis); | 361 RendererSchedulerImpl::kEndIdleWhenHiddenDelayMillis); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 332 template <typename E> | 374 template <typename E> |
| 333 static void CallForEachEnumValue(E first, | 375 static void CallForEachEnumValue(E first, |
| 334 E last, | 376 E last, |
| 335 const char* (*function)(E)) { | 377 const char* (*function)(E)) { |
| 336 for (E val = first; val < last; | 378 for (E val = first; val < last; |
| 337 val = static_cast<E>(static_cast<int>(val) + 1)) { | 379 val = static_cast<E>(static_cast<int>(val) + 1)) { |
| 338 (*function)(val); | 380 (*function)(val); |
| 339 } | 381 } |
| 340 } | 382 } |
| 341 | 383 |
| 342 static void CheckAllPolicyToString() { | 384 static void CheckAllUseCaseToString() { |
| 343 CallForEachEnumValue<RendererSchedulerImpl::Policy>( | 385 CallForEachEnumValue<RendererSchedulerImpl::UseCase>( |
| 344 RendererSchedulerImpl::Policy::FIRST_POLICY, | 386 RendererSchedulerImpl::UseCase::FIRST_USE_CASE, |
| 345 RendererSchedulerImpl::Policy::POLICY_COUNT, | 387 RendererSchedulerImpl::UseCase::USE_CASE_COUNT, |
| 346 &RendererSchedulerImpl::PolicyToString); | 388 &RendererSchedulerImpl::UseCaseToString); |
| 347 } | 389 } |
| 348 | 390 |
| 349 scoped_ptr<base::SimpleTestTickClock> clock_; | 391 scoped_ptr<base::SimpleTestTickClock> clock_; |
| 350 // Only one of mock_task_runner_ or message_loop_ will be set. | 392 // Only one of mock_task_runner_ or message_loop_ will be set. |
| 351 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 393 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
| 352 scoped_ptr<base::MessageLoop> message_loop_; | 394 scoped_ptr<base::MessageLoop> message_loop_; |
| 353 | 395 |
| 354 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; | 396 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; |
| 355 scoped_ptr<RendererSchedulerImplForTest> scheduler_; | 397 scoped_ptr<RendererSchedulerImplForTest> scheduler_; |
| 356 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 398 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance, | 677 FROM_HERE, base::Bind(&base::SimpleTestTickClock::Advance, |
| 636 base::Unretained(clock_.get()), | 678 base::Unretained(clock_.get()), |
| 637 base::TimeDelta::FromMilliseconds(500))); | 679 base::TimeDelta::FromMilliseconds(500))); |
| 638 } | 680 } |
| 639 RunUntilIdle(); | 681 RunUntilIdle(); |
| 640 | 682 |
| 641 // Timers should now be disabled during main thread user userinteractions. | 683 // Timers should now be disabled during main thread user userinteractions. |
| 642 PostTestTasks(&run_order, "C1 T1"); | 684 PostTestTasks(&run_order, "C1 T1"); |
| 643 | 685 |
| 644 scheduler_->DidAnimateForInputOnCompositorThread(); | 686 scheduler_->DidAnimateForInputOnCompositorThread(); |
| 645 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 687 cc::BeginFrameArgs begin_frame_args1 = cc::BeginFrameArgs::Create( |
| 646 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), | 688 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
| 647 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); | 689 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); |
| 690 begin_frame_args1.on_critical_path = true; |
| 691 scheduler_->WillBeginFrame(begin_frame_args1); |
| 692 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period |
| 648 RunUntilIdle(); | 693 RunUntilIdle(); |
| 649 | 694 |
| 650 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1"))); | 695 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1"))); |
| 651 clock_->Advance(priority_escalation_after_input_duration() * 2); | 696 clock_->Advance(priority_escalation_after_input_duration() * 2); |
| 652 | 697 |
| 653 run_order.clear(); | 698 run_order.clear(); |
| 654 RunUntilIdle(); | 699 RunUntilIdle(); |
| 655 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T1"))); | 700 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T1"))); |
| 656 } | 701 } |
| 657 | 702 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); | 836 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); |
| 792 RunUntilIdle(); | 837 RunUntilIdle(); |
| 793 | 838 |
| 794 EXPECT_THAT(run_order, | 839 EXPECT_THAT(run_order, |
| 795 testing::ElementsAre(std::string("L1"), std::string("T1"), | 840 testing::ElementsAre(std::string("L1"), std::string("T1"), |
| 796 std::string("T2"))); | 841 std::string("T2"))); |
| 797 } | 842 } |
| 798 | 843 |
| 799 TEST_F(RendererSchedulerImplTest, LoadingPriorityPolicy) { | 844 TEST_F(RendererSchedulerImplTest, LoadingPriorityPolicy) { |
| 800 std::vector<std::string> run_order; | 845 std::vector<std::string> run_order; |
| 801 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | 846 PostTestTasks(&run_order, "I1 D1 C1 T1 L1 D2 C2 T2 L2"); |
| 802 | 847 |
| 803 scheduler_->OnPageLoadStarted(); | 848 scheduler_->OnPageLoadStarted(); |
| 804 EnableIdleTasks(); | 849 EnableIdleTasks(); |
| 805 RunUntilIdle(); | 850 RunUntilIdle(); |
| 806 // In loading policy compositor tasks are best effort and should be run last. | 851 |
| 807 EXPECT_THAT(run_order, | 852 // In loading policy, loading tasks are prioritized other others. |
| 808 testing::ElementsAre(std::string("L1"), std::string("D1"), | 853 std::string loading_policy_expected[] = { |
| 809 std::string("D2"), std::string("I1"), | 854 std::string("L1"), std::string("L2"), std::string("D1"), |
| 810 std::string("C1"), std::string("C2"))); | 855 std::string("C1"), std::string("T1"), std::string("D2"), |
| 856 std::string("C2"), std::string("T2"), std::string("I1")}; |
| 857 EXPECT_THAT(run_order, testing::ElementsAreArray(loading_policy_expected)); |
| 811 | 858 |
| 812 // Advance 1.5s and try again, the loading policy should have ended and the | 859 // Advance 1.5s and try again, the loading policy should have ended and the |
| 813 // task order should return to normal. | 860 // task order should return to the NONE use case where loading tasks |
| 861 // are prioritized. |
| 814 clock_->Advance(base::TimeDelta::FromMilliseconds(1500)); | 862 clock_->Advance(base::TimeDelta::FromMilliseconds(1500)); |
| 815 run_order.clear(); | 863 run_order.clear(); |
| 816 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | 864 PostTestTasks(&run_order, "I1 D1 C1 T1 L1 D2 C2 T2 L2"); |
| 817 EnableIdleTasks(); | 865 EnableIdleTasks(); |
| 818 RunUntilIdle(); | 866 RunUntilIdle(); |
| 819 EXPECT_THAT(run_order, | 867 std::string default_order_expected[] = { |
| 820 testing::ElementsAre(std::string("L1"), std::string("D1"), | 868 std::string("L1"), std::string("L2"), std::string("D1"), |
| 821 std::string("C1"), std::string("D2"), | 869 std::string("C1"), std::string("T1"), std::string("D2"), |
| 822 std::string("C2"), std::string("I1"))); | 870 std::string("C2"), std::string("T2"), std::string("I1")}; |
| 871 EXPECT_THAT(run_order, testing::ElementsAreArray(default_order_expected)); |
| 823 } | 872 } |
| 824 | 873 |
| 825 TEST_F(RendererSchedulerImplTest, | 874 TEST_F(RendererSchedulerImplTest, |
| 826 EventConsumedOnCompositorThread_IgnoresMouseMove_WhenMouseUp) { | 875 EventConsumedOnCompositorThread_IgnoresMouseMove_WhenMouseUp) { |
| 827 std::vector<std::string> run_order; | 876 std::vector<std::string> run_order; |
| 828 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); | 877 PostTestTasks(&run_order, "I1 D1 C1 D2 C2"); |
| 829 | 878 |
| 830 scheduler_->DidHandleInputEventOnCompositorThread( | 879 scheduler_->DidHandleInputEventOnCompositorThread( |
| 831 FakeInputEvent(blink::WebInputEvent::MouseMove), | 880 FakeInputEvent(blink::WebInputEvent::MouseMove), |
| 832 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 881 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 // Note compositor tasks are not prioritized. | 1009 // Note compositor tasks are not prioritized. |
| 961 EXPECT_THAT(run_order, | 1010 EXPECT_THAT(run_order, |
| 962 testing::ElementsAre(std::string("D1"), std::string("C1"), | 1011 testing::ElementsAre(std::string("D1"), std::string("C1"), |
| 963 std::string("D2"), std::string("C2"), | 1012 std::string("D2"), std::string("C2"), |
| 964 std::string("I1"))); | 1013 std::string("I1"))); |
| 965 scheduler_->DidHandleInputEventOnMainThread( | 1014 scheduler_->DidHandleInputEventOnMainThread( |
| 966 FakeInputEvent(blink::WebInputEvent::KeyDown)); | 1015 FakeInputEvent(blink::WebInputEvent::KeyDown)); |
| 967 } | 1016 } |
| 968 | 1017 |
| 969 TEST_F(RendererSchedulerImplTest, | 1018 TEST_F(RendererSchedulerImplTest, |
| 970 TestCompositorPolicyDoesNotStarveDefaultTasks) { | 1019 TestMainthreadScrollingUseCaseDoesNotStarveDefaultTasks) { |
| 1020 ForceMainthreadScrollingUseCase(); |
| 1021 |
| 971 std::vector<std::string> run_order; | 1022 std::vector<std::string> run_order; |
| 972 PostTestTasks(&run_order, "D1 C1"); | 1023 PostTestTasks(&run_order, "D1 C1"); |
| 973 | 1024 |
| 974 for (int i = 0; i < 20; i++) { | 1025 for (int i = 0; i < 20; i++) { |
| 975 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); | 1026 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); |
| 976 } | 1027 } |
| 977 PostTestTasks(&run_order, "C2"); | 1028 PostTestTasks(&run_order, "C2"); |
| 978 | 1029 |
| 979 scheduler_->DidHandleInputEventOnCompositorThread( | 1030 scheduler_->DidHandleInputEventOnCompositorThread( |
| 980 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 1031 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
| 981 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1032 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 982 RunUntilIdle(); | 1033 RunUntilIdle(); |
| 983 // Ensure that the default D1 task gets to run at some point before the final | 1034 // Ensure that the default D1 task gets to run at some point before the final |
| 984 // C2 compositor task. | 1035 // C2 compositor task. |
| 985 EXPECT_THAT(run_order, | 1036 EXPECT_THAT(run_order, |
| 986 testing::ElementsAre(std::string("C1"), std::string("D1"), | 1037 testing::ElementsAre(std::string("C1"), std::string("D1"), |
| 987 std::string("C2"))); | 1038 std::string("C2"))); |
| 988 } | 1039 } |
| 989 | 1040 |
| 990 TEST_F(RendererSchedulerImplTest, | 1041 TEST_F(RendererSchedulerImplTest, |
| 991 TestCompositorPolicyEnds_CompositorHandlesInput) { | 1042 TestCompositorPolicyEnds_CompositorHandlesInput) { |
| 992 std::vector<std::string> run_order; | |
| 993 PostTestTasks(&run_order, "D1 C1 D2 C2"); | |
| 994 | |
| 995 scheduler_->DidHandleInputEventOnCompositorThread( | 1043 scheduler_->DidHandleInputEventOnCompositorThread( |
| 996 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 1044 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
| 997 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1045 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 998 RunUntilIdle(); | 1046 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, |
| 999 EXPECT_THAT(run_order, | 1047 ForceUpdatePolicyAndGetCurrentUseCase()); |
| 1000 testing::ElementsAre(std::string("C1"), std::string("C2"), | |
| 1001 std::string("D1"), std::string("D2"))); | |
| 1002 | 1048 |
| 1003 run_order.clear(); | |
| 1004 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 1049 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
| 1005 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 1050 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 } | 1051 } |
| 1013 | 1052 |
| 1014 TEST_F(RendererSchedulerImplTest, | 1053 TEST_F(RendererSchedulerImplTest, |
| 1015 TestCompositorPolicyEnds_MainThreadHandlesInput) { | 1054 TestCompositorPolicyEnds_MainThreadHandlesInput) { |
| 1016 std::vector<std::string> run_order; | |
| 1017 PostTestTasks(&run_order, "D1 C1 D2 C2"); | |
| 1018 | |
| 1019 scheduler_->DidHandleInputEventOnCompositorThread( | 1055 scheduler_->DidHandleInputEventOnCompositorThread( |
| 1020 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 1056 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
| 1021 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1057 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
| 1022 scheduler_->DidHandleInputEventOnMainThread( | 1058 scheduler_->DidHandleInputEventOnMainThread( |
| 1023 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1059 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
| 1024 RunUntilIdle(); | 1060 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, |
| 1025 EXPECT_THAT(run_order, | 1061 ForceUpdatePolicyAndGetCurrentUseCase()); |
| 1026 testing::ElementsAre(std::string("C1"), std::string("C2"), | |
| 1027 std::string("D1"), std::string("D2"))); | |
| 1028 | 1062 |
| 1029 run_order.clear(); | |
| 1030 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 1063 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
| 1031 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 1064 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 } | 1065 } |
| 1039 | 1066 |
| 1040 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { | 1067 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { |
| 1041 std::vector<std::string> run_order; | 1068 std::vector<std::string> run_order; |
| 1042 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); | 1069 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); |
| 1043 | 1070 |
| 1044 scheduler_->DidHandleInputEventOnCompositorThread( | 1071 scheduler_->DidHandleInputEventOnCompositorThread( |
| 1045 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1072 FakeInputEvent(blink::WebInputEvent::TouchStart), |
| 1046 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1073 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 1047 RunUntilIdle(); | 1074 RunUntilIdle(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 FakeInputEvent(blink::WebInputEvent::TouchMove), | 1118 FakeInputEvent(blink::WebInputEvent::TouchMove), |
| 1092 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1119 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 1093 RunUntilIdle(); | 1120 RunUntilIdle(); |
| 1094 EXPECT_THAT(run_order, testing::ElementsAre(std::string("L1"))); | 1121 EXPECT_THAT(run_order, testing::ElementsAre(std::string("L1"))); |
| 1095 } | 1122 } |
| 1096 | 1123 |
| 1097 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) { | 1124 TEST_F(RendererSchedulerImplTest, TestIsHighPriorityWorkAnticipated) { |
| 1098 bool is_anticipated_before = false; | 1125 bool is_anticipated_before = false; |
| 1099 bool is_anticipated_after = false; | 1126 bool is_anticipated_after = false; |
| 1100 | 1127 |
| 1101 bool simulate_input = false; | |
| 1102 default_task_runner_->PostTask( | 1128 default_task_runner_->PostTask( |
| 1103 FROM_HERE, | 1129 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(), |
| 1104 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 1130 SimulateInputType::None, &is_anticipated_before, |
| 1105 &is_anticipated_before, &is_anticipated_after)); | 1131 &is_anticipated_after)); |
| 1106 RunUntilIdle(); | 1132 RunUntilIdle(); |
| 1107 // In its default state, without input receipt, the scheduler should indicate | 1133 // In its default state, without input receipt, the scheduler should indicate |
| 1108 // that no high-priority is anticipated. | 1134 // that no high-priority is anticipated. |
| 1109 EXPECT_FALSE(is_anticipated_before); | 1135 EXPECT_FALSE(is_anticipated_before); |
| 1110 EXPECT_FALSE(is_anticipated_after); | 1136 EXPECT_FALSE(is_anticipated_after); |
| 1111 | 1137 |
| 1112 simulate_input = true; | |
| 1113 default_task_runner_->PostTask( | 1138 default_task_runner_->PostTask( |
| 1114 FROM_HERE, | 1139 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(), |
| 1115 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 1140 SimulateInputType::TouchStart, |
| 1116 &is_anticipated_before, &is_anticipated_after)); | 1141 &is_anticipated_before, &is_anticipated_after)); |
| 1142 bool dummy; |
| 1143 default_task_runner_->PostTask( |
| 1144 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(), |
| 1145 SimulateInputType::TouchEnd, &dummy, &dummy)); |
| 1146 |
| 1117 RunUntilIdle(); | 1147 RunUntilIdle(); |
| 1118 // When input is received, the scheduler should indicate that high-priority | 1148 // When input is received, the scheduler should indicate that high-priority |
| 1119 // work is anticipated. | 1149 // work is anticipated. |
| 1120 EXPECT_FALSE(is_anticipated_before); | 1150 EXPECT_FALSE(is_anticipated_before); |
| 1121 EXPECT_TRUE(is_anticipated_after); | 1151 EXPECT_TRUE(is_anticipated_after); |
| 1122 | 1152 |
| 1123 clock_->Advance(priority_escalation_after_input_duration() * 2); | 1153 clock_->Advance(priority_escalation_after_input_duration() * 2); |
| 1124 simulate_input = false; | |
| 1125 default_task_runner_->PostTask( | 1154 default_task_runner_->PostTask( |
| 1126 FROM_HERE, | 1155 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(), |
| 1127 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 1156 SimulateInputType::None, &is_anticipated_before, |
| 1128 &is_anticipated_before, &is_anticipated_after)); | 1157 &is_anticipated_after)); |
| 1129 RunUntilIdle(); | 1158 RunUntilIdle(); |
| 1130 // Without additional input, the scheduler should indicate that high-priority | 1159 // Without additional input, the scheduler should go into NONE |
| 1131 // work is no longer anticipated. | 1160 // use case but with scrolling expected where high-priority work is still |
| 1161 // anticipated. |
| 1162 EXPECT_EQ(UseCase::NONE, CurrentUseCase()); |
| 1163 EXPECT_TRUE(TouchStartExpectedSoon()); |
| 1164 EXPECT_TRUE(is_anticipated_before); |
| 1165 EXPECT_TRUE(is_anticipated_after); |
| 1166 |
| 1167 clock_->Advance(subsequent_input_expected_after_input_duration() * 2); |
| 1168 default_task_runner_->PostTask( |
| 1169 FROM_HERE, base::Bind(&AnticipationTestTask, scheduler_.get(), |
| 1170 SimulateInputType::None, &is_anticipated_before, |
| 1171 &is_anticipated_after)); |
| 1172 RunUntilIdle(); |
| 1173 // Eventually the scheduler should go into the default use case where |
| 1174 // high-priority work is no longer anticipated. |
| 1175 EXPECT_EQ(UseCase::NONE, CurrentUseCase()); |
| 1176 EXPECT_FALSE(TouchStartExpectedSoon()); |
| 1132 EXPECT_FALSE(is_anticipated_before); | 1177 EXPECT_FALSE(is_anticipated_before); |
| 1133 EXPECT_FALSE(is_anticipated_after); | 1178 EXPECT_FALSE(is_anticipated_after); |
| 1134 } | 1179 } |
| 1135 | 1180 |
| 1136 TEST_F(RendererSchedulerImplTest, TestShouldYield) { | 1181 TEST_F(RendererSchedulerImplTest, TestShouldYield) { |
| 1137 bool should_yield_before = false; | 1182 bool should_yield_before = false; |
| 1138 bool should_yield_after = false; | 1183 bool should_yield_after = false; |
| 1139 | 1184 |
| 1185 ForceMainthreadScrollingUseCase(); |
| 1186 |
| 1140 default_task_runner_->PostTask( | 1187 default_task_runner_->PostTask( |
| 1141 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 1188 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
| 1142 default_task_runner_, false, &should_yield_before, | 1189 default_task_runner_, false, &should_yield_before, |
| 1143 &should_yield_after)); | 1190 &should_yield_after)); |
| 1144 RunUntilIdle(); | 1191 RunUntilIdle(); |
| 1145 // Posting to default runner shouldn't cause yielding. | 1192 // Posting to default runner shouldn't cause yielding. |
| 1146 EXPECT_FALSE(should_yield_before); | 1193 EXPECT_FALSE(should_yield_before); |
| 1147 EXPECT_FALSE(should_yield_after); | 1194 EXPECT_FALSE(should_yield_after); |
| 1148 | 1195 |
| 1149 default_task_runner_->PostTask( | 1196 default_task_runner_->PostTask( |
| 1150 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 1197 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
| 1151 compositor_task_runner_, false, | 1198 compositor_task_runner_, false, |
| 1152 &should_yield_before, &should_yield_after)); | 1199 &should_yield_before, &should_yield_after)); |
| 1153 RunUntilIdle(); | 1200 RunUntilIdle(); |
| 1154 // Posting while not in compositor priority shouldn't cause yielding. | 1201 // Posting while not mainthread scrolling shouldn't cause yielding. |
| 1155 EXPECT_FALSE(should_yield_before); | 1202 EXPECT_FALSE(should_yield_before); |
| 1156 EXPECT_FALSE(should_yield_after); | 1203 EXPECT_FALSE(should_yield_after); |
| 1157 | 1204 |
| 1158 default_task_runner_->PostTask( | 1205 default_task_runner_->PostTask( |
| 1159 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 1206 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
| 1160 compositor_task_runner_, true, &should_yield_before, | 1207 compositor_task_runner_, true, &should_yield_before, |
| 1161 &should_yield_after)); | 1208 &should_yield_after)); |
| 1162 RunUntilIdle(); | 1209 RunUntilIdle(); |
| 1163 // We should be able to switch to compositor priority mid-task. | 1210 // We should be able to switch to compositor priority mid-task. |
| 1164 EXPECT_FALSE(should_yield_before); | 1211 EXPECT_FALSE(should_yield_before); |
| 1165 EXPECT_TRUE(should_yield_after); | 1212 EXPECT_TRUE(should_yield_after); |
| 1213 } |
| 1166 | 1214 |
| 1215 TEST_F(RendererSchedulerImplTest, TestShouldYield_TouchStart) { |
| 1167 // Receiving a touchstart should immediately trigger yielding, even if | 1216 // Receiving a touchstart should immediately trigger yielding, even if |
| 1168 // there's no immediately pending work in the compositor queue. | 1217 // there's no immediately pending work in the compositor queue. |
| 1169 EXPECT_FALSE(scheduler_->ShouldYieldForHighPriorityWork()); | 1218 EXPECT_FALSE(scheduler_->ShouldYieldForHighPriorityWork()); |
| 1170 scheduler_->DidHandleInputEventOnCompositorThread( | 1219 scheduler_->DidHandleInputEventOnCompositorThread( |
| 1171 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1220 FakeInputEvent(blink::WebInputEvent::TouchStart), |
| 1172 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1221 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
| 1173 EXPECT_TRUE(scheduler_->ShouldYieldForHighPriorityWork()); | 1222 EXPECT_TRUE(scheduler_->ShouldYieldForHighPriorityWork()); |
| 1174 RunUntilIdle(); | 1223 RunUntilIdle(); |
| 1175 } | 1224 } |
| 1176 | 1225 |
| 1177 TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) { | 1226 TEST_F(RendererSchedulerImplTest, SlowMainThreadInputEvent) { |
| 1178 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 1227 EXPECT_EQ(UseCase::NONE, CurrentUseCase()); |
| 1179 | 1228 |
| 1180 // An input event should bump us into input priority. | 1229 // An input event should bump us into input priority. |
| 1181 scheduler_->DidHandleInputEventOnCompositorThread( | 1230 scheduler_->DidHandleInputEventOnCompositorThread( |
| 1182 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 1231 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
| 1183 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1232 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
| 1184 RunUntilIdle(); | 1233 RunUntilIdle(); |
| 1185 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 1234 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, CurrentUseCase()); |
| 1186 | 1235 |
| 1187 // Simulate the input event being queued for a very long time. The compositor | 1236 // Simulate the input event being queued for a very long time. The compositor |
| 1188 // task we post here represents the enqueued input task. | 1237 // task we post here represents the enqueued input task. |
| 1189 clock_->Advance(priority_escalation_after_input_duration() * 2); | 1238 clock_->Advance(priority_escalation_after_input_duration() * 2); |
| 1190 scheduler_->DidHandleInputEventOnMainThread( | 1239 scheduler_->DidHandleInputEventOnMainThread( |
| 1191 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1240 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
| 1192 RunUntilIdle(); | 1241 RunUntilIdle(); |
| 1193 | 1242 |
| 1194 // Even though we exceeded the input priority escalation period, we should | 1243 // Even though we exceeded the input priority escalation period, we should |
| 1195 // still be in compositor priority since the input remains queued. | 1244 // still be in compositor priority since the input remains queued. |
| 1196 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 1245 EXPECT_EQ(UseCase::COMPOSITOR_GESTURE, CurrentUseCase()); |
| 1197 | 1246 |
| 1198 // After the escalation period ends we should go back into normal mode. | 1247 // After the escalation period ends we should go back into normal mode. |
| 1199 clock_->Advance(priority_escalation_after_input_duration() * 2); | 1248 clock_->Advance(priority_escalation_after_input_duration() * 2); |
| 1200 RunUntilIdle(); | 1249 RunUntilIdle(); |
| 1201 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 1250 EXPECT_EQ(UseCase::NONE, CurrentUseCase()); |
| 1202 } | 1251 } |
| 1203 | 1252 |
| 1204 class RendererSchedulerImplWithMockSchedulerTest | 1253 class RendererSchedulerImplWithMockSchedulerTest |
| 1205 : public RendererSchedulerImplTest { | 1254 : public RendererSchedulerImplTest { |
| 1206 public: | 1255 public: |
| 1207 void SetUp() override { | 1256 void SetUp() override { |
| 1208 mock_task_runner_ = make_scoped_refptr( | 1257 mock_task_runner_ = make_scoped_refptr( |
| 1209 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); | 1258 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); |
| 1210 main_task_runner_ = | 1259 main_task_runner_ = |
| 1211 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); | 1260 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 scheduler_->ShouldYieldForHighPriorityWork(); | 1443 scheduler_->ShouldYieldForHighPriorityWork(); |
| 1395 scheduler_->ShouldYieldForHighPriorityWork(); | 1444 scheduler_->ShouldYieldForHighPriorityWork(); |
| 1396 | 1445 |
| 1397 scheduler_->DidHandleInputEventOnMainThread( | 1446 scheduler_->DidHandleInputEventOnMainThread( |
| 1398 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1447 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
| 1399 scheduler_->DidHandleInputEventOnMainThread( | 1448 scheduler_->DidHandleInputEventOnMainThread( |
| 1400 FakeInputEvent(blink::WebInputEvent::TouchMove)); | 1449 FakeInputEvent(blink::WebInputEvent::TouchMove)); |
| 1401 | 1450 |
| 1402 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1451 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
| 1403 | 1452 |
| 1453 // We expect both the urgent and the delayed updates to run in addition to the |
| 1454 // earlier updated cause by IsHighPriorityWorkAnticipated, a final update |
| 1455 // transitions from 'not_scrolling scroll expected' to 'not_scrolling'. |
| 1404 RunUntilIdle(); | 1456 RunUntilIdle(); |
| 1405 // We expect both the urgent and the delayed updates to run in addition to the | 1457 EXPECT_THAT(mock_scheduler_->use_cases_, |
| 1406 // earlier updated cause by IsHighPriorityWorkAnticipated. | 1458 testing::ElementsAre( |
| 1407 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); | 1459 std::string("touchstart"), std::string("touchstart"), |
| 1460 std::string("none scroll expected"), std::string("none"))); |
| 1408 } | 1461 } |
| 1409 | 1462 |
| 1410 class RendererSchedulerImplWithMessageLoopTest | 1463 class RendererSchedulerImplWithMessageLoopTest |
| 1411 : public RendererSchedulerImplTest { | 1464 : public RendererSchedulerImplTest { |
| 1412 public: | 1465 public: |
| 1413 RendererSchedulerImplWithMessageLoopTest() | 1466 RendererSchedulerImplWithMessageLoopTest() |
| 1414 : RendererSchedulerImplTest(new base::MessageLoop()) {} | 1467 : RendererSchedulerImplTest(new base::MessageLoop()) {} |
| 1415 ~RendererSchedulerImplWithMessageLoopTest() override {} | 1468 ~RendererSchedulerImplWithMessageLoopTest() override {} |
| 1416 | 1469 |
| 1417 void PostFromNestedRunloop(std::vector< | 1470 void PostFromNestedRunloop(std::vector< |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1752 scheduler_->ResumeTimerQueue(); | 1805 scheduler_->ResumeTimerQueue(); |
| 1753 RunUntilIdle(); | 1806 RunUntilIdle(); |
| 1754 EXPECT_TRUE(run_order.empty()); | 1807 EXPECT_TRUE(run_order.empty()); |
| 1755 | 1808 |
| 1756 scheduler_->ResumeTimerQueue(); | 1809 scheduler_->ResumeTimerQueue(); |
| 1757 RunUntilIdle(); | 1810 RunUntilIdle(); |
| 1758 EXPECT_THAT(run_order, | 1811 EXPECT_THAT(run_order, |
| 1759 testing::ElementsAre(std::string("T1"), std::string("T2"))); | 1812 testing::ElementsAre(std::string("T1"), std::string("T2"))); |
| 1760 } | 1813 } |
| 1761 | 1814 |
| 1762 TEST_F(RendererSchedulerImplTest, PolicyToString) { | 1815 TEST_F(RendererSchedulerImplTest, UseCaseToString) { |
| 1763 CheckAllPolicyToString(); | 1816 CheckAllUseCaseToString(); |
| 1764 } | 1817 } |
| 1765 | 1818 |
| 1766 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) { | 1819 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) { |
| 1767 // This should not DCHECK because there was no corresponding compositor side | 1820 // This should not DCHECK because there was no corresponding compositor side |
| 1768 // call to DidHandleInputEventOnCompositorThread with | 1821 // call to DidHandleInputEventOnCompositorThread with |
| 1769 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the | 1822 // 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. | 1823 // compositor to not be there and we don't want to make debugging impossible. |
| 1771 scheduler_->DidHandleInputEventOnMainThread( | 1824 scheduler_->DidHandleInputEventOnMainThread( |
| 1772 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1825 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
| 1773 } | 1826 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 EXPECT_THAT(run_order, | 1881 EXPECT_THAT(run_order, |
| 1829 testing::ElementsAre(std::string("T4"), std::string("T5"))); | 1882 testing::ElementsAre(std::string("T4"), std::string("T5"))); |
| 1830 | 1883 |
| 1831 // Subsequent timer tasks should fire as usual. | 1884 // Subsequent timer tasks should fire as usual. |
| 1832 run_order.clear(); | 1885 run_order.clear(); |
| 1833 PostTestTasks(&run_order, "T6"); | 1886 PostTestTasks(&run_order, "T6"); |
| 1834 RunUntilIdle(); | 1887 RunUntilIdle(); |
| 1835 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6"))); | 1888 EXPECT_THAT(run_order, testing::ElementsAre(std::string("T6"))); |
| 1836 } | 1889 } |
| 1837 } // namespace scheduler | 1890 } // namespace scheduler |
| OLD | NEW |