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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 HttpServerTest() : quit_after_request_count_(0) {} | 182 HttpServerTest() : quit_after_request_count_(0) {} |
183 | 183 |
184 virtual void SetUp() OVERRIDE { | 184 virtual void SetUp() OVERRIDE { |
185 scoped_ptr<ServerSocket> server_socket( | 185 scoped_ptr<ServerSocket> server_socket( |
186 new TCPServerSocket(NULL, net::NetLog::Source())); | 186 new TCPServerSocket(NULL, net::NetLog::Source())); |
187 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); | 187 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); |
188 server_.reset(new HttpServer(server_socket.Pass(), this)); | 188 server_.reset(new HttpServer(server_socket.Pass(), this)); |
189 ASSERT_EQ(OK, server_->GetLocalAddress(&server_address_)); | 189 ASSERT_EQ(OK, server_->GetLocalAddress(&server_address_)); |
190 } | 190 } |
191 | 191 |
192 virtual void OnConnect(int connection_id) OVERRIDE {} | |
193 | |
192 virtual void OnHttpRequest(int connection_id, | 194 virtual void OnHttpRequest(int connection_id, |
193 const HttpServerRequestInfo& info) OVERRIDE { | 195 const HttpServerRequestInfo& info) OVERRIDE { |
194 requests_.push_back(std::make_pair(info, connection_id)); | 196 requests_.push_back(std::make_pair(info, connection_id)); |
195 if (requests_.size() == quit_after_request_count_) | 197 if (requests_.size() == quit_after_request_count_) |
196 run_loop_quit_func_.Run(); | 198 run_loop_quit_func_.Run(); |
197 } | 199 } |
198 | 200 |
199 virtual void OnWebSocketRequest(int connection_id, | 201 virtual void OnWebSocketRequest(int connection_id, |
200 const HttpServerRequestInfo& info) OVERRIDE { | 202 const HttpServerRequestInfo& info) OVERRIDE { |
201 NOTREACHED(); | 203 NOTREACHED(); |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 ASSERT_EQ("/test3", GetRequest(2).path); | 614 ASSERT_EQ("/test3", GetRequest(2).path); |
613 | 615 |
614 ASSERT_EQ(client_connection_id, GetConnectionId(2)); | 616 ASSERT_EQ(client_connection_id, GetConnectionId(2)); |
615 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); | 617 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); |
616 std::string response3; | 618 std::string response3; |
617 ASSERT_TRUE(client.ReadResponse(&response3)); | 619 ASSERT_TRUE(client.ReadResponse(&response3)); |
618 ASSERT_TRUE(StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); | 620 ASSERT_TRUE(StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); |
619 ASSERT_TRUE(EndsWith(response3, "Content for /test3", true)); | 621 ASSERT_TRUE(EndsWith(response3, "Content for /test3", true)); |
620 } | 622 } |
621 | 623 |
624 namespace { | |
mmenke
2014/09/24 15:38:45
nit: Can you just stick this entire file in the a
samuong
2014/09/24 16:32:51
I've done this as much as possible, but HttpServer
| |
625 | |
626 class CloseOnConnectHttpServerTest : public HttpServerTest { | |
627 public: | |
628 virtual void OnConnect(int connection_id) OVERRIDE { | |
629 connection_ids_.push_back(connection_id); | |
630 server_->Close(connection_id); | |
631 } | |
632 | |
633 protected: | |
634 std::vector<int> connection_ids_; | |
635 }; | |
636 | |
637 } // namespace | |
mmenke
2014/09/24 15:38:45
nit: 2 spaces between code and comment.
samuong
2014/09/24 16:32:51
Done.
| |
638 | |
639 TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) { | |
640 TestHttpClient client; | |
641 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | |
642 ASSERT_EQ(1ul, connection_ids_.size()); | |
643 client.Send("GET / HTTP/1.1\r\n\r\n"); | |
644 ASSERT_FALSE(RunUntilRequestsReceived(1)); | |
645 ASSERT_EQ(0ul, requests_.size()); | |
646 } | |
647 | |
622 } // namespace net | 648 } // namespace net |
OLD | NEW |