blob: ab2948a7a4514bba81d8a0bc66bcabf4145d9ae6 [file] [log] [blame]
[email protected]1d197ef52012-11-07 20:41:291// 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 Hamiltona3ee93a72018-08-01 22:03:087#ifndef NET_QUIC_TEST_TASK_RUNNER_H_
8#define NET_QUIC_TEST_TASK_RUNNER_H_
[email protected]1d197ef52012-11-07 20:41:299
[email protected]1d197ef52012-11-07 20:41:2910#include <vector>
11
tzik070c8ffb2017-03-29 05:28:1212#include "base/callback.h"
Avi Drissman13fc8932015-12-20 04:40:4613#include "base/macros.h"
Gabriel Charette14520232018-04-30 23:27:2214#include "base/sequenced_task_runner.h"
[email protected]a8582b12012-12-19 22:18:2915#include "base/task_runner.h"
16#include "base/test/test_pending_task.h"
[email protected]1d197ef52012-11-07 20:41:2917
Ryan Hamilton8d9ee76e2018-05-29 23:52:5218namespace quic {
[email protected]a8582b12012-12-19 22:18:2919class MockClock;
Ryan Hamilton8d9ee76e2018-05-29 23:52:5220} // namespace quic
21namespace net {
[email protected]a8582b12012-12-19 22:18:2922
[email protected]1d197ef52012-11-07 20:41:2923namespace test {
24
[email protected]a8582b12012-12-19 22:18:2925typedef base::TestPendingTask PostedTask;
[email protected]1d197ef52012-11-07 20:41:2926
Zhongyi Shi8fff75b2017-11-19 21:36:3627class TestTaskRunner : public base::SequencedTaskRunner {
[email protected]1d197ef52012-11-07 20:41:2928 public:
Ryan Hamilton8d9ee76e2018-05-29 23:52:5229 explicit TestTaskRunner(quic::MockClock* clock);
[email protected]1d197ef52012-11-07 20:41:2930
[email protected]a8582b12012-12-19 22:18:2931 // base::TaskRunner implementation.
Brett Wilson9c361992017-09-12 06:05:2132 bool PostDelayedTask(const base::Location& from_here,
tzik6e427842017-04-05 10:13:2133 base::OnceClosure task,
dchengb03027d2014-10-21 12:00:2034 base::TimeDelta delay) override;
Zhongyi Shi8fff75b2017-11-19 21:36:3635 bool PostNonNestableDelayedTask(const base::Location& from_here,
36 base::OnceClosure task,
37 base::TimeDelta delay) override;
38
peary23322df62017-05-09 03:55:4839 bool RunsTasksInCurrentSequence() const override;
[email protected]1d197ef52012-11-07 20:41:2940
[email protected]a8582b12012-12-19 22:18:2941 const std::vector<PostedTask>& GetPostedTasks() const;
[email protected]1d197ef52012-11-07 20:41:2942
rch9ecde09b2017-04-08 00:18:2343 // Finds the next task to run, advances the time to the correct time
44 // and then runs the task.
[email protected]1d197ef52012-11-07 20:41:2945 void RunNextTask();
46
rch9ecde09b2017-04-08 00:18:2347 // 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]1d197ef52012-11-07 20:41:2951 protected:
dchengb03027d2014-10-21 12:00:2052 ~TestTaskRunner() override;
[email protected]1d197ef52012-11-07 20:41:2953
54 private:
[email protected]a8582b12012-12-19 22:18:2955 std::vector<PostedTask>::iterator FindNextTask();
56
Ryan Hamilton8d9ee76e2018-05-29 23:52:5257 quic::MockClock* const clock_;
[email protected]1d197ef52012-11-07 20:41:2958 std::vector<PostedTask> tasks_;
[email protected]a8582b12012-12-19 22:18:2959
[email protected]1d197ef52012-11-07 20:41:2960 DISALLOW_COPY_AND_ASSIGN(TestTaskRunner);
61};
62
63} // namespace test
64
65} // namespace net
66
Ryan Hamiltona3ee93a72018-08-01 22:03:0867#endif // NET_QUIC_TEST_TASK_RUNNER_H_