[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 | |||||
7 | #ifndef NET_QUIC_TEST_TOOLS_TEST_TASK_RUNNER_H_ | ||||
8 | #define NET_QUIC_TEST_TOOLS_TEST_TASK_RUNNER_H_ | ||||
9 | |||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 10 | #include <vector> |
11 | |||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame^] | 12 | #include "base/macros.h" |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 13 | #include "base/task_runner.h" |
14 | #include "base/test/test_pending_task.h" | ||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 15 | |
16 | namespace net { | ||||
17 | |||||
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 18 | class MockClock; |
19 | |||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 20 | namespace test { |
21 | |||||
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 22 | typedef base::TestPendingTask PostedTask; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 23 | |
24 | class TestTaskRunner : public base::TaskRunner { | ||||
25 | public: | ||||
26 | explicit TestTaskRunner(MockClock* clock); | ||||
27 | |||||
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 28 | // base::TaskRunner implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 29 | bool PostDelayedTask(const tracked_objects::Location& from_here, |
30 | const base::Closure& task, | ||||
31 | base::TimeDelta delay) override; | ||||
32 | bool RunsTasksOnCurrentThread() const override; | ||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 33 | |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 34 | const std::vector<PostedTask>& GetPostedTasks() const; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 35 | |
36 | void RunNextTask(); | ||||
37 | |||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 38 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 39 | ~TestTaskRunner() override; |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 40 | |
41 | private: | ||||
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 42 | std::vector<PostedTask>::iterator FindNextTask(); |
43 | |||||
44 | MockClock* const clock_; | ||||
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 45 | std::vector<PostedTask> tasks_; |
[email protected] | a8582b1 | 2012-12-19 22:18:29 | [diff] [blame] | 46 | |
[email protected] | 1d197ef5 | 2012-11-07 20:41:29 | [diff] [blame] | 47 | DISALLOW_COPY_AND_ASSIGN(TestTaskRunner); |
48 | }; | ||||
49 | |||||
50 | } // namespace test | ||||
51 | |||||
52 | } // namespace net | ||||
53 | |||||
54 | #endif // NET_QUIC_TEST_TOOLS_TEST_TASK_RUNNER_H_ |