OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 spdy::SpdyFramer::set_enable_compression_default(true); | 167 spdy::SpdyFramer::set_enable_compression_default(true); |
168 // Empty the current queue. | 168 // Empty the current queue. |
169 MessageLoop::current()->RunAllPending(); | 169 MessageLoop::current()->RunAllPending(); |
170 PlatformTest::TearDown(); | 170 PlatformTest::TearDown(); |
171 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 171 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
172 MessageLoop::current()->RunAllPending(); | 172 MessageLoop::current()->RunAllPending(); |
173 } | 173 } |
174 | 174 |
175 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); | 175 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); |
176 | 176 |
177 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], | 177 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
178 size_t reads_count) { | 178 size_t data_count) { |
179 SimpleGetHelperResult out; | 179 SimpleGetHelperResult out; |
180 | 180 |
181 HttpRequestInfo request; | 181 HttpRequestInfo request; |
182 request.method = "GET"; | 182 request.method = "GET"; |
183 request.url = GURL("http://www.google.com/"); | 183 request.url = GURL("http://www.google.com/"); |
184 request.load_flags = 0; | 184 request.load_flags = 0; |
185 | 185 |
186 SessionDependencies session_deps; | 186 SessionDependencies session_deps; |
187 scoped_ptr<HttpTransaction> trans( | 187 scoped_ptr<HttpTransaction> trans( |
188 new HttpNetworkTransaction(CreateSession(&session_deps))); | 188 new HttpNetworkTransaction(CreateSession(&session_deps))); |
189 | 189 |
190 StaticSocketDataProvider data(data_reads, reads_count, NULL, 0); | 190 for (size_t i = 0; i < data_count; ++i) { |
191 session_deps.socket_factory.AddSocketDataProvider(&data); | 191 session_deps.socket_factory.AddSocketDataProvider(data[i]); |
| 192 } |
192 | 193 |
193 TestOldCompletionCallback callback; | 194 TestOldCompletionCallback callback; |
194 | 195 |
195 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 196 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
196 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); | 197 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); |
197 int rv = trans->Start(&request, &callback, log.bound()); | 198 int rv = trans->Start(&request, &callback, log.bound()); |
198 EXPECT_EQ(ERR_IO_PENDING, rv); | 199 EXPECT_EQ(ERR_IO_PENDING, rv); |
199 | 200 |
200 out.rv = callback.WaitForResult(); | 201 out.rv = callback.WaitForResult(); |
201 if (out.rv != OK) | 202 if (out.rv != OK) |
(...skipping 28 matching lines...) Expand all Loading... |
230 NetLogHttpRequestParameter* request_params = | 231 NetLogHttpRequestParameter* request_params = |
231 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get()); | 232 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get()); |
232 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine()); | 233 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine()); |
233 EXPECT_EQ("Host: www.google.com\r\n" | 234 EXPECT_EQ("Host: www.google.com\r\n" |
234 "Connection: keep-alive\r\n\r\n", | 235 "Connection: keep-alive\r\n\r\n", |
235 request_params->GetHeaders().ToString()); | 236 request_params->GetHeaders().ToString()); |
236 | 237 |
237 return out; | 238 return out; |
238 } | 239 } |
239 | 240 |
| 241 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 242 size_t reads_count) { |
| 243 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 244 StaticSocketDataProvider* data[] = { &reads }; |
| 245 return SimpleGetHelperForData(data, 1); |
| 246 } |
| 247 |
240 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 248 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
241 int expected_status); | 249 int expected_status); |
242 | 250 |
243 void ConnectStatusHelper(const MockRead& status); | 251 void ConnectStatusHelper(const MockRead& status); |
244 }; | 252 }; |
245 | 253 |
246 // Fill |str| with a long header list that consumes >= |size| bytes. | 254 // Fill |str| with a long header list that consumes >= |size| bytes. |
247 void FillLargeHeadersString(std::string* str, int size) { | 255 void FillLargeHeadersString(std::string* str, int size) { |
248 const char* row = | 256 const char* row = |
249 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; | 257 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
(...skipping 8988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9238 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9246 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
9239 EXPECT_TRUE(response->was_fetched_via_spdy); | 9247 EXPECT_TRUE(response->was_fetched_via_spdy); |
9240 EXPECT_TRUE(response->was_npn_negotiated); | 9248 EXPECT_TRUE(response->was_npn_negotiated); |
9241 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 9249 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
9242 EXPECT_EQ("hello!", response_data); | 9250 EXPECT_EQ("hello!", response_data); |
9243 | 9251 |
9244 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 9252 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
9245 HttpStreamFactory::set_use_alternate_protocols(false); | 9253 HttpStreamFactory::set_use_alternate_protocols(false); |
9246 } | 9254 } |
9247 | 9255 |
| 9256 TEST_F(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) { |
| 9257 MockRead data_reads1[] = { |
| 9258 MockRead(false, ERR_PIPELINE_EVICTION), |
| 9259 }; |
| 9260 MockRead data_reads2[] = { |
| 9261 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9262 MockRead("hello world"), |
| 9263 MockRead(false, OK), |
| 9264 }; |
| 9265 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), NULL, 0); |
| 9266 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), NULL, 0); |
| 9267 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 9268 |
| 9269 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 9270 |
| 9271 EXPECT_EQ(OK, out.rv); |
| 9272 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 9273 EXPECT_EQ("hello world", out.response_data); |
| 9274 } |
| 9275 |
| 9276 TEST_F(HttpNetworkTransactionTest, SendPipelineEvictionFallback) { |
| 9277 MockWrite data_writes1[] = { |
| 9278 MockWrite(false, ERR_PIPELINE_EVICTION), |
| 9279 }; |
| 9280 MockWrite data_writes2[] = { |
| 9281 MockWrite("GET / HTTP/1.1\r\n" |
| 9282 "Host: www.google.com\r\n" |
| 9283 "Connection: keep-alive\r\n\r\n"), |
| 9284 }; |
| 9285 MockRead data_reads2[] = { |
| 9286 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9287 MockRead("hello world"), |
| 9288 MockRead(false, OK), |
| 9289 }; |
| 9290 StaticSocketDataProvider data1(NULL, 0, |
| 9291 data_writes1, arraysize(data_writes1)); |
| 9292 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9293 data_writes2, arraysize(data_writes2)); |
| 9294 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 9295 |
| 9296 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 9297 |
| 9298 EXPECT_EQ(OK, out.rv); |
| 9299 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 9300 EXPECT_EQ("hello world", out.response_data); |
| 9301 } |
| 9302 |
9248 } // namespace net | 9303 } // namespace net |
OLD | NEW |