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 "base/test/simple_test_tick_clock.h" | 5 #include "base/test/simple_test_tick_clock.h" |
6 #include "components/scheduler/base/test_time_source.h" | 6 #include "components/scheduler/base/test_time_source.h" |
7 #include "components/scheduler/renderer/task_cost_estimator.h" | 7 #include "components/scheduler/renderer/task_cost_estimator.h" |
8 | 8 |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace scheduler { | 12 namespace scheduler { |
13 | 13 |
14 class TaskCostEstimatorTest : public testing::Test { | 14 class TaskCostEstimatorTest : public testing::Test { |
15 public: | 15 public: |
16 TaskCostEstimatorTest() {} | 16 TaskCostEstimatorTest() {} |
17 ~TaskCostEstimatorTest() override {} | 17 ~TaskCostEstimatorTest() override {} |
18 | 18 |
19 void SetUp() override {} | 19 void SetUp() override { |
| 20 test_time_source_.reset(new TestTimeSource(&clock_)); |
| 21 } |
20 | 22 |
21 base::SimpleTestTickClock clock_; | 23 base::SimpleTestTickClock clock_; |
| 24 scoped_ptr<TestTimeSource> test_time_source_; |
22 }; | 25 }; |
23 | 26 |
24 class TaskCostEstimatorForTest : public TaskCostEstimator { | 27 class TaskCostEstimatorForTest : public TaskCostEstimator { |
25 public: | 28 public: |
26 TaskCostEstimatorForTest(base::SimpleTestTickClock* clock, | 29 TaskCostEstimatorForTest(TestTimeSource* test_time_source, |
27 int sample_count, | 30 int sample_count, |
28 double estimation_percentile) | 31 double estimation_percentile) |
29 : TaskCostEstimator(sample_count, estimation_percentile) { | 32 : TaskCostEstimator(test_time_source, |
30 SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock))); | 33 sample_count, |
31 } | 34 estimation_percentile) {} |
32 }; | 35 }; |
33 | 36 |
34 TEST_F(TaskCostEstimatorTest, BasicEstimation) { | 37 TEST_F(TaskCostEstimatorTest, BasicEstimation) { |
35 TaskCostEstimatorForTest estimator(&clock_, 1, 100); | 38 TaskCostEstimatorForTest estimator(test_time_source_.get(), 1, 100); |
36 base::PendingTask task(FROM_HERE, base::Closure()); | 39 base::PendingTask task(FROM_HERE, base::Closure()); |
37 | 40 |
38 estimator.WillProcessTask(task); | 41 estimator.WillProcessTask(task); |
39 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); | 42 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); |
40 estimator.DidProcessTask(task); | 43 estimator.DidProcessTask(task); |
41 | 44 |
42 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), | 45 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), |
43 estimator.expected_task_duration()); | 46 estimator.expected_task_duration()); |
44 } | 47 } |
45 | 48 |
46 TEST_F(TaskCostEstimatorTest, Clear) { | 49 TEST_F(TaskCostEstimatorTest, Clear) { |
47 TaskCostEstimatorForTest estimator(&clock_, 1, 100); | 50 TaskCostEstimatorForTest estimator(test_time_source_.get(), 1, 100); |
48 base::PendingTask task(FROM_HERE, base::Closure()); | 51 base::PendingTask task(FROM_HERE, base::Closure()); |
49 | 52 |
50 estimator.WillProcessTask(task); | 53 estimator.WillProcessTask(task); |
51 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); | 54 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); |
52 estimator.DidProcessTask(task); | 55 estimator.DidProcessTask(task); |
53 | 56 |
54 estimator.Clear(); | 57 estimator.Clear(); |
55 | 58 |
56 EXPECT_EQ(base::TimeDelta(), estimator.expected_task_duration()); | 59 EXPECT_EQ(base::TimeDelta(), estimator.expected_task_duration()); |
57 } | 60 } |
58 | 61 |
59 TEST_F(TaskCostEstimatorTest, NestedRunLoop) { | 62 TEST_F(TaskCostEstimatorTest, NestedRunLoop) { |
60 TaskCostEstimatorForTest estimator(&clock_, 1, 100); | 63 TaskCostEstimatorForTest estimator(test_time_source_.get(), 1, 100); |
61 base::PendingTask task(FROM_HERE, base::Closure()); | 64 base::PendingTask task(FROM_HERE, base::Closure()); |
62 | 65 |
63 // Make sure we ignore the tasks inside the nested run loop. | 66 // Make sure we ignore the tasks inside the nested run loop. |
64 estimator.WillProcessTask(task); | 67 estimator.WillProcessTask(task); |
65 estimator.WillProcessTask(task); | 68 estimator.WillProcessTask(task); |
66 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); | 69 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); |
67 estimator.DidProcessTask(task); | 70 estimator.DidProcessTask(task); |
68 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); | 71 clock_.Advance(base::TimeDelta::FromMilliseconds(500)); |
69 estimator.DidProcessTask(task); | 72 estimator.DidProcessTask(task); |
70 | 73 |
71 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), | 74 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), |
72 estimator.expected_task_duration()); | 75 estimator.expected_task_duration()); |
73 } | 76 } |
74 | 77 |
75 } // namespace scheduler | 78 } // namespace scheduler |
OLD | NEW |