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 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "mojo/application_manager/application_loader.h" | 11 #include "mojo/application_manager/application_loader.h" |
12 #include "mojo/application_manager/application_manager.h" | 12 #include "mojo/application_manager/application_manager.h" |
13 #include "mojo/common/common_type_converters.h" | 13 #include "mojo/common/common_type_converters.h" |
14 #include "mojo/public/interfaces/application/application.mojom.h" | 14 #include "mojo/public/interfaces/application/application.mojom.h" |
15 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 15 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
16 #include "mojo/public/interfaces/application/shell.mojom.h" | 16 #include "mojo/public/interfaces/application/shell.mojom.h" |
17 #include "mojo/shell/domain_socket/net_errors.h" | 17 #include "shell/domain_socket/net_errors.h" |
18 #include "mojo/shell/domain_socket/test_completion_callback.h" | 18 #include "shell/domain_socket/test_completion_callback.h" |
19 #include "mojo/shell/domain_socket/unix_domain_client_socket_posix.h" | 19 #include "shell/domain_socket/unix_domain_client_socket_posix.h" |
20 #include "mojo/shell/external_application_listener_posix.h" | 20 #include "shell/external_application_listener_posix.h" |
21 #include "mojo/shell/external_application_registrar.mojom.h" | 21 #include "shell/external_application_registrar.mojom.h" |
22 #include "mojo/shell/external_application_registrar_connection.h" | 22 #include "shell/external_application_registrar_connection.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
25 | 25 |
26 namespace mojo { | 26 namespace mojo { |
27 namespace shell { | 27 namespace shell { |
28 | 28 |
29 class NotAnApplicationLoader : public ApplicationLoader { | 29 class NotAnApplicationLoader : public ApplicationLoader { |
30 public: | 30 public: |
31 NotAnApplicationLoader() {} | 31 NotAnApplicationLoader() {} |
32 ~NotAnApplicationLoader() override {} | 32 ~NotAnApplicationLoader() override {} |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 base::Closure quit_callback) { | 99 base::Closure quit_callback) { |
100 ExternalApplicationRegistrarConnection connection(socket_path); | 100 ExternalApplicationRegistrarConnection connection(socket_path); |
101 connection.Connect(base::Bind(&QuitLoopOnConnect, to_quit, quit_callback)); | 101 connection.Connect(base::Bind(&QuitLoopOnConnect, to_quit, quit_callback)); |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 TEST_F(ExternalApplicationListenerTest, ConnectConnection) { | 106 TEST_F(ExternalApplicationListenerTest, ConnectConnection) { |
107 listener_->ListenInBackground(socket_path_, base::Bind(&DoLocalRegister)); | 107 listener_->ListenInBackground(socket_path_, base::Bind(&DoLocalRegister)); |
108 listener_->WaitForListening(); | 108 listener_->WaitForListening(); |
109 io_thread_.task_runner()->PostTask(FROM_HERE, | 109 io_thread_.task_runner()->PostTask( |
110 base::Bind(&ConnectOnIOThread, | 110 FROM_HERE, base::Bind(&ConnectOnIOThread, socket_path_, |
111 socket_path_, | 111 loop_.task_runner(), run_loop_.QuitClosure())); |
112 loop_.task_runner(), | |
113 run_loop_.QuitClosure())); | |
114 run_loop_.Run(); | 112 run_loop_.Run(); |
115 } | 113 } |
116 | 114 |
117 namespace { | 115 namespace { |
118 | 116 |
119 class QuitLoopOnConnectApplicationImpl : public InterfaceImpl<Application> { | 117 class QuitLoopOnConnectApplicationImpl : public InterfaceImpl<Application> { |
120 public: | 118 public: |
121 QuitLoopOnConnectApplicationImpl(const std::string& url, | 119 QuitLoopOnConnectApplicationImpl(const std::string& url, |
122 scoped_refptr<base::TaskRunner> loop, | 120 scoped_refptr<base::TaskRunner> loop, |
123 base::Closure quit_callback) | 121 base::Closure quit_callback) |
(...skipping 20 matching lines...) Expand all Loading... |
144 void ConnectSynchronously(const base::FilePath& socket_path) { | 142 void ConnectSynchronously(const base::FilePath& socket_path) { |
145 connection_.reset(new ExternalApplicationRegistrarConnection(socket_path)); | 143 connection_.reset(new ExternalApplicationRegistrarConnection(socket_path)); |
146 TestCompletionCallback connect_callback; | 144 TestCompletionCallback connect_callback; |
147 connection_->Connect(connect_callback.callback()); | 145 connection_->Connect(connect_callback.callback()); |
148 connect_callback.WaitForResult(); | 146 connect_callback.WaitForResult(); |
149 } | 147 } |
150 | 148 |
151 // application_impl is the the actual implementation to be registered. | 149 // application_impl is the the actual implementation to be registered. |
152 void Register(scoped_ptr<InterfaceImpl<Application>> application_impl, | 150 void Register(scoped_ptr<InterfaceImpl<Application>> application_impl, |
153 base::Closure register_complete_callback) { | 151 base::Closure register_complete_callback) { |
154 connection_->Register(GURL(url_), | 152 connection_->Register( |
155 base::Bind(&FakeExternalApplication::OnRegister, | 153 GURL(url_), |
156 base::Unretained(this), | 154 base::Bind(&FakeExternalApplication::OnRegister, base::Unretained(this), |
157 register_complete_callback)); | 155 register_complete_callback)); |
158 application_impl_ = application_impl.Pass(); | 156 application_impl_ = application_impl.Pass(); |
159 } | 157 } |
160 | 158 |
161 void ConnectToAppByUrl(std::string app_url) { | 159 void ConnectToAppByUrl(std::string app_url) { |
162 ServiceProviderPtr sp; | 160 ServiceProviderPtr sp; |
163 ptr_->ConnectToApplication(app_url, GetProxy(&sp)); | 161 ptr_->ConnectToApplication(app_url, GetProxy(&sp)); |
164 } | 162 } |
165 | 163 |
166 const std::string& url() { return url_; } | 164 const std::string& url() { return url_; } |
167 | 165 |
(...skipping 22 matching lines...) Expand all Loading... |
190 void ConnectAndRegisterOnIOThread(const base::FilePath& socket_path, | 188 void ConnectAndRegisterOnIOThread(const base::FilePath& socket_path, |
191 scoped_refptr<base::TaskRunner> loop, | 189 scoped_refptr<base::TaskRunner> loop, |
192 base::Closure quit_callback, | 190 base::Closure quit_callback, |
193 FakeExternalApplication* connector, | 191 FakeExternalApplication* connector, |
194 FakeExternalApplication* connectee) { | 192 FakeExternalApplication* connectee) { |
195 // Connect the first app to the registrar. | 193 // Connect the first app to the registrar. |
196 connector->ConnectSynchronously(socket_path); | 194 connector->ConnectSynchronously(socket_path); |
197 // connector will use this implementation of the Mojo Application interface | 195 // connector will use this implementation of the Mojo Application interface |
198 // once registration complete. | 196 // once registration complete. |
199 scoped_ptr<QuitLoopOnConnectApplicationImpl> connector_app_impl( | 197 scoped_ptr<QuitLoopOnConnectApplicationImpl> connector_app_impl( |
200 new QuitLoopOnConnectApplicationImpl( | 198 new QuitLoopOnConnectApplicationImpl(connector->url(), loop, |
201 connector->url(), loop, quit_callback)); | 199 quit_callback)); |
202 // Since connectee won't be ready when connector is done registering, pass | 200 // Since connectee won't be ready when connector is done registering, pass |
203 // in a do-nothing callback. | 201 // in a do-nothing callback. |
204 connector->Register(connector_app_impl.Pass(), base::Bind(&NoOp)); | 202 connector->Register(connector_app_impl.Pass(), base::Bind(&NoOp)); |
205 | 203 |
206 // Connect the second app to the registrar. | 204 // Connect the second app to the registrar. |
207 connectee->ConnectSynchronously(socket_path); | 205 connectee->ConnectSynchronously(socket_path); |
208 scoped_ptr<QuitLoopOnConnectApplicationImpl> connectee_app_impl( | 206 scoped_ptr<QuitLoopOnConnectApplicationImpl> connectee_app_impl( |
209 new QuitLoopOnConnectApplicationImpl( | 207 new QuitLoopOnConnectApplicationImpl(connectee->url(), loop, |
210 connectee->url(), loop, quit_callback)); | 208 quit_callback)); |
211 // After connectee is successfully registered, connector should be | 209 // After connectee is successfully registered, connector should be |
212 // able to connect to is by URL. Pass in a callback to attempt the | 210 // able to connect to is by URL. Pass in a callback to attempt the |
213 // app -> app connection. | 211 // app -> app connection. |
214 connectee->Register(connectee_app_impl.Pass(), | 212 connectee->Register(connectee_app_impl.Pass(), |
215 base::Bind(&ConnectToApp, connector, connectee)); | 213 base::Bind(&ConnectToApp, connector, connectee)); |
216 } | 214 } |
217 | 215 |
218 void DestroyOnIOThread(scoped_ptr<FakeExternalApplication> doomed1, | 216 void DestroyOnIOThread(scoped_ptr<FakeExternalApplication> doomed1, |
219 scoped_ptr<FakeExternalApplication> doomed2) { | 217 scoped_ptr<FakeExternalApplication> doomed2) { |
220 } | 218 } |
(...skipping 13 matching lines...) Expand all Loading... |
234 base::Unretained(&application_manager))); | 232 base::Unretained(&application_manager))); |
235 listener_->WaitForListening(); | 233 listener_->WaitForListening(); |
236 | 234 |
237 // Create two external apps. | 235 // Create two external apps. |
238 scoped_ptr<FakeExternalApplication> supersweet_app( | 236 scoped_ptr<FakeExternalApplication> supersweet_app( |
239 new FakeExternalApplication("http://my.supersweet.app")); | 237 new FakeExternalApplication("http://my.supersweet.app")); |
240 scoped_ptr<FakeExternalApplication> awesome_app( | 238 scoped_ptr<FakeExternalApplication> awesome_app( |
241 new FakeExternalApplication("http://my.awesome.app")); | 239 new FakeExternalApplication("http://my.awesome.app")); |
242 | 240 |
243 // Connecting and talking to the registrar has to happen on the IO thread. | 241 // Connecting and talking to the registrar has to happen on the IO thread. |
244 io_thread_.task_runner()->PostTask(FROM_HERE, | 242 io_thread_.task_runner()->PostTask( |
245 base::Bind(&ConnectAndRegisterOnIOThread, | 243 FROM_HERE, base::Bind(&ConnectAndRegisterOnIOThread, socket_path_, |
246 socket_path_, | 244 loop_.task_runner(), run_loop_.QuitClosure(), |
247 loop_.task_runner(), | 245 supersweet_app.get(), awesome_app.get())); |
248 run_loop_.QuitClosure(), | |
249 supersweet_app.get(), | |
250 awesome_app.get())); | |
251 run_loop_.Run(); | 246 run_loop_.Run(); |
252 | 247 |
253 // The apps need to be destroyed on the thread where they did socket stuff. | 248 // The apps need to be destroyed on the thread where they did socket stuff. |
254 io_thread_.task_runner()->PostTask(FROM_HERE, | 249 io_thread_.task_runner()->PostTask( |
255 base::Bind(&DestroyOnIOThread, | 250 FROM_HERE, base::Bind(&DestroyOnIOThread, base::Passed(&supersweet_app), |
256 base::Passed(&supersweet_app), | 251 base::Passed(&awesome_app))); |
257 base::Passed(&awesome_app))); | |
258 } | 252 } |
259 | 253 |
260 } // namespace shell | 254 } // namespace shell |
261 } // namespace mojo | 255 } // namespace mojo |
OLD | NEW |