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.
5 #ifndef BASE_TEST_TEST_PENDING_TASK_H_
6 #define BASE_TEST_TEST_PENDING_TASK_H_
10 #include "base/callback.h"
11 #include "base/debug/trace_event_argument.h"
12 #include "base/location.h"
13 #include "base/time/time.h"
17 // TestPendingTask is a helper class for test TaskRunner
18 // implementations. See test_simple_task_runner.h for example usage.
20 struct TestPendingTask
{
21 enum TestNestability
{ NESTABLE
, NON_NESTABLE
};
24 TestPendingTask(const tracked_objects::Location
& location
,
28 TestNestability nestability
);
31 // Returns post_time + delay.
32 TimeTicks
GetTimeToRun() const;
34 // Returns true if this task is nestable and |other| isn't, or if
35 // this task's time to run is strictly earlier than |other|'s time
38 // Note that two tasks may both have the same nestability and delay.
39 // In that case, the caller must use some other criterion (probably
40 // the position in some queue) to break the tie. Conveniently, the
41 // following STL functions already do so:
46 // but the following STL functions don't:
50 bool ShouldRunBefore(const TestPendingTask
& other
) const;
52 tracked_objects::Location location
;
56 TestNestability nestability
;
58 // Functions for using test pending task with tracing, useful in unit
60 void AsValueInto(base::debug::TracedValue
* state
) const;
61 scoped_refptr
<base::debug::ConvertableToTraceFormat
> AsValue() const;
62 std::string
ToString() const;
65 // gtest helpers which allow pretty printing of the tasks, very useful in unit
67 std::ostream
& operator<<(std::ostream
& os
, const TestPendingTask
& task
);
68 void PrintTo(const TestPendingTask
& task
, std::ostream
* os
);
72 #endif // BASE_TEST_TEST_PENDING_TASK_H_