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

Side by Side Diff: components/scheduler/renderer/task_cost_estimator_unittest.cc

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 months 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
(Empty)
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.
4
5 #include "components/scheduler/renderer/task_cost_estimator.h"
6
7 #include <memory>
8
9 #include "base/test/simple_test_tick_clock.h"
10 #include "components/scheduler/base/test_time_source.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace scheduler {
15
16 class TaskCostEstimatorTest : public testing::Test {
17 public:
18 TaskCostEstimatorTest() {}
19 ~TaskCostEstimatorTest() override {}
20
21 void SetUp() override {
22 test_time_source_.reset(new TestTimeSource(&clock_));
23 }
24
25 base::SimpleTestTickClock clock_;
26 std::unique_ptr<TestTimeSource> test_time_source_;
27 };
28
29 class TaskCostEstimatorForTest : public TaskCostEstimator {
30 public:
31 TaskCostEstimatorForTest(TestTimeSource* test_time_source,
32 int sample_count,
33 double estimation_percentile)
34 : TaskCostEstimator(test_time_source,
35 sample_count,
36 estimation_percentile) {}
37 };
38
39 TEST_F(TaskCostEstimatorTest, BasicEstimation) {
40 TaskCostEstimatorForTest estimator(test_time_source_.get(), 1, 100);
41 base::PendingTask task(FROM_HERE, base::Closure());
42
43 estimator.WillProcessTask(task);
44 clock_.Advance(base::TimeDelta::FromMilliseconds(500));
45 estimator.DidProcessTask(task);
46
47 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500),
48 estimator.expected_task_duration());
49 }
50
51 TEST_F(TaskCostEstimatorTest, Clear) {
52 TaskCostEstimatorForTest estimator(test_time_source_.get(), 1, 100);
53 base::PendingTask task(FROM_HERE, base::Closure());
54
55 estimator.WillProcessTask(task);
56 clock_.Advance(base::TimeDelta::FromMilliseconds(500));
57 estimator.DidProcessTask(task);
58
59 estimator.Clear();
60
61 EXPECT_EQ(base::TimeDelta(), estimator.expected_task_duration());
62 }
63
64 TEST_F(TaskCostEstimatorTest, NestedRunLoop) {
65 TaskCostEstimatorForTest estimator(test_time_source_.get(), 1, 100);
66 base::PendingTask task(FROM_HERE, base::Closure());
67
68 // Make sure we ignore the tasks inside the nested run loop.
69 estimator.WillProcessTask(task);
70 estimator.WillProcessTask(task);
71 clock_.Advance(base::TimeDelta::FromMilliseconds(500));
72 estimator.DidProcessTask(task);
73 clock_.Advance(base::TimeDelta::FromMilliseconds(500));
74 estimator.DidProcessTask(task);
75
76 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000),
77 estimator.expected_task_duration());
78 }
79
80 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/task_cost_estimator.cc ('k') | components/scheduler/renderer/throttled_time_domain.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698