| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 8 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
| 10 #include "mojo/public/cpp/application/application_test_base.h" | 10 #include "mojo/public/cpp/application/application_test_base.h" |
| 11 #include "mojo/public/cpp/system/macros.h" | 11 #include "mojo/public/cpp/system/macros.h" |
| 12 #include "mojo/services/http_server/public/cpp/http_server_util.h" | 12 #include "mojo/services/http_server/public/cpp/http_server_util.h" |
| 13 #include "mojo/services/http_server/public/interfaces/http_server.mojom.h" | 13 #include "mojo/services/http_server/public/interfaces/http_server.mojom.h" |
| 14 #include "mojo/services/http_server/public/interfaces/http_server_factory.mojom.
h" | 14 #include "mojo/services/http_server/public/interfaces/http_server_factory.mojom.
h" |
| 15 #include "mojo/services/network/public/interfaces/net_address.mojom.h" | 15 #include "mojo/services/network/public/interfaces/net_address.mojom.h" |
| 16 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 16 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 17 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 17 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
| 18 | 18 |
| 19 namespace http_server { | 19 namespace http_server { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 void WriteMessageToDataPipe( | 22 void WriteMessageToDataPipe( |
| 23 const std::string message, | 23 const std::string message, |
| 24 mojo::ScopedDataPipeConsumerHandle* data_pipe_consumer) { | 24 mojo::ScopedDataPipeConsumerHandle* data_pipe_consumer) { |
| 25 mojo::ScopedDataPipeProducerHandle producer_handle_; | 25 mojo::ScopedDataPipeProducerHandle producer_handle_; |
| 26 MojoCreateDataPipeOptions options = {sizeof(MojoCreateDataPipeOptions), | 26 MojoCreateDataPipeOptions options = {sizeof(MojoCreateDataPipeOptions), |
| 27 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, | 27 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, |
| 28 1, | 28 1, |
| 29 message.size()}; | 29 static_cast<uint32_t>(message.size())}; |
| 30 | 30 |
| 31 MojoResult result = | 31 MojoResult result = |
| 32 CreateDataPipe(&options, &producer_handle_, data_pipe_consumer); | 32 CreateDataPipe(&options, &producer_handle_, data_pipe_consumer); |
| 33 ASSERT_EQ(MOJO_RESULT_OK, result); | 33 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 34 | 34 |
| 35 uint32_t bytes = message.size(); | 35 uint32_t bytes = message.size(); |
| 36 result = WriteDataRaw(producer_handle_.get(), message.data(), &bytes, | 36 result = WriteDataRaw(producer_handle_.get(), message.data(), &bytes, |
| 37 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); | 37 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); |
| 38 ASSERT_EQ(result, MOJO_RESULT_OK); | 38 ASSERT_EQ(result, MOJO_RESULT_OK); |
| 39 ASSERT_EQ(message.size(), bytes); | 39 ASSERT_EQ(message.size(), bytes); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 url_request->method = "POST"; | 188 url_request->method = "POST"; |
| 189 url_request->body.resize(1); | 189 url_request->body.resize(1); |
| 190 WriteMessageToDataPipe(kExampleMessage, &url_request->body[0]); | 190 WriteMessageToDataPipe(kExampleMessage, &url_request->body[0]); |
| 191 | 191 |
| 192 url_loader->Start(url_request.Pass(), base::Bind(&CheckServerResponse)); | 192 url_loader->Start(url_request.Pass(), base::Bind(&CheckServerResponse)); |
| 193 base::RunLoop run_loop; | 193 base::RunLoop run_loop; |
| 194 run_loop.Run(); | 194 run_loop.Run(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace http_server | 197 } // namespace http_server |
| OLD | NEW |