| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" | 
| 9 #include "base/time/clock.h" | 9 #include "base/time/clock.h" | 
| 10 #include "base/time/tick_clock.h" | 10 #include "base/time/tick_clock.h" | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 151 } | 151 } | 
| 152 | 152 | 
| 153 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( | 153 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( | 
| 154     const tracked_objects::Location& from_here, | 154     const tracked_objects::Location& from_here, | 
| 155     const Closure& task, | 155     const Closure& task, | 
| 156     TimeDelta delay) { | 156     TimeDelta delay) { | 
| 157   NOTREACHED(); | 157   NOTREACHED(); | 
| 158   return false; | 158   return false; | 
| 159 } | 159 } | 
| 160 | 160 | 
|  | 161 bool TestMockTimeTaskRunner::IsElapsingStopped() { | 
|  | 162   return false; | 
|  | 163 } | 
|  | 164 | 
| 161 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { | 165 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { | 
| 162   // Empty default implementation. | 166   // Empty default implementation. | 
| 163 } | 167 } | 
| 164 | 168 | 
| 165 void TestMockTimeTaskRunner::OnAfterTimePassed() { | 169 void TestMockTimeTaskRunner::OnAfterTimePassed() { | 
| 166   // Empty default implementation. | 170   // Empty default implementation. | 
| 167 } | 171 } | 
| 168 | 172 | 
| 169 void TestMockTimeTaskRunner::OnAfterTaskRun() { | 173 void TestMockTimeTaskRunner::OnAfterTaskRun() { | 
| 170   // Empty default implementation. | 174   // Empty default implementation. | 
| 171 } | 175 } | 
| 172 | 176 | 
| 173 void TestMockTimeTaskRunner::ProcessAllTasksNoLaterThan(TimeDelta max_delta) { | 177 void TestMockTimeTaskRunner::ProcessAllTasksNoLaterThan(TimeDelta max_delta) { | 
| 174   DCHECK_GE(max_delta, TimeDelta()); | 178   DCHECK_GE(max_delta, TimeDelta()); | 
| 175   const TimeTicks original_now_ticks = now_ticks_; | 179   const TimeTicks original_now_ticks = now_ticks_; | 
| 176   while (true) { | 180   while (!IsElapsingStopped()) { | 
| 177     OnBeforeSelectingTask(); | 181     OnBeforeSelectingTask(); | 
| 178     TestPendingTask task_info; | 182     TestPendingTask task_info; | 
| 179     if (!DequeueNextTask(original_now_ticks, max_delta, &task_info)) | 183     if (!DequeueNextTask(original_now_ticks, max_delta, &task_info)) | 
| 180       break; | 184       break; | 
| 181     // If tasks were posted with a negative delay, task_info.GetTimeToRun() will | 185     // If tasks were posted with a negative delay, task_info.GetTimeToRun() will | 
| 182     // be less than |now_ticks_|. ForwardClocksUntilTickTime() takes care of not | 186     // be less than |now_ticks_|. ForwardClocksUntilTickTime() takes care of not | 
| 183     // moving the clock backwards in this case. | 187     // moving the clock backwards in this case. | 
| 184     ForwardClocksUntilTickTime(task_info.GetTimeToRun()); | 188     ForwardClocksUntilTickTime(task_info.GetTimeToRun()); | 
| 185     task_info.task.Run(); | 189     task_info.task.Run(); | 
| 186     OnAfterTaskRun(); | 190     OnAfterTaskRun(); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 203   if (!tasks_.empty() && | 207   if (!tasks_.empty() && | 
| 204       (tasks_.top().GetTimeToRun() - reference) <= max_delta) { | 208       (tasks_.top().GetTimeToRun() - reference) <= max_delta) { | 
| 205     *next_task = tasks_.top(); | 209     *next_task = tasks_.top(); | 
| 206     tasks_.pop(); | 210     tasks_.pop(); | 
| 207     return true; | 211     return true; | 
| 208   } | 212   } | 
| 209   return false; | 213   return false; | 
| 210 } | 214 } | 
| 211 | 215 | 
| 212 }  // namespace base | 216 }  // namespace base | 
| OLD | NEW | 
|---|