| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <utility> | 6 #include <utility> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 TEST_F(HttpServerTest, Send200) { | 436 TEST_F(HttpServerTest, Send200) { |
| 437 TestHttpClient client; | 437 TestHttpClient client; |
| 438 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 438 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
| 439 client.Send("GET /test HTTP/1.1\r\n\r\n"); | 439 client.Send("GET /test HTTP/1.1\r\n\r\n"); |
| 440 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 440 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
| 441 server_->Send200(GetConnectionId(0), "Response!", "text/plain"); | 441 server_->Send200(GetConnectionId(0), "Response!", "text/plain"); |
| 442 | 442 |
| 443 std::string response; | 443 std::string response; |
| 444 ASSERT_TRUE(client.ReadResponse(&response)); | 444 ASSERT_TRUE(client.ReadResponse(&response)); |
| 445 ASSERT_TRUE(base::StartsWithASCII(response, "HTTP/1.1 200 OK", true)); | 445 ASSERT_TRUE(base::StartsWithASCII(response, "HTTP/1.1 200 OK", true)); |
| 446 ASSERT_TRUE(EndsWith(response, "Response!", true)); | 446 ASSERT_TRUE(base::EndsWith(response, "Response!", true)); |
| 447 } | 447 } |
| 448 | 448 |
| 449 TEST_F(HttpServerTest, SendRaw) { | 449 TEST_F(HttpServerTest, SendRaw) { |
| 450 TestHttpClient client; | 450 TestHttpClient client; |
| 451 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 451 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
| 452 client.Send("GET /test HTTP/1.1\r\n\r\n"); | 452 client.Send("GET /test HTTP/1.1\r\n\r\n"); |
| 453 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 453 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
| 454 server_->SendRaw(GetConnectionId(0), "Raw Data "); | 454 server_->SendRaw(GetConnectionId(0), "Raw Data "); |
| 455 server_->SendRaw(GetConnectionId(0), "More Data"); | 455 server_->SendRaw(GetConnectionId(0), "More Data"); |
| 456 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); | 456 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 body.length(), | 585 body.length(), |
| 586 body.c_str())); | 586 body.c_str())); |
| 587 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 587 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
| 588 ASSERT_EQ(body, GetRequest(0).data); | 588 ASSERT_EQ(body, GetRequest(0).data); |
| 589 | 589 |
| 590 int client_connection_id = GetConnectionId(0); | 590 int client_connection_id = GetConnectionId(0); |
| 591 server_->Send200(client_connection_id, "Content for /test", "text/plain"); | 591 server_->Send200(client_connection_id, "Content for /test", "text/plain"); |
| 592 std::string response1; | 592 std::string response1; |
| 593 ASSERT_TRUE(client.ReadResponse(&response1)); | 593 ASSERT_TRUE(client.ReadResponse(&response1)); |
| 594 ASSERT_TRUE(base::StartsWithASCII(response1, "HTTP/1.1 200 OK", true)); | 594 ASSERT_TRUE(base::StartsWithASCII(response1, "HTTP/1.1 200 OK", true)); |
| 595 ASSERT_TRUE(EndsWith(response1, "Content for /test", true)); | 595 ASSERT_TRUE(base::EndsWith(response1, "Content for /test", true)); |
| 596 | 596 |
| 597 client.Send("GET /test2 HTTP/1.1\r\n\r\n"); | 597 client.Send("GET /test2 HTTP/1.1\r\n\r\n"); |
| 598 ASSERT_TRUE(RunUntilRequestsReceived(2)); | 598 ASSERT_TRUE(RunUntilRequestsReceived(2)); |
| 599 ASSERT_EQ("/test2", GetRequest(1).path); | 599 ASSERT_EQ("/test2", GetRequest(1).path); |
| 600 | 600 |
| 601 ASSERT_EQ(client_connection_id, GetConnectionId(1)); | 601 ASSERT_EQ(client_connection_id, GetConnectionId(1)); |
| 602 server_->Send404(client_connection_id); | 602 server_->Send404(client_connection_id); |
| 603 std::string response2; | 603 std::string response2; |
| 604 ASSERT_TRUE(client.ReadResponse(&response2)); | 604 ASSERT_TRUE(client.ReadResponse(&response2)); |
| 605 ASSERT_TRUE(base::StartsWithASCII(response2, "HTTP/1.1 404 Not Found", true)); | 605 ASSERT_TRUE(base::StartsWithASCII(response2, "HTTP/1.1 404 Not Found", true)); |
| 606 | 606 |
| 607 client.Send("GET /test3 HTTP/1.1\r\n\r\n"); | 607 client.Send("GET /test3 HTTP/1.1\r\n\r\n"); |
| 608 ASSERT_TRUE(RunUntilRequestsReceived(3)); | 608 ASSERT_TRUE(RunUntilRequestsReceived(3)); |
| 609 ASSERT_EQ("/test3", GetRequest(2).path); | 609 ASSERT_EQ("/test3", GetRequest(2).path); |
| 610 | 610 |
| 611 ASSERT_EQ(client_connection_id, GetConnectionId(2)); | 611 ASSERT_EQ(client_connection_id, GetConnectionId(2)); |
| 612 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); | 612 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); |
| 613 std::string response3; | 613 std::string response3; |
| 614 ASSERT_TRUE(client.ReadResponse(&response3)); | 614 ASSERT_TRUE(client.ReadResponse(&response3)); |
| 615 ASSERT_TRUE(base::StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); | 615 ASSERT_TRUE(base::StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); |
| 616 ASSERT_TRUE(EndsWith(response3, "Content for /test3", true)); | 616 ASSERT_TRUE(base::EndsWith(response3, "Content for /test3", true)); |
| 617 } | 617 } |
| 618 | 618 |
| 619 class CloseOnConnectHttpServerTest : public HttpServerTest { | 619 class CloseOnConnectHttpServerTest : public HttpServerTest { |
| 620 public: | 620 public: |
| 621 void OnConnect(int connection_id) override { | 621 void OnConnect(int connection_id) override { |
| 622 connection_ids_.push_back(connection_id); | 622 connection_ids_.push_back(connection_id); |
| 623 server_->Close(connection_id); | 623 server_->Close(connection_id); |
| 624 } | 624 } |
| 625 | 625 |
| 626 protected: | 626 protected: |
| 627 std::vector<int> connection_ids_; | 627 std::vector<int> connection_ids_; |
| 628 }; | 628 }; |
| 629 | 629 |
| 630 TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) { | 630 TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) { |
| 631 TestHttpClient client; | 631 TestHttpClient client; |
| 632 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 632 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
| 633 client.Send("GET / HTTP/1.1\r\n\r\n"); | 633 client.Send("GET / HTTP/1.1\r\n\r\n"); |
| 634 ASSERT_FALSE(RunUntilRequestsReceived(1)); | 634 ASSERT_FALSE(RunUntilRequestsReceived(1)); |
| 635 ASSERT_EQ(1ul, connection_ids_.size()); | 635 ASSERT_EQ(1ul, connection_ids_.size()); |
| 636 ASSERT_EQ(0ul, requests_.size()); | 636 ASSERT_EQ(0ul, requests_.size()); |
| 637 } | 637 } |
| 638 | 638 |
| 639 } // namespace | 639 } // namespace |
| 640 | 640 |
| 641 } // namespace net | 641 } // namespace net |
| OLD | NEW |