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_fetcher_impl.h" | 5 #include "net/url_request/url_fetcher_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 URLRequestThrottlerManager throttler_manager_; | 56 URLRequestThrottlerManager throttler_manager_; |
57 }; | 57 }; |
58 | 58 |
59 class ThrottlingTestURLRequestContextGetter | 59 class ThrottlingTestURLRequestContextGetter |
60 : public TestURLRequestContextGetter { | 60 : public TestURLRequestContextGetter { |
61 public: | 61 public: |
62 ThrottlingTestURLRequestContextGetter( | 62 ThrottlingTestURLRequestContextGetter( |
63 base::MessageLoopProxy* io_message_loop_proxy, | 63 base::MessageLoopProxy* io_message_loop_proxy, |
64 TestURLRequestContext* request_context) | 64 TestURLRequestContext* request_context) |
65 : TestURLRequestContextGetter(io_message_loop_proxy), | 65 : TestURLRequestContextGetter(io_message_loop_proxy), |
66 context_(request_context) { | 66 context_(request_context) {} |
67 } | |
68 | 67 |
69 // TestURLRequestContextGetter: | 68 // TestURLRequestContextGetter: |
70 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { | 69 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { |
71 return context_; | 70 return context_; |
72 } | 71 } |
73 | 72 |
74 protected: | 73 protected: |
75 virtual ~ThrottlingTestURLRequestContextGetter() {} | 74 virtual ~ThrottlingTestURLRequestContextGetter() {} |
76 | 75 |
77 TestURLRequestContext* const context_; | 76 TestURLRequestContext* const context_; |
78 }; | 77 }; |
79 | 78 |
80 } // namespace | 79 } // namespace |
81 | 80 |
82 class URLFetcherTest : public testing::Test, | 81 class URLFetcherTest : public testing::Test, public URLFetcherDelegate { |
83 public URLFetcherDelegate { | |
84 public: | 82 public: |
85 URLFetcherTest() : fetcher_(NULL) {} | 83 URLFetcherTest() : fetcher_(NULL) {} |
86 | 84 |
87 static int GetNumFetcherCores() { | 85 static int GetNumFetcherCores() { |
88 return URLFetcherImpl::GetNumFetcherCores(); | 86 return URLFetcherImpl::GetNumFetcherCores(); |
89 } | 87 } |
90 | 88 |
91 // Creates a URLFetcher, using the program's main thread to do IO. | 89 // Creates a URLFetcher, using the program's main thread to do IO. |
92 virtual void CreateFetcher(const GURL& url); | 90 virtual void CreateFetcher(const GURL& url); |
93 | 91 |
94 // URLFetcherDelegate: | 92 // URLFetcherDelegate: |
95 // Subclasses that override this should either call this function or | 93 // Subclasses that override this should either call this function or |
96 // CleanupAfterFetchComplete() at the end of their processing, depending on | 94 // CleanupAfterFetchComplete() at the end of their processing, depending on |
97 // whether they want to check for a non-empty HTTP 200 response or not. | 95 // whether they want to check for a non-empty HTTP 200 response or not. |
98 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 96 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
99 | 97 |
100 // Deletes |fetcher| and terminates the message loop. | 98 // Deletes |fetcher| and terminates the message loop. |
101 void CleanupAfterFetchComplete(); | 99 void CleanupAfterFetchComplete(); |
102 | 100 |
103 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { | 101 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy() { |
104 return io_message_loop_proxy_; | 102 return io_message_loop_proxy_; |
105 } | 103 } |
106 | 104 |
107 TestURLRequestContext* request_context() { | 105 TestURLRequestContext* request_context() { return context_.get(); } |
108 return context_.get(); | |
109 } | |
110 | 106 |
111 protected: | 107 protected: |
112 // testing::Test: | 108 // testing::Test: |
113 virtual void SetUp() OVERRIDE { | 109 virtual void SetUp() OVERRIDE { |
114 testing::Test::SetUp(); | 110 testing::Test::SetUp(); |
115 | 111 |
116 context_.reset(new ThrottlingTestURLRequestContext()); | 112 context_.reset(new ThrottlingTestURLRequestContext()); |
117 io_message_loop_proxy_ = base::MessageLoopProxy::current(); | 113 io_message_loop_proxy_ = base::MessageLoopProxy::current(); |
118 | 114 |
119 #if defined(USE_NSS) || defined(OS_IOS) | 115 #if defined(USE_NSS) || defined(OS_IOS) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 context_->Init(); | 194 context_->Init(); |
199 | 195 |
200 test_server_.reset(new SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | 196 test_server_.reset(new SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, |
201 SpawnedTestServer::kLocalhost, | 197 SpawnedTestServer::kLocalhost, |
202 base::FilePath(kDocRoot))); | 198 base::FilePath(kDocRoot))); |
203 ASSERT_TRUE(test_server_->Start()); | 199 ASSERT_TRUE(test_server_->Start()); |
204 | 200 |
205 // test_server_.GetURL() returns a URL with 127.0.0.1 (kLocalhost), that is | 201 // test_server_.GetURL() returns a URL with 127.0.0.1 (kLocalhost), that is |
206 // immediately resolved by the MockHostResolver. Use a hostname instead to | 202 // immediately resolved by the MockHostResolver. Use a hostname instead to |
207 // trigger an async resolve. | 203 // trigger an async resolve. |
208 test_url_ = GURL( | 204 test_url_ = GURL(base::StringPrintf("http://example.com:%d/defaultresponse", |
209 base::StringPrintf("http://example.com:%d/defaultresponse", | 205 test_server_->host_port_pair().port())); |
210 test_server_->host_port_pair().port())); | |
211 ASSERT_TRUE(test_url_.is_valid()); | 206 ASSERT_TRUE(test_url_.is_valid()); |
212 } | 207 } |
213 | 208 |
214 void URLFetcherMockDnsTest::CreateFetcher(const GURL& url) { | 209 void URLFetcherMockDnsTest::CreateFetcher(const GURL& url) { |
215 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 210 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
216 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 211 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
217 io_message_loop_proxy().get(), request_context())); | 212 io_message_loop_proxy().get(), request_context())); |
218 } | 213 } |
219 | 214 |
220 void URLFetcherMockDnsTest::OnURLFetchComplete(const URLFetcher* source) { | 215 void URLFetcherMockDnsTest::OnURLFetchComplete(const URLFetcher* source) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 262 virtual void CreateFetcher(const GURL& url) OVERRIDE; |
268 | 263 |
269 // URLFetcherDelegate: | 264 // URLFetcherDelegate: |
270 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 265 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
271 }; | 266 }; |
272 | 267 |
273 // Version of URLFetcherTest that tests download progress reports. | 268 // Version of URLFetcherTest that tests download progress reports. |
274 class URLFetcherDownloadProgressTest : public URLFetcherTest { | 269 class URLFetcherDownloadProgressTest : public URLFetcherTest { |
275 public: | 270 public: |
276 URLFetcherDownloadProgressTest() | 271 URLFetcherDownloadProgressTest() |
277 : previous_progress_(0), | 272 : previous_progress_(0), expected_total_(0) {} |
278 expected_total_(0) { | |
279 } | |
280 | 273 |
281 // URLFetcherTest: | 274 // URLFetcherTest: |
282 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 275 virtual void CreateFetcher(const GURL& url) OVERRIDE; |
283 | 276 |
284 // URLFetcherDelegate: | 277 // URLFetcherDelegate: |
285 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, | 278 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, |
286 int64 current, | 279 int64 current, |
287 int64 total) OVERRIDE; | 280 int64 total) OVERRIDE; |
288 | 281 |
289 protected: | 282 protected: |
290 // Download progress returned by the previous callback. | 283 // Download progress returned by the previous callback. |
291 int64 previous_progress_; | 284 int64 previous_progress_; |
292 // Size of the file being downloaded, known in advance (provided by each test | 285 // Size of the file being downloaded, known in advance (provided by each test |
293 // case). | 286 // case). |
294 int64 expected_total_; | 287 int64 expected_total_; |
295 }; | 288 }; |
296 | 289 |
297 // Version of URLFetcherTest that tests progress reports at cancellation. | 290 // Version of URLFetcherTest that tests progress reports at cancellation. |
298 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { | 291 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { |
299 public: | 292 public: |
300 // URLFetcherTest: | 293 // URLFetcherTest: |
301 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 294 virtual void CreateFetcher(const GURL& url) OVERRIDE; |
302 | 295 |
303 // URLFetcherDelegate: | 296 // URLFetcherDelegate: |
304 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 297 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
305 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, | 298 virtual void OnURLFetchDownloadProgress(const URLFetcher* source, |
306 int64 current, | 299 int64 current, |
307 int64 total) OVERRIDE; | 300 int64 total) OVERRIDE; |
| 301 |
308 protected: | 302 protected: |
309 bool cancelled_; | 303 bool cancelled_; |
310 }; | 304 }; |
311 | 305 |
312 // Version of URLFetcherTest that tests upload progress reports. | 306 // Version of URLFetcherTest that tests upload progress reports. |
313 class URLFetcherUploadProgressTest : public URLFetcherTest { | 307 class URLFetcherUploadProgressTest : public URLFetcherTest { |
314 public: | 308 public: |
315 // URLFetcherTest: | 309 // URLFetcherTest: |
316 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 310 virtual void CreateFetcher(const GURL& url) OVERRIDE; |
317 | 311 |
318 // URLFetcherDelegate: | 312 // URLFetcherDelegate: |
319 virtual void OnURLFetchUploadProgress(const URLFetcher* source, | 313 virtual void OnURLFetchUploadProgress(const URLFetcher* source, |
320 int64 current, | 314 int64 current, |
321 int64 total) OVERRIDE; | 315 int64 total) OVERRIDE; |
| 316 |
322 protected: | 317 protected: |
323 int64 previous_progress_; | 318 int64 previous_progress_; |
324 std::string chunk_; | 319 std::string chunk_; |
325 int64 number_of_chunks_added_; | 320 int64 number_of_chunks_added_; |
326 }; | 321 }; |
327 | 322 |
328 // Version of URLFetcherTest that tests headers. | 323 // Version of URLFetcherTest that tests headers. |
329 class URLFetcherHeadersTest : public URLFetcherTest { | 324 class URLFetcherHeadersTest : public URLFetcherTest { |
330 public: | 325 public: |
331 // URLFetcherDelegate: | 326 // URLFetcherDelegate: |
332 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 327 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
333 }; | 328 }; |
334 | 329 |
335 // Version of URLFetcherTest that tests SocketAddress. | 330 // Version of URLFetcherTest that tests SocketAddress. |
336 class URLFetcherSocketAddressTest : public URLFetcherTest { | 331 class URLFetcherSocketAddressTest : public URLFetcherTest { |
337 public: | 332 public: |
338 // URLFetcherDelegate: | 333 // URLFetcherDelegate: |
339 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 334 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 335 |
340 protected: | 336 protected: |
341 std::string expected_host_; | 337 std::string expected_host_; |
342 uint16 expected_port_; | 338 uint16 expected_port_; |
343 }; | 339 }; |
344 | 340 |
345 // Version of URLFetcherTest that tests stopping on a redirect. | 341 // Version of URLFetcherTest that tests stopping on a redirect. |
346 class URLFetcherStopOnRedirectTest : public URLFetcherTest { | 342 class URLFetcherStopOnRedirectTest : public URLFetcherTest { |
347 public: | 343 public: |
348 URLFetcherStopOnRedirectTest(); | 344 URLFetcherStopOnRedirectTest(); |
349 virtual ~URLFetcherStopOnRedirectTest(); | 345 virtual ~URLFetcherStopOnRedirectTest(); |
(...skipping 12 matching lines...) Expand all Loading... |
362 }; | 358 }; |
363 | 359 |
364 // Version of URLFetcherTest that tests overload protection. | 360 // Version of URLFetcherTest that tests overload protection. |
365 class URLFetcherProtectTest : public URLFetcherTest { | 361 class URLFetcherProtectTest : public URLFetcherTest { |
366 public: | 362 public: |
367 // URLFetcherTest: | 363 // URLFetcherTest: |
368 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 364 virtual void CreateFetcher(const GURL& url) OVERRIDE; |
369 | 365 |
370 // URLFetcherDelegate: | 366 // URLFetcherDelegate: |
371 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 367 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 368 |
372 private: | 369 private: |
373 Time start_time_; | 370 Time start_time_; |
374 }; | 371 }; |
375 | 372 |
376 // Version of URLFetcherTest that tests overload protection, when responses | 373 // Version of URLFetcherTest that tests overload protection, when responses |
377 // passed through. | 374 // passed through. |
378 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { | 375 class URLFetcherProtectTestPassedThrough : public URLFetcherTest { |
379 public: | 376 public: |
380 // URLFetcherTest: | 377 // URLFetcherTest: |
381 virtual void CreateFetcher(const GURL& url) OVERRIDE; | 378 virtual void CreateFetcher(const GURL& url) OVERRIDE; |
382 | 379 |
383 // URLFetcherDelegate: | 380 // URLFetcherDelegate: |
384 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 381 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 382 |
385 private: | 383 private: |
386 Time start_time_; | 384 Time start_time_; |
387 }; | 385 }; |
388 | 386 |
389 // Version of URLFetcherTest that tests bad HTTPS requests. | 387 // Version of URLFetcherTest that tests bad HTTPS requests. |
390 class URLFetcherBadHTTPSTest : public URLFetcherTest { | 388 class URLFetcherBadHTTPSTest : public URLFetcherTest { |
391 public: | 389 public: |
392 URLFetcherBadHTTPSTest(); | 390 URLFetcherBadHTTPSTest(); |
393 | 391 |
394 // URLFetcherDelegate: | 392 // URLFetcherDelegate: |
(...skipping 12 matching lines...) Expand all Loading... |
407 // URLFetcherDelegate: | 405 // URLFetcherDelegate: |
408 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 406 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
409 | 407 |
410 void CancelRequest(); | 408 void CancelRequest(); |
411 }; | 409 }; |
412 | 410 |
413 // Version of TestURLRequestContext that posts a Quit task to the IO | 411 // Version of TestURLRequestContext that posts a Quit task to the IO |
414 // thread once it is deleted. | 412 // thread once it is deleted. |
415 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { | 413 class CancelTestURLRequestContext : public ThrottlingTestURLRequestContext { |
416 public: | 414 public: |
417 explicit CancelTestURLRequestContext() { | 415 explicit CancelTestURLRequestContext() {} |
418 } | |
419 | 416 |
420 private: | 417 private: |
421 virtual ~CancelTestURLRequestContext() { | 418 virtual ~CancelTestURLRequestContext() { |
422 // The d'tor should execute in the IO thread. Post the quit task to the | 419 // The d'tor should execute in the IO thread. Post the quit task to the |
423 // current thread. | 420 // current thread. |
424 base::MessageLoop::current()->PostTask(FROM_HERE, | 421 base::MessageLoop::current()->PostTask(FROM_HERE, |
425 base::MessageLoop::QuitClosure()); | 422 base::MessageLoop::QuitClosure()); |
426 } | 423 } |
427 }; | 424 }; |
428 | 425 |
429 class CancelTestURLRequestContextGetter | 426 class CancelTestURLRequestContextGetter : public TestURLRequestContextGetter { |
430 : public TestURLRequestContextGetter { | |
431 public: | 427 public: |
432 CancelTestURLRequestContextGetter( | 428 CancelTestURLRequestContextGetter( |
433 base::MessageLoopProxy* io_message_loop_proxy, | 429 base::MessageLoopProxy* io_message_loop_proxy, |
434 const GURL& throttle_for_url) | 430 const GURL& throttle_for_url) |
435 : TestURLRequestContextGetter(io_message_loop_proxy), | 431 : TestURLRequestContextGetter(io_message_loop_proxy), |
436 io_message_loop_proxy_(io_message_loop_proxy), | 432 io_message_loop_proxy_(io_message_loop_proxy), |
437 context_created_(false, false), | 433 context_created_(false, false), |
438 throttle_for_url_(throttle_for_url) { | 434 throttle_for_url_(throttle_for_url) {} |
439 } | |
440 | 435 |
441 // TestURLRequestContextGetter: | 436 // TestURLRequestContextGetter: |
442 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { | 437 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { |
443 if (!context_.get()) { | 438 if (!context_.get()) { |
444 context_.reset(new CancelTestURLRequestContext()); | 439 context_.reset(new CancelTestURLRequestContext()); |
445 DCHECK(context_->throttler_manager()); | 440 DCHECK(context_->throttler_manager()); |
446 | 441 |
447 // Registers an entry for test url. The backoff time is calculated by: | 442 // Registers an entry for test url. The backoff time is calculated by: |
448 // new_backoff = 2.0 * old_backoff + 0 | 443 // new_backoff = 2.0 * old_backoff + 0 |
449 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. | 444 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. |
450 // Maximum retries allowed is set to 2. | 445 // Maximum retries allowed is set to 2. |
451 scoped_refptr<URLRequestThrottlerEntry> entry( | 446 scoped_refptr<URLRequestThrottlerEntry> entry( |
452 new URLRequestThrottlerEntry(context_->throttler_manager(), | 447 new URLRequestThrottlerEntry(context_->throttler_manager(), |
453 std::string(), | 448 std::string(), |
454 200, | 449 200, |
455 3, | 450 3, |
456 2000, | 451 2000, |
457 2.0, | 452 2.0, |
458 0.0, | 453 0.0, |
459 4000)); | 454 4000)); |
460 context_->throttler_manager() | 455 context_->throttler_manager()->OverrideEntryForTests(throttle_for_url_, |
461 ->OverrideEntryForTests(throttle_for_url_, entry.get()); | 456 entry.get()); |
462 | 457 |
463 context_created_.Signal(); | 458 context_created_.Signal(); |
464 } | 459 } |
465 return context_.get(); | 460 return context_.get(); |
466 } | 461 } |
467 | 462 |
468 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | 463 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { |
469 return io_message_loop_proxy_; | 464 return io_message_loop_proxy_; |
470 } | 465 } |
471 | 466 |
472 void WaitForContextCreation() { | 467 void WaitForContextCreation() { context_created_.Wait(); } |
473 context_created_.Wait(); | |
474 } | |
475 | 468 |
476 protected: | 469 protected: |
477 virtual ~CancelTestURLRequestContextGetter() {} | 470 virtual ~CancelTestURLRequestContextGetter() {} |
478 | 471 |
479 private: | 472 private: |
480 scoped_ptr<TestURLRequestContext> context_; | 473 scoped_ptr<TestURLRequestContext> context_; |
481 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 474 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
482 base::WaitableEvent context_created_; | 475 base::WaitableEvent context_created_; |
483 GURL throttle_for_url_; | 476 GURL throttle_for_url_; |
484 }; | 477 }; |
485 | 478 |
486 // Version of URLFetcherTest that tests retying the same request twice. | 479 // Version of URLFetcherTest that tests retying the same request twice. |
487 class URLFetcherMultipleAttemptTest : public URLFetcherTest { | 480 class URLFetcherMultipleAttemptTest : public URLFetcherTest { |
488 public: | 481 public: |
489 // URLFetcherDelegate: | 482 // URLFetcherDelegate: |
490 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 483 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| 484 |
491 private: | 485 private: |
492 std::string data_; | 486 std::string data_; |
493 }; | 487 }; |
494 | 488 |
495 class URLFetcherFileTest : public URLFetcherTest { | 489 class URLFetcherFileTest : public URLFetcherTest { |
496 public: | 490 public: |
497 URLFetcherFileTest() : take_ownership_of_file_(false), | 491 URLFetcherFileTest() |
498 expected_file_error_(OK) {} | 492 : take_ownership_of_file_(false), expected_file_error_(OK) {} |
499 | 493 |
500 void CreateFetcherForFile(const GURL& url, const base::FilePath& file_path); | 494 void CreateFetcherForFile(const GURL& url, const base::FilePath& file_path); |
501 void CreateFetcherForTempFile(const GURL& url); | 495 void CreateFetcherForTempFile(const GURL& url); |
502 | 496 |
503 // URLFetcherDelegate: | 497 // URLFetcherDelegate: |
504 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; | 498 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
505 | 499 |
506 protected: | 500 protected: |
507 base::FilePath expected_file_; | 501 base::FilePath expected_file_; |
508 base::FilePath file_path_; | 502 base::FilePath file_path_; |
(...skipping 16 matching lines...) Expand all Loading... |
525 } | 519 } |
526 | 520 |
527 void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) { | 521 void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) { |
528 std::string data; | 522 std::string data; |
529 EXPECT_TRUE(source->GetResponseAsString(&data)); | 523 EXPECT_TRUE(source->GetResponseAsString(&data)); |
530 EXPECT_EQ(std::string("bobsyeruncle"), data); | 524 EXPECT_EQ(std::string("bobsyeruncle"), data); |
531 URLFetcherTest::OnURLFetchComplete(source); | 525 URLFetcherTest::OnURLFetchComplete(source); |
532 } | 526 } |
533 | 527 |
534 URLFetcherPostFileTest::URLFetcherPostFileTest() | 528 URLFetcherPostFileTest::URLFetcherPostFileTest() |
535 : range_offset_(0), | 529 : range_offset_(0), range_length_(kuint64max) { |
536 range_length_(kuint64max) { | |
537 PathService::Get(base::DIR_SOURCE_ROOT, &path_); | 530 PathService::Get(base::DIR_SOURCE_ROOT, &path_); |
538 path_ = path_.Append(FILE_PATH_LITERAL("net")); | 531 path_ = path_.Append(FILE_PATH_LITERAL("net")); |
539 path_ = path_.Append(FILE_PATH_LITERAL("data")); | 532 path_ = path_.Append(FILE_PATH_LITERAL("data")); |
540 path_ = path_.Append(FILE_PATH_LITERAL("url_request_unittest")); | 533 path_ = path_.Append(FILE_PATH_LITERAL("url_request_unittest")); |
541 path_ = path_.Append(FILE_PATH_LITERAL("BullRunSpeech.txt")); | 534 path_ = path_.Append(FILE_PATH_LITERAL("BullRunSpeech.txt")); |
542 } | 535 } |
543 | 536 |
544 void URLFetcherPostFileTest::CreateFetcher(const GURL& url) { | 537 void URLFetcherPostFileTest::CreateFetcher(const GURL& url) { |
545 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | 538 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
546 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 539 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
(...skipping 14 matching lines...) Expand all Loading... |
561 std::min(range_length_, expected.size() - range_offset_); | 554 std::min(range_length_, expected.size() - range_offset_); |
562 | 555 |
563 std::string data; | 556 std::string data; |
564 EXPECT_TRUE(source->GetResponseAsString(&data)); | 557 EXPECT_TRUE(source->GetResponseAsString(&data)); |
565 EXPECT_EQ(expected.substr(range_offset_, expected_size), data); | 558 EXPECT_EQ(expected.substr(range_offset_, expected_size), data); |
566 URLFetcherTest::OnURLFetchComplete(source); | 559 URLFetcherTest::OnURLFetchComplete(source); |
567 } | 560 } |
568 | 561 |
569 void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) { | 562 void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) { |
570 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | 563 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
571 fetcher_->SetRequestContext(new TestURLRequestContextGetter( | 564 fetcher_->SetRequestContext( |
572 io_message_loop_proxy())); | 565 new TestURLRequestContextGetter(io_message_loop_proxy())); |
573 fetcher_->SetUploadData("text/plain", std::string()); | 566 fetcher_->SetUploadData("text/plain", std::string()); |
574 fetcher_->Start(); | 567 fetcher_->Start(); |
575 } | 568 } |
576 | 569 |
577 void URLFetcherEmptyPostTest::OnURLFetchComplete(const URLFetcher* source) { | 570 void URLFetcherEmptyPostTest::OnURLFetchComplete(const URLFetcher* source) { |
578 EXPECT_TRUE(source->GetStatus().is_success()); | 571 EXPECT_TRUE(source->GetStatus().is_success()); |
579 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK | 572 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK |
580 | 573 |
581 std::string data; | 574 std::string data; |
582 EXPECT_TRUE(source->GetResponseAsString(&data)); | 575 EXPECT_TRUE(source->GetResponseAsString(&data)); |
583 EXPECT_TRUE(data.empty()); | 576 EXPECT_TRUE(data.empty()); |
584 | 577 |
585 CleanupAfterFetchComplete(); | 578 CleanupAfterFetchComplete(); |
586 // Do not call the super class method URLFetcherTest::OnURLFetchComplete, | 579 // Do not call the super class method URLFetcherTest::OnURLFetchComplete, |
587 // since it expects a non-empty response. | 580 // since it expects a non-empty response. |
588 } | 581 } |
589 | 582 |
590 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { | 583 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { |
591 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 584 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
592 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 585 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
593 io_message_loop_proxy().get(), request_context())); | 586 io_message_loop_proxy().get(), request_context())); |
594 fetcher_->Start(); | 587 fetcher_->Start(); |
595 } | 588 } |
596 | 589 |
597 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( | 590 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( |
598 const URLFetcher* source, int64 progress, int64 total) { | 591 const URLFetcher* source, |
| 592 int64 progress, |
| 593 int64 total) { |
599 // Increasing between 0 and total. | 594 // Increasing between 0 and total. |
600 EXPECT_LE(0, progress); | 595 EXPECT_LE(0, progress); |
601 EXPECT_GE(total, progress); | 596 EXPECT_GE(total, progress); |
602 EXPECT_LE(previous_progress_, progress); | 597 EXPECT_LE(previous_progress_, progress); |
603 EXPECT_EQ(expected_total_, total); | 598 EXPECT_EQ(expected_total_, total); |
604 previous_progress_ = progress; | 599 previous_progress_ = progress; |
605 } | 600 } |
606 | 601 |
607 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { | 602 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { |
608 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 603 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
609 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 604 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
610 io_message_loop_proxy().get(), request_context())); | 605 io_message_loop_proxy().get(), request_context())); |
611 cancelled_ = false; | 606 cancelled_ = false; |
612 fetcher_->Start(); | 607 fetcher_->Start(); |
613 } | 608 } |
614 | 609 |
615 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( | 610 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( |
616 const URLFetcher* source, int64 current, int64 total) { | 611 const URLFetcher* source, |
| 612 int64 current, |
| 613 int64 total) { |
617 EXPECT_FALSE(cancelled_); | 614 EXPECT_FALSE(cancelled_); |
618 if (!cancelled_) { | 615 if (!cancelled_) { |
619 cancelled_ = true; | 616 cancelled_ = true; |
620 CleanupAfterFetchComplete(); | 617 CleanupAfterFetchComplete(); |
621 } | 618 } |
622 } | 619 } |
623 | 620 |
624 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( | 621 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( |
625 const URLFetcher* source) { | 622 const URLFetcher* source) { |
626 // Should have been cancelled. | 623 // Should have been cancelled. |
627 ADD_FAILURE(); | 624 ADD_FAILURE(); |
628 CleanupAfterFetchComplete(); | 625 CleanupAfterFetchComplete(); |
629 } | 626 } |
630 | 627 |
631 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { | 628 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { |
632 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | 629 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
633 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 630 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
634 io_message_loop_proxy().get(), request_context())); | 631 io_message_loop_proxy().get(), request_context())); |
635 previous_progress_ = 0; | 632 previous_progress_ = 0; |
636 // Large enough data to require more than one read from UploadDataStream. | 633 // Large enough data to require more than one read from UploadDataStream. |
637 chunk_.assign(1<<16, 'a'); | 634 chunk_.assign(1 << 16, 'a'); |
638 // Use chunked upload to wait for a timer event of progress notification. | 635 // Use chunked upload to wait for a timer event of progress notification. |
639 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); | 636 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); |
640 fetcher_->Start(); | 637 fetcher_->Start(); |
641 number_of_chunks_added_ = 1; | 638 number_of_chunks_added_ = 1; |
642 fetcher_->AppendChunkToUpload(chunk_, false); | 639 fetcher_->AppendChunkToUpload(chunk_, false); |
643 } | 640 } |
644 | 641 |
645 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress( | 642 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress( |
646 const URLFetcher* source, int64 current, int64 total) { | 643 const URLFetcher* source, |
| 644 int64 current, |
| 645 int64 total) { |
647 // Increasing between 0 and total. | 646 // Increasing between 0 and total. |
648 EXPECT_LE(0, current); | 647 EXPECT_LE(0, current); |
649 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_, | 648 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_, |
650 current); | 649 current); |
651 EXPECT_LE(previous_progress_, current); | 650 EXPECT_LE(previous_progress_, current); |
652 previous_progress_ = current; | 651 previous_progress_ = current; |
653 EXPECT_EQ(-1, total); | 652 EXPECT_EQ(-1, total); |
654 | 653 |
655 if (number_of_chunks_added_ < 2) { | 654 if (number_of_chunks_added_ < 2) { |
656 number_of_chunks_added_ += 1; | 655 number_of_chunks_added_ += 1; |
657 fetcher_->AppendChunkToUpload(chunk_, true); | 656 fetcher_->AppendChunkToUpload(chunk_, true); |
658 } | 657 } |
659 } | 658 } |
660 | 659 |
661 void URLFetcherHeadersTest::OnURLFetchComplete( | 660 void URLFetcherHeadersTest::OnURLFetchComplete(const URLFetcher* source) { |
662 const URLFetcher* source) { | |
663 std::string header; | 661 std::string header; |
664 EXPECT_TRUE(source->GetResponseHeaders()->GetNormalizedHeader("cache-control", | 662 EXPECT_TRUE(source->GetResponseHeaders()->GetNormalizedHeader("cache-control", |
665 &header)); | 663 &header)); |
666 EXPECT_EQ("private", header); | 664 EXPECT_EQ("private", header); |
667 URLFetcherTest::OnURLFetchComplete(source); | 665 URLFetcherTest::OnURLFetchComplete(source); |
668 } | 666 } |
669 | 667 |
670 void URLFetcherSocketAddressTest::OnURLFetchComplete( | 668 void URLFetcherSocketAddressTest::OnURLFetchComplete(const URLFetcher* source) { |
671 const URLFetcher* source) { | |
672 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host()); | 669 EXPECT_EQ("127.0.0.1", source->GetSocketAddress().host()); |
673 EXPECT_EQ(expected_port_, source->GetSocketAddress().port()); | 670 EXPECT_EQ(expected_port_, source->GetSocketAddress().port()); |
674 URLFetcherTest::OnURLFetchComplete(source); | 671 URLFetcherTest::OnURLFetchComplete(source); |
675 } | 672 } |
676 | 673 |
677 // static | 674 // static |
678 const char* URLFetcherStopOnRedirectTest::kRedirectTarget = | 675 const char* URLFetcherStopOnRedirectTest::kRedirectTarget = |
679 "http://redirect.target.com"; | 676 "http://redirect.target.com"; |
680 | 677 |
681 URLFetcherStopOnRedirectTest::URLFetcherStopOnRedirectTest() | 678 URLFetcherStopOnRedirectTest::URLFetcherStopOnRedirectTest() |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 EXPECT_TRUE(source->GetResponseAsString(&data)); | 762 EXPECT_TRUE(source->GetResponseAsString(&data)); |
766 EXPECT_FALSE(data.empty()); | 763 EXPECT_FALSE(data.empty()); |
767 } else { | 764 } else { |
768 // We should not get here! | 765 // We should not get here! |
769 ADD_FAILURE(); | 766 ADD_FAILURE(); |
770 } | 767 } |
771 | 768 |
772 CleanupAfterFetchComplete(); | 769 CleanupAfterFetchComplete(); |
773 } | 770 } |
774 | 771 |
775 | |
776 URLFetcherBadHTTPSTest::URLFetcherBadHTTPSTest() { | 772 URLFetcherBadHTTPSTest::URLFetcherBadHTTPSTest() { |
777 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); | 773 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); |
778 cert_dir_ = cert_dir_.AppendASCII("chrome"); | 774 cert_dir_ = cert_dir_.AppendASCII("chrome"); |
779 cert_dir_ = cert_dir_.AppendASCII("test"); | 775 cert_dir_ = cert_dir_.AppendASCII("test"); |
780 cert_dir_ = cert_dir_.AppendASCII("data"); | 776 cert_dir_ = cert_dir_.AppendASCII("data"); |
781 cert_dir_ = cert_dir_.AppendASCII("ssl"); | 777 cert_dir_ = cert_dir_.AppendASCII("ssl"); |
782 cert_dir_ = cert_dir_.AppendASCII("certificates"); | 778 cert_dir_ = cert_dir_.AppendASCII("certificates"); |
783 } | 779 } |
784 | 780 |
785 // The "server certificate expired" error should result in automatic | 781 // The "server certificate expired" error should result in automatic |
786 // cancellation of the request by | 782 // cancellation of the request by |
787 // URLRequest::Delegate::OnSSLCertificateError. | 783 // URLRequest::Delegate::OnSSLCertificateError. |
788 void URLFetcherBadHTTPSTest::OnURLFetchComplete( | 784 void URLFetcherBadHTTPSTest::OnURLFetchComplete(const URLFetcher* source) { |
789 const URLFetcher* source) { | |
790 // This part is different from URLFetcherTest::OnURLFetchComplete | 785 // This part is different from URLFetcherTest::OnURLFetchComplete |
791 // because this test expects the request to be cancelled. | 786 // because this test expects the request to be cancelled. |
792 EXPECT_EQ(URLRequestStatus::CANCELED, source->GetStatus().status()); | 787 EXPECT_EQ(URLRequestStatus::CANCELED, source->GetStatus().status()); |
793 EXPECT_EQ(ERR_ABORTED, source->GetStatus().error()); | 788 EXPECT_EQ(ERR_ABORTED, source->GetStatus().error()); |
794 EXPECT_EQ(-1, source->GetResponseCode()); | 789 EXPECT_EQ(-1, source->GetResponseCode()); |
795 EXPECT_TRUE(source->GetCookies().empty()); | 790 EXPECT_TRUE(source->GetCookies().empty()); |
796 std::string data; | 791 std::string data; |
797 EXPECT_TRUE(source->GetResponseAsString(&data)); | 792 EXPECT_TRUE(source->GetResponseAsString(&data)); |
798 EXPECT_TRUE(data.empty()); | 793 EXPECT_TRUE(data.empty()); |
799 CleanupAfterFetchComplete(); | 794 CleanupAfterFetchComplete(); |
800 } | 795 } |
801 | 796 |
802 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { | 797 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { |
803 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 798 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
804 CancelTestURLRequestContextGetter* context_getter = | 799 CancelTestURLRequestContextGetter* context_getter = |
805 new CancelTestURLRequestContextGetter(io_message_loop_proxy().get(), url); | 800 new CancelTestURLRequestContextGetter(io_message_loop_proxy().get(), url); |
806 fetcher_->SetRequestContext(context_getter); | 801 fetcher_->SetRequestContext(context_getter); |
807 fetcher_->SetMaxRetriesOn5xx(2); | 802 fetcher_->SetMaxRetriesOn5xx(2); |
808 fetcher_->Start(); | 803 fetcher_->Start(); |
809 // We need to wait for the creation of the URLRequestContext, since we | 804 // We need to wait for the creation of the URLRequestContext, since we |
810 // rely on it being destroyed as a signal to end the test. | 805 // rely on it being destroyed as a signal to end the test. |
811 context_getter->WaitForContextCreation(); | 806 context_getter->WaitForContextCreation(); |
812 CancelRequest(); | 807 CancelRequest(); |
813 } | 808 } |
814 | 809 |
815 void URLFetcherCancelTest::OnURLFetchComplete( | 810 void URLFetcherCancelTest::OnURLFetchComplete(const URLFetcher* source) { |
816 const URLFetcher* source) { | |
817 // We should have cancelled the request before completion. | 811 // We should have cancelled the request before completion. |
818 ADD_FAILURE(); | 812 ADD_FAILURE(); |
819 CleanupAfterFetchComplete(); | 813 CleanupAfterFetchComplete(); |
820 } | 814 } |
821 | 815 |
822 void URLFetcherCancelTest::CancelRequest() { | 816 void URLFetcherCancelTest::CancelRequest() { |
823 delete fetcher_; | 817 delete fetcher_; |
824 // The URLFetcher's test context will post a Quit task once it is | 818 // The URLFetcher's test context will post a Quit task once it is |
825 // deleted. So if this test simply hangs, it means cancellation | 819 // deleted. So if this test simply hangs, it means cancellation |
826 // did not work. | 820 // did not work. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); | 858 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); |
865 fetcher_->Start(); | 859 fetcher_->Start(); |
866 } | 860 } |
867 | 861 |
868 void URLFetcherFileTest::OnURLFetchComplete(const URLFetcher* source) { | 862 void URLFetcherFileTest::OnURLFetchComplete(const URLFetcher* source) { |
869 if (expected_file_error_ == OK) { | 863 if (expected_file_error_ == OK) { |
870 EXPECT_TRUE(source->GetStatus().is_success()); | 864 EXPECT_TRUE(source->GetStatus().is_success()); |
871 EXPECT_EQ(OK, source->GetStatus().error()); | 865 EXPECT_EQ(OK, source->GetStatus().error()); |
872 EXPECT_EQ(200, source->GetResponseCode()); | 866 EXPECT_EQ(200, source->GetResponseCode()); |
873 | 867 |
874 EXPECT_TRUE(source->GetResponseAsFilePath( | 868 EXPECT_TRUE( |
875 take_ownership_of_file_, &file_path_)); | 869 source->GetResponseAsFilePath(take_ownership_of_file_, &file_path_)); |
876 | 870 |
877 EXPECT_TRUE(base::ContentsEqual(expected_file_, file_path_)); | 871 EXPECT_TRUE(base::ContentsEqual(expected_file_, file_path_)); |
878 } else { | 872 } else { |
879 EXPECT_FALSE(source->GetStatus().is_success()); | 873 EXPECT_FALSE(source->GetStatus().is_success()); |
880 EXPECT_EQ(expected_file_error_, source->GetStatus().error()); | 874 EXPECT_EQ(expected_file_error_, source->GetStatus().error()); |
881 } | 875 } |
882 CleanupAfterFetchComplete(); | 876 CleanupAfterFetchComplete(); |
883 } | 877 } |
884 | 878 |
885 TEST_F(URLFetcherTest, SameThreadsTest) { | 879 TEST_F(URLFetcherTest, SameThreadsTest) { |
(...skipping 16 matching lines...) Expand all Loading... |
902 base::FilePath(kDocRoot)); | 896 base::FilePath(kDocRoot)); |
903 ASSERT_TRUE(test_server.Start()); | 897 ASSERT_TRUE(test_server.Start()); |
904 | 898 |
905 // Create a separate thread that will create the URLFetcher. The current | 899 // Create a separate thread that will create the URLFetcher. The current |
906 // (main) thread will do the IO, and when the fetch is complete it will | 900 // (main) thread will do the IO, and when the fetch is complete it will |
907 // terminate the main thread's message loop; then the other thread's | 901 // terminate the main thread's message loop; then the other thread's |
908 // message loop will be shut down automatically as the thread goes out of | 902 // message loop will be shut down automatically as the thread goes out of |
909 // scope. | 903 // scope. |
910 base::Thread t("URLFetcher test thread"); | 904 base::Thread t("URLFetcher test thread"); |
911 ASSERT_TRUE(t.Start()); | 905 ASSERT_TRUE(t.Start()); |
912 t.message_loop()->PostTask( | 906 t.message_loop()->PostTask(FROM_HERE, |
913 FROM_HERE, | 907 base::Bind(&URLFetcherTest::CreateFetcher, |
914 base::Bind(&URLFetcherTest::CreateFetcher, | 908 base::Unretained(this), |
915 base::Unretained(this), | 909 test_server.GetURL("defaultresponse"))); |
916 test_server.GetURL("defaultresponse"))); | |
917 | 910 |
918 base::MessageLoop::current()->Run(); | 911 base::MessageLoop::current()->Run(); |
919 } | 912 } |
920 | 913 |
921 void CancelAllOnIO() { | 914 void CancelAllOnIO() { |
922 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); | 915 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); |
923 URLFetcherImpl::CancelAll(); | 916 URLFetcherImpl::CancelAll(); |
924 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); | 917 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); |
925 } | 918 } |
926 | 919 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 | 1101 |
1109 // Get a file large enough to require more than one read into | 1102 // Get a file large enough to require more than one read into |
1110 // URLFetcher::Core's IOBuffer. | 1103 // URLFetcher::Core's IOBuffer. |
1111 static const char kFileToFetch[] = "animate1.gif"; | 1104 static const char kFileToFetch[] = "animate1.gif"; |
1112 // Hardcoded file size - it cannot be easily fetched when a remote http server | 1105 // Hardcoded file size - it cannot be easily fetched when a remote http server |
1113 // is used for testing. | 1106 // is used for testing. |
1114 static const int64 kFileSize = 19021; | 1107 static const int64 kFileSize = 19021; |
1115 | 1108 |
1116 expected_total_ = kFileSize; | 1109 expected_total_ = kFileSize; |
1117 | 1110 |
1118 CreateFetcher(test_server.GetURL( | 1111 CreateFetcher( |
1119 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1112 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
1120 | 1113 |
1121 base::MessageLoop::current()->Run(); | 1114 base::MessageLoop::current()->Run(); |
1122 } | 1115 } |
1123 | 1116 |
1124 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { | 1117 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { |
1125 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1118 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1126 SpawnedTestServer::kLocalhost, | 1119 SpawnedTestServer::kLocalhost, |
1127 base::FilePath(kDocRoot)); | 1120 base::FilePath(kDocRoot)); |
1128 ASSERT_TRUE(test_server.Start()); | 1121 ASSERT_TRUE(test_server.Start()); |
1129 | 1122 |
1130 // Get a file large enough to require more than one read into | 1123 // Get a file large enough to require more than one read into |
1131 // URLFetcher::Core's IOBuffer. | 1124 // URLFetcher::Core's IOBuffer. |
1132 static const char kFileToFetch[] = "animate1.gif"; | 1125 static const char kFileToFetch[] = "animate1.gif"; |
1133 CreateFetcher(test_server.GetURL( | 1126 CreateFetcher( |
1134 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1127 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
1135 | 1128 |
1136 base::MessageLoop::current()->Run(); | 1129 base::MessageLoop::current()->Run(); |
1137 } | 1130 } |
1138 | 1131 |
1139 TEST_F(URLFetcherHeadersTest, Headers) { | 1132 TEST_F(URLFetcherHeadersTest, Headers) { |
1140 SpawnedTestServer test_server( | 1133 SpawnedTestServer test_server( |
1141 SpawnedTestServer::TYPE_HTTP, | 1134 SpawnedTestServer::TYPE_HTTP, |
1142 SpawnedTestServer::kLocalhost, | 1135 SpawnedTestServer::kLocalhost, |
1143 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 1136 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
1144 ASSERT_TRUE(test_server.Start()); | 1137 ASSERT_TRUE(test_server.Start()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 // in 200 milliseconds. | 1179 // in 200 milliseconds. |
1187 scoped_refptr<URLRequestThrottlerEntry> entry( | 1180 scoped_refptr<URLRequestThrottlerEntry> entry( |
1188 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1181 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1189 std::string(), | 1182 std::string(), |
1190 200, | 1183 200, |
1191 3, | 1184 3, |
1192 1, | 1185 1, |
1193 2.0, | 1186 2.0, |
1194 0.0, | 1187 0.0, |
1195 256)); | 1188 256)); |
1196 request_context()->throttler_manager() | 1189 request_context()->throttler_manager()->OverrideEntryForTests(url, |
1197 ->OverrideEntryForTests(url, entry.get()); | 1190 entry.get()); |
1198 | 1191 |
1199 CreateFetcher(url); | 1192 CreateFetcher(url); |
1200 | 1193 |
1201 base::MessageLoop::current()->Run(); | 1194 base::MessageLoop::current()->Run(); |
1202 } | 1195 } |
1203 | 1196 |
1204 TEST_F(URLFetcherProtectTest, ServerUnavailable) { | 1197 TEST_F(URLFetcherProtectTest, ServerUnavailable) { |
1205 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1198 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1206 SpawnedTestServer::kLocalhost, | 1199 SpawnedTestServer::kLocalhost, |
1207 base::FilePath(kDocRoot)); | 1200 base::FilePath(kDocRoot)); |
1208 ASSERT_TRUE(test_server.Start()); | 1201 ASSERT_TRUE(test_server.Start()); |
1209 | 1202 |
1210 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1203 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1211 | 1204 |
1212 // Registers an entry for test url. The backoff time is calculated by: | 1205 // Registers an entry for test url. The backoff time is calculated by: |
1213 // new_backoff = 2.0 * old_backoff + 0 | 1206 // new_backoff = 2.0 * old_backoff + 0 |
1214 // and maximum backoff time is 256 milliseconds. | 1207 // and maximum backoff time is 256 milliseconds. |
1215 // Maximum retries allowed is set to 11. | 1208 // Maximum retries allowed is set to 11. |
1216 scoped_refptr<URLRequestThrottlerEntry> entry( | 1209 scoped_refptr<URLRequestThrottlerEntry> entry( |
1217 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1210 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1218 std::string(), | 1211 std::string(), |
1219 200, | 1212 200, |
1220 3, | 1213 3, |
1221 1, | 1214 1, |
1222 2.0, | 1215 2.0, |
1223 0.0, | 1216 0.0, |
1224 256)); | 1217 256)); |
1225 request_context()->throttler_manager() | 1218 request_context()->throttler_manager()->OverrideEntryForTests(url, |
1226 ->OverrideEntryForTests(url, entry.get()); | 1219 entry.get()); |
1227 | 1220 |
1228 CreateFetcher(url); | 1221 CreateFetcher(url); |
1229 | 1222 |
1230 base::MessageLoop::current()->Run(); | 1223 base::MessageLoop::current()->Run(); |
1231 } | 1224 } |
1232 | 1225 |
1233 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { | 1226 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { |
1234 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1227 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1235 SpawnedTestServer::kLocalhost, | 1228 SpawnedTestServer::kLocalhost, |
1236 base::FilePath(kDocRoot)); | 1229 base::FilePath(kDocRoot)); |
1237 ASSERT_TRUE(test_server.Start()); | 1230 ASSERT_TRUE(test_server.Start()); |
1238 | 1231 |
1239 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1232 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1240 | 1233 |
1241 // Registers an entry for test url. The backoff time is calculated by: | 1234 // Registers an entry for test url. The backoff time is calculated by: |
1242 // new_backoff = 2.0 * old_backoff + 0 | 1235 // new_backoff = 2.0 * old_backoff + 0 |
1243 // and maximum backoff time is 150000 milliseconds. | 1236 // and maximum backoff time is 150000 milliseconds. |
1244 // Maximum retries allowed is set to 11. | 1237 // Maximum retries allowed is set to 11. |
1245 scoped_refptr<URLRequestThrottlerEntry> entry( | 1238 scoped_refptr<URLRequestThrottlerEntry> entry( |
1246 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1239 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1247 std::string(), | 1240 std::string(), |
1248 200, | 1241 200, |
1249 3, | 1242 3, |
1250 100, | 1243 100, |
1251 2.0, | 1244 2.0, |
1252 0.0, | 1245 0.0, |
1253 150000)); | 1246 150000)); |
1254 // Total time if *not* for not doing automatic backoff would be 150s. | 1247 // Total time if *not* for not doing automatic backoff would be 150s. |
1255 // In reality it should be "as soon as server responds". | 1248 // In reality it should be "as soon as server responds". |
1256 request_context()->throttler_manager() | 1249 request_context()->throttler_manager()->OverrideEntryForTests(url, |
1257 ->OverrideEntryForTests(url, entry.get()); | 1250 entry.get()); |
1258 | 1251 |
1259 CreateFetcher(url); | 1252 CreateFetcher(url); |
1260 | 1253 |
1261 base::MessageLoop::current()->Run(); | 1254 base::MessageLoop::current()->Run(); |
1262 } | 1255 } |
1263 | 1256 |
1264 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { | 1257 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { |
1265 SpawnedTestServer::SSLOptions ssl_options( | 1258 SpawnedTestServer::SSLOptions ssl_options( |
1266 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | 1259 SpawnedTestServer::SSLOptions::CERT_EXPIRED); |
1267 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, | 1260 SpawnedTestServer test_server( |
1268 ssl_options, | 1261 SpawnedTestServer::TYPE_HTTPS, ssl_options, base::FilePath(kDocRoot)); |
1269 base::FilePath(kDocRoot)); | |
1270 ASSERT_TRUE(test_server.Start()); | 1262 ASSERT_TRUE(test_server.Start()); |
1271 | 1263 |
1272 CreateFetcher(test_server.GetURL("defaultresponse")); | 1264 CreateFetcher(test_server.GetURL("defaultresponse")); |
1273 base::MessageLoop::current()->Run(); | 1265 base::MessageLoop::current()->Run(); |
1274 } | 1266 } |
1275 | 1267 |
1276 TEST_F(URLFetcherCancelTest, ReleasesContext) { | 1268 TEST_F(URLFetcherCancelTest, ReleasesContext) { |
1277 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1269 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1278 SpawnedTestServer::kLocalhost, | 1270 SpawnedTestServer::kLocalhost, |
1279 base::FilePath(kDocRoot)); | 1271 base::FilePath(kDocRoot)); |
1280 ASSERT_TRUE(test_server.Start()); | 1272 ASSERT_TRUE(test_server.Start()); |
1281 | 1273 |
1282 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1274 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1283 | 1275 |
1284 // Create a separate thread that will create the URLFetcher. The current | 1276 // Create a separate thread that will create the URLFetcher. The current |
1285 // (main) thread will do the IO, and when the fetch is complete it will | 1277 // (main) thread will do the IO, and when the fetch is complete it will |
1286 // terminate the main thread's message loop; then the other thread's | 1278 // terminate the main thread's message loop; then the other thread's |
1287 // message loop will be shut down automatically as the thread goes out of | 1279 // message loop will be shut down automatically as the thread goes out of |
1288 // scope. | 1280 // scope. |
1289 base::Thread t("URLFetcher test thread"); | 1281 base::Thread t("URLFetcher test thread"); |
1290 ASSERT_TRUE(t.Start()); | 1282 ASSERT_TRUE(t.Start()); |
1291 t.message_loop()->PostTask( | 1283 t.message_loop()->PostTask( |
1292 FROM_HERE, | 1284 FROM_HERE, |
1293 base::Bind(&URLFetcherCancelTest::CreateFetcher, | 1285 base::Bind( |
1294 base::Unretained(this), url)); | 1286 &URLFetcherCancelTest::CreateFetcher, base::Unretained(this), url)); |
1295 | 1287 |
1296 base::MessageLoop::current()->Run(); | 1288 base::MessageLoop::current()->Run(); |
1297 } | 1289 } |
1298 | 1290 |
1299 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { | 1291 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { |
1300 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1292 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1301 SpawnedTestServer::kLocalhost, | 1293 SpawnedTestServer::kLocalhost, |
1302 base::FilePath(kDocRoot)); | 1294 base::FilePath(kDocRoot)); |
1303 ASSERT_TRUE(test_server.Start()); | 1295 ASSERT_TRUE(test_server.Start()); |
1304 | 1296 |
1305 GURL url(test_server.GetURL("files/server-unavailable.html")); | 1297 GURL url(test_server.GetURL("files/server-unavailable.html")); |
1306 | 1298 |
1307 // Register an entry for test url. | 1299 // Register an entry for test url. |
1308 // Using a sliding window of 4 seconds, and max of 1 request, under a fast | 1300 // Using a sliding window of 4 seconds, and max of 1 request, under a fast |
1309 // run we expect to have a 4 second delay when posting the Start task. | 1301 // run we expect to have a 4 second delay when posting the Start task. |
1310 scoped_refptr<URLRequestThrottlerEntry> entry( | 1302 scoped_refptr<URLRequestThrottlerEntry> entry( |
1311 new URLRequestThrottlerEntry(request_context()->throttler_manager(), | 1303 new URLRequestThrottlerEntry(request_context()->throttler_manager(), |
1312 std::string(), | 1304 std::string(), |
1313 4000, | 1305 4000, |
1314 1, | 1306 1, |
1315 2000, | 1307 2000, |
1316 2.0, | 1308 2.0, |
1317 0.0, | 1309 0.0, |
1318 4000)); | 1310 4000)); |
1319 request_context()->throttler_manager() | 1311 request_context()->throttler_manager()->OverrideEntryForTests(url, |
1320 ->OverrideEntryForTests(url, entry.get()); | 1312 entry.get()); |
1321 // Fake that a request has just started. | 1313 // Fake that a request has just started. |
1322 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); | 1314 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); |
1323 | 1315 |
1324 // The next request we try to send will be delayed by ~4 seconds. | 1316 // The next request we try to send will be delayed by ~4 seconds. |
1325 // The slower the test runs, the less the delay will be (since it takes the | 1317 // The slower the test runs, the less the delay will be (since it takes the |
1326 // time difference from now). | 1318 // time difference from now). |
1327 | 1319 |
1328 base::Thread t("URLFetcher test thread"); | 1320 base::Thread t("URLFetcher test thread"); |
1329 ASSERT_TRUE(t.Start()); | 1321 ASSERT_TRUE(t.Start()); |
1330 t.message_loop()->PostTask( | 1322 t.message_loop()->PostTask( |
(...skipping 28 matching lines...) Expand all Loading... |
1359 | 1351 |
1360 // Get a small file. | 1352 // Get a small file. |
1361 static const char kFileToFetch[] = "simple.html"; | 1353 static const char kFileToFetch[] = "simple.html"; |
1362 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1354 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1363 CreateFetcherForFile( | 1355 CreateFetcherForFile( |
1364 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1356 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1365 temp_dir.path().AppendASCII(kFileToFetch)); | 1357 temp_dir.path().AppendASCII(kFileToFetch)); |
1366 | 1358 |
1367 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1359 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1368 | 1360 |
1369 ASSERT_FALSE(base::PathExists(file_path_)) | 1361 ASSERT_FALSE(base::PathExists(file_path_)) << file_path_.value() |
1370 << file_path_.value() << " not removed."; | 1362 << " not removed."; |
1371 } | 1363 } |
1372 | 1364 |
1373 TEST_F(URLFetcherFileTest, LargeGet) { | 1365 TEST_F(URLFetcherFileTest, LargeGet) { |
1374 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1366 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1375 SpawnedTestServer::kLocalhost, | 1367 SpawnedTestServer::kLocalhost, |
1376 base::FilePath(kDocRoot)); | 1368 base::FilePath(kDocRoot)); |
1377 ASSERT_TRUE(test_server.Start()); | 1369 ASSERT_TRUE(test_server.Start()); |
1378 | 1370 |
1379 base::ScopedTempDir temp_dir; | 1371 base::ScopedTempDir temp_dir; |
1380 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1372 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
(...skipping 26 matching lines...) Expand all Loading... |
1407 // Get a small file. | 1399 // Get a small file. |
1408 static const char kFileToFetch[] = "simple.html"; | 1400 static const char kFileToFetch[] = "simple.html"; |
1409 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1401 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1410 CreateFetcherForFile( | 1402 CreateFetcherForFile( |
1411 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1403 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1412 temp_dir.path().AppendASCII(kFileToFetch)); | 1404 temp_dir.path().AppendASCII(kFileToFetch)); |
1413 | 1405 |
1414 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1406 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1415 | 1407 |
1416 base::MessageLoop::current()->RunUntilIdle(); | 1408 base::MessageLoop::current()->RunUntilIdle(); |
1417 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | 1409 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) |
1418 "FilePath: " << file_path_.value(); | 1410 << "FilePath: " << file_path_.value(); |
1419 } | 1411 } |
1420 } | 1412 } |
1421 | 1413 |
1422 TEST_F(URLFetcherFileTest, OverwriteExistingFile) { | 1414 TEST_F(URLFetcherFileTest, OverwriteExistingFile) { |
1423 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1415 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1424 SpawnedTestServer::kLocalhost, | 1416 SpawnedTestServer::kLocalhost, |
1425 base::FilePath(kDocRoot)); | 1417 base::FilePath(kDocRoot)); |
1426 ASSERT_TRUE(test_server.Start()); | 1418 ASSERT_TRUE(test_server.Start()); |
1427 | 1419 |
1428 base::ScopedTempDir temp_dir; | 1420 base::ScopedTempDir temp_dir; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 ASSERT_TRUE(test_server.Start()); | 1472 ASSERT_TRUE(test_server.Start()); |
1481 | 1473 |
1482 // Get a small file. | 1474 // Get a small file. |
1483 static const char kFileToFetch[] = "simple.html"; | 1475 static const char kFileToFetch[] = "simple.html"; |
1484 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1476 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1485 CreateFetcherForTempFile( | 1477 CreateFetcherForTempFile( |
1486 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | 1478 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
1487 | 1479 |
1488 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1480 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1489 | 1481 |
1490 ASSERT_FALSE(base::PathExists(file_path_)) | 1482 ASSERT_FALSE(base::PathExists(file_path_)) << file_path_.value() |
1491 << file_path_.value() << " not removed."; | 1483 << " not removed."; |
1492 } | 1484 } |
1493 | 1485 |
1494 TEST_F(URLFetcherFileTest, LargeGetToTempFile) { | 1486 TEST_F(URLFetcherFileTest, LargeGetToTempFile) { |
1495 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1487 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1496 SpawnedTestServer::kLocalhost, | 1488 SpawnedTestServer::kLocalhost, |
1497 base::FilePath(kDocRoot)); | 1489 base::FilePath(kDocRoot)); |
1498 ASSERT_TRUE(test_server.Start()); | 1490 ASSERT_TRUE(test_server.Start()); |
1499 | 1491 |
1500 // Get a file large enough to require more than one read into | 1492 // Get a file large enough to require more than one read into |
1501 // URLFetcher::Core's IOBuffer. | 1493 // URLFetcher::Core's IOBuffer. |
1502 static const char kFileToFetch[] = "animate1.gif"; | 1494 static const char kFileToFetch[] = "animate1.gif"; |
1503 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1495 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1504 CreateFetcherForTempFile(test_server.GetURL( | 1496 CreateFetcherForTempFile( |
1505 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1497 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
1506 | 1498 |
1507 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1499 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1508 } | 1500 } |
1509 | 1501 |
1510 TEST_F(URLFetcherFileTest, SavedOutputTempFileOwnerhisp) { | 1502 TEST_F(URLFetcherFileTest, SavedOutputTempFileOwnerhisp) { |
1511 // If the caller takes the ownership of the temp file, the file should persist | 1503 // If the caller takes the ownership of the temp file, the file should persist |
1512 // even after URLFetcher is gone. If not, the file must be deleted. | 1504 // even after URLFetcher is gone. If not, the file must be deleted. |
1513 const bool kTake[] = {false, true}; | 1505 const bool kTake[] = {false, true}; |
1514 for (size_t i = 0; i < arraysize(kTake); ++i) { | 1506 for (size_t i = 0; i < arraysize(kTake); ++i) { |
1515 take_ownership_of_file_ = kTake[i]; | 1507 take_ownership_of_file_ = kTake[i]; |
1516 | 1508 |
1517 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, | 1509 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, |
1518 SpawnedTestServer::kLocalhost, | 1510 SpawnedTestServer::kLocalhost, |
1519 base::FilePath(kDocRoot)); | 1511 base::FilePath(kDocRoot)); |
1520 ASSERT_TRUE(test_server.Start()); | 1512 ASSERT_TRUE(test_server.Start()); |
1521 | 1513 |
1522 // Get a small file. | 1514 // Get a small file. |
1523 static const char kFileToFetch[] = "simple.html"; | 1515 static const char kFileToFetch[] = "simple.html"; |
1524 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); | 1516 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); |
1525 CreateFetcherForTempFile(test_server.GetURL( | 1517 CreateFetcherForTempFile( |
1526 std::string(kTestServerFilePrefix) + kFileToFetch)); | 1518 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
1527 | 1519 |
1528 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1520 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1529 | 1521 |
1530 base::MessageLoop::current()->RunUntilIdle(); | 1522 base::MessageLoop::current()->RunUntilIdle(); |
1531 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | 1523 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) |
1532 "FilePath: " << file_path_.value(); | 1524 << "FilePath: " << file_path_.value(); |
1533 } | 1525 } |
1534 } | 1526 } |
1535 | 1527 |
1536 } // namespace | 1528 } // namespace |
1537 | 1529 |
1538 } // namespace net | 1530 } // namespace net |
OLD | NEW |