forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_cost_estimator_unittest.cc
75 lines (57 loc) · 2.34 KB
/
task_cost_estimator_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/simple_test_tick_clock.h"
#include "components/scheduler/base/test_time_source.h"
#include "components/scheduler/renderer/task_cost_estimator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace scheduler {
class TaskCostEstimatorTest : public testing::Test {
public:
TaskCostEstimatorTest() {}
~TaskCostEstimatorTest() override {}
void SetUp() override {}
base::SimpleTestTickClock clock_;
};
class TaskCostEstimatorForTest : public TaskCostEstimator {
public:
TaskCostEstimatorForTest(base::SimpleTestTickClock* clock,
int sample_count,
double estimation_percentile)
: TaskCostEstimator(sample_count, estimation_percentile) {
SetTimeSourceForTesting(make_scoped_ptr(new TestTimeSource(clock)));
}
};
TEST_F(TaskCostEstimatorTest, BasicEstimation) {
TaskCostEstimatorForTest estimator(&clock_, 1, 100);
base::PendingTask task(FROM_HERE, base::Closure());
estimator.WillProcessTask(task);
clock_.Advance(base::TimeDelta::FromMilliseconds(500));
estimator.DidProcessTask(task);
EXPECT_EQ(base::TimeDelta::FromMilliseconds(500),
estimator.expected_task_duration());
}
TEST_F(TaskCostEstimatorTest, Clear) {
TaskCostEstimatorForTest estimator(&clock_, 1, 100);
base::PendingTask task(FROM_HERE, base::Closure());
estimator.WillProcessTask(task);
clock_.Advance(base::TimeDelta::FromMilliseconds(500));
estimator.DidProcessTask(task);
estimator.Clear();
EXPECT_EQ(base::TimeDelta(), estimator.expected_task_duration());
}
TEST_F(TaskCostEstimatorTest, NestedRunLoop) {
TaskCostEstimatorForTest estimator(&clock_, 1, 100);
base::PendingTask task(FROM_HERE, base::Closure());
// Make sure we ignore the tasks inside the nested run loop.
estimator.WillProcessTask(task);
estimator.WillProcessTask(task);
clock_.Advance(base::TimeDelta::FromMilliseconds(500));
estimator.DidProcessTask(task);
clock_.Advance(base::TimeDelta::FromMilliseconds(500));
estimator.DidProcessTask(task);
EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000),
estimator.expected_task_duration());
}
} // namespace scheduler