Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / test / test_pending_task.h
blob829baa6574fad8787e3251bd7ab54efb7688d06c
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_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/location.h"
12 #include "base/time/time.h"
13 #include "base/trace_event/trace_event_argument.h"
15 namespace base {
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 };
23 TestPendingTask();
24 TestPendingTask(const tracked_objects::Location& location,
25 const Closure& task,
26 TimeTicks post_time,
27 TimeDelta delay,
28 TestNestability nestability);
29 ~TestPendingTask();
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
36 // to run.
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:
43 // - std::min_element
44 // - std::stable_sort
46 // but the following STL functions don't:
48 // - std::max_element
49 // - std::sort.
50 bool ShouldRunBefore(const TestPendingTask& other) const;
52 tracked_objects::Location location;
53 Closure task;
54 TimeTicks post_time;
55 TimeDelta delay;
56 TestNestability nestability;
58 // Functions for using test pending task with tracing, useful in unit
59 // testing.
60 void AsValueInto(base::trace_event::TracedValue* state) const;
61 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
62 std::string ToString() const;
65 // gtest helpers which allow pretty printing of the tasks, very useful in unit
66 // testing.
67 std::ostream& operator<<(std::ostream& os, const TestPendingTask& task);
68 void PrintTo(const TestPendingTask& task, std::ostream* os);
70 } // namespace base
72 #endif // BASE_TEST_TEST_PENDING_TASK_H_