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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/memory/linked_ptr.h" | 7 #include "base/memory/linked_ptr.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.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/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/data_pipe_utils/data_pipe_utils.h" | 13 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
14 #include "mojo/services/network/interfaces/http_connection.mojom.h" | 14 #include "mojo/services/network/interfaces/http_connection.mojom.h" |
15 #include "mojo/services/network/interfaces/http_message.mojom.h" | 15 #include "mojo/services/network/interfaces/http_message.mojom.h" |
16 #include "mojo/services/network/interfaces/http_server.mojom.h" | 16 #include "mojo/services/network/interfaces/http_server.mojom.h" |
17 #include "mojo/services/network/interfaces/net_address.mojom.h" | 17 #include "mojo/services/network/interfaces/net_address.mojom.h" |
18 #include "mojo/services/network/interfaces/network_service.mojom.h" | 18 #include "mojo/services/network/interfaces/network_service.mojom.h" |
19 #include "mojo/services/network/interfaces/web_socket.mojom.h" | 19 #include "mojo/services/network/interfaces/web_socket.mojom.h" |
20 #include "mojo/services/network/net_address_type_converters.h" | 20 #include "mojo/services/network/net_address_type_converters.h" |
21 #include "mojo/services/network/web_socket_read_queue.h" | 21 #include "mojo/services/network/web_socket_read_queue.h" |
22 #include "mojo/services/network/web_socket_write_queue.h" | 22 #include "mojo/services/network/web_socket_write_queue.h" |
23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "net/base/test_completion_callback.h" | 25 #include "net/base/test_completion_callback.h" |
26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
27 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
28 #include "net/socket/tcp_client_socket.h" | 28 #include "net/socket/tcp_client_socket.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio
n.h" | |
31 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" | 30 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" |
32 #include "third_party/mojo/src/mojo/public/cpp/application/application_test_base
.h" | 31 #include "third_party/mojo/src/mojo/public/cpp/application/application_test_base
.h" |
| 32 #include "third_party/mojo/src/mojo/public/cpp/application/connect.h" |
33 | 33 |
34 namespace mojo { | 34 namespace mojo { |
35 namespace { | 35 namespace { |
36 | 36 |
37 const int kMaxExpectedResponseLength = 2048; | 37 const int kMaxExpectedResponseLength = 2048; |
38 | 38 |
39 NetAddressPtr GetLocalHostWithAnyPort() { | 39 NetAddressPtr GetLocalHostWithAnyPort() { |
40 NetAddressPtr addr(NetAddress::New()); | 40 NetAddressPtr addr(NetAddress::New()); |
41 addr->family = NetAddressFamily::IPV4; | 41 addr->family = NetAddressFamily::IPV4; |
42 addr->ipv4 = NetAddressIPv4::New(); | 42 addr->ipv4 = NetAddressIPv4::New(); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 public: | 546 public: |
547 HttpServerAppTest() : message_loop_(base::MessageLoop::TYPE_IO) {} | 547 HttpServerAppTest() : message_loop_(base::MessageLoop::TYPE_IO) {} |
548 ~HttpServerAppTest() override {} | 548 ~HttpServerAppTest() override {} |
549 | 549 |
550 protected: | 550 protected: |
551 bool ShouldCreateDefaultRunLoop() override { return false; } | 551 bool ShouldCreateDefaultRunLoop() override { return false; } |
552 | 552 |
553 void SetUp() override { | 553 void SetUp() override { |
554 ApplicationTestBase::SetUp(); | 554 ApplicationTestBase::SetUp(); |
555 | 555 |
556 ApplicationConnection* connection = | 556 ConnectToService(application_impl()->shell(), "mojo:network_service", |
557 application_impl()->ConnectToApplication("mojo:network_service"); | 557 GetProxy(&network_service_)); |
558 connection->ConnectToService(&network_service_); | |
559 } | 558 } |
560 | 559 |
561 void CreateHttpServer(InterfaceHandle<HttpServerDelegate> delegate, | 560 void CreateHttpServer(InterfaceHandle<HttpServerDelegate> delegate, |
562 NetAddressPtr* out_bound_to) { | 561 NetAddressPtr* out_bound_to) { |
563 network_service_->CreateHttpServer( | 562 network_service_->CreateHttpServer( |
564 GetLocalHostWithAnyPort(), delegate.Pass(), | 563 GetLocalHostWithAnyPort(), delegate.Pass(), |
565 [out_bound_to](NetworkErrorPtr result, NetAddressPtr bound_to) { | 564 [out_bound_to](NetworkErrorPtr result, NetAddressPtr bound_to) { |
566 ASSERT_EQ(net::OK, result->code); | 565 ASSERT_EQ(net::OK, result->code); |
567 EXPECT_NE(0u, bound_to->ipv4->port); | 566 EXPECT_NE(0u, bound_to->ipv4->port); |
568 *out_bound_to = bound_to.Pass(); | 567 *out_bound_to = bound_to.Pass(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 | 681 |
683 socket_1.Send("How do"); | 682 socket_1.Send("How do"); |
684 socket_1.Send("you do?"); | 683 socket_1.Send("you do?"); |
685 | 684 |
686 socket_0.WaitForMessage(2); | 685 socket_0.WaitForMessage(2); |
687 EXPECT_EQ("How do", socket_0.received_messages()[0]); | 686 EXPECT_EQ("How do", socket_0.received_messages()[0]); |
688 EXPECT_EQ("you do?", socket_0.received_messages()[1]); | 687 EXPECT_EQ("you do?", socket_0.received_messages()[1]); |
689 } | 688 } |
690 | 689 |
691 } // namespace mojo | 690 } // namespace mojo |
OLD | NEW |