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_SYSTEM_TEST_UTILS_H_ | 5 #ifndef MOJO_SYSTEM_TEST_UTILS_H_ |
6 #define MOJO_SYSTEM_TEST_UTILS_H_ | 6 #define MOJO_SYSTEM_TEST_UTILS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/basictypes.h" | |
11 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
| 15 #include "base/threading/thread.h" |
14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
15 | 18 |
16 namespace tracked_objects { | 19 namespace tracked_objects { |
17 class Location; | 20 class Location; |
18 } | 21 } |
19 | 22 |
20 namespace mojo { | 23 namespace mojo { |
21 namespace system { | 24 namespace system { |
22 namespace test { | 25 namespace test { |
23 | 26 |
24 class Stopwatch { | 27 class Stopwatch { |
(...skipping 15 matching lines...) Expand all Loading... |
40 DISALLOW_COPY_AND_ASSIGN(Stopwatch); | 43 DISALLOW_COPY_AND_ASSIGN(Stopwatch); |
41 }; | 44 }; |
42 | 45 |
43 // Posts the given task (to the given task runner) and waits for it to complete. | 46 // Posts the given task (to the given task runner) and waits for it to complete. |
44 // (Note: Doesn't spin the current thread's message loop, so if you're careless | 47 // (Note: Doesn't spin the current thread's message loop, so if you're careless |
45 // this could easily deadlock.) | 48 // this could easily deadlock.) |
46 void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner, | 49 void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner, |
47 const tracked_objects::Location& from_here, | 50 const tracked_objects::Location& from_here, |
48 const base::Closure& task); | 51 const base::Closure& task); |
49 | 52 |
| 53 // TestWithIOThreadBase -------------------------------------------------------- |
| 54 |
| 55 class TestWithIOThreadBase : public testing::Test { |
| 56 public: |
| 57 TestWithIOThreadBase(); |
| 58 virtual ~TestWithIOThreadBase(); |
| 59 |
| 60 virtual void SetUp() OVERRIDE; |
| 61 virtual void TearDown() OVERRIDE; |
| 62 |
| 63 protected: |
| 64 base::MessageLoop* io_thread_message_loop() { |
| 65 return io_thread_.message_loop(); |
| 66 } |
| 67 |
| 68 scoped_refptr<base::TaskRunner> io_thread_task_runner() { |
| 69 return io_thread_message_loop()->message_loop_proxy(); |
| 70 } |
| 71 |
| 72 private: |
| 73 base::Thread io_thread_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(TestWithIOThreadBase); |
| 76 }; |
| 77 |
50 } // namespace test | 78 } // namespace test |
51 } // namespace system | 79 } // namespace system |
52 } // namespace mojo | 80 } // namespace mojo |
53 | 81 |
54 #endif // MOJO_SYSTEM_TEST_UTILS_H_ | 82 #endif // MOJO_SYSTEM_TEST_UTILS_H_ |
OLD | NEW |