| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SHELL_SHELL_TEST_HELPER_ | 5 #ifndef MOJO_SHELL_SHELL_TEST_HELPER_ |
| 6 #define MOJO_SHELL_SHELL_TEST_HELPER_ | 6 #define MOJO_SHELL_SHELL_TEST_HELPER_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "mojo/public/cpp/environment/environment.h" | 12 #include "mojo/public/cpp/environment/environment.h" |
| 13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 13 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class MessageLoopProxy; | 16 class MessageLoopProxy; |
| 17 class RunLoop; | 17 class RunLoop; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace shell { | 21 namespace shell { |
| 22 | 22 |
| 23 // ShellTestHelper is useful for tests to establish a connection to the | 23 // ShellTestHelper is useful for tests to establish a connection to the Shell. |
| 24 // ServiceProvider. ShellTestHelper does this by spawning a thread and | 24 // ShellTestHelper does this by spawning a thread and connecting. Invoke Init() |
| 25 // connecting. Invoke Init() to do this. Once done, service_provider() | 25 // to do this. Once done, shell() returns the handle to the Shell. |
| 26 // returns the handle to the ServiceProvider. | |
| 27 class ShellTestHelper { | 26 class ShellTestHelper { |
| 28 public: | 27 public: |
| 29 struct State; | 28 struct State; |
| 30 | 29 |
| 31 ShellTestHelper(); | 30 ShellTestHelper(); |
| 32 ~ShellTestHelper(); | 31 ~ShellTestHelper(); |
| 33 | 32 |
| 34 void Init(); | 33 void Init(); |
| 35 | 34 |
| 36 // Returns a handle to the ServiceProvider. ShellTestHelper owns the | 35 // Returns a handle to the Shell. ShellTestHelper owns the shell. |
| 37 // ServiceProvider. | 36 Shell* shell() { return shell_.get(); } |
| 38 ServiceProvider* service_provider() { return service_provider_.get(); } | |
| 39 | 37 |
| 40 private: | 38 private: |
| 41 class TestServiceProvider; | 39 class TestShellClient; |
| 42 | 40 |
| 43 // Invoked once connection has been established. | 41 // Invoked once connection has been established. |
| 44 void OnServiceProviderStarted(); | 42 void OnShellStarted(); |
| 45 | 43 |
| 46 Environment environment_; | 44 Environment environment_; |
| 47 | 45 |
| 48 base::Thread service_provider_thread_; | 46 base::Thread shell_thread_; |
| 49 | 47 |
| 50 // If non-null we're in Init() and waiting for connection. | 48 // If non-null we're in Init() and waiting for connection. |
| 51 scoped_ptr<base::RunLoop> run_loop_; | 49 scoped_ptr<base::RunLoop> run_loop_; |
| 52 | 50 |
| 53 // See comment in declaration for details. | 51 // See comment in declaration for details. |
| 54 State* state_; | 52 State* state_; |
| 55 | 53 |
| 56 // Client interface for the shell. | 54 // Client interface for the shell. |
| 57 scoped_ptr<TestServiceProvider> local_service_provider_; | 55 scoped_ptr<TestShellClient> shell_client_; |
| 58 | 56 |
| 59 ServiceProviderPtr service_provider_; | 57 ShellPtr shell_; |
| 60 | 58 |
| 61 DISALLOW_COPY_AND_ASSIGN(ShellTestHelper); | 59 DISALLOW_COPY_AND_ASSIGN(ShellTestHelper); |
| 62 }; | 60 }; |
| 63 | 61 |
| 64 } // namespace shell | 62 } // namespace shell |
| 65 } // namespace mojo | 63 } // namespace mojo |
| 66 | 64 |
| 67 #endif // MOJO_SHELL_SHELL_TEST_HELPER_ | 65 #endif // MOJO_SHELL_SHELL_TEST_HELPER_ |
| OLD | NEW |