OLD | NEW |
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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
9 #include "cc/test/ordered_simple_task_runner.h" | 9 #include "cc/test/ordered_simple_task_runner.h" |
10 #include "components/scheduler/base/task_queue_manager.h" | 10 #include "components/scheduler/base/task_queue_manager.h" |
| 11 #include "components/scheduler/base/test_task_time_tracker.h" |
11 #include "components/scheduler/base/test_time_source.h" | 12 #include "components/scheduler/base/test_time_source.h" |
12 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h" | 13 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace scheduler { | 17 namespace scheduler { |
17 | 18 |
18 class IdleTimeEstimatorForTest : public IdleTimeEstimator { | 19 class IdleTimeEstimatorForTest : public IdleTimeEstimator { |
19 public: | 20 public: |
20 IdleTimeEstimatorForTest( | 21 IdleTimeEstimatorForTest( |
(...skipping 14 matching lines...) Expand all Loading... |
35 | 36 |
36 ~IdleTimeEstimatorTest() override {} | 37 ~IdleTimeEstimatorTest() override {} |
37 | 38 |
38 void SetUp() override { | 39 void SetUp() override { |
39 clock_.reset(new base::SimpleTestTickClock()); | 40 clock_.reset(new base::SimpleTestTickClock()); |
40 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); | 41 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); |
41 test_time_source_.reset(new TestTimeSource(clock_.get())); | 42 test_time_source_.reset(new TestTimeSource(clock_.get())); |
42 mock_task_runner_ = make_scoped_refptr( | 43 mock_task_runner_ = make_scoped_refptr( |
43 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); | 44 new cc::OrderedSimpleTaskRunner(clock_.get(), false)); |
44 main_task_runner_ = SchedulerTqmDelegateForTest::Create( | 45 main_task_runner_ = SchedulerTqmDelegateForTest::Create( |
45 mock_task_runner_, base::WrapUnique(new TestTimeSource(clock_.get()))); | 46 mock_task_runner_, base::MakeUnique<TestTimeSource>(clock_.get())); |
46 manager_ = base::WrapUnique( | 47 manager_ = base::MakeUnique<TaskQueueManager>( |
47 new TaskQueueManager(main_task_runner_, "test.scheduler", | 48 main_task_runner_, "test.scheduler", "test.scheduler", |
48 "test.scheduler", "test.scheduler.debug")); | 49 "test.scheduler.debug"); |
49 compositor_task_runner_ = | 50 compositor_task_runner_ = |
50 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq")); | 51 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq")); |
51 estimator_.reset(new IdleTimeEstimatorForTest( | 52 estimator_.reset(new IdleTimeEstimatorForTest( |
52 compositor_task_runner_, test_time_source_.get(), 10, 50)); | 53 compositor_task_runner_, test_time_source_.get(), 10, 50)); |
53 } | 54 } |
54 | 55 |
55 void SimulateFrameWithOneCompositorTask(int compositor_time) { | 56 void SimulateFrameWithOneCompositorTask(int compositor_time) { |
56 base::TimeDelta non_idle_time = | 57 base::TimeDelta non_idle_time = |
57 base::TimeDelta::FromMilliseconds(compositor_time); | 58 base::TimeDelta::FromMilliseconds(compositor_time); |
58 base::PendingTask task(FROM_HERE, base::Closure()); | 59 base::PendingTask task(FROM_HERE, base::Closure()); |
(...skipping 26 matching lines...) Expand all Loading... |
85 } | 86 } |
86 | 87 |
87 std::unique_ptr<base::SimpleTestTickClock> clock_; | 88 std::unique_ptr<base::SimpleTestTickClock> clock_; |
88 std::unique_ptr<TestTimeSource> test_time_source_; | 89 std::unique_ptr<TestTimeSource> test_time_source_; |
89 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; | 90 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; |
90 scoped_refptr<SchedulerTqmDelegate> main_task_runner_; | 91 scoped_refptr<SchedulerTqmDelegate> main_task_runner_; |
91 std::unique_ptr<TaskQueueManager> manager_; | 92 std::unique_ptr<TaskQueueManager> manager_; |
92 scoped_refptr<TaskQueue> compositor_task_runner_; | 93 scoped_refptr<TaskQueue> compositor_task_runner_; |
93 std::unique_ptr<IdleTimeEstimatorForTest> estimator_; | 94 std::unique_ptr<IdleTimeEstimatorForTest> estimator_; |
94 const base::TimeDelta frame_length_; | 95 const base::TimeDelta frame_length_; |
| 96 TestTaskTimeTracker test_task_time_tracker_; |
95 }; | 97 }; |
96 | 98 |
97 TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) { | 99 TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) { |
98 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_)); | 100 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_)); |
99 } | 101 } |
100 | 102 |
101 TEST_F(IdleTimeEstimatorTest, BasicEstimation_SteadyState) { | 103 TEST_F(IdleTimeEstimatorTest, BasicEstimation_SteadyState) { |
102 SimulateFrameWithOneCompositorTask(5); | 104 SimulateFrameWithOneCompositorTask(5); |
103 SimulateFrameWithOneCompositorTask(5); | 105 SimulateFrameWithOneCompositorTask(5); |
104 | 106 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 SimulateFrameWithTwoCompositorTasks(4, 4); | 160 SimulateFrameWithTwoCompositorTasks(4, 4); |
159 estimator_->DidCommitFrameToCompositor(); | 161 estimator_->DidCommitFrameToCompositor(); |
160 estimator_->DidProcessTask(task); | 162 estimator_->DidProcessTask(task); |
161 | 163 |
162 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11), | 164 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11), |
163 estimator_->GetExpectedIdleDuration(frame_length_)); | 165 estimator_->GetExpectedIdleDuration(frame_length_)); |
164 } | 166 } |
165 | 167 |
166 | 168 |
167 } // namespace scheduler | 169 } // namespace scheduler |
OLD | NEW |