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

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

Issue 1424053002: Adds a flag to support "Virtual Time" to the blink scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 1 month 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 "base/test/simple_test_tick_clock.h"
9 #include "cc/output/begin_frame_args.h" 9 #include "cc/output/begin_frame_args.h"
10 #include "cc/test/ordered_simple_task_runner.h" 10 #include "cc/test/ordered_simple_task_runner.h"
11 #include "components/scheduler/base/test_time_source.h" 11 #include "components/scheduler/base/test_time_source.h"
12 #include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" 12 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h"
13 #include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" 13 #include "components/scheduler/child/scheduler_tqm_delegate_impl.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 {
21 public: 21 public:
22 explicit FakeInputEvent(blink::WebInputEvent::Type event_type) 22 explicit FakeInputEvent(blink::WebInputEvent::Type event_type)
23 : WebInputEvent(sizeof(FakeInputEvent)) { 23 : WebInputEvent(sizeof(FakeInputEvent)) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 171 }
172 172
173 }; // namespace 173 }; // namespace
174 174
175 class RendererSchedulerImplForTest : public RendererSchedulerImpl { 175 class RendererSchedulerImplForTest : public RendererSchedulerImpl {
176 public: 176 public:
177 using RendererSchedulerImpl::OnIdlePeriodEnded; 177 using RendererSchedulerImpl::OnIdlePeriodEnded;
178 using RendererSchedulerImpl::OnIdlePeriodStarted; 178 using RendererSchedulerImpl::OnIdlePeriodStarted;
179 179
180 RendererSchedulerImplForTest( 180 RendererSchedulerImplForTest(
181 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner) 181 scoped_refptr<SchedulerTqmDelegate> main_task_runner)
182 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} 182 : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {}
183 183
184 void UpdatePolicyLocked(UpdateType update_type) override { 184 void UpdatePolicyLocked(UpdateType update_type) override {
185 update_policy_count_++; 185 update_policy_count_++;
186 RendererSchedulerImpl::UpdatePolicyLocked(update_type); 186 RendererSchedulerImpl::UpdatePolicyLocked(update_type);
187 187
188 std::string use_case = 188 std::string use_case =
189 RendererScheduler::UseCaseToString(MainThreadOnly().current_use_case); 189 RendererScheduler::UseCaseToString(MainThreadOnly().current_use_case);
190 if (MainThreadOnly().touchstart_expected_soon) { 190 if (MainThreadOnly().touchstart_expected_soon) {
191 use_cases_.push_back(use_case + " scroll expected"); 191 use_cases_.push_back(use_case + " scroll expected");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 229
230 RendererSchedulerImplTest(base::MessageLoop* message_loop) 230 RendererSchedulerImplTest(base::MessageLoop* message_loop)
231 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) { 231 : clock_(new base::SimpleTestTickClock()), message_loop_(message_loop) {
232 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); 232 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
233 } 233 }
234 234
235 ~RendererSchedulerImplTest() override {} 235 ~RendererSchedulerImplTest() override {}
236 236
237 void SetUp() override { 237 void SetUp() override {
238 if (message_loop_) { 238 if (message_loop_) {
239 main_task_runner_ = 239 main_task_runner_ = SchedulerTqmDelegateImpl::Create(
240 SchedulerTaskRunnerDelegateImpl::Create(message_loop_.get()); 240 message_loop_.get(),
241 make_scoped_ptr(new TestTimeSource(clock_.get())));
241 } else { 242 } else {
242 mock_task_runner_ = make_scoped_refptr( 243 mock_task_runner_ = make_scoped_refptr(
243 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); 244 new cc::OrderedSimpleTaskRunner(clock_.get(), false));
244 main_task_runner_ = 245 main_task_runner_ = SchedulerTqmDelegateForTest::Create(
245 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); 246 mock_task_runner_, make_scoped_ptr(new TestTimeSource(clock_.get())));
246 } 247 }
247 Initialize( 248 Initialize(
248 make_scoped_ptr(new RendererSchedulerImplForTest(main_task_runner_))); 249 make_scoped_ptr(new RendererSchedulerImplForTest(main_task_runner_)));
249 } 250 }
250 251
251 void Initialize(scoped_ptr<RendererSchedulerImplForTest> scheduler) { 252 void Initialize(scoped_ptr<RendererSchedulerImplForTest> scheduler) {
252 scheduler_ = scheduler.Pass(); 253 scheduler_ = scheduler.Pass();
253 default_task_runner_ = scheduler_->DefaultTaskRunner(); 254 default_task_runner_ = scheduler_->DefaultTaskRunner();
254 compositor_task_runner_ = scheduler_->CompositorTaskRunner(); 255 compositor_task_runner_ = scheduler_->CompositorTaskRunner();
255 loading_task_runner_ = scheduler_->LoadingTaskRunner(); 256 loading_task_runner_ = scheduler_->LoadingTaskRunner();
256 idle_task_runner_ = scheduler_->IdleTaskRunner(); 257 idle_task_runner_ = scheduler_->IdleTaskRunner();
257 timer_task_runner_ = scheduler_->TimerTaskRunner(); 258 timer_task_runner_ = scheduler_->TimerTaskRunner();
258 scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting(
259 make_scoped_ptr(new TestTimeSource(clock_.get())));
260 scheduler_->GetSchedulerHelperForTesting()
261 ->GetTaskQueueManagerForTesting()
262 ->SetTimeSourceForTesting(
263 make_scoped_ptr(new TestTimeSource(clock_.get())));
264 scheduler_->GetLoadingTaskCostEstimatorForTesting()
265 ->SetTimeSourceForTesting(
266 make_scoped_ptr(new TestTimeSource(clock_.get())));
267 scheduler_->GetTimerTaskCostEstimatorForTesting()->SetTimeSourceForTesting(
268 make_scoped_ptr(new TestTimeSource(clock_.get())));
269 scheduler_->GetIdleTimeEstimatorForTesting()->SetTimeSourceForTesting(
270 make_scoped_ptr(new TestTimeSource(clock_.get())));
271 } 259 }
272 260
273 void TearDown() override { 261 void TearDown() override {
274 DCHECK(!mock_task_runner_.get() || !message_loop_.get()); 262 DCHECK(!mock_task_runner_.get() || !message_loop_.get());
275 scheduler_->Shutdown(); 263 scheduler_->Shutdown();
276 if (mock_task_runner_.get()) { 264 if (mock_task_runner_.get()) {
277 // Check that all tests stop posting tasks. 265 // Check that all tests stop posting tasks.
278 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true); 266 mock_task_runner_->SetAutoAdvanceNowToPendingTasks(true);
279 while (mock_task_runner_->RunUntilIdle()) { 267 while (mock_task_runner_->RunUntilIdle()) {
280 } 268 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 RendererSchedulerImpl::UseCase::FIRST_USE_CASE, 467 RendererSchedulerImpl::UseCase::FIRST_USE_CASE,
480 RendererSchedulerImpl::UseCase::USE_CASE_COUNT, 468 RendererSchedulerImpl::UseCase::USE_CASE_COUNT,
481 &RendererSchedulerImpl::UseCaseToString); 469 &RendererSchedulerImpl::UseCaseToString);
482 } 470 }
483 471
484 scoped_ptr<base::SimpleTestTickClock> clock_; 472 scoped_ptr<base::SimpleTestTickClock> clock_;
485 // Only one of mock_task_runner_ or message_loop_ will be set. 473 // Only one of mock_task_runner_ or message_loop_ will be set.
486 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 474 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
487 scoped_ptr<base::MessageLoop> message_loop_; 475 scoped_ptr<base::MessageLoop> message_loop_;
488 476
489 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; 477 scoped_refptr<SchedulerTqmDelegate> main_task_runner_;
490 scoped_ptr<RendererSchedulerImplForTest> scheduler_; 478 scoped_ptr<RendererSchedulerImplForTest> scheduler_;
491 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 479 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
492 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 480 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
493 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 481 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
494 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 482 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
495 scoped_refptr<base::SingleThreadTaskRunner> timer_task_runner_; 483 scoped_refptr<base::SingleThreadTaskRunner> timer_task_runner_;
496 bool simulate_timer_task_ran_; 484 bool simulate_timer_task_ran_;
497 485
498 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest); 486 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImplTest);
499 }; 487 };
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 RunUntilIdle(); 1349 RunUntilIdle();
1362 EXPECT_EQ(UseCase::NONE, CurrentUseCase()); 1350 EXPECT_EQ(UseCase::NONE, CurrentUseCase());
1363 } 1351 }
1364 1352
1365 class RendererSchedulerImplWithMockSchedulerTest 1353 class RendererSchedulerImplWithMockSchedulerTest
1366 : public RendererSchedulerImplTest { 1354 : public RendererSchedulerImplTest {
1367 public: 1355 public:
1368 void SetUp() override { 1356 void SetUp() override {
1369 mock_task_runner_ = make_scoped_refptr( 1357 mock_task_runner_ = make_scoped_refptr(
1370 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); 1358 new cc::OrderedSimpleTaskRunner(clock_.get(), false));
1371 main_task_runner_ = 1359 main_task_runner_ = SchedulerTqmDelegateForTest::Create(
1372 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); 1360 mock_task_runner_, make_scoped_ptr(new TestTimeSource(clock_.get())));
1373 mock_scheduler_ = new RendererSchedulerImplForTest(main_task_runner_); 1361 mock_scheduler_ = new RendererSchedulerImplForTest(main_task_runner_);
1374 Initialize(make_scoped_ptr(mock_scheduler_)); 1362 Initialize(make_scoped_ptr(mock_scheduler_));
1375 } 1363 }
1376 1364
1377 protected: 1365 protected:
1378 RendererSchedulerImplForTest* mock_scheduler_; 1366 RendererSchedulerImplForTest* mock_scheduler_;
1379 }; 1367 };
1380 1368
1381 TEST_F(RendererSchedulerImplWithMockSchedulerTest, 1369 TEST_F(RendererSchedulerImplWithMockSchedulerTest,
1382 OnlyOnePendingUrgentPolicyUpdatey) { 1370 OnlyOnePendingUrgentPolicyUpdatey) {
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 } 2214 }
2227 2215
2228 base::TimeDelta time_till_next_frame = 2216 base::TimeDelta time_till_next_frame =
2229 EstimatedNextFrameBegin() - clock_->NowTicks(); 2217 EstimatedNextFrameBegin() - clock_->NowTicks();
2230 if (time_till_next_frame > base::TimeDelta()) 2218 if (time_till_next_frame > base::TimeDelta())
2231 clock_->Advance(time_till_next_frame); 2219 clock_->Advance(time_till_next_frame);
2232 } 2220 }
2233 } 2221 }
2234 2222
2235 } // namespace scheduler 2223 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/renderer_scheduler_impl.cc ('k') | components/scheduler/renderer/task_cost_estimator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698