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

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

Issue 1303353003: scheduler: Disable expensive timers during main thread user input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 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 "base/test/simple_test_tick_clock.h"
6 #include "components/scheduler/renderer/task_cost_estimator.h"
7
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace scheduler {
12
13 class TaskCostEstimatorTest : public testing::Test {
14 public:
15 TaskCostEstimatorTest() {}
16 ~TaskCostEstimatorTest() override {}
17
18 void SetUp() override {}
19
20 base::SimpleTestTickClock clock_;
21 };
22
23 class TaskCostEstimatorForTest : public TaskCostEstimator {
24 public:
25 TaskCostEstimatorForTest(base::SimpleTestTickClock* clock,
26 int sample_count,
27 double estimation_percentile)
28 : TaskCostEstimator(sample_count, estimation_percentile), clock_(clock) {}
29
30 protected:
31 base::TimeTicks Now() override { return clock_->NowTicks(); }
32
33 private:
34 base::SimpleTestTickClock* clock_;
35 };
36
37 TEST_F(TaskCostEstimatorTest, BasicEstimation) {
38 TaskCostEstimatorForTest estimator(&clock_, 1, 100);
39 base::PendingTask task(FROM_HERE, base::Closure());
40
41 estimator.WillProcessTask(task);
42 clock_.Advance(base::TimeDelta::FromMilliseconds(500));
43 estimator.DidProcessTask(task);
44
45 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500),
46 estimator.expected_task_duration());
47 };
48
49 TEST_F(TaskCostEstimatorTest, NestedRunLoop) {
50 TaskCostEstimatorForTest estimator(&clock_, 1, 100);
51 base::PendingTask task(FROM_HERE, base::Closure());
52
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);
60
61 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000),
62 estimator.expected_task_duration());
63 };
64
65 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/task_cost_estimator.cc ('k') | components/scheduler/scheduler.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698