Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: shell/shell_apptest.cc

Issue 1450223002: Add an ApplicationConnector.Duplicate(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « shell/application_manager/shell_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); 84 mojo::NetAddressPtr local_address(mojo::NetAddress::New());
85 local_address->family = mojo::NetAddressFamily::IPV4; 85 local_address->family = mojo::NetAddressFamily::IPV4;
86 local_address->ipv4 = mojo::NetAddressIPv4::New(); 86 local_address->ipv4 = mojo::NetAddressIPv4::New();
87 local_address->ipv4->addr.resize(4); 87 local_address->ipv4->addr.resize(4);
88 local_address->ipv4->addr[0] = 127; 88 local_address->ipv4->addr[0] = 127;
89 local_address->ipv4->addr[1] = 0; 89 local_address->ipv4->addr[1] = 0;
90 local_address->ipv4->addr[2] = 0; 90 local_address->ipv4->addr[2] = 0;
91 local_address->ipv4->addr[3] = 1; 91 local_address->ipv4->addr[3] = 1;
92 local_address->ipv4->port = 0; 92 local_address->ipv4->port = 0;
93 http_server_factory_->CreateHttpServer(mojo::GetProxy(&http_server_), 93 http_server_factory_->CreateHttpServer(GetProxy(&http_server_),
94 local_address.Pass()); 94 local_address.Pass());
95 95
96 http_server_->GetPort([this](uint16_t p) { port_ = p; }); 96 http_server_->GetPort([this](uint16_t p) { port_ = p; });
97 EXPECT_TRUE(http_server_.WaitForIncomingResponse()); 97 EXPECT_TRUE(http_server_.WaitForIncomingResponse());
98 98
99 http_server::HttpHandlerPtr http_handler; 99 http_server::HttpHandlerPtr http_handler;
100 handler_.reset(new GetHandler(mojo::GetProxy(&http_handler).Pass(), port_)); 100 handler_.reset(new GetHandler(GetProxy(&http_handler).Pass(), port_));
101 http_server_->SetHandler(".*", http_handler.Pass(), 101 http_server_->SetHandler(".*", http_handler.Pass(),
102 [](bool result) { EXPECT_TRUE(result); }); 102 [](bool result) { EXPECT_TRUE(result); });
103 EXPECT_TRUE(http_server_.WaitForIncomingResponse()); 103 EXPECT_TRUE(http_server_.WaitForIncomingResponse());
104 } 104 }
105 105
106 std::string GetURL(const std::string& path) { return ::GetURL(port_, path); } 106 std::string GetURL(const std::string& path) { return ::GetURL(port_, path); }
107 107
108 http_server::HttpServerFactoryPtr http_server_factory_; 108 http_server::HttpServerFactoryPtr http_server_factory_;
109 http_server::HttpServerPtr http_server_; 109 http_server::HttpServerPtr http_server_;
110 scoped_ptr<GetHandler> handler_; 110 scoped_ptr<GetHandler> handler_;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 }; 179 };
180 pingable1->Ping("hello", callbacks_builder(1)); 180 pingable1->Ping("hello", callbacks_builder(1));
181 pingable2->Ping("hello", callbacks_builder(2)); 181 pingable2->Ping("hello", callbacks_builder(2));
182 base::RunLoop().Run(); 182 base::RunLoop().Run();
183 } 183 }
184 184
185 // mojo: URLs can have querystrings too 185 // mojo: URLs can have querystrings too
186 TEST_F(ShellAppTest, MojoURLQueryHandling) { 186 TEST_F(ShellAppTest, MojoURLQueryHandling) {
187 PingablePtr pingable; 187 PingablePtr pingable;
188 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable); 188 application_impl()->ConnectToService("mojo:pingable_app?foo", &pingable);
189 auto callback = [this](const String& app_url, const String& connection_url, 189 auto callback = [](const String& app_url, const String& connection_url,
190 const String& message) { 190 const String& message) {
191 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true)); 191 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true));
192 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url); 192 EXPECT_EQ(app_url.To<std::string>() + "?foo", connection_url);
193 EXPECT_EQ("hello", message); 193 EXPECT_EQ("hello", message);
194 base::MessageLoop::current()->Quit(); 194 base::MessageLoop::current()->Quit();
195 }; 195 };
196 pingable->Ping("hello", callback); 196 pingable->Ping("hello", callback);
197 base::RunLoop().Run(); 197 base::RunLoop().Run();
198 } 198 }
199 199
200 TEST_F(ShellAppTest, ApplicationConnector) { 200 void TestApplicationConnector(mojo::ApplicationConnector* app_connector) {
201 mojo::ApplicationConnectorPtr app_connector;
202 app_connector.Bind(application_impl()->CreateApplicationConnector());
203
204 PingablePtr pingable; 201 PingablePtr pingable;
205 ConnectToService(app_connector.get(), "mojo:pingable_app", &pingable); 202 ConnectToService(app_connector, "mojo:pingable_app", &pingable);
206 auto callback = [this](const String& app_url, const String& connection_url, 203 auto callback = [](const String& app_url, const String& connection_url,
207 const String& message) { 204 const String& message) {
208 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true)); 205 EXPECT_TRUE(EndsWith(app_url, "/pingable_app.mojo", true));
209 EXPECT_EQ(app_url, connection_url); 206 EXPECT_EQ(app_url, connection_url);
210 EXPECT_EQ("hello", message); 207 EXPECT_EQ("hello", message);
211 base::MessageLoop::current()->Quit(); 208 base::MessageLoop::current()->Quit();
212 }; 209 };
213 pingable->Ping("hello", callback); 210 pingable->Ping("hello", callback);
214 base::RunLoop().Run(); 211 base::RunLoop().Run();
215 } 212 }
216 213
214 TEST_F(ShellAppTest, ApplicationConnector) {
215 mojo::ApplicationConnectorPtr app_connector;
216 app_connector.Bind(application_impl()->CreateApplicationConnector());
217 TestApplicationConnector(app_connector.get());
218 }
219
220 TEST_F(ShellAppTest, ApplicationConnectorDuplicate) {
221 mojo::ApplicationConnectorPtr app_connector1;
222 app_connector1.Bind(application_impl()->CreateApplicationConnector());
223 {
224 SCOPED_TRACE("app_connector1");
225 TestApplicationConnector(app_connector1.get());
226 }
227
228 mojo::ApplicationConnectorPtr app_connector2;
229 app_connector1->Duplicate(GetProxy(&app_connector2));
230 {
231 SCOPED_TRACE("app_connector2");
232 TestApplicationConnector(app_connector2.get());
233 }
234
235 // The first one should still work.
236 {
237 SCOPED_TRACE("app_connector1 again");
238 TestApplicationConnector(app_connector1.get());
239 }
240 }
241
217 } // namespace 242 } // namespace
OLDNEW
« no previous file with comments | « shell/application_manager/shell_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698