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/application/public/cpp/application_connection.h" | 13 #include "mojo/application/public/cpp/application_connection.h" |
14 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
15 #include "mojo/application/public/cpp/application_test_base.h" | 15 #include "mojo/application/public/cpp/application_test_base.h" |
16 #include "mojo/common/data_pipe_utils.h" | 16 #include "mojo/common/data_pipe_utils.h" |
17 #include "mojo/services/network/net_address_type_converters.h" | 17 #include "mojo/services/network/net_address_type_converters.h" |
18 #include "mojo/services/network/public/cpp/web_socket_read_queue.h" | 18 #include "mojo/services/network/public/cpp/web_socket_read_queue.h" |
19 #include "mojo/services/network/public/cpp/web_socket_write_queue.h" | 19 #include "mojo/services/network/public/cpp/web_socket_write_queue.h" |
20 #include "mojo/services/network/public/interfaces/http_connection.mojom.h" | 20 #include "mojo/services/network/public/interfaces/http_connection.mojom.h" |
21 #include "mojo/services/network/public/interfaces/http_message.mojom.h" | 21 #include "mojo/services/network/public/interfaces/http_message.mojom.h" |
22 #include "mojo/services/network/public/interfaces/http_server.mojom.h" | 22 #include "mojo/services/network/public/interfaces/http_server.mojom.h" |
23 #include "mojo/services/network/public/interfaces/net_address.mojom.h" | 23 #include "mojo/services/network/public/interfaces/net_address.mojom.h" |
24 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 24 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
25 #include "mojo/services/network/public/interfaces/web_socket.mojom.h" | 25 #include "mojo/services/network/public/interfaces/web_socket.mojom.h" |
| 26 #include "mojo/services/network/public/interfaces/web_socket_factory.mojom.h" |
26 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
28 #include "net/base/test_completion_callback.h" | 29 #include "net/base/test_completion_callback.h" |
29 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
30 #include "net/http/http_util.h" | 31 #include "net/http/http_util.h" |
31 #include "net/socket/tcp_client_socket.h" | 32 #include "net/socket/tcp_client_socket.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 | 34 |
34 namespace mojo { | 35 namespace mojo { |
35 namespace { | 36 namespace { |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 bool ShouldCreateDefaultRunLoop() override { return false; } | 550 bool ShouldCreateDefaultRunLoop() override { return false; } |
550 | 551 |
551 void SetUp() override { | 552 void SetUp() override { |
552 ApplicationTestBase::SetUp(); | 553 ApplicationTestBase::SetUp(); |
553 | 554 |
554 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 555 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
555 request->url = mojo::String::From("mojo:network_service"); | 556 request->url = mojo::String::From("mojo:network_service"); |
556 scoped_ptr<ApplicationConnection> connection = | 557 scoped_ptr<ApplicationConnection> connection = |
557 application_impl()->ConnectToApplication(request.Pass()); | 558 application_impl()->ConnectToApplication(request.Pass()); |
558 connection->ConnectToService(&network_service_); | 559 connection->ConnectToService(&network_service_); |
| 560 connection->ConnectToService(&web_socket_factory_); |
559 } | 561 } |
560 | 562 |
561 void CreateHttpServer(HttpServerDelegatePtr delegate, | 563 void CreateHttpServer(HttpServerDelegatePtr delegate, |
562 NetAddressPtr* out_bound_to) { | 564 NetAddressPtr* out_bound_to) { |
563 network_service_->CreateHttpServer( | 565 network_service_->CreateHttpServer( |
564 GetLocalHostWithAnyPort(), delegate.Pass(), | 566 GetLocalHostWithAnyPort(), delegate.Pass(), |
565 [out_bound_to](NetworkErrorPtr result, NetAddressPtr bound_to) { | 567 [out_bound_to](NetworkErrorPtr result, NetAddressPtr bound_to) { |
566 ASSERT_EQ(net::OK, result->code); | 568 ASSERT_EQ(net::OK, result->code); |
567 EXPECT_NE(0u, bound_to->ipv4->port); | 569 EXPECT_NE(0u, bound_to->ipv4->port); |
568 *out_bound_to = bound_to.Pass(); | 570 *out_bound_to = bound_to.Pass(); |
569 }); | 571 }); |
570 network_service_.WaitForIncomingResponse(); | 572 network_service_.WaitForIncomingResponse(); |
571 } | 573 } |
572 | 574 |
573 NetworkServicePtr network_service_; | 575 NetworkServicePtr network_service_; |
| 576 WebSocketFactoryPtr web_socket_factory_; |
574 | 577 |
575 private: | 578 private: |
576 base::MessageLoop message_loop_; | 579 base::MessageLoop message_loop_; |
577 | 580 |
578 DISALLOW_COPY_AND_ASSIGN(HttpServerAppTest); | 581 DISALLOW_COPY_AND_ASSIGN(HttpServerAppTest); |
579 }; | 582 }; |
580 | 583 |
581 } // namespace | 584 } // namespace |
582 | 585 |
583 TEST_F(HttpServerAppTest, BasicHttpRequestResponse) { | 586 TEST_F(HttpServerAppTest, BasicHttpRequestResponse) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 CheckResponse(response_data, response_message); | 653 CheckResponse(response_data, response_message); |
651 } | 654 } |
652 | 655 |
653 TEST_F(HttpServerAppTest, WebSocket) { | 656 TEST_F(HttpServerAppTest, WebSocket) { |
654 NetAddressPtr bound_to; | 657 NetAddressPtr bound_to; |
655 HttpServerDelegatePtr server_delegate_ptr; | 658 HttpServerDelegatePtr server_delegate_ptr; |
656 HttpServerDelegateImpl server_delegate_impl(&server_delegate_ptr); | 659 HttpServerDelegateImpl server_delegate_impl(&server_delegate_ptr); |
657 CreateHttpServer(server_delegate_ptr.Pass(), &bound_to); | 660 CreateHttpServer(server_delegate_ptr.Pass(), &bound_to); |
658 | 661 |
659 WebSocketPtr web_socket_ptr; | 662 WebSocketPtr web_socket_ptr; |
660 network_service_->CreateWebSocket(GetProxy(&web_socket_ptr)); | 663 web_socket_factory_->CreateWebSocket(GetProxy(&web_socket_ptr)); |
661 WebSocketClientImpl socket_0; | 664 WebSocketClientImpl socket_0; |
662 socket_0.Connect( | 665 socket_0.Connect( |
663 web_socket_ptr.Pass(), | 666 web_socket_ptr.Pass(), |
664 base::StringPrintf("ws://127.0.0.1:%d/hello", bound_to->ipv4->port)); | 667 base::StringPrintf("ws://127.0.0.1:%d/hello", bound_to->ipv4->port)); |
665 | 668 |
666 server_delegate_impl.WaitForConnection(1); | 669 server_delegate_impl.WaitForConnection(1); |
667 HttpConnectionDelegateImpl& connection = | 670 HttpConnectionDelegateImpl& connection = |
668 *server_delegate_impl.connections()[0]; | 671 *server_delegate_impl.connections()[0]; |
669 | 672 |
670 connection.WaitForWebSocketRequest(); | 673 connection.WaitForWebSocketRequest(); |
(...skipping 11 matching lines...) Expand all Loading... |
682 | 685 |
683 socket_1.Send("How do"); | 686 socket_1.Send("How do"); |
684 socket_1.Send("you do?"); | 687 socket_1.Send("you do?"); |
685 | 688 |
686 socket_0.WaitForMessage(2); | 689 socket_0.WaitForMessage(2); |
687 EXPECT_EQ("How do", socket_0.received_messages()[0]); | 690 EXPECT_EQ("How do", socket_0.received_messages()[0]); |
688 EXPECT_EQ("you do?", socket_0.received_messages()[1]); | 691 EXPECT_EQ("you do?", socket_0.received_messages()[1]); |
689 } | 692 } |
690 | 693 |
691 } // namespace mojo | 694 } // namespace mojo |
OLD | NEW |