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