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

Side by Side Diff: components/scheduler/renderer/renderer_scheduler_impl_unittest.cc

Issue 1132753008: Replaced TestNowSource with SimpleTestTickClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected typo. Minor changes to keep parity with TestNowSource. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/scheduler/renderer/renderer_scheduler_impl.h" 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/test/simple_test_tick_clock.h"
8 #include "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
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
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));
Sami 2015/05/29 14:00:58 Ditto about base time.
Ankur Verma 2015/06/03 14:56:10 Have'nt changed starting values yet as per mithro'
128 mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_, false)), 128 mock_task_runner_ = new cc::OrderedSimpleTaskRunner(clock_, 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_)));
139 scheduler_->GetSchedulerHelperForTesting() 140 scheduler_->GetSchedulerHelperForTesting()
140 ->GetTaskQueueManagerForTesting() 141 ->GetTaskQueueManagerForTesting()
141 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); 142 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_)));
142 } 143 }
143 144
144 RendererSchedulerImplTest(base::MessageLoop* message_loop) 145 RendererSchedulerImplTest(base::MessageLoop* message_loop)
145 : clock_(cc::TestNowSource::Create(5000)), 146 : clock_(new base::SimpleTestTickClock()),
146 message_loop_(message_loop), 147 message_loop_(message_loop),
147 nestable_task_runner_( 148 nestable_task_runner_(
148 SchedulerMessageLoopDelegate::Create(message_loop)), 149 SchedulerMessageLoopDelegate::Create(message_loop)),
149 scheduler_(new RendererSchedulerImpl(nestable_task_runner_)), 150 scheduler_(new RendererSchedulerImpl(nestable_task_runner_)),
150 default_task_runner_(scheduler_->DefaultTaskRunner()), 151 default_task_runner_(scheduler_->DefaultTaskRunner()),
151 compositor_task_runner_(scheduler_->CompositorTaskRunner()), 152 compositor_task_runner_(scheduler_->CompositorTaskRunner()),
152 loading_task_runner_(scheduler_->LoadingTaskRunner()), 153 loading_task_runner_(scheduler_->LoadingTaskRunner()),
153 idle_task_runner_(scheduler_->IdleTaskRunner()), 154 idle_task_runner_(scheduler_->IdleTaskRunner()),
154 timer_task_runner_(scheduler_->TimerTaskRunner()) { 155 timer_task_runner_(scheduler_->TimerTaskRunner()) {
156 clock_->Advance(base::TimeDelta::FromInternalValue(5000));
Sami 2015/05/29 14:00:58 Ditto about base time.
Ankur Verma 2015/06/03 14:56:10 Have'nt changed starting values yet as per mithro'
155 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( 157 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting(
156 make_scoped_ptr(new TestTimeSource(clock_))); 158 make_scoped_ptr(new TestTimeSource(clock_)));
157 scheduler_->GetSchedulerHelperForTesting() 159 scheduler_->GetSchedulerHelperForTesting()
158 ->GetTaskQueueManagerForTesting() 160 ->GetTaskQueueManagerForTesting()
159 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_))); 161 ->SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock_)));
160 } 162 }
161 ~RendererSchedulerImplTest() override {} 163 ~RendererSchedulerImplTest() override {}
162 164
163 void TearDown() override { 165 void TearDown() override {
164 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); 166 DCHECK(!mock_task_runner_.get() || !message_loop_.get());
(...skipping 11 matching lines...) Expand all
176 // Only one of mock_task_runner_ or message_loop_ should be set. 178 // Only one of mock_task_runner_ or message_loop_ should be set.
177 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); 179 DCHECK(!mock_task_runner_.get() || !message_loop_.get());
178 if (mock_task_runner_.get()) 180 if (mock_task_runner_.get())
179 mock_task_runner_->RunUntilIdle(); 181 mock_task_runner_->RunUntilIdle();
180 else 182 else
181 message_loop_->RunUntilIdle(); 183 message_loop_->RunUntilIdle();
182 } 184 }
183 185
184 void DoMainFrame() { 186 void DoMainFrame() {
185 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 187 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
186 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 188 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
187 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 189 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
188 scheduler_->DidCommitFrameToCompositor(); 190 scheduler_->DidCommitFrameToCompositor();
189 } 191 }
190 192
191 void EnableIdleTasks() { DoMainFrame(); } 193 void EnableIdleTasks() { DoMainFrame(); }
192 194
193 Policy CurrentPolicy() { return scheduler_->current_policy_; } 195 Policy CurrentPolicy() { return scheduler_->current_policy_; }
194 196
195 void EnsureUrgentPolicyUpdatePostedOnMainThread() { 197 void EnsureUrgentPolicyUpdatePostedOnMainThread() {
196 base::AutoLock lock(scheduler_->incoming_signals_lock_); 198 base::AutoLock lock(scheduler_->incoming_signals_lock_);
197 scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(FROM_HERE); 199 scheduler_->EnsureUrgentPolicyUpdatePostedOnMainThread(FROM_HERE);
198 } 200 }
199 201
200 void ScheduleDelayedPolicyUpdate(base::TimeDelta delay) { 202 void ScheduleDelayedPolicyUpdate(base::TimeDelta delay) {
201 scheduler_->delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay, 203 scheduler_->delayed_update_policy_runner_.SetDeadline(FROM_HERE, delay,
202 clock_->Now()); 204 clock_->NowTicks());
203 } 205 }
204 206
205 // Helper for posting several tasks of specific types. |task_descriptor| is a 207 // Helper for posting several tasks of specific types. |task_descriptor| is a
206 // string with space delimited task identifiers. The first letter of each 208 // string with space delimited task identifiers. The first letter of each
207 // task identifier specifies the task type: 209 // task identifier specifies the task type:
208 // - 'D': Default task 210 // - 'D': Default task
209 // - 'C': Compositor task 211 // - 'C': Compositor task
210 // - 'L': Loading task 212 // - 'L': Loading task
211 // - 'I': Idle task 213 // - 'I': Idle task
212 // - 'T': Timer task 214 // - 'T': Timer task
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 &RendererSchedulerImpl::PolicyToString); 286 &RendererSchedulerImpl::PolicyToString);
285 } 287 }
286 288
287 static void CheckAllInputStreamStateToString() { 289 static void CheckAllInputStreamStateToString() {
288 CallForEachEnumValue<RendererSchedulerImpl::InputStreamState>( 290 CallForEachEnumValue<RendererSchedulerImpl::InputStreamState>(
289 RendererSchedulerImpl::InputStreamState::FIRST_INPUT_STREAM_STATE, 291 RendererSchedulerImpl::InputStreamState::FIRST_INPUT_STREAM_STATE,
290 RendererSchedulerImpl::InputStreamState::INPUT_STREAM_STATE_COUNT, 292 RendererSchedulerImpl::InputStreamState::INPUT_STREAM_STATE_COUNT,
291 &RendererSchedulerImpl::InputStreamStateToString); 293 &RendererSchedulerImpl::InputStreamStateToString);
292 } 294 }
293 295
294 scoped_refptr<cc::TestNowSource> clock_; 296 base::SimpleTestTickClock* clock_;
Sami 2015/05/29 14:00:58 Ditto about scoped_ptr.
Ankur Verma 2015/06/03 14:56:10 Done.
295 // Only one of mock_task_runner_ or message_loop_ will be set. 297 // Only one of mock_task_runner_ or message_loop_ will be set.
296 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 298 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
297 scoped_ptr<base::MessageLoop> message_loop_; 299 scoped_ptr<base::MessageLoop> message_loop_;
298 300
299 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; 301 scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_;
300 scoped_ptr<RendererSchedulerImpl> scheduler_; 302 scoped_ptr<RendererSchedulerImpl> scheduler_;
301 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 303 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
302 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 304 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
303 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 305 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
304 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 306 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
(...skipping 27 matching lines...) Expand all
332 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_, 334 FROM_HERE, base::Bind(AppendToVectorReentrantTask, default_task_runner_,
333 &run_order, &count, 5)); 335 &run_order, &count, 5));
334 RunUntilIdle(); 336 RunUntilIdle();
335 337
336 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4)); 338 EXPECT_THAT(run_order, testing::ElementsAre(0, 1, 2, 3, 4));
337 } 339 }
338 340
339 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) { 341 TEST_F(RendererSchedulerImplTest, TestPostIdleTask) {
340 int run_count = 0; 342 int run_count = 0;
341 base::TimeTicks expected_deadline = 343 base::TimeTicks expected_deadline =
342 clock_->Now() + base::TimeDelta::FromMilliseconds(2300); 344 clock_->NowTicks() + base::TimeDelta::FromMilliseconds(2300);
343 base::TimeTicks deadline_in_task; 345 base::TimeTicks deadline_in_task;
344 346
345 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); 347 clock_->Advance(base::TimeDelta::FromMilliseconds(100));
346 idle_task_runner_->PostIdleTask( 348 idle_task_runner_->PostIdleTask(
347 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 349 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
348 350
349 RunUntilIdle(); 351 RunUntilIdle();
350 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame. 352 EXPECT_EQ(0, run_count); // Shouldn't run yet as no WillBeginFrame.
351 353
352 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 354 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
353 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 355 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
354 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 356 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
355 RunUntilIdle(); 357 RunUntilIdle();
356 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor. 358 EXPECT_EQ(0, run_count); // Shouldn't run as no DidCommitFrameToCompositor.
357 359
358 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1200)); 360 clock_->Advance(base::TimeDelta::FromMilliseconds(1200));
359 scheduler_->DidCommitFrameToCompositor(); 361 scheduler_->DidCommitFrameToCompositor();
360 RunUntilIdle(); 362 RunUntilIdle();
361 EXPECT_EQ(0, run_count); // We missed the deadline. 363 EXPECT_EQ(0, run_count); // We missed the deadline.
362 364
363 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 365 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
364 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 366 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
365 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 367 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
366 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(800)); 368 clock_->Advance(base::TimeDelta::FromMilliseconds(800));
367 scheduler_->DidCommitFrameToCompositor(); 369 scheduler_->DidCommitFrameToCompositor();
368 RunUntilIdle(); 370 RunUntilIdle();
369 EXPECT_EQ(1, run_count); 371 EXPECT_EQ(1, run_count);
370 EXPECT_EQ(expected_deadline, deadline_in_task); 372 EXPECT_EQ(expected_deadline, deadline_in_task);
371 } 373 }
372 374
373 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) { 375 TEST_F(RendererSchedulerImplTest, TestRepostingIdleTask) {
374 int run_count = 0; 376 int run_count = 0;
375 377
376 max_idle_task_reposts = 2; 378 max_idle_task_reposts = 2;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 479
478 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) { 480 TEST_F(RendererSchedulerImplTest, TestDelayedEndIdlePeriodCanceled) {
479 int run_count = 0; 481 int run_count = 0;
480 482
481 base::TimeTicks deadline_in_task; 483 base::TimeTicks deadline_in_task;
482 idle_task_runner_->PostIdleTask( 484 idle_task_runner_->PostIdleTask(
483 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 485 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
484 486
485 // Trigger the beginning of an idle period for 1000ms. 487 // Trigger the beginning of an idle period for 1000ms.
486 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 488 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
487 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 489 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
488 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 490 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
489 DoMainFrame(); 491 DoMainFrame();
490 492
491 // End the idle period early (after 500ms), and send a WillBeginFrame which 493 // End the idle period early (after 500ms), and send a WillBeginFrame which
492 // specifies that the next idle period should end 1000ms from now. 494 // specifies that the next idle period should end 1000ms from now.
493 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(500)); 495 clock_->Advance(base::TimeDelta::FromMilliseconds(500));
494 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 496 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
495 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 497 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
496 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 498 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
497 499
498 RunUntilIdle(); 500 RunUntilIdle();
499 EXPECT_EQ(0, run_count); // Not currently in an idle period. 501 EXPECT_EQ(0, run_count); // Not currently in an idle period.
500 502
501 // Trigger the start of the idle period before the task to end the previous 503 // Trigger the start of the idle period before the task to end the previous
502 // idle period has been triggered. 504 // idle period has been triggered.
503 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(400)); 505 clock_->Advance(base::TimeDelta::FromMilliseconds(400));
504 scheduler_->DidCommitFrameToCompositor(); 506 scheduler_->DidCommitFrameToCompositor();
505 507
506 // Post a task which simulates running until after the previous end idle 508 // Post a task which simulates running until after the previous end idle
507 // period delayed task was scheduled for 509 // period delayed task was scheduled for
508 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask)); 510 scheduler_->DefaultTaskRunner()->PostTask(FROM_HERE, base::Bind(NullTask));
509 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(300)); 511 clock_->Advance(base::TimeDelta::FromMilliseconds(300));
510 512
511 RunUntilIdle(); 513 RunUntilIdle();
512 EXPECT_EQ(1, run_count); // We should still be in the new idle period. 514 EXPECT_EQ(1, run_count); // We should still be in the new idle period.
513 } 515 }
514 516
515 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) { 517 TEST_F(RendererSchedulerImplTest, TestDefaultPolicy) {
516 std::vector<std::string> run_order; 518 std::vector<std::string> run_order;
517 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2"); 519 PostTestTasks(&run_order, "L1 I1 D1 C1 D2 C2");
518 520
519 EnableIdleTasks(); 521 EnableIdleTasks();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 675
674 scheduler_->DidReceiveInputEventOnCompositorThread( 676 scheduler_->DidReceiveInputEventOnCompositorThread(
675 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 677 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
676 DoMainFrame(); 678 DoMainFrame();
677 RunUntilIdle(); 679 RunUntilIdle();
678 EXPECT_THAT(run_order, 680 EXPECT_THAT(run_order,
679 testing::ElementsAre(std::string("C1"), std::string("C2"), 681 testing::ElementsAre(std::string("C1"), std::string("C2"),
680 std::string("D1"), std::string("D2"))); 682 std::string("D1"), std::string("D2")));
681 683
682 run_order.clear(); 684 run_order.clear();
683 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); 685 clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
684 PostTestTasks(&run_order, "D1 C1 D2 C2"); 686 PostTestTasks(&run_order, "D1 C1 D2 C2");
685 687
686 // Compositor policy mode should have ended now that the clock has advanced. 688 // Compositor policy mode should have ended now that the clock has advanced.
687 RunUntilIdle(); 689 RunUntilIdle();
688 EXPECT_THAT(run_order, 690 EXPECT_THAT(run_order,
689 testing::ElementsAre(std::string("D1"), std::string("C1"), 691 testing::ElementsAre(std::string("D1"), std::string("C1"),
690 std::string("D2"), std::string("C2"))); 692 std::string("D2"), std::string("C2")));
691 } 693 }
692 694
693 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) { 695 TEST_F(RendererSchedulerImplTest, TestTouchstartPolicyEndsAfterTimeout) {
694 std::vector<std::string> run_order; 696 std::vector<std::string> run_order;
695 PostTestTasks(&run_order, "L1 D1 C1 D2 C2"); 697 PostTestTasks(&run_order, "L1 D1 C1 D2 C2");
696 698
697 scheduler_->DidReceiveInputEventOnCompositorThread( 699 scheduler_->DidReceiveInputEventOnCompositorThread(
698 FakeInputEvent(blink::WebInputEvent::TouchStart)); 700 FakeInputEvent(blink::WebInputEvent::TouchStart));
699 RunUntilIdle(); 701 RunUntilIdle();
700 EXPECT_THAT(run_order, 702 EXPECT_THAT(run_order,
701 testing::ElementsAre(std::string("C1"), std::string("C2"), 703 testing::ElementsAre(std::string("C1"), std::string("C2"),
702 std::string("D1"), std::string("D2"))); 704 std::string("D1"), std::string("D2")));
703 705
704 run_order.clear(); 706 run_order.clear();
705 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); 707 clock_->Advance(base::TimeDelta::FromMilliseconds(1000));
706 708
707 // Don't post any compositor tasks to simulate a very long running event 709 // Don't post any compositor tasks to simulate a very long running event
708 // handler. 710 // handler.
709 PostTestTasks(&run_order, "D1 D2"); 711 PostTestTasks(&run_order, "D1 D2");
710 712
711 // Touchstart policy mode should have ended now that the clock has advanced. 713 // Touchstart policy mode should have ended now that the clock has advanced.
712 RunUntilIdle(); 714 RunUntilIdle();
713 EXPECT_THAT(run_order, 715 EXPECT_THAT(run_order,
714 testing::ElementsAre(std::string("L1"), std::string("D1"), 716 testing::ElementsAre(std::string("L1"), std::string("D1"),
715 std::string("D2"))); 717 std::string("D2")));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 default_task_runner_->PostTask( 766 default_task_runner_->PostTask(
765 FROM_HERE, 767 FROM_HERE,
766 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 768 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
767 &is_anticipated_before, &is_anticipated_after)); 769 &is_anticipated_before, &is_anticipated_after));
768 RunUntilIdle(); 770 RunUntilIdle();
769 // When input is received, the scheduler should indicate that high-priority 771 // When input is received, the scheduler should indicate that high-priority
770 // work is anticipated. 772 // work is anticipated.
771 EXPECT_FALSE(is_anticipated_before); 773 EXPECT_FALSE(is_anticipated_before);
772 EXPECT_TRUE(is_anticipated_after); 774 EXPECT_TRUE(is_anticipated_after);
773 775
774 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); 776 clock_->Advance(priority_escalation_after_input_duration() * 2);
775 simulate_input = false; 777 simulate_input = false;
776 default_task_runner_->PostTask( 778 default_task_runner_->PostTask(
777 FROM_HERE, 779 FROM_HERE,
778 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input, 780 base::Bind(&AnticipationTestTask, scheduler_.get(), simulate_input,
779 &is_anticipated_before, &is_anticipated_after)); 781 &is_anticipated_before, &is_anticipated_after));
780 RunUntilIdle(); 782 RunUntilIdle();
781 // Without additional input, the scheduler should indicate that high-priority 783 // Without additional input, the scheduler should indicate that high-priority
782 // work is no longer anticipated. 784 // work is no longer anticipated.
783 EXPECT_FALSE(is_anticipated_before); 785 EXPECT_FALSE(is_anticipated_before);
784 EXPECT_FALSE(is_anticipated_after); 786 EXPECT_FALSE(is_anticipated_after);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 830 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
829 831
830 // An input event should bump us into input priority. 832 // An input event should bump us into input priority.
831 scheduler_->DidReceiveInputEventOnCompositorThread( 833 scheduler_->DidReceiveInputEventOnCompositorThread(
832 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 834 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
833 RunUntilIdle(); 835 RunUntilIdle();
834 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 836 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
835 837
836 // Simulate the input event being queued for a very long time. The compositor 838 // Simulate the input event being queued for a very long time. The compositor
837 // task we post here represents the enqueued input task. 839 // task we post here represents the enqueued input task.
838 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); 840 clock_->Advance(priority_escalation_after_input_duration() * 2);
839 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); 841 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask));
840 RunUntilIdle(); 842 RunUntilIdle();
841 843
842 // Even though we exceeded the input priority escalation period, we should 844 // Even though we exceeded the input priority escalation period, we should
843 // still be in compositor priority since the input remains queued. 845 // still be in compositor priority since the input remains queued.
844 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 846 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
845 847
846 // Simulate the input event triggering a composition. This should start the 848 // Simulate the input event triggering a composition. This should start the
847 // countdown for going back into normal policy. 849 // countdown for going back into normal policy.
848 DoMainFrame(); 850 DoMainFrame();
849 RunUntilIdle(); 851 RunUntilIdle();
850 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 852 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
851 853
852 // After the escalation period ends we should go back into normal mode. 854 // After the escalation period ends we should go back into normal mode.
853 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); 855 clock_->Advance(priority_escalation_after_input_duration() * 2);
854 RunUntilIdle(); 856 RunUntilIdle();
855 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 857 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
856 } 858 }
857 859
858 TEST_F(RendererSchedulerImplTest, SlowNoOpInputEvent) { 860 TEST_F(RendererSchedulerImplTest, SlowNoOpInputEvent) {
859 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 861 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
860 862
861 // An input event should bump us into input priority. 863 // An input event should bump us into input priority.
862 scheduler_->DidReceiveInputEventOnCompositorThread( 864 scheduler_->DidReceiveInputEventOnCompositorThread(
863 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 865 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
864 RunUntilIdle(); 866 RunUntilIdle();
865 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 867 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
866 868
867 // Simulate the input event being queued for a very long time. The compositor 869 // Simulate the input event being queued for a very long time. The compositor
868 // task we post here represents the enqueued input task. 870 // task we post here represents the enqueued input task.
869 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); 871 clock_->Advance(priority_escalation_after_input_duration() * 2);
870 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); 872 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask));
871 RunUntilIdle(); 873 RunUntilIdle();
872 874
873 // Even though we exceeded the input priority escalation period, we should 875 // Even though we exceeded the input priority escalation period, we should
874 // still be in compositor priority since the input remains queued. 876 // still be in compositor priority since the input remains queued.
875 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 877 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
876 878
877 // If we let the compositor queue drain, we should fall out of input 879 // If we let the compositor queue drain, we should fall out of input
878 // priority. 880 // priority.
879 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); 881 clock_->Advance(priority_escalation_after_input_duration() * 2);
880 RunUntilIdle(); 882 RunUntilIdle();
881 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 883 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
882 } 884 }
883 885
884 TEST_F(RendererSchedulerImplTest, NoOpInputEvent) { 886 TEST_F(RendererSchedulerImplTest, NoOpInputEvent) {
885 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 887 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
886 888
887 // An input event should bump us into input priority. 889 // An input event should bump us into input priority.
888 scheduler_->DidReceiveInputEventOnCompositorThread( 890 scheduler_->DidReceiveInputEventOnCompositorThread(
889 FakeInputEvent(blink::WebInputEvent::GestureFlingStart)); 891 FakeInputEvent(blink::WebInputEvent::GestureFlingStart));
890 RunUntilIdle(); 892 RunUntilIdle();
891 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 893 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
892 894
893 // If nothing else happens after this, we should drop out of compositor 895 // If nothing else happens after this, we should drop out of compositor
894 // priority after the escalation period ends and stop polling. 896 // priority after the escalation period ends and stop polling.
895 clock_->AdvanceNow(priority_escalation_after_input_duration() * 2); 897 clock_->Advance(priority_escalation_after_input_duration() * 2);
896 RunUntilIdle(); 898 RunUntilIdle();
897 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 899 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
898 EXPECT_FALSE(mock_task_runner_->HasPendingTasks()); 900 EXPECT_FALSE(mock_task_runner_->HasPendingTasks());
899 } 901 }
900 902
901 TEST_F(RendererSchedulerImplTest, NoOpInputEventExtendsEscalationPeriod) { 903 TEST_F(RendererSchedulerImplTest, NoOpInputEventExtendsEscalationPeriod) {
902 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 904 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
903 905
904 // Simulate one handled input event. 906 // Simulate one handled input event.
905 scheduler_->DidReceiveInputEventOnCompositorThread( 907 scheduler_->DidReceiveInputEventOnCompositorThread(
906 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); 908 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin));
907 RunUntilIdle(); 909 RunUntilIdle();
908 DoMainFrame(); 910 DoMainFrame();
909 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 911 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
910 912
911 // Send a no-op input event in the middle of the escalation period. 913 // Send a no-op input event in the middle of the escalation period.
912 clock_->AdvanceNow(priority_escalation_after_input_duration() / 2); 914 clock_->Advance(priority_escalation_after_input_duration() / 2);
913 scheduler_->DidReceiveInputEventOnCompositorThread( 915 scheduler_->DidReceiveInputEventOnCompositorThread(
914 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate)); 916 FakeInputEvent(blink::WebInputEvent::GestureScrollUpdate));
915 RunUntilIdle(); 917 RunUntilIdle();
916 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 918 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
917 919
918 // The escalation period should have been extended by the new input event. 920 // The escalation period should have been extended by the new input event.
919 clock_->AdvanceNow(3 * priority_escalation_after_input_duration() / 4); 921 clock_->Advance(3 * priority_escalation_after_input_duration() / 4);
920 RunUntilIdle(); 922 RunUntilIdle();
921 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 923 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
922 924
923 clock_->AdvanceNow(priority_escalation_after_input_duration() / 2); 925 clock_->Advance(priority_escalation_after_input_duration() / 2);
924 RunUntilIdle(); 926 RunUntilIdle();
925 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 927 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
926 } 928 }
927 929
928 TEST_F(RendererSchedulerImplTest, InputArrivesAfterBeginFrame) { 930 TEST_F(RendererSchedulerImplTest, InputArrivesAfterBeginFrame) {
929 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 931 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
930 932
931 cc::BeginFrameArgs args = cc::BeginFrameArgs::Create( 933 cc::BeginFrameArgs args = cc::BeginFrameArgs::Create(
932 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 934 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
933 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL); 935 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL);
934 clock_->AdvanceNow(priority_escalation_after_input_duration() / 2); 936 clock_->Advance(priority_escalation_after_input_duration() / 2);
935 937
936 scheduler_->DidReceiveInputEventOnCompositorThread( 938 scheduler_->DidReceiveInputEventOnCompositorThread(
937 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin)); 939 FakeInputEvent(blink::WebInputEvent::GestureScrollBegin));
938 940
939 // Simulate a BeginMainFrame task from the past. 941 // Simulate a BeginMainFrame task from the past.
940 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); 942 clock_->Advance(2 * priority_escalation_after_input_duration());
941 scheduler_->WillBeginFrame(args); 943 scheduler_->WillBeginFrame(args);
942 scheduler_->DidCommitFrameToCompositor(); 944 scheduler_->DidCommitFrameToCompositor();
943 945
944 // This task represents the queued-up input event. 946 // This task represents the queued-up input event.
945 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); 947 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask));
946 948
947 // Should remain in input priority policy since the input event hasn't been 949 // Should remain in input priority policy since the input event hasn't been
948 // processed yet. 950 // processed yet.
949 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); 951 clock_->Advance(2 * priority_escalation_after_input_duration());
950 RunUntilIdle(); 952 RunUntilIdle();
951 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy()); 953 EXPECT_EQ(Policy::COMPOSITOR_PRIORITY, CurrentPolicy());
952 954
953 // Process the input event with a new BeginMainFrame. 955 // Process the input event with a new BeginMainFrame.
954 DoMainFrame(); 956 DoMainFrame();
955 clock_->AdvanceNow(2 * priority_escalation_after_input_duration()); 957 clock_->Advance(2 * priority_escalation_after_input_duration());
956 RunUntilIdle(); 958 RunUntilIdle();
957 EXPECT_EQ(Policy::NORMAL, CurrentPolicy()); 959 EXPECT_EQ(Policy::NORMAL, CurrentPolicy());
958 } 960 }
959 961
960 class RendererSchedulerImplForTest : public RendererSchedulerImpl { 962 class RendererSchedulerImplForTest : public RendererSchedulerImpl {
961 public: 963 public:
962 RendererSchedulerImplForTest( 964 RendererSchedulerImplForTest(
963 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) 965 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner)
964 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} 966 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {}
965 967
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 EnableIdleTasks(); 1164 EnableIdleTasks();
1163 RunUntilIdle(); 1165 RunUntilIdle();
1164 // Note we expect task 3 to run last because it's non-nestable. 1166 // 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"), 1167 EXPECT_THAT(order, testing::ElementsAre(std::string("1"), std::string("2"),
1166 std::string("4"), std::string("5"), 1168 std::string("4"), std::string("5"),
1167 std::string("3"))); 1169 std::string("3")));
1168 } 1170 }
1169 1171
1170 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) { 1172 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriod) {
1171 base::TimeTicks expected_deadline = 1173 base::TimeTicks expected_deadline =
1172 clock_->Now() + maximum_idle_period_duration(); 1174 clock_->NowTicks() + maximum_idle_period_duration();
1173 base::TimeTicks deadline_in_task; 1175 base::TimeTicks deadline_in_task;
1174 int run_count = 0; 1176 int run_count = 0;
1175 1177
1176 idle_task_runner_->PostIdleTask( 1178 idle_task_runner_->PostIdleTask(
1177 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 1179 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
1178 1180
1179 RunUntilIdle(); 1181 RunUntilIdle();
1180 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period. 1182 EXPECT_EQ(0, run_count); // Shouldn't run yet as no idle period.
1181 1183
1182 scheduler_->BeginFrameNotExpectedSoon(); 1184 scheduler_->BeginFrameNotExpectedSoon();
1183 RunUntilIdle(); 1185 RunUntilIdle();
1184 EXPECT_EQ(1, run_count); // Should have run in a long idle time. 1186 EXPECT_EQ(1, run_count); // Should have run in a long idle time.
1185 EXPECT_EQ(expected_deadline, deadline_in_task); 1187 EXPECT_EQ(expected_deadline, deadline_in_task);
1186 } 1188 }
1187 1189
1188 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) { 1190 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodWithPendingDelayedTask) {
1189 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30); 1191 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(30);
1190 base::TimeTicks expected_deadline = clock_->Now() + pending_task_delay; 1192 base::TimeTicks expected_deadline = clock_->NowTicks() + pending_task_delay;
1191 base::TimeTicks deadline_in_task; 1193 base::TimeTicks deadline_in_task;
1192 int run_count = 0; 1194 int run_count = 0;
1193 1195
1194 idle_task_runner_->PostIdleTask( 1196 idle_task_runner_->PostIdleTask(
1195 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 1197 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
1196 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), 1198 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask),
1197 pending_task_delay); 1199 pending_task_delay);
1198 1200
1199 scheduler_->BeginFrameNotExpectedSoon(); 1201 scheduler_->BeginFrameNotExpectedSoon();
1200 RunUntilIdle(); 1202 RunUntilIdle();
1201 EXPECT_EQ(1, run_count); // Should have run in a long idle time. 1203 EXPECT_EQ(1, run_count); // Should have run in a long idle time.
1202 EXPECT_EQ(expected_deadline, deadline_in_task); 1204 EXPECT_EQ(expected_deadline, deadline_in_task);
1203 } 1205 }
1204 1206
1205 TEST_F(RendererSchedulerImplTest, 1207 TEST_F(RendererSchedulerImplTest,
1206 TestLongIdlePeriodWithLatePendingDelayedTask) { 1208 TestLongIdlePeriodWithLatePendingDelayedTask) {
1207 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10); 1209 base::TimeDelta pending_task_delay = base::TimeDelta::FromMilliseconds(10);
1208 base::TimeTicks deadline_in_task; 1210 base::TimeTicks deadline_in_task;
1209 int run_count = 0; 1211 int run_count = 0;
1210 1212
1211 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask), 1213 default_task_runner_->PostDelayedTask(FROM_HERE, base::Bind(&NullTask),
1212 pending_task_delay); 1214 pending_task_delay);
1213 1215
1214 // Advance clock until after delayed task was meant to be run. 1216 // Advance clock until after delayed task was meant to be run.
1215 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(20)); 1217 clock_->Advance(base::TimeDelta::FromMilliseconds(20));
1216 1218
1217 // Post an idle task and BeginFrameNotExpectedSoon to initiate a long idle 1219 // 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 1220 // period. Since there is a late pending delayed task this shouldn't actually
1219 // start an idle period. 1221 // start an idle period.
1220 idle_task_runner_->PostIdleTask( 1222 idle_task_runner_->PostIdleTask(
1221 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 1223 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
1222 scheduler_->BeginFrameNotExpectedSoon(); 1224 scheduler_->BeginFrameNotExpectedSoon();
1223 RunUntilIdle(); 1225 RunUntilIdle();
1224 EXPECT_EQ(0, run_count); 1226 EXPECT_EQ(0, run_count);
1225 1227
1226 // After the delayed task has been run we should trigger an idle period. 1228 // After the delayed task has been run we should trigger an idle period.
1227 clock_->AdvanceNow(maximum_idle_period_duration()); 1229 clock_->Advance(maximum_idle_period_duration());
1228 RunUntilIdle(); 1230 RunUntilIdle();
1229 EXPECT_EQ(1, run_count); 1231 EXPECT_EQ(1, run_count);
1230 } 1232 }
1231 1233
1232 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) { 1234 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodRepeating) {
1233 int run_count = 0; 1235 int run_count = 0;
1234 1236
1235 max_idle_task_reposts = 3; 1237 max_idle_task_reposts = 3;
1236 idle_task_runner_->PostIdleTask( 1238 idle_task_runner_->PostIdleTask(
1237 FROM_HERE, 1239 FROM_HERE,
1238 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); 1240 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count));
1239 1241
1240 scheduler_->BeginFrameNotExpectedSoon(); 1242 scheduler_->BeginFrameNotExpectedSoon();
1241 RunUntilIdle(); 1243 RunUntilIdle();
1242 EXPECT_EQ(1, run_count); // Should only run once per idle period. 1244 EXPECT_EQ(1, run_count); // Should only run once per idle period.
1243 1245
1244 // Advance time to start of next long idle period and check task reposted task 1246 // Advance time to start of next long idle period and check task reposted task
1245 // gets run. 1247 // gets run.
1246 clock_->AdvanceNow(maximum_idle_period_duration()); 1248 clock_->Advance(maximum_idle_period_duration());
1247 RunUntilIdle(); 1249 RunUntilIdle();
1248 EXPECT_EQ(2, run_count); 1250 EXPECT_EQ(2, run_count);
1249 1251
1250 // Advance time to start of next long idle period then end idle period with a 1252 // 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. 1253 // new BeginMainFrame and check idle task doesn't run.
1252 clock_->AdvanceNow(maximum_idle_period_duration()); 1254 clock_->Advance(maximum_idle_period_duration());
1253 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 1255 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
1254 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 1256 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
1255 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 1257 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
1256 RunUntilIdle(); 1258 RunUntilIdle();
1257 EXPECT_EQ(2, run_count); 1259 EXPECT_EQ(2, run_count);
1258 } 1260 }
1259 1261
1260 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) { 1262 TEST_F(RendererSchedulerImplTest, TestLongIdlePeriodDoesNotWakeScheduler) {
1261 base::TimeTicks deadline_in_task; 1263 base::TimeTicks deadline_in_task;
1262 int run_count = 0; 1264 int run_count = 0;
1263 1265
1264 // Start a long idle period and get the time it should end. 1266 // Start a long idle period and get the time it should end.
1265 scheduler_->BeginFrameNotExpectedSoon(); 1267 scheduler_->BeginFrameNotExpectedSoon();
1266 // The scheduler should not run the initiate_next_long_idle_period task if 1268 // 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 1269 // 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 1270 // the idle period deadline shouldn't update at the end of the current long
1269 // idle period. 1271 // idle period.
1270 base::TimeTicks idle_period_deadline = 1272 base::TimeTicks idle_period_deadline =
1271 scheduler_->CurrentIdleTaskDeadlineForTesting(); 1273 scheduler_->CurrentIdleTaskDeadlineForTesting();
1272 clock_->AdvanceNow(maximum_idle_period_duration()); 1274 clock_->Advance(maximum_idle_period_duration());
1273 RunUntilIdle(); 1275 RunUntilIdle();
1274 1276
1275 base::TimeTicks new_idle_period_deadline = 1277 base::TimeTicks new_idle_period_deadline =
1276 scheduler_->CurrentIdleTaskDeadlineForTesting(); 1278 scheduler_->CurrentIdleTaskDeadlineForTesting();
1277 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline); 1279 EXPECT_EQ(idle_period_deadline, new_idle_period_deadline);
1278 1280
1279 // Posting a after-wakeup idle task also shouldn't wake the scheduler or 1281 // Posting a after-wakeup idle task also shouldn't wake the scheduler or
1280 // initiate the next long idle period. 1282 // initiate the next long idle period.
1281 idle_task_runner_->PostIdleTaskAfterWakeup( 1283 idle_task_runner_->PostIdleTaskAfterWakeup(
1282 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 1284 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
(...skipping 20 matching lines...) Expand all
1303 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task)); 1305 FROM_HERE, base::Bind(&IdleTestTask, &run_count, &deadline_in_task));
1304 1306
1305 // Observation of touchstart should defer the start of the long idle period. 1307 // Observation of touchstart should defer the start of the long idle period.
1306 scheduler_->DidReceiveInputEventOnCompositorThread( 1308 scheduler_->DidReceiveInputEventOnCompositorThread(
1307 FakeInputEvent(blink::WebInputEvent::TouchStart)); 1309 FakeInputEvent(blink::WebInputEvent::TouchStart));
1308 scheduler_->BeginFrameNotExpectedSoon(); 1310 scheduler_->BeginFrameNotExpectedSoon();
1309 RunUntilIdle(); 1311 RunUntilIdle();
1310 EXPECT_EQ(0, run_count); 1312 EXPECT_EQ(0, run_count);
1311 1313
1312 // The long idle period should start after the touchstart policy has finished. 1314 // The long idle period should start after the touchstart policy has finished.
1313 clock_->AdvanceNow(priority_escalation_after_input_duration()); 1315 clock_->Advance(priority_escalation_after_input_duration());
1314 RunUntilIdle(); 1316 RunUntilIdle();
1315 EXPECT_EQ(1, run_count); 1317 EXPECT_EQ(1, run_count);
1316 } 1318 }
1317 1319
1318 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler, 1320 void TestCanExceedIdleDeadlineIfRequiredTask(RendererScheduler* scheduler,
1319 bool* can_exceed_idle_deadline_out, 1321 bool* can_exceed_idle_deadline_out,
1320 int* run_count, 1322 int* run_count,
1321 base::TimeTicks deadline) { 1323 base::TimeTicks deadline) {
1322 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired(); 1324 *can_exceed_idle_deadline_out = scheduler->CanExceedIdleDeadlineIfRequired();
1323 (*run_count)++; 1325 (*run_count)++;
(...skipping 24 matching lines...) Expand all
1348 FROM_HERE, 1350 FROM_HERE,
1349 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), 1351 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(),
1350 &can_exceed_idle_deadline, &run_count)); 1352 &can_exceed_idle_deadline, &run_count));
1351 scheduler_->BeginFrameNotExpectedSoon(); 1353 scheduler_->BeginFrameNotExpectedSoon();
1352 RunUntilIdle(); 1354 RunUntilIdle();
1353 EXPECT_EQ(2, run_count); 1355 EXPECT_EQ(2, run_count);
1354 EXPECT_FALSE(can_exceed_idle_deadline); 1356 EXPECT_FALSE(can_exceed_idle_deadline);
1355 1357
1356 // Next long idle period will be for the maximum time, so 1358 // Next long idle period will be for the maximum time, so
1357 // CanExceedIdleDeadlineIfRequired should return true. 1359 // CanExceedIdleDeadlineIfRequired should return true.
1358 clock_->AdvanceNow(maximum_idle_period_duration()); 1360 clock_->Advance(maximum_idle_period_duration());
1359 idle_task_runner_->PostIdleTask( 1361 idle_task_runner_->PostIdleTask(
1360 FROM_HERE, 1362 FROM_HERE,
1361 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(), 1363 base::Bind(&TestCanExceedIdleDeadlineIfRequiredTask, scheduler_.get(),
1362 &can_exceed_idle_deadline, &run_count)); 1364 &can_exceed_idle_deadline, &run_count));
1363 RunUntilIdle(); 1365 RunUntilIdle();
1364 EXPECT_EQ(3, run_count); 1366 EXPECT_EQ(3, run_count);
1365 EXPECT_TRUE(can_exceed_idle_deadline); 1367 EXPECT_TRUE(can_exceed_idle_deadline);
1366 1368
1367 // Next long idle period will be for the maximum time, so 1369 // Next long idle period will be for the maximum time, so
1368 // CanExceedIdleDeadlineIfRequired should return true. 1370 // CanExceedIdleDeadlineIfRequired should return true.
1369 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create( 1371 scheduler_->WillBeginFrame(cc::BeginFrameArgs::Create(
1370 BEGINFRAME_FROM_HERE, clock_->Now(), base::TimeTicks(), 1372 BEGINFRAME_FROM_HERE, clock_->NowTicks(), base::TimeTicks(),
1371 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL)); 1373 base::TimeDelta::FromMilliseconds(1000), cc::BeginFrameArgs::NORMAL));
1372 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired()); 1374 EXPECT_FALSE(scheduler_->CanExceedIdleDeadlineIfRequired());
1373 } 1375 }
1374 1376
1375 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) { 1377 TEST_F(RendererSchedulerImplTest, TestRendererHiddenIdlePeriod) {
1376 int run_count = 0; 1378 int run_count = 0;
1377 1379
1378 idle_task_runner_->PostIdleTask( 1380 idle_task_runner_->PostIdleTask(
1379 FROM_HERE, 1381 FROM_HERE,
1380 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count)); 1382 base::Bind(&RepostingIdleTestTask, idle_task_runner_, &run_count));
1381 1383
1382 // Renderer should start in visible state. 1384 // Renderer should start in visible state.
1383 RunUntilIdle(); 1385 RunUntilIdle();
1384 EXPECT_EQ(0, run_count); 1386 EXPECT_EQ(0, run_count);
1385 1387
1386 // When we hide the renderer it should start an idle period. 1388 // When we hide the renderer it should start an idle period.
1387 scheduler_->OnRendererHidden(); 1389 scheduler_->OnRendererHidden();
1388 RunUntilIdle(); 1390 RunUntilIdle();
1389 EXPECT_EQ(1, run_count); 1391 EXPECT_EQ(1, run_count);
1390 1392
1391 // Advance time to start of next long idle period and check task reposted task 1393 // Advance time to start of next long idle period and check task reposted task
1392 // gets run. 1394 // gets run.
1393 clock_->AdvanceNow(maximum_idle_period_duration()); 1395 clock_->Advance(maximum_idle_period_duration());
1394 RunUntilIdle(); 1396 RunUntilIdle();
1395 EXPECT_EQ(2, run_count); 1397 EXPECT_EQ(2, run_count);
1396 1398
1397 // Advance time by amount of time by the maximum amount of time we execute 1399 // 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. 1400 // idle tasks when hidden (plus some slack) - idle period should have ended.
1399 clock_->AdvanceNow(end_idle_when_hidden_delay() + 1401 clock_->Advance(end_idle_when_hidden_delay() +
1400 base::TimeDelta::FromMilliseconds(10)); 1402 base::TimeDelta::FromMilliseconds(10));
1401 RunUntilIdle(); 1403 RunUntilIdle();
1402 EXPECT_EQ(2, run_count); 1404 EXPECT_EQ(2, run_count);
1403 } 1405 }
1404 1406
1405 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) { 1407 TEST_F(RendererSchedulerImplTest, TimerQueueEnabledByDefault) {
1406 std::vector<std::string> run_order; 1408 std::vector<std::string> run_order;
1407 PostTestTasks(&run_order, "T1 T2"); 1409 PostTestTasks(&run_order, "T1 T2");
1408 RunUntilIdle(); 1410 RunUntilIdle();
1409 EXPECT_THAT(run_order, 1411 EXPECT_THAT(run_order,
1410 testing::ElementsAre(std::string("T1"), std::string("T2"))); 1412 testing::ElementsAre(std::string("T1"), std::string("T2")));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 1456
1455 TEST_F(RendererSchedulerImplTest, PolicyToString) { 1457 TEST_F(RendererSchedulerImplTest, PolicyToString) {
1456 CheckAllTaskQueueIdToString(); 1458 CheckAllTaskQueueIdToString();
1457 } 1459 }
1458 1460
1459 TEST_F(RendererSchedulerImplTest, InputStreamStateToString) { 1461 TEST_F(RendererSchedulerImplTest, InputStreamStateToString) {
1460 CheckAllInputStreamStateToString(); 1462 CheckAllInputStreamStateToString();
1461 } 1463 }
1462 1464
1463 } // namespace scheduler 1465 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698