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

Side by Side Diff: components/scheduler/renderer/idle_time_estimator_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/idle_time_estimator.h" 5 #include "components/scheduler/renderer/idle_time_estimator.h"
6 6
7 #include "base/test/simple_test_tick_clock.h" 7 #include "base/test/simple_test_tick_clock.h"
8 #include "cc/test/ordered_simple_task_runner.h" 8 #include "cc/test/ordered_simple_task_runner.h"
9 #include "components/scheduler/base/task_queue_manager.h" 9 #include "components/scheduler/base/task_queue_manager.h"
10 #include "components/scheduler/base/test_time_source.h" 10 #include "components/scheduler/base/test_time_source.h"
11 #include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" 11 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace scheduler { 15 namespace scheduler {
16 16
17 class IdleTimeEstimatorForTest : public IdleTimeEstimator { 17 class IdleTimeEstimatorForTest : public IdleTimeEstimator {
18 public: 18 public:
19 IdleTimeEstimatorForTest( 19 IdleTimeEstimatorForTest(
20 const scoped_refptr<TaskQueue>& compositor_task_runner, 20 const scoped_refptr<TaskQueue>& compositor_task_runner,
21 base::SimpleTestTickClock* clock, 21 TestTimeSource* test_time_source,
22 int sample_count, 22 int sample_count,
23 double estimation_percentile) 23 double estimation_percentile)
24 : IdleTimeEstimator(compositor_task_runner, 24 : IdleTimeEstimator(compositor_task_runner,
25 test_time_source,
25 sample_count, 26 sample_count,
26 estimation_percentile) { 27 estimation_percentile) {}
27 SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock)));
28 }
29 }; 28 };
30 29
31 class IdleTimeEstimatorTest : public testing::Test { 30 class IdleTimeEstimatorTest : public testing::Test {
32 public: 31 public:
33 IdleTimeEstimatorTest() 32 IdleTimeEstimatorTest()
34 : frame_length_(base::TimeDelta::FromMilliseconds(16)) {} 33 : frame_length_(base::TimeDelta::FromMilliseconds(16)) {}
35 34
36 ~IdleTimeEstimatorTest() override {} 35 ~IdleTimeEstimatorTest() override {}
37 36
38 void SetUp() override { 37 void SetUp() override {
39 clock_.reset(new base::SimpleTestTickClock()); 38 clock_.reset(new base::SimpleTestTickClock());
40 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); 39 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
40 test_time_source_.reset(new TestTimeSource(clock_.get()));
41 mock_task_runner_ = make_scoped_refptr( 41 mock_task_runner_ = make_scoped_refptr(
42 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); 42 new cc::OrderedSimpleTaskRunner(clock_.get(), false));
43 main_task_runner_ = 43 main_task_runner_ = SchedulerTqmDelegateForTest::Create(
44 SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); 44 mock_task_runner_, make_scoped_ptr(new TestTimeSource(clock_.get())));
45 manager_ = make_scoped_ptr(new TaskQueueManager( 45 manager_ = make_scoped_ptr(new TaskQueueManager(
46 main_task_runner_, "test.scheduler", "test.scheduler", 46 main_task_runner_, "test.scheduler", "test.scheduler",
47 "test.scheduler.debug")); 47 "test.scheduler.debug"));
48 compositor_task_runner_ = 48 compositor_task_runner_ =
49 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq")); 49 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq"));
50 estimator_.reset(new IdleTimeEstimatorForTest(compositor_task_runner_, 50 estimator_.reset(new IdleTimeEstimatorForTest(
51 clock_.get(), 10, 50)); 51 compositor_task_runner_, test_time_source_.get(), 10, 50));
52 } 52 }
53 53
54 void SimulateFrameWithOneCompositorTask(int compositor_time) { 54 void SimulateFrameWithOneCompositorTask(int compositor_time) {
55 base::TimeDelta non_idle_time = 55 base::TimeDelta non_idle_time =
56 base::TimeDelta::FromMilliseconds(compositor_time); 56 base::TimeDelta::FromMilliseconds(compositor_time);
57 base::PendingTask task(FROM_HERE, base::Closure()); 57 base::PendingTask task(FROM_HERE, base::Closure());
58 estimator_->WillProcessTask(task); 58 estimator_->WillProcessTask(task);
59 clock_->Advance(non_idle_time); 59 clock_->Advance(non_idle_time);
60 estimator_->DidCommitFrameToCompositor(); 60 estimator_->DidCommitFrameToCompositor();
61 estimator_->DidProcessTask(task); 61 estimator_->DidProcessTask(task);
(...skipping 15 matching lines...) Expand all
77 estimator_->WillProcessTask(task); 77 estimator_->WillProcessTask(task);
78 clock_->Advance(non_idle_time2); 78 clock_->Advance(non_idle_time2);
79 estimator_->DidCommitFrameToCompositor(); 79 estimator_->DidCommitFrameToCompositor();
80 estimator_->DidProcessTask(task); 80 estimator_->DidProcessTask(task);
81 81
82 base::TimeDelta idle_time = frame_length_ - non_idle_time1 - non_idle_time2; 82 base::TimeDelta idle_time = frame_length_ - non_idle_time1 - non_idle_time2;
83 clock_->Advance(idle_time); 83 clock_->Advance(idle_time);
84 } 84 }
85 85
86 scoped_ptr<base::SimpleTestTickClock> clock_; 86 scoped_ptr<base::SimpleTestTickClock> clock_;
87 scoped_ptr<TestTimeSource> test_time_source_;
87 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 88 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
88 scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; 89 scoped_refptr<SchedulerTqmDelegate> main_task_runner_;
89 scoped_ptr<TaskQueueManager> manager_; 90 scoped_ptr<TaskQueueManager> manager_;
90 scoped_refptr<TaskQueue> compositor_task_runner_; 91 scoped_refptr<TaskQueue> compositor_task_runner_;
91 scoped_ptr<IdleTimeEstimatorForTest> estimator_; 92 scoped_ptr<IdleTimeEstimatorForTest> estimator_;
92 const base::TimeDelta frame_length_; 93 const base::TimeDelta frame_length_;
93 }; 94 };
94 95
95 TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) { 96 TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) {
96 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_)); 97 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_));
97 } 98 }
98 99
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 SimulateFrameWithTwoCompositorTasks(4, 4); 157 SimulateFrameWithTwoCompositorTasks(4, 4);
157 estimator_->DidCommitFrameToCompositor(); 158 estimator_->DidCommitFrameToCompositor();
158 estimator_->DidProcessTask(task); 159 estimator_->DidProcessTask(task);
159 160
160 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11), 161 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
161 estimator_->GetExpectedIdleDuration(frame_length_)); 162 estimator_->GetExpectedIdleDuration(frame_length_));
162 } 163 }
163 164
164 165
165 } // namespace scheduler 166 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/idle_time_estimator.cc ('k') | components/scheduler/renderer/renderer_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698