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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 base::TimeTicks deadline) { | 72 base::TimeTicks deadline) { |
73 if ((*run_count + 1) < max_idle_task_reposts) { | 73 if ((*run_count + 1) < max_idle_task_reposts) { |
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 UpdateClockToDeadlineIdleTestTask( | 81 void UpdateClockToDeadlineIdleTestTask( |
82 cc::TestNowSource* clock, | 82 base::SimpleTestTickClock* clock, |
83 base::SingleThreadTaskRunner* task_runner, | 83 base::SingleThreadTaskRunner* task_runner, |
84 int* run_count, | 84 int* run_count, |
85 base::TimeTicks deadline) { | 85 base::TimeTicks deadline) { |
86 clock->SetNow(deadline); | 86 clock->Advance(deadline - clock->NowTicks()); |
87 // Due to the way in which OrderedSimpleTestRunner orders tasks and the fact | 87 // Due to the way in which OrderedSimpleTestRunner orders tasks and the fact |
88 // that we updated the time within a task, the delayed pending task to call | 88 // that we updated the time within a task, the delayed pending task to call |
89 // EndIdlePeriod will not happen until after a TaskQueueManager DoWork, so | 89 // EndIdlePeriod will not happen until after a TaskQueueManager DoWork, so |
90 // post a normal task here to ensure it runs before the next idle task. | 90 // post a normal task here to ensure it runs before the next idle task. |
91 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); | 91 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); |
92 (*run_count)++; | 92 (*run_count)++; |
93 } | 93 } |
94 | 94 |
95 void PostingYieldingTestTask(RendererSchedulerImpl* scheduler, | 95 void PostingYieldingTestTask(RendererSchedulerImpl* scheduler, |
96 base::SingleThreadTaskRunner* task_runner, | 96 base::SingleThreadTaskRunner* task_runner, |
(...skipping 19 matching lines...) Expand all Loading... |
116 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 116 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
117 } | 117 } |
118 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); | 118 *is_anticipated_after = scheduler->IsHighPriorityWorkAnticipated(); |
119 } | 119 } |
120 }; // namespace | 120 }; // namespace |
121 | 121 |
122 class RendererSchedulerImplTest : public testing::Test { | 122 class RendererSchedulerImplTest : public testing::Test { |
123 public: | 123 public: |
124 using Policy = RendererSchedulerImpl::Policy; | 124 using Policy = RendererSchedulerImpl::Policy; |
125 | 125 |
126 RendererSchedulerImplTest() | 126 RendererSchedulerImplTest() : clock_(new base::SimpleTestTickClock()) { |
127 : clock_(cc::TestNowSource::Create(5000)), | 127 clock_->Advance(base::TimeDelta::FromInternalValue(5000)); |
128 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_, false)), | 128 mock_task_runner_ = new cc::OrderedSimpleTaskRunner(clock_.get(), false); |
129 nestable_task_runner_( | 129 nestable_task_runner_ = |
130 NestableTaskRunnerForTest::Create(mock_task_runner_)), | 130 NestableTaskRunnerForTest::Create(mock_task_runner_); |
131 scheduler_(new RendererSchedulerImpl(nestable_task_runner_)), | 131 scheduler_ = |
132 default_task_runner_(scheduler_->DefaultTaskRunner()), | 132 make_scoped_ptr(new RendererSchedulerImpl(nestable_task_runner_)); |
133 compositor_task_runner_(scheduler_->CompositorTaskRunner()), | 133 default_task_runner_ = scheduler_->DefaultTaskRunner(); |
134 loading_task_runner_(scheduler_->LoadingTaskRunner()), | 134 compositor_task_runner_ = scheduler_->CompositorTaskRunner(); |
135 idle_task_runner_(scheduler_->IdleTaskRunner()), | 135 loading_task_runner_ = scheduler_->LoadingTaskRunner(); |
136 timer_task_runner_(scheduler_->TimerTaskRunner()) { | 136 idle_task_runner_ = scheduler_->IdleTaskRunner(); |
| 137 timer_task_runner_ = scheduler_->TimerTaskRunner(); |
137 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 138 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
138 make_scoped_ptr(new TestTimeSource(clock_))); | 139 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
139 scheduler_->GetSchedulerHelperForTesting() | 140 scheduler_->GetSchedulerHelperForTesting() |
140 ->GetTaskQueueManagerForTesting() | 141 ->GetTaskQueueManagerForTesting() |
141 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 142 ->SetTimeSourceForTesting( |
| 143 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
142 } | 144 } |
143 | 145 |
144 RendererSchedulerImplTest(base::MessageLoop* message_loop) | 146 RendererSchedulerImplTest(base::MessageLoop* message_loop) |
145 : clock_(cc::TestNowSource::Create(5000)), | 147 : clock_(new base::SimpleTestTickClock()), |
146 message_loop_(message_loop), | 148 message_loop_(message_loop), |
147 nestable_task_runner_( | 149 nestable_task_runner_( |
148 SchedulerMessageLoopDelegate::Create(message_loop)), | 150 SchedulerMessageLoopDelegate::Create(message_loop)), |
149 scheduler_(new RendererSchedulerImpl(nestable_task_runner_)), | 151 scheduler_(new RendererSchedulerImpl(nestable_task_runner_)), |
150 default_task_runner_(scheduler_->DefaultTaskRunner()), | 152 default_task_runner_(scheduler_->DefaultTaskRunner()), |
151 compositor_task_runner_(scheduler_->CompositorTaskRunner()), | 153 compositor_task_runner_(scheduler_->CompositorTaskRunner()), |
152 loading_task_runner_(scheduler_->LoadingTaskRunner()), | 154 loading_task_runner_(scheduler_->LoadingTaskRunner()), |
153 idle_task_runner_(scheduler_->IdleTaskRunner()), | 155 idle_task_runner_(scheduler_->IdleTaskRunner()), |
154 timer_task_runner_(scheduler_->TimerTaskRunner()) { | 156 timer_task_runner_(scheduler_->TimerTaskRunner()) { |
| 157 clock_->Advance(base::TimeDelta::FromInternalValue(5000)); |
155 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 158 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
156 make_scoped_ptr(new TestTimeSource(clock_))); | 159 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
157 scheduler_->GetSchedulerHelperForTesting() | 160 scheduler_->GetSchedulerHelperForTesting() |
158 ->GetTaskQueueManagerForTesting() | 161 ->GetTaskQueueManagerForTesting() |
159 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 162 ->SetTimeSourceForTesting( |
| 163 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
160 } | 164 } |
161 ~RendererSchedulerImplTest() override {} | 165 ~RendererSchedulerImplTest() override {} |
162 | 166 |
163 void TearDown() override { | 167 void TearDown() override { |
164 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); | 168 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); |
165 if (mock_task_runner_.get()) { | 169 if (mock_task_runner_.get()) { |
166 // Check that all tests stop posting tasks. | 170 // Check that all tests stop posting tasks. |
167 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 171 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
168 while (mock_task_runner_->RunUntilIdle()) { | 172 while (mock_task_runner_->RunUntilIdle()) { |
169 } | 173 } |
170 } else { | 174 } else { |
171 message_loop_->RunUntilIdle(); | 175 message_loop_->RunUntilIdle(); |
172 } | 176 } |
173 } | 177 } |
174 | 178 |
175 void RunUntilIdle() { | 179 void RunUntilIdle() { |
176 // Only one of mock_task_runner_ or message_loop_ should be set. | 180 // Only one of mock_task_runner_ or message_loop_ should be set. |
177 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); | 181 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); |
178 if (mock_task_runner_.get()) | 182 if (mock_task_runner_.get()) |
179 mock_task_runner_->RunUntilIdle(); | 183 mock_task_runner_->RunUntilIdle(); |
180 else | 184 else |
181 message_loop_->RunUntilIdle(); | 185 message_loop_->RunUntilIdle(); |
182 } | 186 } |
183 | 187 |
184 void DoMainFrame() { | 188 void DoMainFrame() { |
185 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 189 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
186 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 190 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
187 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 191 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
188 scheduler_->DidCommitFrameToCompositor(); | 192 scheduler_->DidCommitFrameToCompositor(); |
189 } | 193 } |
190 | 194 |
191 void EnableIdleTasks() { DoMainFrame(); } | 195 void EnableIdleTasks() { DoMainFrame(); } |
192 | 196 |
193 Policy CurrentPolicy() { return scheduler_->current_policy_; } | 197 Policy CurrentPolicy() { return scheduler_->current_policy_; } |
194 | 198 |
195 void EnsureUrgentPolicyUpdatePostedOnMainThread() { | 199 void EnsureUrgentPolicyUpdatePostedOnMainThread() { |
196 base::AutoLock lock(scheduler_->incoming_signals_lock_); | 200 base::AutoLock lock(scheduler_->incoming_signals_lock_); |
197 scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(FROM_HERE); | 201 scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(FROM_HERE); |
198 } | 202 } |
199 | 203 |
200 void ScheduleDelayedPolicyUpdate(base::TimeDelta delay) { | 204 void ScheduleDelayedPolicyUpdate(base::TimeDelta delay) { |
201 scheduler_->delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay, | 205 scheduler_->delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay, |
202 clock_->Now()); | 206 clock_->NowTicks()); |
203 } | 207 } |
204 | 208 |
205 // Helper for posting several tasks of specific types. |task_descriptor| is a | 209 // Helper for posting several tasks of specific types. |task_descriptor| is a |
206 // string with space delimited task identifiers. The first letter of each | 210 // string with space delimited task identifiers. The first letter of each |
207 // task identifier specifies the task type: | 211 // task identifier specifies the task type: |
208 // - 'D': Default task | 212 // - 'D': Default task |
209 // - 'C': Compositor task | 213 // - 'C': Compositor task |
210 // - 'L': Loading task | 214 // - 'L': Loading task |
211 // - 'I': Idle task | 215 // - 'I': Idle task |
212 // - 'T': Timer task | 216 // - 'T': Timer task |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 &RendererSchedulerImpl::PolicyToString); | 288 &RendererSchedulerImpl::PolicyToString); |
285 } | 289 } |
286 | 290 |
287 static void CheckAllInputStreamStateToString() { | 291 static void CheckAllInputStreamStateToString() { |
288 CallForEachEnumValue<RendererSchedulerImpl::InputStreamState>( | 292 CallForEachEnumValue<RendererSchedulerImpl::InputStreamState>( |
289 RendererSchedulerImpl::InputStreamState::FIRST_INPUT_STREAM_STATE, | 293 RendererSchedulerImpl::InputStreamState::FIRST_INPUT_STREAM_STATE, |
290 RendererSchedulerImpl::InputStreamState::INPUT_STREAM_STATE_COUNT, | 294 RendererSchedulerImpl::InputStreamState::INPUT_STREAM_STATE_COUNT, |
291 &RendererSchedulerImpl::InputStreamStateToString); | 295 &RendererSchedulerImpl::InputStreamStateToString); |
292 } | 296 } |
293 | 297 |
294 scoped_refptr<cc::TestNowSource> clock_; | 298 scoped_ptr<base::SimpleTestTickClock> clock_; |
295 // Only one of mock_task_runner_ or message_loop_ will be set. | 299 // Only one of mock_task_runner_ or message_loop_ will be set. |
296 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 300 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
297 scoped_ptr<base::MessageLoop> message_loop_; | 301 scoped_ptr<base::MessageLoop> message_loop_; |
298 | 302 |
299 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; | 303 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; |
300 scoped_ptr<RendererSchedulerImpl> scheduler_; | 304 scoped_ptr<RendererSchedulerImpl> scheduler_; |
301 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; | 305 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; |
302 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 306 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
303 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; | 307 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; |
304 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 308 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
(...skipping 27 matching lines...) Expand all Loading... |
332 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_, | 336 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_, |
333 &run_order, &count, 5)); | 337 &run_order, &count, 5)); |
334 RunUntilIdle(); | 338 RunUntilIdle(); |
335 | 339 |
336 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4)); | 340 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4)); |
337 } | 341 } |
338 | 342 |
339 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) { | 343 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) { |
340 int run_count = 0; | 344 int run_count = 0; |
341 base::TimeTicks expected_deadline = | 345 base::TimeTicks expected_deadline = |
342 clock_->Now() + base::TimeDelta::FromMilliseconds(2300); | 346 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(2300); |
343 base::TimeTicks deadline_in_task; | 347 base::TimeTicks deadline_in_task; |
344 | 348 |
345 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 349 clock_->Advance(base::TimeDelta::FromMilliseconds(100)); |
346 idle_task_runner_->PostIdleTask( | 350 idle_task_runner_->PostIdleTask( |
347 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 351 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
348 | 352 |
349 RunUntilIdle(); | 353 RunUntilIdle(); |
350 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame. | 354 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame. |
351 | 355 |
352 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 356 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
353 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 357 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
354 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 358 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
355 RunUntilIdle(); | 359 RunUntilIdle(); |
356 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor. | 360 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor. |
357 | 361 |
358 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1200)); | 362 clock_->Advance(base::TimeDelta::FromMilliseconds(1200)); |
359 scheduler_->DidCommitFrameToCompositor(); | 363 scheduler_->DidCommitFrameToCompositor(); |
360 RunUntilIdle(); | 364 RunUntilIdle(); |
361 EXPECT_EQ(0, run_count); // We missed the deadline. | 365 EXPECT_EQ(0, run_count); // We missed the deadline. |
362 | 366 |
363 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 367 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
364 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 368 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
365 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 369 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
366 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(800)); | 370 clock_->Advance(base::TimeDelta::FromMilliseconds(800)); |
367 scheduler_->DidCommitFrameToCompositor(); | 371 scheduler_->DidCommitFrameToCompositor(); |
368 RunUntilIdle(); | 372 RunUntilIdle(); |
369 EXPECT_EQ(1, run_count); | 373 EXPECT_EQ(1, run_count); |
370 EXPECT_EQ(expected_deadline, deadline_in_task); | 374 EXPECT_EQ(expected_deadline, deadline_in_task); |
371 } | 375 } |
372 | 376 |
373 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) { | 377 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) { |
374 int run_count = 0; | 378 int run_count = 0; |
375 | 379 |
376 max_idle_task_reposts = 2; | 380 max_idle_task_reposts = 2; |
(...skipping 12 matching lines...) Expand all Loading... |
389 RunUntilIdle(); | 393 RunUntilIdle(); |
390 EXPECT_EQ(2, run_count); | 394 EXPECT_EQ(2, run_count); |
391 } | 395 } |
392 | 396 |
393 TEST_F(RendererSchedulerImplTest, TestIdleTaskExceedsDeadline) { | 397 TEST_F(RendererSchedulerImplTest, TestIdleTaskExceedsDeadline) { |
394 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 398 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
395 int run_count = 0; | 399 int run_count = 0; |
396 | 400 |
397 // Post two UpdateClockToDeadlineIdleTestTask tasks. | 401 // Post two UpdateClockToDeadlineIdleTestTask tasks. |
398 idle_task_runner_->PostIdleTask( | 402 idle_task_runner_->PostIdleTask( |
399 FROM_HERE, base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, | 403 FROM_HERE, base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), |
400 default_task_runner_, &run_count)); | 404 default_task_runner_, &run_count)); |
401 idle_task_runner_->PostIdleTask( | 405 idle_task_runner_->PostIdleTask( |
402 FROM_HERE, base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_, | 406 FROM_HERE, base::Bind(&UpdateClockToDeadlineIdleTestTask, clock_.get(), |
403 default_task_runner_, &run_count)); | 407 default_task_runner_, &run_count)); |
404 | 408 |
405 EnableIdleTasks(); | 409 EnableIdleTasks(); |
406 RunUntilIdle(); | 410 RunUntilIdle(); |
407 // Only the first idle task should execute since it's used up the deadline. | 411 // Only the first idle task should execute since it's used up the deadline. |
408 EXPECT_EQ(1, run_count); | 412 EXPECT_EQ(1, run_count); |
409 | 413 |
410 EnableIdleTasks(); | 414 EnableIdleTasks(); |
411 RunUntilIdle(); | 415 RunUntilIdle(); |
412 // Second task should be run on the next idle period. | 416 // Second task should be run on the next idle period. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 481 |
478 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) { | 482 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) { |
479 int run_count = 0; | 483 int run_count = 0; |
480 | 484 |
481 base::TimeTicks deadline_in_task; | 485 base::TimeTicks deadline_in_task; |
482 idle_task_runner_->PostIdleTask( | 486 idle_task_runner_->PostIdleTask( |
483 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 487 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
484 | 488 |
485 // Trigger the beginning of an idle period for 1000ms. | 489 // Trigger the beginning of an idle period for 1000ms. |
486 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 490 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
487 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 491 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
488 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 492 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
489 DoMainFrame(); | 493 DoMainFrame(); |
490 | 494 |
491 // End the idle period early (after 500ms), and send a WillBeginFrame which | 495 // End the idle period early (after 500ms), and send a WillBeginFrame which |
492 // specifies that the next idle period should end 1000ms from now. | 496 // specifies that the next idle period should end 1000ms from now. |
493 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(500)); | 497 clock_->Advance(base::TimeDelta::FromMilliseconds(500)); |
494 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 498 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
495 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 499 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
496 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 500 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
497 | 501 |
498 RunUntilIdle(); | 502 RunUntilIdle(); |
499 EXPECT_EQ(0, run_count); // Not currently in an idle period. | 503 EXPECT_EQ(0, run_count); // Not currently in an idle period. |
500 | 504 |
501 // Trigger the start of the idle period before the task to end the previous | 505 // Trigger the start of the idle period before the task to end the previous |
502 // idle period has been triggered. | 506 // idle period has been triggered. |
503 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(400)); | 507 clock_->Advance(base::TimeDelta::FromMilliseconds(400)); |
504 scheduler_->DidCommitFrameToCompositor(); | 508 scheduler_->DidCommitFrameToCompositor(); |
505 | 509 |
506 // Post a task which simulates running until after the previous end idle | 510 // Post a task which simulates running until after the previous end idle |
507 // period delayed task was scheduled for | 511 // period delayed task was scheduled for |
508 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask)); | 512 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask)); |
509 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(300)); | 513 clock_->Advance(base::TimeDelta::FromMilliseconds(300)); |
510 | 514 |
511 RunUntilIdle(); | 515 RunUntilIdle(); |
512 EXPECT_EQ(1, run_count); // We should still be in the new idle period. | 516 EXPECT_EQ(1, run_count); // We should still be in the new idle period. |
513 } | 517 } |
514 | 518 |
515 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { | 519 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { |
516 std::vector<std::string> run_order; | 520 std::vector<std::string> run_order; |
517 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); | 521 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); |
518 | 522 |
519 EnableIdleTasks(); | 523 EnableIdleTasks(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 | 677 |
674 scheduler_->DidReceiveInputEventOnCompositorThread( | 678 scheduler_->DidReceiveInputEventOnCompositorThread( |
675 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 679 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
676 DoMainFrame(); | 680 DoMainFrame(); |
677 RunUntilIdle(); | 681 RunUntilIdle(); |
678 EXPECT_THAT(run_order, | 682 EXPECT_THAT(run_order, |
679 testing::ElementsAre(std::string("C1"), std::string("C2"), | 683 testing::ElementsAre(std::string("C1"), std::string("C2"), |
680 std::string("D1"), std::string("D2"))); | 684 std::string("D1"), std::string("D2"))); |
681 | 685 |
682 run_order.clear(); | 686 run_order.clear(); |
683 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 687 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
684 PostTestTasks(&run_order, "D1 C1 D2 C2"); | 688 PostTestTasks(&run_order, "D1 C1 D2 C2"); |
685 | 689 |
686 // Compositor policy mode should have ended now that the clock has advanced. | 690 // Compositor policy mode should have ended now that the clock has advanced. |
687 RunUntilIdle(); | 691 RunUntilIdle(); |
688 EXPECT_THAT(run_order, | 692 EXPECT_THAT(run_order, |
689 testing::ElementsAre(std::string("D1"), std::string("C1"), | 693 testing::ElementsAre(std::string("D1"), std::string("C1"), |
690 std::string("D2"), std::string("C2"))); | 694 std::string("D2"), std::string("C2"))); |
691 } | 695 } |
692 | 696 |
693 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { | 697 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { |
694 std::vector<std::string> run_order; | 698 std::vector<std::string> run_order; |
695 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); | 699 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); |
696 | 700 |
697 scheduler_->DidReceiveInputEventOnCompositorThread( | 701 scheduler_->DidReceiveInputEventOnCompositorThread( |
698 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 702 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
699 RunUntilIdle(); | 703 RunUntilIdle(); |
700 EXPECT_THAT(run_order, | 704 EXPECT_THAT(run_order, |
701 testing::ElementsAre(std::string("C1"), std::string("C2"), | 705 testing::ElementsAre(std::string("C1"), std::string("C2"), |
702 std::string("D1"), std::string("D2"))); | 706 std::string("D1"), std::string("D2"))); |
703 | 707 |
704 run_order.clear(); | 708 run_order.clear(); |
705 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 709 clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
706 | 710 |
707 // Don't post any compositor tasks to simulate a very long running event | 711 // Don't post any compositor tasks to simulate a very long running event |
708 // handler. | 712 // handler. |
709 PostTestTasks(&run_order, "D1 D2"); | 713 PostTestTasks(&run_order, "D1 D2"); |
710 | 714 |
711 // Touchstart policy mode should have ended now that the clock has advanced. | 715 // Touchstart policy mode should have ended now that the clock has advanced. |
712 RunUntilIdle(); | 716 RunUntilIdle(); |
713 EXPECT_THAT(run_order, | 717 EXPECT_THAT(run_order, |
714 testing::ElementsAre(std::string("L1"), std::string("D1"), | 718 testing::ElementsAre(std::string("L1"), std::string("D1"), |
715 std::string("D2"))); | 719 std::string("D2"))); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 default_task_runner_->PostTask( | 768 default_task_runner_->PostTask( |
765 FROM_HERE, | 769 FROM_HERE, |
766 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 770 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
767 &is_anticipated_before, &is_anticipated_after)); | 771 &is_anticipated_before, &is_anticipated_after)); |
768 RunUntilIdle(); | 772 RunUntilIdle(); |
769 // When input is received, the scheduler should indicate that high-priority | 773 // When input is received, the scheduler should indicate that high-priority |
770 // work is anticipated. | 774 // work is anticipated. |
771 EXPECT_FALSE(is_anticipated_before); | 775 EXPECT_FALSE(is_anticipated_before); |
772 EXPECT_TRUE(is_anticipated_after); | 776 EXPECT_TRUE(is_anticipated_after); |
773 | 777 |
774 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 778 clock_->Advance(priority_escalation_after_input_duration() * 2); |
775 simulate_input = false; | 779 simulate_input = false; |
776 default_task_runner_->PostTask( | 780 default_task_runner_->PostTask( |
777 FROM_HERE, | 781 FROM_HERE, |
778 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, | 782 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, |
779 &is_anticipated_before, &is_anticipated_after)); | 783 &is_anticipated_before, &is_anticipated_after)); |
780 RunUntilIdle(); | 784 RunUntilIdle(); |
781 // Without additional input, the scheduler should indicate that high-priority | 785 // Without additional input, the scheduler should indicate that high-priority |
782 // work is no longer anticipated. | 786 // work is no longer anticipated. |
783 EXPECT_FALSE(is_anticipated_before); | 787 EXPECT_FALSE(is_anticipated_before); |
784 EXPECT_FALSE(is_anticipated_after); | 788 EXPECT_FALSE(is_anticipated_after); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 832 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
829 | 833 |
830 // An input event should bump us into input priority. | 834 // An input event should bump us into input priority. |
831 scheduler_->DidReceiveInputEventOnCompositorThread( | 835 scheduler_->DidReceiveInputEventOnCompositorThread( |
832 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 836 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
833 RunUntilIdle(); | 837 RunUntilIdle(); |
834 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 838 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
835 | 839 |
836 // Simulate the input event being queued for a very long time. The compositor | 840 // Simulate the input event being queued for a very long time. The compositor |
837 // task we post here represents the enqueued input task. | 841 // task we post here represents the enqueued input task. |
838 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 842 clock_->Advance(priority_escalation_after_input_duration() * 2); |
839 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); | 843 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); |
840 RunUntilIdle(); | 844 RunUntilIdle(); |
841 | 845 |
842 // Even though we exceeded the input priority escalation period, we should | 846 // Even though we exceeded the input priority escalation period, we should |
843 // still be in compositor priority since the input remains queued. | 847 // still be in compositor priority since the input remains queued. |
844 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 848 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
845 | 849 |
846 // Simulate the input event triggering a composition. This should start the | 850 // Simulate the input event triggering a composition. This should start the |
847 // countdown for going back into normal policy. | 851 // countdown for going back into normal policy. |
848 DoMainFrame(); | 852 DoMainFrame(); |
849 RunUntilIdle(); | 853 RunUntilIdle(); |
850 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 854 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
851 | 855 |
852 // After the escalation period ends we should go back into normal mode. | 856 // After the escalation period ends we should go back into normal mode. |
853 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 857 clock_->Advance(priority_escalation_after_input_duration() * 2); |
854 RunUntilIdle(); | 858 RunUntilIdle(); |
855 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 859 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
856 } | 860 } |
857 | 861 |
858 TEST_F(RendererSchedulerImplTest, SlowNoOpInputEvent) { | 862 TEST_F(RendererSchedulerImplTest, SlowNoOpInputEvent) { |
859 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 863 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
860 | 864 |
861 // An input event should bump us into input priority. | 865 // An input event should bump us into input priority. |
862 scheduler_->DidReceiveInputEventOnCompositorThread( | 866 scheduler_->DidReceiveInputEventOnCompositorThread( |
863 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 867 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
864 RunUntilIdle(); | 868 RunUntilIdle(); |
865 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 869 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
866 | 870 |
867 // Simulate the input event being queued for a very long time. The compositor | 871 // Simulate the input event being queued for a very long time. The compositor |
868 // task we post here represents the enqueued input task. | 872 // task we post here represents the enqueued input task. |
869 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 873 clock_->Advance(priority_escalation_after_input_duration() * 2); |
870 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); | 874 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); |
871 RunUntilIdle(); | 875 RunUntilIdle(); |
872 | 876 |
873 // Even though we exceeded the input priority escalation period, we should | 877 // Even though we exceeded the input priority escalation period, we should |
874 // still be in compositor priority since the input remains queued. | 878 // still be in compositor priority since the input remains queued. |
875 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 879 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
876 | 880 |
877 // If we let the compositor queue drain, we should fall out of input | 881 // If we let the compositor queue drain, we should fall out of input |
878 // priority. | 882 // priority. |
879 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 883 clock_->Advance(priority_escalation_after_input_duration() * 2); |
880 RunUntilIdle(); | 884 RunUntilIdle(); |
881 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 885 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
882 } | 886 } |
883 | 887 |
884 TEST_F(RendererSchedulerImplTest, NoOpInputEvent) { | 888 TEST_F(RendererSchedulerImplTest, NoOpInputEvent) { |
885 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 889 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
886 | 890 |
887 // An input event should bump us into input priority. | 891 // An input event should bump us into input priority. |
888 scheduler_->DidReceiveInputEventOnCompositorThread( | 892 scheduler_->DidReceiveInputEventOnCompositorThread( |
889 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); | 893 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); |
890 RunUntilIdle(); | 894 RunUntilIdle(); |
891 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 895 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
892 | 896 |
893 // If nothing else happens after this, we should drop out of compositor | 897 // If nothing else happens after this, we should drop out of compositor |
894 // priority after the escalation period ends and stop polling. | 898 // priority after the escalation period ends and stop polling. |
895 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); | 899 clock_->Advance(priority_escalation_after_input_duration() * 2); |
896 RunUntilIdle(); | 900 RunUntilIdle(); |
897 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 901 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
898 EXPECT_FALSE(mock_task_runner_->HasPendingTasks()); | 902 EXPECT_FALSE(mock_task_runner_->HasPendingTasks()); |
899 } | 903 } |
900 | 904 |
901 TEST_F(RendererSchedulerImplTest, NoOpInputEventExtendsEscalationPeriod) { | 905 TEST_F(RendererSchedulerImplTest, NoOpInputEventExtendsEscalationPeriod) { |
902 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 906 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
903 | 907 |
904 // Simulate one handled input event. | 908 // Simulate one handled input event. |
905 scheduler_->DidReceiveInputEventOnCompositorThread( | 909 scheduler_->DidReceiveInputEventOnCompositorThread( |
906 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); | 910 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); |
907 RunUntilIdle(); | 911 RunUntilIdle(); |
908 DoMainFrame(); | 912 DoMainFrame(); |
909 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 913 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
910 | 914 |
911 // Send a no-op input event in the middle of the escalation period. | 915 // Send a no-op input event in the middle of the escalation period. |
912 clock_->AdvanceNow(priority_escalation_after_input_duration() / 2); | 916 clock_->Advance(priority_escalation_after_input_duration() / 2); |
913 scheduler_->DidReceiveInputEventOnCompositorThread( | 917 scheduler_->DidReceiveInputEventOnCompositorThread( |
914 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate)); | 918 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate)); |
915 RunUntilIdle(); | 919 RunUntilIdle(); |
916 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 920 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
917 | 921 |
918 // The escalation period should have been extended by the new input event. | 922 // The escalation period should have been extended by the new input event. |
919 clock_->AdvanceNow(3 * priority_escalation_after_input_duration() / 4); | 923 clock_->Advance(3 * priority_escalation_after_input_duration() / 4); |
920 RunUntilIdle(); | 924 RunUntilIdle(); |
921 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 925 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
922 | 926 |
923 clock_->AdvanceNow(priority_escalation_after_input_duration() / 2); | 927 clock_->Advance(priority_escalation_after_input_duration() / 2); |
924 RunUntilIdle(); | 928 RunUntilIdle(); |
925 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 929 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
926 } | 930 } |
927 | 931 |
928 TEST_F(RendererSchedulerImplTest, InputArrivesAfterBeginFrame) { | 932 TEST_F(RendererSchedulerImplTest, InputArrivesAfterBeginFrame) { |
929 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 933 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
930 | 934 |
931 cc::BeginFrameArgs args = cc::BeginFrameArgs::Create( | 935 cc::BeginFrameArgs args = cc::BeginFrameArgs::Create( |
932 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 936 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
933 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); | 937 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); |
934 clock_->AdvanceNow(priority_escalation_after_input_duration() / 2); | 938 clock_->Advance(priority_escalation_after_input_duration() / 2); |
935 | 939 |
936 scheduler_->DidReceiveInputEventOnCompositorThread( | 940 scheduler_->DidReceiveInputEventOnCompositorThread( |
937 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); | 941 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); |
938 | 942 |
939 // Simulate a BeginMainFrame task from the past. | 943 // Simulate a BeginMainFrame task from the past. |
940 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); | 944 clock_->Advance(2 * priority_escalation_after_input_duration()); |
941 scheduler_->WillBeginFrame(args); | 945 scheduler_->WillBeginFrame(args); |
942 scheduler_->DidCommitFrameToCompositor(); | 946 scheduler_->DidCommitFrameToCompositor(); |
943 | 947 |
944 // This task represents the queued-up input event. | 948 // This task represents the queued-up input event. |
945 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); | 949 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); |
946 | 950 |
947 // Should remain in input priority policy since the input event hasn't been | 951 // Should remain in input priority policy since the input event hasn't been |
948 // processed yet. | 952 // processed yet. |
949 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); | 953 clock_->Advance(2 * priority_escalation_after_input_duration()); |
950 RunUntilIdle(); | 954 RunUntilIdle(); |
951 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); | 955 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); |
952 | 956 |
953 // Process the input event with a new BeginMainFrame. | 957 // Process the input event with a new BeginMainFrame. |
954 DoMainFrame(); | 958 DoMainFrame(); |
955 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); | 959 clock_->Advance(2 * priority_escalation_after_input_duration()); |
956 RunUntilIdle(); | 960 RunUntilIdle(); |
957 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); | 961 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); |
958 } | 962 } |
959 | 963 |
960 class RendererSchedulerImplForTest : public RendererSchedulerImpl { | 964 class RendererSchedulerImplForTest : public RendererSchedulerImpl { |
961 public: | 965 public: |
962 RendererSchedulerImplForTest( | 966 RendererSchedulerImplForTest( |
963 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) | 967 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) |
964 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} | 968 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} |
965 | 969 |
(...skipping 18 matching lines...) Expand all Loading... |
984 RunUntilIdle(); | 988 RunUntilIdle(); |
985 | 989 |
986 EXPECT_EQ(1, mock_scheduler->update_policy_count_); | 990 EXPECT_EQ(1, mock_scheduler->update_policy_count_); |
987 } | 991 } |
988 | 992 |
989 TEST_F(RendererSchedulerImplTest, OnePendingDelayedAndOneUrgentUpdatePolicy) { | 993 TEST_F(RendererSchedulerImplTest, OnePendingDelayedAndOneUrgentUpdatePolicy) { |
990 RendererSchedulerImplForTest* mock_scheduler = | 994 RendererSchedulerImplForTest* mock_scheduler = |
991 new RendererSchedulerImplForTest(nestable_task_runner_); | 995 new RendererSchedulerImplForTest(nestable_task_runner_); |
992 scheduler_.reset(mock_scheduler); | 996 scheduler_.reset(mock_scheduler); |
993 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 997 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
994 make_scoped_ptr(new TestTimeSource(clock_))); | 998 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
995 scheduler_->GetSchedulerHelperForTesting() | 999 scheduler_->GetSchedulerHelperForTesting() |
996 ->GetTaskQueueManagerForTesting() | 1000 ->GetTaskQueueManagerForTesting() |
997 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 1001 ->SetTimeSourceForTesting( |
| 1002 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
998 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1003 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
999 | 1004 |
1000 ScheduleDelayedPolicyUpdate(base::TimeDelta::FromMilliseconds(1)); | 1005 ScheduleDelayedPolicyUpdate(base::TimeDelta::FromMilliseconds(1)); |
1001 EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1006 EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1002 | 1007 |
1003 RunUntilIdle(); | 1008 RunUntilIdle(); |
1004 | 1009 |
1005 // We expect both the urgent and the delayed updates to run. | 1010 // We expect both the urgent and the delayed updates to run. |
1006 EXPECT_EQ(2, mock_scheduler->update_policy_count_); | 1011 EXPECT_EQ(2, mock_scheduler->update_policy_count_); |
1007 } | 1012 } |
1008 | 1013 |
1009 TEST_F(RendererSchedulerImplTest, OneUrgentAndOnePendingDelayedUpdatePolicy) { | 1014 TEST_F(RendererSchedulerImplTest, OneUrgentAndOnePendingDelayedUpdatePolicy) { |
1010 RendererSchedulerImplForTest* mock_scheduler = | 1015 RendererSchedulerImplForTest* mock_scheduler = |
1011 new RendererSchedulerImplForTest(nestable_task_runner_); | 1016 new RendererSchedulerImplForTest(nestable_task_runner_); |
1012 scheduler_.reset(mock_scheduler); | 1017 scheduler_.reset(mock_scheduler); |
1013 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 1018 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
1014 make_scoped_ptr(new TestTimeSource(clock_))); | 1019 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1015 scheduler_->GetSchedulerHelperForTesting() | 1020 scheduler_->GetSchedulerHelperForTesting() |
1016 ->GetTaskQueueManagerForTesting() | 1021 ->GetTaskQueueManagerForTesting() |
1017 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 1022 ->SetTimeSourceForTesting( |
| 1023 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1018 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1024 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1019 | 1025 |
1020 EnsureUrgentPolicyUpdatePostedOnMainThread(); | 1026 EnsureUrgentPolicyUpdatePostedOnMainThread(); |
1021 ScheduleDelayedPolicyUpdate(base::TimeDelta::FromMilliseconds(1)); | 1027 ScheduleDelayedPolicyUpdate(base::TimeDelta::FromMilliseconds(1)); |
1022 | 1028 |
1023 RunUntilIdle(); | 1029 RunUntilIdle(); |
1024 | 1030 |
1025 // We expect both the urgent and the delayed updates to run. | 1031 // We expect both the urgent and the delayed updates to run. |
1026 EXPECT_EQ(2, mock_scheduler->update_policy_count_); | 1032 EXPECT_EQ(2, mock_scheduler->update_policy_count_); |
1027 } | 1033 } |
1028 | 1034 |
1029 TEST_F(RendererSchedulerImplTest, UpdatePolicyCountTriggeredByOneInputEvent) { | 1035 TEST_F(RendererSchedulerImplTest, UpdatePolicyCountTriggeredByOneInputEvent) { |
1030 RendererSchedulerImplForTest* mock_scheduler = | 1036 RendererSchedulerImplForTest* mock_scheduler = |
1031 new RendererSchedulerImplForTest(nestable_task_runner_); | 1037 new RendererSchedulerImplForTest(nestable_task_runner_); |
1032 scheduler_.reset(mock_scheduler); | 1038 scheduler_.reset(mock_scheduler); |
1033 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 1039 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
1034 make_scoped_ptr(new TestTimeSource(clock_))); | 1040 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1035 scheduler_->GetSchedulerHelperForTesting() | 1041 scheduler_->GetSchedulerHelperForTesting() |
1036 ->GetTaskQueueManagerForTesting() | 1042 ->GetTaskQueueManagerForTesting() |
1037 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 1043 ->SetTimeSourceForTesting( |
| 1044 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1038 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1045 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1039 | 1046 |
1040 scheduler_->DidReceiveInputEventOnCompositorThread( | 1047 scheduler_->DidReceiveInputEventOnCompositorThread( |
1041 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1048 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1042 | 1049 |
1043 RunUntilIdle(); | 1050 RunUntilIdle(); |
1044 | 1051 |
1045 // We expect an urgent policy update followed by a delayed one 100ms later. | 1052 // We expect an urgent policy update followed by a delayed one 100ms later. |
1046 EXPECT_EQ(2, mock_scheduler->update_policy_count_); | 1053 EXPECT_EQ(2, mock_scheduler->update_policy_count_); |
1047 } | 1054 } |
1048 | 1055 |
1049 TEST_F(RendererSchedulerImplTest, UpdatePolicyCountTriggeredByTwoInputEvents) { | 1056 TEST_F(RendererSchedulerImplTest, UpdatePolicyCountTriggeredByTwoInputEvents) { |
1050 RendererSchedulerImplForTest* mock_scheduler = | 1057 RendererSchedulerImplForTest* mock_scheduler = |
1051 new RendererSchedulerImplForTest(nestable_task_runner_); | 1058 new RendererSchedulerImplForTest(nestable_task_runner_); |
1052 scheduler_.reset(mock_scheduler); | 1059 scheduler_.reset(mock_scheduler); |
1053 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 1060 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
1054 make_scoped_ptr(new TestTimeSource(clock_))); | 1061 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1055 scheduler_->GetSchedulerHelperForTesting() | 1062 scheduler_->GetSchedulerHelperForTesting() |
1056 ->GetTaskQueueManagerForTesting() | 1063 ->GetTaskQueueManagerForTesting() |
1057 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 1064 ->SetTimeSourceForTesting( |
| 1065 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1058 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1066 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1059 | 1067 |
1060 scheduler_->DidReceiveInputEventOnCompositorThread( | 1068 scheduler_->DidReceiveInputEventOnCompositorThread( |
1061 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1069 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1062 scheduler_->DidReceiveInputEventOnCompositorThread( | 1070 scheduler_->DidReceiveInputEventOnCompositorThread( |
1063 FakeInputEvent(blink::WebInputEvent::TouchMove)); | 1071 FakeInputEvent(blink::WebInputEvent::TouchMove)); |
1064 | 1072 |
1065 RunUntilIdle(); | 1073 RunUntilIdle(); |
1066 | 1074 |
1067 // We expect an urgent policy update followed by a delayed one 100ms later. | 1075 // We expect an urgent policy update followed by a delayed one 100ms later. |
1068 EXPECT_EQ(2, mock_scheduler->update_policy_count_); | 1076 EXPECT_EQ(2, mock_scheduler->update_policy_count_); |
1069 } | 1077 } |
1070 | 1078 |
1071 TEST_F(RendererSchedulerImplTest, EnsureUpdatePolicyNotTriggeredTooOften) { | 1079 TEST_F(RendererSchedulerImplTest, EnsureUpdatePolicyNotTriggeredTooOften) { |
1072 RendererSchedulerImplForTest* mock_scheduler = | 1080 RendererSchedulerImplForTest* mock_scheduler = |
1073 new RendererSchedulerImplForTest(nestable_task_runner_); | 1081 new RendererSchedulerImplForTest(nestable_task_runner_); |
1074 scheduler_.reset(mock_scheduler); | 1082 scheduler_.reset(mock_scheduler); |
1075 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( | 1083 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( |
1076 make_scoped_ptr(new TestTimeSource(clock_))); | 1084 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1077 scheduler_->GetSchedulerHelperForTesting() | 1085 scheduler_->GetSchedulerHelperForTesting() |
1078 ->GetTaskQueueManagerForTesting() | 1086 ->GetTaskQueueManagerForTesting() |
1079 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); | 1087 ->SetTimeSourceForTesting( |
| 1088 make_scoped_ptr(new TestTimeSource(clock_.get()))); |
1080 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); | 1089 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); |
1081 | 1090 |
1082 scheduler_->DidReceiveInputEventOnCompositorThread( | 1091 scheduler_->DidReceiveInputEventOnCompositorThread( |
1083 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1092 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1084 scheduler_->DidReceiveInputEventOnCompositorThread( | 1093 scheduler_->DidReceiveInputEventOnCompositorThread( |
1085 FakeInputEvent(blink::WebInputEvent::TouchMove)); | 1094 FakeInputEvent(blink::WebInputEvent::TouchMove)); |
1086 | 1095 |
1087 // We expect the first call to IsHighPriorityWorkAnticipated to be called | 1096 // We expect the first call to IsHighPriorityWorkAnticipated to be called |
1088 // after recieving an input event (but before the UpdateTask was processed) to | 1097 // after recieving an input event (but before the UpdateTask was processed) to |
1089 // call UpdatePolicy. | 1098 // call UpdatePolicy. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 EnableIdleTasks(); | 1171 EnableIdleTasks(); |
1163 RunUntilIdle(); | 1172 RunUntilIdle(); |
1164 // Note we expect task 3 to run last because it's non-nestable. | 1173 // Note we expect task 3 to run last because it's non-nestable. |
1165 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"), | 1174 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"), |
1166 std::string("4"), std::string("5"), | 1175 std::string("4"), std::string("5"), |
1167 std::string("3"))); | 1176 std::string("3"))); |
1168 } | 1177 } |
1169 | 1178 |
1170 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) { | 1179 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) { |
1171 base::TimeTicks expected_deadline = | 1180 base::TimeTicks expected_deadline = |
1172 clock_->Now() + maximum_idle_period_duration(); | 1181 clock_->NowTicks() + maximum_idle_period_duration(); |
1173 base::TimeTicks deadline_in_task; | 1182 base::TimeTicks deadline_in_task; |
1174 int run_count = 0; | 1183 int run_count = 0; |
1175 | 1184 |
1176 idle_task_runner_->PostIdleTask( | 1185 idle_task_runner_->PostIdleTask( |
1177 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1186 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1178 | 1187 |
1179 RunUntilIdle(); | 1188 RunUntilIdle(); |
1180 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period. | 1189 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period. |
1181 | 1190 |
1182 scheduler_->BeginFrameNotExpectedSoon(); | 1191 scheduler_->BeginFrameNotExpectedSoon(); |
1183 RunUntilIdle(); | 1192 RunUntilIdle(); |
1184 EXPECT_EQ(1, run_count); // Should have run in a long idle time. | 1193 EXPECT_EQ(1, run_count); // Should have run in a long idle time. |
1185 EXPECT_EQ(expected_deadline, deadline_in_task); | 1194 EXPECT_EQ(expected_deadline, deadline_in_task); |
1186 } | 1195 } |
1187 | 1196 |
1188 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) { | 1197 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) { |
1189 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30); | 1198 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30); |
1190 base::TimeTicks expected_deadline = clock_->Now() + pending_task_delay; | 1199 base::TimeTicks expected_deadline = clock_->NowTicks() + pending_task_delay; |
1191 base::TimeTicks deadline_in_task; | 1200 base::TimeTicks deadline_in_task; |
1192 int run_count = 0; | 1201 int run_count = 0; |
1193 | 1202 |
1194 idle_task_runner_->PostIdleTask( | 1203 idle_task_runner_->PostIdleTask( |
1195 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1204 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1196 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), | 1205 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), |
1197 pending_task_delay); | 1206 pending_task_delay); |
1198 | 1207 |
1199 scheduler_->BeginFrameNotExpectedSoon(); | 1208 scheduler_->BeginFrameNotExpectedSoon(); |
1200 RunUntilIdle(); | 1209 RunUntilIdle(); |
1201 EXPECT_EQ(1, run_count); // Should have run in a long idle time. | 1210 EXPECT_EQ(1, run_count); // Should have run in a long idle time. |
1202 EXPECT_EQ(expected_deadline, deadline_in_task); | 1211 EXPECT_EQ(expected_deadline, deadline_in_task); |
1203 } | 1212 } |
1204 | 1213 |
1205 TEST_F(RendererSchedulerImplTest, | 1214 TEST_F(RendererSchedulerImplTest, |
1206 TestLongIdlePeriodWithLatePendingDelayedTask) { | 1215 TestLongIdlePeriodWithLatePendingDelayedTask) { |
1207 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10); | 1216 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10); |
1208 base::TimeTicks deadline_in_task; | 1217 base::TimeTicks deadline_in_task; |
1209 int run_count = 0; | 1218 int run_count = 0; |
1210 | 1219 |
1211 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), | 1220 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), |
1212 pending_task_delay); | 1221 pending_task_delay); |
1213 | 1222 |
1214 // Advance clock until after delayed task was meant to be run. | 1223 // Advance clock until after delayed task was meant to be run. |
1215 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(20)); | 1224 clock_->Advance(base::TimeDelta::FromMilliseconds(20)); |
1216 | 1225 |
1217 // Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle | 1226 // Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle |
1218 // period. Since there is a late pending delayed task this shouldn't actually | 1227 // period. Since there is a late pending delayed task this shouldn't actually |
1219 // start an idle period. | 1228 // start an idle period. |
1220 idle_task_runner_->PostIdleTask( | 1229 idle_task_runner_->PostIdleTask( |
1221 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1230 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1222 scheduler_->BeginFrameNotExpectedSoon(); | 1231 scheduler_->BeginFrameNotExpectedSoon(); |
1223 RunUntilIdle(); | 1232 RunUntilIdle(); |
1224 EXPECT_EQ(0, run_count); | 1233 EXPECT_EQ(0, run_count); |
1225 | 1234 |
1226 // After the delayed task has been run we should trigger an idle period. | 1235 // After the delayed task has been run we should trigger an idle period. |
1227 clock_->AdvanceNow(maximum_idle_period_duration()); | 1236 clock_->Advance(maximum_idle_period_duration()); |
1228 RunUntilIdle(); | 1237 RunUntilIdle(); |
1229 EXPECT_EQ(1, run_count); | 1238 EXPECT_EQ(1, run_count); |
1230 } | 1239 } |
1231 | 1240 |
1232 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) { | 1241 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) { |
1233 int run_count = 0; | 1242 int run_count = 0; |
1234 | 1243 |
1235 max_idle_task_reposts = 3; | 1244 max_idle_task_reposts = 3; |
1236 idle_task_runner_->PostIdleTask( | 1245 idle_task_runner_->PostIdleTask( |
1237 FROM_HERE, | 1246 FROM_HERE, |
1238 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); | 1247 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); |
1239 | 1248 |
1240 scheduler_->BeginFrameNotExpectedSoon(); | 1249 scheduler_->BeginFrameNotExpectedSoon(); |
1241 RunUntilIdle(); | 1250 RunUntilIdle(); |
1242 EXPECT_EQ(1, run_count); // Should only run once per idle period. | 1251 EXPECT_EQ(1, run_count); // Should only run once per idle period. |
1243 | 1252 |
1244 // Advance time to start of next long idle period and check task reposted task | 1253 // Advance time to start of next long idle period and check task reposted task |
1245 // gets run. | 1254 // gets run. |
1246 clock_->AdvanceNow(maximum_idle_period_duration()); | 1255 clock_->Advance(maximum_idle_period_duration()); |
1247 RunUntilIdle(); | 1256 RunUntilIdle(); |
1248 EXPECT_EQ(2, run_count); | 1257 EXPECT_EQ(2, run_count); |
1249 | 1258 |
1250 // Advance time to start of next long idle period then end idle period with a | 1259 // Advance time to start of next long idle period then end idle period with a |
1251 // new BeginMainFrame and check idle task doesn't run. | 1260 // new BeginMainFrame and check idle task doesn't run. |
1252 clock_->AdvanceNow(maximum_idle_period_duration()); | 1261 clock_->Advance(maximum_idle_period_duration()); |
1253 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 1262 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
1254 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 1263 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
1255 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 1264 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
1256 RunUntilIdle(); | 1265 RunUntilIdle(); |
1257 EXPECT_EQ(2, run_count); | 1266 EXPECT_EQ(2, run_count); |
1258 } | 1267 } |
1259 | 1268 |
1260 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) { | 1269 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) { |
1261 base::TimeTicks deadline_in_task; | 1270 base::TimeTicks deadline_in_task; |
1262 int run_count = 0; | 1271 int run_count = 0; |
1263 | 1272 |
1264 // Start a long idle period and get the time it should end. | 1273 // Start a long idle period and get the time it should end. |
1265 scheduler_->BeginFrameNotExpectedSoon(); | 1274 scheduler_->BeginFrameNotExpectedSoon(); |
1266 // The scheduler should not run the initiate_next_long_idle_period task if | 1275 // The scheduler should not run the initiate_next_long_idle_period task if |
1267 // there are no idle tasks and no other task woke up the scheduler, thus | 1276 // there are no idle tasks and no other task woke up the scheduler, thus |
1268 // the idle period deadline shouldn't update at the end of the current long | 1277 // the idle period deadline shouldn't update at the end of the current long |
1269 // idle period. | 1278 // idle period. |
1270 base::TimeTicks idle_period_deadline = | 1279 base::TimeTicks idle_period_deadline = |
1271 scheduler_->CurrentIdleTaskDeadlineForTesting(); | 1280 scheduler_->CurrentIdleTaskDeadlineForTesting(); |
1272 clock_->AdvanceNow(maximum_idle_period_duration()); | 1281 clock_->Advance(maximum_idle_period_duration()); |
1273 RunUntilIdle(); | 1282 RunUntilIdle(); |
1274 | 1283 |
1275 base::TimeTicks new_idle_period_deadline = | 1284 base::TimeTicks new_idle_period_deadline = |
1276 scheduler_->CurrentIdleTaskDeadlineForTesting(); | 1285 scheduler_->CurrentIdleTaskDeadlineForTesting(); |
1277 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline); | 1286 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline); |
1278 | 1287 |
1279 // Posting a after-wakeup idle task also shouldn't wake the scheduler or | 1288 // Posting a after-wakeup idle task also shouldn't wake the scheduler or |
1280 // initiate the next long idle period. | 1289 // initiate the next long idle period. |
1281 idle_task_runner_->PostIdleTaskAfterWakeup( | 1290 idle_task_runner_->PostIdleTaskAfterWakeup( |
1282 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1291 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
(...skipping 20 matching lines...) Expand all Loading... |
1303 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); | 1312 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); |
1304 | 1313 |
1305 // Observation of touchstart should defer the start of the long idle period. | 1314 // Observation of touchstart should defer the start of the long idle period. |
1306 scheduler_->DidReceiveInputEventOnCompositorThread( | 1315 scheduler_->DidReceiveInputEventOnCompositorThread( |
1307 FakeInputEvent(blink::WebInputEvent::TouchStart)); | 1316 FakeInputEvent(blink::WebInputEvent::TouchStart)); |
1308 scheduler_->BeginFrameNotExpectedSoon(); | 1317 scheduler_->BeginFrameNotExpectedSoon(); |
1309 RunUntilIdle(); | 1318 RunUntilIdle(); |
1310 EXPECT_EQ(0, run_count); | 1319 EXPECT_EQ(0, run_count); |
1311 | 1320 |
1312 // The long idle period should start after the touchstart policy has finished. | 1321 // The long idle period should start after the touchstart policy has finished. |
1313 clock_->AdvanceNow(priority_escalation_after_input_duration()); | 1322 clock_->Advance(priority_escalation_after_input_duration()); |
1314 RunUntilIdle(); | 1323 RunUntilIdle(); |
1315 EXPECT_EQ(1, run_count); | 1324 EXPECT_EQ(1, run_count); |
1316 } | 1325 } |
1317 | 1326 |
1318 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler, | 1327 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler, |
1319 bool* can_exceed_idle_deadline_out, | 1328 bool* can_exceed_idle_deadline_out, |
1320 int* run_count, | 1329 int* run_count, |
1321 base::TimeTicks deadline) { | 1330 base::TimeTicks deadline) { |
1322 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired(); | 1331 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired(); |
1323 (*run_count)++; | 1332 (*run_count)++; |
(...skipping 24 matching lines...) Expand all Loading... |
1348 FROM_HERE, | 1357 FROM_HERE, |
1349 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), | 1358 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), |
1350 &can_exceed_idle_deadline, &run_count)); | 1359 &can_exceed_idle_deadline, &run_count)); |
1351 scheduler_->BeginFrameNotExpectedSoon(); | 1360 scheduler_->BeginFrameNotExpectedSoon(); |
1352 RunUntilIdle(); | 1361 RunUntilIdle(); |
1353 EXPECT_EQ(2, run_count); | 1362 EXPECT_EQ(2, run_count); |
1354 EXPECT_FALSE(can_exceed_idle_deadline); | 1363 EXPECT_FALSE(can_exceed_idle_deadline); |
1355 | 1364 |
1356 // Next long idle period will be for the maximum time, so | 1365 // Next long idle period will be for the maximum time, so |
1357 // CanExceedIdleDeadlineIfRequired should return true. | 1366 // CanExceedIdleDeadlineIfRequired should return true. |
1358 clock_->AdvanceNow(maximum_idle_period_duration()); | 1367 clock_->Advance(maximum_idle_period_duration()); |
1359 idle_task_runner_->PostIdleTask( | 1368 idle_task_runner_->PostIdleTask( |
1360 FROM_HERE, | 1369 FROM_HERE, |
1361 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), | 1370 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), |
1362 &can_exceed_idle_deadline, &run_count)); | 1371 &can_exceed_idle_deadline, &run_count)); |
1363 RunUntilIdle(); | 1372 RunUntilIdle(); |
1364 EXPECT_EQ(3, run_count); | 1373 EXPECT_EQ(3, run_count); |
1365 EXPECT_TRUE(can_exceed_idle_deadline); | 1374 EXPECT_TRUE(can_exceed_idle_deadline); |
1366 | 1375 |
1367 // Next long idle period will be for the maximum time, so | 1376 // Next long idle period will be for the maximum time, so |
1368 // CanExceedIdleDeadlineIfRequired should return true. | 1377 // CanExceedIdleDeadlineIfRequired should return true. |
1369 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( | 1378 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( |
1370 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), | 1379 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(), |
1371 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); | 1380 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); |
1372 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired()); | 1381 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired()); |
1373 } | 1382 } |
1374 | 1383 |
1375 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) { | 1384 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) { |
1376 int run_count = 0; | 1385 int run_count = 0; |
1377 | 1386 |
1378 idle_task_runner_->PostIdleTask( | 1387 idle_task_runner_->PostIdleTask( |
1379 FROM_HERE, | 1388 FROM_HERE, |
1380 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); | 1389 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); |
1381 | 1390 |
1382 // Renderer should start in visible state. | 1391 // Renderer should start in visible state. |
1383 RunUntilIdle(); | 1392 RunUntilIdle(); |
1384 EXPECT_EQ(0, run_count); | 1393 EXPECT_EQ(0, run_count); |
1385 | 1394 |
1386 // When we hide the renderer it should start an idle period. | 1395 // When we hide the renderer it should start an idle period. |
1387 scheduler_->OnRendererHidden(); | 1396 scheduler_->OnRendererHidden(); |
1388 RunUntilIdle(); | 1397 RunUntilIdle(); |
1389 EXPECT_EQ(1, run_count); | 1398 EXPECT_EQ(1, run_count); |
1390 | 1399 |
1391 // Advance time to start of next long idle period and check task reposted task | 1400 // Advance time to start of next long idle period and check task reposted task |
1392 // gets run. | 1401 // gets run. |
1393 clock_->AdvanceNow(maximum_idle_period_duration()); | 1402 clock_->Advance(maximum_idle_period_duration()); |
1394 RunUntilIdle(); | 1403 RunUntilIdle(); |
1395 EXPECT_EQ(2, run_count); | 1404 EXPECT_EQ(2, run_count); |
1396 | 1405 |
1397 // Advance time by amount of time by the maximum amount of time we execute | 1406 // Advance time by amount of time by the maximum amount of time we execute |
1398 // idle tasks when hidden (plus some slack) - idle period should have ended. | 1407 // idle tasks when hidden (plus some slack) - idle period should have ended. |
1399 clock_->AdvanceNow(end_idle_when_hidden_delay() + | 1408 clock_->Advance(end_idle_when_hidden_delay() + |
1400 base::TimeDelta::FromMilliseconds(10)); | 1409 base::TimeDelta::FromMilliseconds(10)); |
1401 RunUntilIdle(); | 1410 RunUntilIdle(); |
1402 EXPECT_EQ(2, run_count); | 1411 EXPECT_EQ(2, run_count); |
1403 } | 1412 } |
1404 | 1413 |
1405 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) { | 1414 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) { |
1406 std::vector<std::string> run_order; | 1415 std::vector<std::string> run_order; |
1407 PostTestTasks(&run_order, "T1 T2"); | 1416 PostTestTasks(&run_order, "T1 T2"); |
1408 RunUntilIdle(); | 1417 RunUntilIdle(); |
1409 EXPECT_THAT(run_order, | 1418 EXPECT_THAT(run_order, |
1410 testing::ElementsAre(std::string("T1"), std::string("T2"))); | 1419 testing::ElementsAre(std::string("T1"), std::string("T2"))); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 | 1463 |
1455 TEST_F(RendererSchedulerImplTest, PolicyToString) { | 1464 TEST_F(RendererSchedulerImplTest, PolicyToString) { |
1456 CheckAllTaskQueueIdToString(); | 1465 CheckAllTaskQueueIdToString(); |
1457 } | 1466 } |
1458 | 1467 |
1459 TEST_F(RendererSchedulerImplTest, InputStreamStateToString) { | 1468 TEST_F(RendererSchedulerImplTest, InputStreamStateToString) { |
1460 CheckAllInputStreamStateToString(); | 1469 CheckAllInputStreamStateToString(); |
1461 } | 1470 } |
1462 | 1471 |
1463 } // namespace scheduler | 1472 } // namespace scheduler |
OLD | NEW |