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
3 // found in the LICENSE file.
5 #include "base/test/simple_test_tick_clock.h"
6 #include "components/scheduler/renderer/task_cost_estimator.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 class TaskCostEstimatorTest
: public testing::Test
{
15 TaskCostEstimatorTest() {}
16 ~TaskCostEstimatorTest() override
{}
18 void SetUp() override
{}
20 base::SimpleTestTickClock clock_
;
23 class TaskCostEstimatorForTest
: public TaskCostEstimator
{
25 TaskCostEstimatorForTest(base::SimpleTestTickClock
* clock
,
27 double estimation_percentile
)
28 : TaskCostEstimator(sample_count
, estimation_percentile
), clock_(clock
) {}
31 base::TimeTicks
Now() override
{ return clock_
->NowTicks(); }
34 base::SimpleTestTickClock
* clock_
;
37 TEST_F(TaskCostEstimatorTest
, BasicEstimation
) {
38 TaskCostEstimatorForTest
estimator(&clock_
, 1, 100);
39 base::PendingTask
task(FROM_HERE
, base::Closure());
41 estimator
.WillProcessTask(task
);
42 clock_
.Advance(base::TimeDelta::FromMilliseconds(500));
43 estimator
.DidProcessTask(task
);
45 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500),
46 estimator
.expected_task_duration());
49 TEST_F(TaskCostEstimatorTest
, NestedRunLoop
) {
50 TaskCostEstimatorForTest
estimator(&clock_
, 1, 100);
51 base::PendingTask
task(FROM_HERE
, base::Closure());
53 // Make sure we ignore the tasks inside the nested run loop.
54 estimator
.WillProcessTask(task
);
55 estimator
.WillProcessTask(task
);
56 clock_
.Advance(base::TimeDelta::FromMilliseconds(500));
57 estimator
.DidProcessTask(task
);
58 clock_
.Advance(base::TimeDelta::FromMilliseconds(500));
59 estimator
.DidProcessTask(task
);
61 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000),
62 estimator
.expected_task_duration());
65 } // namespace scheduler