OLD | NEW |
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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "mojo/converters/base/base_type_converters.h" | 13 #include "mojo/converters/base/base_type_converters.h" |
14 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 14 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
15 #include "mojo/public/cpp/application/application_impl.h" | 15 #include "mojo/public/cpp/application/application_impl.h" |
16 #include "mojo/public/cpp/application/application_test_base.h" | 16 #include "mojo/public/cpp/application/application_test_base.h" |
17 #include "mojo/public/cpp/application/connect.h" | 17 #include "mojo/public/cpp/application/connect.h" |
| 18 #include "mojo/public/cpp/bindings/synchronous_interface_ptr.h" |
18 #include "mojo/public/cpp/system/macros.h" | 19 #include "mojo/public/cpp/system/macros.h" |
19 #include "mojo/public/interfaces/application/application_connector.mojom.h" | 20 #include "mojo/public/interfaces/application/application_connector.mojom.h" |
20 #include "mojo/services/http_server/cpp/http_server_util.h" | 21 #include "mojo/services/http_server/cpp/http_server_util.h" |
21 #include "mojo/services/http_server/interfaces/http_server.mojom.h" | 22 #include "mojo/services/http_server/interfaces/http_server.mojom-sync.h" |
22 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" | 23 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" |
23 #include "mojo/services/network/interfaces/net_address.mojom.h" | 24 #include "mojo/services/network/interfaces/net_address.mojom.h" |
24 #include "shell/kPingable.h" | 25 #include "shell/kPingable.h" |
25 #include "shell/test/pingable.mojom.h" | 26 #include "shell/test/pingable.mojom.h" |
26 | 27 |
27 using mojo::String; | 28 using mojo::String; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 std::string GetURL(uint16_t port, const std::string& path) { | 32 std::string GetURL(uint16_t port, const std::string& path) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 86 |
86 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); | 87 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); |
87 local_address->family = mojo::NetAddressFamily::IPV4; | 88 local_address->family = mojo::NetAddressFamily::IPV4; |
88 local_address->ipv4 = mojo::NetAddressIPv4::New(); | 89 local_address->ipv4 = mojo::NetAddressIPv4::New(); |
89 local_address->ipv4->addr.resize(4); | 90 local_address->ipv4->addr.resize(4); |
90 local_address->ipv4->addr[0] = 127; | 91 local_address->ipv4->addr[0] = 127; |
91 local_address->ipv4->addr[1] = 0; | 92 local_address->ipv4->addr[1] = 0; |
92 local_address->ipv4->addr[2] = 0; | 93 local_address->ipv4->addr[2] = 0; |
93 local_address->ipv4->addr[3] = 1; | 94 local_address->ipv4->addr[3] = 1; |
94 local_address->ipv4->port = 0; | 95 local_address->ipv4->port = 0; |
95 http_server_factory_->CreateHttpServer(GetProxy(&http_server_), | 96 http_server_factory_->CreateHttpServer(GetSynchronousProxy(&http_server_), |
96 local_address.Pass()); | 97 local_address.Pass()); |
97 | 98 |
98 http_server_->GetPort([this](uint16_t p) { port_ = p; }); | 99 EXPECT_TRUE(http_server_->GetPort(&port_)); |
99 EXPECT_TRUE(http_server_.WaitForIncomingResponse()); | |
100 | 100 |
101 http_server::HttpHandlerPtr http_handler; | 101 http_server::HttpHandlerPtr http_handler; |
102 handler_.reset(new GetHandler(GetProxy(&http_handler).Pass(), port_)); | 102 handler_.reset(new GetHandler(GetProxy(&http_handler).Pass(), port_)); |
103 http_server_->SetHandler(".*", http_handler.Pass(), | 103 bool result = false; |
104 [](bool result) { EXPECT_TRUE(result); }); | 104 EXPECT_TRUE(http_server_->SetHandler(".*", http_handler.Pass(), &result)); |
105 EXPECT_TRUE(http_server_.WaitForIncomingResponse()); | 105 EXPECT_TRUE(result); |
106 } | 106 } |
107 | 107 |
108 std::string GetURL(const std::string& path) { return ::GetURL(port_, path); } | 108 std::string GetURL(const std::string& path) { return ::GetURL(port_, path); } |
109 | 109 |
110 http_server::HttpServerFactoryPtr http_server_factory_; | 110 http_server::HttpServerFactoryPtr http_server_factory_; |
111 http_server::HttpServerPtr http_server_; | 111 mojo::SynchronousInterfacePtr<http_server::HttpServer> http_server_; |
112 scoped_ptr<GetHandler> handler_; | 112 scoped_ptr<GetHandler> handler_; |
113 uint16_t port_; | 113 uint16_t port_; |
114 | 114 |
115 private: | 115 private: |
116 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); | 116 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellHTTPAppTest); |
117 }; | 117 }; |
118 | 118 |
119 // Test that we can load apps over http. | 119 // Test that we can load apps over http. |
120 TEST_F(ShellHTTPAppTest, Http) { | 120 TEST_F(ShellHTTPAppTest, Http) { |
121 PingablePtr pingable; | 121 PingablePtr pingable; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 244 } |
245 | 245 |
246 // The first one should still work. | 246 // The first one should still work. |
247 { | 247 { |
248 SCOPED_TRACE("app_connector1 again"); | 248 SCOPED_TRACE("app_connector1 again"); |
249 TestApplicationConnector(app_connector1.get()); | 249 TestApplicationConnector(app_connector1.get()); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 } // namespace | 253 } // namespace |
OLD | NEW |