Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: net/server/http_server_unittest.cc

Issue 1215933004: New new versions of Starts/EndsWith and SplitString in net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@starts_with
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_utils.cc ('k') | net/spdy/spdy_test_util_common.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 TEST_F(HttpServerTest, Request) { 264 TEST_F(HttpServerTest, Request) {
265 TestHttpClient client; 265 TestHttpClient client;
266 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); 266 ASSERT_EQ(OK, client.ConnectAndWait(server_address_));
267 client.Send("GET /test HTTP/1.1\r\n\r\n"); 267 client.Send("GET /test HTTP/1.1\r\n\r\n");
268 ASSERT_TRUE(RunUntilRequestsReceived(1)); 268 ASSERT_TRUE(RunUntilRequestsReceived(1));
269 ASSERT_EQ("GET", GetRequest(0).method); 269 ASSERT_EQ("GET", GetRequest(0).method);
270 ASSERT_EQ("/test", GetRequest(0).path); 270 ASSERT_EQ("/test", GetRequest(0).path);
271 ASSERT_EQ("", GetRequest(0).data); 271 ASSERT_EQ("", GetRequest(0).data);
272 ASSERT_EQ(0u, GetRequest(0).headers.size()); 272 ASSERT_EQ(0u, GetRequest(0).headers.size());
273 ASSERT_TRUE( 273 ASSERT_TRUE(base::StartsWith(GetRequest(0).peer.ToString(), "127.0.0.1",
274 base::StartsWithASCII(GetRequest(0).peer.ToString(), "127.0.0.1", true)); 274 base::CompareCase::SENSITIVE));
275 } 275 }
276 276
277 TEST_F(HttpServerTest, RequestWithHeaders) { 277 TEST_F(HttpServerTest, RequestWithHeaders) {
278 TestHttpClient client; 278 TestHttpClient client;
279 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); 279 ASSERT_EQ(OK, client.ConnectAndWait(server_address_));
280 const char* const kHeaders[][3] = { 280 const char* const kHeaders[][3] = {
281 {"Header", ": ", "1"}, 281 {"Header", ": ", "1"},
282 {"HeaderWithNoWhitespace", ":", "1"}, 282 {"HeaderWithNoWhitespace", ":", "1"},
283 {"HeaderWithWhitespace", " : \t ", "1 1 1 \t "}, 283 {"HeaderWithWhitespace", " : \t ", "1 1 1 \t "},
284 {"HeaderWithColon", ": ", "1:1"}, 284 {"HeaderWithColon", ": ", "1:1"},
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 435
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::StartsWith(response, "HTTP/1.1 200 OK",
446 ASSERT_TRUE(base::EndsWith(response, "Response!", true)); 446 base::CompareCase::SENSITIVE));
447 ASSERT_TRUE(
448 base::EndsWith(response, "Response!", base::CompareCase::SENSITIVE));
447 } 449 }
448 450
449 TEST_F(HttpServerTest, SendRaw) { 451 TEST_F(HttpServerTest, SendRaw) {
450 TestHttpClient client; 452 TestHttpClient client;
451 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); 453 ASSERT_EQ(OK, client.ConnectAndWait(server_address_));
452 client.Send("GET /test HTTP/1.1\r\n\r\n"); 454 client.Send("GET /test HTTP/1.1\r\n\r\n");
453 ASSERT_TRUE(RunUntilRequestsReceived(1)); 455 ASSERT_TRUE(RunUntilRequestsReceived(1));
454 server_->SendRaw(GetConnectionId(0), "Raw Data "); 456 server_->SendRaw(GetConnectionId(0), "Raw Data ");
455 server_->SendRaw(GetConnectionId(0), "More Data"); 457 server_->SendRaw(GetConnectionId(0), "More Data");
456 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); 458 server_->SendRaw(GetConnectionId(0), "Third Piece of Data");
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 "Content-Length: %" PRIuS "\r\n\r\n%s", 586 "Content-Length: %" PRIuS "\r\n\r\n%s",
585 body.length(), 587 body.length(),
586 body.c_str())); 588 body.c_str()));
587 ASSERT_TRUE(RunUntilRequestsReceived(1)); 589 ASSERT_TRUE(RunUntilRequestsReceived(1));
588 ASSERT_EQ(body, GetRequest(0).data); 590 ASSERT_EQ(body, GetRequest(0).data);
589 591
590 int client_connection_id = GetConnectionId(0); 592 int client_connection_id = GetConnectionId(0);
591 server_->Send200(client_connection_id, "Content for /test", "text/plain"); 593 server_->Send200(client_connection_id, "Content for /test", "text/plain");
592 std::string response1; 594 std::string response1;
593 ASSERT_TRUE(client.ReadResponse(&response1)); 595 ASSERT_TRUE(client.ReadResponse(&response1));
594 ASSERT_TRUE(base::StartsWithASCII(response1, "HTTP/1.1 200 OK", true)); 596 ASSERT_TRUE(base::StartsWith(response1, "HTTP/1.1 200 OK",
595 ASSERT_TRUE(base::EndsWith(response1, "Content for /test", true)); 597 base::CompareCase::SENSITIVE));
598 ASSERT_TRUE(base::EndsWith(response1, "Content for /test",
599 base::CompareCase::SENSITIVE));
596 600
597 client.Send("GET /test2 HTTP/1.1\r\n\r\n"); 601 client.Send("GET /test2 HTTP/1.1\r\n\r\n");
598 ASSERT_TRUE(RunUntilRequestsReceived(2)); 602 ASSERT_TRUE(RunUntilRequestsReceived(2));
599 ASSERT_EQ("/test2", GetRequest(1).path); 603 ASSERT_EQ("/test2", GetRequest(1).path);
600 604
601 ASSERT_EQ(client_connection_id, GetConnectionId(1)); 605 ASSERT_EQ(client_connection_id, GetConnectionId(1));
602 server_->Send404(client_connection_id); 606 server_->Send404(client_connection_id);
603 std::string response2; 607 std::string response2;
604 ASSERT_TRUE(client.ReadResponse(&response2)); 608 ASSERT_TRUE(client.ReadResponse(&response2));
605 ASSERT_TRUE(base::StartsWithASCII(response2, "HTTP/1.1 404 Not Found", true)); 609 ASSERT_TRUE(base::StartsWith(response2, "HTTP/1.1 404 Not Found",
610 base::CompareCase::SENSITIVE));
606 611
607 client.Send("GET /test3 HTTP/1.1\r\n\r\n"); 612 client.Send("GET /test3 HTTP/1.1\r\n\r\n");
608 ASSERT_TRUE(RunUntilRequestsReceived(3)); 613 ASSERT_TRUE(RunUntilRequestsReceived(3));
609 ASSERT_EQ("/test3", GetRequest(2).path); 614 ASSERT_EQ("/test3", GetRequest(2).path);
610 615
611 ASSERT_EQ(client_connection_id, GetConnectionId(2)); 616 ASSERT_EQ(client_connection_id, GetConnectionId(2));
612 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); 617 server_->Send200(client_connection_id, "Content for /test3", "text/plain");
613 std::string response3; 618 std::string response3;
614 ASSERT_TRUE(client.ReadResponse(&response3)); 619 ASSERT_TRUE(client.ReadResponse(&response3));
615 ASSERT_TRUE(base::StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); 620 ASSERT_TRUE(base::StartsWith(response3, "HTTP/1.1 200 OK",
616 ASSERT_TRUE(base::EndsWith(response3, "Content for /test3", true)); 621 base::CompareCase::SENSITIVE));
622 ASSERT_TRUE(base::EndsWith(response3, "Content for /test3",
623 base::CompareCase::SENSITIVE));
617 } 624 }
618 625
619 class CloseOnConnectHttpServerTest : public HttpServerTest { 626 class CloseOnConnectHttpServerTest : public HttpServerTest {
620 public: 627 public:
621 void OnConnect(int connection_id) override { 628 void OnConnect(int connection_id) override {
622 connection_ids_.push_back(connection_id); 629 connection_ids_.push_back(connection_id);
623 server_->Close(connection_id); 630 server_->Close(connection_id);
624 } 631 }
625 632
626 protected: 633 protected:
627 std::vector<int> connection_ids_; 634 std::vector<int> connection_ids_;
628 }; 635 };
629 636
630 TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) { 637 TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) {
631 TestHttpClient client; 638 TestHttpClient client;
632 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); 639 ASSERT_EQ(OK, client.ConnectAndWait(server_address_));
633 client.Send("GET / HTTP/1.1\r\n\r\n"); 640 client.Send("GET / HTTP/1.1\r\n\r\n");
634 ASSERT_FALSE(RunUntilRequestsReceived(1)); 641 ASSERT_FALSE(RunUntilRequestsReceived(1));
635 ASSERT_EQ(1ul, connection_ids_.size()); 642 ASSERT_EQ(1ul, connection_ids_.size());
636 ASSERT_EQ(0ul, requests_.size()); 643 ASSERT_EQ(0ul, requests_.size());
637 } 644 }
638 645
639 } // namespace 646 } // namespace
640 647
641 } // namespace net 648 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_utils.cc ('k') | net/spdy/spdy_test_util_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698