[email protected] | 6db833d1 | 2012-01-21 00:45:19 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/http/http_stream_parser.h" |
| 6 | |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 7 | #include "base/file_path.h" |
| 8 | #include "base/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 9 | #include "base/files/scoped_temp_dir.h" |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
[email protected] | 6db833d1 | 2012-01-21 00:45:19 | [diff] [blame] | 11 | #include "base/string_piece.h" |
| 12 | #include "base/stringprintf.h" |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 13 | #include "googleurl/src/gurl.h" |
| 14 | #include "net/base/io_buffer.h" |
[email protected] | 6db833d1 | 2012-01-21 00:45:19 | [diff] [blame] | 15 | #include "net/base/net_errors.h" |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 16 | #include "net/base/test_completion_callback.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 17 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 18 | #include "net/base/upload_data_stream.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 19 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 20 | #include "net/http/http_request_headers.h" |
| 21 | #include "net/http/http_request_info.h" |
| 22 | #include "net/http/http_response_info.h" |
| 23 | #include "net/socket/client_socket_handle.h" |
| 24 | #include "net/socket/socket_test_util.h" |
[email protected] | 6db833d1 | 2012-01-21 00:45:19 | [diff] [blame] | 25 | #include "testing/gtest/include/gtest/gtest.h" |
| 26 | |
| 27 | namespace net { |
| 28 | |
| 29 | const size_t kOutputSize = 1024; // Just large enough for this test. |
| 30 | // The number of bytes that can fit in a buffer of kOutputSize. |
| 31 | const size_t kMaxPayloadSize = |
| 32 | kOutputSize - HttpStreamParser::kChunkHeaderFooterSize; |
| 33 | |
| 34 | // The empty payload is how the last chunk is encoded. |
| 35 | TEST(HttpStreamParser, EncodeChunk_EmptyPayload) { |
| 36 | char output[kOutputSize]; |
| 37 | |
| 38 | const base::StringPiece kPayload = ""; |
| 39 | const base::StringPiece kExpected = "0\r\n\r\n"; |
| 40 | const int num_bytes_written = |
| 41 | HttpStreamParser::EncodeChunk(kPayload, output, sizeof(output)); |
| 42 | ASSERT_EQ(kExpected.size(), static_cast<size_t>(num_bytes_written)); |
| 43 | EXPECT_EQ(kExpected, base::StringPiece(output, num_bytes_written)); |
| 44 | } |
| 45 | |
| 46 | TEST(HttpStreamParser, EncodeChunk_ShortPayload) { |
| 47 | char output[kOutputSize]; |
| 48 | |
| 49 | const std::string kPayload("foo\x00\x11\x22", 6); |
| 50 | // 11 = payload size + sizeof("6") + CRLF x 2. |
| 51 | const std::string kExpected("6\r\nfoo\x00\x11\x22\r\n", 11); |
| 52 | const int num_bytes_written = |
| 53 | HttpStreamParser::EncodeChunk(kPayload, output, sizeof(output)); |
| 54 | ASSERT_EQ(kExpected.size(), static_cast<size_t>(num_bytes_written)); |
| 55 | EXPECT_EQ(kExpected, base::StringPiece(output, num_bytes_written)); |
| 56 | } |
| 57 | |
| 58 | TEST(HttpStreamParser, EncodeChunk_LargePayload) { |
| 59 | char output[kOutputSize]; |
| 60 | |
| 61 | const std::string kPayload(1000, '\xff'); // '\xff' x 1000. |
| 62 | // 3E8 = 1000 in hex. |
| 63 | const std::string kExpected = "3E8\r\n" + kPayload + "\r\n"; |
| 64 | const int num_bytes_written = |
| 65 | HttpStreamParser::EncodeChunk(kPayload, output, sizeof(output)); |
| 66 | ASSERT_EQ(kExpected.size(), static_cast<size_t>(num_bytes_written)); |
| 67 | EXPECT_EQ(kExpected, base::StringPiece(output, num_bytes_written)); |
| 68 | } |
| 69 | |
| 70 | TEST(HttpStreamParser, EncodeChunk_FullPayload) { |
| 71 | char output[kOutputSize]; |
| 72 | |
| 73 | const std::string kPayload(kMaxPayloadSize, '\xff'); |
| 74 | // 3F4 = 1012 in hex. |
| 75 | const std::string kExpected = "3F4\r\n" + kPayload + "\r\n"; |
| 76 | const int num_bytes_written = |
| 77 | HttpStreamParser::EncodeChunk(kPayload, output, sizeof(output)); |
| 78 | ASSERT_EQ(kExpected.size(), static_cast<size_t>(num_bytes_written)); |
| 79 | EXPECT_EQ(kExpected, base::StringPiece(output, num_bytes_written)); |
| 80 | } |
| 81 | |
| 82 | TEST(HttpStreamParser, EncodeChunk_TooLargePayload) { |
| 83 | char output[kOutputSize]; |
| 84 | |
| 85 | // The payload is one byte larger the output buffer size. |
| 86 | const std::string kPayload(kMaxPayloadSize + 1, '\xff'); |
| 87 | const int num_bytes_written = |
| 88 | HttpStreamParser::EncodeChunk(kPayload, output, sizeof(output)); |
| 89 | ASSERT_EQ(ERR_INVALID_ARGUMENT, num_bytes_written); |
| 90 | } |
| 91 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 92 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_NoBody) { |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 93 | // Shouldn't be merged if upload data is non-existent. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 94 | ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 95 | "some header", NULL)); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 96 | } |
| 97 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 98 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_EmptyBody) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 99 | ScopedVector<UploadElementReader> element_readers; |
| 100 | scoped_ptr<UploadDataStream> body(new UploadDataStream(&element_readers, 0)); |
[email protected] | df7adc6 | 2012-09-18 14:01:53 | [diff] [blame] | 101 | ASSERT_EQ(OK, body->InitSync()); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 102 | // Shouldn't be merged if upload data is empty. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 103 | ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 104 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 107 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_ChunkedBody) { |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 108 | const std::string payload = "123"; |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 109 | scoped_ptr<UploadDataStream> body( |
| 110 | new UploadDataStream(UploadDataStream::CHUNKED, 0)); |
| 111 | body->AppendChunk(payload.data(), payload.size(), true); |
[email protected] | df7adc6 | 2012-09-18 14:01:53 | [diff] [blame] | 112 | ASSERT_EQ(OK, body->InitSync()); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 113 | // Shouldn't be merged if upload data carries chunked data. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 114 | ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 115 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 116 | } |
| 117 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 118 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 119 | ScopedVector<UploadElementReader> element_readers; |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 120 | |
| 121 | // Create an empty temporary file. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 122 | base::ScopedTempDir temp_dir; |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 123 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 124 | FilePath temp_file_path; |
| 125 | ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), |
| 126 | &temp_file_path)); |
| 127 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 128 | element_readers.push_back(new UploadFileElementReader( |
| 129 | temp_file_path, 0, 0, base::Time())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 130 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 131 | scoped_ptr<UploadDataStream> body(new UploadDataStream(&element_readers, 0)); |
[email protected] | df7adc6 | 2012-09-18 14:01:53 | [diff] [blame] | 132 | ASSERT_EQ(OK, body->InitSync()); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 133 | // Shouldn't be merged if upload data carries a file, as it's not in-memory. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 134 | ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 135 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 136 | } |
| 137 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 138 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 139 | ScopedVector<UploadElementReader> element_readers; |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 140 | const std::string payload = "123"; |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 141 | element_readers.push_back(new UploadBytesElementReader( |
| 142 | payload.data(), payload.size())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 143 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 144 | scoped_ptr<UploadDataStream> body(new UploadDataStream(&element_readers, 0)); |
[email protected] | df7adc6 | 2012-09-18 14:01:53 | [diff] [blame] | 145 | ASSERT_EQ(OK, body->InitSync()); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 146 | // Yes, should be merged if the in-memory body is small here. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 147 | ASSERT_TRUE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 148 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 151 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_LargeBodyInMemory) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 152 | ScopedVector<UploadElementReader> element_readers; |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 153 | const std::string payload(10000, 'a'); // 'a' x 10000. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 154 | element_readers.push_back(new UploadBytesElementReader( |
| 155 | payload.data(), payload.size())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 156 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 157 | scoped_ptr<UploadDataStream> body(new UploadDataStream(&element_readers, 0)); |
[email protected] | df7adc6 | 2012-09-18 14:01:53 | [diff] [blame] | 158 | ASSERT_EQ(OK, body->InitSync()); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 159 | // Shouldn't be merged if the in-memory body is large here. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 160 | ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 161 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 164 | // Test to ensure the HttpStreamParser state machine does not get confused |
| 165 | // when sending a request with a chunked body, where chunks become available |
| 166 | // asynchronously, over a socket where writes may also complete |
| 167 | // asynchronously. |
| 168 | // This is a regression test for http://crbug.com/132243 |
| 169 | TEST(HttpStreamParser, AsyncChunkAndAsyncSocket) { |
| 170 | // The chunks that will be written in the request, as reflected in the |
| 171 | // MockWrites below. |
| 172 | static const char kChunk1[] = "Chunk 1"; |
| 173 | static const char kChunk2[] = "Chunky 2"; |
| 174 | static const char kChunk3[] = "Test 3"; |
| 175 | |
| 176 | MockWrite writes[] = { |
| 177 | MockWrite(ASYNC, 0, |
| 178 | "GET /one.html HTTP/1.1\r\n" |
| 179 | "Host: localhost\r\n" |
| 180 | "Transfer-Encoding: chunked\r\n" |
| 181 | "Connection: keep-alive\r\n\r\n"), |
| 182 | MockWrite(ASYNC, 1, "7\r\nChunk 1\r\n"), |
| 183 | MockWrite(ASYNC, 2, "8\r\nChunky 2\r\n"), |
| 184 | MockWrite(ASYNC, 3, "6\r\nTest 3\r\n"), |
| 185 | MockWrite(ASYNC, 4, "0\r\n\r\n"), |
| 186 | }; |
| 187 | |
| 188 | // The size of the response body, as reflected in the Content-Length of the |
| 189 | // MockRead below. |
| 190 | static const int kBodySize = 8; |
| 191 | |
| 192 | MockRead reads[] = { |
| 193 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), |
| 194 | MockRead(ASYNC, 6, "Content-Length: 8\r\n\r\n"), |
| 195 | MockRead(ASYNC, 7, "one.html"), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 196 | MockRead(SYNCHRONOUS, 0, 8), // EOF |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 197 | }; |
| 198 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 199 | UploadDataStream upload_stream(UploadDataStream::CHUNKED, 0); |
| 200 | upload_stream.AppendChunk(kChunk1, arraysize(kChunk1) - 1, false); |
[email protected] | bf3eb00 | 2012-11-15 05:50:11 | [diff] [blame] | 201 | ASSERT_EQ(OK, upload_stream.InitSync()); |
[email protected] | 9a96389 | 2012-11-01 11:48:13 | [diff] [blame] | 202 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 203 | DeterministicSocketData data(reads, arraysize(reads), |
| 204 | writes, arraysize(writes)); |
| 205 | data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 206 | |
| 207 | scoped_ptr<DeterministicMockTCPClientSocket> transport( |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 208 | new DeterministicMockTCPClientSocket(NULL, &data)); |
| 209 | data.set_socket(transport->AsWeakPtr()); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 210 | |
| 211 | TestCompletionCallback callback; |
| 212 | int rv = transport->Connect(callback.callback()); |
| 213 | rv = callback.GetResult(rv); |
| 214 | ASSERT_EQ(OK, rv); |
| 215 | |
| 216 | scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle); |
| 217 | socket_handle->set_socket(transport.release()); |
| 218 | |
| 219 | HttpRequestInfo request_info; |
| 220 | request_info.method = "GET"; |
| 221 | request_info.url = GURL("http://localhost"); |
| 222 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | bf3eb00 | 2012-11-15 05:50:11 | [diff] [blame] | 223 | request_info.upload_data_stream = &upload_stream; |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 224 | |
| 225 | scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 226 | HttpStreamParser parser(socket_handle.get(), &request_info, read_buffer, |
| 227 | BoundNetLog()); |
| 228 | |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 229 | HttpRequestHeaders request_headers; |
| 230 | request_headers.SetHeader("Host", "localhost"); |
| 231 | request_headers.SetHeader("Transfer-Encoding", "chunked"); |
| 232 | request_headers.SetHeader("Connection", "keep-alive"); |
| 233 | |
| 234 | HttpResponseInfo response_info; |
| 235 | // This will attempt to Write() the initial request and headers, which will |
| 236 | // complete asynchronously. |
| 237 | rv = parser.SendRequest("GET /one.html HTTP/1.1\r\n", request_headers, |
[email protected] | bf3eb00 | 2012-11-15 05:50:11 | [diff] [blame] | 238 | &response_info, callback.callback()); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 239 | ASSERT_EQ(ERR_IO_PENDING, rv); |
| 240 | |
| 241 | // Complete the initial request write. Additionally, this should enqueue the |
| 242 | // first chunk. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 243 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 244 | ASSERT_FALSE(callback.have_result()); |
| 245 | |
| 246 | // Now append another chunk (while the first write is still pending), which |
| 247 | // should not confuse the state machine. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 248 | upload_stream.AppendChunk(kChunk2, arraysize(kChunk2) - 1, false); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 249 | ASSERT_FALSE(callback.have_result()); |
| 250 | |
| 251 | // Complete writing the first chunk, which should then enqueue the second |
| 252 | // chunk for writing and return, because it is set to complete |
| 253 | // asynchronously. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 254 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 255 | ASSERT_FALSE(callback.have_result()); |
| 256 | |
| 257 | // Complete writing the second chunk. However, because no chunks are |
| 258 | // available yet, no further writes should be called until a new chunk is |
| 259 | // added. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 260 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 261 | ASSERT_FALSE(callback.have_result()); |
| 262 | |
| 263 | // Add the final chunk. This will enqueue another write, but it will not |
| 264 | // complete due to the async nature. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame^] | 265 | upload_stream.AppendChunk(kChunk3, arraysize(kChunk3) - 1, true); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 266 | ASSERT_FALSE(callback.have_result()); |
| 267 | |
| 268 | // Finalize writing the last chunk, which will enqueue the trailer. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 269 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 270 | ASSERT_FALSE(callback.have_result()); |
| 271 | |
| 272 | // Finalize writing the trailer. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 273 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 274 | ASSERT_TRUE(callback.have_result()); |
| 275 | |
| 276 | // Warning: This will hang if the callback doesn't already have a result, |
| 277 | // due to the deterministic socket provider. Do not remove the above |
| 278 | // ASSERT_TRUE, which will avoid this hang. |
| 279 | rv = callback.WaitForResult(); |
| 280 | ASSERT_EQ(OK, rv); |
| 281 | |
| 282 | // Attempt to read the response status and the response headers. |
| 283 | rv = parser.ReadResponseHeaders(callback.callback()); |
| 284 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 285 | data.RunFor(2); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 286 | |
| 287 | ASSERT_TRUE(callback.have_result()); |
| 288 | rv = callback.WaitForResult(); |
| 289 | ASSERT_GT(rv, 0); |
| 290 | |
| 291 | // Finally, attempt to read the response body. |
| 292 | scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); |
| 293 | rv = parser.ReadResponseBody(body_buffer, kBodySize, callback.callback()); |
| 294 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 295 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 296 | |
| 297 | ASSERT_TRUE(callback.have_result()); |
| 298 | rv = callback.WaitForResult(); |
| 299 | ASSERT_EQ(kBodySize, rv); |
| 300 | } |
| 301 | |
[email protected] | 6db833d1 | 2012-01-21 00:45:19 | [diff] [blame] | 302 | } // namespace net |