| 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 #ifndef BASE_TEST_TEST_MOCK_TIME_TASK_RUNNER_H_ | 5 #ifndef BASE_TEST_TEST_MOCK_TIME_TASK_RUNNER_H_ |
| 6 #define BASE_TEST_TEST_MOCK_TIME_TASK_RUNNER_H_ | 6 #define BASE_TEST_TEST_MOCK_TIME_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // track of a mock (virtual) tick clock time that can be fast-forwarded. | 25 // track of a mock (virtual) tick clock time that can be fast-forwarded. |
| 26 // | 26 // |
| 27 // TestMockTimeTaskRunner has the following properties: | 27 // TestMockTimeTaskRunner has the following properties: |
| 28 // | 28 // |
| 29 // - Methods RunsTasksOnCurrentThread() and Post[Delayed]Task() can be called | 29 // - Methods RunsTasksOnCurrentThread() and Post[Delayed]Task() can be called |
| 30 // from any thread, but the rest of the methods must be called on the same | 30 // from any thread, but the rest of the methods must be called on the same |
| 31 // thread the TaskRunner was created on. | 31 // thread the TaskRunner was created on. |
| 32 // - It allows for reentrancy, in that it handles the running of tasks that in | 32 // - It allows for reentrancy, in that it handles the running of tasks that in |
| 33 // turn call back into it (e.g., to post more tasks). | 33 // turn call back into it (e.g., to post more tasks). |
| 34 // - Tasks are stored in a priority queue, and executed in the increasing | 34 // - Tasks are stored in a priority queue, and executed in the increasing |
| 35 // order of post time + delay. | 35 // order of post time + delay, but ignoring nestability. |
| 36 // - It does not check for overflow when doing time arithmetic. A sufficient | 36 // - It does not check for overflow when doing time arithmetic. A sufficient |
| 37 // condition for preventing overflows is to make sure that the sum of all | 37 // condition for preventing overflows is to make sure that the sum of all |
| 38 // posted task delays and fast-forward increments is still representable by | 38 // posted task delays and fast-forward increments is still representable by |
| 39 // a TimeDelta, and that adding this delta to the starting values of Time | 39 // a TimeDelta, and that adding this delta to the starting values of Time |
| 40 // and TickTime is still within their respective range. | 40 // and TickTime is still within their respective range. |
| 41 // - Non-nestable tasks are not supported. | |
| 42 // - Tasks aren't guaranteed to be destroyed immediately after they're run. | 41 // - Tasks aren't guaranteed to be destroyed immediately after they're run. |
| 43 // | 42 // |
| 44 // This is a slightly more sophisticated version of TestSimpleTaskRunner, in | 43 // This is a slightly more sophisticated version of TestSimpleTaskRunner, in |
| 45 // that it supports running delayed tasks in the correct temporal order. | 44 // that it supports running delayed tasks in the correct temporal order. |
| 46 class TestMockTimeTaskRunner : public SingleThreadTaskRunner { | 45 class TestMockTimeTaskRunner : public SingleThreadTaskRunner { |
| 47 public: | 46 public: |
| 48 // Constructs an instance whose virtual time will start at the Unix epoch, and | 47 // Constructs an instance whose virtual time will start at the Unix epoch, and |
| 49 // whose time ticks will start at zero. | 48 // whose time ticks will start at zero. |
| 50 TestMockTimeTaskRunner(); | 49 TestMockTimeTaskRunner(); |
| 51 | 50 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // |tasks_lock_| is held. | 141 // |tasks_lock_| is held. |
| 143 TaskPriorityQueue tasks_; | 142 TaskPriorityQueue tasks_; |
| 144 Lock tasks_lock_; | 143 Lock tasks_lock_; |
| 145 | 144 |
| 146 DISALLOW_COPY_AND_ASSIGN(TestMockTimeTaskRunner); | 145 DISALLOW_COPY_AND_ASSIGN(TestMockTimeTaskRunner); |
| 147 }; | 146 }; |
| 148 | 147 |
| 149 } // namespace base | 148 } // namespace base |
| 150 | 149 |
| 151 #endif // BASE_TEST_TEST_MOCK_TIME_TASK_RUNNER_H_ | 150 #endif // BASE_TEST_TEST_MOCK_TIME_TASK_RUNNER_H_ |
| OLD | NEW |