| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/net/url_fetcher_impl.h" | 5 #include "content/common/net/url_fetcher_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); | 273 fetcher_ = new URLFetcherImpl(url, content::URLFetcher::GET, this); |
| 274 fetcher_->SetRequestContext(new TestURLRequestContextGetter( | 274 fetcher_->SetRequestContext(new TestURLRequestContextGetter( |
| 275 io_message_loop_proxy())); | 275 io_message_loop_proxy())); |
| 276 | 276 |
| 277 // Use the IO message loop to do the file operations in this test. | 277 // Use the IO message loop to do the file operations in this test. |
| 278 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); | 278 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); |
| 279 fetcher_->Start(); | 279 fetcher_->Start(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 TEST_F(URLFetcherTempFileTest, SmallGet) { | 282 TEST_F(URLFetcherTempFileTest, SmallGet) { |
| 283 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 283 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 284 net::TestServer::kLocalhost, |
| 285 FilePath(kDocRoot)); |
| 284 ASSERT_TRUE(test_server.Start()); | 286 ASSERT_TRUE(test_server.Start()); |
| 285 | 287 |
| 286 // Get a small file. | 288 // Get a small file. |
| 287 const char* kFileToFetch = "simple.html"; | 289 const char* kFileToFetch = "simple.html"; |
| 288 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); | 290 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
| 289 CreateFetcher( | 291 CreateFetcher( |
| 290 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | 292 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); |
| 291 | 293 |
| 292 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 294 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
| 293 | 295 |
| 294 ASSERT_FALSE(file_util::PathExists(temp_file_)) | 296 ASSERT_FALSE(file_util::PathExists(temp_file_)) |
| 295 << temp_file_.value() << " not removed."; | 297 << temp_file_.value() << " not removed."; |
| 296 } | 298 } |
| 297 | 299 |
| 298 TEST_F(URLFetcherTempFileTest, LargeGet) { | 300 TEST_F(URLFetcherTempFileTest, LargeGet) { |
| 299 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 301 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 302 net::TestServer::kLocalhost, |
| 303 FilePath(kDocRoot)); |
| 300 ASSERT_TRUE(test_server.Start()); | 304 ASSERT_TRUE(test_server.Start()); |
| 301 | 305 |
| 302 // Get a file large enough to require more than one read into | 306 // Get a file large enough to require more than one read into |
| 303 // URLFetcher::Core's IOBuffer. | 307 // URLFetcher::Core's IOBuffer. |
| 304 const char* kFileToFetch = "animate1.gif"; | 308 const char* kFileToFetch = "animate1.gif"; |
| 305 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); | 309 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
| 306 CreateFetcher(test_server.GetURL( | 310 CreateFetcher(test_server.GetURL( |
| 307 std::string(kTestServerFilePrefix) + kFileToFetch)); | 311 std::string(kTestServerFilePrefix) + kFileToFetch)); |
| 308 | 312 |
| 309 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 313 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
| 310 } | 314 } |
| 311 | 315 |
| 312 TEST_F(URLFetcherTempFileTest, CanTakeOwnershipOfFile) { | 316 TEST_F(URLFetcherTempFileTest, CanTakeOwnershipOfFile) { |
| 313 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 317 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 318 net::TestServer::kLocalhost, |
| 319 FilePath(kDocRoot)); |
| 314 ASSERT_TRUE(test_server.Start()); | 320 ASSERT_TRUE(test_server.Start()); |
| 315 | 321 |
| 316 // Get a small file. | 322 // Get a small file. |
| 317 const char* kFileToFetch = "simple.html"; | 323 const char* kFileToFetch = "simple.html"; |
| 318 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); | 324 expected_file_ = test_server.document_root().AppendASCII(kFileToFetch); |
| 319 CreateFetcher(test_server.GetURL( | 325 CreateFetcher(test_server.GetURL( |
| 320 std::string(kTestServerFilePrefix) + kFileToFetch)); | 326 std::string(kTestServerFilePrefix) + kFileToFetch)); |
| 321 | 327 |
| 322 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 328 MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
| 323 | 329 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 take_ownership_of_temp_file_, &temp_file_)); | 525 take_ownership_of_temp_file_, &temp_file_)); |
| 520 | 526 |
| 521 EXPECT_TRUE(file_util::ContentsEqual(expected_file_, temp_file_)); | 527 EXPECT_TRUE(file_util::ContentsEqual(expected_file_, temp_file_)); |
| 522 | 528 |
| 523 delete fetcher_; | 529 delete fetcher_; |
| 524 | 530 |
| 525 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 531 io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 526 } | 532 } |
| 527 | 533 |
| 528 TEST_F(URLFetcherTest, SameThreadsTest) { | 534 TEST_F(URLFetcherTest, SameThreadsTest) { |
| 529 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 535 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 536 net::TestServer::kLocalhost, |
| 537 FilePath(kDocRoot)); |
| 530 ASSERT_TRUE(test_server.Start()); | 538 ASSERT_TRUE(test_server.Start()); |
| 531 | 539 |
| 532 // Create the fetcher on the main thread. Since IO will happen on the main | 540 // Create the fetcher on the main thread. Since IO will happen on the main |
| 533 // thread, this will test URLFetcher's ability to do everything on one | 541 // thread, this will test URLFetcher's ability to do everything on one |
| 534 // thread. | 542 // thread. |
| 535 CreateFetcher(test_server.GetURL("defaultresponse")); | 543 CreateFetcher(test_server.GetURL("defaultresponse")); |
| 536 | 544 |
| 537 MessageLoop::current()->Run(); | 545 MessageLoop::current()->Run(); |
| 538 } | 546 } |
| 539 | 547 |
| 540 #if defined(OS_MACOSX) | 548 #if defined(OS_MACOSX) |
| 541 // SIGSEGV on Mac: http://crbug.com/60426 | 549 // SIGSEGV on Mac: http://crbug.com/60426 |
| 542 TEST_F(URLFetcherTest, DISABLED_DifferentThreadsTest) { | 550 TEST_F(URLFetcherTest, DISABLED_DifferentThreadsTest) { |
| 543 #else | 551 #else |
| 544 TEST_F(URLFetcherTest, DifferentThreadsTest) { | 552 TEST_F(URLFetcherTest, DifferentThreadsTest) { |
| 545 #endif | 553 #endif |
| 546 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 554 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 555 net::TestServer::kLocalhost, |
| 556 FilePath(kDocRoot)); |
| 547 ASSERT_TRUE(test_server.Start()); | 557 ASSERT_TRUE(test_server.Start()); |
| 548 | 558 |
| 549 // Create a separate thread that will create the URLFetcher. The current | 559 // Create a separate thread that will create the URLFetcher. The current |
| 550 // (main) thread will do the IO, and when the fetch is complete it will | 560 // (main) thread will do the IO, and when the fetch is complete it will |
| 551 // terminate the main thread's message loop; then the other thread's | 561 // terminate the main thread's message loop; then the other thread's |
| 552 // message loop will be shut down automatically as the thread goes out of | 562 // message loop will be shut down automatically as the thread goes out of |
| 553 // scope. | 563 // scope. |
| 554 base::Thread t("URLFetcher test thread"); | 564 base::Thread t("URLFetcher test thread"); |
| 555 ASSERT_TRUE(t.Start()); | 565 ASSERT_TRUE(t.Start()); |
| 556 t.message_loop()->PostTask( | 566 t.message_loop()->PostTask( |
| 557 FROM_HERE, | 567 FROM_HERE, |
| 558 base::Bind(&URLFetcherTest::CreateFetcher, | 568 base::Bind(&URLFetcherTest::CreateFetcher, |
| 559 base::Unretained(this), | 569 base::Unretained(this), |
| 560 test_server.GetURL("defaultresponse"))); | 570 test_server.GetURL("defaultresponse"))); |
| 561 | 571 |
| 562 MessageLoop::current()->Run(); | 572 MessageLoop::current()->Run(); |
| 563 } | 573 } |
| 564 | 574 |
| 565 #if defined(OS_MACOSX) | 575 #if defined(OS_MACOSX) |
| 566 // SIGSEGV on Mac: http://crbug.com/60426 | 576 // SIGSEGV on Mac: http://crbug.com/60426 |
| 567 TEST_F(URLFetcherPostTest, DISABLED_Basic) { | 577 TEST_F(URLFetcherPostTest, DISABLED_Basic) { |
| 568 #else | 578 #else |
| 569 TEST_F(URLFetcherPostTest, Basic) { | 579 TEST_F(URLFetcherPostTest, Basic) { |
| 570 #endif | 580 #endif |
| 571 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 581 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 582 net::TestServer::kLocalhost, |
| 583 FilePath(kDocRoot)); |
| 572 ASSERT_TRUE(test_server.Start()); | 584 ASSERT_TRUE(test_server.Start()); |
| 573 | 585 |
| 574 CreateFetcher(test_server.GetURL("echo")); | 586 CreateFetcher(test_server.GetURL("echo")); |
| 575 MessageLoop::current()->Run(); | 587 MessageLoop::current()->Run(); |
| 576 } | 588 } |
| 577 | 589 |
| 578 TEST_F(URLFetcherHeadersTest, Headers) { | 590 TEST_F(URLFetcherHeadersTest, Headers) { |
| 579 net::TestServer test_server(net::TestServer::TYPE_HTTP, | 591 net::TestServer test_server( |
| 592 net::TestServer::TYPE_HTTP, |
| 593 net::TestServer::kLocalhost, |
| 580 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 594 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 581 ASSERT_TRUE(test_server.Start()); | 595 ASSERT_TRUE(test_server.Start()); |
| 582 | 596 |
| 583 CreateFetcher(test_server.GetURL("files/with-headers.html")); | 597 CreateFetcher(test_server.GetURL("files/with-headers.html")); |
| 584 MessageLoop::current()->Run(); | 598 MessageLoop::current()->Run(); |
| 585 // The actual tests are in the URLFetcherHeadersTest fixture. | 599 // The actual tests are in the URLFetcherHeadersTest fixture. |
| 586 } | 600 } |
| 587 | 601 |
| 588 TEST_F(URLFetcherSocketAddressTest, SocketAddress) { | 602 TEST_F(URLFetcherSocketAddressTest, SocketAddress) { |
| 589 net::TestServer test_server(net::TestServer::TYPE_HTTP, | 603 net::TestServer test_server( |
| 604 net::TestServer::TYPE_HTTP, |
| 605 net::TestServer::kLocalhost, |
| 590 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 606 FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 591 ASSERT_TRUE(test_server.Start()); | 607 ASSERT_TRUE(test_server.Start()); |
| 592 expected_port_ = test_server.host_port_pair().port(); | 608 expected_port_ = test_server.host_port_pair().port(); |
| 593 | 609 |
| 594 // Reusing "with-headers.html" but doesn't really matter. | 610 // Reusing "with-headers.html" but doesn't really matter. |
| 595 CreateFetcher(test_server.GetURL("files/with-headers.html")); | 611 CreateFetcher(test_server.GetURL("files/with-headers.html")); |
| 596 MessageLoop::current()->Run(); | 612 MessageLoop::current()->Run(); |
| 597 // The actual tests are in the URLFetcherSocketAddressTest fixture. | 613 // The actual tests are in the URLFetcherSocketAddressTest fixture. |
| 598 } | 614 } |
| 599 | 615 |
| 600 TEST_F(URLFetcherProtectTest, Overload) { | 616 TEST_F(URLFetcherProtectTest, Overload) { |
| 601 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 617 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 618 net::TestServer::kLocalhost, |
| 619 FilePath(kDocRoot)); |
| 602 ASSERT_TRUE(test_server.Start()); | 620 ASSERT_TRUE(test_server.Start()); |
| 603 | 621 |
| 604 GURL url(test_server.GetURL("defaultresponse")); | 622 GURL url(test_server.GetURL("defaultresponse")); |
| 605 | 623 |
| 606 // Registers an entry for test url. It only allows 3 requests to be sent | 624 // Registers an entry for test url. It only allows 3 requests to be sent |
| 607 // in 200 milliseconds. | 625 // in 200 milliseconds. |
| 608 net::URLRequestThrottlerManager* manager = | 626 net::URLRequestThrottlerManager* manager = |
| 609 net::URLRequestThrottlerManager::GetInstance(); | 627 net::URLRequestThrottlerManager::GetInstance(); |
| 610 scoped_refptr<net::URLRequestThrottlerEntry> entry( | 628 scoped_refptr<net::URLRequestThrottlerEntry> entry( |
| 611 new net::URLRequestThrottlerEntry(manager, "", 200, 3, 1, 2.0, 0.0, 256)); | 629 new net::URLRequestThrottlerEntry(manager, "", 200, 3, 1, 2.0, 0.0, 256)); |
| 612 manager->OverrideEntryForTests(url, entry); | 630 manager->OverrideEntryForTests(url, entry); |
| 613 | 631 |
| 614 CreateFetcher(url); | 632 CreateFetcher(url); |
| 615 | 633 |
| 616 MessageLoop::current()->Run(); | 634 MessageLoop::current()->Run(); |
| 617 | 635 |
| 618 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); | 636 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); |
| 619 } | 637 } |
| 620 | 638 |
| 621 TEST_F(URLFetcherProtectTest, ServerUnavailable) { | 639 TEST_F(URLFetcherProtectTest, ServerUnavailable) { |
| 622 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 640 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 641 net::TestServer::kLocalhost, |
| 642 FilePath(kDocRoot)); |
| 623 ASSERT_TRUE(test_server.Start()); | 643 ASSERT_TRUE(test_server.Start()); |
| 624 | 644 |
| 625 GURL url(test_server.GetURL("files/server-unavailable.html")); | 645 GURL url(test_server.GetURL("files/server-unavailable.html")); |
| 626 | 646 |
| 627 // Registers an entry for test url. The backoff time is calculated by: | 647 // Registers an entry for test url. The backoff time is calculated by: |
| 628 // new_backoff = 2.0 * old_backoff + 0 | 648 // new_backoff = 2.0 * old_backoff + 0 |
| 629 // and maximum backoff time is 256 milliseconds. | 649 // and maximum backoff time is 256 milliseconds. |
| 630 // Maximum retries allowed is set to 11. | 650 // Maximum retries allowed is set to 11. |
| 631 net::URLRequestThrottlerManager* manager = | 651 net::URLRequestThrottlerManager* manager = |
| 632 net::URLRequestThrottlerManager::GetInstance(); | 652 net::URLRequestThrottlerManager::GetInstance(); |
| 633 scoped_refptr<net::URLRequestThrottlerEntry> entry( | 653 scoped_refptr<net::URLRequestThrottlerEntry> entry( |
| 634 new net::URLRequestThrottlerEntry(manager, "", 200, 3, 1, 2.0, 0.0, 256)); | 654 new net::URLRequestThrottlerEntry(manager, "", 200, 3, 1, 2.0, 0.0, 256)); |
| 635 manager->OverrideEntryForTests(url, entry); | 655 manager->OverrideEntryForTests(url, entry); |
| 636 | 656 |
| 637 CreateFetcher(url); | 657 CreateFetcher(url); |
| 638 | 658 |
| 639 MessageLoop::current()->Run(); | 659 MessageLoop::current()->Run(); |
| 640 | 660 |
| 641 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); | 661 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); |
| 642 } | 662 } |
| 643 | 663 |
| 644 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { | 664 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { |
| 645 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 665 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 666 net::TestServer::kLocalhost, |
| 667 FilePath(kDocRoot)); |
| 646 ASSERT_TRUE(test_server.Start()); | 668 ASSERT_TRUE(test_server.Start()); |
| 647 | 669 |
| 648 GURL url(test_server.GetURL("files/server-unavailable.html")); | 670 GURL url(test_server.GetURL("files/server-unavailable.html")); |
| 649 | 671 |
| 650 // Registers an entry for test url. The backoff time is calculated by: | 672 // Registers an entry for test url. The backoff time is calculated by: |
| 651 // new_backoff = 2.0 * old_backoff + 0 | 673 // new_backoff = 2.0 * old_backoff + 0 |
| 652 // and maximum backoff time is 150000 milliseconds. | 674 // and maximum backoff time is 150000 milliseconds. |
| 653 // Maximum retries allowed is set to 11. | 675 // Maximum retries allowed is set to 11. |
| 654 net::URLRequestThrottlerManager* manager = | 676 net::URLRequestThrottlerManager* manager = |
| 655 net::URLRequestThrottlerManager::GetInstance(); | 677 net::URLRequestThrottlerManager::GetInstance(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 681 CreateFetcher(test_server.GetURL("defaultresponse")); | 703 CreateFetcher(test_server.GetURL("defaultresponse")); |
| 682 MessageLoop::current()->Run(); | 704 MessageLoop::current()->Run(); |
| 683 } | 705 } |
| 684 | 706 |
| 685 #if defined(OS_MACOSX) | 707 #if defined(OS_MACOSX) |
| 686 // SIGSEGV on Mac: http://crbug.com/60426 | 708 // SIGSEGV on Mac: http://crbug.com/60426 |
| 687 TEST_F(URLFetcherCancelTest, DISABLED_ReleasesContext) { | 709 TEST_F(URLFetcherCancelTest, DISABLED_ReleasesContext) { |
| 688 #else | 710 #else |
| 689 TEST_F(URLFetcherCancelTest, ReleasesContext) { | 711 TEST_F(URLFetcherCancelTest, ReleasesContext) { |
| 690 #endif | 712 #endif |
| 691 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 713 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 714 net::TestServer::kLocalhost, |
| 715 FilePath(kDocRoot)); |
| 692 ASSERT_TRUE(test_server.Start()); | 716 ASSERT_TRUE(test_server.Start()); |
| 693 | 717 |
| 694 GURL url(test_server.GetURL("files/server-unavailable.html")); | 718 GURL url(test_server.GetURL("files/server-unavailable.html")); |
| 695 | 719 |
| 696 // Registers an entry for test url. The backoff time is calculated by: | 720 // Registers an entry for test url. The backoff time is calculated by: |
| 697 // new_backoff = 2.0 * old_backoff +0 | 721 // new_backoff = 2.0 * old_backoff +0 |
| 698 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. | 722 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. |
| 699 // Maximum retries allowed is set to 2. | 723 // Maximum retries allowed is set to 2. |
| 700 net::URLRequestThrottlerManager* manager = | 724 net::URLRequestThrottlerManager* manager = |
| 701 net::URLRequestThrottlerManager::GetInstance(); | 725 net::URLRequestThrottlerManager::GetInstance(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 714 t.message_loop()->PostTask( | 738 t.message_loop()->PostTask( |
| 715 FROM_HERE, | 739 FROM_HERE, |
| 716 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); | 740 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); |
| 717 | 741 |
| 718 MessageLoop::current()->Run(); | 742 MessageLoop::current()->Run(); |
| 719 | 743 |
| 720 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); | 744 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); |
| 721 } | 745 } |
| 722 | 746 |
| 723 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { | 747 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { |
| 724 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 748 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 749 net::TestServer::kLocalhost, |
| 750 FilePath(kDocRoot)); |
| 725 ASSERT_TRUE(test_server.Start()); | 751 ASSERT_TRUE(test_server.Start()); |
| 726 | 752 |
| 727 GURL url(test_server.GetURL("files/server-unavailable.html")); | 753 GURL url(test_server.GetURL("files/server-unavailable.html")); |
| 728 | 754 |
| 729 // Register an entry for test url. | 755 // Register an entry for test url. |
| 730 // Using a sliding window of 4 seconds, and max of 1 request, under a fast | 756 // Using a sliding window of 4 seconds, and max of 1 request, under a fast |
| 731 // run we expect to have a 4 second delay when posting the Start task. | 757 // run we expect to have a 4 second delay when posting the Start task. |
| 732 net::URLRequestThrottlerManager* manager = | 758 net::URLRequestThrottlerManager* manager = |
| 733 net::URLRequestThrottlerManager::GetInstance(); | 759 net::URLRequestThrottlerManager::GetInstance(); |
| 734 scoped_refptr<net::URLRequestThrottlerEntry> entry( | 760 scoped_refptr<net::URLRequestThrottlerEntry> entry( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 747 t.message_loop()->PostTask( | 773 t.message_loop()->PostTask( |
| 748 FROM_HERE, | 774 FROM_HERE, |
| 749 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); | 775 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); |
| 750 | 776 |
| 751 MessageLoop::current()->Run(); | 777 MessageLoop::current()->Run(); |
| 752 | 778 |
| 753 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); | 779 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); |
| 754 } | 780 } |
| 755 | 781 |
| 756 TEST_F(URLFetcherMultipleAttemptTest, SameData) { | 782 TEST_F(URLFetcherMultipleAttemptTest, SameData) { |
| 757 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 783 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 784 net::TestServer::kLocalhost, |
| 785 FilePath(kDocRoot)); |
| 758 ASSERT_TRUE(test_server.Start()); | 786 ASSERT_TRUE(test_server.Start()); |
| 759 | 787 |
| 760 // Create the fetcher on the main thread. Since IO will happen on the main | 788 // Create the fetcher on the main thread. Since IO will happen on the main |
| 761 // thread, this will test URLFetcher's ability to do everything on one | 789 // thread, this will test URLFetcher's ability to do everything on one |
| 762 // thread. | 790 // thread. |
| 763 CreateFetcher(test_server.GetURL("defaultresponse")); | 791 CreateFetcher(test_server.GetURL("defaultresponse")); |
| 764 | 792 |
| 765 MessageLoop::current()->Run(); | 793 MessageLoop::current()->Run(); |
| 766 } | 794 } |
| 767 | 795 |
| 768 void CancelAllOnIO() { | 796 void CancelAllOnIO() { |
| 769 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); | 797 EXPECT_EQ(1, URLFetcherTest::GetNumFetcherCores()); |
| 770 URLFetcherImpl::CancelAll(); | 798 URLFetcherImpl::CancelAll(); |
| 771 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); | 799 EXPECT_EQ(0, URLFetcherTest::GetNumFetcherCores()); |
| 772 } | 800 } |
| 773 | 801 |
| 774 // Tests to make sure CancelAll() will successfully cancel existing URLFetchers. | 802 // Tests to make sure CancelAll() will successfully cancel existing URLFetchers. |
| 775 TEST_F(URLFetcherTest, CancelAll) { | 803 TEST_F(URLFetcherTest, CancelAll) { |
| 776 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); | 804 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 805 net::TestServer::kLocalhost, |
| 806 FilePath(kDocRoot)); |
| 777 ASSERT_TRUE(test_server.Start()); | 807 ASSERT_TRUE(test_server.Start()); |
| 778 EXPECT_EQ(0, GetNumFetcherCores()); | 808 EXPECT_EQ(0, GetNumFetcherCores()); |
| 779 | 809 |
| 780 CreateFetcher(test_server.GetURL("defaultresponse")); | 810 CreateFetcher(test_server.GetURL("defaultresponse")); |
| 781 io_message_loop_proxy()->PostTaskAndReply( | 811 io_message_loop_proxy()->PostTaskAndReply( |
| 782 FROM_HERE, | 812 FROM_HERE, |
| 783 base::Bind(&CancelAllOnIO), | 813 base::Bind(&CancelAllOnIO), |
| 784 MessageLoop::QuitClosure()); | 814 MessageLoop::QuitClosure()); |
| 785 MessageLoop::current()->Run(); | 815 MessageLoop::current()->Run(); |
| 786 EXPECT_EQ(0, GetNumFetcherCores()); | 816 EXPECT_EQ(0, GetNumFetcherCores()); |
| 787 delete fetcher_; | 817 delete fetcher_; |
| 788 } | 818 } |
| 789 | 819 |
| 790 } // namespace. | 820 } // namespace. |
| OLD | NEW |