OLD | NEW |
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/test_mock_time_task_runner.h" | 5 #include "base/test/test_mock_time_task_runner.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/time/clock.h" | 10 #include "base/time/clock.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 const TestOrderedPendingTask& second_task) const { | 112 const TestOrderedPendingTask& second_task) const { |
113 if (first_task.GetTimeToRun() == second_task.GetTimeToRun()) | 113 if (first_task.GetTimeToRun() == second_task.GetTimeToRun()) |
114 return first_task.ordinal > second_task.ordinal; | 114 return first_task.ordinal > second_task.ordinal; |
115 return first_task.GetTimeToRun() > second_task.GetTimeToRun(); | 115 return first_task.GetTimeToRun() > second_task.GetTimeToRun(); |
116 } | 116 } |
117 | 117 |
118 TestMockTimeTaskRunner::TestMockTimeTaskRunner() | 118 TestMockTimeTaskRunner::TestMockTimeTaskRunner() |
119 : now_(Time::UnixEpoch()), next_task_ordinal_(0) { | 119 : now_(Time::UnixEpoch()), next_task_ordinal_(0) { |
120 } | 120 } |
121 | 121 |
| 122 TestMockTimeTaskRunner::TestMockTimeTaskRunner(Time start_time, |
| 123 TimeTicks start_ticks) |
| 124 : now_(Time::UnixEpoch()), now_ticks_(start_ticks), next_task_ordinal_(0) {} |
| 125 |
122 TestMockTimeTaskRunner::~TestMockTimeTaskRunner() { | 126 TestMockTimeTaskRunner::~TestMockTimeTaskRunner() { |
123 } | 127 } |
124 | 128 |
125 void TestMockTimeTaskRunner::FastForwardBy(TimeDelta delta) { | 129 void TestMockTimeTaskRunner::FastForwardBy(TimeDelta delta) { |
126 DCHECK(thread_checker_.CalledOnValidThread()); | 130 DCHECK(thread_checker_.CalledOnValidThread()); |
127 DCHECK_GE(delta, TimeDelta()); | 131 DCHECK_GE(delta, TimeDelta()); |
128 | 132 |
129 const TimeTicks original_now_ticks = now_ticks_; | 133 const TimeTicks original_now_ticks = now_ticks_; |
130 ProcessAllTasksNoLaterThan(delta); | 134 ProcessAllTasksNoLaterThan(delta); |
131 ForwardClocksUntilTickTime(original_now_ticks + delta); | 135 ForwardClocksUntilTickTime(original_now_ticks + delta); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (!tasks_.empty() && | 259 if (!tasks_.empty() && |
256 (tasks_.top().GetTimeToRun() - reference) <= max_delta) { | 260 (tasks_.top().GetTimeToRun() - reference) <= max_delta) { |
257 *next_task = tasks_.top(); | 261 *next_task = tasks_.top(); |
258 tasks_.pop(); | 262 tasks_.pop(); |
259 return true; | 263 return true; |
260 } | 264 } |
261 return false; | 265 return false; |
262 } | 266 } |
263 | 267 |
264 } // namespace base | 268 } // namespace base |
OLD | NEW |