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

Side by Side Diff: net/http/http_stream_parser_unittest.cc

Issue 284913003: Remove DCHECK in HttpStreamParser::ReadResponseHeaders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Really remove line Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_stream_parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/http/http_stream_parser.h" 5 #include "net/http/http_stream_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 get_runner.ReadHeaders(); 797 get_runner.ReadHeaders();
798 EXPECT_EQ(200, get_runner.response_info()->headers->response_code()); 798 EXPECT_EQ(200, get_runner.response_info()->headers->response_code());
799 EXPECT_EQ(headers_size, get_runner.parser()->received_bytes()); 799 EXPECT_EQ(headers_size, get_runner.parser()->received_bytes());
800 int64 response_size = headers_size + body.size(); 800 int64 response_size = headers_size + body.size();
801 int body_size = body.size(); 801 int body_size = body.size();
802 int read_lengths[] = {body_size, 0}; 802 int read_lengths[] = {body_size, 0};
803 get_runner.ReadBody(body_size, read_lengths); 803 get_runner.ReadBody(body_size, read_lengths);
804 EXPECT_EQ(response_size, get_runner.parser()->received_bytes()); 804 EXPECT_EQ(response_size, get_runner.parser()->received_bytes());
805 } 805 }
806 806
807 // Test that an HttpStreamParser can be read from after it's received headers
808 // and data structures owned by its owner have been deleted. This happens
809 // when a ResponseBodyDrainer is used.
810 TEST(HttpStreamParser, ReadAfterUnownedObjectsDestroyed) {
811 MockWrite writes[] = {
812 MockWrite(SYNCHRONOUS, 0,
813 "GET /foo.html HTTP/1.1\r\n\r\n"),
814 MockWrite(SYNCHRONOUS, 1, "1"),
815 };
816
817 const int kBodySize = 1;
818 MockRead reads[] = {
819 MockRead(SYNCHRONOUS, 5, "HTTP/1.1 200 OK\r\n"),
820 MockRead(SYNCHRONOUS, 6, "Content-Length: 1\r\n\r\n"),
821 MockRead(SYNCHRONOUS, 6, "Connection: Keep-Alive\r\n\r\n"),
822 MockRead(SYNCHRONOUS, 7, "1"),
823 MockRead(SYNCHRONOUS, 0, 8), // EOF
824 };
825
826 StaticSocketDataProvider data(reads, arraysize(reads), writes,
827 arraysize(writes));
828 data.set_connect_data(MockConnect(SYNCHRONOUS, OK));
829
830 scoped_ptr<MockTCPClientSocket> transport(
831 new MockTCPClientSocket(AddressList(), NULL, &data));
832
833 TestCompletionCallback callback;
834 ASSERT_EQ(OK, transport->Connect(callback.callback()));
835
836 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle);
837 socket_handle->SetSocket(transport.PassAs<StreamSocket>());
838
839 scoped_ptr<HttpRequestInfo> request_info(new HttpRequestInfo());
840 request_info->method = "GET";
841 request_info->url = GURL("http://somewhere/foo.html");
842
843 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer);
844 HttpStreamParser parser(socket_handle.get(), request_info.get(),
845 read_buffer.get(), BoundNetLog());
846
847 scoped_ptr<HttpRequestHeaders> request_headers(new HttpRequestHeaders());
848 scoped_ptr<HttpResponseInfo> response_info(new HttpResponseInfo());
849 ASSERT_EQ(OK, parser.SendRequest("GET /foo.html HTTP/1.1\r\n",
850 *request_headers, response_info.get(), callback.callback()));
851 ASSERT_EQ(OK, parser.ReadResponseHeaders(callback.callback()));
852
853 // If the object that owns the HttpStreamParser is deleted, it takes the
854 // objects passed to the HttpStreamParser with it.
855 request_info.reset();
856 request_headers.reset();
857 response_info.reset();
858
859 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize));
860 ASSERT_EQ(kBodySize, parser.ReadResponseBody(
861 body_buffer.get(), kBodySize, callback.callback()));
862 }
863
807 } // namespace 864 } // namespace
808 865
809 } // namespace net 866 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698