[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_util.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame^] | 8 | #include "base/files/file_path.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] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 101 | ASSERT_EQ(OK, body->Init(CompletionCallback())); |
[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] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 112 | ASSERT_EQ(OK, body->Init(CompletionCallback())); |
[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()); |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 124 | base::FilePath temp_file_path; |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 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( |
[email protected] | 671a714 | 2013-01-10 14:08:07 | [diff] [blame] | 129 | base::MessageLoopProxy::current(), 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] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 132 | TestCompletionCallback callback; |
| 133 | ASSERT_EQ(ERR_IO_PENDING, body->Init(callback.callback())); |
| 134 | ASSERT_EQ(OK, callback.WaitForResult()); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 135 | // 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] | 136 | ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 137 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 140 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 141 | ScopedVector<UploadElementReader> element_readers; |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 142 | const std::string payload = "123"; |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 143 | element_readers.push_back(new UploadBytesElementReader( |
| 144 | payload.data(), payload.size())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 145 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 146 | scoped_ptr<UploadDataStream> body(new UploadDataStream(&element_readers, 0)); |
[email protected] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 147 | ASSERT_EQ(OK, body->Init(CompletionCallback())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 148 | // Yes, should be merged if the in-memory body is small here. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 149 | ASSERT_TRUE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 150 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 153 | TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_LargeBodyInMemory) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 154 | ScopedVector<UploadElementReader> element_readers; |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 155 | const std::string payload(10000, 'a'); // 'a' x 10000. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 156 | element_readers.push_back(new UploadBytesElementReader( |
| 157 | payload.data(), payload.size())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 158 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 159 | scoped_ptr<UploadDataStream> body(new UploadDataStream(&element_readers, 0)); |
[email protected] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 160 | ASSERT_EQ(OK, body->Init(CompletionCallback())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 161 | // Shouldn't be merged if the in-memory body is large here. |
[email protected] | 75577ec | 2012-01-24 23:41:50 | [diff] [blame] | 162 | ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 163 | "some header", body.get())); |
[email protected] | 7a1fcff | 2012-01-24 01:07:49 | [diff] [blame] | 164 | } |
| 165 | |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 166 | // Test to ensure the HttpStreamParser state machine does not get confused |
| 167 | // when sending a request with a chunked body, where chunks become available |
| 168 | // asynchronously, over a socket where writes may also complete |
| 169 | // asynchronously. |
| 170 | // This is a regression test for http://crbug.com/132243 |
| 171 | TEST(HttpStreamParser, AsyncChunkAndAsyncSocket) { |
| 172 | // The chunks that will be written in the request, as reflected in the |
| 173 | // MockWrites below. |
| 174 | static const char kChunk1[] = "Chunk 1"; |
| 175 | static const char kChunk2[] = "Chunky 2"; |
| 176 | static const char kChunk3[] = "Test 3"; |
| 177 | |
| 178 | MockWrite writes[] = { |
| 179 | MockWrite(ASYNC, 0, |
| 180 | "GET /one.html HTTP/1.1\r\n" |
| 181 | "Host: localhost\r\n" |
| 182 | "Transfer-Encoding: chunked\r\n" |
| 183 | "Connection: keep-alive\r\n\r\n"), |
| 184 | MockWrite(ASYNC, 1, "7\r\nChunk 1\r\n"), |
| 185 | MockWrite(ASYNC, 2, "8\r\nChunky 2\r\n"), |
| 186 | MockWrite(ASYNC, 3, "6\r\nTest 3\r\n"), |
| 187 | MockWrite(ASYNC, 4, "0\r\n\r\n"), |
| 188 | }; |
| 189 | |
| 190 | // The size of the response body, as reflected in the Content-Length of the |
| 191 | // MockRead below. |
| 192 | static const int kBodySize = 8; |
| 193 | |
| 194 | MockRead reads[] = { |
| 195 | MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), |
| 196 | MockRead(ASYNC, 6, "Content-Length: 8\r\n\r\n"), |
| 197 | MockRead(ASYNC, 7, "one.html"), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 198 | MockRead(SYNCHRONOUS, 0, 8), // EOF |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 199 | }; |
| 200 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 201 | UploadDataStream upload_stream(UploadDataStream::CHUNKED, 0); |
| 202 | upload_stream.AppendChunk(kChunk1, arraysize(kChunk1) - 1, false); |
[email protected] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 203 | ASSERT_EQ(OK, upload_stream.Init(CompletionCallback())); |
[email protected] | 9a96389 | 2012-11-01 11:48:13 | [diff] [blame] | 204 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 205 | DeterministicSocketData data(reads, arraysize(reads), |
| 206 | writes, arraysize(writes)); |
| 207 | data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 208 | |
| 209 | scoped_ptr<DeterministicMockTCPClientSocket> transport( |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 210 | new DeterministicMockTCPClientSocket(NULL, &data)); |
| 211 | data.set_socket(transport->AsWeakPtr()); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 212 | |
| 213 | TestCompletionCallback callback; |
| 214 | int rv = transport->Connect(callback.callback()); |
| 215 | rv = callback.GetResult(rv); |
| 216 | ASSERT_EQ(OK, rv); |
| 217 | |
| 218 | scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle); |
| 219 | socket_handle->set_socket(transport.release()); |
| 220 | |
| 221 | HttpRequestInfo request_info; |
| 222 | request_info.method = "GET"; |
| 223 | request_info.url = GURL("http://localhost"); |
| 224 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | bf3eb00 | 2012-11-15 05:50:11 | [diff] [blame] | 225 | request_info.upload_data_stream = &upload_stream; |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 226 | |
| 227 | scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 228 | HttpStreamParser parser(socket_handle.get(), &request_info, read_buffer, |
| 229 | BoundNetLog()); |
| 230 | |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 231 | HttpRequestHeaders request_headers; |
| 232 | request_headers.SetHeader("Host", "localhost"); |
| 233 | request_headers.SetHeader("Transfer-Encoding", "chunked"); |
| 234 | request_headers.SetHeader("Connection", "keep-alive"); |
| 235 | |
| 236 | HttpResponseInfo response_info; |
| 237 | // This will attempt to Write() the initial request and headers, which will |
| 238 | // complete asynchronously. |
| 239 | rv = parser.SendRequest("GET /one.html HTTP/1.1\r\n", request_headers, |
[email protected] | bf3eb00 | 2012-11-15 05:50:11 | [diff] [blame] | 240 | &response_info, callback.callback()); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 241 | ASSERT_EQ(ERR_IO_PENDING, rv); |
| 242 | |
| 243 | // Complete the initial request write. Additionally, this should enqueue the |
| 244 | // first chunk. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 245 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 246 | ASSERT_FALSE(callback.have_result()); |
| 247 | |
| 248 | // Now append another chunk (while the first write is still pending), which |
| 249 | // should not confuse the state machine. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 250 | upload_stream.AppendChunk(kChunk2, arraysize(kChunk2) - 1, false); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 251 | ASSERT_FALSE(callback.have_result()); |
| 252 | |
| 253 | // Complete writing the first chunk, which should then enqueue the second |
| 254 | // chunk for writing and return, because it is set to complete |
| 255 | // asynchronously. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 256 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 257 | ASSERT_FALSE(callback.have_result()); |
| 258 | |
| 259 | // Complete writing the second chunk. However, because no chunks are |
| 260 | // available yet, no further writes should be called until a new chunk is |
| 261 | // added. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 262 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 263 | ASSERT_FALSE(callback.have_result()); |
| 264 | |
| 265 | // Add the final chunk. This will enqueue another write, but it will not |
| 266 | // complete due to the async nature. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 267 | upload_stream.AppendChunk(kChunk3, arraysize(kChunk3) - 1, true); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 268 | ASSERT_FALSE(callback.have_result()); |
| 269 | |
| 270 | // Finalize writing the last chunk, which will enqueue the trailer. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 271 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 272 | ASSERT_FALSE(callback.have_result()); |
| 273 | |
| 274 | // Finalize writing the trailer. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 275 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 276 | ASSERT_TRUE(callback.have_result()); |
| 277 | |
| 278 | // Warning: This will hang if the callback doesn't already have a result, |
| 279 | // due to the deterministic socket provider. Do not remove the above |
| 280 | // ASSERT_TRUE, which will avoid this hang. |
| 281 | rv = callback.WaitForResult(); |
| 282 | ASSERT_EQ(OK, rv); |
| 283 | |
| 284 | // Attempt to read the response status and the response headers. |
| 285 | rv = parser.ReadResponseHeaders(callback.callback()); |
| 286 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 287 | data.RunFor(2); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 288 | |
| 289 | ASSERT_TRUE(callback.have_result()); |
| 290 | rv = callback.WaitForResult(); |
| 291 | ASSERT_GT(rv, 0); |
| 292 | |
| 293 | // Finally, attempt to read the response body. |
| 294 | scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); |
| 295 | rv = parser.ReadResponseBody(body_buffer, kBodySize, callback.callback()); |
| 296 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 297 | data.RunFor(1); |
[email protected] | 4750937f | 2012-06-15 20:44:21 | [diff] [blame] | 298 | |
| 299 | ASSERT_TRUE(callback.have_result()); |
| 300 | rv = callback.WaitForResult(); |
| 301 | ASSERT_EQ(kBodySize, rv); |
| 302 | } |
| 303 | |
[email protected] | 6db833d1 | 2012-01-21 00:45:19 | [diff] [blame] | 304 | } // namespace net |