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 "cc/output/begin_frame_args.h" | 9 #include "cc/output/begin_frame_args.h" |
9 #include "cc/test/ordered_simple_task_runner.h" | 10 #include "cc/test/ordered_simple_task_runner.h" |
10 #include "cc/test/test_now_source.h" | |
11 #include "components/scheduler/child/nestable_task_runner_for_test.h" | 11 #include "components/scheduler/child/nestable_task_runner_for_test.h" |
12 #include "components/scheduler/child/scheduler_message_loop_delegate.h" | 12 #include "components/scheduler/child/scheduler_message_loop_delegate.h" |
13 #include "components/scheduler/child/test_time_source.h" | 13 #include "components/scheduler/child/test_time_source.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace scheduler { | 17 namespace scheduler { |
18 | 18 |
19 namespace { | 19 namespace { |
20 class FakeInputEvent : public blink::WebInputEvent { | 20 class FakeInputEvent : public blink::WebInputEvent { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 idle_task_runner->PostIdleTask( | 74 idle_task_runner->PostIdleTask( |
75 FROM_HERE, base::Bind(&RepostingIdleTestTask, | 75 FROM_HERE, base::Bind(&RepostingIdleTestTask, |
76 base::Unretained(idle_task_runner), run_count)); | 76 base::Unretained(idle_task_runner), run_count)); |
77 } | 77 } |
78 (*run_count)++; | 78 (*run_count)++; |
79 } | 79 } |
80 | 80 |
81 void RepostingUpdateClockIdleTestTask( | 81 void RepostingUpdateClockIdleTestTask( |
82 SingleThreadIdleTaskRunner* idle_task_runner, | 82 SingleThreadIdleTaskRunner* idle_task_runner, |
83 int* run_count, | 83 int* run_count, |
84 scoped_refptr<cc::TestNowSource> clock, | 84 base::SimpleTestTickClock* clock, |
85 base::TimeDelta advance_time, | 85 base::TimeDelta advance_time, |
86 std::vector<base::TimeTicks>* deadlines, | 86 std::vector<base::TimeTicks>* deadlines, |
87 base::TimeTicks deadline) { | 87 base::TimeTicks deadline) { |
88 if ((*run_count + 1) < max_idle_task_reposts) { | 88 if ((*run_count + 1) < max_idle_task_reposts) { |
89 idle_task_runner->PostIdleTask( | 89 idle_task_runner->PostIdleTask( |
90 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, | 90 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, |
91 base::Unretained(idle_task_runner), run_count, | 91 base::Unretained(idle_task_runner), run_count, |
92 clock, advance_time, deadlines)); | 92 clock, advance_time, deadlines)); |
93 } | 93 } |
94 deadlines->push_back(deadline); | 94 deadlines->push_back(deadline); |
95 (*run_count)++; | 95 (*run_count)++; |
96 clock->AdvanceNow(advance_time); | 96 clock->Advance(advance_time); |
97 } | 97 } |
98 | 98 |
99 void WillBeginFrameIdleTask(RendererScheduler* scheduler, | 99 void WillBeginFrameIdleTask(RendererScheduler* scheduler, |
100 scoped_refptr<cc::TestNowSource> clock, | 100 base::SimpleTestTickClock* clock, |
101 base::TimeTicks deadline) { | 101 base::TimeTicks deadline) { |
102 scheduler->WillBeginFrame(cc::BeginFrameArgs::Create( | 102 scheduler->WillBeginFrame(cc::BeginFrameArgs::Create( |
103 BEGINFRAME_FROM_HERE, clock->Now(), base::TimeTicks(), | 103 BEGINFRAME_FROM_HERE, clock->NowTicks(), base::TimeTicks(), |
104 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 104 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
105 } | 105 } |
106 | 106 |
107 void UpdateClockToDeadlineIdleTestTask( | 107 void UpdateClockToDeadlineIdleTestTask(base::SimpleTestTickClock* clock, |
108 cc::TestNowSource* clock, | 108 int* run_count, |
109 int* run_count, | 109 base::TimeTicks deadline) { |
110 base::TimeTicks deadline) { | 110 clock->Advance(deadline - clock->NowTicks()); |
111 clock->SetNow(deadline); | |
112 (*run_count)++; | 111 (*run_count)++; |
113 } | 112 } |
114 | 113 |
115 void PostingYieldingTestTask(RendererSchedulerImpl* scheduler, | 114 void PostingYieldingTestTask(RendererSchedulerImpl* scheduler, |
116 base::SingleThreadTaskRunner* task_runner, | 115 base::SingleThreadTaskRunner* task_runner, |
117 bool simulate_input, | 116 bool simulate_input, |
118 bool* should_yield_before, | 117 bool* should_yield_before, |
119 bool* should_yield_after) { | 118 bool* should_yield_after) { |
120 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); | 119 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); |
121 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); | 120 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // Lets gtest print human readable Policy values. | 177 // Lets gtest print human readable Policy values. |
179 ::std::ostream& operator<<(::std::ostream& os, | 178 ::std::ostream& operator<<(::std::ostream& os, |
180 const RendererSchedulerImplForTest::Policy& policy) { | 179 const RendererSchedulerImplForTest::Policy& policy) { |
181 return os << RendererSchedulerImplForTest::PolicyToString(policy); | 180 return os << RendererSchedulerImplForTest::PolicyToString(policy); |
182 } | 181 } |
183 | 182 |
184 class RendererSchedulerImplTest : public testing::Test { | 183 class RendererSchedulerImplTest : public testing::Test { |
185 public: | 184 public: |
186 using Policy = RendererSchedulerImpl::Policy; | 185 using Policy = RendererSchedulerImpl::Policy; |
187 | 186 |
188 RendererSchedulerImplTest() : clock_(cc::TestNowSource::Create(5000)) {} | 187 RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) { |
| 188 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); |
| 189 } |
189 | 190 |
190 RendererSchedulerImplTest(base::MessageLoop* message_loop) | 191 RendererSchedulerImplTest(base::MessageLoop* message_loop) |
191 : clock_(cc::TestNowSource::Create(5000)), message_loop_(message_loop) {} | 192 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) { |
| 193 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); |
| 194 } |
192 | 195 |
193 ~RendererSchedulerImplTest() override {} | 196 ~RendererSchedulerImplTest() override {} |
194 | 197 |
195 void SetUp() override { | 198 void SetUp() override { |
196 if (message_loop_) { | 199 if (message_loop_) { |
197 nestable_task_runner_ = | 200 nestable_task_runner_ = |
198 SchedulerMessageLoopDelegate::Create(message_loop_.get()); | 201 SchedulerMessageLoopDelegate::Create(message_loop_.get()); |
199 } else { | 202 } else { |
200 mock_task_runner_ = | 203 mock_task_runner_ = make_scoped_refptr( |
201 make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_, false)); | 204 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); |
202 nestable_task_runner_ = | 205 nestable_task_runner_ = |
203 NestableTaskRunnerForTest::Create(mock_task_runner_); | 206 NestableTaskRunnerForTest::Create(mock_task_runner_); |
204 } | 207 } |
205 Initialize(make_scoped_ptr( | 208 Initialize(make_scoped_ptr( |
206 new RendererSchedulerImplForTest(nestable_task_runner_))); | 209 new RendererSchedulerImplForTest(nestable_task_runner_))); |
207 } | 210 } |
208 | 211 |
209 void Initialize(scoped_ptr<RendererSchedulerImplForTest> scheduler) { | 212 void Initialize(scoped_ptr<RendererSchedulerImplForTest> scheduler) { |
210 scheduler_ = scheduler.Pass(); | 213 scheduler_ = scheduler.Pass(); |
211 default_task_runner_ = scheduler_->DefaultTaskRunner(); | 214 default_task_runner_ = scheduler_->DefaultTaskRunner(); |
212 compositor_task_runner_ = scheduler_->CompositorTaskRunner(); | 215 compositor_task_runner_ = scheduler_->CompositorTaskRunner(); |
213 loading_task_runner_ = scheduler_->LoadingTaskRunner(); | 216 loading_task_runner_ = scheduler_->LoadingTaskRunner(); |
214 idle_task_runner_ = scheduler_->IdleTaskRunner(); | 217 idle_task_runner_ = scheduler_->IdleTaskRunner(); |
215 timer_task_runner_ = scheduler_->TimerTaskRunner(); | 218 timer_task_runner_ = scheduler_->TimerTaskRunner(); |
216 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 219 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
217 make_scoped_ptr(new TestTimeSource(clock_))); | 220 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
218 scheduler_->GetSchedulerHelperForTesting() | 221 scheduler_->GetSchedulerHelperForTesting() |
219 ->GetTaskQueueManagerForTesting() | 222 ->GetTaskQueueManagerForTesting() |
220 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 223 ->SetTimeSourceForTesting( |
| 224 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
221 } | 225 } |
222 | 226 |
223 void TearDown() override { | 227 void TearDown() override { |
224 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); | 228 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); |
225 scheduler_->Shutdown(); | 229 scheduler_->Shutdown(); |
226 if (mock_task_runner_.get()) { | 230 if (mock_task_runner_.get()) { |
227 // Check that all tests stop posting tasks. | 231 // Check that all tests stop posting tasks. |
228 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 232 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
229 while (mock_task_runner_->RunUntilIdle()) { | 233 while (mock_task_runner_->RunUntilIdle()) { |
230 } | 234 } |
231 } else { | 235 } else { |
232 message_loop_->RunUntilIdle(); | 236 message_loop_->RunUntilIdle(); |
233 } | 237 } |
234 scheduler_.reset(); | 238 scheduler_.reset(); |
235 } | 239 } |
236 | 240 |
237 void RunUntilIdle() { | 241 void RunUntilIdle() { |
238 // Only one of mock_task_runner_ or message_loop_ should be set. | 242 // Only one of mock_task_runner_ or message_loop_ should be set. |
239 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); | 243 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); |
240 if (mock_task_runner_.get()) | 244 if (mock_task_runner_.get()) |
241 mock_task_runner_->RunUntilIdle(); | 245 mock_task_runner_->RunUntilIdle(); |
242 else | 246 else |
243 message_loop_->RunUntilIdle(); | 247 message_loop_->RunUntilIdle(); |
244 } | 248 } |
245 | 249 |
246 void DoMainFrame() { | 250 void DoMainFrame() { |
247 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 251 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
248 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 252 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
249 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 253 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
250 scheduler_->DidCommitFrameToCompositor(); | 254 scheduler_->DidCommitFrameToCompositor(); |
251 } | 255 } |
252 | 256 |
253 void EnableIdleTasks() { DoMainFrame(); } | 257 void EnableIdleTasks() { DoMainFrame(); } |
254 | 258 |
255 Policy CurrentPolicy() { | 259 Policy CurrentPolicy() { |
256 return scheduler_->MainThreadOnly().current_policy_; | 260 return scheduler_->MainThreadOnly().current_policy_; |
257 } | 261 } |
258 | 262 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 &RendererSchedulerImpl::TaskQueueIdToString); | 340 &RendererSchedulerImpl::TaskQueueIdToString); |
337 } | 341 } |
338 | 342 |
339 static void CheckAllPolicyToString() { | 343 static void CheckAllPolicyToString() { |
340 CallForEachEnumValue<RendererSchedulerImpl::Policy>( | 344 CallForEachEnumValue<RendererSchedulerImpl::Policy>( |
341 RendererSchedulerImpl::Policy::FIRST_POLICY, | 345 RendererSchedulerImpl::Policy::FIRST_POLICY, |
342 RendererSchedulerImpl::Policy::POLICY_COUNT, | 346 RendererSchedulerImpl::Policy::POLICY_COUNT, |
343 &RendererSchedulerImpl::PolicyToString); | 347 &RendererSchedulerImpl::PolicyToString); |
344 } | 348 } |
345 | 349 |
346 scoped_refptr<cc::TestNowSource> clock_; | 350 scoped_ptr<base::SimpleTestTickClock> clock_; |
347 // Only one of mock_task_runner_ or message_loop_ will be set. | 351 // Only one of mock_task_runner_ or message_loop_ will be set. |
348 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 352 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
349 scoped_ptr<base::MessageLoop> message_loop_; | 353 scoped_ptr<base::MessageLoop> message_loop_; |
350 | 354 |
351 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; | 355 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; |
352 scoped_ptr<RendererSchedulerImplForTest> scheduler_; | 356 scoped_ptr<RendererSchedulerImplForTest> scheduler_; |
353 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 357 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
354 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 358 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
355 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; | 359 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; |
356 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 360 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
(...skipping 27 matching lines...) Expand all Loading... |
384 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_, | 388 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_, |
385 &run_order, &count, 5)); | 389 &run_order, &count, 5)); |
386 RunUntilIdle(); | 390 RunUntilIdle(); |
387 | 391 |
388 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4)); | 392 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4)); |
389 } | 393 } |
390 | 394 |
391 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) { | 395 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) { |
392 int run_count = 0; | 396 int run_count = 0; |
393 base::TimeTicks expected_deadline = | 397 base::TimeTicks expected_deadline = |
394 clock_->Now() + base::TimeDelta::FromMilliseconds(2300); | 398 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(2300); |
395 base::TimeTicks deadline_in_task; | 399 base::TimeTicks deadline_in_task; |
396 | 400 |
397 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 401 clock_->Advance(base::TimeDelta::FromMilliseconds(100)); |
398 idle_task_runner_->PostIdleTask( | 402 idle_task_runner_->PostIdleTask( |
399 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 403 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
400 | 404 |
401 RunUntilIdle(); | 405 RunUntilIdle(); |
402 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame. | 406 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame. |
403 | 407 |
404 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 408 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
405 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 409 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
406 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 410 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
407 RunUntilIdle(); | 411 RunUntilIdle(); |
408 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor. | 412 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor. |
409 | 413 |
410 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1200)); | 414 clock_->Advance(base::TimeDelta::FromMilliseconds(1200)); |
411 scheduler_->DidCommitFrameToCompositor(); | 415 scheduler_->DidCommitFrameToCompositor(); |
412 RunUntilIdle(); | 416 RunUntilIdle(); |
413 EXPECT_EQ(0, run_count); // We missed the deadline. | 417 EXPECT_EQ(0, run_count); // We missed the deadline. |
414 | 418 |
415 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 419 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
416 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 420 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
417 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 421 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
418 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(800)); | 422 clock_->Advance(base::TimeDelta::FromMilliseconds(800)); |
419 scheduler_->DidCommitFrameToCompositor(); | 423 scheduler_->DidCommitFrameToCompositor(); |
420 RunUntilIdle(); | 424 RunUntilIdle(); |
421 EXPECT_EQ(1, run_count); | 425 EXPECT_EQ(1, run_count); |
422 EXPECT_EQ(expected_deadline, deadline_in_task); | 426 EXPECT_EQ(expected_deadline, deadline_in_task); |
423 } | 427 } |
424 | 428 |
425 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) { | 429 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) { |
426 int run_count = 0; | 430 int run_count = 0; |
427 | 431 |
428 max_idle_task_reposts = 2; | 432 max_idle_task_reposts = 2; |
(...skipping 13 matching lines...) Expand all Loading... |
442 EXPECT_EQ(2, run_count); | 446 EXPECT_EQ(2, run_count); |
443 } | 447 } |
444 | 448 |
445 TEST_F(RendererSchedulerImplTest, TestIdleTaskExceedsDeadline) { | 449 TEST_F(RendererSchedulerImplTest, TestIdleTaskExceedsDeadline) { |
446 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 450 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
447 int run_count = 0; | 451 int run_count = 0; |
448 | 452 |
449 // Post two UpdateClockToDeadlineIdleTestTask tasks. | 453 // Post two UpdateClockToDeadlineIdleTestTask tasks. |
450 idle_task_runner_->PostIdleTask( | 454 idle_task_runner_->PostIdleTask( |
451 FROM_HERE, | 455 FROM_HERE, |
452 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, &run_count)); | 456 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), &run_count)); |
453 idle_task_runner_->PostIdleTask( | 457 idle_task_runner_->PostIdleTask( |
454 FROM_HERE, | 458 FROM_HERE, |
455 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, &run_count)); | 459 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), &run_count)); |
456 | 460 |
457 EnableIdleTasks(); | 461 EnableIdleTasks(); |
458 RunUntilIdle(); | 462 RunUntilIdle(); |
459 // Only the first idle task should execute since it's used up the deadline. | 463 // Only the first idle task should execute since it's used up the deadline. |
460 EXPECT_EQ(1, run_count); | 464 EXPECT_EQ(1, run_count); |
461 | 465 |
462 EnableIdleTasks(); | 466 EnableIdleTasks(); |
463 RunUntilIdle(); | 467 RunUntilIdle(); |
464 // Second task should be run on the next idle period. | 468 // Second task should be run on the next idle period. |
465 EXPECT_EQ(2, run_count); | 469 EXPECT_EQ(2, run_count); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 533 |
530 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) { | 534 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) { |
531 int run_count = 0; | 535 int run_count = 0; |
532 | 536 |
533 base::TimeTicks deadline_in_task; | 537 base::TimeTicks deadline_in_task; |
534 idle_task_runner_->PostIdleTask( | 538 idle_task_runner_->PostIdleTask( |
535 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 539 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
536 | 540 |
537 // Trigger the beginning of an idle period for 1000ms. | 541 // Trigger the beginning of an idle period for 1000ms. |
538 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 542 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
539 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 543 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
540 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 544 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
541 DoMainFrame(); | 545 DoMainFrame(); |
542 | 546 |
543 // End the idle period early (after 500ms), and send a WillBeginFrame which | 547 // End the idle period early (after 500ms), and send a WillBeginFrame which |
544 // specifies that the next idle period should end 1000ms from now. | 548 // specifies that the next idle period should end 1000ms from now. |
545 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(500)); | 549 clock_->Advance(base::TimeDelta::FromMilliseconds(500)); |
546 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 550 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
547 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 551 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
548 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 552 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
549 | 553 |
550 RunUntilIdle(); | 554 RunUntilIdle(); |
551 EXPECT_EQ(0, run_count); // Not currently in an idle period. | 555 EXPECT_EQ(0, run_count); // Not currently in an idle period. |
552 | 556 |
553 // Trigger the start of the idle period before the task to end the previous | 557 // Trigger the start of the idle period before the task to end the previous |
554 // idle period has been triggered. | 558 // idle period has been triggered. |
555 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(400)); | 559 clock_->Advance(base::TimeDelta::FromMilliseconds(400)); |
556 scheduler_->DidCommitFrameToCompositor(); | 560 scheduler_->DidCommitFrameToCompositor(); |
557 | 561 |
558 // Post a task which simulates running until after the previous end idle | 562 // Post a task which simulates running until after the previous end idle |
559 // period delayed task was scheduled for | 563 // period delayed task was scheduled for |
560 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask)); | 564 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask)); |
561 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(300)); | 565 clock_->Advance(base::TimeDelta::FromMilliseconds(300)); |
562 | 566 |
563 RunUntilIdle(); | 567 RunUntilIdle(); |
564 EXPECT_EQ(1, run_count); // We should still be in the new idle period. | 568 EXPECT_EQ(1, run_count); // We should still be in the new idle period. |
565 } | 569 } |
566 | 570 |
567 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { | 571 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { |
568 std::vector<std::string> run_order; | 572 std::vector<std::string> run_order; |
569 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | 573 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); |
570 | 574 |
571 EnableIdleTasks(); | 575 EnableIdleTasks(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 std::string("I1"))); | 625 std::string("I1"))); |
622 } | 626 } |
623 | 627 |
624 TEST_F(RendererSchedulerImplTest, | 628 TEST_F(RendererSchedulerImplTest, |
625 TestCompositorPolicy_TimersOnlyRunWhenIdle_MainThreadOnCriticalPath) { | 629 TestCompositorPolicy_TimersOnlyRunWhenIdle_MainThreadOnCriticalPath) { |
626 std::vector<std::string> run_order; | 630 std::vector<std::string> run_order; |
627 PostTestTasks(&run_order, "C1 T1"); | 631 PostTestTasks(&run_order, "C1 T1"); |
628 | 632 |
629 scheduler_->DidAnimateForInputOnCompositorThread(); | 633 scheduler_->DidAnimateForInputOnCompositorThread(); |
630 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 634 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
631 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 635 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
632 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); | 636 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); |
633 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period | 637 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period |
634 RunUntilIdle(); | 638 RunUntilIdle(); |
635 | 639 |
636 EXPECT_THAT(run_order, | 640 EXPECT_THAT(run_order, |
637 testing::ElementsAre(std::string("C1"), std::string("T1"))); | 641 testing::ElementsAre(std::string("C1"), std::string("T1"))); |
638 | 642 |
639 // End the idle period. | 643 // End the idle period. |
640 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(500)); | 644 clock_->Advance(base::TimeDelta::FromMilliseconds(500)); |
641 scheduler_->DidAnimateForInputOnCompositorThread(); | 645 scheduler_->DidAnimateForInputOnCompositorThread(); |
642 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 646 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
643 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 647 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
644 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); | 648 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); |
645 | 649 |
646 run_order.clear(); | 650 run_order.clear(); |
647 PostTestTasks(&run_order, "C1 T1"); | 651 PostTestTasks(&run_order, "C1 T1"); |
648 RunUntilIdle(); | 652 RunUntilIdle(); |
649 | 653 |
650 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1"))); | 654 EXPECT_THAT(run_order, testing::ElementsAre(std::string("C1"))); |
651 } | 655 } |
652 | 656 |
653 TEST_F(RendererSchedulerImplTest, | 657 TEST_F(RendererSchedulerImplTest, |
654 TestCompositorPolicy_TimersAlwaysRunIfNoRecentIdlePeriod) { | 658 TestCompositorPolicy_TimersAlwaysRunIfNoRecentIdlePeriod) { |
655 std::vector<std::string> run_order; | 659 std::vector<std::string> run_order; |
656 PostTestTasks(&run_order, "C1 T1"); | 660 PostTestTasks(&run_order, "C1 T1"); |
657 | 661 |
658 // Simulate no recent idle period. | 662 // Simulate no recent idle period. |
659 clock_->AdvanceNow(idle_period_starvation_threshold() * 2); | 663 clock_->Advance(idle_period_starvation_threshold() * 2); |
660 | 664 |
661 scheduler_->DidAnimateForInputOnCompositorThread(); | 665 scheduler_->DidAnimateForInputOnCompositorThread(); |
662 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 666 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
663 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 667 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
664 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); | 668 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL)); |
665 | 669 |
666 RunUntilIdle(); | 670 RunUntilIdle(); |
667 | 671 |
668 EXPECT_THAT(run_order, | 672 EXPECT_THAT(run_order, |
669 testing::ElementsAre(std::string("C1"), std::string("T1"))); | 673 testing::ElementsAre(std::string("C1"), std::string("T1"))); |
670 } | 674 } |
671 | 675 |
672 TEST_F(RendererSchedulerImplTest, | 676 TEST_F(RendererSchedulerImplTest, |
673 TestCompositorPolicy_TimersAlwaysRun_MainThreadNotOnCriticalPath) { | 677 TestCompositorPolicy_TimersAlwaysRun_MainThreadNotOnCriticalPath) { |
674 std::vector<std::string> run_order; | 678 std::vector<std::string> run_order; |
675 PostTestTasks(&run_order, "C1 T1"); | 679 PostTestTasks(&run_order, "C1 T1"); |
676 | 680 |
677 scheduler_->DidAnimateForInputOnCompositorThread(); | 681 scheduler_->DidAnimateForInputOnCompositorThread(); |
678 cc::BeginFrameArgs begin_frame_args1 = cc::BeginFrameArgs::Create( | 682 cc::BeginFrameArgs begin_frame_args1 = cc::BeginFrameArgs::Create( |
679 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 683 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
680 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); | 684 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); |
681 begin_frame_args1.on_critical_path = false; | 685 begin_frame_args1.on_critical_path = false; |
682 scheduler_->WillBeginFrame(begin_frame_args1); | 686 scheduler_->WillBeginFrame(begin_frame_args1); |
683 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period | 687 scheduler_->DidCommitFrameToCompositor(); // Starts Idle Period |
684 RunUntilIdle(); | 688 RunUntilIdle(); |
685 | 689 |
686 EXPECT_THAT(run_order, | 690 EXPECT_THAT(run_order, |
687 testing::ElementsAre(std::string("C1"), std::string("T1"))); | 691 testing::ElementsAre(std::string("C1"), std::string("T1"))); |
688 | 692 |
689 // End the idle period. | 693 // End the idle period. |
690 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(500)); | 694 clock_->Advance(base::TimeDelta::FromMilliseconds(500)); |
691 scheduler_->DidAnimateForInputOnCompositorThread(); | 695 scheduler_->DidAnimateForInputOnCompositorThread(); |
692 cc::BeginFrameArgs begin_frame_args2 = cc::BeginFrameArgs::Create( | 696 cc::BeginFrameArgs begin_frame_args2 = cc::BeginFrameArgs::Create( |
693 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 697 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
694 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); | 698 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); |
695 begin_frame_args2.on_critical_path = false; | 699 begin_frame_args2.on_critical_path = false; |
696 scheduler_->WillBeginFrame(begin_frame_args2); | 700 scheduler_->WillBeginFrame(begin_frame_args2); |
697 | 701 |
698 run_order.clear(); | 702 run_order.clear(); |
699 PostTestTasks(&run_order, "C1 T1"); | 703 PostTestTasks(&run_order, "C1 T1"); |
700 RunUntilIdle(); | 704 RunUntilIdle(); |
701 | 705 |
702 EXPECT_THAT(run_order, | 706 EXPECT_THAT(run_order, |
703 testing::ElementsAre(std::string("C1"), std::string("T1"))); | 707 testing::ElementsAre(std::string("C1"), std::string("T1"))); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 EnableIdleTasks(); | 801 EnableIdleTasks(); |
798 RunUntilIdle(); | 802 RunUntilIdle(); |
799 // In loading policy compositor tasks are best effort and should be run last. | 803 // In loading policy compositor tasks are best effort and should be run last. |
800 EXPECT_THAT(run_order, | 804 EXPECT_THAT(run_order, |
801 testing::ElementsAre(std::string("L1"), std::string("D1"), | 805 testing::ElementsAre(std::string("L1"), std::string("D1"), |
802 std::string("D2"), std::string("I1"), | 806 std::string("D2"), std::string("I1"), |
803 std::string("C1"), std::string("C2"))); | 807 std::string("C1"), std::string("C2"))); |
804 | 808 |
805 // Advance 1.5s and try again, the loading policy should have ended and the | 809 // Advance 1.5s and try again, the loading policy should have ended and the |
806 // task order should return to normal. | 810 // task order should return to normal. |
807 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1500)); | 811 clock_->Advance(base::TimeDelta::FromMilliseconds(1500)); |
808 run_order.clear(); | 812 run_order.clear(); |
809 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | 813 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); |
810 EnableIdleTasks(); | 814 EnableIdleTasks(); |
811 RunUntilIdle(); | 815 RunUntilIdle(); |
812 EXPECT_THAT(run_order, | 816 EXPECT_THAT(run_order, |
813 testing::ElementsAre(std::string("L1"), std::string("D1"), | 817 testing::ElementsAre(std::string("L1"), std::string("D1"), |
814 std::string("C1"), std::string("D2"), | 818 std::string("C1"), std::string("D2"), |
815 std::string("C2"), std::string("I1"))); | 819 std::string("C2"), std::string("I1"))); |
816 } | 820 } |
817 | 821 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 991 |
988 scheduler_->DidHandleInputEventOnCompositorThread( | 992 scheduler_->DidHandleInputEventOnCompositorThread( |
989 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 993 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
990 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 994 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
991 RunUntilIdle(); | 995 RunUntilIdle(); |
992 EXPECT_THAT(run_order, | 996 EXPECT_THAT(run_order, |
993 testing::ElementsAre(std::string("C1"), std::string("C2"), | 997 testing::ElementsAre(std::string("C1"), std::string("C2"), |
994 std::string("D1"), std::string("D2"))); | 998 std::string("D1"), std::string("D2"))); |
995 | 999 |
996 run_order.clear(); | 1000 run_order.clear(); |
997 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1001 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
998 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 1002 PostTestTasks(&run_order, "D1 C1 D2 C2"); |
999 | 1003 |
1000 // Compositor policy mode should have ended now that the clock has advanced. | 1004 // Compositor policy mode should have ended now that the clock has advanced. |
1001 RunUntilIdle(); | 1005 RunUntilIdle(); |
1002 EXPECT_THAT(run_order, | 1006 EXPECT_THAT(run_order, |
1003 testing::ElementsAre(std::string("D1"), std::string("C1"), | 1007 testing::ElementsAre(std::string("D1"), std::string("C1"), |
1004 std::string("D2"), std::string("C2"))); | 1008 std::string("D2"), std::string("C2"))); |
1005 } | 1009 } |
1006 | 1010 |
1007 TEST_F(RendererSchedulerImplTest, | 1011 TEST_F(RendererSchedulerImplTest, |
1008 TestCompositorPolicyEnds_MainThreadHandlesInput) { | 1012 TestCompositorPolicyEnds_MainThreadHandlesInput) { |
1009 std::vector<std::string> run_order; | 1013 std::vector<std::string> run_order; |
1010 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 1014 PostTestTasks(&run_order, "D1 C1 D2 C2"); |
1011 | 1015 |
1012 scheduler_->DidHandleInputEventOnCompositorThread( | 1016 scheduler_->DidHandleInputEventOnCompositorThread( |
1013 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 1017 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
1014 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1018 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1015 scheduler_->DidHandleInputEventOnMainThread( | 1019 scheduler_->DidHandleInputEventOnMainThread( |
1016 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1020 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
1017 RunUntilIdle(); | 1021 RunUntilIdle(); |
1018 EXPECT_THAT(run_order, | 1022 EXPECT_THAT(run_order, |
1019 testing::ElementsAre(std::string("C1"), std::string("C2"), | 1023 testing::ElementsAre(std::string("C1"), std::string("C2"), |
1020 std::string("D1"), std::string("D2"))); | 1024 std::string("D1"), std::string("D2"))); |
1021 | 1025 |
1022 run_order.clear(); | 1026 run_order.clear(); |
1023 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1027 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1024 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 1028 PostTestTasks(&run_order, "D1 C1 D2 C2"); |
1025 | 1029 |
1026 // Compositor policy mode should have ended now that the clock has advanced. | 1030 // Compositor policy mode should have ended now that the clock has advanced. |
1027 RunUntilIdle(); | 1031 RunUntilIdle(); |
1028 EXPECT_THAT(run_order, | 1032 EXPECT_THAT(run_order, |
1029 testing::ElementsAre(std::string("D1"), std::string("C1"), | 1033 testing::ElementsAre(std::string("D1"), std::string("C1"), |
1030 std::string("D2"), std::string("C2"))); | 1034 std::string("D2"), std::string("C2"))); |
1031 } | 1035 } |
1032 | 1036 |
1033 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { | 1037 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { |
1034 std::vector<std::string> run_order; | 1038 std::vector<std::string> run_order; |
1035 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); | 1039 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); |
1036 | 1040 |
1037 scheduler_->DidHandleInputEventOnCompositorThread( | 1041 scheduler_->DidHandleInputEventOnCompositorThread( |
1038 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1042 FakeInputEvent(blink::WebInputEvent::TouchStart), |
1039 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1043 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
1040 RunUntilIdle(); | 1044 RunUntilIdle(); |
1041 EXPECT_THAT(run_order, | 1045 EXPECT_THAT(run_order, |
1042 testing::ElementsAre(std::string("C1"), std::string("C2"), | 1046 testing::ElementsAre(std::string("C1"), std::string("C2"), |
1043 std::string("D1"), std::string("D2"))); | 1047 std::string("D1"), std::string("D2"))); |
1044 | 1048 |
1045 run_order.clear(); | 1049 run_order.clear(); |
1046 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1050 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1047 | 1051 |
1048 // Don't post any compositor tasks to simulate a very long running event | 1052 // Don't post any compositor tasks to simulate a very long running event |
1049 // handler. | 1053 // handler. |
1050 PostTestTasks(&run_order, "D1 D2"); | 1054 PostTestTasks(&run_order, "D1 D2"); |
1051 | 1055 |
1052 // Touchstart policy mode should have ended now that the clock has advanced. | 1056 // Touchstart policy mode should have ended now that the clock has advanced. |
1053 RunUntilIdle(); | 1057 RunUntilIdle(); |
1054 EXPECT_THAT(run_order, | 1058 EXPECT_THAT(run_order, |
1055 testing::ElementsAre(std::string("L1"), std::string("D1"), | 1059 testing::ElementsAre(std::string("L1"), std::string("D1"), |
1056 std::string("D2"))); | 1060 std::string("D2"))); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 default_task_runner_->PostTask( | 1110 default_task_runner_->PostTask( |
1107 FROM_HERE, | 1111 FROM_HERE, |
1108 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 1112 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
1109 &is_anticipated_before, &is_anticipated_after)); | 1113 &is_anticipated_before, &is_anticipated_after)); |
1110 RunUntilIdle(); | 1114 RunUntilIdle(); |
1111 // When input is received, the scheduler should indicate that high-priority | 1115 // When input is received, the scheduler should indicate that high-priority |
1112 // work is anticipated. | 1116 // work is anticipated. |
1113 EXPECT_FALSE(is_anticipated_before); | 1117 EXPECT_FALSE(is_anticipated_before); |
1114 EXPECT_TRUE(is_anticipated_after); | 1118 EXPECT_TRUE(is_anticipated_after); |
1115 | 1119 |
1116 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 1120 clock_->Advance(priority_escalation_after_input_duration() * 2); |
1117 simulate_input = false; | 1121 simulate_input = false; |
1118 default_task_runner_->PostTask( | 1122 default_task_runner_->PostTask( |
1119 FROM_HERE, | 1123 FROM_HERE, |
1120 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 1124 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
1121 &is_anticipated_before, &is_anticipated_after)); | 1125 &is_anticipated_before, &is_anticipated_after)); |
1122 RunUntilIdle(); | 1126 RunUntilIdle(); |
1123 // Without additional input, the scheduler should indicate that high-priority | 1127 // Without additional input, the scheduler should indicate that high-priority |
1124 // work is no longer anticipated. | 1128 // work is no longer anticipated. |
1125 EXPECT_FALSE(is_anticipated_before); | 1129 EXPECT_FALSE(is_anticipated_before); |
1126 EXPECT_FALSE(is_anticipated_after); | 1130 EXPECT_FALSE(is_anticipated_after); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 | 1176 |
1173 // An input event should bump us into input priority. | 1177 // An input event should bump us into input priority. |
1174 scheduler_->DidHandleInputEventOnCompositorThread( | 1178 scheduler_->DidHandleInputEventOnCompositorThread( |
1175 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 1179 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
1176 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1180 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1177 RunUntilIdle(); | 1181 RunUntilIdle(); |
1178 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 1182 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
1179 | 1183 |
1180 // Simulate the input event being queued for a very long time. The compositor | 1184 // Simulate the input event being queued for a very long time. The compositor |
1181 // task we post here represents the enqueued input task. | 1185 // task we post here represents the enqueued input task. |
1182 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 1186 clock_->Advance(priority_escalation_after_input_duration() * 2); |
1183 scheduler_->DidHandleInputEventOnMainThread( | 1187 scheduler_->DidHandleInputEventOnMainThread( |
1184 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1188 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
1185 RunUntilIdle(); | 1189 RunUntilIdle(); |
1186 | 1190 |
1187 // Even though we exceeded the input priority escalation period, we should | 1191 // Even though we exceeded the input priority escalation period, we should |
1188 // still be in compositor priority since the input remains queued. | 1192 // still be in compositor priority since the input remains queued. |
1189 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 1193 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
1190 | 1194 |
1191 // After the escalation period ends we should go back into normal mode. | 1195 // After the escalation period ends we should go back into normal mode. |
1192 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 1196 clock_->Advance(priority_escalation_after_input_duration() * 2); |
1193 RunUntilIdle(); | 1197 RunUntilIdle(); |
1194 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 1198 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
1195 } | 1199 } |
1196 | 1200 |
1197 class RendererSchedulerImplWithMockSchedulerTest | 1201 class RendererSchedulerImplWithMockSchedulerTest |
1198 : public RendererSchedulerImplTest { | 1202 : public RendererSchedulerImplTest { |
1199 public: | 1203 public: |
1200 void SetUp() override { | 1204 void SetUp() override { |
1201 mock_task_runner_ = | 1205 mock_task_runner_ = make_scoped_refptr( |
1202 make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_, false)); | 1206 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); |
1203 nestable_task_runner_ = | 1207 nestable_task_runner_ = |
1204 NestableTaskRunnerForTest::Create(mock_task_runner_); | 1208 NestableTaskRunnerForTest::Create(mock_task_runner_); |
1205 mock_scheduler_ = new RendererSchedulerImplForTest(nestable_task_runner_); | 1209 mock_scheduler_ = new RendererSchedulerImplForTest(nestable_task_runner_); |
1206 Initialize(make_scoped_ptr(mock_scheduler_)); | 1210 Initialize(make_scoped_ptr(mock_scheduler_)); |
1207 } | 1211 } |
1208 | 1212 |
1209 protected: | 1213 protected: |
1210 RendererSchedulerImplForTest* mock_scheduler_; | 1214 RendererSchedulerImplForTest* mock_scheduler_; |
1211 }; | 1215 }; |
1212 | 1216 |
1213 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1217 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1214 OnlyOnePendingUrgentPolicyUpdatey) { | 1218 OnlyOnePendingUrgentPolicyUpdatey) { |
1215 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1219 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1216 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1220 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1217 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1221 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1218 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1222 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1219 | 1223 |
1220 RunUntilIdle(); | 1224 RunUntilIdle(); |
1221 | 1225 |
1222 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1226 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1223 } | 1227 } |
1224 | 1228 |
1225 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1229 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1226 OnePendingDelayedAndOneUrgentUpdatePolicy) { | 1230 OnePendingDelayedAndOneUrgentUpdatePolicy) { |
1227 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1231 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1228 | 1232 |
1229 mock_scheduler_->ScheduleDelayedPolicyUpdate( | 1233 mock_scheduler_->ScheduleDelayedPolicyUpdate( |
1230 clock_->Now(), base::TimeDelta::FromMilliseconds(1)); | 1234 clock_->NowTicks(), base::TimeDelta::FromMilliseconds(1)); |
1231 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1235 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1232 | 1236 |
1233 RunUntilIdle(); | 1237 RunUntilIdle(); |
1234 | 1238 |
1235 // We expect both the urgent and the delayed updates to run. | 1239 // We expect both the urgent and the delayed updates to run. |
1236 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1240 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1237 } | 1241 } |
1238 | 1242 |
1239 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1243 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1240 OneUrgentAndOnePendingDelayedUpdatePolicy) { | 1244 OneUrgentAndOnePendingDelayedUpdatePolicy) { |
1241 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1245 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1242 | 1246 |
1243 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1247 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1244 mock_scheduler_->ScheduleDelayedPolicyUpdate( | 1248 mock_scheduler_->ScheduleDelayedPolicyUpdate( |
1245 clock_->Now(), base::TimeDelta::FromMilliseconds(1)); | 1249 clock_->NowTicks(), base::TimeDelta::FromMilliseconds(1)); |
1246 | 1250 |
1247 RunUntilIdle(); | 1251 RunUntilIdle(); |
1248 | 1252 |
1249 // We expect both the urgent and the delayed updates to run. | 1253 // We expect both the urgent and the delayed updates to run. |
1250 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1254 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1251 } | 1255 } |
1252 | 1256 |
1253 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1257 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1254 UpdatePolicyCountTriggeredByOneInputEvent) { | 1258 UpdatePolicyCountTriggeredByOneInputEvent) { |
1255 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy | 1259 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy |
1256 // update. | 1260 // update. |
1257 scheduler_->DidHandleInputEventOnCompositorThread( | 1261 scheduler_->DidHandleInputEventOnCompositorThread( |
1258 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1262 FakeInputEvent(blink::WebInputEvent::TouchStart), |
1259 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1263 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1260 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); | 1264 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); |
1261 mock_task_runner_->RunPendingTasks(); | 1265 mock_task_runner_->RunPendingTasks(); |
1262 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1266 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1263 | 1267 |
1264 scheduler_->DidHandleInputEventOnMainThread( | 1268 scheduler_->DidHandleInputEventOnMainThread( |
1265 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1269 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1266 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1270 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1267 | 1271 |
1268 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1272 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1269 RunUntilIdle(); | 1273 RunUntilIdle(); |
1270 | 1274 |
1271 // We finally expect a delayed policy update 100ms later. | 1275 // We finally expect a delayed policy update 100ms later. |
1272 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1276 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1273 } | 1277 } |
1274 | 1278 |
1275 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1279 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1276 UpdatePolicyCountTriggeredByThreeInputEvents) { | 1280 UpdatePolicyCountTriggeredByThreeInputEvents) { |
1277 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy | 1281 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy |
1278 // update. | 1282 // update. |
(...skipping 28 matching lines...) Expand all Loading... |
1307 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1311 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1308 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1312 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1309 mock_task_runner_->RunPendingTasks(); | 1313 mock_task_runner_->RunPendingTasks(); |
1310 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1314 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1311 | 1315 |
1312 // We expect DidHandleInputEvent to trigger a policy update. | 1316 // We expect DidHandleInputEvent to trigger a policy update. |
1313 scheduler_->DidHandleInputEventOnMainThread( | 1317 scheduler_->DidHandleInputEventOnMainThread( |
1314 FakeInputEvent(blink::WebInputEvent::TouchMove)); | 1318 FakeInputEvent(blink::WebInputEvent::TouchMove)); |
1315 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1319 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1316 | 1320 |
1317 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1321 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1318 RunUntilIdle(); | 1322 RunUntilIdle(); |
1319 | 1323 |
1320 // We finally expect a delayed policy update. | 1324 // We finally expect a delayed policy update. |
1321 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); | 1325 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); |
1322 } | 1326 } |
1323 | 1327 |
1324 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1328 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1325 UpdatePolicyCountTriggeredByTwoInputEventsWithALongSeparatingDelay) { | 1329 UpdatePolicyCountTriggeredByTwoInputEventsWithALongSeparatingDelay) { |
1326 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy | 1330 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy |
1327 // update. | 1331 // update. |
1328 scheduler_->DidHandleInputEventOnCompositorThread( | 1332 scheduler_->DidHandleInputEventOnCompositorThread( |
1329 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1333 FakeInputEvent(blink::WebInputEvent::TouchStart), |
1330 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1334 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1331 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); | 1335 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); |
1332 mock_task_runner_->RunPendingTasks(); | 1336 mock_task_runner_->RunPendingTasks(); |
1333 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1337 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1334 | 1338 |
1335 scheduler_->DidHandleInputEventOnMainThread( | 1339 scheduler_->DidHandleInputEventOnMainThread( |
1336 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1340 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1337 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1341 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1338 | 1342 |
1339 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1343 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1340 RunUntilIdle(); | 1344 RunUntilIdle(); |
1341 // We expect a delayed policy update. | 1345 // We expect a delayed policy update. |
1342 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1346 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1343 | 1347 |
1344 // We expect the second call to DidHandleInputEventOnCompositorThread to post | 1348 // We expect the second call to DidHandleInputEventOnCompositorThread to post |
1345 // an urgent policy update because we are no longer in compositor priority. | 1349 // an urgent policy update because we are no longer in compositor priority. |
1346 scheduler_->DidHandleInputEventOnCompositorThread( | 1350 scheduler_->DidHandleInputEventOnCompositorThread( |
1347 FakeInputEvent(blink::WebInputEvent::TouchMove), | 1351 FakeInputEvent(blink::WebInputEvent::TouchMove), |
1348 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1352 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1349 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1353 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1350 mock_task_runner_->RunPendingTasks(); | 1354 mock_task_runner_->RunPendingTasks(); |
1351 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); | 1355 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); |
1352 | 1356 |
1353 scheduler_->DidHandleInputEventOnMainThread( | 1357 scheduler_->DidHandleInputEventOnMainThread( |
1354 FakeInputEvent(blink::WebInputEvent::TouchMove)); | 1358 FakeInputEvent(blink::WebInputEvent::TouchMove)); |
1355 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); | 1359 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); |
1356 | 1360 |
1357 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1361 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1358 RunUntilIdle(); | 1362 RunUntilIdle(); |
1359 | 1363 |
1360 // We finally expect a delayed policy update. | 1364 // We finally expect a delayed policy update. |
1361 EXPECT_EQ(4, mock_scheduler_->update_policy_count_); | 1365 EXPECT_EQ(4, mock_scheduler_->update_policy_count_); |
1362 } | 1366 } |
1363 | 1367 |
1364 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1368 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1365 EnsureUpdatePolicyNotTriggeredTooOften) { | 1369 EnsureUpdatePolicyNotTriggeredTooOften) { |
1366 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1370 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1367 | 1371 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 EnableIdleTasks(); | 1459 EnableIdleTasks(); |
1456 RunUntilIdle(); | 1460 RunUntilIdle(); |
1457 // Note we expect task 3 to run last because it's non-nestable. | 1461 // Note we expect task 3 to run last because it's non-nestable. |
1458 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"), | 1462 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"), |
1459 std::string("4"), std::string("5"), | 1463 std::string("4"), std::string("5"), |
1460 std::string("3"))); | 1464 std::string("3"))); |
1461 } | 1465 } |
1462 | 1466 |
1463 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) { | 1467 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) { |
1464 base::TimeTicks expected_deadline = | 1468 base::TimeTicks expected_deadline = |
1465 clock_->Now() + maximum_idle_period_duration(); | 1469 clock_->NowTicks() + maximum_idle_period_duration(); |
1466 base::TimeTicks deadline_in_task; | 1470 base::TimeTicks deadline_in_task; |
1467 int run_count = 0; | 1471 int run_count = 0; |
1468 | 1472 |
1469 idle_task_runner_->PostIdleTask( | 1473 idle_task_runner_->PostIdleTask( |
1470 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1474 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1471 | 1475 |
1472 RunUntilIdle(); | 1476 RunUntilIdle(); |
1473 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period. | 1477 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period. |
1474 | 1478 |
1475 scheduler_->BeginFrameNotExpectedSoon(); | 1479 scheduler_->BeginFrameNotExpectedSoon(); |
1476 RunUntilIdle(); | 1480 RunUntilIdle(); |
1477 EXPECT_EQ(1, run_count); // Should have run in a long idle time. | 1481 EXPECT_EQ(1, run_count); // Should have run in a long idle time. |
1478 EXPECT_EQ(expected_deadline, deadline_in_task); | 1482 EXPECT_EQ(expected_deadline, deadline_in_task); |
1479 } | 1483 } |
1480 | 1484 |
1481 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) { | 1485 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) { |
1482 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30); | 1486 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30); |
1483 base::TimeTicks expected_deadline = clock_->Now() + pending_task_delay; | 1487 base::TimeTicks expected_deadline = clock_->NowTicks() + pending_task_delay; |
1484 base::TimeTicks deadline_in_task; | 1488 base::TimeTicks deadline_in_task; |
1485 int run_count = 0; | 1489 int run_count = 0; |
1486 | 1490 |
1487 idle_task_runner_->PostIdleTask( | 1491 idle_task_runner_->PostIdleTask( |
1488 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1492 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1489 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), | 1493 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), |
1490 pending_task_delay); | 1494 pending_task_delay); |
1491 | 1495 |
1492 scheduler_->BeginFrameNotExpectedSoon(); | 1496 scheduler_->BeginFrameNotExpectedSoon(); |
1493 RunUntilIdle(); | 1497 RunUntilIdle(); |
1494 EXPECT_EQ(1, run_count); // Should have run in a long idle time. | 1498 EXPECT_EQ(1, run_count); // Should have run in a long idle time. |
1495 EXPECT_EQ(expected_deadline, deadline_in_task); | 1499 EXPECT_EQ(expected_deadline, deadline_in_task); |
1496 } | 1500 } |
1497 | 1501 |
1498 TEST_F(RendererSchedulerImplTest, | 1502 TEST_F(RendererSchedulerImplTest, |
1499 TestLongIdlePeriodWithLatePendingDelayedTask) { | 1503 TestLongIdlePeriodWithLatePendingDelayedTask) { |
1500 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10); | 1504 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10); |
1501 base::TimeTicks deadline_in_task; | 1505 base::TimeTicks deadline_in_task; |
1502 int run_count = 0; | 1506 int run_count = 0; |
1503 | 1507 |
1504 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), | 1508 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), |
1505 pending_task_delay); | 1509 pending_task_delay); |
1506 | 1510 |
1507 // Advance clock until after delayed task was meant to be run. | 1511 // Advance clock until after delayed task was meant to be run. |
1508 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(20)); | 1512 clock_->Advance(base::TimeDelta::FromMilliseconds(20)); |
1509 | 1513 |
1510 // Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle | 1514 // Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle |
1511 // period. Since there is a late pending delayed task this shouldn't actually | 1515 // period. Since there is a late pending delayed task this shouldn't actually |
1512 // start an idle period. | 1516 // start an idle period. |
1513 idle_task_runner_->PostIdleTask( | 1517 idle_task_runner_->PostIdleTask( |
1514 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1518 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1515 scheduler_->BeginFrameNotExpectedSoon(); | 1519 scheduler_->BeginFrameNotExpectedSoon(); |
1516 RunUntilIdle(); | 1520 RunUntilIdle(); |
1517 EXPECT_EQ(0, run_count); | 1521 EXPECT_EQ(0, run_count); |
1518 | 1522 |
1519 // After the delayed task has been run we should trigger an idle period. | 1523 // After the delayed task has been run we should trigger an idle period. |
1520 clock_->AdvanceNow(maximum_idle_period_duration()); | 1524 clock_->Advance(maximum_idle_period_duration()); |
1521 RunUntilIdle(); | 1525 RunUntilIdle(); |
1522 EXPECT_EQ(1, run_count); | 1526 EXPECT_EQ(1, run_count); |
1523 } | 1527 } |
1524 | 1528 |
1525 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) { | 1529 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) { |
1526 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1530 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1527 std::vector<base::TimeTicks> actual_deadlines; | 1531 std::vector<base::TimeTicks> actual_deadlines; |
1528 int run_count = 0; | 1532 int run_count = 0; |
1529 | 1533 |
1530 max_idle_task_reposts = 3; | 1534 max_idle_task_reposts = 3; |
1531 base::TimeTicks clock_before(clock_->Now()); | 1535 base::TimeTicks clock_before(clock_->NowTicks()); |
1532 base::TimeDelta idle_task_runtime(base::TimeDelta::FromMilliseconds(10)); | 1536 base::TimeDelta idle_task_runtime(base::TimeDelta::FromMilliseconds(10)); |
1533 idle_task_runner_->PostIdleTask( | 1537 idle_task_runner_->PostIdleTask( |
1534 FROM_HERE, | 1538 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, |
1535 base::Bind(&RepostingUpdateClockIdleTestTask, idle_task_runner_, | 1539 idle_task_runner_, &run_count, clock_.get(), |
1536 &run_count, clock_, idle_task_runtime, &actual_deadlines)); | 1540 idle_task_runtime, &actual_deadlines)); |
1537 scheduler_->BeginFrameNotExpectedSoon(); | 1541 scheduler_->BeginFrameNotExpectedSoon(); |
1538 RunUntilIdle(); | 1542 RunUntilIdle(); |
1539 EXPECT_EQ(3, run_count); | 1543 EXPECT_EQ(3, run_count); |
1540 EXPECT_THAT( | 1544 EXPECT_THAT( |
1541 actual_deadlines, | 1545 actual_deadlines, |
1542 testing::ElementsAre( | 1546 testing::ElementsAre( |
1543 clock_before + maximum_idle_period_duration(), | 1547 clock_before + maximum_idle_period_duration(), |
1544 clock_before + idle_task_runtime + maximum_idle_period_duration(), | 1548 clock_before + idle_task_runtime + maximum_idle_period_duration(), |
1545 clock_before + (2 * idle_task_runtime) + | 1549 clock_before + (2 * idle_task_runtime) + |
1546 maximum_idle_period_duration())); | 1550 maximum_idle_period_duration())); |
1547 | 1551 |
1548 // Check that idle tasks don't run after the idle period ends with a | 1552 // Check that idle tasks don't run after the idle period ends with a |
1549 // new BeginMainFrame. | 1553 // new BeginMainFrame. |
1550 max_idle_task_reposts = 5; | 1554 max_idle_task_reposts = 5; |
1551 idle_task_runner_->PostIdleTask( | 1555 idle_task_runner_->PostIdleTask( |
1552 FROM_HERE, | 1556 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, |
1553 base::Bind(&RepostingUpdateClockIdleTestTask, idle_task_runner_, | 1557 idle_task_runner_, &run_count, clock_.get(), |
1554 &run_count, clock_, idle_task_runtime, &actual_deadlines)); | 1558 idle_task_runtime, &actual_deadlines)); |
1555 idle_task_runner_->PostIdleTask( | 1559 idle_task_runner_->PostIdleTask( |
1556 FROM_HERE, base::Bind(&WillBeginFrameIdleTask, | 1560 FROM_HERE, base::Bind(&WillBeginFrameIdleTask, |
1557 base::Unretained(scheduler_.get()), clock_)); | 1561 base::Unretained(scheduler_.get()), clock_.get())); |
1558 RunUntilIdle(); | 1562 RunUntilIdle(); |
1559 EXPECT_EQ(4, run_count); | 1563 EXPECT_EQ(4, run_count); |
1560 } | 1564 } |
1561 | 1565 |
1562 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) { | 1566 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) { |
1563 base::TimeTicks deadline_in_task; | 1567 base::TimeTicks deadline_in_task; |
1564 int run_count = 0; | 1568 int run_count = 0; |
1565 | 1569 |
1566 // Start a long idle period and get the time it should end. | 1570 // Start a long idle period and get the time it should end. |
1567 scheduler_->BeginFrameNotExpectedSoon(); | 1571 scheduler_->BeginFrameNotExpectedSoon(); |
1568 // The scheduler should not run the initiate_next_long_idle_period task if | 1572 // The scheduler should not run the initiate_next_long_idle_period task if |
1569 // there are no idle tasks and no other task woke up the scheduler, thus | 1573 // there are no idle tasks and no other task woke up the scheduler, thus |
1570 // the idle period deadline shouldn't update at the end of the current long | 1574 // the idle period deadline shouldn't update at the end of the current long |
1571 // idle period. | 1575 // idle period. |
1572 base::TimeTicks idle_period_deadline = | 1576 base::TimeTicks idle_period_deadline = |
1573 scheduler_->CurrentIdleTaskDeadlineForTesting(); | 1577 scheduler_->CurrentIdleTaskDeadlineForTesting(); |
1574 clock_->AdvanceNow(maximum_idle_period_duration()); | 1578 clock_->Advance(maximum_idle_period_duration()); |
1575 RunUntilIdle(); | 1579 RunUntilIdle(); |
1576 | 1580 |
1577 base::TimeTicks new_idle_period_deadline = | 1581 base::TimeTicks new_idle_period_deadline = |
1578 scheduler_->CurrentIdleTaskDeadlineForTesting(); | 1582 scheduler_->CurrentIdleTaskDeadlineForTesting(); |
1579 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline); | 1583 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline); |
1580 | 1584 |
1581 // Posting a after-wakeup idle task also shouldn't wake the scheduler or | 1585 // Posting a after-wakeup idle task also shouldn't wake the scheduler or |
1582 // initiate the next long idle period. | 1586 // initiate the next long idle period. |
1583 idle_task_runner_->PostIdleTaskAfterWakeup( | 1587 idle_task_runner_->PostIdleTaskAfterWakeup( |
1584 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1588 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
(...skipping 21 matching lines...) Expand all Loading... |
1606 | 1610 |
1607 // Observation of touchstart should defer the start of the long idle period. | 1611 // Observation of touchstart should defer the start of the long idle period. |
1608 scheduler_->DidHandleInputEventOnCompositorThread( | 1612 scheduler_->DidHandleInputEventOnCompositorThread( |
1609 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1613 FakeInputEvent(blink::WebInputEvent::TouchStart), |
1610 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1614 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
1611 scheduler_->BeginFrameNotExpectedSoon(); | 1615 scheduler_->BeginFrameNotExpectedSoon(); |
1612 RunUntilIdle(); | 1616 RunUntilIdle(); |
1613 EXPECT_EQ(0, run_count); | 1617 EXPECT_EQ(0, run_count); |
1614 | 1618 |
1615 // The long idle period should start after the touchstart policy has finished. | 1619 // The long idle period should start after the touchstart policy has finished. |
1616 clock_->AdvanceNow(priority_escalation_after_input_duration()); | 1620 clock_->Advance(priority_escalation_after_input_duration()); |
1617 RunUntilIdle(); | 1621 RunUntilIdle(); |
1618 EXPECT_EQ(1, run_count); | 1622 EXPECT_EQ(1, run_count); |
1619 } | 1623 } |
1620 | 1624 |
1621 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler, | 1625 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler, |
1622 bool* can_exceed_idle_deadline_out, | 1626 bool* can_exceed_idle_deadline_out, |
1623 int* run_count, | 1627 int* run_count, |
1624 base::TimeTicks deadline) { | 1628 base::TimeTicks deadline) { |
1625 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired(); | 1629 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired(); |
1626 (*run_count)++; | 1630 (*run_count)++; |
(...skipping 24 matching lines...) Expand all Loading... |
1651 FROM_HERE, | 1655 FROM_HERE, |
1652 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), | 1656 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), |
1653 &can_exceed_idle_deadline, &run_count)); | 1657 &can_exceed_idle_deadline, &run_count)); |
1654 scheduler_->BeginFrameNotExpectedSoon(); | 1658 scheduler_->BeginFrameNotExpectedSoon(); |
1655 RunUntilIdle(); | 1659 RunUntilIdle(); |
1656 EXPECT_EQ(2, run_count); | 1660 EXPECT_EQ(2, run_count); |
1657 EXPECT_FALSE(can_exceed_idle_deadline); | 1661 EXPECT_FALSE(can_exceed_idle_deadline); |
1658 | 1662 |
1659 // Next long idle period will be for the maximum time, so | 1663 // Next long idle period will be for the maximum time, so |
1660 // CanExceedIdleDeadlineIfRequired should return true. | 1664 // CanExceedIdleDeadlineIfRequired should return true. |
1661 clock_->AdvanceNow(maximum_idle_period_duration()); | 1665 clock_->Advance(maximum_idle_period_duration()); |
1662 idle_task_runner_->PostIdleTask( | 1666 idle_task_runner_->PostIdleTask( |
1663 FROM_HERE, | 1667 FROM_HERE, |
1664 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), | 1668 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), |
1665 &can_exceed_idle_deadline, &run_count)); | 1669 &can_exceed_idle_deadline, &run_count)); |
1666 RunUntilIdle(); | 1670 RunUntilIdle(); |
1667 EXPECT_EQ(3, run_count); | 1671 EXPECT_EQ(3, run_count); |
1668 EXPECT_TRUE(can_exceed_idle_deadline); | 1672 EXPECT_TRUE(can_exceed_idle_deadline); |
1669 | 1673 |
1670 // Next long idle period will be for the maximum time, so | 1674 // Next long idle period will be for the maximum time, so |
1671 // CanExceedIdleDeadlineIfRequired should return true. | 1675 // CanExceedIdleDeadlineIfRequired should return true. |
1672 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 1676 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
1673 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 1677 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
1674 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 1678 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
1675 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired()); | 1679 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired()); |
1676 } | 1680 } |
1677 | 1681 |
1678 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) { | 1682 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) { |
1679 int run_count = 0; | 1683 int run_count = 0; |
1680 | 1684 |
1681 max_idle_task_reposts = 2; | 1685 max_idle_task_reposts = 2; |
1682 idle_task_runner_->PostIdleTask( | 1686 idle_task_runner_->PostIdleTask( |
1683 FROM_HERE, | 1687 FROM_HERE, |
1684 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); | 1688 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); |
1685 | 1689 |
1686 // Renderer should start in visible state. | 1690 // Renderer should start in visible state. |
1687 RunUntilIdle(); | 1691 RunUntilIdle(); |
1688 EXPECT_EQ(0, run_count); | 1692 EXPECT_EQ(0, run_count); |
1689 | 1693 |
1690 // When we hide the renderer it should start a max deadline idle period, which | 1694 // When we hide the renderer it should start a max deadline idle period, which |
1691 // will run an idle task and then immediately start a new idle period, which | 1695 // will run an idle task and then immediately start a new idle period, which |
1692 // runs the second idle task. | 1696 // runs the second idle task. |
1693 scheduler_->OnRendererHidden(); | 1697 scheduler_->OnRendererHidden(); |
1694 RunUntilIdle(); | 1698 RunUntilIdle(); |
1695 EXPECT_EQ(2, run_count); | 1699 EXPECT_EQ(2, run_count); |
1696 | 1700 |
1697 // Advance time by amount of time by the maximum amount of time we execute | 1701 // Advance time by amount of time by the maximum amount of time we execute |
1698 // idle tasks when hidden (plus some slack) - idle period should have ended. | 1702 // idle tasks when hidden (plus some slack) - idle period should have ended. |
1699 max_idle_task_reposts = 3; | 1703 max_idle_task_reposts = 3; |
1700 idle_task_runner_->PostIdleTask( | 1704 idle_task_runner_->PostIdleTask( |
1701 FROM_HERE, | 1705 FROM_HERE, |
1702 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); | 1706 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); |
1703 clock_->AdvanceNow(end_idle_when_hidden_delay() + | 1707 clock_->Advance(end_idle_when_hidden_delay() + |
1704 base::TimeDelta::FromMilliseconds(10)); | 1708 base::TimeDelta::FromMilliseconds(10)); |
1705 RunUntilIdle(); | 1709 RunUntilIdle(); |
1706 EXPECT_EQ(2, run_count); | 1710 EXPECT_EQ(2, run_count); |
1707 } | 1711 } |
1708 | 1712 |
1709 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) { | 1713 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) { |
1710 std::vector<std::string> run_order; | 1714 std::vector<std::string> run_order; |
1711 PostTestTasks(&run_order, "T1 T2"); | 1715 PostTestTasks(&run_order, "T1 T2"); |
1712 RunUntilIdle(); | 1716 RunUntilIdle(); |
1713 EXPECT_THAT(run_order, | 1717 EXPECT_THAT(run_order, |
1714 testing::ElementsAre(std::string("T1"), std::string("T2"))); | 1718 testing::ElementsAre(std::string("T1"), std::string("T2"))); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the | 1770 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the |
1767 // compositor to not be there and we don't want to make debugging impossible. | 1771 // compositor to not be there and we don't want to make debugging impossible. |
1768 scheduler_->DidHandleInputEventOnMainThread( | 1772 scheduler_->DidHandleInputEventOnMainThread( |
1769 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1773 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
1770 } | 1774 } |
1771 | 1775 |
1772 TEST_F(RendererSchedulerImplTest, BeginMainFrameOnCriticalPath) { | 1776 TEST_F(RendererSchedulerImplTest, BeginMainFrameOnCriticalPath) { |
1773 ASSERT_FALSE(scheduler_->BeginMainFrameOnCriticalPath()); | 1777 ASSERT_FALSE(scheduler_->BeginMainFrameOnCriticalPath()); |
1774 | 1778 |
1775 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create( | 1779 cc::BeginFrameArgs begin_frame_args = cc::BeginFrameArgs::Create( |
1776 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 1780 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
1777 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); | 1781 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); |
1778 scheduler_->WillBeginFrame(begin_frame_args); | 1782 scheduler_->WillBeginFrame(begin_frame_args); |
1779 ASSERT_TRUE(scheduler_->BeginMainFrameOnCriticalPath()); | 1783 ASSERT_TRUE(scheduler_->BeginMainFrameOnCriticalPath()); |
1780 | 1784 |
1781 begin_frame_args.on_critical_path = false; | 1785 begin_frame_args.on_critical_path = false; |
1782 scheduler_->WillBeginFrame(begin_frame_args); | 1786 scheduler_->WillBeginFrame(begin_frame_args); |
1783 ASSERT_FALSE(scheduler_->BeginMainFrameOnCriticalPath()); | 1787 ASSERT_FALSE(scheduler_->BeginMainFrameOnCriticalPath()); |
1784 } | 1788 } |
1785 | 1789 |
1786 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) { | 1790 TEST_F(RendererSchedulerImplTest, ShutdownPreventsPostingOfNewTasks) { |
1787 scheduler_->Shutdown(); | 1791 scheduler_->Shutdown(); |
1788 std::vector<std::string> run_order; | 1792 std::vector<std::string> run_order; |
1789 PostTestTasks(&run_order, "D1 C1"); | 1793 PostTestTasks(&run_order, "D1 C1"); |
1790 RunUntilIdle(); | 1794 RunUntilIdle(); |
1791 EXPECT_TRUE(run_order.empty()); | 1795 EXPECT_TRUE(run_order.empty()); |
1792 } | 1796 } |
1793 | 1797 |
1794 } // namespace scheduler | 1798 } // namespace scheduler |
OLD | NEW |