[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | // Common utilities for Quic tests | ||||
6 | |||||
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 7 | #ifndef NET_QUIC_TEST_TASK_RUNNER_H_ |
8 | #define NET_QUIC_TEST_TASK_RUNNER_H_ | ||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 9 | |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 10 | #include <vector> |
11 | |||||
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 12 | #include "base/callback.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 13 | #include "base/macros.h" |
Gabriel Charette | 1452023 | 2018-04-30 23:27:22 | [diff] [blame] | 14 | #include "base/sequenced_task_runner.h" |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 15 | #include "base/task_runner.h" |
16 | #include "base/test/test_pending_task.h" | ||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 17 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 18 | namespace quic { |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 19 | class MockClock; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 20 | } // namespace quic |
21 | namespace net { | ||||
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 22 | |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 23 | namespace test { |
24 | |||||
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 25 | typedef base::TestPendingTask PostedTask; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 26 | |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 27 | class TestTaskRunner : public base::SequencedTaskRunner { |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 28 | public: |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 29 | explicit TestTaskRunner(quic::MockClock* clock); |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 30 | |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 31 | // base::TaskRunner implementation. |
Brett Wilson | 9c36199 | 2017-09-12 06:05:21 | [diff] [blame] | 32 | bool PostDelayedTask(const base::Location& from_here, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 33 | base::OnceClosure task, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 34 | base::TimeDelta delay) override; |
Zhongyi Shi | 8fff75b | 2017-11-19 21:36:36 | [diff] [blame] | 35 | bool PostNonNestableDelayedTask(const base::Location& from_here, |
36 | base::OnceClosure task, | ||||
37 | base::TimeDelta delay) override; | ||||
38 | |||||
peary2 | 3322df6 | 2017-05-09 03:55:48 | [diff] [blame] | 39 | bool RunsTasksInCurrentSequence() const override; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 40 | |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 41 | const std::vector<PostedTask>& GetPostedTasks() const; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 42 | |
rch | 9ecde09b | 2017-04-08 00:18:23 | [diff] [blame] | 43 | // Finds the next task to run, advances the time to the correct time |
44 | // and then runs the task. | ||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 45 | void RunNextTask(); |
46 | |||||
rch | 9ecde09b | 2017-04-08 00:18:23 | [diff] [blame] | 47 | // While there are posted tasks, finds the next task to run, advances the |
48 | // time to the correct time and then runs the task. | ||||
49 | void RunUntilIdle(); | ||||
50 | |||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 51 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 52 | ~TestTaskRunner() override; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 53 | |
54 | private: | ||||
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 55 | std::vector<PostedTask>::iterator FindNextTask(); |
56 | |||||
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 57 | quic::MockClock* const clock_; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 58 | std::vector<PostedTask> tasks_; |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 59 | |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 60 | DISALLOW_COPY_AND_ASSIGN(TestTaskRunner); |
61 | }; | ||||
62 | |||||
63 | } // namespace test | ||||
64 | |||||
65 | } // namespace net | ||||
66 | |||||
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 67 | #endif // NET_QUIC_TEST_TASK_RUNNER_H_ |