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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 spdy::SpdyFramer::set_enable_compression_default(true); | 139 spdy::SpdyFramer::set_enable_compression_default(true); |
140 // Empty the current queue. | 140 // Empty the current queue. |
141 MessageLoop::current()->RunAllPending(); | 141 MessageLoop::current()->RunAllPending(); |
142 PlatformTest::TearDown(); | 142 PlatformTest::TearDown(); |
143 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 143 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
144 MessageLoop::current()->RunAllPending(); | 144 MessageLoop::current()->RunAllPending(); |
145 } | 145 } |
146 | 146 |
147 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); | 147 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); |
148 | 148 |
149 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], | 149 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
150 size_t reads_count) { | 150 size_t data_count) { |
151 SimpleGetHelperResult out; | 151 SimpleGetHelperResult out; |
152 | 152 |
153 HttpRequestInfo request; | 153 HttpRequestInfo request; |
154 request.method = "GET"; | 154 request.method = "GET"; |
155 request.url = GURL("http://www.google.com/"); | 155 request.url = GURL("http://www.google.com/"); |
156 request.load_flags = 0; | 156 request.load_flags = 0; |
157 | 157 |
158 SessionDependencies session_deps; | 158 SessionDependencies session_deps; |
159 scoped_ptr<HttpTransaction> trans( | 159 scoped_ptr<HttpTransaction> trans( |
160 new HttpNetworkTransaction(CreateSession(&session_deps))); | 160 new HttpNetworkTransaction(CreateSession(&session_deps))); |
161 | 161 |
162 StaticSocketDataProvider data(data_reads, reads_count, NULL, 0); | 162 for (size_t i = 0; i < data_count; ++i) { |
163 session_deps.socket_factory.AddSocketDataProvider(&data); | 163 session_deps.socket_factory.AddSocketDataProvider(data[i]); |
| 164 } |
164 | 165 |
165 TestOldCompletionCallback callback; | 166 TestOldCompletionCallback callback; |
166 | 167 |
167 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 168 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
168 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); | 169 EXPECT_TRUE(log.bound().IsLoggingAllEvents()); |
169 int rv = trans->Start(&request, &callback, log.bound()); | 170 int rv = trans->Start(&request, &callback, log.bound()); |
170 EXPECT_EQ(ERR_IO_PENDING, rv); | 171 EXPECT_EQ(ERR_IO_PENDING, rv); |
171 | 172 |
172 out.rv = callback.WaitForResult(); | 173 out.rv = callback.WaitForResult(); |
173 if (out.rv != OK) | 174 if (out.rv != OK) |
(...skipping 28 matching lines...) Expand all Loading... |
202 NetLogHttpRequestParameter* request_params = | 203 NetLogHttpRequestParameter* request_params = |
203 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get()); | 204 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get()); |
204 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine()); | 205 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine()); |
205 EXPECT_EQ("Host: www.google.com\r\n" | 206 EXPECT_EQ("Host: www.google.com\r\n" |
206 "Connection: keep-alive\r\n\r\n", | 207 "Connection: keep-alive\r\n\r\n", |
207 request_params->GetHeaders().ToString()); | 208 request_params->GetHeaders().ToString()); |
208 | 209 |
209 return out; | 210 return out; |
210 } | 211 } |
211 | 212 |
| 213 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 214 size_t reads_count) { |
| 215 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); |
| 216 StaticSocketDataProvider* data[] = { &reads }; |
| 217 return SimpleGetHelperForData(data, 1); |
| 218 } |
| 219 |
212 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 220 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
213 int expected_status); | 221 int expected_status); |
214 | 222 |
215 void ConnectStatusHelper(const MockRead& status); | 223 void ConnectStatusHelper(const MockRead& status); |
216 }; | 224 }; |
217 | 225 |
218 // Fill |str| with a long header list that consumes >= |size| bytes. | 226 // Fill |str| with a long header list that consumes >= |size| bytes. |
219 void FillLargeHeadersString(std::string* str, int size) { | 227 void FillLargeHeadersString(std::string* str, int size) { |
220 const char* row = | 228 const char* row = |
221 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; | 229 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
(...skipping 8991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9213 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9221 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
9214 EXPECT_TRUE(response->was_fetched_via_spdy); | 9222 EXPECT_TRUE(response->was_fetched_via_spdy); |
9215 EXPECT_TRUE(response->was_npn_negotiated); | 9223 EXPECT_TRUE(response->was_npn_negotiated); |
9216 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 9224 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
9217 EXPECT_EQ("hello!", response_data); | 9225 EXPECT_EQ("hello!", response_data); |
9218 | 9226 |
9219 HttpStreamFactory::set_next_protos(""); | 9227 HttpStreamFactory::set_next_protos(""); |
9220 HttpStreamFactory::set_use_alternate_protocols(false); | 9228 HttpStreamFactory::set_use_alternate_protocols(false); |
9221 } | 9229 } |
9222 | 9230 |
| 9231 TEST_F(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) { |
| 9232 MockRead data_reads1[] = { |
| 9233 MockRead(false, ERR_PIPELINE_EVICTION), |
| 9234 }; |
| 9235 MockRead data_reads2[] = { |
| 9236 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9237 MockRead("hello world"), |
| 9238 MockRead(false, OK), |
| 9239 }; |
| 9240 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), NULL, 0); |
| 9241 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), NULL, 0); |
| 9242 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 9243 |
| 9244 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 9245 |
| 9246 EXPECT_EQ(OK, out.rv); |
| 9247 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 9248 EXPECT_EQ("hello world", out.response_data); |
| 9249 } |
| 9250 |
| 9251 TEST_F(HttpNetworkTransactionTest, SendPipelineEvictionFallback) { |
| 9252 MockWrite data_writes1[] = { |
| 9253 MockWrite(false, ERR_PIPELINE_EVICTION), |
| 9254 }; |
| 9255 MockWrite data_writes2[] = { |
| 9256 MockWrite("GET / HTTP/1.1\r\n" |
| 9257 "Host: www.google.com\r\n" |
| 9258 "Connection: keep-alive\r\n\r\n"), |
| 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(NULL, 0, |
| 9266 data_writes1, arraysize(data_writes1)); |
| 9267 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9268 data_writes2, arraysize(data_writes2)); |
| 9269 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
| 9270 |
| 9271 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
| 9272 |
| 9273 EXPECT_EQ(OK, out.rv); |
| 9274 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 9275 EXPECT_EQ("hello world", out.response_data); |
| 9276 } |
| 9277 |
9223 } // namespace net | 9278 } // namespace net |
OLD | NEW |