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 16 matching lines...) Expand all Loading... |
138 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 137 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
139 } | 138 } |
140 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); | 139 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); |
141 } | 140 } |
142 }; // namespace | 141 }; // namespace |
143 | 142 |
144 class RendererSchedulerImplTest : public testing::Test { | 143 class RendererSchedulerImplTest : public testing::Test { |
145 public: | 144 public: |
146 using Policy = RendererSchedulerImpl::Policy; | 145 using Policy = RendererSchedulerImpl::Policy; |
147 | 146 |
148 RendererSchedulerImplTest() : clock_(cc::TestNowSource::Create(5000)) {} | 147 RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) { |
| 148 clock_->Advance(base::TimeDelta::FromInternalValue(5000)); |
| 149 } |
149 | 150 |
150 RendererSchedulerImplTest(base::MessageLoop* message_loop) | 151 RendererSchedulerImplTest(base::MessageLoop* message_loop) |
151 : clock_(cc::TestNowSource::Create(5000)), message_loop_(message_loop) {} | 152 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) { |
| 153 clock_->Advance(base::TimeDelta::FromInternalValue(5000)); |
| 154 } |
152 | 155 |
153 ~RendererSchedulerImplTest() override {} | 156 ~RendererSchedulerImplTest() override {} |
154 | 157 |
155 void SetUp() override { | 158 void SetUp() override { |
156 if (message_loop_) { | 159 if (message_loop_) { |
157 nestable_task_runner_ = | 160 nestable_task_runner_ = |
158 SchedulerMessageLoopDelegate::Create(message_loop_.get()); | 161 SchedulerMessageLoopDelegate::Create(message_loop_.get()); |
159 } else { | 162 } else { |
160 mock_task_runner_ = | 163 mock_task_runner_ = make_scoped_refptr( |
161 make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_, false)); | 164 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); |
162 nestable_task_runner_ = | 165 nestable_task_runner_ = |
163 NestableTaskRunnerForTest::Create(mock_task_runner_); | 166 NestableTaskRunnerForTest::Create(mock_task_runner_); |
164 } | 167 } |
165 Initialize( | 168 Initialize( |
166 make_scoped_ptr(new RendererSchedulerImpl(nestable_task_runner_))); | 169 make_scoped_ptr(new RendererSchedulerImpl(nestable_task_runner_))); |
167 } | 170 } |
168 | 171 |
169 void Initialize(scoped_ptr<RendererSchedulerImpl> scheduler) { | 172 void Initialize(scoped_ptr<RendererSchedulerImpl> scheduler) { |
170 scheduler_ = scheduler.Pass(); | 173 scheduler_ = scheduler.Pass(); |
171 default_task_runner_ = scheduler_->DefaultTaskRunner(); | 174 default_task_runner_ = scheduler_->DefaultTaskRunner(); |
172 compositor_task_runner_ = scheduler_->CompositorTaskRunner(); | 175 compositor_task_runner_ = scheduler_->CompositorTaskRunner(); |
173 loading_task_runner_ = scheduler_->LoadingTaskRunner(); | 176 loading_task_runner_ = scheduler_->LoadingTaskRunner(); |
174 idle_task_runner_ = scheduler_->IdleTaskRunner(); | 177 idle_task_runner_ = scheduler_->IdleTaskRunner(); |
175 timer_task_runner_ = scheduler_->TimerTaskRunner(); | 178 timer_task_runner_ = scheduler_->TimerTaskRunner(); |
176 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 179 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
177 make_scoped_ptr(new TestTimeSource(clock_))); | 180 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
178 scheduler_->GetSchedulerHelperForTesting() | 181 scheduler_->GetSchedulerHelperForTesting() |
179 ->GetTaskQueueManagerForTesting() | 182 ->GetTaskQueueManagerForTesting() |
180 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 183 ->SetTimeSourceForTesting( |
| 184 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
181 } | 185 } |
182 | 186 |
183 void TearDown() override { | 187 void TearDown() override { |
184 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); | 188 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); |
185 scheduler_->Shutdown(); | 189 scheduler_->Shutdown(); |
186 if (mock_task_runner_.get()) { | 190 if (mock_task_runner_.get()) { |
187 // Check that all tests stop posting tasks. | 191 // Check that all tests stop posting tasks. |
188 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 192 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
189 while (mock_task_runner_->RunUntilIdle()) { | 193 while (mock_task_runner_->RunUntilIdle()) { |
190 } | 194 } |
191 } else { | 195 } else { |
192 message_loop_->RunUntilIdle(); | 196 message_loop_->RunUntilIdle(); |
193 } | 197 } |
194 scheduler_.reset(); | 198 scheduler_.reset(); |
195 } | 199 } |
196 | 200 |
197 void RunUntilIdle() { | 201 void RunUntilIdle() { |
198 // Only one of mock_task_runner_ or message_loop_ should be set. | 202 // Only one of mock_task_runner_ or message_loop_ should be set. |
199 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); | 203 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); |
200 if (mock_task_runner_.get()) | 204 if (mock_task_runner_.get()) |
201 mock_task_runner_->RunUntilIdle(); | 205 mock_task_runner_->RunUntilIdle(); |
202 else | 206 else |
203 message_loop_->RunUntilIdle(); | 207 message_loop_->RunUntilIdle(); |
204 } | 208 } |
205 | 209 |
206 void DoMainFrame() { | 210 void DoMainFrame() { |
207 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 211 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
208 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 212 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
209 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 213 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
210 scheduler_->DidCommitFrameToCompositor(); | 214 scheduler_->DidCommitFrameToCompositor(); |
211 } | 215 } |
212 | 216 |
213 void EnableIdleTasks() { DoMainFrame(); } | 217 void EnableIdleTasks() { DoMainFrame(); } |
214 | 218 |
215 Policy CurrentPolicy() { return scheduler_->current_policy_; } | 219 Policy CurrentPolicy() { return scheduler_->current_policy_; } |
216 | 220 |
217 // Helper for posting several tasks of specific types. |task_descriptor| is a | 221 // Helper for posting several tasks of specific types. |task_descriptor| is a |
218 // string with space delimited task identifiers. The first letter of each | 222 // string with space delimited task identifiers. The first letter of each |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 &RendererSchedulerImpl::TaskQueueIdToString); | 293 &RendererSchedulerImpl::TaskQueueIdToString); |
290 } | 294 } |
291 | 295 |
292 static void CheckAllPolicyToString() { | 296 static void CheckAllPolicyToString() { |
293 CallForEachEnumValue<RendererSchedulerImpl::Policy>( | 297 CallForEachEnumValue<RendererSchedulerImpl::Policy>( |
294 RendererSchedulerImpl::Policy::FIRST_POLICY, | 298 RendererSchedulerImpl::Policy::FIRST_POLICY, |
295 RendererSchedulerImpl::Policy::POLICY_COUNT, | 299 RendererSchedulerImpl::Policy::POLICY_COUNT, |
296 &RendererSchedulerImpl::PolicyToString); | 300 &RendererSchedulerImpl::PolicyToString); |
297 } | 301 } |
298 | 302 |
299 scoped_refptr<cc::TestNowSource> clock_; | 303 scoped_ptr<base::SimpleTestTickClock> clock_; |
300 // Only one of mock_task_runner_ or message_loop_ will be set. | 304 // Only one of mock_task_runner_ or message_loop_ will be set. |
301 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 305 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
302 scoped_ptr<base::MessageLoop> message_loop_; | 306 scoped_ptr<base::MessageLoop> message_loop_; |
303 | 307 |
304 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; | 308 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; |
305 scoped_ptr<RendererSchedulerImpl> scheduler_; | 309 scoped_ptr<RendererSchedulerImpl> scheduler_; |
306 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 310 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
307 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 311 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
308 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; | 312 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; |
309 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 313 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_, | 373 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_, |
370 &run_order, &count, 5)); | 374 &run_order, &count, 5)); |
371 RunUntilIdle(); | 375 RunUntilIdle(); |
372 | 376 |
373 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4)); | 377 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4)); |
374 } | 378 } |
375 | 379 |
376 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) { | 380 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) { |
377 int run_count = 0; | 381 int run_count = 0; |
378 base::TimeTicks expected_deadline = | 382 base::TimeTicks expected_deadline = |
379 clock_->Now() + base::TimeDelta::FromMilliseconds(2300); | 383 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(2300); |
380 base::TimeTicks deadline_in_task; | 384 base::TimeTicks deadline_in_task; |
381 | 385 |
382 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 386 clock_->Advance(base::TimeDelta::FromMilliseconds(100)); |
383 idle_task_runner_->PostIdleTask( | 387 idle_task_runner_->PostIdleTask( |
384 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 388 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
385 | 389 |
386 RunUntilIdle(); | 390 RunUntilIdle(); |
387 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame. | 391 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame. |
388 | 392 |
389 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 393 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
390 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 394 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
391 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 395 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
392 RunUntilIdle(); | 396 RunUntilIdle(); |
393 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor. | 397 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor. |
394 | 398 |
395 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1200)); | 399 clock_->Advance(base::TimeDelta::FromMilliseconds(1200)); |
396 scheduler_->DidCommitFrameToCompositor(); | 400 scheduler_->DidCommitFrameToCompositor(); |
397 RunUntilIdle(); | 401 RunUntilIdle(); |
398 EXPECT_EQ(0, run_count); // We missed the deadline. | 402 EXPECT_EQ(0, run_count); // We missed the deadline. |
399 | 403 |
400 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 404 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
401 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 405 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
402 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 406 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
403 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(800)); | 407 clock_->Advance(base::TimeDelta::FromMilliseconds(800)); |
404 scheduler_->DidCommitFrameToCompositor(); | 408 scheduler_->DidCommitFrameToCompositor(); |
405 RunUntilIdle(); | 409 RunUntilIdle(); |
406 EXPECT_EQ(1, run_count); | 410 EXPECT_EQ(1, run_count); |
407 EXPECT_EQ(expected_deadline, deadline_in_task); | 411 EXPECT_EQ(expected_deadline, deadline_in_task); |
408 } | 412 } |
409 | 413 |
410 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) { | 414 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) { |
411 int run_count = 0; | 415 int run_count = 0; |
412 | 416 |
413 max_idle_task_reposts = 2; | 417 max_idle_task_reposts = 2; |
(...skipping 13 matching lines...) Expand all Loading... |
427 EXPECT_EQ(2, run_count); | 431 EXPECT_EQ(2, run_count); |
428 } | 432 } |
429 | 433 |
430 TEST_F(RendererSchedulerImplTest, TestIdleTaskExceedsDeadline) { | 434 TEST_F(RendererSchedulerImplTest, TestIdleTaskExceedsDeadline) { |
431 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 435 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
432 int run_count = 0; | 436 int run_count = 0; |
433 | 437 |
434 // Post two UpdateClockToDeadlineIdleTestTask tasks. | 438 // Post two UpdateClockToDeadlineIdleTestTask tasks. |
435 idle_task_runner_->PostIdleTask( | 439 idle_task_runner_->PostIdleTask( |
436 FROM_HERE, | 440 FROM_HERE, |
437 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, &run_count)); | 441 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), &run_count)); |
438 idle_task_runner_->PostIdleTask( | 442 idle_task_runner_->PostIdleTask( |
439 FROM_HERE, | 443 FROM_HERE, |
440 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, &run_count)); | 444 base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), &run_count)); |
441 | 445 |
442 EnableIdleTasks(); | 446 EnableIdleTasks(); |
443 RunUntilIdle(); | 447 RunUntilIdle(); |
444 // Only the first idle task should execute since it's used up the deadline. | 448 // Only the first idle task should execute since it's used up the deadline. |
445 EXPECT_EQ(1, run_count); | 449 EXPECT_EQ(1, run_count); |
446 | 450 |
447 EnableIdleTasks(); | 451 EnableIdleTasks(); |
448 RunUntilIdle(); | 452 RunUntilIdle(); |
449 // Second task should be run on the next idle period. | 453 // Second task should be run on the next idle period. |
450 EXPECT_EQ(2, run_count); | 454 EXPECT_EQ(2, run_count); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 518 |
515 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) { | 519 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) { |
516 int run_count = 0; | 520 int run_count = 0; |
517 | 521 |
518 base::TimeTicks deadline_in_task; | 522 base::TimeTicks deadline_in_task; |
519 idle_task_runner_->PostIdleTask( | 523 idle_task_runner_->PostIdleTask( |
520 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 524 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
521 | 525 |
522 // Trigger the beginning of an idle period for 1000ms. | 526 // Trigger the beginning of an idle period for 1000ms. |
523 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 527 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
524 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 528 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
525 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 529 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
526 DoMainFrame(); | 530 DoMainFrame(); |
527 | 531 |
528 // End the idle period early (after 500ms), and send a WillBeginFrame which | 532 // End the idle period early (after 500ms), and send a WillBeginFrame which |
529 // specifies that the next idle period should end 1000ms from now. | 533 // specifies that the next idle period should end 1000ms from now. |
530 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(500)); | 534 clock_->Advance(base::TimeDelta::FromMilliseconds(500)); |
531 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 535 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
532 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 536 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
533 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 537 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
534 | 538 |
535 RunUntilIdle(); | 539 RunUntilIdle(); |
536 EXPECT_EQ(0, run_count); // Not currently in an idle period. | 540 EXPECT_EQ(0, run_count); // Not currently in an idle period. |
537 | 541 |
538 // Trigger the start of the idle period before the task to end the previous | 542 // Trigger the start of the idle period before the task to end the previous |
539 // idle period has been triggered. | 543 // idle period has been triggered. |
540 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(400)); | 544 clock_->Advance(base::TimeDelta::FromMilliseconds(400)); |
541 scheduler_->DidCommitFrameToCompositor(); | 545 scheduler_->DidCommitFrameToCompositor(); |
542 | 546 |
543 // Post a task which simulates running until after the previous end idle | 547 // Post a task which simulates running until after the previous end idle |
544 // period delayed task was scheduled for | 548 // period delayed task was scheduled for |
545 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask)); | 549 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask)); |
546 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(300)); | 550 clock_->Advance(base::TimeDelta::FromMilliseconds(300)); |
547 | 551 |
548 RunUntilIdle(); | 552 RunUntilIdle(); |
549 EXPECT_EQ(1, run_count); // We should still be in the new idle period. | 553 EXPECT_EQ(1, run_count); // We should still be in the new idle period. |
550 } | 554 } |
551 | 555 |
552 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { | 556 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { |
553 std::vector<std::string> run_order; | 557 std::vector<std::string> run_order; |
554 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | 558 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); |
555 | 559 |
556 EnableIdleTasks(); | 560 EnableIdleTasks(); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 864 |
861 scheduler_->DidHandleInputEventOnCompositorThread( | 865 scheduler_->DidHandleInputEventOnCompositorThread( |
862 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 866 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
863 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 867 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
864 RunUntilIdle(); | 868 RunUntilIdle(); |
865 EXPECT_THAT(run_order, | 869 EXPECT_THAT(run_order, |
866 testing::ElementsAre(std::string("C1"), std::string("C2"), | 870 testing::ElementsAre(std::string("C1"), std::string("C2"), |
867 std::string("D1"), std::string("D2"))); | 871 std::string("D1"), std::string("D2"))); |
868 | 872 |
869 run_order.clear(); | 873 run_order.clear(); |
870 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 874 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
871 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 875 PostTestTasks(&run_order, "D1 C1 D2 C2"); |
872 | 876 |
873 // Compositor policy mode should have ended now that the clock has advanced. | 877 // Compositor policy mode should have ended now that the clock has advanced. |
874 RunUntilIdle(); | 878 RunUntilIdle(); |
875 EXPECT_THAT(run_order, | 879 EXPECT_THAT(run_order, |
876 testing::ElementsAre(std::string("D1"), std::string("C1"), | 880 testing::ElementsAre(std::string("D1"), std::string("C1"), |
877 std::string("D2"), std::string("C2"))); | 881 std::string("D2"), std::string("C2"))); |
878 } | 882 } |
879 | 883 |
880 TEST_F(RendererSchedulerImplTest, | 884 TEST_F(RendererSchedulerImplTest, |
881 TestCompositorPolicyEnds_MainThreadHandlesInput) { | 885 TestCompositorPolicyEnds_MainThreadHandlesInput) { |
882 std::vector<std::string> run_order; | 886 std::vector<std::string> run_order; |
883 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 887 PostTestTasks(&run_order, "D1 C1 D2 C2"); |
884 | 888 |
885 scheduler_->DidHandleInputEventOnCompositorThread( | 889 scheduler_->DidHandleInputEventOnCompositorThread( |
886 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 890 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
887 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 891 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
888 scheduler_->DidHandleInputEventOnMainThread( | 892 scheduler_->DidHandleInputEventOnMainThread( |
889 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 893 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
890 RunUntilIdle(); | 894 RunUntilIdle(); |
891 EXPECT_THAT(run_order, | 895 EXPECT_THAT(run_order, |
892 testing::ElementsAre(std::string("C1"), std::string("C2"), | 896 testing::ElementsAre(std::string("C1"), std::string("C2"), |
893 std::string("D1"), std::string("D2"))); | 897 std::string("D1"), std::string("D2"))); |
894 | 898 |
895 run_order.clear(); | 899 run_order.clear(); |
896 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 900 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
897 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 901 PostTestTasks(&run_order, "D1 C1 D2 C2"); |
898 | 902 |
899 // Compositor policy mode should have ended now that the clock has advanced. | 903 // Compositor policy mode should have ended now that the clock has advanced. |
900 RunUntilIdle(); | 904 RunUntilIdle(); |
901 EXPECT_THAT(run_order, | 905 EXPECT_THAT(run_order, |
902 testing::ElementsAre(std::string("D1"), std::string("C1"), | 906 testing::ElementsAre(std::string("D1"), std::string("C1"), |
903 std::string("D2"), std::string("C2"))); | 907 std::string("D2"), std::string("C2"))); |
904 } | 908 } |
905 | 909 |
906 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { | 910 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { |
907 std::vector<std::string> run_order; | 911 std::vector<std::string> run_order; |
908 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); | 912 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); |
909 | 913 |
910 scheduler_->DidHandleInputEventOnCompositorThread( | 914 scheduler_->DidHandleInputEventOnCompositorThread( |
911 FakeInputEvent(blink::WebInputEvent::TouchStart), | 915 FakeInputEvent(blink::WebInputEvent::TouchStart), |
912 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 916 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
913 RunUntilIdle(); | 917 RunUntilIdle(); |
914 EXPECT_THAT(run_order, | 918 EXPECT_THAT(run_order, |
915 testing::ElementsAre(std::string("C1"), std::string("C2"), | 919 testing::ElementsAre(std::string("C1"), std::string("C2"), |
916 std::string("D1"), std::string("D2"))); | 920 std::string("D1"), std::string("D2"))); |
917 | 921 |
918 run_order.clear(); | 922 run_order.clear(); |
919 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 923 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
920 | 924 |
921 // Don't post any compositor tasks to simulate a very long running event | 925 // Don't post any compositor tasks to simulate a very long running event |
922 // handler. | 926 // handler. |
923 PostTestTasks(&run_order, "D1 D2"); | 927 PostTestTasks(&run_order, "D1 D2"); |
924 | 928 |
925 // Touchstart policy mode should have ended now that the clock has advanced. | 929 // Touchstart policy mode should have ended now that the clock has advanced. |
926 RunUntilIdle(); | 930 RunUntilIdle(); |
927 EXPECT_THAT(run_order, | 931 EXPECT_THAT(run_order, |
928 testing::ElementsAre(std::string("L1"), std::string("D1"), | 932 testing::ElementsAre(std::string("L1"), std::string("D1"), |
929 std::string("D2"))); | 933 std::string("D2"))); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 default_task_runner_->PostTask( | 983 default_task_runner_->PostTask( |
980 FROM_HERE, | 984 FROM_HERE, |
981 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 985 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
982 &is_anticipated_before, &is_anticipated_after)); | 986 &is_anticipated_before, &is_anticipated_after)); |
983 RunUntilIdle(); | 987 RunUntilIdle(); |
984 // When input is received, the scheduler should indicate that high-priority | 988 // When input is received, the scheduler should indicate that high-priority |
985 // work is anticipated. | 989 // work is anticipated. |
986 EXPECT_FALSE(is_anticipated_before); | 990 EXPECT_FALSE(is_anticipated_before); |
987 EXPECT_TRUE(is_anticipated_after); | 991 EXPECT_TRUE(is_anticipated_after); |
988 | 992 |
989 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 993 clock_->Advance(priority_escalation_after_input_duration() * 2); |
990 simulate_input = false; | 994 simulate_input = false; |
991 default_task_runner_->PostTask( | 995 default_task_runner_->PostTask( |
992 FROM_HERE, | 996 FROM_HERE, |
993 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 997 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
994 &is_anticipated_before, &is_anticipated_after)); | 998 &is_anticipated_before, &is_anticipated_after)); |
995 RunUntilIdle(); | 999 RunUntilIdle(); |
996 // Without additional input, the scheduler should indicate that high-priority | 1000 // Without additional input, the scheduler should indicate that high-priority |
997 // work is no longer anticipated. | 1001 // work is no longer anticipated. |
998 EXPECT_FALSE(is_anticipated_before); | 1002 EXPECT_FALSE(is_anticipated_before); |
999 EXPECT_FALSE(is_anticipated_after); | 1003 EXPECT_FALSE(is_anticipated_after); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 | 1049 |
1046 // An input event should bump us into input priority. | 1050 // An input event should bump us into input priority. |
1047 scheduler_->DidHandleInputEventOnCompositorThread( | 1051 scheduler_->DidHandleInputEventOnCompositorThread( |
1048 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), | 1052 FakeInputEvent(blink::WebInputEvent::GestureFlingStart), |
1049 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1053 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1050 RunUntilIdle(); | 1054 RunUntilIdle(); |
1051 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 1055 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
1052 | 1056 |
1053 // Simulate the input event being queued for a very long time. The compositor | 1057 // Simulate the input event being queued for a very long time. The compositor |
1054 // task we post here represents the enqueued input task. | 1058 // task we post here represents the enqueued input task. |
1055 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 1059 clock_->Advance(priority_escalation_after_input_duration() * 2); |
1056 scheduler_->DidHandleInputEventOnMainThread( | 1060 scheduler_->DidHandleInputEventOnMainThread( |
1057 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1061 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
1058 RunUntilIdle(); | 1062 RunUntilIdle(); |
1059 | 1063 |
1060 // Even though we exceeded the input priority escalation period, we should | 1064 // Even though we exceeded the input priority escalation period, we should |
1061 // still be in compositor priority since the input remains queued. | 1065 // still be in compositor priority since the input remains queued. |
1062 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 1066 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
1063 | 1067 |
1064 // After the escalation period ends we should go back into normal mode. | 1068 // After the escalation period ends we should go back into normal mode. |
1065 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 1069 clock_->Advance(priority_escalation_after_input_duration() * 2); |
1066 RunUntilIdle(); | 1070 RunUntilIdle(); |
1067 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 1071 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
1068 } | 1072 } |
1069 | 1073 |
1070 class RendererSchedulerImplWithMockSchedulerTest | 1074 class RendererSchedulerImplWithMockSchedulerTest |
1071 : public RendererSchedulerImplTest { | 1075 : public RendererSchedulerImplTest { |
1072 public: | 1076 public: |
1073 void SetUp() override { | 1077 void SetUp() override { |
1074 mock_task_runner_ = | 1078 mock_task_runner_ = make_scoped_refptr( |
1075 make_scoped_refptr(new cc::OrderedSimpleTaskRunner(clock_, false)); | 1079 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); |
1076 nestable_task_runner_ = | 1080 nestable_task_runner_ = |
1077 NestableTaskRunnerForTest::Create(mock_task_runner_); | 1081 NestableTaskRunnerForTest::Create(mock_task_runner_); |
1078 mock_scheduler_ = new RendererSchedulerImplForTest(nestable_task_runner_); | 1082 mock_scheduler_ = new RendererSchedulerImplForTest(nestable_task_runner_); |
1079 Initialize(make_scoped_ptr(mock_scheduler_)); | 1083 Initialize(make_scoped_ptr(mock_scheduler_)); |
1080 } | 1084 } |
1081 | 1085 |
1082 protected: | 1086 protected: |
1083 RendererSchedulerImplForTest* mock_scheduler_; | 1087 RendererSchedulerImplForTest* mock_scheduler_; |
1084 }; | 1088 }; |
1085 | 1089 |
1086 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1090 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1087 OnlyOnePendingUrgentPolicyUpdatey) { | 1091 OnlyOnePendingUrgentPolicyUpdatey) { |
1088 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1092 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1089 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1093 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1090 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1094 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1091 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1095 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1092 | 1096 |
1093 RunUntilIdle(); | 1097 RunUntilIdle(); |
1094 | 1098 |
1095 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1099 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1096 } | 1100 } |
1097 | 1101 |
1098 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1102 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1099 OnePendingDelayedAndOneUrgentUpdatePolicy) { | 1103 OnePendingDelayedAndOneUrgentUpdatePolicy) { |
1100 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1104 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1101 | 1105 |
1102 mock_scheduler_->ScheduleDelayedPolicyUpdate( | 1106 mock_scheduler_->ScheduleDelayedPolicyUpdate( |
1103 clock_->Now(), base::TimeDelta::FromMilliseconds(1)); | 1107 clock_->NowTicks(), base::TimeDelta::FromMilliseconds(1)); |
1104 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1108 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1105 | 1109 |
1106 RunUntilIdle(); | 1110 RunUntilIdle(); |
1107 | 1111 |
1108 // We expect both the urgent and the delayed updates to run. | 1112 // We expect both the urgent and the delayed updates to run. |
1109 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1113 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1110 } | 1114 } |
1111 | 1115 |
1112 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1116 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1113 OneUrgentAndOnePendingDelayedUpdatePolicy) { | 1117 OneUrgentAndOnePendingDelayedUpdatePolicy) { |
1114 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1118 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1115 | 1119 |
1116 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1120 mock_scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1117 mock_scheduler_->ScheduleDelayedPolicyUpdate( | 1121 mock_scheduler_->ScheduleDelayedPolicyUpdate( |
1118 clock_->Now(), base::TimeDelta::FromMilliseconds(1)); | 1122 clock_->NowTicks(), base::TimeDelta::FromMilliseconds(1)); |
1119 | 1123 |
1120 RunUntilIdle(); | 1124 RunUntilIdle(); |
1121 | 1125 |
1122 // We expect both the urgent and the delayed updates to run. | 1126 // We expect both the urgent and the delayed updates to run. |
1123 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1127 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1124 } | 1128 } |
1125 | 1129 |
1126 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1130 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1127 UpdatePolicyCountTriggeredByOneInputEvent) { | 1131 UpdatePolicyCountTriggeredByOneInputEvent) { |
1128 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy | 1132 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy |
1129 // update. | 1133 // update. |
1130 scheduler_->DidHandleInputEventOnCompositorThread( | 1134 scheduler_->DidHandleInputEventOnCompositorThread( |
1131 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1135 FakeInputEvent(blink::WebInputEvent::TouchStart), |
1132 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1136 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1133 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); | 1137 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); |
1134 mock_task_runner_->RunPendingTasks(); | 1138 mock_task_runner_->RunPendingTasks(); |
1135 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1139 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1136 | 1140 |
1137 scheduler_->DidHandleInputEventOnMainThread( | 1141 scheduler_->DidHandleInputEventOnMainThread( |
1138 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1142 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1139 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1143 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1140 | 1144 |
1141 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1145 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1142 RunUntilIdle(); | 1146 RunUntilIdle(); |
1143 | 1147 |
1144 // We finally expect a delayed policy update 100ms later. | 1148 // We finally expect a delayed policy update 100ms later. |
1145 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1149 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1146 } | 1150 } |
1147 | 1151 |
1148 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1152 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1149 UpdatePolicyCountTriggeredByThreeInputEvents) { | 1153 UpdatePolicyCountTriggeredByThreeInputEvents) { |
1150 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy | 1154 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy |
1151 // update. | 1155 // update. |
(...skipping 28 matching lines...) Expand all Loading... |
1180 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1184 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1181 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1185 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1182 mock_task_runner_->RunPendingTasks(); | 1186 mock_task_runner_->RunPendingTasks(); |
1183 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1187 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1184 | 1188 |
1185 // We expect DidHandleInputEvent to trigger a policy update. | 1189 // We expect DidHandleInputEvent to trigger a policy update. |
1186 scheduler_->DidHandleInputEventOnMainThread( | 1190 scheduler_->DidHandleInputEventOnMainThread( |
1187 FakeInputEvent(blink::WebInputEvent::TouchMove)); | 1191 FakeInputEvent(blink::WebInputEvent::TouchMove)); |
1188 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1192 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1189 | 1193 |
1190 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1194 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1191 RunUntilIdle(); | 1195 RunUntilIdle(); |
1192 | 1196 |
1193 // We finally expect a delayed policy update. | 1197 // We finally expect a delayed policy update. |
1194 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); | 1198 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); |
1195 } | 1199 } |
1196 | 1200 |
1197 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1201 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1198 UpdatePolicyCountTriggeredByTwoInputEventsWithALongSeparatingDelay) { | 1202 UpdatePolicyCountTriggeredByTwoInputEventsWithALongSeparatingDelay) { |
1199 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy | 1203 // We expect DidHandleInputEventOnCompositorThread to post an urgent policy |
1200 // update. | 1204 // update. |
1201 scheduler_->DidHandleInputEventOnCompositorThread( | 1205 scheduler_->DidHandleInputEventOnCompositorThread( |
1202 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1206 FakeInputEvent(blink::WebInputEvent::TouchStart), |
1203 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1207 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1204 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); | 1208 EXPECT_EQ(0, mock_scheduler_->update_policy_count_); |
1205 mock_task_runner_->RunPendingTasks(); | 1209 mock_task_runner_->RunPendingTasks(); |
1206 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1210 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1207 | 1211 |
1208 scheduler_->DidHandleInputEventOnMainThread( | 1212 scheduler_->DidHandleInputEventOnMainThread( |
1209 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1213 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1210 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); | 1214 EXPECT_EQ(1, mock_scheduler_->update_policy_count_); |
1211 | 1215 |
1212 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1216 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1213 RunUntilIdle(); | 1217 RunUntilIdle(); |
1214 // We expect a delayed policy update. | 1218 // We expect a delayed policy update. |
1215 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1219 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1216 | 1220 |
1217 // We expect the second call to DidHandleInputEventOnCompositorThread to post | 1221 // We expect the second call to DidHandleInputEventOnCompositorThread to post |
1218 // an urgent policy update because we are no longer in compositor priority. | 1222 // an urgent policy update because we are no longer in compositor priority. |
1219 scheduler_->DidHandleInputEventOnCompositorThread( | 1223 scheduler_->DidHandleInputEventOnCompositorThread( |
1220 FakeInputEvent(blink::WebInputEvent::TouchMove), | 1224 FakeInputEvent(blink::WebInputEvent::TouchMove), |
1221 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); | 1225 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD); |
1222 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); | 1226 EXPECT_EQ(2, mock_scheduler_->update_policy_count_); |
1223 mock_task_runner_->RunPendingTasks(); | 1227 mock_task_runner_->RunPendingTasks(); |
1224 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); | 1228 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); |
1225 | 1229 |
1226 scheduler_->DidHandleInputEventOnMainThread( | 1230 scheduler_->DidHandleInputEventOnMainThread( |
1227 FakeInputEvent(blink::WebInputEvent::TouchMove)); | 1231 FakeInputEvent(blink::WebInputEvent::TouchMove)); |
1228 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); | 1232 EXPECT_EQ(3, mock_scheduler_->update_policy_count_); |
1229 | 1233 |
1230 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 1234 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
1231 RunUntilIdle(); | 1235 RunUntilIdle(); |
1232 | 1236 |
1233 // We finally expect a delayed policy update. | 1237 // We finally expect a delayed policy update. |
1234 EXPECT_EQ(4, mock_scheduler_->update_policy_count_); | 1238 EXPECT_EQ(4, mock_scheduler_->update_policy_count_); |
1235 } | 1239 } |
1236 | 1240 |
1237 TEST_F(RendererSchedulerImplWithMockSchedulerTest, | 1241 TEST_F(RendererSchedulerImplWithMockSchedulerTest, |
1238 EnsureUpdatePolicyNotTriggeredTooOften) { | 1242 EnsureUpdatePolicyNotTriggeredTooOften) { |
1239 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1243 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1240 | 1244 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 EnableIdleTasks(); | 1332 EnableIdleTasks(); |
1329 RunUntilIdle(); | 1333 RunUntilIdle(); |
1330 // Note we expect task 3 to run last because it's non-nestable. | 1334 // Note we expect task 3 to run last because it's non-nestable. |
1331 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"), | 1335 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"), |
1332 std::string("4"), std::string("5"), | 1336 std::string("4"), std::string("5"), |
1333 std::string("3"))); | 1337 std::string("3"))); |
1334 } | 1338 } |
1335 | 1339 |
1336 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) { | 1340 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) { |
1337 base::TimeTicks expected_deadline = | 1341 base::TimeTicks expected_deadline = |
1338 clock_->Now() + maximum_idle_period_duration(); | 1342 clock_->NowTicks() + maximum_idle_period_duration(); |
1339 base::TimeTicks deadline_in_task; | 1343 base::TimeTicks deadline_in_task; |
1340 int run_count = 0; | 1344 int run_count = 0; |
1341 | 1345 |
1342 idle_task_runner_->PostIdleTask( | 1346 idle_task_runner_->PostIdleTask( |
1343 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1347 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1344 | 1348 |
1345 RunUntilIdle(); | 1349 RunUntilIdle(); |
1346 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period. | 1350 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period. |
1347 | 1351 |
1348 scheduler_->BeginFrameNotExpectedSoon(); | 1352 scheduler_->BeginFrameNotExpectedSoon(); |
1349 RunUntilIdle(); | 1353 RunUntilIdle(); |
1350 EXPECT_EQ(1, run_count); // Should have run in a long idle time. | 1354 EXPECT_EQ(1, run_count); // Should have run in a long idle time. |
1351 EXPECT_EQ(expected_deadline, deadline_in_task); | 1355 EXPECT_EQ(expected_deadline, deadline_in_task); |
1352 } | 1356 } |
1353 | 1357 |
1354 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) { | 1358 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) { |
1355 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30); | 1359 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30); |
1356 base::TimeTicks expected_deadline = clock_->Now() + pending_task_delay; | 1360 base::TimeTicks expected_deadline = clock_->NowTicks() + pending_task_delay; |
1357 base::TimeTicks deadline_in_task; | 1361 base::TimeTicks deadline_in_task; |
1358 int run_count = 0; | 1362 int run_count = 0; |
1359 | 1363 |
1360 idle_task_runner_->PostIdleTask( | 1364 idle_task_runner_->PostIdleTask( |
1361 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1365 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1362 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), | 1366 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), |
1363 pending_task_delay); | 1367 pending_task_delay); |
1364 | 1368 |
1365 scheduler_->BeginFrameNotExpectedSoon(); | 1369 scheduler_->BeginFrameNotExpectedSoon(); |
1366 RunUntilIdle(); | 1370 RunUntilIdle(); |
1367 EXPECT_EQ(1, run_count); // Should have run in a long idle time. | 1371 EXPECT_EQ(1, run_count); // Should have run in a long idle time. |
1368 EXPECT_EQ(expected_deadline, deadline_in_task); | 1372 EXPECT_EQ(expected_deadline, deadline_in_task); |
1369 } | 1373 } |
1370 | 1374 |
1371 TEST_F(RendererSchedulerImplTest, | 1375 TEST_F(RendererSchedulerImplTest, |
1372 TestLongIdlePeriodWithLatePendingDelayedTask) { | 1376 TestLongIdlePeriodWithLatePendingDelayedTask) { |
1373 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10); | 1377 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10); |
1374 base::TimeTicks deadline_in_task; | 1378 base::TimeTicks deadline_in_task; |
1375 int run_count = 0; | 1379 int run_count = 0; |
1376 | 1380 |
1377 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), | 1381 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), |
1378 pending_task_delay); | 1382 pending_task_delay); |
1379 | 1383 |
1380 // Advance clock until after delayed task was meant to be run. | 1384 // Advance clock until after delayed task was meant to be run. |
1381 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(20)); | 1385 clock_->Advance(base::TimeDelta::FromMilliseconds(20)); |
1382 | 1386 |
1383 // Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle | 1387 // Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle |
1384 // period. Since there is a late pending delayed task this shouldn't actually | 1388 // period. Since there is a late pending delayed task this shouldn't actually |
1385 // start an idle period. | 1389 // start an idle period. |
1386 idle_task_runner_->PostIdleTask( | 1390 idle_task_runner_->PostIdleTask( |
1387 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1391 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1388 scheduler_->BeginFrameNotExpectedSoon(); | 1392 scheduler_->BeginFrameNotExpectedSoon(); |
1389 RunUntilIdle(); | 1393 RunUntilIdle(); |
1390 EXPECT_EQ(0, run_count); | 1394 EXPECT_EQ(0, run_count); |
1391 | 1395 |
1392 // After the delayed task has been run we should trigger an idle period. | 1396 // After the delayed task has been run we should trigger an idle period. |
1393 clock_->AdvanceNow(maximum_idle_period_duration()); | 1397 clock_->Advance(maximum_idle_period_duration()); |
1394 RunUntilIdle(); | 1398 RunUntilIdle(); |
1395 EXPECT_EQ(1, run_count); | 1399 EXPECT_EQ(1, run_count); |
1396 } | 1400 } |
1397 | 1401 |
1398 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) { | 1402 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) { |
1399 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1403 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1400 std::vector<base::TimeTicks> actual_deadlines; | 1404 std::vector<base::TimeTicks> actual_deadlines; |
1401 int run_count = 0; | 1405 int run_count = 0; |
1402 | 1406 |
1403 max_idle_task_reposts = 3; | 1407 max_idle_task_reposts = 3; |
1404 base::TimeTicks clock_before(clock_->Now()); | 1408 base::TimeTicks clock_before(clock_->NowTicks()); |
1405 base::TimeDelta idle_task_runtime(base::TimeDelta::FromMilliseconds(10)); | 1409 base::TimeDelta idle_task_runtime(base::TimeDelta::FromMilliseconds(10)); |
1406 idle_task_runner_->PostIdleTask( | 1410 idle_task_runner_->PostIdleTask( |
1407 FROM_HERE, | 1411 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, |
1408 base::Bind(&RepostingUpdateClockIdleTestTask, idle_task_runner_, | 1412 idle_task_runner_, &run_count, clock_.get(), |
1409 &run_count, clock_, idle_task_runtime, &actual_deadlines)); | 1413 idle_task_runtime, &actual_deadlines)); |
1410 scheduler_->BeginFrameNotExpectedSoon(); | 1414 scheduler_->BeginFrameNotExpectedSoon(); |
1411 RunUntilIdle(); | 1415 RunUntilIdle(); |
1412 EXPECT_EQ(3, run_count); | 1416 EXPECT_EQ(3, run_count); |
1413 EXPECT_THAT( | 1417 EXPECT_THAT( |
1414 actual_deadlines, | 1418 actual_deadlines, |
1415 testing::ElementsAre( | 1419 testing::ElementsAre( |
1416 clock_before + maximum_idle_period_duration(), | 1420 clock_before + maximum_idle_period_duration(), |
1417 clock_before + idle_task_runtime + maximum_idle_period_duration(), | 1421 clock_before + idle_task_runtime + maximum_idle_period_duration(), |
1418 clock_before + (2 * idle_task_runtime) + | 1422 clock_before + (2 * idle_task_runtime) + |
1419 maximum_idle_period_duration())); | 1423 maximum_idle_period_duration())); |
1420 | 1424 |
1421 // Check that idle tasks don't run after the idle period ends with a | 1425 // Check that idle tasks don't run after the idle period ends with a |
1422 // new BeginMainFrame. | 1426 // new BeginMainFrame. |
1423 max_idle_task_reposts = 5; | 1427 max_idle_task_reposts = 5; |
1424 idle_task_runner_->PostIdleTask( | 1428 idle_task_runner_->PostIdleTask( |
1425 FROM_HERE, | 1429 FROM_HERE, base::Bind(&RepostingUpdateClockIdleTestTask, |
1426 base::Bind(&RepostingUpdateClockIdleTestTask, idle_task_runner_, | 1430 idle_task_runner_, &run_count, clock_.get(), |
1427 &run_count, clock_, idle_task_runtime, &actual_deadlines)); | 1431 idle_task_runtime, &actual_deadlines)); |
1428 idle_task_runner_->PostIdleTask( | 1432 idle_task_runner_->PostIdleTask( |
1429 FROM_HERE, base::Bind(&WillBeginFrameIdleTask, | 1433 FROM_HERE, base::Bind(&WillBeginFrameIdleTask, |
1430 base::Unretained(scheduler_.get()), clock_)); | 1434 base::Unretained(scheduler_.get()), clock_.get())); |
1431 RunUntilIdle(); | 1435 RunUntilIdle(); |
1432 EXPECT_EQ(4, run_count); | 1436 EXPECT_EQ(4, run_count); |
1433 } | 1437 } |
1434 | 1438 |
1435 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) { | 1439 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) { |
1436 base::TimeTicks deadline_in_task; | 1440 base::TimeTicks deadline_in_task; |
1437 int run_count = 0; | 1441 int run_count = 0; |
1438 | 1442 |
1439 // Start a long idle period and get the time it should end. | 1443 // Start a long idle period and get the time it should end. |
1440 scheduler_->BeginFrameNotExpectedSoon(); | 1444 scheduler_->BeginFrameNotExpectedSoon(); |
1441 // The scheduler should not run the initiate_next_long_idle_period task if | 1445 // The scheduler should not run the initiate_next_long_idle_period task if |
1442 // there are no idle tasks and no other task woke up the scheduler, thus | 1446 // there are no idle tasks and no other task woke up the scheduler, thus |
1443 // the idle period deadline shouldn't update at the end of the current long | 1447 // the idle period deadline shouldn't update at the end of the current long |
1444 // idle period. | 1448 // idle period. |
1445 base::TimeTicks idle_period_deadline = | 1449 base::TimeTicks idle_period_deadline = |
1446 scheduler_->CurrentIdleTaskDeadlineForTesting(); | 1450 scheduler_->CurrentIdleTaskDeadlineForTesting(); |
1447 clock_->AdvanceNow(maximum_idle_period_duration()); | 1451 clock_->Advance(maximum_idle_period_duration()); |
1448 RunUntilIdle(); | 1452 RunUntilIdle(); |
1449 | 1453 |
1450 base::TimeTicks new_idle_period_deadline = | 1454 base::TimeTicks new_idle_period_deadline = |
1451 scheduler_->CurrentIdleTaskDeadlineForTesting(); | 1455 scheduler_->CurrentIdleTaskDeadlineForTesting(); |
1452 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline); | 1456 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline); |
1453 | 1457 |
1454 // Posting a after-wakeup idle task also shouldn't wake the scheduler or | 1458 // Posting a after-wakeup idle task also shouldn't wake the scheduler or |
1455 // initiate the next long idle period. | 1459 // initiate the next long idle period. |
1456 idle_task_runner_->PostIdleTaskAfterWakeup( | 1460 idle_task_runner_->PostIdleTaskAfterWakeup( |
1457 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1461 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
(...skipping 21 matching lines...) Expand all Loading... |
1479 | 1483 |
1480 // Observation of touchstart should defer the start of the long idle period. | 1484 // Observation of touchstart should defer the start of the long idle period. |
1481 scheduler_->DidHandleInputEventOnCompositorThread( | 1485 scheduler_->DidHandleInputEventOnCompositorThread( |
1482 FakeInputEvent(blink::WebInputEvent::TouchStart), | 1486 FakeInputEvent(blink::WebInputEvent::TouchStart), |
1483 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); | 1487 RendererScheduler::InputEventState::EVENT_CONSUMED_BY_COMPOSITOR); |
1484 scheduler_->BeginFrameNotExpectedSoon(); | 1488 scheduler_->BeginFrameNotExpectedSoon(); |
1485 RunUntilIdle(); | 1489 RunUntilIdle(); |
1486 EXPECT_EQ(0, run_count); | 1490 EXPECT_EQ(0, run_count); |
1487 | 1491 |
1488 // The long idle period should start after the touchstart policy has finished. | 1492 // The long idle period should start after the touchstart policy has finished. |
1489 clock_->AdvanceNow(priority_escalation_after_input_duration()); | 1493 clock_->Advance(priority_escalation_after_input_duration()); |
1490 RunUntilIdle(); | 1494 RunUntilIdle(); |
1491 EXPECT_EQ(1, run_count); | 1495 EXPECT_EQ(1, run_count); |
1492 } | 1496 } |
1493 | 1497 |
1494 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler, | 1498 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler, |
1495 bool* can_exceed_idle_deadline_out, | 1499 bool* can_exceed_idle_deadline_out, |
1496 int* run_count, | 1500 int* run_count, |
1497 base::TimeTicks deadline) { | 1501 base::TimeTicks deadline) { |
1498 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired(); | 1502 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired(); |
1499 (*run_count)++; | 1503 (*run_count)++; |
(...skipping 24 matching lines...) Expand all Loading... |
1524 FROM_HERE, | 1528 FROM_HERE, |
1525 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), | 1529 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), |
1526 &can_exceed_idle_deadline, &run_count)); | 1530 &can_exceed_idle_deadline, &run_count)); |
1527 scheduler_->BeginFrameNotExpectedSoon(); | 1531 scheduler_->BeginFrameNotExpectedSoon(); |
1528 RunUntilIdle(); | 1532 RunUntilIdle(); |
1529 EXPECT_EQ(2, run_count); | 1533 EXPECT_EQ(2, run_count); |
1530 EXPECT_FALSE(can_exceed_idle_deadline); | 1534 EXPECT_FALSE(can_exceed_idle_deadline); |
1531 | 1535 |
1532 // Next long idle period will be for the maximum time, so | 1536 // Next long idle period will be for the maximum time, so |
1533 // CanExceedIdleDeadlineIfRequired should return true. | 1537 // CanExceedIdleDeadlineIfRequired should return true. |
1534 clock_->AdvanceNow(maximum_idle_period_duration()); | 1538 clock_->Advance(maximum_idle_period_duration()); |
1535 idle_task_runner_->PostIdleTask( | 1539 idle_task_runner_->PostIdleTask( |
1536 FROM_HERE, | 1540 FROM_HERE, |
1537 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), | 1541 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), |
1538 &can_exceed_idle_deadline, &run_count)); | 1542 &can_exceed_idle_deadline, &run_count)); |
1539 RunUntilIdle(); | 1543 RunUntilIdle(); |
1540 EXPECT_EQ(3, run_count); | 1544 EXPECT_EQ(3, run_count); |
1541 EXPECT_TRUE(can_exceed_idle_deadline); | 1545 EXPECT_TRUE(can_exceed_idle_deadline); |
1542 | 1546 |
1543 // Next long idle period will be for the maximum time, so | 1547 // Next long idle period will be for the maximum time, so |
1544 // CanExceedIdleDeadlineIfRequired should return true. | 1548 // CanExceedIdleDeadlineIfRequired should return true. |
1545 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 1549 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
1546 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 1550 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
1547 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 1551 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
1548 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired()); | 1552 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired()); |
1549 } | 1553 } |
1550 | 1554 |
1551 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) { | 1555 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) { |
1552 int run_count = 0; | 1556 int run_count = 0; |
1553 | 1557 |
1554 max_idle_task_reposts = 2; | 1558 max_idle_task_reposts = 2; |
1555 idle_task_runner_->PostIdleTask( | 1559 idle_task_runner_->PostIdleTask( |
1556 FROM_HERE, | 1560 FROM_HERE, |
1557 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); | 1561 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); |
1558 | 1562 |
1559 // Renderer should start in visible state. | 1563 // Renderer should start in visible state. |
1560 RunUntilIdle(); | 1564 RunUntilIdle(); |
1561 EXPECT_EQ(0, run_count); | 1565 EXPECT_EQ(0, run_count); |
1562 | 1566 |
1563 // When we hide the renderer it should start a max deadline idle period, which | 1567 // When we hide the renderer it should start a max deadline idle period, which |
1564 // will run an idle task and then immediately start a new idle period, which | 1568 // will run an idle task and then immediately start a new idle period, which |
1565 // runs the second idle task. | 1569 // runs the second idle task. |
1566 scheduler_->OnRendererHidden(); | 1570 scheduler_->OnRendererHidden(); |
1567 RunUntilIdle(); | 1571 RunUntilIdle(); |
1568 EXPECT_EQ(2, run_count); | 1572 EXPECT_EQ(2, run_count); |
1569 | 1573 |
1570 // Advance time by amount of time by the maximum amount of time we execute | 1574 // Advance time by amount of time by the maximum amount of time we execute |
1571 // idle tasks when hidden (plus some slack) - idle period should have ended. | 1575 // idle tasks when hidden (plus some slack) - idle period should have ended. |
1572 max_idle_task_reposts = 3; | 1576 max_idle_task_reposts = 3; |
1573 idle_task_runner_->PostIdleTask( | 1577 idle_task_runner_->PostIdleTask( |
1574 FROM_HERE, | 1578 FROM_HERE, |
1575 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); | 1579 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); |
1576 clock_->AdvanceNow(end_idle_when_hidden_delay() + | 1580 clock_->Advance(end_idle_when_hidden_delay() + |
1577 base::TimeDelta::FromMilliseconds(10)); | 1581 base::TimeDelta::FromMilliseconds(10)); |
1578 RunUntilIdle(); | 1582 RunUntilIdle(); |
1579 EXPECT_EQ(2, run_count); | 1583 EXPECT_EQ(2, run_count); |
1580 } | 1584 } |
1581 | 1585 |
1582 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) { | 1586 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) { |
1583 std::vector<std::string> run_order; | 1587 std::vector<std::string> run_order; |
1584 PostTestTasks(&run_order, "T1 T2"); | 1588 PostTestTasks(&run_order, "T1 T2"); |
1585 RunUntilIdle(); | 1589 RunUntilIdle(); |
1586 EXPECT_THAT(run_order, | 1590 EXPECT_THAT(run_order, |
1587 testing::ElementsAre(std::string("T1"), std::string("T2"))); | 1591 testing::ElementsAre(std::string("T1"), std::string("T2"))); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) { | 1640 TEST_F(RendererSchedulerImplTest, MismatchedDidHandleInputEventOnMainThread) { |
1637 // This should not DCHECK because there was no corresponding compositor side | 1641 // This should not DCHECK because there was no corresponding compositor side |
1638 // call to DidHandleInputEventOnCompositorThread with | 1642 // call to DidHandleInputEventOnCompositorThread with |
1639 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the | 1643 // INPUT_EVENT_ACK_STATE_NOT_CONSUMED. There are legitimate reasons for the |
1640 // compositor to not be there and we don't want to make debugging impossible. | 1644 // compositor to not be there and we don't want to make debugging impossible. |
1641 scheduler_->DidHandleInputEventOnMainThread( | 1645 scheduler_->DidHandleInputEventOnMainThread( |
1642 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 1646 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
1643 } | 1647 } |
1644 | 1648 |
1645 } // namespace scheduler | 1649 } // namespace scheduler |
OLD | NEW |