OLD | NEW |
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/url_request/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "net/base/request_priority.h" | 10 #include "net/base/request_priority.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 using URLRequestFtpJob::Start; | 104 using URLRequestFtpJob::Start; |
105 using URLRequestFtpJob::Kill; | 105 using URLRequestFtpJob::Kill; |
106 using URLRequestFtpJob::priority; | 106 using URLRequestFtpJob::priority; |
107 | 107 |
108 protected: | 108 protected: |
109 virtual ~TestURLRequestFtpJob() {} | 109 virtual ~TestURLRequestFtpJob() {} |
110 }; | 110 }; |
111 | 111 |
112 class MockFtpTransactionFactory : public FtpTransactionFactory { | 112 class MockFtpTransactionFactory : public FtpTransactionFactory { |
113 public: | 113 public: |
114 virtual FtpTransaction* CreateTransaction() OVERRIDE { | 114 virtual FtpTransaction* CreateTransaction() OVERRIDE { return NULL; } |
115 return NULL; | |
116 } | |
117 | 115 |
118 virtual void Suspend(bool suspend) OVERRIDE {} | 116 virtual void Suspend(bool suspend) OVERRIDE {} |
119 }; | 117 }; |
120 | 118 |
121 // Fixture for priority-related tests. Priority matters when there is | 119 // Fixture for priority-related tests. Priority matters when there is |
122 // an HTTP proxy. | 120 // an HTTP proxy. |
123 class URLRequestFtpJobPriorityTest : public testing::Test { | 121 class URLRequestFtpJobPriorityTest : public testing::Test { |
124 protected: | 122 protected: |
125 URLRequestFtpJobPriorityTest() | 123 URLRequestFtpJobPriorityTest() |
126 : proxy_service_(new SimpleProxyConfigService, NULL, NULL), | 124 : proxy_service_(new SimpleProxyConfigService, NULL, NULL), |
(...skipping 10 matching lines...) Expand all Loading... |
137 MockFtpTransactionFactory ftp_factory_; | 135 MockFtpTransactionFactory ftp_factory_; |
138 FtpAuthCache ftp_auth_cache_; | 136 FtpAuthCache ftp_auth_cache_; |
139 TestURLRequestContext context_; | 137 TestURLRequestContext context_; |
140 TestDelegate delegate_; | 138 TestDelegate delegate_; |
141 TestURLRequest req_; | 139 TestURLRequest req_; |
142 }; | 140 }; |
143 | 141 |
144 // Make sure that SetPriority actually sets the URLRequestFtpJob's | 142 // Make sure that SetPriority actually sets the URLRequestFtpJob's |
145 // priority, both before and after start. | 143 // priority, both before and after start. |
146 TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) { | 144 TEST_F(URLRequestFtpJobPriorityTest, SetPriorityBasic) { |
147 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( | 145 scoped_refptr<TestURLRequestFtpJob> job( |
148 &req_, &ftp_factory_, &ftp_auth_cache_)); | 146 new TestURLRequestFtpJob(&req_, &ftp_factory_, &ftp_auth_cache_)); |
149 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 147 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
150 | 148 |
151 job->SetPriority(LOWEST); | 149 job->SetPriority(LOWEST); |
152 EXPECT_EQ(LOWEST, job->priority()); | 150 EXPECT_EQ(LOWEST, job->priority()); |
153 | 151 |
154 job->SetPriority(LOW); | 152 job->SetPriority(LOW); |
155 EXPECT_EQ(LOW, job->priority()); | 153 EXPECT_EQ(LOW, job->priority()); |
156 | 154 |
157 job->Start(); | 155 job->Start(); |
158 EXPECT_EQ(LOW, job->priority()); | 156 EXPECT_EQ(LOW, job->priority()); |
159 | 157 |
160 job->SetPriority(MEDIUM); | 158 job->SetPriority(MEDIUM); |
161 EXPECT_EQ(MEDIUM, job->priority()); | 159 EXPECT_EQ(MEDIUM, job->priority()); |
162 } | 160 } |
163 | 161 |
164 // Make sure that URLRequestFtpJob passes on its priority to its | 162 // Make sure that URLRequestFtpJob passes on its priority to its |
165 // transaction on start. | 163 // transaction on start. |
166 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) { | 164 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriorityOnStart) { |
167 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( | 165 scoped_refptr<TestURLRequestFtpJob> job( |
168 &req_, &ftp_factory_, &ftp_auth_cache_)); | 166 new TestURLRequestFtpJob(&req_, &ftp_factory_, &ftp_auth_cache_)); |
169 job->SetPriority(LOW); | 167 job->SetPriority(LOW); |
170 | 168 |
171 EXPECT_FALSE(network_layer_.last_transaction()); | 169 EXPECT_FALSE(network_layer_.last_transaction()); |
172 | 170 |
173 job->Start(); | 171 job->Start(); |
174 | 172 |
175 ASSERT_TRUE(network_layer_.last_transaction()); | 173 ASSERT_TRUE(network_layer_.last_transaction()); |
176 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 174 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
177 } | 175 } |
178 | 176 |
179 // Make sure that URLRequestFtpJob passes on its priority updates to | 177 // Make sure that URLRequestFtpJob passes on its priority updates to |
180 // its transaction. | 178 // its transaction. |
181 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) { | 179 TEST_F(URLRequestFtpJobPriorityTest, SetTransactionPriority) { |
182 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( | 180 scoped_refptr<TestURLRequestFtpJob> job( |
183 &req_, &ftp_factory_, &ftp_auth_cache_)); | 181 new TestURLRequestFtpJob(&req_, &ftp_factory_, &ftp_auth_cache_)); |
184 job->SetPriority(LOW); | 182 job->SetPriority(LOW); |
185 job->Start(); | 183 job->Start(); |
186 ASSERT_TRUE(network_layer_.last_transaction()); | 184 ASSERT_TRUE(network_layer_.last_transaction()); |
187 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 185 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
188 | 186 |
189 job->SetPriority(HIGHEST); | 187 job->SetPriority(HIGHEST); |
190 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); | 188 EXPECT_EQ(HIGHEST, network_layer_.last_transaction()->priority()); |
191 } | 189 } |
192 | 190 |
193 // Make sure that URLRequestFtpJob passes on its priority updates to | 191 // Make sure that URLRequestFtpJob passes on its priority updates to |
194 // newly-created transactions after the first one. | 192 // newly-created transactions after the first one. |
195 TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) { | 193 TEST_F(URLRequestFtpJobPriorityTest, SetSubsequentTransactionPriority) { |
196 scoped_refptr<TestURLRequestFtpJob> job(new TestURLRequestFtpJob( | 194 scoped_refptr<TestURLRequestFtpJob> job( |
197 &req_, &ftp_factory_, &ftp_auth_cache_)); | 195 new TestURLRequestFtpJob(&req_, &ftp_factory_, &ftp_auth_cache_)); |
198 job->Start(); | 196 job->Start(); |
199 | 197 |
200 job->SetPriority(LOW); | 198 job->SetPriority(LOW); |
201 ASSERT_TRUE(network_layer_.last_transaction()); | 199 ASSERT_TRUE(network_layer_.last_transaction()); |
202 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 200 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
203 | 201 |
204 job->Kill(); | 202 job->Kill(); |
205 network_layer_.ClearLastTransaction(); | 203 network_layer_.ClearLastTransaction(); |
206 | 204 |
207 // Creates a second transaction. | 205 // Creates a second transaction. |
208 job->Start(); | 206 job->Start(); |
209 ASSERT_TRUE(network_layer_.last_transaction()); | 207 ASSERT_TRUE(network_layer_.last_transaction()); |
210 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 208 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
211 } | 209 } |
212 | 210 |
213 class URLRequestFtpJobTest : public testing::Test { | 211 class URLRequestFtpJobTest : public testing::Test { |
214 public: | 212 public: |
215 URLRequestFtpJobTest() | 213 URLRequestFtpJobTest() |
216 : request_context_(&socket_factory_, | 214 : request_context_( |
217 new ProxyService( | 215 &socket_factory_, |
218 new SimpleProxyConfigService, NULL, NULL), | 216 new ProxyService(new SimpleProxyConfigService, NULL, NULL), |
219 &network_delegate_, | 217 &network_delegate_, |
220 &ftp_transaction_factory_) { | 218 &ftp_transaction_factory_) {} |
221 } | |
222 | 219 |
223 virtual ~URLRequestFtpJobTest() { | 220 virtual ~URLRequestFtpJobTest() { |
224 // Clean up any remaining tasks that mess up unrelated tests. | 221 // Clean up any remaining tasks that mess up unrelated tests. |
225 base::RunLoop run_loop; | 222 base::RunLoop run_loop; |
226 run_loop.RunUntilIdle(); | 223 run_loop.RunUntilIdle(); |
227 } | 224 } |
228 | 225 |
229 void AddSocket(MockRead* reads, size_t reads_size, | 226 void AddSocket(MockRead* reads, |
230 MockWrite* writes, size_t writes_size) { | 227 size_t reads_size, |
231 DeterministicSocketData* socket_data = new DeterministicSocketData( | 228 MockWrite* writes, |
232 reads, reads_size, writes, writes_size); | 229 size_t writes_size) { |
| 230 DeterministicSocketData* socket_data = |
| 231 new DeterministicSocketData(reads, reads_size, writes, writes_size); |
233 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 232 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
234 socket_data->StopAfter(reads_size + writes_size - 1); | 233 socket_data->StopAfter(reads_size + writes_size - 1); |
235 socket_factory_.AddSocketDataProvider(socket_data); | 234 socket_factory_.AddSocketDataProvider(socket_data); |
236 | 235 |
237 socket_data_.push_back(socket_data); | 236 socket_data_.push_back(socket_data); |
238 } | 237 } |
239 | 238 |
240 FtpTestURLRequestContext* request_context() { return &request_context_; } | 239 FtpTestURLRequestContext* request_context() { return &request_context_; } |
241 TestNetworkDelegate* network_delegate() { return &network_delegate_; } | 240 TestNetworkDelegate* network_delegate() { return &network_delegate_; } |
242 DeterministicSocketData* socket_data(size_t index) { | 241 DeterministicSocketData* socket_data(size_t index) { |
243 return socket_data_[index]; | 242 return socket_data_[index]; |
244 } | 243 } |
245 | 244 |
246 private: | 245 private: |
247 ScopedVector<DeterministicSocketData> socket_data_; | 246 ScopedVector<DeterministicSocketData> socket_data_; |
248 DeterministicMockClientSocketFactory socket_factory_; | 247 DeterministicMockClientSocketFactory socket_factory_; |
249 TestNetworkDelegate network_delegate_; | 248 TestNetworkDelegate network_delegate_; |
250 MockFtpTransactionFactory ftp_transaction_factory_; | 249 MockFtpTransactionFactory ftp_transaction_factory_; |
251 | 250 |
252 FtpTestURLRequestContext request_context_; | 251 FtpTestURLRequestContext request_context_; |
253 }; | 252 }; |
254 | 253 |
255 TEST_F(URLRequestFtpJobTest, FtpProxyRequest) { | 254 TEST_F(URLRequestFtpJobTest, FtpProxyRequest) { |
256 MockWrite writes[] = { | 255 MockWrite writes[] = { |
257 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 256 MockWrite(ASYNC, |
258 "Host: ftp.example.com\r\n" | 257 0, |
259 "Proxy-Connection: keep-alive\r\n\r\n"), | 258 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 259 "Host: ftp.example.com\r\n" |
| 260 "Proxy-Connection: keep-alive\r\n\r\n"), |
260 }; | 261 }; |
261 MockRead reads[] = { | 262 MockRead reads[] = { |
262 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 263 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
263 MockRead(ASYNC, 2, "Content-Length: 9\r\n\r\n"), | 264 MockRead(ASYNC, 2, "Content-Length: 9\r\n\r\n"), |
264 MockRead(ASYNC, 3, "test.html"), | 265 MockRead(ASYNC, 3, "test.html"), |
265 }; | 266 }; |
266 | 267 |
267 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 268 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
268 | 269 |
269 TestDelegate request_delegate; | 270 TestDelegate request_delegate; |
270 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 271 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
271 DEFAULT_PRIORITY, | 272 DEFAULT_PRIORITY, |
272 &request_delegate, | 273 &request_delegate, |
273 request_context()); | 274 request_context()); |
274 url_request.Start(); | 275 url_request.Start(); |
275 ASSERT_TRUE(url_request.is_pending()); | 276 ASSERT_TRUE(url_request.is_pending()); |
276 socket_data(0)->RunFor(4); | 277 socket_data(0)->RunFor(4); |
277 | 278 |
278 EXPECT_TRUE(url_request.status().is_success()); | 279 EXPECT_TRUE(url_request.status().is_success()); |
279 EXPECT_EQ(1, network_delegate()->completed_requests()); | 280 EXPECT_EQ(1, network_delegate()->completed_requests()); |
280 EXPECT_EQ(0, network_delegate()->error_count()); | 281 EXPECT_EQ(0, network_delegate()->error_count()); |
281 EXPECT_FALSE(request_delegate.auth_required_called()); | 282 EXPECT_FALSE(request_delegate.auth_required_called()); |
282 EXPECT_EQ("test.html", request_delegate.data_received()); | 283 EXPECT_EQ("test.html", request_delegate.data_received()); |
283 } | 284 } |
284 | 285 |
285 // Regression test for http://crbug.com/237526 . | 286 // Regression test for http://crbug.com/237526 . |
286 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { | 287 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { |
287 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. | 288 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. |
288 request_context()->set_proxy_service( | 289 request_context()->set_proxy_service(new ProxyService( |
289 new ProxyService( | 290 new ProxyConfigServiceFixed( |
290 new ProxyConfigServiceFixed( | 291 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo"))), |
291 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo"))), | 292 new MockAsyncProxyResolver, |
292 new MockAsyncProxyResolver, NULL)); | 293 NULL)); |
293 | 294 |
294 TestDelegate request_delegate; | 295 TestDelegate request_delegate; |
295 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 296 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
296 DEFAULT_PRIORITY, | 297 DEFAULT_PRIORITY, |
297 &request_delegate, | 298 &request_delegate, |
298 request_context()); | 299 request_context()); |
299 url_request.Start(); | 300 url_request.Start(); |
300 | 301 |
301 // Now |url_request| will be deleted before its completion, | 302 // Now |url_request| will be deleted before its completion, |
302 // resulting in it being orphaned. It should not crash. | 303 // resulting in it being orphaned. It should not crash. |
303 } | 304 } |
304 | 305 |
305 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthNoCredentials) { | 306 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthNoCredentials) { |
306 MockWrite writes[] = { | 307 MockWrite writes[] = { |
307 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 308 MockWrite(ASYNC, |
308 "Host: ftp.example.com\r\n" | 309 0, |
309 "Proxy-Connection: keep-alive\r\n\r\n"), | 310 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 311 "Host: ftp.example.com\r\n" |
| 312 "Proxy-Connection: keep-alive\r\n\r\n"), |
310 }; | 313 }; |
311 MockRead reads[] = { | 314 MockRead reads[] = { |
312 // No credentials. | 315 // No credentials. |
313 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | 316 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), |
314 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " | 317 MockRead(ASYNC, |
315 "realm=\"MyRealm1\"\r\n"), | 318 2, |
316 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 319 "Proxy-Authenticate: Basic " |
317 MockRead(ASYNC, 4, "test.html"), | 320 "realm=\"MyRealm1\"\r\n"), |
| 321 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
| 322 MockRead(ASYNC, 4, "test.html"), |
318 }; | 323 }; |
319 | 324 |
320 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 325 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
321 | 326 |
322 TestDelegate request_delegate; | 327 TestDelegate request_delegate; |
323 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 328 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
324 DEFAULT_PRIORITY, | 329 DEFAULT_PRIORITY, |
325 &request_delegate, | 330 &request_delegate, |
326 request_context()); | 331 request_context()); |
327 url_request.Start(); | 332 url_request.Start(); |
328 ASSERT_TRUE(url_request.is_pending()); | 333 ASSERT_TRUE(url_request.is_pending()); |
329 socket_data(0)->RunFor(5); | 334 socket_data(0)->RunFor(5); |
330 | 335 |
331 EXPECT_TRUE(url_request.status().is_success()); | 336 EXPECT_TRUE(url_request.status().is_success()); |
332 EXPECT_EQ(1, network_delegate()->completed_requests()); | 337 EXPECT_EQ(1, network_delegate()->completed_requests()); |
333 EXPECT_EQ(0, network_delegate()->error_count()); | 338 EXPECT_EQ(0, network_delegate()->error_count()); |
334 EXPECT_TRUE(request_delegate.auth_required_called()); | 339 EXPECT_TRUE(request_delegate.auth_required_called()); |
335 EXPECT_EQ("test.html", request_delegate.data_received()); | 340 EXPECT_EQ("test.html", request_delegate.data_received()); |
336 } | 341 } |
337 | 342 |
338 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthWithCredentials) { | 343 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthWithCredentials) { |
339 MockWrite writes[] = { | 344 MockWrite writes[] = { |
340 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 345 MockWrite(ASYNC, |
341 "Host: ftp.example.com\r\n" | 346 0, |
342 "Proxy-Connection: keep-alive\r\n\r\n"), | 347 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
343 MockWrite(ASYNC, 5, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 348 "Host: ftp.example.com\r\n" |
344 "Host: ftp.example.com\r\n" | 349 "Proxy-Connection: keep-alive\r\n\r\n"), |
345 "Proxy-Connection: keep-alive\r\n" | 350 MockWrite(ASYNC, |
346 "Proxy-Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), | 351 5, |
| 352 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 353 "Host: ftp.example.com\r\n" |
| 354 "Proxy-Connection: keep-alive\r\n" |
| 355 "Proxy-Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), |
347 }; | 356 }; |
348 MockRead reads[] = { | 357 MockRead reads[] = { |
349 // No credentials. | 358 // No credentials. |
350 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | 359 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), |
351 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " | 360 MockRead(ASYNC, |
352 "realm=\"MyRealm1\"\r\n"), | 361 2, |
353 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 362 "Proxy-Authenticate: Basic " |
354 MockRead(ASYNC, 4, "test.html"), | 363 "realm=\"MyRealm1\"\r\n"), |
| 364 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
| 365 MockRead(ASYNC, 4, "test.html"), |
355 | 366 |
356 // Second response. | 367 // Second response. |
357 MockRead(ASYNC, 6, "HTTP/1.1 200 OK\r\n"), | 368 MockRead(ASYNC, 6, "HTTP/1.1 200 OK\r\n"), |
358 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), | 369 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), |
359 MockRead(ASYNC, 8, "test2.html"), | 370 MockRead(ASYNC, 8, "test2.html"), |
360 }; | 371 }; |
361 | 372 |
362 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 373 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
363 | 374 |
364 TestDelegate request_delegate; | 375 TestDelegate request_delegate; |
365 request_delegate.set_credentials( | 376 request_delegate.set_credentials( |
366 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 377 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
367 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 378 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
368 DEFAULT_PRIORITY, | 379 DEFAULT_PRIORITY, |
369 &request_delegate, | 380 &request_delegate, |
370 request_context()); | 381 request_context()); |
371 url_request.Start(); | 382 url_request.Start(); |
372 ASSERT_TRUE(url_request.is_pending()); | 383 ASSERT_TRUE(url_request.is_pending()); |
373 socket_data(0)->RunFor(9); | 384 socket_data(0)->RunFor(9); |
374 | 385 |
375 EXPECT_TRUE(url_request.status().is_success()); | 386 EXPECT_TRUE(url_request.status().is_success()); |
376 EXPECT_EQ(1, network_delegate()->completed_requests()); | 387 EXPECT_EQ(1, network_delegate()->completed_requests()); |
377 EXPECT_EQ(0, network_delegate()->error_count()); | 388 EXPECT_EQ(0, network_delegate()->error_count()); |
378 EXPECT_TRUE(request_delegate.auth_required_called()); | 389 EXPECT_TRUE(request_delegate.auth_required_called()); |
379 EXPECT_EQ("test2.html", request_delegate.data_received()); | 390 EXPECT_EQ("test2.html", request_delegate.data_received()); |
380 } | 391 } |
381 | 392 |
382 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthNoCredentials) { | 393 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthNoCredentials) { |
383 MockWrite writes[] = { | 394 MockWrite writes[] = { |
384 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 395 MockWrite(ASYNC, |
385 "Host: ftp.example.com\r\n" | 396 0, |
386 "Proxy-Connection: keep-alive\r\n\r\n"), | 397 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 398 "Host: ftp.example.com\r\n" |
| 399 "Proxy-Connection: keep-alive\r\n\r\n"), |
387 }; | 400 }; |
388 MockRead reads[] = { | 401 MockRead reads[] = {// No credentials. |
389 // No credentials. | 402 MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
390 MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), | 403 MockRead(ASYNC, |
391 MockRead(ASYNC, 2, "WWW-Authenticate: Basic " | 404 2, |
392 "realm=\"MyRealm1\"\r\n"), | 405 "WWW-Authenticate: Basic " |
393 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 406 "realm=\"MyRealm1\"\r\n"), |
394 MockRead(ASYNC, 4, "test.html"), | 407 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
| 408 MockRead(ASYNC, 4, "test.html"), |
395 }; | 409 }; |
396 | 410 |
397 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 411 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
398 | 412 |
399 TestDelegate request_delegate; | 413 TestDelegate request_delegate; |
400 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 414 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
401 DEFAULT_PRIORITY, | 415 DEFAULT_PRIORITY, |
402 &request_delegate, | 416 &request_delegate, |
403 request_context()); | 417 request_context()); |
404 url_request.Start(); | 418 url_request.Start(); |
405 ASSERT_TRUE(url_request.is_pending()); | 419 ASSERT_TRUE(url_request.is_pending()); |
406 socket_data(0)->RunFor(5); | 420 socket_data(0)->RunFor(5); |
407 | 421 |
408 EXPECT_TRUE(url_request.status().is_success()); | 422 EXPECT_TRUE(url_request.status().is_success()); |
409 EXPECT_EQ(1, network_delegate()->completed_requests()); | 423 EXPECT_EQ(1, network_delegate()->completed_requests()); |
410 EXPECT_EQ(0, network_delegate()->error_count()); | 424 EXPECT_EQ(0, network_delegate()->error_count()); |
411 EXPECT_TRUE(request_delegate.auth_required_called()); | 425 EXPECT_TRUE(request_delegate.auth_required_called()); |
412 EXPECT_EQ("test.html", request_delegate.data_received()); | 426 EXPECT_EQ("test.html", request_delegate.data_received()); |
413 } | 427 } |
414 | 428 |
415 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthWithCredentials) { | 429 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthWithCredentials) { |
416 MockWrite writes[] = { | 430 MockWrite writes[] = { |
417 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 431 MockWrite(ASYNC, |
418 "Host: ftp.example.com\r\n" | 432 0, |
419 "Proxy-Connection: keep-alive\r\n\r\n"), | 433 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
420 MockWrite(ASYNC, 5, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 434 "Host: ftp.example.com\r\n" |
421 "Host: ftp.example.com\r\n" | 435 "Proxy-Connection: keep-alive\r\n\r\n"), |
422 "Proxy-Connection: keep-alive\r\n" | 436 MockWrite(ASYNC, |
423 "Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), | 437 5, |
| 438 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 439 "Host: ftp.example.com\r\n" |
| 440 "Proxy-Connection: keep-alive\r\n" |
| 441 "Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), |
424 }; | 442 }; |
425 MockRead reads[] = { | 443 MockRead reads[] = {// No credentials. |
426 // No credentials. | 444 MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
427 MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), | 445 MockRead(ASYNC, |
428 MockRead(ASYNC, 2, "WWW-Authenticate: Basic " | 446 2, |
429 "realm=\"MyRealm1\"\r\n"), | 447 "WWW-Authenticate: Basic " |
430 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 448 "realm=\"MyRealm1\"\r\n"), |
431 MockRead(ASYNC, 4, "test.html"), | 449 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
| 450 MockRead(ASYNC, 4, "test.html"), |
432 | 451 |
433 // Second response. | 452 // Second response. |
434 MockRead(ASYNC, 6, "HTTP/1.1 200 OK\r\n"), | 453 MockRead(ASYNC, 6, "HTTP/1.1 200 OK\r\n"), |
435 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), | 454 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), |
436 MockRead(ASYNC, 8, "test2.html"), | 455 MockRead(ASYNC, 8, "test2.html"), |
437 }; | 456 }; |
438 | 457 |
439 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 458 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
440 | 459 |
441 TestDelegate request_delegate; | 460 TestDelegate request_delegate; |
442 request_delegate.set_credentials( | 461 request_delegate.set_credentials( |
443 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 462 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
444 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 463 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
445 DEFAULT_PRIORITY, | 464 DEFAULT_PRIORITY, |
446 &request_delegate, | 465 &request_delegate, |
447 request_context()); | 466 request_context()); |
448 url_request.Start(); | 467 url_request.Start(); |
449 ASSERT_TRUE(url_request.is_pending()); | 468 ASSERT_TRUE(url_request.is_pending()); |
450 socket_data(0)->RunFor(9); | 469 socket_data(0)->RunFor(9); |
451 | 470 |
452 EXPECT_TRUE(url_request.status().is_success()); | 471 EXPECT_TRUE(url_request.status().is_success()); |
453 EXPECT_EQ(1, network_delegate()->completed_requests()); | 472 EXPECT_EQ(1, network_delegate()->completed_requests()); |
454 EXPECT_EQ(0, network_delegate()->error_count()); | 473 EXPECT_EQ(0, network_delegate()->error_count()); |
455 EXPECT_TRUE(request_delegate.auth_required_called()); | 474 EXPECT_TRUE(request_delegate.auth_required_called()); |
456 EXPECT_EQ("test2.html", request_delegate.data_received()); | 475 EXPECT_EQ("test2.html", request_delegate.data_received()); |
457 } | 476 } |
458 | 477 |
459 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAndServerAuth) { | 478 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAndServerAuth) { |
460 MockWrite writes[] = { | 479 MockWrite writes[] = { |
461 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 480 MockWrite(ASYNC, |
462 "Host: ftp.example.com\r\n" | 481 0, |
463 "Proxy-Connection: keep-alive\r\n\r\n"), | 482 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
464 MockWrite(ASYNC, 5, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 483 "Host: ftp.example.com\r\n" |
465 "Host: ftp.example.com\r\n" | 484 "Proxy-Connection: keep-alive\r\n\r\n"), |
466 "Proxy-Connection: keep-alive\r\n" | 485 MockWrite(ASYNC, |
467 "Proxy-Authorization: Basic " | 486 5, |
468 "cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"), | 487 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
469 MockWrite(ASYNC, 10, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 488 "Host: ftp.example.com\r\n" |
470 "Host: ftp.example.com\r\n" | 489 "Proxy-Connection: keep-alive\r\n" |
471 "Proxy-Connection: keep-alive\r\n" | 490 "Proxy-Authorization: Basic " |
472 "Proxy-Authorization: Basic " | 491 "cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"), |
473 "cHJveHl1c2VyOnByb3h5cGFzcw==\r\n" | 492 MockWrite(ASYNC, |
474 "Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), | 493 10, |
| 494 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 495 "Host: ftp.example.com\r\n" |
| 496 "Proxy-Connection: keep-alive\r\n" |
| 497 "Proxy-Authorization: Basic " |
| 498 "cHJveHl1c2VyOnByb3h5cGFzcw==\r\n" |
| 499 "Authorization: Basic bXl1c2VyOm15cGFzcw==\r\n\r\n"), |
475 }; | 500 }; |
476 MockRead reads[] = { | 501 MockRead reads[] = { |
477 // No credentials. | 502 // No credentials. |
478 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | 503 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), |
479 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " | 504 MockRead(ASYNC, |
480 "realm=\"MyRealm1\"\r\n"), | 505 2, |
481 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 506 "Proxy-Authenticate: Basic " |
482 MockRead(ASYNC, 4, "test.html"), | 507 "realm=\"MyRealm1\"\r\n"), |
| 508 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
| 509 MockRead(ASYNC, 4, "test.html"), |
483 | 510 |
484 // Second response. | 511 // Second response. |
485 MockRead(ASYNC, 6, "HTTP/1.1 401 Unauthorized\r\n"), | 512 MockRead(ASYNC, 6, "HTTP/1.1 401 Unauthorized\r\n"), |
486 MockRead(ASYNC, 7, "WWW-Authenticate: Basic " | 513 MockRead(ASYNC, |
487 "realm=\"MyRealm1\"\r\n"), | 514 7, |
488 MockRead(ASYNC, 8, "Content-Length: 9\r\n\r\n"), | 515 "WWW-Authenticate: Basic " |
489 MockRead(ASYNC, 9, "test.html"), | 516 "realm=\"MyRealm1\"\r\n"), |
| 517 MockRead(ASYNC, 8, "Content-Length: 9\r\n\r\n"), |
| 518 MockRead(ASYNC, 9, "test.html"), |
490 | 519 |
491 // Third response. | 520 // Third response. |
492 MockRead(ASYNC, 11, "HTTP/1.1 200 OK\r\n"), | 521 MockRead(ASYNC, 11, "HTTP/1.1 200 OK\r\n"), |
493 MockRead(ASYNC, 12, "Content-Length: 10\r\n\r\n"), | 522 MockRead(ASYNC, 12, "Content-Length: 10\r\n\r\n"), |
494 MockRead(ASYNC, 13, "test2.html"), | 523 MockRead(ASYNC, 13, "test2.html"), |
495 }; | 524 }; |
496 | 525 |
497 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 526 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
498 | 527 |
499 GURL url("ftp://ftp.example.com"); | 528 GURL url("ftp://ftp.example.com"); |
500 | 529 |
501 // Make sure cached FTP credentials are not used for proxy authentication. | 530 // Make sure cached FTP credentials are not used for proxy authentication. |
502 request_context()->GetFtpAuthCache()->Add( | 531 request_context()->GetFtpAuthCache()->Add( |
503 url.GetOrigin(), | 532 url.GetOrigin(), |
504 AuthCredentials(ASCIIToUTF16("userdonotuse"), | 533 AuthCredentials(ASCIIToUTF16("userdonotuse"), |
(...skipping 14 matching lines...) Expand all Loading... |
519 | 548 |
520 EXPECT_TRUE(url_request.status().is_success()); | 549 EXPECT_TRUE(url_request.status().is_success()); |
521 EXPECT_EQ(1, network_delegate()->completed_requests()); | 550 EXPECT_EQ(1, network_delegate()->completed_requests()); |
522 EXPECT_EQ(0, network_delegate()->error_count()); | 551 EXPECT_EQ(0, network_delegate()->error_count()); |
523 EXPECT_TRUE(request_delegate.auth_required_called()); | 552 EXPECT_TRUE(request_delegate.auth_required_called()); |
524 EXPECT_EQ("test2.html", request_delegate.data_received()); | 553 EXPECT_EQ("test2.html", request_delegate.data_received()); |
525 } | 554 } |
526 | 555 |
527 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { | 556 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { |
528 MockWrite writes[] = { | 557 MockWrite writes[] = { |
529 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 558 MockWrite(ASYNC, |
530 "Host: ftp.example.com\r\n" | 559 0, |
531 "Proxy-Connection: keep-alive\r\n\r\n"), | 560 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 561 "Host: ftp.example.com\r\n" |
| 562 "Proxy-Connection: keep-alive\r\n\r\n"), |
532 }; | 563 }; |
533 MockRead reads[] = { | 564 MockRead reads[] = { |
534 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 565 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
535 MockRead(ASYNC, 2, "Content-Length: 9\r\n"), | 566 MockRead(ASYNC, 2, "Content-Length: 9\r\n"), |
536 MockRead(ASYNC, 3, "Set-Cookie: name=value\r\n\r\n"), | 567 MockRead(ASYNC, 3, "Set-Cookie: name=value\r\n\r\n"), |
537 MockRead(ASYNC, 4, "test.html"), | 568 MockRead(ASYNC, 4, "test.html"), |
538 }; | 569 }; |
539 | 570 |
540 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 571 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
541 | 572 |
542 TestDelegate request_delegate; | 573 TestDelegate request_delegate; |
543 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 574 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
544 DEFAULT_PRIORITY, | 575 DEFAULT_PRIORITY, |
545 &request_delegate, | 576 &request_delegate, |
546 request_context()); | 577 request_context()); |
547 url_request.Start(); | 578 url_request.Start(); |
548 ASSERT_TRUE(url_request.is_pending()); | 579 ASSERT_TRUE(url_request.is_pending()); |
549 | 580 |
550 socket_data(0)->RunFor(5); | 581 socket_data(0)->RunFor(5); |
551 | 582 |
552 EXPECT_TRUE(url_request.status().is_success()); | 583 EXPECT_TRUE(url_request.status().is_success()); |
553 EXPECT_EQ(1, network_delegate()->completed_requests()); | 584 EXPECT_EQ(1, network_delegate()->completed_requests()); |
554 EXPECT_EQ(0, network_delegate()->error_count()); | 585 EXPECT_EQ(0, network_delegate()->error_count()); |
555 | 586 |
556 // Make sure we do not accept cookies. | 587 // Make sure we do not accept cookies. |
557 EXPECT_EQ(0, network_delegate()->set_cookie_count()); | 588 EXPECT_EQ(0, network_delegate()->set_cookie_count()); |
558 | 589 |
559 EXPECT_FALSE(request_delegate.auth_required_called()); | 590 EXPECT_FALSE(request_delegate.auth_required_called()); |
560 EXPECT_EQ("test.html", request_delegate.data_received()); | 591 EXPECT_EQ("test.html", request_delegate.data_received()); |
561 } | 592 } |
562 | 593 |
563 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotFollowRedirects) { | 594 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotFollowRedirects) { |
564 MockWrite writes[] = { | 595 MockWrite writes[] = { |
565 MockWrite(SYNCHRONOUS, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 596 MockWrite(SYNCHRONOUS, |
566 "Host: ftp.example.com\r\n" | 597 0, |
567 "Proxy-Connection: keep-alive\r\n\r\n"), | 598 "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
| 599 "Host: ftp.example.com\r\n" |
| 600 "Proxy-Connection: keep-alive\r\n\r\n"), |
568 }; | 601 }; |
569 MockRead reads[] = { | 602 MockRead reads[] = { |
570 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 302 Found\r\n"), | 603 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 302 Found\r\n"), |
571 MockRead(ASYNC, 2, "Location: http://other.example.com/\r\n\r\n"), | 604 MockRead(ASYNC, 2, "Location: http://other.example.com/\r\n\r\n"), |
572 }; | 605 }; |
573 | 606 |
574 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 607 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
575 | 608 |
576 TestDelegate request_delegate; | 609 TestDelegate request_delegate; |
577 URLRequest url_request(GURL("ftp://ftp.example.com/"), | 610 URLRequest url_request(GURL("ftp://ftp.example.com/"), |
578 DEFAULT_PRIORITY, | 611 DEFAULT_PRIORITY, |
579 &request_delegate, | 612 &request_delegate, |
580 request_context()); | 613 request_context()); |
581 url_request.Start(); | 614 url_request.Start(); |
(...skipping 10 matching lines...) Expand all Loading... |
592 | 625 |
593 EXPECT_EQ(1, network_delegate()->completed_requests()); | 626 EXPECT_EQ(1, network_delegate()->completed_requests()); |
594 EXPECT_EQ(1, network_delegate()->error_count()); | 627 EXPECT_EQ(1, network_delegate()->error_count()); |
595 EXPECT_FALSE(url_request.status().is_success()); | 628 EXPECT_FALSE(url_request.status().is_success()); |
596 EXPECT_EQ(ERR_UNSAFE_REDIRECT, url_request.status().error()); | 629 EXPECT_EQ(ERR_UNSAFE_REDIRECT, url_request.status().error()); |
597 } | 630 } |
598 | 631 |
599 // We should re-use socket for requests using the same scheme, host, and port. | 632 // We should re-use socket for requests using the same scheme, host, and port. |
600 TEST_F(URLRequestFtpJobTest, FtpProxyRequestReuseSocket) { | 633 TEST_F(URLRequestFtpJobTest, FtpProxyRequestReuseSocket) { |
601 MockWrite writes[] = { | 634 MockWrite writes[] = { |
602 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/first HTTP/1.1\r\n" | 635 MockWrite(ASYNC, |
603 "Host: ftp.example.com\r\n" | 636 0, |
604 "Proxy-Connection: keep-alive\r\n\r\n"), | 637 "GET ftp://ftp.example.com/first HTTP/1.1\r\n" |
605 MockWrite(ASYNC, 4, "GET ftp://ftp.example.com/second HTTP/1.1\r\n" | 638 "Host: ftp.example.com\r\n" |
606 "Host: ftp.example.com\r\n" | 639 "Proxy-Connection: keep-alive\r\n\r\n"), |
607 "Proxy-Connection: keep-alive\r\n\r\n"), | 640 MockWrite(ASYNC, |
| 641 4, |
| 642 "GET ftp://ftp.example.com/second HTTP/1.1\r\n" |
| 643 "Host: ftp.example.com\r\n" |
| 644 "Proxy-Connection: keep-alive\r\n\r\n"), |
608 }; | 645 }; |
609 MockRead reads[] = { | 646 MockRead reads[] = { |
610 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 647 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
611 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), | 648 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), |
612 MockRead(ASYNC, 3, "test1.html"), | 649 MockRead(ASYNC, 3, "test1.html"), |
613 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), | 650 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), |
614 MockRead(ASYNC, 6, "Content-Length: 10\r\n\r\n"), | 651 MockRead(ASYNC, 6, "Content-Length: 10\r\n\r\n"), |
615 MockRead(ASYNC, 7, "test2.html"), | 652 MockRead(ASYNC, 7, "test2.html"), |
616 }; | 653 }; |
617 | 654 |
618 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 655 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
619 | 656 |
620 TestDelegate request_delegate1; | 657 TestDelegate request_delegate1; |
621 URLRequest url_request1(GURL("ftp://ftp.example.com/first"), | 658 URLRequest url_request1(GURL("ftp://ftp.example.com/first"), |
622 DEFAULT_PRIORITY, | 659 DEFAULT_PRIORITY, |
623 &request_delegate1, | 660 &request_delegate1, |
624 request_context()); | 661 request_context()); |
625 url_request1.Start(); | 662 url_request1.Start(); |
(...skipping 19 matching lines...) Expand all Loading... |
645 EXPECT_EQ(2, network_delegate()->completed_requests()); | 682 EXPECT_EQ(2, network_delegate()->completed_requests()); |
646 EXPECT_EQ(0, network_delegate()->error_count()); | 683 EXPECT_EQ(0, network_delegate()->error_count()); |
647 EXPECT_FALSE(request_delegate2.auth_required_called()); | 684 EXPECT_FALSE(request_delegate2.auth_required_called()); |
648 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 685 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
649 } | 686 } |
650 | 687 |
651 // We should not re-use socket when there are two requests to the same host, | 688 // We should not re-use socket when there are two requests to the same host, |
652 // but one is FTP and the other is HTTP. | 689 // but one is FTP and the other is HTTP. |
653 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotReuseSocket) { | 690 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotReuseSocket) { |
654 MockWrite writes1[] = { | 691 MockWrite writes1[] = { |
655 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/first HTTP/1.1\r\n" | 692 MockWrite(ASYNC, |
656 "Host: ftp.example.com\r\n" | 693 0, |
657 "Proxy-Connection: keep-alive\r\n\r\n"), | 694 "GET ftp://ftp.example.com/first HTTP/1.1\r\n" |
| 695 "Host: ftp.example.com\r\n" |
| 696 "Proxy-Connection: keep-alive\r\n\r\n"), |
658 }; | 697 }; |
659 MockWrite writes2[] = { | 698 MockWrite writes2[] = { |
660 MockWrite(ASYNC, 0, "GET /second HTTP/1.1\r\n" | 699 MockWrite(ASYNC, |
661 "Host: ftp.example.com\r\n" | 700 0, |
662 "Connection: keep-alive\r\n" | 701 "GET /second HTTP/1.1\r\n" |
663 "User-Agent:\r\n" | 702 "Host: ftp.example.com\r\n" |
664 "Accept-Encoding: gzip,deflate\r\n" | 703 "Connection: keep-alive\r\n" |
665 "Accept-Language: en-us,fr\r\n\r\n"), | 704 "User-Agent:\r\n" |
| 705 "Accept-Encoding: gzip,deflate\r\n" |
| 706 "Accept-Language: en-us,fr\r\n\r\n"), |
666 }; | 707 }; |
667 MockRead reads1[] = { | 708 MockRead reads1[] = { |
668 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 709 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
669 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), | 710 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), |
670 MockRead(ASYNC, 3, "test1.html"), | 711 MockRead(ASYNC, 3, "test1.html"), |
671 }; | 712 }; |
672 MockRead reads2[] = { | 713 MockRead reads2[] = { |
673 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 714 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
674 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), | 715 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), |
675 MockRead(ASYNC, 3, "test2.html"), | 716 MockRead(ASYNC, 3, "test2.html"), |
676 }; | 717 }; |
677 | 718 |
678 AddSocket(reads1, arraysize(reads1), writes1, arraysize(writes1)); | 719 AddSocket(reads1, arraysize(reads1), writes1, arraysize(writes1)); |
679 AddSocket(reads2, arraysize(reads2), writes2, arraysize(writes2)); | 720 AddSocket(reads2, arraysize(reads2), writes2, arraysize(writes2)); |
680 | 721 |
681 TestDelegate request_delegate1; | 722 TestDelegate request_delegate1; |
682 URLRequest url_request1(GURL("ftp://ftp.example.com/first"), | 723 URLRequest url_request1(GURL("ftp://ftp.example.com/first"), |
683 DEFAULT_PRIORITY, | 724 DEFAULT_PRIORITY, |
684 &request_delegate1, | 725 &request_delegate1, |
685 request_context()); | 726 request_context()); |
(...skipping 19 matching lines...) Expand all Loading... |
705 EXPECT_TRUE(url_request2.status().is_success()); | 746 EXPECT_TRUE(url_request2.status().is_success()); |
706 EXPECT_EQ(2, network_delegate()->completed_requests()); | 747 EXPECT_EQ(2, network_delegate()->completed_requests()); |
707 EXPECT_EQ(0, network_delegate()->error_count()); | 748 EXPECT_EQ(0, network_delegate()->error_count()); |
708 EXPECT_FALSE(request_delegate2.auth_required_called()); | 749 EXPECT_FALSE(request_delegate2.auth_required_called()); |
709 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 750 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
710 } | 751 } |
711 | 752 |
712 } // namespace | 753 } // namespace |
713 | 754 |
714 } // namespace net | 755 } // namespace net |
OLD | NEW |