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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 269 |
270 virtual void Accept() OVERRIDE { NOTREACHED(); } | 270 virtual void Accept() OVERRIDE { NOTREACHED(); } |
271 | 271 |
272 private: | 272 private: |
273 virtual ~MockStreamListenSocket() {} | 273 virtual ~MockStreamListenSocket() {} |
274 }; | 274 }; |
275 | 275 |
276 } // namespace | 276 } // namespace |
277 | 277 |
278 TEST_F(HttpServerTest, RequestWithBodySplitAcrossPackets) { | 278 TEST_F(HttpServerTest, RequestWithBodySplitAcrossPackets) { |
279 scoped_refptr<StreamListenSocket> socket( | 279 StreamListenSocket* socket = |
280 new MockStreamListenSocket(server_.get())); | 280 new MockStreamListenSocket(server_.get()); |
281 server_->DidAccept(NULL, socket.get()); | 281 server_->DidAccept(NULL, make_scoped_ptr(socket)); |
282 std::string body("body"); | 282 std::string body("body"); |
283 std::string request = base::StringPrintf( | 283 std::string request = base::StringPrintf( |
284 "GET /test HTTP/1.1\r\n" | 284 "GET /test HTTP/1.1\r\n" |
285 "SomeHeader: 1\r\n" | 285 "SomeHeader: 1\r\n" |
286 "Content-Length: %" PRIuS "\r\n\r\n%s", | 286 "Content-Length: %" PRIuS "\r\n\r\n%s", |
287 body.length(), | 287 body.length(), |
288 body.c_str()); | 288 body.c_str()); |
289 server_->DidRead(socket.get(), request.c_str(), request.length() - 2); | 289 server_->DidRead(socket, request.c_str(), request.length() - 2); |
290 ASSERT_EQ(0u, requests_.size()); | 290 ASSERT_EQ(0u, requests_.size()); |
291 server_->DidRead(socket.get(), request.c_str() + request.length() - 2, 2); | 291 server_->DidRead(socket, request.c_str() + request.length() - 2, 2); |
292 ASSERT_EQ(1u, requests_.size()); | 292 ASSERT_EQ(1u, requests_.size()); |
293 ASSERT_EQ(body, requests_[0].data); | 293 ASSERT_EQ(body, requests_[0].data); |
294 } | 294 } |
295 | 295 |
296 TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) { | 296 TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) { |
297 // The idea behind this test is that requests with or without bodies should | 297 // The idea behind this test is that requests with or without bodies should |
298 // not break parsing of the next request. | 298 // not break parsing of the next request. |
299 TestHttpClient client; | 299 TestHttpClient client; |
300 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 300 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
301 std::string body = "body"; | 301 std::string body = "body"; |
302 client.Send(base::StringPrintf( | 302 client.Send(base::StringPrintf( |
303 "GET /test HTTP/1.1\r\n" | 303 "GET /test HTTP/1.1\r\n" |
304 "Content-Length: %" PRIuS "\r\n\r\n%s", | 304 "Content-Length: %" PRIuS "\r\n\r\n%s", |
305 body.length(), | 305 body.length(), |
306 body.c_str())); | 306 body.c_str())); |
307 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 307 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
308 ASSERT_EQ(body, requests_[0].data); | 308 ASSERT_EQ(body, requests_[0].data); |
309 | 309 |
310 client.Send("GET /test2 HTTP/1.1\r\n\r\n"); | 310 client.Send("GET /test2 HTTP/1.1\r\n\r\n"); |
311 ASSERT_TRUE(RunUntilRequestsReceived(2)); | 311 ASSERT_TRUE(RunUntilRequestsReceived(2)); |
312 ASSERT_EQ("/test2", requests_[1].path); | 312 ASSERT_EQ("/test2", requests_[1].path); |
313 | 313 |
314 client.Send("GET /test3 HTTP/1.1\r\n\r\n"); | 314 client.Send("GET /test3 HTTP/1.1\r\n\r\n"); |
315 ASSERT_TRUE(RunUntilRequestsReceived(3)); | 315 ASSERT_TRUE(RunUntilRequestsReceived(3)); |
316 ASSERT_EQ("/test3", requests_[2].path); | 316 ASSERT_EQ("/test3", requests_[2].path); |
317 } | 317 } |
318 | 318 |
319 } // namespace net | 319 } // namespace net |
OLD | NEW |