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