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

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

Issue 1132753008: Replaced TestNowSource with SimpleTestTickClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased again. Replaces TimeSource with TickClock in TestAlwaysFailTimeSource Created 5 years, 6 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
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 "components/scheduler/renderer/deadline_task_runner.h" 6 #include "components/scheduler/renderer/deadline_task_runner.h"
6 7
7 #include "cc/test/ordered_simple_task_runner.h" 8 #include "cc/test/ordered_simple_task_runner.h"
8 #include "cc/test/test_now_source.h"
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 DeadlineTaskRunnerTest : public testing::Test { 14 class DeadlineTaskRunnerTest : public testing::Test {
15 public: 15 public:
16 DeadlineTaskRunnerTest() {} 16 DeadlineTaskRunnerTest() {}
17 ~DeadlineTaskRunnerTest() override {} 17 ~DeadlineTaskRunnerTest() override {}
18 18
19 void SetUp() override { 19 void SetUp() override {
20 clock_ = cc::TestNowSource::Create(5000); 20 clock_.reset(new base::SimpleTestTickClock());
21 mock_task_runner_ = new cc::OrderedSimpleTaskRunner(clock_, true); 21 clock_->Advance(base::TimeDelta::FromInternalValue(5000));
22 mock_task_runner_ = new cc::OrderedSimpleTaskRunner(clock_.get(), true);
22 deadline_task_runner_.reset(new DeadlineTaskRunner( 23 deadline_task_runner_.reset(new DeadlineTaskRunner(
23 base::Bind(&DeadlineTaskRunnerTest::TestTask, base::Unretained(this)), 24 base::Bind(&DeadlineTaskRunnerTest::TestTask, base::Unretained(this)),
24 mock_task_runner_)); 25 mock_task_runner_));
25 run_times_.clear(); 26 run_times_.clear();
26 } 27 }
27 28
28 bool RunUntilIdle() { return mock_task_runner_->RunUntilIdle(); } 29 bool RunUntilIdle() { return mock_task_runner_->RunUntilIdle(); }
29 30
30 void TestTask() { run_times_.push_back(clock_->Now()); } 31 void TestTask() { run_times_.push_back(clock_->NowTicks()); }
31 32
32 scoped_refptr<cc::TestNowSource> clock_; 33 scoped_ptr<base::SimpleTestTickClock> clock_;
33 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; 34 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
34 scoped_ptr<DeadlineTaskRunner> deadline_task_runner_; 35 scoped_ptr<DeadlineTaskRunner> deadline_task_runner_;
35 std::vector<base::TimeTicks> run_times_; 36 std::vector<base::TimeTicks> run_times_;
36 }; 37 };
37 38
38 TEST_F(DeadlineTaskRunnerTest, RunOnce) { 39 TEST_F(DeadlineTaskRunnerTest, RunOnce) {
39 base::TimeTicks start_time = clock_->Now(); 40 base::TimeTicks start_time = clock_->NowTicks();
40 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); 41 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10);
41 deadline_task_runner_->SetDeadline(FROM_HERE, delay, clock_->Now()); 42 deadline_task_runner_->SetDeadline(FROM_HERE, delay, clock_->NowTicks());
42 RunUntilIdle(); 43 RunUntilIdle();
43 44
44 EXPECT_THAT(run_times_, testing::ElementsAre(start_time + delay)); 45 EXPECT_THAT(run_times_, testing::ElementsAre(start_time + delay));
45 }; 46 };
46 47
47 TEST_F(DeadlineTaskRunnerTest, RunTwice) { 48 TEST_F(DeadlineTaskRunnerTest, RunTwice) {
48 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(10); 49 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(10);
49 base::TimeTicks deadline1 = clock_->Now() + delay1; 50 base::TimeTicks deadline1 = clock_->NowTicks() + delay1;
50 deadline_task_runner_->SetDeadline(FROM_HERE, delay1, clock_->Now()); 51 deadline_task_runner_->SetDeadline(FROM_HERE, delay1, clock_->NowTicks());
51 RunUntilIdle(); 52 RunUntilIdle();
52 53
53 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(100); 54 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(100);
54 base::TimeTicks deadline2 = clock_->Now() + delay2; 55 base::TimeTicks deadline2 = clock_->NowTicks() + delay2;
55 deadline_task_runner_->SetDeadline(FROM_HERE, delay2, clock_->Now()); 56 deadline_task_runner_->SetDeadline(FROM_HERE, delay2, clock_->NowTicks());
56 RunUntilIdle(); 57 RunUntilIdle();
57 58
58 EXPECT_THAT(run_times_, testing::ElementsAre(deadline1, deadline2)); 59 EXPECT_THAT(run_times_, testing::ElementsAre(deadline1, deadline2));
59 }; 60 };
60 61
61 TEST_F(DeadlineTaskRunnerTest, EarlierDeadlinesTakePrecidence) { 62 TEST_F(DeadlineTaskRunnerTest, EarlierDeadlinesTakePrecidence) {
62 base::TimeTicks start_time = clock_->Now(); 63 base::TimeTicks start_time = clock_->NowTicks();
63 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(1); 64 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(1);
64 base::TimeDelta delay10 = base::TimeDelta::FromMilliseconds(10); 65 base::TimeDelta delay10 = base::TimeDelta::FromMilliseconds(10);
65 base::TimeDelta delay100 = base::TimeDelta::FromMilliseconds(100); 66 base::TimeDelta delay100 = base::TimeDelta::FromMilliseconds(100);
66 deadline_task_runner_->SetDeadline(FROM_HERE, delay100, clock_->Now()); 67 deadline_task_runner_->SetDeadline(FROM_HERE, delay100, clock_->NowTicks());
67 deadline_task_runner_->SetDeadline(FROM_HERE, delay10, clock_->Now()); 68 deadline_task_runner_->SetDeadline(FROM_HERE, delay10, clock_->NowTicks());
68 deadline_task_runner_->SetDeadline(FROM_HERE, delay1, clock_->Now()); 69 deadline_task_runner_->SetDeadline(FROM_HERE, delay1, clock_->NowTicks());
69 70
70 RunUntilIdle(); 71 RunUntilIdle();
71 72
72 EXPECT_THAT(run_times_, testing::ElementsAre(start_time + delay1)); 73 EXPECT_THAT(run_times_, testing::ElementsAre(start_time + delay1));
73 }; 74 };
74 75
75 TEST_F(DeadlineTaskRunnerTest, LaterDeadlinesIgnored) { 76 TEST_F(DeadlineTaskRunnerTest, LaterDeadlinesIgnored) {
76 base::TimeTicks start_time = clock_->Now(); 77 base::TimeTicks start_time = clock_->NowTicks();
77 base::TimeDelta delay100 = base::TimeDelta::FromMilliseconds(100); 78 base::TimeDelta delay100 = base::TimeDelta::FromMilliseconds(100);
78 base::TimeDelta delay10000 = base::TimeDelta::FromMilliseconds(10000); 79 base::TimeDelta delay10000 = base::TimeDelta::FromMilliseconds(10000);
79 deadline_task_runner_->SetDeadline(FROM_HERE, delay100, clock_->Now()); 80 deadline_task_runner_->SetDeadline(FROM_HERE, delay100, clock_->NowTicks());
80 deadline_task_runner_->SetDeadline(FROM_HERE, delay10000, clock_->Now()); 81 deadline_task_runner_->SetDeadline(FROM_HERE, delay10000, clock_->NowTicks());
81 82
82 RunUntilIdle(); 83 RunUntilIdle();
83 84
84 EXPECT_THAT(run_times_, testing::ElementsAre(start_time + delay100)); 85 EXPECT_THAT(run_times_, testing::ElementsAre(start_time + delay100));
85 }; 86 };
86 87
87 TEST_F(DeadlineTaskRunnerTest, DeleteDeadlineTaskRunnerAfterPosting) { 88 TEST_F(DeadlineTaskRunnerTest, DeleteDeadlineTaskRunnerAfterPosting) {
88 deadline_task_runner_->SetDeadline( 89 deadline_task_runner_->SetDeadline(
89 FROM_HERE, base::TimeDelta::FromMilliseconds(10), clock_->Now()); 90 FROM_HERE, base::TimeDelta::FromMilliseconds(10), clock_->NowTicks());
90 91
91 // Deleting the pending task should cancel it. 92 // Deleting the pending task should cancel it.
92 deadline_task_runner_.reset(nullptr); 93 deadline_task_runner_.reset(nullptr);
93 RunUntilIdle(); 94 RunUntilIdle();
94 95
95 EXPECT_TRUE(run_times_.empty()); 96 EXPECT_TRUE(run_times_.empty());
96 }; 97 };
97 98
98 } // namespace scheduler 99 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698