OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_EDK_SYSTEM_TEST_UTILS_H_ | 5 #ifndef MOJO_EDK_SYSTEM_TEST_UTILS_H_ |
6 #define MOJO_EDK_SYSTEM_TEST_UTILS_H_ | 6 #define MOJO_EDK_SYSTEM_TEST_UTILS_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | |
9 #include "base/macros.h" | 8 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/task_runner.h" | |
12 #include "base/threading/thread.h" | |
13 #include "base/time/time.h" | 9 #include "base/time/time.h" |
14 | 10 |
15 namespace tracked_objects { | |
16 class Location; | |
17 } | |
18 | |
19 namespace mojo { | 11 namespace mojo { |
20 namespace system { | 12 namespace system { |
21 namespace test { | 13 namespace test { |
22 | 14 |
23 // Posts the given task (to the given task runner) and waits for it to complete. | |
24 // (Note: Doesn't spin the current thread's message loop, so if you're careless | |
25 // this could easily deadlock.) | |
26 void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner, | |
27 const tracked_objects::Location& from_here, | |
28 const base::Closure& task); | |
29 | |
30 // A timeout smaller than |TestTimeouts::tiny_timeout()|. Warning: This may lead | 15 // A timeout smaller than |TestTimeouts::tiny_timeout()|. Warning: This may lead |
31 // to flakiness, but this is unavoidable if, e.g., you're trying to ensure that | 16 // to flakiness, but this is unavoidable if, e.g., you're trying to ensure that |
32 // functions with timeouts are reasonably accurate. We want this to be as small | 17 // functions with timeouts are reasonably accurate. We want this to be as small |
33 // as possible without causing too much flakiness. | 18 // as possible without causing too much flakiness. |
34 base::TimeDelta EpsilonTimeout(); | 19 base::TimeDelta EpsilonTimeout(); |
35 | 20 |
36 // Stopwatch ------------------------------------------------------------------- | 21 // Stopwatch ------------------------------------------------------------------- |
37 | 22 |
38 // A simple "stopwatch" for measuring time elapsed from a given starting point. | 23 // A simple "stopwatch" for measuring time elapsed from a given starting point. |
39 class Stopwatch { | 24 class Stopwatch { |
40 public: | 25 public: |
41 Stopwatch() {} | 26 Stopwatch() {} |
42 ~Stopwatch() {} | 27 ~Stopwatch() {} |
43 | 28 |
44 void Start() { start_time_ = base::TimeTicks::Now(); } | 29 void Start() { start_time_ = base::TimeTicks::Now(); } |
45 | 30 |
46 base::TimeDelta Elapsed() { return base::TimeTicks::Now() - start_time_; } | 31 base::TimeDelta Elapsed() { return base::TimeTicks::Now() - start_time_; } |
47 | 32 |
48 private: | 33 private: |
49 base::TimeTicks start_time_; | 34 base::TimeTicks start_time_; |
50 | 35 |
51 DISALLOW_COPY_AND_ASSIGN(Stopwatch); | 36 DISALLOW_COPY_AND_ASSIGN(Stopwatch); |
52 }; | 37 }; |
53 | 38 |
54 } // namespace test | 39 } // namespace test |
55 } // namespace system | 40 } // namespace system |
56 } // namespace mojo | 41 } // namespace mojo |
57 | 42 |
58 #endif // MOJO_EDK_SYSTEM_TEST_UTILS_H_ | 43 #endif // MOJO_EDK_SYSTEM_TEST_UTILS_H_ |
OLD | NEW |