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" | |
12 #include "mojo/public/cpp/environment/environment.h" | 11 #include "mojo/public/cpp/environment/environment.h" |
13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 12 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 13 #include "mojo/service_manager/service_loader.h" |
| 14 #include "mojo/shell/context.h" |
14 | 15 |
15 class GURL; | 16 class GURL; |
16 | 17 |
17 namespace base { | |
18 class MessageLoopProxy; | |
19 class RunLoop; | |
20 } | |
21 | |
22 namespace mojo { | 18 namespace mojo { |
23 | 19 |
24 class ServiceLoader; | 20 class ServiceLoader; |
25 | 21 |
26 namespace shell { | 22 namespace shell { |
27 | 23 |
28 // ShellTestHelper is useful for tests to establish a connection to the | 24 // ShellTestHelper is useful for tests to establish a connection to the |
29 // ServiceProvider. ShellTestHelper does this by spawning a thread and | 25 // ServiceProvider. Invoke Init() to establish the connection. Once done, |
30 // connecting. Invoke Init() to do this. Once done, service_provider() | 26 // service_provider() returns the handle to the ServiceProvider. |
31 // returns the handle to the ServiceProvider. | |
32 class ShellTestHelper { | 27 class ShellTestHelper { |
33 public: | 28 public: |
34 struct State; | |
35 | |
36 ShellTestHelper(); | 29 ShellTestHelper(); |
37 ~ShellTestHelper(); | 30 ~ShellTestHelper(); |
38 | 31 |
39 void Init(); | 32 void Init(); |
40 | 33 |
41 // Returns a handle to the ServiceProvider. ShellTestHelper owns the | 34 // Returns a handle to the ServiceProvider. ShellTestHelper owns the |
42 // ServiceProvider. | 35 // ServiceProvider. |
43 ServiceProvider* service_provider() { return service_provider_.get(); } | 36 ServiceProvider* service_provider() { return service_provider_.get(); } |
44 | 37 |
45 // Sets a ServiceLoader for the specified URL. |loader| is ultimately used on | 38 // Sets a ServiceLoader for the specified URL. |loader| is ultimately used on |
46 // the thread this class spawns. | 39 // the thread this class spawns. |
47 void SetLoaderForURL(scoped_ptr<ServiceLoader> loader, const GURL& url); | 40 void SetLoaderForURL(scoped_ptr<ServiceLoader> loader, const GURL& url); |
48 | 41 |
49 private: | 42 private: |
50 class TestServiceProvider; | 43 class TestServiceProvider; |
51 | 44 |
52 // Invoked once connection has been established. | |
53 void OnServiceProviderStarted(); | |
54 | |
55 Environment environment_; | 45 Environment environment_; |
56 | 46 |
57 base::Thread service_provider_thread_; | 47 scoped_ptr<Context> context_; |
58 | 48 |
59 // If non-null we're in Init() and waiting for connection. | 49 scoped_ptr<ServiceManager::TestAPI> test_api_; |
60 scoped_ptr<base::RunLoop> run_loop_; | |
61 | 50 |
62 // See comment in declaration for details. | 51 // ScopedMessagePipeHandle service_provider_handle_; |
63 State* state_; | |
64 | 52 |
65 // Client interface for the shell. | 53 // Client interface for the shell. |
66 scoped_ptr<TestServiceProvider> local_service_provider_; | 54 scoped_ptr<TestServiceProvider> local_service_provider_; |
67 | 55 |
68 ServiceProviderPtr service_provider_; | 56 ServiceProviderPtr service_provider_; |
69 | 57 |
70 DISALLOW_COPY_AND_ASSIGN(ShellTestHelper); | 58 DISALLOW_COPY_AND_ASSIGN(ShellTestHelper); |
71 }; | 59 }; |
72 | 60 |
73 } // namespace shell | 61 } // namespace shell |
74 } // namespace mojo | 62 } // namespace mojo |
75 | 63 |
76 #endif // MOJO_SHELL_SHELL_TEST_HELPER_ | 64 #endif // MOJO_SHELL_SHELL_TEST_HELPER_ |
OLD | NEW |